Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtfile / FindP.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: FindP.c /main/5 1996/10/15 10:07:22 mustafa $ */
24 /************************************<+>*************************************
25  ****************************************************************************
26  *
27  *   FILE:           FindP.c
28  *
29  *   COMPONENT_NAME: Desktop File Manager (dtfile)
30  *
31  *   Description:    Processing functions for the find file dialog.
32  *
33  *   FUNCTIONS: FindClose
34  *              ShowFindDialog
35  *
36  *   (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
37  *   (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
38  *   (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
39  *   (c) Copyright 1993, 1994, 1995 Novell, Inc.
40  *
41  ****************************************************************************
42  ************************************<+>*************************************/
43
44 #include <stdio.h>
45
46 #include <Xm/Xm.h>
47 #include <Xm/RowColumn.h>
48
49 #include <Dt/FileM.h>
50 #include "Encaps.h"
51 #include "SharedProcs.h"
52
53 #include "FileMgr.h"
54 #include "Desktop.h"
55 #include "Main.h"
56 #include "Common.h"
57 #include "Find.h"
58 #include "SharedMsgs.h"
59
60
61
62 /********    Static Function Declarations    ********/
63
64 static void FindClose(  XtPointer client_data,
65                         DialogData *old_dialog_data,
66                         DialogData *new_dialog_data) ;
67
68 /********    End Static Function Declarations    ********/
69
70
71
72
73 /************************************************************************
74  *
75  *  ShowFindDialog
76  *      Callback functions invoked from the Find File ... menu
77  *      item.  This function displays the find file dialog.
78  *
79  ************************************************************************/
80
81 void
82 ShowFindDialog(
83         Widget w,
84         XtPointer client_data,
85         XtPointer callback )
86 {
87    FileMgrRec  * file_mgr_rec;
88    DialogData  * dialog_data;
89    FileMgrData * file_mgr_data;
90    FindRec     * find_rec;
91    FindData * find_data;
92    Arg args[2];
93    Widget mbar;
94    int i;
95    XmString label_string;
96    char *tempStr, *tmpStr;
97
98    /*  Set the menu item to insensitive to prevent multiple  */
99    /*  dialogs from being posted and get the area under the  */
100    /*  menu pane redrawn.                                    */
101
102    if (w)
103    {
104       if ( (int) client_data == FM_POPUP )
105         mbar = XtParent(w);
106       else
107         mbar = XmGetPostedFromWidget(XtParent(w));
108
109       XmUpdateDisplay (w);
110       XtSetArg(args[0], XmNuserData, &file_mgr_rec);
111       XtGetValues(mbar, args, 1);
112
113       /* Ignore accelerators when we're insensitive */
114       if ((file_mgr_rec->menuStates & FIND) == 0)
115       {
116          XSetInputFocus(XtDisplay(w),
117                         XtWindow(file_mgr_rec->findBtn_child),
118                         RevertToParent, CurrentTime);
119          return;
120       }
121    }
122    else
123    {
124       /* Done only when restoring a session */
125       file_mgr_rec = (FileMgrRec *)client_data;
126    }
127
128
129    /* Ignore accelerators received after we're unposted */
130    if ((dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec)) == NULL)
131       return;
132
133    file_mgr_data = (FileMgrData *) dialog_data->data;
134
135    file_mgr_rec->menuStates &= ~FIND;
136
137    dialog_data = (DialogData *)file_mgr_data->find;
138    find_data = (FindData *)dialog_data->data;
139    find_data->file_mgr_data = file_mgr_data;
140   
141    if(find_data->content != NULL && w != NULL)
142    {
143       if(strcmp(find_data->content, "") != 0)
144          XtFree(find_data->content);
145       find_data->content = NULL;
146    }
147
148    if(find_data->filter != NULL && w != NULL)
149    {
150       XtFree(find_data->filter);
151       find_data->filter = NULL;
152    }
153
154    if(find_data->directories != NULL && w != NULL)
155    {
156       XtFree(find_data->directories);
157       find_data->directories = NULL;
158    }
159
160    if(w != NULL)
161    {
162       for (i = 0; i < find_data->num_matches; i++)
163          XtFree (find_data->matches[i]);
164
165       XtFree ((char *) find_data->matches);
166
167       find_data->matches = NULL;
168       find_data->num_matches = 0;
169       find_data->selected_item = -1;
170    }
171
172    _DtShowDialog (file_mgr_rec->shell, NULL,
173                (XtPointer)file_mgr_rec, file_mgr_data->find, 
174                NULL, (XtPointer)file_mgr_rec,
175                FindClose, (XtPointer)file_mgr_rec, NULL, False, 
176                False, NULL, NULL);
177
178    /* Save a ptr to file_mgr_rec in the find dialogs structure */
179    find_rec = (FindRec *)_DtGetDialogInstance(file_mgr_data->find);
180    find_rec->fileMgrRec = file_mgr_rec;
181
182    if(file_mgr_data->title != NULL &&
183                strcmp(file_mgr_data->helpVol, DTFILE_HELP_NAME) != 0)
184    {
185       tmpStr = (GETMESSAGE(15,46, "Find"));
186       tempStr = (char *)XtMalloc(strlen(tmpStr) +
187                                  strlen(file_mgr_data->title) + 5);
188       sprintf(tempStr, "%s - %s", file_mgr_data->title, tmpStr);
189    }
190    else
191    {
192       tmpStr = (GETMESSAGE(15,49, "File Manager - Find"));
193       tempStr = XtNewString(tmpStr);
194    }
195    XtSetArg (args[0], XmNtitle, tempStr);
196    XtSetValues (find_rec->shell, args, 1);
197    XtFree(tempStr);
198    file_mgr_rec->findBtn_child=find_rec->shell;
199
200 #if defined(__hpux) || defined(sun)
201    if(file_mgr_data->toolbox)
202    {
203       XtSetArg (args[0], XmNmenuHistory, find_rec->widgArry[ON]);
204       XtSetValues(find_rec->followLink, args, 1);
205    }
206 #endif
207
208    label_string = XmStringCreateLocalized (GetSharedMessage(FILES_FOUND_LABEL));
209    XtSetArg (args[0], XmNlabelString, label_string);
210    XtSetValues (find_rec->listLabel, args, 1);
211    XmStringFree (label_string);
212 }
213
214
215
216
217 /************************************************************************
218  *
219  *  FindClose
220  *      Callback function invoked from the find file dialog's close
221  *      button.  This function resensitizes the menu item, and saves the
222  *      interim dialog values.
223  *
224  ************************************************************************/
225
226 static void
227 FindClose(
228         XtPointer client_data,
229         DialogData *old_dialog_data,
230         DialogData *new_dialog_data )
231 {
232    FileMgrRec * file_mgr_rec = (FileMgrRec *) client_data;
233    XtPointer save_data;
234
235
236    /* Free up the old interim values, and save the new ones */
237    save_data = old_dialog_data->data;
238    old_dialog_data->data = new_dialog_data->data;
239    new_dialog_data->data = save_data;
240    _DtFreeDialogData (new_dialog_data);
241
242
243    /* Resensitize the associated menubutton */
244    file_mgr_rec->menuStates |= FIND;
245 }