Anyone did a better InputRequester module or include?

Everything else that doesn't fall into one of the other PB categories.
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Anyone did a better InputRequester module or include?

Post by Kukulkan »

Hi,

for a quick project I need a simple input requester that allows wordwrapped multiline message on top of the input field. It needs to adapt the height automatically to fit to the message text. I thought this is nothing special and a no-brainer, but the existing InputRequester is not capable of doing that.

I first searched this forum but found no ready to use solution.

I then wanted to create my own but there is no TextGadget that does wordwrap and automatic height at all. Therefore, the only solution I see is using drawing functions and doing my own wordwrap function using TextWidth() and TextHeight() functions. Then using this to draw my message to a canvas (aliasing!) and then use that in the dialog. I can't believe it is that hard in 2025 :shock:

The dialog library also seem to not provide some auto sizing and wordwrap for the TextGadget. Or did I miss something?

Is there anyone who already did an include or module for this and is willing to share? Need it for Windows only.
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Anyone did a better InputRequester module or include?

Post by Caronte3D »

Take a look to this thread, maybe you can use (or modify to your needs) it:
viewtopic.php?p=564489#p564489
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Anyone did a better InputRequester module or include?

Post by Kukulkan »

Caronte3D wrote: Mon Jun 16, 2025 9:53 am Take a look to this thread, maybe you can use (or modify to your needs) it:
viewtopic.php?p=564489#p564489
Thanks, but all of these examples using fixed dialog heights. Also, I can't find any automatic word wrap there?

My dialog message is concatenated during runtime and also translated to several languages. Chinese takes much less space than French or German. In addition, different system font settings for Windows may also affect the dialog sizes. So setting a fixed pixel height for such dialog is really asking for trouble...

Until now I found no other way for wordwrap and automatic calculating dialog height than using drawing functions and doing my own word wrap as described in my first post.

Interestingly, the MessageRequester() function is both wrapping the text and automatically adjusts the dialog height fo fit the message content. This is what I want for the InputRequester.
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Anyone did a better InputRequester module or include?

Post by Caronte3D »

Kukulkan wrote: Mon Jun 16, 2025 10:20 am ...calculating dialog height than using drawing functions and doing my own word wrap...
Maybe the only option :? or... you can try to doing it with html and WebViewGadget, I don't know.... :P
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Anyone did a better InputRequester module or include?

Post by Kukulkan »

Caronte3D wrote: Mon Jun 16, 2025 12:21 pm
Kukulkan wrote: Mon Jun 16, 2025 10:20 am ...calculating dialog height than using drawing functions and doing my own word wrap...
Maybe the only option :? or... you can try to doing it with html and WebViewGadget, I don't know.... :P
Hm. The WebViewGadget and WebGadget are gadgets created in an ordinary window using width and height in pixel. The containing HTML/CSS would do that easily, but then I would get scrollbars or unused empty space. It is the same as for a big TextGadget. It does not solve my problem. I need a requester/window that adjusts its height automatically based on message content including wordwrap.

Maybe PB is not the best choice for GUI interfaces... In .NET it would be lblMessage.WordWrap = True and lblMessage.PreferredSize.Height to get the needed size. Then, simply resetting the rest of the elements and window height in a second step before display. Or even more easy using Anchor and Dock properties. But PB feels very much like 20 years ago... Unfortunately, I have to do a single executable and I can't use .NET (I plan to do on MAC and Linux, too, later). So I thought PB would be a good choice.

Anyway, I will have to find a workaround. I give it up here for the moment. It is simply not possible in PB...
Last edited by Kukulkan on Mon Jun 16, 2025 1:39 pm, edited 1 time in total.
Axolotl
Enthusiast
Enthusiast
Posts: 797
Joined: Wed Dec 31, 2008 3:36 pm

Re: Anyone did a better InputRequester module or include?

Post by Axolotl »

maybe you can start with something like this...
Instead of calculation inside the procedure I resize the boxes in development mode and than set the parameter WndW, WndH to the best values.
But thats the way I do it, because I am the only one who uses my codes....

Code: Select all


EnableExplicit 

