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
|
(*
GTK-Kylix Library: GTKDialogs - Special purpose dialogs
Copyright (C) 2006 Tomas Bzatek <tbzatek@users.sourceforge.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307 USA.
*)
unit GTKDialogs;
interface
uses lazglib2, lazgobject2, lazgdk3, lazgtk3, Classes, GTKControls, GTKStdCtrls, GTKForms;
type
(****************************************** TGTKFILECHOOSERDIALOG *************************************************************)
TGTKFileChooserDialog = class(TGTKDialog)
private
function GetFileName: string;
procedure SetFileName(Value: string);
protected
public
constructor Create(AOwner: TComponent); override;
constructor CreateWithTitle(AOwner: TComponent; const Title: string);
destructor Destroy; override;
published
property FileName: string read GetFileName write SetFileName;
end;
(****************************************** TGTKCOLORBUTTON *******************************************************************)
TGTKColorButton = class(TGTKButton)
private
FColorChanged: TNotifyEvent;
function GetColor: string;
procedure SetColor(Value: string);
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure SetDefaultColor;
published
property Color: string read GetColor write SetColor;
property OnColorChanged: TNotifyEvent read FColorChanged write FColorChanged;
end;
(****************************************** TGTKFontButton *************************************************************)
TGTKFontButton = class(TGTKButton)
private
FFontNameChanged: TNotifyEvent;
function GetFontName: string;
procedure SetFontName(Value: string);
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property FontName: string read GetFontName write SetFontName;
property OnFontNameChanged: TNotifyEvent read FFontNameChanged write FFontNameChanged;
end;
(********************************************************************************************************************************)
(********************************************************************************************************************************)
implementation
uses SysUtils, DateUtils;
(********************************************************************************************************************************)
(********************************************************************************************************************************)
constructor TGTKFileChooserDialog.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FWidget := gtk_file_chooser_dialog_new(nil, PGtkWindow((AOwner as TCustomGTKForm).FWidget), GTK_FILE_CHOOSER_ACTION_OPEN, nil, [nil]);
Show;
end;
constructor TGTKFileChooserDialog.CreateWithTitle(AOwner: TComponent; const Title: string);
begin
inherited Create(AOwner);
FWidget := gtk_file_chooser_dialog_new(PChar(Title), PGtkWindow((AOwner as TCustomGTKForm).FWidget), GTK_FILE_CHOOSER_ACTION_OPEN, nil, [nil]);
Show;
end;
destructor TGTKFileChooserDialog.Destroy;
begin
inherited Destroy;
end;
function TGTKFileChooserDialog.GetFileName: string;
begin
Result := String(gtk_file_chooser_get_filename(PGtkFileChooser(FWidget)));
end;
procedure TGTKFileChooserDialog.SetFileName(Value: string);
begin
gtk_file_chooser_set_filename(PGtkFileChooser(FWidget), PChar(Value));
end;
(********************************************************************************************************************************)
(********************************************************************************************************************************)
procedure GtkColorButton_color_set(widget: PGtkColorButton; user_data: gpointer); cdecl;
begin
if Assigned(user_data) and Assigned(TGTKColorButton(user_data).FColorChanged) then
TGTKColorButton(user_data).FColorChanged(TGTKColorButton(user_data));
end;
constructor TGTKColorButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FWidget := gtk_color_button_new();
g_signal_connect_data(PGObject(FWidget), 'color-set', TGCallback(@GtkColorButton_color_set), Self, nil, G_CONNECT_DEFAULT);
Show;
FColorChanged := nil;
end;
destructor TGTKColorButton.Destroy;
begin
inherited Destroy;
end;
function TGTKColorButton.GetColor: string;
var c: TGdkRGBA;
begin
FillChar(c, sizeof(TGdkRGBA), 0);
gtk_color_chooser_get_rgba(PGtkColorChooser(FWidget), @c);
Result := string(gdk_rgba_to_string(@c));
end;
procedure TGTKColorButton.SetColor(Value: string);
var c: TGdkRGBA;
begin
if gdk_rgba_parse(@c, PChar(Value)) then
gtk_color_chooser_set_rgba(PGtkColorChooser(FWidget), @c);
end;
procedure TGTKColorButton.SetDefaultColor;
begin
gtk_color_chooser_set_rgba(PGtkColorChooser(FWidget), nil);
end;
(********************************************************************************************************************************)
(********************************************************************************************************************************)
procedure GtkFontButton_font_set(widget: PGtkFontButton; user_data: gpointer); cdecl;
begin
if Assigned(user_data) and Assigned(TGTKFontButton(user_data).FFontNameChanged) then
TGTKFontButton(user_data).FFontNameChanged(TGTKFontButton(user_data));
end;
constructor TGTKFontButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FWidget := gtk_font_button_new();
g_signal_connect_data(PGObject(FWidget), 'font-set', TGCallback(@GtkFontButton_font_set), Self, nil, G_CONNECT_DEFAULT);
Show;
FFontNameChanged := nil;
end;
destructor TGTKFontButton.Destroy;
begin
inherited Destroy;
end;
function TGTKFontButton.GetFontName: string;
begin
Result := String(gtk_font_chooser_get_font(PGtkFontChooser(FWidget)));
end;
procedure TGTKFontButton.SetFontName(Value: string);
begin
gtk_font_chooser_set_font(PGtkFontChooser(FWidget), PChar(Value));
end;
(********************************************************************************************************************************)
end.
|