Page 1 of 2

Is it possible to have <CR> in a text with Gadgettooltip ?

Posted: Fri Nov 26, 2010 10:37 am
by GG
Hi all,

I would like to put some few lines, but chr(10) and chr(13) are not interpreted.
If not, any alternative ?

Re: Is it possible to have <CR> in a text with Gadgettooltip

Posted: Fri Nov 26, 2010 11:20 am
by Trond
This works on Linux, does it not work on Windows?

Code: Select all

GadgetToolTip(0, "Line 1" + #CRLF$ + "Line 2")

Re: Is it possible to have <CR> in a text with Gadgettooltip

Posted: Fri Nov 26, 2010 11:35 am
by GG
Unfortunately no, It prints two more squares on the same line.

Re: Is it possible to have <CR> in a text with Gadgettooltip

Posted: Fri Nov 26, 2010 4:35 pm
by IdeasVacuum
Wow, that is a surprise. Probably can do it via the API. There is an API solution using balloon tips, can't remember who published the following code, works well:

Code: Select all

Enumeration
   #Window
   #StrGadget
EndEnumeration

Procedure TestWindow()
;-------------------
        If OpenWindow(#Window, 0, 0, 200, 100, "Tooltip", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

          StringGadget(#StrGadget, 10, 40, 180, 20,"")
         ;GadgetToolTip(#StrGadget, "Line 1" + #CRLF$ + #CRLF$ + "Line 2")

        EndIf

EndProcedure

Procedure BalloonTip(iWindowID.i, iGadget.i, sTip.s , sTitle.s, iIcon.i)
;-----------------------------------------------------------------------

    iToolTip = CreateWindowEx_(0,"ToolTips_Class32","",#WS_POPUP | #TTS_NOPREFIX | #TTS_BALLOON,0,0,0,0,iWindowID,0,GetModuleHandle_(0),0)

    SendMessage_(iToolTip,#TTM_SETDELAYTIME, #TTDT_AUTOPOP, 30000)
    SendMessage_(iToolTip,#TTM_SETTIPTEXTCOLOR,GetSysColor_(#COLOR_INFOTEXT),0)
    SendMessage_(iToolTip,#TTM_SETTIPBKCOLOR,GetSysColor_(#COLOR_INFOBK),0)
    SendMessage_(iToolTip,#TTM_SETMAXTIPWIDTH,0,280)

    Balloon.TOOLINFO\cbSize=SizeOf(TOOLINFO)
    Balloon\uFlags = #TTF_IDISHWND | #TTF_SUBCLASS
    Balloon\hwnd = GadgetID(iGadget)
    Balloon\uId = GadgetID(iGadget)
    Balloon\lpszText = @sTip

    SendMessage_(iToolTip, #TTM_ADDTOOL, 0, @Balloon)

    If (sTitle > "")

        SendMessage_(iToolTip, #TTM_SETTITLE, iIcon, @sTitle)

    EndIf

EndProcedure

TestWindow()
BalloonTip(#Window, #StrGadget, "Line 1" + #CRLF$ + "Line 2" + #CRLF$ + "Line 3" , "multi-line tip", 0)

Repeat

Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: Is it possible to have <CR> in a text with Gadgettooltip

Posted: Fri Nov 26, 2010 4:54 pm
by IdeasVacuum
...yes, you can modify the BalloonTip procedure to get a self-wrapping regular tooltip:

Code: Select all

Procedure Tip(iWindowID.i, iGadget.i, sTip.s)
;--------------------------------------------

    iToolTip = CreateWindowEx_(0,"ToolTips_Class32","",#WS_POPUP | #TTS_NOPREFIX,0,0,0,0,iWindowID,0,GetModuleHandle_(0),0)

    SendMessage_(iToolTip,#TTM_SETTIPTEXTCOLOR,GetSysColor_(#COLOR_INFOTEXT),0)
    SendMessage_(iToolTip,#TTM_SETTIPBKCOLOR,GetSysColor_(#COLOR_INFOBK),0)
    SendMessage_(iToolTip,#TTM_SETMAXTIPWIDTH,0,200)

    Tip.TOOLINFO\cbSize=SizeOf(TOOLINFO)
    Tip\uFlags = #TTF_IDISHWND | #TTF_SUBCLASS
    Tip\hwnd = GadgetID(iGadget)
    Tip\uId = GadgetID(iGadget)
    Tip\lpszText = @sTip

    SendMessage_(iToolTip, #TTM_ADDTOOL, 0, @Tip)


EndProcedure

TestWindow()
Tip(#Window, #StrGadget, "Long long long long long long long long long long long long long long long long long tip")

Re: Is it possible to have <CR> in a text with Gadgettooltip

Posted: Fri Nov 26, 2010 5:19 pm
by GG
Oh yes, thanks a lot !
Nice one with BallonTip. Exactly what I expected. :)

However, do you think the wierd #CRLF$ behaviour (2 squares in the GadgetToolTip instead of real chr(13) and chr(10) LineFeed and Carriage Return) must be considered as a bug under Windows ? Seems to be OK under Linux regarding Trond experience.

Same behaviour for Windows users ?

Re: Is it possible to have <CR> in a text with Gadgettooltip

Posted: Fri Nov 26, 2010 5:36 pm
by IdeasVacuum
Maybe not a bug, it seems that Windows simply does not support CrLf in a regular tooltip. Let's wait for a definitive opinion from one of the API experts.

Re: Is it possible to have <CR> in a text with Gadgettooltip

Posted: Fri Nov 26, 2010 6:04 pm
by WilliamL

Code: Select all

GadgetToolTip(0, "Line 1" + chr(13) + "Line 2")
Works fine on the Mac.

Re: Is it possible to have <CR> in a text with Gadgettooltip

Posted: Mon Nov 29, 2010 9:48 pm
by DoubleDutch
Maybe it's a bug then, I personally would like multiline tool tips to be standard (maybe in a nice Christmas present update Fred?).

Re: Is it possible to have <CR> in a text with Gadgettooltip

Posted: Mon Nov 29, 2010 10:05 pm
by TomS
It's not a bug in PB. Tooltips are provided and handled by the OS. Windows simply doesn't support it.
Windows does not support many things regarding CR and LF.

Another example: http://purebasic.fr/english/viewtopic.php?f=18&t=44201
According to Vera, the Debugger on Linux creates new lines at CR and LF. Windows displays [] or nothing at all.

Re: Is it possible to have <CR> in a text with Gadgettooltip

Posted: Wed Dec 01, 2010 5:38 am
by inSANE
TomS wrote:It's not a bug in PB. Tooltips are provided and handled by the OS. Windows simply doesn't support it.
That's just not correct. Absence of CRLF-support and/or Multiline-Tooltips belongs to PB, not to windows.

See WinAPI-example.

Re: Is it possible to have <CR> in a text with Gadgettooltip

Posted: Wed Dec 01, 2010 1:37 pm
by Shardik
inSANE wrote:
TomS wrote:It's not a bug in PB. Tooltips are provided and handled by the OS. Windows simply doesn't support it.
That's just not correct. Absence of CRLF-support and/or Multiline-Tooltips belongs to PB, not to windows.
TomS:
Just read the corresponding chapter in the MSDN:
MSDN wrote:Implementing Multiline Tooltips

Multiline tooltips allow text to be displayed on more than one line. They are supported by version 4.70 and later of the common controls. Your application creates a multiline tooltip by sending a TTM_SETMAXTIPWIDTH message, specifying the width of the display rectangle.
The following code example (which uses the nice code from netmaestro to obtain the ToolTip handle)
demonstrates how to display a ToolTip created with the PureBasic function GadgetToolTip() and
display that TooltTip with 2 lines using a CR. You also could use #LF$ or #CRLF$ instead of #CR$:

Code: Select all

; ToolTipID() code from netmaestro
; http://www.purebasic.fr/english/viewtopic.php?t=36765&start=0

Procedure EnumProc(hwnd, lparam)
  Shared ctrl
  cn$ = Space(100)
  GetClassName_(hwnd, @cn$, 99)
  If UCase(cn$) = "TOOLTIPS_CLASS32"
    With ti.TOOLINFO
      \cbSize = SizeOf(TOOLINFO)
      \hwnd = GetParent_(ctrl)
      \uid = ctrl
    EndWith
    If SendMessage_(hwnd, #TTM_GETTOOLINFO, 0, @ti)
      PokeI(lparam, hwnd)
      ProcedureReturn 0
    Else
      ProcedureReturn 1
    EndIf
  Else
    ProcedureReturn 1
  EndIf
EndProcedure

ProcedureDLL.i ToolTipID(gadget)
  Shared ctrl
  ctrl = gadget
  EnumWindows_(@EnumProc(),@TTID)
  ProcedureReturn TTID
EndProcedure

OpenWindow(0, 1800, 400, 270, 100, "GadgetTooltip")
ButtonGadget(0, 10, 30, 250, 30, "Button with Tooltip")
GadgetToolTip(0, "Multiline Tooltip" + #CR$ + "with CR")

SendMessage_(ToolTipID(GadgetID(0)), #TTM_SETMAXTIPWIDTH, 0, 200)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: Is it possible to have <CR> in a text with Gadgettooltip

Posted: Wed Dec 01, 2010 1:51 pm
by TomS
@inSANE & Shardik: Thanks.
I guess I was to quick to answer, based on the experience with the debugger in my thread. But maybe that's an PB issue, too.

Re: Is it possible to have <CR> in a text with Gadgettooltip

Posted: Wed Dec 01, 2010 3:23 pm
by c4s
I think this should go to the Windows related bug section then.

Re: Is it possible to have <CR> in a text with Gadgettooltip

Posted: Wed Dec 01, 2010 8:35 pm
by inSANE
c4s wrote:I think this should go to the Windows related bug section then.
I assume, it's not a bug. It's more like an unsupported feature (as there are on many other controls as well).
So I would say, it's something for the "Feature Requests and Wishlists" section.