fixed memleak in gtk opendlg

git-svn-id: trunk@5320 -
This commit is contained in:
mattias 2004-03-18 00:55:56 +00:00
parent 1dd0201529
commit 53728989e3
3 changed files with 47 additions and 25 deletions

View File

@ -2073,13 +2073,13 @@ var
begin begin
Result:=false; Result:=false;
if (Data=nil) then ; if (Data=nil) then ;
theDialog:=TCommonDialog(GetLCLObject(Widget)); theDialog:=TCommonDialog(GetNearestLCLObject(Widget));
if (theDialog is TOpenDialog) then begin if (theDialog is TOpenDialog) then begin
// check if history activated // check if history activated
AHistoryEntry:=gtk_object_get_data(PGtkObject(Widget), AHistoryEntry:=gtk_object_get_data(PGtkObject(Widget),
'LCLIsHistoryMenuItem'); 'LCLIsHistoryMenuItem');
if (AHistoryEntry<>nil) and (AHistoryEntry^.Filename<>nil) then begin if (AHistoryEntry<>nil) and (AHistoryEntry^.Filename<>nil) then begin
// use has choosen a history file // user has choosen a history file
// -> select it in the filedialog // -> select it in the filedialog
gtk_file_selection_complete(PGtkFileSelection(theDialog.Handle), gtk_file_selection_complete(PGtkFileSelection(theDialog.Handle),
AHistoryEntry^.Filename); AHistoryEntry^.Filename);
@ -3065,6 +3065,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.222 2004/03/18 00:55:56 mattias
fixed memleak in gtk opendlg
Revision 1.221 2004/02/23 18:24:38 mattias Revision 1.221 2004/02/23 18:24:38 mattias
completed new TToolBar completed new TToolBar

View File

