RichardL wrote:Would it be possible to colour the TAB on the panel gadget so the current one is clearly distinguishable?
You mean something like this (please run the code) ?
Code: Select all
;{- Enumerations / DataSections
;{ Windows
Enumeration
#Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
#Panel_0_0
EndEnumeration
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Procedure.l PanelTabsCallback(hwnd.l, message.l, wParam.l, lParam.l) ; PanelGadget subclassing callback
Protected ReturnValue.l, TheTextBuffer.s, tab.TC_ITEM, ItemRect.RECT, I.l, TextColor.l
Shared OldPanelCallback
If OldPanelCallback
ReturnValue = CallWindowProc_(OldPanelCallback, hwnd, message, wParam, lParam)
If message = #WM_ERASEBKGND
For I = 0 To CountGadgetItems(GetDlgCtrlID_(hwnd)) - 1
TheTextBuffer = Space(255)
tab\mask = #TCIF_TEXT
tab\pszText = @TheTextBuffer
tab\cchTextMax = 255
SendMessage_(hwnd, #TCM_GETITEM, I, @tab)
SendMessage_(hwnd, #TCM_GETITEMRECT, I, @ItemRect.RECT)
ItemRect\left = ItemRect\left + 4
If GetGadgetState(GetDlgCtrlID_(hwnd))= I
ItemRect\top = ItemRect\top + 2
TextColor = #Red
Else
ItemRect\top = ItemRect\top + 4
TextColor = #Black
EndIf
DC = GetDC_(hwnd)
SetBkMode_(DC, #TRANSPARENT)
SelectObject_(DC, GetGadgetFont(GetDlgCtrlID_(hwnd)))
SetTextColor_(DC, TextColor)
SetBkColor_(DC, GetSysColor_(#COLOR_BTNFACE))
DrawText_(DC, TheTextBuffer, Len(TheTextBuffer), @ItemRect, dtFlags)
ReleaseDC_(DC, hwnd)
Next
;
ReturnValue = #True
EndIf
EndIf
ProcedureReturn ReturnValue
EndProcedure
Procedure OpenWindow_Window_0()
Shared OldPanelCallback
If OpenWindow(#Window_0, 450, 200, 400, 400, "Highlite current tab", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
If CreateGadgetList(WindowID(#Window_0))
PanelGadget(#Panel_0_0, 24, 31, 355, 345) ;>
; Tab #1
AddGadgetItem(#Panel_0_0, -1, "Tab #1")
; Tab #2
AddGadgetItem(#Panel_0_0, -1, "Tab #2")
; Tab #3
AddGadgetItem(#Panel_0_0, -1, "Tab #3")
; Tab #4
AddGadgetItem(#Panel_0_0, -1, "Tab #4")
; Tab #5
AddGadgetItem(#Panel_0_0, -1, "Tab #5")
CloseGadgetList() ;<
SetWindowLong_(GadgetID(#Panel_0_0), #GWL_STYLE, GetWindowLong_(GadgetID(#Panel_0_0), #GWL_STYLE) | #TCS_OWNERDRAWFIXED)
OldPanelCallback = SetWindowLong_(GadgetID(#Panel_0_0), #GWL_WNDPROC, @PanelTabsCallback())
EndIf
EndIf
EndProcedure
OpenWindow_Window_0()
;{- Event loop
Repeat
Event = WaitWindowEvent()
Select Event
; ///////////////////
Case #PB_Event_Gadget
EventGadget = EventGadget()
EventType = EventType()
If EventGadget = #Panel_0_0
EndIf
; ////////////////////////
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = #Window_0
CloseWindow(#Window_0)
Break
EndIf
EndSelect
ForEver
;
;}
or this :
Code: Select all
;{- Enumerations / DataSections
;{ Windows
Enumeration
#Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
#Panel_0_0
EndEnumeration
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Procedure.l PanelTabsCallback(hwnd.l, message.l, wParam.l, lParam.l) ; PanelGadget subclassing callback
Protected ReturnValue.l, TheTextBuffer.s, tab.TC_ITEM, ItemRect.RECT, I.l, TextColor.l, BackColor.l
Shared OldPanelCallback
If OldPanelCallback
ReturnValue = CallWindowProc_(OldPanelCallback, hwnd, message, wParam, lParam)
If message = #WM_ERASEBKGND
For I = 0 To CountGadgetItems(GetDlgCtrlID_(hwnd)) - 1
TheTextBuffer = Space(255)
tab\mask = #TCIF_TEXT
tab\pszText = @TheTextBuffer
tab\cchTextMax = 255
SendMessage_(hwnd, #TCM_GETITEM, I, @tab)
SendMessage_(hwnd, #TCM_GETITEMRECT, I, @ItemRect.RECT)
ItemRect\left = ItemRect\left + 4
If GetGadgetState(GetDlgCtrlID_(hwnd))= I
ItemRect\top = ItemRect\top + 2
TextColor = GetSysColor_(#COLOR_BTNFACE)
BackColor = GetSysColor_(#COLOR_BTNTEXT)
Else
ItemRect\top = ItemRect\top + 4
TextColor = GetSysColor_(#COLOR_BTNTEXT)
BackColor = GetSysColor_(#COLOR_BTNFACE)
EndIf
DC = GetDC_(hwnd)
SelectObject_(DC, GetGadgetFont(GetDlgCtrlID_(hwnd)))
SetTextColor_(DC, TextColor)
SetBkColor_(DC, BackColor)
DrawText_(DC, TheTextBuffer, Len(TheTextBuffer), @ItemRect, 0)
ReleaseDC_(DC, hwnd)
Next
;
ReturnValue = #True
EndIf
EndIf
ProcedureReturn ReturnValue
EndProcedure
Procedure OpenWindow_Window_0()
Shared OldPanelCallback
If OpenWindow(#Window_0, 450, 200, 400, 400, "Highlite current tab", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
If CreateGadgetList(WindowID(#Window_0))
PanelGadget(#Panel_0_0, 24, 31, 355, 345) ;>
; Tab #1
AddGadgetItem(#Panel_0_0, -1, "Tab #1")
; Tab #2
AddGadgetItem(#Panel_0_0, -1, "Tab #2")
; Tab #3
AddGadgetItem(#Panel_0_0, -1, "Tab #3")
; Tab #4
AddGadgetItem(#Panel_0_0, -1, "Tab #4")
; Tab #5
AddGadgetItem(#Panel_0_0, -1, "Tab #5")
CloseGadgetList() ;<
SetWindowLong_(GadgetID(#Panel_0_0), #GWL_STYLE, GetWindowLong_(GadgetID(#Panel_0_0), #GWL_STYLE) | #TCS_OWNERDRAWFIXED)
OldPanelCallback = SetWindowLong_(GadgetID(#Panel_0_0), #GWL_WNDPROC, @PanelTabsCallback())
EndIf
EndIf
EndProcedure
OpenWindow_Window_0()
;{- Event loop
Repeat
Event = WaitWindowEvent()
Select Event
; ///////////////////
Case #PB_Event_Gadget
EventGadget = EventGadget()
EventType = EventType()
If EventGadget = #Panel_0_0
EndIf
; ////////////////////////
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = #Window_0
CloseWindow(#Window_0)
Break
EndIf
EndSelect
ForEver
;
;}