[lazarus] new dialogs.pp
Sergio Kessler
sak at perio.unlp.edu.ar
Wed May 19 01:01:59 EDT 1999
Hi all,
I've done a OpenDialog that behave like a normal Borland dialog,
i.e. it should be used like
OpenDialog1 := TOpenDialog.Create( self);
if OpenDialog1.Execute then
begin
<do whatever with OpenDialog1.FileName>
end;
OpenDialog1.Destroy // should be Free
and yes, it _is_ modal (and a _lot_ cleaner).
I tested it and is working nicely.
Tomorow I will make some enhancements to this.
Of course, TEditor need some modifications, but I'm not going
to deal with that mess :)
Oh, I've commented controls.pp in the part where it create
this object.
attached and pasted here (for those lazy :)
{
Dialogs Unit
Contains :
TOpenFileDialog
}
unit dialogs;
{$mode objfpc}
interface
uses
glib,gdk,gtk,classes,Controls,vclGlobals;
type
TCustomDialog = class(TWinControl)
private
FUserChoose: integer;
FFileName : PChar;
Procedure SetFileName(Value : PChar);
Function GetFileName : PChar;
function gtk_Ok( widget: PGtkWidget) : Boolean; cdecl;
function gtk_Cancel( widget: PGtkWidget) : Boolean; cdecl;
function gtk_Close( widget: PGtkWidget) : Boolean; cdecl;
protected
public
property FileName : PChar read GetFileName write SetFileName;
constructor Create(AOwner : TComponent); override;
destructor destroy; override;
// procedure Free; override;
Function Execute : boolean;
end;
TOpenFileDialog = class(TCustomDialog)
private
public
constructor Create (AOwner : TComponent); override;
destructor destroy; override;
// procedure Free; override;
end;
Implementation
//----------------------------------------------------------------------------
function TCustomDialog.gtk_Ok( widget: PGtkWidget) : Boolean; cdecl;
begin
writeln('--> in gtk_ok');
FUserChoose := 1;
end;
//----------------------------------------------------------------------------
function TCustomDialog.gtk_Cancel( widget: PGtkWidget) : Boolean; cdecl;
begin
writeln('--> in gtk_cancel');
FUserChoose := 2;
end;
//----------------------------------------------------------------------------
function TCustomDialog.gtk_Close( widget: PGtkWidget) : Boolean; cdecl;
begin
writeln('--> in gtk_close');
FUserChoose := 3;
end;
//----------------------------------------------------------------------------
Procedure TCustomDialog.SetFileName( Value : PChar);
begin
FFileName := Value;
gtk_file_selection_set_filename( PGtkFileSelection( FComponent),
Value);
end;
//----------------------------------------------------------------------------
Function TCustomDialog.GetFileName : PChar;
Begin
GetFileName := FFileName;
End;
//----------------------------------------------------------------------------
constructor TCustomDialog.Create (AOwner : TComponent);
begin
// the TCustomDialog should not create the file_selection
inherited Create(AOwner);
End;
//----------------------------------------------------------------------------
destructor TCustomDialog.destroy;
begin
inherited Destroy;
End;
//----------------------------------------------------------------------------
Function TCustomDialog.Execute : boolean;
begin
FUserChoose := 0;
writeln('--> about to file_sel_show');
gtk_widget_show( FComponent);
repeat
gtk_main_iteration;
until FUserChoose <> 0;
writeln('--> about to file_sel_hide');
gtk_widget_hide( FComponent);
Execute := (FUserChoose = 1);
if Execute then
begin
FFileName := gtk_file_selection_get_filename( PGtkFileSelection(
FComponent));
end;
end;
//----------------------------------------------------------------------------
constructor TOpenFileDialog.Create (AOwner : TComponent);
begin
inherited Create(AOwner);
FComponent := gtk_file_selection_new('Select a file');
gtk_signal_connect_object( gtk_object(
(PGtkFileSelection(FComponent))^.ok_button),
'clicked',
gtk_signal_func( @gtk_ok),
gtk_object( self));
gtk_signal_connect_object( gtk_object(
(PGtkFileSelection(FComponent))^.cancel_button),
'clicked',
gtk_signal_func( @gtk_cancel),
gtk_object( self));
gtk_signal_connect_object( gtk_object( FComponent),
'destroy',
gtk_signal_func( @gtk_close),
gtk_object( self));
end;
//----------------------------------------------------------------------------
destructor TOpenFileDialog.destroy;
begin
// should this be in Free ?
gtk_signal_handlers_destroy( gtk_object(
(PGtkFileSelection(FComponent))^.ok_button));
gtk_signal_handlers_destroy( gtk_object(
(PGtkFileSelection(FComponent))^.cancel_button));
gtk_signal_handlers_destroy( gtk_object( FComponent));
gtk_widget_destroy( PGtkWidget( FComponent));
inherited Destroy;
end;
end.
--
| Sergio A. Kessler http://perio.unlp.edu.ar/~sergio
-O_O- Keep working at it... you will either succeed, or become an expert.
More information about the Lazarus
mailing list