Creating a sub window

BlitzMax Modules Forums/Brucey's Modules/Creating a sub window

As the title says, I want to create a sub window under the main window, to add a 'pos' after you push a button in the tool bar it'll pop up..

heres my code so far... after i push the button nothing happens though... any ideas?


heres the chunk of code in question...
'The window
Type myFrame Extends wxFrame

	'constants
	Const menu_Exit:Int = 201
	Const tb_Add:Int = 202
	Const tb_Remove:Int = 203
	Const win_posadd:Int = 204
	
	'on start up...
	Method OnInit()
		
		
		'MENU BAR
		Local mb:wxMenuBar = New wxMenuBar.Create()
		
		Local fileMenu:wxMenu = New wxMenu.Create()
		fileMenu.Append(menu_Exit, "Exit")
		
		mb.Append(fileMenu,"File")
		SetMenuBar(mb)
		
		'STATUS BAR
		CreateStatusBar()
		SetStatusText("Welcome to POS Tracker!")
		
		'toolbar
		Local tb1:wxToolBar = New wxToolBar.Create(Self, wxID_ANY, ,, ,, wxTB_FLAT | wxTB_NODIVIDER | wxTB_HORZ_TEXT)
		tb1.SetToolBitmapSize(20, 20)
		tb1.AddTool(tb_Remove, "Remove POS", wxArtProvider.GetBitmap(wxART_ERROR,,20,20))
		tb1.AddTool(tb_Add, "Add POS", wxArtProvider.GetBitmap(wxART_ADD_BOOKMARK,,20,20))
		tb1.Realize()
		
		
		'EVENT HANDLING
		Connect(menu_Exit, wxEVT_COMMAND_MENU_SELECTED, OnExit)
		Connect(tb_Add, wxEVT_COMMAND_BUTTON_CLICKED, CreateAddPOSWindow)
		
	End Method
	
	'a function to handle exiting...
	Function OnExit(event:wxEvent)
		wxFrame(event.parent).Close(True)
	End Function
	
	'Create a Add POS window...
	Function CreateAddPOSWindow(event:wxEvent)
	
		Local Addpos:wxWindow = New wxWindow.CreateWin(wxFrame(event.parent),win_posadd,,,300,200,wxDEFAULT_NO_RESIZE)
		
	End Function

End Type


A wxDialog might be a better choice? You might have to also pass wxSTAY_ON_TOP in the dialog styles.

Arent dialog boxes those little notifiers that give you Yes, No, or Cancel, Retry ect?



I'm looking for like a sub window. There is mini window things, i saw the example, looks like what i might need.

But wouldnt I at least get an error with the above code? I think i'm connecting the clicking event wrong? But I cant find a list of event commands, Button clicked seems the closest i can find for the tool bar..

Any ideas?

I'm not clear as to what your intention is.

What do you mean by "pop up"?

Do you want the parent window to lose focus and stop responding to input while the child is in play?

"Do you want the parent window to lose focus and stop responding to input while the child is in play?"

Yes, like a little control window, try this: open any options panel on your internet browser; notice how a sub window comes up with all the additional options ect.. (If your using IE go tools -> internet options)

I want a "Sub window" (just what i call them) to pop up after you hit the 'add POS' button, that sub window will have some fields and options on it, then a 'OK' button.

After you hit OK that window will close and the info you provided will be applied somewhere on the main window.


make sense?

Sounds like a modal wxDialog to me :-)

Perhaps connect to wxEVT_COMMAND_TOOL_CLICKED?

that'll do it, thanks, now just to implement the dialog box... :)

Hmm this is creating an error...

	Function CreateAddPOSWindow(event:wxEvent)
	
		Local Addpos:wxDialog = New wxDialog.Create_(Self, , "Add POS", , , 500, 300)
		
	End Function


Saying the my WxFrame is not a WxWindow... Any ideas?

