summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graemeg@users.sourceforge.net>2007-01-23 14:48:31 +0000
committerGraeme Geldenhuys <graemeg@users.sourceforge.net>2007-01-23 14:48:31 +0000
commitc0fe0b96fa12d2ce8b7ff0d2d929c5b2181135f7 (patch)
tree59e9a7de4871633cafdfaf77e442c0d656d582ce
parent07a6706d95e5a97e610eba483b13217367a193d3 (diff)
downloadfpGUI-c0fe0b96fa12d2ce8b7ff0d2d929c5b2181135f7.tar.xz
* MouseLeaveCheck no fires off a MouseEnter and MouseLeave event for widgets.
This makes writing other widgets easier. * Fixed the button size of the TComboBox widget. * Fixed the examples/gui/helloworld application. * Added a extras directory where we can store all kinds of stuff. Currently I added a Lazarus code template for creating a new fpGUI application. * Fixed a bug in fpGFX/X11 where the OnEnter event was checked when in actual fact the OnLeave event occured. * Fixed up some code to start Xft support for Linux again. * Internal or composite widgets like the Button in the ComboBox are now named with a hash and then the name.
-rw-r--r--examples/gui/helloworld/helloworld.lpi9
-rw-r--r--examples/gui/helloworld/helloworld.pas56
-rw-r--r--examples/gui/utfdemo/utfdemo.lpr1
-rw-r--r--examples/gui/widgettest/widgettest.lpi1
-rw-r--r--extras/code_templates/lazarus.dci50
-rw-r--r--extras/code_templates/readme.txt27
-rw-r--r--gfx/x11/gfx_x11.pas40
-rw-r--r--gui/buttons.inc3
-rw-r--r--gui/combobox.inc67
-rw-r--r--gui/menus.inc13
-rw-r--r--gui/scrollbar.inc67
-rw-r--r--gui/style.inc11
-rw-r--r--gui/widget.inc28
-rw-r--r--prototypes/multihandle/gui2Base.pas35
14 files changed, 283 insertions, 125 deletions
diff --git a/examples/gui/helloworld/helloworld.lpi b/examples/gui/helloworld/helloworld.lpi
index c180f8dc..e0302f2b 100644
--- a/examples/gui/helloworld/helloworld.lpi
+++ b/examples/gui/helloworld/helloworld.lpi
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<CONFIG>
<ProjectOptions>
- <PathDelim Value="\"/>
+ <PathDelim Value="/"/>
<Version Value="5"/>
<General>
<Flags>
@@ -14,15 +14,13 @@
</General>
<PublishOptions>
<Version Value="2"/>
- <DestinationDirectory Value="$(TestDir)\publishedproject\"/>
- <IgnoreBinaries Value="False"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
- <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
+ <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</RunParams>
<RequiredPackages Count="1">
@@ -40,9 +38,8 @@
</ProjectOptions>
<CompilerOptions>
<Version Value="5"/>
- <PathDelim Value="\"/>
<SearchPaths>
- <OtherUnitFiles Value="..\..\src\"/>
+ <OtherUnitFiles Value="../../src/"/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
diff --git a/examples/gui/helloworld/helloworld.pas b/examples/gui/helloworld/helloworld.pas
index b9921756..b09ec498 100644
--- a/examples/gui/helloworld/helloworld.pas
+++ b/examples/gui/helloworld/helloworld.pas
@@ -3,20 +3,60 @@ program HelloWorld;
{$mode objfpc}{$h+}
uses
- fpGUI, fpguipackage;
+ fpGUI
+ ,fpGFX { GFApplication }
+ ,gfxBase
+ ;
type
TMainForm = class(TForm)
- TextLabel: TLabel;
- lblClose: TLabel;
+ private
+ BoxLayout: TBoxLayout;
+ btnHello: TButton;
+ public
+ procedure AfterConstruction; override;
end;
+
+{ TMainForm }
+
+procedure TMainForm.AfterConstruction;
var
- MainForm: TMainForm;
+ lSize: TSize;
+begin
+ inherited AfterConstruction;
+ Name := 'MainForm';
+ BorderWidth := 8;
+ Text := 'fpGUI Application';
+
+ { every fpGUI app needs a layout manager }
+ BoxLayout := TBoxLayout.Create(self);
+ BoxLayout.Spacing := 8;
+ BoxLayout.VertAlign := vertFill;
+ InsertChild(BoxLayout);
+
+ { create our button }
+ btnHello := TButton.Create('Hello World!', self);
+ btnHello.CanExpandWidth := True;
+ btnHello.CanExpandHeight := True;
+ BoxLayout.InsertChild(btnHello);
+ { set a min and max size }
+ lSize.cx := 150;
+ lSize.cy := 100;
+ Wnd.SetMinMaxClientSize(lSize, lSize);
+end;
+
+
+var
+ MainForm: TMainForm;
begin
- Application.CreateForm(TMainForm, MainForm);
-
- Application.Run;
- MainForm.Free;
+ GFApplication.Initialize;
+ MainForm := TMainForm.Create(GFApplication);
+ try
+ MainForm.Show;
+ GFApplication.Run;
+ finally
+ MainForm.Free;
+ end;
end.
diff --git a/examples/gui/utfdemo/utfdemo.lpr b/examples/gui/utfdemo/utfdemo.lpr
index c3c7ba6c..b59f7f96 100644
--- a/examples/gui/utfdemo/utfdemo.lpr
+++ b/examples/gui/utfdemo/utfdemo.lpr
@@ -63,7 +63,6 @@ begin
GFApplication.Initialize;
MainForm := TMainForm.Create(GFApplication);
try
- GFApplication.AddWindow(MainForm.Wnd); { I don't like this! }
MainForm.Show;
GFApplication.Run;
finally
diff --git a/examples/gui/widgettest/widgettest.lpi b/examples/gui/widgettest/widgettest.lpi
index 0fe05a78..efbb9314 100644
--- a/examples/gui/widgettest/widgettest.lpi
+++ b/examples/gui/widgettest/widgettest.lpi
@@ -6,7 +6,6 @@
<General>
<Flags>
<SaveOnlyProjectUnits Value="True"/>
- <AlwaysBuild Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
diff --git a/extras/code_templates/lazarus.dci b/extras/code_templates/lazarus.dci
new file mode 100644
index 00000000..a21c6190
--- /dev/null
+++ b/extras/code_templates/lazarus.dci
@@ -0,0 +1,50 @@
+[fpguiapp | fpGUI template application]
+uses
+ fpGFX, fpGUI;
+
+type
+ TMainForm = class(TForm)
+ private
+ FMainLayout: TBoxLayout;
+ lblTemplate: TLabel;
+ public
+ procedure AfterConstruction; override;
+ end;
+
+
+{ TMainForm }
+
+procedure TMainForm.AfterConstruction;
+begin
+ inherited AfterConstruction;
+ Name := 'MainForm';
+ BorderWidth := 8;
+ Text := 'fpGUI Template Application';
+
+ FMainLayout := TBoxLayout.Create(self);
+ FMainLayout.Spacing := 8;
+ FMainLayout.Orientation := Vertical;
+ FMainLayout.VertAlign := vertFill;
+ InsertChild(FMainLayout);
+
+ lblTemplate := TLabel.Create('MainForm', self);
+ FMainLayout.InsertChild(lblTemplate);
+
+ // Create other components here
+
+end;
+
+
+var
+ MainForm: TMainForm;
+begin
+ GFApplication.Initialize;
+ MainForm := TMainForm.Create(GFApplication);
+ try
+ MainForm.Show;
+ GFApplication.Run;
+ finally
+ MainForm.Free;
+ end;
+end.
+
diff --git a/extras/code_templates/readme.txt b/extras/code_templates/readme.txt
new file mode 100644
index 00000000..ee1f3aab
--- /dev/null
+++ b/extras/code_templates/readme.txt
@@ -0,0 +1,27 @@
+
+fpGUI Code Templates
+--------------------
+
+This is a directory where you will find fpGUI Code Templates for use with
+the Lazarus IDE.
+
+
+1) Open the template you want to add to Lazurus. For example basicapp.txt
+
+2) Open the lazarus.dci file with you favourite editor. This is the file that
+ Lazarus uses to store all code templates. The location of
+ the lararus.dci is normally as follows:
+
+ Linux:
+ /home/<your user name>/.lazarus/lazarus.dci
+
+3) Copy all the text from the template file you opened in (1).
+
+4) Move to the end of the lazarus.dci file you opened in (2) and paste the
+ text from the clipboard.
+
+5) Save the lazarus.dci file and you are ready to go!
+
+
+ -----------.oO0Oo.-----------
+
diff --git a/gfx/x11/gfx_x11.pas b/gfx/x11/gfx_x11.pas
index d8d49fbf..9285e49e 100644
--- a/gfx/x11/gfx_x11.pas
+++ b/gfx/x11/gfx_x11.pas
@@ -30,7 +30,7 @@ uses
SysUtils, Classes, // FPC units
X, XLib, XUtil, // X11 units
{$IFDEF XftSupport}
- unitxft; // Xft font support
+ unitxft, // Xft font support
{$ENDIF}
GfxBase, // fpGFX units
GELDirty; // fpGFX emulation layer
@@ -257,7 +257,12 @@ function GetXEventName(Event: LongInt): String;
implementation
uses
- GELImage, fpGFX;
+ GELImage
+ ,fpGFX
+ {$IFDEF XftSupport}
+ ,schar16 // Unicode support
+ {$ENDIF}
+ ;
resourcestring
SFontCreationFailed = 'Could not create font with descriptor "%s"';
@@ -334,9 +339,9 @@ begin
// FBufferWin := -1;
// FXftDrawBuffer := nil;
{$ENDIF}
- FXftDraw := XftDrawCreate(gApplication.Handle, Handle,
- XDefaultVisual(gApplication.Handle, XDefaultScreen(gApplication.Handle)),
- XDefaultColormap(gApplication.Handle, XDefaultScreen(gApplication.Handle)));
+ FXftDraw := XftDrawCreate(GFApplication.Handle, Handle,
+ XDefaultVisual(GFApplication.Handle, XDefaultScreen(GFApplication.Handle)),
+ XDefaultColormap(GFApplication.Handle, XDefaultScreen(GFApplication.Handle)));
{$ENDIF XftSupport}
end;
@@ -641,12 +646,12 @@ begin
Exit; //==>
{$IFDEF XftSupport}
- fnt := XftFontOpenName(gApplication.Handle, XDefaultScreen(gApplication.Handle), PChar('Sans-12'));
+ fnt := XftFontOpenName(GFApplication.Handle, XDefaultScreen(GFApplication.Handle), PChar('Sans-12'));
SetXftColor(FCurColor,fntColor);
s := u8(AText);
-// XftDrawString8(FXftDraw, fntColor, fnt, APosition.x, Aposition.y, PChar(AText),Length(AText));
- XftDrawString16(FXftDraw, fntColor, fnt, APosition.x, Aposition.y * 3, @s[1], Length16(s));
- XftFontClose(gApplication.Handle, fnt);
+ XftDrawString8(FXftDraw, fntColor, fnt, APosition.x, Aposition.y, PChar(AText),Length(AText));
+// XftDrawString16(FXftDraw, fntColor, fnt, APosition.x, Aposition.y * 3, @s[1], Length16(s));
+ XftFontClose(GFApplication.Handle, fnt);
{$ELSE}
XDrawString(GFApplication.Handle, Handle, GC, APosition.x,
APosition.y + FFontStruct^.ascent, PChar(AText), Length(AText));
@@ -1530,21 +1535,24 @@ begin
GFApplication.DirtyList.AddRect(Self, ARect);
end;
-
procedure TX11Window.PaintInvalidRegion;
begin
GFApplication.DirtyList.PaintQueueForWindow(Self);
end;
-
procedure TX11Window.CaptureMouse;
begin
- XGrabPointer(GFApplication.Handle, Handle, False, ButtonPressMask or
- ButtonReleaseMask or EnterWindowMask or LeaveWindowMask or
- PointerMotionMask, GrabModeAsync, GrabModeAsync, 0, 0, CurrentTime);
+ XGrabPointer(GFApplication.Handle, Handle,
+ True,
+ ButtonPressMask or ButtonReleaseMask or EnterWindowMask or LeaveWindowMask or PointerMotionMask,
+ GrabModeAsync,
+ GrabModeAsync,
+ 0,
+ 0,
+ CurrentTime
+ );
end;
-
procedure TX11Window.ReleaseMouse;
begin
XUngrabPointer(GFApplication.Handle, CurrentTime);
@@ -1615,7 +1623,7 @@ begin
end;
etMouseLeave:
begin
- if Assigned(OnMouseEnter) then OnMouseLeave(Self)
+ if Assigned(OnMouseLeave) then OnMouseLeave(Self)
else if Assigned(Parent) then Parent.ProcessEvent(AEvent);
end;
etMousePressed:
diff --git a/gui/buttons.inc b/gui/buttons.inc
index 9e62aa52..9e1465cb 100644
--- a/gui/buttons.inc
+++ b/gui/buttons.inc
@@ -41,6 +41,7 @@
TButton = class(TCustomButton)
published
property CanExpandWidth;
+ property CanExpandHeight;
property Enabled;
property Text;
property OnClick;
@@ -98,7 +99,6 @@ begin
Style.DrawButtonFace(Canvas, Rect(0, 0, BoundsSize.cx, BoundsSize.cy), Flags);
end;
-
// ===================================================================
// TCustomButton
// ===================================================================
@@ -139,7 +139,6 @@ begin
FDefSize := FMinSize + gfxbase.Size(20, 2);
end;
-
constructor TCustomButton.Create(const pText: string; pOwner: TComponent);
begin
Create(pOwner);
diff --git a/gui/combobox.inc b/gui/combobox.inc
index 5d225907..1d67773c 100644
--- a/gui/combobox.inc
+++ b/gui/combobox.inc
@@ -20,8 +20,6 @@
{ Combobox widget declarations }
- { TCustomComboBox }
-
TComboBoxPopup = class(TPopupWindow)
private
FLayout: TBoxLayout;
@@ -37,12 +35,12 @@
FItemIndex: Integer;
FItems: TStrings;
FOnChange: TNotifyEvent;
- procedure ButtonClick(Sender: TObject);
+ procedure ComboBoxButtonClick(Sender: TObject);
procedure DropDownDeactivate(Sender: TObject);
procedure DropDownDestroy(Sender: TObject);
procedure SetItemIndex(const AValue: Integer);
protected
- FButton: TGenericButton;
+ ComboBoxButton: TGenericButton;
FDropDown: TComboBoxPopup;
lbl: TLabel;
procedure Click; override;
@@ -98,7 +96,7 @@ end;
procedure TArrowButton.CalcSizes;
begin
- FMinSize := Style.GetComboBoxArrowSize;
+ FMinSize := Style.GetComboBoxBtnSize;
end;
constructor TComboBoxPopup.Create(AOwner: TComponent);
@@ -107,15 +105,16 @@ begin
WidgetStyle := WidgetStyle + [wsCaptureMouse, wsClickable, wsOpaque];
BorderWidth := 1;
Color := clBlack;
+ Name := '#ComboBoxPopup';
FLayout := TBoxLayout.Create(self);
- FLayout.Name := 'VBox';
+ FLayout.Name := '#VBoxLayout';
FLayout.Orientation := Vertical;
FLayout.Spacing := 0;
InsertChild(FLayout);
FListBox := TListBox.Create(self);
- FListBox.Name := 'Listbox';
+ FListBox.Name := '#Listbox';
FListBox.HotTrack := True;
FLayout.InsertChild(FListBox);
end;
@@ -133,12 +132,13 @@ begin
FItems := TStringList.Create;
FItemIndex := -1;
- FButton := TArrowButton.Create(Self);
- FButton.Name := 'FButton';
- FButton.Embedded := True;
- FButton.CanExpandWidth := False;
- FButton.OnClick := @ButtonClick;
- FButton.Parent := Self;
+ ComboBoxButton := TArrowButton.Create(Self);
+ ComboBoxButton.Name := '#ComboBoxButton';
+ ComboBoxButton.Embedded := True;
+ ComboBoxButton.CanExpandWidth := False;
+ ComboBoxButton.CanExpandHeight := False;
+ ComboBoxButton.OnClick := @ComboBoxButtonClick;
+ ComboBoxButton.SetEmbeddedParent(Self);
end;
destructor TCustomComboBox.Destroy;
@@ -152,6 +152,8 @@ var
Pt: TPoint;
ItemRect: TRect;
ItemFlags: TItemFlags;
+ c: TFCanvas;
+ r: TRect;
begin
ItemFlags := [];
Style.DrawEditBox(Canvas, Rect(0, 0, Width, Height));
@@ -168,14 +170,28 @@ begin
Include(ItemFlags, ifSelected);
end;
- ItemRect := Rect(0, 0, (Width - FButton.Width), Height);
+ ItemRect := Rect(0, 0, (Width - ComboBoxButton.Width), Height);
// InflateRect(ItemRect, -1, -1);
ItemRect.TopLeft := ItemRect.TopLeft + 1;
ItemRect.BottomRight := ItemRect.BottomRight - 2;
- Style.DrawItemBefore(Canvas, ItemRect, ItemFlags);
- Style.DrawText(Canvas, Pt, Text, WidgetState);
- Style.DrawItemAfter(Canvas, ItemRect, ItemFlags);
+ { Text must be clipped before reaching the button }
+// try
+// Canvas.SaveState;
+// writeln(Format('Canvas size Before %d:%d', [Canvas.Width, Canvas.Height]));
+// r := Canvas.Transform(ComboBoxButton.BoundsRect);
+// writeln(Format(' Bounding rectangle (%d:%d)x(%d:%d)', [BoundsRect.Top, BoundsRect.Left, BoundsRect.Bottom, BoundsRect.Right]));
+// writeln(Format(' Canvas rectangle (%d:%d)x(%d:%d)', [Canvas.GetClipRect.Top, Canvas.GetClipRect.Left, Canvas.GetClipRect.Bottom, Canvas.GetClipRect.Right]));
+// writeln(Format(' ComboButton rectangle (%d:%d)x(%d:%d)', [r.Top, r.Left, r.Bottom, r.Right]));
+// Canvas.IntersectClipRect(r);
+// writeln(Format('Canvas size After %d:%d', [Canvas.Width, Canvas.Height]));
+
+ Style.DrawItemBefore(Canvas, ItemRect, ItemFlags);
+ Style.DrawText(Canvas, Pt, Text, WidgetState);
+ Style.DrawItemAfter(Canvas, ItemRect, ItemFlags);
+// finally
+// Canvas.RestoreState;
+// end;
end
else
begin
@@ -187,25 +203,26 @@ end;
procedure TCustomComboBox.CalcSizes;
begin
with Style.GetEditBoxBorders do
- FMinSize := gfxBase.Size(FButton.MinSize.cx,
- Max(FindForm.Wnd.Canvas.FontCellHeight, FButton.MinSize.cy)) +
+ FMinSize := Size(ComboBoxButton.MinSize.cx,
+ Max(FindForm.Wnd.Canvas.FontCellHeight, ComboBoxButton.MinSize.cy)) +
TopLeft + BottomRight;
end;
procedure TCustomComboBox.Resized;
begin
with Style.GetEditBoxBorders do
- FButton.SetBounds(Point(Width - Right - FButton.MinSize.cx, Top),
- FButton.MinSize);
+ ComboBoxButton.SetBounds(
+ Point(Width - Right - ComboBoxButton.MinSize.cx, Top),
+ ComboBoxButton.MinSize);
end;
function TCustomComboBox.DistributeEvent(Event: TEventObj): Boolean;
begin
- Result := Event.SendToChild(FButton) or
- inherited DistributeEvent(Event);
+ Result := Event.SendToChild(ComboBoxButton);
+// or inherited DistributeEvent(Event);
end;
-procedure TCustomComboBox.ButtonClick(Sender: TObject);
+procedure TCustomComboBox.ComboBoxButtonClick(Sender: TObject);
begin
if Assigned(FDropDown) and FDropDown.Visible then
begin
@@ -262,7 +279,7 @@ end;
component, or press the spacebar key. }
procedure TCustomComboBox.Click;
begin
- ButtonClick(nil);
+ ComboBoxButtonClick(nil);
inherited Click;
end;
diff --git a/gui/menus.inc b/gui/menus.inc
index f2cbc8e7..b4622fdf 100644
--- a/gui/menus.inc
+++ b/gui/menus.inc
@@ -30,6 +30,7 @@
FSeparator: boolean;
protected
procedure Paint(Canvas: TFCanvas); override;
+ function ProcessEvent(Event: TEventObj): Boolean; override;
public
constructor Create(const pText: string; pOwner: TComponent); overload;
published
@@ -71,6 +72,18 @@ begin
inherited Paint(Canvas);
end;
+function TMenuItem.ProcessEvent(Event: TEventObj): Boolean;
+begin
+ {$IFDEF DEBUG}
+ if Event.InheritsFrom(TMouseEnterEventObj) then
+ writeln(Format('MouseEnter for %s:%s', [Text, Classname]))
+ else if Event.InheritsFrom(TMouseLeaveEventObj) then
+ writeln(Format('MouseLeave for %s:%s', [Text, Classname]));
+ {$ENDIF}
+
+ Result:=inherited ProcessEvent(Event);
+end;
+
constructor TMenuItem.Create(const pText: string; pOwner: TComponent);
begin
inherited Create(pText, pOwner);
diff --git a/gui/scrollbar.inc b/gui/scrollbar.inc
index f6eb59f4..b2bfda1f 100644
--- a/gui/scrollbar.inc
+++ b/gui/scrollbar.inc
@@ -167,7 +167,6 @@ begin
WidgetStyle := WidgetStyle + [wsCaptureMouse, wsClickable, wsOpaque];
end;
-
procedure TScrollBarSlider.UpdateBar;
var
Size: Integer;
@@ -199,7 +198,6 @@ begin
end;
end;
-
procedure TScrollBarSlider.Paint(Canvas: TFCanvas);
var
Size: Integer;
@@ -256,7 +254,6 @@ begin
Style.DrawButtonFace(Canvas, r, [btnIsEmbedded]);
end;
-
function TScrollBarSlider.ProcessEvent(Event: TEventObj): Boolean;
begin
Result := False;
@@ -274,7 +271,6 @@ begin
UpdateBar;
end;
-
function TScrollBarSlider.EvMousePressed(Event: TMousePressedEventObj): Boolean;
var
Pos: Integer;
@@ -309,9 +305,7 @@ begin
Result := True;
end;
-
-function TScrollBarSlider.EvMouseReleased(
- Event: TMouseReleasedEventObj): Boolean;
+function TScrollBarSlider.EvMouseReleased(Event: TMouseReleasedEventObj): Boolean;
var
NewPosition: Integer;
begin
@@ -348,7 +342,6 @@ begin
Result := True;
end;
-
function TScrollBarSlider.EvMouseMove(Event: TMouseMoveEventObj): Boolean;
var
Pos, Size, VirtualPos: Integer;
@@ -356,6 +349,7 @@ begin
if IsDraggingButton then
begin
if wsMouseInside in WidgetState then
+ begin
if TCustomScrollBar(Owner).Orientation = Horizontal then
begin
Pos := Event.Position.x;
@@ -364,7 +358,8 @@ begin
begin
Pos := Event.Position.y;
Size := Height;
- end
+ end;
+ end
else
begin
Pos := DragStartMousePos;
@@ -372,7 +367,7 @@ begin
Size := Width
else
Size := Height;
- end;
+ end; { if/else }
ButtonPos := ClipMinMax(DragStartButtonPos + Pos - DragStartMousePos,
0, Size - ButtonSize);
@@ -391,7 +386,6 @@ begin
Result := False;
end;
-
procedure TScrollBarSlider.CalcSizes;
begin
if TCustomScrollBar(Owner).Orientation = Horizontal then
@@ -400,31 +394,31 @@ begin
FDefSize.cy := Style.GetScrollBarBtnSize(Vertical).cx * 5;
end;
-
function TScrollBarSlider.CalcPosition: Integer;
var
Size: Integer;
+ lOwner: TCustomScrollBar;
begin
- with TCustomScrollBar(Owner) do
- begin
- if Orientation = Horizontal then
- Size := Self.Width
- else
- Size := Self.Height;
+ Assert(Owner is TCustomScrollBar);
+ lOwner := TCustomScrollBar(Owner);
+
+ if lOwner.Orientation = Horizontal then
+ Size := Width
+ else
+ Size := Height;
- if Size = ButtonSize then
- Position := 0
+ if Size = ButtonSize then
+ lOwner.Position := 0
+ else
+ begin
+ if lOwner.PageSize = 0 then
+ Result := ButtonPos * (lOwner.Max - lOwner.Min + 1)
else
- begin
- if PageSize = 0 then
- Result := ButtonPos * (Max - Min + 1)
- else
- Result := ButtonPos * (Max - Min - PageSize + 2);
- Result := Result div (Size - ButtonSize);
- Result := Result + Min;
- end;
- Result := ClipPosition(Result);
+ Result := ButtonPos * (lOwner.Max - lOwner.Min - lOwner.PageSize + 2);
+ Result := Result div (Size - ButtonSize);
+ Result := Result + lOwner.Min;
end;
+ Result := lOwner.ClipPosition(Result);
end;
@@ -438,8 +432,8 @@ begin
Include(WidgetStyle, wsOpaque);
Embedded := False;
- FMax := 100;
- FSmallChange := 1;
+ FMax := 100;
+ FSmallChange := 1;
ButtonUp := TScrollBarButton.Create(Self);
ButtonUp.Name := '#ScrollBarButtonUp';
@@ -451,7 +445,7 @@ begin
ButtonUp.SetEmbeddedParent(Self);
Slider := TScrollBarSlider.Create(Self);
- Slider.Name := '#ScrollBarSlider';
+ Slider.Name := '#ScrollBarSlider';
Slider.SetEmbeddedParent(Self);
ButtonDown := TScrollBarButton.Create(Self);
@@ -464,19 +458,16 @@ begin
ButtonDown.SetEmbeddedParent(Self);
end;
-
procedure TCustomScrollBar.LineUp;
begin
Position := Position - SmallChange;
end;
-
procedure TCustomScrollBar.LineDown;
begin
Position := Position + SmallChange;
end;
-
procedure TCustomScrollBar.PageUp;
var
Diff: Integer;
@@ -703,11 +694,13 @@ end;
function TCustomScrollBar.ClipPosition(APosition: Integer): Integer;
begin
- if APosition > Max - PageSize then
+ if APosition > (Max - PageSize) then
+ begin
if PageSize = 0 then
Result := Max
else
- Result := Max - PageSize + 1
+ Result := Max - PageSize + 1;
+ end
else
Result := APosition;
if Result < Min then
diff --git a/gui/style.inc b/gui/style.inc
index c71dce16..ef32d399 100644
--- a/gui/style.inc
+++ b/gui/style.inc
@@ -70,6 +70,7 @@
// Combo boxes
function GetComboBoxArrowSize: TSize; virtual; abstract;
procedure DrawComboBoxArrow(Canvas: TFCanvas; const ARect: TRect; IsPressed, IsEnabled: Boolean); virtual; abstract;
+ function GetComboBoxBtnSize: TSize; virtual; abstract;
// Scroll bars
function GetScrollBarBorders(Orientation: TOrientation): TRect; virtual; abstract;
function GetScrollBarBtnSize(Orientation: TOrientation): TSize; virtual; abstract;
@@ -127,6 +128,7 @@
// Combo boxes
procedure DrawComboBoxArrow(Canvas: TFCanvas; const ARect: TRect; IsPressed, IsEnabled: Boolean); override;
function GetComboBoxArrowSize: TSize; override;
+ function GetComboBoxBtnSize: TSize; override;
// Scroll bars
function GetScrollBarBorders(Orientation: TOrientation): TRect; override;
function GetScrollBarBtnSize(Orientation: TOrientation): TSize; override;
@@ -627,7 +629,14 @@ end;
function TDefaultStyle.GetComboBoxArrowSize: TSize;
begin
- Result := Size(16, 17);
+ Result.cx := 17;
+ Result.cy := 17;
+end;
+
+function TDefaultStyle.GetComboBoxBtnSize: TSize;
+begin
+ Result.cx := 18;
+ Result.cy := 18;
end;
procedure TDefaultStyle.DrawComboBoxArrow(Canvas: TFCanvas;
diff --git a/gui/widget.inc b/gui/widget.inc
index cfd2b17c..e277bcf9 100644
--- a/gui/widget.inc
+++ b/gui/widget.inc
@@ -426,15 +426,11 @@ end;
function TMouseLeaveCheckEventObj.SendToChild(AChild: TWidget): Boolean;
begin
-(* if AChild = AChild.FindForm.MouseCaptureWidget then
- WriteLn('CapturedWidget: Leave check for ', MouseX, ' / ', MouseY);
- if {(AChild <> AChild.FindForm.MouseCaptureWidget) and}
- ((MouseX < AChild.Left) or (MouseY < AChild.Top) or
- (MouseX >= AChild.Left + AChild.Width) or
- (MouseY >= AChild.Top + AChild.Height)) and
- (wsMouseInside in AChild.WidgetState) then
- AChild.SendEvent(TMouseLeaveEventObj.Create(Self));
-*)
+ if ((FPosition.X < AChild.Left) or (FPosition.Y < AChild.Top) or
+ (FPosition.X >= AChild.Left + AChild.Width) or
+ (FPosition.Y >= AChild.Top + AChild.Height)) and
+ (wsMouseInside in AChild.WidgetState) then
+ AChild.SendEvent(TMouseLeaveEventObj.Create(Self));
Result := inherited SendToChild(AChild);
end;
@@ -1224,9 +1220,9 @@ function TWidget.EvCalcSizes(Event: TCalcSizesEventObj): Boolean;
begin
LAYOUTTRACE('TWidget.EvCalcSizes for %s:%s', [Name, ClassName]);
- FMinSize := gfxbase.Size(0, 0);
- FMaxSize := gfxbase.Size(InfiniteSize, InfiniteSize);
- FDefSize := gfxbase.Size(0, 0);
+ FMinSize := Size(0, 0);
+ FMaxSize := Size(InfiniteSize, InfiniteSize);
+ FDefSize := Size(0, 0);
CalcSizes;
@@ -1329,7 +1325,9 @@ begin
(wsEnabled in WidgetState) then
Redraw;
Result := False;
- // WriteLn('Mouse entered ', Name, ':', ClassName, '. New cursor: ', Ord(Event.NewCursor));
+ {$IFDEF DEBUG}
+ WriteLn('Mouse entered ', Name, ':', ClassName, '. New cursor: ', Ord(Event.NewCursor));
+ {$ENDIF}
end;
function TWidget.EvMouseLeave(Event: TMouseLeaveEventObj): Boolean;
@@ -1339,7 +1337,9 @@ begin
(wsEnabled in WidgetState) then
Redraw;
Result := False;
- // WriteLn('Mouse left ', Name, ':', ClassName);
+ {$IFDEF DEBUG}
+ WriteLn('Mouse left ', Name, ':', ClassName);
+ {$ENDIF}
end;
function TWidget.EvMouseLeaveCheck(Event: TMouseLeaveCheckEventObj): Boolean;
diff --git a/prototypes/multihandle/gui2Base.pas b/prototypes/multihandle/gui2Base.pas
index d7197f88..90fcc843 100644
--- a/prototypes/multihandle/gui2Base.pas
+++ b/prototypes/multihandle/gui2Base.pas
@@ -192,7 +192,6 @@ begin
if wsClicked in FWidgetState then
begin
Exclude(FWidgetState, wsClicked);
- Exclude(FWidgetState, wsHasFocus);
Paint;
if Assigned(OnClick) then
OnClick(self);
@@ -209,13 +208,14 @@ begin
begin
Include(FWidgetState, wsClicked);
SetFocus;
- Paint;
+// Paint;
end;
end;
procedure TWidget.EvOnMouseLeave(Sender: TObject);
begin
-// Exclude(FWidgetState, wsHasFocus);
+ Exclude(FWidgetState, wsHasFocus);
+ Paint;
end;
procedure TWidget.SetColor(const AValue: TGfxColor);
@@ -280,6 +280,7 @@ end;
procedure TWidget.SetFocus;
begin
Include(FWidgetState, wsHasFocus);
+ Paint;
// FindForm.FocusedWidget := Self;
end;
@@ -323,16 +324,7 @@ begin
Include(lFlags, btnIsSelected);
end;
- if btnIsSelected in lFlags then
- begin
- Canvas.SetColor(cl3DDkShadow);
- Canvas.DrawRect(r);
- Inc(r.Left);
- Inc(r.Top);
- Dec(r.Right);
- Dec(r.Bottom);
- end;
-
+ { draw actual button }
if btnIsPressed in lFlags then
begin
Canvas.SetColor(cl3DShadow);
@@ -343,8 +335,23 @@ begin
Dec(r.Bottom);
end
else
+ begin
Draw3DFrame(TFCanvas(Canvas), r, cl3DHighlight, cl3DLight, cl3DDkShadow, cl3DShadow);
-
+ end;
+
+ { draw focus rectangle }
+ if (btnIsSelected in lFlags) and not (btnIsPressed in lFlags) then
+ begin
+ Inc(r.Left, 2);
+ Inc(r.Top, 2);
+ Dec(r.Right, 2);
+ Dec(r.Bottom, 2);
+ Canvas.SetColor(cl3DDkShadow);
+ Canvas.SetLineStyle(lsDot);
+ Canvas.DrawRect(r);
+ Canvas.SetLineStyle(lsSolid);
+ end;
+
Canvas.SetColor(colBlack);
Pt.x := (Width - Canvas.TextWidth(FCaption)) div 2;
Pt.y := ((Height - Canvas.FontCellHeight) div 2) + 1;