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