My guess it's the "Self". You need to pass a correct parent handle. If you posted code I could run it'd be easier ;-)

complete code:

SuperStrict

'import needed modules
Framework wx.wxApp
Import wx.wxFrame
Import wx.wxComboBox
Import wx.wxAui
Import wx.wxTextCtrl
Import wx.wxTreeCtrl
Import wx.wxSpinCtrl
Import wx.wxButton
Import wx.wxBitmapButton
Import wx.wxStaticText
Import wx.wxArtProvider
Import wx.wxColourDialog
Import wx.wxHtmlWindow

'consts
Const wxDEFAULT_NO_RESIZE:Int = wxSYSTEM_MENU | wxMINIMIZE_BOX | ..
wxMAXIMIZE_BOX | wxCLOSE_BOX | wxCAPTION | wxCLIP_CHILDREN | wxBORDER_STATIC


'App stuff
Type MyApp Extends wxApp

	Field frame:myFrame
	Field box1:wxComboBox

	Method OnInit:Int()
		
		'create window and show it
		frame = myFrame(New myFrame.Create(,,"POS Tracker", 200, 200, 800, 600, wxDEFAULT_NO_RESIZE))
		frame.show()
		
	
		'return successful
		Return True
	
	End Method

End Type

'The window
Type myFrame Extends wxFrame

	'constants
	Const menu_Exit:Int = 201
	Const tb_Add:Int = 202
	Const tb_Remove:Int = 203
	Const win_posadd:Int = 204
	
	'on start up...
	Method OnInit()
		
		
		'MENU BAR
		Local mb:wxMenuBar = New wxMenuBar.Create()
		
		Local fileMenu:wxMenu = New wxMenu.Create()
		fileMenu.Append(menu_Exit, "Exit")
		
		mb.Append(fileMenu,"File")
		SetMenuBar(mb)
		
		'STATUS BAR
		CreateStatusBar()
		SetStatusText("Welcome to the POS Tracker!")
		
		'toolbar
		Local tb1:wxToolBar = New wxToolBar.Create(Self, wxID_ANY, ,, ,, wxTB_FLAT | wxTB_NODIVIDER | wxTB_HORZ_TEXT)
		tb1.SetToolBitmapSize(20, 20)
		tb1.AddTool(tb_Remove, "Remove POS", wxArtProvider.GetBitmap(wxART_ERROR,,20,20))
		tb1.AddTool(tb_Add, "Add POS", wxArtProvider.GetBitmap(wxART_ADD_BOOKMARK,,20,20))
		tb1.Realize()
		
		
		'EVENT HANDLING
		Connect(menu_Exit, wxEVT_COMMAND_MENU_SELECTED, OnExit)
		Connect(tb_Add, wxEVT_COMMAND_TOOL_CLICKED, CreateAddPOSWindow)
		
	End Method
	
	'a function to handle exiting...
	Function OnExit(event:wxEvent)
		wxFrame(event.parent).Close(True)
	End Function
	
	'Create a Add POS window...
	Function CreateAddPOSWindow(event:wxEvent)
	
		Local Addpos:wxDialog = New wxDialog.Create_(, , "Add POS", , , 500, 300)
		
	End Function

End Type



'run the program
New MyApp.run()


Giving me a compilation error, and I know why: It wants wxwindow not wxframe, but i don't know how to fix that.

Local Addpos:wxDialog = New wxDialog.Create_(Null,wxID_ANY , "Add POS",200,200 , 500, 300, wxSTAY_ON_TOP|  wxDEFAULT_DIALOG_STYLE)
		
Addpos.ShowModal()


?

I don't know what you did, but it works now, thanks.

That was a bit of a cheat. You could have created the dialog within myFrame's OnInit() - passing Self as the parent window and then just called ShowModal() on the button click.

