tabber and text area blues

BlitzMax Forums/BlitzMax GUI Programming/tabber and text area blues

Right, I've been buggering away with this for a few days now, and its got me as sick as a parrot

Basically, I want a setup like MaxIDE when it comes to tabbers and text areas... And a little browser tab (Kind of like the Blitz 'Help' tab)

Problem is, that when I open more tabs and text areas, it gets a bit hairy, they dont open in the right order (tabs dont match text area) and when I go to close one, its goes to pot!

Heres the code:-

Framework MaxGUI.MaxGUI
Import BRL.EventQueue
Import BRL.Retro
Import MaxGui.Drivers

SuperStrict 




Local documentCount:Int = 0
Const DOC_BROWSER:Byte = 0
Const DOC_TEXT:Byte = 1
Local currentdocument:Int  
Local documentList:TList = New TList

Local GUIFont:TGuiFont=LoadGuiFont( "Consolas",10)

Type TDocument
	Field documentID:Int 
	Field document:TGadget
	Field documentName:String
	Field documentPath:String
	Field documentDeletable:Byte
	Field documentType:Int 
End Type 



Local window:TGadget = CreateWindow("SPad",30,20,400,300,Desktop(),WINDOW_TITLEBAR | WINDOW_MENU | WINDOW_STATUS)
MaximizeWindow(window)
Local tabber:TGadget = CreateTabber(0,0,ClientWidth(window),ClientHeight(window),window)
SetGadgetLayout tabber,1,1,1,1 

'Add Browser to Document List
AddGadgetItem tabber,"Browser",False,-1,"Browser View"

Local browser:TDocument = New TDocument
browser.documentID = 0
browser.document = CreatePanel(0,0,ClientWidth(tabber),ClientHeight(tabber),tabber)
browser.documentType = DOC_BROWSER
browser.documentDeletable = False 
Local BrowserGo:TGadget = CreateButton("Go",10,10,40,20,browser.document)
Local BrowserURLText:TGadget = CreateTextField(60,10,300,20,browser.document)
Local browserArea:TGadget = CreateHTMLView(10,40,GadgetWidth(window)-40,GadgetHeight(window)-120,browser.document)
documentList.AddLast(browser)
currentDocument = 0
documentCount = 1

'Menu
Local filemenu:TGadget
Local editmenu:TGadget
Local helpmenu:TGadget

Const MENU_NEW:Int=101
Const MENU_OPEN:Int=102
Const MENU_SAVE:Int=103
Const MENU_CLOSE:Int=104
Const MENU_EXIT:Int=105

Const MENU_CUT:Int=201
Const MENU_COPY:Int=202
Const MENU_PASTE:Int=203

Const MENU_ABOUT:Int=901

filemenu=CreateMenu("&File",0,WindowMenu(window))
CreateMenu"&New",MENU_NEW,filemenu,KEY_N,MODIFIER_COMMAND
CreateMenu"&Open",MENU_OPEN,filemenu,KEY_O,MODIFIER_COMMAND
CreateMenu"&Close",MENU_CLOSE,filemenu,KEY_W,MODIFIER_COMMAND
CreateMenu"",0,filemenu
Local saveMenu:Tgadget = CreateMenu("&Save",MENU_SAVE,filemenu,KEY_S,MODIFIER_COMMAND)
DisableMenu saveMenu
CreateMenu"",0,filemenu
CreateMenu"E&xit",MENU_EXIT,filemenu,KEY_F4,MODIFIER_COMMAND

editmenu=CreateMenu("&Edit",0,WindowMenu(window))
CreateMenu "Cu&t",MENU_CUT,editmenu,KEY_X,MODIFIER_COMMAND
CreateMenu "&Copy",MENU_COPY,editmenu,KEY_C,MODIFIER_COMMAND
CreateMenu "&Paste",MENU_PASTE,editmenu,KEY_V,MODIFIER_COMMAND

