How can I set text to an EditorGadget?

Just starting out? Need help? Post your questions and find answers here.
The8th
User
User
Posts: 29
Joined: Fri Sep 04, 2015 10:23 am

How can I set text to an EditorGadget?

Post by The8th »

I am trying to put text to an EditorGadget, but all efforts fail.
I want the text in the EditorGadget look the same as in the TextGadget (bottom example)

Code: Select all

EnableExplicit
#ST_UNICOE = 8
Define ste.SETTEXTEX
ste\flags = #ST_UNICOE
ste\codepage = 1200

Define text$ = "Before they're forever banned?" + #LF$
text$ + "(Kotae, bou ya, osora fuku) 答え、坊や、お空吹く" + #LF$
text$ + "(Kaze ga shitteru dake sa) 風が知ってるだけさ" + #LF$
text$ + "How many years must a mountain exist" + #LF$

Define font.l = LoadFont(0, "Arial", 14)
OpenWindow(0, 300, 300, 570, 500, "Editorgadget")
EditorGadget(1, 10, 10, 550, 120, #PB_Editor_ReadOnly)
SetGadgetFont(1, font)
EditorGadget(2, 10, 140, 550, 120, #PB_Editor_ReadOnly)
SetGadgetFont(2, font)
EditorGadget(3, 10, 270, 550, 120, #PB_Editor_ReadOnly)
SetGadgetFont(3, font)
TextGadget(4, 10, 400, 550, 120, "")
SetGadgetFont(4, font)

SetGadgetText(1, text$) ;not working
SendMessage_(GadgetID(2), #WM_SETTEXT, 0, @text$) ;not working
SendMessage_(GadgetID(3), #EM_SETTEXTEX, @ste, @text$) ;not working
SetGadgetText(4, text$) ;working

Repeat
Until WaitWindowEvent(1) = #PB_Event_CloseWindow
What is the correct way to put text to an EditorGadget? It all works in a TextGadget, but the text in the EditorGadget always changes the font after the first Unicode character.

Henry

Purebasic 5.72, Windows 10-64
User avatar
spikey
Enthusiast
Enthusiast
Posts: 750
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: How can I set text to an EditorGadget?

Post by spikey »

It looks Kanji to me, is that right?

The problem isn't how you are adding the text to the control - SetGadgetText is doing its job properly.

The problem arises from the font you are using. The Arial font doesn't contain the necessary Kanji glyphs so the control starts to display in Arial but switches on the fly, to a different font which does, when it hits the first Kanji glyph. A rich edit control can support multiple fonts so this is why you get the mixture. What it doesn't do is switch back to Arial after the Kanji sections, so that's why the following Latin glyphs look inconsistent with the initial ones.

The TextGadget doesn't support mutliple fonts so when it hits a Kanji glyph the whole gadget gets changed to the new font.

The solution is to pick a font which supports all the glyphs you need. I don't have a Windows 10 machine to hand so I can't say which one might be a good choice - maybe some of the Windows 10 guys will chip in with a suggestion...

For example, if I replace Arial with Meiryo UI on my Win 7 machine, I get a consistent look across all four gadgets.

Code: Select all

Define font.l = LoadFont(0, "Meiryo UI", 14)
Edit: Found a nicer looking font than MS UI Gothic.
The8th
User
User
Posts: 29
Joined: Fri Sep 04, 2015 10:23 am

Re: How can I set text to an EditorGadget?

Post by The8th »

My question is:
Why does it work in a TextGadget, but not in the EditorGagdet?
The problem is not the language glyphs, it happens after all Unicode characters. And it is independant of the font. It happens with all fonts.
Look at the following example.
The text is OK in the TextGadget, not OK in the EditorGadgets.

Code: Select all

EnableExplicit
#ST_UNICOE = 8
Define ste.SETTEXTEX
ste\flags = #ST_UNICOE
ste\codepage = 1200

Define text$ = "Before they're forever banned" + Chr($A789) + " Any Text"

Define font.l = LoadFont(0, "Consolas", 14)
OpenWindow(0, 300, 300, 570, 500, "Editorgadget")
EditorGadget(1, 10, 10, 550, 120, #PB_Editor_ReadOnly)
SetGadgetFont(1, font)
EditorGadget(2, 10, 140, 550, 120, #PB_Editor_ReadOnly)
SetGadgetFont(2, font)
EditorGadget(3, 10, 270, 550, 120, #PB_Editor_ReadOnly)
SetGadgetFont(3, font)
TextGadget(4, 10, 400, 550, 120, "")
SetGadgetFont(4, font)

SetGadgetText(1, text$) ;not working
SendMessage_(GadgetID(2), #WM_SETTEXT, 0, @text$) ;not working
SendMessage_(GadgetID(3), #EM_SETTEXTEX, @ste, @text$) ;not working
SetGadgetText(4, text$) ;working

Repeat
Until WaitWindowEvent(1) = #PB_Event_CloseWindow
PureBasic 5.72 - Windows 10
Henry
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: How can I set text to an EditorGadget?

Post by RASHAD »

PureBasic 5.72 is using Riched20.dll
Try using PB ver 5.73 with the most recent dll (msftedit.dll)
Everything is OK
Egypt my love
The8th
User
User
Posts: 29
Joined: Fri Sep 04, 2015 10:23 am

Re: How can I set text to an EditorGadget?

Post by The8th »

RASHAD wrote:PureBasic 5.72 is using Riched20.dll
Try using PB ver 5.73 with the most recent dll (msftedit.dll)
Everything is OK
Ah, thanks. That's it. I missed this.
Henry
Post Reply