Recent

Author Topic: Issues with THintWindow  (Read 605 times)

CM630

  • Hero Member
  • *****
  • Posts: 1522
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Issues with THintWindow
« on: October 18, 2025, 09:45:17 pm »
I have some issue with THintWindow.

1. In Linux (Mint Cinnamon):
1.1. LineEnding + LineEnding is rendered as a single line endings, insted of two line endings.
Code: Pascal  [Select][+][-]
  1. HintWindow.Caption := 'Line 1' + LineEnding + LineEnding + 'Line 2';

The good thing is that I have found a workarond - I added a space between the LineEndings.
Code: Pascal  [Select][+][-]
  1. HintWindow.Caption := 'Line 1' + LineEnding + '  ' + LineEnding + 'Line 2';

Is it a bug, shall I report it? In windows it works fine.

1.2. The text in HintWindow is vertically aligned in the centre. Is it possible to align it to the top? Unlike TLabel, there is no .Layout property.
In Windows the text is aligned to the top.

2. In Windows
2.1. THintWindow steals the focus, so the main form loses focus, when it is shown.
Can this behaviour be prevented?
TForm(aOwner).SetFocus; did not help.
In Linux the focus is not stolen. Could there be a bug in some of the OSes?







Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Button2: TButton;
  17.     Label1: TLabel;
  18.     procedure Button1Click(Sender: TObject);
  19.     procedure Button2Click(Sender: TObject);
  20.     procedure FormCreate(Sender: TObject);
  21.   private
  22.  
  23.   public
  24.  
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.   HintWindow : THintWindow;
  30.  
  31. implementation
  32.  
  33. {$R *.lfm}
  34.  
  35. { TForm1 }
  36.  
  37. procedure TForm1.Button1Click(Sender: TObject);
  38. begin
  39.   HintWindow.top := self.top + 20 ;
  40.   HintWindow.left := self.left + 20;
  41.   HintWindow.Show;
  42.   HintWindow.Caption := 'Line 1' + LineEnding + LineEnding + 'Line 2';
  43. end;
  44.  
  45. procedure TForm1.Button2Click(Sender: TObject);
  46. begin
  47.   HintWindow.top := self.top + 20 ;
  48.   HintWindow.left := self.left + 20;
  49.   HintWindow.Show;
  50.   HintWindow.Caption := 'Line 1' + LineEnding + ' ' + LineEnding + 'Line 2';
  51. end;
  52.  
  53. procedure TForm1.FormCreate(Sender: TObject);
  54. begin
  55.   HintWindow := THintWindow.Create(Self);
  56.   HintWindow.Width := 100;
  57.   HintWindow.Height := 100;
  58.   HintWindow.
  59. end;
  60.  
  61. end.
« Last Edit: October 18, 2025, 09:48:28 pm by CM630 »
Лазар 4,2 32 bit (sometimes 64 bit); FPC3,2,2

jamie

  • Hero Member
  • *****
  • Posts: 7302
Re: Issues with THintWindow
« Reply #1 on: October 18, 2025, 10:00:18 pm »
Use one of the Activate methods to show it instead ? It may take care of the focus issue, otherwise you are just showing a floating window.

 Just a thought but I think you could be limited to its use.

 There is a PopUpNotify component on the board, did you look at that one?

 jamie
The only true wisdom is knowing you know nothing

CM630

  • Hero Member
  • *****
  • Posts: 1522
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Issues with THintWindow
« Reply #2 on: October 19, 2025, 12:18:32 am »
Use one of the Activate methods to show it instead ? It may take care of the focus issue, otherwise you are just showing a floating window.
Thanks, indeed using .Activate seems to fix to issue with the stolen focus:

Code: Pascal  [Select][+][-]
  1. procedure ShowHintWindow(aHintWindow: THintWindow; Location : Tpoint; aString : String);
  2. var
  3.   mRect : trect;
  4. begin
  5.   mRect := HintWindow.CalcHintRect(0, aString ,nil);
  6.   mRect.Width := mRect.Width + Location.X;
  7.   mRect.Height := mRect.Height + Location.Y;
  8.   mRect.Left := Location.X;
  9.   mRect.Top := Location.Y;
  10.   aHintWindow.ActivateHint(mRect,aString);
  11. end;
  12.  

