Difficulty with Editor Gadget

Everything else that doesn't fall into one of the other PB categories.
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Difficulty with Editor Gadget

Post by coco2 »

I have an editor gadget and I can change the font size in it using a button to make the font bigger or smaller. The problem I'm having is that if I type something with small text for example, then copy the small text, then make the font size bigger and paste in what I copied, it pastes in the smaller text. How can I make the editor gadget only paste in the same size text as what it's set to?
BarryG
Addict
Addict
Posts: 4136
Joined: Thu Apr 18, 2019 8:17 am

Re: Difficulty with Editor Gadget

Post by BarryG »

Copying and pasting rich text always uses how it was copied, so this is normal (see WordPad, Word, etc). You can't change it to what the font size currently is because it hasn't been copied that way.
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Difficulty with Editor Gadget

Post by coco2 »

I didn't know it was rich text. The help doesn't say anything about rich text. How would you even use rich text in it?
AZJIO
Addict
Addict
Posts: 2143
Joined: Sun May 14, 2017 1:48 am

Re: Difficulty with Editor Gadget

Post by AZJIO »

1. Enable RTF

Code: Select all

SendMessage_(GadgetID(0), #EM_SETTEXTMODE, #TM_RICHTEXT, 0)
2. Set the font size in the gadget

Code: Select all

SetGadgetFont(#Gadget , FontID)
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Difficulty with Editor Gadget

Post by coco2 »

Hi AZJIO,
How do you disable Richtext in the gadget?
I tried this but it didn't work:

Code: Select all

SendMessage_(GadgetID(#edtInput), #EM_SETTEXTMODE, #TM_PLAINTEXT, 0)
BarryG
Addict
Addict
Posts: 4136
Joined: Thu Apr 18, 2019 8:17 am

Re: Difficulty with Editor Gadget

Post by BarryG »

coco2 wrote: Sun Feb 23, 2025 3:07 amI didn't know it was rich text. The help doesn't say anything about rich text. How would you even use rich text in it?
Oh, I mistakenly assumed it was because you mentioned the different font size, and I thought you meant the editor had different font sizes in it for different parts of its text (your button comment made me think that).

[Edit] I was correct after all, per your linked image further below.
Last edited by BarryG on Sun Feb 23, 2025 6:18 am, edited 1 time in total.
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Difficulty with Editor Gadget

Post by coco2 »

I may not have been clear, I'm trying to remove all rich text formatting from the editor gadget, but not having any luck.
AZJIO
Addict
Addict
Posts: 2143
Joined: Sun May 14, 2017 1:48 am

Re: Difficulty with Editor Gadget

Post by AZJIO »

coco2 wrote: Sun Feb 23, 2025 4:13 am remove all rich text formatting
What version of PureBasic are you using? In recent versions, RTF is disabled by default.
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Difficulty with Editor Gadget

Post by coco2 »

I'm using 6.20

Here is what I'm talking about:

https://imgur.com/a/pKdceZC
BarryG
Addict
Addict
Posts: 4136
Joined: Thu Apr 18, 2019 8:17 am

Re: Difficulty with Editor Gadget

Post by BarryG »

Yeah, that looks like rich text to me, because there's two different font sizes. So I was right in my initial comment.
Axolotl
Addict
Addict
Posts: 804
Joined: Wed Dec 31, 2008 3:36 pm

Re: Difficulty with Editor Gadget

Post by Axolotl »

you can try this

Code: Select all

SetGadgetText(1, GetGadgetText(1))      ; <-- this does work on rtf 
see this Testcode and press the buttons to see the differences.

Code: Select all

; tested with PB 6.11 x64
Global rtf_text.s = "" + 
"{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1031{\fonttbl{\f0\fnil\fcharset0 Calibri;}} " + 
"{\*\generator Riched20 10.0.19041}\viewkind4\uc1 " + 
"\pard\sa200\sl276\slmult1\f0\fs22\lang7 Test with \fs32 different \fs22 Fonts. \par " +
"} "

Procedure Main() 
  
  If OpenWindow(0, 0, 0, 322, 340, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    EditorGadget(0, 8, 8, 306, 133)     ; plain 
    SendMessage_(GadgetID(0), #EM_SETTEXTMODE, #TM_PLAINTEXT, 0) 

    EditorGadget(1, 8, 133+16, 306, 133) ; rtf 
    SendMessage_(GadgetID(1), #EM_SETTEXTMODE, #TM_RICHTEXT, 0) 
 
    ButtonGadget(2,  8, 310, 76, 20, "Plain") 
    ButtonGadget(3, 88, 310, 76, 20, "RTF") 
    
    SetGadgetText(0, rtf_text)  ; <-- this does not work this way 
    SetGadgetText(1, rtf_text)  ; <-- with formatting 
    
    Repeat 
      Select WaitWindowEvent() 
        Case #PB_Event_CloseWindow
          Break 
        Case #PB_Event_Gadget 
          Select EventGadget() 
            Case  2
              SetGadgetText(0, GetGadgetText(1))      ; <-- this does work on plain 
            Case 3 
              SetGadgetText(1, GetGadgetText(1))      ; <-- this does work on rtf 
          EndSelect 
      EndSelect  
    ForEver  
  EndIf
EndProcedure 

End Main() 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Re: Difficulty with Editor Gadget

Post by PBJim »

Can anyone confirm, was there definitely a change after PB 6.00 that requires #TM_RICHTEXT to be set, in order to display RTF content? It wasn't necessary on PB 6.00 (Windows 64-bit).

Code: Select all

editor.i = EditorGadget(#PB_Any, 10, 10, 360, 250, #PB_Editor_ReadOnly | #PB_Editor_WordWrap)
SendMessage_(GadgetID(editor.i), #EM_SETTEXTMODE, #TM_RICHTEXT, 0)
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Difficulty with Editor Gadget

Post by Fred »

Yes.
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Re: Difficulty with Editor Gadget

Post by PBJim »

Merci Fred, pour la réponse rapide. Thank you, Jim.
Post Reply