Modal dialogs

BlitzMax Forums/MaxGUI Module/Modal dialogs

ziggy(Posted 2006) [#1]
Any way to make a form act as a modal dialog?


Dreamora(Posted 2006) [#2]
Yes. On creation, make the form (window normally) parent to null and when showing it, disable the main window.

you will as well need to use the winapi function to set the window to "always on top", there is a module tweak or codearchive entry on that. with a little luck you even find the old thread on modal dialogs which brought up that solution :)


ziggy(Posted 2006) [#3]
Yes, I've already done that, but I was asking for a real system modal dialog, you know, (clicking the not'active window has to show the modal one, with a short flikering, and all this issues). Does anybody managed to make this, I don't care if It's been done using WinApi or whatever.


Dreamora(Posted 2006) [#4]
Might I ask what you are exactly trying to achive? (I mostly ask because there are a few dialogs within BM already supporting it. Notify and Confirm for ex)


ziggy(Posted 2006) [#5]
I'm making an extended GUI module, that encapsulates most of the work and adds some functionality. My Idea is to convine this with a GUI designer for BLIde. the fact is I think MaxGUI handles everything in a not much user friendly way (maybe too low level) I want to make an additional handler class much more OO friendly, and much more similar to the way events and GUI elements are handled by Visual Studio. (As instance, al windows inherit the BGWindow class, and all buttons or whatever in the window are in fact, fields of a certain type, etc etc. the same as in Visual Studio).

But the fact is that I'm finding a lot of limitations, and I'm just trying to solve them mantaining the cross-platform implementation of the resoulting source code.

MaxGUI is a very good and complete module, but I think it needs some extra work in certain areas. It seems it has been build for procedural programing, But I really don't see the benefits of making procedural programing in a event-based interface (it's just my opinion).

this is a sample of how clean the code is after appling this module:

Import blide.blgui

Type WelcomeDialog Extends BGWindow  
	Field but1:BGGlowButton 
	 
	'#Region THIS CODE IS GENERATED BY THE GUI EDITOR	 
		
	Method WelcomeDialog_Close(e:BGSimpleEvent)
		End
	End Method
	    
	Method But1_Pressed(e:BGMouseEvent)
		Notify("button pressed:  "    + but1.Text_get() + " contained in an object of type " +  but1.Container_Get().GetType()) + " mouse button used: " + e.Button + " Event identifier: " + e.id         	
	End Method 
End Type

Local I:WelcomeDialog= New WelcomeDialog 'Creates the instance
i.Load	'Creates the GUI elements and loads all the form

Repeat
	DoEvents()  	
Forever


You can see, you don't have to deal with event const any more... and you can forget about those bug Select ... End Select structures, and all windows are created as classes, etc etc. I hope I'll have this finished soon to start the BLIde GUI editor.

So, in fact, I was wondering how could I let a Window be modal.


Dreamora(Posted 2006) [#6]
MaxGUIs base problem is, and I think this is out of question as the win32maxgui mod shows this quite clearly, that it bases on BlitzPlus code. This itself isn't bad but the fact is that this already is based around procedural, winapi like behavior instead of the modern approach used by most other languages with event handlers and the like ...
This would need a major redesign which I'm not sure if it makes sense. Because over short or long, this module will vanish and be replaced by a .NET based one. This theoretically would then be crossplattform as well and that with far less problems than the current one.

From your example, it seems like you are going the Visual Basic way, right?

Hope you let it open for users to go the "C#" way with event handling functions that can be attached to function pointers because in the end, the VB way is "fixed" as well and to me not much better than the WinAPI constant switching way.


ziggy(Posted 2006) [#7]
@Dreamora: I'm going in the C# way, it's just not being shown in the example. let me show a more detailed one (with the region opened).

Import blide.blgui

Type WelcomeDialog Extends BGWindow  
	Field but1:BGGlowButton 
	'#Region  THIS CODE IS GENERATED BY THE GUI EDITOR
	Method Load()          
		Self.Create("This is my window", 10, 10, 400, 400, Null, enums.FormStyles.TitleBar | enums.FormStyles.IsResizable  )      'This is the window
		but1 = New BGGlowButton	'the window has a button called but1
		but1.Create(Self, "ok", 1, 40)    'the button is created

		'Handlers:
		Self.Event_Close = Welcomedialog_Close_Handler	'This is the function that will be called when the window is closed.
		Self.Event_Resize = WelcomeDialog_Resize_Handler ' This is the handler for resize window.
		but1.Event_Action = But1_EventAction_Handler	    'This is the function that is called when the button is pressed

	End Method    
	
	'This functions sends event-handling from generic functions the methods in the apropiate instance:
	'you can always change the original function pointers to anyway else.

	Function But1_EventAction_Handler(sender:BGBasicGadget,e:BGMouseEvent)     
     		WelcomeDialog(BGGlowButton(sender).GetWindow()).But1_Pressed(e)
	End Function 
                    
	Function Welcomedialog_Close_Handler(sender:bgbasicgadget, e:BGSimpleEvent)
		WelcomeDialog(sender).WelcomeDialog_Close(e) 
	End Function 
  
	Function WelcomeDialog_Resize_Handler(sender:bgbasicgadget, e:BGMouseEvent)
		WelcomeDialog(sender).WelcomeDialog_Resize(e)
	End Function
	'#End Region

	Method WelcomeDialog_Close(e:BGSimpleEvent)
		End
	End Method
	    
	Method But1_Pressed(e:BGMouseEvent)
		Notify("button pressed:  "    + but1.Text_get() + " contained in an object of type " +  but1.Container_Get().GetType()) + " mouse button used: " + e.Button + " Event identifier: " + e.id         	
	End Method 
End Type

Local I:WelcomeDialog= New WelcomeDialog 'Creates the instance
i.Load	'Creates the GUI elements and loads all the form

Repeat
	DoEvents()  	
Forever





SebHoll(Posted 2006) [#8]
Hi,

clicking the not'active window has to show the modal one, with a short flikering, and all this issues

You can acheive that in MaxGUI by:

a) When creating the window (using CreateWindow), set the parent paramter to the main window's gadget.
b) When you want the window to be modal, show it, disable the main window and activate the Child Modal window.
c) Once finished, hide child modal window and enable main window, then activate the main window and all should be well.

MaxIDE uses this technique for its requestors (e.g. Find & Replace). This works for me and even if the user switches programs, they have to respond to the modal window before they gain access to the Main one.

Seb