(* GTK-Kylix Library: GTKDialogs - Special purpose dialogs Copyright (C) 2006 Tomas Bzatek 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.