[edit] Sorry, long overdue for lunch :-)
		Local  Addpos:wxDialog  = New wxDialog.Create_(myFrame(event.parent),wxID_ANY , "Add POS",200,200 , 500, 300, wxDEFAULT_DIALOG_STYLE)
		Addpos.ShowModal()

Is the more standard alternative

How would i create it in the Oninit() then ShowModal it on the CreateAddPOSWindow function? because i tried it and it doesnt work.

I'd like to be able to do this so i can just end it from a different function, called by a button click on the window..

code:

SuperStrict

'import needed modules
Framework wx.wxApp
Import wx.wxFrame
Import wx.wxComboBox
Import wx.wxAui
Import wx.wxTextCtrl
Import wx.wxTreeCtrl
Import wx.wxSpinCtrl
Import wx.wxButton
Import wx.wxBitmapButton
Import wx.wxStaticText
Import wx.wxArtProvider
Import wx.wxColourDialog

'consts
Const wxDEFAULT_NO_RESIZE:Int = wxSYSTEM_MENU | wxMINIMIZE_BOX | ..
wxMAXIMIZE_BOX | wxCLOSE_BOX | wxCAPTION | wxCLIP_CHILDREN | wxBORDER_STATIC


'global vars




'App stuff
Type MyApp Extends wxApp

	Field frame:myFrame
	Field box1:wxComboBox

	Method OnInit:Int()
		
		'create window and show it
		frame = myFrame(New myFrame.Create(,,"POS Tracker", 200, 200, 800, 600, wxDEFAULT_NO_RESIZE))
		frame.show()
		
	
		'return successful
		Return True
	
	End Method

End Type

'The window
Type myFrame Extends wxFrame

	'fields
	
	
	'constants
	Const menu_Exit:Int = 201
	Const tb_Add:Int = 202
	Const tb_Remove:Int = 203
	Const win_posadd:Int = 204
	Const but_ok1:Int = 205
	
	'on start up...
	Method OnInit()
		
		
		'MENU BAR
		Local mb:wxMenuBar = New wxMenuBar.Create()
		
		Local fileMenu:wxMenu = New wxMenu.Create()
		fileMenu.Append(menu_Exit, "Exit")
		
		mb.Append(fileMenu,"File")
		SetMenuBar(mb)
		
		'STATUS BAR
		CreateStatusBar()
		SetStatusText("Welcome to the POS Tracker!")
		
		'toolbar
		Local tb1:wxToolBar = New wxToolBar.Create(Self, wxID_ANY, ,, ,, wxTB_FLAT | wxTB_NODIVIDER | wxTB_HORZ_TEXT)
		tb1.SetToolBitmapSize(20, 20)
		tb1.AddTool(tb_Remove, "Remove POS", wxArtProvider.GetBitmap(wxART_ERROR,,20,20))
		tb1.AddTool(tb_Add, "Add POS", wxArtProvider.GetBitmap(wxART_ADD_BOOKMARK,,20,20))
		tb1.Realize()
		
		'Create the Add POS sub window
		Local Addpos:wxDialog = New wxDialog.Create_(Self,wxID_ANY , "Add POS",-1 ,-1 , 500, 300, wxSTAY_ON_TOP|  wxDEFAULT_DIALOG_STYLE)
		Local ok:wxButton = New wxButton.Create(Addpos,but_ok1,"Ok")	
		
		'EVENT HANDLING
		Connect(menu_Exit, wxEVT_COMMAND_MENU_SELECTED, OnExit)
		Connect(tb_Add, wxEVT_COMMAND_TOOL_CLICKED, AddPOSWindow)
		Connect(but_ok1, wxEVT_COMMAND_BUTTON_CLICKED, AddPOS)
		
	End Method
	
	'a function to handle exiting...
	Function OnExit(event:wxEvent)
	
		wxFrame(event.parent).Close(True)
		
	End Function
	
	'show ADD POS window
	Function AddPOSWindow(event:wxEvent)
	
		Addpos.ShowModal()
		
	End Function
	
	'Adds a POS / ends the the dialog
	Function AddPOS(event:wxEvent)
	
		Addpos.EndModal()
	
	End Function
	

