2
0

Callbacks.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these librararies and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: Callbacks.c /main/21 1996/10/22 12:22:33 cde-hp $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** File: Callbacks.c
  28. **
  29. ** Project: Display Area Library
  30. **
  31. **
  32. ** Description: This body of code handles the callbacks for the
  33. ** Display Area.
  34. **
  35. ****************************************************************************
  36. ************************************<+>*************************************/
  37. /*
  38. * (c) Copyright 1996 Digital Equipment Corporation.
  39. * (c) Copyright 1987-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 <stdio.h>
  50. #include <stdlib.h>
  51. #include <limits.h>
  52. #include <X11/Xlib.h>
  53. #include <X11/Xatom.h>
  54. #include <X11/Intrinsic.h>
  55. #include <Xm/Xm.h>
  56. #include <Xm/AtomMgr.h>
  57. #include <Xm/DrawnB.h>
  58. #include <Xm/CutPaste.h>
  59. #include <Xm/XmPrivate.h>
  60. /*
  61. * Canvas Engine
  62. */
  63. #include "CanvasP.h"
  64. /*
  65. * private includes
  66. */
  67. #include "Access.h"
  68. #include "DisplayAreaP.h"
  69. #include "CallbacksI.h"
  70. #include "FontI.h"
  71. #include "FontAttrI.h"
  72. #include "HyperTextI.h"
  73. #include "SetListI.h"
  74. #include "HelposI.h"
  75. #include "XInterfaceI.h"
  76. #ifdef NLS16
  77. #endif
  78. /******** Private Function Declarations ********/
  79. static Boolean ConvertSelectionCB (
  80. Widget widget,
  81. Atom *selection,
  82. Atom *target,
  83. Atom *type,
  84. XtPointer *value,
  85. unsigned long *length,
  86. int *format );
  87. static void ScrollTimerCB (
  88. XtPointer client_data,
  89. XtIntervalId *id );
  90. static void StartSelection (
  91. Widget widget,
  92. XtPointer client_data );
  93. /******** End Private Function Declarations ********/
  94. /******** Private Defines ********/
  95. #define SCROLL_BAR_FLAGS 0x03
  96. #define HORIZONTAL 0
  97. #define VERTICAL 1
  98. /******** End Private Defines ********/
  99. /******** Private Variable Declarations ********/
  100. /******** End Private Variable Declarations ********/
  101. /******************************************************************************
  102. * Private Functions
  103. ******************************************************************************/
  104. /*****************************************************************************
  105. * Function: ConvertSelectionCB
  106. *
  107. * ConvertSelectionCB - this routine is called when someone asks for
  108. * our selection.
  109. *
  110. *****************************************************************************/
  111. static Boolean
  112. ConvertSelectionCB (
  113. Widget widget,
  114. Atom *selection,
  115. Atom *target,
  116. Atom *type,
  117. XtPointer *value,
  118. unsigned long *length,
  119. int *format )
  120. {
  121. Atom TARGETS = XmInternAtom(XtDisplay(widget), "TARGETS" , False);
  122. Atom TIMESTAMP = XmInternAtom(XtDisplay(widget), "TIMESTAMP", False);
  123. Atom TEXT = XmInternAtom(XtDisplay(widget), "TEXT" , False);
  124. Atom CMP_TEXT = XmInternAtom(XtDisplay(widget), "COMPOUND_TEXT",False);
  125. Atom LOCALE;
  126. int retStatus = 0;
  127. char *testString = "ABC"; /* these are characters in XPCS, so... safe */
  128. char *tmpString = NULL;
  129. Arg args[2];
  130. DtHelpDispAreaStruct *pDAS;
  131. XTextProperty tmpProp;
  132. XtSetArg(args[0], XmNuserData, &pDAS);
  133. XtGetValues(widget, args, 1);
  134. if (pDAS == NULL || pDAS->primary == False || *selection != XA_PRIMARY)
  135. return False;
  136. retStatus = XmbTextListToTextProperty(XtDisplay(widget), &testString, 1,
  137. (XICCEncodingStyle)XTextStyle, &tmpProp);
  138. LOCALE = (Atom) 9999; /* XmbTextList... should always be able
  139. * to convert XPCS characters; but in
  140. * case its broken, this prevents a core
  141. * dump.
  142. */
  143. if (retStatus == Success)
  144. {
  145. LOCALE = tmpProp.encoding;
  146. XFree(tmpProp.value);
  147. }
  148. /*
  149. * List the targets understood
  150. */
  151. if (*target == TARGETS)
  152. {
  153. Atom *targs = (Atom *)XtMalloc((unsigned) (5 * sizeof(Atom)));
  154. *value = (char *) targs;
  155. *targs++ = LOCALE;
  156. *targs++ = TIMESTAMP;
  157. *targs++ = TEXT;
  158. *targs++ = CMP_TEXT;
  159. *targs++ = XA_STRING;
  160. *type = XA_ATOM;
  161. *length = (5 * sizeof(Atom)) >> 2;
  162. *format = 32;
  163. }
  164. else if (*target == TIMESTAMP)
  165. {
  166. Time *timestamp;
  167. timestamp = (Time *) XtMalloc(sizeof(Time));
  168. *timestamp = pDAS->anchor_time;
  169. *value = (char *) timestamp;
  170. *type = XA_INTEGER;
  171. *length = sizeof(Time);
  172. *format = 32;
  173. }
  174. else if (*target == XA_STRING)
  175. {
  176. /*
  177. * initialize the return type here in case we fail
  178. */
  179. *type = (Atom) XA_STRING;
  180. *format = 8;
  181. /*
  182. * get the string
  183. */
  184. _DtCanvasGetSelection (pDAS->canvas,
  185. (_DtCvSELECTED_TEXT | _DtCvSELECTED_REGION),
  186. (_DtCvPointer *)(&tmpString));
  187. retStatus = -1;
  188. if (tmpString != NULL && *tmpString != '\0')
  189. retStatus = XmbTextListToTextProperty(XtDisplay(widget),
  190. &tmpString, 1,
  191. (XICCEncodingStyle)XStringStyle, &tmpProp);
  192. /*
  193. * free the original copy of the string and check the results
  194. */
  195. if (tmpString != NULL)
  196. free(tmpString);
  197. if (retStatus == Success || retStatus > 0)
  198. {
  199. *value = (XtPointer) tmpProp.value;
  200. *length = tmpProp.nitems;
  201. }
  202. else
  203. {
  204. *value = NULL;
  205. *length = 0;
  206. return False;
  207. }
  208. }
  209. else if (*target == TEXT)
  210. {
  211. /*
  212. * set the type and format to those calculated
  213. */
  214. *type = TEXT;
  215. *format = 8;
  216. /*
  217. * get the string
  218. */
  219. _DtCanvasGetSelection (pDAS->canvas,
  220. (_DtCvSELECTED_TEXT | _DtCvSELECTED_REGION),
  221. (_DtCvPointer *)(&tmpString));
  222. retStatus = -1;
  223. if (tmpString != NULL && *tmpString != '\0')
  224. retStatus = XmbTextListToTextProperty(XtDisplay(widget),
  225. &tmpString, 1,
  226. (XICCEncodingStyle)XStdICCTextStyle, &tmpProp);
  227. /*
  228. * free the original copy of the string and check the results
  229. */
  230. if (tmpString != NULL)
  231. free(tmpString);
  232. if (retStatus == Success || retStatus > 0)
  233. {
  234. *value = (XtPointer) tmpProp.value;
  235. *length = tmpProp.nitems;
  236. }
  237. else
  238. {
  239. *value = NULL;
  240. *length = 0;
  241. return False;
  242. }
  243. }
  244. else if (*target == LOCALE)
  245. {
  246. /*
  247. * pass the string straight through
  248. */
  249. *type = LOCALE;
  250. *format = 8;
  251. _DtCanvasGetSelection (pDAS->canvas,
  252. (_DtCvSELECTED_TEXT | _DtCvSELECTED_REGION),
  253. (_DtCvPointer *)(value));
  254. *length = 0;
  255. if (*value != NULL)
  256. *length = strlen((char *)(*value));
  257. }
  258. else if (*target == CMP_TEXT)
  259. {
  260. *type = CMP_TEXT;
  261. *format = 8;
  262. /*
  263. * get the selected text.
  264. */
  265. _DtCanvasGetSelection (pDAS->canvas,
  266. (_DtCvSELECTED_TEXT | _DtCvSELECTED_REGION),
  267. (_DtCvPointer *)(&tmpString));
  268. retStatus = -1;
  269. if (tmpString != NULL && *tmpString != '\0')
  270. retStatus = XmbTextListToTextProperty(XtDisplay(widget),
  271. &tmpString, 1,
  272. (XICCEncodingStyle)XCompoundTextStyle, &tmpProp);
  273. /*
  274. * free the original copy of the string and check the results
  275. */
  276. if (tmpString != NULL)
  277. free(tmpString);
  278. if (retStatus == Success || retStatus > 0)
  279. {
  280. *value = (XtPointer) tmpProp.value;
  281. *length = tmpProp.nitems;
  282. }
  283. else
  284. {
  285. *value = NULL;
  286. *length = 0;
  287. return False;
  288. }
  289. }
  290. else
  291. return False;
  292. return True;
  293. } /* End ConvertSelectionCB */
  294. /*****************************************************************************
  295. * Function: ScrollTimerCB
  296. *
  297. * ScrollTimerCB - This routine is called when we have a timer
  298. * go off with the mouse outside the Display Area during a
  299. * selection.
  300. *
  301. *****************************************************************************/
  302. static void
  303. ScrollTimerCB (
  304. XtPointer client_data, /* data from applicaiton */
  305. XtIntervalId *id ) /* timer id */
  306. {
  307. int diffY = 0;
  308. int diffX = 0;
  309. int x;
  310. int y;
  311. int scrollTimeOut;
  312. int maxY;
  313. int dispY;
  314. Arg args[2];
  315. XmScrollBarCallbackStruct callData;
  316. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  317. if (*id != pDAS->scr_timer_id)
  318. return;
  319. pDAS->scr_timer_id = 0;
  320. maxY = pDAS->maxYpos;
  321. dispY = pDAS->firstVisible + pDAS->dispUseHeight;
  322. if ((pDAS->scr_timer_data.vertical_reason == XmCR_INCREMENT && maxY <= dispY)
  323. ||
  324. (pDAS->scr_timer_data.vertical_reason == XmCR_DECREMENT &&
  325. !pDAS->firstVisible))
  326. pDAS->scr_timer_data.vertical_reason = XmCR_NONE;
  327. if ((pDAS->scr_timer_data.horizontal_reason == XmCR_INCREMENT &&
  328. pDAS->maxX <= pDAS->virtualX + ((int)pDAS->dispUseWidth))
  329. ||
  330. (pDAS->scr_timer_data.horizontal_reason == XmCR_DECREMENT &&
  331. !pDAS->virtualX))
  332. pDAS->scr_timer_data.horizontal_reason = XmCR_NONE;
  333. if ( pDAS->scr_timer_data.vertical_reason == XmCR_NONE &&
  334. pDAS->scr_timer_data.horizontal_reason == XmCR_NONE)
  335. return;
  336. y = pDAS->firstVisible;
  337. if (pDAS->scr_timer_data.vertical_reason == XmCR_NONE)
  338. y = pDAS->scr_timer_y - pDAS->decorThickness;
  339. else if (pDAS->scr_timer_data.vertical_reason == XmCR_INCREMENT)
  340. {
  341. y = y + pDAS->dispUseHeight + pDAS->lineHeight;
  342. if (y > pDAS->maxYpos)
  343. y = pDAS->maxYpos;
  344. diffY = y - pDAS->firstVisible - pDAS->dispUseHeight;
  345. }
  346. else if (pDAS->scr_timer_data.vertical_reason == XmCR_DECREMENT)
  347. {
  348. y -= pDAS->lineHeight;
  349. if (y < 0)
  350. y = 0;
  351. diffY = y - pDAS->firstVisible;
  352. }
  353. if (pDAS->scr_timer_data.horizontal_reason == XmCR_NONE)
  354. x = pDAS->scr_timer_x - pDAS->decorThickness;
  355. else
  356. {
  357. if (pDAS->scr_timer_data.horizontal_reason == XmCR_INCREMENT)
  358. {
  359. diffX = (int) (pDAS->charWidth / 10);
  360. x = pDAS->dispUseWidth;
  361. if (x + pDAS->virtualX + diffX > pDAS->maxX)
  362. diffX = pDAS->maxX - x - pDAS->virtualX;
  363. }
  364. else if (pDAS->scr_timer_data.horizontal_reason == XmCR_DECREMENT)
  365. {
  366. diffX = -((int)(pDAS->charWidth / 10));
  367. x = 0;
  368. if (pDAS->virtualX + diffX < 0)
  369. diffX = -(pDAS->virtualX);
  370. }
  371. }
  372. _DtCanvasProcessSelection (pDAS->canvas,
  373. (x + diffX + pDAS->virtualX - pDAS->decorThickness),
  374. y, _DtCvSELECTION_UPDATE);
  375. callData.event = NULL;
  376. if (diffX)
  377. {
  378. scrollTimeOut = pDAS->horz_rep_scr;
  379. callData.reason = pDAS->scr_timer_data.horizontal_reason;
  380. callData.value = pDAS->virtualX + diffX;
  381. _DtHelpHorzScrollCB (pDAS->horzScrollWid, client_data,
  382. (XtPointer) &callData);
  383. if (pDAS->horzScrollWid)
  384. {
  385. XtSetArg (args[0], XmNvalue, pDAS->virtualX);
  386. XtSetValues (pDAS->horzScrollWid, args, 1);
  387. }
  388. if (diffY != 0 && pDAS->vertScrollWid)
  389. {
  390. XtSetArg (args[0], XmNvalue, y);
  391. XtSetValues (pDAS->vertScrollWid, args, 1);
  392. if (pDAS->vScrollNotify)
  393. (pDAS->vScrollNotify)(pDAS->clientData, y);
  394. }
  395. }
  396. else
  397. {
  398. scrollTimeOut = pDAS->vert_rep_scr;
  399. callData.reason = pDAS->scr_timer_data.vertical_reason;
  400. callData.value = pDAS->firstVisible + diffY;
  401. _DtHelpVertScrollCB (pDAS->vertScrollWid, client_data,
  402. (XtPointer) &callData);
  403. if (pDAS->vertScrollWid)
  404. {
  405. XtSetArg (args[0], XmNvalue, pDAS->firstVisible);
  406. XtSetValues (pDAS->vertScrollWid, args, 1);
  407. if (pDAS->vScrollNotify)
  408. (pDAS->vScrollNotify)(pDAS->clientData, pDAS->firstVisible);
  409. }
  410. }
  411. pDAS->scr_timer_id = XtAppAddTimeOut (
  412. XtWidgetToApplicationContext (pDAS->dispWid),
  413. ((unsigned long) scrollTimeOut),
  414. ScrollTimerCB, client_data);
  415. } /* End ScrollTimerCB */
  416. /******************************************************************************
  417. * Function: DrawWholeCanvas
  418. *
  419. *****************************************************************************/
  420. static void
  421. DrawWholeCanvas(
  422. DtHelpDispAreaStruct *pDAS)
  423. {
  424. _DtCvUnit top;
  425. _DtCvUnit bottom;
  426. _DtCvUnit right;
  427. _DtCvUnit next_y;
  428. _DtCanvasMoveTraversal(pDAS->canvas,_DtCvTRAVERSAL_OFF, False,
  429. (XtIsRealized(pDAS->dispWid) ? True : False),
  430. NULL, NULL, NULL, NULL, NULL);
  431. top = pDAS->firstVisible;
  432. bottom = top + pDAS->dispUseHeight;
  433. right = pDAS->virtualX + pDAS->dispUseWidth;
  434. _DtCanvasRender (pDAS->canvas, pDAS->virtualX, top, right, bottom,
  435. pDAS->render_type, _DtCvTRUE, NULL, &next_y);
  436. pDAS->nextNonVisible =
  437. (pDAS->render_type == _DtCvRENDER_PARTIAL) ? bottom : next_y;
  438. /*
  439. * If we have a hypertext link boxed, draw it
  440. */
  441. _DtCanvasMoveTraversal(pDAS->canvas, _DtCvTRAVERSAL_ON, False,
  442. (XtIsRealized(pDAS->dispWid) ? True : False),
  443. NULL, NULL, NULL, NULL, NULL);
  444. /*
  445. * if the toc exists within this area, draw it.
  446. */
  447. if ((pDAS->toc_flag & _DT_HELP_TOC_ON) &&
  448. pDAS->toc_y + pDAS->toc_height >= top && pDAS->toc_y < bottom)
  449. _DtHelpDATocMarker((XtPointer) pDAS, True);
  450. } /* End DrawWholeCanvas */
  451. /******************************************************************************
  452. * Semi Public Functions
  453. *****************************************************************************/
  454. /******************************************************************************
  455. * Function: _DtHelpCleanAndDrawWholeCanvas
  456. *
  457. *****************************************************************************/
  458. void
  459. _DtHelpCleanAndDrawWholeCanvas(
  460. XtPointer client_data)
  461. {
  462. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  463. XClearArea (XtDisplay(pDAS->dispWid), XtWindow(pDAS->dispWid),
  464. pDAS->decorThickness, pDAS->decorThickness,
  465. pDAS->dispUseWidth,
  466. pDAS->dispUseHeight,
  467. False);
  468. DrawWholeCanvas (pDAS);
  469. }
  470. void
  471. _DtHelpSearchMoveTraversal(XtPointer client_data, int search_hit_index)
  472. {
  473. _DtCvUnit baseline, ascend, descend;
  474. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  475. if (_DtCvGetSearchLineMetrics(pDAS->canvas, search_hit_index,
  476. &baseline, &descend, &ascend) == 0) {
  477. _DtCvUnit top, hitY, height;
  478. top = pDAS->firstVisible;
  479. hitY = baseline - ascend - pDAS->lineThickness;
  480. height = ascend + descend + 2 * pDAS->lineThickness;
  481. if (hitY < top)
  482. top = hitY;
  483. else if (hitY + height > top + ((int) pDAS->dispUseHeight))
  484. top = hitY + height - ((int) pDAS->dispUseHeight);
  485. if (top != pDAS->firstVisible) {
  486. _DtCvUnit dispUseHeightHalf =
  487. pDAS->dispUseHeight / 2 + pDAS->dispUseHeight % 2;
  488. /* put search hit in the middle of the viewport */
  489. if (top == hitY)
  490. top -= dispUseHeightHalf - height;
  491. else {
  492. top += dispUseHeightHalf + height;
  493. if (top + ((int)pDAS->dispUseHeight) > pDAS->maxYpos)
  494. top = pDAS->maxYpos - pDAS->dispUseHeight;
  495. }
  496. if (top < 0)
  497. top = 0;
  498. if (top != pDAS->firstVisible) {
  499. Arg arg;
  500. pDAS->firstVisible = top;
  501. XtSetArg(arg, XmNvalue, pDAS->firstVisible);
  502. XtSetValues(pDAS->vertScrollWid, &arg, 1);
  503. if (pDAS->vScrollNotify)
  504. (pDAS->vScrollNotify)(pDAS->clientData, pDAS->firstVisible);
  505. _DtHelpCleanAndDrawWholeCanvas(pDAS);
  506. }
  507. }
  508. }
  509. }
  510. /******************************************************************************
  511. * Function: _DtHelpCancelSelection
  512. *
  513. * Returns : True if a selection was active and cancelled.
  514. * False if a selection was not active.
  515. *
  516. *****************************************************************************/
  517. Boolean
  518. _DtHelpCancelSelection(
  519. XtPointer client_data)
  520. {
  521. Boolean selActive = False;
  522. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  523. if (pDAS->select_state == _DtHelpSelectingText && pDAS->primary == True)
  524. {
  525. selActive = True;
  526. if (pDAS->scr_timer_id)
  527. {
  528. XtRemoveTimeOut (pDAS->scr_timer_id);
  529. pDAS->scr_timer_id = 0;
  530. }
  531. _DtHelpClearSelection (client_data);
  532. }
  533. return selActive;
  534. }
  535. /******************************************************************************
  536. * Public Functions
  537. *****************************************************************************/
  538. /******************************************************************************
  539. * Function: _DtHelpExposeCB
  540. *
  541. * _DtHelpExposeCB handles the exposure events for a Text Graphic Area.
  542. *
  543. *****************************************************************************/
  544. void
  545. _DtHelpExposeCB(
  546. Widget widget,
  547. XtPointer client_data,
  548. XtPointer call_data )
  549. {
  550. Arg args[4];
  551. Dimension height;
  552. Dimension width;
  553. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  554. XmDrawnButtonCallbackStruct *callback =
  555. (XmDrawnButtonCallbackStruct *) call_data;
  556. if (callback->reason != XmCR_EXPOSE ||
  557. (pDAS->neededFlags & (1 << (VisibilityFullyObscured + 3))))
  558. return;
  559. /*
  560. * get the width and height.
  561. */
  562. XtSetArg(args[0], XmNwidth, &width);
  563. XtSetArg(args[1], XmNheight, &height);
  564. XtGetValues(widget, args, 2);
  565. /*
  566. * if this exposure is a result of a resize,
  567. * wait for the resize to handle it.
  568. */
  569. if (width != pDAS->dispWidth || height != pDAS->dispHeight)
  570. return;
  571. if (!(callback->event) || callback->event->xexpose.count)
  572. return;
  573. /*
  574. * re-draw the information in the display area
  575. */
  576. DrawWholeCanvas (pDAS);
  577. } /* End _DtHelpExposeCB */
  578. /*********************************************************************
  579. * Function: _DtHelpResizeCB
  580. *
  581. * _DtHelpResizeCB handles the exposure events for a Text Graphic Area.
  582. *
  583. *********************************************************************/
  584. void
  585. _DtHelpResizeCB(
  586. Widget widget,
  587. XtPointer client_data,
  588. XtPointer call_data )
  589. {
  590. Arg args[4];
  591. Dimension width;
  592. Dimension height;
  593. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  594. XmDrawnButtonCallbackStruct *callback =
  595. (XmDrawnButtonCallbackStruct *) call_data;
  596. if (callback->reason != XmCR_RESIZE)
  597. return;
  598. /*
  599. * get the width and height of the form.
  600. */
  601. XtSetArg(args[0], XmNwidth, &width);
  602. XtSetArg(args[1], XmNheight, &height);
  603. XtGetValues(XtParent(widget), args, 2);
  604. if (width == pDAS->formWidth && height == pDAS->formHeight)
  605. return;
  606. pDAS->formWidth = width;
  607. pDAS->formHeight = height;
  608. /*
  609. * get the width and height.
  610. */
  611. XtSetArg(args[0], XmNwidth, &width);
  612. XtSetArg(args[1], XmNheight, &height);
  613. XtGetValues(widget, args, 2);
  614. if (width == pDAS->dispWidth && height == pDAS->dispHeight)
  615. return;
  616. /*
  617. _DtHelpClearSelection (pDAS);
  618. * reset the scroll bars and possibly reformat the text for the size.
  619. */
  620. (void) _DtHelpSetScrollBars (client_data, width, height);
  621. if (XtIsRealized (pDAS->dispWid))
  622. _DtHelpCleanAndDrawWholeCanvas (client_data);
  623. /*
  624. * I will get an expose event after the resize.
  625. */
  626. } /* End _DtHelpResizeCB */
  627. /***************************************************************************
  628. * Function: _DtHelpVertScrollCB
  629. *
  630. * _DtHelpVertScrollCB is called when the vertical scroll bar is changed.
  631. *
  632. **************************************************************************/
  633. void
  634. _DtHelpVertScrollCB(
  635. Widget widget,
  636. XtPointer clientData,
  637. XtPointer callData )
  638. {
  639. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) clientData;
  640. XmScrollBarCallbackStruct *callBack =
  641. (XmScrollBarCallbackStruct *) callData;
  642. int diff = pDAS->lineHeight;
  643. int srcY, dstY;
  644. int clearY;
  645. int reason = callBack->reason;
  646. _DtCvUnit absTop;
  647. _DtCvUnit absBot;
  648. Display *dpy;
  649. Window win;
  650. /*
  651. * if the policy is XmEXPLICIT, don't want the focus on the scrollbar
  652. */
  653. if (callBack->event != NULL && callBack->event->type == ButtonPress &&
  654. _XmGetFocusPolicy(XtParent(XtParent(pDAS->dispWid))) != XmPOINTER)
  655. XmProcessTraversal(pDAS->dispWid, XmTRAVERSE_CURRENT);
  656. /*
  657. * check to make sure we don't do a rerender when we don't have to.
  658. */
  659. if (pDAS->firstVisible == callBack->value)
  660. return;
  661. /* If a drag occured, reset the reason to increment, decrement, page */
  662. /* increment, or page decrement depending on the distance and direction */
  663. /* dragged. */
  664. if (callBack->reason == XmCR_DRAG || callBack->reason == XmCR_VALUE_CHANGED)
  665. {
  666. diff = callBack->value - pDAS->firstVisible;
  667. if (diff > 0 && diff <= ((int) pDAS->dispUseHeight))
  668. reason = XmCR_INCREMENT;
  669. else if (diff < 0 && -(diff) <= ((int) pDAS->dispUseHeight))
  670. {
  671. reason = XmCR_DECREMENT;
  672. diff = -diff;
  673. }
  674. else if (diff > ((int) pDAS->dispUseHeight))
  675. reason = XmCR_PAGE_DECREMENT;
  676. else
  677. reason = XmCR_PAGE_INCREMENT;
  678. }
  679. else if (callBack->reason == XmCR_INCREMENT ||
  680. callBack->reason == XmCR_DECREMENT)
  681. {
  682. diff = callBack->value - pDAS->firstVisible;
  683. if (diff < 0)
  684. diff = -diff;
  685. }
  686. /* Reset first visible to the returned scrollbar value. */
  687. pDAS->firstVisible = callBack->value;
  688. /* For page increment and decrement, call _DtHelpCleanAndDrawWholeCanvas
  689. * to clear the view area and redisplay the text.
  690. *
  691. * For increment and decrement,
  692. * use XCopyArea to move the visible lines and draw the cleared out line.
  693. */
  694. if (!pDAS->maxYpos ||
  695. (pDAS->neededFlags & (1 << (VisibilityFullyObscured + 3))))
  696. return;
  697. dpy = XtDisplay (widget);
  698. win = XtWindow (pDAS->dispWid);
  699. if (reason == XmCR_PAGE_INCREMENT || reason == XmCR_PAGE_DECREMENT ||
  700. reason == XmCR_TO_TOP || reason == XmCR_TO_BOTTOM)
  701. _DtHelpCleanAndDrawWholeCanvas (clientData);
  702. else
  703. {
  704. if (reason == XmCR_INCREMENT)
  705. {
  706. dstY = pDAS->decorThickness;
  707. srcY = dstY + diff;
  708. clearY = pDAS->dispHeight - pDAS->decorThickness - diff;
  709. }
  710. else
  711. {
  712. srcY = pDAS->decorThickness;
  713. dstY = srcY + diff;
  714. clearY = srcY;
  715. }
  716. XCopyArea(dpy, win, win, pDAS->normalGC, pDAS->decorThickness, srcY,
  717. pDAS->dispUseWidth, (pDAS->dispUseHeight - diff),
  718. pDAS->decorThickness, dstY);
  719. XClearArea(dpy, win, pDAS->decorThickness, clearY,
  720. pDAS->dispUseWidth, ((unsigned int) diff), False);
  721. if (pDAS->neededFlags & (1 << (VisibilityPartiallyObscured + 3)))
  722. {
  723. /*
  724. * redraw all the information
  725. */
  726. DrawWholeCanvas (pDAS);
  727. }
  728. else
  729. {
  730. /*
  731. * draw the line that sits on the cleared line
  732. */
  733. absTop = clearY + pDAS->firstVisible - pDAS->decorThickness;
  734. absBot = absTop + diff;
  735. _DtCanvasRender (pDAS->canvas, 0, absTop,
  736. pDAS->virtualX + pDAS->dispWidth, absBot,
  737. _DtCvRENDER_PARTIAL, _DtCvFALSE, NULL, NULL);
  738. /*
  739. * if the toc exists within this area, draw it.
  740. */
  741. if ((pDAS->toc_flag & _DT_HELP_TOC_ON)
  742. && pDAS->toc_y + pDAS->toc_height >= absTop
  743. && pDAS->toc_y < absBot)
  744. _DtHelpDATocMarker((XtPointer) pDAS, True);
  745. }
  746. }
  747. } /* End _DtHelpVertScrollCB */
  748. /***************************************************************************
  749. * Function: _DtHelpHorzScrollCB
  750. *
  751. * _DtHelpHorzScrollCB is called when the horizontal scroll bar is changed.
  752. *
  753. **************************************************************************/
  754. void
  755. _DtHelpHorzScrollCB(
  756. Widget widget,
  757. XtPointer clientData,
  758. XtPointer callData )
  759. {
  760. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) clientData;
  761. XmScrollBarCallbackStruct *callBack =
  762. (XmScrollBarCallbackStruct *) callData;
  763. int diff = (int)(pDAS->charWidth / 10);
  764. int srcX;
  765. int dstX;
  766. int clearX;
  767. int reason = callBack->reason;
  768. _DtCvUnit absLeft;
  769. _DtCvUnit absRight;
  770. _DtCvUnit absY;
  771. Display *dpy;
  772. Window win;
  773. /*
  774. * if the policy is XmEXPLICIT, don't want the focus on the scrollbar
  775. */
  776. if (callBack->event != NULL && callBack->event->type == ButtonPress &&
  777. _XmGetFocusPolicy(XtParent(XtParent(pDAS->dispWid))) != XmPOINTER)
  778. XmProcessTraversal(pDAS->dispWid, XmTRAVERSE_CURRENT);
  779. /*
  780. * check to make sure we don't do a rerender when we don't have to.
  781. */
  782. if (pDAS->virtualX == callBack->value)
  783. return;
  784. /* If a drag occured, reset the reason to increment, decrement, page */
  785. /* increment, or page decrement depending on the distance and direction */
  786. /* dragged. */
  787. if (callBack->reason == XmCR_DRAG || callBack->reason == XmCR_VALUE_CHANGED)
  788. {
  789. diff = callBack->value - pDAS->virtualX;
  790. if (diff > 0 && diff <= ((int) pDAS->dispUseWidth))
  791. reason = XmCR_INCREMENT;
  792. else if (diff < 0 && -(diff) <= ((int) pDAS->dispUseWidth))
  793. {
  794. reason = XmCR_DECREMENT;
  795. diff = -diff;
  796. }
  797. else if (diff > ((int) pDAS->dispUseWidth))
  798. reason = XmCR_PAGE_DECREMENT;
  799. else
  800. reason = XmCR_PAGE_INCREMENT;
  801. }
  802. else if (callBack->reason == XmCR_INCREMENT ||
  803. callBack->reason == XmCR_DECREMENT)
  804. {
  805. diff = callBack->value - pDAS->virtualX;
  806. if (diff < 0)
  807. diff = -diff;
  808. }
  809. /* Reset first visible to the returned scrollbar value. */
  810. pDAS->virtualX = callBack->value;
  811. /* For page increment and decrement, call _DtHelpCleanAndDrawWholeCanvas
  812. * to clear the view area and redisplay the text.
  813. *
  814. * For increment and decrement,
  815. * use XCopyArea to move the visible lines and draw the cleared out line.
  816. */
  817. if (!pDAS->maxX || !pDAS->visibleCount ||
  818. (pDAS->neededFlags & (1 << (VisibilityFullyObscured + 3))))
  819. return;
  820. dpy = XtDisplay (widget);
  821. win = XtWindow (pDAS->dispWid);
  822. /* For page increment and decrement, clear the view area and call
  823. * View_DtHelpExposeCB to redisplay the text. For increment and decrement,
  824. * use XCopyArea to move the visible lines and draw the cleared out line.
  825. */
  826. if (reason == XmCR_PAGE_INCREMENT || reason == XmCR_PAGE_DECREMENT ||
  827. reason == XmCR_TO_TOP || reason == XmCR_TO_BOTTOM)
  828. _DtHelpCleanAndDrawWholeCanvas (clientData);
  829. else
  830. {
  831. if (reason == XmCR_INCREMENT)
  832. {
  833. dstX = pDAS->decorThickness;
  834. srcX = dstX + diff;
  835. clearX = pDAS->dispWidth - pDAS->decorThickness - diff;
  836. }
  837. else
  838. {
  839. srcX = pDAS->decorThickness;
  840. dstX = srcX + diff;
  841. clearX = srcX;
  842. }
  843. XCopyArea(dpy, win, win, pDAS->normalGC, srcX, pDAS->decorThickness,
  844. pDAS->dispUseWidth - diff, pDAS->dispUseHeight,
  845. dstX, pDAS->decorThickness);
  846. XClearArea(dpy, win, clearX, pDAS->decorThickness,
  847. ((unsigned int) diff), pDAS->dispUseHeight, False);
  848. if (pDAS->neededFlags & (1 << (VisibilityPartiallyObscured + 3)))
  849. {
  850. /*
  851. * redraw all the information
  852. */
  853. DrawWholeCanvas (pDAS);
  854. }
  855. else
  856. {
  857. /*
  858. * draw the line that sits on the cleared line
  859. */
  860. absLeft = clearX + pDAS->virtualX - pDAS->decorThickness;
  861. absRight = absLeft + diff;
  862. absY = pDAS->firstVisible - pDAS->decorThickness;
  863. _DtCanvasRender (pDAS->canvas, absLeft, absY,
  864. absRight, absY + pDAS->dispHeight,
  865. _DtCvRENDER_PARTIAL, _DtCvFALSE, NULL, NULL);
  866. /*
  867. * if the toc exists within this area, draw it.
  868. */
  869. if ((pDAS->toc_flag & _DT_HELP_TOC_ON)
  870. && ((int) (pDAS->toc_y + pDAS->toc_height)) >= ((int) absY)
  871. && ((int) pDAS->toc_y) < ((int) (absY + pDAS->dispHeight)))
  872. _DtHelpDATocMarker((XtPointer) pDAS, True);
  873. }
  874. }
  875. } /* End _DtHelpHorzScrollCB */
  876. /***************************************************************************
  877. * Function: _DtHelpClickOrSelectCB
  878. *
  879. * _DtHelpClickOrSelectCB is called when the vertical scroll bar is changed.
  880. *
  881. **************************************************************************/
  882. void
  883. _DtHelpClickOrSelectCB(
  884. Widget widget,
  885. XtPointer clientData,
  886. XtPointer callData )
  887. {
  888. XmDrawnButtonCallbackStruct *callBack =
  889. (XmDrawnButtonCallbackStruct *) callData;
  890. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct*) clientData;
  891. /*
  892. * If this is not an ARM call or entered through an Arm&Activate
  893. * (event-type will be keypress or keyrelease) throw it away.
  894. */
  895. if (callBack->reason != XmCR_ARM || callBack->event == NULL ||
  896. callBack->event->type == KeyPress ||
  897. callBack->event->type == KeyRelease)
  898. return;
  899. pDAS->timerX = callBack->event->xbutton.x;
  900. pDAS->timerY = callBack->event->xbutton.y;
  901. pDAS->select_state = _DtHelpCopyOrLink;
  902. if (NULL != pDAS->armCallback)
  903. (pDAS->armCallback)(pDAS->clientData);
  904. } /* End _DtHelpClickOrSelectCB */
  905. /*****************************************************************************
  906. * Function: _DtHelpEndSelectionCB
  907. *
  908. *
  909. * Called by: Callback for the Selection mechanism
  910. *****************************************************************************/
  911. void
  912. _DtHelpEndSelectionCB (
  913. Widget w, /* widget id */
  914. XtPointer client_data, /* data from applicaiton */
  915. XtPointer call_data ) /* data from widget class */
  916. {
  917. XmDrawnButtonCallbackStruct *callback =
  918. (XmDrawnButtonCallbackStruct *) call_data;
  919. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct*) client_data;
  920. int newX;
  921. int newY;
  922. if (callback->reason != XmCR_DISARM || callback->event == NULL ||
  923. callback->event->type == KeyPress ||
  924. callback->event->type == KeyRelease)
  925. return;
  926. /*
  927. * if a scroll timer is active, we are selecting text.
  928. * stop it.
  929. */
  930. if (pDAS->scr_timer_id)
  931. {
  932. XtRemoveTimeOut (pDAS->scr_timer_id);
  933. pDAS->scr_timer_id = 0;
  934. }
  935. newX = callback->event->xbutton.x;
  936. newY = callback->event->xbutton.y;
  937. if (pDAS->select_state == _DtHelpCopyOrLink)
  938. {
  939. if (abs (pDAS->timerX - newX) <= pDAS->moveThreshold &&
  940. abs (pDAS->timerY - newY) <= pDAS->moveThreshold)
  941. {
  942. _DtHelpClearSelection (client_data);
  943. /*
  944. * If this is null, we came the the Arm&Activate routine
  945. * which means a key was pressed, so we ignore this call.
  946. */
  947. if (callback->event)
  948. /*
  949. * find the hypertext link and process it.
  950. */
  951. _DtHelpProcessHyperSelection (client_data,
  952. pDAS->timerX, pDAS->timerY,
  953. callback->event);
  954. }
  955. else
  956. StartSelection (w, client_data);
  957. return;
  958. }
  959. /*
  960. * The user was doing a selection, finish it up.
  961. */
  962. if (pDAS->select_state != _DtHelpNothingDoing)
  963. {
  964. _DtCanvasProcessSelection(pDAS->canvas,
  965. (newX + pDAS->virtualX - pDAS->decorThickness),
  966. (newY + pDAS->firstVisible - pDAS->decorThickness),
  967. _DtCvSELECTION_END);
  968. _DtCanvasMoveTraversal(pDAS->canvas, _DtCvTRAVERSAL_ON, False, True,
  969. NULL, NULL, NULL, NULL, NULL);
  970. }
  971. pDAS->select_state = _DtHelpNothingDoing;
  972. return;
  973. } /* End _DtHelpEndSelectionCB */
  974. /***************************************************************************
  975. * Function: _DtHelpMouseMoveCB
  976. *
  977. * _DtHelpMouseMoveCB tracks the mouse movement for the Selection mechanism
  978. *
  979. **************************************************************************/
  980. void
  981. _DtHelpMouseMoveCB(
  982. Widget widget,
  983. XtPointer client_data,
  984. XEvent *event )
  985. {
  986. _DtCvUnit newX;
  987. _DtCvUnit newY;
  988. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  989. /*
  990. * If a selection is not in progress, don't do anything.
  991. */
  992. if (pDAS->select_state == _DtHelpNothingDoing || event->type != MotionNotify)
  993. return;
  994. if (pDAS->scr_timer_id)
  995. {
  996. XtRemoveTimeOut (pDAS->scr_timer_id);
  997. pDAS->scr_timer_id = 0;
  998. }
  999. newX = event->xmotion.x;
  1000. newY = event->xmotion.y;
  1001. if (pDAS->select_state == _DtHelpCopyOrLink)
  1002. {
  1003. if (abs (newX - pDAS->timerX) < pDAS->moveThreshold &&
  1004. abs (newY - pDAS->timerY) < pDAS->moveThreshold)
  1005. return;
  1006. StartSelection (widget, client_data);
  1007. return;
  1008. }
  1009. if (newY < ((int) pDAS->decorThickness) && pDAS->firstVisible)
  1010. pDAS->scr_timer_data.vertical_reason = XmCR_DECREMENT;
  1011. else if ((newY >
  1012. (((int) pDAS->dispHeight)-((int)pDAS->decorThickness))) &&
  1013. (pDAS->maxYpos >
  1014. (((int)pDAS->firstVisible)
  1015. + ((int)pDAS->dispUseHeight))))
  1016. pDAS->scr_timer_data.vertical_reason = XmCR_INCREMENT;
  1017. else
  1018. pDAS->scr_timer_data.vertical_reason = XmCR_NONE;
  1019. if (newX < ((int) pDAS->decorThickness) && pDAS->virtualX)
  1020. pDAS->scr_timer_data.horizontal_reason = XmCR_DECREMENT;
  1021. else if (newX > ((int) pDAS->dispWidth) &&
  1022. pDAS->maxX > pDAS->virtualX + ((int) pDAS->dispUseWidth))
  1023. pDAS->scr_timer_data.horizontal_reason = XmCR_INCREMENT;
  1024. else
  1025. pDAS->scr_timer_data.horizontal_reason = XmCR_NONE;
  1026. if (pDAS->scr_timer_data.vertical_reason != XmCR_NONE ||
  1027. pDAS->scr_timer_data.horizontal_reason != XmCR_NONE)
  1028. {
  1029. int scrollTimeOut = pDAS->vert_init_scr;
  1030. if (pDAS->scr_timer_data.horizontal_reason != XmCR_NONE)
  1031. scrollTimeOut = pDAS->horz_init_scr;
  1032. pDAS->scr_timer_x = newX;
  1033. pDAS->scr_timer_y = newY;
  1034. pDAS->scr_timer_id =
  1035. XtAppAddTimeOut(XtWidgetToApplicationContext(widget),
  1036. ((unsigned long) scrollTimeOut),
  1037. ScrollTimerCB, (XtPointer) pDAS);
  1038. return;
  1039. }
  1040. newX = newX + pDAS->virtualX - pDAS->decorThickness;
  1041. if (newX < 0)
  1042. newX = 0;
  1043. newY = newY + pDAS->firstVisible - pDAS->decorThickness;
  1044. if (newY < 0)
  1045. newY = 0;
  1046. _DtCanvasProcessSelection(pDAS->canvas, newX, newY, _DtCvSELECTION_UPDATE);
  1047. } /* End _DtHelpMouseMoveCB */
  1048. /*****************************************************************************
  1049. * Function: StartSelection
  1050. *
  1051. * StartSelection - If this routine is called, the user has initiated a
  1052. * selection.
  1053. *
  1054. *****************************************************************************/
  1055. static void
  1056. StartSelection (
  1057. Widget widget, /* widget id */
  1058. XtPointer client_data ) /* data from applicaiton */
  1059. {
  1060. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct*) client_data;
  1061. /*
  1062. * If this widget doesn't own the primary selection, get it.
  1063. */
  1064. _DtHelpGetClearSelection(widget, client_data);
  1065. /*
  1066. * check to see if we have the primary selection.
  1067. */
  1068. if (pDAS->primary == True)
  1069. {
  1070. _DtCanvasMoveTraversal(pDAS->canvas, _DtCvTRAVERSAL_OFF, False, True,
  1071. NULL, NULL, NULL, NULL, NULL);
  1072. _DtCanvasProcessSelection(pDAS->canvas,
  1073. pDAS->timerX + pDAS->virtualX - pDAS->decorThickness,
  1074. pDAS->timerY + pDAS->firstVisible -pDAS->decorThickness,
  1075. _DtCvSELECTION_START);
  1076. pDAS->select_state = _DtHelpSelectingText;
  1077. pDAS->text_selected = True;
  1078. }
  1079. } /* End StartSelection */
  1080. /*****************************************************************************
  1081. * Function: _DtHelpLoseSelectionCB
  1082. *
  1083. * _DtHelpLoseSelectionCB - This routine is called when we lose the selection
  1084. *
  1085. *****************************************************************************/
  1086. void
  1087. _DtHelpLoseSelectionCB (
  1088. Widget widget,
  1089. Atom *selection )
  1090. {
  1091. Arg args[2];
  1092. DtHelpDispAreaStruct *pDAS;
  1093. XtSetArg(args[0], XmNuserData, &pDAS);
  1094. XtGetValues(widget, args, 1);
  1095. if (pDAS != NULL && pDAS->dispWid == widget && *selection == XA_PRIMARY)
  1096. {
  1097. _DtHelpClearSelection ((XtPointer) pDAS);
  1098. pDAS->primary = False;
  1099. pDAS->text_selected = False;
  1100. }
  1101. } /* End _DtHelpLoseSelectionCB */
  1102. /*****************************************************************************
  1103. * Function: _DtHelpClearSelection
  1104. *
  1105. * Clears the selection pointers and variables
  1106. *
  1107. *****************************************************************************/
  1108. void
  1109. _DtHelpClearSelection ( XtPointer client_data)
  1110. {
  1111. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct*) client_data;
  1112. if (pDAS->primary == True)
  1113. {
  1114. if (NULL != pDAS->canvas)
  1115. {
  1116. _DtCanvasMoveTraversal(pDAS->canvas, _DtCvTRAVERSAL_OFF, False, True,
  1117. NULL, NULL, NULL, NULL, NULL);
  1118. _DtCanvasProcessSelection(pDAS->canvas, 0, 0, _DtCvSELECTION_CLEAR);
  1119. _DtCanvasMoveTraversal(pDAS->canvas, _DtCvTRAVERSAL_ON, False, True,
  1120. NULL, NULL, NULL, NULL, NULL);
  1121. }
  1122. pDAS->select_state = _DtHelpNothingDoing;
  1123. pDAS->text_selected = False;
  1124. }
  1125. }
  1126. /***************************************************************************
  1127. * Function: _DtHelpFocusCB
  1128. *
  1129. * _DtHelpFocusCB tracks the traversal of the hypertext.
  1130. *
  1131. **************************************************************************/
  1132. void
  1133. _DtHelpFocusCB(
  1134. Widget widget,
  1135. XtPointer client_data,
  1136. XEvent *event )
  1137. {
  1138. Boolean oldFlag;
  1139. Boolean newFlag = False;
  1140. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  1141. if (pDAS->hyperCall == NULL ||
  1142. (event->type != FocusIn && event->type != FocusOut) ||
  1143. !event->xfocus.send_event)
  1144. return;
  1145. /*
  1146. * get the old flag
  1147. */
  1148. oldFlag = (pDAS->neededFlags & _DT_HELP_FOCUS_FLAG) ? True : False;
  1149. /*
  1150. * get the new flag
  1151. */
  1152. if (event->type == FocusIn)
  1153. newFlag = True;
  1154. if (oldFlag != newFlag)
  1155. {
  1156. if (newFlag == False)
  1157. {
  1158. _DtCanvasMoveTraversal (pDAS->canvas, _DtCvTRAVERSAL_OFF, False,
  1159. (XtIsRealized(widget) ? True : False),
  1160. NULL, NULL, NULL, NULL, NULL);
  1161. pDAS->neededFlags = pDAS->neededFlags & ~(_DT_HELP_FOCUS_FLAG);
  1162. }
  1163. else
  1164. {
  1165. pDAS->neededFlags = pDAS->neededFlags | _DT_HELP_FOCUS_FLAG;
  1166. _DtCanvasMoveTraversal (pDAS->canvas, _DtCvTRAVERSAL_ON, False,
  1167. (XtIsRealized(widget) ? True : False),
  1168. NULL, NULL, NULL, NULL, NULL);
  1169. }
  1170. }
  1171. } /* End _DtHelpFocusCB */
  1172. /***************************************************************************
  1173. * Function: _DtHelpEnterLeaveCB
  1174. *
  1175. * _DtHelpEnterLeaveCB tracks the traversal of the hypertext.
  1176. *
  1177. **************************************************************************/
  1178. void
  1179. _DtHelpEnterLeaveCB(
  1180. Widget widget,
  1181. XtPointer client_data,
  1182. XEvent *event )
  1183. {
  1184. Boolean oldFlag;
  1185. Boolean newFlag = False;
  1186. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  1187. if (pDAS->hyperCall == NULL ||
  1188. (event->type != EnterNotify && event->type != LeaveNotify))
  1189. return;
  1190. /*
  1191. * get the old flag
  1192. */
  1193. oldFlag = (pDAS->neededFlags & _DT_HELP_FOCUS_FLAG) ? True : False;
  1194. /*
  1195. * get the new flag
  1196. */
  1197. if (event->type == FocusIn)
  1198. newFlag = True;
  1199. if (oldFlag != newFlag)
  1200. {
  1201. if (oldFlag == True)
  1202. {
  1203. _DtCanvasMoveTraversal (pDAS->canvas, _DtCvTRAVERSAL_OFF, False,
  1204. (XtIsRealized(widget) ? True : False),
  1205. NULL, NULL, NULL, NULL, NULL);
  1206. pDAS->neededFlags = pDAS->neededFlags & ~(_DT_HELP_FOCUS_FLAG);
  1207. }
  1208. else
  1209. {
  1210. pDAS->neededFlags = pDAS->neededFlags | _DT_HELP_FOCUS_FLAG;
  1211. _DtCanvasMoveTraversal (pDAS->canvas, _DtCvTRAVERSAL_ON, False,
  1212. (XtIsRealized(widget) ? True : False),
  1213. NULL, NULL, NULL, NULL, NULL);
  1214. }
  1215. }
  1216. } /* End _DtHelpEnterLeaveCB */
  1217. /***************************************************************************
  1218. * Function: _DtHelpVisibilityCB
  1219. *
  1220. * _DtHelpVisibilityCB tracks whether the window becomes obscured.
  1221. *
  1222. **************************************************************************/
  1223. void
  1224. _DtHelpVisibilityCB(
  1225. Widget widget,
  1226. XtPointer client_data,
  1227. XEvent *event )
  1228. {
  1229. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  1230. if (event->type != VisibilityNotify)
  1231. return;
  1232. /*
  1233. * save the scrollbar and focus flags while clearing the visibility flags.
  1234. */
  1235. pDAS->neededFlags = pDAS->neededFlags &
  1236. (_DT_HELP_FOCUS_FLAG | SCROLL_BAR_FLAGS);
  1237. /*
  1238. * set the visibility flag
  1239. */
  1240. pDAS->neededFlags = pDAS->neededFlags |
  1241. (1 << (event->xvisibility.state + 3));
  1242. } /* End _DtHelpVisibilityCB */
  1243. /*****************************************************************************
  1244. * Function: _DtHelpInitiateClipboard
  1245. *
  1246. * _DtHelpInitiateClipboard
  1247. *
  1248. *****************************************************************************/
  1249. void
  1250. _DtHelpInitiateClipboard (
  1251. XtPointer client_data)
  1252. {
  1253. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  1254. /*
  1255. * check to see if we have the primary selection
  1256. * before trying for the clipboard.
  1257. */
  1258. if (pDAS->primary == True && pDAS->text_selected == True)
  1259. {
  1260. long itemId = 0L; /* clipboard item id */
  1261. long dataId = 0L; /* clipboard data id */
  1262. int status; /* clipboard status */
  1263. XmString clipLabel;
  1264. Display *dpy = XtDisplay(pDAS->dispWid);
  1265. Window win = XtWindow(pDAS->dispWid);
  1266. char *atomName;
  1267. char *tmpString;
  1268. XTextProperty tmpProp;
  1269. /*
  1270. * get the selected text
  1271. */
  1272. _DtCanvasGetSelection (pDAS->canvas,
  1273. (_DtCvSELECTED_TEXT | _DtCvSELECTED_REGION),
  1274. (_DtCvPointer *)(&tmpString));
  1275. /*
  1276. * Using the Xm clipboard facilities,
  1277. * copy the selected text to the clipboard
  1278. */
  1279. if (tmpString != NULL)
  1280. {
  1281. clipLabel = XmStringCreateLocalized ("DT_HELP");
  1282. /*
  1283. * start copy to clipboard
  1284. */
  1285. status = XmClipboardStartCopy(dpy, win, clipLabel,
  1286. XtLastTimestampProcessed(dpy),
  1287. pDAS->dispWid, NULL, &itemId);
  1288. /*
  1289. * no longer need the label
  1290. */
  1291. XmStringFree(clipLabel);
  1292. if (status != ClipboardSuccess)
  1293. {
  1294. free(tmpString);
  1295. return;
  1296. }
  1297. status = XmbTextListToTextProperty(dpy, &tmpString, 1,
  1298. (XICCEncodingStyle)XStdICCTextStyle,
  1299. &tmpProp);
  1300. /*
  1301. * free the original copy of the string and check the results.
  1302. */
  1303. free(tmpString);
  1304. if (status != Success && status <= 0)
  1305. {
  1306. XmClipboardCancelCopy(dpy, win, itemId);
  1307. return;
  1308. }
  1309. atomName = XGetAtomName(dpy, tmpProp.encoding);
  1310. /* move the data to the clipboard */
  1311. status = XmClipboardCopy(dpy, win, itemId, atomName,
  1312. (XtPointer)tmpProp.value, tmpProp.nitems,
  1313. 0, &dataId);
  1314. XtFree(atomName);
  1315. if (status != ClipboardSuccess)
  1316. {
  1317. XmClipboardCancelCopy(dpy, win, itemId);
  1318. XFree((char*)tmpProp.value);
  1319. return;
  1320. }
  1321. /*
  1322. * end the copy to the clipboard
  1323. */
  1324. status = XmClipboardEndCopy (dpy, win, itemId);
  1325. XFree((char*)tmpProp.value);
  1326. }
  1327. }
  1328. } /* End _DtHelpInitiateClipboard */
  1329. /***************************************************************************
  1330. * Function: _DtHelpMoveBtnFocusCB
  1331. *
  1332. * _DtHelpMoveBtnFocusCB tracks the mouse movement for the Selection mechanism
  1333. *
  1334. **************************************************************************/
  1335. void
  1336. _DtHelpMoveBtnFocusCB(
  1337. Widget widget,
  1338. XtPointer client_data,
  1339. XEvent *event )
  1340. {
  1341. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  1342. /*
  1343. * if the policy is XmEXPLICIT, don't want the focus on the scrollbar
  1344. */
  1345. if (event->type == ButtonPress &&
  1346. _XmGetFocusPolicy(XtParent(XtParent(pDAS->dispWid))) != XmPOINTER)
  1347. XmProcessTraversal(pDAS->dispWid, XmTRAVERSE_CURRENT);
  1348. }
  1349. /*****************************************************************************
  1350. * Function: _DtHelpGetClearSelection
  1351. *
  1352. * _DtHelpGetClearSelection - If this routine is called,
  1353. * the user has initiated a selection.
  1354. *
  1355. *****************************************************************************/
  1356. void
  1357. _DtHelpGetClearSelection (
  1358. Widget widget, /* widget id */
  1359. XtPointer client_data ) /* data from applicaiton */
  1360. {
  1361. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  1362. /*
  1363. * If this widget doesn't own the primary selection, get it.
  1364. */
  1365. if (pDAS->primary != True)
  1366. {
  1367. if (XtOwnSelection (widget, XA_PRIMARY,
  1368. XtLastTimestampProcessed(XtDisplay(widget)),
  1369. (XtConvertSelectionProc) ConvertSelectionCB,
  1370. (XtLoseSelectionProc) _DtHelpLoseSelectionCB,
  1371. (XtSelectionDoneProc) NULL))
  1372. {
  1373. pDAS->primary = True;
  1374. pDAS->anchor_time = XtLastTimestampProcessed(XtDisplay(widget));
  1375. }
  1376. }
  1377. else
  1378. _DtHelpClearSelection (client_data);
  1379. } /* End _DtHelpGetClearSelection */