A Plain-text only editorGadget?

Just starting out? Need help? Post your questions and find answers here.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: A Plain-text only editorGadget?

Post by rsts »

As written, All the items fit in the window. No scoll necessary.

You're ending with a chr(13) which creates a carriage return at the end of the text.

Seems to work fine.

cheers
Nico
Enthusiast
Enthusiast
Posts: 274
Joined: Sun Jan 11, 2004 11:34 am
Location: France

Re: A Plain-text only editorGadget?

Post by Nico »

Hello,

you never see the last line if it is empty, and impossible to scroll to the end.

you do not have this problem?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: A Plain-text only editorGadget?

Post by RASHAD »

Hi

Code: Select all

Texte.s="1"+Chr(13)+"2"+Chr(13)+"3"+Chr(13)+"4"+Chr(13)+"5"+Chr(13)+"6"+Chr(13)+"7"+Chr(13)
If OpenWindow(0, 0, 0, 300, 120, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
   hWnd = EditorGadget(0, 10, 10, 280, 100) 
   SetGadgetText(0, "")
   SetGadgetText(0,Texte)    
   SendMessage_(hWnd, #EM_SETTEXTMODE, #TM_PLAINTEXT, 0) 
   Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf 
Or

Code: Select all

Texte.s="1"+Chr(13)+"2"+Chr(13)+"3"+Chr(13)+"4"+Chr(13)+"5"+Chr(13)+"6"+Chr(13)+"7"+Chr(13)
If OpenWindow(0, 0, 0, 300, 120, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
  hWnd = EditorGadget(0, 10, 10, 280, 100)
  SendMessage_(hWnd, #EM_SETTEXTMODE, #TM_PLAINTEXT, 0)
    SetGadgetText(0, "")  
    SetGadgetText(0,Texte)    
    
   Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf 
Egypt my love
Nico
Enthusiast
Enthusiast
Posts: 274
Joined: Sun Jan 11, 2004 11:34 am
Location: France

Re: A Plain-text only editorGadget?

Post by Nico »

SendMessage_ (hWnd, EM_SETTEXTMODE #, # TM_PLAINTEXT, 0) does not work in the examples you give.
Indeed, it is possible to paste text in color (RTF)

We must make a SetGadgetText (0, "") just before.

:(
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: A Plain-text only editorGadget?

Post by RASHAD »

Nico
Both the two examples are OK
Tested with PB 4.5 and XP x86 SP2 and Win 7 x86
For paste color RTF see next URL

http://www.purebasic.fr/english/viewto ... 2&t=43458
Egypt my love
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: A Plain-text only editorGadget?

Post by srod »

Nico is correct Rashad. Your code allows for the pasting of styled text which is what the original code was there to prevent. You need to reorder the code.
I may look like a mule, but I'm not a complete ass.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: A Plain-text only editorGadget?

Post by RASHAD »

In that case we should keep Nico code as it is
Just update

Code: Select all

Texte.s="1"+Chr(13)+"2"+Chr(13)+"3"+Chr(13)+"4"+Chr(13)+"5"+Chr(13)+"6"+Chr(13)+"7"+Chr(13)

To

Code: Select all

Texte.s="1"+Chr(13)+"2"+Chr(13)+"3"+Chr(13)+"4"+Chr(13)+"5"+Chr(13)+"6"+Chr(13)+"7"+Chr(10)+Chr(13)
There will be more 1 blank line but you can scroll to the end
Egypt my love
Nico
Enthusiast
Enthusiast
Posts: 274
Joined: Sun Jan 11, 2004 11:34 am
Location: France

Re: A Plain-text only editorGadget?

Post by Nico »

Yes it works but it's very annoying that scroll.

Thanks
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: A Plain-text only editorGadget?

Post by rsts »

Hi Nico,

I'm not exactly sure what it is you're attempting to do or what the issue is with the scroll.

Regarding plain text. I believe code has been posted which will make the editor gadget a plain text control.

Is there still some issue regarding plain text? You can set up a callback and capture any "paste" into the editor and only paste plain text yourself, as an alternative.

Regarding the scroll problem. In the Windows world, a "new line" is a CRLF or chr(13) + chr(10), whereas in Unix a chr(10) is sufficient.

Since Windows regards new line as a separator:

"There is also some confusion whether newlines terminate or separate lines. If a newline is considered a separator, there will be no newline after the last line of a file. The general convention on most systems is to add a newline even after the last line, i.e. to treat newline as a line terminator. Some programs have problems processing the last line of a file if it is not newline terminated. Conversely, programs that expect newline to be used as a separator will interpret a final newline as starting a new (empty) line." from Wikipedia.

I believe you can solve the scrolling problem by adhering to the Windows conventions for new lines - i.e. separate new lines with a CR+LF

If you wish to use LF as the separator, add a blank to the last line so it's not empty.

I haven't used a raw windows edit control enough to know if PB is handling this differently than MS but I doubt it since PB is merely employing the MS control.

Does that help at all?

cheers
Nico
Enthusiast
Enthusiast
Posts: 274
Joined: Sun Jan 11, 2004 11:34 am
Location: France

Re: A Plain-text only editorGadget?

Post by Nico »

I am surprised that you did not have this problem, I decided to use a multiline stringgadget for now.

Thank you for your contribution!
Post Reply