End Type



'run the program
New MyApp.run()


Thanks for all the help so far.


SuperStrict

'import needed modules
Framework wx.wxApp
Import wx.wxFrame
Import wx.wxComboBox
Import wx.wxAui
Import wx.wxTextCtrl
Import wx.wxTreeCtrl
Import wx.wxSpinCtrl
Import wx.wxButton
Import wx.wxBitmapButton
Import wx.wxStaticText
Import wx.wxArtProvider
Import wx.wxColourDialog

'consts
Const wxDEFAULT_NO_RESIZE:Int = wxSYSTEM_MENU | wxMINIMIZE_BOX | ..
wxMAXIMIZE_BOX | wxCLOSE_BOX | wxCAPTION | wxCLIP_CHILDREN | wxBORDER_STATIC


'global vars




'App stuff
Type MyApp Extends wxApp

	Field frame:myFrame
	Field box1:wxComboBox

	Method OnInit:Int()
		
		'create window and show it
		frame = myFrame(New myFrame.Create(,,"POS Tracker", 200, 200, 800, 600, wxDEFAULT_NO_RESIZE))
		frame.show()
		
	
		'return successful
		Return True
	
	End Method

End Type

'The window
Type myFrame Extends wxFrame

	'fields
	
	
	'constants
	Const menu_Exit:Int = 201
	Const tb_Add:Int = 202
	Const tb_Remove:Int = 203
	Const win_posadd:Int = 204
	Const but_ok1:Int = 205

	Field Addpos:wxDialog
	
	'on start up...
	Method OnInit()
		
		
		'MENU BAR
		Local mb:wxMenuBar = New wxMenuBar.Create()
		
		Local fileMenu:wxMenu = New wxMenu.Create()
		fileMenu.Append(menu_Exit, "Exit")
		
		mb.Append(fileMenu,"File")
		SetMenuBar(mb)
		
		'STATUS BAR
		CreateStatusBar()
		SetStatusText("Welcome to the POS Tracker!")
	
		'Create the Add POS sub window
		Addpos = New wxDialog.Create_(Self,wxID_ANY , "Add POS",200 ,200 , 500, 300, wxSTAY_ON_TOP|  wxDEFAULT_DIALOG_STYLE)
	
		'toolbar
		Local tb1:wxToolBar = New wxToolBar.Create(Self, wxID_ANY, ,, ,, wxTB_FLAT | wxTB_NODIVIDER | wxTB_HORZ_TEXT)
		tb1.SetToolBitmapSize(20, 20)
		tb1.AddTool(tb_Remove, "Remove POS", wxArtProvider.GetBitmap(wxART_ERROR,,20,20))
		tb1.AddTool(tb_Add, "Add POS", wxArtProvider.GetBitmap(wxART_ADD_BOOKMARK,,20,20))
		tb1.Realize()
		
		Local ok:wxButton = New wxButton.Create(Addpos,wxID_OK,"Ok")	
		
		'EVENT HANDLING
		Connect(menu_Exit, wxEVT_COMMAND_MENU_SELECTED, OnExit)
		Connect(tb_Add, wxEVT_COMMAND_TOOL_CLICKED, AddPOSWindow)
	'	Connect(but_ok1, wxEVT_COMMAND_BUTTON_CLICKED, AddPOS)
		
	End Method
	
	'a function to handle exiting...
	Function OnExit(event:wxEvent)
	
		wxFrame(event.parent).Close(True)
		
	End Function
	
	'show ADD POS window
	Function AddPOSWindow(event:wxEvent)
	
		MyFrame(event.parent).Addpos.ShowModal()
		
	End Function
	
	'Adds a POS / ends the the dialog
	'Function AddPOSOK(event:wxEvent)
	
		'MyFrame(event.parent).Addpos.EndModal()
	
	'End Function
	