There is a PopUpNotify component on the board, did you look at that one?
...
I tried it, it is not what I am looking for - an updateble non-autohiding hint.
Лазар 4,2 32 bit (sometimes 64 bit); FPC3,2,2

jamie

  • Hero Member
  • *****
  • Posts: 7302
Re: Issues with THintWindow
« Reply #3 on: October 19, 2025, 01:57:48 am »
You can use the OffSetRect() function to via the Location to adjust the rect locations instead of the line by line stuff.

Code: Pascal  [Select][+][-]
  1. Offsetrect(YourRect, Location.X,Location.Y);
  2.  

Something like that.
The only true wisdom is knowing you know nothing

Hartmut

  • Hero Member
  • *****
  • Posts: 1000
Re: Issues with THintWindow
« Reply #4 on: October 19, 2025, 10:52:08 am »
Code: Pascal  [Select][+][-]
  1. procedure ShowHintWindow(aHintWindow: THintWindow; Location : Tpoint; aString : String);
  2. var
  3.   mRect : trect;
  4. begin
  5.   mRect := HintWindow.CalcHintRect(0, aString ,nil);
  6.   mRect.Width := mRect.Width + Location.X;
  7.   mRect.Height := mRect.Height + Location.Y;
  8.   mRect.Left := Location.X;
  9.   mRect.Top := Location.Y;
  10.   aHintWindow.ActivateHint(mRect,aString);
  11. end;
  12.  

If you call aHintWindow.CalcHintRect() with 1st param 'MaxWidth=0', then the current values of aHintWindow.Left and aHintWindow.Top are used, to determine the displaying Monitor and it's values for Width and PixelsPerInch are used. So if your program should run correctly on a 2nd Monitor, then you should set the values of aHintWindow.Left and aHintWindow.Top to Location.X and Location.Y before calling aHintWindow.CalcHintRect().

CM630

  • Hero Member
  • *****
  • Posts: 1522
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Issues with THintWindow
« Reply #5 on: October 20, 2025, 09:17:54 am »
Thanks,
I found that both codes work with two displays with different resolutions in Windows.
I tested ShowHintWindow1 more extensively (arranged the displays in all ways that I thought of).
So the windows issue can be considered as “Solved”, the linux ones remain, though I have workarounds for one of them and with proper sizing, the second one is not observed.


Code: Pascal  [Select][+][-]
  1. procedure ShowHintWindow1(aHintWindow: THintWindow; Location : Tpoint; aString : String);
  2. var
  3.   mRect : trect;
  4. begin
  5.   mRect := aHintWindow.CalcHintRect(0, aString ,nil);
  6.   Offsetrect(mRect, Location.X,Location.Y);
  7.   aHintWindow.ActivateHint(mRect,aString);
  8. end;
  9.  
  10. procedure ShowHintWindow2(aHintWindow: THintWindow; Location : Tpoint; aString : String);
  11. var
  12.   mRect : trect;
  13. begin
  14.   mRect.Left := Location.X;
  15.   mRect.Top := Location.Y;
  16.   mRect := aHintWindow.CalcHintRect(0, aString ,nil);
  17.   Offsetrect(mRect, Location.X,Location.Y);
  18.   aHintWindow.ActivateHint(mRect,aString);
  19. end;
Лазар 4,2 32 bit (sometimes 64 bit); FPC3,2,2

Hartmut

  • Hero Member
  • *****
  • Posts: 1000
Re: Issues with THintWindow
« Reply #6 on: October 20, 2025, 09:54:13 am »
I assume that you see only a difference, if the width in pixel of your 2 monitors is different and if your string 'aString' is so long, that automatic lineendings have to be inserted after this width and if the window is displayed on the 2nd monitor. And instead of
Code: Pascal  [Select][+][-]
  1. mRect.Left := Location.X;
  2. mRect.Top := Location.Y;
you need
Code: Pascal  [Select][+][-]
  1. aHintWindow.Left := Location.X;
  2. aHintWindow.Top := Location.Y;
(as I wrote).

 

TinyPortal © 2005-2018