Object Theme Library (for Dark or Light Theme)

Share your advanced PureBasic knowledge/code with the community.
User avatar
jacdelad
Addict
Addict
Posts: 1472
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Object Theme Library (for Dark or Light Theme)

Post by jacdelad »

Nah, it's definitely not trash. Don't know why I have problems, but there will be a solution.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
fryquez
Enthusiast
Enthusiast
Posts: 367
Joined: Mon Dec 21, 2015 8:12 pm

Re: Object Theme Library (for Dark or Light Theme)

Post by fryquez »

Seems the line 1031: SendMessage_(lParam, #EM_SETSEL, -1, 0)
causes a new WM_CTLCOLOREDIT on some machines. So you will get endless recursion.

Maybe something like this could help (at least it does here).

Code: Select all

Protected low, high
SendMessage_(lParam, #EM_GETSEL, @low, @high)
If low Or high
  SendMessage_(lParam, #EM_SETSEL, -1, 0)   ; Deselect the ComboBox editable string if not the active Gadget
EndIf
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Object Theme Library (for Dark or Light Theme)

Post by ChrisR »

Thanks fryquez :)
I understand if that's the case, here it send a WM_COMMAND but not a new WM_CTLCOLOREDIT.
Can you confirm the trick jacdelad, dcr3
User avatar
jacdelad
Addict
Addict
Posts: 1472
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Object Theme Library (for Dark or Light Theme)

Post by jacdelad »

I can and will test it on monday.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
dcr3
Enthusiast
Enthusiast
Posts: 165
Joined: Fri Aug 04, 2017 11:03 pm

Re: Object Theme Library (for Dark or Light Theme)

Post by dcr3 »

I guess you don't need to be worried. :D

I tried you module in three different laptops.

Two of them the module works great, no issues.

One, the laptop that has given me issues, the windows hasn't been updated for long time.
that is Win10 64bit.

So I replaced the hard drive,on this laptop with a clean, Win10 install all issues has gone.
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Object Theme Library (for Dark or Light Theme)

Post by ChrisR »

dcr3 wrote: Fri Nov 24, 2023 8:59 pm I guess you don't need to be worried. :D
An inevitable disappointment when you've spent a bit of time on it and realize that it won't be used at all if it crashes for some people, build Windows version probably here.

I tested with Fryquez's solution and by changing "If low <> high", I'm pretty confident it will do the job. Thanks again.
In this way, SendMessage_(lParam, #EM_SETSEL, -1, 0) will be called once for each editable ComboBox and it's enough 8)

I've updated to version 1.4
And I've also added the attributes #PB_Gadget_GrayBackColor and GrayTextColor for the Editor, Spin and String. For their colors when they are disabled.
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: Object Theme Library (for Dark or Light Theme)

Post by Kuron »

@ChrisR See, no bug. You just had an undocumented feature that version checked Windows 10 to see if it was up to date! :mrgreen:
Best wishes to the PB community. Thank you for the memories. ♥️
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Object Theme Library (for Dark or Light Theme)

Post by ChrisR »

I have updated to version 1.5
ObjectTheme is no longer split into 3 parts: ObjectTheme, CreateGadget and DataSection for easy handling.
Add #PB_Gadget_HighLightBorder attribute for button and ButtonImage Gadget and revised a bit their border drawing.
JellyButtons (included in IceDesign) which are ButtonGadget, can work together with ObjectTheme ButtonGadget. A JellyButtons remains a JellyButtons and is not processed by ObjectTheme.
I'll add ObjectTheme soon in IceDesign replacing ObjectColor, as it goes further and it performs better.
User avatar
jacdelad
Addict
Addict
Posts: 1472
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Object Theme Library (for Dark or Light Theme)

Post by jacdelad »

Argh, I forgot to test: I just downloaded 1.5 and it no longer crashes for me. Thanks Chris!!!
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
jacdelad
Addict
Addict
Posts: 1472
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Object Theme Library (for Dark or Light Theme)

Post by jacdelad »

I am usually working with dialogs, not windows (which is just a matter of creation and some auto functions like auto-arranging). However, ObjectTheme does not work with it. Since you use (mostly) "normal" controls: Is there a way to adapt it to work with dialogs too? I already thought about it, and given the handle of a window you should be able to retrieve all children of it.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Object Theme Library (for Dark or Light Theme)

Post by ChrisR »

Hi jacdelad,
Thank you for your interest, it's a bit difficult here these days...

ObjectTheme should also be compatible with the Dialog library.
When calling SetObjectTheme(), gadgets are retrieved with PB_Object_Enumerate.
For dynamic windows, SetObjectTheme() must be called after each new OpenXMLDialog().
See the note below for ComboBox, its drop-down list is not painted with Dialog.
Ex:

Code: Select all

#Dialog = 0
#Xml1 = 1
#Xml2 = 2

; Note: For ObjectTheme ComboBox, #CBS_HASSTRINGS | #CBS_OWNERDRAWFIXED flags should be added to have the drop-down list painted.
;       But I don't know how they could be added with XML dialog, they must be added at creation time but the Dialog library does not accept them.
;       And it does not work if they are added later With SetWindowLongPtr_()  

XIncludeFile "ObjectTheme.pbi"
UseModule ObjectTheme

XML1$ = "<window id='1' name='test1' text='test1' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
        "  <panel>" +
        "    <tab text='Premier Onglet'>" +
        "      <vbox expand='item:2'>" +
        "        <hbox>" +
        "          <button id='0' text='Bouton 1'/>" +
        "          <checkbox id='1' text='Case à cocher 1'/>" +
        "          <button id='2' text='Bouton 2'/>" +
        "        </hbox>" +
        "        <editor id='3' text='Contenu...' height='150'/>" +
        "      </vbox>" +
        "    </tab>" +
        "    <tab text='Second Onglet'>" +
        "      <vbox expand='No'>" +
        "        <combobox id='4' Height='28' flags='#PB_ComboBox_Editable'/>" +
        "        <string id='5' text='String' height='24'/>" +
        "        <progressbar id='6' height='25' min='1' max='100' value='66'/>" +
        "        <trackbar id='7' invisible='No' Flags='#PB_TrackBar_Ticks' height='25' min='1' max='100' value='66'/>"+
        "        <hbox>" +
        "          <option id='8' text='option 1' name='option1'/>"+
        "          <option id='9' text='option 2' name='option2'/>"+
        "        </hbox>" +
        "      </vbox>" +
        "    </tab>" +
        "  </panel>" +
        "</window>"

XML2$ = "<window id='2' name='test2' text='Gridbox' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
        "    <gridbox columns='5' rowexpand='yes'>" +
        "          <button text='Bouton 1' />" +
        "          <button text='Bouton 2' />" +
        "          <button text='Bouton 3' colspan='3' />" +
        "          <button text='Bouton 4' rowspan='2' />" +
        "          <button text='Bouton 5' />" +
        "          <button text='Bouton 6' />" +
        "          <button text='Bouton 7' />" +
        "          <button text='Bouton 8' />" +
        "          <button text='Bouton 9' />" +
        "          <button text='Bouton 10' />" +
        "    </gridbox>" +
        "  </window>"

If ParseXML(#Xml1, XML1$) And XMLStatus(#Xml1) = #PB_XML_Success 
  If ParseXML(#Xml2, XML2$) And XMLStatus(#Xml2) = #PB_XML_Success
    
    If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml1, "test1")
      For i = 1 To 5
        AddGadgetItem(4, -1,"Combo Element : " + Str(i))
      Next
      SetGadgetState(4, 0)
      SetGadgetState(8, 1)
      SetObjectTheme(#ObjectTheme_DarkBlue)
      SetGadgetColor(6, #PB_Gadget_FrontColor, $005636)   ; Or SetObjectColor(6, #PB_Gadget_FrontColor, $005636). To do after SetObjectTheme
      
      Repeat
        Select WaitWindowEvent()
          Case #PB_Event_CloseWindow
            If EventWindow() = 1
              OpenXMLDialog(#Dialog, #Xml2, "test2")
              CloseWindow(1)
              SetObjectTheme(#ObjectTheme_DarkBlue)   ; For dynamic Dialog, SetObjectTheme() must be added after each OpenXMLDialog()
            Else               
              Break
            EndIf
          Case #PB_Event_Gadget
        EndSelect
      ForEver 
      
    Else  
      Debug "Dialog error: " + DialogError(#Dialog)
    EndIf
  Else
    Debug "XML2 error: " + XMLError(#Xml2) + " (Line: " + XMLErrorLine(#Xml2) + ")"
  EndIf
Else
  Debug "XML1 error: " + XMLError(#Xml1) + " (Line: " + XMLErrorLine(#Xml1) + ")"
EndIf
User avatar
jacdelad
Addict
Addict
Posts: 1472
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Object Theme Library (for Dark or Light Theme)

Post by jacdelad »

Ah yes, now it worked. Very nice! Unfortunately it doesn't paint the statusbar, has this been mentioned before?
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Object Theme Library (for Dark or Light Theme)

Post by ChrisR »

Yes, I'm aware that nothing has been done for the Menu, ToolBar and StatusBar.
For ToolBar, it uses the window's background color but keeps the default black text color, which isn't great at all for a dark background.
If anyone tells me how to paint the Menu, ToolBar or StatusBar, I'll be happy to add them.
User avatar
jacdelad
Addict
Addict
Posts: 1472
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Object Theme Library (for Dark or Light Theme)

Post by jacdelad »

I can't help you with that. For me, I use my Ribbon-Menu which can be colored to my liking.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Jeromyal
Enthusiast
Enthusiast
Posts: 208
Joined: Wed Jul 17, 2013 8:49 am

Re: Object Theme Library (for Dark or Light Theme)

Post by Jeromyal »

Thank you so much for this ChrisR !
Post Reply