2
0

XUICreate.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  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: XUICreate.c /main/22 1997/06/18 17:33:46 samborn $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** File: XUICreate.c
  28. **
  29. ** Project: Cde Help System
  30. **
  31. ** Description: Builds a GUI containing a Drawn Button with scroll
  32. ** bars and wraps it around a canvas.
  33. **
  34. ****************************************************************************
  35. ************************************<+>*************************************/
  36. /*
  37. * (c) Copyright 1996 Digital Equipment Corporation.
  38. * (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992,
  39. 1993, 1994, 1996 Hewlett-Packard Company.
  40. * (c) Copyright 1993, 1994, 1996 International Business Machines Corp.
  41. * (c) Copyright 1993, 1994, 1996 Sun Microsystems, Inc.
  42. * (c) Copyright 1993, 1994, 1996 Novell, Inc.
  43. * (c) Copyright 1996 FUJITSU LIMITED.
  44. * (c) Copyright 1996 Hitachi.
  45. */
  46. /*
  47. * system includes
  48. */
  49. #include <stdlib.h>
  50. #include <string.h>
  51. #include <Xm/Xm.h>
  52. #include <Xm/XmP.h>
  53. #include <Xm/AtomMgr.h>
  54. #include <Xm/DrawnB.h>
  55. #include <Xm/Form.h>
  56. #include <Xm/ScrollBar.h>
  57. #include <Xm/XmPrivate.h>
  58. /*
  59. * Canvas Engine
  60. */
  61. #include "CanvasP.h"
  62. #include "CanvasSegP.h"
  63. /*
  64. * private includes
  65. */
  66. #include "bufioI.h"
  67. #include "Access.h"
  68. #include "DisplayAreaP.h"
  69. #include "CallbacksI.h"
  70. #include "XUICreateI.h"
  71. #include "FontI.h"
  72. #include "FontAttrI.h"
  73. #include "DestroyI.h"
  74. #include "FormatUtilI.h"
  75. #include "SetListI.h"
  76. #include "XInterfaceI.h"
  77. #include "Lock.h"
  78. #ifdef NLS16
  79. #endif
  80. /******** Private Function Declarations ********/
  81. static Boolean get_fontsetproperty(
  82. XFontSet fontset,
  83. Atom atom,
  84. unsigned long *value_return);
  85. /******** End Private Function Declarations ********/
  86. /******** Private Variables ********/
  87. static _DtCvVirtualInfo DefVirtFunctions =
  88. {
  89. _DtHelpDAGetCvsMetrics, /* void (*_DtCvGetMetrics)() */
  90. _DtHelpDARenderElem, /* void (*_DtCvRenderElem)() */
  91. _DtHelpDAGetStrWidth, /* _DtCvUnit (*_DtCvGetElemWidth)() */
  92. _DtHelpDAGetFontMetrics, /* void (*_DtCvGetFontMetrics)() */
  93. _DtHelpDABuildSelection, /* void (*_DtCvBuildSelection)() */
  94. NULL, /* _DtCvStatus (*_DtCvFilterExecCmd)()*/
  95. };
  96. /******** End Private Variables ********/
  97. /******** Semi-Private Variables ********/
  98. /******** End Semi-Private Variables ********/
  99. /******************************************************************************
  100. *
  101. * Here are the type and variable declarations for finding view subresources.
  102. *
  103. *****************************************************************************/
  104. /*
  105. * These are used to parse subresources for the text display areas.
  106. */
  107. typedef struct
  108. {
  109. int marginWidth;
  110. int marginHeight;
  111. int leading;
  112. int moveThreshold;
  113. int initialDelay;
  114. int repeatDelay;
  115. XmFontList userFont;
  116. Pixel search_color;
  117. }
  118. DAArgs, *DAArgsPtr;
  119. static XtResource Resources[] = {
  120. {
  121. "leading", "Leading", XmRInt, sizeof(int),
  122. XtOffset(DAArgsPtr, leading), XmRImmediate, (XtPointer) 1
  123. },
  124. {
  125. XmNmarginWidth, XmCMarginWidth, XmRInt, sizeof(int),
  126. XtOffset(DAArgsPtr, marginWidth), XmRImmediate, (XtPointer) 5
  127. },
  128. {
  129. XmNmarginHeight, XmCMarginHeight, XmRInt, sizeof(int),
  130. XtOffset(DAArgsPtr, marginHeight), XmRImmediate, (XtPointer) 5
  131. },
  132. {
  133. "moveThreshold", "MoveThreshold", XmRInt, sizeof(int),
  134. XtOffset(DAArgsPtr, moveThreshold), XmRImmediate, (XtPointer) 10
  135. },
  136. {
  137. XmNinitialDelay, XmCInitialDelay, XmRInt, sizeof(int),
  138. XtOffset(DAArgsPtr, initialDelay), XmRImmediate, (XtPointer) 250
  139. },
  140. {
  141. XmNrepeatDelay, XmCRepeatDelay, XmRInt, sizeof(int),
  142. XtOffset(DAArgsPtr, repeatDelay), XmRImmediate, (XtPointer) 50
  143. },
  144. {
  145. "userFont", XmCFontList, XmRFontList, sizeof (XmFontList),
  146. XtOffset(DAArgsPtr, userFont), XmRString, "Fixed"
  147. },
  148. {
  149. "searchColor", "SearchColor", XtRPixel, sizeof (Pixel),
  150. XtOffset(DAArgsPtr, search_color), XmRString, "blue"
  151. },
  152. };
  153. static String DrawnBTransTable = "\
  154. ~s ~m ~a <Key>Return: ActivateLink()\n\
  155. ~s c ~m ~a <Key>backslash: DeSelectAll()\n\
  156. ~s c ~m ~a <Key>slash: SelectAll()\n\
  157. ~s ~m ~a <Key>space: ActivateLink()\n\
  158. <Key>osfActivate: ActivateLink()\n\
  159. <Key>osfCopy: CopyToClipboard()\n\
  160. ~c <Key>osfDown: NextLink(1)\n\
  161. c <Key>osfDown: PageUpOrDown(1)\n\
  162. ~s c ~m ~a <Key>osfInsert: CopyToClipboard()\n\
  163. ~c <Key>osfLeft: NextLink(0)\n\
  164. c <Key>osfLeft: PageLeftOrRight(0)\n\
  165. ~c <Key>osfPageDown: PageUpOrDown(1)\n\
  166. c <Key>osfPageDown: PageLeftOrRight(1)\n\
  167. <Key>osfPageLeft: PageLeftOrRight(0)\n\
  168. <Key>osfPageRight: PageLeftOrRight(1)\n\
  169. ~c <Key>osfPageUp: PageUpOrDown(0)\n\
  170. c <Key>osfPageUp: PageLeftOrRight(0)\n\
  171. ~c <Key>osfRight: NextLink(1)\n\
  172. c <Key>osfRight: PageLeftOrRight(1)\n\
  173. ~s ~c <Key>osfSelect: ActivateLink()\n\
  174. ~c <Key>osfUp: NextLink(0)\n\
  175. c <Key>osfUp: PageUpOrDown(0)\n\
  176. c <Key>osfBeginLine: NextLink(2)\n\
  177. c <Key>osfEndLine: NextLink(3)\
  178. ";
  179. static XtTranslations DrawnBTrans = NULL;
  180. /*********************************************************************
  181. * Private Functions
  182. *********************************************************************/
  183. /* This function returns the max value of XGetFontProperty calls for each
  184. * font in the fontset.
  185. */
  186. static Boolean
  187. get_fontsetproperty(
  188. XFontSet fontset,
  189. Atom atom,
  190. unsigned long *value_return)
  191. {
  192. int numfont;
  193. XFontStruct **font_list;
  194. char **name_list;
  195. int i;
  196. Bool ret = FALSE;
  197. unsigned long value;
  198. numfont=XFontsOfFontSet(fontset,&font_list,&name_list);
  199. for(i = 0; i < numfont; i++) {
  200. if(XGetFontProperty(font_list[i], atom, &value) == TRUE) {
  201. if(ret == FALSE) {
  202. *value_return = value;
  203. ret = TRUE;
  204. }
  205. else {
  206. if(value > *value_return)
  207. *value_return = value;
  208. }
  209. }
  210. }
  211. return(ret);
  212. }
  213. /*
  214. * This function returns the underline distance and size for the base
  215. * font.
  216. */
  217. static void
  218. GetUnderLineInfo (
  219. Display *dpy,
  220. DtHelpDispAreaStruct *pDAS,
  221. int *ret_underThick )
  222. {
  223. int idx;
  224. XtPointer myFont;
  225. XFontSetExtents *extents;
  226. /*
  227. * cast the parameter as a pointer to a long though the value
  228. * returned is really a int.
  229. */
  230. idx = __DtHelpDefaultFontIndexGet(pDAS);
  231. if (idx < 0)
  232. {
  233. myFont = (XtPointer)__DtHelpFontSetGet(pDAS->font_info, idx);
  234. if (get_fontsetproperty((XFontSet)myFont, XA_UNDERLINE_POSITION,
  235. ((unsigned long *) &(pDAS->underLine))) == FALSE)
  236. {
  237. extents = XExtentsOfFontSet((XFontSet)myFont);
  238. pDAS->underLine = ((int)(extents->max_ink_extent.height +
  239. extents->max_ink_extent.y)) / 2;
  240. }
  241. }
  242. else
  243. {
  244. myFont = (XtPointer)__DtHelpFontStructGet(pDAS->font_info, idx);
  245. if (XGetFontProperty((XFontStruct *)myFont, XA_UNDERLINE_POSITION,
  246. ((unsigned long *) &(pDAS->underLine))) == FALSE)
  247. pDAS->underLine = ((XFontStruct *)myFont)->max_bounds.descent / 2;
  248. }
  249. /*
  250. * if we do not find an underline thickness for the font
  251. * use 15% of the font height.
  252. *
  253. * cast the parameter to a pointer to a long though the value
  254. * returned is really a unsigned int.
  255. */
  256. if (idx < 0)
  257. {
  258. if (get_fontsetproperty((XFontSet)myFont, XA_UNDERLINE_THICKNESS,
  259. ((unsigned long *) ret_underThick)) == FALSE)
  260. *ret_underThick = pDAS->lineHeight * 15 / 100;
  261. }
  262. else
  263. {
  264. if (XGetFontProperty((XFontStruct *)myFont, XA_UNDERLINE_THICKNESS,
  265. ((unsigned long *) ret_underThick)) == FALSE)
  266. *ret_underThick = pDAS->lineHeight * 15 / 100;
  267. }
  268. /*
  269. * now adjust the underline depth so that the when the underline is
  270. * drawn the top of the line is UNDERLINE_POSITION pixels below
  271. * the base line.
  272. */
  273. /*
  274. * SYSTEM - ifdef this for other architectures.
  275. * an example of Hewlett-Packard's implementation is given for reference.
  276. */
  277. /* On Hewlett-Packard machines lines are */
  278. /* drawn like this: */
  279. /* */
  280. /* line width 1: y-> **************** */
  281. /* */
  282. /* **************** */
  283. /* line width 2: y-> **************** */
  284. /* */
  285. /* **************** */
  286. /* line width 3: y-> **************** */
  287. /* **************** */
  288. /* */
  289. /* **************** */
  290. /* **************** */
  291. /* line width 4: y-> **************** */
  292. /* **************** */
  293. /* */
  294. /* **************** */
  295. /* **************** */
  296. /* line width 5: y-> **************** */
  297. /* **************** */
  298. /* **************** */
  299. /* etc...... */
  300. /* */
  301. pDAS->underLine = pDAS->underLine + (*ret_underThick) / 2;
  302. }
  303. /*********************************************************************
  304. * Public Functions
  305. *********************************************************************/
  306. /*********************************************************************
  307. * Function: CreateDA
  308. *
  309. * CreateDA creates a Text Graphic area with the appropriate scroll bars.
  310. *
  311. *********************************************************************/
  312. static XtPointer
  313. HelpCreateDA(
  314. Widget parent,
  315. char *name,
  316. short vert_flag,
  317. short horz_flag,
  318. Boolean traversal_flag,
  319. _DtCvValue honor_size,
  320. _DtCvRenderType render_type,
  321. int rows,
  322. int columns,
  323. unsigned short media_resolution,
  324. void (*hyperTextCB)(),
  325. void (*resizeCB)(),
  326. int (*exec_ok_routine)(),
  327. XtPointer client_data,
  328. XmFontList default_list )
  329. {
  330. DtHelpDispAreaStruct *pDAS;
  331. DAArgs DA_args;
  332. Arg args[20];
  333. int n;
  334. int maxFontAscent;
  335. int maxFontDescent;
  336. int maxFontCharWidth;
  337. short margin_width;
  338. short margin_height;
  339. short shadowThick, highThick;
  340. Dimension hBarHeight = 0;
  341. Dimension vBarWidth = 0;
  342. Dimension width;
  343. Boolean value;
  344. Widget form;
  345. Display *dpy = XtDisplay(parent);
  346. Screen *retScr = XtScreen(parent);
  347. int screen = XScreenNumberOfScreen(retScr);
  348. Colormap colormap;
  349. Pixmap tile;
  350. XGCValues gcValues;
  351. unsigned long gcMask;
  352. unsigned long char_width;
  353. Atom xa_ave_width;
  354. XFontStruct *tmpFont = NULL;
  355. XtPointer default_font = NULL;
  356. XRectangle rectangle[1];
  357. XmFontContext fontContext;
  358. XmFontListEntry fontEntry;
  359. XmFontType fontType;
  360. /* Allocate the Display Area. */
  361. pDAS = (DtHelpDispAreaStruct *) XtMalloc(sizeof(DtHelpDispAreaStruct));
  362. /*
  363. * get the resources
  364. */
  365. XtGetSubresources(parent, &DA_args, name, "XmDrawnButton",
  366. Resources, XtNumber(Resources), NULL, 0);
  367. if (rows <= 0)
  368. rows = 1;
  369. if (columns <= 0)
  370. columns = 1;
  371. /*
  372. * initialize the structure variables.
  373. */
  374. pDAS->text_selected = False;
  375. pDAS->primary = False;
  376. pDAS->select_state = _DtHelpNothingDoing;
  377. pDAS->toc_y = 0;
  378. pDAS->toc_base = 0;
  379. pDAS->toc_flag = 0;
  380. if (traversal_flag)
  381. pDAS->toc_flag = _DT_HELP_SHADOW_TRAVERSAL | _DT_HELP_NOT_INITIALIZED;
  382. pDAS->max_spc = 0;
  383. pDAS->cur_spc = 0;
  384. pDAS->maxX = 0;
  385. pDAS->virtualX = 0;
  386. pDAS->firstVisible = 0;
  387. pDAS->visibleCount = rows;
  388. pDAS->maxYpos = 0;
  389. pDAS->neededFlags = 0;
  390. pDAS->vert_init_scr = DA_args.initialDelay;
  391. pDAS->vert_rep_scr = DA_args.repeatDelay;
  392. pDAS->horz_init_scr = DA_args.initialDelay;
  393. pDAS->horz_rep_scr = DA_args.repeatDelay;
  394. pDAS->moveThreshold = DA_args.moveThreshold;
  395. pDAS->marginWidth = DA_args.marginWidth;
  396. pDAS->marginHeight = DA_args.marginHeight;
  397. pDAS->searchColor = DA_args.search_color;
  398. pDAS->depth = 0;
  399. pDAS->spc_chars = NULL;
  400. pDAS->scr_timer_id = 0;
  401. pDAS->def_pix = 0;
  402. pDAS->context = NULL;
  403. pDAS->vertIsMapped = False;
  404. pDAS->horzIsMapped = False;
  405. pDAS->lst_topic = NULL;
  406. pDAS->nextNonVisible = 0;
  407. pDAS->media_resolution = media_resolution;
  408. pDAS->honor_size = honor_size;
  409. pDAS->render_type = render_type;
  410. pDAS->dtinfo = 0;
  411. pDAS->stipple = None;
  412. /*
  413. * locale dependant information
  414. */
  415. pDAS->nl_to_space = 1;
  416. pDAS->cant_begin_chars = NULL;
  417. pDAS->cant_end_chars = NULL;
  418. if (1 < MB_CUR_MAX)
  419. _DtHelpLoadMultiInfo (&(pDAS->cant_begin_chars),
  420. &(pDAS->cant_end_chars), &(pDAS->nl_to_space));
  421. /*
  422. * initialize the hypertext callback pointer
  423. */
  424. pDAS->exec_filter = exec_ok_routine;
  425. pDAS->hyperCall = hyperTextCB;
  426. pDAS->resizeCall = resizeCB;
  427. pDAS->clientData = client_data;
  428. /*
  429. * zero out other callback fields
  430. */
  431. pDAS->vScrollNotify = NULL ;
  432. pDAS->armCallback = NULL ;
  433. /*
  434. * create the atoms needed
  435. */
  436. xa_ave_width = XmInternAtom(dpy, "AVERAGE_WIDTH" , False);
  437. /*
  438. * Malloc for the default font.
  439. */
  440. (void) XmeRenderTableGetDefaultFont(DA_args.userFont, &tmpFont);
  441. if (default_list != NULL &&
  442. XmFontListInitFontContext (&fontContext, default_list))
  443. {
  444. fontEntry = XmFontListNextEntry (fontContext);
  445. if (fontEntry != NULL)
  446. default_font = XmFontListEntryGetFont (fontEntry, &fontType);
  447. XmFontListFreeFontContext (fontContext);
  448. }
  449. /*
  450. * fake out the next call by using the parent as the display widget
  451. */
  452. pDAS->dispWid = parent;
  453. __DtHelpFontDatabaseInit (pDAS, default_font, fontType, tmpFont);
  454. /*
  455. * Get the base font meterics.
  456. */
  457. __DtHelpFontMetrics (pDAS->font_info, __DtHelpDefaultFontIndexGet(pDAS),
  458. &maxFontAscent, &maxFontDescent, &maxFontCharWidth,
  459. NULL, NULL);
  460. pDAS->leading = DA_args.leading;
  461. pDAS->fontAscent = maxFontAscent;
  462. pDAS->lineHeight = maxFontAscent + maxFontDescent + pDAS->leading + 1;
  463. n = __DtHelpDefaultFontIndexGet(pDAS);
  464. if (n < 0)
  465. value = get_fontsetproperty(__DtHelpFontSetGet(pDAS->font_info, n),
  466. xa_ave_width, ((unsigned long *) &(pDAS->charWidth)));
  467. else
  468. value = XGetFontProperty(__DtHelpFontStructGet(pDAS->font_info, n),
  469. xa_ave_width, ((unsigned long *) &(pDAS->charWidth)));
  470. if (False == value || 0 == pDAS->charWidth)
  471. {
  472. int len = maxFontCharWidth;
  473. if (n < 0)
  474. len += XmbTextEscapement(
  475. __DtHelpFontSetGet(pDAS->font_info,n),"1",1);
  476. else
  477. len += XTextWidth(__DtHelpFontStructGet(pDAS->font_info, n),"1",1);
  478. pDAS->charWidth = 10 * len / 2;
  479. }
  480. /*
  481. * Create the form to manage the window and scroll bars.
  482. */
  483. n = 0;
  484. XtSetArg(args[n], XmNresizePolicy , XmRESIZE_ANY); ++n;
  485. XtSetArg(args[n], XmNshadowType , XmSHADOW_OUT); ++n;
  486. form = XmCreateForm(parent, "DisplayAreaForm", args, n);
  487. XtManageChild(form);
  488. /*
  489. * force the shadowThickness to zero. The XmManager will try to set
  490. * this to one.
  491. */
  492. n = 0;
  493. XtSetArg(args[n], XmNshadowThickness , 0); ++n;
  494. XtSetArg(args[n], XmNhighlightThickness, 0); ++n;
  495. XtSetValues (form, args, n);
  496. /*
  497. * get the colors and margin widths and heights
  498. */
  499. n = 0;
  500. XtSetArg (args[n], XmNmarginWidth , &margin_width); ++n;
  501. XtSetArg (args[n], XmNmarginHeight, &margin_height); ++n;
  502. XtSetArg (args[n], XmNcolormap , &colormap); ++n;
  503. XtGetValues(form, args, n);
  504. /* Create the vertical scrollbar. */
  505. pDAS->vertScrollWid = NULL;
  506. if (vert_flag != _DtHelpNONE)
  507. {
  508. if (vert_flag == _DtHelpSTATIC)
  509. pDAS->vertIsMapped = True;
  510. n = 0;
  511. XtSetArg(args[n], XmNtopAttachment , XmATTACH_FORM); ++n;
  512. XtSetArg(args[n], XmNtopOffset , 0); ++n;
  513. XtSetArg(args[n], XmNbottomAttachment , XmATTACH_FORM); ++n;
  514. XtSetArg(args[n], XmNbottomOffset , margin_height); ++n;
  515. XtSetArg(args[n], XmNrightAttachment , XmATTACH_FORM); ++n;
  516. XtSetArg(args[n], XmNrightOffset , 0); ++n;
  517. XtSetArg(args[n], XmNorientation , XmVERTICAL); ++n;
  518. XtSetArg(args[n], XmNtraversalOn , True); ++n;
  519. XtSetArg(args[n], XmNhighlightThickness, 1); ++n;
  520. XtSetArg(args[n], XmNshadowType , XmSHADOW_IN); ++n;
  521. XtSetArg(args[n], XmNvalue , 0); ++n;
  522. XtSetArg(args[n], XmNminimum , 0); ++n;
  523. /* fake out the scrollbar manager, who will init dims to 100 */
  524. XtSetArg(args[n], XmNheight , 1); ++n;
  525. XtSetArg(args[n], XmNmaximum , 1); ++n;
  526. XtSetArg(args[n], XmNincrement , 1); ++n;
  527. XtSetArg(args[n], XmNpageIncrement , 1); ++n;
  528. XtSetArg(args[n], XmNsliderSize , 1); ++n;
  529. XtSetArg(args[n], XtNmappedWhenManaged , pDAS->vertIsMapped); ++n;
  530. pDAS->vertScrollWid = XmCreateScrollBar(form,
  531. "DisplayDtHelpVertScrollBar", args, n);
  532. XtManageChild(pDAS->vertScrollWid);
  533. if (vert_flag != _DtHelpSTATIC)
  534. pDAS->neededFlags = _DtHelpSET_AS_NEEDED (pDAS->neededFlags,
  535. _DtHelpVERTICAL_SCROLLBAR);
  536. XtAddCallback(pDAS->vertScrollWid, XmNdragCallback,
  537. _DtHelpVertScrollCB, (XtPointer) pDAS);
  538. XtAddCallback(pDAS->vertScrollWid, XmNincrementCallback,
  539. _DtHelpVertScrollCB, (XtPointer) pDAS);
  540. XtAddCallback(pDAS->vertScrollWid, XmNdecrementCallback,
  541. _DtHelpVertScrollCB, (XtPointer) pDAS);
  542. XtAddCallback(pDAS->vertScrollWid, XmNpageIncrementCallback,
  543. _DtHelpVertScrollCB, (XtPointer) pDAS);
  544. XtAddCallback(pDAS->vertScrollWid, XmNpageDecrementCallback,
  545. _DtHelpVertScrollCB, (XtPointer) pDAS);
  546. XtAddCallback(pDAS->vertScrollWid, XmNtoBottomCallback,
  547. _DtHelpVertScrollCB, (XtPointer) pDAS);
  548. XtAddCallback(pDAS->vertScrollWid, XmNtoTopCallback,
  549. _DtHelpVertScrollCB, (XtPointer) pDAS);
  550. XtAddCallback(pDAS->vertScrollWid, XmNvalueChangedCallback,
  551. _DtHelpVertScrollCB, (XtPointer) pDAS);
  552. XtAddEventHandler (pDAS->vertScrollWid, ButtonPressMask, True,
  553. (XtEventHandler)_DtHelpMoveBtnFocusCB,(XtPointer) pDAS);
  554. }
  555. /* Create the horizontal scrollbar. */
  556. pDAS->horzScrollWid = NULL;
  557. if (horz_flag != _DtHelpNONE)
  558. {
  559. if (horz_flag == _DtHelpSTATIC)
  560. pDAS->horzIsMapped = True;
  561. n = 0;
  562. XtSetArg(args[n], XmNbottomAttachment , XmATTACH_FORM); ++n;
  563. XtSetArg(args[n], XmNbottomOffset , 0); ++n;
  564. XtSetArg(args[n], XmNrightAttachment , XmATTACH_FORM); ++n;
  565. XtSetArg(args[n], XmNrightOffset , margin_width); ++n;
  566. XtSetArg(args[n], XmNleftAttachment , XmATTACH_FORM); ++n;
  567. XtSetArg(args[n], XmNleftOffset , 0); ++n;
  568. XtSetArg(args[n], XmNorientation , XmHORIZONTAL); ++n;
  569. XtSetArg(args[n], XmNtraversalOn , True); ++n;
  570. XtSetArg(args[n], XmNhighlightThickness, 1); ++n;
  571. XtSetArg(args[n], XmNshadowType , XmSHADOW_IN); ++n;
  572. XtSetArg(args[n], XmNvalue , 0); ++n;
  573. XtSetArg(args[n], XmNminimum , 0); ++n;
  574. XtSetArg(args[n], XmNmaximum , (pDAS->charWidth/10)); ++n;
  575. /* fake out the scrollbar manager, who will init dims to 100 */
  576. XtSetArg(args[n], XmNwidth , 1); ++n;
  577. XtSetArg(args[n], XmNincrement , (pDAS->charWidth/10)); ++n;
  578. XtSetArg(args[n], XmNpageIncrement , (pDAS->charWidth/10)); ++n;
  579. XtSetArg(args[n], XmNsliderSize , (pDAS->charWidth/10)); ++n;
  580. XtSetArg(args[n], XtNmappedWhenManaged , pDAS->horzIsMapped); ++n;
  581. pDAS->horzScrollWid = XmCreateScrollBar(form,
  582. "DisplayHorzScrollBar", args, n);
  583. XtManageChild(pDAS->horzScrollWid);
  584. if (horz_flag != _DtHelpSTATIC)
  585. pDAS->neededFlags = _DtHelpSET_AS_NEEDED (pDAS->neededFlags,
  586. _DtHelpHORIZONTAL_SCROLLBAR);
  587. XtAddCallback(pDAS->horzScrollWid, XmNdragCallback,
  588. _DtHelpHorzScrollCB, (XtPointer) pDAS);
  589. XtAddCallback(pDAS->horzScrollWid, XmNincrementCallback,
  590. _DtHelpHorzScrollCB, (XtPointer) pDAS);
  591. XtAddCallback(pDAS->horzScrollWid, XmNdecrementCallback,
  592. _DtHelpHorzScrollCB, (XtPointer) pDAS);
  593. XtAddCallback(pDAS->horzScrollWid, XmNpageIncrementCallback,
  594. _DtHelpHorzScrollCB, (XtPointer) pDAS);
  595. XtAddCallback(pDAS->horzScrollWid, XmNpageDecrementCallback,
  596. _DtHelpHorzScrollCB, (XtPointer) pDAS);
  597. XtAddCallback(pDAS->horzScrollWid, XmNtoBottomCallback,
  598. _DtHelpHorzScrollCB, (XtPointer) pDAS);
  599. XtAddCallback(pDAS->horzScrollWid, XmNtoTopCallback,
  600. _DtHelpHorzScrollCB, (XtPointer) pDAS);
  601. XtAddCallback(pDAS->horzScrollWid, XmNvalueChangedCallback,
  602. _DtHelpHorzScrollCB, (XtPointer) pDAS);
  603. }
  604. /*
  605. * check for the horizontal attachments
  606. */
  607. n = 0;
  608. if (horz_flag == _DtHelpSTATIC)
  609. {
  610. XtSetArg(args[n], XmNbottomAttachment , XmATTACH_WIDGET); ++n;
  611. XtSetArg(args[n], XmNbottomWidget , pDAS->horzScrollWid); ++n;
  612. }
  613. else
  614. {
  615. XtSetArg(args[n], XmNbottomAttachment , XmATTACH_FORM); ++n;
  616. }
  617. /*
  618. * check for the vertical attachments
  619. */
  620. if (vert_flag == _DtHelpSTATIC)
  621. {
  622. XtSetArg(args[n], XmNrightAttachment , XmATTACH_WIDGET); ++n;
  623. XtSetArg(args[n], XmNrightWidget , pDAS->vertScrollWid); ++n;
  624. }
  625. else
  626. {
  627. XtSetArg(args[n], XmNrightAttachment , XmATTACH_FORM); ++n;
  628. }
  629. /*
  630. * do the rest of the arguments
  631. */
  632. XtSetArg(args[n], XmNbottomOffset , margin_height); ++n;
  633. XtSetArg(args[n], XmNrightOffset , margin_width); ++n;
  634. XtSetArg(args[n], XmNtopAttachment , XmATTACH_FORM); ++n;
  635. XtSetArg(args[n], XmNtopOffset , 0); ++n;
  636. XtSetArg(args[n], XmNleftAttachment , XmATTACH_FORM); ++n;
  637. XtSetArg(args[n], XmNleftOffset , 0); ++n;
  638. XtSetArg(args[n], XmNrecomputeSize , False); ++n;
  639. XtSetArg(args[n], XmNpushButtonEnabled , False); ++n;
  640. XtSetArg(args[n], XmNtraversalOn , True); ++n;
  641. XtSetArg(args[n], XmNhighlightThickness, 1); ++n;
  642. XtSetArg(args[n], XmNshadowType , XmSHADOW_IN); ++n;
  643. XtSetArg(args[n], XmNmultiClick , XmMULTICLICK_DISCARD); ++n;
  644. XtSetArg(args[n], XmNuserData , pDAS); ++n;
  645. pDAS->dispWid = XmCreateDrawnButton(form, name, args, n);
  646. XtManageChild(pDAS->dispWid);
  647. XtAddCallback(pDAS->dispWid, XmNexposeCallback, _DtHelpExposeCB,
  648. (XtPointer) pDAS);
  649. XtAddCallback(pDAS->dispWid, XmNresizeCallback, _DtHelpResizeCB,
  650. (XtPointer) pDAS);
  651. XtAddCallback(pDAS->dispWid, XmNarmCallback, _DtHelpClickOrSelectCB,
  652. (XtPointer) pDAS);
  653. XtAddCallback(pDAS->dispWid, XmNdisarmCallback, _DtHelpEndSelectionCB,
  654. (XtPointer) pDAS);
  655. XtAddEventHandler (pDAS->dispWid, Button1MotionMask, True,
  656. (XtEventHandler)_DtHelpMouseMoveCB, (XtPointer) pDAS);
  657. /*
  658. * add my actions
  659. * parse the translations.
  660. */
  661. _DtHelpProcessLock();
  662. if (DrawnBTrans == NULL)
  663. DrawnBTrans = XtParseTranslationTable(DrawnBTransTable);
  664. /*
  665. * override the translations
  666. XtSetArg(args[n], XmNtranslations , DrawnBTrans); ++n;
  667. */
  668. if (DrawnBTrans != NULL)
  669. XtOverrideTranslations(pDAS->dispWid, DrawnBTrans);
  670. _DtHelpProcessUnlock();
  671. if (_XmGetFocusPolicy(parent) == XmPOINTER)
  672. {
  673. XtAddEventHandler (pDAS->dispWid, EnterWindowMask, True,
  674. (XtEventHandler)_DtHelpEnterLeaveCB, (XtPointer) pDAS);
  675. XtAddEventHandler (pDAS->dispWid, LeaveWindowMask, True,
  676. (XtEventHandler)_DtHelpEnterLeaveCB, (XtPointer) pDAS);
  677. }
  678. else
  679. XtAddEventHandler (pDAS->dispWid, FocusChangeMask, True,
  680. (XtEventHandler)_DtHelpFocusCB, (XtPointer) pDAS);
  681. XtAddEventHandler (pDAS->dispWid, VisibilityChangeMask, True,
  682. (XtEventHandler)_DtHelpVisibilityCB, (XtPointer) pDAS);
  683. /* Add a destroy callback so that the display area can clean up prior to
  684. * the help widget getting destroyed (e.g. display area's parent)
  685. */
  686. XtAddCallback(pDAS->dispWid, XmNdestroyCallback,
  687. _DtHelpDisplayAreaDestroyCB, (XtPointer) pDAS);
  688. n = 0;
  689. XtSetArg(args[n], XmNshadowThickness , &shadowThick); ++n;
  690. XtSetArg(args[n], XmNhighlightThickness, &highThick); ++n;
  691. XtSetArg(args[n], XmNforeground , &(pDAS->foregroundColor)); ++n;
  692. XtSetArg(args[n], XmNbackground , &(pDAS->backgroundColor)); ++n;
  693. XtSetArg(args[n], XmNhighlightColor, &(pDAS->traversalColor) ); ++n;
  694. XtSetArg(args[n], XmNdepth , &(pDAS->depth) ); ++n;
  695. XtGetValues(pDAS->dispWid, args, n);
  696. pDAS->decorThickness = shadowThick + highThick;
  697. /*
  698. * Get the underline information
  699. */
  700. GetUnderLineInfo (dpy, pDAS, &(pDAS->lineThickness));
  701. /*
  702. * get the tiling pattern.
  703. */
  704. tile = XmGetPixmap (XtScreen(pDAS->dispWid), "50_foreground",
  705. pDAS->foregroundColor, pDAS->backgroundColor);
  706. /*
  707. * Get the data for the graphics contexts and create the GC's.
  708. */
  709. gcMask = (GCFunction | GCPlaneMask | GCForeground |
  710. GCBackground | GCLineWidth | GCLineStyle |
  711. GCClipXOrigin | GCClipYOrigin | GCClipMask);
  712. gcValues.function = GXcopy;
  713. gcValues.plane_mask = AllPlanes;
  714. gcValues.foreground = pDAS->foregroundColor;
  715. gcValues.background = pDAS->backgroundColor;
  716. gcValues.line_style = LineSolid;
  717. gcValues.line_width = pDAS->lineThickness;
  718. gcValues.clip_x_origin = 0;
  719. gcValues.clip_y_origin = 0;
  720. gcValues.clip_mask = None;
  721. if (tile)
  722. {
  723. gcMask |= GCTile;
  724. gcValues.tile = tile;
  725. }
  726. pDAS->normalGC = XCreateGC(dpy,
  727. RootWindowOfScreen(XtScreen(pDAS->dispWid)), gcMask, &gcValues);
  728. gcMask &= (~GCTile);
  729. pDAS->pixmapGC = XCreateGC(dpy,
  730. RootWindowOfScreen(XtScreen(pDAS->dispWid)), gcMask, &gcValues);
  731. gcValues.foreground = pDAS->backgroundColor;
  732. gcValues.background = pDAS->foregroundColor;
  733. pDAS->invertGC = XCreateGC(dpy,
  734. RootWindowOfScreen(XtScreen(pDAS->dispWid)), gcMask, &gcValues);
  735. /*
  736. * Set the size of the text view area to the requested
  737. * number of columns and lines.
  738. */
  739. char_width = pDAS->charWidth * columns;
  740. /*
  741. * Make sure the margins include enough room for a traversal line
  742. */
  743. if (((int) pDAS->marginWidth) < pDAS->lineThickness)
  744. pDAS->marginWidth = pDAS->lineThickness;
  745. if (((int) pDAS->marginHeight) < pDAS->lineThickness)
  746. pDAS->marginHeight = pDAS->lineThickness;
  747. if (pDAS->leading < pDAS->lineThickness)
  748. pDAS->leading = pDAS->lineThickness;
  749. /*
  750. * get the scrollbar widths.
  751. */
  752. if (NULL != pDAS->horzScrollWid)
  753. {
  754. n = 0;
  755. XtSetArg(args[n], XmNheight , &hBarHeight); n++;
  756. XtSetArg(args[n], XmNinitialDelay, &(pDAS->horz_init_scr)); n++;
  757. XtSetArg(args[n], XmNrepeatDelay , &(pDAS->horz_rep_scr)); n++;
  758. XtGetValues(pDAS->horzScrollWid, args, n);
  759. }
  760. if (NULL != pDAS->vertScrollWid)
  761. {
  762. n = 0;
  763. XtSetArg(args[n], XmNwidth , &vBarWidth); n++;
  764. XtSetArg(args[n], XmNinitialDelay, &(pDAS->vert_init_scr)); n++;
  765. XtSetArg(args[n], XmNrepeatDelay , &(pDAS->vert_rep_scr)); n++;
  766. XtGetValues(pDAS->vertScrollWid, args, n);
  767. }
  768. /*
  769. * calculate the display area height/width
  770. */
  771. pDAS->dispUseWidth = ((int) (char_width / 10 + (char_width % 10 ? 1 : 0)))
  772. + 2 * pDAS->marginWidth;
  773. if (vert_flag != _DtHelpSTATIC && pDAS->dispUseWidth < vBarWidth)
  774. pDAS->dispUseWidth = vBarWidth;
  775. pDAS->dispWidth = pDAS->dispUseWidth + 2 * pDAS->decorThickness;
  776. pDAS->dispUseHeight = pDAS->lineHeight * rows;
  777. if (horz_flag != _DtHelpSTATIC && pDAS->dispUseHeight < hBarHeight)
  778. pDAS->dispUseHeight = hBarHeight;
  779. pDAS->dispHeight = pDAS->dispUseHeight + 2 * pDAS->decorThickness;
  780. /*
  781. * Truncate the width and height to the size of the display.
  782. * This will prevent an X protocal error when it is asked for
  783. * a too large size. Besides, any decent window manager will
  784. * force the overall size to the height and width of the display.
  785. * This simply refines the size down to a closer (but not perfect)
  786. * fit.
  787. */
  788. if (((int) pDAS->dispWidth) > XDisplayWidth (dpy, screen)) {
  789. pDAS->dispWidth = XDisplayWidth (dpy, screen);
  790. }
  791. if (((int) pDAS->dispHeight) > XDisplayHeight (dpy, screen)) {
  792. pDAS->dispHeight = XDisplayHeight (dpy, screen);
  793. }
  794. n = 0;
  795. pDAS->formWidth = 0;
  796. pDAS->formHeight = 0;
  797. XtSetArg(args[n], XmNwidth, pDAS->dispWidth); ++n;
  798. XtSetArg(args[n], XmNheight, pDAS->dispHeight); ++n;
  799. XtSetValues(pDAS->dispWid, args, n);
  800. /*
  801. * set the scroll bar values
  802. */
  803. if (pDAS->vertScrollWid != NULL)
  804. {
  805. n = 0;
  806. XtSetArg(args[n], XmNmaximum , pDAS->dispUseHeight); ++n;
  807. XtSetArg(args[n], XmNincrement , pDAS->lineHeight); ++n;
  808. XtSetArg(args[n], XmNpageIncrement , pDAS->lineHeight); ++n;
  809. XtSetArg(args[n], XmNsliderSize , pDAS->dispUseHeight); ++n;
  810. XtSetValues(pDAS->vertScrollWid, args, n);
  811. }
  812. if (pDAS->resizeCall)
  813. (*(pDAS->resizeCall)) (pDAS->clientData);
  814. /*
  815. * calculate the offset for the right edge of the
  816. * horizontal scrollbar.
  817. */
  818. if (vert_flag == _DtHelpSTATIC && pDAS->horzScrollWid)
  819. {
  820. width = vBarWidth + margin_width;
  821. XtSetArg(args[0], XmNrightOffset , width);
  822. XtSetValues(pDAS->horzScrollWid, args, 1);
  823. }
  824. /*
  825. * calculate the offset for the bottom end of the
  826. * vertical scrollbar.
  827. */
  828. if (horz_flag == _DtHelpSTATIC && pDAS->vertScrollWid)
  829. {
  830. width = hBarHeight + margin_height;
  831. XtSetArg(args[0], XmNbottomOffset , width);
  832. XtSetValues(pDAS->vertScrollWid, args, 1);
  833. }
  834. rectangle[0].x = pDAS->decorThickness;
  835. rectangle[0].y = pDAS->decorThickness;
  836. rectangle[0].width = pDAS->dispUseWidth;
  837. rectangle[0].height = pDAS->dispUseHeight;
  838. XSetClipRectangles(XtDisplay(pDAS->dispWid), pDAS->normalGC, 0, 0,
  839. rectangle, 1, Unsorted);
  840. XSetClipRectangles(XtDisplay(pDAS->dispWid), pDAS->invertGC, 0, 0,
  841. rectangle, 1, Unsorted);
  842. /*
  843. * get the colormap and the visual
  844. */
  845. if (!XtIsShell(parent) && XtParent(parent) != NULL)
  846. parent = XtParent(parent);
  847. pDAS->visual = NULL;
  848. n = 0;
  849. XtSetArg (args[n], XmNcolormap, &(pDAS->colormap)); n++;
  850. XtSetArg (args[n], XmNvisual , &(pDAS->visual )); n++;
  851. XtGetValues (parent, args, n);
  852. if (pDAS->visual == NULL)
  853. pDAS->visual = XDefaultVisualOfScreen(XtScreen(pDAS->dispWid));
  854. /*
  855. * set up the canvas
  856. */
  857. _DtHelpProcessLock();
  858. DefVirtFunctions.exec_cmd_filter = exec_ok_routine;
  859. pDAS->canvas = _DtCanvasCreate (DefVirtFunctions, (_DtCvPointer) pDAS);
  860. _DtHelpProcessUnlock();
  861. return (XtPointer) pDAS;
  862. } /* End _DtHelpCreateDA */
  863. /*********************************************************************
  864. * Function: CreateDisplayArea
  865. *
  866. * Creates a Text Graphic area with the appropriate scroll bars.
  867. * specifying the size with rows and columns
  868. *
  869. *********************************************************************/
  870. XtPointer
  871. _DtHelpCreateDisplayArea(
  872. Widget parent,
  873. char *name,
  874. short vert_flag,
  875. short horz_flag,
  876. Boolean traversal_flag,
  877. int rows,
  878. int columns,
  879. void (*hyperTextCB)(),
  880. void (*resizeCB)(),
  881. int (*exec_ok_routine)(),
  882. XtPointer client_data,
  883. XmFontList default_list )
  884. {
  885. return HelpCreateDA(parent, name,
  886. vert_flag, horz_flag,
  887. traversal_flag,
  888. _DtCvIGNORE_BOUNDARY, _DtCvRENDER_PARTIAL,
  889. rows, columns, 100,
  890. hyperTextCB, resizeCB, exec_ok_routine,
  891. client_data, default_list);
  892. }
  893. /*********************************************************************
  894. * Function: CreateOutputArea
  895. *
  896. * Creates a Text Graphic area with the appropriate scroll bars.
  897. * specifying the size with width and height
  898. *
  899. *********************************************************************/
  900. XtPointer
  901. _DtHelpCreateOutputArea(
  902. Widget parent,
  903. char *name,
  904. short vert_flag,
  905. short horz_flag,
  906. Boolean traversal_flag,
  907. _DtCvValue honor_size,
  908. _DtCvRenderType render_type,
  909. Dimension width,
  910. Dimension height,
  911. unsigned short media_resolution,
  912. void (*hyperTextCB)(),
  913. void (*resizeCB)(),
  914. int (*exec_ok_routine)(),
  915. XtPointer client_data,
  916. XmFontList default_list )
  917. {
  918. DtHelpDispAreaStruct *pDAS;
  919. pDAS = HelpCreateDA(parent, name,
  920. vert_flag, horz_flag,
  921. traversal_flag, honor_size, render_type,
  922. 1, 1, media_resolution,
  923. hyperTextCB, resizeCB, exec_ok_routine,
  924. client_data, default_list);
  925. /* if area created successfully, then resize it to the given size */
  926. if (pDAS)
  927. _DtHelpSetScrollBars(pDAS, width, height);
  928. return pDAS;
  929. }