Page 2 of 2

Re: [Given up to peer pressure] String Gadget ReadOnly

Posted: Sat Sep 16, 2017 6:06 am
by Dude
Thunder93 wrote:I don't like the fact it greys out the text colour and making it very difficult to see.
Well, perhaps the StringGadget can be subclassed to prevent tabbing to it and selecting the text?

Re: [Given up to peer pressure] String Gadget ReadOnly

Posted: Sat Sep 16, 2017 2:01 pm
by IdeasVacuum
If the StringGadget is disabled, there are no events from it. My actual work-around is to use Win Api to hold the Z-level of an Image Gadget over the StringGadget - so the string text is inaccessible and the ImageGadget() events can be used.

If you want to disable a StringGadget but don't like the greyed-out look, you can disable, then set the front and back colours!

Re: [Given up to peer pressure] String Gadget ReadOnly

Posted: Sat Sep 16, 2017 4:14 pm
by Thunder93
Yes.. Setting the text colour before, or after disabling the gadget.. does nothing. It turns grey when you disable the gadget.

Re: [Given up to peer pressure] String Gadget ReadOnly

Posted: Sat Sep 16, 2017 8:04 pm
by IdeasVacuum
You are right Thunderbird93 - I'm sure that trick used to work......... :?

Anyhow, snippet below showing the mask method, with or without a change of colour:

Code: Select all

Enumeration
#Win
#StrGdt
#ImgGdtMask
#Mask
#BtnDisable
EndEnumeration

