1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
|
{ $Id: FpGuiwsmenus.pp 5319 2004-03-17 20:11:29Z marc $}
{
*****************************************************************************
* FpGuiWSMenus.pp *
* ------------ *
* *
* *
*****************************************************************************
*****************************************************************************
This file is part of the Lazarus Component Library (LCL)
See the file COPYING.LCL, included in this distribution,
for details about the license.
*****************************************************************************
}
unit FpGuiWSMenus;
{$mode delphi}{$H+}
interface
uses
// LCL
SysUtils, Menus, Forms, Controls,
// widgetset
WSMenus, WSLCLClasses, LCLType, fpguiobjects, fpguiwsprivate,
// interface
fpg_base, fpg_main, fpg_menu;
type
{ TFpGuiWSMenuItem }
TFpGuiWSMenuItem = class(TWSMenuItem)
private
protected
published
class procedure AttachMenu(const AMenuItem: TMenuItem); override;
class function CreateHandle(const AMenuItem: TMenuItem): HMENU; override;
class procedure DestroyHandle(const AMenuItem: TMenuItem); override;
class procedure SetCaption(const AMenuItem: TMenuItem; const ACaption: string); override;
// class procedure SetShortCut(const AMenuItem: TMenuItem; const ShortCutK1, ShortCutK2: TShortCut); override;
class procedure SetVisible(const AMenuItem: TMenuItem; const Visible: boolean); override;
class function SetCheck(const AMenuItem: TMenuItem; const Checked: boolean): boolean; override;
class function SetEnable(const AMenuItem: TMenuItem; const Enabled: boolean): boolean; override;
// class function SetRadioItem(const AMenuItem: TMenuItem; const RadioItem: boolean): boolean; override;
// class function SetRightJustify(const AMenuItem: TMenuItem; const Justified: boolean): boolean; override;
// class procedure UpdateMenuIcon(const AMenuItem: TMenuItem; const HasIcon: Boolean; const AIcon: TBitmap); override;
end;
{ TFpGuiWSMenu }
TFpGuiWSMenu = class(TWSMenu)
private
protected
published
class function CreateHandle(const AMenu: TMenu): HMENU; override;
// class procedure SetBiDiMode(const AMenu: TMenu; UseRightToLeftAlign, UseRightToLeftReading : Boolean); override;
end;
{ TFpGuiWSMainMenu }
TFpGuiWSMainMenu = class(TWSMainMenu)
private
protected
public
end;
{ TFpGuiWSPopupMenu }
TFpGuiWSPopupMenu = class(TWSPopupMenu)
private
protected
published
class procedure Popup(const APopupMenu: TPopupMenu; const X, Y: integer); override;
end;
implementation
uses
LCLMessageGlue;
{ TFpGuiWSMenuItem }
class procedure TFpGuiWSMenuItem.AttachMenu(const AMenuItem: TMenuItem);
begin
end;
{------------------------------------------------------------------------------
Function: TFpGuiWSMenuItem.CreateHandle
Params: None
Returns: Nothing
Creates a Menu Item
------------------------------------------------------------------------------}
class function TFpGuiWSMenuItem.CreateHandle(const AMenuItem: TMenuItem): HMENU;
var
Menu: TFPGUIPrivateMenuItem;
AMenuName: string;
// hotkeydef: string;
{ Possible parents }
ParentPrivateItem: TFPGUIPrivateMenuItem;
ParentMenuBar: TfpgMenuBar;
ParentPrivatePopUp: TFPGUIPrivatePopUpMenu;
begin
{$ifdef VerboseFPGUIIntf}
WriteLn('trace:> [TFPGuiWSMenuItem.CreateHandle] Caption: ', AMenuItem.Caption,
' Subitems: ' + IntToStr(AMenuItem.Count));
Write('trace:< [TFPGuiWSMenuItem.CreateHandle]');
{$endif}
{------------------------------------------------------------------------------
Set's default values for variables used at several places bellow
------------------------------------------------------------------------------}
AMenuName := AMenuItem.Caption;
Menu := nil;
{------------------------------------------------------------------------------
This case should not happen. A menu item must have a parent, but it seams LCL
will sometimes create a menu item prior to creating it's parent.
So, if we arrive here, we must create this item as if it was a TMenu
------------------------------------------------------------------------------}
if (not AMenuItem.HasParent) then
begin
{$ifdef VerboseFPGUIIntf}
Write(' Parent: Menu without parent');
{$endif}
// Result := TQtWSMenu.CreateHandle(AMenuItem.GetParentMenu);
end
{------------------------------------------------------------------------------
If the parent has no parent, then this item is directly owned by a TMenu
In this case we have to detect if the parent is a TMainMenu or a TPopUpMenu
because TMainMenu uses the special Handle TfpgMenuBar
------------------------------------------------------------------------------}
else
if AMenuItem.Parent.HasParent then begin
{------------------------------------------------------------------------------
If the parent has a parent, then that item's Handle is necessarely a TFPGUIPrivateMenuItem
------------------------------------------------------------------------------}
Menu := TFPGUIPrivateMenuItem.Create;
Menu.LCLMenuItem := AMenuItem;
ParentPrivateItem := TFPGUIPrivateMenuItem(AMenuItem.Parent.Handle);
Menu.MenuItem := ParentPrivateItem.MenuItem.SubMenu.AddMenuItem(AMenuName, '', Menu.HandleOnClick);
Result := HMENU(Menu);
end else if (AMenuItem.GetParentMenu is TMainMenu) then begin
Menu := TFPGUIPrivateMenuItem.Create;
Menu.LCLMenuItem := AMenuItem;
ParentMenuBar := TfpgMenuBar(AMenuItem.GetParentMenu.Handle);
Menu.MenuItem := ParentMenuBar.AddMenuItem(AMenuName, Menu.HandleOnClick);
Result := HMENU(Menu);
end else begin
Menu := TFPGUIPrivateMenuItem.Create;
Menu.LCLMenuItem := AMenuItem;
ParentPrivatePopUp := TFPGUIPrivatePopUpMenu(AMenuItem.GetParentMenu.Handle);
Menu.MenuItem := ParentPrivatePopUp.PopUpMenu.AddMenuItem(AMenuName,'',Menu.HandleOnClick);
Result := HMENU(Menu);
end;
{------------------------------------------------------------------------------
If the menuitem has submenus, create a popupmenu for the submenu
------------------------------------------------------------------------------}
if AMenuItem.Count > 0 then
begin
Menu.MenuItem.SubMenu := TfpgPopupMenu.Create(Menu.MenuItem);
end;
Menu.MenuItem.Checked:=AMenuItem.Checked;
{$ifdef VerboseFPGUIIntf}
WriteLn(' Result: ', IntToStr(Result));
{$endif}
end;
class procedure TFpGuiWSMenuItem.DestroyHandle(const AMenuItem: TMenuItem);
begin
TFPGUIPrivateMenuItem(AMenuItem.Handle).Free;
AMenuItem.Handle:=0;
end;
class procedure TFpGuiWSMenuItem.SetCaption(const AMenuItem: TMenuItem;
const ACaption: string);
var
lPrivateMenuItem: TFPGUIPrivateMenuItem;
begin
lPrivateMenuItem:=TFPGUIPrivateMenuItem(AMenuItem.Handle);
lPrivateMenuItem.MenuItem.Text:=ACaption;
end;
class procedure TFpGuiWSMenuItem.SetVisible(const AMenuItem: TMenuItem;
const Visible: boolean);
var
lPrivateMenuItem: TFPGUIPrivateMenuItem;
lMenuBar: TfpgMenuBar;
lMainMenu: TMainMenu;
lTestMenuItem: TMenuItem;
lOneVisible: Boolean;
j: Integer;
procedure InvalidateCache(const aHeightVariance: integer);
var
LCLForm: TCustomForm;
j: integer;
c: TControl;
pW: TFPGUIPrivateWindow;
w: TFPGUIPrivateWidget;
begin
if Assigned(lMainMenu.Parent) then begin
if lMainMenu.Parent is TCustomForm then begin
LCLForm:=TCustomForm(TFPGUIPrivateWindow(TCustomForm(lMainMenu.Parent).Handle).LCLObject);
LCLForm.InvalidateClientRectCache(false);
(*
LCLForm.DoAdjustClientRectChange(true);
pw:=TFPGUIPrivateWindow(LCLForm.Handle);
for j := 0 to Pred(LCLForm.ControlCount) do
begin
c:=LCLForm.Controls[j];
if c is TWinControl then begin
w:=TFPGUIPrivateWidget(TWinControl(c).Handle);
pw.SetWidgetPosition(w.Widget,c.Left,c.Top);
end;
end;
*)
end;
end;
end;
begin
lPrivateMenuItem:=TFPGUIPrivateMenuItem(AMenuItem.Handle);
lPrivateMenuItem.MenuItem.Visible:=Visible;
if AMenuItem.GetParentMenu is TMainMenu then begin
lMenuBar:=TfpgMenuBar(AMenuItem.GetParentMenu.Handle);
lMainMenu:=TMainMenu(AMenuItem.GetParentMenu);
lOneVisible:=false;
for j := 0 to Pred(lMainMenu.Items.Count) do begin
lTestMenuItem:=lMainMenu.Items[j];
if TFPGUIPrivateMenuItem(lTestMenuItem.Handle).MenuItem.Visible then begin
lOneVisible:=true;
break;
end;
end;
if lOneVisible and not(lMenuBar.Visible) then begin
lMenuBar.Visible:=true;
InvalidateCache(lMenuBar.Height);
end else if not lOneVisible and lMenuBar.Visible then begin
lMenuBar.Visible:=false;
InvalidateCache(lMenuBar.Height*-1);
end;
end;
end;
class function TFpGuiWSMenuItem.SetCheck(const AMenuItem: TMenuItem;
const Checked: boolean): boolean;
var
lPrivateMenuItem: TFPGUIPrivateMenuItem;
begin
lPrivateMenuItem:=TFPGUIPrivateMenuItem(AMenuItem.Handle);
lPrivateMenuItem.MenuItem.Checked:=Checked;
Result:=true;
end;
class function TFpGuiWSMenuItem.SetEnable(const AMenuItem: TMenuItem;
const Enabled: boolean): boolean;
begin
Result:=false; //Default by now
end;
{ TFpGuiWSMenu }
class function TFpGuiWSMenu.CreateHandle(const AMenu: TMenu): HMENU;
var
MenuBar: TfpgMenuBar;
Menu: TFPGUIPrivatePopUpMenu;
begin
{------------------------------------------------------------------------------
If the menu is a main menu, there is no need to create a handle for it.
It's already created on the window
------------------------------------------------------------------------------}
if (AMenu is TMainMenu) and (AMenu.Parent is TCustomForm) then
begin
MenuBar := TFPGUIPrivateWindow(TCustomForm(AMenu.Parent).Handle).MenuBar;
MenuBar.Visible := true;
MenuBar.Align := alTop;
Result := HMENU(MenuBar);
// Invalidate the ClientRectCache in the LCL side.
TCustomForm(AMenu.Parent).InvalidateClientRectCache(true);
end
{------------------------------------------------------------------------------
The menu is a popup menu
------------------------------------------------------------------------------}
else if (AMenu is TPopUpMenu) then
begin
Menu := TFPGUIPrivatePopUpMenu.Create(TPopUpMenu(AMenu), AMenu.Items);
Result := HMENU(Menu);
end
else
Result := HMENU(0);
{$ifdef VerboseFPGUIIntf}
Write('[TFpGuiWSMenu.CreateHandle] ');
if (AMenu is TMainMenu) then Write('IsMainMenu ');
WriteLn(' Handle: ', IntToStr(Result), ' Name: ', AMenu.Name);
{$endif}
end;
{ TFpGuiWSPopupMenu }
class procedure TFpGuiWSPopupMenu.Popup(const APopupMenu: TPopupMenu; const X, Y: integer);
begin
TFPGUIPrivatePopUpMenu(APopUpMenu.Handle).PopUp(X, Y);
end;
end.
|