@ -5344,7 +5344,6 @@ begin
// create the menu items in the history menu // create the menu items in the history menu
MenuItemWidget:=gtk_menu_item_new_with_label( MenuItemWidget:=gtk_menu_item_new_with_label(
PFileSelHistoryEntry(HistoryList[i])^.Filename); PFileSelHistoryEntry(HistoryList[i])^.Filename);
SetLCLObject(MenuItemWidget,OpenDialog);
// connect the new MenuItem to the HistoryList entry // connect the new MenuItem to the HistoryList entry
gtk_object_set_data(PGtkObject(MenuItemWidget), 'LCLIsHistoryMenuItem', gtk_object_set_data(PGtkObject(MenuItemWidget), 'LCLIsHistoryMenuItem',
HistoryList[i]); HistoryList[i]);
@ -5637,51 +5636,52 @@ procedure TGtkWidgetSet.InitializeOpenDialog(OpenDialog: TOpenDialog;
SelWidget: PGtkWidget); SelWidget: PGtkWidget);
var var
FileDetailLabel, HBox, FrameWidget: PGtkWidget; FileDetailLabel, HBox, FrameWidget: PGtkWidget;
FileSelWidget: PGtkFileSelection;
begin begin
FileSelWidget:=GTK_FILE_SELECTION(SelWidget);
// Multiselection // Multiselection
if ofAllowMultiSelect in OpenDialog.Options then if ofAllowMultiSelect in OpenDialog.Options then
begin begin
LastFileSelectRow := -1; LastFileSelectRow := -1;
g_signal_connect(gtk_object(PGtkCList( g_signal_connect(gtk_object(FileSelWidget^.file_list),
PGtkFileSelection(SelWidget)^.file_list)),
'select-row', 'select-row',
gtk_signal_func(@gtkOpenDialogRowSelectCB), OpenDialog); gtk_signal_func(@gtkOpenDialogRowSelectCB), OpenDialog);
gtk_clist_set_selection_mode( gtk_clist_set_selection_mode(
PGtkCList(PGtkFileSelection(SelWidget)^.file_list), PGtkCList(FileSelWidget^.file_list),GTK_SELECTION_MULTIPLE);
GTK_SELECTION_MULTIPLE);
end; end;
// Help button // Help button
if (ofShowHelp in OpenDialog.Options) if (ofShowHelp in OpenDialog.Options)
and (GTK_FILE_SELECTION(SelWidget)^.Help_Button<>nil) then begin and (FileSelWidget^.Help_Button<>nil) then begin
gtk_widget_show(GTK_FILE_SELECTION(SelWidget)^.Help_Button); gtk_widget_show(FileSelWidget^.Help_Button);
g_signal_connect( gtk_object((PGtkFileSelection(SelWidget))^.help_button), g_signal_connect( gtk_object(FileSelWidget^.help_button),
'clicked', gtk_signal_func(@gtkDialogHelpclickedCB), OpenDialog); 'clicked', gtk_signal_func(@gtkDialogHelpclickedCB), OpenDialog);
end; end;
// connect selection entry (edit field for filename) // connect selection entry (edit field for filename)
if (GTK_FILE_SELECTION(SelWidget)^.selection_entry<>nil) then begin if (FileSelWidget^.selection_entry<>nil) then begin
SetLCLObject(GTK_FILE_SELECTION(SelWidget)^.selection_entry,OpenDialog); SetLCLObject(FileSelWidget^.selection_entry,OpenDialog);
g_signal_connect( g_signal_connect(
gtk_object((PGtkFileSelection(SelWidget))^.selection_entry), gtk_object(FileSelWidget^.selection_entry),
'key-press-event', gtk_signal_func(@GTKDialogKeyUpDownCB), 'key-press-event', gtk_signal_func(@GTKDialogKeyUpDownCB),
OpenDialog); OpenDialog);
g_signal_connect( g_signal_connect(
gtk_object((PGtkFileSelection(SelWidget))^.selection_entry), gtk_object(FileSelWidget^.selection_entry),
'focus-in-event', gtk_signal_func(@GTKDialogFocusInCB), OpenDialog); 'focus-in-event', gtk_signal_func(@GTKDialogFocusInCB), OpenDialog);
end; end;
// connect dir list (list of directories) // connect dir list (list of directories)
if (GTK_FILE_SELECTION(SelWidget)^.dir_list<>nil) then begin if (FileSelWidget^.dir_list<>nil) then begin
SetLCLObject(GTK_FILE_SELECTION(SelWidget)^.dir_list,OpenDialog); SetLCLObject(FileSelWidget^.dir_list,OpenDialog);
g_signal_connect(gtk_object((PGtkFileSelection(SelWidget))^.dir_list), g_signal_connect(gtk_object(FileSelWidget^.dir_list),
'select-row', gtk_signal_func(@GTKDialogSelectRowCB), OpenDialog); 'select-row', gtk_signal_func(@GTKDialogSelectRowCB), OpenDialog);
end; end;
// connect file list (list of files in current directory) // connect file list (list of files in current directory)
if (GTK_FILE_SELECTION(SelWidget)^.file_list<>nil) then begin if (FileSelWidget^.file_list<>nil) then begin
SetLCLObject(GTK_FILE_SELECTION(SelWidget)^.file_list,OpenDialog); SetLCLObject(FileSelWidget^.file_list,OpenDialog);
g_signal_connect(gtk_object((PGtkFileSelection(SelWidget))^.file_list), g_signal_connect(gtk_object(FileSelWidget^.file_list),
'select-row', gtk_signal_func(@GTKDialogSelectRowCB), OpenDialog); 'select-row', gtk_signal_func(@GTKDialogSelectRowCB), OpenDialog);
end; end;
@ -5695,7 +5695,7 @@ begin
if (ofViewDetail in OpenDialog.Options) then begin if (ofViewDetail in OpenDialog.Options) then begin
// create the frame around the information // create the frame around the information
FrameWidget:=gtk_frame_new(PChar(rsFileInformation)); FrameWidget:=gtk_frame_new(PChar(rsFileInformation));
gtk_box_pack_start(GTK_BOX(GTK_FILE_SELECTION(SelWidget)^.main_vbox), gtk_box_pack_start(GTK_BOX(FileSelWidget^.main_vbox),
FrameWidget,false,false,0); FrameWidget,false,false,0);
gtk_widget_show(FrameWidget); gtk_widget_show(FrameWidget);
// create a HBox, so that the information is left justified // create a HBox, so that the information is left justified
@ -5716,8 +5716,7 @@ begin
// set initial filename // set initial filename
if OpenDialog.Filename<>'' then if OpenDialog.Filename<>'' then
gtk_file_selection_set_filename(GTK_FILE_SELECTION(SelWidget), gtk_file_selection_set_filename(FileSelWidget,PChar(OpenDialog.Filename));
PChar(OpenDialog.Filename));
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -9283,6 +9282,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.480 2004/03/18 00:55:56 mattias
fixed memleak in gtk opendlg
Revision 1.479 2004/03/09 15:30:15 peter Revision 1.479 2004/03/09 15:30:15 peter
* fixed gtk2 compilation * fixed gtk2 compilation

