Interesting MaxGUI Gadget Text Behavior

Archives Forums/MaxGUI Bug Reports/Interesting MaxGUI Gadget Text Behavior

overmeeren(Posted 2010) [#1]
Import MaxGui.Drivers

SuperStrict

Local window:TGadget = CreateWindow( AppTitle, 10, 10, 400, 300, Null, WINDOW_TITLEBAR )

Local label:TGadget = CreateLabel("Label text",10,10,280,52,window)

SetGadgetText(label, "New label text")

SetGadgetText(label, "")

SetGadgetText(label, GadgetText(label))

Repeat
	WaitEvent()
	Print CurrentEvent.ToString()
	Select EventID()
		Case EVENT_APPTERMINATE, EVENT_WINDOWCLOSE
			End
	End Select
Forever


BCC 1.39
Mac OS X 10.6.4
XCode 3.2.2

My expectation would be to see nothing in the label as text, or if there is some strange pointer thing going on, the previous string("New label text"). But strangely enough, it points to the original.

I can guess, but I'm not sure what is going on here with pointers/memory behind the layers of MaxGUI.

Anyone have an idea? (I've searched the forum, but could not find any clues)


jsp(Posted 2010) [#2]
Looks like a mac thing, works as expected on XP.


SebHoll(Posted 2010) [#3]
Mac bug:

Fix for MaxGUI.CocoaMaxGUI's cocoagui.bmx:

	Method SetText(msg$)
		If internalclass=GADGET_HTMLVIEW
			Local	anchor$,a
			a=msg.Find("#")
			If a<>-1 anchor=msg[a..];msg=msg[..a]
			If msg[0..7].ToLower()<>"http://" And msg[0..7].ToLower()<>"file://"
				If FileType(msg)
					msg="file://"+msg
				Else
					msg="http://"+msg
				EndIf
			EndIf
			msg:+anchor
			msg=msg.Replace(" ","%20")
		ElseIf internalclass=GADGET_MENUITEM
			msg=msg.Replace("&", "")
		EndIf
		name=msg                        ' <-- Add this line here
		NSSetText Self,msg
	End Method


TCocoaGadget.GetText() seems to resort to internal field if an empty string is returned by NSGetText() - Skid, any idea why this was?


skidracer(Posted 2010) [#4]
Yuck...

Apologies for sloppy original code. After quick review name should be private to individual gadgetclass and generic usage is not advised.

Labels IMHO instead should be fixed to reflect OS state.

Gadgets like textarea certainly don't need their contents retained, so will try some more test code first.
seems to resort to internal field if an empty string is returned by NSGetText() -


hmph, i thought that was testing for null at first glance, weird

To stop cocogui.bmx retaining more than it needs I propose nulling nsgadget.name after it is used as parameter to NSInitGadget


	Function Create:TNSGadget(internalclass,text$,x,y,w,h,group:TGadget,style)
		
		Local gadget:TNSGadget = New TNSGadget
		gadget.origclass = internalclass
		gadget.internalclass = internalclass
		
		If Not group And internalclass<>GADGET_DESKTOP Then group = Desktop()
		gadget.parent = group
		
		gadget.name = text
		gadget.SetRect x,y,w,h	'setarea
		gadget.style = style
		gadget.font = TCocoaMaxGUIDriver.CocoaGUIFont
		
		If TNSGadget(group) Then
			gadget.forceDisable = Not (TNSGadget(group).enabled And Not TNSGadget(group).forceDisable)
		EndIf
		
		NSInitGadget gadget
		
		gadget.name=Null ' <- fixed to keep thing lightweight ?topic=91292




and removing undocumented/incomprehensible fallback in GetText:

	Method GetText$()
		Return NSGetText(Self)
	End Method




skidracer(Posted 2010) [#5]
Fixed in next release.


overmeeren(Posted 2010) [#6]
Fantastic guys! thanks for looking at it and finding it.