Procedure.s InputRequesterMultiLines(Caption$, Description$, DefaultText$, WndW = 240, WndH = 160) 
  Protected NWnd, NWndParent, NLblDescr, NStrInput, NBtnOk, NBtnCancel  ; <== dynamic Window and Gadgets numbers start with N 
  Protected th, wflag, hParent   
  Protected result$ 

  wflag = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget 

  NWndParent = GetActiveWindow() 
  If NWndParent <> -1 
    hParent = WindowID(NWndParent) 
    DisableWindow(NWndParent, 1)      ; <- disable parent window (because of our own event loop) 
    wflag | #PB_Window_WindowCentered 
  Else 
    hParent = 0 
    wflag | #PB_Window_ScreenCentered 
  EndIf 

  th = 16 * (CountString(Description$, #LF$) + 1) 
  WndH + th 

  NWnd = OpenWindow(#PB_Any, 8, 8, WndW, WndH, Caption$, wflag, hParent) 
  If NWnd ; <> 0 
    NLblDescr = TextGadget(#PB_Any, 2, 2, WndW-4, th, Description$) 
;SetGadgetColor(NLblDescr, #PB_Gadget_BackColor, #Yellow) 
    NStrInput = StringGadget(#PB_Any, 2, th+4, WndW-4, WndH - th - 4-32, DefaultText$, #ES_MULTILINE | #ES_AUTOVSCROLL | #WS_VSCROLL | #WS_HSCROLL) 
    NBtnOk     = ButtonGadget(#PB_Any, WndW-156, WndH-28, 76, 24, "OK") 
    NBtnCancel = ButtonGadget(#PB_Any, WndW-78, WndH-28, 76, 24, "Cancel") 

    AddKeyboardShortcut(NWnd, #PB_Shortcut_Escape, 27) 
   ;AddKeyboardShortcut(NWnd, #PB_Shortcut_Return, 13)  ; we want return for multi line input 

    result$ = ""  ; init the return value 
    Repeat 
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow 
          Break  ; bye 

        Case #PB_Event_SizeWindow 
          WndW = WindowWidth(NWnd) : WndH = WindowHeight(NWnd)                       
          Debug "■ ==> New Window Size == " + WndW + ", " + WndH 
          
          ResizeGadget(NLblDescr, #PB_Ignore, #PB_Ignore, WndW-4, #PB_Ignore) 
          ResizeGadget(NStrInput, #PB_Ignore, #PB_Ignore, WndW-4, WndH-th-36) 
          ResizeGadget(NBtnOk, WndW-156, WndH-28, #PB_Ignore, #PB_Ignore) 
          ResizeGadget(NBtnCancel, WndW-78, WndH-28, #PB_Ignore, #PB_Ignore) 

        Case #PB_Event_Menu
          Select EventMenu() 
            Case 27 : Break  ; leave the loop 
          EndSelect 

        Case #PB_Event_Gadget
          Select EventGadget() 
            Case NBtnOk     : result$ = GetGadgetText(NStrInput)  : Break  ; get the input and leave the loop 
            Case NBtnCancel : result$ = ""                        : Break  ; leave the loop 
          EndSelect 
      EndSelect 
    ForEver ; until break is used 
    RemoveKeyboardShortcut(NWnd, #PB_Shortcut_Escape) 
   ;RemoveKeyboardShortcut(NWnd, #PB_Shortcut_Return)  
    CloseWindow(NWnd) 
  EndIf 

  If NWndParent <> -1  
    DisableWindow(NWndParent, 0)  ; enable parent window again, now we use the main event loop 
  EndIf 

  ProcedureReturn result$  ; return the input 
EndProcedure


CompilerIf #PB_Compiler_IsMainFile 
Global ret$

Repeat 
  ret$ =  InputRequesterMultiLines("Caption", "Description"+#LF$+"second "+#LF$+"third line", "DefaultText") 
  Debug "" + ret$ 
Until ret$ = "" 

CompilerEndIf 
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).
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Anyone did a better InputRequester module or include?

Post by Kukulkan »

Axolotl wrote: Mon Jun 16, 2025 1:33 pm maybe you can start with something like this...
Thank you, but your example dialog needs the user to resize. It resizes the input field if the user resizes the dialog. This is not what I want. Maybe I'm simply not able to describe my needs correctly :(

Code: Select all

a.s = InputRequester("title", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.", "")
As a result, I like a dialog that shows the long message wordwrapped and auto-sized in a way that the full text message is displayed on top of the input field (single line input is fine for me).

Code: Select all

--------------------------
| LONG MESSAGE WITH AUTO | 
| WORDWRAP FOR ANY TEXT  |
| THAT IS MAYBE EVEN MUCH| <- dialog matches the height to wordwrapped message (whatever length)
| MUCH LONGER]           |
|                        | <- always just a few pixel of space
| [        input       ] |
|                        | <- always just a few pixel of space
|          [OK] [Cancel] |
--------------------------
Axolotl
Enthusiast
Enthusiast
Posts: 797
Joined: Wed Dec 31, 2008 3:36 pm

Re: Anyone did a better InputRequester module or include?

Post by Axolotl »

Okay. I played around a little....
If you are on windows, try this.

Code: Select all

EnableExplicit 

Procedure.s InputRequesterMultiLines(Caption$, Description$, DefaultText$, WndW = 240, WndH = 160) 
  Protected NWnd, NWndParent, NLblDescr, NStrInput, NBtnOk, NBtnCancel  ; <== dynamic Window and Gadgets numbers start with N 
  Protected tw, th, wflag, hParent , hdc, hFont, rc.RECT  
  Protected result$ 

  wflag = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_Invisible 

  NWndParent = GetActiveWindow() 
  If NWndParent <> -1 
    hParent = WindowID(NWndParent) 
    DisableWindow(NWndParent, 1)      ; <- disable parent window (because of our own event loop) 
    wflag | #PB_Window_WindowCentered 
  Else 
    hParent = 0 
    wflag | #PB_Window_ScreenCentered 
  EndIf 

;   th = 16 * (CountString(Description$, #LF$) + 1) 
;   WndH + th 

  ; set the size of the Textgadget! 
  ; 
  hdc = GetDC_(0) ; GadgetID(NLblDescr)) 
  hFont = GetGadgetFont(#PB_Default)  ; hFont = SendMessage_(GadgetID(Gad), #WM_GETFONT, 0, 0)
  SelectObject_(hdc, hFont) 
  rc\right = WndH 
  DrawText_(hdc, Description$, Len(Description$), @rc, #DT_CALCRECT|#DT_WORDBREAK)
 ;ReleaseDC_(GadgetID(NLblDescr), hdc) 
  ReleaseDC_(0, hdc) 
  tw = rc\right - rc\left
  th = rc\bottom - rc\top 
  If tw < WndW-4 : tw = WndW-4 : EndIf
; If th > WndH-44 : WndH = th + 44 : EndIf 

  NWnd = OpenWindow(#PB_Any, 8, 8, WndW, WndH, Caption$, wflag, hParent) 
  If NWnd ; <> 0 

    NLblDescr = TextGadget(#PB_Any, 2, 2, WndW-4, th, Description$) 
SetGadgetColor(NLblDescr, #PB_Gadget_BackColor, #Yellow) 

    NStrInput = StringGadget(#PB_Any, 2, th+4, WndW-4, WndH - th - 4-32, DefaultText$, #ES_MULTILINE | #ES_AUTOVSCROLL | #WS_VSCROLL | #WS_HSCROLL) 
    NBtnOk     = ButtonGadget(#PB_Any, WndW-156, WndH-28, 76, 24, "OK") 
    NBtnCancel = ButtonGadget(#PB_Any, WndW-78, WndH-28, 76, 24, "Cancel") 

    AddKeyboardShortcut(NWnd, #PB_Shortcut_Escape, 27) 
   ;AddKeyboardShortcut(NWnd, #PB_Shortcut_Return, 13)  ; we want return for multi line input 

    result$ = ""  ; init the return value 
    HideWindow(NWnd, 0) 
    Repeat 
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow 
          Break  ; bye 

        Case #PB_Event_SizeWindow 
          WndW = WindowWidth(NWnd) : WndH = WindowHeight(NWnd)                       
          Debug "■ ==> New Window Size == " + WndW + ", " + WndH 

          hdc = GetDC_(GadgetID(NLblDescr)) 
          hFont = GetGadgetFont(#PB_Default)  ; hFont = SendMessage_(GadgetID(Gad), #WM_GETFONT, 0, 0)
          SelectObject_(hdc, hFont) 
          rc\right = WndH 
          DrawText_(hdc, Description$, Len(Description$), @rc, #DT_CALCRECT|#DT_WORDBREAK)
          ReleaseDC_(GadgetID(NLblDescr), hdc) 
          tw = rc\right - rc\left
          th = rc\bottom - rc\top 
          If tw < WndW-4 : tw = WndW-4 : EndIf

          ResizeGadget(NLblDescr, #PB_Ignore, #PB_Ignore, tw, th) 
          ResizeGadget(NStrInput, #PB_Ignore, th+4, tw, WndH-th-36) 
;         ResizeGadget(NLblDescr, #PB_Ignore, #PB_Ignore, WndW-4, #PB_Ignore) 
;         ResizeGadget(NStrInput, #PB_Ignore, #PB_Ignore, WndW-4, WndH-th-36) 
          ResizeGadget(NBtnOk, WndW-156, WndH-28, #PB_Ignore, #PB_Ignore) 
          ResizeGadget(NBtnCancel, WndW-78, WndH-28, #PB_Ignore, #PB_Ignore) 

        Case #PB_Event_Menu
          Select EventMenu() 
            Case 27 : Break  ; leave the loop 
          EndSelect 

        Case #PB_Event_Gadget
          Select EventGadget() 
            Case NBtnOk     : result$ = GetGadgetText(NStrInput)  : Break  ; get the input and leave the loop 
            Case NBtnCancel : result$ = ""                        : Break  ; leave the loop 
          EndSelect 
      EndSelect 
    ForEver ; until break is used 
    RemoveKeyboardShortcut(NWnd, #PB_Shortcut_Escape) 
   ;RemoveKeyboardShortcut(NWnd, #PB_Shortcut_Return)  
    CloseWindow(NWnd) 
  EndIf 

  If NWndParent <> -1  
    DisableWindow(NWndParent, 0)  ; enable parent window again, now we use the main event loop 
  EndIf 

  ProcedureReturn result$  ; return the input 
EndProcedure


CompilerIf #PB_Compiler_IsMainFile 
Global ret$

Repeat 
  ret$ =  InputRequesterMultiLines("Caption", "A very long Description to describe the input data and all the needed aspects of usage."+#LF$+"second "+#LF$+"third line", "DefaultText") 
  Debug "" + ret$ 
Until ret$ = "" 

CompilerEndIf 
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).
Axolotl
Enthusiast
Enthusiast
Posts: 797
Joined: Wed Dec 31, 2008 3:36 pm

Re: Anyone did a better InputRequester module or include?

Post by Axolotl »

I was to fast...
New => This should meet your requirements.

Code: Select all

EnableExplicit 

Procedure.s InputRequesterMultiLines(Caption$, Description$, DefaultText$) 
  Protected NWnd, NWndParent, NLblDescr, NStrInput, NBtnOk, NBtnCancel  ; <== dynamic Window and Gadgets numbers start with N 
  Protected WndW, WndH, margin  
  Protected tw, th, wflag, hParent, hdc, hFont, rc.RECT  
  Protected result$ 

  NWndParent = GetActiveWindow() 
  If NWndParent <> -1 
    hParent = WindowID(NWndParent) 
    DisableWindow(NWndParent, 1)      ; <- disable parent window (because of our own event loop) 
    wflag = #PB_Window_SystemMenu | #PB_Window_WindowCentered 
  Else 
    hParent = 0 
    wflag = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 
  EndIf 

  WndW = 320    ; smallest window 
  WndH = 160    ; smallest window 
  margin = 8    ; gadget margin 

  ; calc the size of the Textgadget! 
  ; 
  hdc = GetDC_(0) 
  hFont = GetGadgetFont(#PB_Default) 
  SelectObject_(hdc, hFont) 
  rc\right = WndW - (margin << 1) 
  DrawText_(hdc, Description$, Len(Description$), @rc, #DT_CALCRECT|#DT_WORDBREAK)
  ReleaseDC_(0, hdc) 
  tw = rc\right - rc\left
  th = rc\bottom - rc\top 

  WndH = th + 20 + 28 + (margin * 3)   ; calc new window height == Text + String + Buttons + margins 

  NWnd = OpenWindow(#PB_Any, 8, 8, WndW, WndH, Caption$, wflag, hParent) 
  If NWnd ; <> 0 
    NLblDescr = TextGadget(#PB_Any, margin, 0, WndW-(margin << 1), th, Description$) 

    ; single line Input 
    ;
    NStrInput = StringGadget(#PB_Any, margin, th+margin, WndW-(margin << 1), 20, DefaultText$) 

    ; Button Line 
    ;
    NBtnOk     = ButtonGadget(#PB_Any, WndW-156, WndH-28, 76, 24, "OK") 
    NBtnCancel = ButtonGadget(#PB_Any, WndW- 78, WndH-28, 76, 24, "Cancel") 

    result$ = ""  ; init the return value 
    Repeat 
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow 
          result$ = "" 
          Break  ; bye 

        Case #WM_KEYDOWN 
          Select EventwParam() 
            Case 27 : Debug "KEYDOWN ... ESC " 
              result$ = "" 
              Break 
            Case 13 : Debug "KEYDOWN ... RETURN "  
              result$ = GetGadgetText(NStrInput) 
              Break  
          EndSelect 

        Case #PB_Event_Gadget
          Select EventGadget() 
            Case NBtnOk     : result$ = GetGadgetText(NStrInput)  : Break  ; get the input and leave the loop 
            Case NBtnCancel : result$ = ""                        : Break  ; leave the loop 
          EndSelect 
      EndSelect 
    ForEver ; until break is used 
    CloseWindow(NWnd) 
  EndIf 

  If NWndParent <> -1  
    DisableWindow(NWndParent, 0)  ; enable parent window again, now we use the main event loop 
  EndIf 

  ProcedureReturn result$  ; return the input 
EndProcedure


CompilerIf #PB_Compiler_IsMainFile 
Global ret$, message$ 

message$ = "A very long Description to describe the input data and all the needed aspects of usage. " 
Repeat 
  ret$ =  InputRequesterMultiLines("Caption", message$, "DefaultText") 
  Debug "" + ret$ 
  message$ + "On every loop, we get a longer Text with important news.... " 
Until ret$ = "" 

CompilerEndIf 
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).
User avatar
minimy
Enthusiast
Enthusiast
Posts: 551
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: Anyone did a better InputRequester module or include?

Post by minimy »

Hello, kukulcan try this, can be a solution.

Code: Select all

win= OpenWindow(#PB_Any,0,0,400,400,"test",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
tex= TextGadget(#PB_Any,0,0,400,30,"Test autoresize EditorGadget and window",#PB_Text_Center | #SS_CENTERIMAGE)
edi= EditorGadget(#PB_Any,0,30,WindowWidth(win),WindowHeight(win)-30,#PB_Editor_WordWrap)

txt.s= "Lorem ipsum dolor sit amet consectetur adipiscing elit duis cum class dictum, quis semper tincidunt magna sociosqu feugiat natoque parturient enim augue, accumsan urna nibh auctor hendrerit magnis felis arcu aptent laoreet. Facilisis vehicula dui gravida penatibus hendrerit habitasse donec lobortis eget, elementum taciti nunc potenti sem nullam class vestibulum volutpat hac, in faucibus tempor urna porttitor orci malesuada maecenas. Ante aliquet rhoncus vestibulum platea iaculis eleifend nullam consequat, scelerisque ridiculus sociosqu habitant torquent id imperdiet."
SetGadgetText(edi,txt)

l= CountGadgetItems(edi):oldl=l
hdc = GetDC_(GadgetID(edi)):tm.TEXTMETRIC:GetTextMetrics_(hdc, @tm)
slh= tm\tmHeight + tm\tmExternalLeading
ResizeWindow(win,#PB_Ignore,#PB_Ignore,#PB_Ignore,30 + slh * l):ResizeGadget(edi,#PB_Ignore,#PB_Ignore,#PB_Ignore,slh * l)

Repeat
  event= WindowEvent()
  
  Select event
    Case #PB_Event_Gadget
      eg=  EventGadget()
      et=    EventType()
      Select eg
        Case edi
          If et=#PB_EventType_Change
            l= CountGadgetItems(edi)
            If oldl<>l
              ResizeWindow(win,#PB_Ignore,#PB_Ignore,#PB_Ignore,30 + slh * l):ResizeGadget(edi,#PB_Ignore,#PB_Ignore,#PB_Ignore,slh * l)
              oldl=l
            EndIf
          EndIf
          
      EndSelect
      
    Case #PB_Event_CloseWindow
      Break
      
  EndSelect
  
ForEver
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Anyone did a better InputRequester module or include?

Post by Kukulkan »

Axolotl wrote: Mon Jun 16, 2025 2:19 pm I was to fast...
New => This should meet your requirements.
Hi Axolotl, yes, this is exactly what I needed. THANK YOU :D

Well, therefore it is impossible without using API outside of PB standard functions. Really sad. I was away from PB for a while and got the impression that Fred is also enhancing GUI functionality or at least the dialog library for modern requirements. Seems that did not happen yet. :(
minimy wrote: Mon Jun 16, 2025 7:22 pm Hello, kukulcan try this, can be a solution.
Thanks minimy, but this is not what I asked for. I don't need a multiline input field? A single line input text field is fine for me. I tried really hard to describe what I need (multiline dialog message with wordwrap and auto adapting dialog size, see all my above posts including ASCII art) but I was not able to communicate. I'm sorry.

But anyway, thanks for you help as well! :)
Quin
Addict
Addict
Posts: 1122
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Anyone did a better InputRequester module or include?

Post by Quin »

Kukulkan wrote: Tue Jun 17, 2025 7:58 am Well, therefore it is impossible without using API outside of PB standard functions. Really sad. I was away from PB for a while and got the impression that Fred is also enhancing GUI functionality or at least the dialog library for modern requirements. Seems that did not happen yet. :(
Not sure where you got this information, but the Dialog library is sadly one of the more neglected parts of PB. The IDE has a ton of dialog code in it, basically its own layer to make it actually useable for a large app, but that's not in the PB stdlib and it seems like it may never be.
User avatar
minimy
Enthusiast
Enthusiast
Posts: 551
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: Anyone did a better InputRequester module or include?

Post by minimy »

Gracias minimy, pero esto no es lo que pedí. ¿No necesito un campo de entrada multilínea? Un campo de texto de entrada de una sola línea está bien para mí. Me esforcé mucho por describir lo que necesito (mensaje de diálogo multilínea con ajuste de palabras y tamaño de diálogo que se adapta automáticamente, vea todas mis publicaciones anteriores, incluido el arte ASCII) pero no pude comunicarme. Lo siento.
My code may be the result of a combination of beers and dirty glasses, sorry! :lol:
Intention is what counts :mrgreen:
If translation=Error: reply="Sorry, Im Spanish": Endif
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4941
Joined: Sun Apr 12, 2009 6:27 am

Re: Anyone did a better InputRequester module or include?

Post by RASHAD »

Hi

Code: Select all


Text$ = "  Lorem ipsum dolor sit amet, consectetur adipisici elit, sed" +
        " eiusmod tempor incidunt ut labore et dolore magna aliqua." +
        " Ut enim ad minim veniam, quis nostrud exercitation ullamco" +
        " laboris nisi ut aliquid ex ea commodi consequat." +
        " Quis aute iure reprehenderit in voluptate velit esse" +
        " cillum dolore eu fugiat nulla pariatur." +
        " Excepteur sint obcaecat cupiditat non proident, sunt" +
        " in culpa qui officia deserunt mollit anim id est laborum."

If OpenWindow(0, 0, 0, 600, 100, "Hand Made Input Requester", #PB_Window_SystemMenu | #PB_Window_Invisible)
  EditorGadget(0, -WindowWidth(0),10, WindowWidth(0)-10,100,#PB_Editor_WordWrap)
  ContainerGadget(1,5,5,390,20,#PB_Container_Flat)
  TextGadget(2,5,0,380,20,"")
  CloseGadgetList()
  SetGadgetColor(1,#PB_Gadget_BackColor,$E6FEFE)
  SetGadgetColor(2,#PB_Gadget_BackColor,$E6FEFE)
  SetGadgetColor(2,#PB_Gadget_FrontColor,#Red)
  ;SendMessage_(GadgetID(0), #EM_SETTARGETDEVICE, #Null, 0)
  SetGadgetText(0,Text$)
  
  nLines = CountGadgetItems(0)    
  
  StartDrawing(WindowOutput(0))
  hLine = TextHeight("W")+5
  StopDrawing()
  
  SetGadgetText(2,Text$)
  FreeGadget(0)
  
  ResizeWindow(0,#PB_Ignore,#PB_Ignore,WindowWidth(0),hLine*nLines+80)
  StringGadget(3,5,hLine*nLines+15,WindowWidth(0)-10,24,"")
  ButtonGadget(4,WindowWidth(0)/2-60,hLine*nLines+48,80,24,"OK")
  ButtonGadget(5,WindowWidth(0)/2+25,hLine*nLines+48,80,24,"Cancel")
  ResizeGadget(1,5,5,WindowWidth(0)-10,hLine*nLines)
  ResizeGadget(2,5,0,WindowWidth(0)-10,hLine*nLines)
  
  HideWindow(0,0,#PB_Window_ScreenCentered)
  SetActiveGadget(3)
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Quit = 1
        
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 3
          Case 4
            Debug GetGadgetText(3)
          Case 5
            Debug "Cancel"
        EndSelect
    EndSelect                             
  Until Quit = 1
EndIf


Egypt my love
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Anyone did a better InputRequester module or include?

Post by Kukulkan »

Huh? Two days ago I posted my final dialog code and Fred did even enhance it for DPI awareness, and all is gone? I think a backup was installed after the server outage?

This is my current inputDialog function. Unfortunatelly, I did not yet copy the enhanced version of Fred.

@Fred: Can you please post your DPI enhanced version here, too?

Code: Select all

; inputDialog.pbi
; PureBasic 6.20 and possibly also before
; WINDOWS ONLY

EnableExplicit

#inpDialogEscMenu = 32767 ; ESC key menu event number
#inpDialogRetMenu = 32768 ; RETURN key menu event number

; Alternative inputDialog
;  appTitle.s      : dialog title
;  message.s       : dialog message
;  width.i         : dialog width (px), defaults to 400
;  defaultText.s   : the default to put into the text field
;  cancelResult.s  : what to return if dialog is cancelled (no NULL in PB), default to "-1". This allows "" as valid result.
Procedure.s inputDialog(appTitle.s, message.s, width.i = 400, defaultText.s = "", cancelResult.s = "-1")
  Protected inputText.s = ""
  Protected result.i = 0
  Protected NWndParent.i, hParent.i, wflag.i
  
  NWndParent.i = GetActiveWindow() 
  If NWndParent.i <> -1 
    hParent.i = WindowID(NWndParent.i) 
    DisableWindow(NWndParent.i, 1) ; <- disable parent window (because of our own event loop) 
    wflag.i = #PB_Window_Tool | #PB_Window_WindowCentered 
  Else 
    hParent = 0 
    wflag.i = #PB_Window_Tool | #PB_Window_ScreenCentered 
  EndIf
  
  ; helpers
  Protected margin.i = 12   ; generic gadget margin
  Protected gadH.i = 24     ; usual gadget height (text, buttons)
  Protected buttonW.i = 70  ; button width
  
  ; calc the size of the Textgadget! 
  Protected rc.RECT
  Protected hdc.i = GetDC_(0) 
  Protected hFont.i = GetGadgetFont(#PB_Default) 
  SelectObject_(hdc.i, hFont.i) 
  rc\right = width.i - (margin * 2)
  DrawText_(hdc.i, message.s, Len(message.s), @rc, #DT_CALCRECT|#DT_WORDBREAK)
  ReleaseDC_(0, hdc.i) 
  Protected txtHeight.i = rc\bottom - rc\top ; <- TextGadget height!
  
  ; calc final window height
  Protected WndH.i = margin + txtHeight.i + margin + gadH + margin + gadH + margin.i 

  Protected inputWin.i = OpenWindow(#PB_Any,
                                    0, 0, 
                                    width.i, WndH.i, 
                                    "   " + appTitle.s, 
                                    wflag.i, hParent.i)
  
  If inputWin.i = 0
    Debug "Failed to open dialog window!"
    ProcedureReturn cancelResult.s
  EndIf
  
  Protected labelGadget.i = TextGadget(#PB_Any, 
                                       margin, 
                                       margin, 
                                       width.i - margin * 2, 
                                       txtHeight.i, 
                                       message.s)

  Protected inputGadget.i = StringGadget(#PB_Any, 
                                         margin, 
                                         margin + txtHeight.i + margin, 
                                         width.i - margin * 2, 
                                         gadH.i, 
                                         defaultText.s)
  
  Protected okButton.i = ButtonGadget(#PB_Any, 
                                      width.i - margin.i - buttonW.i - margin.i - buttonW.i, 
                                      margin.i + txtHeight.i + margin.i + gadH.i + margin.i, 
                                      buttonW.i, 
                                      gadH.i, 
                                      "OK")
  
  Protected cancelButton.i = ButtonGadget(#PB_Any, 
                                          width.i - margin.i - buttonW.i, 
                                          margin.i + txtHeight.i + margin.i + gadH.i + margin.i, 
                                          buttonW.i, 
                                          gadH.i, 
                                          "Cancel")

  SetActiveGadget(inputGadget.i)
  
  AddKeyboardShortcut(inputWin, #PB_Shortcut_Escape, #inpDialogEscMenu)
  AddKeyboardShortcut(inputWin, #PB_Shortcut_Return, #inpDialogRetMenu)
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case okButton
            inputText.s = GetGadgetText(inputGadget.i)
            result.i = 1
            Break
          Case cancelButton
            inputText.s = ""
            result.i = 0
            Break
        EndSelect
        
      Case #PB_Event_CloseWindow
        inputText.s = ""
        result.i = 0
        Break
        
      Case #PB_Event_Menu
        Select EventMenu()
          Case #inpDialogEscMenu
            inputText.s = ""
            result.i = 0
            Break
          Case #inpDialogRetMenu
            inputText.s = GetGadgetText(inputGadget.i)
            result.i = 1
            Break
        EndSelect
    EndSelect
  ForEver
  
  RemoveKeyboardShortcut(inputWin.i, #PB_Shortcut_Escape)
  RemoveKeyboardShortcut(inputWin.i, #PB_Shortcut_Return)
  
  CloseWindow(inputWin.i)
  
  If NWndParent.i <> -1  
    DisableWindow(NWndParent.i, 0)  ; enable parent window again, now we use the main event loop 
  EndIf 
  
  If result.i = 1
    ProcedureReturn inputText.s
  EndIf
  ProcedureReturn cancelResult.s
EndProcedure

CompilerIf #PB_Compiler_IsMainFile = #True
  ; test if started from include file
  Define proxy.s = inputDialog("Testing inputDialog 1", 
                               "Enter proxy server in the following format:"+#CR$+#CR$+
                               "proxyServer:Port optionalUsername optionalPassword"+#CR$+#CR$+
                               "Supported protocols:"+#CR$+
                               "- http://    - HTTP proxy (Default)"+#CR$+
                               "- socks4://  - SOCKS4 proxy"+#CR$+
                               "- socks4a:// - SOCKS4 proxy with domain name support rather than IP address"+#CR$+
                               "- socks5://  - SOCKS5 proxy"+#CR$+
                               "- socks5h:// - SOCKS5 proxy and ask the proxy to do the hostname resolving",
                               500)
  Debug "inputDialog result: [" + proxy.s + "]"
  
  proxy.s = inputDialog("Testing inputDialog 2", 
                        "Enter proxy server:")
  Debug "inputDialog result: [" + proxy.s + "]"
CompilerEndIf
[code-pb]
Post Reply