View File

@ -2526,6 +2526,8 @@ var
AHistoryEntry: PFileSelHistoryEntry; AHistoryEntry: PFileSelHistoryEntry;
AFilterEntry: PFileSelFilterEntry; AFilterEntry: PFileSelFilterEntry;
i: integer; i: integer;
FileSelWidget: PGtkFileSelection;
LCLFilterMenu, LCLHistoryMenu: PGTKWidget;
begin begin
if (ADialog=nil) or (not ADialog.HandleAllocated) then exit; if (ADialog=nil) or (not ADialog.HandleAllocated) then exit;
DlgWindow:=PGtkWidget(ADialog.Handle); DlgWindow:=PGtkWidget(ADialog.Handle);
@ -2535,6 +2537,17 @@ begin
gtk_window_set_transient_for(PGtkWindow(DlgWindow),nil); gtk_window_set_transient_for(PGtkWindow(DlgWindow),nil);
if ADialog is TOpenDialog then begin if ADialog is TOpenDialog then begin
FileSelWidget:=GTK_FILE_SELECTION(DlgWindow);
FreeWinWidgetInfo(FileSelWidget^.selection_entry);
FreeWinWidgetInfo(FileSelWidget^.dir_list);
FreeWinWidgetInfo(FileSelWidget^.file_list);
LCLFilterMenu:=PGTKWidget(gtk_object_get_data(PGtkObject(FileSelWidget),
'LCLFilterMenu'));
if LCLFilterMenu<>nil then FreeWinWidgetInfo(LCLFilterMenu);
LCLHistoryMenu:=PGTKWidget(gtk_object_get_data(PGtkObject(FileSelWidget),
'LCLHistoryMenu'));
if LCLHistoryMenu<>nil then FreeWinWidgetInfo(LCLHistoryMenu);
// free history // free history
HistoryList:=TList(gtk_object_get_data(PGtkObject(DlgWindow), HistoryList:=TList(gtk_object_get_data(PGtkObject(DlgWindow),
'LCLHistoryList')); 'LCLHistoryList'));
@ -2974,7 +2987,8 @@ begin
end; end;
end; end;
function CreateWidgetInfo(const AHandle: THandle; const AObject: TObject; const AParams: TCreateParams): PWinWidgetInfo; function CreateWidgetInfo(const AHandle: THandle; const AObject: TObject;
const AParams: TCreateParams): PWinWidgetInfo;
begin begin
Result := CreateWidgetInfo(Pointer(AHandle)); Result := CreateWidgetInfo(Pointer(AHandle));
if Result = nil then Exit; if Result = nil then Exit;
@ -6635,6 +6649,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.269 2004/03/18 00:55:56 mattias
fixed memleak in gtk opendlg
Revision 1.268 2004/03/09 15:30:15 peter Revision 1.268 2004/03/09 15:30:15 peter
* fixed gtk2 compilation * fixed gtk2 compilation