flatnotebook

BlitzMax Modules Forums/Brucey's Modules/flatnotebook

I'm trying to get the text of a page as it's being closed, however using this:
	Function OnPageClosing(event:wxEvent) 
	  Local fnb:wxFlatNotebook = mainFrame.book
		  Notify fnb.GetPageText(fnb.GetPageIndex(fnb.GetCurrentPage())) 
		
	End Function

I get a number from the notify command, why?

EDIT: is there a simpler way to get the text of a tab on a flatnotebook?

If you mean Notify as in BRL.System's Notify() then I've found it's best not to mix it with wxMax.

Not sure if that's your problem in this case, but use a wxMessageBox(s_text) instead.

Most certainly not the problem, still getting numbers.

old habits ;)

I'd break up that one line and see if GetCurrentPage() is working. What event are you hooking into? Perhaps the page has already closed?

If I use the same technique when the page is changed it gives a number again, if I switch to another tab, and back again, the number is different then the first time on that tab.

I think it's better to initialise fnb as

fnb:wxFlatNotebook = wxFlatNotebook(event.parent) instead of using that global. Assuming the notebook is the source of the event of course.

GetPageText(GetSelection()) ? [edit] Actually you should be able to cast the event to a wxFlatNoteBookEvent and then event.GetSelection()

Does that make any difference? Not having used wxFlatNotebook, I'm about at the end of my guesses, sorry.

event.parent is a wxEvtHandler, and does not seem to convert to a wxFlatNotebook type. (I get "Unhandled Exception:Attempt to access field or method of Null object" any time i try to access something from fnb, using event.parent to wxFlatNotebook)

OK, so I just tried it below and am getting a number readout too. If you type something in each page and switch back and forth, you will see the second method works:

wxTextCtrl(GetCurrentPage()).GetValue()

SuperStrict

Framework wx.wxApp
Import wx.wxFrame
Import wx.wxFlatNotebook
Import wx.wxTextCtrl

New MyApp.run()

Type MyApp Extends wxApp

	Field Window:wxFrame
	Field NoteBook:TFlatNoteBook
	
	Method OnInit:Int()
	
		Window = New wxFrame.Create( Null,TId.GetNextId(),"FlatNoteBook",0,0,500,500)
		Window.Centre()	
		NoteBook = New TFlatNoteBook.CreateGadget(Window,5,5,490,490)
		Window.Show()				
		Window.Refresh()
					
		Return True
	
	End Method

End Type

Type TFlatNoteBook Extends wxFlatNotebook

	Field Id:Int
	Global s_Page:String[] = ["Page One","Page Two","Page Three"]
		
	Method CreateGadget:TFlatNoteBook(_parent:wxWindow,_x:Int,_y:Int,_w:Int,_h:Int)
	
		Id = TId.GetNextId()
		CreateFNB(_parent,Id,_x,_y,_w,_h)
		Return Self
	
	End Method
	
	Method OnInit()
				
		
		
		For Local s_title:String = EachIn s_Page
			AddPage(New wxTextCtrl.Create(Self,TId.GetNextId(),Null,0,0,490,490),s_title)
		Next
	
		Connect(Id, wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CHANGED, _OnPageChanged)
	
	End Method
	
	Method OnPageChanged(_event:wxFlatNotebookEvent)
		DebugLog GetPageText(_event.GetSelection())
		DebugLog _event.GetSelection() +" page label " +s_Page[_event.GetSelection()]
		DebugLog wxTextCtrl(GetCurrentPage()).GetValue()
	End Method
	
	Function _OnPageChanged(_event:wxEvent)
		TFlatNoteBook(_event.parent).OnPageChanged(wxFlatNotebookEvent(_event))
	End Function

End Type

Type TId 		
	
	Global CurrentId:Int = wxID_HIGHEST

	Function GetCurrentId:Int()
		Return CurrentId
	End Function

	Function GetNextId:Int()
		CurrentId :+ 1
		Return CurrentId
	End Function
		
End Type


Your code doesn't seem to run. From what I can see, your just getting the text from the textctrl, I'm trying to get the title of the tab.

Oh dear, I'm not doing very well am I? :-) I completely misunderstood you.

Strange that the code above doesn't run. Works fine here in Leopard.

I just edited it to show *a* way of getting the labels. Cheating, I know.

[edit] Hmmm works fine in XP Parallels too...

Apologies for not replying sooner.
Please update for a fix.

SuperStrict isn't completely Super Strict, unfortunately...

Thanks Brucey, forgot I had one of the first versions of wxmax.