SetStatusBarFieldMode

Linux specific forum
User avatar
mk-soft
Always Here
Always Here
Posts: 6246
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

SetStatusBarFieldMode

Post by mk-soft »

Changes the text output mode in the statusbar field.

Side effect:
The size of the window is no longer automatically adapted to the statusbar.

Update v1.01.3

Code: Select all

;-TOP by mk-soft, v1.01.3, 16.06.2024, LGPL

; Link: https://www.purebasic.fr/english/viewtopic.php?t=84557

ImportC ""
  gtk_label_set_ellipsize(Label, Mode)
EndImport

Enumeration
  #PANGO_ELLIPSIZE_NONE
  #PANGO_ELLIPSIZE_START
  #PANGO_ELLIPSIZE_MIDDLE
  #PANGO_ELLIPSIZE_END
EndEnumeration

Procedure SetStatusBarFieldMode(StatusBar, Item, Mode)
  Protected *widget, *list.glist, *frame, *label, *name, cnt
  
  *widget = StatusBarID(StatusBar)
  *list = gtk_container_get_children_(*widget)
  If *list
    cnt = g_list_length_(*list)
    If Item >= cnt
      g_list_free_(*list)
      ProcedureReturn #False
    EndIf
    *frame = g_list_nth_data_(*list, Item)
    g_list_free_(*list)
    If Not *frame
      ProcedureReturn #False
    EndIf
    *list = gtk_container_get_children_(*frame)
    If *list
      *label = g_list_nth_data_(*list, 0)
      g_list_free_(*list)
      If Not *label
        ProcedureReturn #False
      EndIf
      *name = gtk_widget_get_name_(*label)
      If *name And PeekS(*name, -1, #PB_UTF8) = "GtkLabel"
        gtk_label_set_ellipsize(*label, Mode)
        ProcedureReturn #True
      EndIf
    EndIf
  EndIf
  ProcedureReturn #False
EndProcedure

; ********

CompilerIf #PB_Compiler_IsMainFile
  
  ;-Example
  
  Procedure UpdateWindow()
    Protected dx, dy
    dx = WindowWidth(0)
    dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
    ; Resize Gadgets
  EndProcedure
  
  Procedure Main()
    Protected dx, dy
    
    #WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
    
    If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 400, "Test Window", #WinStyle)
      ; MenuBar
      CreateMenu(0, WindowID(0))
      MenuTitle("File")
      MenuItem(99, "Exit")
      
      ; StatusBar
      CreateStatusBar(0, WindowID(0))
      AddStatusBarField(100)
      AddStatusBarField(#PB_Ignore)
      SetStatusBarFieldMode(0, 0, #PANGO_ELLIPSIZE_END)
      SetStatusBarFieldMode(0, 1, #PANGO_ELLIPSIZE_MIDDLE)
      
      ; Gadgets
      dx = WindowWidth(0)
      dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
      
      ; Bind Events
      BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
      
      StatusBarText(0, 0, " Program: " + ProgramFilename() + " ")
      StatusBarText(0, 1, " Documents: " + GetUserDirectory(#PB_Directory_Documents) + " ")
      
      ; Main Loop
      Repeat
        Select WaitWindowEvent()
          Case #PB_Event_CloseWindow
            Select EventWindow()
              Case 0
                Break
            EndSelect
            
          Case #PB_Event_Menu
            Select EventMenu()
              Case 99
                Break
                
            EndSelect
            
          Case #PB_Event_Gadget
            Select EventGadget()
                
            EndSelect
            
        EndSelect
      ForEver
      
    EndIf
    
  EndProcedure : Main()
  
CompilerEndIf
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