PanelGadget() and GadgetToolTip()
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
PanelGadget() and GadgetToolTip()
When using GadgetToolTip() with a PanelGadget(), we currently can only assign 1 tooltip to the whole gadget.
It would be very useful to be able to assign individual tooltips to each tab of a PanelGadget.
It would be very useful to be able to assign individual tooltips to each tab of a PanelGadget.
Re: PanelGadget() and GadgetToolTip()
See the rashad's code here https://www.purebasic.fr/english/viewto ... ip#p500018
M.
Code: Select all
EnableExplicit
Global.i TT,oldCB
Global.i TT_1, TT_2
Global.rect n1, n2
Procedure IsMouseOver(r.i)
Protected p.Point
GetCursorPos_(p)
ScreenToClient_ (WindowID(0), @p)
ProcedureReturn PtInRect_(r,p\y << 32 + p\x)
EndProcedure
Procedure.i callback(hWnd.i, uMsg.i, wParam.i, lParam.i)
Protected msg.MSG
If uMsg = #WM_MOUSEMOVE
If IsMouseOver(n1)
TT = TT_1
ElseIf IsMouseOver(n2)
TT = TT_2
EndIf
msg\hwnd = hWnd
msg\message = uMsg
msg\wParam = wParam
msg\lParam = lParam
SendMessage_(TT, #TTM_RELAYEVENT, 0,msg)
EndIf
ProcedureReturn CallWindowProc_(oldCB,hWnd,uMsg,wParam,lParam)
EndProcedure
Define gtt.i
Define ti.Toolinfo
Define null.i, Quit.i
If OpenWindow(0, 0, 0, 270, 200, "GadgetTooltip", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
PanelGadget(2,0,0,270,200)
AddGadgetItem(2, -1, "Tab1")
ButtonGadget(0, 10, 30, 250, 30, "Button with Tooltip-1")
AddGadgetItem(2, -1, "Tab2")
CloseGadgetList()
SendMessage_(GadgetID(2),#TCM_GETITEMRECT,0,n1.RECT)
SendMessage_(GadgetID(2),#TCM_GETITEMRECT,1,n2.RECT)
GadgetToolTip(0, "Tooltip For Button 0"+#CR$+"With more than one line")
GTT = FindWindow_("tooltips_class32",0)
SetWindowLongPtr_(GTT, #GWL_STYLE, GetWindowLongPtr_(GTT, #GWL_STYLE) | #TTS_ALWAYSTIP| #TTS_NOPREFIX| #WS_POPUP| #TTS_BALLOON) ;#TTS_BUBBLE
SetWindowTheme_(GTT, @null, @null)
SendMessage_(GTT,#TTM_SETMAXTIPWIDTH,0,200)
SendMessage_(GTT,#TTM_SETTIPTEXTCOLOR,$00FF00,0)
SendMessage_(GTT, #TTM_SETTITLE, #TOOLTIP_INFO_ICON, @"Tooltip for Button 0")
ti\cbSize = SizeOf(ti)
ti\uFlags = #TTF_CENTERTIP
ti\hWnd = GadgetID(2)
TT_1 = CreateWindowEx_(0, "Tooltips_Class32", "", #TTS_ALWAYSTIP| #TTS_NOPREFIX| #WS_POPUP| #TTS_BALLOON, 0, 0, 0, 0, 0, 0, 0, 0)
SetWindowTheme_(TT_1, @null, @null)
SendMessage_(TT_1, #TTM_SETMAXTIPWIDTH, 0, 250)
SendMessage_(TT_1,#TTM_SETTIPTEXTCOLOR,$0000FF,0)
SendMessage_(TT_1,#TTM_SETTIPBKCOLOR,$D1FFFF,0)
ti\lpszText = @"Tool 0"
SetRect_(@ti\rect, n1\left,n1\top,n1\right,n1\bottom)
SendMessage_(TT_1, #TTM_ADDTOOL, 0, ti)
SendMessage_(TT_1, #TTM_SETTITLE, #TOOLTIP_WARNING_ICON, @"TAB #1")
TT_2 = CreateWindowEx_(0, "Tooltips_Class32", "", #TTS_ALWAYSTIP| #TTS_NOPREFIX| #WS_POPUP| #TTS_BALLOON &~ #WS_BORDER, 0, 0, 0, 0, 0, 0, 0, 0)
SetWindowTheme_(TT_2, @null, @null)
SendMessage_(TT_2, #TTM_SETMAXTIPWIDTH, 0, 100)
SendMessage_(TT_2,#TTM_SETTIPTEXTCOLOR,$FF0000,0)
ti\lpszText = @"Tooltip For TAB 2 With More Lines 3"
SetRect_(@ti\rect, n2\left,n2\top,n2\right,n2\bottom)
SendMessage_(TT_2, #TTM_ADDTOOL, 0, ti)
SendMessage_(TT_2, #TTM_SETTITLE, #TOOLTIP_ERROR_ICON, @"TAB #2")
oldCB = SetWindowLongPtr_(GadgetID(2),#GWL_WNDPROC,@callback())
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
EndIf
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: PanelGadget() and GadgetToolTip()
Thank you, Mesa! That's helpful for my current project on Windows.
My wish remains, however, as a built-in command would be easier to use and, most importantly, would/should be cross-platform.
My wish remains, however, as a built-in command would be easier to use and, most importantly, would/should be cross-platform.
Re: PanelGadget() and GadgetToolTip()
+1Little John wrote: ↑Tue Jan 18, 2022 10:21 pm When using GadgetToolTip() with a PanelGadget(), we currently can only assign 1 tooltip to the whole gadget.
It would be very useful to be able to assign individual tooltips to each tab of a PanelGadget.
DE AA EB
Re: PanelGadget() and GadgetToolTip()
I've made a quick coded multiplatform solution, but it works with 1 panelgadget with only 2 macros:
M.
Code: Select all
Macro AddTabTooltip(panelgadget,text)
;Gadget as tooltip
tooltiptab=TextGadget(#PB_Any,-1,-1,0,0,"Tab",#PB_Text_Center)
SetGadgetColor(tooltiptab, #PB_Gadget_BackColor, #Yellow)
pyi=GadgetY(panelgadget)
pyf=GadgetY(panelgadget)+GetGadgetAttribute(panelgadget, #PB_Panel_TabHeight )
ntabs = CountGadgetItems(panelgadget)
Dim wtabs(ntabs)
Dim tootiptexts.s(ntabs)
For i = 0 To ntabs-1
tmp$=StringField(text, i+1, "@@")
SetGadgetText(tooltiptab,tmp$)
wtabs(i)=GadgetWidth(tooltiptab,#PB_Gadget_RequiredSize);
wtab=wtab+wtabs(i)
tootiptexts(i)=tmp$
Next i
Dim xtab(ntabs)
w=0
margin=20
For i=0 To ntabs-1
w=w+wtabs(i)+margin
xtab(i)=w
Next i
EndMacro
Macro SurveyToolTipsTabs(Window)
mx=WindowMouseX(window)
my=WindowMouseY(window)
If mx <> last_mx
last_mx = mx
ok=0
EndIf
If my>pyi And my<pyf
For i=0 To ntabs;-1
If mx<xtab(i)
SetGadgetText(tooltiptab,tootiptexts(i))
If ok=0
ResizeGadget(tooltiptab,mx+20,my,wtabs(i),20)
EndIf
ok=1
Break
EndIf
Next i
Else
ResizeGadget(tooltiptab,-1,-1,0,0)
EndIf
EndMacro
#window=1
#panelgadget=10
If OpenWindow(#window, 0, 0, 322, 220, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
PanelGadget (#panelgadget, 8, 8, 306, 203)
AddGadgetItem (#panelgadget, -1, "Tab 1")
AddGadgetItem (#panelgadget, -1,"zzzzzzzzzTab 2")
ButtonGadget(2, 10, 15, 80, 24,"Button 1")
ButtonGadget(3, 95, 15, 80, 24,"Button 2")
AddGadgetItem (#panelgadget, -1,"Tab 3")
CloseGadgetList()
AddTabTooltip(#panelgadget,"Tab 1@@Tab 2<=====>@@Tab 3")
Repeat
SurveyToolTipsTabs(#window)
Event=WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: PanelGadget() and GadgetToolTip()
Thank you for this interesting approach!
Unfortunately, it does not work reliably in all situations.
The main problem is, that the value of xtab(i) is based on the value of wtabs(i).
But xtab(i) should store the width of the tabs, not the width of the tooltips.
For instance in my current project, the text in the tabs are file names, and the text in the corresponding tooltips are the complete path names of the file. I.e. the tooltip text is considerably longer than the corresponding tab text. So the above code unfortunately will not work as expected.
Unfortunately, it does not work reliably in all situations.
The main problem is, that the value of xtab(i) is based on the value of wtabs(i).
But xtab(i) should store the width of the tabs, not the width of the tooltips.
For instance in my current project, the text in the tabs are file names, and the text in the corresponding tooltips are the complete path names of the file. I.e. the tooltip text is considerably longer than the corresponding tab text. So the above code unfortunately will not work as expected.
Re: PanelGadget() and GadgetToolTip()
I think you can make a multiline tooltip with chr(10) but i don't know if it will work with linux or osx.
Code: Select all
Macro AddTabTooltip(panelgadget,text)
;Gadget as tooltip
tooltiptab=TextGadget(#PB_Any,-1,-1,0,0,"Tab",#PB_Text_Center)
SetGadgetColor(tooltiptab, #PB_Gadget_BackColor, #Yellow)
pyi=GadgetY(panelgadget)
pyf=GadgetY(panelgadget)+GetGadgetAttribute(panelgadget, #PB_Panel_TabHeight )
ntabs = CountGadgetItems(panelgadget)
Dim wtabs(ntabs)
Dim tootiptexts.s(ntabs)
For i = 0 To ntabs-1
tmp$=StringField(text, i+1, "@@")
If Len(tmp$)>20; limit to 20 char long
For j=1 To Len(tmp$) Step 20
tmp$=InsertString(tmp$,#LF$,j)
Next j
EndIf
SetGadgetText(tooltiptab,tmp$)
wtabs(i)=GadgetWidth(tooltiptab,#PB_Gadget_RequiredSize);
wtab=wtab+wtabs(i)
tootiptexts(i)=tmp$
Next i
Dim xtab(ntabs)
w=0
margin=20
For i=0 To ntabs-1
w=w+wtabs(i)+margin
xtab(i)=w
Next i
EndMacro
Macro SurveyToolTipsTabs(Window)
mx=WindowMouseX(window)
my=WindowMouseY(window)
If mx <> last_mx
last_mx = mx
ok=0
EndIf
If my>pyi And my<pyf
For i=0 To ntabs;-1
If mx<xtab(i)
SetGadgetText(tooltiptab,tootiptexts(i))
If ok=0
ResizeGadget(tooltiptab,mx+20,my,wtabs(i),GadgetHeight(tooltiptab,#PB_Gadget_RequiredSize))
EndIf
ok=1
Break
EndIf
Next i
Else
ResizeGadget(tooltiptab,-1,-1,0,0)
EndIf
EndMacro
#window=1
#panelgadget=10
If OpenWindow(#window, 0, 0, 322, 220, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
PanelGadget (#panelgadget, 8, 8, 306, 203)
AddGadgetItem (#panelgadget, -1, "Tab 1")
AddGadgetItem (#panelgadget, -1,"zzzzzzzzzTab 2")
ButtonGadget(2, 10, 15, 80, 24,"Button 1")
ButtonGadget(3, 95, 15, 80, 24,"Button 2")
AddGadgetItem (#panelgadget, -1,"Tab 3")
CloseGadgetList()
tip1$="Line 1" + Chr(10) + "Line 2" + Chr(10) + "Line 3"
tip2$="Tab 2<=====>"
tip3$="azertyuiopmlkjhgfdsqwxcvbn,;:!ù123456786"
tip$=tip1$+"@@"+tip2$+"@@"+tip3$
AddTabTooltip(#panelgadget,tip$)
Repeat
SurveyToolTipsTabs(#window)
Event=WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
Re: PanelGadget() and GadgetToolTip()
10 years ago RSBasic posted already this code example in the German forum using a window callback (WinAPI32, so only for Windows). I have just tested the modified version of Danilo some postings later and it worked like a charm on my Windows 10 Enterprise 21H2 with PB x86 and x64 5.73.
Re: PanelGadget() and GadgetToolTip()
There is a very powerfull "TabBarGadget" as a panel gadget, multi platform and you will be able to add a tooltip for each tabs.
STARGATE: https://www.purebasic.fr/english/viewto ... 12&t=47588
KENMO: https://github.com/kenmo-pb/TabBarGadget
This gadget is used in the purebasic IDE .
M.
STARGATE: https://www.purebasic.fr/english/viewto ... 12&t=47588
KENMO: https://github.com/kenmo-pb/TabBarGadget
This gadget is used in the purebasic IDE .
M.