dtpad.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  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. /* $TOG: dtpad.c /main/14 1999/09/15 15:15:02 mgreess $ */
  24. /**********************************<+>*************************************
  25. ***************************************************************************
  26. **
  27. ** File: dtpad.c
  28. **
  29. ** Project: DT dtpad, a memo maker type editor based on the Dt Editor
  30. ** widget.
  31. **
  32. ** Description:
  33. ** -----------
  34. **
  35. ** This file contains routines that create the dtpad menu bar widget
  36. ** and the Dt Editor widget.
  37. **
  38. *******************************************************************
  39. ** (c) Copyright Hewlett-Packard Company, 1990, 1991, 1992, 1993.
  40. ** All rights are
  41. ** reserved. Copying or other reproduction of this program
  42. ** except for archival purposes is prohibited without prior
  43. ** written consent of Hewlett-Packard Company.
  44. ********************************************************************
  45. **
  46. ********************************************************************
  47. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  48. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  49. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  50. ** (c) Copyright 1993, 1994 Novell, Inc.
  51. ********************************************************************
  52. **
  53. **
  54. **************************************************************************
  55. **********************************<+>*************************************/
  56. #include "dtpad.h"
  57. #include "signal.h"
  58. #include "X11/Xutil.h"
  59. #include <X11/StringDefs.h>
  60. #ifndef NO_MESSAGE_CATALOG
  61. # define TRUE 1
  62. # define FALSE 0
  63. # include <nl_types.h>
  64. #endif
  65. extern Editor *pPadList; /* declared in main.c */
  66. extern int numActivePads; /* declared in main.c */
  67. extern Widget topLevelWithWmCommand; /* declared in main.c */
  68. /************************************************************************
  69. * CreateDefaultImage - create a default image for the warning symbol.
  70. *
  71. ************************************************************************/
  72. void
  73. CreateDefaultImage(
  74. char *bits,
  75. int width,
  76. int height,
  77. char *name )
  78. {
  79. XImage *image; /* image for warning pixmap */
  80. image = (XImage *) XtMalloc (sizeof (XImage));
  81. image->width = width;
  82. image->height = height;
  83. image->data = bits;
  84. image->depth = 1;
  85. image->xoffset = 0;
  86. image->format = XYBitmap;
  87. image->byte_order = LSBFirst;
  88. image->bitmap_unit = 8;
  89. image->bitmap_bit_order = LSBFirst;
  90. image->bitmap_pad = 8;
  91. image->bytes_per_line = (width+7)/8;
  92. XmInstallImage (image, name);
  93. }
  94. /*
  95. * The following functions are multibyte-aware string handling routines,
  96. * including MbStrchr, MbStrrchr, and MbBasename. These routines are
  97. * used as substitutes for the single-byte-only strchr and strrchr routines.
  98. *
  99. *
  100. * [SuG 5/12/95] Added MbStrchri which does exactly MbStrchr, but also returns
  101. * index.
  102. */
  103. /************************************************************************
  104. * MbStrchr -
  105. ************************************************************************/
  106. char *
  107. MbStrchr(
  108. char *str,
  109. int ch)
  110. {
  111. size_t mbCurMax = MB_CUR_MAX;
  112. wchar_t targetChar, curChar;
  113. char tmpChar;
  114. int i, numBytes, byteLen;
  115. if(mbCurMax <= 1) return strchr(str, ch);
  116. tmpChar = (char)ch;
  117. mbtowc(&targetChar, &tmpChar, mbCurMax);
  118. for(i = 0, numBytes = 0, byteLen = strlen(str); i < byteLen; i += numBytes)
  119. {
  120. numBytes = mbtowc(&curChar, &str[i], mbCurMax);
  121. if(curChar == targetChar) return &str[i];
  122. }
  123. return (char *)NULL;
  124. }
  125. /************************************************************************
  126. * MbStrchri -
  127. ************************************************************************/
  128. char *
  129. MbStrchri(
  130. char *str,
  131. int ch, int* in)
  132. {
  133. size_t mbCurMax = MB_CUR_MAX;
  134. wchar_t targetChar, curChar;
  135. char tmpChar;
  136. int i, j, numBytes, byteLen;
  137. /*if(mbCurMax <= 1) return strchr(str, ch);*/
  138. tmpChar = (char)ch;
  139. mbtowc(&targetChar, &tmpChar, mbCurMax);
  140. for(i = 0, j = 0, numBytes = 0, byteLen = strlen(str); i < byteLen;
  141. i += numBytes, j++)
  142. {
  143. numBytes = mbtowc(&curChar, &str[i], mbCurMax);
  144. if(curChar == targetChar) {
  145. *in = j;
  146. return &str[i];
  147. }
  148. }
  149. *in = -1;
  150. return (char *)NULL;
  151. }
  152. /************************************************************************
  153. * MbStrrchr -
  154. ************************************************************************/
  155. char *
  156. MbStrrchr(
  157. char *str,
  158. int ch)
  159. {
  160. size_t mbCurMax = MB_CUR_MAX;
  161. wchar_t targetChar, curChar;
  162. char tmpChar, *lastChar;
  163. int i, numBytes, byteLen;
  164. if(mbCurMax <= 1) return strrchr(str, ch);
  165. tmpChar = (char)ch;
  166. mbtowc(&targetChar, &tmpChar, mbCurMax);
  167. for(i = 0, numBytes = 0, lastChar = (char *)NULL, byteLen = strlen(str);
  168. i < byteLen; i += numBytes)
  169. {
  170. numBytes = mbtowc(&curChar, &str[i], mbCurMax);
  171. if(curChar == targetChar) lastChar = &str[i];
  172. }
  173. return lastChar;
  174. }
  175. /************************************************************************
  176. * MbBasename -
  177. ************************************************************************/
  178. char *
  179. MbBasename(
  180. char *str)
  181. {
  182. char *lastSlash;
  183. lastSlash = MbStrrchr(str, '/');
  184. if(lastSlash != (char *)NULL)
  185. return lastSlash + 1;
  186. else
  187. return str;
  188. }
  189. /************************************************************************
  190. * ChangeMainWindowTitle - If necessary, put file name in window title
  191. ************************************************************************/
  192. void
  193. ChangeMainWindowTitle(
  194. Editor *pPad)
  195. {
  196. Arg al[5];
  197. char *name;
  198. char *title;
  199. Boolean freeName = False;
  200. XTextProperty textProp;
  201. /* Should happen only when creating a new view */
  202. if (!XtIsRealized(pPad->app_shell))
  203. return;
  204. if (pPad->ttEditReq.contract &&
  205. (pPad->ttEditReq.docName && *pPad->ttEditReq.docName)) {
  206. name = pPad->ttEditReq.docName;
  207. } else if (pPad->fileStuff.fileName && *pPad->fileStuff.fileName) {
  208. name = MbBasename(pPad->fileStuff.fileName);
  209. } else {
  210. name = strdup(UNNAMED_TITLE);
  211. freeName = True;
  212. }
  213. title = (char *)XtMalloc(strlen(DialogTitle(pPad)) + strlen(name) + 1);
  214. sprintf(title, "%s%s", DialogTitle(pPad), name);
  215. XmbTextListToTextProperty(pPad->display, &name, 1, XStdICCTextStyle,
  216. &textProp);
  217. XSetWMIconName(pPad->display, XtWindow(pPad->app_shell), &textProp);
  218. XFree(textProp.value);
  219. XtSetArg(al[0], XmNtitle, title);
  220. XtSetArg(al[1], XmNtitleEncoding, None);
  221. XtSetValues(pPad->app_shell, al, 2);
  222. if(freeName == True)
  223. free(name);
  224. XtFree(title);
  225. }
  226. /************************************************************************
  227. * SetSaveAsLabelAndDialog - set the File menu [Save As] button label and
  228. * mnemonic, and the SaveAs dialog title based on whether or not the
  229. * file name can change.
  230. ************************************************************************/
  231. void
  232. SetSaveAsLabelAndDialog(
  233. Editor *pPad)
  234. {
  235. char buf[256];
  236. Arg al[10];
  237. int ac, count = 0;
  238. char *mnemonic;
  239. XmString tmpStr;
  240. if (pPad->fileStuff.fileWidgets.saveAsBtn) {
  241. if (pPad->xrdb.nameChange) {
  242. mnemonic = strdup(((char *)GETMESSAGE(11, 25, "A")));
  243. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 26, "Save As...")));
  244. } else {
  245. mnemonic = strdup(((char *)GETMESSAGE(11, 109, "F")));
  246. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 110, "Copy To File...")));
  247. }
  248. ac = 0;
  249. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  250. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  251. XtSetValues(pPad->fileStuff.fileWidgets.saveAsBtn, al, ac);
  252. free(mnemonic);
  253. XmStringFree(tmpStr);
  254. }
  255. if (pPad->fileStuff.fileWidgets.saveAs.saveAs_form) {
  256. strcpy(buf, DialogTitle(pPad));
  257. if (pPad->xrdb.nameChange) {
  258. strcat(buf, (char *)GETMESSAGE(5, 7, "Save As"));
  259. } else {
  260. strcat(buf, (char *)GETMESSAGE(5, 43, "Copy To File"));
  261. }
  262. tmpStr = XmStringCreateLocalized(buf);
  263. XtSetArg(al[0], XmNdialogTitle, tmpStr);
  264. XtSetValues(pPad->fileStuff.fileWidgets.saveAs.saveAs_form, al, 1);
  265. XmStringFree(tmpStr);
  266. }
  267. }
  268. /************************************************************************
  269. * CreateHelpMenu - Create the Help pulldown menu
  270. *
  271. * Overview
  272. * ----------
  273. * Tasks
  274. * Table of Contents
  275. * Reference
  276. * On Item
  277. * ----------
  278. * Using Help
  279. * ----------
  280. * About Text Editor
  281. *
  282. ************************************************************************/
  283. static void
  284. CreateHelpMenu(
  285. Editor *pPad)
  286. {
  287. Widget help_pane, cascade, WidgList[12];
  288. Arg al[10];
  289. int ac, count = 0;
  290. char *mnemonic;
  291. XmString tmpStr;
  292. /* -----> create "Help" PulldownMenu */
  293. ac = 0;
  294. help_pane = XmCreatePulldownMenu (pPad->menu_bar, "helpMenu", al, ac);
  295. XtAddCallback(help_pane, XmNhelpCallback,
  296. (XtCallbackProc)HelpHelpCB, pPad);
  297. mnemonic = strdup(((char *)GETMESSAGE(11, 81, "H")));
  298. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 82, "Help")));
  299. ac = 0;
  300. XtSetArg (al[ac], XmNsubMenuId, help_pane); ac++;
  301. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  302. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  303. cascade = XmCreateCascadeButtonGadget(pPad->menu_bar, "Help", al, ac);
  304. XtAddCallback(cascade, XmNhelpCallback,(XtCallbackProc)HelpHelpCB, pPad);
  305. XtManageChild(cascade);
  306. free(mnemonic);
  307. XmStringFree(tmpStr);
  308. ac = 0;
  309. XtSetArg(al[ac], XmNmenuHelpWidget, cascade); ac++;
  310. XtSetValues (pPad->menu_bar, al, ac);
  311. /* -----> create "Overview" push button */
  312. mnemonic = strdup(((char *)GETMESSAGE(11, 83, "v")));
  313. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 84, "Overview")));
  314. ac = 0;
  315. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  316. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  317. WidgList[count++]= XmCreatePushButtonGadget(help_pane, "overview", al, ac );
  318. XtAddCallback (WidgList[count-1], XmNactivateCallback,
  319. (XtCallbackProc)HelpOverviewCB, (XtPointer) pPad);
  320. free(mnemonic);
  321. XmStringFree(tmpStr);
  322. /* -----> craete Separator */
  323. ac = 0;
  324. WidgList[count++] = XmCreateSeparatorGadget (help_pane, "sep1", al, ac);
  325. /* -----> create "Tasks" push button */
  326. mnemonic = strdup(((char *)GETMESSAGE(11, 85, "T")));
  327. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 86, "Tasks")));
  328. ac = 0;
  329. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  330. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  331. WidgList[count++]= XmCreatePushButtonGadget(help_pane, "tasks", al, ac );
  332. XtAddCallback (WidgList[count-1], XmNactivateCallback,
  333. (XtCallbackProc)HelpTasksCB, (XtPointer) pPad);
  334. free(mnemonic);
  335. XmStringFree(tmpStr);
  336. /* -----> create "Table of Contents" push button */
  337. mnemonic = strdup(((char *)GETMESSAGE(11, 87, "C")));
  338. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 88, "Table of Contents")));
  339. ac = 0;
  340. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  341. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  342. WidgList[count++]= XmCreatePushButtonGadget(help_pane, "TOC", al, ac );
  343. XtAddCallback (WidgList[count-1], XmNactivateCallback,
  344. (XtCallbackProc)HelpTOCCB, (XtPointer) pPad);
  345. free(mnemonic);
  346. XmStringFree(tmpStr);
  347. /* -----> create "Reference" push button */
  348. mnemonic = strdup(((char *)GETMESSAGE(11, 89, "R")));
  349. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 90, "Reference")));
  350. ac = 0;
  351. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  352. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  353. WidgList[count++]= XmCreatePushButtonGadget(help_pane, "reference", al, ac );
  354. XtAddCallback (WidgList[count-1], XmNactivateCallback,
  355. (XtCallbackProc)HelpReferenceCB, (XtPointer) pPad);
  356. free(mnemonic);
  357. XmStringFree(tmpStr);
  358. /* -----> create "On Item" push button */
  359. mnemonic = strdup(((char *)GETMESSAGE(11, 91, "O")));
  360. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 92, "On Item")));
  361. ac = 0;
  362. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  363. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  364. WidgList[count++]= XmCreatePushButtonGadget(help_pane, "onItem", al, ac );
  365. XtAddCallback (WidgList[count-1], XmNactivateCallback,
  366. (XtCallbackProc)HelpOnItemCB, (XtPointer) pPad);
  367. free(mnemonic);
  368. XmStringFree(tmpStr);
  369. /* -----> create Separator*/
  370. ac = 0;
  371. WidgList[count++] = XmCreateSeparatorGadget (help_pane, "sep2", al, ac);
  372. /* -----> create "Using Help" push button */
  373. mnemonic = strdup(((char *)GETMESSAGE(11, 93, "U")));
  374. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 94, "Using Help")));
  375. ac = 0;
  376. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  377. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  378. WidgList[count++]= XmCreatePushButtonGadget(help_pane, "usingHelp", al, ac );
  379. XtAddCallback (WidgList[count-1], XmNactivateCallback,
  380. (XtCallbackProc)HelpUsingHelpCB, (XtPointer) pPad);
  381. free(mnemonic);
  382. XmStringFree(tmpStr);
  383. /* -----> create Separator */
  384. ac = 0;
  385. WidgList[count++] = XmCreateSeparatorGadget (help_pane, "sep3", al, ac);
  386. /* -----> create "About Text Editor" push button */
  387. mnemonic = strdup(((char *)GETMESSAGE(11, 95, "A")));
  388. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 96, "About Text Editor")));
  389. ac = 0;
  390. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  391. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  392. WidgList[count++]= XmCreatePushButtonGadget(help_pane, "about", al, ac );
  393. XtAddCallback (WidgList[count-1], XmNactivateCallback,
  394. (XtCallbackProc)HelpAboutCB, (XtPointer) pPad);
  395. free(mnemonic);
  396. XmStringFree(tmpStr);
  397. XtManageChildren(WidgList, count);
  398. }
  399. /************************************************************************
  400. * CreateFileMenu - Create the "File" pulldown menu
  401. *
  402. * New
  403. * Open...
  404. * Include...
  405. * ----------
  406. * Save or [Save (needed)]
  407. * Save As...
  408. * Print...
  409. * ----------
  410. * Close
  411. *
  412. ************************************************************************/
  413. static void
  414. CreateFileMenu(
  415. Editor *pPad)
  416. {
  417. Widget file_pane, cascade, WidgList[12];
  418. Arg al[10];
  419. int ac, count = 0;
  420. char *mnemonic;
  421. XmString tmpStr;
  422. FileWidgets *pWidg = &pPad->fileStuff.fileWidgets;
  423. /* -----> create "File" PulldownMenu */
  424. ac = 0;
  425. file_pane = XmCreatePulldownMenu (pPad->menu_bar, "fileMenu", al, ac);
  426. XtAddCallback(file_pane, XmNhelpCallback,
  427. (XtCallbackProc)HelpFileCB, pPad);
  428. mnemonic = strdup(((char *)GETMESSAGE(11, 15, "F")));
  429. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 16, "File")));
  430. ac = 0;
  431. XtSetArg (al[ac], XmNsubMenuId, file_pane); ac++;
  432. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  433. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  434. cascade = XmCreateCascadeButtonGadget (pPad->menu_bar, "File", al, ac);
  435. XtAddCallback (cascade, XmNcascadingCallback,
  436. (XtCallbackProc)FileCascadingCB, (XtPointer) pPad);
  437. XtAddCallback(cascade, XmNhelpCallback, (XtCallbackProc)HelpFileCB, pPad);
  438. XtManageChild (cascade);
  439. free(mnemonic);
  440. XmStringFree(tmpStr);
  441. /* -----> create "New" push button */
  442. mnemonic = strdup(((char *)GETMESSAGE(11, 17, "N")));
  443. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 18, "New")));
  444. ac = 0;
  445. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  446. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  447. WidgList[count++] = XmCreatePushButtonGadget (file_pane, "new", al, ac);
  448. pWidg->newBtn = WidgList[count-1];
  449. XtAddCallback (WidgList[count-1], XmNactivateCallback,
  450. (XtCallbackProc)FileNewCB, (XtPointer) pPad);
  451. free(mnemonic);
  452. XmStringFree(tmpStr);
  453. /* -----> create "Open..." push button */
  454. mnemonic = strdup(((char *)GETMESSAGE(11, 19, "O")));
  455. tmpStr=XmStringCreateLocalized(((char *)GETMESSAGE(11, 20, "Open...")));
  456. ac = 0;
  457. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  458. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  459. WidgList[count++] = XmCreatePushButtonGadget (file_pane, "open", al, ac);
  460. pWidg->openBtn = WidgList[count - 1];
  461. XtAddCallback (WidgList[count-1], XmNactivateCallback,
  462. (XtCallbackProc) FileOpenCB, (XtPointer) pPad);
  463. free(mnemonic);
  464. XmStringFree(tmpStr);
  465. /* -----> create "Include..." push button */
  466. mnemonic = strdup(((char *)GETMESSAGE(11, 21, "I")));
  467. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 22, "Include...")));
  468. ac = 0;
  469. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  470. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  471. WidgList[count++] = XmCreatePushButtonGadget (file_pane, "include", al, ac);
  472. pWidg->includeBtn = WidgList[count - 1];
  473. XtAddCallback (WidgList[count-1], XmNactivateCallback,
  474. (XtCallbackProc) FileIncludeCB, (XtPointer) pPad);
  475. free(mnemonic);
  476. XmStringFree(tmpStr);
  477. /* -----> create save/print separator */
  478. ac = 0;
  479. WidgList[count++] = XmCreateSeparatorGadget (file_pane, "SvSp", al, ac);
  480. /* -----> create "Save" push button */
  481. mnemonic = strdup(((char *)GETMESSAGE(11, 23, "S")));
  482. /* Note: The "Save" label is set in FileCascadingCB() when the File menu
  483. * is displayed based on whether or not there are unsaved changes */
  484. pPad->fileStuff.saveBtnLabel =
  485. XmStringCreateLocalized(((char *)GETMESSAGE(11, 24, "Save")));
  486. pPad->fileStuff.saveNeededBtnLabel =
  487. XmStringCreateLocalized(((char *)GETMESSAGE(11, 73, "Save (needed)")));
  488. ac = 0;
  489. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  490. WidgList[count++] = XmCreatePushButtonGadget (file_pane, "save", al, ac);
  491. pWidg->saveBtn = WidgList[count - 1];
  492. XtAddCallback (WidgList[count-1], XmNactivateCallback,
  493. (XtCallbackProc) FileSaveCB, (XtPointer) pPad);
  494. free(mnemonic);
  495. /* -----> create "Save As..." push button
  496. * (its label/mnemonic are set later in SetSaveAsLabelAndDialog()
  497. * based on xrdb.nameChange) */
  498. ac = 0;
  499. WidgList[count++] = XmCreatePushButtonGadget (file_pane, "saveAs", al, ac);
  500. pWidg->saveAsBtn = WidgList[count - 1];
  501. XtAddCallback (WidgList[count-1], XmNactivateCallback,
  502. (XtCallbackProc) FileSaveAsCB, (XtPointer) pPad);
  503. /* -----> create "Print..." push button */
  504. mnemonic = strdup(((char *)GETMESSAGE(11, 27, "P")));
  505. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 28, "Print...")));
  506. ac = 0;
  507. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  508. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  509. WidgList[count++] = XmCreatePushButtonGadget (file_pane, "print", al, ac);
  510. pWidg->printBtn = WidgList[count - 1];
  511. XtAddCallback (WidgList[count-1], XmNactivateCallback,
  512. (XtCallbackProc) FileXpPrintCB, (XtPointer) pPad);
  513. free(mnemonic);
  514. XmStringFree(tmpStr);
  515. /* -----> create close/exit separator */
  516. ac = 0;
  517. WidgList[count++] = XmCreateSeparatorGadget (file_pane, "ExSp", al, ac);
  518. /* -----> create "Close" (Exit) push button */
  519. mnemonic = strdup(((char *)GETMESSAGE(11, 29, "C")));
  520. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 30, "Close")));
  521. ac = 0;
  522. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  523. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  524. WidgList[count++] = XmCreatePushButtonGadget (file_pane, "close", al, ac);
  525. pPad->ExitWid = WidgList[count-1];
  526. pWidg->exitBtn = WidgList[count - 1];
  527. XtAddCallback (WidgList[count-1], XmNactivateCallback,
  528. (XtCallbackProc) FileExitCB, (XtPointer) pPad);
  529. free(mnemonic);
  530. XmStringFree(tmpStr);
  531. /* -----> manage the all "File" menu buttons */
  532. XtManageChildren(WidgList, count);
  533. }
  534. /************************************************************************
  535. * CreateEditMenu - Create the "Edit" pulldown menu
  536. *
  537. * Undo
  538. * ----------
  539. * Cut
  540. * Copy
  541. * Paste
  542. * Clear
  543. * Delete
  544. * Select All
  545. * ----------
  546. * Find/Change...
  547. * Check Spellilng...
  548. *
  549. ************************************************************************/
  550. static void
  551. CreateEditMenu(
  552. Editor *pPad)
  553. {
  554. Widget edit_pane, cascade, WidgList[12];
  555. Arg al[10];
  556. int ac, count = 0;
  557. char *mnemonic;
  558. XmString tmpStr;
  559. EditWidgets *pWidg = &pPad->editStuff.widgets;
  560. /* -----> create "Edit" PulldownMenu */
  561. ac = 0;
  562. edit_pane = XmCreatePulldownMenu (pPad->menu_bar, "editMenu", al, ac);
  563. XtAddCallback(edit_pane, XmNhelpCallback,
  564. (XtCallbackProc)HelpEditCB, pPad);
  565. mnemonic = strdup(((char *)GETMESSAGE(11, 31, "E")));
  566. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 32, "Edit")));
  567. ac = 0;
  568. XtSetArg(al[ac], XmNsubMenuId, edit_pane); ac++;
  569. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  570. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  571. cascade= XmCreateCascadeButtonGadget(pPad->menu_bar, "Edit", al, ac);
  572. XtAddCallback(cascade, XmNhelpCallback,(XtCallbackProc)HelpEditCB, pPad);
  573. XtManageChild(cascade);
  574. free(mnemonic);
  575. XmStringFree(tmpStr);
  576. /* -----> create "Undo" push button */
  577. mnemonic = strdup(((char *)GETMESSAGE(11, 33, "U")));
  578. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 34, "Undo")));
  579. ac = 0;
  580. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  581. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  582. WidgList[count++] = XmCreatePushButtonGadget(edit_pane, "undo", al, ac);
  583. pWidg->undoBtn = WidgList[count - 1];
  584. XtAddCallback(WidgList[count-1], XmNactivateCallback,
  585. (XtCallbackProc) EditUndoCB, (XtPointer) pPad);
  586. free(mnemonic);
  587. XmStringFree(tmpStr);
  588. /* -----> create undo separator */
  589. ac = 0;
  590. WidgList[count++] = XmCreateSeparatorGadget(edit_pane, "CtSp", al, ac);
  591. /* -----> create "Cut" push button */
  592. mnemonic = strdup(((char *)GETMESSAGE(11, 35, "t")));
  593. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 36, "Cut")));
  594. ac = 0;
  595. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  596. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  597. WidgList[count++] = XmCreatePushButtonGadget(edit_pane, "cut", al, ac);
  598. pWidg->cutBtn = WidgList[count - 1];
  599. XtAddCallback(WidgList[count-1], XmNactivateCallback,
  600. (XtCallbackProc) EditCutCB, (XtPointer) pPad);
  601. free(mnemonic);
  602. XmStringFree(tmpStr);
  603. /* -----> create "Copy" push button */
  604. mnemonic = strdup(((char *)GETMESSAGE(11, 37, "C")));
  605. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 38, "Copy")));
  606. ac = 0;
  607. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  608. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  609. WidgList[count++] = XmCreatePushButtonGadget(edit_pane, "copy", al, ac);
  610. pWidg->copyBtn = WidgList[count - 1];
  611. XtAddCallback(WidgList[count-1], XmNactivateCallback,
  612. (XtCallbackProc) EditCopyCB, (XtPointer) pPad);
  613. free(mnemonic);
  614. XmStringFree(tmpStr);
  615. /* -----> create "Paste" push button */
  616. mnemonic = strdup(((char *)GETMESSAGE(11, 39, "P")));
  617. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 40, "Paste")));
  618. ac = 0;
  619. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  620. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  621. WidgList[count++] = XmCreatePushButtonGadget(edit_pane, "paste", al, ac);
  622. pWidg->pasteBtn = WidgList[count - 1];
  623. XtAddCallback(WidgList[count-1], XmNactivateCallback,
  624. (XtCallbackProc) EditPasteCB, (XtPointer) pPad);
  625. free(mnemonic);
  626. XmStringFree(tmpStr);
  627. /* -----> create "Clear" push button */
  628. mnemonic = strdup(((char *)GETMESSAGE(11, 41, "e")));
  629. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 42, "Clear")));
  630. ac = 0;
  631. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  632. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  633. WidgList[count++] = XmCreatePushButtonGadget(edit_pane, "clear", al, ac);
  634. pWidg->clearBtn = WidgList[count - 1];
  635. XtAddCallback(WidgList[count-1], XmNactivateCallback,
  636. (XtCallbackProc) EditClearCB, (XtPointer) pPad);
  637. free(mnemonic);
  638. XmStringFree(tmpStr);
  639. /* -----> create "Delete" push button */
  640. mnemonic = strdup(((char *)GETMESSAGE(11, 43, "D")));
  641. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 44,"Delete")));
  642. ac = 0;
  643. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  644. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  645. WidgList[count++] = XmCreatePushButtonGadget (edit_pane, "delete", al, ac);
  646. pWidg->deleteBtn = WidgList[count - 1];
  647. XtAddCallback(WidgList[count-1], XmNactivateCallback,
  648. (XtCallbackProc) EditDeleteCB, (XtPointer) pPad);
  649. free(mnemonic);
  650. XmStringFree(tmpStr);
  651. /* -----> XXX - create "Select All" push button */
  652. mnemonic = strdup(((char *)GETMESSAGE(11, 101, "S")));
  653. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 102, "Select All")));
  654. ac = 0;
  655. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  656. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  657. WidgList[count++] = XmCreatePushButtonGadget(edit_pane, "selectAll", al, ac);
  658. pWidg->selectAllBtn = WidgList[count - 1];
  659. XtAddCallback(WidgList[count-1], XmNactivateCallback,
  660. (XtCallbackProc) SelectAllCB, (XtPointer) pPad);
  661. free(mnemonic);
  662. XmStringFree(tmpStr);
  663. /* -----> create find/change separator */
  664. ac = 0;
  665. WidgList[count++] = XmCreateSeparatorGadget (edit_pane, "FSSp", al, ac);
  666. /* -----> create "Find/Change" push button */
  667. mnemonic = strdup(((char *)GETMESSAGE(11, 103, "F")));
  668. tmpStr =XmStringCreateLocalized(((char *)GETMESSAGE(11, 104,"Find/Change...")));
  669. ac = 0;
  670. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  671. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  672. WidgList[count++] =
  673. XmCreatePushButtonGadget(edit_pane, "findChange", al, ac);
  674. pWidg->findChangeBtn = WidgList[count - 1];
  675. XtAddCallback(WidgList[count-1], XmNactivateCallback,
  676. (XtCallbackProc) FindChangeCB, (XtPointer) pPad);
  677. free(mnemonic);
  678. XmStringFree(tmpStr);
  679. /* -----> create "Check Spelling" push button */
  680. mnemonic = strdup(((char *)GETMESSAGE(11, 105, "k")));
  681. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 106, "Check Spelling...")));
  682. ac = 0;
  683. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  684. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  685. WidgList[count++] = XmCreatePushButtonGadget(edit_pane, "checkSpelling",
  686. al, ac);
  687. pWidg->checkSpellingBtn = WidgList[count - 1];
  688. XtAddCallback(WidgList[count-1], XmNactivateCallback,
  689. (XtCallbackProc) CheckSpellingCB, (XtPointer) pPad);
  690. free(mnemonic);
  691. XmStringFree(tmpStr);
  692. /* -----> manage all the "Edit" menu buttons */
  693. XtManageChildren(WidgList, count);
  694. }
  695. /************************************************************************
  696. * CreateFormatMenu - Create the "Format" pulldown menu
  697. *
  698. * Settings...
  699. * Paragraph
  700. * All
  701. *
  702. ************************************************************************/
  703. static void
  704. CreateFormatMenu(
  705. Editor *pPad)
  706. {
  707. Widget format_pane, cascade, WidgList[12];
  708. Arg al[10];
  709. int ac, count = 0;
  710. char *mnemonic;
  711. XmString tmpStr;
  712. /* -----> create "Format" PulldownMenu */
  713. ac = 0;
  714. format_pane = XmCreatePulldownMenu (pPad->menu_bar, "formatMenu", al, ac);
  715. XtAddCallback(format_pane, XmNhelpCallback,
  716. (XtCallbackProc)HelpFormatCB, pPad);
  717. mnemonic = strdup(((char *)GETMESSAGE(11, 51, "r")));
  718. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 52, "Format")));
  719. ac = 0;
  720. XtSetArg (al[ac], XmNsubMenuId, format_pane); ac++;
  721. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  722. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  723. cascade= XmCreateCascadeButtonGadget (pPad->menu_bar, "format", al, ac);
  724. XtAddCallback(cascade, XmNhelpCallback,(XtCallbackProc)HelpFormatCB, pPad);
  725. pPad->formatStuff.widgets.formatBtn = cascade;
  726. XtManageChild (cascade);
  727. free(mnemonic);
  728. XmStringFree(tmpStr);
  729. /* -----> create "Settings..." button */
  730. mnemonic = strdup(((char *)GETMESSAGE(11, 53, "S")));
  731. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 54, "Settings...")));
  732. ac = 0;
  733. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  734. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  735. WidgList[count++] =
  736. XmCreatePushButtonGadget (format_pane, "settings", al, ac);
  737. XtAddCallback (WidgList[count-1], XmNactivateCallback,
  738. (XtCallbackProc) FormatCB, (XtPointer) pPad);
  739. free(mnemonic);
  740. XmStringFree(tmpStr);
  741. /* -----> create "Paragraph" button */
  742. mnemonic = strdup(((char *)GETMESSAGE(11, 55, "P")));
  743. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 56, "Paragraph")));
  744. ac = 0;
  745. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  746. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  747. WidgList[count++] =
  748. XmCreatePushButtonGadget (format_pane, "paragraph", al, ac);
  749. XtAddCallback (WidgList[count-1], XmNactivateCallback,
  750. (XtCallbackProc) FormatParaCB, (XtPointer) pPad);
  751. free(mnemonic);
  752. XmStringFree(tmpStr);
  753. /* -----> create "All" button */
  754. mnemonic = strdup(((char *)GETMESSAGE(11, 57, "l")));
  755. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 58, "All")));
  756. ac = 0;
  757. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  758. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  759. WidgList[count++] = XmCreatePushButtonGadget (format_pane, "all", al, ac);
  760. XtAddCallback (WidgList[count-1], XmNactivateCallback,
  761. (XtCallbackProc) FormatAllCB, (XtPointer) pPad);
  762. free(mnemonic);
  763. XmStringFree(tmpStr);
  764. /* -----> manage the all "Format" menu buttons */
  765. XtManageChildren(WidgList, count);
  766. }
  767. /************************************************************************
  768. * CreateOptionsMenu - Create the "Options" pulldown menu
  769. *
  770. * Overstrike
  771. * Wrap To Fit
  772. * Status Line
  773. *
  774. ************************************************************************/
  775. static void
  776. CreateOptionsMenu(
  777. Editor *pPad)
  778. {
  779. Widget options_pane, cascade, WidgList[12];
  780. Arg al[10];
  781. int ac, count = 0;
  782. char *mnemonic;
  783. XmString tmpStr;
  784. OptionsMenuWidgets *pWidg = &pPad->optionsStuff.widgets;
  785. /* -----> create "Options" PulldownMenu */
  786. ac = 0;
  787. options_pane = XmCreatePulldownMenu (pPad->menu_bar, "optionsMenu", al, ac);
  788. XtAddCallback(options_pane, XmNhelpCallback,
  789. (XtCallbackProc)HelpOptionsCB, pPad);
  790. mnemonic = strdup(((char *)GETMESSAGE(11, 59, "O")));
  791. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 60, "Options")));
  792. ac = 0;
  793. XtSetArg(al[ac], XmNsubMenuId, options_pane); ac++;
  794. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  795. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  796. cascade= XmCreateCascadeButtonGadget (pPad->menu_bar, "options", al, ac);
  797. XtAddCallback(cascade, XmNhelpCallback,(XtCallbackProc)HelpOptionsCB, pPad);
  798. pPad->optionsStuff.widgets.optionsBtn = cascade;
  799. XtManageChild (cascade);
  800. free(mnemonic);
  801. XmStringFree(tmpStr);
  802. /* -----> create "Overstrike" toggle button */
  803. mnemonic = strdup(((char *)GETMESSAGE(11, 61, "O")));
  804. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 62, "Overstrike")));
  805. ac = 0;
  806. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  807. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  808. XtSetArg(al[ac], XmNvisibleWhenOff, True); ac++;
  809. XtSetArg(al[ac], XmNset, pPad->xrdb.overstrike); ac++;
  810. WidgList[count++] = XmCreateToggleButton (options_pane, "overstrike", al, ac);
  811. pWidg->overstrikeBtn = WidgList[count - 1];
  812. XtAddCallback (WidgList[count-1], XmNvalueChangedCallback,
  813. (XtCallbackProc) OverstrikeCB, (XtPointer) pPad);
  814. free(mnemonic);
  815. XmStringFree(tmpStr);
  816. /* -----> create "Wrap To Fit" toggle button */
  817. mnemonic = strdup(((char *)GETMESSAGE(11, 111, "W")));
  818. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 112, "Wrap To Fit")));
  819. ac = 0;
  820. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  821. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  822. XtSetArg(al[ac], XmNvisibleWhenOff, True); ac++;
  823. XtSetArg(al[ac], XmNset, pPad->xrdb.wordWrap); ac++;
  824. WidgList[count++] = XmCreateToggleButton (options_pane, "wordWrap", al, ac);
  825. pWidg->wordWrapBtn = WidgList[count - 1];
  826. XtAddCallback (WidgList[count-1], XmNvalueChangedCallback,
  827. (XtCallbackProc) WordWrapCB, (XtPointer) pPad);
  828. free(mnemonic);
  829. XmStringFree(tmpStr);
  830. /* -----> create "Status Line" toggle button */
  831. mnemonic = strdup(((char *)GETMESSAGE(11, 65, "S")));
  832. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 66, "Status Line")));
  833. ac = 0;
  834. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  835. XtSetArg(al[ac], XmNmnemonic, mnemonic[0]); ac++;
  836. XtSetArg(al[ac], XmNvisibleWhenOff, True); ac++;
  837. XtSetArg(al[ac], XmNset, pPad->xrdb.statusLine); ac++;
  838. WidgList[count++] = XmCreateToggleButton (options_pane, "statusLine", al, ac);
  839. pWidg->statusLineBtn = WidgList[count - 1];
  840. XtAddCallback (WidgList[count-1], XmNvalueChangedCallback,
  841. (XtCallbackProc) StatusLineCB, (XtPointer) pPad);
  842. free(mnemonic);
  843. XmStringFree(tmpStr);
  844. XtManageChildren(WidgList, count);
  845. }
  846. /************************************************************************
  847. * CreateMenuBar - Create MenuBar in MainWindow
  848. *
  849. ************************************************************************/
  850. void
  851. CreateMenuBar( Editor *pPad )
  852. {
  853. pPad->menu_bar = XmCreateMenuBar (pPad->mainWindow, "bar", NULL, 0);
  854. XtAddCallback(pPad->menu_bar, XmNhelpCallback,
  855. (XtCallbackProc)HelpMenubarCB, pPad);
  856. CreateFileMenu(pPad);
  857. CreateEditMenu(pPad);
  858. CreateFormatMenu(pPad);
  859. CreateOptionsMenu(pPad);
  860. CreateHelpMenu(pPad);
  861. }
  862. /************************************************************************
  863. * CreateEditorWidget - creates the Dt Editor widget
  864. ************************************************************************/
  865. void
  866. CreateEditorWidget(
  867. Editor *pPad)
  868. {
  869. Widget parent = pPad->mainWindow;
  870. Arg al[10]; /* arg list */
  871. int ac; /* arg count */
  872. Pixel background, foreground, top_shadow, bottom_shadow, selectColor;
  873. Colormap colormap;
  874. XmString dialogTitleStr = XmStringCreateLocalized(DialogTitle(pPad));
  875. /* create the DtEditor widget */
  876. ac = 0;
  877. XtSetArg(al[ac], DtNrows, DEFAULT_ROWS); ac++;
  878. XtSetArg(al[ac], DtNcolumns, DEFAULT_COLS); ac++;
  879. XtSetArg(al[ac], DtNdialogTitle, dialogTitleStr); ac++;
  880. pPad->editor = DtCreateEditor(parent, "editor", al, ac);
  881. XmStringFree(dialogTitleStr);
  882. /* add the DtEditor callbacks */
  883. XtAddCallback(pPad->editor, XmNhelpCallback,
  884. (XtCallbackProc) HelpEditorWidgetCB,
  885. (XtPointer) pPad);
  886. XtAddCallback(pPad->editor, DtNtextSelectCallback,
  887. (XtCallbackProc) TextSelectedCB,
  888. (XtPointer) pPad);
  889. XtAddCallback(pPad->editor, DtNtextDeselectCallback,
  890. (XtCallbackProc) TextDeselectedCB,
  891. (XtPointer) pPad);
  892. /* get id of status line text field widget */
  893. pPad->statusLineMsg = DtEditorGetMessageTextFieldID(pPad->editor);
  894. }
  895. /************************************************************************
  896. * FindOrCreatePad - finds an unused entry in the list of Editors or,
  897. * if none can be found, creates a new entry with some defaults
  898. * obtain from the last entry that was created.
  899. *
  900. * Returns True if an existing, unused entry is "reused" or False
  901. * if a new entry is created. Also updates the current entry
  902. * (whose address is passed as a parameter) to point to the
  903. * found/created entry.
  904. *
  905. * Note: The first entry in the list of Editors is created by
  906. * CreatedFirstPad(). This routine is used to create
  907. * all subsequent entries.
  908. *
  909. ************************************************************************/
  910. Boolean
  911. FindOrCreatePad(
  912. Editor **ppPad)
  913. {
  914. Boolean foundPad = False;
  915. Editor *pPad;
  916. Arg al[10];
  917. int ac;
  918. /* -----> Reuse unused entries (corresponding to closed editor windows)
  919. * before creating new ones. */
  920. for (pPad = pPadList; pPad != (Editor *)NULL; pPad = pPad->pNextPad){
  921. if (pPad->inUse == False) {
  922. pPad->inUse = True;
  923. foundPad = True;
  924. numActivePads++;
  925. break;
  926. }
  927. }
  928. /* -----> Create a new entry if an unused one can not be found. */
  929. if (foundPad == False) {
  930. int argc_l, i;
  931. char **argv_l, **c_argv_l;
  932. char *pProgName;
  933. Display *display;
  934. unsigned short group_id,
  935. user_id;
  936. /* -----> Save some defaults from the last entry that was created. */
  937. Boolean exitOnLastClose = pPadList->xrdb.exitOnLastClose;
  938. pProgName = pPadList->progname;
  939. group_id = pPadList->group_id;
  940. user_id = pPadList->user_id;
  941. display = pPadList->display;
  942. /* -----> Create a new entry and point pPad and the global, pPadList
  943. * to it. */
  944. CreatePad(&pPad);
  945. pPad->inUse = True;
  946. /* -----> Set some defaults from the last entry that was created. */
  947. pPad->display = display;
  948. pPad->progname = pProgName;
  949. pPad->group_id = group_id;
  950. pPad->user_id = user_id;
  951. pPad->xrdb.exitOnLastClose = exitOnLastClose;
  952. /* -----> Create the application shell for the new Editor entry. */
  953. ac = 0;
  954. XtSetArg(al[ac], XmNargv, &argv_l); ac++;
  955. XtSetArg(al[ac], XmNargc, &argc_l); ac++;
  956. XtGetValues(topLevelWithWmCommand, al, ac);
  957. c_argv_l = (char **) XtMalloc(argc_l * sizeof(char*));
  958. for (i=0; i<argc_l; i++)
  959. c_argv_l[i] = strdup(argv_l[i]);
  960. ac = 0;
  961. XtSetArg(al[ac], XmNargv, argv_l); ac++;
  962. XtSetArg(al[ac], XmNargc, argc_l); ac++;
  963. pPad->app_shell = XtAppCreateShell(pPad->progname, DTPAD_CLASS_NAME,
  964. applicationShellWidgetClass,
  965. pPad->display, al, ac);
  966. pPad->app_context = XtWidgetToApplicationContext(pPad->app_shell);
  967. /* -----> Set all resources to initial server values */
  968. RestoreInitialServerResources(pPad);
  969. }
  970. /* -----> update the pointer to the current entry and return whether or
  971. * not an existing entry was reused */
  972. *ppPad = pPad;
  973. return foundPad;
  974. }
  975. /************************************************************************
  976. * SetWorkSpaceHints -
  977. *
  978. ************************************************************************/
  979. void
  980. SetWorkSpaceHints(
  981. Widget shell,
  982. char *workspaces )
  983. {
  984. char * ptr;
  985. Atom * workspace_atoms = NULL;
  986. int num_workspaces=0;
  987. if (workspaces)
  988. {
  989. do
  990. {
  991. ptr = MbStrchr (workspaces, ' ');
  992. if (ptr != NULL) *ptr = 0;
  993. workspace_atoms = (Atom *) XtRealloc ((char *)workspace_atoms,
  994. sizeof (Atom) * (num_workspaces + 1));
  995. workspace_atoms[num_workspaces] =
  996. XmInternAtom (XtDisplay(shell), workspaces, True);
  997. num_workspaces++;
  998. if (ptr != NULL)
  999. {
  1000. *ptr = ' ';
  1001. workspaces = ptr + 1;
  1002. }
  1003. } while (ptr != NULL);
  1004. DtWsmSetWorkspacesOccupied(XtDisplay(shell), XtWindow (shell),
  1005. workspace_atoms, num_workspaces);
  1006. XtFree ((char *) workspace_atoms);
  1007. workspace_atoms = NULL;
  1008. }
  1009. else
  1010. {
  1011. Window rootWindow;
  1012. Atom pCurrent;
  1013. Screen *currentScreen;
  1014. int screen;
  1015. char *workspace_name;
  1016. screen = XDefaultScreen(XtDisplay(shell));
  1017. currentScreen = XScreenOfDisplay(XtDisplay(shell), screen);
  1018. rootWindow = RootWindowOfScreen(currentScreen);
  1019. if(DtWsmGetCurrentWorkspace(XtDisplay(shell), rootWindow,
  1020. &pCurrent) == Success)
  1021. {
  1022. DtWsmSetWorkspacesOccupied(XtDisplay(shell), XtWindow (shell),
  1023. &pCurrent, 1);
  1024. }
  1025. }
  1026. }
  1027. /************************************************************************
  1028. * ClearStatusMessage - clears the message (XmTextField) portion of the
  1029. * DtEditor widget's status line.
  1030. ************************************************************************/
  1031. /* ARGSUSED */
  1032. void
  1033. ClearStatusMessage(
  1034. Editor *pPad)
  1035. {
  1036. XmTextFieldSetString(pPad->statusLineMsg, "");
  1037. }
  1038. /************************************************************************
  1039. * SetStatusMessage - sets the message (XmTextField) portion of the
  1040. * DtEditor widget's status line to the specified string.
  1041. ************************************************************************/
  1042. /* ARGSUSED */
  1043. void
  1044. SetStatusMessage(
  1045. Editor *pPad,
  1046. char *str)
  1047. {
  1048. XmTextFieldSetString(pPad->statusLineMsg, str);
  1049. }
  1050. #ifdef POPUP
  1051. /*
  1052. * CreatePopupMenu - Create popup menu in editor window
  1053. */
  1054. void
  1055. CreatePopupMenu( Editor *pPad )
  1056. {
  1057. Arg al[5];
  1058. int ac;
  1059. Widget popupCascade, popupBtns[10];
  1060. Widget fileMenu, editMenu, optionMenu, helpMenu;
  1061. XmString tmpStr;
  1062. char *mnemonic;
  1063. int i = 0;
  1064. pPad->popup = XmCreatePopupMenu(pPad->editor, "popupMenu", NULL, 0);
  1065. XtAddEventHandler(parent, ButtonPressMask, False, PopupHandler,
  1066. (XtPointer)popupMenu);
  1067. /* Create text editor title */
  1068. popupBtns[i] =
  1069. (Widget)XmCreateLabelGadget(pPad->popup, "popupTitle", NULL, 0);
  1070. /* Create title separators */
  1071. popupBtns[i++] = XmCreateSeparatorGadget(pPad->popup, "sep2", NULL, 0);
  1072. fileMenu = XmCreatePulldownMenu (pPad->popup, "fileMenu", NULL, 0);
  1073. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 16, "File")));
  1074. mnemonic = strdup(((char *)GETMESSAGE(11, 15, "F")));
  1075. ac = 0;
  1076. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  1077. XtSetArg(al[ac], XmNsubMenuId, fileMenu); ac++;
  1078. XtSetArg(al[ac], XmNmnemonic, mnemonic); ac++;
  1079. popupBtns[i++] = XmCreateCascadeButtonGadget(pPad->popup, "File", al, ac);
  1080. free(mnemonic);
  1081. XmStringFree(tmpStr);
  1082. mnemonic = strdup(((char *)GETMESSAGE(11, 17, "N")));
  1083. tmpStr = XmStringCreateLocalized(((char *)GETMESSAGE(11, 18, "New")));
  1084. ac = 0;
  1085. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  1086. XtSetArg(al[ac], XmNmnemonic, mnemonic); ac++;
  1087. popupBtns[i] = XmCreatePushButtonGadget(pPad->popup, "New", al, ac);
  1088. XtAddCallback(button, XmNactivateCallback, callback, callData);
  1089. XtAddCallback (popupBtns[i], XmNactivateCallback,
  1090. (XtCallbackProc)FileNewCB, (XtPointer) pPad);
  1091. free(mnemonic);
  1092. XmStringFree(tmpStr);
  1093. i++;
  1094. CreateButton(fileMenu, "Open...", 'O', DisplayFsbCb, (XtPointer)LOAD_DATA);
  1095. CreateButton(fileMenu, "Include...", 'I', DisplayFsbCb,
  1096. (XtPointer)INSERT_DATA);
  1097. CreateButton(fileMenu, "Save As...", 'A', DisplayFsbCb, (XtPointer)SAVE_DATA
  1098. );
  1099. CreateButton(fileMenu, "New", 'N', ResetEditorCb, NULL);
  1100. editMenu = XmCreatePulldownMenu (popupMenu, "editMenu", NULL, 0);
  1101. CreateCascade(popupMenu, "Edit", 'E', editMenu);
  1102. CreateButton(editMenu, "Undo", 'U', UndoCb, (XtPointer)LOAD_DATA);
  1103. ad.cutPopupButton = CreateButton(editMenu, "Cut", 't', CutCb, NULL);
  1104. ad.copyPopupButton = CreateButton(editMenu, "Copy", 'C', CopyCb, NULL);
  1105. CreateButton(editMenu, "Paste", 'P', PasteCb, NULL);
  1106. CreateButton(popupMenu, "Find/Change...", 'F', FindCb, (XtPointer)ad.editor)
  1107. ;
  1108. return (popupMenu);
  1109. }
  1110. static void PopupHandler(Widget w, XtPointer cd, XEvent *event, Boolean *ctd)
  1111. {
  1112. if (((XButtonEvent *)event)->button != Button3) return;
  1113. XmMenuPosition((Widget)cd, (XButtonEvent *)event);
  1114. XtManageChild ((Widget)cd);
  1115. }
  1116. #endif