GDialog Class Reference

A top level dialog window. More...

#include <LgiWidgets.h>

Inheritance diagram for GDialog:

GWindow GLgiRes GView GDragDropTarget GAbout GAlert GFindReplaceCommon GFontSelect GInput GProgressDlg GFindDlg GReplaceDlg

List of all members.

Public Member Functions

 GDialog ()
 Constructor.
 ~GDialog ()
 Destructor.
virtual int DoModal (OsView ParentHnd=0)
 Run the dialog in modal mode.
virtual int DoModeless ()
 Run the dialog in modeless mode.
virtual void EndModal (int Code=0)
 End a modal window. Typically calling in the OnNotify event of the GDialog.
virtual void EndModeless (int Code=0)
 End a modeless window. Typically calling in the OnNotify event of the GDialog.
int OnEvent (GMessage *Msg)
 Called to process every message received by this window.
bool OnRequestClose (bool OsClose)
 Called on a top level window when something requests to close the window.
void OnPosChange ()
 Called when the view position changes.

Protected Member Functions

bool LoadFromResource (int Resource)
 Load the dialog from a resource.

Friends

class GControl


Detailed Description

A top level dialog window.

GDialog's can either be modal or modeless. A modal dialog blocks the user from accessing the parent GWindow until the dialog has been dismissed. A modeless dialog behaves like any other top level window in that it doesn't block the user accessing any other top level window while it's open.

GDialog's can be created in two different ways. Firstly you can create code to instantiate all the various controls and add them manually to the GView::Children list. Or you can load all the controls from a resource file. The resource files are in XML format and there is a graphical tool LgiRes.

Manual example:

 #define IDC_STRING         100

 class Example : public GDialog
 {
 public:
        char *Str;

    Example(GView *p)
    {
            Str = 0;
        SetParent(p);
        GRect r(0, 0, 400, 300);
        SetPos(p);
        MoveToCenter();
            
        Children.Insert(new GEdit(IDC_STRING, 10, 10, 200, 20, ""));
        Children.Insert(new GButton(IDOK, 10, 30, 80, 20, "Ok"));
        Children.Insert(new GButton(IDCANCEL, 100, 30, 80, 20, "Cancel"));
    }

        ~Example()
        {
            DeleteArray(Str);
        }
        
    int OnNotify(GViewI *c, int Flags)
    {
        switch (c->GetId())
        {
            case IDOK:
                {
                    Str = NewStr(GetCtrlName(IDC_STRING));
                    // fall thru
                }
                case IDCANCEL:
            {
                EndModal(c->GetId());
                break;
            }
        }
 
        return 0;
    }
 };

This example shows how to insert child widgets into the window and then process clicks on the buttons and finally return data to the caller via a public member variable. It is desirable to pass data using this method because a dialog could be running in it's own thread on some systems and therefor should not be accessing data structures outside of itself directly without locking them. If your main application' doesn't have thread locking in place for it's main data structures then accessing them from the dialog wouldn't be thread safe. This is mainly the case with the BeOS port of Lgi, but is good practise for the Windows and Linux ports for cross platform compatibility.

The resource file method of creating dialogs is arguably the easier route to take once your've got it set up. Firstly create a resource file using LgiRes with the same name as your programs executable, but a different extension ("lr8"). When you call the GLgiRes::LoadFromResource function Lgi will automatically look for a file named after the running executable with the right extension and load it. Then it will find the dialog resource and instantiate all the controls specified in the resource. All the built in Lgi controls are supported directly as tags in the XML file and you can create your own custom controls that the resource loader can instantiate as well using the GViewFactory system.

Resource file example:

 #include "Resdefs.h" // For the dialog defines

 class Example : public GDialog
 {
 public:
        char *Str;

    Example(GView *p)
    {
            Str = 0;
        SetParent(p);
            if (LoadFromResource(IDD_EXAMPLE))
            {
            MoveToCenter();
        }
    }

        ~Example()
        {
            DeleteArray(Str);
        }
        
    int OnNotify(GViewI *c, int Flags)
    {
        switch (c->GetId())
        {
            case IDOK:
                {
                    Str = NewStr(GetCtrlName(1));
                    // fall thru
                }
                case IDCANCEL:
            {
                EndModal(c->GetId());
                break;
            }
        }
 
        return 0;
    }
 };

This assumes you have created an lr8 file with the resource named 'IDD_EXAMPLE' in it.

Now to actually call either of these dialogs you would use code like this:

 Example Dlg(MyWindow);
 if (Dlg.DoModal() == IDOK)
 {
    // Do something with Dlg.Str
 }

The built in controls that you can use are:


Member Function Documentation

int GDialog::DoModal ( OsView  ParentHnd = 0  )  [virtual]

Run the dialog in modal mode.

The user has to dismiss the dialog to continue.

Parameters:
ParentHnd  Optional override parent window handle

References GView::AttachChildren(), GView::GetParent(), GWindow::OnCreate(), and GWindow::WindowHandle().

Referenced by GTextView3::DoFind(), GTextView3::DoReplace(), GAbout::GAbout(), SystemFunctions::GetInputDlg(), Html2::GHtml2::OnKey(), GHtml::OnKey(), and GTextView3::OnMouseClick().

int GDialog::DoModeless (  )  [virtual]

Run the dialog in modeless mode.

It will behave like any other top level window. The user doesn't have to dismiss the window to continue, it can just move to the back.

References GWindow::Attach(), GView::AttachChildren(), and GWindow::Visible().

Referenced by GProgressDlg::GProgressDlg().

bool GDialog::LoadFromResource ( int  Resource  )  [protected]

Load the dialog from a resource.

Parameters:
Resource  The resource ID

References GWindow::Name(), and GWindow::SetPos().


The documentation for this class was generated from the following files:

Generated on Wed Dec 1 15:41:02 2010 for Lgi by  doxygen 1.5.7.1