Panel gadget with highlighted tabs

Windows specific forum
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Panel gadget with highlighted tabs

Post 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.)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

If the user can't select the tabs don't display them.
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post 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.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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 

Last edited by Sparkie on Fri Feb 15, 2008 3:19 am, edited 1 time in total.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

Post by Konne »

I think if u disable the tab child it will be disabled.
Apart from that Mrs Lincoln, how was the show?
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post 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 

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Re: Panel gadget with highlighted tabs

Post 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

Image
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post 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!
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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).

Image
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

PB, can I see a screenshot of what you get with my original code without my last fix. ?
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post 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.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Thanks for your 2 cents but how about showing us your code :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply