TextEditGadgetEx PB 4.60

Share your advanced PureBasic knowledge/code with the community.
BjornF
User
User
Posts: 35
Joined: Mon Jun 23, 2008 11:09 am
Location: Copenhagen

Re: TextEditGadgetEx PB 4.60

Post by BjornF »

Very nice gadget !

I just noticed a minor bug (I think), on line 565 it says #PB_Canvas_GrabMouse, shouldn't it be #PB_Canvas_ClipMouse ?

all the best / Björn
User avatar
idle
Always Here
Always Here
Posts: 5890
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: TextEditGadgetEx PB 4.60

Post by idle »

I don't know maybe the constants been changed,thanks for the heads up
there's still a few bugs in it, it was never really intended to be an editor
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: TextEditGadgetEx PB 4.60

Post by Tenaja »

idle, have you done anything with this? I just tried it, and on Windows 7 it crashes on line 716 when I hit the Tab key:

Code: Select all

Procedure TextGadgetEx_AddText(*this.TextGadgetEX,mword.s,font=-1,size=12,color=-1,style=0)
	Protected timg,width,height,ct,word.s,a,tf.i,key.s
	
	If ListSize(*this\ltype()) = 0     ; <---- CRASH on Tab key: Invalid Memory Access.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: TextEditGadgetEx PB 4.60

Post by Tenaja »

I did not try to truly understand the code, but you had a static var that was never assigned a value, and that was used as a pointer in a call to CanvasCallBack() here:

Code: Select all

CompilerIf  #PB_Compiler_OS = #PB_OS_Windows
	Procedure CanvasCallBack(hwnd,msg,wparam,lparam)
		Static lobj      ; <------ Never initialized -------
		Protected proc,obj,ctrl,*obj.TextGadgetEX
		proc = GetProp_(hwnd,"proc")
		obj = GetProp_(hwnd,"obj")
		*obj = obj
		If msg = #WM_CHAR
			If  wparam > 31   
				TextGadgetEx_AddText(obj,Chr(wparam))
				TextGadgetEx_Output(obj)
			EndIf
		ElseIf msg = #WM_KEYUP
			If wparam = #VK_TAB
				*obj\lstate=1
				TextGadgetEx_AddText(lobj,Chr(wparam)) ; <---was used on these two lines
				TextGadgetEx_Output(lobj)                       ; <--- I replaced them with just obj.
			EndIf
		ElseIf msg = #WM_NCDESTROY
			RemoveProp_(hwnd, "proc")
			RemoveProp_(hwnd, "obj")
		EndIf
		ProcedureReturn CallWindowProc_(proc,hwnd,msg,wparam,lparam) 
	EndProcedure
	
CompilerEndIf
Replacing those two calls using lobj with just obj seemed to make it work.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: TextEditGadgetEx PB 4.60

Post by davido »

@idle,

Hadn't seen this before. Very nice.

Runs fine on Window 7 after the a few changes:

Error log:
[19:31:25] [COMPILER] Line 565: Constant not found: #PB_Canvas_GrabMouse. GrabMouse -> ClipMouse
[19:31:41] [COMPILER] Line 652: Comparisons (=, <, >, =< and >=) are only supported with keywords like If, While, Until or within Bool(). -> Added Bool(
[19:32:22] [COMPILER] Line 1161: Constant not found: #PB_Shortcut_Prior. Prior -> PageDown
[19:33:06] [COMPILER] Line 1163: Constant not found: #PB_Shortcut_Next. Prior -> PageUp
[19:33:26] Waiting for executable to start...
[19:33:26] Executable type: Windows - x64 (64bit, Unicode)
[19:33:26] Executable started.
[19:37:34] The Program execution has finished.
DE AA EB
User avatar
idle
Always Here
Always Here
Posts: 5890
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: TextEditGadgetEx PB 4.60

Post by idle »

Sorry the code is a bit of a Frankenstein it was originally made before we had the canvas gadget
I'm without windows at the moment, I had fixed the callback but apparently didn't post the fix
and the current version I have is to long to post as it has a syntax highlighter half built in.

If you can send me the fixed code I'll edit the post.
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Bisonte
Addict
Addict
Posts: 1313
Joined: Tue Oct 09, 2007 2:15 am

Re: TextEditGadgetEx PB 4.60

Post by Bisonte »

line 652 in procedure TextGadgetEx_Clear() is a little bit confusing :

Code: Select all

Procedure  TextGadgetEx_Clear(*this.TextGadgetEX)
 
   ForEach *this\glyphs()
       If IsImage(*this\glyphs()\img)
         FreeImage(*this\glyphs()\img)
         *this\glyphs()\img = 0
         *this\glyphs()\ref = 0
       EndIf
    Next   
   
    ClearList(*this\ltype())
       
     AddElement(*this\ltype())
     *this\ltype()\rc\left = *this\MarginLeft
     *this\ltype()\rc\right = *this\MarginRight = *this\MarginLeft+1 ; <<<<<<<<<<<<< ??????? 
     *this\ltype()\rc\bottom = 1
     If *this\cfont\size <> 0
       CopyStructure(*this\cfont,*this\ltype()\font,font)
     EndIf
     AddElement(*this\ltype())
    *this\insert = @*this\ltype()
    TextGadgetEx_Output(*this)
    *this\bedit = 0
  EndProcedure
How can I change that to work ?
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: TextEditGadgetEx PB 4.60

Post by yrreti »

*this\ltype()\rc\right = *this\MarginRight = *this\MarginLeft+1 ; <<<<<<<<<<<<< ???????

Code: Select all

*this\ltype()\rc\right = *this\MarginRight + *this\MarginLeft+1 ; <<<<<<<<<<<<< common += typo
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: TextEditGadgetEx PB 4.60

Post by Tenaja »

yrreti wrote:
*this\ltype()\rc\right = *this\MarginRight = *this\MarginLeft+1 ; <<<<<<<<<<<<< ???????

Code: Select all

*this\ltype()\rc\right = *this\MarginRight + *this\MarginLeft+1 ; <<<<<<<<<<<<< common += typo
Funny, I wrapped it in bool() instead; cannot tell a difference in operating. I did not try to debug it.
User avatar
idle
Always Here
Always Here
Posts: 5890
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: TextEditGadgetEx PB 4.60

Post by idle »

I updated the code with the last version I had minus the highlighter.
The code is really a dogs bollicks, it was Ok when it was only intended to display text
but adding in editing really messed it up.
Windows 11, Manjaro, Raspberry Pi OS
Image
Post Reply