helpmenu=CreateMenu("&Help",0,WindowMenu(window))
CreateMenu "&About Sanitry Pad",MENU_ABOUT,helpmenu

UpdateWindowMenu window

While True 
	PollEvent()
	
	Select EventID()
		Case EVENT_GADGETACTION
			Local docEventID:TDocument
			For docEventID = EachIn DocumentList
				If docEventID.documentID = currentdocument
					Exit 
				End If
			Next
			Select(EventSource())
				Case tabber
					
					For Local currentDoc:TDocument = EachIn DocumentList
						If currentDoc.documentID = currentdocument
							HideGadget currentDoc.document
							Exit 
						End If
					Next

					If EventData() = 0
							Local currentDoc:TDocument = TDocument(documentList.first())
							ShowGadget currentDoc.document
							HtmlViewGo browserArea,"http://www.syntaxbomb.com"
							SetGadgetText(BrowserURLText,HtmlViewCurrentURL(browserArea))
							currentdocument = 0
					
					Else
						currentdocument=EventData()
						Print currentdocument 
						For Local currentDoc:TDocument = EachIn DocumentList
							If currentDoc.documentID = currentdocument
								ShowGadget currentDoc.document
							End If
						Next
					End If 

				Case BrowserGo
					HtmlViewGo browserArea,TextFieldText$(BrowserURLText)
					SetGadgetText(BrowserURLText,HtmlViewCurrentURL(browserArea))
				Case docEventID.document
					If currentDocument <> 0
						'FormatLine(docEventID.document)
					End If 
			End Select 
		
		Case EVENT_WINDOWCLOSE
			End

		Case EVENT_MENUACTION
			Select EventData()
				Case MENU_CLOSE
					Local docLoop:TDocument
					For docLoop= EachIn DocumentList
						If docLoop.documentID = currentdocument
							Exit 
						End If
					Next
					
					If docLoop.documentDeletable = True
						HideGadget docLoop.document
						FreeGadget docLoop.document
						documentList.Remove(TDocument(documentList.ValueAtIndex(currentDocument)))
						RemoveGadgetItem(tabber,currentDocument)
						documentCount = documentCount - 1
						
						Local docLoop:TDocument
						Local counter:Int = 0
						For docLoop = EachIn DocumentList
							docLoop.documentID = counter
							counter = counter + 1
						Next
						
						Local currentDoc:TDocument = TDocument(documentList.first())
						ShowGadget currentDoc.document
						
					End If
					
				Case MENU_NEW
					Local result:String = RequestFile("Save new file as...","All files:*",True)
					If result <> "" 
						documentCount = documentCount + 1
						AddGadgetItem(tabber,StripDir$(result),False,-1,result)
						
						Local newDocument:TDocument = New TDocument
						newDocument.documentID = documentCount 
						newDocument.document = CreateTextArea(10,10,GadgetWidth(window)-40,GadgetHeight(window)-120,tabber)
						newDocument.documentType = DOC_TEXT
						newDocument.documentName = StripDir$(result)
						newDocument.documentPath = result 
						newDocument.documentDeletable = True 
						newDocument.documentType = DOC_TEXT
						
						SetTextAreaFont(newDocument.document,GUIFont)
						SetTextAreaColor(newDocument.document,1,81,107,True)
						SetTextAreaColor(newDocument.document,255,255,255,False) 
						
						documentList.AddLast(newDocument)
				
						'Local fileout:TStream = WriteFile(result)
						'CloseFile fileout 
						 
						EnableMenu saveMenu
						UpdateWindowMenu window 
					End If
				Case MENU_OPEN
					Local result:String = RequestFile("Open file...","All files:*",False)
					If result <> "" 
						documentCount = documentCount + 1
						AddGadgetItem(tabber,StripDir$(result),False,-1,result)
						
						Local newDocument:TDocument = New TDocument
						newDocument.documentID = documentCount 
						newDocument.document = CreateTextArea(10,10,GadgetWidth(window)-40,GadgetHeight(window)-120,tabber)
						newDocument.documentType = DOC_TEXT
						newDocument.documentName = StripDir$(result)
						newDocument.documentPath = result 
						newDocument.documentDeletable = True 
						newDocument.documentType = DOC_TEXT
						
						SetTextAreaText(newDocument.document,LoadText$(result))

						SetTextAreaFont(newDocument.document,GUIFont)
						SetTextAreaColor(newDocument.document,1,81,107,True)
						SetTextAreaColor(newDocument.document,255,255,255,False) 
						
						'FormatDocument(newDocument.document)
						
						documentList.AddLast(newDocument)

						EnableMenu saveMenu
						UpdateWindowMenu window
					End If 
				Case MENU_EXIT
					End
				Case MENU_ABOUT
					Notify "Sanitry Pad"
			End Select
	End Select

