Page 1 of 2

Tooltip Manager ( customize the default PB tooltip )

Posted: Thu May 15, 2008 5:00 am
by eddy
v1.1 for PB4.20 & 4.30

You can customize the default PB tooltip display and behaviour. ( without creating a new one )
convert it to balloon tooltip

Code: Select all

;{ Utils
Enumeration
   #TOOLTIPM_NO_ICON=0
   #TOOLTIPM_INFO_ICON
   #TOOLTIPM_WARNING_ICON
   #TOOLTIPM_ERROR_ICON
EndEnumeration
Structure TooltipManagerParams
   ID.l
   IsBalloon.l
   ColorText.l
   ColorBack.l
   Title.s
   IconForTitle.l
   MaxWidth.l
   Manager.l
EndStructure
Global NewList TooltipManagers.TooltipManagerParams()
Procedure FindDefaultTooltipManager(Window, unused)
   ; ==========================================
   ; Find Default Purebasic TOOLTIP Handle
   ; ==========================================
   Protected WindowClass.s=Space(255)
   If GetClassName_(Window, @WindowClass, Len(WindowClass))
      If LCase(WindowClass)=LCase("ToolTips_Class32")
         If GetWindowThreadProcessId_(Window, 0)=GetCurrentThreadId_()
            
            AddElement(TooltipManagers())
            TooltipManagers()\Title=""
            TooltipManagers()\IconForTitle=0
            TooltipManagers()\IsBalloon=GetWindowLong_(Window, #GWL_STYLE)
            TooltipManagers()\MaxWidth=SendMessage_(Window, #TTM_GETMAXTIPWIDTH, 0, 0)
            TooltipManagers()\ColorText=SendMessage_(Window, #TTM_GETTIPTEXTCOLOR, 0, 0)
            TooltipManagers()\ColorBack=SendMessage_(Window, #TTM_GETTIPBKCOLOR, 0, 0)
            TooltipManagers()\ID=#PB_Ignore
            TooltipManagers()\Manager=Window
            
            ProcedureReturn 0
         EndIf
      EndIf
   EndIf
   ProcedureReturn 1
EndProcedure
;}

;{ TooltipManager Functions
ProcedureDLL.b UseTooltipManager(ID=#PB_Ignore) ;Use specific TooltipManager, returns true if success
   ForEach TooltipManagers()
      If TooltipManagers()\ID=ID
         ; ====================
         ; Modify Parameters
         ; ====================
         Protected TooltipManager=TooltipManagers()\Manager
         SetWindowLong_(TooltipManager, #GWL_STYLE, TooltipManagers()\IsBalloon)
         SendMessage_(TooltipManager, #TTM_SETTIPTEXTCOLOR, TooltipManagers()\ColorText, 0)
         SendMessage_(TooltipManager, #TTM_SETTIPBKCOLOR, TooltipManagers()\ColorBack, 0)
         SendMessage_(TooltipManager, #TTM_SETTITLE, TooltipManagers()\IconForTitle, TooltipManagers()\Title)
         SendMessage_(TooltipManager, #TTM_SETMAXTIPWIDTH, 0, TooltipManagers()\MaxWidth)
         ; SetWindowLong_(TooltipManager,#GWL_EXSTYLE,#WS_EX_TOPMOST) ;If StickWindow enabled
         ; SendMessage_(TooltipManager,#TTM_SETDELAYTIME,#TTDT_INITIAL,200)
         ; SendMessage_(TooltipManager,#TTM_SETDELAYTIME,#TTDT_AUTOPOP,10000)
         ; ====================
         ; Refresh Content
         ; ====================
         SendMessage_(TooltipManager, #TTM_UPDATE, 0, 0)
         ProcedureReturn #True
      EndIf
   Next
   
   ProcedureReturn #False
EndProcedure
ProcedureDLL.l CreateTooltipManager(ID, IsBalloon=#False, ColorText=#PB_Ignore, ColorBack=#PB_Ignore, Title.s="", IconForTitle=#PB_Ignore, MaxWidth=#PB_Ignore) ;Create TooltipManager, returns non-zero if success
   If ID=#PB_Ignore
      ProcedureReturn 0
   EndIf
   
   CompilerIf #PB_Compiler_Version<430
      Protected TooltipManagersCount=CountList(TooltipManagers())
   CompilerElse
      Protected TooltipManagersCount=ListSize(TooltipManagers())
   CompilerEndIf
   
   If TooltipManagersCount=0
      ; ==========================================
      ; Start Default Purebasic TOOLTIP
      ; ==========================================
      Protected ButtonWithTip=ButtonGadget(#PB_Any, 10, 30, 250, 30, "New Button with Tooltip")
      If ButtonWithTip And IsGadget(ButtonWithTip)
         GadgetToolTip(ButtonWithTip, "New Tooltip")
         FreeGadget(ButtonWithTip)
         
         ;find the default tooltip handle...
         EnumWindows_(@FindDefaultTooltipManager(), #Null)
      EndIf
   EndIf
   
   CompilerIf #PB_Compiler_Version<430
      TooltipManagersCount=CountList(TooltipManagers())
   CompilerElse
      TooltipManagersCount=ListSize(TooltipManagers())
   CompilerEndIf
   
   If TooltipManagersCount And IsBalloon<>#PB_Ignore
      ; ==========================================
      ; Overwrite existing TooltipManager ID
      ; (If necessary)
      ; ==========================================
      ForEach TooltipManagers()
         If TooltipManagers()\ID=ID
            DeleteElement(TooltipManagers())
            Break
         EndIf
      Next
      
      ; ==========================================
      ; Register new TooltipManager ID
      ; (With Or without Default parameters)
      ; ==========================================
      UseTooltipManager()
      Protected DefaultIsBalloon=TooltipManagers()\IsBalloon
      Protected DefaultColorText=TooltipManagers()\ColorText
      Protected DefaultColorBack=TooltipManagers()\ColorBack
      Protected DefaultMaxWidth=TooltipManagers()\MaxWidth
      Protected DefaultManager=TooltipManagers()\Manager
      
      AddElement(TooltipManagers())
      TooltipManagers()\ID=ID
      If IsBalloon=#False
         TooltipManagers()\IsBalloon=DefaultIsBalloon
      Else
         TooltipManagers()\IsBalloon=#WS_POPUP | #TTS_NOPREFIX | #TTS_BALLOON | #TTS_ALWAYSTIP
      EndIf
      If ColorText=#PB_Ignore
         TooltipManagers()\ColorText=DefaultColorText
      Else
         TooltipManagers()\ColorText=ColorText
      EndIf
      If ColorBack=#PB_Ignore
         TooltipManagers()\ColorBack=DefaultColorBack
      Else
         TooltipManagers()\ColorBack=ColorBack
      EndIf
      If MaxWidth=#PB_Ignore
         TooltipManagers()\MaxWidth=DefaultMaxWidth
      Else
         TooltipManagers()\MaxWidth=MaxWidth
      EndIf
      If IconForTitle=#PB_Ignore
         TooltipManagers()\IconForTitle=#TOOLTIPM_INFO_ICON
      Else
         TooltipManagers()\IconForTitle=IconForTitle
      EndIf
      TooltipManagers()\Title=Left(Trim(Title), 255)
      TooltipManagers()\Manager=DefaultManager
      
      ProcedureReturn TooltipManagers()\Manager
   EndIf
EndProcedure
;}

; ====================
; EXAMPLE
; ====================
OpenWindow(0, 0, 0, 270, 200, "Customize Gadget Tooltip", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CompilerIf #PB_Compiler_Version<430
   CreateGadgetList(WindowID(0))
CompilerEndIf

CreateTooltipManager(0, #True)
CreateTooltipManager(1, #True, #PB_Ignore, $0000FF, "1", #TOOLTIPM_WARNING_ICON)
CreateTooltipManager(2, #False, RGB(64, 255, 64), RGB(64, 64, 64) , "2", #TOOLTIPM_NO_ICON, 50)
UseTooltipManager(0)

ButtonGadget(10, 10, 10, 250, 30, "TooltipManager 0")
ButtonGadget(11, 10, 50, 250, 30, "TooltipManager 1")
ButtonGadget(12, 10, 90, 250, 30, "TooltipManager 2")
ButtonGadget(20, 10, 130, 250, 30, "Default PUREBASIC TooltipManager")
GadgetToolTip(10, "10 > Super long tooltip message here !!...")
GadgetToolTip(11, "11 > Super long tooltip message here !!...")
GadgetToolTip(12, "12 > Super long tooltip message here !!...")
GadgetToolTip(20, "20 > Super long tooltip message here !!...")

Repeat
   If EventType()=#PB_EventType_LeftClick
      Select EventGadget()
         Case 10
            UseTooltipManager(0)
         Case 11
            UseTooltipManager(1)
         Case 12
            UseTooltipManager(2)
         Case 20
            UseTooltipManager()
      EndSelect
   EndIf
Until WaitWindowEvent()=#PB_Event_CloseWindow

Posted: Thu May 15, 2008 5:29 am
by Fangbeast
Hi Eddy, good examples. Always good to see more ways of doing this and I have been doing something similar for one program that does sql queries for addresses.

By the way, you have a minor syntax error on this line.

CreateTooltipManager(1,#True,#PB_Ignore,$66FFCC,"QuickHelp#TOOLTIPM_WARNING_ICON)

Should be.

CreateTooltipManager(1,#True,#PB_Ignore,$66FFCC,"QuickHelp", #TOOLTIPM_WARNING_ICON)

I do this all the time. Miracle that I can type at all:)

Posted: Thu May 15, 2008 5:36 am
by rsts
Nice :)

Thanks for sharing.

cheers

Posted: Thu May 15, 2008 7:27 am
by eddy

Code: Select all

By the way, you have a minor syntax error on this line. 
Fixed

Posted: Thu May 15, 2008 7:44 am
by SofT MANiAC
8) I like it

Posted: Thu May 15, 2008 8:14 am
by Kwai chang caine
Great code EDDY 8)
But it don't works in v4.20 Beta2 :cry:

Posted: Thu May 15, 2008 9:01 am
by eddy
Kwaï chang caïne wrote:Great code EDDY 8)
But it don't works in v4.20 Beta2 :cry:
ah why ? Does it compile ?

Posted: Thu May 15, 2008 9:04 am
by milan1612
I get an IMA in line 52 when compiling with debugger enabled :?

Re: Tooltip Manager ( customize the default PB tooltip )

Posted: Thu May 15, 2008 10:32 am
by UserOfPure
eddy wrote:Enumeration
#TOOLTIPM_NO_ICON = 0
#TOOLTIPM_INFO_ICON = 1
#TOOLTIPM_WARNING_ICON = 2
#TOOLTIPM_ERROR_ICON = 3
EndEnumeration
Just a tip: if you're going to assign numeric values to a constant like that, then wrapping them in Enumeration isn't needed. Enumeration is for when you're NOT assigning a value. ;)

Posted: Sat May 17, 2008 11:45 pm
by eddy
[ Updated ]
- remove useless global variables
- UseTooltipManager simplified

Code: Select all

success.b = UseTooltipManager(ID) ;Use specific TooltipManager, returns true if success 

UseTooltipManager() ;Use default purebasic TooltipManager

Posted: Sun May 18, 2008 9:31 pm
by Marco2007
Great! Very Useful! :D

Posted: Sun May 18, 2008 9:51 pm
by Fred
The callback provided to EnumWindows_() doesn't look right..

Posted: Sun May 18, 2008 11:07 pm
by eddy
yes... It's perhaps the reason why this code does not compile with PB v4.20 Beta2.

I tried to reduce the size of code, but in the original version there's 3 functions

Posted: Fri May 30, 2008 6:02 pm
by ricardo
Dont works in PB 4.20

Posted: Fri May 30, 2008 8:57 pm
by eddy
I see no problem with the last version