[lazarus] dialogs 0.3

Shane Miller SMiller1 at stvgb.org
Fri May 21 11:06:48 EDT 1999


Well all we would actually do is grab the control by name and therefore we would have the associated widget along with it.

That should work.

Shane


>>> "Baeseman, Cliff" <Cliff.Baeseman at Greenheck.com> 05/21 9:53 AM >>>
Shane something interesting to note is that in the flat ide I handle the
widgets global.

maybe some widget storage location with grab widget by name?  might be handy
for the stuff you are talking about.

Just thinking.

cliff

-----Original Message-----
From: Shane Miller [mailto:SMiller1 at stvgb.org] 
Sent: Friday, May 21, 1999 9:38 AM
To: lazarus at miraclec.com 
Subject: Re: [lazarus] dialogs 0.3


Looking at your dialogs.pp file I have some questions. <Enter>  :-)

I thought the idea was to seperate the GTK from the classes?  
Now I see a lot of gtk specific calls in dialogs.pp

Why not create a unit that has a function called CreateControl or something
like that.  You pass it a fcomponentstyle and it passes back a pointer.
This
way when we want to create Lazarus qith QT widget, we create a unit that
replaces
the CreateControl with QT's createControl and it create's QT widgets?  Also,
the set_modal
could actually call a procedure in that unit.

This makes perfect sense to me because I see it as helping out when
we have to write a QT interface.  Nothing in the classes will need to
change.

(don't flame too much)
Shane



>>> Sergio Kessler <sak at perio.unlp.edu.ar> 05/21 1:50 AM >>>

Hi all,

dialogs.pp 0.3 is out

I've tested extensively and is working fine, if something is 
broke on your pc, you are not following th How-To  :)

attached and pasted here:

//==================================================================
//
//     Dialogs Unit
//
//     Contains : TOpenFileDialog
//                TSaveFileDialog
//                ShowMessage
//
//-----------------------------------------------------------------
//
//     Authors: Sergio A. Kessler
//
//     License: in consideration (MPL ?).
//
//     Version: 0.3
//
//==================================================================


unit dialogs;

{$mode objfpc}

interface

uses
    gtk, classes, Controls, vclGlobals, sysutils;


type

    TCustomDialog = class(TWinControl)
      private
	 FUserChoice: (user_thinking, user_ok, user_cancel, user_close);
         function gtk_Ok( widget: PGtkWidget) : Boolean; cdecl;
	 function gtk_Cancel( widget: PGtkWidget) : Boolean; cdecl;
	 function gtk_Close( widget: PGtkWidget) : Boolean; cdecl;
      protected
      public
         constructor Create(AOwner : TComponent); override;
	 destructor destroy; override;
    end;

    TOpenFileDialog  = class(TCustomDialog)
      private
         FFileName : AnsiString;
         FTitle: AnsiString;
	 FFilter: AnsiString;
	 procedure gtk_create;
	 procedure gtk_destroy;
      public
	 constructor Create (AOwner : TComponent); override;
	 destructor destroy; override;
	 Function Execute : boolean;
	 property FileName : AnsiString read FFileName write FFileName;
	 property Title : AnsiString read FTitle write FTitle;
	 property Filter : AnsiString read FFilter write FFilter;
    end;

	TSaveFileDialog  = class(TOpenFileDialog);


    procedure ShowMessage( const msg: AnsiString );



Implementation

var btn_ok: boolean;

//--------------------------------------------------------------------------
--

function TCustomDialog.gtk_Ok( widget: PGtkWidget) : Boolean; cdecl;
begin
     writeln('--> in gtk_ok');
     FUserChoice := user_ok;
end;

//--------------------------------------------------------------------------
--

function TCustomDialog.gtk_Cancel( widget: PGtkWidget) : Boolean; cdecl;
begin
     writeln('--> in gtk_cancel');
     FUserChoice := user_cancel;
end;

//--------------------------------------------------------------------------
--

function TCustomDialog.gtk_Close( widget: PGtkWidget) : Boolean; cdecl;
begin
     writeln('--> in gtk_close');
     FUserChoice := user_close;
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;

//--------------------------------------------------------------------------
--


