summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/gui/menutest/menutest.lpr34
-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
4 files changed, 66 insertions, 30 deletions
diff --git a/examples/gui/menutest/menutest.lpr b/examples/gui/menutest/menutest.lpr
index 1ed77135..c95c49de 100644
--- a/examples/gui/menutest/menutest.lpr
+++ b/examples/gui/menutest/menutest.lpr
@@ -22,6 +22,7 @@ type
FHelpSubMenu: TfpgPopupMenu;
edit1: TfpgEdit;
procedure miExitClicked(Sender: TObject);
+ procedure miMenuItemSelected(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
end;
@@ -34,6 +35,12 @@ begin
Close;
end;
+procedure TMainForm.miMenuItemSelected(Sender: TObject);
+begin
+ if Sender is TfpgMenuItem then
+ writeln('Menu clicked: ', TfpgMenuItem(Sender).Text);
+end;
+
constructor TMainForm.Create(AOwner: TComponent);
var
mi: TfpgMenuItem;
@@ -45,29 +52,29 @@ begin
// Create top level sub-menus
FFileSubMenu := TfpgPopupMenu.Create(self);
- FFileSubMenu.AddMenuItem('&Open', 'Ctrl-O', nil);
- FFileSubMenu.AddMenuItem('&Save', 'Ctrl-S', nil);
- FFileSubMenu.AddMenuItem('S&ave As', 'Ctrl+Shift+S', nil);
+ FFileSubMenu.AddMenuItem('&Open', 'Ctrl-O', @miMenuItemSelected);
+ FFileSubMenu.AddMenuItem('&Save', 'Ctrl-S', @miMenuItemSelected);
+ FFileSubMenu.AddMenuItem('S&ave As', 'Ctrl+Shift+S', @miMenuItemSelected);
FFileSubMenu.AddMenuItem('-', '', nil);
- FFileSubMenu.AddMenuItem('Save && Reload', '', nil);
+ FFileSubMenu.AddMenuItem('Save && Reload', '', @miMenuItemSelected);
FFileSubMenu.AddMenuItem('-', '', nil);
FFileSubMenu.AddMenuItem('&Quit', 'Ctrl-Q', @miExitClicked);
FEditSubMenu := TfpgPopupMenu.Create(self);
- FEditSubMenu.AddMenuItem('&Cut', 'Ctrl-X', nil);
- FEditSubMenu.AddMenuItem('C&opy', 'Ctrl-C', nil);
- FEditSubMenu.AddMenuItem('&Paste', 'Ctrl-V', nil);
+ FEditSubMenu.AddMenuItem('&Cut', 'Ctrl-X', @miMenuItemSelected);
+ FEditSubMenu.AddMenuItem('C&opy', 'Ctrl-C', @miMenuItemSelected);
+ FEditSubMenu.AddMenuItem('&Paste', 'Ctrl-V', @miMenuItemSelected);
FEditSubMenu.AddMenuItem('-', '', nil);
- FEditSubMenu.AddMenuItem('&Spell check', 'F4', nil).Enabled := False;
+ FEditSubMenu.AddMenuItem('&Spell check', 'F4', @miMenuItemSelected).Enabled := False;
FEditSelectSubMenu := TfpgPopupMenu.Create(self);
FEditSubMenu.AddMenuItem('Selec&t', '', nil).SubMenu := FEditSelectSubMenu;
- FEditSelectSubMenu.AddMenuItem('Select All', '', nil);
- FEditSelectSubMenu.AddMenuItem('Select Word', '', nil);
- FEditSelectSubMenu.AddMenuItem('Select Line', '', nil);
+ FEditSelectSubMenu.AddMenuItem('Select All', '', @miMenuItemSelected);
+ FEditSelectSubMenu.AddMenuItem('Select Word', '', @miMenuItemSelected);
+ FEditSelectSubMenu.AddMenuItem('Select Line', '', @miMenuItemSelected);
FHelpSubMenu := TfpgPopupMenu.Create(self);
- FHelpSubMenu.AddMenuItem('&About', 'F12', nil);
- FHelpSubMenu.AddMenuItem('Test Russian text -> Òåñò', '', nil);
+ FHelpSubMenu.AddMenuItem('&About', 'F12', @miMenuItemSelected);
+ FHelpSubMenu.AddMenuItem('Test Russian text -> Òåñò', '', @miMenuItemSelected);
// Create main menu bar
FMenuBar := TfpgMenuBar.Create(self);
@@ -78,7 +85,6 @@ begin
FMenuBar.AddMenuItem('&Disabled', nil).Enabled := False;
FMenuBar.AddMenuItem('&Help', nil).SubMenu := FHelpSubMenu;
-
edit1 := TfpgEdit.Create(self);
edit1.SetPosition(10, 70, 100, 24);
end;
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;