multiline string gadget with dialog library

Just starting out? Need help? Post your questions and find answers here.
nsstudios
Enthusiast
Enthusiast
Posts: 309
Joined: Wed Aug 28, 2019 1:01 pm
Location: Serbia
Contact:

multiline string gadget with dialog library

Post by nsstudios »

Hi,

I tried to convert my gadget code to dialog library, and I have a problem.
I use the following flags for my string gadgets:

Code: Select all

#ES_MULTILINE|#ESB_DISABLE_LEFT|#ESB_DISABLE_RIGHT|#ES_AUTOVSCROLL|#ES_AUTOHSCROLL| #WS_VSCROLL
Using them in the dialog xml results in an error, even if if I make them available through runtime.
Is there any way to still make string gadgets with dialog library with those flags?
I would use editor gadget, but it hooks the tab key, and all of the examples I've seen for disabling that behavior are for Windows only, and I'd still need the extra Windows flags anyway.

I'd really appreciate a solution to this problem.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: multiline string gadget with dialog library

Post by RASHAD »

There is noway to change the properties of the StringGadget() after creation
Next is a workaround
Remember to use id='?'

Code: Select all

EnableExplicit

Global dlg_window1 = CreateDialog(#PB_Any)
Global DialogsXML$ = #Empty$
DialogsXML$ +
   "<dialogs>" +
   "   <window name='window1' flags='#PB_Window_SystemMenu|#PB_Window_SizeGadget| #PB_Window_ScreenCentered'>" +
   "      <string name='editor1' id='0' width='200' height='100'/>" +
   "   </window>" +
   "</dialogs>"
Define DialogsXML = ParseXML(#PB_Any, DialogsXML$)
Define x,y,w,h

If OpenXMLDialog(dlg_window1, DialogsXML, "window1")
  Define editor = DialogGadget(dlg_window1, "editor1")
  x = GadgetX(editor)
  y = GadgetY(editor)
  w = GadgetWidth(editor)
  h = GadgetHeight(editor)
   FreeGadget(editor)
   StringGadget(editor,x,y,w,h,"",#ES_MULTILINE|#ESB_DISABLE_LEFT|#ESB_DISABLE_RIGHT|#ES_AUTOVSCROLL|#ES_AUTOHSCROLL| #WS_VSCROLL)
  ;SendMessage_(GadgetID(editor),#EM_SHOWSCROLLBAR, #SB_VERT,0)
  ;SendMessage_(GadgetID(editor),#EM_SHOWSCROLLBAR, #SB_HORZ,0)

  SetGadgetText(editor, ~"11111111111111111111111111111111\n22222222222222222222222222222222\n\n\n\n\n\n\n")
EndIf

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Egypt my love
nsstudios
Enthusiast
Enthusiast
Posts: 309
Joined: Wed Aug 28, 2019 1:01 pm
Location: Serbia
Contact:

Re: multiline string gadget with dialog library

Post by nsstudios »

Good idea! Thanks.
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: multiline string gadget with dialog library

Post by Quin »

RASHAD wrote: Mon Oct 26, 2020 7:59 am There is noway to change the properties of the StringGadget() after creation
Next is a workaround
Remember to use id='?'

Code: Select all

EnableExplicit

Global dlg_window1 = CreateDialog(#PB_Any)
Global DialogsXML$ = #Empty$
DialogsXML$ +
   "<dialogs>" +
   "   <window name='window1' flags='#PB_Window_SystemMenu|#PB_Window_SizeGadget| #PB_Window_ScreenCentered'>" +
   "      <string name='editor1' id='0' width='200' height='100'/>" +
   "   </window>" +
   "</dialogs>"
Define DialogsXML = ParseXML(#PB_Any, DialogsXML$)
Define x,y,w,h

If OpenXMLDialog(dlg_window1, DialogsXML, "window1")
  Define editor = DialogGadget(dlg_window1, "editor1")
  x = GadgetX(editor)
  y = GadgetY(editor)
  w = GadgetWidth(editor)
  h = GadgetHeight(editor)
   FreeGadget(editor)
   StringGadget(editor,x,y,w,h,"",#ES_MULTILINE|#ESB_DISABLE_LEFT|#ESB_DISABLE_RIGHT|#ES_AUTOVSCROLL|#ES_AUTOHSCROLL| #WS_VSCROLL)
  ;SendMessage_(GadgetID(editor),#EM_SHOWSCROLLBAR, #SB_VERT,0)
  ;SendMessage_(GadgetID(editor),#EM_SHOWSCROLLBAR, #SB_HORZ,0)

  SetGadgetText(editor, ~"11111111111111111111111111111111\n22222222222222222222222222222222\n\n\n\n\n\n\n")
EndIf

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Hi there,
This works, except there is one problem with it. If you put a TextGadget above/below the field (for screen reader accessibility) it isn't read after you remove/recreate the gadget in this way :cry:
Is there any other way? I tried

Code: Select all

SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) | #ES_AUTOHSCROLL | #ES_MULTILINE | #ES_NOHIDESEL)
This half works. It tricks my screen reader into saying multiline and reporting the multiline role, but it doesn't actually let me paste or insert multiple lines.
Post Reply