constructor TOpenFileDialog.Create (AOwner : TComponent);
begin
     inherited Create(AOwner);
     gtk_create;
end;

//--------------------------------------------------------------------------
--

destructor TOpenFileDialog.destroy;
begin
     gtk_destroy;
     inherited Destroy;
end;

//--------------------------------------------------------------------------
--

Function TOpenFileDialog.Execute : boolean;
begin
     if not (GTK_IS_FILE_SELECTION( FComponent)) then gtk_create;

     if FTitle <> '' then
     begin
        gtk_window_set_title( @((PGtkFileSelection( FComponent))^.Window),
                              PChar(FTitle));
     end;
     
     if FFileName <> '' then
     begin
        gtk_file_selection_set_filename( PGtkFileSelection( FComponent),
                                         PChar(FFileName));
     end;

     if FFilter <> '' then
     begin
        gtk_file_selection_complete( PGtkFileSelection( FComponent),
                                     PChar(FFilter));
     end;
     
     FUserChoice := user_thinking;
     writeln('--> about to file_sel_show');
     Show;
     repeat
          gtk_main_iteration;
     until FUserChoice <> user_thinking;

     writeln('--> about to file_sel_hide');
     if (FUserChoice <> user_close) then Hide;

     Execute := (FUserChoice = user_ok);
     if Execute then
     begin
          FFileName := gtk_file_selection_get_filename( PGtkFileSelection(
FComponent));
     end;
end;

//--------------------------------------------------------------------------
--

Procedure TOpenFileDialog.gtk_create;
begin
     FComponent := gtk_file_selection_new( PChar( FTitle));
     
     gtk_window_set_modal( @((PGtkFileSelection( FComponent))^.Window),
True);

     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;

//--------------------------------------------------------------------------
--

Procedure TOpenFileDialog.gtk_destroy;
begin
     if (GTK_IS_FILE_SELECTION( FComponent)) then
     begin
         writeln('--> destroying file_selection');
         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));
     end;
end;

{function TCustomDialog.GetFileName : String;
Begin
    // this is buggy because you don't know if the widget is destroyed !!

    FFileName := gtk_file_selection_get_filename( PGtkFileSelection(
FComponent));
    GetFileName := FFileName;
End;}

//--------------------------------------------------------------------------
--


procedure ShowMessage( const msg: AnsiString );
var dlg: PGtkWidget;
    btn: PGtkWidget;
    lab: PGtkWidget;

function gtk_btn_ok( widget: PGtkWidget) : Boolean; cdecl;
begin
     writeln('--> in gtk_btn_ok');
     btn_ok := true;
end;
    
begin
// this fu* shit is absolutely trivial in Gnome

    dlg := gtk_dialog_new;
    btn := gtk_button_new_with_label('Ok');
    lab := gtk_label_new( PChar(msg));
    
    gtk_box_pack_start( PGtkBox( PGtkDialog( dlg)^.action_area), btn, True,
True, 0);
    gtk_box_pack_start( PGtkBox( PGtkDialog( dlg)^.vbox), lab, True, True,
0);

    gtk_signal_connect_object( gtk_object( btn),
                               'clicked',
                                gtk_signal_func( @gtk_btn_ok),
                                gtk_object( btn));

    gtk_signal_connect_object( gtk_object( dlg),
                               'destroy',
                                gtk_signal_func( @gtk_btn_ok),
                                gtk_object( dlg));

    btn_ok := false;
    gtk_widget_show( btn);
    gtk_widget_show( lab);
    gtk_widget_show( dlg);
    
    repeat
        gtk_main_iteration;
    until btn_ok;
    
    if GTK_IS_DIALOG( dlg) then
    begin
        gtk_widget_hide( dlg);
        gtk_signal_handlers_destroy( gtk_object( btn));
        gtk_widget_destroy( dlg);
    end;
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.

_________________________________________________________________
     To unsubscribe: mail lazarus-request at miraclec.com with
                "unsubscribe" as the Subject
    archives at http://www.miraclec.com/list_archives/lazarus 

_________________________________________________________________
     To unsubscribe: mail lazarus-request at miraclec.com with
                "unsubscribe" as the Subject
    archives at http://www.miraclec.com/list_archives/lazarus






More information about the Lazarus mailing list