Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » How to create a modal dialog
How to create a modal dialog [message #2299] Fri, 07 April 2006 07:59 Go to next message
forlano is currently offline  forlano
Messages: 1189
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

so far we have create widgets in the main window of the application. Sometimes the action requires to open a window dialog to get further input from the user. The dialog can be modal or not modal. In the first case the dialog is on the top of the screen and the main window is temporary inactive. In the second case the user can switch and perform action on the dialog and on the main window as well.
The following code is my last experiment with modal dialoga. It shows a main window with a button that open a modal dialog. This last has been create with the Designer (I can't live without it Smile )

#include <CtrlLib/CtrlLib.h>
#define LAYOUTFILE <Vega/editmask.lay> //substitute the path of your layout file
#include <CtrlCore/lay.h>

void testAction()
    { PromptOK("Hello World!");
    }

 ///////////////////////// class //////////////////////
class ButtonOpenDlg : public WithButtonOpen<TopWindow> {
public:
 
    typedef ButtonOpenDlg CLASSNAME;

	ButtonOpenDlg();
};

ButtonOpenDlg::ButtonOpenDlg()
{
	CtrlLayout(*this, "");
    //btnOpen <<= THISBACK(testAction); //this doesn't work: testAction() is a member of ButtonOpenDlg class
	btnOpen.WhenAction = callback(testAction); //testAction() must be OUT of the class
}
///////////////////// end class ////////////////////


void OpenDialog()
{
  ButtonOpenDlg a;
  a.Run();
}


GUI_APP_MAIN
{ 	TopWindow w;
	Button b;
		
	w.Add(b);
	b.SetLabel("button - testAction");
	b.SetPos(b.PosLeft(200, 250), b.PosTop(100, 30));	
	b.WhenAction=callback(OpenDialog);

	w.Run();
}


//////////////////////// editmask.lay //////////////////
LAYOUT(ButtonOpen, 280, 208)
	ITEM(Button, btnOpen, SetLabel(t_("Open Window")).LeftPosZ(92, 96).TopPosZ(88, 24))
END_LAYOUT



I have noticed that the

btnOpen <<= THISBACK(myCallback);

works only for members of the class. While if you want have access to a function out the class you must use

btnOpen.WhenAction = callback(OpenDialog);

Is this correct? One more question. How to create a non modal dialog?
Thank you,
Luigi
Re: How to create a modal dialog [message #2300 is a reply to message #2299] Fri, 07 April 2006 09:21 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13984
Registered: November 2005
Ultimate Member
forlano wrote on Fri, 07 April 2006 01:59

I have noticed that the

btnOpen <<= THISBACK(myCallback);

works only for members of the class. While if you want have access to a function out the class you must use

btnOpen.WhenAction = callback(OpenDialog);



Correct. Also, you can call callback of another instance.

btnOpen.WhenAction = callback(object_ptr, &ObjectClass::Method)

Note that Ctrl::WhenAction can also be assigned using '<<=':

btn <<= callback(OpenDialog);

Quote:


How to create a non modal dialog?



Make it a member of your main window class - that way it will not be closed at the and of scope by destructor (you will have to add code for closing it as well).

Mirek
Re: How to create a modal dialog [message #2303 is a reply to message #2299] Fri, 07 April 2006 10:25 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
Modal dialogs are evil from UI ergonomy point.
Try to avoid them as much as possible, if you think you "need" modal dialog, you are very likely having some serious problem with your overall UI design, or you are taking a coding shortcut to omit code which would be needed to handle more "alive" windows at the same time. (The latter is understandable as resources are never unlimited, but try to avoid them...)
Re: How to create a modal dialog [message #2305 is a reply to message #2303] Fri, 07 April 2006 11:24 Go to previous message
mirek is currently offline  mirek
Messages: 13984
Registered: November 2005
Ultimate Member
mr_ped wrote on Fri, 07 April 2006 04:25

Modal dialogs are evil from UI ergonomy point.
Try to avoid them as much as possible, if you think you "need" modal dialog, you are very likely having some serious problem with your overall UI design, or you are taking a coding shortcut to omit code which would be needed to handle more "alive" windows at the same time. (The latter is understandable as resources are never unlimited, but try to avoid them...)


Ahh, well, after 8 years of experiences of dealing with users of my little municipal agenda, I would not draw conclusions so fast.

Modal dialogs have their places in GUI.

(That said, it is as easy to do modal and modeless in U++)

Mirek
Previous Topic: How to call the methods of a class from another class
Next Topic: How to add a three state button in an ArrayCtrl
Goto Forum:
  


Current Time: Sat Jun 15 16:45:57 CEST 2024

Total time taken to generate the page: 0.01955 seconds