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