lazarus/lcl/include/hintwindow.inc
lazarus bd91f45a43 MWE: Applied patch from "Andrew Johnson" <aj_genius@hotmail.com>
Here is the run down of what it includes -

 -Vasily Volchenko's Updated Russian Localizations

 -improvements to GTK Styles/SysColors
 -initial GTK Palette code - (untested, and for now useless)

 -Hint Windows and Modal dialogs now try to stay transient to
  the main program form, aka they stay on top of the main form
  and usually minimize/maximize with it.

 -fixes to Form BorderStyle code(tool windows needed a border)

 -fixes DrawFrameControl DFCS_BUTTONPUSH to match Win32 better
  when flat

 -fixes DrawFrameControl DFCS_BUTTONCHECK to match Win32 better
  and to match GTK theme better. It works most of the time now,
  but some themes, noteably Default, don't work.

 -fixes bug in Bitmap code which broke compiling in NoGDKPixbuf
  mode.

 -misc other cleanups/ fixes in gtk interface

 -speedbutton's should now draw correctly when flat in Win32

 -I have included an experimental new CheckBox(disabled by
  default) which has initial support for cbGrayed(Tri-State),
  and WordWrap, and misc other improvements. It is not done, it
  is mostly a quick hack to test DrawFrameControl
  DFCS_BUTTONCHECK, however it offers many improvements which
  can be seen in cbsCheck/cbsCrissCross (aka non-themed) state.

 -fixes Message Dialogs to more accurately determine
  button Spacing/Size, and Label Spacing/Size based on current
  System font.
 -fixes MessageDlgPos, & ShowMessagePos in Dialogs
 -adds InputQuery & InputBox to Dialogs

 -re-arranges & somewhat re-designs Control Tabbing, it now
  partially works - wrapping around doesn't work, and
  subcontrols(Panels & Children, etc) don't work. TabOrder now
  works to an extent. I am not sure what is wrong with my code,
  based on my other tests at least wrapping and TabOrder SHOULD
  work properly, but.. Anyone want to try and fix?

 -SynEdit(Code Editor) now changes mouse cursor to match
  position(aka over scrollbar/gutter vs over text edit)

 -adds a TRegion property to Graphics.pp, and Canvas. Once I
  figure out how to handle complex regions(aka polygons) data
  properly I will add Region functions to the canvas itself
  (SetClipRect, intersectClipRect etc.)

 -BitBtn now has a Stored flag on Glyph so it doesn't store to
  lfm/lrs if Glyph is Empty, or if Glyph is not bkCustom(aka
  bkOk, bkCancel, etc.) This should fix most crashes with older
  GDKPixbuf libs.

git-svn-id: trunk@2183 -
2002-08-17 23:41:05 +00:00

155 lines
4.4 KiB
PHP

// included by forms.pp
{ THintWindow
*****************************************************************************
* *
* This file is part of the Lazarus Component Library (LCL) *
* *
* See the file COPYING.LCL, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
}
{
use:
HintWindow := THintWindow.Create(nil);
Rect := HintWindow.CalcHintRect(0,'This is the hint',nil);
HintWindow.ActivateHint(Rect,'This is the hint');
}
constructor THintWindow.Create(AOwner: TComponent);
var TheTimer: TTimer;
begin
inherited Create(AOwner);
fCompStyle := csHintWindow;
parent := nil;
Canvas.Font := Screen.HintFont;
color := clInfoBk;
Caption := 'THintWindow';
SetBounds(1,1,25,25);
FHideInterval := 3000;
TheTimer := TTimer.Create(self);
FAutoHideTimer := TheTimer;
TheTimer.Interval := HideInterval;
TheTimer.Enabled := False;
TheTimer.OnTimer := @AutoHideHint;
end;
destructor THintWIndow.Destroy;
begin
fAutoHideTimer.Free;
inherited;
end;
Procedure THintWindow.SetHideInterval(Value : Integer);
Begin
FHideInterval := Value;
TTimer(FAutoHideTimer).Interval := FHideInterval;
end;
Procedure THintWindow.SetAutoHide(Value : Boolean);
Begin
FAutoHide := Value;
if not(value) then
TTimer(FAutoHideTimer).Enabled := False;
end;
Procedure THintWindow.AutoHideHint(Sender : TObject);
Begin
TTimer(FAutoHideTimer).Enabled := False;
if Visible then Visible := False;//Hide;
End;
procedure THintWindow.Paint;
var
Rect: TRect;
//DefaultDraw: Boolean;
begin
Rect := ClientRect;
Canvas.Brush.Color := Color;
Canvas.Brush.Style := bsSolid;
Canvas.Rectangle(Rect);
Canvas.TextRect(Rect, 3, 3, Caption);
end;
procedure THintWindow.ActivateHint(Rect: TRect; const AHint: String);
begin
FActivating := True;
try
Caption := AHint;
if Rect.Bottom > Screen.Height then
begin
Rect.Top := Screen.Height - (Rect.Bottom - Rect.Top);
Rect.Bottom := Screen.Height;
end;
if Rect.Right > Screen.Width then
begin
Rect.Left := Screen.Width - (Rect.Right - Rect.Left);
Rect.Right := Screen.Width;
end;
if Rect.Left < 0 then Rect.Left := 0;
if Rect.Bottom < 0 then Rect.Bottom := 0;
SetBounds(Rect.Left, Rect.Top, Rect.Right - Rect.Left, Rect.Bottom - Rect.Top);
Visible := True;
TTimer(FAutoHideTimer).Enabled := False;
TTimer(FAutoHideTimer).Enabled := FAutoHide;
finally
FActivating := False;
end;
end;
function THintWindow.CalcHintRect(MaxWidth: Integer; const AHint: String;
AData: Pointer): TRect;
var
//Temp : Integer;
Num : Integer;
tempHint : String;
LongestLine : String;
Lines : Integer;
begin
Result.Left := 0;
Result.Top := 0;
TempHint := AHint;
LongestLine := '';
num := pos(#10,TempHint);
Lines := 1;
if Num > 0 then
Begin
//set TempHint to the longest line.
//set Lines to the number of lines.
while num > 0 do
Begin
inc(Lines);
if Canvas.TextWidth(copy(TempHint,1,num-1)) > Canvas.TextWidth(LongestLine) then
LongestLine := Copy(TempHint,1,num-1);
delete(TempHint,1,num);
Num := pos(#10,TempHint);
end;
end;
if Canvas.TextWidth(copy(TempHint,1,Length(TempHint))) > Canvas.TextWidth(LongestLine) then
LongestLine := Copy(TempHint,1,Length(TempHint));
TempHint := LongestLine;
if ((MaxWidth > 0) and (Canvas.TextWidth(TempHint) > MaxWidth)) then
Result.Right := Result.Left + MaxWidth
else
Result.Right := Result.Left + Canvas.TextWidth(TempHint);
Result.Bottom := result.Top + (Lines * (Canvas.TextHeight(AHint)));
Inc(Result.Bottom, 4);
Dec(Result.Top, 2);
Inc(Result.Right, 8);
end;