Page 1 of 1

[Implemented] StringGadget maximal length

Posted: Thu Apr 20, 2006 10:53 pm
by PureBaser
A constant such in the way:

#PB_String_MaxLength

Thanks for reading

Posted: Sat Apr 29, 2006 9:59 pm
by Sub-Routine
Yes, a Flag to use with StringGadget...

Posted: Sun Apr 30, 2006 11:18 am
by maw
Actually it's easy enough to do by yourself. This snippet is for PB4, Windows only, and handles backspace, delete, paste and such things.

Code: Select all

Procedure stringlength(gadget.l, length.l)
	text$ = GetGadgetText(gadget)
	textlength.l = Len(text$)

	If textlength > length
		SendMessage_(GadgetID(gadget), #EM_GETSEL, @startpos.l, @endpos.l)
		SetGadgetText(gadget, Left(text$, startpos - 1) + Mid(text$, startpos + 1, Len(text$) - 1))
		SendMessage_(GadgetID(gadget), #EM_SETSEL, startpos - 1, startpos - 1)
		FlashWindow_(WindowID(0), 1)
		MessageBeep_(-1)
	EndIf
EndProcedure


OpenWindow(0, 0, 0, 320, 240, "Test")
CreateGadgetList(WindowID(0))
StringGadget(0, 20, 20, 200, 20, "")
StringGadget(1, 20, 50, 200, 20, "")
StringGadget(2, 20, 80, 200, 20, "")
StringGadget(3, 20, 110, 200, 20, "")

Repeat
	Select WindowEvent()
		Case #PB_Event_CloseWindow
			Break
		Case #PB_Event_Gadget
			gadget.l = EventGadget()
			Select gadget
				Case 0,1
					stringlength(gadget, 20)
				Case 2
					stringlength(gadget, 10)
				Case 3
					stringlength(gadget, 32)
			EndSelect
	EndSelect
ForEver

Posted: Sun Apr 30, 2006 5:08 pm
by Fred
We could add an attribute for that, you're right. For Windows you can also use that:

Code: Select all


OpenWindow(0, 0, 0, 320, 240, "Test")
CreateGadgetList(WindowID(0))
StringGadget(0, 20, 20, 200, 20, "")
StringGadget(1, 20, 50, 200, 20, "")
StringGadget(2, 20, 80, 200, 20, "")
StringGadget(3, 20, 110, 200, 20, "")

SendMessage_(GadgetID(0), #EM_LIMITTEXT, 3, 0)

Repeat
   Select WindowEvent()
      Case #PB_Event_CloseWindow
         Break
      Case #PB_Event_Gadget
         gadget.l = EventGadget()
   EndSelect
ForEver