End Type



'run the program
New MyApp.run()


If you create a default wxOK button, EndModal() is called implicitly.

Hey... toolbars and dialogs in your first attempt ;-)

After creating the "Addpos" dialog, you might find this is useful too:
		Addpos.Center(wxBOTH)

It centers the dialog nicely.

Remember too, that if your dialog is going to be reasonably complicated, you could Extend from wxDialog with your own Type, and add control creation into its own OnInit() method. Otherwise you end up with lots of control creation in one place - I'm for keeping things grouped together :-p

Thanks for the help,

couple more questions:

1)I'm confused, about connections. For ID's I can take any number and my my own ID correct? Then why are there wxID's ? if you have more then one button with a WX id won't it get them mixed up?

Also, if i replace wxID_ok with something else, it won't close the dialog... odd.

2)do you know if WxWidgets takes XP style manifests? so I can make the application look windows XP ish?

3) Does this have group boxes? for an example, fire up IE, and go to tools -> internet options -> security and look at the little box with the label "Security level for this zone", thats what I'm looking for.

1)Yes you can use your own ID, however if your also using wxID's best make sure none of your ID's are the same as any wxID's that your using.
EDIT: make sure you change the id on both the create function for the object and the connect function.

2)You should just be able to put it in the .exe with Resource Hacker (wxWidgets might have it built in, not sure.)

3)not sure

1) If you are worried about number clashes, start yours from wxID_HIGHEST.
wxID_xxxx's are special-case id's that when used trigger certain functionality. It might be to tell Mac to put a menu in a platform-specific place, or to make a button work in a certain way.

2) According to http://www.wxwidgets.org/docs/faqmsw.htm#winxp yes.
But I dunno much about Windows and manifests and such like so you might have to experiment a bit with it.

3) there's a wxStaticBox and wxStaticBoxSizer. The sizer is probably the best to work with, as it takes care of a lot of the niggly stuff. For example, wxStaticBox isn't meant to be used as a parent/container.

@Also, if i replace wxID_ok with something else, it won't close the dialog... odd.

In that case, you can use SetAffirmativeId() for OK and SetEscapeId() for CANCEL on your custom buttons.

Edit: Ignore me i'm an idiot.. :D forgot to import the mods..

Alright, now i'm trying to add tabbers, based on the basic_notebook example.

Now i'm not 100% of this but i think a notebook is a tabber? (for an example on what i call a tabber see your Bmax IDE and see the top "Help" tabber + whatever files you have open)

anyways, here's my code, i see no tabber at the moment.. trying to figure this out.


see " 'body " under the MainWindow type, thats where i'm trying..


SuperStrict

'import needed modules
Framework wx.wxApp
Import wx.wxFrame
Import wx.wxComboBox
Import wx.wxAui
Import wx.wxTextCtrl
Import wx.wxTreeCtrl
Import wx.wxSpinCtrl
Import wx.wxButton
Import wx.wxBitmapButton
Import wx.wxStaticText
Import wx.wxArtProvider
Import wx.wxColourDialog
Import wx.wxPanel
Import wx.wxNotebook
Import wx.wxListBox

'consts
Const wxDEFAULT_NO_RESIZE:Int = wxSYSTEM_MENU | wxMINIMIZE_BOX | ..
wxMAXIMIZE_BOX | wxCLOSE_BOX | wxCAPTION | wxCLIP_CHILDREN | wxBORDER_STATIC


'global vars




'App stuff
Type MyApp Extends wxApp

	Field frame:MainWindow
	Field box1:wxComboBox

	Method OnInit:Int()
		
		'create window and show it
		frame = MainWindow(New MainWindow.Create(Null, -1, "POS Tracker", 200, 200, 800, 600, wxDEFAULT_NO_RESIZE))
		frame.show()
		
	
		'return successful
		Return True
	
	End Method

End Type