Wend 


Its beyond a joke now, so can anyone see what the hell I'm missing?

Tar

Dabz

Can you post some code that we can compile?

I get the following error when I try the above:

Building untitled1
Compiling:untitled1.bmx
Compile Error: Identifier 'FormatLine' not found


MaxGUI tabbers are exciting because you have to manage them yourself (what's all that about?)

Therefore you might want to implement your own tabber set/unset code to track what gadgets you are hiding and displaying.

Anyhoo, how's about adding this for now in your MENU_OPEN select block :
EnableGadgetItem tabber, CountGadgetItems(tabber)-1

which changes the tabber item to the last one (which is the one you just added the document to.

You will also want to hide the gadget that was previously selected too, of course.


Good luck with MaxGUI :-)

Sorry, me bad! :)

Just delete FormatLine and FormatDocument, these have no bearing on the way the GUI runs Seb me auld fruit! ;)

Dabz

P.S. Will remove them lines now from above!

Can you post some code that we can compile?

Compiles and runs fine if you comment out those errors, btw.
<edit> like what dabz said above ;-)

Cheers Brucey... I'll take a peek...

I ruddy hate GUI programming me! :D

Dabz

IMHO, you shouldn't be having to manage a tabber like that anyway. It should all be abstracted away so that all you need to do is set a page, and the child for that page is shown.

Different philosophies, I suppose... and each to their own :-)

Yeah, its a bit of a pain... I'll get over it... but GUI always grinds me down... After hard-coding the sodding thing, managing it becomes a chore the bigger it is.

Still, onwards and upwards Brucey mate! :D hehehe

Dabz

but GUI always grinds me down

Yeah, but it shouldn't. In reality it is just a means to an end.

Like in VB.. you never really notice the GUI coding - as you are able to concentrate on the main application logic itself. Which is how things should be, I think.

You'll get there in the end, though ;-)

I ended up doing this in C#, using MDI instead... Took 30mins, works a charm! ;)

I should of just used that in the first place really, now to convert the guts of my app from Max to C#! :rolleyes:

Thanks for your help anyway Brucey me auld fruit! ;)

Dabz

IMHO, you shouldn't be having to manage a tabber like that anyway. It should all be abstracted away so that all you need to do is set a page, and the child for that page is shown.

I completely agree, but I assume Mark/Skid wanted tabbers to be able to use the same commands as the other list based controls. Also, as the Windows API expects you to do it yourself, and BlitzPlus was originally just for Windows, they probably felt that's how they should leave it.

When MaxGUI came out, and it went cross-platform, all behaviour on other platforms was hacked to behave like BlitzPlus Windows applications.

Still, we can't change it or it would break people's code, wouldn't it Brucey? ;-)

Like in VB.. you never really notice the GUI coding - as you are able to concentrate on the main application logic itself.

How many times?!?!?! "BlitzMax is a games programming language." Hee-hee! The work you are doing with wxWidgets is disproving this, and I'm doing the best I can over here with MaxGUI, but you're right, BlitzMax + MaxGUI isn't quite up to VB 2005 standard yet. :P