summaryrefslogtreecommitdiff
path: root/libgtk_kylix/GTKMenus.pas
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@redhat.com>2024-12-24 12:41:48 +0100
committerTomas Bzatek <tbzatek@redhat.com>2025-11-27 19:39:51 +0100
commit1b2b4bb4f3ecc034a6e9364d8768e50b167a9680 (patch)
tree065ddde53b64f7957a30b7dc9d83a748f309868c /libgtk_kylix/GTKMenus.pas
parentb9703b29819b619037cc282d719c187e51bacd30 (diff)
downloadtuxcmd-1b2b4bb4f3ecc034a6e9364d8768e50b167a9680.tar.xz
Rough GTK3 port
Diffstat (limited to 'libgtk_kylix/GTKMenus.pas')
-rw-r--r--libgtk_kylix/GTKMenus.pas127
1 files changed, 33 insertions, 94 deletions
diff --git a/libgtk_kylix/GTKMenus.pas b/libgtk_kylix/GTKMenus.pas
index ed2bfba..5819d5c 100644
--- a/libgtk_kylix/GTKMenus.pas
+++ b/libgtk_kylix/GTKMenus.pas
@@ -1,6 +1,5 @@
(*
GTK-Kylix Library: GTKMenus - Menu handling and related routines
- Version 0.6.13 (last updated 2003-07-10)
Copyright (C) 2003 Tomas Bzatek <tbzatek@users.sourceforge.net>
This library is free software; you can redistribute it and/or
@@ -24,7 +23,7 @@ unit GTKMenus;
interface
-uses gtk2, gdk2, glib2, lazglib2, lazgobject2, Classes, GTKControls, GTKConsts, GTKPixbuf;
+uses lazglib2, lazgobject2, lazgdk3, lazgtk3, Classes, GTKControls, GTKConsts, GTKPixbuf;
type
(****************************************** TGDKSHORTCUTS ***********************************************************************)
@@ -55,12 +54,11 @@ type
end;
(****************************************** TGTKMENUITEM ************************************************************************)
- TGTKMenuItemType = (itLabel, itSeparator, itTearOff, itCheck, itImageText, itRadio);
+ TGTKMenuItemType = (itLabel, itSeparator, itCheck, itImageText, itRadio);
TGTKMenuItemGroup = PGSList;
TGTKMenuItem = class(TGTKBin)
private
FItems: TList;
- FTearOffTitle: string;
FOnClick: TNotifyEvent;
FUKey: guint;
FItemType: TGTKMenuItemType;
@@ -71,17 +69,12 @@ type
function GetCount: Integer;
function GetItem(Index: Integer): TGTKMenuItem;
function GetCaption: string;
- function GetRightJustified: boolean;
- function GetTornOff: boolean;
function GetChecked: boolean;
function GetGroup: TGTKMenuItemGroup;
procedure SetCaption(Value: string);
- procedure SetTearOffTitle(Value: string);
- procedure SetRightJustified(Value: boolean);
procedure SetItemType(Value: TGTKMenuItemType);
- procedure SetTornOff(Value: boolean);
procedure SetChecked(Value: boolean);
- procedure SetStockIcon(Value: string);
+ procedure SetIconName(Value: string);
procedure SetIcon(Value: TGDKPixbuf);
procedure SetGroup(Value: TGTKMenuItemGroup);
protected
@@ -97,22 +90,17 @@ type
procedure Clear;
procedure Delete(Index: Integer);
procedure Insert(Index: Integer; Item: TGTKMenuItem);
- procedure TearOff;
- procedure UnTearOff;
procedure PopUp;
procedure PopDown;
procedure SetCaptionPlain(Value: string);
property Count: Integer read GetCount;
property Items[Index: Integer]: TGTKMenuItem read GetItem; default;
property Caption: string read GetCaption write SetCaption;
- property TearOffTitle: string read FTearOffTitle write SetTearOffTitle;
- property RightJustified: boolean read GetRightJustified write SetRightJustified default False;
property OnClick: TNotifyEvent read FOnClick write FOnClick;
property ItemType: TGTKMenuItemType read FItemType write SetItemType default itLabel;
- property TornOff: boolean read GetTornOff write SetTornOff;
property Checked: boolean read GetChecked write SetChecked;
property Notify: TNotifyEvent read FNotify write FNotify;
- property StockIcon: string write SetStockIcon;
+ property IconName: string write SetIconName;
property Icon: TGDKPixbuf write SetIcon;
property Data: Pointer read FData write FData;
property OnPopup: TNotifyEvent read FOnPopup write FOnPopup;
@@ -131,7 +119,7 @@ type
property Items: TGTKMenuItem read FItems;
end;
-
+
function MakeGDKShortCut(Key: word; Locked, ModAlt, ModShift, ModCtrl : boolean): TGDKShortCut;
(********************************************************************************************************************************)
@@ -142,6 +130,9 @@ implementation
uses GTKForms;
+function gtk_image_menu_item_new_with_mnemonic(const L: Pgchar): PGtkImageMenuItem; cdecl; external LazGtk3_library;
+
+
(********************************************************************************************************************************)
(********************************************************************************************************************************)
constructor TGTKMenuBar.Create(AOwner: TComponent);
@@ -180,7 +171,6 @@ begin
FData := nil;
FOnPopup := nil;
ShortCuts := TGDKShortCuts.Create(Self);
- FTearOffTitle := '';
FUKey := 0;
Recreate;
end;
@@ -198,7 +188,6 @@ begin
FNotify := nil;
FData := nil;
ShortCuts := TGDKShortCuts.Create(Self);
- FTearOffTitle := '';
FUKey := 0;
Recreate(AGroup);
end;
@@ -225,8 +214,7 @@ begin
end;
case FItemType of
itLabel: FWidget := gtk_menu_item_new_with_mnemonic(Pgchar(SCDefaultMenuItemCaption));
- itSeparator: FWidget := gtk_menu_item_new;
- itTearOff: FWidget := gtk_tearoff_menu_item_new;
+ itSeparator: FWidget := gtk_separator_menu_item_new();
itCheck: FWidget := gtk_check_menu_item_new_with_mnemonic(Pgchar(SCDefaultMenuItemCaption));
itImageText: begin
FWidget := gtk_image_menu_item_new_with_mnemonic(Pgchar(SCDefaultMenuItemCaption));
@@ -234,7 +222,7 @@ begin
gtk_widget_show(FImageWidget);
gtk_image_menu_item_set_image(PGtkImageMenuItem(FWidget), FImageWidget);
end;
- itRadio: FWidget := gtk_radio_menu_item_new_with_mnemonic(GLIB2.PGSList(AGroup), Pgchar(SCDefaultMenuItemCaption));
+ itRadio: FWidget := gtk_radio_menu_item_new_with_mnemonic(PGSList(AGroup), Pgchar(SCDefaultMenuItemCaption));
end;
g_signal_connect_data(PGObject(FWidget), 'activate', TGCallback(@TGTKMenuItem_activate), Self, nil, G_CONNECT_DEFAULT);
Show;
@@ -277,7 +265,7 @@ begin
if (FParentMenu is TGTKMenuItem) or (FParentMenu is TGTKMenuBar)
then begin
if (FParentMenu is TGTKMenuItem) or (FParentMenu is TGTKMenuBar)
- then gtk_menu_item_remove_submenu(PGtkMenuItem(FWidget));
+ then gtk_menu_item_set_submenu(PGtkMenuItem(FWidget), nil);
gtk_widget_destroy(FMenu);
FMenu := nil;
end;
@@ -289,13 +277,12 @@ end;
procedure TGTKMenuItem.Insert(Index: Integer; Item: TGTKMenuItem);
begin
- if (Item = Self) or (FItemType in [itSeparator, itTearOff]) then Exit;
+ if (Item = Self) or (FItemType in [itSeparator]) then Exit;
if FItems = nil then begin
FItems := TList.Create;
if FMenu = nil then FMenu := gtk_menu_new;
if (FParentMenu is TGTKMenuItem) or (FParentMenu is TGTKMenuBar)
- then gtk_menu_item_set_submenu(PGtkMenuItem(FWidget), FMenu);
- SetTearOffTitle(FTearOffTitle);
+ then gtk_menu_item_set_submenu(PGtkMenuItem(FWidget), PGtkMenu(FMenu));
end;
Item.FParentMenu := Self;
FItems.Insert(Index, Item);
@@ -308,44 +295,20 @@ end;
function TGTKMenuItem.GetCaption: string;
begin
Result := '';
- if FItemType in [itSeparator, itTearOff] then Exit;
+ if FItemType in [itSeparator] then Exit;
if Assigned(ChildControl) then Result := String(gtk_label_get_text(PGtkLabel(ChildControl)));
end;
procedure TGTKMenuItem.SetCaption(Value: string);
begin
- if FItemType in [itSeparator, itTearOff] then Exit;
+ if FItemType in [itSeparator] then Exit;
gtk_label_set_markup_with_mnemonic(PGtkLabel(ChildControl), PChar(Value));
- if FTearOffTitle = '' then SetTearOffTitle(Value);
end;
procedure TGTKMenuItem.SetCaptionPlain(Value: string);
begin
- if FItemType in [itSeparator, itTearOff] then Exit;
+ if FItemType in [itSeparator] then Exit;
gtk_label_set_markup(PGtkLabel(ChildControl), PChar(Value));
- if FTearOffTitle = '' then SetTearOffTitle(Value);
-end;
-
-procedure TGTKMenuItem.SetTearOffTitle(Value: string);
-begin
- FTearOffTitle := Value;
- if FItemType = itTearOff then begin
- if Assigned(FParentMenu) and (FParentMenu is TGTKMenuItem) and Assigned((FParentMenu as TGTKMenuItem).FMenu)
- then gtk_menu_set_title(PGtkMenu((FParentMenu as TGTKMenuItem).FMenu), PChar(FTearOffTitle))
- end else if Assigned(FMenu) then gtk_menu_set_title(PGtkMenu(FMenu), PChar(FTearOffTitle));
-end;
-
-function TGTKMenuItem.GetRightJustified: boolean;
-begin
- Result := False;
- if FItemType in [itSeparator, itTearOff] then Exit;
- Result := gtk_menu_item_get_right_justified(PGtkMenuItem(FWidget));
-end;
-
-procedure TGTKMenuItem.SetRightJustified(Value: boolean);
-begin
- if FItemType in [itSeparator, itTearOff] then Exit;
- gtk_menu_item_set_right_justified(PGtkMenuItem(FWidget), Value);
end;
procedure TGTKMenuItem.SetItemType(Value: TGTKMenuItemType);
@@ -356,33 +319,6 @@ begin
end;
end;
-function TGTKMenuItem.GetTornOff: boolean;
-var b: gboolean;
-begin
- b := False;
- if FItemType = itTearOff then g_object_get(PGObject(FWidget), 'tearoff-state', [@b, nil]) else
- if Assigned(FMenu) and (Count > 0) then g_object_get(PGObject(FMenu), 'tearoff-state', [@b, nil]);
- Result := b;
-end;
-
-procedure TGTKMenuItem.SetTornOff(Value: boolean);
-begin
- if FItemType = itTearOff then begin
- if Assigned(FParentMenu) and (FParentMenu is TGTKMenuItem) and Assigned((FParentMenu as TGTKMenuItem).FMenu)
- then gtk_menu_set_tearoff_state(PGtkMenu((FParentMenu as TGTKMenuItem).FMenu), Value);
- end else if Assigned(FMenu) then gtk_menu_set_tearoff_state(PGtkMenu(FMenu), Value);
-end;
-
-procedure TGTKMenuItem.TearOff;
-begin
- SetTornOff(True);
-end;
-
-procedure TGTKMenuItem.UnTearOff;
-begin
- SetTornOff(False);
-end;
-
function TGTKMenuItem.GetChecked: boolean;
begin
Result := False;
@@ -407,9 +343,9 @@ begin
if (FItems <> nil) and (FItems.Count > 0) then gtk_menu_popdown(PGtkMenu(FMenu));
end;
-procedure TGTKMenuItem.SetStockIcon(Value: string);
+procedure TGTKMenuItem.SetIconName(Value: string);
begin
- gtk_image_set_from_stock(PGtkImage(FImageWidget), PChar(Value), GTK_ICON_SIZE_MENU);
+ gtk_image_set_from_icon_name(PGtkImage(FImageWidget), PChar(Value), GTK_ICON_SIZE_MENU);
end;
procedure TGTKMenuItem.SetIcon(Value: TGDKPixbuf);
@@ -419,12 +355,12 @@ end;
function TGTKMenuItem.GetGroup: TGTKMenuItemGroup;
begin
- Result := LAZGLIB2.PGSList(gtk_radio_menu_item_get_group(PGtkRadioMenuItem(FWidget)));
+ Result := PGSList(gtk_radio_menu_item_get_group(PGtkRadioMenuItem(FWidget)));
end;
procedure TGTKMenuItem.SetGroup(Value: TGTKMenuItemGroup);
begin
- gtk_radio_menu_item_set_group(PGtkRadioMenuItem(FWidget), GLIB2.PGSList(Value) );
+ gtk_radio_menu_item_set_group(PGtkRadioMenuItem(FWidget), PGSList(Value));
end;
(********************************************************************************************************************************)
@@ -453,10 +389,13 @@ begin
end;
procedure TGDKShortCuts.AddName(Item: string);
-var Key, Modifiers: guint;
+var accelerator_key: guint;
+ accelerator_mods: TGdkModifierType;
begin
- gtk_accelerator_parse(PChar(Item), @Key, @Modifiers);
- if Key <> 0 then Add(MakeGDKShortCut(Key, False, Modifiers and GDK_MOD1_MASK = GDK_MOD1_MASK, Modifiers and GDK_SHIFT_MASK = GDK_SHIFT_MASK, Modifiers and GDK_CONTROL_MASK = GDK_CONTROL_MASK));
+ accelerator_key := 0;
+ accelerator_mods := [];
+ gtk_accelerator_parse(PChar(Item), @accelerator_key, @accelerator_mods);
+ if accelerator_key <> 0 then Add(MakeGDKShortCut(accelerator_key, False, GDK_MOD1_MASK in accelerator_mods, GDK_SHIFT_MASK in accelerator_mods, GDK_CONTROL_MASK in accelerator_mods));
end;
procedure TGDKShortCuts.Clear;
@@ -465,18 +404,18 @@ begin
for i := Count - 1 downto 0 do Delete(i);
end;
-function GetAccelMods(SC: TGDKShortCut): guint;
+function GetAccelMods(SC: TGDKShortCut): TGdkModifierType;
begin
- Result := 0;
- if SC.ModShift then Inc(Result, GDK_SHIFT_MASK);
- if SC.ModCtrl then Inc(Result, GDK_CONTROL_MASK);
- if SC.ModAlt then Inc(Result, GDK_MOD1_MASK);
+ Result := [];
+ if SC.ModShift then Result += [GDK_SHIFT_MASK];
+ if SC.ModCtrl then Result += [GDK_CONTROL_MASK];
+ if SC.ModAlt then Result += [GDK_MOD1_MASK];
end;
function GetAccelFlags(SC: TGDKShortCut): TGtkAccelFlags;
begin
- Result := GTK_ACCEL_VISIBLE;
- if SC.Locked then Result := GTK_ACCEL_LOCKED;
+ Result := [GTK_ACCEL_VISIBLE];
+ if SC.Locked then Result := [GTK_ACCEL_LOCKED];
end;
procedure TGDKShortCuts.Delete(Index: Integer);