'The window
Type MainWindow Extends wxFrame

	'fields
	
	
	'constants
	
	
	'Custom ID constants
	Const menu_Exit:Int = 201
	Const tb_Add:Int = 202
	Const tb_Remove:Int = 203
	Const win_posadd:Int = 204
	Const but_ok1:Int = 205
	Const tabber:Int = 206
	

	'fields
	Field Addpos:wxDialog
	Field notebook:wxNotebook
	
	'on start up...
	Method OnInit()
		
		
		'MENU BAR
		Local mb:wxMenuBar = New wxMenuBar.Create()
		
		Local fileMenu:wxMenu = New wxMenu.Create()
		fileMenu.Append(menu_Exit, "Exit")
		
		mb.Append(fileMenu,"File")
		SetMenuBar(mb)
		
		'STATUS BAR
		CreateStatusBar()
		SetStatusText("Welcome to the POS Tracker!")
	

		'toolbar
		Local tb1:wxToolBar = New wxToolBar.Create(Self, wxID_ANY, ,, ,, wxTB_FLAT | wxTB_NODIVIDER | wxTB_HORZ_TEXT)
		tb1.SetToolBitmapSize(20, 20)
		tb1.AddTool(tb_Remove, "Remove POS", wxArtProvider.GetBitmap(wxART_ERROR,,20,20))
		tb1.AddTool(tb_Add, "Add POS", wxArtProvider.GetBitmap(wxART_ADD_BOOKMARK,,20,20))
		tb1.Realize()
		
		
		

		'Body
		
		notebook = wxNotebook.CreateNotebook(Self, tabber)
		
		Local panel:wxPanel = wxPanel.CreatePanel(notebook)
		notebook.AddPage(panel, "Tab1", True)

		panel = wxPanel.CreatePanel(notebook)
		notebook.AddPage(panel, "Tab2", False)
		
		panel = wxPanel.CreatePanel(notebook)	
		notebook.AddPage(panel, "Tab3", False)
		
		
		
		'Create Add POS sub window, but don't show it yet
		Addpos = New wxDialog.Create_(Self,wxID_ANY , "Add POS",200 ,200 , 300, 500, wxSTAY_ON_TOP|  wxDEFAULT_DIALOG_STYLE)
		MainWindow(Self).Addpos.Center(wxBOTH)
		Local ok:wxButton = New wxButton.Create(Addpos,wxID_Ok,"Ok",105,410)
		
		
		'EVENT HANDLING
		Connect(menu_Exit, wxEVT_COMMAND_MENU_SELECTED, OnExit)
		Connect(tb_Add, wxEVT_COMMAND_TOOL_CLICKED, AddPOSWindow)
		Connect(wxID_Ok, wxEVT_COMMAND_BUTTON_CLICKED, AddPOSdone)
		
	End Method
	
	'a function to handle exiting...
	Function OnExit(event:wxEvent)
	
		wxFrame(event.parent).Close(True)
		
	End Function
	
	'show ADD POS window
	Function AddPOSWindow(event:wxEvent)
	
		MainWindow(event.parent).Addpos.ShowModal()
		
	End Function
	
	'Adds a POS / ends the the dialog
	Function AddPOSdone(event:wxEvent)
	
	
	End Function
	

End Type



'run the program
New MyApp.run()


Thanks in advance

You've got no positioning code for the notebook in there. I can see it in osx - it's in the top left corner. Yes notebook is a tabber. You may want to put a large base panel on your window as your very first object. wxWidgets manuals often recommend this as a way of avoiding object positioning issues.

but what do i change position on? the notebook or the panel? also the basic_notebook example doesnt include position code. and it looks fine

Method Create:wxNotebook(parent:wxWindow, id:Int, x:Int = -1, y:Int = -1, w:Int = -1, h:Int = -1, style:Int = 0)

Try filling in x,y,w,h

The sample is probably using sizers.

Thanks