ChangeDir.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387
  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 libraries 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: ChangeDir.c /main/7 1996/10/30 11:09:35 drk $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. *
  27. * FILE: ChangeDir.c
  28. *
  29. * COMPONENT_NAME: Desktop File Manager (dtfile)
  30. *
  31. * DESCRIPTION: Source file for the change directory dialog.
  32. *
  33. * FUNCTIONS: ChangeToNewDir
  34. * CheckRestrictedDir
  35. * Create
  36. * Destroy
  37. * DropOnChangeView
  38. * FreeValues
  39. * GetDefaultValues
  40. * GetResourceValues
  41. * GetValues
  42. * GoToNewDir
  43. * InstallChange
  44. * InstallClose
  45. * OkCallback
  46. * SetFocus
  47. * SetValues
  48. * TextChange
  49. * TryToChangeDir
  50. * WriteResourceValues
  51. *
  52. * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
  53. * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
  54. * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
  55. * (c) Copyright 1993, 1994, 1995 Novell, Inc.
  56. *
  57. ****************************************************************************
  58. ************************************<+>*************************************/
  59. #include <signal.h>
  60. #include <stdio.h>
  61. #include <sys/types.h>
  62. #include <sys/stat.h>
  63. #ifdef __hpux
  64. #include <sys/inode.h>
  65. #endif
  66. #include <ctype.h>
  67. #include <pwd.h>
  68. #include <Xm/XmP.h>
  69. #include <Xm/Xm.h>
  70. #include <Xm/MessageB.h>
  71. #include <Xm/SelectioB.h>
  72. #include <Xm/TextF.h>
  73. #include <Xm/VendorSEP.h>
  74. #include <Xm/List.h>
  75. #include <Xm/MwmUtil.h>
  76. #include <Xm/Protocols.h>
  77. #include <X11/ShellP.h>
  78. #include <X11/Shell.h>
  79. #include <X11/Xatom.h>
  80. #include <Dt/Action.h>
  81. #include <Dt/Connect.h>
  82. #include <Dt/DtNlUtils.h>
  83. #include <Dt/SharedProcs.h>
  84. #include <Tt/tttk.h>
  85. #include <Xm/DragIcon.h>
  86. #include <Xm/DragC.h>
  87. #include <Xm/TextF.h>
  88. #include <Xm/XmPrivate.h> /* _XmStringUngenerate */
  89. #include <Dt/Dnd.h>
  90. #include "Encaps.h"
  91. #include "SharedProcs.h"
  92. #include "FileMgr.h"
  93. #include "Desktop.h"
  94. #include "Main.h"
  95. #include "ChangeDir.h"
  96. #include "Help.h"
  97. #include "SharedMsgs.h"
  98. #define MAX_PATH PATH_MAX
  99. static char * CHANGEDIRECTORY = "ChangeDirectory";
  100. static DialogResource resources[] =
  101. {
  102. { "string_path", XmRXmString, sizeof(XmString),
  103. XtOffset(ChangeDirDataPtr, string_path), NULL, _DtXmStringToString },
  104. { "historyList", XmRXmStringTable, sizeof(XmStringTable),
  105. XtOffset(ChangeDirDataPtr, history_list), NULL, _DtXmStringTableToString },
  106. { "visibleCount", XmRInt, sizeof(int),
  107. XtOffset(ChangeDirDataPtr, visible_count), (XtPointer) 8, _DtIntToString },
  108. { "listCount", XmRInt, sizeof(int),
  109. XtOffset(ChangeDirDataPtr, list_count), NULL, _DtIntToString },
  110. };
  111. /******** Static Function Declarations ********/
  112. static void Create( Display *display,
  113. Widget parent,
  114. Widget *shell,
  115. XtPointer *dialog) ;
  116. static void InstallChange( ChangeDirRec *change_dir_rec,
  117. XtCallbackProc callback,
  118. XtPointer client_data) ;
  119. static void InstallClose( ChangeDirRec *change_dir_rec,
  120. XtCallbackProc callback,
  121. XtPointer client_data) ;
  122. static void Destroy( ChangeDirRec *change_dir_rec) ;
  123. static XtPointer GetValues( ChangeDirRec *change_dir_rec) ;
  124. static XtPointer GetDefaultValues( void ) ;
  125. static XtPointer GetResourceValues( XrmDatabase data_base,
  126. char **name_list) ;
  127. static void SetValues( ChangeDirRec *change_dir_rec,
  128. ChangeDirData *change_dir_data) ;
  129. static void WriteResourceValues( DialogData *values,
  130. int fd,
  131. char **name_list) ;
  132. static void FreeValues( ChangeDirData *change_dir_data) ;
  133. static Boolean TryToChangeDir( Boolean isFromDialog,
  134. char * incoming_string,
  135. FileMgrData * file_mgr_data,
  136. FileMgrRec * file_mgr_rec,
  137. ChangeDirData * change_dir_data,
  138. Widget selection_box,
  139. ChangeDirApply * apply_data,
  140. XmSelectionBoxCallbackStruct * callback_data,
  141. void (*callback)()) ;
  142. static void OkCallback( Widget selection_box,
  143. ChangeDirApply *apply_data,
  144. XmSelectionBoxCallbackStruct *callback_data) ;
  145. static int CheckRestrictedDir ( FileMgrRec * file_mgr_rec,
  146. FileMgrData * file_mgr_data,
  147. char ** value,
  148. Boolean relative_name);
  149. static void GoToNewDir ( FileMgrData * file_mgr_data,
  150. char * dir_name) ;
  151. static void SetFocus(
  152. ChangeDirRec *change_dir_rec,
  153. ChangeDirData *change_dir_data) ;
  154. /******** End Static Function Declarations ********/
  155. extern char *getwd(char *);
  156. /*
  157. * The Dialog Class structure.
  158. */
  159. static DialogClass changeDirClassRec =
  160. {
  161. resources,
  162. XtNumber(resources),
  163. Create,
  164. (DialogInstallChangeProc) InstallChange,
  165. (DialogInstallCloseProc) InstallClose,
  166. (DialogDestroyProc) Destroy,
  167. (DialogGetValuesProc) GetValues,
  168. GetDefaultValues,
  169. GetResourceValues,
  170. (DialogSetValuesProc) SetValues,
  171. WriteResourceValues,
  172. (DialogFreeValuesProc) FreeValues,
  173. (DialogMapWindowProc) _DtGenericMapWindow,
  174. (DialogSetFocusProc) SetFocus,
  175. };
  176. DialogClass * changeDirClass = (DialogClass *) &changeDirClassRec;
  177. /************************************************************************
  178. *
  179. * Create
  180. *
  181. ************************************************************************/
  182. static void
  183. Create(
  184. Display *display,
  185. Widget parent,
  186. Widget *shell,
  187. XtPointer *dialog )
  188. {
  189. ChangeDirRec * change_dir_rec;
  190. XmString prompt;
  191. Widget w;
  192. Arg args[8];
  193. int n;
  194. XtTranslations trans_table;
  195. Widget change_dir;
  196. /* Allocate the change directory dialog instance record. */
  197. change_dir_rec = (ChangeDirRec *) XtMalloc (sizeof (ChangeDirRec));
  198. prompt = XmStringCreateLocalized (((char *)GETMESSAGE(2,14, "Destination Folder:")));
  199. trans_table = XtParseTranslationTable(translations_space);
  200. n = 0;
  201. XtSetArg (args[n], XmNselectionLabelString, prompt); n++;
  202. XtSetArg (args[n], XmNokLabelString, okXmString); n++;
  203. XtSetArg (args[n], XmNcancelLabelString, cancelXmString); n++;
  204. XtSetArg (args[n], XmNhelpLabelString, helpXmString); n++;
  205. XtSetArg (args[n], XmNautoUnmanage, False); n++;
  206. XtSetArg (args[n], XmNtextTranslations, trans_table); n++;
  207. change_dir = change_dir_rec->change_dir =
  208. XmCreateSelectionDialog (parent, "change_directory", args, n);
  209. change_dir_rec->shell = XtParent(change_dir);
  210. XmStringFree (prompt);
  211. /* Add the help callback to each of the important sub-components */
  212. XtAddCallback(change_dir, XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
  213. HELP_CHANGEDIR_DIALOG_STR);
  214. w = XmSelectionBoxGetChild(change_dir, XmDIALOG_APPLY_BUTTON);
  215. XtAddCallback(w, XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
  216. HELP_CHANGEDIR_DIALOG_STR);
  217. w = XmSelectionBoxGetChild(change_dir, XmDIALOG_CANCEL_BUTTON);
  218. XtAddCallback(w, XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
  219. HELP_CHANGEDIR_DIALOG_STR);
  220. w = XmSelectionBoxGetChild(change_dir, XmDIALOG_HELP_BUTTON);
  221. XtAddCallback(w, XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
  222. HELP_CHANGEDIR_DIALOG_STR);
  223. XtAddCallback(w, XmNactivateCallback, (XtCallbackProc)HelpRequestCB,
  224. HELP_CHANGEDIR_DIALOG_STR);
  225. w = XmSelectionBoxGetChild(change_dir, XmDIALOG_OK_BUTTON);
  226. XtAddCallback(w, XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
  227. HELP_CHANGEDIR_DIALOG_STR);
  228. w = XmSelectionBoxGetChild(change_dir, XmDIALOG_LIST);
  229. XtAddCallback(XtParent(w), XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
  230. HELP_CHANGEDIR_DIALOG_STR);
  231. w = XmSelectionBoxGetChild(change_dir, XmDIALOG_LIST_LABEL);
  232. XtAddCallback(w, XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
  233. HELP_CHANGEDIR_DIALOG_STR);
  234. w = XmSelectionBoxGetChild(change_dir, XmDIALOG_SELECTION_LABEL);
  235. XtAddCallback(w, XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
  236. HELP_CHANGEDIR_DIALOG_STR);
  237. w = XmSelectionBoxGetChild(change_dir, XmDIALOG_TEXT);
  238. XtAddCallback(w, XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
  239. HELP_CHANGEDIR_DIALOG_STR);
  240. /* Adjust the margin widths and heights of each of the buttons */
  241. XtSetArg (args[0], XmNmarginWidth, 6);
  242. XtSetArg (args[1], XmNmarginHeight, 2);
  243. w = XmSelectionBoxGetChild (change_dir_rec->change_dir, XmDIALOG_OK_BUTTON);
  244. XtSetValues (w, args, 2);
  245. w = XmSelectionBoxGetChild (change_dir_rec->change_dir,
  246. XmDIALOG_HELP_BUTTON);
  247. XtSetValues (w, args, 2);
  248. w = XmSelectionBoxGetChild (change_dir_rec->change_dir,
  249. XmDIALOG_CANCEL_BUTTON);
  250. XtSetValues (w, args, 2);
  251. XtUnmanageChild(XmSelectionBoxGetChild (change_dir_rec->change_dir,
  252. XmDIALOG_APPLY_BUTTON));
  253. /* Adjust the decorations for the dialog shell of the dialog */
  254. XtSetArg(args[0], XmNmwmFunctions, MWM_FUNC_MOVE | MWM_FUNC_CLOSE);
  255. XtSetArg(args[1], XmNmwmDecorations,
  256. MWM_DECOR_BORDER | MWM_DECOR_TITLE);
  257. XtSetValues (change_dir_rec->shell, args, 2);
  258. XtSetArg(args[0], XmNcancelButton, w);
  259. XtSetValues (change_dir_rec->change_dir, args, 1);
  260. /* Set the return values for the dialog widget and dialog instance. */
  261. *shell = change_dir_rec->change_dir;
  262. *dialog = (XtPointer) change_dir_rec;
  263. }
  264. /************************************************************************
  265. *
  266. * InstallChange
  267. *
  268. ************************************************************************/
  269. static void
  270. InstallChange(
  271. ChangeDirRec *change_dir_rec,
  272. XtCallbackProc callback,
  273. XtPointer client_data )
  274. {
  275. Widget selection_box = change_dir_rec->change_dir;
  276. ChangeDirApply * apply_data;
  277. /* Setup the callback data to be sent to the Ok callback. */
  278. /* This contains the encapsulation callback to invoke upon */
  279. /* the data within the dialog being changed. */
  280. apply_data = (ChangeDirApply *) XtMalloc (sizeof (ChangeDirApply));
  281. apply_data->callback = callback;
  282. apply_data->client_data = client_data;
  283. apply_data->change_dir_rec = (XtPointer) change_dir_rec;
  284. change_dir_rec->apply_data = apply_data;
  285. /* Add the callbacks for list item insertion and help. */
  286. XtAddCallback (selection_box, XmNokCallback, (XtCallbackProc) OkCallback,
  287. (XtPointer) apply_data);
  288. }
  289. /************************************************************************
  290. *
  291. * InstallClose
  292. *
  293. ************************************************************************/
  294. static void
  295. InstallClose(
  296. ChangeDirRec *change_dir_rec,
  297. XtCallbackProc callback,
  298. XtPointer client_data )
  299. {
  300. Widget close_widget;
  301. Atom delete_window_atom;
  302. close_widget =
  303. XmSelectionBoxGetChild (change_dir_rec->change_dir,
  304. XmDIALOG_CANCEL_BUTTON);
  305. XtAddCallback (close_widget, XmNactivateCallback, callback, client_data);
  306. delete_window_atom = XmInternAtom (XtDisplay(change_dir_rec->shell),
  307. "WM_DELETE_WINDOW", True);
  308. XmRemoveWMProtocols( change_dir_rec->shell, &delete_window_atom, 1 );
  309. XmAddWMProtocolCallback( change_dir_rec->shell, delete_window_atom, callback,
  310. (XtPointer)client_data );
  311. }
  312. /************************************************************************
  313. *
  314. * Destroy
  315. *
  316. ************************************************************************/
  317. static void
  318. Destroy(
  319. ChangeDirRec *change_dir_rec )
  320. {
  321. XtDestroyWidget (change_dir_rec->change_dir);
  322. XtFree ((char *) change_dir_rec->apply_data);
  323. XtFree ((char *) change_dir_rec);
  324. }
  325. /************************************************************************
  326. *
  327. * GetValues
  328. *
  329. ************************************************************************/
  330. static XtPointer
  331. GetValues(
  332. ChangeDirRec *change_dir_rec )
  333. {
  334. ChangeDirData * change_dir_data;
  335. Arg args[8];
  336. int n;
  337. XmStringTable history_list;
  338. XmString string_path;
  339. /* Allocate and initialize the change dir dialog data. */
  340. change_dir_data = (ChangeDirData *) XtMalloc (sizeof (ChangeDirData));
  341. change_dir_data->displayed = True;
  342. change_dir_data->host_name = NULL;
  343. change_dir_data->file_mgr_rec = NULL;
  344. n = 0;
  345. XtSetArg (args[n], XmNx, &change_dir_data->x); n++;
  346. XtSetArg (args[n], XmNy, &change_dir_data->y); n++;
  347. XtSetArg (args[n], XmNwidth, &change_dir_data->width); n++;
  348. XtSetArg (args[n], XmNheight, &change_dir_data->height); n++;
  349. XtSetArg (args[n], XmNlistItemCount, &change_dir_data->list_count); n++;
  350. XtSetArg (args[n], XmNlistVisibleItemCount, &change_dir_data->visible_count); n++;
  351. XtSetArg (args[n], XmNtextString, &string_path); n++;
  352. XtSetArg (args[n], XmNlistItems, &history_list); n++;
  353. XtGetValues (change_dir_rec->change_dir, args, n);
  354. /* Extract and make local copies of the XmString data. */
  355. change_dir_data->history_list = (XmStringTable)
  356. XtMalloc (sizeof(XmStringTable) * (change_dir_data->list_count + 1));
  357. for (n = 0; n < change_dir_data->list_count; n++)
  358. change_dir_data->history_list[n] = XmStringCopy (history_list[n]);
  359. change_dir_data->history_list[n] = NULL;
  360. if(change_dir_data->string_path)
  361. XmStringFree (change_dir_data->string_path);
  362. change_dir_data->string_path = XmStringCopy (string_path);
  363. return ((XtPointer) change_dir_data);
  364. }
  365. /************************************************************************
  366. *
  367. * GetDefaultValues
  368. *
  369. ************************************************************************/
  370. static XtPointer
  371. GetDefaultValues( void )
  372. {
  373. ChangeDirData * change_dir_data;
  374. /* Allocate and initialize the default change dir dialog data. */
  375. change_dir_data = (ChangeDirData *) XtMalloc (sizeof (ChangeDirData));
  376. change_dir_data->displayed = False;
  377. change_dir_data->x = 0;
  378. change_dir_data->y = 0;
  379. change_dir_data->height = 0;
  380. change_dir_data->width = 0;
  381. change_dir_data->string_path = NULL;
  382. /*
  383. This will cause users_home_dir to be displayed in
  384. Application Manager go to dialog.
  385. if(restrictMode)
  386. change_dir_data->string_path =
  387. XmStringCreateLocalized(users_home_dir, XmFONTLIST_DEFAULT_TAG);
  388. else
  389. change_dir_data->string_path = NULL;
  390. */
  391. change_dir_data->history_list = NULL;
  392. change_dir_data->visible_count = 8;
  393. change_dir_data->list_count = 0;
  394. change_dir_data->host_name = NULL;
  395. change_dir_data->file_mgr_rec = NULL;
  396. return ((XtPointer) change_dir_data);
  397. }
  398. /************************************************************************
  399. *
  400. * GetResourceValues
  401. *
  402. ************************************************************************/
  403. static XtPointer
  404. GetResourceValues(
  405. XrmDatabase data_base,
  406. char **name_list )
  407. {
  408. ChangeDirData * change_dir_data;
  409. XmStringTable new_table;
  410. int i;
  411. /* Allocate and get the resources for change dir dialog data. */
  412. change_dir_data = (ChangeDirData *) XtMalloc (sizeof (ChangeDirData));
  413. _DtDialogGetResources (data_base, name_list,
  414. CHANGEDIRECTORY, (char *) change_dir_data,
  415. resources, changeDirClass->resource_count);
  416. change_dir_data->host_name = NULL;
  417. /* If the history list is Non-Null, realloc the pointer array */
  418. /* one element larger and NULL out the new last element */
  419. if (change_dir_data->list_count != 0)
  420. {
  421. new_table = (XmStringTable) XtMalloc (sizeof (XmStringTable) *
  422. (change_dir_data->list_count + 1));
  423. for (i = 0; i < change_dir_data->list_count; i++)
  424. new_table[i] = change_dir_data->history_list[i];
  425. new_table[change_dir_data->list_count] = NULL;
  426. /******************
  427. THIS WILL BE A MEMORY HOLE WHEN MOTIF FIXES THE XMSTRINGTABLE
  428. CONVERTER. EITHER REALLOC THE RETURNED TABLE OR COPY AND FREE IT.
  429. ******************/
  430. change_dir_data->history_list = new_table;
  431. }
  432. return ((XtPointer) change_dir_data);
  433. }
  434. /************************************************************************
  435. *
  436. * SetValues
  437. *
  438. ************************************************************************/
  439. static void
  440. SetValues(
  441. ChangeDirRec *change_dir_rec,
  442. ChangeDirData *change_dir_data )
  443. {
  444. Arg args[4];
  445. char *tmp_str, *host_name;
  446. XmString host_string;
  447. DialogData * dialog_data;
  448. FileMgrData * file_mgr_data;
  449. dialog_data = _DtGetInstanceData (change_dir_data->file_mgr_rec);
  450. file_mgr_data = (FileMgrData *) dialog_data->data;
  451. if(change_dir_data->string_path)
  452. XmStringFree (change_dir_data->string_path);
  453. if( restrictMode
  454. && file_mgr_data->toolbox == False )
  455. change_dir_data->string_path =
  456. XmStringCreateLocalized( users_home_dir);
  457. else if( file_mgr_data->restricted_directory )
  458. change_dir_data->string_path =
  459. XmStringCreateLocalized( file_mgr_data->current_directory);
  460. else
  461. change_dir_data->string_path = NULL;
  462. XtSetArg (args[0], XmNlistItemCount, change_dir_data->list_count);
  463. XtSetArg (args[1], XmNlistVisibleItemCount, change_dir_data->visible_count);
  464. XtSetArg (args[2], XmNtextString, change_dir_data->string_path);
  465. XtSetArg (args[3], XmNlistItems, change_dir_data->history_list);
  466. XtSetValues (change_dir_rec->change_dir, args, 4);
  467. if( change_dir_data->string_path )
  468. {
  469. Widget text;
  470. text = XmSelectionBoxGetChild(change_dir_rec->change_dir, XmDIALOG_TEXT);
  471. XtAddCallback (text, XmNmodifyVerifyCallback,
  472. (XtCallbackProc)TextChange, (XtPointer)file_mgr_data );
  473. XtAddCallback (text, XmNmotionVerifyCallback,
  474. (XtCallbackProc)TextChange, (XtPointer)file_mgr_data );
  475. XtAddCallback (text, XmNvalueChangedCallback,
  476. (XtCallbackProc)TextChange, (XtPointer)file_mgr_data );
  477. }
  478. tmp_str = GETMESSAGE(2, 16, "System Name: ");
  479. host_name = XtMalloc(strlen(tmp_str) + strlen(change_dir_data->host_name)+1);
  480. sprintf(host_name, "%s%s", tmp_str, change_dir_data->host_name);
  481. host_string = XmStringCreateLocalized (host_name);
  482. XtSetArg (args[0], XmNlabelString, host_string);
  483. XtSetValues (XmSelectionBoxGetChild (change_dir_rec->change_dir,
  484. XmDIALOG_LIST_LABEL), args, 1);
  485. XtFree(host_name);
  486. XmStringFree(host_string);
  487. }
  488. /************************************************************************
  489. *
  490. * WriteResourceValues
  491. *
  492. ************************************************************************/
  493. static void
  494. WriteResourceValues(
  495. DialogData *values,
  496. int fd,
  497. char **name_list )
  498. {
  499. ChangeDirData * change_dir_data = (ChangeDirData *) values->data;
  500. ChangeDirRec * change_dir_rec;
  501. /* If the dialog is currently displayed, update the geometry */
  502. /* fields to their current values. */
  503. if (change_dir_data->displayed == True)
  504. {
  505. _DtGenericUpdateWindowPosition(values);
  506. change_dir_rec = (ChangeDirRec *) _DtGetDialogInstance (values);
  507. }
  508. _DtDialogPutResources (fd, name_list, CHANGEDIRECTORY, values->data,
  509. resources, changeDirClass->resource_count);
  510. }
  511. /************************************************************************
  512. *
  513. * FreeValues
  514. *
  515. ************************************************************************/
  516. static void
  517. FreeValues(
  518. ChangeDirData *change_dir_data )
  519. {
  520. int i;
  521. for (i = 0; i < change_dir_data->list_count; i++)
  522. XmStringFree (change_dir_data->history_list[i]);
  523. XtFree ((char *) change_dir_data->history_list);
  524. XmStringFree (change_dir_data->string_path);
  525. XtFree ((char *) change_dir_data->host_name);
  526. XtFree ((char *) change_dir_data);
  527. }
  528. /************************************************************************
  529. ************************************************************************
  530. *
  531. * Internal functions used by the ChangeDir dialog
  532. *
  533. ************************************************************************
  534. ************************************************************************/
  535. /*****************************************************************************
  536. TryToChangeDir
  537. INPUT:
  538. OUTPUT:
  539. DESCRIPTION:
  540. This function is used both by the ChangeDir dialog, and the FileMgr
  541. dialog's text field; it attempts to verify the incoming string, and
  542. then change to the indicated directory.
  543. NOTE:
  544. *****************************************************************************/
  545. static Boolean
  546. TryToChangeDir(
  547. Boolean isFromDialog,
  548. char * incoming_string,
  549. FileMgrData * file_mgr_data,
  550. FileMgrRec * file_mgr_rec,
  551. ChangeDirData * change_dir_data,
  552. Widget selection_box,
  553. ChangeDirApply * apply_data,
  554. XmSelectionBoxCallbackStruct * callback_data,
  555. void (*callback)())
  556. {
  557. char * new_directory;
  558. char * host;
  559. char * path;
  560. struct stat stat_buf;
  561. Widget list;
  562. XmString path_string;
  563. XmString host_string;
  564. Arg args[1];
  565. char * message_buf;
  566. char * tmpStr;
  567. char * title;
  568. char * msg;
  569. Boolean rc = True;
  570. char *restricted = NULL;
  571. new_directory = XtNewString(incoming_string);
  572. if ((new_directory) && (strcmp(new_directory, "") != 0))
  573. {
  574. _DtPathFromInput(new_directory, file_mgr_data->current_directory,
  575. &host, &path);
  576. }
  577. else
  578. {
  579. tmpStr = GetSharedMessage(CHANGE_DIR_ERROR_TITLE);
  580. title = XtNewString(tmpStr);
  581. tmpStr = GETMESSAGE(2,18, "Destination Folder name is missing.\nType in a folder name or select a folder from the list.");
  582. msg = XtNewString(tmpStr);
  583. if(isFromDialog)
  584. _DtMessage(selection_box, title, msg, NULL, HelpRequestCB);
  585. else
  586. _DtMessage(file_mgr_rec->current_directory_text, title, msg, NULL,
  587. HelpRequestCB);
  588. XtFree(title);
  589. XtFree(msg);
  590. return False;
  591. }
  592. /* Don't allow access to the desktop directory */
  593. if (path)
  594. {
  595. char *ttpath = (char *) GetTTPath(path);
  596. char *dtpath = (char *) GetTTPath(desktop_dir);
  597. if( ttpath && strcmp(ttpath, dtpath) == 0)
  598. {
  599. restricted = ttpath;
  600. XtFree(path);
  601. path = NULL;
  602. }
  603. }
  604. /* Stat the file and see if it is a valid directory. (If the current view
  605. is restricted, make sure that the new directory doesn't violate the
  606. directory restrictions. If so, refilter the displayed file set to show
  607. the files in this directory.
  608. */
  609. if ((path)
  610. &&(stat(path, &stat_buf) == 0)
  611. &&((stat_buf.st_mode & S_IFMT) == S_IFDIR)
  612. &&(CheckRestrictedDir(file_mgr_rec, file_mgr_data, &path, False) == 0))
  613. {
  614. /* Check for read/xcute permission */
  615. if (CheckAccess(path, R_OK | X_OK))
  616. {
  617. tmpStr = GETMESSAGE(9, 6, "Action Error");
  618. title = XtNewString(tmpStr);
  619. msg = (char *)XtMalloc(strlen(GETMESSAGE(30, 1, "Cannot read from %s"))
  620. + strlen(new_directory)
  621. + 1);
  622. sprintf(msg, GETMESSAGE(30, 1, "Cannot read from %s"), new_directory);
  623. if(isFromDialog)
  624. _DtMessage(selection_box, title, msg, NULL, HelpRequestCB);
  625. else
  626. _DtMessage(file_mgr_rec->current_directory_text, title,
  627. msg, NULL, HelpRequestCB);
  628. XtFree(title);
  629. XtFree(msg);
  630. return False;
  631. }
  632. else
  633. {
  634. if (selection_box)
  635. {
  636. /* Adjust the selection box elements to add the text item
  637. into the list.
  638. */
  639. list = XmSelectionBoxGetChild(selection_box, XmDIALOG_LIST);
  640. path_string = XmStringCreateLocalized(path);
  641. if (XmListItemExists(list, path_string))
  642. XmListDeselectAllItems(list);
  643. else
  644. XmListAddItem(list, path_string, 0);
  645. XmListSelectItem(list, path_string, False);
  646. XmListSetBottomPos(list, 0);
  647. XmStringFree(path_string);
  648. }
  649. /* Clear out the text string */
  650. if (isFromDialog)
  651. {
  652. if(restrictMode)
  653. XtSetArg(args[0],
  654. XmNtextString,
  655. XmStringCreateLocalized(users_home_dir));
  656. else
  657. XtSetArg(args[0], XmNtextString, NULL);
  658. XtSetValues(selection_box, args, 1);
  659. }
  660. else
  661. {
  662. if(!file_mgr_data || !file_mgr_data->restricted_directory)
  663. XmTextFieldSetString(file_mgr_rec->current_directory_text,
  664. incoming_string);
  665. }
  666. /* Update the change directory host name field
  667. and the host name indicator widget in the dialog.
  668. */
  669. XtFree((char *) change_dir_data->host_name);
  670. change_dir_data->host_name = XtNewString(host);
  671. if (selection_box)
  672. {
  673. tmpStr = GETMESSAGE(2, 16, "System Name: ");
  674. message_buf = XtMalloc(strlen(tmpStr) +
  675. strlen(change_dir_data->host_name) + 1);
  676. sprintf(message_buf, "%s%s", tmpStr, change_dir_data->host_name);
  677. host_string =
  678. XmStringCreateLocalized(message_buf);
  679. XtSetArg(args[0], XmNlabelString, host_string);
  680. XtSetValues(XmSelectionBoxGetChild(selection_box,XmDIALOG_LIST_LABEL),
  681. args, 1);
  682. XtFree(message_buf);
  683. XmStringFree(host_string);
  684. XmUpdateDisplay (selection_box);
  685. }
  686. /* Call the encapsulation change data callback */
  687. if (isFromDialog)
  688. (*callback)(selection_box, apply_data->client_data, path);
  689. else
  690. (*callback)(file_mgr_data, path);
  691. }
  692. }
  693. else
  694. {
  695. tmpStr = GetSharedMessage(CHANGE_DIR_ERROR_TITLE);
  696. title = XtNewString(tmpStr);
  697. if(restricted)
  698. {
  699. tmpStr = GETMESSAGE(2,20,"You cannot switch to folder:\n\n%s\n\nYou are not allowed to view this folder\nbecause it is a restricted folder.");
  700. path = restricted;
  701. }
  702. else
  703. tmpStr = GETMESSAGE(2,19,"The following folder name is invalid.\n\n%s");
  704. if(path)
  705. {
  706. message_buf = XtMalloc(strlen(tmpStr) + strlen(path) + 1);
  707. sprintf(message_buf, tmpStr, path);
  708. }
  709. else
  710. {
  711. message_buf = XtMalloc(strlen(tmpStr) + strlen(new_directory) + 1);
  712. sprintf(message_buf, tmpStr, new_directory);
  713. }
  714. if (isFromDialog)
  715. _DtMessage(selection_box, title, message_buf, NULL, HelpRequestCB);
  716. else
  717. _DtMessage(file_mgr_rec->current_directory_text, title, message_buf,
  718. NULL, HelpRequestCB);
  719. XtFree(title);
  720. XtFree(message_buf);
  721. rc = False;
  722. }
  723. if (path)
  724. XtFree((char *) path);
  725. XtFree((char *) host);
  726. XtFree((char *) new_directory);
  727. return rc;
  728. }
  729. /************************************************************************
  730. *
  731. * OkCallback
  732. * This is a callback function called when the Ok button (Apply)
  733. * is pressed. It adds the string contained within the call data
  734. * into the selection boxes list.
  735. *
  736. ************************************************************************/
  737. static void
  738. OkCallback(
  739. Widget selection_box,
  740. ChangeDirApply *apply_data,
  741. XmSelectionBoxCallbackStruct *callback_data )
  742. {
  743. DialogData * dialog_data;
  744. ChangeDirData * change_dir_data;
  745. FileMgrRec * file_mgr_rec;
  746. FileMgrData * file_mgr_data;
  747. char *strValue;
  748. char *value = NULL;
  749. int result;
  750. char message_buf[MAX_PATH + 100];
  751. char * tmpStr;
  752. char * title;
  753. char * msg;
  754. /* Get the change dir data record */
  755. dialog_data = _DtGetInstanceData (apply_data->change_dir_rec);
  756. change_dir_data = (ChangeDirData *) dialog_data->data;
  757. file_mgr_rec = (FileMgrRec *) change_dir_data->file_mgr_rec;
  758. dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
  759. file_mgr_data = (FileMgrData *) dialog_data->data;
  760. value = (char *) _XmStringUngenerate((XmString)callback_data->value,
  761. XmFONTLIST_DEFAULT_TAG,
  762. XmCHARSET_TEXT, XmCHARSET_TEXT);
  763. if ( value == NULL)
  764. {
  765. tmpStr = GetSharedMessage(CHANGE_DIR_ERROR_TITLE);
  766. title = XtNewString(tmpStr);
  767. tmpStr = (char *) GETMESSAGE(2, 11, "Cannot get the new folder name.");
  768. msg = XtNewString(tmpStr);
  769. _DtMessage(selection_box, title, message_buf, NULL, HelpRequestCB);
  770. XtFree(title);
  771. XtFree(msg);
  772. return;
  773. }
  774. strValue = XtNewString(value);
  775. if(file_mgr_data->toolbox && strValue[0] != '/')
  776. result = CheckRestrictedDir(file_mgr_rec, file_mgr_data, &strValue, True);
  777. else
  778. result = CheckRestrictedDir(file_mgr_rec, file_mgr_data, &strValue,False);
  779. /* Process the string representing a directory to verify */
  780. /* that it is a valid path. */
  781. if (result == 0)
  782. {
  783. TryToChangeDir(True, (char *)strValue, file_mgr_data,
  784. file_mgr_rec, change_dir_data, selection_box, apply_data,
  785. callback_data, apply_data->callback);
  786. }
  787. XtFree(value);
  788. XtFree(strValue);
  789. }
  790. /************************************************************************
  791. *
  792. * CheckRestrictedDir:
  793. * Make sure we stay inside a restricted directory
  794. *
  795. ************************************************************************/
  796. static int
  797. CheckRestrictedDir (
  798. FileMgrRec * file_mgr_rec,
  799. FileMgrData * file_mgr_data,
  800. char ** value,
  801. Boolean relative_name)
  802. {
  803. char *tmpStr, directory[MAXPATHLEN];
  804. int len;
  805. char *tmpBuffer, *title, *msg;
  806. /* If not in restricte mode, everything is ok. */
  807. if (file_mgr_data->restricted_directory == NULL && !restrictMode)
  808. return 0;
  809. /* get real file name */
  810. if (relative_name)
  811. {
  812. tmpStr = (char *)XtMalloc(strlen(*value) +
  813. strlen(file_mgr_data->restricted_directory) + 3);
  814. strcpy(tmpStr, file_mgr_data->restricted_directory);
  815. if(*value[0] != '/')
  816. strcat(tmpStr, "/");
  817. strcat(tmpStr, *value);
  818. XtFree(*value);
  819. *value = tmpStr;
  820. }
  821. *value = (char *) DtEliminateDots (*value);
  822. if( restrictMode
  823. && file_mgr_data->toolbox == False )
  824. {
  825. if( strcmp( users_home_dir, "/" ) == 0 )
  826. return 0;
  827. strcpy( directory, users_home_dir );
  828. }
  829. else
  830. strcpy( directory, file_mgr_data->restricted_directory );
  831. len = strlen(directory);
  832. if( len > 1 && directory[len-1] == '/' )
  833. {
  834. directory[len - 1] = 0x0;
  835. --len;
  836. }
  837. /* check if value is inside the restricted subdir */
  838. len = strlen(directory);
  839. if (strncmp(*value, directory, len) != 0 ||
  840. (*value)[len] != '/' && (*value)[len] != '\0')
  841. {
  842. tmpBuffer = GetSharedMessage(CHANGE_DIR_ERROR_TITLE);
  843. title = XtNewString(tmpBuffer);
  844. if(restrictMode)
  845. tmpBuffer = GETMESSAGE(2,8, "You cannot switch to this folder. You are\nallowed to view only folders beneath your\ncurrent folder. You cannot specify an absolute\npath to the new folder.");
  846. else
  847. tmpBuffer = GETMESSAGE(2,9, "This view is in restricted mode. You cannot go\nto the specified folder because it is not in the\nrelative path of the restricted folder.\n");
  848. msg = XtNewString(tmpBuffer);
  849. _DtMessage(file_mgr_rec->current_directory_text, title, msg,
  850. NULL, HelpRequestCB);
  851. XtFree(title);
  852. XtFree(msg);
  853. return -1;
  854. }
  855. return 0;
  856. }
  857. /************************************************************************
  858. *
  859. * ChangeToNewDir
  860. * This is the activate callback for the FileMgr text field provided
  861. * for quickly changing the current directory being viewed.
  862. *
  863. ************************************************************************/
  864. void
  865. ChangeToNewDir (
  866. Widget text_field,
  867. XtPointer client_data,
  868. XmAnyCallbackStruct * callback_data )
  869. {
  870. DialogData * dialog_data;
  871. ChangeDirData * change_dir_data;
  872. ChangeDirRec * change_dir_rec;
  873. FileMgrRec * file_mgr_rec;
  874. FileMgrData * file_mgr_data;
  875. char * value;
  876. Widget selection_box;
  877. Arg args[1];
  878. char * tmpStr;
  879. int rc;
  880. /* Get the change dir data record */
  881. file_mgr_rec = (FileMgrRec *) client_data;
  882. dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
  883. file_mgr_data = (FileMgrData *) dialog_data->data;
  884. change_dir_data = (ChangeDirData *) file_mgr_data->change_dir->data;
  885. change_dir_rec =(ChangeDirRec *)_DtGetDialogInstance(file_mgr_data->change_dir);
  886. if (change_dir_rec)
  887. selection_box = change_dir_rec->change_dir;
  888. else
  889. selection_box = NULL;
  890. value = (char *)XmTextFieldGetString(text_field);
  891. /* check if user attempts to go outside restricted directory */
  892. rc = CheckRestrictedDir (file_mgr_rec, file_mgr_data, &value, True);
  893. /*
  894. This code will de-activate the text widget.
  895. HCI requests that if the switch is not successful, don't de-activate it
  896. so user has a change to go back and correct it without having to pop it
  897. up again.
  898. XmProcessTraversal(file_mgr_rec->file_window, XmTRAVERSE_CURRENT);
  899. XtSetArg (args[0], XmNallowShellResize, False);
  900. XtSetValues (file_mgr_rec->shell, args, 1);
  901. XtUnmanageChild(file_mgr_rec->current_directory_text);
  902. XtSetArg (args[0], XmNallowShellResize, True);
  903. XtSetValues (file_mgr_rec->shell, args, 1);
  904. file_mgr_data->fast_cd_enabled = False;
  905. */
  906. /* Process the string representing a directory to verify */
  907. /* that it is a valid path. */
  908. if (rc == 0)
  909. {
  910. if( TryToChangeDir(False, value, file_mgr_data, file_mgr_rec,
  911. change_dir_data, selection_box, NULL, NULL,
  912. GoToNewDir) )
  913. /* de-activate the text widget */
  914. UnpostTextPath( file_mgr_data );
  915. }
  916. XtFree(value);
  917. }
  918. /************************************************************************
  919. *
  920. * DropOnChangeView
  921. * This is the drop callback for the change-view icon provided
  922. * for quickly changing the current directory being viewed.
  923. *
  924. ************************************************************************/
  925. void
  926. DropOnChangeView (
  927. Widget w,
  928. XtPointer client_data,
  929. XtPointer call_data)
  930. {
  931. DtDndDropCallbackStruct *fileList = (DtDndDropCallbackStruct *)call_data;
  932. FileMgrRec *file_mgr_rec;
  933. DialogData * dialog_data;
  934. ChangeDirData * change_dir_data;
  935. ChangeDirRec * change_dir_rec;
  936. FileMgrData * file_mgr_data;
  937. Widget selection_box;
  938. char *full_path_name;
  939. int numFiles;
  940. numFiles = fileList->dropData->numItems;
  941. /* if multiple selection, ignore all but the last one */
  942. if (numFiles > 0 && fileList->reason == DtCR_DND_DROP_ANIMATE)
  943. {
  944. file_mgr_rec = (FileMgrRec *) client_data;
  945. dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
  946. file_mgr_data = (FileMgrData *) dialog_data->data;
  947. full_path_name = XtNewString(fileList->dropData->data.files[numFiles-1]);
  948. if (CheckRestrictedDir(file_mgr_rec, file_mgr_data,
  949. &full_path_name, False) == 0)
  950. {
  951. change_dir_data = (ChangeDirData *) file_mgr_data->change_dir->data;
  952. change_dir_rec =
  953. (ChangeDirRec *)_DtGetDialogInstance(file_mgr_data->change_dir);
  954. if (change_dir_rec)
  955. selection_box = change_dir_rec->change_dir;
  956. else
  957. selection_box = NULL;
  958. TryToChangeDir(False, full_path_name, file_mgr_data, file_mgr_rec,
  959. change_dir_data, selection_box, NULL, NULL,
  960. GoToNewDir);
  961. }
  962. XtFree(full_path_name);
  963. }
  964. fileList->status = DtDND_FAILURE;
  965. }
  966. static void
  967. GoToNewDir(
  968. FileMgrData * file_mgr_data,
  969. char * dir_name )
  970. {
  971. ChangeDirData * change_dir_data;
  972. int i;
  973. Boolean found;
  974. XmString xm_dir_name;
  975. /* Clear out any selected portion of the old CWD string */
  976. if (file_mgr_data->cd_select != NULL)
  977. {
  978. XtFree(file_mgr_data->cd_select);
  979. file_mgr_data->cd_select = NULL;
  980. }
  981. /* Update the internal copy of the dialog history list */
  982. if (file_mgr_data->change_dir)
  983. {
  984. change_dir_data = (ChangeDirData *) file_mgr_data->change_dir->data;
  985. xm_dir_name = XmStringCreateLocalized(dir_name);
  986. /* Add the directory only if not already in the list */
  987. for (i = 0, found = False; i < change_dir_data->list_count; i++)
  988. {
  989. if (XmStringCompare(xm_dir_name, change_dir_data->history_list[i]))
  990. {
  991. found = True;
  992. XmStringFree(xm_dir_name);
  993. break;
  994. }
  995. }
  996. if (!found)
  997. {
  998. change_dir_data->list_count++;
  999. change_dir_data->history_list = (XmStringTable)
  1000. XtRealloc((char *)change_dir_data->history_list,
  1001. sizeof(XmStringTable) * (change_dir_data->list_count + 1));
  1002. change_dir_data->history_list[change_dir_data->list_count - 1] =
  1003. xm_dir_name;
  1004. change_dir_data->history_list[change_dir_data->list_count] = NULL;
  1005. }
  1006. /* Update view to display the new directory */
  1007. ShowNewDirectory(file_mgr_data, change_dir_data->host_name, dir_name);
  1008. }
  1009. }
  1010. /*
  1011. * Class function for forcing the focus to the text field, each time
  1012. * the Change Dir dialog is posted.
  1013. */
  1014. static void
  1015. SetFocus(
  1016. ChangeDirRec *change_dir_rec,
  1017. ChangeDirData *change_dir_data )
  1018. {
  1019. Widget text;
  1020. /* Force the focus to the text field */
  1021. text = XmSelectionBoxGetChild (change_dir_rec->change_dir, XmDIALOG_TEXT);
  1022. XmProcessTraversal(text, XmTRAVERSE_CURRENT);
  1023. }
  1024. /***************************************************************************
  1025. *
  1026. * TextChange() - callback from editable text widgets when something is
  1027. * typed in the text widget. Only used when in restricted mode.
  1028. * Used to make sure the users are not going out of their
  1029. * "restricted" space.
  1030. *
  1031. ****************************************************************************/
  1032. void
  1033. TextChange(
  1034. Widget text,
  1035. XtPointer client_data,
  1036. XmTextVerifyCallbackStruct * callback_data )
  1037. {
  1038. char *homeDir, *homeDirBackup;
  1039. char *selection;
  1040. if (callback_data->reason == XmCR_MODIFYING_TEXT_VALUE ||
  1041. callback_data->reason == XmCR_MOVING_INSERT_CURSOR )
  1042. {
  1043. FileMgrData * file_mgr_data;
  1044. file_mgr_data = (FileMgrData *) client_data;
  1045. selection = XmTextFieldGetSelection(text);
  1046. /* get whats in the text widget */
  1047. homeDir = homeDirBackup = XmTextFieldGetString(text);
  1048. if(selection != NULL)
  1049. {
  1050. if(callback_data->event == NULL)
  1051. XmTextFieldClearSelection(text, CurrentTime);
  1052. else
  1053. XmTextFieldClearSelection(text, callback_data->event->xkey.time);
  1054. callback_data->doit = False;
  1055. }
  1056. else if(callback_data->reason == XmCR_MODIFYING_TEXT_VALUE)
  1057. {
  1058. /* see if the user is trying to back over the 'restricted'
  1059. * text, in this case users_home_dir
  1060. */
  1061. if( strcmp( homeDir, "" ) != 0
  1062. && strcmp( homeDir, file_mgr_data->restricted_directory ) <= 0 )
  1063. {
  1064. if( callback_data->text->length != 0 )
  1065. {
  1066. if( strncmp( file_mgr_data->restricted_directory,
  1067. callback_data->text->ptr,
  1068. strlen(file_mgr_data->restricted_directory)) != 0)
  1069. {
  1070. callback_data->doit = True;
  1071. }
  1072. }
  1073. else
  1074. {
  1075. callback_data->doit = False;
  1076. }
  1077. }
  1078. }
  1079. else
  1080. {
  1081. int maxlength;
  1082. maxlength = strlen( file_mgr_data->restricted_directory );
  1083. if(callback_data->newInsert < maxlength)
  1084. {
  1085. if(callback_data->event == NULL)
  1086. _XmTextFieldSetDestination((Widget)text,
  1087. (Position)callback_data->currInsert, CurrentTime);
  1088. else
  1089. {
  1090. _XmTextFieldSetDestination((Widget)text,
  1091. (Position)callback_data->currInsert,
  1092. callback_data->event->xkey.time);
  1093. callback_data->doit = False;
  1094. }
  1095. }
  1096. }
  1097. XtFree(homeDirBackup);
  1098. XtFree(selection);
  1099. }
  1100. }
  1101. void
  1102. ChangeDirectoryToParent(
  1103. FileMgrRec * file_mgr_rec,
  1104. char *directory)
  1105. {
  1106. DialogData * dialog_data;
  1107. ChangeDirData * change_dir_data;
  1108. ChangeDirRec * change_dir_rec;
  1109. FileMgrData * file_mgr_data;
  1110. Widget selection_box;
  1111. char * tmpStr;
  1112. int rc;
  1113. /* Get the change dir data record */
  1114. dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
  1115. file_mgr_data = (FileMgrData *) dialog_data->data;
  1116. change_dir_data = (ChangeDirData *) file_mgr_data->change_dir->data;
  1117. change_dir_rec =(ChangeDirRec *)_DtGetDialogInstance(file_mgr_data->change_dir);
  1118. if (change_dir_rec)
  1119. selection_box = change_dir_rec->change_dir;
  1120. else
  1121. selection_box = NULL;
  1122. /* check if user attempts to go outside restricted directory */
  1123. rc = CheckRestrictedDir (file_mgr_rec, file_mgr_data, &directory, True);
  1124. /* Process the string representing a directory to verify */
  1125. /* that it is a valid path. */
  1126. if (rc == 0)
  1127. {
  1128. TryToChangeDir(False, directory, file_mgr_data, file_mgr_rec,
  1129. change_dir_data, selection_box, NULL, NULL,
  1130. GoToNewDir);
  1131. }
  1132. }