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

Just starting out? Need help? Post your questions and find answers here.
User avatar
GG
Enthusiast
Enthusiast
Posts: 258
Joined: Tue Jul 26, 2005 12:02 pm
Location: Lieusaint (77), France

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

Post 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 ?
Purebasic 6.04 64 bits - Windows 11 Pro 64 bits 23H2
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

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

Post by Trond »

This works on Linux, does it not work on Windows?

Code: Select all

GadgetToolTip(0, "Line 1" + #CRLF$ + "Line 2")
User avatar
GG
Enthusiast
Enthusiast
Posts: 258
Joined: Tue Jul 26, 2005 12:02 pm
Location: Lieusaint (77), France

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

Post by GG »

Unfortunately no, It prints two more squares on the same line.
Purebasic 6.04 64 bits - Windows 11 Pro 64 bits 23H2
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

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

Post 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
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

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

Post 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")
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
GG
Enthusiast
Enthusiast
Posts: 258
Joined: Tue Jul 26, 2005 12:02 pm
Location: Lieusaint (77), France

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

Post 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 ?
Purebasic 6.04 64 bits - Windows 11 Pro 64 bits 23H2
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

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

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
WilliamL
Addict
Addict
Posts: 1224
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

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

Post by WilliamL »

Code: Select all

GadgetToolTip(0, "Line 1" + chr(13) + "Line 2")
Works fine on the Mac.
MacBook Pro-M1 (2021), Sonoma 14.4.1, PB 6.10LTS M1
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

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

Post 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?).
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

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

Post 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.
User avatar
inSANE
User
User
Posts: 10
Joined: Tue Nov 16, 2010 3:17 pm

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

Post 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.
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

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

Post 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
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

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

Post 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.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

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

Post by c4s »

I think this should go to the Windows related bug section then.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
inSANE
User
User
Posts: 10
Joined: Tue Nov 16, 2010 3:17 pm

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

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