summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-01-04 15:01:00 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-01-04 15:01:00 +0000
commitc780e72b9f7f6d7eb39fcee5b551e4b285f58106 (patch)
tree601d04f58faf50b83b640a826975be85cde06c8f /src
parentb742ef33b0d8657e556e1182bccd89c224bff844 (diff)
downloadfpGUI-c780e72b9f7f6d7eb39fcee5b551e4b285f58106.tar.xz
* GUI: Moved all MenuItem painting into the Paint event handler.
* GUI: MenuItems OnClick is now triggered on mouse button up (like all other toolkits). * GUI: Clicking outside a menu while it's open doesn't trigger the OnClick event anymore. * Examples: Extended the menu example to show when each menu item's OnClick was triggered. * All the above needs testing under Windows.
Diffstat (limited to 'src')
-rw-r--r--src/corelib/gfx_command_intf.pas6
-rw-r--r--src/gui/gui_button.pas2
-rw-r--r--src/gui/gui_menu.pas54
3 files changed, 46 insertions, 16 deletions
diff --git a/src/corelib/gfx_command_intf.pas b/src/corelib/gfx_command_intf.pas
index 3e5133de..61eb89cd 100644
--- a/src/corelib/gfx_command_intf.pas
+++ b/src/corelib/gfx_command_intf.pas
@@ -1,10 +1,14 @@
+{
+ This is based on the Command design pattern. Use Google if you don't
+ know what design patterns are. The Command pattern is very similar to
+ Delphi's TAction feature.
+}
unit gfx_command_intf;
{$mode objfpc}{$H+}
interface
-
type
ICommand = interface(IInterface)
['{28D72102-D883-41A1-9585-D86B24D9C628}']
diff --git a/src/gui/gui_button.pas b/src/gui/gui_button.pas
index 85377623..ff5a22ee 100644
--- a/src/gui/gui_button.pas
+++ b/src/gui/gui_button.pas
@@ -1,7 +1,7 @@
{
fpGUI - Free Pascal GUI Library
- Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this
+ Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this
distribution, for details of the copyright.
See the file COPYING.modifiedLGPL, included in this distribution,
diff --git a/src/gui/gui_menu.pas b/src/gui/gui_menu.pas
index ac49070e..3cdb9f27 100644
--- a/src/gui/gui_menu.pas
+++ b/src/gui/gui_menu.pas
@@ -1,7 +1,7 @@
{
fpGUI - Free Pascal GUI Library
- Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this
+ Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this
distribution, for details of the copyright.
See the file COPYING.modifiedLGPL, included in this distribution,
@@ -22,7 +22,7 @@ unit gui_menu;
{
TODO:
* Refactor the HotKey painting code into Canvas.DrawString so that other
- widgets like TfpgButton could also use it.gui_menu
+ widgets like TfpgButton could also use it.
* Global keyboard activation of menu items are still missing.
}
@@ -79,7 +79,7 @@ type
end;
- // Actual Menu Items are stored in TComponents Components property
+ // Actual Menu Items are stored in TComponent's Components property
// Visible only items are stored in FItems just before a paint
TfpgPopupMenu = class(TfpgPopupWindow)
private
@@ -103,8 +103,10 @@ type
FSymbolWidth: integer;
FItems: TList;
FFocusItem: integer;
+ procedure HandleMouseExit; override;
procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); override;
procedure HandleLMouseDown(x, y: integer; shiftstate: TShiftState); override;
+ procedure HandleLMouseUp(x, y: integer; shiftstate: TShiftState); override;
procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override;
procedure HandlePaint; override;
procedure HandleShow; override;
@@ -360,6 +362,9 @@ begin
if newf = FFocusItem then
Exit; //==>
+ //if VisibleItem(newf).SubMenu.Visible then
+ //exit;
+
DrawColumn(FFocusItem, False);
FFocusItem := newf;
DrawColumn(FFocusItem, True);
@@ -648,8 +653,9 @@ end;
procedure TfpgPopupMenu.SetBackgroundColor(const AValue: TfpgColor);
begin
- if FBackgroundColor=AValue then exit;
- FBackgroundColor:=AValue;
+ if FBackgroundColor = AValue then Exit; //==>
+ Exit;
+ FBackgroundColor := AValue;
end;
procedure TfpgPopupMenu.DoSelect;
@@ -731,18 +737,33 @@ begin
if newf = FFocusItem then
Exit; //==>
- DrawRow(FFocusItem, False);
FFocusItem := newf;
- DrawRow(FFocusItem, True);
-// repaint;
+ Repaint;
end;
procedure TfpgPopupMenu.HandleLMouseDown(x, y: integer; shiftstate: TShiftState);
var
+ r: TfpgRect;
+begin
+ inherited HandleLMouseDown(x, y, shiftstate);
+
+ r.SetRect(0, 0, Width, Height);
+ if not PtInRect(r, Point(x, y)) then
+ begin
+// writeln('Pointer out of bounds.');
+ ClosePopups;
+ Exit;
+ end;
+end;
+
+procedure TfpgPopupMenu.HandleLMouseUp(x, y: integer; shiftstate: TShiftState);
+var
newf: integer;
mi: TfpgMenuItem;
+ r: TfpgRect;
begin
inherited HandleLMouseUp(x, y, shiftstate);
+
newf := CalcMouseRow(y);
if not VisibleItem(newf).Selectable then
@@ -775,8 +796,7 @@ var
begin
if oldf <> FFocusItem then
begin
- DrawRow(oldf, False);
- DrawRow(FFocusItem, True);
+ Repaint;
end;
end;
@@ -882,10 +902,10 @@ begin
Canvas.SetColor(clWidgetFrame);
Canvas.DrawRectangle(0, 0, Width, Height); // black rectangle border
Canvas.DrawButtonFace(1, 1, Width-1, Height-1, []); // 3d rectangle inside black border
+
for n := 1 to VisibleCount do
- begin
DrawRow(n, n = FFocusItem);
- end;
+
Canvas.EndDraw;
end;
@@ -970,7 +990,6 @@ begin
end
else
begin
-// Canvas.SetColor(clInactiveSel);
Canvas.SetColor(clShadow1);
Canvas.SetTextColor(clInactiveSelText);
end;
@@ -1029,6 +1048,13 @@ begin
end;
end;
+procedure TfpgPopupMenu.HandleMouseExit;
+begin
+ inherited HandleMouseExit;
+ FFocusItem := 0;
+ Repaint;
+end;
+
// Collecting visible items and measuring sizes
procedure TfpgPopupMenu.PrepareToShow;
var
@@ -1116,7 +1142,7 @@ begin
FSymbolWidth := FMenuFont.Height+2;
FBeforeShow := nil;
- FFocusItem := 1;
+ FFocusItem := 0;
OpenerPopup := nil;
OpenerMenubar := nil;
end;