Page 1 of 2
Panel gadget with highlighted tabs
Posted: Thu Aug 17, 2006 9:58 am
by RichardL
I am writing an application using a panel gadget with several tabs.
Depending on serial comms input the user can choose some tabs and not others.
I have the application working and getting some feedback from testers.
They ask that I highlight the panel tabs that are available by highlighting the tab name or colouring the name green. OUCH!
Any suggestions how to do this would be greatfully received.
(As an interim fix I have put in a 'rude noise' if the user tries a non-valid tab.)
Posted: Thu Aug 17, 2006 10:14 am
by Trond
If the user can't select the tabs don't display them.
Posted: Thu Aug 17, 2006 11:53 am
by RichardL
@Trond
I did not want to use RemoveGadgetItem() because I wanted to keep the 'visual aiming point' the same.
The software is running on a Flybook PC which has a physically small 600x1024 (portrait) screen working as a tablet, no keyboard. To reduce the error rate I'm keen to keep the screen layout consistent. In sunlight the display is not as readable as I would like.
After some experience the user will remember where the correct tab is located and go for it, but as I want to reduce the possibility of error as much as possible; a colour highlight seemed the best solotion.
Posted: Thu Aug 17, 2006 1:52 pm
by Sparkie
See if this ownderdraw method works for you Richard...
Code: Select all
;===========================================
; Code : Colorize PanelGadget Tabs
; Author : Sparkie
; Date : 08/17/06 (updated 02/14/2008 to apply the rsts fix)
; PB Version : PB 4.00
; OS Support : Windows only
;===========================================
Global oldCallback
;... Create our background brush for use with tabs
Global greenBrush = CreateSolidBrush_(#Green)
Global defaultBrush = CreateSolidBrush_(GetSysColor_(#COLOR_3DFACE))
;...Our subclassed PanelGadget events
Procedure myPGcallback(hwnd, msg, wParam, lParam)
result = CallWindowProc_(oldCallback, hwnd, msg, wParam, lParam)
Select msg
Case #WM_DRAWITEM
*PGdis.DRAWITEMSTRUCT = lParam
If *PGdis\CtlType = #ODT_TAB
Select *PGdis\itemID
;...Tabs that will appear with red text on a green background
Case 0, 2
tabText$ = GetGadgetItemText(0, *PGdis\itemID, 0)
FillRect_(*PGdis\hdc, *PGdis\rcItem, greenBrush)
SetTextColor_(*PGdis\hdc, #Red)
SetBkMode_(*PGdis\hdc, #TRANSPARENT)
DrawText_(*PGdis\hdc, tabText$, Len(tabText$), *PGdis\rcItem, #DT_CENTER | #DT_SINGLELINE | #DT_VCENTER | #DT_NOCLIP)
Default
;...Tabs that will appear with blue text on system default color
tabText$ = GetGadgetItemText(0, *PGdis\itemID, 0)
FillRect_(*PGdis\hdc, *PGdis\rcItem, defaultBrush)
SetTextColor_(*PGdis\hdc, #Blue)
SetBkMode_(*PGdis\hdc, #TRANSPARENT)
DrawText_(*PGdis\hdc, tabText$, Len(tabText$), *PGdis\rcItem, #DT_CENTER | #DT_SINGLELINE | #DT_VCENTER | #DT_NOCLIP)
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 322, 220,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
PanelGadget(0, 8, 8, 306, 203)
AddGadgetItem (0, -1, "Panel 1")
ButtonGadget(1, 10, 30, 50, 20, "Hello")
AddGadgetItem (0, -1,"Panel 2")
ButtonGadget(2, 10, 30, 50, 20, "World")
AddGadgetItem (0, -1,"Panel 3")
ButtonGadget(3, 10, 30, 80, 20, "PureBasic")
CloseGadgetList()
; Ownderdraw and subcalss PanelGadget to colorize tabs
SetWindowLong_(GadgetID(0), #GWL_STYLE, GetWindowLong_(GadgetID(0), #GWL_STYLE) | #TCS_OWNERDRAWFIXED)
oldCallback = SetWindowLong_(GetParent_(GadgetID(0)), #GWL_WNDPROC, @myPGcallback())
Repeat
event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
DeleteObject_(greenBrush)
DeleteObject_(defaultBrush)
EndIf
End
Posted: Thu Aug 17, 2006 1:56 pm
by Konne
I think if u disable the tab child it will be disabled.
Posted: Thu Aug 17, 2006 2:27 pm
by localmotion34
take a look at my disable panelgadget code. you can set text or background color like Sparkie, and you can prevent a user from selecting a panel tab.
Code: Select all
Global OriginProc.l,textcolor
Global Dim oldsel.l(1)
Procedure tabproc(hwnd,msg,wParam,lParam)
Select msg
Case #WM_DRAWITEM
textbuffer.s=Space(255)
*lpdis.DRAWITEMSTRUCT=lParam
tab.TC_ITEM
Select *lpdis\CtlType
Case #ODT_TAB
Select *lpdis\itemState
Case #ODS_SELECTED
tab\Mask=#TCIF_TEXT
tab\pszText=@textbuffer
tab\cchTextMax=255
SendMessage_(*lpdis\hwndItem,#TCM_GETITEM,*lpdis\itemID,@tab)
textcolor.l= #Black
Case #ODS_SELECTED | #ODS_FOCUS
drawfoc.l=#True
Case 0
tab\Mask=#TCIF_PARAM
SendMessage_(*lpdis\hwndItem,#TCM_GETITEM,*lpdis\itemID,@tab)
If tab\lParam=1
tab\Mask=#TCIF_TEXT
tab\pszText=@textbuffer
tab\cchTextMax=255
SendMessage_(*lpdis\hwndItem,#TCM_GETITEM,*lpdis\itemID,@tab)
textcolor.l= #White
*lpdis\rcItem\left+5
*lpdis\rcItem\top+3
SetTextColor_(*lpdis\hdc, textcolor)
DrawText_(*lpdis\hdc, textbuffer, Len(textbuffer), *lpdis\rcItem, dtFlags)
textcolor.l= RGB(84,82,84)
*lpdis\rcItem\top-3
*lpdis\rcItem\left-5
; this code here draws text just like windows disabled, grey with white shadow
; by messing with the RECT coordinates
Else
tab\Mask=#TCIF_TEXT
tab\pszText=@textbuffer
tab\cchTextMax=255
SendMessage_(*lpdis\hwndItem,#TCM_GETITEM,*lpdis\itemID,@tab)
textcolor.l= #Black
EndIf
EndSelect
If drawfoc=#True
DrawFocusRect_(*lpdis\hdc, *lpdis\rcItem)
EndIf
SetBkMode_(*lpdis\hdc, #TRANSPARENT)
*lpdis\rcItem\left+4
*lpdis\rcItem\top+2
SetTextColor_(*lpdis\hdc, textcolor)
DrawText_(*lpdis\hdc, textbuffer, Len(textbuffer), *lpdis\rcItem, dtFlags)
ProcedureReturn 0
EndSelect
Case #WM_NOTIFY
*pNMHDR.NMHDR = lParam
tab1.TC_ITEM
Select *pNMHDR\code
Case #TCN_SELCHANGING
; --> Get the index of the Tab that is about to lose focus
oldsel(0)=SendMessage_(*pNMHDR\hwndFrom,#TCM_GETCURSEL,0,0)
Case #TCN_SELCHANGE
; --> Get the index of the selected Tab
newTab = SendMessage_(*pNMHDR\hwndFrom,#TCM_GETCURSEL,0,0)
tab1\Mask=#TCIF_PARAM
SendMessage_(*pNMHDR\hwndFrom,#TCM_GETITEM,newTab,@tab1)
If tab1\lParam=1
SendMessage_(*pNMHDR\hwndFrom,#TCM_SETCURSEL,oldsel(0),0)
EndIf
ProcedureReturn 0
EndSelect
EndSelect
ProcedureReturn CallWindowProc_(OriginProc,hwnd,msg,wParam,lParam)
EndProcedure
Procedure disablepanelitem(panel,item,State)
If State=1
itm.TC_ITEM
itm\Mask=#TCIF_PARAM
SendMessage_(GadgetID(panel),#TCM_GETITEM,item,@itm)
itm\lParam=1
itm\Mask=#TCIF_PARAM
SendMessage_(GadgetID(panel),#TCM_SETITEM,item,@itm)
ElseIf State=0
itm.TC_ITEM
itm\Mask=#TCIF_PARAM
SendMessage_(GadgetID(panel),#TCM_GETITEM,item,@itm)
itm\lParam=0
itm\Mask=#TCIF_PARAM
SendMessage_(GadgetID(panel),#TCM_SETITEM,item,@itm)
EndIf
EndProcedure
#WindowWidth = 390
#WindowHeight = 350
If OpenWindow(0, 100, 200, #WindowWidth, #WindowHeight, "",#PB_Window_MinimizeGadget)
If CreateGadgetList(WindowID(0))
PanelGadget(30,30,30,360,300)
SetWindowLong_(GadgetID(30),#GWL_STYLE,GetWindowLong_(GadgetID(30),#GWL_STYLE) |#TCS_OWNERDRAWFIXED)
RedrawWindow_(GadgetID(30),0,0,7)
ShowWindow_(GadgetID(30),#SW_SHOW)
OriginProc=SetWindowLong_(GetParent_(GadgetID(30)),#GWL_WNDPROC,@tabproc())
For a=0 To 3
AddGadgetItem(30,a,"test" + Str(a))
Next
CloseGadgetList()
EndIf
disablepanelitem(30,2,1)
;- event loop
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_Gadget
Select EventGadget()
EndSelect
EndIf
Until EventID = #PB_Event_CloseWindow
EndIf
End
Re: Panel gadget with highlighted tabs
Posted: Thu Aug 17, 2006 4:31 pm
by TerryHough
RichardL wrote:They ask that I highlight the panel tabs that are available by highlighting the tab name or colouring the name green.
You might want to take a look at my example code here:
http://elfecc.no-ip.info/purebasic/inde ... PanelIcons

Posted: Thu Aug 17, 2006 5:14 pm
by RichardL
Gentlemen...
Thank you all for your postings...
I'm not sure which method I will use, but its so good to have options!
Posted: Wed Feb 13, 2008 1:05 pm
by PB
> ; Code : Colorize PanelGadget Tabs
> ; Author : Sparkie
Hi Sparkie, I just tried your code and noted that it draws a line on the
PanelGadget under the selected tab, which is not desirable as it doesn't
look normal. Is there a way to prevent that? Thanks.
Posted: Wed Feb 13, 2008 1:48 pm
by Sparkie
I'm at work so no time for a quick fix right now. You could try adjusting the rect, maybe with *PGdis\rcItem\bottom - 2 and see if you get what you want. I'll take a closer look later tonight when I get home.

Posted: Thu Feb 14, 2008 3:15 am
by Sparkie
PB, try adding this between line 20 and line 21 and let me know if it resloves the problem for you.
Code: Select all
If *PGdis\itemState = #ODS_SELECTED
*PGdis\rcItem\bottom - 2
EndIf
Posted: Thu Feb 14, 2008 10:29 am
by PB
No good, Sparkie. Adjusting that value only moves the green box and text up.
See the following screenshot to see what I mean. (I used -10 in the screenshot).

Posted: Thu Feb 14, 2008 2:14 pm
by Sparkie
PB, can I see a screenshot of what you get with my original code without my last fix. ?
Posted: Thu Feb 14, 2008 6:33 pm
by Fluid Byte
I have seen now many requests and codes regarding coloring panel tabs and to honest, it's simply not worth it. None of these codes is working 100% correctly or is XP / Vista compatible. I think it's simply not worth the hassle(hoff).
If you really want custom colored tabs simply use container gadgets + images and you are fine to go. Just my 2 cents.
Posted: Thu Feb 14, 2008 7:31 pm
by Sparkie
Thanks for your 2 cents but how about showing us your code
