SOL9 2.0 Class: ModelessDialog

 SOL9 C++ Class Library  SOL9 Samples  SOL9 Tutorial  SOL9 FAQ  SOL9 ClassTree 

Source code

/*
 * ModelessDialog.h 
 * Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL++2000
// 2000.02.18
#pragma once

#include <sol\PopupView.h>
#include <sol\InvalidArgumentException.h>
#include <sol\InvalidWindowException.h>


namespace SOL {

class ModelessDialog :public PopupView {

protected:
    virtual long command(Event& event) 
    {
        HWND child   = event.getChild();
        const char* name = findCallbackName(event, child);

        WPARAM wParam = event.getWParam();
        // If it was a OK button, then ...
        if(name == XmNactivateCallback &&  wParam == 1) {
            child = ::GetFocus();
        }
        callCallback(name, (Key)child, NULL, event);
        return TRUE;
    }
  

public:
    ModelessDialog():PopupView() { }

public:
    ModelessDialog(View* owner, const char* name, Args& args)
    :PopupView(owner)
    {
    //ModelessDialog::create(owner, name, args);
        setOwner(owner);

        HWND howner    = NULL; 
        HINSTANCE hins = NULL;
        if (owner) {
            howner = owner -> getWindow();
            hins   = owner -> getInstanceHandle();
        }

        const char* templateName = (const char*) args.get(XmNtemplateName);

        if (templateName == NULL || *templateName == Zero) {
            throw InvalidArgumentException("Dialog template-name is missing");
        }

        HWND hwnd = ::CreateDialog(hins, templateName, 
                            howner, 
                            (DLGPROC)PopupView::procedure);

        if (hwnd == NULL) {
            throw InvalidWindowException("Failed to create a modeless dialog");
        }
        setWindow(hwnd);
    
        int focusId = IDOK;
        ulong val;
        if (args.get(XmNfocusId, &val)){
            focusId = (int)val;        
        }
        setFocusId(focusId);
        setPopupFocus();

        Application::add(hwnd, this);
    
        addCallback(XmNactivateCallback, IDCANCEL, this,
            (Callback)&ModelessDialog::popdown, NULL);

    }

public:
    virtual Boolean create(View* owner, const char* name, Args& args)
    {
    // 2001/03/11
        Boolean rc = PopupView::create(owner);
    
        setOwner(owner);

        HWND howner    = NULL; 
        HINSTANCE hins = NULL;
        if (owner) {
            howner = owner -> getWindow();
            hins   = owner -> getInstanceHandle();
        }

        const char* templateName = (const char*) args.get(XmNtemplateName);

        if (templateName == NULL || *templateName == Zero) {
            throw InvalidArgumentException("Dialog template-name is missing");
        }

        HWND hwnd = ::CreateDialog(hins, templateName, 
                            howner, 
                            (DLGPROC)PopupView::procedure);

        if (hwnd == NULL) {
            throw InvalidWindowException("Failed to create a modeless dialog");
        }
        setWindow(hwnd);
    
        int focusId = IDOK;
        ulong val;
        if (args.get(XmNfocusId, &val)){
            focusId = (int)val;        
        }
        setFocusId(focusId);
        setPopupFocus();

        Application::add(hwnd, this);
    
        addCallback(XmNactivateCallback, IDCANCEL, this,
            (Callback)&ModelessDialog::popdown, NULL);

        return rc;
    }


public:
    void popup(Action& action)
    {
        raise();
        show(SW_NORMAL);    
    }
};

}



Last modified: 1 Feb 2012

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