Opening a wxFileDialog from within a wxDialog

BlitzMax Modules Forums/Brucey's Modules/Opening a wxFileDialog from within a wxDialog

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

Righty...

You'll need to update to the latest wxMax for this stuff...

SuperStrict

Framework wx.wxApp
Import wx.wxFrame
Import wx.wxDialog
Import wx.wxButton
Import wx.wxFileDialog

New MyApp.run()

Type MyApp Extends wxApp

	Field Window:TTestWindow
	
	Method OnInit:Int()
					
		Window = New TTestWindow
		Window.Create(, , "Window", -1, -1, 550, 550)
		Window.Center()
		Window.Show()
		Window.Refresh(True)
				
		Return True
		
	End Method

End Type

Type TTestWindow Extends wxFrame
	
	Field Dialog:TTestDialog
		
	Method OnInit()
		
		'	Open up a file requester 
		Local file_dialog:wxFileDialog = New wxFileDialog.Create(Self, "File dialog 1: Parent is the wxFrame",Null,Null, "*.*", wxFD_OPEN|wxFD_DEFAULT_STYLE)
	
		If file_dialog.ShowModal() <>  wxID_OK Then DebugLog "User selected cancel from the file dialog"
		
		Dialog = TTestDialog(New TTestDialog.Create_(Self, wxID_ANY,"1st dialog"))',,,,, wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP))
		Dialog.ShowModal()
							
	End Method

End Type

Type TTestDialog Extends wxDialog

	Field Button:TTestButton
	Field Dialog2:TTestDialog2
	
	Method OnInit()
		Button = TTestButton(New TTestButton.Create(Self, wxID_OK, "OK"))
		Button.ConnectAny(wxEVT_COMMAND_BUTTON_CLICKED, _OnClick, Null, Self)
	End Method

	Method OnClick(_event:wxCommandEvent)
	
		DebugLog "Dialog 1 Clicked! - attempting to open a dialog"
		
		'	Open up a file requester 
		Local file_dialog:wxFileDialog = New wxFileDialog.Create(Self, "File dialog 2: Parent is Dialog 1",Null,Null, "*.*", wxFD_OPEN|wxFD_DEFAULT_STYLE)
		
		If file_dialog.ShowModal() <>  wxID_OK Then DebugLog "User selected cancel from the file dialog"
		
		Dialog2 =TTestDialog2( New TTestDialog2.Create_(Self, wxID_ANY,"2nd dialog"))',,,,, wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP) )
		Dialog2.ShowModal()
		
	End Method		
	
	Function _OnClick(_event:wxEvent)
	
		'	parent is the Object of the click, sink is the Object that handles the event.
	
		TTestDialog(_event.sink).OnClick(wxCommandEvent(_event))
	End Function
	
	Method ShowModal()
		HIWindowChangeClass(MacGetWindowRef(), 4);
		Super.ShowModal()
	End Method
	
End Type

Extern
	Function HIWindowChangeClass:Int(handle:Byte Ptr, style:Int)
End Extern

Type TTestDialog2 Extends wxDialog

	Field Button:TTestButton
		
	Method OnInit()
		Button = TTestButton(New TTestButton.Create(Self, wxID_OK, "2nd OK"))
		Button.ConnectAny(wxEVT_COMMAND_BUTTON_CLICKED, _OnClick, Null, Self)
	End Method

	Method OnClick(_event:wxCommandEvent)
	
		DebugLog "Clicked! Dialog 2 - attempting to open a file dialog"
	
		'	Open up a file requester 
		Local file_dialog:wxFileDialog = New wxFileDialog.Create(Self, "File dialog 3: Choose a file",Null,Null, "*.*", wxFD_OPEN|wxFD_DEFAULT_STYLE)
	
		If file_dialog.ShowModal() <>  wxID_OK Then DebugLog "User selected cancel from the file dialog"
		
	
	End Method		
	
	Function _OnClick(_event:wxEvent)
		'	parent is the Object of the click, sink is the Object that handles the event.
		TTestDialog2(_event.sink).OnClick(wxCommandEvent(_event))
	End Function

	Method ShowModal()
		HIWindowChangeClass(MacGetWindowRef(), 4);
		Super.ShowModal()
	End Method

End Type


Type TTestButton Extends wxButton
End Type


This is your original code as posted at the top with some additions, based on the thread I linked to previously.
Notably, the dialogs now override ShowModal :
	Method ShowModal()
		HIWindowChangeClass(MacGetWindowRef(), 4);
		Super.ShowModal()
	End Method

"4" is kMovableModalWindowClass.

And for HIWindowChange you need to add :
Extern
	Function HIWindowChangeClass:Int(handle:Byte Ptr, style:Int)
End Extern


Now the windows appear to handle modality in a more expected way.
However, the close/min/max buttons are now disabled. But then, a Modal dialog tends to work a bit differently to a normal document window, so this may not be a problem. (there may well be a way to re-enable those in flags).

See how you get on with that...

:o)