Increasing capacity of StringGadget

Just starting out? Need help? Post your questions and find answers here.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Increasing capacity of StringGadget

Post by PB »

I just did some searching here but didn't find the answer, but I'm sure
someone had some code to increase the capacity of a StringGadget?
Currently it can only hold 30000 bytes of data, but I need way more...
(And yes, I tried the EditorGadget, but it only holds 32767 bytes).
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

For the stringgadget, use this to increase the size:

Code: Select all

SendMessage_(GadgetID(#String), #EM_LIMITTEXT, NewSize, 0)
This one is for EditorGadget:

Code: Select all

SendMessage_(GadgetID(#Editor), #EM_EXLIMITTEXT, 0, NewSize)

Timo
quidquid Latine dictum sit altum videtur
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> SendMessage_(GadgetID(#String), #EM_LIMITTEXT, NewSize, 0)

Thanks Freak! :) I've used this before to limit a StringGadget, but totally
forgot it can be used to also increase the default size. :oops:
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Interesting.
What are the maximal authorized values for NewSize for the two gadgets ?
Can a StringGadget or an EditorGadget hold more than 64k ?
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

There is no mention of an upper limit for the EditorGadget() so i guess
it would be up to 2 GB?? Never tested that though :lol:

For Stringgadget, there are some limits depending on the used system:
Before EM_LIMITTEXT is called, the default limit for the amount of text a user can enter in an edit control is 32,767 characters.

Edit controls on Windows NT/2000/XP: For single-line edit controls, the text limit is either 0x7FFFFFFE bytes or the value of the wParam parameter, whichever is smaller. For multiline edit controls, this value is either –1 bytes or the value of the wParam parameter, whichever is smaller.

Edit controls on Windows 95/98/Me: For single-line edit controls, the text limit is either 0x7FFE bytes or the value of the wParam parameter, whichever is smaller. For multiline edit controls, this value is either 0xFFFF bytes or the value of the wParam parameter, whichever is smaller.
However, you must keep in mind, that the PB string system is limited
to 64K. So if you want more, you have to use memory buffers to
handle the strings.

Timo
quidquid Latine dictum sit altum videtur
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> you must keep in mind, that the PB string system is limited to 64K

Actually, Fred posted a way to increase it -- and it works great! I'm
now using strings of 1 MB instead of the tiny 64 K default, with no
bad speed loss in my apps. Since his tip was in the middle of a long
thread, I've re-posted it as standalone tip here (and put it in the FAQ):

viewtopic.php?p=45054
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

Code: Select all

SendMessage_(GadgetID(#Editor), #EM_EXLIMITTEXT, 0, NewSize)
What is the metric of NewSize? Byte,Kilobyte ?
How should I set the new size if i want to have a 120 Kb EditorGadget?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

NewSize refers to bytes.

1 KB = 1024 Bytes

Convert your 120 KB max size to bytes by multiplying 120 * 1024.

NewSize = 122880 :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> There is no mention of an upper limit for the EditorGadget() so i guess
> it would be up to 2 GB?? Never tested that though :lol:

Is this confirmed with PureBasic v4.00 at all? Or to put it another way: what
is the EditorGadget's default size? Do I need to use the SendMessage API to
increase it if I want to load a 500 KB file, etc?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Increasing capacity of StringGadget

Post by Michael Vogel »

Any chance to increase the StringGadget content to allow more than 1024 characters in multiline mode?

When you try to paste content into the following gadgets, it fails for the multiline type:

Code: Select all

s.s=Space(1000)
z.s=s+"|<1000            1024>|"

If OpenWindow(0,0,0,1066,100,"StringGadget Flags", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	c=StringGadget(0, 58,10,1000,20,"")
	SendMessage_(c,#EM_LIMITTEXT,10000,0)
	SetGadgetText(0,z)
	
	c=StringGadget(1, 58,40,1000,20,"",#ES_MULTILINE)
	SendMessage_(c,#EM_LIMITTEXT,10000,0)
	SetGadgetText(1,z)
	
	TextGadget(2,8,10,40,20,"")
	TextGadget(3,8,40,40,20,"")
	Repeat
		SetGadgetText(2,Str(Len(GetGadgetText(0))))
		SetGadgetText(3,Str(Len(GetGadgetText(1))))
	Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Increasing capacity of StringGadget

Post by Dude »

Michael Vogel wrote:When you try to paste content into the following gadgets, it fails for the multiline type
It works if you TYPE the extra text, but not if PASTING extra text, which is weird. :shock:

StringGadgets() don't officially support multiline mode (#ES_MULTILINE is just a hack).
User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Increasing capacity of StringGadget

Post by Michael Vogel »

Interesting, im am using PB 5.45 on Windows 8.1 and can't add additional characters by using the keyboard - only SetGadgetText seems to ignore the limit of 1024 characters. No difference when the unicode compiler option i set.

I am using the multiline flag to allow centering the text within the gadget as seen here (the following code doesn't show any new behaviour, it's just to demonstrate how the text is vertically centered within the gadget...)

Code: Select all

s.s="|"+Space(999)
z.s=s+"|<1000            1024>|"

; z="< more characters> "+z

Procedure StringGadgetInitialize(GadgetID)

	#StringGadgetBorder=6
	#StringGadgetHeight=28

	Protected hdc
	Protected fsz.Size
	Protected Rect.Rect
	Protected font

	font=GetGadgetFont(GadgetID)
	GadgetID=GadgetID(GadgetID)

	hdc=GetDC_(GadgetID)
	SelectObject_(hdc,font)
	GetTextExtentPoint32_(hdc,"|",1,fsz)
	ReleaseDC_(GadgetID,hdc)

	GetWindowRect_(GadgetID,Rect)
	Global StringGadgetOffset=Rect\bottom-Rect\top
	StringGadgetOffset=StringGadgetOffset>>1-fsz\cy<<4/20;	cy*16/20 (Text eher weiter oben) bis cy*16/22 (eher weiter unten)

EndProcedure
Procedure StringGadgetAlignment(GadgetID)

	Protected hwndEdit
	Protected erect.Rect

	hwndEdit=GadgetID(GadgetID)

	GetClientRect_(hwndEdit,eRect)
	erect\left=#StringGadgetBorder
	eRect\top=StringGadgetOffset
	eRect\bottom=#StringGadgetHeight

	SendMessage_(hwndEdit,#EM_SETRECT,0,eRect)

EndProcedure

If OpenWindow(0,0,0,1066,120,"StringGadget Flags", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	c=StringGadget(0, 58,10,1000,35,"")
	SendMessage_(c,#EM_LIMITTEXT,10000,0)
	StringGadgetInitialize(0)
	SetGadgetText(0,z)
	
	c=StringGadget(1, 58,50,1000,35,"",#ES_MULTILINE)
	SendMessage_(c,#EM_LIMITTEXT,10000,10000)
	StringGadgetAlignment(1)
	SetGadgetText(1,z)
	
	TextGadget(2,8,10,40,35,"",#SS_CENTERIMAGE)
	TextGadget(3,8,50,40,35,"",#SS_CENTERIMAGE)
	
	Repeat
		SetGadgetText(2,Str(Len(GetGadgetText(0))))
		SetGadgetText(3,Str(Len(GetGadgetText(1))))
	Until WaitWindowEvent() = #PB_Event_CloseWindow
	
EndIf
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Increasing capacity of StringGadget

Post by Dude »

Michael Vogel wrote:im am using PB 5.45 on Windows 8.1 and can't add additional characters by using the keyboard
We're up to v5.62 now, so try it with that version on Windows 8.1 and see. :P
User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Increasing capacity of StringGadget

Post by Michael Vogel »

At least the version 5.61 does the same like 5.45, so I must do another update, Dude :)
Post Reply