1
{ Copyright (C) 2008-2009 Matthias Klumpp
6
This program is free software: you can redistribute it and/or modify it under
7
the terms of the GNU General Public License as published by the Free Software
10
This program is distributed in the hope that it will be useful, but WITHOUT
11
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License v3
15
along with this program. If not, see <http://www.gnu.org/licenses/>.}
16
//** This unit contains an icon-load procedure to find the right icons for Qt4 and GTK2 GUI
24
Classes, SysUtils, Graphics, LCLType
26
,gtkdef, gtk2, gdk2pixbuf, gtk2int, gdk2
29
//** Loads a stock icon (native on GTK2, if Qt4 is used aditional images are needed) @returns Handle to th bitmap
30
procedure LoadStockPixmap(StockId: PChar; IconSize: integer;bmp: TBitmap);
34
STOCK_QUIT='stock-quit';
35
STOCK_GO_FORWARD='stock-go-forward';
36
STOCK_GO_BACK='stock-go-back';
37
STOCK_DIALOG_WARNING='stock-dialog-warning';
38
STOCK_CLOSE='stock-close';
39
STOCK_DELETE='stock-delete';
40
STOCK_EXECUTE='stock-execute';
41
STOCK_APPLY='stock-apply';
42
STOCK_DIALOG_INFO='stock-dialog-info';
43
STOCK_REFRESH='stock-refresh';
44
STOCK_OPEN='stock-open';
45
STOCK_PROJECT_OPEN='stock-project-open';
47
ICON_SIZE_SMALL_TOOLBAR=2;
48
ICON_SIZE_LARGE_TOOLBAR=3;
51
//** Directory with KDE4 icons
52
KDE_ICON_DIR='/usr/share/icons/default.kde4/';
56
procedure LoadStockPixmap(StockId: PChar; IconSize: integer; bmp: TBitmap);
58
function Gtk2LoadStockPixmap(StockId: PChar; IconSize: integer): HBitmap;
60
StockWindow: PGtkWidget;
65
// If not a default icon then stop
66
if gtk_icon_factory_lookup_default(StockId) = nil then Exit;
67
StockWindow := gtk_window_new(GTK_WINDOW_TOPLEVEL);
68
Pixbuf := gtk_widget_render_icon(StockWindow, StockId, IconSize, nil);
69
gtk_widget_destroy(StockWindow);
70
// Check if icon was assigned
71
if PtrUInt(Pixbuf) = 0 then Exit;
72
Pixmap := Gtk2WidgetSet.NewGDIObject(gdiBitmap);
75
GDIBitmapType := gbPixmap;
76
visual := gdk_visual_get_system();
77
gdk_visual_ref(visual);
78
colormap := gdk_colormap_get_system();
79
gdk_colormap_ref(colormap);
80
gdk_pixbuf_render_pixmap_and_mask(Pixbuf, GDIPixmapObject.Image,
81
GDIPixmapObject.Mask, 192);
83
gdk_pixbuf_unref(Pixbuf);
84
Result := HBitmap(PtrUInt(Pixmap));
86
var cicon: String;BH: HBitmap;
90
if StockId = STOCK_PROJECT_OPEN then StockId:=STOCK_OPEN;
91
cicon:=StringReplace(StockId,'stock','gtk',[rfReplaceAll]);
92
BH:=Gtk2LoadStockPixmap(PChar(cicon),IconSize);
96
var cicon: String;pic: TPicture;s: String;
98
if not DirectoryExists(KDE_ICON_DIR+'22x22/') then
99
if not DirectoryExists('/usr/share/icons/default.kde/22x22') then
100
if not DirectoryExists('/usr/share/icons/oxygen/22x22') then
101
if not DirectoryExists('/usr/share/icons/hicolor/22x22') then exit;
102
if StockId = STOCK_QUIT then cicon:='process-stop.png';
103
if StockId = STOCK_GO_FORWARD then cicon:='arrow-right.png';
104
if StockId = STOCK_GO_BACK then cicon:='arrow-left.png';
105
if StockId = STOCK_DIALOG_WARNING then cicon:='../status/dialog-warning.png';
106
if StockId = STOCK_CLOSE then cicon:='window-close.png';
107
if StockId = STOCK_DELETE then cicon:='edit-delete.png';
108
if StockId = STOCK_EXECUTE then cicon:='fork.png';
109
if StockId = STOCK_APPLY then cicon:='dialog-ok-apply.png';
110
if StockId = STOCK_DIALOG_INFO then cicon:='help-hint.png';
111
if StockId = STOCK_REFRESH then cicon:='view-refresh.png';
112
if StockId = STOCK_PROJECT_OPEN then cicon:='project-open.png';
113
if StockId = STOCK_OPEN then cicon:='../places/folder.png';
116
s:=KDE_ICON_DIR+'16x16/actions/';
118
s:=KDE_ICON_DIR+'32x32/actions/';
120
s:=KDE_ICON_DIR+'22x22/actions/';
122
s:=KDE_ICON_DIR+'16x16/actions/';
123
if not FileExists(s) then exit;
124
pic:=TPicture.Create;
125
pic.LoadFromFile(s+cicon);
127
bmp.LoadFromBitmapHandles(pic.Bitmap.Handle,pic.Bitmap.MaskHandle);