CreateImage(#Mask, 214, 38, 32, #PB_Image_Transparent)

Procedure DisableStrGdt()
;#-----------------------

             ;SetGadgetColor(#StrGdt, #PB_Gadget_BackColor, RGB(228,228,228)) ;If required
                  HideGadget(#ImgGdtMask, #False)
               SetWindowPos_(GadgetID(#ImgGdtMask), #HWND_TOP, 0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED)
EndProcedure

Procedure Win()
;#-------------

              If OpenWindow(#Win, 0, 0, 230, 110, "StringGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

                         StringGadget(#StrGdt,      8, 14, 214, 38, "STRING GADGET TEXT", #ES_CENTER)
                          ImageGadget(#ImgGdtMask,  8, 14, 214, 38, ImageID(#Mask)) : HideGadget(#ImgGdtMask, #True)
                         ButtonGadget(#BtnDisable, 10, 60, 212, 40, "Disable")
                       SetGadgetColor(#StrGdt, #PB_Gadget_FrontColor, RGB(5,5,5))
                       SetGadgetColor(#StrGdt, #PB_Gadget_BackColor, RGB(128,255,128))
                      BindGadgetEvent(#BtnDisable, @DisableStrGdt(), #PB_EventType_LeftClick)
              EndIf
EndProcedure

Procedure Wait()
;#--------------
              Repeat
              Until WaitWindowEvent(1) = #PB_Event_CloseWindow
EndProcedure

 Win()
Wait()
End

Re: [Given up to peer pressure] String Gadget ReadOnly

Posted: Sun Sep 17, 2017 1:29 am
by Lunasole
IdeasVacuum wrote:In Read Only mode, the User cannot edit the text in the Gadget.

I think that mode should also:

1) Not switch the mouse cursor to the text cursor;
2) Not allow text selection (for copy to the clipboard)
Well that read only mode acts like it should and is typical for windows controls.
I don't think PB should change something with it. You can hide mouse cursor using WinAPI (HideCaret function if I'm not wrong), there is also something to disable selection, also tab switching can be changed or disabled.

Re: [Given up to peer pressure] String Gadget ReadOnly

Posted: Sun Sep 17, 2017 4:47 am
by Thunder93
If you only care for Windows-specific version... It is easy to have something matching all your criteria.

Code: Select all

Global oldStringGadgetProc

Procedure.i StringGadgetProc(hWnd, uMsg, wParam, lParam)
  Protected result
  Select uMsg
    Case #WM_CONTEXTMENU
      result = 0
    Default
      result = CallWindowProc_(oldStringGadgetProc, hWnd, uMsg, wParam, lParam)
  EndSelect
  ProcedureReturn result
EndProcedure

OpenWindow(0,200,200,400,70,"test",#PB_Window_SystemMenu)

ButtonGadget(1,10,20,60,25,"Allow tab")

ButtonGadget(2,80,20,60,25,"Allow tab")

StringGadget(3,150,20,230,25,"Can't tab here or select this text", #PB_String_ReadOnly)
oldStringGadgetProc = SetWindowLongPtr_(GadgetID(3), #GWL_WNDPROC, @StringGadgetProc())

SetGadgetColor(3, #PB_Gadget_BackColor, RGB(255,255,255))

SetActiveGadget(1)

Repeat
  Event = WaitWindowEvent()
  
  Select Event
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 3 
          Select EventType()
            Case #PB_EventType_Focus
              SetActiveGadget(1)
          EndSelect
      EndSelect
  EndSelect
Until Event=#PB_Event_CloseWindow

Re: [Given up to peer pressure] String Gadget ReadOnly

Posted: Sun Sep 17, 2017 5:02 am
by Dude
Nice one, Thunder93. That's the subclassing that I meant. :)

Re: [Given up to peer pressure] String Gadget ReadOnly

Posted: Sun Sep 17, 2017 5:07 am
by Thunder93
Thanks Dude :)

Re: [Given up to peer pressure] String Gadget ReadOnly

Posted: Sun Sep 17, 2017 12:42 pm
by IdeasVacuum
I get the jist of it Thunderbird93, but it's not working on my machine........ both buttons have the same label, neither allows text selection. In any mode, I need an event from the StringGadget if the User clicked it (hence my code snippet above).

Re: [Given up to peer pressure] String Gadget ReadOnly

Posted: Sun Sep 17, 2017 1:22 pm
by Dude
IdeasVacuum wrote:both buttons have the same label, neither allows text selection.
The buttons are named "Allow tab" to show that you can tab to those buttons only; NOT to allow tabbing to the StringGadget. ;)

Re: [Given up to peer pressure] String Gadget ReadOnly

Posted: Sun Sep 17, 2017 4:49 pm
by IdeasVacuum
Oh well, it's not applicable in my case anyway. :D

Re: [Given up to peer pressure] String Gadget ReadOnly

Posted: Sun Sep 17, 2017 5:45 pm
by Thunder93
It was only to demonstrate how we think a Read-Only gadget like StringField should be like. Didn't realize you wanted me to include also the bells and whistles. :twisted:

Code: Select all

Global oldStringGadgetProc, DisableStrGdt

Procedure.i StringGadgetProc(hWnd, uMsg, wParam, lParam)
  Protected result
  Select uMsg
    Case #WM_CONTEXTMENU      
      If DisableStrGdt : result = 0 : ProcedureReturn result : EndIf      
      result = CallWindowProc_(oldStringGadgetProc, hWnd, uMsg, wParam, lParam)
    Default
      result = CallWindowProc_(oldStringGadgetProc, hWnd, uMsg, wParam, lParam)
  EndSelect
  
  ProcedureReturn result
EndProcedure

Procedure DisableStrGdt()
  
  If Not DisableStrGdt
    DisableStrGdt = 1
    
    SetGadgetText(2, "Normal")
    
    SetGadgetColor(3, #PB_Gadget_BackColor, RGB(128,255,128))
    
  Else
    
    DisableStrGdt = 0
    
    SetGadgetText(2, "ReadOnly")
    
    SetGadgetColor(3, #PB_Gadget_BackColor, #PB_Default)    

  EndIf
  
EndProcedure


OpenWindow(0,200,200,400,70,"test",#PB_Window_SystemMenu)

ButtonGadget(2,80,20,60,25,"ReadOnly")

StringGadget(3,150,20,230,25,"STRING GADGET TEXT", #ES_CENTER)

oldStringGadgetProc = SetWindowLongPtr_(GadgetID(3), #GWL_WNDPROC, @StringGadgetProc())

BindGadgetEvent(2, @DisableStrGdt(), #PB_EventType_LeftClick)

SetActiveGadget(2)

Repeat
  Event = WaitWindowEvent()
  
  Select Event
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 3 
          Select EventType()
            Case #PB_EventType_Focus
              If DisableStrGdt
                SetActiveGadget(2)
              EndIf              
          EndSelect
      EndSelect
  EndSelect
Until Event=#PB_Event_CloseWindow