[Implemented] New flag for EditorGadget: #PB_Editor_WordWrap

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

[Implemented] New flag for EditorGadget: #PB_Editor_WordWrap

Post by Shardik »

It would be nice to have a flag for activating word wrap in the EditorGadget.
My code in a cross platform project looks something alike:

Code: Select all

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    gtk_text_view_set_wrap_mode_(GadgetID(#EditorGadget), #GTK_WRAP_WORD)
  CompilerCase #PB_OS_MacOS
    ImportC ""
      GetControlProperty(Control, PropertyCreator, PropertyTag, BufferSize, *ActualSize, *PropertyBuffer)
      TXNSetTXNObjectControls(TXNObject, ClearAll, ControlCount, ControlTags, ControlData)
    EndImport

    Define TXNObject.L
    Dim ControlTag.L(0)
    Dim ControlData.L(0)

    ControlTag(0) = 'wwrs' ; kTXNWordWrapStateTag
    ControlData(0) = 0     ; kTXNAutoWrap

    If GetControlProperty(GadgetID(#EditorGadget), 'PURE', 'TXOB', 4, 0, @TXNObject) = 0
      TXNSetTXNObjectControls(TXNObject, #False, 1, @ControlTag(0), @ControlData(0))
    EndIf
  CompilerCase #PB_OS_Windows
    SendMessage_(GadgetID(#EditorGadget), #EM_SETTARGETDEVICE, 0, 0)
CompilerEndSelect
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: New flag for EditorGadget: #PB_Editor_WordWrap

Post by Rook Zimbabwe »

I think it would be a gadget attribute
SetGadgetAttribute(#PB_WordWrap, 1)

I think it exists in windows AAAPI but I do not think it doess in Linux or Mac

Apparently in windows there is a default wordwrap function but it does not wrap??? Iss it turned off?

in API:
An application sends the EM_SETWORDBREAKPROC message to an edit control to replace the default wordwrap function with an application-defined wordwrap function.

EM_SETWORDBREAKPROC
wParam = 0; // not used; must be zero
lParam = (LPARAM)(EDITWORDBREAKPROC)ewbprc; // function address


Parameters

ewbprc

Value of lParam. Specifies the address of the application-defined wordwrap function. For more information about breaking lines, see the description of the EditWordBreakProc callback function.



Return Values

This message does not return a value.

Remarks

A wordwrap function scans a text buffer that contains text to be sent to the screen, looking for the first word that does not fit on the current screen line. The wordwrap function places this word at the beginning of the next line on the screen.
A wordwrap function defines the point at which Windows should break a line of text for multiline edit controls, usually at a space character that separates two words. Either a multiline or a single-line edit control might call this function when the user presses arrow keys in combination with the CTRL key to move the caret to the next word or previous word. The default wordwrap function breaks a line of text at a space character. The application-defined function may define the wordwrap to occur at a hyphen or a character other than the space character.
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: New flag for EditorGadget: #PB_Editor_WordWrap

Post by Shardik »

@Rook Zimbabwe,

did you try my code example? It activates word wrap in the EditorGadget on Windows, Linux
and MacOS. I posted it so Fred or freak don't have to do too much research on it when trying to
implement it in PureBasic... :roll:

I would suggest using the flag #PB_Editor_WordWrap as a constant in creating an EditorGadget
like this:

Code: Select all

EditorGadget(0, 10, 10, 200, 80, #PB_Editor_WordWrap)
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Re: New flag for EditorGadget: #PB_Editor_WordWrap

Post by USCode »

Yes please! +1
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: New flag for EditorGadget: #PB_Editor_WordWrap

Post by blueznl »

#PB_Editor_WordWrap but then also please another flag #PB_Editor_TabOut to change the [Tab] behaviour.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Jihugen
User
User
Posts: 45
Joined: Mon Jun 07, 2010 11:36 pm
Location: Normandy, France

Re: New flag for EditorGadget: #PB_Editor_WordWrap

Post by Jihugen »

Thanks a lot Shardik for this line, I was looking for it in the Win SDK but it finding it wasn't so obvious.

Code: Select all

SendMessage_(GadgetID(#EditorGadget), #EM_SETTARGETDEVICE, 0, 0)
There is currently no PB gadget with both word wrap and scrollbars (TextGadget (ie. static control) clips the text when it does not fit, other gadgets don't use word warp).
So +1 for this feature.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: New flag for EditorGadget: #PB_Editor_WordWrap

Post by Tenaja »

+1 for this... its a shame we must use a ScintillaGadget if we want these features without rolling our own.
Post Reply