How do I put a Shifted Return in a Stringgadget

Just starting out? Need help? Post your questions and find answers here.
leodh
Enthusiast
Enthusiast
Posts: 164
Joined: Sun Nov 06, 2005 6:07 am
Location: Perth Western Australia

How do I put a Shifted Return in a Stringgadget

Post by leodh »

Hi,

I am writing a input program for work and want to be able to control the lenght of text on a line in a multiline Stringgadget - 12 characters ( This is so when it is printed out it should look the same as on the screen ) and make it insert a shifted return and to drop the cursor to the beginning of the next line for more text to be entered or stop and tell the user that there is no more space to enter data ( 60 characters max has been reached. )

This is what I have so far but I am now stuck. I have taken out the input part as the rest of it is far to long to put here and is not related to the stringgadget problem.

Code: Select all

Global Well.l
Global Sample.l
Global Dim Paste.s(96)

OpenWindow(0,0,0,1010,660,"Grid input",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)

CreateGadgetList(WindowID(0))

Well = 0    
For Column = 1 To 12
  For Row = 1 To 8
    Well = B + Row
    StringGadget(Well,(Column * 80)-50,(Row * 75)-55,80,75,"", #ES_MULTILINE|#ESB_DISABLE_LEFT|#ESB_DISABLE_RIGHT) 
    SendMessage_(GadgetID(well),#EM_SETREADONLY,1,0)
  Next Row
  B = B + 8
Next Column

For t= 1 To 12
  TextGadget(100+t,(t*80)-15,5,40,15,Str(t))
Next t  
For t = 1 To 8
  TextGadget(112+t,10,(t*75)-25,15,75,Chr(64+t))
Next t

CreateMenu(0, WindowID(0))
  MenuTitle("Edit")
    MenuItem(1,"Copy")
    MenuItem(2,"Paste")
    MenuItem(3,"Clear Grid")
  MenuTitle("Print")
    MenuItem(4,"Print") 
  MenuTitle("Quit")
  MenuTitle("About")
   
Repeat
  Event = WaitWindowEvent()
  
  Select Event
    
    Case #PB_Event_Gadget
      
      Select EventGadget()
        
        Case 1 To 96
          sample = EventGadget()
          Quit = 0
          C = (Sample/8)+1
          R.f = ((sample/8)-Int(Sample/8))*8
          If R = 0
            R = 8
          EndIf  
          
          Select EventType()
            
            Case #PB_EventType_Focus
              SetGadgetColor(sample,#PB_Gadget_BackColor,RGB(251, 149, 4))
              OpenWindow(1,0,0,150,150,"",#PB_Window_ScreenCentered|#PB_Window_BorderLess )
                StickyWindow(1,1)
                SetWindowColor(1,RGB(234,56,34)) 
                CreateGadgetList(WindowID(1))
                  StringGadget(500, 35, 10, 80, 75,"",#ES_MULTILINE|#ESB_DISABLE_LEFT|#ESB_DISABLE_RIGHT)
                  ButtonGadget(501, 80,120, 60, 20,"Enter")
                  ButtonGadget(502, 10,120, 60, 20,"Clear")
                  TextGadget  (503, 10, 95,135,20,"Use Shift Enter for new line.")
                  SetGadgetColor(503,#PB_Gadget_BackColor,RGB(234,56,34))
                  SetGadgetColor(503,#PB_Gadget_FrontColor,RGB(255, 255, 0))
                  
                  SetGadgetText(500,GetGadgetText(Sample))
                  SetActiveGadget(500)
              Repeat
                EventID = WaitWindowEvent()
                If EventID = #PB_Event_Gadget
                  
                  Select EventGadget()
                    
                    Case 501
                      If Len(GetGadgetText(500)) > 0 And Len(GetGadgetText(500)) < 61
                        SetGadgetText(Sample,GetGadgetText(500))
                        SetGadgetColor(sample,#PB_Gadget_BackColor,GetSysColor_(#COLOR_3DFACE))
                      Else
                        MessageRequester(" INPUT ERROR ! ","Incorrect Input. " + Chr(10) + Chr(10) + "Must be between 1 and 60 characters long.",0)
                        SetGadgetColor(sample,#PB_Gadget_BackColor,GetSysColor_(#COLOR_3DFACE))
                      EndIf     
                      Quit = 1
                   
                   Case 502
                     SetGadgetText(Sample,"")
                     SetGadgetColor(sample,#PB_Gadget_BackColor,GetSysColor_(#COLOR_3DFACE))
                     Quit = 1
                       
                  EndSelect
                  
                  EndIf
                  NR.s = Chr(10) + Chr(13) 
                  If EventID = 256
                    If GetActiveGadget() = 500
                      K = K + 1
                      If K > 11
                        T$ = GetGadgetText(500) 
                        t$ =  t$ + Chr(16) + Chr(13)+ Chr(10)
                        SetGadgetText(500,T$)
                        K=0
                      EndIf  
                    EndIf
                  EndIf
              Until quit = 1
              CloseWindow(1)
          EndSelect
          
      EndSelect
      
    Case #PB_Event_Menu

      Select EventMenu()
        
        Case 1
          SetClipboardText("")
          NR.s = Chr(13) + Chr(10)
          Copy.s = ""
          For t = 1 To 96
            Copy.s = Copy.s + GetGadgetText(t) + NR.s
          Next t
          SetClipboardText(Copy.s)
          
        Case 2
          NumberofSamples.l =1
          Text$ = GetClipboardText()
          ClipData$ = GetClipboardText()
          For t = 1 To Len(ClipData$)
            A$ = Mid(ClipData$, t, 1)
            If A$ = Chr(13) 
              A$ = ""
              NumberofSamples.l = NumberofSamples.l + 1
              B$ = ""
              DataColumn = 1
            EndIf
            If A$ = Chr(10) 
              A$ = ""
            EndIf
            B$ = B$ + A$
            Paste.s(NumberofSamples.l) = B$
          Next t
          For t= 1 To 96
          SetGadgetText(t,Paste.s(t))
          Next t
          
        Case 3
          For t= 1 To 96
            SetGadgetText(t,"")
          Next t
          
       Case 4
        ;Gosub PrintSheet   
              
      EndSelect
    
  EndSelect
  
Until Event = #PB_Event_CloseWindow
End
I do not want to force the font type used because they are hard to read on some screen that we will be using.

Hope someone can help me with this.

Regards
Leo
Regards
Leo
thearr
User
User
Posts: 21
Joined: Sun Apr 26, 2009 3:18 am
Location: RU

Post by thearr »

Hope it could be usefull as a starting point:

Code: Select all

Global *WndProc

Procedure StringGadgetCallback(hwnd, uMsg, wParam, lParam)
  If uMsg = #WM_CHAR
    If wParam <> #CR And wParam <> #VK_BACK
      If (Len(GetGadgetText(0))+1) % 14 = 13
        SendMessage_(hwnd, uMsg, #CR, lParam)
      EndIf
    EndIf
  EndIf
  ProcedureReturn CallWindowProc_(*WndProc, hwnd, uMsg, wParam, lParam)
EndProcedure
  
WinID = OpenWindow(0, 0, 0, 300, 300, "String gadget: 5 lines per 12 simbols", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
GadID = StringGadget(0, 0, 0, 300, 300, "", #ES_MULTILINE)
SendMessage_(GadID, #EM_LIMITTEXT, 14*5, 0)
  
*WndProc = SetWindowLong_(GadID, #GWL_WNDPROC, @StringGadgetCallback())
Repeat : Until WindowEvent() = #PB_Event_CloseWindow
Ceterum censeo Carthaginem esse delendam!
leodh
Enthusiast
Enthusiast
Posts: 164
Joined: Sun Nov 06, 2005 6:07 am
Location: Perth Western Australia

Post by leodh »

@ thearr

Thanks, that seems to work great, I dont understand it all but that does not matter. The only question that I have is, what is lParam for ?

Anyway thanks again.
Regards
Leo
thearr
User
User
Posts: 21
Joined: Sun Apr 26, 2009 3:18 am
Location: RU

Post by thearr »

With WM_CHAR lParam
Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table (MSDN).
Ceterum censeo Carthaginem esse delendam!
Post Reply