SOL9 2.0 Sample: ModalDialog

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * ModalDialog.cpp 
 * Copyright (c) 2009 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL++2000
// 1999.09.25 Modified

// 2000.02.18


#include <sol\ApplicationView.h>
#include <sol\ScrolledText.h>
#include <sol\ModalDialog.h>
#include <sol\Text.h>
#include <sol\ListBox.h>
#include "resource.h"

namespace SOL {

class FileDlg : public ModalDialog {
private:

    Text*    text;
    ListBox* listbox;

private:
    void changeDir(Action& action)
    {
        TCHAR dir[128];
        WPARAM attribute = DDL_READWRITE|DDL_READONLY|DDL_HIDDEN |\
            DDL_SYSTEM|DDL_ARCHIVE|DDL_DIRECTORY;

        text -> getText(dir, sizeof(dir));

        TCHAR pattern[MAX_PATH];
        _stprintf(pattern, _T("%s\\*.*"), dir);
        listbox -> resetContent();
        listbox -> dir(attribute, pattern);
    }

public:
    FileDlg(View* parent, const TCHAR* caption, Args& args)
    :ModalDialog(parent, caption,
            args.set(XmNtemplateName, "FileName"))
    {

        text    = NULL;
        listbox = NULL;

    }

public:
    ~FileDlg()
    {
        if(text)    delete text;
        if(listbox) delete listbox; 
    }

private:
    long initDialog(Event& event)    
    {
        if(text)    delete text;
        if(listbox) delete listbox;

        text    = new Text(this, getItem(IDC_EDIT));
        listbox = new ListBox(this, getItem(IDC_LIST));
        text -> setFocus();
        text -> addCallback(XmNactivateCallback, this,
            (Callback)&FileDlg::changeDir, NULL);

        return NULL;
    }

public:
    void getFileName(TCHAR* fileName, int size)
    {
        TCHAR* dir = text -> getText();
        TCHAR* file = listbox -> getCurText();    
        *fileName = Zero;
        if(dir && file) {
            _stprintf(fileName, _T("%s\\%s"), dir, file);
        }
        delete [] dir;
        delete [] file;
    }

};


//
class AppView :public ApplicationView {
private:
    FileDlg*    fileDlg;
    ScrolledText   text;

private:
    void ok(Action& action)
    {
        TCHAR fileName[256];
        fileDlg->getFileName(fileName, sizeof(fileName));
          text.load(fileName);
    }

public:
    AppView(Application& applet, const TCHAR* name, Args& args)
        :ApplicationView(applet, name, args)
    {
        Args ar;
        ar.set(XmNtemplateName, _T("FileName"));
         fileDlg = new FileDlg(this, NULL, ar);

        ar.reset();
        text.create(this, NULL, ar);
        // 1999.09.25
        add(text);

        addCallback(XmNmenuCallback, ID_OPEN, fileDlg,
            (Callback)&ModalDialog::popup, NULL);

        addCallback(XmNmenuCallback, ID_EXIT, this,
            (Callback)&AppView::exit, NULL);

        fileDlg->addCallback(XmNactivateCallback, IDOK, this,
            (Callback)&AppView::ok, NULL);    

        restorePlacement();
    }
};

}

//
void    Main(int argc, TCHAR** argv)
{
    const TCHAR* appClass = _T("AppView");
    try {
        Application applet(appClass, argc, argv);

        Args args;
        AppView appView(applet, appClass, args);
        appView.realize();

        applet.run();
    } catch (...) {

    }
}


Last modified: 11 Nov 2009

Copyright (c) 2009 Antillia.com ALL RIGHTS RESERVED.