It is currently Mon Nov 20, 2017 1:02 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 27 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: [Given up to peer pressure] String Gadget ReadOnly
PostPosted: Sat Sep 16, 2017 6:06 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1023
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: [Given up to peer pressure] String Gadget ReadOnly
PostPosted: Sat Sep 16, 2017 2:01 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5686
Location: Wales, UK
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!

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Given up to peer pressure] String Gadget ReadOnly
PostPosted: Sat Sep 16, 2017 4:14 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Mar 21, 2006 12:31 am
Posts: 1773
Location: Canada
Yes.. Setting the text colour before, or after disabling the gadget.. does nothing. It turns grey when you disable the gadget.

_________________
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley


Top
 Profile  
Reply with quote  
 Post subject: Re: [Given up to peer pressure] String Gadget ReadOnly
PostPosted: Sat Sep 16, 2017 8:04 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5686
Location: Wales, UK
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:
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

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Given up to peer pressure] String Gadget ReadOnly
PostPosted: Sun Sep 17, 2017 1:29 am 
Offline
Addict
Addict
User avatar

Joined: Mon Oct 26, 2015 2:55 am
Posts: 887
Location: Ukraine
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.

_________________
Time beyond time

Like a copyleft notify: all the source code created by me and posted on Purebasic official forums is free to use and modification in all possible (and several impossible) ways for anyone, without asking my permission


Top
 Profile  
Reply with quote  
 Post subject: Re: [Given up to peer pressure] String Gadget ReadOnly
PostPosted: Sun Sep 17, 2017 4:47 am 
Offline
Addict
Addict
User avatar

Joined: Tue Mar 21, 2006 12:31 am
Posts: 1773
Location: Canada
If you only care for Windows-specific version... It is easy to have something matching all your criteria.

Code:
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

_________________
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley


Top
 Profile  
Reply with quote  
 Post subject: Re: [Given up to peer pressure] String Gadget ReadOnly
PostPosted: Sun Sep 17, 2017 5:02 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1023
Nice one, Thunder93. That's the subclassing that I meant. :)


Top
 Profile  
Reply with quote  
 Post subject: Re: [Given up to peer pressure] String Gadget ReadOnly
PostPosted: Sun Sep 17, 2017 5:07 am 
Offline
Addict
Addict
User avatar

Joined: Tue Mar 21, 2006 12:31 am
Posts: 1773
Location: Canada
Thanks Dude :)

_________________
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley


Top
 Profile  
Reply with quote  
 Post subject: Re: [Given up to peer pressure] String Gadget ReadOnly
PostPosted: Sun Sep 17, 2017 12:42 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5686
Location: Wales, UK
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).

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Given up to peer pressure] String Gadget ReadOnly
PostPosted: Sun Sep 17, 2017 1:22 pm 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1023
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. ;)


Top
 Profile  
Reply with quote  
 Post subject: Re: [Given up to peer pressure] String Gadget ReadOnly
PostPosted: Sun Sep 17, 2017 4:49 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5686
Location: Wales, UK
Oh well, it's not applicable in my case anyway. :D

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Given up to peer pressure] String Gadget ReadOnly
PostPosted: Sun Sep 17, 2017 5:45 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Mar 21, 2006 12:31 am
Posts: 1773
Location: Canada
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:
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

_________________
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 27 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye