Change fonts form wide sort of works

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Change fonts form wide sort of works

Post by Fangbeast »

I am using the approximate code below to change all gadgets on a form to a user's requested font and it half works.

While the program is running:

When the user answer the font requester, the first ListIconGadget contents and heading area change to the requested fonts but the second ListIconGadget only changes the heading font but not the contents???. All other gadgets change correctly.

When the program starts up:

Last user chosen font is read (from a database table) and all gadgets change correctly!

How on earth can just the heading font change in a ListIconGadget and not the contents? The exact same code is used to do it during running time and startup.

Code: Select all

; Change the user's choice of program font

Global Programfontname.s  = "Comic Sans MS"
Global Programfontsize.i  = 9
Global IsFontLoaded.i     

Procedure ChangeProgramFont()
  IsFontSelected.i     = FontRequester(Programfontname.s, Programfontsize.i, #Null) 
  If IsFontSelected.i
    Programfontname.s  = SelectedFontName()
    Programfontsize.i  = SelectedFontSize()
    If Programfontsize.i > 9
      Programfontsize.i = 9
    EndIf
    IsFontLoaded = LoadFont(#PB_Any, Programfontname.s, Programfontsize.i, #PB_Font_HighQuality)
    If IsFontLoaded
      EnumChildWindows_(WindowID(#Window_MyStuff), @ChangeAllFonts(), 0)
    Else
      MessageRequester("Display font load error", "No new font loded, unknown problem ocurred.", #MB_ICONERROR)
    EndIf
  Else
    MessageRequester("Display font selection", "No new font selected, user cancelled.", #MB_ICONWARNING)
  EndIf
EndProcedure

; Change to the user selected fonts on all gadgets and windows

Procedure ChangeAllFonts(ControlHandle, ControlParameter)
  SendMessage_(ControlHandle, #WM_SETFONT, FontID(IsFontLoaded), 0)
  InvalidateRect_(ControlHandle, 0, #True)
  ProcedureReturn #True
EndProcedure
P.S: #Window_MyStuff is my main home inventory window
Amateur Radio, D-STAR/VK3HAF
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Change fonts form wide sort of works

Post by RASHAD »

Hi Fang
It seems that I am loosing my mind :)
I think i read something else and you changed your post while I am posting :mrgreen:
Anyhow just adapt it for your needs
You can control any part of your GUI

Code: Select all

; Change the user's choice of program font

Global Programfontname.s  = "Comic Sans MS"
Global Programfontsize.i  = 9
Global IsFontLoaded.i

LoadFont(0,Programfontname.s,Programfontsize.i)

Procedure ChangeAllFonts(ControlHandle, ControlParameter)
  If ControlHandle = GadgetID(0)   ;ListIcon Gadget
    header = SendMessage_(ControlHandle, #LVM_GETHEADER, 0, 0)
    SendMessage_(header,#WM_SETFONT,FontID(IsFontLoaded),0)
  ElseIf ControlHandle = GadgetID(2)  ;ComboBox Gadget
    SendMessage_(ControlHandle, #WM_SETFONT, FontID(IsFontLoaded), 0)
    dLhwnd = FindWindow_("ComboLBox",0)
    SendMessage_(dLhwnd, #WM_SETFONT, FontID(0), 0)
  Else
    SendMessage_(ControlHandle, #WM_SETFONT, FontID(IsFontLoaded), 0)
  EndIf
  InvalidateRect_(ControlHandle, 0, #True)
  ProcedureReturn #True
EndProcedure     

Procedure ChangeProgramFont()
  IsFontSelected.i     = FontRequester(Programfontname.s, Programfontsize.i, #Null)
  If IsFontSelected.i
    Programfontname.s  = SelectedFontName()
    Programfontsize.i  = SelectedFontSize()
    If Programfontsize.i > 9
      Programfontsize.i = 9
    EndIf
    IsFontLoaded = LoadFont(#PB_Any, Programfontname.s, Programfontsize.i, #PB_Font_HighQuality)
    If IsFontLoaded
      EnumChildWindows_(WindowID(0), @ChangeAllFonts(), 0)
    Else
      MessageRequester("Display font load error", "No new font loded, unknown problem ocurred.", #MB_ICONERROR)
    EndIf
  Else
    MessageRequester("Display font selection", "No new font selected, user cancelled.", #MB_ICONWARNING)
  EndIf
EndProcedure


OpenWindow(0,0,0,800,600,"TEST",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ListIconGadget(0,10,10,780,200,"Column 0",150,#PB_ListIcon_GridLines)
AddGadgetColumn(0,1,"Column 1",150)
AddGadgetColumn(0,2,"Column 2",150)
For l = 1 To 10
    AddGadgetItem(0, -1, "Item " + Str(l)) ; Also updates header with new size
Next

ListIconGadget(1,10,220,780,200,"Column 0",150,#PB_ListIcon_GridLines)
AddGadgetColumn(1,1,"Column 1",150)
AddGadgetColumn(1,2,"Column 2",150)
For l = 1 To 10
    AddGadgetItem(1, -1, "Item " + Str(l)) ; Also updates header with new size
Next

ComboBoxGadget(2, 10, 430, 250, 24)
  For a = 1 To 5
    AddGadgetItem(2, -1,"ComboBox item " + Str(a))
  Next
SetGadgetState(2,2)

ButtonGadget(3,10,570,100,20,"Change")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 3
          ChangeProgramFont()
      EndSelect
  EndSelect
Until Quit = 1
Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Change fonts form wide sort of works

Post by Fangbeast »

RASHAD, thanks for the example but it doesn't explain why my code changes the first listicongadget and heading (and all other gadgets) but only the heading on the second when I first set the font.

But when I start the program up, all the fonts change everywhere correctly using the SAME code to do it.

Seems to make no sort of sense unless it is a lucky fluke that it did?

I will change it to yours tonight and see what happens:):)
Amateur Radio, D-STAR/VK3HAF
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Change fonts form wide sort of works

Post by Fangbeast »

RASHAD, it must be windows 10 redstone release again.

I just tried your code and only the header changed for listicon 1 but not the contents.

Listicon 2 and combox box were changed completely.
Amateur Radio, D-STAR/VK3HAF
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Change fonts form wide sort of works

Post by RASHAD »

Yes because I did that on purpose

Code: Select all

  If ControlHandle = GadgetID(0)   ;ListIcon Gadget
    header = SendMessage_(ControlHandle, #LVM_GETHEADER, 0, 0)
    SendMessage_(header,#WM_SETFONT,FontID(IsFontLoaded),0)
  ElseIf ControlHandle = GadgetID(2)  ;ComboBox Gadget
    SendMessage_(ControlHandle, #WM_SETFONT, FontID(IsFontLoaded), 0)
    dLhwnd = FindWindow_("ComboLBox",0)
    SendMessage_(dLhwnd, #WM_SETFONT, FontID(0), 0)
  Else
    SendMessage_(ControlHandle, #WM_SETFONT, FontID(IsFontLoaded), 0)
  EndIf
So I do not think it is a matter of Windows 10
So you can make sure by changing the previous code for both the ListIcon Gadgets with or without the header and let us know
Egypt my love
User avatar
Bisonte
Addict
Addict
Posts: 1232
Joined: Tue Oct 09, 2007 2:15 am

Re: Change fonts form wide sort of works

Post by Bisonte »

If you set the font with the native PB function it works....

Code: Select all

Procedure ChangeAllFonts(ControlHandle, ControlParameter)
  
  Gadget = GetProp_(ControlHandle, "PB_ID")
  If IsFont(IsFontLoaded)
    If IsGadget(Gadget)
      SetGadgetFont(Gadget, FontID(IsFontLoaded))
    EndIf
  EndIf
  InvalidateRect_(ControlHandle, 0, #True)
  ProcedureReturn #True
  
EndProcedure 
here the demo with rashad's window....
And I add a parameter to your ChangeProgramFont() procedure to allow other windows as your "#Window_MyStuff"

Code: Select all

; Change the user's choice of program font

Global Programfontname.s  = "Comic Sans MS"
Global Programfontsize.i  = 9
Global IsFontLoaded.i     

Procedure ChangeAllFonts(ControlHandle, ControlParameter)
  
  Gadget = GetProp_(ControlHandle, "PB_ID")
  If IsFont(IsFontLoaded)
    If IsGadget(Gadget)
      SetGadgetFont(Gadget, FontID(IsFontLoaded))
    EndIf
  EndIf
  InvalidateRect_(ControlHandle, 0, #True)
  ProcedureReturn #True
  
EndProcedure 

Procedure ChangeProgramFont(Window)
  If Not IsWindow(Window) : ProcedureReturn #False : EndIf
  
  IsFontSelected.i     = FontRequester(Programfontname.s, Programfontsize.i, #Null)
  If IsFontSelected.i
    Programfontname.s  = SelectedFontName()
    Programfontsize.i  = SelectedFontSize()
    If Programfontsize.i > 9
      Programfontsize.i = 9
    EndIf
    IsFontLoaded = LoadFont(#PB_Any, Programfontname.s, Programfontsize.i, #PB_Font_HighQuality)
    If IsFontLoaded
      EnumChildWindows_(WindowID(Window), @ChangeAllFonts(), 0)
    Else
      MessageRequester("Display font load error", "No new font loded, unknown problem ocurred.", #MB_ICONERROR)
    EndIf
  Else
    MessageRequester("Display font selection", "No new font selected, user cancelled.", #MB_ICONWARNING)
  EndIf
EndProcedure

; Change to the user selected fonts on all gadgets and windows

OpenWindow(0,0,0,800,600,"TEST",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ListIconGadget(0,10,10,780,200,"Column 0",150,#PB_ListIcon_GridLines)
AddGadgetColumn(0,1,"Column 1",150)
AddGadgetColumn(0,2,"Column 2",150)
For l = 1 To 10
    AddGadgetItem(0, -1, "Item " + Str(l)) ; Also updates header with new size
Next

ListIconGadget(1,10,220,780,200,"Column 0",150,#PB_ListIcon_GridLines)
AddGadgetColumn(1,1,"Column 1",150)
AddGadgetColumn(1,2,"Column 2",150)
For l = 1 To 10
    AddGadgetItem(1, -1, "Item " + Str(l)) ; Also updates header with new size
Next

ComboBoxGadget(2, 10, 430, 250, 24)
  For a = 1 To 5
    AddGadgetItem(2, -1,"ComboBox item " + Str(a))
  Next
SetGadgetState(2,2)

ButtonGadget(3,10,570,100,20,"Change")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
     
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 3
          ChangeProgramFont(0)
      EndSelect
  EndSelect
Until Quit = 1
Last edited by Bisonte on Wed May 17, 2017 8:47 am, edited 1 time in total.
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Change fonts form wide sort of works

Post by Fangbeast »

Whoops, I am silly:):)

By the way, is there any way I can get the GadgetType from the ControlHandle so that I can handle gadgets on any form and not have to specify the gadget directly?

Something like:

Code: Select all

Select GadgetType(GadgetID(ControlHandle))
  Case #PB_GadgetType_ListIcon
    header = SendMessage_(ControlHandle, #LVM_GETHEADER, 0, 0)
    SendMessage_(header, #WM_SETFONT, FontID(IsFontLoaded), 0)
  Case  #PB_GadgetType_ComboBox
    SendMessage_(ControlHandle, #WM_SETFONT, FontID(IsFontLoaded), 0)
    dLhwnd = FindWindow_("ComboLBox",0)
    SendMessage_(dLhwnd, #WM_SETFONT, FontID(0), 0)
EndSelect
I had to do this to get both listicons AND headers to change but witht he combobox, only the first item changed.

Procedure ChangeAllFonts(ControlHandle, ControlParameter)

Code: Select all

  If ControlHandle = GadgetID(0)   ;ListIcon Gadget
    header = SendMessage_(ControlHandle, #LVM_GETHEADER, 0, 0)
    SendMessage_(header,#WM_SETFONT,FontID(IsFontLoaded),0)
    SendMessage_(ControlHandle, #WM_SETFONT, FontID(IsFontLoaded), 0)
  ElseIf ControlHandle = GadgetID(1)   ;ListIcon Gadget
    header = SendMessage_(ControlHandle, #LVM_GETHEADER, 0, 0)
    SendMessage_(header,#WM_SETFONT,FontID(IsFontLoaded),0)
    SendMessage_(ControlHandle, #WM_SETFONT, FontID(IsFontLoaded), 0)
  ElseIf ControlHandle = GadgetID(2)  ;ComboBox Gadget
    SendMessage_(ControlHandle, #WM_SETFONT, FontID(IsFontLoaded), 0)
    dLhwnd = FindWindow_("ComboLBox",0)
    SendMessage_(dLhwnd, #WM_SETFONT, FontID(0), 0)
  Else
    SendMessage_(ControlHandle, #WM_SETFONT, FontID(IsFontLoaded), 0)
  EndIf
  InvalidateRect_(ControlHandle, 0, #True)
  ProcedureReturn #True
EndProcedure     
Amateur Radio, D-STAR/VK3HAF
User avatar
Bisonte
Addict
Addict
Posts: 1232
Joined: Tue Oct 09, 2007 2:15 am

Re: Change fonts form wide sort of works

Post by Bisonte »

Code: Select all

Gadget = GetProp_(ControlHandle, "PB_ID")
If IsGadget(Gadget)
  Select GadgetType(Gadget)
    Case #PB_GadgetType_ComboBox
      ...
Edit : And I edit my post above....
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Change fonts form wide sort of works

Post by Fangbeast »

This is so strange to be adding a post and then find someone else's post above me:):) (Like the twilight zone)

Thanks Bisonte. I will be allowed to play after tea:)
Amateur Radio, D-STAR/VK3HAF
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Change fonts form wide sort of works

Post by Fangbeast »

Thanks RASHAD and Bisonte. Massaged your code into MyStuff, tested it and uploaded new one to DropBox
Amateur Radio, D-STAR/VK3HAF
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Change fonts form wide sort of works

Post by Fangbeast »

Bisonte. Windows 10 build 16199 got delivered today and once again the code doesn't work properly. I am not kidding, so many things wrong with the redstone builds that I want to chuck the whole machine in the bin.

MS fixes one thing and ten others break.
Amateur Radio, D-STAR/VK3HAF
User avatar
Bisonte
Addict
Addict
Posts: 1232
Joined: Tue Oct 09, 2007 2:15 am

Re: Change fonts form wide sort of works

Post by Bisonte »

hmm my Windows 10 is Version : 1703 (Build 15063.296) and it work.

(checked with [Win+R] type winver and press enter)

Are you using an insider-build ? These one's are always "beta"....
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Change fonts form wide sort of works

Post by Fangbeast »

Bisonte wrote:hmm my Windows 10 is Version : 1703 (Build 15063.296) and it work.

(checked with [Win+R] type winver and press enter)

Are you using an insider-build ? These one's are always "beta"....
Build 16199.rs prerelease.170513-2252

yes, broken:):)
Amateur Radio, D-STAR/VK3HAF
User avatar
mk-soft
Always Here
Always Here
Posts: 5406
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Change fonts form wide sort of works

Post by mk-soft »

I have added SetAllGadgetFont(...) into my Module AGF

Code: Select all

  Procedure SetAllGadgetFont(FontID, WindowID=0)
    Protected object, item, cnt
    PB_Object_EnumerateStart(PB_Gadget_Objects)
    While PB_Object_EnumerateNext(PB_Gadget_Objects, @object)
      If WindowID = 0 Or GetParentWindowID(object) = WindowID
        SetGadgetFont(object, FontID)
      EndIf
    Wend
    
  EndProcedure
Perhaps thats right

Link: http://www.purebasic.fr/english/viewtop ... 12&t=66856
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Change fonts form wide sort of works

Post by Fangbeast »

This is frustrating

When changing the font while the program is running, only the first ListIconGadget and heading changes. The second ListIconGadget only changes the heading and NOT the contents.

When you START the program up, ALL gadgets and headings change.

I've tried various codes shown here and ALL have the same problem.

Even turned off the ListIconGadget header colouring callback to see if that interferes and no change.

Must be something in the events list trashing this complex (to me) redraw of the client area of the of the second ListiconGadget while the program is running but no problems when it starts up as it hasn't reached the event handler section yet.
Amateur Radio, D-STAR/VK3HAF
Post Reply