diff options
author | Graeme Geldenhuys <graemeg@users.sourceforge.net> | 2007-03-07 10:14:45 +0000 |
---|---|---|
committer | Graeme Geldenhuys <graemeg@users.sourceforge.net> | 2007-03-07 10:14:45 +0000 |
commit | a78f65fa1c1dc35922205e7cf88ac431aee59bb6 (patch) | |
tree | 9d39771e1138d8efec2d267ff3f3de2e0709185f /gui/menus.inc | |
parent | 835b1aaa20d62437be9f2d552d0e2eebc9256286 (diff) | |
download | fpGUI-a78f65fa1c1dc35922205e7cf88ac431aee59bb6.tar.xz |
* Added more debug events.
* Implemented a very basic TPopupMenu
* Modified the WidgetTest demo to show the basic popup menu (still needs work).
Diffstat (limited to 'gui/menus.inc')
-rw-r--r-- | gui/menus.inc | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/gui/menus.inc b/gui/menus.inc index bbe356c0..cad0f3c9 100644 --- a/gui/menus.inc +++ b/gui/menus.inc @@ -22,17 +22,26 @@ {$IFDEF read_interface} + TPopupMenu = class; + TMenuBar = class; + { TMenuItem } TMenuItem = class(TCustomPanel) private FHotKeyDef: string; FSeparator: boolean; + FSubMenu: TPopupMenu; + function GetSubMenu: TPopupMenu; + procedure InternalShowPopupMenu; protected procedure Paint(Canvas: TFCanvas); override; function ProcessEvent(Event: TEventObj): Boolean; override; + procedure Click; override; public constructor Create(const pText: string; pOwner: TComponent); overload; + destructor Destroy; override; + property SubMenu: TPopupMenu read GetSubMenu; published property Separator: boolean read FSeparator write FSeparator; property HotKeyDef: string read FHotKeyDef write FHotKeyDef; @@ -40,6 +49,19 @@ property Visible; property Enabled; end; + + + { TPopupMenu } + + TPopupMenu = class(TPopupWindow) + private + FMenu: TMenuBar; + public + constructor Create(AOwner: TComponent); override; + destructor Destroy; override; + function AddMenu(const pTitle: string): TMenuItem; + function AddMenu(const pTitle: string; const pHotKeyDef: string; pHandlerProc: TNotifyEvent): TMenuItem; + end; { TMenuBar } @@ -62,6 +84,31 @@ { TMenuItem } +function TMenuItem.GetSubMenu: TPopupMenu; +begin + if not Assigned(FSubMenu) then + FSubMenu := TPopupMenu.Create(self); + Result := FSubMenu; +end; + +procedure TMenuItem.InternalShowPopupMenu; +begin + if Assigned(FSubMenu) and FSubMenu.Visible then + begin + FSubMenu.Close; + Exit; //==> + end; + + if not Assigned(FSubMenu) then + begin + FSubMenu := TPopupMenu.Create(Self); + end; + + FSubMenu.SetPosition(ClientToScreen(Point(0, Height))); + FSubMenu.Show; + FSubMenu.Wnd.SetMinMaxClientSize(MaxSize, MaxSize); +end; + procedure TMenuItem.Paint(Canvas: TFCanvas); begin if (wsClicked in WidgetState) or (wsMouseInside in WidgetState) then @@ -90,6 +137,11 @@ begin else if Event.InheritsFrom(TMouseLeaveEventObj) then begin Exclude(WidgetState, wsMouseInside); +// if Assigned(FSubMenu) and (FSubMenu.Visible) then +// begin +// writeln('1111111111111'); +// FSubMenu.Close; +// end; Redraw; result := True; end @@ -97,6 +149,16 @@ begin result := inherited ProcessEvent(Event); end; +procedure TMenuItem.Click; +begin + if (wsMouseInside in WidgetState) and Assigned(FSubMenu) then + begin + InternalShowPopupMenu; + end + else + inherited Click; +end; + constructor TMenuItem.Create(const pText: string; pOwner: TComponent); begin inherited Create(pText, pOwner); @@ -104,6 +166,49 @@ begin FBevelStyle := bsPlain; end; +destructor TMenuItem.Destroy; +begin + if Assigned(FSubMenu) then + FSubMenu.Free; + inherited Destroy; +end; + +{ TPopupMenu } + +constructor TPopupMenu.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + WidgetStyle := WidgetStyle + [wsCaptureMouse, wsClickable, wsOpaque]; + BorderWidth := 1; + Color := clBlack; + Name := '#MenuPopup'; + + FMenu := TMenuBar.Create(self); + FMenu.Name := '#VBoxMenu'; + FMenu.Orientation := Vertical; + FMenu.Spacing := 0; + InsertChild(FMenu); +end; + +destructor TPopupMenu.Destroy; +begin + FMenu.Free; + inherited Destroy; +end; + +function TPopupMenu.AddMenu(const pTitle: string): TMenuItem; +begin + Result := FMenu.AddMenu(pTitle); +end; + +function TPopupMenu.AddMenu(const pTitle: string; const pHotKeyDef: string; + pHandlerProc: TNotifyEvent): TMenuItem; +begin + Result := FMenu.AddMenu(pTitle, photKeyDef, pHandlerProc); +end; + +{ TMenuBar } + constructor TMenuBar.Create(AOwner: TComponent); begin inherited Create(AOwner); |