window modal

BlitzMax Forums/BlitzMax Beginners Area/window modal

Hi

I would like to load a second window but modal, I did't found anything in the doc but bmax ide have such modal window in 'IDE options window' but it's not modal, if I switch tab and come back in maxide then option box is no longer modal it minimize someone have a clue doing this ?

Interesting question - here's a quick attempt I just put together to explore it. I'm not sure if this will do exactly what you need, but it disables the "main" window when the modal one is launched and reenables it when the modal one closes:

Strict

Local window:TGadget = CreateWindow( "Main", 10,10, 400,300 )
Local button1:TGadget = CreateButton( "Launch modal window", 50,50, 150,24, window, BUTTON_PUSH )
Local text:TGadget = CreateTextArea( 50,110, 100,24, window )
Local buttontest:TGadget = CreateButton( "Test Activity", 50,140, 100,24, window, BUTTON_PUSH )

Local windowmodal:TGadget = CreateWindow( "Modal", 200,200, 200,150 )
Local buttonmodal:TGadget = CreateButton( "Close modal window", 10,10, 120,24, windowmodal, BUTTON_PUSH )

Local modalhidden = True
HideGadget windowmodal

Repeat
	WaitEvent

	If  EventID() = EVENT_APPRESUME Then
		ActivateGadget window
		If Not modalhidden Then ActivateGadget windowmodal
	EndIf
	
	Select EventSource()
		Case buttontest
			Select EventID()
				Case EVENT_GADGETACTION
				SetTextAreaText( text, Int( TextAreaText( text ) ) + 1 )
			End Select		
		Case window
			Select EventID()
				Case EVENT_WINDOWCLOSE
					End
			End Select
		Case button1
			Select EventID()
				Case EVENT_GADGETACTION
					ShowGadget windowmodal
					modalhidden = False
					DisableGadget window
			End Select
		Case buttonmodal
			Select EventID()
				Case EVENT_GADGETACTION
					EnableGadget window
					HideGadget windowmodal
					modalhidden = True
			End Select			
		Case windowmodal
			Select EventID()
				Case EVENT_WINDOWCLOSE
					EnableGadget window
					HideGadget windowmodal
					modalhidden = True
			End Select
	End Select
Forever


In this example, you can't do anything with the main window or its gadgets once the modal one is launched. The EVENT_APPRESUME checking makes sure that the right one is brought back to front when you alt-tab away and back. I have to use a "modalhidden" flag since GadgetHidden doesn't seem to work with windows (it always returns false even if the window is hidden).

I've only tried this in Windows, not Mac OS or Linux.

win:tgadget = CreateWindow("",0,0,GadgetWidth(Desktop()),GadgetHeight(Desktop()))
win1:tgadget = CreateWindow("",0,0,320,240,win)
DisableGadget(win)

While EventID()<>EVENT_WINDOWCLOSE
	WaitEvent()
Wend


Thanks that help a lot :)

Wendel your method is pretty good the only thing is that we see all the window when the program start and it hide it, can be a problem if I load more then one window at startup..

Papa your method is very good
here my version

here my code
win:tgadget = CreateWindow("",0,0,GadgetWidth(Desktop()),GadgetHeight(Desktop()))
win1:tgadget = CreateWindow("",0,0,320,240,win)
DisableGadget(win)

While WaitEvent()

Select EventID()
		Case EVENT_WINDOWCLOSE
		   If EventSource()= win Then
		      End
		   Else
			  If EventSource()=win1 Then
			     HideGadget win1:TGadget
			     EnableGadget(win)
			     activatewindow(win)
		      End If
		   End If

	
	End Select

Wend



even if I enable the window again it did't re-activate it we must do it manualy.. also the program create the window modal at startup, if I create it when I need it
the EventSource() can't detect windowmodal because it don't exist how to avoid this?

You could always stick your modal window into a function with its own event loop...
Global win:tgadget = CreateWindow("",0,0,GadgetWidth(Desktop()),GadgetHeight(Desktop()))
Local button:tgadget = CreateButton("Test modal window",10,10,100,20,win)

While WaitEvent()

	Select EventID()
		Case EVENT_GADGETACTION
			If EventSource() = button Then TestModalWindow()
		Case EVENT_WINDOWCLOSE
			If EventSource() = win Then End
	End Select
	
Wend


Function TestModalWindow()

	Local win1:tgadget = CreateWindow("Test",0,0,320,240,win,WINDOW_TITLEBAR)
	DisableGadget(win)

	While WaitEvent()
		Select EventID()
			Case EVENT_WINDOWCLOSE ; Exit
		End Select
	Wend

	EnableGadget(win)
	FreeGadget(win1)

EndFunction