~ubuntu-branches/ubuntu/quantal/openmotif/quantal

« back to all changes in this revision

Viewing changes to lib/Xm/DataF.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Bauer
  • Date: 2010-06-23 12:12:31 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100623121231-u89gxdp51sg9wjj2
Tags: 2.3.0-1
* New Maintainer (Closes: #379258) 
* Acknowledge NMU changes
* New upstream release (Closes: #494375)
* Get rid of security patches as they are already part of new upstream
  release (00-xpmvuln.openmotif.patch, 342092-CVE-2005-3964.patch)
* Bump Standards to 3.8.4
* Added {misc:Depends} to make the package lintian cleaner
* Fix weak-library-dev-dependency by adding ${binary:Version}) for the
  -dev Package of openmotif
* Let package depend on autotools-dev to use newer autotools-helper-files
* Work around an autoconf-bug (Gentoo-Bug #1475)
* Added Client-side anti-aliased fonts support via XFT
* Added UTF-8 and UTF8_STRING atom support
* Ability to show text and pixmaps in Label, LabelGadget and all
  derived widgets
* Support of PNG/JPEG image formats in the same way as XPM is supported
* Increase FILE_OFFSET_BITS to 64 to show files >2GB in file-selector
  Idea taken from Magne Oestlyngen (Closes: #288537)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * (c) Copyright 1989, 1990, 1991, 1992, 1993, 1994 OPEN SOFTWARE FOUNDATION, INC. 
 
3
 * ALL RIGHTS RESERVED 
 
4
*/ 
 
5
/* 
 
6
 * Motif Release 1.2.4
 
7
*/
 
8
/* 
 
9
 * HISTORY
 
10
*/ 
 
11
#ifdef HAVE_CONFIG_H
 
12
#include <config.h>
 
13
#endif
 
14
 
 
15
#ifdef REV_INFO
 
16
#ifndef lint
 
17
static char rcsid[] = "$RCSfile: DataF.c,v $ $Revision: 1.25 $ $Date: 2005/12/19 10:32:35 $"
 
18
#endif
 
19
#endif
 
20
/**  (c) Copyright 1989, 1990, 1991, 1992 HEWLETT-PACKARD COMPANY */
 
21
#include <stdio.h>
 
22
#include <string.h>
 
23
#include <ctype.h>
 
24
#include <limits.h>
 
25
#include <Xm/XmosP.h>
 
26
#include <X11/Xatom.h>
 
27
#include <X11/ShellP.h>
 
28
#include <X11/VendorP.h>
 
29
#include <X11/keysym.h>
 
30
#include <X11/Xresource.h>
 
31
#include "XmI.h"
 
32
#include <Xm/AtomMgr.h>
 
33
#include <Xm/CutPaste.h>
 
34
#include <Xm/DragC.h>
 
35
#include <Xm/DragIcon.h>
 
36
#include <Xm/DropSMgr.h>
 
37
#include <Xm/DropTrans.h>
 
38
#include <Xm/Display.h>
 
39
#include <Xm/ManagerP.h>
 
40
#include <Xm/ScreenP.h>
 
41
#include <Xm/DragIconP.h>
 
42
#include <Xm/TransltnsP.h>
 
43
#include <Xm/DrawP.h>
 
44
 
 
45
#include <Xm/Ext.h>
 
46
#include <Xm/DataFSelP.h>
 
47
#include <Xm/DataFP.h>
 
48
 
 
49
#include <Xm/TraitP.h>
 
50
#include <Xm/AccTextT.h>
 
51
#include <Xm/TransferT.h>
 
52
#include <Xm/SpecRenderT.h>
 
53
#include <Xm/VaSimpleP.h>
 
54
 
 
55
#include "TextFI.h"
 
56
#include "TextFSelI.h"
 
57
#include "XmStringI.h"
 
58
#include "ImageCachI.h"
 
59
 
 
60
#ifdef USE_XFT
 
61
#include <X11/Xft/Xft.h>
 
62
#include "XmRenderTI.h"
 
63
#endif
 
64
 
 
65
/*
 
66
 * Stuff from various internal motif headers that we need to declare
 
67
 */
 
68
 
 
69
#ifndef MAX
 
70
#define MAX(x,y)        ((x) > (y) ? (x) : (y))
 
71
#endif
 
72
 
 
73
#define TEXT_MAX_INSERT_SIZE 64    /* Size of buffer for XLookupString. */
 
74
/*
 
75
 * Various DataField messages macro
 
76
 */
 
77
#define MSG1            _XmMsgDataF_0000
 
78
#define MSG2            _XmMsgDataF_0001
 
79
#define MSG3            _XmMsgDataF_0002
 
80
#define MSG4            _XmMsgDataF_0003
 
81
#define MSG5            _XmMsgDataF_0004
 
82
#define MSG6            _XmMsgDataF_0005
 
83
#define MSG7            _XmMsgDataF_0006
 
84
#define WC_MSG1         _XmMsgDataFWcs_0000
 
85
#define WC_MSG2         _XmMsgDataFWcs_0001
 
86
#define GRABKBDERROR    _XmMsgRowColText_0024
 
87
 
 
88
#ifdef _XmConst
 
89
       #undef _XmConst
 
90
       #define _XmConst
 
91
#else
 
92
       #define _XmConst
 
93
#endif
 
94
 
 
95
static _XmConst char _XmMsgRowColText_0024[] =
 
96
   "XtGrabKeyboard failed";
 
97
 
 
98
static _XmConst char _XmMsgDataF_0000[] =
 
99
   "Invalid cursor position, must be >= 0.";
 
100
 
 
101
static _XmConst char _XmMsgDataF_0001[] =
 
102
   "Invalid columns, must be > 0.";
 
103
 
 
104
static _XmConst char _XmMsgDataF_0002[] =
 
105
   "XmFontListInitFontContext Failed.";
 
106
 
 
107
static _XmConst char _XmMsgDataF_0003[] =
 
108
   "XmFontListGetNextFont Failed.";
 
109
 
 
110
static _XmConst char _XmMsgDataF_0004[] =
 
111
   "Character '%c', not supported in font.  Discarded.";
 
112
 
 
113
static _XmConst char _XmMsgDataF_0005[] =
 
114
   "Traversal_on must always be true.";
 
115
 
 
116
static _XmConst char _XmMsgDataF_0006[] =
 
117
   "Invalid columns, must be >= 0.";
 
118
 
 
119
static _XmConst char _XmMsgDataFWcs_0000[] =
 
120
   "Character '%s', not supported in font.  Discarded.";
 
121
 
 
122
static _XmConst char _XmMsgDataFWcs_0001[] =
 
123
   "Cannot use multibyte locale without a fontset.  Value discarded.";
 
124
 
 
125
#ifdef _NO_PROTO
 
126
extern Boolean _XmParentProcess();
 
127
extern Boolean _XmMgrTraversal();
 
128
extern unsigned char _XmGetFocusPolicy();
 
129
extern void _XmPrimitiveFocusIn();
 
130
extern void _XmPrimitiveEnter();
 
131
extern void _XmPrimitiveLeave();
 
132
extern Boolean _XmGetImage();
 
133
extern Boolean _XmGetIconControlInfo();
 
134
extern unsigned char _XmGetAudibleWarning();
 
135
extern void _XmSetDestination();
 
136
#else
 
137
extern Boolean _XmParentProcess(Widget, XmParentProcessData);
 
138
extern Boolean _XmMgrTraversal(Widget, XmTraversalDirection);
 
139
extern unsigned char _XmGetFocusPolicy(Widget);
 
140
extern void _XmPrimitiveFocusIn(Widget, XEvent *, String *, Cardinal *);
 
141
extern void _XmPrimitiveEnter(Widget, XEvent *, String *, Cardinal *);
 
142
extern void _XmPrimitiveLeave(Widget, XEvent *, String *, Cardinal *);
 
143
extern Boolean _XmGetImage(Screen *, char *, XImage **);
 
144
extern Boolean _XmGetIconControlInfo( 
 
145
                        Screen *screen,
 
146
                        Boolean *useMaskRtn,
 
147
                        Boolean *useMultiColorIconsRtn,
 
148
                        Boolean *useIconFileCacheRtn) ;
 
149
extern unsigned char _XmGetAudibleWarning(Widget);
 
150
extern void _XmSetDestination(Display *, Widget);
 
151
#endif
 
152
 
 
153
/*
 
154
 * Back to the original XmTextField code
 
155
 */
 
156
#define TEXT_INCREMENT 32
 
157
#define PRIM_SCROLL_INTERVAL 100
 
158
#define SEC_SCROLL_INTERVAL 200
 
159
#define XmDYNAMIC_BOOL 255
 
160
 
 
161
#define EventBindings1  _XmDataF_EventBindings1
 
162
#define EventBindings2  _XmDataF_EventBindings2
 
163
#define EventBindings3  _XmDataF_EventBindings3
 
164
 
 
165
static char _XmDataF_EventBindings1[] = "\
 
166
:m <Key>osfPrimaryPaste:cut-primary()\n\
 
167
:a <Key>osfPrimaryPaste:cut-primary()\n\
 
168
:<Key>osfPrimaryPaste:copy-primary()\n\
 
169
:m <Key>osfCut:cut-primary()\n\
 
170
:a <Key>osfCut:cut-primary()\n\
 
171
:<Key>osfCut:cut-clipboard()\n\
 
172
:<Key>osfPaste:paste-clipboard()\n\
 
173
:m <Key>osfCopy:copy-primary()\n\
 
174
:a <Key>osfCopy:copy-primary()\n\
 
175
:<Key>osfCopy:copy-clipboard()\n\
 
176
:s <Key>osfBeginLine:beginning-of-line(extend)\n\
 
177
:<Key>osfBeginLine:beginning-of-line()\n\
 
178
:s <Key>osfEndLine:end-of-line(extend)\n\
 
179
:<Key>osfEndLine:end-of-line()\n\
 
180
:s <Key>osfPageLeft:page-left(extend)\n\
 
181
:<Key>osfPageLeft:page-left()\n\
 
182
:s c<Key>osfPageUp:page-left(extend)\n\
 
183
:c <Key>osfPageUp:page-left()\n\
 
184
:s <Key>osfPageRight:page-right(extend)\n\
 
185
:<Key>osfPageRight:page-right()\n\
 
186
:s c <Key>osfPageDown:page-right(extend)\n\
 
187
:c <Key>osfPageDown:page-right()\n\
 
188
:<Key>osfClear:clear-selection()\n\
 
189
:<Key>osfBackSpace:delete-previous-character()\n\
 
190
:s m <Key>osfDelete:cut-primary()\n\
 
191
:s a <Key>osfDelete:cut-primary()\n\
 
192
:s <Key>osfDelete:cut-clipboard()\n\
 
193
:c <Key>osfDelete:delete-to-end-of-line()\n\
 
194
:<Key>osfDelete:delete-next-character()\n";
 
195
 
 
196
static char _XmDataF_EventBindings2[] = "\
 
197
:c m <Key>osfInsert:copy-primary()\n\
 
198
:c a <Key>osfInsert:copy-primary()\n\
 
199
:s <Key>osfInsert:paste-clipboard()\n\
 
200
:c <Key>osfInsert:copy-clipboard()\n\
 
201
:s <Key>osfSelect:key-select()\n\
 
202
:<Key>osfSelect:set-anchor()\n\
 
203
:<Key>osfActivate:activate()\n\
 
204
:<Key>osfAddMode:toggle-add-mode()\n\
 
205
:<Key>osfHelp:Help()\n\
 
206
:<Key>osfCancel:process-cancel()\n\
 
207
:s c <Key>osfLeft:backward-word(extend)\n\
 
208
:c <Key>osfLeft:backward-word()\n\
 
209
:s <Key>osfLeft:key-select(left)\n\
 
210
:<Key>osfLeft:backward-character()\n\
 
211
:s c <Key>osfRight:forward-word(extend)\n\
 
212
:c <Key>osfRight:forward-word()\n\
 
213
:s <Key>osfRight:key-select(right)\n\
 
214
:<Key>osfRight:forward-character()\n\
 
215
:<Key>osfUp:traverse-prev()\n\
 
216
:<Key>osfDown:traverse-next()\n\
 
217
c ~m ~a <Key>slash:select-all()\n\
 
218
c ~m ~a <Key>backslash:deselect-all()\n\
 
219
s ~m ~a <Key>Tab:prev-tab-group()\n\
 
220
~m ~a <Key>Tab:next-tab-group()\n\
 
221
~s ~m ~a <Key>Return:activate()\n\
 
222
c ~s ~m ~a <Key>space:set-anchor()\n\
 
223
c s ~m ~a <Key>space:key-select()\n\
 
224
s ~c ~m ~a <Key>space:self-insert()\n\
 
225
<Key>:self-insert()\n";
 
226
 
 
227
static char _XmDataF_EventBindings3[] = "\
 
228
<Unmap>:unmap()\n\
 
229
<Enter>:enter()\n\
 
230
<Leave>:leave()\n\
 
231
<FocusIn>:focusIn()\n\
 
232
<FocusOut>:focusOut()\n\
 
233
~c s ~m ~a <Btn1Down>:extend-start()\n\
 
234
c ~s ~m ~a <Btn1Down>:move-destination()\n\
 
235
~c ~s ~m ~a <Btn1Down>:grab-focus()\n\
 
236
~c ~m ~a <Btn1Motion>:extend-adjust()\n\
 
237
~c ~m ~a <Btn1Up>:extend-end()\n\
 
238
<Btn2Down>:process-bdrag()\n\
 
239
m ~a <Btn2Motion>:secondary-adjust()\n\
 
240
~m a <Btn2Motion>:secondary-adjust()\n\
 
241
~s <Btn2Up>:copy-to()\n\
 
242
~c <Btn2Up>:move-to()";
 
243
 
 
244
static char df_translations[] = 
 
245
"s ~m ~a <Key>Tab:ValidateAndMove(prev)\n\
 
246
~m ~a<Key>Tab:ValidateAndMove(next)";
 
247
 
 
248
typedef struct {
 
249
    Boolean has_destination;
 
250
    XmTextPosition position;
 
251
    int replace_length;
 
252
    Boolean quick_key;
 
253
} TextFDestDataRec, *TextFDestData;
 
254
 
 
255
typedef struct {
 
256
    XmDataFieldWidget tf;
 
257
} TextFGCDataRec, *TextFGCData;
 
258
 
 
259
 
 
260
/********    Static Function Declarations    ********/
 
261
#ifdef _NO_PROTO
 
262
 
 
263
static void df_ValidateAndMove() ;
 
264
static int _XmDataFieldCountCharacters() ;
 
265
static void df_MakeCopy() ;
 
266
static void df_WcsMakeCopy() ;
 
267
static void df_FreeContextData() ;
 
268
static TextFDestData df_GetTextFDestData() ;
 
269
static void df_SetDropContext() ;
 
270
static void df_DeleteDropContext() ;
 
271
static TextFGCData df_GetTextFGCData() ;
 
272
static _XmHighlightRec * df_FindHighlight() ;
 
273
static void df_InsertHighlight() ;
 
274
static void DataFieldSetHighlight() ;
 
275
static Boolean df_GetXYFromPos() ;
 
276
static Boolean df_CurrentCursorState() ;
 
277
static void df_PaintCursor() ;
 
278
static int _XmGetImage();
 
279
static void df_BlinkInsertionPoint() ;
 
280
static void df_HandleTimer() ;
 
281
static void df_ChangeBlinkBehavior() ;
 
282
static void df_GetRect() ;
 
283
static void df_CheckHasRect() ;
 
284
static void df_XmSetFullGC() ;
 
285
static void df_XmSetMarginGC() ;
 
286
static void df_XmResetSaveGC() ;
 
287
static void df_XmSetNormGC() ;
 
288
static void df_XmSetInvGC() ;
 
289
static void df_DrawText() ;
 
290
static int df_FindPixelLength() ;
 
291
static void df_DrawTextSegment() ;
 
292
static void df_RedisplayText() ;
 
293
static void df_ComputeSize() ;
 
294
static XtGeometryResult df_TryResize() ;
 
295
static Boolean df_AdjustText() ;
 
296
static void df_AdjustSize() ;
 
297
static Boolean df_ModifyVerify() ;
 
298
static void df_ResetClipOrigin() ;
 
299
static void df_InvertImageGC() ;
 
300
static void df_ResetImageGC() ;
 
301
static void df_SetCursorPosition() ;
 
302
static void df_VerifyBounds() ;
 
303
static XmTextPosition df_GetPosFromX() ;
 
304
static XmTextPosition RightAlignedGetPosFromX() ;
 
305
static Boolean df_SetDestination() ;
 
306
static Boolean df_VerifyLeave() ;
 
307
static Boolean _XmDataFieldIsWordBoundary() ;
 
308
static int _XmGetImage(Screen *, char *, XImage **);
 
309
static Boolean _XmDataFieldIsWSpace() ;
 
310
static void df_FindWord() ;
 
311
static void df_FindPrevWord() ;
 
312
static void df_FindNextWord() ;
 
313
static void df_CheckDisjointSelection() ;
 
314
static Boolean df_NeedsPendingDelete() ;
 
315
static Boolean df_NeedsPendingDeleteDisjoint() ;
 
316
static Time df_GetServerTime() ;
 
317
static void df_InsertChar() ;
 
318
static void df_InsertString() ;
 
319
static void df_DeletePrevChar() ;
 
320
static void df_DeleteNextChar() ;
 
321
static void df_DeletePrevWord() ;
 
322
static void df_DeleteNextWord() ;
 
323
static void df_DeleteToEndOfLine() ;
 
324
static void df_DeleteToStartOfLine() ;
 
325
static void df_ProcessCancel() ;
 
326
static void df_Activate() ;
 
327
static void df_SetAnchorBalancing() ;
 
328
static void df_SetNavigationAnchor() ;
 
329
static void df_CompleteNavigation() ;
 
330
static void df_SimpleMovement() ;
 
331
static void df_BackwardChar() ;
 
332
static void df_ForwardChar() ;
 
333
static void df_BackwardWord() ;
 
334
static void df_ForwardWord() ;
 
335
static void df_EndOfLine() ;
 
336
static void df_BeginningOfLine() ;
 
337
static void df_SetSelection() ;
 
338
static void df_ProcessHorizontalParams() ;
 
339
static void df_ProcessSelectParams() ;
 
340
static void df_KeySelection() ;
 
341
static void df_TextFocusIn() ;
 
342
static void df_TextFocusOut() ;
 
343
static void df_SetScanIndex() ;
 
344
static void df_ExtendScanSelection() ;
 
345
static void df_SetScanSelection() ;
 
346
static void df_StartPrimary() ;
 
347
static void df_MoveDestination() ;
 
348
static void df_ExtendPrimary() ;
 
349
static void df_ExtendEnd() ;
 
350
static void df_DoExtendedSelection() ;
 
351
static void df_DoSecondaryExtend() ;
 
352
static void df_BrowseScroll() ;
 
353
static Boolean df_CheckTimerScrolling() ;
 
354
static void df_RestorePrimaryHighlight() ;
 
355
static void df_StartDrag() ;
 
356
static void df_StartSecondary() ;
 
357
static void df_ProcessBDrag() ;
 
358
static void df_ExtendSecondary() ;
 
359
static void df_DoStuff() ;
 
360
static void df_Stuff() ;
 
361
static void df_HandleSelectionReplies() ;
 
362
static void df_SecondaryNotify() ;
 
363
static void df_HandleTargets() ;
 
364
static void df_ProcessBDragRelease() ;
 
365
static void df_ProcessCopy() ;
 
366
static void df_ProcessMove() ;
 
367
static void df_DeleteSelection() ;
 
368
static void df_ClearSelection() ;
 
369
static void df_PageRight() ;
 
370
static void df_PageLeft() ;
 
371
static void df_CopyPrimary() ;
 
372
static void df_CutPrimary() ;
 
373
static void df_SetAnchor() ;
 
374
static void df_ToggleOverstrike() ;
 
375
static void df_ToggleAddMode() ;
 
376
static void df_SelectAll() ;
 
377
static void df_DeselectAll() ;
 
378
static void df_VoidAction() ;
 
379
static void df_CutClipboard() ;
 
380
static void df_CopyClipboard() ;
 
381
static void df_PasteClipboard() ;
 
382
static void df_TraverseDown() ;
 
383
static void df_TraverseUp() ;
 
384
static void df_TraverseHome() ;
 
385
static void df_TraverseNextTabGroup() ;
 
386
static void df_TraversePrevTabGroup() ;
 
387
static void df_TextEnter() ;
 
388
static void df_TextLeave() ;
 
389
static void df_ClassPartInitialize() ;
 
390
static void df_Validates() ;
 
391
static Boolean df_LoadFontMetrics() ;
 
392
static void df_ValidateString() ;
 
393
static void df_InitializeTextStruct() ;
 
394
static Pixmap df_GetClipMask() ;
 
395
static void df_LoadGCs() ;
 
396
static void df_MakeIBeamOffArea() ;
 
397
static void df_MakeIBeamStencil() ;
 
398
static void df_MakeAddModeCursor() ;
 
399
static void df_MakeCursors() ;
 
400
static void df_DropDestroyCB() ;
 
401
static void df_DropTransferCallback() ;
 
402
static void df_HandleDrop() ;
 
403
static void df_DragProcCallback() ;
 
404
static void df_DropProcCallback() ;
 
405
static void df_RegisterDropSite() ;
 
406
static void df_Initialize() ;
 
407
static void df_Realize() ;
 
408
static void df_Destroy() ;
 
409
static void df_Resize() ;
 
410
static XtGeometryResult df_QueryGeometry() ;
 
411
static void DataFieldExpose() ;
 
412
static Boolean df_SetValues() ;
 
413
static Boolean DataFieldGetBaselines() ;
 
414
static Boolean DataFieldGetDisplayRect() ;
 
415
static void DataFieldMarginsProc() ;
 
416
static Boolean DataFieldRemove();
 
417
static void PictureVerifyCallback();
 
418
static void ClassInit();
 
419
static void XmDataFieldSetStringWcs();
 
420
#else
 
421
static void df_ValidateAndMove(
 
422
                               Widget w,
 
423
                               XEvent *ev,
 
424
                               String *args,
 
425
                               Cardinal *nargs) ;
 
426
static int _XmDataFieldCountCharacters( 
 
427
                        XmDataFieldWidget tf,
 
428
                        char *ptr,
 
429
                        int n_bytes) ;
 
430
static void df_MakeCopy( 
 
431
                        Widget w,
 
432
                        int n,
 
433
                        XtArgVal *value) ;
 
434
static void df_WcsMakeCopy( 
 
435
                        Widget w,
 
436
                        int n,
 
437
                        XtArgVal *value) ;
 
438
static void df_FreeContextData( 
 
439
                        Widget w,
 
440
                        XtPointer clientData,
 
441
                        XtPointer callData) ;
 
442
static TextFDestData df_GetTextFDestData( 
 
443
                        Widget w) ;
 
444
static void df_SetDropContext( 
 
445
                        Widget w) ;
 
446
static void df_DeleteDropContext( 
 
447
                        Widget w) ;
 
448
static TextFGCData df_GetTextFGCData( 
 
449
                        Widget w) ;
 
450
static _XmHighlightRec * df_FindHighlight( 
 
451
                        XmDataFieldWidget w,
 
452
                        XmTextPosition position) ;
 
453
static void df_InsertHighlight( 
 
454
                        XmDataFieldWidget w,
 
455
                        XmTextPosition position,
 
456
                        XmHighlightMode mode) ;
 
457
static void DataFieldSetHighlight( 
 
458
                        XmDataFieldWidget tf,
 
459
                        XmTextPosition left,
 
460
                        XmTextPosition right,
 
461
                        XmHighlightMode mode) ;
 
462
static Boolean df_GetXYFromPos( 
 
463
                        XmDataFieldWidget tf,
 
464
                        XmTextPosition position,
 
465
                        Position *x,
 
466
                        Position *y) ;
 
467
static Boolean df_CurrentCursorState( 
 
468
                        XmDataFieldWidget tf) ;
 
469
static void df_PaintCursor( 
 
470
                        XmDataFieldWidget tf) ;
 
471
static void df_BlinkInsertionPoint( 
 
472
                        XmDataFieldWidget tf) ;
 
473
static void df_HandleTimer( 
 
474
                        XtPointer closure,
 
475
                        XtIntervalId *id) ;
 
476
 
 
477
static void df_ChangeBlinkBehavior( 
 
478
                        XmDataFieldWidget tf,
 
479
#if NeedWidePrototypes
 
480
                        int turn_on) ;
 
481
#else
 
482
                        Boolean turn_on) ;
 
483
#endif /* NeedWidePrototypes */
 
484
 
 
485
static void df_GetRect( 
 
486
                        XmDataFieldWidget tf,
 
487
                        XRectangle *rect) ;
 
488
static void df_CheckHasRect( 
 
489
                        XmDataFieldWidget tf) ;
 
490
static void df_XmSetFullGC( 
 
491
                        XmDataFieldWidget tf,
 
492
                        GC gc) ;
 
493
static void df_XmSetMarginGC( 
 
494
                        XmDataFieldWidget tf,
 
495
                        GC gc) ;
 
496
static void df_XmResetSaveGC( 
 
497
                        XmDataFieldWidget tf,
 
498
                        GC gc) ;
 
499
static void df_XmSetNormGC( 
 
500
                        XmDataFieldWidget tf,
 
501
                        GC gc,
 
502
#if NeedWidePrototypes
 
503
                        int change_stipple,
 
504
                        int stipple) ;
 
505
#else
 
506
                        Boolean change_stipple,
 
507
                        Boolean stipple) ;
 
508
#endif /* NeedWidePrototypes */
 
509
 
 
510
static void df_XmSetInvGC( 
 
511
                        XmDataFieldWidget tf,
 
512
                        GC gc) ;
 
513
static void df_DrawText( 
 
514
                        XmDataFieldWidget tf,
 
515
                        GC gc,
 
516
                        int x,
 
517
                        int y,
 
518
                        char *string,
 
519
                        int length) ;
 
520
static int df_FindPixelLength( 
 
521
                        XmDataFieldWidget tf,
 
522
                        char *string,
 
523
                        int length) ;
 
524
 
 
525
static void df_DrawTextSegment( 
 
526
                        XmDataFieldWidget tf,
 
527
                        XmHighlightMode mode,
 
528
                        XmTextPosition prev_seg_start,
 
529
                        XmTextPosition seg_start,
 
530
                        XmTextPosition seg_end,
 
531
                        XmTextPosition next_seg,
 
532
#if NeedWidePrototypes
 
533
                        int stipple,
 
534
#else
 
535
                        Boolean stipple,
 
536
#endif /* NeedWidePrototypes */
 
537
                        int y,
 
538
                        int *x) ;
 
539
 
 
540
static void df_RedisplayText( 
 
541
                        XmDataFieldWidget tf,
 
542
                        XmTextPosition start,
 
543
                        XmTextPosition end) ;
 
544
static void df_ComputeSize( 
 
545
                        XmDataFieldWidget tf,
 
546
                        Dimension *width,
 
547
                        Dimension *height) ;
 
548
 
 
549
static XtGeometryResult df_TryResize( 
 
550
                        XmDataFieldWidget tf,
 
551
#if NeedWidePrototypes
 
552
                        int width,
 
553
                        int height) ;
 
554
#else
 
555
                        Dimension width,
 
556
                        Dimension height) ;
 
557
#endif /* NeedWidePrototypes */
 
558
 
 
559
static Boolean df_AdjustText( 
 
560
                        XmDataFieldWidget tf,
 
561
                        XmTextPosition position,
 
562
#if NeedWidePrototypes
 
563
                        int flag) ;
 
564
#else
 
565
                        Boolean flag) ;
 
566
#endif /* NeedWidePrototypes */
 
567
 
 
568
static void df_AdjustSize( 
 
569
                        XmDataFieldWidget tf) ;
 
570
static Boolean df_ModifyVerify( 
 
571
                        XmDataFieldWidget tf,
 
572
                        XEvent *event,
 
573
                        XmTextPosition *replace_prev,
 
574
                        XmTextPosition *replace_next,
 
575
                        char **insert,
 
576
                        int *insert_length,
 
577
                        XmTextPosition *newInsert,
 
578
                        int *free_insert) ;
 
579
 
 
580
static void df_ResetClipOrigin( 
 
581
                        XmDataFieldWidget tf,
 
582
#if NeedWidePrototypes
 
583
                        int clip_mask_reset) ;
 
584
#else
 
585
                        Boolean clip_mask_reset) ;
 
586
#endif /* NeedWidePrototypes */
 
587
 
 
588
static void df_InvertImageGC( 
 
589
                        XmDataFieldWidget tf) ;
 
590
static void df_ResetImageGC( 
 
591
                        XmDataFieldWidget tf) ;
 
592
static void df_SetCursorPosition( 
 
593
                        XmDataFieldWidget tf,
 
594
                        XEvent *event,
 
595
                        XmTextPosition position,
 
596
#if NeedWidePrototypes
 
597
                        int adjust_flag,
 
598
                        int call_cb,
 
599
                        int set_dest) ;
 
600
#else
 
601
                        Boolean adjust_flag,
 
602
                        Boolean call_cb,
 
603
                        Boolean set_dest) ;
 
604
#endif /* NeedWidePrototypes */
 
605
 
 
606
static void df_VerifyBounds( 
 
607
                        XmDataFieldWidget tf,
 
608
                        XmTextPosition *from,
 
609
                        XmTextPosition *to) ;
 
610
static XmTextPosition df_GetPosFromX( 
 
611
                        XmDataFieldWidget tf,
 
612
#if NeedWidePrototypes
 
613
                        int x) ;
 
614
#else
 
615
                        Position x) ;
 
616
#endif /* NeedWidePrototypes */
 
617
 
 
618
static XmTextPosition RightAlignedGetPosFromX( 
 
619
                        XmDataFieldWidget tf,
 
620
#if NeedWidePrototypes
 
621
                        int x) ;
 
622
#else
 
623
                        Position x) ;
 
624
#endif /* NeedWidePrototypes */
 
625
 
 
626
static Boolean df_SetDestination( 
 
627
                        Widget w,
 
628
                        XmTextPosition position,
 
629
 
 
630
#if NeedWidePrototypes
 
631
                        int disown,
 
632
#else
 
633
                        Boolean disown,
 
634
#endif /* NeedWidePrototypes */
 
635
                        Time set_time) ;
 
636
 
 
637
static Boolean df_VerifyLeave( 
 
638
                        XmDataFieldWidget tf,
 
639
                        XEvent *event) ;
 
640
static Boolean _XmDataFieldIsWordBoundary( 
 
641
                        XmDataFieldWidget tf,
 
642
                        XmTextPosition pos1,
 
643
                        XmTextPosition pos2) ;
 
644
static Boolean _XmDataFieldIsWSpace( 
 
645
                        wchar_t wide_char,
 
646
                        wchar_t *white_space,
 
647
                        int num_entries) ;
 
648
static void df_FindWord( 
 
649
                        XmDataFieldWidget tf,
 
650
                        XmTextPosition begin,
 
651
                        XmTextPosition *left,
 
652
                        XmTextPosition *right) ;
 
653
static void df_FindPrevWord( 
 
654
                        XmDataFieldWidget tf,
 
655
                        XmTextPosition *left,
 
656
                        XmTextPosition *right) ;
 
657
static void df_FindNextWord( 
 
658
                        XmDataFieldWidget tf,
 
659
                        XmTextPosition *left,
 
660
                        XmTextPosition *right) ;
 
661
static void df_CheckDisjointSelection( 
 
662
                        Widget w,
 
663
                        XmTextPosition position,
 
664
                        Time sel_time) ;
 
665
static Boolean df_NeedsPendingDelete( 
 
666
                        XmDataFieldWidget tf) ;
 
667
static Boolean df_NeedsPendingDeleteDisjoint( 
 
668
                        XmDataFieldWidget tf) ;
 
669
static Time df_GetServerTime( 
 
670
                        Widget w) ;
 
671
static void df_InsertChar( 
 
672
                        Widget w,
 
673
                        XEvent *event,
 
674
                        char **params,
 
675
                        Cardinal *num_params) ;
 
676
static void df_InsertString( 
 
677
                        Widget w,
 
678
                        XEvent *event,
 
679
                        char **params,
 
680
                        Cardinal *num_params) ;
 
681
static void df_DeletePrevChar( 
 
682
                        Widget w,
 
683
                        XEvent *event,
 
684
                        char **params,
 
685
                        Cardinal *num_params) ;
 
686
static void df_DeleteNextChar( 
 
687
                        Widget w,
 
688
                        XEvent *event,
 
689
                        char **params,
 
690
                        Cardinal *num_params) ;
 
691
static void df_DeletePrevWord( 
 
692
                        Widget w,
 
693
                        XEvent *event,
 
694
                        char **params,
 
695
                        Cardinal *num_params) ;
 
696
static void df_DeleteNextWord( 
 
697
                        Widget w,
 
698
                        XEvent *event,
 
699
                        char **params,
 
700
                        Cardinal *num_params) ;
 
701
static void df_DeleteToEndOfLine( 
 
702
                        Widget w,
 
703
                        XEvent *event,
 
704
                        char **params,
 
705
                        Cardinal *num_params) ;
 
706
static void df_DeleteToStartOfLine( 
 
707
                        Widget w,
 
708
                        XEvent *event,
 
709
                        char **params,
 
710
                        Cardinal *num_params) ;
 
711
static void df_ProcessCancel( 
 
712
                        Widget w,
 
713
                        XEvent *event,
 
714
                        char **params,
 
715
                        Cardinal *num_params) ;
 
716
static void df_Activate( 
 
717
                        Widget w,
 
718
                        XEvent *event,
 
719
                        char **params,
 
720
                        Cardinal *num_params) ;
 
721
static void df_SetAnchorBalancing( 
 
722
                        XmDataFieldWidget tf,
 
723
                        XmTextPosition position) ;
 
724
 
 
725
static void df_SetNavigationAnchor( 
 
726
                        XmDataFieldWidget tf,
 
727
                        XmTextPosition position,
 
728
#if NeedWidePrototypes
 
729
                        int extend) ;
 
730
#else
 
731
                        Boolean extend) ;
 
732
#endif /* NeedWidePrototypes */
 
733
 
 
734
static void df_CompleteNavigation( 
 
735
                        XmDataFieldWidget tf,
 
736
                        XEvent *event,
 
737
                        XmTextPosition position,
 
738
                        Time time,
 
739
#if NeedWidePrototypes
 
740
                        int extend) ;
 
741
#else
 
742
                        Boolean extend) ;
 
743
#endif /* NeedWidePrototypes */
 
744
 
 
745
static void df_SimpleMovement( 
 
746
                        Widget w,
 
747
                        XEvent *event,
 
748
                        String *params,
 
749
                        Cardinal *num_params,
 
750
                        XmTextPosition cursorPos,
 
751
                        XmTextPosition position) ;
 
752
static void df_BackwardChar( 
 
753
                        Widget w,
 
754
                        XEvent *event,
 
755
                        char **params,
 
756
                        Cardinal *num_params) ;
 
757
static void df_ForwardChar( 
 
758
                        Widget w,
 
759
                        XEvent *event,
 
760
                        char **params,
 
761
                        Cardinal *num_params) ;
 
762
static void df_BackwardWord( 
 
763
                        Widget w,
 
764
                        XEvent *event,
 
765
                        char **params,
 
766
                        Cardinal *num_params) ;
 
767
static void df_ForwardWord( 
 
768
                        Widget w,
 
769
                        XEvent *event,
 
770
                        char **params,
 
771
                        Cardinal *num_params) ;
 
772
static void df_EndOfLine( 
 
773
                        Widget w,
 
774
                        XEvent *event,
 
775
                        char **params,
 
776
                        Cardinal *num_params) ;
 
777
static void df_BeginningOfLine( 
 
778
                        Widget w,
 
779
                        XEvent *event,
 
780
                        char **params,
 
781
                        Cardinal *num_params) ;
 
782
 
 
783
static void df_SetSelection( 
 
784
                        XmDataFieldWidget tf,
 
785
                        XmTextPosition left,
 
786
                        XmTextPosition right,
 
787
#if NeedWidePrototypes
 
788
                        int redisplay) ;
 
789
#else
 
790
                        Boolean redisplay) ;
 
791
#endif /* NeedWidePrototypes */
 
792
 
 
793
static void df_ProcessHorizontalParams( 
 
794
                        Widget w,
 
795
                        XEvent *event,
 
796
                        char **params,
 
797
                        Cardinal *num_params,
 
798
                        XmTextPosition *left,
 
799
                        XmTextPosition *right,
 
800
                        XmTextPosition *position) ;
 
801
static void df_ProcessSelectParams( 
 
802
                        Widget w,
 
803
                        XEvent *event,
 
804
                        XmTextPosition *left,
 
805
                        XmTextPosition *right,
 
806
                        XmTextPosition *position) ;
 
807
static void df_KeySelection( 
 
808
                        Widget w,
 
809
                        XEvent *event,
 
810
                        char **params,
 
811
                        Cardinal *num_params) ;
 
812
static void df_TextFocusIn( 
 
813
                        Widget w,
 
814
                        XEvent *event,
 
815
                        char **params,
 
816
                        Cardinal *num_params) ;
 
817
static void df_TextFocusOut( 
 
818
                        Widget w,
 
819
                        XEvent *event,
 
820
                        char **params,
 
821
                        Cardinal *num_params) ;
 
822
static void df_SetScanIndex( 
 
823
                        XmDataFieldWidget tf,
 
824
                        XEvent *event) ;
 
825
static void df_ExtendScanSelection( 
 
826
                        XmDataFieldWidget tf,
 
827
                        XEvent *event) ;
 
828
static void df_SetScanSelection( 
 
829
                        XmDataFieldWidget tf,
 
830
                        XEvent *event) ;
 
831
static void df_StartPrimary( 
 
832
                        Widget w,
 
833
                        XEvent *event,
 
834
                        char **params,
 
835
                        Cardinal *num_params) ;
 
836
static void df_MoveDestination( 
 
837
                        Widget w,
 
838
                        XEvent *event,
 
839
                        char **params,
 
840
                        Cardinal *num_params) ;
 
841
static void df_ExtendPrimary( 
 
842
                        Widget w,
 
843
                        XEvent *event,
 
844
                        char **params,
 
845
                        Cardinal *num_params) ;
 
846
static void df_ExtendEnd( 
 
847
                        Widget w,
 
848
                        XEvent *event,
 
849
                        char **params,
 
850
                        Cardinal *num_params) ;
 
851
static void df_DoExtendedSelection( 
 
852
                        Widget w,
 
853
                        Time time) ;
 
854
static void df_DoSecondaryExtend( 
 
855
                        Widget w,
 
856
                        Time ev_time) ;
 
857
static void df_BrowseScroll( 
 
858
                        XtPointer closure,
 
859
                        XtIntervalId *id) ;
 
860
static Boolean df_CheckTimerScrolling( 
 
861
                        Widget w,
 
862
                        XEvent *event) ;
 
863
static void df_RestorePrimaryHighlight( 
 
864
                        XmDataFieldWidget tf,
 
865
                        XmTextPosition prim_left,
 
866
                        XmTextPosition prim_right) ;
 
867
static void df_StartDrag( 
 
868
                        Widget w,
 
869
                        XEvent *event,
 
870
                        String *params,
 
871
                        Cardinal *num_params) ;
 
872
static void df_StartSecondary( 
 
873
                        Widget w,
 
874
                        XEvent *event,
 
875
                        char **params,
 
876
                        Cardinal *num_params) ;
 
877
static void df_ProcessBDrag( 
 
878
                        Widget w,
 
879
                        XEvent *event,
 
880
                        char **params,
 
881
                        Cardinal *num_params) ;
 
882
static void df_ExtendSecondary( 
 
883
                        Widget w,
 
884
                        XEvent *event,
 
885
                        char **params,
 
886
                        Cardinal *num_params) ;
 
887
static void df_DoStuff( 
 
888
                        Widget w,
 
889
                        XtPointer closure,
 
890
                        Atom *seltype,
 
891
                        Atom *type,
 
892
                        XtPointer value,
 
893
                        unsigned long *length,
 
894
                        int *format) ;
 
895
static void df_Stuff( 
 
896
                        Widget w,
 
897
                        XEvent *event,
 
898
                        char **params,
 
899
                        Cardinal *num_params) ;
 
900
static void df_HandleSelectionReplies( 
 
901
                        Widget w,
 
902
                        XtPointer closure,
 
903
                        XEvent *event,
 
904
                        Boolean *cont) ;
 
905
static void df_SecondaryNotify( 
 
906
                        Widget w,
 
907
                        XEvent *event,
 
908
                        char **params,
 
909
                        Cardinal *num_params) ;
 
910
static void df_HandleTargets( 
 
911
                        Widget w,
 
912
                        XtPointer closure,
 
913
                        Atom *seltype,
 
914
                        Atom *type,
 
915
                        XtPointer value,
 
916
                        unsigned long *length,
 
917
                        int *format) ;
 
918
static void df_ProcessBDragRelease( 
 
919
                        Widget w,
 
920
                        XEvent *event,
 
921
                        String *params,
 
922
                        Cardinal *num_params) ;
 
923
static void df_ProcessCopy( 
 
924
                        Widget w,
 
925
                        XEvent *event,
 
926
                        char **params,
 
927
                        Cardinal *num_params) ;
 
928
static void df_ProcessMove( 
 
929
                        Widget w,
 
930
                        XEvent *event,
 
931
                        char **params,
 
932
                        Cardinal *num_params) ;
 
933
static void df_DeleteSelection( 
 
934
                        Widget w,
 
935
                        XEvent *event,
 
936
                        char **params,
 
937
                        Cardinal *num_params) ;
 
938
static void df_ClearSelection( 
 
939
                        Widget w,
 
940
                        XEvent *event,
 
941
                        char **params,
 
942
                        Cardinal *num_params) ;
 
943
static void df_PageRight( 
 
944
                        Widget w,
 
945
                        XEvent *event,
 
946
                        char **params,
 
947
                        Cardinal *num_params) ;
 
948
static void df_PageLeft( 
 
949
                        Widget w,
 
950
                        XEvent *event,
 
951
                        char **params,
 
952
                        Cardinal *num_params) ;
 
953
static void df_CopyPrimary( 
 
954
                        Widget w,
 
955
                        XEvent *event,
 
956
                        char **params,
 
957
                        Cardinal *num_params) ;
 
958
static void df_CutPrimary( 
 
959
                        Widget w,
 
960
                        XEvent *event,
 
961
                        char **params,
 
962
                        Cardinal *num_params) ;
 
963
static void df_SetAnchor( 
 
964
                        Widget w,
 
965
                        XEvent *event,
 
966
                        char **params,
 
967
                        Cardinal *num_params) ;
 
968
static void df_ToggleOverstrike( 
 
969
                        Widget w,
 
970
                        XEvent *event,
 
971
                        char **params,
 
972
                        Cardinal *num_params) ;
 
973
static void df_ToggleAddMode( 
 
974
                        Widget w,
 
975
                        XEvent *event,
 
976
                        char **params,
 
977
                        Cardinal *num_params) ;
 
978
static void df_SelectAll( 
 
979
                        Widget w,
 
980
                        XEvent *event,
 
981
                        char **params,
 
982
                        Cardinal *num_params) ;
 
983
static void df_DeselectAll( 
 
984
                        Widget w,
 
985
                        XEvent *event,
 
986
                        char **params,
 
987
                        Cardinal *num_params) ;
 
988
static void df_VoidAction( 
 
989
                        Widget w,
 
990
                        XEvent *event,
 
991
                        char **params,
 
992
                        Cardinal *num_params) ;
 
993
static void df_CutClipboard( 
 
994
                        Widget w,
 
995
                        XEvent *event,
 
996
                        char **params,
 
997
                        Cardinal *num_params) ;
 
998
static void df_CopyClipboard( 
 
999
                        Widget w,
 
1000
                        XEvent *event,
 
1001
                        char **params,
 
1002
                        Cardinal *num_params) ;
 
1003
static void df_PasteClipboard( 
 
1004
                        Widget w,
 
1005
                        XEvent *event,
 
1006
                        char **params,
 
1007
                        Cardinal *num_params) ;
 
1008
static void df_TraverseDown( 
 
1009
                        Widget w,
 
1010
                        XEvent *event,
 
1011
                        char **params,
 
1012
                        Cardinal *num_params) ;
 
1013
static void df_TraverseUp( 
 
1014
                        Widget w,
 
1015
                        XEvent *event,
 
1016
                        char **params,
 
1017
                        Cardinal *num_params) ;
 
1018
static void df_TraverseHome( 
 
1019
                        Widget w,
 
1020
                        XEvent *event,
 
1021
                        char **params,
 
1022
                        Cardinal *num_params) ;
 
1023
static void df_TraverseNextTabGroup( 
 
1024
                        Widget w,
 
1025
                        XEvent *event,
 
1026
                        char **params,
 
1027
                        Cardinal *num_params) ;
 
1028
static void df_TraversePrevTabGroup( 
 
1029
                        Widget w,
 
1030
                        XEvent *event,
 
1031
                        char **params,
 
1032
                        Cardinal *num_params) ;
 
1033
static void df_TextEnter( 
 
1034
                        Widget w,
 
1035
                        XEvent *event,
 
1036
                        String *params,
 
1037
                        Cardinal *num_params) ;
 
1038
static void df_TextLeave( 
 
1039
                        Widget w,
 
1040
                        XEvent *event,
 
1041
                        String *params,
 
1042
                        Cardinal *num_params) ;
 
1043
static void df_ClassPartInitialize( 
 
1044
                        WidgetClass w_class) ;
 
1045
static void df_Validates( 
 
1046
                        XmDataFieldWidget tf) ;
 
1047
static Boolean df_LoadFontMetrics( 
 
1048
                        XmDataFieldWidget tf) ;
 
1049
 
 
1050
static void df_ValidateString( 
 
1051
                        XmDataFieldWidget tf,
 
1052
                        char *value,
 
1053
#if NeedWidePrototypes
 
1054
                        int is_wchar) ;
 
1055
#else
 
1056
                        Boolean is_wchar) ;
 
1057
#endif /* NeedWidePrototypes */
 
1058
 
 
1059
static void df_InitializeTextStruct( 
 
1060
                        XmDataFieldWidget tf) ;
 
1061
static Pixmap df_GetClipMask( 
 
1062
                        XmDataFieldWidget tf,
 
1063
                        char *pixmap_name) ;
 
1064
static void df_LoadGCs( 
 
1065
                        XmDataFieldWidget tf,
 
1066
                        Pixel background,
 
1067
                        Pixel foreground) ;
 
1068
 
 
1069
static void df_MakeIBeamOffArea( 
 
1070
                        XmDataFieldWidget tf,
 
1071
#if NeedWidePrototypes
 
1072
                        int width,
 
1073
                        int height) ;
 
1074
#else
 
1075
                        Dimension width,
 
1076
                        Dimension height) ;
 
1077
#endif /* NeedWidePrototypes */
 
1078
 
 
1079
static void df_MakeIBeamStencil( 
 
1080
                        XmDataFieldWidget tf,
 
1081
                        int line_width) ;
 
1082
static void df_MakeAddModeCursor( 
 
1083
                        XmDataFieldWidget tf,
 
1084
                        int line_width) ;
 
1085
static void df_MakeCursors( 
 
1086
                        XmDataFieldWidget tf) ;
 
1087
static void df_DropDestroyCB( 
 
1088
                        Widget w,
 
1089
                        XtPointer clientData,
 
1090
                        XtPointer callData) ;
 
1091
static void df_DropTransferCallback( 
 
1092
                        Widget w,
 
1093
                        XtPointer closure,
 
1094
                        Atom *seltype,
 
1095
                        Atom *type,
 
1096
                        XtPointer value,
 
1097
                        unsigned long *length,
 
1098
                        int *format) ;
 
1099
static void df_HandleDrop( 
 
1100
                        Widget w,
 
1101
                        XmDropProcCallbackStruct *cb) ;
 
1102
static void df_DragProcCallback( 
 
1103
                        Widget w,
 
1104
                        XtPointer client,
 
1105
                        XtPointer call) ;
 
1106
static void df_DropProcCallback( 
 
1107
                        Widget w,
 
1108
                        XtPointer client,
 
1109
                        XtPointer call) ;
 
1110
static void df_RegisterDropSite( 
 
1111
                        Widget w) ;
 
1112
static void df_Initialize( 
 
1113
                        Widget request,
 
1114
                        Widget new_w,
 
1115
                        ArgList args,
 
1116
                        Cardinal *num_args) ;
 
1117
static void df_Realize( 
 
1118
                        Widget w,
 
1119
                        XtValueMask *valueMask,
 
1120
                        XSetWindowAttributes *attributes) ;
 
1121
static void df_Destroy( 
 
1122
                        Widget wid) ;
 
1123
static void df_Resize( 
 
1124
                        Widget w) ;
 
1125
static XtGeometryResult df_QueryGeometry( 
 
1126
                        Widget w,
 
1127
                        XtWidgetGeometry *intended,
 
1128
                        XtWidgetGeometry *reply) ;
 
1129
static void DataFieldExpose( 
 
1130
                        Widget w,
 
1131
                        XEvent *event,
 
1132
                        Region region) ;
 
1133
static Boolean df_SetValues( 
 
1134
                        Widget old,
 
1135
                        Widget request,
 
1136
                        Widget new_w,
 
1137
                        ArgList args,
 
1138
                        Cardinal *num_args) ;
 
1139
static Boolean DataFieldGetBaselines( 
 
1140
                        Widget w,
 
1141
                        Dimension **baselines,
 
1142
                        int *line_count) ;
 
1143
static Boolean DataFieldGetDisplayRect( 
 
1144
                        Widget w,
 
1145
                        XRectangle *display_rect) ;
 
1146
static void DataFieldMarginsProc( 
 
1147
                        Widget w,
 
1148
                        XmBaselineMargins *margins_rec) ;
 
1149
static XtPointer DataFieldGetValue(Widget w, 
 
1150
                                   int format);
 
1151
 
 
1152
static void DataFieldSetValue(Widget w, 
 
1153
                              XtPointer s, 
 
1154
                              int format);
 
1155
 
 
1156
static int DataFieldPreferredValue(Widget w);
 
1157
 
 
1158
static void CheckSetRenderTable(Widget wid,
 
1159
                                int offset,
 
1160
                                XrmValue *value); 
 
1161
 
 
1162
static Boolean DataFieldRemove(Widget w,
 
1163
                               XEvent *event);
 
1164
static void PictureVerifyCallback(Widget w,
 
1165
    XtPointer call_d, XtPointer client_d);
 
1166
static void ClassInit(void);
 
1167
 
 
1168
 
 
1169
static void XmDataFieldSetStringWcs(Widget w, wchar_t *wc_value);
 
1170
 
 
1171
#endif /* _NO_PROTO */
 
1172
 
 
1173
/***************** End Static Function Declarations  ************/
 
1174
 
 
1175
static XmTextScanType df_sarray[] = {
 
1176
    XmSELECT_POSITION, XmSELECT_WORD, XmSELECT_LINE
 
1177
};
 
1178
 
 
1179
static int df_sarraysize = XtNumber(df_sarray);
 
1180
 
 
1181
static XContext _XmDataFDestContext = 0;
 
1182
static XContext _XmDataFGCContext = 0;
 
1183
static XContext _XmDataFDNDContext = 0;
 
1184
 
 
1185
 
 
1186
/* default translations and action recs */
 
1187
 
 
1188
static XtActionsRec data_actions[] = {
 
1189
/* ICS DataField actions */
 
1190
  {"ValidateAndMove",           df_ValidateAndMove},
 
1191
/* Text Replacing Bindings */
 
1192
  {"self-insert",               df_InsertChar},
 
1193
  {"insert-string",             df_InsertString},
 
1194
  {"delete-previous-character", df_DeletePrevChar},
 
1195
  {"delete-next-character",     df_DeleteNextChar},
 
1196
  {"delete-previous-word",      df_DeletePrevWord},
 
1197
  {"delete-next-word",          df_DeleteNextWord},
 
1198
  {"delete-to-end-of-line",     df_DeleteToEndOfLine},
 
1199
  {"delete-to-start-of-line",   df_DeleteToStartOfLine},
 
1200
/* Miscellaneous Bindings */
 
1201
  {"activate",                  df_Activate},
 
1202
  {"process-cancel",            df_ProcessCancel},
 
1203
  {"process-bdrag",             df_ProcessBDrag},
 
1204
/* Motion Bindings */
 
1205
  {"backward-character",        df_BackwardChar},
 
1206
  {"forward-character",         df_ForwardChar},
 
1207
  {"backward-word",             df_BackwardWord},
 
1208
  {"forward-word",              df_ForwardWord},
 
1209
  {"end-of-line",               df_EndOfLine},
 
1210
  {"beginning-of-line",         df_BeginningOfLine},
 
1211
  {"page-left",                 df_PageLeft},
 
1212
  {"page-right",                df_PageRight},
 
1213
/* Selection Bindings */
 
1214
  {"key-select",                df_KeySelection},
 
1215
  {"grab-focus",                df_StartPrimary},
 
1216
  {"move-destination",          df_MoveDestination},
 
1217
  {"extend-start",              df_ExtendPrimary},
 
1218
  {"extend-adjust",             df_ExtendPrimary},
 
1219
  {"extend-end",                df_ExtendEnd},
 
1220
  {"delete-selection",          df_DeleteSelection},
 
1221
  {"clear-selection",           df_ClearSelection},
 
1222
  {"cut-primary",               df_CutPrimary},
 
1223
  {"copy-primary",              df_CopyPrimary},
 
1224
  {"set-anchor",                df_SetAnchor},
 
1225
  {"toggle-overstrike",         df_ToggleOverstrike},
 
1226
  {"toggle-add-mode",           df_ToggleAddMode},
 
1227
  {"select-all",                df_SelectAll},
 
1228
  {"deselect-all",              df_DeselectAll},
 
1229
/* Quick Cut and Paste Bindings */
 
1230
  {"secondary-start",           df_StartSecondary},
 
1231
  {"secondary-adjust",          df_ExtendSecondary},
 
1232
  {"copy-to",                   df_ProcessCopy},
 
1233
  {"move-to",                   df_ProcessMove},
 
1234
  {"quick-cut-set",             df_VoidAction},
 
1235
  {"quick-copy-set",            df_VoidAction},
 
1236
  {"do-quick-action",           df_VoidAction},
 
1237
/* Clipboard Bindings */
 
1238
  {"cut-clipboard",             df_CutClipboard},
 
1239
  {"copy-clipboard",            df_CopyClipboard},
 
1240
  {"paste-clipboard",           df_PasteClipboard},
 
1241
/* Traversal */
 
1242
  {"traverse-next",             df_TraverseDown},
 
1243
  {"traverse-prev",             df_TraverseUp},
 
1244
  {"traverse-home",             df_TraverseHome},
 
1245
  {"next-tab-group",            df_TraverseNextTabGroup},
 
1246
  {"prev-tab-group",            df_TraversePrevTabGroup},
 
1247
/* Focus */
 
1248
  {"focusIn",                   df_TextFocusIn},
 
1249
  {"focusOut",                  df_TextFocusOut},
 
1250
  {"enter",                     df_TextEnter},
 
1251
  {"leave",                     df_TextLeave},
 
1252
};
 
1253
 
 
1254
static XtResource resources[] =
 
1255
{
 
1256
    {
 
1257
      XmNpicture, XmCPicture, XmRString, sizeof(String),
 
1258
      XtOffsetOf(XmDataFieldRec, data.picture_source),
 
1259
      XmRImmediate, (XtPointer) NULL
 
1260
    },
 
1261
    {
 
1262
      XmNautoFill, XmCAutoFill, XmRBoolean, sizeof(Boolean),
 
1263
      XtOffsetOf(XmDataFieldRec, data.auto_fill),
 
1264
      XmRImmediate, (XtPointer) True
 
1265
    },
 
1266
    {
 
1267
      XmNalignment, XmCAlignment, XmRAlignment, sizeof(unsigned char),
 
1268
      XtOffsetOf(XmDataFieldRec, data.alignment), XmRImmediate,
 
1269
      (XtPointer) XmALIGNMENT_BEGINNING
 
1270
    },
 
1271
    {
 
1272
      XmNpictureErrorCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList),
 
1273
      XtOffsetOf(XmDataFieldRec, data.picture_error_cb), XmRCallback,
 
1274
      (XtPointer) NULL
 
1275
    },
 
1276
    {
 
1277
      XmNvalidateCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList),
 
1278
      XtOffsetOf(XmDataFieldRec, data.validate_cb),
 
1279
      XmRCallback, (XtPointer) NULL
 
1280
    },
 
1281
 
 
1282
        /* the following are undocumented overrides of XmTextField resources */
 
1283
    {
 
1284
      XmNactivateCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList),
 
1285
      XtOffsetOf(XmDataFieldRec, text.activate_callback),
 
1286
      XmRCallback, NULL
 
1287
    },
 
1288
    {
 
1289
      XmNlosingFocusCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList),
 
1290
      XtOffsetOf(XmDataFieldRec, text.losing_focus_callback),
 
1291
      XmRCallback, NULL
 
1292
    },
 
1293
    {
 
1294
      XmNfocusCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList),
 
1295
      XtOffsetOf(XmDataFieldRec, text.focus_callback),
 
1296
      XmRCallback, NULL
 
1297
    },
 
1298
    {
 
1299
      XmNmodifyVerifyCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList),
 
1300
      XtOffsetOf(XmDataFieldRec, text.modify_verify_callback),
 
1301
      XmRCallback, NULL
 
1302
    },
 
1303
    {
 
1304
      XmNmodifyVerifyCallbackWcs, XmCCallback, XmRCallback, sizeof(XtCallbackList),
 
1305
      XtOffsetOf(XmDataFieldRec, text.wcs_modify_verify_callback),
 
1306
      XmRCallback, NULL
 
1307
    },
 
1308
    {
 
1309
      XmNmotionVerifyCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList),
 
1310
      XtOffsetOf(XmDataFieldRec, text.motion_verify_callback),
 
1311
      XmRCallback, NULL
 
1312
    },
 
1313
    {
 
1314
      XmNgainPrimaryCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList),
 
1315
      XtOffsetOf(XmDataFieldRec, text.gain_primary_callback),
 
1316
      XmRCallback, NULL
 
1317
    },
 
1318
    {
 
1319
      XmNlosePrimaryCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList),
 
1320
      XtOffsetOf(XmDataFieldRec, text.lose_primary_callback),
 
1321
      XmRCallback, NULL
 
1322
    },
 
1323
    {
 
1324
      XmNvalueChangedCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList),
 
1325
      XtOffsetOf(XmDataFieldRec, text.value_changed_callback),
 
1326
      XmRCallback, NULL
 
1327
    },
 
1328
    {
 
1329
      XmNvalue, XmCValue, XmRString, sizeof(String),
 
1330
      XtOffsetOf(XmDataFieldRec, text.value),
 
1331
      XmRString, ""
 
1332
    },
 
1333
    {
 
1334
      XmNvalueWcs, XmCValueWcs, XmRValueWcs, sizeof(wchar_t*),
 
1335
      XtOffsetOf(XmDataFieldRec, text.wc_value),
 
1336
      XmRString, NULL
 
1337
    },
 
1338
    {
 
1339
      XmNmarginHeight, XmCMarginHeight, XmRVerticalDimension, sizeof(Dimension),
 
1340
      XtOffsetOf(XmDataFieldRec, text.margin_height),
 
1341
      XmRImmediate, (XtPointer) 5
 
1342
    },
 
1343
    {
 
1344
      XmNmarginWidth, XmCMarginWidth, XmRHorizontalDimension, sizeof(Dimension),
 
1345
      XtOffsetOf(XmDataFieldRec, text.margin_width),
 
1346
      XmRImmediate, (XtPointer) 5
 
1347
    },
 
1348
    {
 
1349
      XmNcursorPosition, XmCCursorPosition, XmRTextPosition, sizeof (XmTextPosition),
 
1350
      XtOffsetOf(XmDataFieldRec, text.cursor_position),
 
1351
      XmRImmediate, (XtPointer) 0
 
1352
    },
 
1353
    {
 
1354
      XmNcolumns, XmCColumns, XmRShort, sizeof(short),
 
1355
      XtOffsetOf(XmDataFieldRec, text.columns),
 
1356
      XmRImmediate, (XtPointer) 20
 
1357
    },
 
1358
    {
 
1359
      XmNmaxLength, XmCMaxLength, XmRInt, sizeof(int),
 
1360
      XtOffsetOf(XmDataFieldRec, text.max_length),
 
1361
      XmRImmediate, (XtPointer) INT_MAX
 
1362
    },
 
1363
    {
 
1364
      XmNblinkRate, XmCBlinkRate, XmRInt, sizeof(int),
 
1365
      XtOffsetOf(XmDataFieldRec, text.blink_rate),
 
1366
      XmRImmediate, (XtPointer) 500
 
1367
    },
 
1368
    {
 
1369
      "pri.vate", "Pri.vate", XmRBoolean, sizeof(Boolean),
 
1370
      XtOffsetOf(XmDataFieldRec, text.check_set_render_table),
 
1371
      XmRImmediate, (XtPointer) False
 
1372
    },
 
1373
    {
 
1374
     XmNfontList, XmCFontList, XmRFontList, sizeof(XmFontList),
 
1375
     XtOffsetOf(XmDataFieldRec, text.font_list),
 
1376
     XmRCallProc, (XtPointer)CheckSetRenderTable
 
1377
    },
 
1378
    {
 
1379
     XmNrenderTable, XmCRenderTable, XmRRenderTable, sizeof(XmRenderTable),
 
1380
     XtOffsetOf(XmDataFieldRec, text.font_list),
 
1381
     XmRCallProc, (XtPointer)CheckSetRenderTable
 
1382
    },
 
1383
    {
 
1384
      XmNselectionArray, XmCSelectionArray, XmRPointer,
 
1385
      sizeof(XtPointer),
 
1386
      XtOffsetOf(XmDataFieldRec, text.selection_array),
 
1387
      XmRImmediate, (XtPointer) df_sarray
 
1388
    },
 
1389
    {
 
1390
      XmNselectionArrayCount, XmCSelectionArrayCount, XmRInt, sizeof(int),
 
1391
      XtOffsetOf(XmDataFieldRec, text.selection_array_count),
 
1392
      XmRInt, (XtPointer) &df_sarraysize
 
1393
    },
 
1394
    {
 
1395
      XmNresizeWidth, XmCResizeWidth, XmRBoolean, sizeof(Boolean),
 
1396
      XtOffsetOf(XmDataFieldRec, text.resize_width),
 
1397
      XmRImmediate, (XtPointer) False
 
1398
    },
 
1399
    {
 
1400
      XmNpendingDelete, XmCPendingDelete, XmRBoolean, sizeof(Boolean),
 
1401
      XtOffsetOf(XmDataFieldRec, text.pending_delete),
 
1402
      XmRImmediate, (XtPointer) True
 
1403
    },
 
1404
    {
 
1405
      XmNeditable, XmCEditable, XmRBoolean, sizeof(Boolean),
 
1406
      XtOffsetOf(XmDataFieldRec, text.editable),
 
1407
      XmRImmediate, (XtPointer) True
 
1408
    },
 
1409
    {
 
1410
      XmNcursorPositionVisible, XmCCursorPositionVisible, XmRBoolean,
 
1411
      sizeof(Boolean),
 
1412
      XtOffsetOf(XmDataFieldRec, text.cursor_position_visible),
 
1413
      XmRImmediate, (XtPointer) True
 
1414
    },
 
1415
   {
 
1416
     XmNverifyBell, XmCVerifyBell, XmRBoolean, sizeof(Boolean),
 
1417
     XtOffsetOf(XmDataFieldRec, text.verify_bell),
 
1418
     XmRImmediate, (XtPointer) XmDYNAMIC_BOOL
 
1419
   },
 
1420
   {
 
1421
     XmNselectThreshold, XmCSelectThreshold, XmRInt, sizeof(int),
 
1422
     XtOffsetOf(XmDataFieldRec, text.threshold),
 
1423
     XmRImmediate, (XtPointer) 5
 
1424
   },
 
1425
   {
 
1426
     XmNnavigationType, XmCNavigationType, XmRNavigationType,
 
1427
     sizeof (unsigned char),
 
1428
     XtOffsetOf(XmDataFieldRec, primitive.navigation_type),
 
1429
     XmRImmediate, (XtPointer) XmTAB_GROUP
 
1430
   },
 
1431
};
 
1432
 
 
1433
/* Definition for resources that need special processing in get values */
 
1434
static XmSyntheticResource syn_resources[] =
 
1435
{
 
1436
   {
 
1437
     XmNmarginWidth,
 
1438
     sizeof(Dimension),
 
1439
     XtOffsetOf(XmDataFieldRec, text.margin_width),
 
1440
     XmeFromHorizontalPixels,
 
1441
     XmeToHorizontalPixels
 
1442
   },
 
1443
 
 
1444
   {
 
1445
     XmNmarginHeight,
 
1446
     sizeof(Dimension),
 
1447
     XtOffsetOf(XmDataFieldRec, text.margin_height),
 
1448
     XmeFromVerticalPixels,
 
1449
     XmeToVerticalPixels
 
1450
   },
 
1451
 
 
1452
   {
 
1453
     XmNvalue,
 
1454
     sizeof(char *),
 
1455
     XtOffsetOf(XmDataFieldRec, text.value),
 
1456
     df_MakeCopy,
 
1457
     NULL
 
1458
   },
 
1459
 
 
1460
   {
 
1461
     XmNvalueWcs,
 
1462
     sizeof(wchar_t *),
 
1463
     XtOffsetOf(XmDataFieldRec, text.wc_value),
 
1464
     df_WcsMakeCopy,
 
1465
     NULL
 
1466
   },
 
1467
 
 
1468
};
 
1469
 
 
1470
XmPrimitiveClassExtRec _XmDataFPrimClassExtRec = {
 
1471
    NULL,
 
1472
    NULLQUARK,
 
1473
    XmPrimitiveClassExtVersion,
 
1474
    sizeof(XmPrimitiveClassExtRec),
 
1475
    DataFieldGetBaselines,              /* widget_baseline        */
 
1476
    DataFieldGetDisplayRect,            /* widget_display_rect    */
 
1477
    DataFieldMarginsProc,               /* get/set widget margins */
 
1478
};
 
1479
 
 
1480
 
 
1481
externaldef(xmdatafieldclassrec) XmDataFieldClassRec xmDataFieldClassRec =
 
1482
{
 
1483
   {
 
1484
      (WidgetClass) &xmPrimitiveClassRec,       /* superclass         */
 
1485
      "XmDataField",                            /* class_name         */
 
1486
      sizeof(XmDataFieldRec),                   /* widget_size        */
 
1487
      ClassInit,                                /* class_initialize   */
 
1488
      df_ClassPartInitialize,                   /* class_part_initiali*/
 
1489
      FALSE,                                    /* class_inited       */
 
1490
      df_Initialize,                            /* initialize         */
 
1491
      (XtArgsProc)NULL,                         /* initialize_hook    */
 
1492
      df_Realize,                               /* realize            */
 
1493
      data_actions,                             /* actions            */
 
1494
      XtNumber(data_actions),                   /* num_actions        */
 
1495
      resources,                                /* resources          */
 
1496
      XtNumber(resources),                      /* num_resources      */
 
1497
      NULLQUARK,                                /* xrm_class          */
 
1498
      TRUE,                                     /* compress_motion    */
 
1499
      XtExposeCompressMaximal,                  /* compress_exposure  */
 
1500
      TRUE,                                     /* compress_enterleave*/
 
1501
      FALSE,                                    /* visible_interest   */
 
1502
      df_Destroy,                               /* destroy            */
 
1503
      df_Resize,                                /* resize             */
 
1504
      DataFieldExpose,                          /* expose             */
 
1505
      df_SetValues,                             /* set_values         */
 
1506
 
 
1507
#ifdef sco    /* ICS -pwc 7/28/93 */
 
1508
      NULL,                                     /* set_values_hook    */
 
1509
#else
 
1510
      (XtArgsFunc)NULL,                         /* set_values_hook    */
 
1511
#endif        /* sco */
 
1512
 
 
1513
      XtInheritSetValuesAlmost,                 /* set_values_almost  */
 
1514
      (XtArgsProc)NULL,                         /* get_values_hook    */
 
1515
 
 
1516
#ifdef sco              /* ICS - pwc 7/28/93 */
 
1517
      NULL,                                     /* accept_focus       */
 
1518
#else
 
1519
      (XtAcceptFocusProc)NULL,                  /* accept_focus       */
 
1520
#endif /* sco */
 
1521
 
 
1522
      XtVersion,                        /* version            */
 
1523
      NULL,                                     /* callback_private   */
 
1524
      NULL,                                     /* tm_table           */
 
1525
      df_QueryGeometry,                         /* query_geometry     */
 
1526
      (XtStringProc)NULL,                       /* display accel      */
 
1527
      NULL,                                     /* extension          */
 
1528
   },
 
1529
 
 
1530
   {                                            /* Xmprimitive        */
 
1531
      XmInheritBorderHighlight,                 /* border_highlight   */
 
1532
      XmInheritBorderUnhighlight,               /* border_unhighlight */
 
1533
      NULL,                                     /* translations       */
 
1534
      (XtActionProc)NULL,                       /* arm_and_activate   */
 
1535
      syn_resources,                            /* syn resources      */
 
1536
      XtNumber(syn_resources),                  /* num syn_resources  */
 
1537
      (XtPointer) &_XmDataFPrimClassExtRec,     /* extension          */
 
1538
   },
 
1539
   {                                            /* text classs        */
 
1540
      NULL,                                     /* extension          */
 
1541
   }
 
1542
};
 
1543
 
 
1544
externaldef(xmdatafieldwidgetclass) WidgetClass xmDataFieldWidgetClass =
 
1545
                                         (WidgetClass) &xmDataFieldClassRec;
 
1546
 
 
1547
/* AccessXmString Trait record for DataField */
 
1548
static XmConst XmAccessTextualTraitRec dataFieldCS = {
 
1549
  0,                              /* version */
 
1550
  DataFieldGetValue,
 
1551
  DataFieldSetValue,
 
1552
  DataFieldPreferredValue,
 
1553
};
 
1554
 
 
1555
static void
 
1556
#ifdef _NO_PROTO
 
1557
ClassInit()
 
1558
#else
 
1559
ClassInit(void)
 
1560
#endif
 
1561
{
 
1562
    XmDataFieldClassRec* wc = &xmDataFieldClassRec;
 
1563
    XmTransferTrait tt;
 
1564
 
 
1565
    /* set TextField's transfer trait */
 
1566
    tt = XmeTraitGet((XtPointer)xmTextFieldWidgetClass, XmQTtransfer);
 
1567
    XmeTraitSet((XtPointer)xmDataFieldWidgetClass,
 
1568
                XmQTtransfer,
 
1569
                (XtPointer) &tt);
 
1570
    
 
1571
    XmeTraitSet((XtPointer)xmDataFieldWidgetClass, 
 
1572
                XmQTaccessTextual, 
 
1573
                (XtPointer) &dataFieldCS);   
 
1574
}
 
1575
 
 
1576
/* ARGSUSED */
 
1577
static void 
 
1578
#ifdef _NO_PROTO
 
1579
df_ValidateAndMove(w, ev, args, nargs)
 
1580
     Widget w;
 
1581
     XEvent *ev;
 
1582
     String *args;
 
1583
     Cardinal *nargs;
 
1584
#else
 
1585
df_ValidateAndMove(
 
1586
    Widget w,
 
1587
    XEvent *ev,
 
1588
    String *args,
 
1589
    Cardinal *nargs)
 
1590
#endif
 
1591
{
 
1592
    XmDataFieldCallbackStruct cbs;
 
1593
    
 
1594
    /*
 
1595
     * We are guaranteed that the picture will have accepted the string, so
 
1596
     * just call the verify callbacks.
 
1597
     */
 
1598
    cbs.w      = w;
 
1599
    cbs.text   = XmDataFieldGetString(w);
 
1600
    cbs.accept = True;
 
1601
    XtCallCallbackList(w, XmDataField_validate_cb(w), (XtPointer)&cbs);
 
1602
    XtFree(cbs.text);
 
1603
    
 
1604
    /*
 
1605
     * Make sure we accepted it
 
1606
     */
 
1607
    if(cbs.accept == False)
 
1608
    {
 
1609
        XBell(XtDisplay(w), 0);
 
1610
        return;
 
1611
    }
 
1612
 
 
1613
    /*
 
1614
     * Otherwise just give up the focus and process the traversal as
 
1615
     * normal
 
1616
     */
 
1617
    if(*nargs > 0 && strncasecmp(args[0], "prev", 4) == 0) {
 
1618
        (void) XmProcessTraversal(w, XmTRAVERSE_PREV_TAB_GROUP);
 
1619
    } else {
 
1620
        (void) XmProcessTraversal(w, XmTRAVERSE_NEXT_TAB_GROUP);
 
1621
    }
 
1622
}
 
1623
 
 
1624
 
 
1625
 
 
1626
/* ARGSUSED */
 
1627
static void
 
1628
#ifdef _NO_PROTO
 
1629
PictureVerifyCallback(w, client_d, call_d)
 
1630
    Widget w;
 
1631
    XtPointer client_d;
 
1632
    XtPointer call_d;
 
1633
#else
 
1634
PictureVerifyCallback(
 
1635
    Widget w,
 
1636
    XtPointer client_d,
 
1637
    XtPointer call_d )
 
1638
#endif /* _NO_PROTO */
 
1639
{
 
1640
    XmTextVerifyCallbackStruct *cbs = 
 
1641
        (XmTextVerifyCallbackStruct*) call_d;
 
1642
    char *curr, *newptr, *changed = NULL;
 
1643
    int src, dst, i;
 
1644
    XmPictureState ps;
 
1645
    Boolean done = False;
 
1646
 
 
1647
    /*
 
1648
     * If we're just backspacing, allow the change irregarless
 
1649
     */
 
1650
    if(cbs->startPos < cbs->currInsert || cbs->text->length == 0)
 
1651
        return;
 
1652
    
 
1653
    /*
 
1654
     * Get the current string, and splice in the intended changes
 
1655
     */
 
1656
    curr = XmDataFieldGetString(w);
 
1657
    
 
1658
    newptr = XtMalloc((cbs->text->length + strlen(curr) + 2) * 
 
1659
                      sizeof(char *));
 
1660
    
 
1661
    dst = 0;
 
1662
    
 
1663
    /* Copy in the stuff before the modification */
 
1664
    for(src=0; src<cbs->startPos; src++, dst++)
 
1665
        newptr[dst] = curr[src];
 
1666
 
 
1667
    /* Then the modification text */
 
1668
    if(cbs->text->ptr) {
 
1669
        for(src=0; src<cbs->text->length; src++, dst++)
 
1670
            newptr[dst] = cbs->text->ptr[src];
 
1671
    }
 
1672
    /* Then the last bit */
 
1673
    if(cbs->endPos > cbs->startPos) {
 
1674
        for(dst = cbs->endPos + cbs->text->length;
 
1675
            src<cbs->endPos;
 
1676
            src++, dst++)
 
1677
            newptr[dst] = curr[src];
 
1678
    }
 
1679
    /* And stick a null in for good measure and sanity in debugging */
 
1680
    newptr[dst] = '\0';
 
1681
 
 
1682
    /*
 
1683
     * Run it through the picture, and bail if it isn't accepted 
 
1684
     */
 
1685
    ps = XmGetNewPictureState(XmDataField_picture(w));
 
1686
 
 
1687
    for(i=0; i<strlen(newptr); i++) {
 
1688
        changed = XmPictureProcessCharacter(ps, newptr[i], &done);
 
1689
        if(changed == NULL || done) break;
 
1690
    }
 
1691
        
 
1692
    if(changed == NULL) {
 
1693
        cbs->doit = False;
 
1694
        XtCallCallbackList(w, XmDataField_picture_error_cb(w), NULL);
 
1695
        return;
 
1696
    }
 
1697
 
 
1698
 
 
1699
    /*
 
1700
     * And now try autofilling
 
1701
     */
 
1702
    if(XmDataField_auto_fill(w)) {
 
1703
        changed = XmPictureDoAutoFill(ps);
 
1704
    } else {
 
1705
        changed = XmPictureGetCurrentString(ps);
 
1706
    }
 
1707
 
 
1708
    /*
 
1709
     * Now the hard part:  we may have been auto-filled, so we have to
 
1710
     * massage the callback struct to reflect what's happened
 
1711
     */
 
1712
 
 
1713
    cbs->startPos = 0;
 
1714
    /* CR03686 cbs->endPos = strlen(newptr); */
 
1715
    cbs->text->ptr = strdup(changed);
 
1716
    cbs->text->length = strlen(changed);
 
1717
 
 
1718
    XtFree(newptr);
 
1719
    XmPictureDeleteState(ps);
 
1720
}
 
1721
 
 
1722
 
 
1723
/* USE ITERATIONS OF mblen TO COUNT THE NUMBER OF CHARACTERS REPRESENTED
 
1724
 * BY n_bytes BYTES POINTED TO BY ptr, a pointer to char*.
 
1725
 * n_bytes does not include NULL terminator (if any), nor does return.
 
1726
 */
 
1727
 
 
1728
/* ARGSUSED */
 
1729
static int
 
1730
#ifdef _NO_PROTO
 
1731
_XmDataFieldCountCharacters( tf, ptr, n_bytes )
 
1732
        XmDataFieldWidget tf ;
 
1733
        char *ptr ;
 
1734
        int n_bytes ;
 
1735
#else
 
1736
_XmDataFieldCountCharacters(
 
1737
        XmDataFieldWidget tf,
 
1738
        char *ptr,
 
1739
        int n_bytes )
 
1740
#endif /* _NO_PROTO */
 
1741
{
 
1742
   char * bptr;
 
1743
   int count = 0;
 
1744
   int char_size = 0;
 
1745
 
 
1746
   if (n_bytes <= 0 || ptr == NULL || *ptr == '\0')
 
1747
      return 0;
 
1748
 
 
1749
   if (XmTextF_max_char_size(tf) == 1)
 
1750
      return n_bytes;
 
1751
 
 
1752
   bptr = ptr;
 
1753
 
 
1754
   for (bptr = ptr; n_bytes > 0; count++, bptr+= char_size){
 
1755
      char_size = mblen(bptr, XmTextF_max_char_size(tf));
 
1756
      if (char_size < 0) break; /* error */
 
1757
      n_bytes -= char_size;
 
1758
   }
 
1759
   return count;
 
1760
}
 
1761
 
 
1762
/* USE ITERATIONS OF wctomb TO COUNT THE NUMBER OF BYTES REQUIRED FOR THE
 
1763
 * MULTI-BYTE REPRESENTION OF num_chars WIDE CHARACTERS IN wc_value.
 
1764
 * COUNT TERMINATED IF NULL ENCOUNTERED IN THE STRING.
 
1765
 * NUMBER OF BYTES IS RETURNED.
 
1766
 */
 
1767
 
 
1768
/* ARGSUSED */
 
1769
int
 
1770
#ifdef _NO_PROTO
 
1771
_XmDataFieldCountBytes( tf, wc_value, num_chars )
 
1772
        XmDataFieldWidget tf;
 
1773
        wchar_t * wc_value; 
 
1774
        int num_chars;
 
1775
#else /* _NO_PROTO */
 
1776
_XmDataFieldCountBytes(
 
1777
        XmDataFieldWidget tf,
 
1778
        wchar_t * wc_value, 
 
1779
        int num_chars)
 
1780
#endif /* _NO_PROTO */
 
1781
{
 
1782
   wchar_t      * wc_ptr;
 
1783
   char         tmp[MB_LEN_MAX];  /* defined in limits.h: max in any locale */
 
1784
   int          n_bytes = 0;
 
1785
 
 
1786
   if (num_chars <= 0 || wc_value == NULL || *wc_value == (wchar_t)0L)
 
1787
      return 0;
 
1788
 
 
1789
   if (XmTextF_max_char_size(tf) == 1)
 
1790
      return num_chars;
 
1791
 
 
1792
   wc_ptr = wc_value;
 
1793
   while ((num_chars > 0) && (*wc_ptr != (wchar_t)0L)){
 
1794
      n_bytes += wctomb(tmp, *wc_ptr);
 
1795
      num_chars--;
 
1796
      wc_ptr++;
 
1797
   }
 
1798
   return n_bytes;
 
1799
}
 
1800
 
 
1801
/*ARGSUSED*/
 
1802
static void 
 
1803
#ifdef _NO_PROTO
 
1804
df_MakeCopy( w, n, value )
 
1805
        Widget w ;
 
1806
        int n;
 
1807
        XtArgVal *value ;
 
1808
#else
 
1809
df_MakeCopy(
 
1810
        Widget w,
 
1811
        int n,
 
1812
        XtArgVal *value )
 
1813
#endif /* _NO_PROTO */
 
1814
{
 
1815
    (*value) = (XtArgVal) XmDataFieldGetString (w);
 
1816
}
 
1817
 
 
1818
/*ARGSUSED*/
 
1819
static void 
 
1820
#ifdef _NO_PROTO
 
1821
df_WcsMakeCopy( w, n, value )
 
1822
        Widget w ;
 
1823
        int n;
 
1824
        XtArgVal *value ;
 
1825
#else
 
1826
df_WcsMakeCopy(
 
1827
        Widget w,
 
1828
        int n,
 
1829
        XtArgVal *value )
 
1830
#endif /* _NO_PROTO */
 
1831
{
 
1832
    (*value) = (XtArgVal) XmDataFieldGetStringWcs (w);
 
1833
}
 
1834
 
 
1835
/* ARGSUSED */
 
1836
static void
 
1837
#ifdef _NO_PROTO
 
1838
df_FreeContextData(w, clientData, callData)
 
1839
    Widget w;
 
1840
    XtPointer clientData;
 
1841
    XtPointer callData;
 
1842
#else
 
1843
df_FreeContextData( 
 
1844
        Widget w,
 
1845
        XtPointer clientData,
 
1846
        XtPointer callData )
 
1847
#endif /* _NO_PROTO */
 
1848
{
 
1849
    XmTextContextData ctx_data = (XmTextContextData) clientData;
 
1850
    Display *display = DisplayOfScreen(ctx_data->screen);
 
1851
    XtPointer data_ptr;
 
1852
 
 
1853
    if (XFindContext(display, (Window) ctx_data->screen,
 
1854
                     ctx_data->context, (char **) &data_ptr)) {
 
1855
 
 
1856
       if (ctx_data->type == _XM_IS_PIXMAP_CTX) {
 
1857
          XFreePixmap(display, (Pixmap) data_ptr);
 
1858
       } else if (ctx_data->type != '\0') {
 
1859
          if (data_ptr)
 
1860
             XtFree((char *) data_ptr);
 
1861
       }
 
1862
 
 
1863
       XDeleteContext (display, (Window) ctx_data->screen, ctx_data->context);
 
1864
    }
 
1865
 
 
1866
    XtFree ((char *) ctx_data);
 
1867
}
 
1868
 
 
1869
static TextFDestData 
 
1870
#ifdef _NO_PROTO
 
1871
df_GetTextFDestData( w )
 
1872
        Widget w ;
 
1873
#else
 
1874
df_GetTextFDestData(
 
1875
        Widget w )
 
1876
#endif /* _NO_PROTO */
 
1877
{
 
1878
   static TextFDestData dest_data;
 
1879
   Display *display = XtDisplay(w);
 
1880
   Screen *screen = XtScreen(w);
 
1881
 
 
1882
   if (_XmDataFDestContext == 0)
 
1883
      _XmDataFDestContext = XUniqueContext();
 
1884
 
 
1885
   if (XFindContext(display, (Window) screen,
 
1886
                    _XmDataFDestContext, (char **) &dest_data)) {
 
1887
       XmTextContextData ctx_data;
 
1888
       Widget xm_display = (Widget) XmGetXmDisplay(display);
 
1889
 
 
1890
       ctx_data = (XmTextContextData) XtMalloc(sizeof(XmTextContextDataRec));
 
1891
 
 
1892
       ctx_data->screen = screen;
 
1893
       ctx_data->context = _XmDataFDestContext;
 
1894
       ctx_data->type = _XM_IS_DEST_CTX;
 
1895
 
 
1896
       dest_data = (TextFDestData) XtCalloc(1, sizeof(TextFDestDataRec));
 
1897
 
 
1898
       XtAddCallback(xm_display, XmNdestroyCallback, 
 
1899
                     (XtCallbackProc) df_FreeContextData, (XtPointer) ctx_data);
 
1900
 
 
1901
       XSaveContext(XtDisplay(w), (Window) screen,
 
1902
                    _XmDataFDestContext, (XPointer)dest_data);
 
1903
   }
 
1904
 
 
1905
   return dest_data;
 
1906
}
 
1907
 
 
1908
static void
 
1909
#ifdef _NO_PROTO
 
1910
df_SetDropContext( w )
 
1911
        Widget w ;
 
1912
#else
 
1913
df_SetDropContext(
 
1914
        Widget w )
 
1915
#endif /* _NO_PROTO */
 
1916
{
 
1917
   Display *display = XtDisplay(w);
 
1918
   Screen *screen = XtScreen(w);
 
1919
 
 
1920
   if (_XmDataFDNDContext == 0)
 
1921
      _XmDataFDNDContext = XUniqueContext();
 
1922
 
 
1923
   XSaveContext(display, (Window)screen,
 
1924
                _XmDataFDNDContext, (XPointer)w);
 
1925
}
 
1926
 
 
1927
 
 
1928
static void
 
1929
#ifdef _NO_PROTO
 
1930
df_DeleteDropContext( w )
 
1931
        Widget w ;
 
1932
#else
 
1933
df_DeleteDropContext(
 
1934
        Widget w )
 
1935
#endif /* _NO_PROTO */
 
1936
{
 
1937
   Display *display = XtDisplay(w);
 
1938
   Screen *screen = XtScreen(w);
 
1939
 
 
1940
   XDeleteContext(display, (Window)screen, _XmDataFDNDContext);
 
1941
}
 
1942
 
 
1943
 
 
1944
Widget
 
1945
#ifdef _NO_PROTO
 
1946
_XmDataFieldGetDropReciever( w )
 
1947
        Widget w ;
 
1948
#else
 
1949
_XmDataFieldGetDropReciever(
 
1950
        Widget w )
 
1951
#endif /* _NO_PROTO */
 
1952
{
 
1953
   Widget widget;
 
1954
 
 
1955
   if (_XmDataFDNDContext == 0) return NULL;
 
1956
 
 
1957
   if (!XFindContext(XtDisplay(w), (Window) XtScreen(w),
 
1958
                     _XmDataFDNDContext, (char **) &widget)) {
 
1959
      return widget;
 
1960
   } 
 
1961
 
 
1962
   return NULL;
 
1963
}
 
1964
 
 
1965
 
 
1966
 
 
1967
static TextFGCData 
 
1968
#ifdef _NO_PROTO
 
1969
df_GetTextFGCData( w )
 
1970
        Widget w ;
 
1971
#else
 
1972
df_GetTextFGCData(
 
1973
        Widget w )
 
1974
#endif /* _NO_PROTO */
 
1975
{
 
1976
   static TextFGCData gc_data;
 
1977
   Display *display = XtDisplay(w);
 
1978
   Screen *screen = XtScreen(w);
 
1979
 
 
1980
   if (_XmDataFGCContext == 0)
 
1981
      _XmDataFGCContext = XUniqueContext();
 
1982
 
 
1983
   if (XFindContext(display, (Window)screen,
 
1984
                    _XmDataFGCContext, (char **)&gc_data)) {
 
1985
       XmTextContextData ctx_data;
 
1986
       Widget xm_display = (Widget) XmGetXmDisplay(display);
 
1987
 
 
1988
       ctx_data = (XmTextContextData) XtMalloc(sizeof(XmTextContextDataRec));
 
1989
 
 
1990
       ctx_data->screen = screen;
 
1991
       ctx_data->context = _XmDataFGCContext;
 
1992
       ctx_data->type = _XM_IS_GC_DATA_CTX;
 
1993
 
 
1994
       gc_data = (TextFGCData) XtCalloc(1, sizeof(TextFGCDataRec));
 
1995
 
 
1996
       XtAddCallback(xm_display, XmNdestroyCallback, 
 
1997
                     (XtCallbackProc) df_FreeContextData, (XtPointer) ctx_data);
 
1998
 
 
1999
       XSaveContext(display, (Window)screen, _XmDataFGCContext, 
 
2000
                    (XPointer)gc_data);
 
2001
       gc_data->tf = (XmDataFieldWidget) w;
 
2002
   }
 
2003
 
 
2004
   if (gc_data->tf == NULL) gc_data->tf = (XmDataFieldWidget) w;
 
2005
 
 
2006
   return gc_data;
 
2007
}
 
2008
 
 
2009
void
 
2010
#ifdef _NO_PROTO
 
2011
_XmDataFToggleCursorGC( widget )
 
2012
        Widget widget;
 
2013
#else
 
2014
_XmDataFToggleCursorGC(
 
2015
        Widget widget )
 
2016
#endif /* _NO_PROTO */
 
2017
{
 
2018
    XmDataFieldWidget tf = (XmDataFieldWidget) widget;
 
2019
    XGCValues values;
 
2020
    unsigned long valuemask = GCFillStyle|GCFunction|GCForeground|GCBackground;
 
2021
 
 
2022
    if (!XtIsRealized(widget)) return;
 
2023
 
 
2024
    if (!XmTextF_has_rect(tf)) _XmDataFieldSetClipRect(tf);
 
2025
 
 
2026
    if (XmTextF_overstrike(tf)) {
 
2027
      if (!XmTextF_add_mode(tf) && XtIsSensitive(widget) &&
 
2028
          (XmTextF_has_focus(tf) || XmTextF_has_destination(tf))) {
 
2029
        values.fill_style = FillSolid;
 
2030
      } else {
 
2031
        values.fill_style = FillTiled;
 
2032
      }
 
2033
      values.foreground = values.background =
 
2034
        tf->primitive.foreground ^ tf->core.background_pixel;
 
2035
      values.function = GXxor;
 
2036
    } else {
 
2037
      if (XtIsSensitive(widget) && !XmTextF_add_mode(tf) &&
 
2038
          (XmTextF_has_focus(tf) || XmTextF_has_destination(tf))) {
 
2039
        if (XmTextF_cursor(tf) == XmUNSPECIFIED_PIXMAP) return;
 
2040
        values.stipple = XmTextF_cursor(tf);
 
2041
      } else {
 
2042
        if (XmTextF_add_mode_cursor(tf) == XmUNSPECIFIED_PIXMAP) return;
 
2043
        values.stipple = XmTextF_add_mode_cursor(tf);
 
2044
      }
 
2045
      values.fill_style = FillStippled;
 
2046
      values.function = GXcopy;
 
2047
      if (XmTextF_have_inverted_image_gc(tf)){
 
2048
        values.background = tf->primitive.foreground;
 
2049
        values.foreground = tf->core.background_pixel;
 
2050
      } else {
 
2051
        values.foreground = tf->primitive.foreground;
 
2052
        values.background = tf->core.background_pixel;
 
2053
      }
 
2054
      valuemask |= GCStipple;
 
2055
    }
 
2056
    XChangeGC(XtDisplay(widget), XmTextF_image_gc(tf), valuemask, &values);
 
2057
}
 
2058
 
 
2059
/*
 
2060
 * Find the highlight record corresponding to the given position.  Returns a
 
2061
 * pointer to the record.  The third argument indicates whether we are probing
 
2062
 * the left or right edge of a highlighting range.
 
2063
 */
 
2064
static _XmHighlightRec * 
 
2065
#ifdef _NO_PROTO
 
2066
df_FindHighlight( w, position )
 
2067
        XmDataFieldWidget w ;
 
2068
        XmTextPosition position ;
 
2069
#else
 
2070
df_FindHighlight(
 
2071
        XmDataFieldWidget w,
 
2072
        XmTextPosition position )
 
2073
#endif /* _NO_PROTO */
 
2074
{
 
2075
    _XmHighlightRec *l = XmTextF_highlight(w).list;
 
2076
    int i;
 
2077
 
 
2078
    for (i=XmTextF_highlight(w).number - 1 ; i>=0 ; i--)
 
2079
        if (position >= l[i].position) {
 
2080
            l = l + i;
 
2081
            break;
 
2082
        }
 
2083
 
 
2084
    return(l);
 
2085
}
 
2086
 
 
2087
static void 
 
2088
#ifdef _NO_PROTO
 
2089
df_InsertHighlight( w, position, mode )
 
2090
        XmDataFieldWidget w ;
 
2091
        XmTextPosition position ;
 
2092
        XmHighlightMode mode ;
 
2093
#else
 
2094
df_InsertHighlight(
 
2095
        XmDataFieldWidget w,
 
2096
        XmTextPosition position,
 
2097
        XmHighlightMode mode )
 
2098
#endif /* _NO_PROTO */
 
2099
{
 
2100
    _XmHighlightRec *l1;
 
2101
    _XmHighlightRec *l = XmTextF_highlight(w).list;
 
2102
    int i, j;
 
2103
 
 
2104
    l1 = df_FindHighlight(w, position);
 
2105
    if (l1->position == position)
 
2106
       l1->mode = mode;
 
2107
    else {
 
2108
       i = (l1 - l) + 1;
 
2109
       XmTextF_highlight(w).number++;
 
2110
       if (XmTextF_highlight(w).number > XmTextF_highlight(w).maximum) {
 
2111
          XmTextF_highlight(w).maximum = XmTextF_highlight(w).number;
 
2112
          l = XmTextF_highlight(w).list = (_XmHighlightRec *)XtRealloc((char *) l,
 
2113
              (unsigned)(XmTextF_highlight(w).maximum * sizeof(_XmHighlightRec)));
 
2114
       }
 
2115
       for (j=XmTextF_highlight(w).number-1 ; j>i ; j--)
 
2116
           l[j] = l[j-1];
 
2117
       l[i].position = position;
 
2118
       l[i].mode = mode;
 
2119
    }
 
2120
}
 
2121
 
 
2122
static void 
 
2123
#ifdef _NO_PROTO
 
2124
DataFieldSetHighlight( tf, left, right, mode )
 
2125
        XmDataFieldWidget tf ;
 
2126
        XmTextPosition left ;
 
2127
        XmTextPosition right ;
 
2128
        XmHighlightMode mode ;
 
2129
#else
 
2130
DataFieldSetHighlight(
 
2131
        XmDataFieldWidget tf,
 
2132
        XmTextPosition left,
 
2133
        XmTextPosition right,
 
2134
        XmHighlightMode mode )
 
2135
#endif /* _NO_PROTO */
 
2136
{
 
2137
    _XmHighlightRec *l;
 
2138
    XmHighlightMode endmode;
 
2139
    int i, j;
 
2140
 
 
2141
    if (left >= right || right <= 0) return;
 
2142
 
 
2143
    _XmDataFieldDrawInsertionPoint(tf, False);
 
2144
    endmode = df_FindHighlight(tf, right)->mode;
 
2145
    df_InsertHighlight(tf, left, mode);
 
2146
    df_InsertHighlight(tf, right, endmode);
 
2147
    l = XmTextF_highlight(tf).list;
 
2148
    i = 1;
 
2149
    while (i < XmTextF_highlight(tf).number) {
 
2150
        if (l[i].position >= left && l[i].position < right)
 
2151
            l[i].mode = mode;
 
2152
        if (l[i].mode == l[i-1].mode) {
 
2153
            XmTextF_highlight(tf).number--;
 
2154
            for (j=i ; j<XmTextF_highlight(tf).number ; j++)
 
2155
                l[j] = l[j+1];
 
2156
        } else i++;
 
2157
    }
 
2158
    if (XmTextF_cursor_position(tf) > left && XmTextF_cursor_position(tf) < right){
 
2159
       if (mode == XmHIGHLIGHT_SELECTED){
 
2160
          df_InvertImageGC(tf);
 
2161
       } else if (mode != XmHIGHLIGHT_SELECTED){
 
2162
          df_ResetImageGC(tf);
 
2163
       }
 
2164
    }
 
2165
    XmTextF_refresh_ibeam_off(tf) = True;
 
2166
    _XmDataFieldDrawInsertionPoint(tf, True);
 
2167
}
 
2168
 
 
2169
/*
 
2170
 * Get x and y based on position.
 
2171
 */
 
2172
static Boolean 
 
2173
#ifdef _NO_PROTO
 
2174
df_GetXYFromPos( tf, position, x, y )
 
2175
        XmDataFieldWidget tf ;
 
2176
        XmTextPosition position ;
 
2177
        Position *x ;
 
2178
        Position *y ;
 
2179
#else
 
2180
df_GetXYFromPos(
 
2181
        XmDataFieldWidget tf,
 
2182
        XmTextPosition position,
 
2183
        Position *x,
 
2184
        Position *y )
 
2185
#endif /* _NO_PROTO */
 
2186
{
 
2187
    int x1, x2;
 
2188
 
 
2189
    /* initialize the x and y positions to zero */
 
2190
    if (XmDataField_alignment(tf) == XmALIGNMENT_BEGINNING)
 
2191
    {
 
2192
        *x = 0;
 
2193
        *y = 0;
 
2194
 
 
2195
        if (position > XmTextF_string_length(tf)) return False;
 
2196
 
 
2197
        if (XmTextF_max_char_size(tf) != 1) {
 
2198
            x1 = df_FindPixelLength(tf, (char*)XmTextF_wc_value(tf), (int)position);
 
2199
        } else {
 
2200
            x1 = df_FindPixelLength(tf, XmTextF_value(tf), (int)position);
 
2201
        }
 
2202
    }
 
2203
    else
 
2204
    {
 
2205
        int     length;
 
2206
 
 
2207
        *x = tf->core.width - (XmTextF_margin_width(tf) +
 
2208
                               tf->primitive.highlight_thickness +
 
2209
                               tf->primitive.shadow_thickness);
 
2210
        *y = 0;
 
2211
 
 
2212
        length = XmTextF_string_length(tf) - position;
 
2213
 
 
2214
        if (length < 0) return False;
 
2215
 
 
2216
        if (XmTextF_max_char_size(tf) != 1) {
 
2217
            x1 = df_FindPixelLength(tf, (char*)(XmTextF_wc_value(tf) + position),
 
2218
                                 length);
 
2219
        } else {
 
2220
            x1 = df_FindPixelLength(tf, XmTextF_value(tf) + position, length);
 
2221
        }
 
2222
    }
 
2223
 
 
2224
    *y += tf->primitive.highlight_thickness + tf->primitive.shadow_thickness
 
2225
          + XmTextF_margin_top(tf) + XmTextF_font_ascent(tf);
 
2226
    x2 = (Position) XmTextF_h_offset(tf);
 
2227
 
 
2228
    if (XmDataField_alignment(tf) == XmALIGNMENT_BEGINNING)
 
2229
    {
 
2230
        *x += x1 + x2;
 
2231
    }
 
2232
    else
 
2233
    {
 
2234
        *x -= (x1 - x2);
 
2235
    }
 
2236
 
 
2237
    return True;
 
2238
}
 
2239
 
 
2240
static Boolean 
 
2241
#ifdef _NO_PROTO
 
2242
df_CurrentCursorState( tf )
 
2243
        XmDataFieldWidget tf ;
 
2244
#else
 
2245
df_CurrentCursorState(
 
2246
        XmDataFieldWidget tf )
 
2247
#endif /* _NO_PROTO */
 
2248
{
 
2249
    if (XmTextF_cursor_on(tf) < 0) return False;
 
2250
    if (XmTextF_blink_on(tf) || !XtIsSensitive((Widget)tf))
 
2251
        return True;
 
2252
    return False;
 
2253
}
 
2254
 
 
2255
/*
 
2256
 * Paint insert cursor
 
2257
 */
 
2258
static void 
 
2259
#ifdef _NO_PROTO
 
2260
df_PaintCursor( tf )
 
2261
        XmDataFieldWidget tf ;
 
2262
#else
 
2263
df_PaintCursor(
 
2264
        XmDataFieldWidget tf )
 
2265
#endif /* _NO_PROTO */
 
2266
{
 
2267
    Position x, y;
 
2268
    XmTextPosition position;
 
2269
 
 
2270
    if (!XmTextF_cursor_position_visible(tf)) return;
 
2271
 
 
2272
    if (!XmTextF_has_rect(tf)) _XmDataFieldSetClipRect(tf);
 
2273
 
 
2274
    position = XmTextF_cursor_position(tf);
 
2275
    (void) df_GetXYFromPos(tf, position, &x, &y);
 
2276
 
 
2277
    if (!XmTextF_overstrike(tf))
 
2278
      x -=(XmTextF_cursor_width(tf) >> 1) + 1; /* "+1" for 1 pixel left of char */
 
2279
    else {
 
2280
      int pxlen;
 
2281
      if (XmTextF_max_char_size(tf) != 1) 
 
2282
        pxlen = df_FindPixelLength(tf, (char*)&(XmTextF_wc_value(tf)[position]), 1);
 
2283
      else 
 
2284
        pxlen = df_FindPixelLength(tf, &(XmTextF_value(tf)[position]), 1);
 
2285
      if (pxlen > XmTextF_cursor_width(tf))
 
2286
        x += (pxlen - XmTextF_cursor_width(tf)) >> 1;
 
2287
    }
 
2288
    y = (y + (Position) XmTextF_font_descent(tf)) -
 
2289
         (Position) XmTextF_cursor_height(tf);
 
2290
 
 
2291
/* If time to paint the I Beam... first capture the IBeamOffArea, then draw
 
2292
 * the IBeam */
 
2293
 
 
2294
    if (XmTextF_refresh_ibeam_off(tf) == True){ /* get area under IBeam first */
 
2295
      /* Fill is needed to realign clip rectangle with gc */
 
2296
       XFillRectangle(XtDisplay((Widget)tf), XtWindow((Widget)tf),
 
2297
                         XmTextF_save_gc(tf), 0, 0, 0, 0);
 
2298
 
 
2299
       XCopyArea(XtDisplay(tf), XtWindow(tf), XmTextF_ibeam_off(tf), 
 
2300
                 XmTextF_save_gc(tf), x, y, XmTextF_cursor_width(tf), 
 
2301
                 XmTextF_cursor_height(tf), 0, 0);
 
2302
       XmTextF_refresh_ibeam_off(tf) = False;
 
2303
    }
 
2304
 
 
2305
    if ((XmTextF_cursor_on(tf) >= 0) && XmTextF_blink_on(tf)) {
 
2306
       XFillRectangle(XtDisplay(tf), XtWindow(tf), XmTextF_image_gc(tf), x, y,
 
2307
                      XmTextF_cursor_width(tf), XmTextF_cursor_height(tf));
 
2308
    } else {
 
2309
       XCopyArea(XtDisplay(tf), XmTextF_ibeam_off(tf), XtWindow(tf), 
 
2310
                 XmTextF_save_gc(tf), 0, 0, XmTextF_cursor_width(tf), 
 
2311
                 XmTextF_cursor_height(tf), x, y);
 
2312
    }
 
2313
}
 
2314
 
 
2315
void 
 
2316
#ifdef _NO_PROTO
 
2317
_XmDataFieldDrawInsertionPoint( tf, turn_on )
 
2318
        XmDataFieldWidget tf ;
 
2319
        Boolean turn_on ;
 
2320
#else
 
2321
_XmDataFieldDrawInsertionPoint(
 
2322
        XmDataFieldWidget tf,
 
2323
        Boolean turn_on )
 
2324
#endif /* _NO_PROTO */
 
2325
{
 
2326
 
 
2327
    if (turn_on == True) {
 
2328
       XmTextF_cursor_on(tf) += 1;
 
2329
       if (XmTextF_blink_rate(tf) == 0 || !XmTextF_has_focus(tf))
 
2330
          XmTextF_blink_on(tf) = True;
 
2331
    } else {
 
2332
       if (XmTextF_blink_on(tf) && (XmTextF_cursor_on(tf) == 0))
 
2333
          if (XmTextF_blink_on(tf) == df_CurrentCursorState(tf) &&
 
2334
              XtIsRealized((Widget)tf)){
 
2335
             XmTextF_blink_on(tf) = !XmTextF_blink_on(tf);
 
2336
             df_PaintCursor(tf);
 
2337
       }
 
2338
       XmTextF_cursor_on(tf) -= 1;
 
2339
    }
 
2340
 
 
2341
    if (XmTextF_cursor_on(tf) < 0 || !XtIsRealized((Widget) tf))
 
2342
        return;
 
2343
 
 
2344
    df_PaintCursor(tf);
 
2345
}
 
2346
 
 
2347
static void 
 
2348
#ifdef _NO_PROTO
 
2349
df_BlinkInsertionPoint( tf )
 
2350
        XmDataFieldWidget tf ;
 
2351
#else
 
2352
df_BlinkInsertionPoint(
 
2353
        XmDataFieldWidget tf )
 
2354
#endif /* _NO_PROTO */
 
2355
{
 
2356
    if ((XmTextF_cursor_on(tf) >= 0) &&
 
2357
        XmTextF_blink_on(tf) == df_CurrentCursorState(tf) &&
 
2358
        XtIsRealized((Widget)tf)) {
 
2359
       XmTextF_blink_on(tf) = !XmTextF_blink_on(tf);
 
2360
       df_PaintCursor(tf);
 
2361
    }
 
2362
}
 
2363
 
 
2364
 
 
2365
 
 
2366
/*
 
2367
 * Handle blink on and off
 
2368
 */
 
2369
/* ARGSUSED */
 
2370
static void 
 
2371
#ifdef _NO_PROTO
 
2372
df_HandleTimer( closure, id )
 
2373
        XtPointer closure ;
 
2374
        XtIntervalId *id ;
 
2375
#else
 
2376
df_HandleTimer(
 
2377
        XtPointer closure,
 
2378
        XtIntervalId *id )
 
2379
#endif /* _NO_PROTO */
 
2380
{
 
2381
    XmDataFieldWidget tf = (XmDataFieldWidget) closure;
 
2382
 
 
2383
    if (XmTextF_blink_rate(tf) != 0)
 
2384
        XmTextF_timer_id(tf) =
 
2385
                 XtAppAddTimeOut(XtWidgetToApplicationContext((Widget)tf),
 
2386
                                 (unsigned long)XmTextF_blink_rate(tf),
 
2387
                                 df_HandleTimer,
 
2388
                                 (XtPointer) closure);
 
2389
    if (XmTextF_has_focus(tf) && XtIsSensitive((Widget)tf))
 
2390
        df_BlinkInsertionPoint(tf);
 
2391
}
 
2392
 
 
2393
 
 
2394
/*
 
2395
 * Change state of blinking insert cursor on and off
 
2396
 */
 
2397
static void 
 
2398
#ifdef _NO_PROTO
 
2399
df_ChangeBlinkBehavior( tf, turn_on )
 
2400
        XmDataFieldWidget tf ;
 
2401
        Boolean turn_on ;
 
2402
#else
 
2403
df_ChangeBlinkBehavior(
 
2404
        XmDataFieldWidget tf,
 
2405
#if NeedWidePrototypes
 
2406
        int turn_on )
 
2407
#else
 
2408
        Boolean turn_on )
 
2409
#endif /* NeedWidePrototypes */
 
2410
#endif /* _NO_PROTO */
 
2411
{
 
2412
 
 
2413
    if (turn_on) {
 
2414
        if (XmTextF_blink_rate(tf) != 0 && XmTextF_timer_id(tf) == (XtIntervalId)0)
 
2415
            XmTextF_timer_id(tf) =
 
2416
                XtAppAddTimeOut(XtWidgetToApplicationContext((Widget)tf),
 
2417
                                (unsigned long)XmTextF_blink_rate(tf),
 
2418
                                df_HandleTimer,
 
2419
                                (XtPointer) tf);
 
2420
        XmTextF_blink_on(tf) = True;
 
2421
    } else {
 
2422
        if (XmTextF_timer_id(tf))
 
2423
            XtRemoveTimeOut(XmTextF_timer_id(tf));
 
2424
        XmTextF_timer_id(tf) = (XtIntervalId)0;
 
2425
    }
 
2426
}
 
2427
 
 
2428
static void 
 
2429
#ifdef _NO_PROTO
 
2430
df_GetRect( tf, rect )
 
2431
        XmDataFieldWidget tf ;
 
2432
        XRectangle *rect ;
 
2433
#else
 
2434
df_GetRect(
 
2435
        XmDataFieldWidget tf,
 
2436
        XRectangle *rect )
 
2437
#endif /* _NO_PROTO */
 
2438
{
 
2439
  Dimension margin_width = XmTextF_margin_width(tf) +
 
2440
                           tf->primitive.shadow_thickness +
 
2441
                           tf->primitive.highlight_thickness;
 
2442
  Dimension margin_top = XmTextF_margin_top(tf) + tf->primitive.shadow_thickness +
 
2443
                         tf->primitive.highlight_thickness;
 
2444
  Dimension margin_bottom = XmTextF_margin_bottom(tf) +
 
2445
                            tf->primitive.shadow_thickness +
 
2446
                            tf->primitive.highlight_thickness;
 
2447
 
 
2448
  if (margin_width < tf->core.width)
 
2449
     rect->x = margin_width;
 
2450
  else
 
2451
     rect->x = tf->core.width;
 
2452
 
 
2453
  if (margin_top  < tf->core.height)
 
2454
     rect->y = margin_top;
 
2455
  else
 
2456
     rect->y = tf->core.height;
 
2457
 
 
2458
  if ((int)(2 * margin_width) < (int)tf->core.width)
 
2459
     rect->width = (int) tf->core.width - (2 * margin_width);
 
2460
  else
 
2461
     rect->width = 0;
 
2462
 
 
2463
  if ((int)(margin_top + margin_bottom) < (int)tf->core.height)
 
2464
     rect->height = (int) tf->core.height - (margin_top + margin_bottom);
 
2465
  else
 
2466
     rect->height = 0;
 
2467
}
 
2468
 
 
2469
static void
 
2470
#ifdef _NO_PROTO
 
2471
df_CheckHasRect( tf )
 
2472
        XmDataFieldWidget tf ;
 
2473
#else
 
2474
df_CheckHasRect(
 
2475
        XmDataFieldWidget tf )
 
2476
#endif /* _NO_PROTO */
 
2477
{
 
2478
 /*
 
2479
  * Make sure the cached GC has the clipping rectangle
 
2480
  * set to the current widget.
 
2481
  */
 
2482
  if (!XmTextF_has_rect(tf)) {
 
2483
     TextFGCData gc_data = df_GetTextFGCData((Widget)tf);
 
2484
     XmTextF_has_rect(gc_data->tf) = False;
 
2485
     gc_data->tf = tf;
 
2486
     XmTextF_has_rect(tf) = True;
 
2487
  }
 
2488
}
 
2489
 
 
2490
static void 
 
2491
#ifdef _NO_PROTO
 
2492
df_XmSetFullGC( tf, gc )
 
2493
        XmDataFieldWidget tf ;
 
2494
        GC gc ;
 
2495
#else
 
2496
df_XmSetFullGC(
 
2497
        XmDataFieldWidget tf,
 
2498
        GC gc )
 
2499
#endif /* _NO_PROTO */
 
2500
{
 
2501
  XRectangle ClipRect;
 
2502
 
 
2503
 /* adjust clip rectangle to allow the cursor to paint into the margins */
 
2504
  ClipRect.x = tf->primitive.shadow_thickness +
 
2505
               tf->primitive.highlight_thickness;
 
2506
  ClipRect.y = tf->primitive.shadow_thickness +
 
2507
               tf->primitive.highlight_thickness;
 
2508
  ClipRect.width = tf->core.width - (2 * (tf->primitive.shadow_thickness +
 
2509
                                          tf->primitive.highlight_thickness));
 
2510
  ClipRect.height = tf->core.height - (2 * (tf->primitive.shadow_thickness +
 
2511
                                           tf->primitive.highlight_thickness));
 
2512
 
 
2513
  XSetClipRectangles(XtDisplay(tf), gc, 0, 0, &ClipRect, 1,
 
2514
                     Unsorted);
 
2515
}
 
2516
 
 
2517
static void 
 
2518
#ifdef _NO_PROTO
 
2519
df_XmSetMarginGC( tf, gc )
 
2520
        XmDataFieldWidget tf ;
 
2521
        GC gc ;
 
2522
#else
 
2523
df_XmSetMarginGC(
 
2524
        XmDataFieldWidget tf,
 
2525
        GC gc )
 
2526
#endif /* _NO_PROTO */
 
2527
{
 
2528
  XRectangle ClipRect;
 
2529
 
 
2530
  df_GetRect(tf, &ClipRect);
 
2531
#ifdef USE_XFT
 
2532
  if (XmTextF_use_xft(tf))
 
2533
    _XmXftSetClipRectangles(XtDisplay(tf), XtWindow(tf), 0, 0, &ClipRect, 1);
 
2534
#endif
 
2535
  XSetClipRectangles(XtDisplay(tf), gc, 0, 0, &ClipRect, 1,
 
2536
                     Unsorted);
 
2537
}
 
2538
 
 
2539
 
 
2540
static void
 
2541
#ifdef _NO_PROTO
 
2542
df_XmResetSaveGC( tf, gc )
 
2543
        XmDataFieldWidget tf ;
 
2544
        GC gc ;
 
2545
#else
 
2546
df_XmResetSaveGC(
 
2547
        XmDataFieldWidget tf,
 
2548
        GC gc )
 
2549
#endif /* _NO_PROTO */
 
2550
{
 
2551
  XSetClipMask(XtDisplay(tf), gc, None);
 
2552
}
 
2553
 
 
2554
/*
 
2555
 * Set new clipping rectangle for text field.  This is
 
2556
 * done on each focus in event since the text field widgets
 
2557
 * share the same GC.
 
2558
 */
 
2559
void 
 
2560
#ifdef _NO_PROTO
 
2561
_XmDataFieldSetClipRect( tf )
 
2562
        XmDataFieldWidget tf ;
 
2563
#else
 
2564
_XmDataFieldSetClipRect(
 
2565
        XmDataFieldWidget tf )
 
2566
#endif /* _NO_PROTO */
 
2567
{
 
2568
  XGCValues values;
 
2569
  unsigned long valuemask = (unsigned long) 0;
 
2570
  
 
2571
 
 
2572
 /*
 
2573
  * Make sure the cached GC has the clipping rectangle
 
2574
  * set to the current widget.
 
2575
  */
 
2576
  df_CheckHasRect(tf);
 
2577
 
 
2578
  df_XmSetMarginGC(tf, XmTextF_gc(tf));
 
2579
  df_XmSetFullGC(tf, XmTextF_image_gc(tf));
 
2580
 
 
2581
  df_ResetClipOrigin(tf, False);
 
2582
 
 
2583
 
 
2584
 /* Restore cached save gc to state correct for this instantiation */
 
2585
  if (XmTextF_save_gc(tf)){
 
2586
     valuemask = (GCFunction | GCBackground | GCForeground);
 
2587
     values.function = GXcopy;
 
2588
     values.foreground = tf->primitive.foreground ;
 
2589
     values.background = tf->core.background_pixel;
 
2590
     XChangeGC(XtDisplay(tf), XmTextF_save_gc(tf), valuemask, &values);
 
2591
  }
 
2592
 
 
2593
 /* Restore cached text gc to state correct for this instantiation */
 
2594
 
 
2595
  if (XmTextF_gc(tf)){
 
2596
#if USE_XFT
 
2597
     if (!XmTextF_have_fontset(tf) && !XmTextF_use_xft(tf)
 
2598
         && (XmTextF_font(tf) != NULL)) {
 
2599
#else
 
2600
     if (!XmTextF_have_fontset(tf) && (XmTextF_font(tf) != NULL)){
 
2601
#endif
 
2602
        valuemask |= GCFont;
 
2603
        values.font = XmTextF_font(tf)->fid;
 
2604
     }
 
2605
     valuemask |= GCGraphicsExposures;
 
2606
     values.graphics_exposures = (Bool) True;
 
2607
     values.foreground = tf->primitive.foreground ^ tf->core.background_pixel;
 
2608
     values.background = 0;
 
2609
     XChangeGC(XtDisplay(tf), XmTextF_gc(tf), valuemask, &values);
 
2610
  }
 
2611
 
 
2612
 /* Restore cached image gc to state correct for this instantiation */
 
2613
  if (XmTextF_image_gc(tf)){
 
2614
     valuemask = (GCForeground | GCBackground);
 
2615
     if (XmTextF_overstrike(tf)) {
 
2616
       values.background = values.foreground = 
 
2617
         tf->core.background_pixel ^ tf->primitive.foreground;
 
2618
     } else if (XmTextF_have_inverted_image_gc(tf)){
 
2619
       values.background = tf->primitive.foreground;
 
2620
       values.foreground = tf->core.background_pixel;
 
2621
     } else {
 
2622
       values.foreground = tf->primitive.foreground;
 
2623
       values.background = tf->core.background_pixel;
 
2624
     }
 
2625
     XChangeGC(XtDisplay(tf), XmTextF_image_gc(tf), valuemask, &values);
 
2626
  }
 
2627
 
 
2628
  _XmDataFToggleCursorGC((Widget)tf);
 
2629
}
 
2630
 
 
2631
static void 
 
2632
#ifdef _NO_PROTO
 
2633
df_XmSetNormGC( tf, gc, change_stipple, stipple )
 
2634
        XmDataFieldWidget tf ;
 
2635
        GC gc ;
 
2636
        Boolean change_stipple;
 
2637
        Boolean stipple;
 
2638
#else
 
2639
df_XmSetNormGC(
 
2640
        XmDataFieldWidget tf,
 
2641
        GC gc,
 
2642
#if NeedWidePrototypes
 
2643
        int change_stipple,
 
2644
        int stipple)
 
2645
#else
 
2646
        Boolean change_stipple,
 
2647
        Boolean stipple)
 
2648
#endif /* NeedWidePrototypes */
 
2649
#endif /* _NO_PROTO */
 
2650
{
 
2651
    unsigned long valueMask = (GCForeground | GCBackground);
 
2652
    XGCValues values;
 
2653
 
 
2654
    if (!XmTextF_has_rect(tf)) _XmDataFieldSetClipRect(tf);
 
2655
    values.foreground = tf->primitive.foreground;
 
2656
    values.background = tf->core.background_pixel;
 
2657
    if (change_stipple) {
 
2658
       valueMask |= GCTile | GCFillStyle;
 
2659
       values.tile = XmTextF_stipple_tile(tf);
 
2660
       if (stipple) values.fill_style = FillTiled;
 
2661
       else values.fill_style = FillSolid;
 
2662
    }
 
2663
 
 
2664
    XChangeGC(XtDisplay(tf), gc, valueMask, &values);
 
2665
}
 
2666
 
 
2667
static void 
 
2668
#ifdef _NO_PROTO
 
2669
df_XmSetInvGC( tf, gc )
 
2670
        XmDataFieldWidget tf ;
 
2671
        GC gc ;
 
2672
#else
 
2673
df_XmSetInvGC(
 
2674
        XmDataFieldWidget tf,
 
2675
        GC gc )
 
2676
#endif /* _NO_PROTO */
 
2677
{
 
2678
    unsigned long valueMask = (GCForeground | GCBackground);
 
2679
    XGCValues values;
 
2680
 
 
2681
    if (!XmTextF_has_rect(tf)) _XmDataFieldSetClipRect(tf);
 
2682
    values.foreground = tf->core.background_pixel;
 
2683
    values.background = tf->primitive.foreground;
 
2684
 
 
2685
    XChangeGC(XtDisplay(tf), gc, valueMask, &values);
 
2686
}
 
2687
 
 
2688
static void
 
2689
#ifdef _NO_PROTO
 
2690
df_DrawText( tf, gc, x, y, string, length )
 
2691
        XmDataFieldWidget tf ;
 
2692
        GC gc ;
 
2693
        int x ;
 
2694
        int y ;
 
2695
        char * string ;
 
2696
        int length ;
 
2697
#else
 
2698
df_DrawText(
 
2699
        XmDataFieldWidget tf,
 
2700
        GC  gc,
 
2701
        int x,
 
2702
        int y,
 
2703
        char * string,
 
2704
        int length )
 
2705
#endif /* _NO_PROTO */
 
2706
{
 
2707
   if (XmTextF_have_fontset(tf)){
 
2708
      if (XmTextF_max_char_size(tf) != 1) 
 
2709
         XwcDrawString (XtDisplay(tf), XtWindow(tf), (XFontSet)XmTextF_font(tf),
 
2710
                        gc, x, y, (wchar_t*) string, length);
 
2711
 
 
2712
      else  /* one byte chars */
 
2713
         XmbDrawString (XtDisplay(tf), XtWindow(tf), (XFontSet)XmTextF_font(tf),
 
2714
                        gc, x, y, string, length);
 
2715
 
 
2716
#ifdef USE_XFT
 
2717
  } else if (XmTextF_use_xft(tf)) {
 
2718
    if (XmTextF_max_char_size(tf) != 1) { /* was passed a wchar_t*  */
 
2719
      char stack_cache[400], *tmp;
 
2720
      wchar_t tmp_wc;
 
2721
      wchar_t *wc_string = (wchar_t*)string;
 
2722
      int num_bytes = 0;
 
2723
      /* ptr = tmp = XtMalloc((int)(length + 1)*sizeof(wchar_t)); */
 
2724
      tmp = (char *)XmStackAlloc((Cardinal) ((length + 1)*sizeof(wchar_t)),
 
2725
                                 stack_cache);
 
2726
      tmp_wc = wc_string[length];
 
2727
      wc_string[length] = 0L;
 
2728
      num_bytes = wcstombs(tmp, wc_string,
 
2729
                           (int)((length + 1) * sizeof(wchar_t)));
 
2730
      wc_string[length] = tmp_wc;
 
2731
      if (num_bytes >= 0)
 
2732
        _XmXftDrawString2(XtDisplay(tf), XtWindow(tf), gc, XmTextF_xft_font(tf),
 
2733
                        1, x, y, tmp, num_bytes);
 
2734
      XmStackFree(tmp, stack_cache);
 
2735
    } else /* one byte chars */
 
2736
        _XmXftDrawString2(XtDisplay(tf), XtWindow(tf), gc, XmTextF_xft_font(tf),
 
2737
                        1, x, y, string, length);
 
2738
#endif
 
2739
   } else { /* have a font struct, not a font set */
 
2740
      if (XmTextF_max_char_size(tf) != 1) { /* was passed a wchar_t*  */
 
2741
         char stack_cache[400], *tmp;
 
2742
         wchar_t tmp_wc;
 
2743
         wchar_t *wc_string = (wchar_t*)string;
 
2744
         int num_bytes = 0;
 
2745
         /* ptr = tmp = XtMalloc((int)(length + 1)*sizeof(wchar_t)); */
 
2746
         tmp = (char *)XmStackAlloc((Cardinal) ((length + 1)*sizeof(wchar_t)),
 
2747
                                    stack_cache);
 
2748
         tmp_wc = wc_string[length];
 
2749
         wc_string[length] = 0L;
 
2750
         num_bytes = wcstombs(tmp, wc_string,
 
2751
                              (int)((length + 1) * sizeof(wchar_t)));
 
2752
         wc_string[length] = tmp_wc;
 
2753
         if (num_bytes >= 0) {
 
2754
           if (_XmIsISO10646(XtDisplay(tf), XmTextF_font(tf))) {
 
2755
             size_t str_len = 0;
 
2756
             XChar2b *str = _XmUtf8ToUcs2(tmp, num_bytes, &str_len);
 
2757
             XDrawString16(XtDisplay(tf), XtWindow(tf), gc, x, y,
 
2758
                             str, str_len);
 
2759
             XFree(str);
 
2760
           } else
 
2761
             XDrawString(XtDisplay(tf), XtWindow(tf), gc, x, y,
 
2762
                             tmp, num_bytes);
 
2763
         }
 
2764
         XmStackFree((char *)tmp, stack_cache);
 
2765
      } else /* one byte chars */
 
2766
         XDrawString (XtDisplay(tf), XtWindow(tf), gc, x, y, string, length);
 
2767
   }
 
2768
}
 
2769
 
 
2770
static int
 
2771
#ifdef _NO_PROTO
 
2772
df_FindPixelLength( tf, string, length)
 
2773
        XmDataFieldWidget tf ;
 
2774
        char * string ;
 
2775
        int length ;
 
2776
#else
 
2777
df_FindPixelLength(
 
2778
        XmDataFieldWidget tf,
 
2779
        char * string,
 
2780
        int length )
 
2781
#endif /* _NO_PROTO */
 
2782
{
 
2783
   if (XmTextF_have_fontset(tf)) {
 
2784
      if (XmTextF_max_char_size(tf) != 1)
 
2785
         return (XwcTextEscapement((XFontSet)XmTextF_font(tf), 
 
2786
                                   (wchar_t *) string, length));
 
2787
      else /* one byte chars */
 
2788
         return (XmbTextEscapement((XFontSet)XmTextF_font(tf), string, length));
 
2789
#ifdef USE_XFT
 
2790
  } else if (XmTextF_use_xft(tf)) {
 
2791
    XGlyphInfo  ext;
 
2792
    if (XmTextF_max_char_size(tf) != 1) { /* was passed a wchar_t*  */
 
2793
      wchar_t *wc_string = (wchar_t*)string;
 
2794
      wchar_t wc_tmp = wc_string[length];
 
2795
      char stack_cache[400], *tmp;
 
2796
      int num_bytes;
 
2797
      
 
2798
      wc_string[length] = 0L;
 
2799
      tmp = (char*)XmStackAlloc((Cardinal)((length + 1) * sizeof(wchar_t)),
 
2800
                                stack_cache);
 
2801
      num_bytes = wcstombs(tmp, wc_string, 
 
2802
                           (int)((length + 1)*sizeof(wchar_t)));
 
2803
      wc_string[length] = wc_tmp;
 
2804
      XftTextExtentsUtf8(XtDisplay(tf), XmTextF_xft_font(tf),
 
2805
          (FcChar8*)tmp, num_bytes, &ext);
 
2806
      XmStackFree(tmp, stack_cache);
 
2807
    } else /* one byte chars */
 
2808
      XftTextExtentsUtf8(XtDisplay(tf), XmTextF_xft_font(tf),
 
2809
          (FcChar8*)string, length, &ext);
 
2810
 
 
2811
    return ext.xOff;
 
2812
#endif
 
2813
   } else { /* have font struct, not a font set */
 
2814
      if (XmTextF_max_char_size(tf) != 1) { /* was passed a wchar_t*  */
 
2815
         wchar_t *wc_string = (wchar_t*)string;
 
2816
         wchar_t wc_tmp = wc_string[length];
 
2817
         char stack_cache[400], *tmp;
 
2818
         int num_bytes, ret_len = 0;
 
2819
 
 
2820
         wc_string[length] = 0L;
 
2821
         tmp = (char*)XmStackAlloc((Cardinal)((length + 1) * sizeof(wchar_t)),
 
2822
                                   stack_cache);
 
2823
         num_bytes = wcstombs(tmp, wc_string, 
 
2824
                              (int)((length + 1)*sizeof(wchar_t)));
 
2825
         wc_string[length] = wc_tmp;
 
2826
         if (num_bytes >= 0) {
 
2827
           if (_XmIsISO10646(XtDisplay(tf), XmTextF_font(tf))) {
 
2828
             size_t str_len = 0;
 
2829
             XChar2b *str = _XmUtf8ToUcs2(tmp, num_bytes, &str_len);
 
2830
             ret_len = XTextWidth16(XmTextF_font(tf), str, str_len);
 
2831
             XFree(str);
 
2832
           } else
 
2833
            ret_len = XTextWidth(XmTextF_font(tf), tmp, num_bytes);
 
2834
         }
 
2835
         XmStackFree((char *)tmp, stack_cache);
 
2836
         return (ret_len);
 
2837
      } else /* one byte chars */
 
2838
         return (XTextWidth(XmTextF_font(tf), string, length));
 
2839
   }
 
2840
}
 
2841
 
 
2842
static void
 
2843
#ifdef _NO_PROTO
 
2844
df_DrawTextSegment( tf, mode, prev_seg_start, seg_start, seg_end, next_seg,
 
2845
                 stipple, y, x)
 
2846
        XmDataFieldWidget tf ;
 
2847
        XmHighlightMode mode;
 
2848
        XmTextPosition prev_seg_start;
 
2849
        XmTextPosition seg_start;
 
2850
        XmTextPosition seg_end;
 
2851
        XmTextPosition next_seg;
 
2852
        Boolean stipple;
 
2853
        int y ;
 
2854
        int *x ;
 
2855
#else
 
2856
df_DrawTextSegment(
 
2857
        XmDataFieldWidget tf,
 
2858
        XmHighlightMode mode,
 
2859
        XmTextPosition prev_seg_start,
 
2860
        XmTextPosition seg_start,
 
2861
        XmTextPosition seg_end,
 
2862
        XmTextPosition next_seg,
 
2863
#if NeedWidePrototypes
 
2864
        int stipple,
 
2865
#else
 
2866
        Boolean stipple,
 
2867
#endif /* NeedWidePrototypes */
 
2868
        int y,
 
2869
        int *x)
 
2870
#endif /* _NO_PROTO */
 
2871
{
 
2872
    int x_seg_len;
 
2873
 
 
2874
#if PWC_DEBUG
 
2875
    {
 
2876
        char seg[256];
 
2877
 
 
2878
        memset((char *)seg, 256, 0);
 
2879
        strncpy(seg, (char *)(XmTextF_value(tf) + seg_start),
 
2880
                seg_end - seg_start);
 
2881
 
 
2882
        seg[seg_end] = '\0';
 
2883
 
 
2884
        printf("df_DrawText(\"%s\" - %s) :: [start(%d), end(%d), x(%d), offset(%d)]\n",
 
2885
               seg, (mode == XmHIGHLIGHT_NORMAL ? "NORMAL" : "HIGHLIGHT"),
 
2886
               seg_start, seg_end, *x, XmTextF_h_offset(tf));
 
2887
    }
 
2888
#endif
 
2889
 
 
2890
    /* update x position up to start position */
 
2891
    if (XmTextF_max_char_size(tf) != 1) {
 
2892
       *x += df_FindPixelLength(tf, (char*)(XmTextF_wc_value(tf) + prev_seg_start),
 
2893
                                 (int)(seg_start - prev_seg_start));
 
2894
       x_seg_len = df_FindPixelLength(tf, (char*)(XmTextF_wc_value(tf) + seg_start),
 
2895
                                           (int)seg_end - (int)seg_start);
 
2896
    } else {
 
2897
       *x += df_FindPixelLength(tf, XmTextF_value(tf) + prev_seg_start,
 
2898
                                 (int)(seg_start - prev_seg_start));
 
2899
       x_seg_len = df_FindPixelLength(tf, XmTextF_value(tf) + seg_start,
 
2900
                                           (int)seg_end - (int)seg_start);
 
2901
    }
 
2902
    if (mode == XmHIGHLIGHT_SELECTED) {
 
2903
      /* Draw the selected text using an inverse gc */
 
2904
       df_XmSetNormGC(tf, XmTextF_gc(tf), False, False);
 
2905
       XFillRectangle(XtDisplay(tf), XtWindow(tf), XmTextF_gc(tf), *x, 
 
2906
                      y - XmTextF_font_ascent(tf), x_seg_len,
 
2907
                      XmTextF_font_ascent(tf) + XmTextF_font_descent(tf));
 
2908
       df_XmSetInvGC(tf, XmTextF_gc(tf));
 
2909
    } else {
 
2910
       df_XmSetInvGC(tf, XmTextF_gc(tf));
 
2911
       XFillRectangle(XtDisplay(tf), XtWindow(tf), XmTextF_gc(tf), *x, 
 
2912
                      y - XmTextF_font_ascent(tf), x_seg_len,
 
2913
                      XmTextF_font_ascent(tf) + XmTextF_font_descent(tf));
 
2914
       df_XmSetNormGC(tf, XmTextF_gc(tf), True, stipple);
 
2915
    }
 
2916
 
 
2917
    if (XmTextF_max_char_size(tf) != 1) {
 
2918
       df_DrawText(tf, XmTextF_gc(tf), *x, y, (char*) (XmTextF_wc_value(tf) + seg_start),
 
2919
                                           (int)seg_end - (int)seg_start);
 
2920
    } else {
 
2921
       df_DrawText(tf, XmTextF_gc(tf), *x, y, XmTextF_value(tf) + seg_start,
 
2922
                                           (int)seg_end - (int)seg_start);
 
2923
    }
 
2924
    if (stipple) df_XmSetNormGC(tf, XmTextF_gc(tf), True, !stipple);
 
2925
   
 
2926
    if (mode == XmHIGHLIGHT_SECONDARY_SELECTED)
 
2927
       XDrawLine(XtDisplay(tf), XtWindow(tf), XmTextF_gc(tf), *x, y,
 
2928
                              *x + x_seg_len - 1, y);
 
2929
 
 
2930
   /* update x position up to the next highlight position */
 
2931
    if (XmTextF_max_char_size(tf) != 1)
 
2932
       *x += df_FindPixelLength(tf, (char*) (XmTextF_wc_value(tf) + seg_start),
 
2933
                                    (int)(next_seg - (int)seg_start));
 
2934
    else
 
2935
       *x += df_FindPixelLength(tf, XmTextF_value(tf) + seg_start,
 
2936
                                    (int)(next_seg - (int)seg_start));
 
2937
}
 
2938
 
 
2939
 
 
2940
/*
 
2941
 * Redisplay the new adjustments that have been made the the text
 
2942
 * field widget.
 
2943
 */
 
2944
static void 
 
2945
#ifdef _NO_PROTO
 
2946
df_RedisplayText( tf, start, end )
 
2947
        XmDataFieldWidget tf ;
 
2948
        XmTextPosition start ;
 
2949
        XmTextPosition end ;
 
2950
#else
 
2951
df_RedisplayText(
 
2952
        XmDataFieldWidget tf,
 
2953
        XmTextPosition start,
 
2954
        XmTextPosition end )
 
2955
#endif /* _NO_PROTO */
 
2956
{
 
2957
  _XmHighlightRec *l = XmTextF_highlight(tf).list;
 
2958
  XRectangle rect;
 
2959
  int x, y, i, startx = 0;
 
2960
  Dimension margin_width = XmTextF_margin_width(tf) +
 
2961
                           tf->primitive.shadow_thickness +
 
2962
                           tf->primitive.highlight_thickness;
 
2963
  Dimension margin_top = XmTextF_margin_top(tf) + tf->primitive.shadow_thickness +
 
2964
                         tf->primitive.highlight_thickness;
 
2965
  Dimension margin_bottom = XmTextF_margin_bottom(tf) +
 
2966
                            tf->primitive.shadow_thickness +
 
2967
                            tf->primitive.highlight_thickness;
 
2968
  Boolean stipple = False;
 
2969
 
 
2970
  if (!XtIsRealized((Widget)tf)) return;
 
2971
 
 
2972
  if (XmTextF_in_setvalues(tf)) {
 
2973
     XmTextF_redisplay(tf) = True;
 
2974
     return;
 
2975
  }
 
2976
 
 
2977
  if ((int)tf->core.width - (int)(2 * margin_width) <= 0)
 
2978
    return;
 
2979
  if ((int)tf->core.height - (int)(margin_top + margin_bottom) <= 0)
 
2980
    return;
 
2981
 
 
2982
 /*
 
2983
  * Make sure the cached GC has the clipping rectangle
 
2984
  * set to the current widget.
 
2985
  */
 
2986
  if (!XmTextF_has_rect(tf)) _XmDataFieldSetClipRect(tf);
 
2987
 
 
2988
  _XmDataFieldDrawInsertionPoint(tf, False);
 
2989
 
 
2990
 /* Get the current rectangle.
 
2991
  */
 
2992
  df_GetRect(tf, &rect);
 
2993
 
 
2994
  y = margin_top + XmTextF_font_ascent(tf);
 
2995
  
 
2996
  if (XmDataField_alignment(tf) == XmALIGNMENT_END)
 
2997
  {
 
2998
      x = tf->core.width - margin_width + XmTextF_h_offset(tf);
 
2999
 
 
3000
      if (XmTextF_max_char_size(tf) != 1)
 
3001
          x -= df_FindPixelLength(tf, (char*)(XmTextF_wc_value(tf) + l[0].position),
 
3002
                               XmTextF_string_length(tf) - l[0].position);
 
3003
      else 
 
3004
          x -= df_FindPixelLength(tf, XmTextF_value(tf) + l[0].position,
 
3005
                               XmTextF_string_length(tf) - l[0].position);
 
3006
 
 
3007
      /* PWC - alignment requires we draw all characters to the left of end */
 
3008
      start = 0;
 
3009
      startx = x;
 
3010
  }
 
3011
  else
 
3012
      x = (int) XmTextF_h_offset(tf);
 
3013
 
 
3014
  if (!XtIsSensitive((Widget)tf)) stipple = True;
 
3015
 
 
3016
  /* search through the highlight array and draw the text */
 
3017
  for (i = 0; i + 1 < XmTextF_highlight(tf).number; i++) {
 
3018
#if PWC_DEBUG
 
3019
      printf("XmTextF_value(\"%s\")::Highlight #%d = pos(%d), start(%d), end(%d)\n",
 
3020
             (char *)XmTextF_value(tf), i, l[i].position, start, end);
 
3021
#endif
 
3022
     /* make sure start is within current highlight */
 
3023
      if (l[i].position <= start && start < l[i+1].position &&
 
3024
          l[i].position < end) {
 
3025
 
 
3026
         if (end > l[i+1].position) {
 
3027
            
 
3028
            df_DrawTextSegment(tf, l[i].mode, l[i].position, start,
 
3029
                            l[i+1].position, l[i+1].position, stipple, y, &x);
 
3030
 
 
3031
           /* update start position to the next highlight position */
 
3032
            start = l[i+1].position;
 
3033
 
 
3034
         } else {
 
3035
 
 
3036
            df_DrawTextSegment(tf, l[i].mode, l[i].position, start,
 
3037
                            end, l[i+1].position, stipple, y, &x);
 
3038
            start = end;
 
3039
         }
 
3040
      }
 
3041
      else
 
3042
      { /* start not within current record */
 
3043
          if (XmTextF_max_char_size(tf) != 1)
 
3044
          {
 
3045
              x += df_FindPixelLength(tf, (char *) (XmTextF_wc_value(tf)
 
3046
                                                 + l[i].position),
 
3047
                                   (int)(l[i+1].position - l[i].position));
 
3048
          }
 
3049
          else
 
3050
          {
 
3051
              x += df_FindPixelLength(tf, XmTextF_value(tf) + l[i].position,
 
3052
                                   (int)(l[i+1].position - l[i].position));
 
3053
          }
 
3054
     }
 
3055
  }  /* end for loop */
 
3056
 
 
3057
  if (l[i].position < end)
 
3058
  {
 
3059
      /* complete the drawing of the text to the end of the line */
 
3060
      df_DrawTextSegment(tf, l[i].mode, l[i].position, start, end,
 
3061
                      XmTextF_string_length(tf), stipple, y, &x);
 
3062
  } else {
 
3063
      if (XmTextF_max_char_size(tf) != 1)
 
3064
         x += df_FindPixelLength(tf, (char*) (XmTextF_wc_value(tf) + l[i].position),
 
3065
                              XmTextF_string_length(tf) - (int)l[i].position);
 
3066
     else 
 
3067
         x += df_FindPixelLength(tf, XmTextF_value(tf) + l[i].position,
 
3068
                              XmTextF_string_length(tf) - (int)l[i].position);
 
3069
  }
 
3070
 
 
3071
  if (x < (int)(rect.x + rect.width)
 
3072
      && XmDataField_alignment(tf) == XmALIGNMENT_BEGINNING) {
 
3073
    df_XmSetInvGC(tf, XmTextF_gc(tf));
 
3074
    XFillRectangle(XtDisplay(tf), XtWindow(tf), XmTextF_gc(tf), x, rect.y,
 
3075
                    rect.x + rect.width - x, rect.height);
 
3076
  } else if (XmTextF_h_offset(tf) < startx
 
3077
        && XmDataField_alignment(tf) == XmALIGNMENT_END) {
 
3078
    df_XmSetInvGC(tf, XmTextF_gc(tf));
 
3079
    XFillRectangle(XtDisplay(tf), XtWindow(tf), XmTextF_gc(tf), XmTextF_h_offset(tf), rect.y,
 
3080
                    startx - XmTextF_h_offset(tf), rect.height);
 
3081
  }
 
3082
 
 
3083
  XmTextF_refresh_ibeam_off(tf) = True;
 
3084
  _XmDataFieldDrawInsertionPoint(tf, True);
 
3085
}
 
3086
 
 
3087
 
 
3088
/*
 
3089
 * Use the font along with the resources that have been set
 
3090
 * to determine the height and width of the text field widget.
 
3091
 */
 
3092
static void 
 
3093
#ifdef _NO_PROTO
 
3094
df_ComputeSize( tf, width, height )
 
3095
        XmDataFieldWidget tf ;
 
3096
        Dimension *width ;
 
3097
        Dimension *height ;
 
3098
#else
 
3099
df_ComputeSize(
 
3100
        XmDataFieldWidget tf,
 
3101
        Dimension *width,
 
3102
        Dimension *height )
 
3103
#endif /* _NO_PROTO */
 
3104
{
 
3105
    Dimension tmp = 0;
 
3106
 
 
3107
    if (XmTextF_resize_width(tf) &&
 
3108
        XmTextF_columns(tf) < XmTextF_string_length(tf)){
 
3109
 
 
3110
       if (XmTextF_max_char_size(tf) != 1) 
 
3111
          tmp = df_FindPixelLength(tf, (char *)XmTextF_wc_value(tf),
 
3112
                                XmTextF_string_length(tf));
 
3113
       else
 
3114
          tmp = df_FindPixelLength(tf, XmTextF_value(tf), XmTextF_string_length(tf));
 
3115
 
 
3116
       
 
3117
       *width = tmp + (2 * (XmTextF_margin_width(tf) + 
 
3118
                            tf->primitive.shadow_thickness + 
 
3119
                            tf->primitive.highlight_thickness));
 
3120
    } else {
 
3121
        *width = XmTextF_columns(tf) * XmTextF_average_char_width(tf) +
 
3122
            2 * (XmTextF_margin_width(tf) + tf->primitive.shadow_thickness +
 
3123
                 tf->primitive.highlight_thickness);
 
3124
    }
 
3125
 
 
3126
    if (height != NULL)
 
3127
        *height = XmTextF_font_descent(tf) + XmTextF_font_ascent(tf) +
 
3128
            2 * (XmTextF_margin_height(tf) + tf->primitive.shadow_thickness +
 
3129
                 tf->primitive.highlight_thickness);
 
3130
}
 
3131
 
 
3132
 
 
3133
/*
 
3134
 * df_TryResize - Attempts to resize the width of the text field widget.
 
3135
 * If the attempt fails or is ineffective, return GeometryNo.
 
3136
 */
 
3137
static XtGeometryResult 
 
3138
#ifdef _NO_PROTO
 
3139
df_TryResize( tf, width, height )
 
3140
        XmDataFieldWidget tf ;
 
3141
        Dimension width ;
 
3142
        Dimension height ;
 
3143
#else
 
3144
df_TryResize(
 
3145
        XmDataFieldWidget tf,
 
3146
#if NeedWidePrototypes
 
3147
        int width,
 
3148
        int height )
 
3149
#else
 
3150
        Dimension width,
 
3151
        Dimension height )
 
3152
#endif /* NeedWidePrototypes */
 
3153
#endif /* _NO_PROTO */
 
3154
{
 
3155
    Dimension reswidth, resheight;
 
3156
    Dimension origwidth = tf->core.width;
 
3157
    XtGeometryResult result;
 
3158
 
 
3159
    result = XtMakeResizeRequest((Widget)tf, width, height,
 
3160
                                 &reswidth, &resheight);
 
3161
 
 
3162
    if (result == XtGeometryAlmost) {
 
3163
        result = XtMakeResizeRequest((Widget)tf, reswidth, resheight,
 
3164
                                     &reswidth, &resheight);
 
3165
 
 
3166
        if (reswidth == origwidth)
 
3167
           result = XtGeometryNo;
 
3168
        return result;
 
3169
    }
 
3170
 
 
3171
   /*
 
3172
    * Caution: Some geometry managers return XtGeometryYes
 
3173
    *           and don't change the widget's size.
 
3174
    */
 
3175
    if (tf->core.width != width && tf->core.height != height)
 
3176
        result = XtGeometryNo;
 
3177
 
 
3178
    return result;
 
3179
}
 
3180
 
 
3181
 
 
3182
/*
 
3183
 * Function df_AdjustText
 
3184
 *
 
3185
 * df_AdjustText ensures that the character at the given position is entirely
 
3186
 * visible in the Text Field widget.  If the character is not already entirely
 
3187
 * visible, df_AdjustText changes the Widget's h_offsetring appropriately.  If
 
3188
 * the text must be redrawn, df_AdjustText calls df_RedisplayText.
 
3189
 *
 
3190
 */
 
3191
static Boolean 
 
3192
#ifdef _NO_PROTO
 
3193
df_AdjustText( tf, position, flag )
 
3194
        XmDataFieldWidget tf ;
 
3195
        XmTextPosition position ;
 
3196
        Boolean flag ;
 
3197
#else
 
3198
df_AdjustText(
 
3199
        XmDataFieldWidget tf,
 
3200
        XmTextPosition position,
 
3201
#if NeedWidePrototypes
 
3202
        int flag )
 
3203
#else
 
3204
        Boolean flag )
 
3205
#endif /* NeedWidePrototypes */
 
3206
#endif /* _NO_PROTO */
 
3207
{
 
3208
  int left_edge = 0;
 
3209
  int diff;
 
3210
  Dimension margin_width = XmTextF_margin_width(tf) +
 
3211
                              tf->primitive.shadow_thickness +
 
3212
                              tf->primitive.highlight_thickness;
 
3213
  Dimension thickness    = 2 * (tf->primitive.shadow_thickness +
 
3214
                              tf->primitive.highlight_thickness);
 
3215
  Dimension temp;
 
3216
  
 
3217
  if (XmDataField_alignment(tf) == XmALIGNMENT_END)
 
3218
  {
 
3219
    if (XmTextF_max_char_size(tf) != 1)
 
3220
    {
 
3221
      left_edge = tf->core.width - margin_width + XmTextF_h_offset(tf) -
 
3222
                  df_FindPixelLength(tf, (char *)(XmTextF_wc_value(tf) + position),
 
3223
                                  XmTextF_string_length(tf) - (int) position);
 
3224
    } 
 
3225
    else
 
3226
    {
 
3227
      left_edge = tf->core.width - margin_width + XmTextF_h_offset(tf) -
 
3228
                  df_FindPixelLength(tf, XmTextF_value(tf) + position,
 
3229
                                  XmTextF_string_length(tf) - (int) position);
 
3230
    }
 
3231
  }
 
3232
  else
 
3233
  {
 
3234
    if (XmTextF_max_char_size(tf) != 1)
 
3235
    {
 
3236
      left_edge = df_FindPixelLength(tf, (char *) XmTextF_wc_value(tf),
 
3237
                                  (int)position) + (int) XmTextF_h_offset(tf);
 
3238
    } 
 
3239
    else
 
3240
    {
 
3241
      left_edge = df_FindPixelLength(tf, XmTextF_value(tf), (int)position) +
 
3242
                                  (int) XmTextF_h_offset(tf);
 
3243
    }
 
3244
  }
 
3245
 
 
3246
 /*
 
3247
  * Make sure the cached GC has the clipping rectangle
 
3248
  * set to the current widget.
 
3249
  */
 
3250
  if (!XmTextF_has_rect(tf)) _XmDataFieldSetClipRect(tf);
 
3251
 
 
3252
  if ((diff = left_edge - margin_width) < 0) {
 
3253
    /* We need to scroll the string to the right. */
 
3254
     if (!XtIsRealized((Widget)tf)) {
 
3255
       XmTextF_h_offset(tf) -= diff;
 
3256
       return True;
 
3257
     }
 
3258
     _XmDataFieldDrawInsertionPoint(tf, False);
 
3259
     XmTextF_h_offset(tf) -= diff;
 
3260
     df_XmSetInvGC(tf, XmTextF_gc(tf));
 
3261
     df_XmSetFullGC(tf, XmTextF_gc(tf));
 
3262
     if (tf->core.height <= thickness)
 
3263
       temp = 0;
 
3264
     else
 
3265
       temp = tf->core.height - thickness;
 
3266
     XFillRectangle(XtDisplay(tf), XtWindow(tf), XmTextF_gc(tf),
 
3267
                    tf->primitive.shadow_thickness +
 
3268
                    tf->primitive.highlight_thickness,
 
3269
                    tf->primitive.shadow_thickness +
 
3270
                    tf->primitive.highlight_thickness,
 
3271
                    XmTextF_margin_width(tf),
 
3272
                    temp);
 
3273
     df_XmSetMarginGC(tf, XmTextF_gc(tf));
 
3274
     df_RedisplayText(tf, 0, XmTextF_string_length(tf)); 
 
3275
     _XmDataFieldDrawInsertionPoint(tf, True);
 
3276
     return True;
 
3277
   } else if ((diff = ( left_edge -
 
3278
                       (int)(tf->core.width - margin_width))) > 0) {
 
3279
           /* We need to scroll the string to the left. */
 
3280
            if (!XtIsRealized((Widget)tf)) {
 
3281
              XmTextF_h_offset(tf) -= diff;
 
3282
              return True;
 
3283
            }
 
3284
            _XmDataFieldDrawInsertionPoint(tf, False);
 
3285
            XmTextF_h_offset(tf) -= diff;
 
3286
            df_XmSetInvGC(tf, XmTextF_gc(tf));
 
3287
            df_XmSetFullGC(tf, XmTextF_gc(tf));
 
3288
            if (tf->core.width <= thickness)
 
3289
              temp = 0;
 
3290
            else
 
3291
              temp = tf->core.width - thickness;
 
3292
            XFillRectangle(XtDisplay(tf), XtWindow(tf), XmTextF_gc(tf),
 
3293
                           tf->core.width - margin_width,
 
3294
                           tf->primitive.shadow_thickness +
 
3295
                           tf->primitive.highlight_thickness,
 
3296
                           XmTextF_margin_width(tf),
 
3297
                           temp);
 
3298
             df_XmSetMarginGC(tf, XmTextF_gc(tf));
 
3299
             df_RedisplayText(tf, 0, XmTextF_string_length(tf)); 
 
3300
             _XmDataFieldDrawInsertionPoint(tf, True);
 
3301
             return True;
 
3302
  }
 
3303
 
 
3304
  if (flag) df_RedisplayText(tf, position, XmTextF_string_length(tf)); 
 
3305
 
 
3306
  return False;
 
3307
}
 
3308
 
 
3309
/*
 
3310
 * df_AdjustSize
 
3311
 *
 
3312
 * Adjust size will resize the text to ensure that all the text is visible.
 
3313
 * It will also adjust text that is shrunk.  Shrinkage is limited to the
 
3314
 * size determined by the XmNcolumns resource.
 
3315
 */
 
3316
static void 
 
3317
#ifdef _NO_PROTO
 
3318
df_AdjustSize( tf )
 
3319
        XmDataFieldWidget tf ;
 
3320
#else
 
3321
df_AdjustSize(
 
3322
        XmDataFieldWidget tf )
 
3323
#endif /* _NO_PROTO */
 
3324
{
 
3325
  XtGeometryResult result = XtGeometryYes;
 
3326
  int left_edge = 0;
 
3327
  int diff;
 
3328
  Boolean redisplay = False;
 
3329
  Dimension margin_width = XmTextF_margin_width(tf) +
 
3330
                              tf->primitive.shadow_thickness +
 
3331
                              tf->primitive.highlight_thickness;
 
3332
 
 
3333
  if (XmTextF_max_char_size(tf) != 1) {
 
3334
      left_edge = df_FindPixelLength(tf, (char *) XmTextF_wc_value(tf), 
 
3335
                                  XmTextF_string_length(tf)) + margin_width;
 
3336
  } else {
 
3337
      left_edge = df_FindPixelLength(tf, XmTextF_value(tf), 
 
3338
                                  XmTextF_string_length(tf)) + margin_width;
 
3339
  }
 
3340
 
 
3341
  if ((diff = (left_edge - (tf->core.width - (margin_width)))) > 0) {
 
3342
     if (XmTextF_in_setvalues(tf)) {
 
3343
        tf->core.width += diff;
 
3344
        if (XmDataField_alignment(tf) == XmALIGNMENT_END)
 
3345
            XmTextF_new_h_offset(tf) = diff;
 
3346
        else
 
3347
            XmTextF_new_h_offset(tf) = margin_width - diff;
 
3348
        return;
 
3349
     }
 
3350
    /* Attempt to resize.  If it doesn't succeed, do scrolling.  */
 
3351
     result = df_TryResize(tf, tf->core.width + diff, tf->core.height);
 
3352
     if (result == XtGeometryYes)
 
3353
     {
 
3354
        XtWidgetProc resize;
 
3355
           
 
3356
        _XmProcessLock(); 
 
3357
        resize = tf->core.widget_class->core_class.resize;
 
3358
        _XmProcessUnlock();
 
3359
 
 
3360
        (*resize)((Widget)tf);
 
3361
        return;
 
3362
     } else
 
3363
         /* We need to scroll the string to the left. */
 
3364
         if (XmDataField_alignment(tf) == XmALIGNMENT_END)
 
3365
             XmTextF_h_offset(tf) = diff;            
 
3366
         else
 
3367
             XmTextF_h_offset(tf) = margin_width - diff;
 
3368
  } else {
 
3369
     Dimension width;
 
3370
 
 
3371
    /* If the new size is smaller than core size, we need
 
3372
     * to shrink.  Note: new size will never be less than the
 
3373
     * width determined by the columns resource.
 
3374
     */
 
3375
     df_ComputeSize(tf, &width, NULL);
 
3376
     if (width < tf->core.width) {
 
3377
        if (XmTextF_in_setvalues(tf)) {
 
3378
           tf->core.width = width;
 
3379
           return;
 
3380
        }
 
3381
        result = df_TryResize(tf, width, tf->core.height);
 
3382
        if (result == XtGeometryYes)
 
3383
        {
 
3384
           XtWidgetProc resize;
 
3385
           
 
3386
           _XmProcessLock(); 
 
3387
           resize = tf->core.widget_class->core_class.resize;
 
3388
           _XmProcessUnlock();
 
3389
 
 
3390
           (*resize)((Widget)tf);
 
3391
           return;
 
3392
        }
 
3393
     }
 
3394
  }
 
3395
 
 
3396
  redisplay = df_AdjustText(tf, XmTextF_cursor_position(tf), False);
 
3397
 
 
3398
  if (!redisplay)
 
3399
     df_RedisplayText(tf, 0, XmTextF_string_length(tf));
 
3400
}
 
3401
 
 
3402
/* If MB_CUR_MAX == 1, insert is a char* pointer; else, it is a wchar_t *
 
3403
 * pointer and must be appropriately cast.  In all cases, insert_length
 
3404
 * is the number of characters, not the number of bytes pointed to by
 
3405
 * insert
 
3406
 */
 
3407
static Boolean 
 
3408
#ifdef _NO_PROTO
 
3409
df_ModifyVerify( tf, event, replace_prev, replace_next,
 
3410
              insert, insert_length, newInsert, free_insert )
 
3411
        XmDataFieldWidget tf ;
 
3412
        XEvent *event ;
 
3413
        XmTextPosition *replace_prev ;
 
3414
        XmTextPosition *replace_next ;
 
3415
        char **insert ;
 
3416
        int *insert_length ;
 
3417
        XmTextPosition *newInsert ;
 
3418
        int *free_insert ;
 
3419
#else
 
3420
df_ModifyVerify(
 
3421
        XmDataFieldWidget tf,
 
3422
        XEvent *event,
 
3423
        XmTextPosition *replace_prev,
 
3424
        XmTextPosition *replace_next,
 
3425
        char **insert,
 
3426
        int *insert_length,
 
3427
        XmTextPosition *newInsert,
 
3428
        int *free_insert )
 
3429
#endif /* _NO_PROTO */
 
3430
{
 
3431
     XmTextVerifyCallbackStruct vcb;
 
3432
     XmTextVerifyCallbackStructWcs wcs_vcb;
 
3433
     XmTextBlockRec newblock;
 
3434
     XmTextBlockRecWcs wcs_newblock;
 
3435
     Boolean do_free = False;
 
3436
     Boolean wcs_do_free = False;
 
3437
     int count;
 
3438
     wchar_t *wptr;
 
3439
     
 
3440
     *newInsert = XmTextF_cursor_position(tf);
 
3441
     *free_insert = (int)False;
 
3442
 
 
3443
    /* if there are no callbacks, don't waste any time... just return  True */
 
3444
     if (!XmTextF_modify_verify_callback(tf) && !XmTextF_wcs_modify_verify_callback(tf))
 
3445
        return(True);
 
3446
 
 
3447
     newblock.format = XmFMT_8_BIT;
 
3448
     newblock.length = *insert_length * XmTextF_max_char_size(tf);
 
3449
 
 
3450
     if (*insert_length) {
 
3451
         if (XmTextF_modify_verify_callback(tf)){
 
3452
            newblock.ptr = (char *) XtMalloc((unsigned) newblock.length + 
 
3453
                                             XmTextF_max_char_size(tf));
 
3454
            if (XmTextF_max_char_size(tf) == 1) {
 
3455
              (void)memcpy((void*)newblock.ptr, (void*)*insert,
 
3456
                           newblock.length);
 
3457
              newblock.ptr[newblock.length]='\0';
 
3458
            } else {
 
3459
               count = (int) wcstombs(newblock.ptr, (wchar_t*)*insert,
 
3460
                                                newblock.length);
 
3461
               if (count < 0) { /* bad wchar; don't pass anything */
 
3462
                  newblock.ptr[0] = '\0';
 
3463
                  newblock.length = 0;
 
3464
               } else if (count == newblock.length) {
 
3465
                  newblock.ptr[newblock.length] = '\0';
 
3466
               } else {
 
3467
                  newblock.ptr[count] = '\0';
 
3468
                  newblock.length = count;
 
3469
               }
 
3470
            }
 
3471
            do_free = True;
 
3472
         } else 
 
3473
            newblock.ptr = NULL;
 
3474
     } else 
 
3475
        newblock.ptr = NULL;
 
3476
        
 
3477
    /* Fill in the appropriate structs */
 
3478
     vcb.reason = XmCR_MODIFYING_TEXT_VALUE;
 
3479
     vcb.event = (XEvent *) event;
 
3480
     vcb.doit = True;
 
3481
     vcb.currInsert = XmTextF_cursor_position(tf);
 
3482
     vcb.newInsert = XmTextF_cursor_position(tf);
 
3483
     vcb.text = &newblock;
 
3484
     vcb.startPos = *replace_prev;
 
3485
     vcb.endPos = *replace_next;
 
3486
 
 
3487
     /* Call the modify verify callbacks. */
 
3488
     if (XmTextF_modify_verify_callback(tf))
 
3489
        XtCallCallbackList((Widget) tf, XmTextF_modify_verify_callback(tf),
 
3490
                           (XtPointer) &vcb);
 
3491
 
 
3492
     if (XmTextF_wcs_modify_verify_callback(tf) && vcb.doit){
 
3493
        if (do_free){ /* there is a char* modify verify callback; the data we
 
3494
                       * want is in vcb struct */
 
3495
           wcs_newblock.wcsptr = (wchar_t *) XtMalloc((unsigned) 
 
3496
                                      (vcb.text->length + 1) * sizeof(wchar_t));
 
3497
           wcs_newblock.length = mbstowcs(wcs_newblock.wcsptr, vcb.text->ptr,
 
3498
                                          vcb.text->length);
 
3499
           if (wcs_newblock.length < 0) { /* bad value; don't pass anything */
 
3500
              wcs_newblock.wcsptr[0] = 0L;
 
3501
              wcs_newblock.length = 0;
 
3502
           } else 
 
3503
              wcs_newblock.wcsptr[wcs_newblock.length] = 0L;
 
3504
        } else { /* there was no char* modify verify callback; use data
 
3505
                  * passed in from caller instead of that in vcb struct. */
 
3506
          wcs_newblock.wcsptr = (wchar_t *) XtMalloc((unsigned) 
 
3507
                                       (*insert_length + 1) * sizeof(wchar_t));
 
3508
          if (XmTextF_max_char_size(tf) == 1) 
 
3509
            wcs_newblock.length = mbstowcs(wcs_newblock.wcsptr, *insert,
 
3510
                                          *insert_length);
 
3511
          else {
 
3512
            wcs_newblock.length = *insert_length;
 
3513
            (void)memcpy((void*)wcs_newblock.wcsptr, (void*)*insert,
 
3514
                         *insert_length * sizeof(wchar_t));
 
3515
          }         
 
3516
          if (wcs_newblock.length < 0) { /* bad value; don't pass anything */
 
3517
            wcs_newblock.wcsptr[0] = 0L;
 
3518
            wcs_newblock.length = 0;
 
3519
          } else 
 
3520
            wcs_newblock.wcsptr[wcs_newblock.length] = 0L;
 
3521
 
 
3522
        }
 
3523
        wcs_do_free = True;
 
3524
        wcs_vcb.reason = XmCR_MODIFYING_TEXT_VALUE;
 
3525
        wcs_vcb.event = (XEvent *) event;
 
3526
        wcs_vcb.doit = True;
 
3527
        wcs_vcb.currInsert = vcb.currInsert;
 
3528
        wcs_vcb.newInsert = vcb.newInsert;
 
3529
        wcs_vcb.text = &wcs_newblock;
 
3530
        wcs_vcb.startPos = vcb.startPos;
 
3531
        wcs_vcb.endPos = vcb.endPos;
 
3532
 
 
3533
        XtCallCallbackList((Widget) tf, XmTextF_wcs_modify_verify_callback(tf),
 
3534
                           (XtPointer) &wcs_vcb);
 
3535
 
 
3536
     }
 
3537
     
 
3538
     /* 
 
3539
      * copy the newblock.ptr, length, start, and 
 
3540
      * end to the pointers passed
 
3541
      */
 
3542
 
 
3543
     if (XmTextF_wcs_modify_verify_callback(tf)) 
 
3544
     { /* use wcs_vcb data */
 
3545
         *insert_length = wcs_vcb.text->length; /* length is char count*/
 
3546
         if (wcs_vcb.doit) 
 
3547
         {
 
3548
             if (XmTextF_max_char_size(tf) == 1)
 
3549
             { /* caller expects char */
 
3550
                 wcs_vcb.text->wcsptr[wcs_vcb.text->length] = 0L;
 
3551
                 if (*insert_length > 0) 
 
3552
                 {
 
3553
                     *insert = XtMalloc((unsigned) (*insert_length + 1) \
 
3554
                                        * sizeof(wchar_t));
 
3555
                     *free_insert = (int)True;
 
3556
                     count = wcstombs(*insert, wcs_vcb.text->wcsptr,
 
3557
                                      *insert_length + 1);
 
3558
                     if (count < 0) 
 
3559
                     {
 
3560
                         (*insert)[0] = 0;
 
3561
                         *insert_length = 0;
 
3562
                     }
 
3563
                 }        
 
3564
             } 
 
3565
             else 
 
3566
             {  /* callback struct has wchar*; caller expects wchar* */
 
3567
                 if (*insert_length > 0) 
 
3568
                 {
 
3569
                     *insert = XtMalloc((unsigned)(*insert_length + 1) \
 
3570
                                        * sizeof(wchar_t));
 
3571
                     *free_insert = (int)True;
 
3572
                     (void)memcpy((void*)*insert, (void*)wcs_vcb.text->wcsptr,
 
3573
                                  *insert_length * sizeof(wchar_t));
 
3574
                     wptr = (wchar_t*) *insert;
 
3575
                     wptr[*insert_length] = 0L;
 
3576
                 }      
 
3577
             }  
 
3578
 
 
3579
             *replace_prev = wcs_vcb.startPos;
 
3580
             *replace_next = wcs_vcb.endPos;
 
3581
             *newInsert = wcs_vcb.newInsert;
 
3582
         }
 
3583
     } 
 
3584
     else 
 
3585
     { /* use vcb data */
 
3586
         if (vcb.doit) 
 
3587
         {
 
3588
             if (XmTextF_max_char_size(tf) == 1)
 
3589
             {  /* caller expects char* */
 
3590
                 *insert_length =  vcb.text->length;
 
3591
                 if (*insert_length > 0) 
 
3592
                 {
 
3593
                     *insert = XtMalloc((unsigned) *insert_length + 1);
 
3594
                     *free_insert = (int)True;
 
3595
                     (void)memcpy((void*)*insert, (void*)vcb.text->ptr,
 
3596
                                  *insert_length);
 
3597
                     (*insert)[*insert_length] = 0;
 
3598
                 }
 
3599
             } 
 
3600
             else 
 
3601
             {  /* caller expects wchar_t* back */
 
3602
                 *insert_length =  
 
3603
                     _XmDataFieldCountCharacters(tf, vcb.text->ptr,
 
3604
                                                 vcb.text->length);
 
3605
                 if (*insert_length > 0) 
 
3606
                 {
 
3607
                     *insert = 
 
3608
                         XtMalloc((unsigned)(*insert_length + 1) * 
 
3609
                                  sizeof(wchar_t));
 
3610
                     *free_insert = (int)True;
 
3611
                     count = mbstowcs((wchar_t*)*insert, vcb.text->ptr,
 
3612
                                      *insert_length);
 
3613
                     wptr = (wchar_t*) *insert;
 
3614
                     if (count < 0) {
 
3615
                         wptr[0] = 0L;
 
3616
                         *insert_length = 0;
 
3617
                     } 
 
3618
                     else
 
3619
                     {
 
3620
                         wptr[count] = 0L;
 
3621
                     }
 
3622
                 }      
 
3623
             }
 
3624
             *replace_prev = vcb.startPos;
 
3625
             *replace_next = vcb.endPos;
 
3626
             *newInsert = vcb.newInsert;
 
3627
         }
 
3628
     }
 
3629
 
 
3630
     if (do_free) {
 
3631
         XtFree(newblock.ptr);
 
3632
     }
 
3633
     if (wcs_do_free) {
 
3634
         XtFree((char*)wcs_newblock.wcsptr);
 
3635
     }
 
3636
        
 
3637
     /* If doit becomes False, then don't allow the change. */
 
3638
     if (XmTextF_wcs_modify_verify_callback(tf))
 
3639
        return wcs_vcb.doit;
 
3640
     else
 
3641
        return vcb.doit;
 
3642
}
 
3643
 
 
3644
static void 
 
3645
#ifdef _NO_PROTO
 
3646
df_ResetClipOrigin(tf, clip_mask_reset)
 
3647
        XmDataFieldWidget tf;
 
3648
        Boolean clip_mask_reset;
 
3649
#else /* _NO_PROTO */
 
3650
df_ResetClipOrigin(
 
3651
        XmDataFieldWidget tf, 
 
3652
#if NeedWidePrototypes
 
3653
        int clip_mask_reset)
 
3654
#else
 
3655
        Boolean clip_mask_reset)
 
3656
#endif /* NeedWidePrototypes */
 
3657
#endif /* _NO_PROTO */
 
3658
{
 
3659
   unsigned long valuemask = (GCTileStipXOrigin | GCTileStipYOrigin |
 
3660
                             GCClipXOrigin | GCClipYOrigin);
 
3661
   XGCValues values;
 
3662
   int x, y, clip_mask_x, clip_mask_y;
 
3663
   Position x_pos, y_pos;
 
3664
   (void) df_GetXYFromPos(tf, XmTextF_cursor_position(tf), &x_pos, &y_pos);
 
3665
 
 
3666
   if (!XtIsRealized((Widget)tf)) return;
 
3667
 
 
3668
   if (!XmTextF_has_rect(tf)) _XmDataFieldSetClipRect(tf);
 
3669
   x = (int) x_pos; y = (int) y_pos;
 
3670
 
 
3671
   x -=(XmTextF_cursor_width(tf) >> 1) + 1;
 
3672
 
 
3673
   clip_mask_y = y = (y + XmTextF_font_descent(tf)) - XmTextF_cursor_height(tf);
 
3674
 
 
3675
   if (x < (int)(tf->primitive.highlight_thickness + 
 
3676
       tf->primitive.shadow_thickness + XmTextF_margin_width(tf))){
 
3677
          clip_mask_x = tf->primitive.highlight_thickness +
 
3678
          tf->primitive.shadow_thickness + (int)(XmTextF_margin_width(tf));
 
3679
   } else
 
3680
     clip_mask_x = x; 
 
3681
 
 
3682
   if (clip_mask_reset) {
 
3683
      values.ts_x_origin = x;
 
3684
      values.ts_y_origin = y;
 
3685
      values.clip_x_origin = clip_mask_x;
 
3686
      values.clip_y_origin = clip_mask_y;
 
3687
      XChangeGC(XtDisplay(tf), XmTextF_image_gc(tf), valuemask, &values);
 
3688
   }
 
3689
   else 
 
3690
      XSetTSOrigin(XtDisplay(tf), XmTextF_image_gc(tf), x, y);
 
3691
}
 
3692
 
 
3693
static void
 
3694
#ifdef _NO_PROTO
 
3695
df_InvertImageGC (tf)
 
3696
        XmDataFieldWidget tf ;
 
3697
#else
 
3698
df_InvertImageGC (
 
3699
        XmDataFieldWidget tf )
 
3700
#endif /* _NO_PROTO */
 
3701
{
 
3702
   unsigned long valuemask = (GCForeground | GCBackground);
 
3703
   XGCValues values;
 
3704
   Display *dpy = XtDisplay(tf);
 
3705
 
 
3706
   if (XmTextF_have_inverted_image_gc(tf)) return;
 
3707
 
 
3708
   if (!XmTextF_has_rect(tf)) _XmDataFieldSetClipRect(tf);
 
3709
 
 
3710
   if (!XmTextF_overstrike(tf)) {
 
3711
     values.background = tf->primitive.foreground;
 
3712
     values.foreground = tf->core.background_pixel;
 
3713
     
 
3714
     XChangeGC(dpy, XmTextF_image_gc(tf), valuemask, &values);
 
3715
   }
 
3716
 
 
3717
   XmTextF_have_inverted_image_gc(tf) = True;
 
3718
}
 
3719
 
 
3720
static void
 
3721
#ifdef _NO_PROTO
 
3722
df_ResetImageGC (tf)
 
3723
        XmDataFieldWidget tf ;
 
3724
#else
 
3725
df_ResetImageGC (
 
3726
        XmDataFieldWidget tf )
 
3727
#endif /* _NO_PROTO */
 
3728
{
 
3729
   unsigned long valuemask = (GCForeground | GCBackground);
 
3730
   XGCValues values;
 
3731
   Display *dpy = XtDisplay(tf);
 
3732
 
 
3733
   if (!XmTextF_have_inverted_image_gc(tf)) return;
 
3734
 
 
3735
   if (!XmTextF_has_rect(tf)) 
 
3736
   {
 
3737
       _XmDataFieldSetClipRect(tf);
 
3738
   }
 
3739
 
 
3740
   if (!XmTextF_overstrike(tf)) 
 
3741
   {
 
3742
       values.foreground = tf->primitive.foreground;
 
3743
       values.background = tf->core.background_pixel;
 
3744
     
 
3745
       XChangeGC(dpy, XmTextF_image_gc(tf), valuemask, &values);
 
3746
   }
 
3747
 
 
3748
   XmTextF_have_inverted_image_gc(tf) = False;
 
3749
}
 
3750
 
 
3751
/*
 
3752
 * Calls the motion verify callback.  If the doit flag is true,
 
3753
 * then reset the cursor_position and call df_AdjustText() to
 
3754
 * move the text if need be.
 
3755
 */
 
3756
 
 
3757
void 
 
3758
#ifdef _NO_PROTO
 
3759
_XmDataFielddf_SetCursorPosition( tf, event, position,
 
3760
                              adjust_flag, call_cb)
 
3761
        XmDataFieldWidget tf ;
 
3762
        XEvent *event ;
 
3763
        XmTextPosition position ;
 
3764
        Boolean adjust_flag ;
 
3765
        Boolean call_cb ;
 
3766
#else
 
3767
_XmDataFielddf_SetCursorPosition(
 
3768
        XmDataFieldWidget tf,
 
3769
        XEvent *event,
 
3770
        XmTextPosition position,
 
3771
#if NeedWidePrototypes
 
3772
        int adjust_flag,
 
3773
        int call_cb)
 
3774
#else
 
3775
        Boolean adjust_flag,
 
3776
        Boolean call_cb)
 
3777
#endif /* NeedWidePrototypes */
 
3778
#endif /* _NO_PROTO */
 
3779
{
 
3780
  df_SetCursorPosition(tf, event, position, adjust_flag, call_cb, True);
 
3781
}
 
3782
 
 
3783
static void 
 
3784
#ifdef _NO_PROTO
 
3785
df_SetCursorPosition( tf, event, position,
 
3786
                  adjust_flag, call_cb, set_dest)
 
3787
        XmDataFieldWidget tf ;
 
3788
        XEvent *event ;
 
3789
        XmTextPosition position ;
 
3790
        Boolean adjust_flag ;
 
3791
        Boolean call_cb ;
 
3792
        Boolean set_dest;
 
3793
#else
 
3794
df_SetCursorPosition(
 
3795
        XmDataFieldWidget tf,
 
3796
        XEvent *event,
 
3797
        XmTextPosition position,
 
3798
#if NeedWidePrototypes
 
3799
        int adjust_flag,
 
3800
        int call_cb, 
 
3801
        int set_dest)
 
3802
#else
 
3803
        Boolean adjust_flag,
 
3804
        Boolean call_cb,
 
3805
        Boolean set_dest)
 
3806
#endif /* NeedWidePrototypes */
 
3807
#endif /* _NO_PROTO */
 
3808
{
 
3809
    XmTextVerifyCallbackStruct cb;
 
3810
    Boolean flag = False;
 
3811
    XPoint xmim_point;
 
3812
    _XmHighlightRec *hl_list = XmTextF_highlight(tf).list;
 
3813
    int i;
 
3814
 
 
3815
    if (position < 0) position = 0;
 
3816
 
 
3817
    if (position > XmTextF_string_length(tf))
 
3818
       position = XmTextF_string_length(tf);
 
3819
 
 
3820
    if (XmTextF_cursor_position(tf) != position && call_cb) {
 
3821
      /* Call Motion Verify Callback before Cursor Changes Positon */
 
3822
       cb.reason = XmCR_MOVING_INSERT_CURSOR;
 
3823
       cb.event  = event;
 
3824
       cb.currInsert = XmTextF_cursor_position(tf);
 
3825
       cb.newInsert = position;
 
3826
       cb.doit = True;
 
3827
       XtCallCallbackList((Widget) tf, XmTextF_motion_verify_callback(tf),
 
3828
                          (XtPointer) &cb);
 
3829
 
 
3830
       if (!cb.doit) {
 
3831
          if (XmTextF_verify_bell(tf)) XBell(XtDisplay((Widget)tf), 0);
 
3832
          return;
 
3833
       }
 
3834
    }
 
3835
    _XmDataFieldDrawInsertionPoint(tf, False);
 
3836
 
 
3837
    XmTextF_cursor_position(tf) = position;
 
3838
 
 
3839
    if (!XmTextF_add_mode(tf) && XmTextF_pending_off(tf) && XmTextF_has_primary(tf)) {
 
3840
       df_SetSelection(tf, position, position, True);
 
3841
       flag = True;
 
3842
    }
 
3843
 
 
3844
   /* Deterimine if we need an inverted image GC or not.  Get the highlight
 
3845
    * record for the cursor position.  If position is on a boundary of
 
3846
    * a highlight, then we always display cursor in normal mode (i.e. set
 
3847
    * normal image GC).  If position is within a selected highlight rec,
 
3848
    * then make sure the image GC is inverted.  If we've moved out of a
 
3849
    * selected highlight region, restore the normal image GC. */
 
3850
 
 
3851
    for (i = XmTextF_highlight(tf).number - 1; i >= 0; i--){
 
3852
       if (position >= hl_list[i].position || i == 0)
 
3853
          break;
 
3854
    }
 
3855
 
 
3856
    if (position == hl_list[i].position)
 
3857
       df_ResetImageGC(tf);
 
3858
    else if (hl_list[i].mode != XmHIGHLIGHT_SELECTED)
 
3859
       df_ResetImageGC(tf);
 
3860
    else 
 
3861
       df_InvertImageGC(tf);
 
3862
 
 
3863
    if (adjust_flag) (void) df_AdjustText(tf, position, flag);
 
3864
 
 
3865
    df_ResetClipOrigin(tf, False);
 
3866
 
 
3867
    XmTextF_refresh_ibeam_off(tf) = True;
 
3868
    _XmDataFieldDrawInsertionPoint(tf, True);
 
3869
 
 
3870
    (void) df_GetXYFromPos(tf, XmTextF_cursor_position(tf),
 
3871
                        &xmim_point.x, &xmim_point.y);
 
3872
    XmImVaSetValues((Widget)tf, XmNspotLocation, &xmim_point, NULL);
 
3873
 
 
3874
    if (set_dest)
 
3875
      (void) df_SetDestination((Widget) tf, XmTextF_cursor_position(tf), False, 
 
3876
                            XtLastTimestampProcessed(XtDisplay((Widget)tf)));
 
3877
}
 
3878
 
 
3879
 
 
3880
/*
 
3881
 * This routine is used to verify that the positions are within the bounds
 
3882
 * of the current DataField widgets value.  Also, it ensures that left is
 
3883
 * less than right.
 
3884
 */
 
3885
static void 
 
3886
#ifdef _NO_PROTO
 
3887
df_VerifyBounds( tf, from, to )
 
3888
        XmDataFieldWidget tf ;
 
3889
        XmTextPosition *from ;
 
3890
        XmTextPosition *to ;
 
3891
#else
 
3892
df_VerifyBounds(
 
3893
        XmDataFieldWidget tf,
 
3894
        XmTextPosition *from,
 
3895
        XmTextPosition *to )
 
3896
#endif /* _NO_PROTO */
 
3897
{
 
3898
  XmTextPosition tmp;
 
3899
 
 
3900
    if (*from < 0) 
 
3901
       *from = 0;
 
3902
    else if (*from > XmTextF_string_length(tf)) {
 
3903
       *from = XmTextF_string_length(tf);
 
3904
    }
 
3905
    if (*to < 0 ) 
 
3906
       *to = 0;
 
3907
    else if (*to > XmTextF_string_length(tf)) {
 
3908
       *to = XmTextF_string_length(tf);
 
3909
    }
 
3910
    if (*from > *to) {
 
3911
       tmp = *to;
 
3912
       *to = *from;
 
3913
       *from = tmp;
 
3914
    }
 
3915
}
 
3916
 
 
3917
/*
 
3918
 * Function _XmDataFieldReplaceText
 
3919
 *
 
3920
 * _XmDataFieldReplaceText is a utility function for the text-modifying
 
3921
 * action procedures below (df_InsertChar, df_DeletePrevChar, and so on). 
 
3922
 * _XmDataFieldReplaceText does the real work of editing the string,
 
3923
 * including:
 
3924
 *
 
3925
 *   (1) invoking the modify verify callbacks,
 
3926
 *   (2) allocating more memory for the string if necessary,
 
3927
 *   (3) doing the string manipulation,
 
3928
 *   (4) moving the selection (the insertion point), and
 
3929
 *   (5) redrawing the text.
 
3930
 *
 
3931
 * Though the procedure claims to take a char* argument, MB_CUR_MAX determines
 
3932
 * what the different routines will actually pass to it.  If MB_CUR_MAX is
 
3933
 * greater than 1, then "insert" points to wchar_t data and we must set up
 
3934
 * the appropriate cast.  In all cases, insert_length is the number of
 
3935
 * characters (not bytes) to be inserted.
 
3936
 */
 
3937
Boolean 
 
3938
#ifdef _NO_PROTO
 
3939
_XmDataFieldReplaceText( tf, event, replace_prev, replace_next,
 
3940
                         insert, insert_length, move_cursor )
 
3941
        XmDataFieldWidget tf ;
 
3942
        XEvent *event ;
 
3943
        XmTextPosition replace_prev ;
 
3944
        XmTextPosition replace_next ;
 
3945
        char *insert ;
 
3946
        int insert_length ;
 
3947
        Boolean move_cursor ;
 
3948
#else
 
3949
_XmDataFieldReplaceText(
 
3950
        XmDataFieldWidget tf,
 
3951
        XEvent *event,
 
3952
        XmTextPosition replace_prev,
 
3953
        XmTextPosition replace_next,
 
3954
        char *insert,
 
3955
        int insert_length,
 
3956
        Boolean move_cursor )
 
3957
#endif /* _NO_PROTO */
 
3958
{
 
3959
  int replace_length, i;
 
3960
  char *src, *dst;
 
3961
  wchar_t *wc_src, *wc_dst;
 
3962
  int delta = 0;
 
3963
  XmTextPosition cursorPos, newInsert;
 
3964
  XmTextPosition old_pos = replace_prev;
 
3965
  int free_insert = (int)False;
 
3966
  Position      x1, y1, x2, y2;
 
3967
 
 
3968
  df_VerifyBounds(tf, &replace_prev, &replace_next);
 
3969
 
 
3970
  if (!XmTextF_editable(tf)) {
 
3971
     if (XmTextF_verify_bell(tf)) XBell(XtDisplay((Widget)tf), 0);
 
3972
     return False;
 
3973
  }
 
3974
 
 
3975
  replace_length = (int) (replace_next - replace_prev);
 
3976
  delta = insert_length - replace_length;
 
3977
 
 
3978
 /* Disallow insertions that go beyond max length boundries.
 
3979
  */
 
3980
  if ((delta >= 0) && 
 
3981
      ((XmTextF_string_length(tf) + delta) - (XmTextF_max_length(tf)) > 0)) { 
 
3982
      if (XmTextF_verify_bell(tf)) 
 
3983
      {
 
3984
          XBell(XtDisplay(tf), 0);
 
3985
      }
 
3986
      return False;
 
3987
  }     
 
3988
 
 
3989
  if (XmDataField_alignment(tf) == XmALIGNMENT_END)
 
3990
  {
 
3991
      df_GetXYFromPos(tf, 0, &x1, &y1);
 
3992
  }
 
3993
 
 
3994
 /* If there are modify verify callbacks, verify that we want to continue
 
3995
  * the action.
 
3996
  */
 
3997
  newInsert = XmTextF_cursor_position(tf);
 
3998
 
 
3999
  if (XmTextF_modify_verify_callback(tf) || XmTextF_wcs_modify_verify_callback(tf)) {
 
4000
    /* If the function df_ModifyVerify() returns false then don't
 
4001
     * continue with the action.
 
4002
     */
 
4003
     if (!df_ModifyVerify(tf, event, &replace_prev, &replace_next,
 
4004
                       &insert, &insert_length, &newInsert, &free_insert)) {
 
4005
        if (XmTextF_verify_bell(tf)) XBell(XtDisplay(tf), 0);
 
4006
        if (free_insert) XtFree(insert);
 
4007
        return False;
 
4008
     } else {
 
4009
        df_VerifyBounds(tf, &replace_prev, &replace_next);
 
4010
        replace_length = (int) (replace_next - replace_prev);
 
4011
        delta = insert_length - replace_length;
 
4012
 
 
4013
       /* Disallow insertions that go beyond max length boundries.
 
4014
        */
 
4015
        if ((delta >= 0) && 
 
4016
            ((XmTextF_string_length(tf) + delta) - (XmTextF_max_length(tf)) > 0)) { 
 
4017
            if (XmTextF_verify_bell(tf)) XBell(XtDisplay(tf), 0);
 
4018
            if (free_insert) XtFree(insert);
 
4019
            return False;
 
4020
        }
 
4021
 
 
4022
     }
 
4023
  }
 
4024
 
 
4025
 /* make sure selections are turned off prior to changeing text */
 
4026
  if (XmTextF_has_primary(tf) &&
 
4027
      XmTextF_prim_pos_left(tf) != XmTextF_prim_pos_right(tf))
 
4028
     XmDataFieldSetHighlight((Widget)tf, XmTextF_prim_pos_left(tf),
 
4029
                             XmTextF_prim_pos_right(tf), XmHIGHLIGHT_NORMAL);
 
4030
 
 
4031
  _XmDataFieldDrawInsertionPoint(tf, False);
 
4032
 
 
4033
  /* Allocate more space if we need it.
 
4034
   */
 
4035
  if (XmTextF_max_char_size(tf) == 1){
 
4036
  if (XmTextF_string_length(tf) + insert_length - replace_length >=
 
4037
      XmTextF_size_allocd(tf))
 
4038
    {
 
4039
      XmTextF_size_allocd(tf) += MAX(insert_length + TEXT_INCREMENT,
 
4040
                                        (XmTextF_size_allocd(tf) * 2));
 
4041
      XmTextF_value(tf) = (char *) XtRealloc((char*)XmTextF_value(tf), 
 
4042
                              (unsigned) (XmTextF_size_allocd(tf) * sizeof(char)));
 
4043
    }
 
4044
  } else {
 
4045
  if ((XmTextF_string_length(tf) + insert_length - replace_length) *
 
4046
                                        sizeof(wchar_t) >= XmTextF_size_allocd(tf))
 
4047
    {
 
4048
      XmTextF_size_allocd(tf) +=
 
4049
                          MAX((insert_length + TEXT_INCREMENT)*sizeof(wchar_t),
 
4050
                              (XmTextF_size_allocd(tf) * 2));
 
4051
      XmTextF_wc_value(tf) = (wchar_t *) XtRealloc((char*)XmTextF_wc_value(tf), 
 
4052
                           (unsigned) XmTextF_size_allocd(tf));
 
4053
    }
 
4054
  }
 
4055
 
 
4056
  if (XmTextF_has_primary(tf) && replace_prev < XmTextF_prim_pos_right(tf) &&
 
4057
                              replace_next > XmTextF_prim_pos_left(tf)) {
 
4058
     if (replace_prev <= XmTextF_prim_pos_left(tf)) {
 
4059
        if (replace_next < XmTextF_prim_pos_right(tf)) {
 
4060
          /* delete encompasses left half of the selection
 
4061
           * so move left endpoint
 
4062
           */
 
4063
           XmTextF_prim_pos_left(tf) = replace_next;
 
4064
        } else {
 
4065
          /* delete encompasses the selection so set selection to NULL */
 
4066
           XmTextF_prim_pos_left(tf) = XmTextF_prim_pos_right(tf);
 
4067
        }
 
4068
     } else {
 
4069
        if (replace_next > XmTextF_prim_pos_right(tf)) {
 
4070
          /* delete encompasses the right half of the selection
 
4071
           * so move right endpoint
 
4072
           */
 
4073
           XmTextF_prim_pos_right(tf) = replace_next;
 
4074
        } else {
 
4075
          /* delete is completely within the selection
 
4076
           * so set selection to NULL
 
4077
           */
 
4078
           XmTextF_prim_pos_right(tf) = XmTextF_prim_pos_left(tf);
 
4079
        }
 
4080
     }
 
4081
  }
 
4082
 
 
4083
  if (XmTextF_max_char_size(tf) == 1) {
 
4084
     if (replace_length > insert_length)
 
4085
       /* We need to shift the text at and after replace_next to the left. */
 
4086
       for (src = XmTextF_value(tf) + replace_next,
 
4087
            dst = src + (insert_length - replace_length),
 
4088
            i = (int) ((XmTextF_string_length(tf) + 1) - replace_next);
 
4089
            i > 0;
 
4090
            ++src, ++dst, --i)
 
4091
         *dst = *src;
 
4092
     else if (replace_length < insert_length)
 
4093
       /* We need to shift the text at and after replace_next to the right. */
 
4094
       /* Need to add 1 to string_length to handle the NULL terminator on */
 
4095
       /* the string. */
 
4096
       for (src = XmTextF_value(tf) + XmTextF_string_length(tf),
 
4097
            dst = src + (insert_length - replace_length),
 
4098
            i = (int) ((XmTextF_string_length(tf) + 1) - replace_next);
 
4099
            i > 0;
 
4100
            --src, --dst, --i)
 
4101
         *dst = *src;
 
4102
 
 
4103
    /* Update the string.
 
4104
     */
 
4105
     if (insert_length != 0) {
 
4106
        for (src = insert,
 
4107
             dst = XmTextF_value(tf) + replace_prev,
 
4108
             i = insert_length;
 
4109
             i > 0;
 
4110
             ++src, ++dst, --i)
 
4111
          *dst = *src;
 
4112
     }
 
4113
   } else {  /* have wchar_t* data */
 
4114
     if (replace_length > insert_length)
 
4115
       /* We need to shift the text at and after replace_next to the left. */
 
4116
       for (wc_src = XmTextF_wc_value(tf) + replace_next,
 
4117
            wc_dst = wc_src + (insert_length - replace_length),
 
4118
            i = (int) ((XmTextF_string_length(tf) + 1) - replace_next);
 
4119
            i > 0;
 
4120
            ++wc_src, ++wc_dst, --i)
 
4121
         *wc_dst = *wc_src;
 
4122
     else if (replace_length < insert_length)
 
4123
       /* We need to shift the text at and after replace_next to the right. */
 
4124
       /* Need to add 1 to string_length to handle the NULL terminator on */
 
4125
       /* the string. */
 
4126
       for (wc_src = XmTextF_wc_value(tf) + XmTextF_string_length(tf),
 
4127
            wc_dst = wc_src + (insert_length - replace_length),
 
4128
            i = (int) ((XmTextF_string_length(tf) + 1) - replace_next);
 
4129
            i > 0;
 
4130
            --wc_src, --wc_dst, --i)
 
4131
         *wc_dst = *wc_src;
 
4132
 
 
4133
    /* Update the string.
 
4134
     */
 
4135
     if (insert_length != 0) {
 
4136
        for (wc_src = (wchar_t *)insert,
 
4137
             wc_dst = XmTextF_wc_value(tf) + replace_prev,
 
4138
             i = insert_length;
 
4139
             i > 0;
 
4140
             ++wc_src, ++wc_dst, --i)
 
4141
          *wc_dst = *wc_src;
 
4142
     }
 
4143
   }
 
4144
 
 
4145
  if (XmTextF_has_primary(tf) &&
 
4146
      XmTextF_prim_pos_left(tf) != XmTextF_prim_pos_right(tf)) {
 
4147
     if (replace_prev <= XmTextF_prim_pos_left(tf)) {
 
4148
        XmTextF_prim_pos_left(tf) += delta;
 
4149
        XmTextF_prim_pos_right(tf) += delta;
 
4150
     }
 
4151
     if (XmTextF_prim_pos_left(tf) > XmTextF_prim_pos_right(tf))
 
4152
        XmTextF_prim_pos_right(tf) = XmTextF_prim_pos_left(tf);
 
4153
  }
 
4154
 
 
4155
 /* make sure the selection are redisplay, since 
 
4156
  * they were turned off earlier 
 
4157
  */
 
4158
  if (XmTextF_has_primary(tf) &&
 
4159
      XmTextF_prim_pos_left(tf) != XmTextF_prim_pos_right(tf))
 
4160
  {
 
4161
     XmDataFieldSetHighlight((Widget)tf, XmTextF_prim_pos_left(tf),
 
4162
                             XmTextF_prim_pos_right(tf), 
 
4163
                             XmHIGHLIGHT_SELECTED);
 
4164
  }
 
4165
  XmTextF_string_length(tf) += insert_length - replace_length;
 
4166
 
 
4167
  if (move_cursor) {
 
4168
     if (XmTextF_cursor_position(tf) != newInsert) {
 
4169
        if (newInsert > XmTextF_string_length(tf)) {
 
4170
           cursorPos = XmTextF_string_length(tf);
 
4171
        } else if (newInsert < 0) {
 
4172
           cursorPos = 0;
 
4173
        } else {
 
4174
           cursorPos = newInsert;
 
4175
        }
 
4176
     } else
 
4177
       cursorPos = replace_next + (insert_length - replace_length);
 
4178
     if (event != NULL) {
 
4179
        (void)df_SetDestination((Widget)tf, cursorPos, False, event->xkey.time);
 
4180
     } else {
 
4181
        (void) df_SetDestination((Widget)tf, cursorPos, False,
 
4182
                              XtLastTimestampProcessed(XtDisplay((Widget)tf)));
 
4183
     }
 
4184
     _XmDataFielddf_SetCursorPosition(tf, event, cursorPos, False, True);
 
4185
  }
 
4186
 
 
4187
  if (XmDataField_alignment(tf) == XmALIGNMENT_END)
 
4188
  {
 
4189
      df_GetXYFromPos(tf, 0, &x2, &y2);
 
4190
 
 
4191
      y2 -= XmTextF_font_ascent(tf);
 
4192
 
 
4193
      if ((x2 > 0) && (x1 < x2) && (y2 < y1))
 
4194
      {
 
4195
          if (x1 < 0) x1 = 0;
 
4196
 
 
4197
          /* PWC - Erase leading space (delta of old & new first position) */
 
4198
          df_XmSetInvGC(tf, XmTextF_gc(tf));
 
4199
          XFillRectangle(XtDisplay(tf), XtWindow(tf), XmTextF_gc(tf),
 
4200
                         x1, y2, x2, y1);
 
4201
#if PWC_DEBUG
 
4202
          printf("Fill Rectangle :: x1(%d), y1(%d) - x2(%d), y2(%d)\n",
 
4203
                 x1, y2, x2, y1);
 
4204
#endif
 
4205
      }
 
4206
  }
 
4207
 
 
4208
  if (XmTextF_resize_width(tf) && XmTextF_do_resize(tf)) 
 
4209
  {
 
4210
     df_AdjustSize(tf);
 
4211
  } else {
 
4212
     df_AdjustText(tf, XmTextF_cursor_position(tf), False);
 
4213
     df_RedisplayText(tf, old_pos, XmTextF_string_length(tf));
 
4214
  }
 
4215
 
 
4216
  _XmDataFieldDrawInsertionPoint(tf, True);
 
4217
  if (free_insert) {
 
4218
      XtFree(insert);
 
4219
  }
 
4220
 
 
4221
  return True;
 
4222
}
 
4223
 
 
4224
 
 
4225
/*
 
4226
 * Reset selection flag and selection positions and then display
 
4227
 * the new settings.
 
4228
 */
 
4229
void 
 
4230
#ifdef _NO_PROTO
 
4231
_XmDataFieldDeselectSelection( w, disown, sel_time )
 
4232
        Widget w ;
 
4233
        Boolean disown ;
 
4234
        Time sel_time ;
 
4235
#else
 
4236
_XmDataFieldDeselectSelection(
 
4237
        Widget w,
 
4238
#if NeedWidePrototypes
 
4239
        int disown,
 
4240
#else
 
4241
        Boolean disown,
 
4242
#endif /* NeedWidePrototypes */
 
4243
        Time sel_time )
 
4244
#endif /* _NO_PROTO */
 
4245
{
 
4246
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
4247
 
 
4248
  if (disown)
 
4249
  {
 
4250
    /*
 
4251
     * Disown the primary selection (This function is a no-op if
 
4252
     * this widget doesn't own the primary selection)
 
4253
     */
 
4254
     XtDisownSelection(w, XA_PRIMARY, sel_time);
 
4255
  }
 
4256
  if (tf != NULL) {
 
4257
     _XmDataFieldDrawInsertionPoint(tf, False);
 
4258
     XmTextF_has_primary(tf) = False;
 
4259
     DataFieldSetHighlight(tf, XmTextF_prim_pos_left(tf),
 
4260
                           XmTextF_prim_pos_right(tf), XmHIGHLIGHT_NORMAL);
 
4261
     XmTextF_prim_pos_left(tf) = XmTextF_prim_pos_right(tf) =
 
4262
               XmTextF_prim_anchor(tf) = XmTextF_cursor_position(tf);
 
4263
 
 
4264
     if (!XmTextF_has_focus(tf)) 
 
4265
     {
 
4266
         XmDataFieldSetAddMode(w, False);
 
4267
     }
 
4268
     df_RedisplayText(tf, 0, XmTextF_string_length(tf));
 
4269
 
 
4270
     _XmDataFieldDrawInsertionPoint(tf, True);
 
4271
  }
 
4272
}
 
4273
 
 
4274
/*
 
4275
 * Finds the cursor position from the given X value.
 
4276
 */
 
4277
static XmTextPosition 
 
4278
#ifdef _NO_PROTO
 
4279
df_GetPosFromX( tf, x )
 
4280
        XmDataFieldWidget tf ;
 
4281
        Position x ;
 
4282
#else
 
4283
df_GetPosFromX(
 
4284
        XmDataFieldWidget tf,
 
4285
#if NeedWidePrototypes
 
4286
        int x )
 
4287
#else
 
4288
        Position x )
 
4289
#endif /* NeedWidePrototypes */
 
4290
#endif /* _NO_PROTO */
 
4291
{
 
4292
    XmTextPosition position;
 
4293
    int temp_x = 0;
 
4294
    int next_char_width = 0;
 
4295
 
 
4296
    if (XmDataField_alignment(tf) == XmALIGNMENT_END)
 
4297
        return RightAlignedGetPosFromX(tf, x);
 
4298
 
 
4299
   /* Decompose the x to equal the length of the text string */
 
4300
    temp_x += (int) XmTextF_h_offset(tf);
 
4301
 
 
4302
   /* Next width is an offset allowing button presses on the left side 
 
4303
    * of a character to select that character, while button presses
 
4304
    * on the rigth side of the character select the  NEXT character.
 
4305
    */
 
4306
 
 
4307
    if (XmTextF_string_length(tf) > 0) {
 
4308
 
 
4309
       if (XmTextF_max_char_size(tf) != 1) {
 
4310
          next_char_width = df_FindPixelLength(tf, (char*)XmTextF_wc_value(tf), 1);
 
4311
       } else {
 
4312
          next_char_width = df_FindPixelLength(tf, XmTextF_value(tf), 1);
 
4313
       }
 
4314
    }
 
4315
 
 
4316
    for (position = 0; temp_x + next_char_width/2 < (int) x &&
 
4317
                       position < XmTextF_string_length(tf); position++){
 
4318
 
 
4319
       temp_x+=next_char_width;    /* 
 
4320
                                    * We still haven't reached the x pos.
 
4321
                                    * Add the width and find the next chars
 
4322
                                    * width. 
 
4323
                                    */
 
4324
 
 
4325
        /*
 
4326
         * If there is a next position, find its width.  Otherwise, use the
 
4327
         * current "next" width.
 
4328
         */
 
4329
 
 
4330
       if (XmTextF_string_length(tf) > position + 1) {
 
4331
          if (XmTextF_max_char_size(tf) != 1) {
 
4332
             next_char_width = df_FindPixelLength(tf,
 
4333
                                  (char*)(XmTextF_wc_value(tf) + position + 1), 1);
 
4334
          } else {
 
4335
             next_char_width = df_FindPixelLength(tf,
 
4336
                                           XmTextF_value(tf) + position + 1, 1);
 
4337
          }
 
4338
       } 
 
4339
    } /* for */
 
4340
 
 
4341
    return position;
 
4342
}
 
4343
 
 
4344
/*
 
4345
 * Finds the cursor position from the given X value.
 
4346
 */
 
4347
static XmTextPosition 
 
4348
#ifdef _NO_PROTO
 
4349
RightAlignedGetPosFromX( tf, x )
 
4350
    XmDataFieldWidget tf ;
 
4351
    Position x ;
 
4352
#else
 
4353
RightAlignedGetPosFromX( XmDataFieldWidget tf,
 
4354
#if NeedWidePrototypes
 
4355
    int x )
 
4356
#else
 
4357
    Position x )
 
4358
#endif /* NeedWidePrototypes */
 
4359
#endif /* _NO_PROTO */
 
4360
{
 
4361
    XmTextPosition position;
 
4362
    int margin_width = XmTextF_margin_width(tf) +
 
4363
                        tf->primitive.highlight_thickness +
 
4364
                        tf->primitive.shadow_thickness;
 
4365
    int temp_x;
 
4366
    int next_char_width = 0;
 
4367
 
 
4368
    position = XmTextF_string_length(tf);
 
4369
 
 
4370
    temp_x = tf->core.width - margin_width + XmTextF_h_offset(tf);
 
4371
 
 
4372
    if (XmTextF_string_length(tf) > 0) {
 
4373
 
 
4374
       if (XmTextF_max_char_size(tf) != 1) {
 
4375
          next_char_width = df_FindPixelLength(tf, (char*)XmTextF_wc_value(tf) + 
 
4376
                                            position - 1, 1);
 
4377
       } else {
 
4378
          next_char_width = df_FindPixelLength(tf, XmTextF_value(tf) +
 
4379
                                            position - 1, 1);
 
4380
       }
 
4381
    }
 
4382
 
 
4383
    for (; x < (temp_x - next_char_width / 2) && (position > 0); position--)
 
4384
    {
 
4385
        temp_x -= next_char_width; /* 
 
4386
                                    * We still haven't reached the x pos.
 
4387
                                    * Add the width and find the next chars
 
4388
                                    * width. 
 
4389
                                    */
 
4390
 
 
4391
        /*
 
4392
         * If there is a next position, find its width.  Otherwise, use the
 
4393
         * current "next" width.
 
4394
         */
 
4395
        if (position > 1)
 
4396
        {
 
4397
            if (XmTextF_max_char_size(tf) != 1) {
 
4398
                next_char_width = df_FindPixelLength(tf,
 
4399
                    (char*)(XmTextF_wc_value(tf) + position - 2), 1);
 
4400
            } else {
 
4401
                next_char_width = df_FindPixelLength(tf,
 
4402
                    XmTextF_value(tf) + position - 2 , 1);
 
4403
            }
 
4404
        } 
 
4405
    } /* for */
 
4406
 
 
4407
#if PWC_DEBUG
 
4408
    printf("CursorPos(%d), x(%d)\n", position, x);
 
4409
#endif
 
4410
 
 
4411
    return position;
 
4412
}
 
4413
 
 
4414
/* ARGSUSED */
 
4415
static Boolean 
 
4416
#ifdef _NO_PROTO
 
4417
df_SetDestination( w, position, disown, set_time )
 
4418
        Widget w ;
 
4419
        XmTextPosition position ;
 
4420
        Boolean disown ;
 
4421
        Time set_time ;
 
4422
#else
 
4423
df_SetDestination(
 
4424
        Widget w,
 
4425
        XmTextPosition position,
 
4426
#if NeedWidePrototypes
 
4427
        int disown,
 
4428
#else
 
4429
        Boolean disown,
 
4430
#endif /* NeedWidePrototypes */
 
4431
        Time set_time )
 
4432
#endif /* _NO_PROTO */
 
4433
{
 
4434
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
4435
    Boolean result = TRUE;
 
4436
    Atom MOTIF_DESTINATION = XmInternAtom(XtDisplay(w),
 
4437
                                        "MOTIF_DESTINATION", False);
 
4438
 
 
4439
    if (!XtIsRealized(w)) return False;
 
4440
 
 
4441
    _XmDataFieldDrawInsertionPoint(tf, False);
 
4442
 
 
4443
    if (!disown) {
 
4444
        if (!XmTextF_has_destination(tf)) {
 
4445
            if (!set_time) set_time = df_GetServerTime(w);
 
4446
            result = XtOwnSelection(w, MOTIF_DESTINATION, set_time,
 
4447
                                    _XmDataFieldConvert,
 
4448
                                    _XmDataFieldLoseSelection,
 
4449
                                    (XtSelectionDoneProc) NULL);
 
4450
            XmTextF_dest_time(tf) = set_time;
 
4451
            XmTextF_has_destination(tf) = result;
 
4452
 
 
4453
            if (result) _XmSetDestination(XtDisplay(w), w);
 
4454
            _XmDataFToggleCursorGC(w);
 
4455
        }
 
4456
    } else {
 
4457
        if (XmTextF_has_destination(tf))
 
4458
           if (!set_time) set_time = df_GetServerTime(w);
 
4459
           XtDisownSelection(w, MOTIF_DESTINATION, set_time);
 
4460
 
 
4461
          /* Call XmGetDestination(dpy) to get widget that last had
 
4462
             destination cursor. */
 
4463
           if (w == XmGetDestination(XtDisplay(w)))
 
4464
              _XmSetDestination(XtDisplay(w), (Widget)NULL);
 
4465
 
 
4466
           XmTextF_has_destination(tf) = False;
 
4467
           _XmDataFToggleCursorGC(w);
 
4468
    }
 
4469
 
 
4470
    _XmDataFieldDrawInsertionPoint(tf, True);
 
4471
 
 
4472
    return result;
 
4473
}
 
4474
 
 
4475
Boolean 
 
4476
#ifdef _NO_PROTO
 
4477
_XmDataFielddf_SetDestination( w, position, set_time )
 
4478
        Widget w ;
 
4479
        XmTextPosition position ;
 
4480
        Time set_time ;
 
4481
#else
 
4482
_XmDataFielddf_SetDestination(
 
4483
        Widget w,
 
4484
        XmTextPosition position,
 
4485
        Time set_time )
 
4486
#endif /* _NO_PROTO */
 
4487
{
 
4488
   Boolean result;
 
4489
 
 
4490
   result = df_SetDestination(w, position, False, set_time);
 
4491
 
 
4492
   return result;
 
4493
}
 
4494
 
 
4495
 
 
4496
/*
 
4497
 * Calls the losing focus verify callback to verify that the application
 
4498
 * want to traverse out of the text field widget.  Returns the result.
 
4499
 */
 
4500
static Boolean 
 
4501
#ifdef _NO_PROTO
 
4502
df_VerifyLeave( tf, event )
 
4503
        XmDataFieldWidget tf ;
 
4504
        XEvent *event ;
 
4505
#else
 
4506
df_VerifyLeave(
 
4507
        XmDataFieldWidget tf,
 
4508
        XEvent *event )
 
4509
#endif /* _NO_PROTO */
 
4510
{
 
4511
    XmTextVerifyCallbackStruct  cbdata;
 
4512
 
 
4513
    cbdata.reason = XmCR_LOSING_FOCUS;
 
4514
    cbdata.event = event;
 
4515
    cbdata.doit = True;
 
4516
    cbdata.currInsert = XmTextF_cursor_position(tf);
 
4517
    cbdata.newInsert = XmTextF_cursor_position(tf);
 
4518
    cbdata.startPos = XmTextF_cursor_position(tf);
 
4519
    cbdata.endPos = XmTextF_cursor_position(tf);
 
4520
    cbdata.text = NULL;
 
4521
    XtCallCallbackList((Widget) tf, XmTextF_losing_focus_callback(tf), 
 
4522
                       (XtPointer) &cbdata);
 
4523
    return(cbdata.doit);
 
4524
}
 
4525
 
 
4526
/* This routine is used to determine if two adjacent wchar_t characters
 
4527
 * constitute a word boundary */
 
4528
/* ARGSUSED */
 
4529
static Boolean
 
4530
#ifdef _NO_PROTO
 
4531
_XmDataFieldIsWordBoundary( tf, pos1, pos2 )
 
4532
        XmDataFieldWidget tf ;
 
4533
        XmTextPosition pos1 ;
 
4534
        XmTextPosition pos2 ;
 
4535
#else
 
4536
_XmDataFieldIsWordBoundary(
 
4537
        XmDataFieldWidget tf,
 
4538
        XmTextPosition pos1 ,
 
4539
        XmTextPosition pos2 )
 
4540
#endif /* _NO_PROTO */
 
4541
{
 
4542
   int size_pos1 = 0;
 
4543
   int size_pos2 = 0;
 
4544
   char s1[MB_LEN_MAX];
 
4545
   char s2[MB_LEN_MAX];
 
4546
 
 
4547
/* if positions aren't adjacent, return False */
 
4548
   if(pos1 < pos2 && ((pos2 - pos1) != 1)) 
 
4549
      return False;
 
4550
   else if(pos2 < pos1 && ((pos1 - pos2) != 1)) 
 
4551
      return False;
 
4552
 
 
4553
   if (XmTextF_max_char_size(tf) == 1) { /* data is char* and one-byte per char */
 
4554
      if (isspace((int)(unsigned char)XmTextF_value(tf)[pos1]) || 
 
4555
          isspace((int)(unsigned char)XmTextF_value(tf)[pos2])) return True;
 
4556
   } else {
 
4557
      size_pos1 = wctomb(s1, XmTextF_wc_value(tf)[pos1]);
 
4558
      size_pos2 = wctomb(s2, XmTextF_wc_value(tf)[pos2]);
 
4559
      if (size_pos1 == 1 && (size_pos2 != 1 || 
 
4560
                             isspace((int)(unsigned char)*s1)))
 
4561
        return True;
 
4562
      if (size_pos2 == 1 && (size_pos1 != 1 || 
 
4563
                             isspace((int)(unsigned char)*s2)))
 
4564
        return True;
 
4565
   }
 
4566
   return False;
 
4567
}
 
4568
 
 
4569
/* This routine accepts an array of wchar_t's containing wchar encodings
 
4570
 * of whitespace characters (and the number of array elements), comparing
 
4571
 * the wide character passed to each element of the array.  If a match
 
4572
 * is found, we got a white space.  This routine exists only because
 
4573
 * iswspace(3c) is not yet standard.  If a system has isw* available,
 
4574
 * calls to this routine should be changed to iswspace(3c) (and callers
 
4575
 * should delete initialization of the array), and this routine should
 
4576
 * be deleted.  Its a stop gap measure to avoid allocating an instance
 
4577
 * variable for the white_space array and/or declaring a widget wide
 
4578
 * global for the data and using a macro.  Its ugly, but it works and 
 
4579
 * in the long run will be replaced by standard functionality. */
 
4580
 
 
4581
/* ARGSUSED */
 
4582
static Boolean
 
4583
#ifdef _NO_PROTO
 
4584
_XmDataFieldIsWSpace( wide_char, white_space, num_entries )
 
4585
        wchar_t wide_char ;
 
4586
        wchar_t * white_space ;
 
4587
        int num_entries ;
 
4588
#else
 
4589
_XmDataFieldIsWSpace(
 
4590
        wchar_t wide_char,
 
4591
        wchar_t * white_space ,
 
4592
        int num_entries )
 
4593
#endif /* _NO_PROTO */
 
4594
{
 
4595
   int i;
 
4596
 
 
4597
   for (i=num_entries; i > 0; i--){
 
4598
      if (wide_char == white_space[i]) return True;
 
4599
   }
 
4600
   return False;
 
4601
}
 
4602
 
 
4603
static void 
 
4604
#ifdef _NO_PROTO
 
4605
df_FindWord( tf, begin, left, right )
 
4606
        XmDataFieldWidget tf ;
 
4607
        XmTextPosition begin ;
 
4608
        XmTextPosition *left ;
 
4609
        XmTextPosition *right ;
 
4610
#else
 
4611
df_FindWord(
 
4612
        XmDataFieldWidget tf,
 
4613
        XmTextPosition begin,
 
4614
        XmTextPosition *left,
 
4615
        XmTextPosition *right )
 
4616
#endif /* _NO_PROTO */
 
4617
{
 
4618
    XmTextPosition start, end;
 
4619
    wchar_t white_space[3];
 
4620
 
 
4621
    if (XmTextF_max_char_size(tf) == 1) {
 
4622
       for (start = begin; start > 0; start--) {
 
4623
          if (isspace((int)(unsigned char)XmTextF_value(tf)[start - 1])) {
 
4624
             break;
 
4625
          }
 
4626
       }
 
4627
       *left = start;
 
4628
 
 
4629
       for (end = begin; end <= XmTextF_string_length(tf); end++) {
 
4630
          if (isspace((int)(unsigned char)XmTextF_value(tf)[end])) {
 
4631
             end++;
 
4632
             break;
 
4633
          }
 
4634
       }
 
4635
       *right = end - 1;
 
4636
    } else { /* check for iswspace and iswordboundary in each direction */
 
4637
       (void)mbtowc(&white_space[0], " ", 1);
 
4638
       (void)mbtowc(&white_space[1], "\n", 1);
 
4639
       (void)mbtowc(&white_space[2], "\t", 1);
 
4640
       for (start = begin; start > 0; start --) {
 
4641
          if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[start-1],white_space, 3)
 
4642
              || _XmDataFieldIsWordBoundary(tf, (XmTextPosition) start - 1, 
 
4643
                                            start)) {
 
4644
                 break;
 
4645
          }
 
4646
       }
 
4647
       *left = start;
 
4648
 
 
4649
       for (end = begin; end <= XmTextF_string_length(tf); end++) {
 
4650
           if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[end], white_space, 3)){
 
4651
              end++;
 
4652
              break;
 
4653
           } else if (end < XmTextF_string_length(tf)) {
 
4654
              if (_XmDataFieldIsWordBoundary(tf, end, (XmTextPosition)end + 1)){
 
4655
                 end += 2; /* want to return position of next word; end + 1 */
 
4656
                 break;    /* is that position && *right = end - 1... */
 
4657
              }
 
4658
           }
 
4659
       }
 
4660
       *right = end - 1;
 
4661
   }
 
4662
}
 
4663
 
 
4664
static void 
 
4665
#ifdef _NO_PROTO
 
4666
df_FindPrevWord( tf, left, right )
 
4667
        XmDataFieldWidget tf ;
 
4668
        XmTextPosition *left ;
 
4669
        XmTextPosition *right ;
 
4670
#else
 
4671
df_FindPrevWord(
 
4672
        XmDataFieldWidget tf,
 
4673
        XmTextPosition *left,
 
4674
        XmTextPosition *right )
 
4675
#endif /* _NO_PROTO */
 
4676
{
 
4677
 
 
4678
    XmTextPosition start = XmTextF_cursor_position(tf);
 
4679
    wchar_t white_space[3];
 
4680
 
 
4681
    if (XmTextF_max_char_size(tf) != 1) {
 
4682
       (void)mbtowc(&white_space[0], " ", 1);
 
4683
       (void)mbtowc(&white_space[1], "\n", 1);
 
4684
       (void)mbtowc(&white_space[2], "\t", 1);
 
4685
    }
 
4686
 
 
4687
 
 
4688
    if (XmTextF_max_char_size(tf) == 1) {
 
4689
       if ((start > 0) && 
 
4690
           (isspace((int)(unsigned char)XmTextF_value(tf)[start - 1]))) {
 
4691
           for (; start > 0; start--) {
 
4692
               if (!isspace((int)(unsigned char)XmTextF_value(tf)[start - 1])) {
 
4693
                  start--;
 
4694
                  break;
 
4695
               }
 
4696
           }
 
4697
       }
 
4698
       df_FindWord(tf, start, left, right);
 
4699
    } else { 
 
4700
       if ((start > 0) && (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[start - 1],
 
4701
                                                white_space, 3))) {
 
4702
          for (; start > 0; start--) {
 
4703
             if (!_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[start -1], 
 
4704
                                       white_space, 3)){
 
4705
                start--;
 
4706
                break;
 
4707
             }
 
4708
          }
 
4709
       } else if ((start > 0) && 
 
4710
                  _XmDataFieldIsWordBoundary(tf, (XmTextPosition) start - 1, 
 
4711
                                             start)){
 
4712
          start--;
 
4713
       }
 
4714
       df_FindWord(tf, start, left, right);
 
4715
    }
 
4716
}
 
4717
 
 
4718
static void 
 
4719
#ifdef _NO_PROTO
 
4720
df_FindNextWord( tf, left, right )
 
4721
        XmDataFieldWidget tf ;
 
4722
        XmTextPosition *left ;
 
4723
        XmTextPosition *right ;
 
4724
#else
 
4725
df_FindNextWord(
 
4726
        XmDataFieldWidget tf,
 
4727
        XmTextPosition *left,
 
4728
        XmTextPosition *right )
 
4729
#endif /* _NO_PROTO */
 
4730
{
 
4731
 
 
4732
    XmTextPosition end = XmTextF_cursor_position(tf);
 
4733
    wchar_t white_space[3];
 
4734
 
 
4735
    if (XmTextF_max_char_size(tf) != 1) {
 
4736
       (void)mbtowc(&white_space[0], " ", 1);
 
4737
       (void)mbtowc(&white_space[1], "\n", 1);
 
4738
       (void)mbtowc(&white_space[2], "\t", 1);
 
4739
    }
 
4740
 
 
4741
 
 
4742
    if(XmTextF_max_char_size(tf) == 1) {
 
4743
       if (isspace((int)(unsigned char)XmTextF_value(tf)[end])) {
 
4744
           for (end = XmTextF_cursor_position(tf);
 
4745
                end < XmTextF_string_length(tf); end++) {
 
4746
               if (!isspace((int)(unsigned char)XmTextF_value(tf)[end])) {
 
4747
                  break;
 
4748
               }
 
4749
           }
 
4750
       }
 
4751
       df_FindWord(tf, end, left, right);
 
4752
      /*
 
4753
       * Set right to the last whitespace following the end of the
 
4754
       * current word.
 
4755
       */
 
4756
       while (*right < XmTextF_string_length(tf) &&
 
4757
              isspace((int)(unsigned char)XmTextF_value(tf)[(int)*right]))
 
4758
             *right = *right + 1;
 
4759
       if (*right < XmTextF_string_length(tf))
 
4760
          *right = *right - 1;
 
4761
   } else {
 
4762
      if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[end], white_space, 3)) {
 
4763
         for ( ; end < XmTextF_string_length(tf); end ++) {
 
4764
           if (!_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[end], white_space, 3)) {
 
4765
               break;
 
4766
           }
 
4767
         }
 
4768
      } else { /* if for other reasons at word boundry, advance to next word */
 
4769
         if ((end < XmTextF_string_length(tf)) && 
 
4770
              _XmDataFieldIsWordBoundary(tf, end, (XmTextPosition) end + 1))
 
4771
              end++;
 
4772
      }
 
4773
      df_FindWord(tf, end, left, right);
 
4774
      /*
 
4775
       * If word boundary caused by whitespace, set right to the last 
 
4776
       * whitespace following the end of the current word.
 
4777
       */
 
4778
      if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[(int)*right], white_space, 3))      {
 
4779
         while (*right < XmTextF_string_length(tf) &&
 
4780
               _XmDataFieldIsWSpace(XmTextF_wc_value(tf)[(int)*right], 
 
4781
                                    white_space, 3)) {
 
4782
            *right = *right + 1;
 
4783
         }
 
4784
         if (*right < XmTextF_string_length(tf))
 
4785
            *right = *right - 1;
 
4786
      }
 
4787
   }
 
4788
}
 
4789
 
 
4790
static void 
 
4791
#ifdef _NO_PROTO
 
4792
df_CheckDisjointSelection( w, position, sel_time )
 
4793
        Widget w ;
 
4794
        XmTextPosition position ;
 
4795
        Time sel_time ;
 
4796
#else
 
4797
df_CheckDisjointSelection(
 
4798
        Widget w,
 
4799
        XmTextPosition position,
 
4800
        Time sel_time )
 
4801
#endif /* _NO_PROTO */
 
4802
{
 
4803
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
4804
    XmTextPosition left = 0, right = 0;
 
4805
 
 
4806
    if (XmTextF_add_mode(tf) || 
 
4807
        (XmDataFieldGetSelectionPosition(w, &left, &right) && left != right &&
 
4808
         position >= left && position <= right))
 
4809
       XmTextF_pending_off(tf) = FALSE;
 
4810
    else
 
4811
       XmTextF_pending_off(tf) = TRUE;
 
4812
 
 
4813
    if (left == right) {
 
4814
       (void) df_SetDestination(w, position, False, sel_time);
 
4815
       XmTextF_prim_anchor(tf) = position;
 
4816
    } else {
 
4817
       (void) df_SetDestination(w, position, False, sel_time);
 
4818
       if (!XmTextF_add_mode(tf)) XmTextF_prim_anchor(tf) = position;
 
4819
    }
 
4820
}
 
4821
 
 
4822
static Boolean 
 
4823
#ifdef _NO_PROTO
 
4824
df_NeedsPendingDelete( tf )
 
4825
        XmDataFieldWidget tf ;
 
4826
#else
 
4827
df_NeedsPendingDelete(
 
4828
        XmDataFieldWidget tf )
 
4829
#endif /* _NO_PROTO */
 
4830
{
 
4831
   return (XmTextF_add_mode(tf) ?
 
4832
           (XmTextF_pending_delete(tf) &&
 
4833
            XmTextF_has_primary(tf) &&
 
4834
            XmTextF_prim_pos_left(tf) != XmTextF_prim_pos_right(tf) &&
 
4835
            XmTextF_prim_pos_left(tf) <= XmTextF_cursor_position(tf) &&
 
4836
            XmTextF_prim_pos_right(tf) >= XmTextF_cursor_position(tf)) :
 
4837
           (XmTextF_has_primary(tf) &&
 
4838
            XmTextF_prim_pos_left(tf) != XmTextF_prim_pos_right(tf)));
 
4839
}
 
4840
 
 
4841
static Boolean 
 
4842
#ifdef _NO_PROTO
 
4843
df_NeedsPendingDeleteDisjoint( tf )
 
4844
        XmDataFieldWidget tf ;
 
4845
#else
 
4846
df_NeedsPendingDeleteDisjoint(
 
4847
        XmDataFieldWidget tf )
 
4848
#endif /* _NO_PROTO */
 
4849
{
 
4850
  return (XmTextF_pending_delete(tf) &&
 
4851
          XmTextF_has_primary(tf) &&
 
4852
          XmTextF_prim_pos_left(tf) != XmTextF_prim_pos_right(tf) &&
 
4853
          XmTextF_prim_pos_left(tf) <= XmTextF_cursor_position(tf) &&
 
4854
          XmTextF_prim_pos_right(tf) >= XmTextF_cursor_position(tf));
 
4855
}
 
4856
 
 
4857
static Time
 
4858
#ifdef _NO_PROTO
 
4859
df_GetServerTime( w )
 
4860
        Widget w ;
 
4861
#else
 
4862
df_GetServerTime(
 
4863
        Widget w )
 
4864
#endif /* _NO_PROTO */
 
4865
{
 
4866
  XEvent event;
 
4867
  EventMask shellMask;
 
4868
 
 
4869
  while(!XtIsShell(w)) w = XtParent(w);
 
4870
 
 
4871
  shellMask =  XtBuildEventMask(w);
 
4872
 
 
4873
  if (!(shellMask & PropertyChangeMask))
 
4874
     XSelectInput(XtDisplay(w), XtWindow(w),
 
4875
                  (long)(shellMask | PropertyChangeMask));
 
4876
 
 
4877
  XChangeProperty(XtDisplay(w), XtWindow(w), XA_WM_HINTS, XA_WM_HINTS,
 
4878
                  32, PropModeAppend, (unsigned char *)NULL, 0);
 
4879
 
 
4880
 
 
4881
  XWindowEvent(XtDisplay(w), XtWindow(w), PropertyChangeMask, &event);
 
4882
 
 
4883
  if (!(shellMask & PropertyChangeMask))
 
4884
     XSelectInput(XtDisplay(w), XtWindow(w), (long)shellMask);
 
4885
 
 
4886
  return (event.xproperty.time);
 
4887
}
 
4888
 
 
4889
static Boolean
 
4890
PrintableString(XmDataFieldWidget tf,
 
4891
                char* str, 
 
4892
                int n, 
 
4893
                Boolean use_wchar) /* sometimes unused */
 
4894
{
 
4895
#ifdef SUPPORT_ZERO_WIDTH
 
4896
  /* some locales (such as Thai) have characters that are
 
4897
   * printable but non-spacing. These should be inserted,
 
4898
   * even if they have zero width.
 
4899
   */
 
4900
  if (tf->text.max_char_size == 1) {
 
4901
    int i;
 
4902
    if (!use_wchar) {
 
4903
      for (i = 0; i < n; i++) {
 
4904
        if (!isprint((unsigned char)str[i])) {
 
4905
          return False;
 
4906
        }
 
4907
      }
 
4908
    } else {
 
4909
      char scratch[8];
 
4910
      wchar_t *ws = (wchar_t *) str;
 
4911
      for (i = 0; i < n; i++) {
 
4912
        if (wctomb(scratch, ws[i]) <= 0)
 
4913
          return False;
 
4914
        if (!isprint((unsigned char)scratch[0])) {
 
4915
          return False;
 
4916
        }
 
4917
      }
 
4918
    }
 
4919
    return True;
 
4920
  } else {
 
4921
    /* tf->text.max_char_size > 1 */
 
4922
#ifdef HAS_WIDECHAR_FUNCTIONS
 
4923
    if (use_wchar) {
 
4924
      int i;
 
4925
      wchar_t *ws = (wchar_t *) str;
 
4926
      for (i = 0; i < n; i++) {
 
4927
        if (!iswprint(ws[i])) {
 
4928
          return False;
 
4929
        }
 
4930
      }
 
4931
      return True;
 
4932
    } else {
 
4933
      int i, csize;
 
4934
      wchar_t wc;
 
4935
#ifndef NO_MULTIBYTE
 
4936
      for (i = 0, csize = mblen(str, tf->text.max_char_size);
 
4937
           i < n;
 
4938
           i += csize, csize=mblen(&(str[i]), tf->text.max_char_size))
 
4939
#else
 
4940
      for (i = 0, csize = *str ? 1 : 0; i < n;
 
4941
           i += csize, csize = str[i] ? 1 : 0)
 
4942
#endif
 
4943
        {
 
4944
          if (csize < 0) 
 
4945
            return False;
 
4946
          if (mbtowc(&wc, &(str[i]), tf->text.max_char_size) <= 0)
 
4947
            return False;
 
4948
          if (!iswprint(wc)) {
 
4949
            return False;
 
4950
          }
 
4951
        }
 
4952
    }
 
4953
#else /* HAS_WIDECHAR_FUNCTIONS */ 
 
4954
    /*
 
4955
     * This will only check if any single-byte characters are non-
 
4956
     * printable. Better than nothing...
 
4957
     */
 
4958
    int i, csize;
 
4959
    if (!use_wchar) {
 
4960
#ifndef NO_MULTIBYTE
 
4961
      for (i = 0, csize = mblen(str, tf->text.max_char_size);
 
4962
           i < n;
 
4963
           i += csize, csize=mblen(&(str[i]), tf->text.max_char_size))
 
4964
#else
 
4965
      for (i = 0, csize = *str ? 1 : 0; i < n;
 
4966
           i += csize, csize = str[i] ? 1 : 0)
 
4967
#endif
 
4968
        {
 
4969
          if (csize < 0)
 
4970
            return False;
 
4971
          if (csize == 1 && !isprint((unsigned char)str[i])) {
 
4972
            return False;
 
4973
          }
 
4974
        }
 
4975
    } else {
 
4976
      char scratch[8];
 
4977
      wchar_t *ws = (wchar_t *) str;
 
4978
      for (i = 0; i < n; i++) {
 
4979
        if ((csize = wctomb(scratch, ws[i])) <= 0)
 
4980
          return False;
 
4981
        if (csize == 1 && !isprint((unsigned char)scratch[0])) {
 
4982
          return False;
 
4983
        }
 
4984
      }
 
4985
    }
 
4986
#endif /* HAS_WIDECHAR_FUNCTIONS */
 
4987
    return True;
 
4988
  }
 
4989
#else /* SUPPORT_ZERO_WIDTH */
 
4990
  if (TextF_UseFontSet(tf)) {
 
4991
      if(use_wchar) 
 
4992
          return (XwcTextEscapement((XFontSet)TextF_Font(tf), (wchar_t *)str, n) != 0);
 
4993
      else
 
4994
          return (XmbTextEscapement((XFontSet)TextF_Font(tf), str, n) != 0);
 
4995
#ifdef USE_XFT
 
4996
  } else if (TextF_UseXft(tf)) {
 
4997
    XGlyphInfo  ext;
 
4998
 
 
4999
    XftTextExtentsUtf8(XtDisplay(tf), TextF_XftFont(tf),
 
5000
            (FcChar8*)str, n, &ext);
 
5001
 
 
5002
    return ext.xOff != 0;
 
5003
#endif
 
5004
  }
 
5005
  else {
 
5006
    if (use_wchar) {
 
5007
      char cache[100];
 
5008
      char *tmp, *cache_ptr; 
 
5009
      wchar_t *tmp_str;
 
5010
      int ret_val, buf_size, count;
 
5011
      Boolean is_printable;
 
5012
      buf_size = (n * MB_CUR_MAX) + 1;
 
5013
      cache_ptr = tmp = XmStackAlloc(buf_size, cache);
 
5014
   
 
5015
      tmp_str = (wchar_t *)str;
 
5016
      // Fixed MZ BZ#1257: by Brad Despres <brad@sd.aonix.com>
 
5017
      count = 0;
 
5018
      do {
 
5019
        ret_val = wctomb(tmp, *tmp_str);
 
5020
        count += 1;
 
5021
        tmp += ret_val;
 
5022
        buf_size -= ret_val;
 
5023
        tmp_str++;
 
5024
      } while ( (ret_val > 0)&& (buf_size >= MB_CUR_MAX) && (count < n) ) ;
 
5025
      if (ret_val == -1)    /* bad character */
 
5026
        return (False);
 
5027
      is_printable = XTextWidth(TextF_Font(tf), cache_ptr, tmp - cache_ptr);
 
5028
      XmStackFree(cache_ptr, cache);
 
5029
      return (is_printable);
 
5030
    }
 
5031
    else {
 
5032
      return (XTextWidth(TextF_Font(tf), str, n) != 0);
 
5033
    }
 
5034
  }
 
5035
#endif /* SUPPORT_ZERO_WIDTH */ 
 
5036
}
 
5037
 
 
5038
/****************************************************************
 
5039
 *
 
5040
 * Input functions defined in the action table.
 
5041
 *
 
5042
 ****************************************************************/
 
5043
 
 
5044
/* ARGSUSED */
 
5045
static void 
 
5046
#ifdef _NO_PROTO
 
5047
df_InsertChar( w, event, params, num_params )
 
5048
        Widget w ;
 
5049
        XEvent *event ;
 
5050
        char **params ;
 
5051
        Cardinal *num_params ;
 
5052
#else
 
5053
df_InsertChar(
 
5054
        Widget w,
 
5055
        XEvent *event,
 
5056
        char **params,
 
5057
        Cardinal *num_params )
 
5058
#endif /* _NO_PROTO */
 
5059
{
 
5060
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
5061
  char insert_string[TEXT_MAX_INSERT_SIZE];
 
5062
  XmTextPosition cursorPos, nextPos;
 
5063
  wchar_t * wc_insert_string;
 
5064
  int insert_length, i;
 
5065
  int num_chars;
 
5066
  Boolean replace_res;
 
5067
  Boolean pending_delete = False;
 
5068
  Status status_return;
 
5069
  XmAnyCallbackStruct cb;
 
5070
 
 
5071
  /* Determine what was pressed.
 
5072
  */
 
5073
  insert_length = XmImMbLookupString(w, (XKeyEvent *) event, insert_string, 
 
5074
                                     TEXT_MAX_INSERT_SIZE, (KeySym *) NULL, 
 
5075
                                     &status_return);
 
5076
 
 
5077
  if (insert_length > 0 && !XmTextF_editable(tf)) {
 
5078
     if (XmTextF_verify_bell(tf)) XBell(XtDisplay((Widget)tf), 0);
 
5079
     return;
 
5080
  }
 
5081
 
 
5082
 /* If there is more data than we can handle, bail out */
 
5083
  if (status_return == XBufferOverflow || insert_length > TEXT_MAX_INSERT_SIZE)
 
5084
  {
 
5085
     return;
 
5086
  }
 
5087
 
 
5088
 /* *LookupString in some cases can return the NULL as a character, such
 
5089
  * as when the user types <Ctrl><back_quote> or <Ctrl><@>.  Text widget
 
5090
  * can't handle the NULL as a character, so we dump it here.
 
5091
  */
 
5092
 
 
5093
  for (i=0; i < insert_length; i++)
 
5094
     if (insert_string[i] == 0) insert_length = 0; /* toss out input string */
 
5095
     
 
5096
  if (insert_length > 0) {
 
5097
    /* do not insert non-printing characters */
 
5098
    if (!PrintableString(tf, insert_string, insert_length, False))
 
5099
      return;
 
5100
 
 
5101
    _XmDataFieldDrawInsertionPoint(tf, False);
 
5102
    if (df_NeedsPendingDeleteDisjoint(tf)){
 
5103
       if (!XmDataFieldGetSelectionPosition(w, &cursorPos, &nextPos) ||
 
5104
            cursorPos == nextPos) {
 
5105
          XmTextF_prim_anchor(tf) = XmTextF_cursor_position(tf);
 
5106
       }
 
5107
       pending_delete = True;
 
5108
 
 
5109
       XmTextF_prim_anchor(tf) = XmTextF_cursor_position(tf);
 
5110
 
 
5111
    } else {
 
5112
       cursorPos = nextPos = XmTextF_cursor_position(tf);
 
5113
    }
 
5114
 
 
5115
 
 
5116
    if (XmTextF_max_char_size(tf) == 1) {
 
5117
       if (XmTextF_overstrike(tf)) nextPos += insert_length;
 
5118
       if (nextPos > XmTextF_string_length(tf)) nextPos = XmTextF_string_length(tf);
 
5119
       replace_res = _XmDataFieldReplaceText(tf, (XEvent *) event, cursorPos,
 
5120
                                             nextPos, insert_string,
 
5121
                                             insert_length, True);
 
5122
    } else {
 
5123
       char stack_cache[100];
 
5124
       insert_string[insert_length] = '\0'; /* NULL terminate for mbstowcs */
 
5125
       wc_insert_string = (wchar_t*)XmStackAlloc((Cardinal)(insert_length+1) *                                               sizeof(wchar_t), stack_cache);
 
5126
       num_chars = mbstowcs( wc_insert_string, insert_string, insert_length+1);
 
5127
       if (XmTextF_overstrike(tf)) nextPos += num_chars;
 
5128
       if (nextPos > XmTextF_string_length(tf)) nextPos = XmTextF_string_length(tf);
 
5129
       replace_res = _XmDataFieldReplaceText(tf, (XEvent *) event, cursorPos,
 
5130
                                             nextPos, (char*) wc_insert_string,
 
5131
                                             num_chars, True);
 
5132
       XmStackFree((char *)wc_insert_string, stack_cache);
 
5133
    }
 
5134
 
 
5135
    if (replace_res) {
 
5136
        if (pending_delete) {
 
5137
           XmDataFieldSetSelection(w, XmTextF_cursor_position(tf),
 
5138
                               XmTextF_cursor_position(tf), event->xkey.time);
 
5139
        }
 
5140
        df_CheckDisjointSelection(w, XmTextF_cursor_position(tf),
 
5141
                               event->xkey.time);
 
5142
        _XmDataFielddf_SetCursorPosition(tf, event, XmTextF_cursor_position(tf), 
 
5143
                                      False, True);
 
5144
        cb.reason = XmCR_VALUE_CHANGED;
 
5145
        cb.event = event;
 
5146
        XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
5147
                           (XtPointer) &cb);
 
5148
    }
 
5149
    _XmDataFieldDrawInsertionPoint(tf, True);
 
5150
  }
 
5151
}
 
5152
 
 
5153
/* ARGSUSED */
 
5154
static void 
 
5155
#ifdef _NO_PROTO
 
5156
df_InsertString( w, event, params, num_params )
 
5157
        Widget w ;
 
5158
        XEvent *event ;
 
5159
        char **params ;
 
5160
        Cardinal *num_params ;
 
5161
#else
 
5162
df_InsertString(
 
5163
        Widget w,
 
5164
        XEvent *event,
 
5165
        char **params,
 
5166
        Cardinal *num_params )
 
5167
#endif /* _NO_PROTO */
 
5168
{
 
5169
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
5170
  char insert_string[TEXT_MAX_INSERT_SIZE];
 
5171
  XmTextPosition cursorPos, nextPos;
 
5172
  wchar_t * wc_insert_string;
 
5173
  int insert_length;
 
5174
  int num_chars;
 
5175
  Boolean replace_res;
 
5176
  Boolean pending_delete = False;
 
5177
  register int i;
 
5178
 
 
5179
  if (!XmTextF_editable(tf)) {
 
5180
     if (XmTextF_verify_bell(tf)) XBell(XtDisplay((Widget)tf), 0);
 
5181
  }
 
5182
 
 
5183
  for (i = 0; i < *num_params; i++)  {
 
5184
      strcpy(insert_string, params[i]);
 
5185
      insert_length = strlen(insert_string);
 
5186
     
 
5187
      if (insert_length > 0) {
 
5188
          /* do not insert non-printing characters */
 
5189
          if (XmTextF_have_fontset(tf)){
 
5190
              if (!XmbTextEscapement((XFontSet)XmTextF_font(tf), insert_string, 
 
5191
                                     insert_length)) 
 
5192
                  return;
 
5193
          } else {
 
5194
              if (!XTextWidth(XmTextF_font(tf), insert_string, insert_length)) 
 
5195
                  return;
 
5196
          }
 
5197
 
 
5198
          _XmDataFieldDrawInsertionPoint(tf, False);
 
5199
          if (df_NeedsPendingDeleteDisjoint(tf)){
 
5200
              if (!XmDataFieldGetSelectionPosition(w, &cursorPos, &nextPos) ||
 
5201
                  cursorPos == nextPos) {
 
5202
                  XmTextF_prim_anchor(tf) = XmTextF_cursor_position(tf);
 
5203
              }
 
5204
              pending_delete = True;
 
5205
              
 
5206
              XmTextF_prim_anchor(tf) = XmTextF_cursor_position(tf);
 
5207
              
 
5208
          } else {
 
5209
              cursorPos = nextPos = XmTextF_cursor_position(tf);
 
5210
          }
 
5211
 
 
5212
          
 
5213
          if (XmTextF_overstrike(tf)) {
 
5214
              if (nextPos != XmTextF_string_length(tf)) nextPos++;
 
5215
          }
 
5216
          if (XmTextF_max_char_size(tf) == 1) {
 
5217
              replace_res =
 
5218
                  _XmDataFieldReplaceText(tf, (XEvent *) event, cursorPos,
 
5219
                                          nextPos, insert_string,insert_length,
 
5220
                                          True);
 
5221
          } else {
 
5222
              insert_string[insert_length] = '\0'; /* NULL terminate for mbstowcs */
 
5223
              wc_insert_string = (wchar_t*)XtMalloc((unsigned)(insert_length+1) *                                                    sizeof(wchar_t));
 
5224
              num_chars = mbstowcs( wc_insert_string, insert_string, insert_length+1);
 
5225
              replace_res = _XmDataFieldReplaceText(tf, (XEvent *) event, cursorPos,
 
5226
                                                    nextPos, (char*) wc_insert_string,
 
5227
                                                    num_chars, True);
 
5228
              XtFree((char *)wc_insert_string);
 
5229
          }
 
5230
 
 
5231
          if (replace_res) {
 
5232
              if (pending_delete) {
 
5233
                  XmDataFieldSetSelection(w, XmTextF_cursor_position(tf),
 
5234
                                          XmTextF_cursor_position(tf), event->xkey.time);
 
5235
              }
 
5236
              df_CheckDisjointSelection(w, XmTextF_cursor_position(tf),
 
5237
                                     event->xkey.time);
 
5238
              _XmDataFielddf_SetCursorPosition(tf, event, 
 
5239
                                            XmTextF_cursor_position(tf), False, True);
 
5240
          }
 
5241
          _XmDataFieldDrawInsertionPoint(tf, True);
 
5242
      }
 
5243
  }
 
5244
}
 
5245
 
 
5246
/* ARGSUSED */
 
5247
static void 
 
5248
#ifdef _NO_PROTO
 
5249
df_DeletePrevChar( w, event, params, num_params )
 
5250
        Widget w ;
 
5251
        XEvent *event ;
 
5252
        char **params ;
 
5253
        Cardinal *num_params ;
 
5254
#else
 
5255
df_DeletePrevChar(
 
5256
        Widget w,
 
5257
        XEvent *event,
 
5258
        char **params,
 
5259
        Cardinal *num_params )
 
5260
#endif /* _NO_PROTO */
 
5261
{
 
5262
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
5263
  XmAnyCallbackStruct cb;
 
5264
 
 
5265
  /* if pending delete is on and there is a selection */
 
5266
  _XmDataFieldDrawInsertionPoint(tf, False);
 
5267
  if (df_NeedsPendingDelete(tf)) (void) DataFieldRemove(w, event);
 
5268
  else { 
 
5269
     if (XmTextF_has_primary(tf) &&
 
5270
         XmTextF_prim_pos_left(tf) != XmTextF_prim_pos_right(tf)) {
 
5271
        if (XmTextF_cursor_position(tf) - 1 >= 0)
 
5272
           if (_XmDataFieldReplaceText(tf, event, XmTextF_cursor_position(tf) - 1,
 
5273
                                     XmTextF_cursor_position(tf), NULL, 0, True)) {
 
5274
              df_CheckDisjointSelection(w, XmTextF_cursor_position(tf),
 
5275
                       event->xkey.time);
 
5276
              _XmDataFielddf_SetCursorPosition(tf, event,
 
5277
                                            XmTextF_cursor_position(tf),
 
5278
                                            False, True);
 
5279
              cb.reason = XmCR_VALUE_CHANGED;
 
5280
              cb.event = event;
 
5281
              XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
5282
                                 (XtPointer) &cb);
 
5283
           }
 
5284
      } else if (XmTextF_cursor_position(tf) - 1 >= 0) {
 
5285
        if (_XmDataFieldReplaceText(tf, event, XmTextF_cursor_position(tf) - 1,
 
5286
                                    XmTextF_cursor_position(tf), NULL, 0, True)) {
 
5287
            df_CheckDisjointSelection(w, XmTextF_cursor_position(tf),
 
5288
                     event->xkey.time);
 
5289
            _XmDataFielddf_SetCursorPosition(tf, event, XmTextF_cursor_position(tf), 
 
5290
                                          False, True);
 
5291
            cb.reason = XmCR_VALUE_CHANGED;
 
5292
            cb.event = event;
 
5293
            XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
5294
                               (XtPointer) &cb);
 
5295
        }
 
5296
      }  
 
5297
  }
 
5298
  _XmDataFieldDrawInsertionPoint(tf, True);
 
5299
}
 
5300
 
 
5301
/* ARGSUSED */
 
5302
static void 
 
5303
#ifdef _NO_PROTO
 
5304
df_DeleteNextChar( w, event, params, num_params )
 
5305
        Widget w ;
 
5306
        XEvent *event ;
 
5307
        char **params ;
 
5308
        Cardinal *num_params ;
 
5309
#else
 
5310
df_DeleteNextChar(
 
5311
        Widget w,
 
5312
        XEvent *event,
 
5313
        char **params,
 
5314
        Cardinal *num_params )
 
5315
#endif /* _NO_PROTO */
 
5316
{
 
5317
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
5318
  XmAnyCallbackStruct cb;
 
5319
 
 
5320
 /* if pending delete is on and there is a selection */
 
5321
  _XmDataFieldDrawInsertionPoint(tf, False);
 
5322
  if (df_NeedsPendingDelete(tf)) (void) DataFieldRemove(w, event);
 
5323
  else { 
 
5324
      if (XmTextF_has_primary(tf) &&
 
5325
           XmTextF_prim_pos_left(tf) != XmTextF_prim_pos_right(tf)) {
 
5326
          if (XmTextF_cursor_position(tf) < XmTextF_string_length(tf))
 
5327
             if (_XmDataFieldReplaceText(tf, event, XmTextF_cursor_position(tf),
 
5328
                                 XmTextF_cursor_position(tf) + 1, NULL, 0, True)) {
 
5329
                 df_CheckDisjointSelection(w, XmTextF_cursor_position(tf),
 
5330
                                        event->xkey.time);
 
5331
                 _XmDataFielddf_SetCursorPosition(tf, event, 
 
5332
                                               XmTextF_cursor_position(tf), 
 
5333
                                               False, True);
 
5334
                 cb.reason = XmCR_VALUE_CHANGED;
 
5335
                 cb.event = event;
 
5336
                 XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
5337
                                    (XtPointer) &cb);
 
5338
             }
 
5339
       } else if (XmTextF_cursor_position(tf) < XmTextF_string_length(tf))
 
5340
          if (_XmDataFieldReplaceText(tf, event, XmTextF_cursor_position(tf),
 
5341
                                      XmTextF_cursor_position(tf) + 1, 
 
5342
                                      NULL, 0, True)) 
 
5343
          {
 
5344
              df_CheckDisjointSelection(w, XmTextF_cursor_position(tf),
 
5345
                                        event->xkey.time);
 
5346
              _XmDataFielddf_SetCursorPosition(tf, event, 
 
5347
                                            XmTextF_cursor_position(tf),
 
5348
                                            False, True);
 
5349
              cb.reason = XmCR_VALUE_CHANGED;
 
5350
              cb.event = event;
 
5351
              XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
5352
                                 (XtPointer) &cb);
 
5353
          }
 
5354
  }
 
5355
  _XmDataFieldDrawInsertionPoint(tf, True);
 
5356
}
 
5357
 
 
5358
/* ARGSUSED */
 
5359
static void 
 
5360
#ifdef _NO_PROTO
 
5361
df_DeletePrevWord( w, event, params, num_params )
 
5362
        Widget w ;
 
5363
        XEvent *event ;
 
5364
        char **params ;
 
5365
        Cardinal *num_params ;
 
5366
#else
 
5367
df_DeletePrevWord(
 
5368
        Widget w,
 
5369
        XEvent *event,
 
5370
        char **params,
 
5371
        Cardinal *num_params )
 
5372
#endif /* _NO_PROTO */
 
5373
{
 
5374
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
5375
  XmTextPosition left, right;
 
5376
  XmAnyCallbackStruct cb;
 
5377
 
 
5378
 /* if pending delete is on and there is a selection */
 
5379
  _XmDataFieldDrawInsertionPoint(tf, False);
 
5380
  if (df_NeedsPendingDelete(tf)) (void) DataFieldRemove(w, event);
 
5381
  else { 
 
5382
       df_FindPrevWord(tf, &left, &right);
 
5383
       if (XmTextF_has_primary(tf) &&
 
5384
           XmTextF_prim_pos_left(tf) != XmTextF_prim_pos_right(tf)) 
 
5385
       {
 
5386
           if (_XmDataFieldReplaceText(tf, event, 
 
5387
                                       left, XmTextF_cursor_position(tf),
 
5388
                                       NULL, 0, True)) 
 
5389
           {
 
5390
               df_CheckDisjointSelection(w, XmTextF_cursor_position(tf),
 
5391
                                         event->xkey.time);
 
5392
               _XmDataFielddf_SetCursorPosition(tf, event, 
 
5393
                                                XmTextF_cursor_position(tf), 
 
5394
                                                False, True);
 
5395
               cb.reason = XmCR_VALUE_CHANGED;
 
5396
               cb.event = event;
 
5397
               XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
5398
                                  (XtPointer) &cb);
 
5399
           }    
 
5400
       } else if (XmTextF_cursor_position(tf) - 1 >= 0)
 
5401
          if (_XmDataFieldReplaceText(tf, event, left, XmTextF_cursor_position(tf),
 
5402
                                      NULL, 0, True)) {
 
5403
              df_CheckDisjointSelection(w, XmTextF_cursor_position(tf),
 
5404
                                     event->xkey.time);
 
5405
              _XmDataFielddf_SetCursorPosition(tf, event,
 
5406
                                            XmTextF_cursor_position(tf),
 
5407
                                            False, True);
 
5408
              cb.reason = XmCR_VALUE_CHANGED;
 
5409
              cb.event = event;
 
5410
              XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
5411
                                 (XtPointer) &cb);
 
5412
          }
 
5413
  }
 
5414
  _XmDataFieldDrawInsertionPoint(tf, True);
 
5415
}
 
5416
 
 
5417
/* ARGSUSED */
 
5418
static void 
 
5419
#ifdef _NO_PROTO
 
5420
df_DeleteNextWord( w, event, params, num_params )
 
5421
        Widget w ;
 
5422
        XEvent *event ;
 
5423
        char **params ;
 
5424
        Cardinal *num_params ;
 
5425
#else
 
5426
df_DeleteNextWord(
 
5427
        Widget w,
 
5428
        XEvent *event,
 
5429
        char **params,
 
5430
        Cardinal *num_params )
 
5431
#endif /* _NO_PROTO */
 
5432
{
 
5433
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
5434
  XmTextPosition left, right;
 
5435
  XmAnyCallbackStruct cb;
 
5436
 
 
5437
 /* if pending delete is on and there is a selection */
 
5438
  _XmDataFieldDrawInsertionPoint(tf, False);
 
5439
  if (df_NeedsPendingDelete(tf)) (void) DataFieldRemove(w, event);
 
5440
  else { 
 
5441
       df_FindNextWord(tf, &left, &right);
 
5442
       if (XmTextF_has_primary(tf) &&
 
5443
           XmTextF_prim_pos_left(tf) != XmTextF_prim_pos_right(tf)) {
 
5444
          if (_XmDataFieldReplaceText(tf, event, XmTextF_cursor_position(tf),
 
5445
                                      right, NULL, 0, True)){
 
5446
             df_CheckDisjointSelection(w, XmTextF_cursor_position(tf),
 
5447
                                    event->xkey.time);
 
5448
             _XmDataFielddf_SetCursorPosition(tf, event,
 
5449
                                           XmTextF_cursor_position(tf),
 
5450
                                           False, True);
 
5451
             cb.reason = XmCR_VALUE_CHANGED;
 
5452
             cb.event = event;
 
5453
             XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
5454
                                (XtPointer) &cb);
 
5455
          }
 
5456
       } else if (XmTextF_cursor_position(tf) < XmTextF_string_length(tf))
 
5457
          if (_XmDataFieldReplaceText(tf, event, XmTextF_cursor_position(tf),
 
5458
                                      right, NULL, 0, True)){
 
5459
              df_CheckDisjointSelection(w, XmTextF_cursor_position(tf),
 
5460
                                     event->xkey.time);
 
5461
              _XmDataFielddf_SetCursorPosition(tf, event, 
 
5462
                                            XmTextF_cursor_position(tf), 
 
5463
                                            False, True);
 
5464
              cb.reason = XmCR_VALUE_CHANGED;
 
5465
              cb.event = event;
 
5466
              XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
5467
                                 (XtPointer) &cb);
 
5468
          }
 
5469
  }
 
5470
  _XmDataFieldDrawInsertionPoint(tf, True);
 
5471
}
 
5472
 
 
5473
 
 
5474
/* ARGSUSED */
 
5475
static void 
 
5476
#ifdef _NO_PROTO
 
5477
df_DeleteToEndOfLine( w, event, params, num_params )
 
5478
        Widget w ;
 
5479
        XEvent *event ;
 
5480
        char **params ;
 
5481
        Cardinal *num_params ;
 
5482
#else
 
5483
df_DeleteToEndOfLine(
 
5484
        Widget w,
 
5485
        XEvent *event,
 
5486
        char **params,
 
5487
        Cardinal *num_params )
 
5488
#endif /* _NO_PROTO */
 
5489
{
 
5490
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
5491
  XmAnyCallbackStruct cb;
 
5492
    
 
5493
 /* if pending delete is on and there is a selection */
 
5494
  _XmDataFieldDrawInsertionPoint(tf, False);
 
5495
  if (df_NeedsPendingDelete(tf)) (void) DataFieldRemove(w, event);
 
5496
  else if (XmTextF_cursor_position(tf) < XmTextF_string_length(tf)) {
 
5497
     if (_XmDataFieldReplaceText(tf, event, XmTextF_cursor_position(tf),
 
5498
                                 XmTextF_string_length(tf), NULL, 0, True)) {
 
5499
         df_CheckDisjointSelection(w, XmTextF_cursor_position(tf),
 
5500
                                event->xkey.time);
 
5501
         _XmDataFielddf_SetCursorPosition(tf, event, XmTextF_cursor_position(tf),
 
5502
                                       False, True);
 
5503
         cb.reason = XmCR_VALUE_CHANGED;
 
5504
         cb.event = event;
 
5505
         XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
5506
                            (XtPointer) &cb);
 
5507
       }
 
5508
  }
 
5509
  _XmDataFieldDrawInsertionPoint(tf, True);
 
5510
}
 
5511
 
 
5512
 
 
5513
/* ARGSUSED */
 
5514
static void 
 
5515
#ifdef _NO_PROTO
 
5516
df_DeleteToStartOfLine( w, event, params, num_params )
 
5517
        Widget w ;
 
5518
        XEvent *event ;
 
5519
        char **params ;
 
5520
        Cardinal *num_params ;
 
5521
#else
 
5522
df_DeleteToStartOfLine(
 
5523
        Widget w,
 
5524
        XEvent *event,
 
5525
        char **params,
 
5526
        Cardinal *num_params )
 
5527
#endif /* _NO_PROTO */
 
5528
{
 
5529
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
5530
  XmAnyCallbackStruct cb;
 
5531
    
 
5532
 /* if pending delete is on and there is a selection */
 
5533
  _XmDataFieldDrawInsertionPoint(tf, False);
 
5534
  if (df_NeedsPendingDelete(tf)) (void) DataFieldRemove(w, event);
 
5535
  else if (XmTextF_cursor_position(tf) - 1 >= 0) {
 
5536
    if (_XmDataFieldReplaceText(tf, event, 0, 
 
5537
                                XmTextF_cursor_position(tf), NULL, 0, True)) {
 
5538
        df_CheckDisjointSelection(w, XmTextF_cursor_position(tf),
 
5539
                               event->xkey.time);
 
5540
        _XmDataFielddf_SetCursorPosition(tf, event, XmTextF_cursor_position(tf),
 
5541
                                      False, True);
 
5542
        cb.reason = XmCR_VALUE_CHANGED;
 
5543
        cb.event = event;
 
5544
        XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
5545
                           (XtPointer) &cb);
 
5546
       }
 
5547
  }
 
5548
  _XmDataFieldDrawInsertionPoint(tf, True);
 
5549
}
 
5550
 
 
5551
/* ARGSUSED */
 
5552
static void 
 
5553
#ifdef _NO_PROTO
 
5554
df_ProcessCancel( w, event, params, num_params )
 
5555
        Widget w ;
 
5556
        XEvent *event ;
 
5557
        char **params ;
 
5558
        Cardinal *num_params ;
 
5559
#else
 
5560
df_ProcessCancel(
 
5561
        Widget w,
 
5562
        XEvent *event,
 
5563
        char **params,
 
5564
        Cardinal *num_params )
 
5565
#endif /* _NO_PROTO */
 
5566
{
 
5567
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
5568
 
 
5569
    XmParentInputActionRec  p_event ;
 
5570
 
 
5571
    p_event.process_type = XmINPUT_ACTION ;
 
5572
    p_event.action = XmPARENT_CANCEL ;
 
5573
    p_event.event = event ;/* Pointer to XEvent. */
 
5574
    p_event.params = params ; /* Or use what you have if   */
 
5575
    p_event.num_params = num_params ;/* input is from translation.*/
 
5576
 
 
5577
    _XmDataFieldDrawInsertionPoint(tf, False);
 
5578
    if (XmTextF_has_secondary(tf)) {
 
5579
       XmTextF_cancel(tf) = True;
 
5580
       _XmDataFieldSetSel2(w, 0, 0, False, event->xkey.time);
 
5581
       XmTextF_has_secondary(tf) = False;
 
5582
       XtUngrabKeyboard(w, CurrentTime);
 
5583
    }
 
5584
 
 
5585
    if (XmTextF_has_primary(tf) && XmTextF_extending(tf)) {
 
5586
       XmTextF_cancel(tf) = True;
 
5587
      /* reset orig_left and orig_right */
 
5588
       XmDataFieldSetSelection(w, XmTextF_orig_left(tf),
 
5589
                               XmTextF_orig_right(tf), event->xkey.time);
 
5590
    }
 
5591
 
 
5592
    if (!XmTextF_cancel(tf))
 
5593
       (void) _XmParentProcess(XtParent(tf), (XmParentProcessData) &p_event);
 
5594
 
 
5595
    if (XmTextF_select_id(tf)) {
 
5596
       XtRemoveTimeOut(XmTextF_select_id(tf));
 
5597
       XmTextF_select_id(tf) = 0;
 
5598
    }
 
5599
    _XmDataFieldDrawInsertionPoint(tf, True);
 
5600
 
 
5601
}
 
5602
 
 
5603
/* ARGSUSED */
 
5604
static void 
 
5605
#ifdef _NO_PROTO
 
5606
df_Activate( w, event, params, num_params )
 
5607
        Widget w ;
 
5608
        XEvent *event ;
 
5609
        char **params ;
 
5610
        Cardinal *num_params ;
 
5611
#else
 
5612
df_Activate(
 
5613
        Widget w,
 
5614
        XEvent *event,
 
5615
        char **params,
 
5616
        Cardinal *num_params )
 
5617
#endif /* _NO_PROTO */
 
5618
{
 
5619
    XmAnyCallbackStruct cb;
 
5620
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
5621
    XmParentInputActionRec  p_event ;
 
5622
 
 
5623
    p_event.process_type = XmINPUT_ACTION ;
 
5624
    p_event.action = XmPARENT_ACTIVATE ;
 
5625
    p_event.event = event ;/* Pointer to XEvent. */
 
5626
    p_event.params = params ; /* Or use what you have if   */
 
5627
    p_event.num_params = num_params ;/* input is from translation.*/
 
5628
 
 
5629
    cb.reason = XmCR_ACTIVATE;
 
5630
    cb.event  = event;
 
5631
    XtCallCallbackList(w, XmTextF_activate_callback(tf), (XtPointer) &cb);
 
5632
 
 
5633
    (void) _XmParentProcess(XtParent(w), (XmParentProcessData) &p_event);
 
5634
}
 
5635
 
 
5636
static void
 
5637
#ifdef _NO_PROTO
 
5638
df_SetAnchorBalancing(tf, position)
 
5639
XmDataFieldWidget tf;
 
5640
XmTextPosition position;
 
5641
#else
 
5642
df_SetAnchorBalancing(
 
5643
        XmDataFieldWidget tf,
 
5644
        XmTextPosition position)
 
5645
#endif /* _NO_PROTO */
 
5646
{
 
5647
    XmTextPosition left, right;
 
5648
    float bal_point;
 
5649
 
 
5650
    if (!XmDataFieldGetSelectionPosition((Widget)tf, &left, &right) ||
 
5651
        left == right) {
 
5652
          XmTextF_prim_anchor(tf) = position;
 
5653
    } else {
 
5654
          bal_point = (float)(((float)(right - left) / 2.0) + (float)left);
 
5655
 
 
5656
         /* shift anchor and direction to opposite end of the selection */
 
5657
          if ((float)position < bal_point) {
 
5658
             XmTextF_prim_anchor(tf) = XmTextF_orig_right(tf);
 
5659
          } else if ((float)position > bal_point) {
 
5660
             XmTextF_prim_anchor(tf) = XmTextF_orig_left(tf);
 
5661
          }
 
5662
    }
 
5663
}
 
5664
 
 
5665
static void
 
5666
#ifdef _NO_PROTO
 
5667
df_SetNavigationAnchor(tf, position, extend)
 
5668
XmDataFieldWidget tf;
 
5669
XmTextPosition position;
 
5670
Boolean extend;
 
5671
#else
 
5672
df_SetNavigationAnchor(
 
5673
        XmDataFieldWidget tf,
 
5674
        XmTextPosition position,
 
5675
#if NeedWidePrototypes
 
5676
        int extend )
 
5677
#else
 
5678
        Boolean extend )
 
5679
#endif /* NeedWidePrototypes */
 
5680
#endif /* _NO_PROTO */
 
5681
{
 
5682
    XmTextPosition left, right;
 
5683
 
 
5684
    if (!XmTextF_add_mode(tf)) {
 
5685
       if (extend) {
 
5686
          df_SetAnchorBalancing(tf, position);
 
5687
       } else {
 
5688
         if (XmDataFieldGetSelectionPosition((Widget)tf, &left, &right) &&
 
5689
            left != right) {
 
5690
           df_SetSelection(tf, position, position, True);
 
5691
           XmTextF_prim_anchor(tf) = position;
 
5692
         }
 
5693
       }
 
5694
    } else if (extend) {
 
5695
       df_SetAnchorBalancing(tf, position);
 
5696
    }
 
5697
}
 
5698
 
 
5699
static void
 
5700
#ifdef _NO_PROTO
 
5701
df_CompleteNavigation(tf, event, position, time, extend)
 
5702
XmDataFieldWidget tf;
 
5703
XEvent *event;
 
5704
XmTextPosition position;
 
5705
Time time;
 
5706
Boolean extend;
 
5707
#else
 
5708
df_CompleteNavigation(
 
5709
        XmDataFieldWidget tf,
 
5710
        XEvent *event,
 
5711
        XmTextPosition position,
 
5712
        Time time,
 
5713
#if NeedWidePrototypes
 
5714
        int extend )
 
5715
#else
 
5716
        Boolean extend )
 
5717
#endif /* NeedWidePrototypes */
 
5718
#endif /* _NO_PROTO */
 
5719
{
 
5720
    XmTextPosition left, right;
 
5721
    Boolean     backward = False;
 
5722
 
 
5723
    if ((XmTextF_add_mode(tf) &&
 
5724
         XmDataFieldGetSelectionPosition((Widget)tf, &left, &right) &&
 
5725
         position >= left && position <= right) || extend)
 
5726
       XmTextF_pending_off(tf) = FALSE;
 
5727
    else
 
5728
       XmTextF_pending_off(tf) = TRUE;
 
5729
 
 
5730
    _XmDataFielddf_SetCursorPosition(tf, event, position, True, True);
 
5731
 
 
5732
    if (extend) {
 
5733
       if (XmTextF_prim_anchor(tf) > position) {
 
5734
          left = position;
 
5735
          right = XmTextF_prim_anchor(tf);
 
5736
          backward = True;
 
5737
       } else {
 
5738
          left = XmTextF_prim_anchor(tf);
 
5739
          right = position;
 
5740
       }
 
5741
       XmDataFieldSetSelection((Widget)tf, left, right, time);
 
5742
 
 
5743
    /*  Begin fix for CR 5994 */
 
5744
    if ( backward ) 
 
5745
      _XmDataFielddf_SetCursorPosition(tf, event, position, False, False);
 
5746
    /*  End fix for CR 5994 */
 
5747
 
 
5748
       XmTextF_orig_left(tf) = left;
 
5749
       XmTextF_orig_right(tf) = right;
 
5750
    }
 
5751
}
 
5752
 
 
5753
/* ARGSUSED */
 
5754
static void 
 
5755
#ifdef _NO_PROTO
 
5756
df_SimpleMovement( w, event, params, num_params, cursorPos, position )
 
5757
        Widget w ;
 
5758
        XEvent *event ;
 
5759
        String *params ;
 
5760
        Cardinal *num_params ;
 
5761
        XmTextPosition cursorPos ;
 
5762
        XmTextPosition position ;
 
5763
#else
 
5764
df_SimpleMovement(
 
5765
        Widget w,
 
5766
        XEvent *event,
 
5767
        String *params,
 
5768
        Cardinal *num_params,
 
5769
        XmTextPosition cursorPos,
 
5770
        XmTextPosition position )
 
5771
#endif /* _NO_PROTO */
 
5772
{
 
5773
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
5774
  Boolean extend = False;
 
5775
 
 
5776
  if (*num_params > 0 && !strcmp(*params, "extend")) extend = True;
 
5777
 
 
5778
  _XmDataFieldDrawInsertionPoint(tf, False);
 
5779
  df_SetNavigationAnchor(tf, cursorPos, extend);
 
5780
  df_CompleteNavigation(tf, event, position, event->xkey.time, extend);
 
5781
  _XmDataFieldDrawInsertionPoint(tf, True);
 
5782
}
 
5783
 
 
5784
/* ARGSUSED */
 
5785
static void 
 
5786
#ifdef _NO_PROTO
 
5787
df_BackwardChar( w, event, params, num_params )
 
5788
        Widget w ;
 
5789
        XEvent *event ;
 
5790
        char **params ;
 
5791
        Cardinal *num_params ;
 
5792
#else
 
5793
df_BackwardChar(
 
5794
        Widget w,
 
5795
        XEvent *event,
 
5796
        char **params,
 
5797
        Cardinal *num_params )
 
5798
#endif /* _NO_PROTO */
 
5799
{
 
5800
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
5801
    XmTextPosition cursorPos, position;
 
5802
 
 
5803
    cursorPos = XmTextF_cursor_position(tf);
 
5804
 
 
5805
    if (cursorPos > 0) {
 
5806
       _XmDataFieldDrawInsertionPoint(tf, False);
 
5807
       position = cursorPos - 1;
 
5808
       df_SimpleMovement((Widget) tf, event, params, num_params,
 
5809
                      cursorPos, position);
 
5810
       _XmDataFieldDrawInsertionPoint(tf, True);
 
5811
    }
 
5812
}
 
5813
 
 
5814
/* ARGSUSED */
 
5815
static void 
 
5816
#ifdef _NO_PROTO
 
5817
df_ForwardChar( w, event, params, num_params )
 
5818
        Widget w ;
 
5819
        XEvent *event ;
 
5820
        char **params ;
 
5821
        Cardinal *num_params ;
 
5822
#else
 
5823
df_ForwardChar(
 
5824
        Widget w,
 
5825
        XEvent *event,
 
5826
        char **params,
 
5827
        Cardinal *num_params )
 
5828
#endif /* _NO_PROTO */
 
5829
{
 
5830
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
5831
    XmTextPosition cursorPos, position;
 
5832
 
 
5833
    cursorPos = XmTextF_cursor_position(tf);
 
5834
 
 
5835
    if (cursorPos < XmTextF_string_length(tf)) {
 
5836
       _XmDataFieldDrawInsertionPoint(tf, False);
 
5837
       position = cursorPos + 1;
 
5838
       df_SimpleMovement((Widget) tf, event, params, num_params,
 
5839
                      cursorPos, position);
 
5840
       _XmDataFieldDrawInsertionPoint(tf, True);
 
5841
    }
 
5842
}
 
5843
 
 
5844
/* ARGSUSED */
 
5845
static void 
 
5846
#ifdef _NO_PROTO
 
5847
df_BackwardWord( w, event, params, num_params )
 
5848
        Widget w ;
 
5849
        XEvent *event ;
 
5850
        char **params ;
 
5851
        Cardinal *num_params ;
 
5852
#else
 
5853
df_BackwardWord(
 
5854
        Widget w,
 
5855
        XEvent *event,
 
5856
        char **params,
 
5857
        Cardinal *num_params )
 
5858
#endif /* _NO_PROTO */
 
5859
{
 
5860
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
5861
   XmTextPosition cursorPos, position, dummy;
 
5862
 
 
5863
   cursorPos = XmTextF_cursor_position(tf);
 
5864
 
 
5865
   if (cursorPos > 0) {
 
5866
      _XmDataFieldDrawInsertionPoint(tf, False);
 
5867
      df_FindPrevWord(tf, &position, &dummy);
 
5868
      df_SimpleMovement((Widget) tf, event, params, num_params,
 
5869
                     cursorPos, position);
 
5870
      _XmDataFieldDrawInsertionPoint(tf, True);
 
5871
   }
 
5872
}
 
5873
 
 
5874
/* ARGSUSED */
 
5875
static void 
 
5876
#ifdef _NO_PROTO
 
5877
df_ForwardWord( w, event, params, num_params )
 
5878
        Widget w ;
 
5879
        XEvent *event ;
 
5880
        char **params ;
 
5881
        Cardinal *num_params ;
 
5882
#else
 
5883
df_ForwardWord(
 
5884
        Widget w,
 
5885
        XEvent *event,
 
5886
        char **params,
 
5887
        Cardinal *num_params )
 
5888
#endif /* _NO_PROTO */
 
5889
{
 
5890
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
5891
    XmTextPosition cursorPos, position, dummy;
 
5892
    wchar_t white_space[3];
 
5893
 
 
5894
    if (XmTextF_max_char_size(tf) != 1) {
 
5895
       (void)mbtowc(&white_space[0], " ", 1);
 
5896
       (void)mbtowc(&white_space[1], "\n", 1);
 
5897
       (void)mbtowc(&white_space[2], "\t", 1);
 
5898
    }
 
5899
 
 
5900
    cursorPos = XmTextF_cursor_position(tf);
 
5901
 
 
5902
    _XmDataFieldDrawInsertionPoint(tf, False);
 
5903
    if (cursorPos < XmTextF_string_length(tf)) {
 
5904
       if (XmTextF_max_char_size(tf) == 1) {
 
5905
         if (isspace((int)(unsigned char)XmTextF_value(tf)[cursorPos]))
 
5906
            df_FindWord(tf, cursorPos, &dummy, &position);
 
5907
         else
 
5908
            df_FindNextWord(tf, &dummy, &position);
 
5909
          if(isspace((int)(unsigned char)XmTextF_value(tf)[position])){
 
5910
             for (;position < XmTextF_string_length(tf); position++){
 
5911
                if (!isspace((int)(unsigned char)XmTextF_value(tf)[position]))
 
5912
                break;
 
5913
             }
 
5914
          }
 
5915
       } else {
 
5916
          if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[cursorPos],
 
5917
                                   white_space, 3))
 
5918
             df_FindWord(tf, cursorPos, &dummy, &position);
 
5919
          else
 
5920
             df_FindNextWord(tf, &dummy, &position);
 
5921
          if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[position],
 
5922
                                   white_space, 3)){
 
5923
             for (; position < XmTextF_string_length(tf); position++) {
 
5924
                if (!_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[position], 
 
5925
                                          white_space, 3))
 
5926
                   break;
 
5927
             }
 
5928
          }
 
5929
       }
 
5930
       df_SimpleMovement((Widget) tf, event, params, num_params,
 
5931
                      cursorPos, position);
 
5932
    }
 
5933
    _XmDataFieldDrawInsertionPoint(tf, True);
 
5934
}
 
5935
 
 
5936
 
 
5937
/* ARGSUSED */
 
5938
static void 
 
5939
#ifdef _NO_PROTO
 
5940
df_EndOfLine( w, event, params, num_params )
 
5941
        Widget w ;
 
5942
        XEvent *event ;
 
5943
        char **params ;
 
5944
        Cardinal *num_params ;
 
5945
#else
 
5946
df_EndOfLine(
 
5947
        Widget w,
 
5948
        XEvent *event,
 
5949
        char **params,
 
5950
        Cardinal *num_params )
 
5951
#endif /* _NO_PROTO */
 
5952
{
 
5953
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
5954
   XmTextPosition cursorPos, position;
 
5955
 
 
5956
   cursorPos = XmTextF_cursor_position(tf);
 
5957
 
 
5958
   if (cursorPos < XmTextF_string_length(tf)) {
 
5959
      _XmDataFieldDrawInsertionPoint(tf, False);
 
5960
      position = XmTextF_string_length(tf);
 
5961
      df_SimpleMovement((Widget) tf, event, params, num_params,
 
5962
                     cursorPos, position);
 
5963
      _XmDataFieldDrawInsertionPoint(tf, True);
 
5964
   }
 
5965
}
 
5966
 
 
5967
 
 
5968
/* ARGSUSED */
 
5969
static void 
 
5970
#ifdef _NO_PROTO
 
5971
df_BeginningOfLine( w, event, params, num_params )
 
5972
        Widget w ;
 
5973
        XEvent *event ;
 
5974
        char **params ;
 
5975
        Cardinal *num_params ;
 
5976
#else
 
5977
df_BeginningOfLine(
 
5978
        Widget w,
 
5979
        XEvent *event,
 
5980
        char **params,
 
5981
        Cardinal *num_params )
 
5982
#endif /* _NO_PROTO */
 
5983
{
 
5984
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
5985
   XmTextPosition cursorPos, position;
 
5986
 
 
5987
   cursorPos = XmTextF_cursor_position(tf);
 
5988
 
 
5989
   if (cursorPos > 0) {
 
5990
      position = 0;
 
5991
      _XmDataFieldDrawInsertionPoint(tf, False);
 
5992
      df_SimpleMovement((Widget) tf, event, params, num_params,
 
5993
                     cursorPos, position);
 
5994
      _XmDataFieldDrawInsertionPoint(tf, True);
 
5995
   }
 
5996
}
 
5997
 
 
5998
static void 
 
5999
#ifdef _NO_PROTO
 
6000
df_SetSelection( tf, left, right, redisplay )
 
6001
        XmDataFieldWidget tf ;
 
6002
        XmTextPosition left ;
 
6003
        XmTextPosition right ;
 
6004
        Boolean redisplay ;
 
6005
#else
 
6006
df_SetSelection(
 
6007
        XmDataFieldWidget tf,
 
6008
        XmTextPosition left,
 
6009
        XmTextPosition right,
 
6010
#if NeedWidePrototypes
 
6011
        int redisplay )
 
6012
#else
 
6013
        Boolean redisplay )
 
6014
#endif /* NeedWidePrototypes */
 
6015
#endif /* _NO_PROTO */
 
6016
{
 
6017
   XmTextPosition display_left, display_right;
 
6018
   XmTextPosition old_prim_left, old_prim_right;
 
6019
 
 
6020
   if (left < 0) left = 0;
 
6021
   if (right < 0) right = 0;
 
6022
 
 
6023
   if (left > XmTextF_string_length(tf))
 
6024
      left = XmTextF_string_length(tf);
 
6025
   if (right > XmTextF_string_length(tf))
 
6026
      right = XmTextF_string_length(tf);
 
6027
 
 
6028
   if (left == right && XmTextF_prim_pos_left(tf) != XmTextF_prim_pos_right(tf))
 
6029
      XmDataFieldSetAddMode((Widget)tf, False);
 
6030
   if (left == XmTextF_prim_pos_left(tf) && right == XmTextF_prim_pos_right(tf))
 
6031
      return;
 
6032
 
 
6033
   DataFieldSetHighlight(tf, XmTextF_prim_pos_left(tf),
 
6034
                         XmTextF_prim_pos_right(tf), XmHIGHLIGHT_NORMAL);
 
6035
 
 
6036
   old_prim_left = XmTextF_prim_pos_left(tf);
 
6037
   old_prim_right = XmTextF_prim_pos_right(tf);
 
6038
 
 
6039
   if (left > right) {
 
6040
      XmTextF_prim_pos_left(tf) = right;
 
6041
      XmTextF_prim_pos_right(tf) = left;
 
6042
   } else {
 
6043
      XmTextF_prim_pos_left(tf) = left;
 
6044
      XmTextF_prim_pos_right(tf) = right;
 
6045
   }
 
6046
 
 
6047
   DataFieldSetHighlight(tf, XmTextF_prim_pos_left(tf),
 
6048
                            XmTextF_prim_pos_right(tf), XmHIGHLIGHT_SELECTED);
 
6049
 
 
6050
   if (redisplay) {
 
6051
      if (old_prim_left > XmTextF_prim_pos_left(tf)) {
 
6052
         display_left = XmTextF_prim_pos_left(tf);
 
6053
      } else if (old_prim_left < XmTextF_prim_pos_left(tf)) {
 
6054
         display_left = old_prim_left;
 
6055
      } else
 
6056
         display_left = (old_prim_right > XmTextF_prim_pos_right(tf)) ?
 
6057
                        XmTextF_prim_pos_right(tf) : old_prim_right;
 
6058
 
 
6059
      if (old_prim_right < XmTextF_prim_pos_right(tf)) {
 
6060
         display_right = XmTextF_prim_pos_right(tf);
 
6061
      } else if (old_prim_right > XmTextF_prim_pos_right(tf)) {
 
6062
         display_right = old_prim_right;
 
6063
      } else
 
6064
         display_right = (old_prim_left < XmTextF_prim_pos_left(tf)) ?
 
6065
                         XmTextF_prim_pos_left(tf) : old_prim_left;
 
6066
 
 
6067
      df_RedisplayText(tf, display_left, display_right);
 
6068
   }
 
6069
   XmTextF_refresh_ibeam_off(tf) = True;
 
6070
}
 
6071
 
 
6072
 
 
6073
/*
 
6074
 * Begin the selection by gaining ownership of the selection
 
6075
 * and setting the selection parameters.
 
6076
 */
 
6077
void 
 
6078
#ifdef _NO_PROTO
 
6079
_XmDataFieldStartSelection( tf, left, right, sel_time )
 
6080
        XmDataFieldWidget tf ;
 
6081
        XmTextPosition left ;
 
6082
        XmTextPosition right ;
 
6083
        Time sel_time ;
 
6084
#else
 
6085
_XmDataFieldStartSelection(
 
6086
        XmDataFieldWidget tf,
 
6087
        XmTextPosition left,
 
6088
        XmTextPosition right,
 
6089
        Time sel_time )
 
6090
#endif /* _NO_PROTO */
 
6091
{
 
6092
  if (!XtIsRealized((Widget)tf)) return;
 
6093
 
 
6094
  /* if we don't already own the selection */
 
6095
  if (!XmTextF_has_primary(tf)) {
 
6096
    /*
 
6097
     * Try to gain ownership. This function identifies the
 
6098
     * XtConvertSelectionProc and the XtLoseSelectionProc.
 
6099
     */
 
6100
     if (XtOwnSelection((Widget)tf, XA_PRIMARY, sel_time, _XmDataFieldConvert, 
 
6101
                      _XmDataFieldLoseSelection, (XtSelectionDoneProc) NULL)) {
 
6102
       XmAnyCallbackStruct cb;
 
6103
 
 
6104
       XmTextF_prim_time(tf) = sel_time;
 
6105
       _XmDataFieldDrawInsertionPoint(tf, False);
 
6106
       XmTextF_has_primary(tf) = True; 
 
6107
       XmTextF_prim_pos_left(tf) = XmTextF_prim_pos_right(tf) =
 
6108
                           XmTextF_prim_anchor(tf) = XmTextF_cursor_position(tf);
 
6109
      /*
 
6110
       * Set the selection boundries for highlighting the text,
 
6111
       * and marking the selection.
 
6112
       */
 
6113
       df_SetSelection(tf, left, right, True);
 
6114
 
 
6115
       _XmDataFieldDrawInsertionPoint(tf, True);
 
6116
 
 
6117
      /* Call the gain selection callback */
 
6118
       cb.reason = XmCR_GAIN_PRIMARY;
 
6119
       cb.event = NULL;
 
6120
       XtCallCallbackList((Widget) tf, XmTextF_gain_primary_callback(tf), 
 
6121
                          (XtPointer) &cb);
 
6122
 
 
6123
    } else 
 
6124
     /*
 
6125
      * Failed to gain ownership of the selection so make sure
 
6126
      * the text does not think it owns the selection.
 
6127
      * (this might be overkill)
 
6128
      */
 
6129
       _XmDataFieldDeselectSelection((Widget)tf, True, sel_time);
 
6130
  } else {
 
6131
       _XmDataFieldDrawInsertionPoint(tf, False);
 
6132
       XmDataFieldSetHighlight((Widget)tf, XmTextF_prim_pos_left(tf),
 
6133
                          XmTextF_prim_pos_right(tf), XmHIGHLIGHT_NORMAL);
 
6134
       XmTextF_prim_pos_left(tf) = XmTextF_prim_pos_right(tf) =
 
6135
                           XmTextF_prim_anchor(tf) = XmTextF_cursor_position(tf);
 
6136
      /*
 
6137
       * Set the new selection boundries for highlighting the text,
 
6138
       * and marking the selection.
 
6139
       */
 
6140
       df_SetSelection(tf, left, right, True);
 
6141
 
 
6142
       _XmDataFieldDrawInsertionPoint(tf, True);
 
6143
  }
 
6144
}
 
6145
 
 
6146
/* ARGSUSED */
 
6147
static void 
 
6148
#ifdef _NO_PROTO
 
6149
df_ProcessHorizontalParams( w, event, params, num_params, left, right, position )
 
6150
        Widget w ;
 
6151
        XEvent *event ;
 
6152
        char **params ;
 
6153
        Cardinal *num_params;
 
6154
        XmTextPosition *left ;
 
6155
        XmTextPosition *right ;
 
6156
        XmTextPosition *position ;
 
6157
#else
 
6158
df_ProcessHorizontalParams(
 
6159
        Widget w,
 
6160
        XEvent *event,
 
6161
        char **params,
 
6162
        Cardinal *num_params,
 
6163
        XmTextPosition *left,
 
6164
        XmTextPosition *right,
 
6165
        XmTextPosition *position )
 
6166
#endif /* _NO_PROTO */
 
6167
{
 
6168
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
6169
    XmTextPosition old_cursorPos = XmTextF_cursor_position(tf);
 
6170
 
 
6171
    *position = XmTextF_cursor_position(tf);
 
6172
 
 
6173
    if (!XmDataFieldGetSelectionPosition(w, left, right) || *left == *right) {
 
6174
        XmTextF_orig_left(tf) = XmTextF_orig_right(tf) = XmTextF_prim_anchor(tf);
 
6175
        *left = *right = old_cursorPos;
 
6176
    }
 
6177
 
 
6178
    if (*num_params > 0 && !strcmp(*params, "right")) {
 
6179
       if (*position >= XmTextF_string_length(tf)) return;
 
6180
       (*position)++;
 
6181
    } else if (*num_params > 0 && !strcmp(*params, "left")) {
 
6182
       if (*position <= 0) return;
 
6183
       (*position)--;
 
6184
    }
 
6185
}
 
6186
 
 
6187
 
 
6188
/* ARGSUSED */
 
6189
static void 
 
6190
#ifdef _NO_PROTO
 
6191
df_ProcessSelectParams( w, event, left, right, position )
 
6192
        Widget w ;
 
6193
        XEvent *event ;
 
6194
        XmTextPosition *left ;
 
6195
        XmTextPosition *right ;
 
6196
        XmTextPosition *position ;
 
6197
#else
 
6198
df_ProcessSelectParams(
 
6199
        Widget w,
 
6200
        XEvent *event,
 
6201
        XmTextPosition *left,
 
6202
        XmTextPosition *right,
 
6203
        XmTextPosition *position )
 
6204
#endif /* _NO_PROTO */
 
6205
{
 
6206
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
6207
 
 
6208
   *position = XmTextF_cursor_position(tf);
 
6209
 
 
6210
   if (!XmDataFieldGetSelectionPosition(w, left, right) || *left == *right) {
 
6211
      if (*position > XmTextF_prim_anchor(tf)) {
 
6212
        *left = XmTextF_prim_anchor(tf);
 
6213
        *right = *position;
 
6214
      } else {
 
6215
        *left = *position;
 
6216
        *right = XmTextF_prim_anchor(tf);
 
6217
      }
 
6218
   }
 
6219
}
 
6220
 
 
6221
 
 
6222
/* ARGSUSED */
 
6223
static void 
 
6224
#ifdef _NO_PROTO
 
6225
df_KeySelection( w, event, params, num_params )
 
6226
        Widget w ;
 
6227
        XEvent *event ;
 
6228
        char **params ;
 
6229
        Cardinal *num_params ;
 
6230
#else
 
6231
df_KeySelection(
 
6232
        Widget w,
 
6233
        XEvent *event,
 
6234
        char **params,
 
6235
        Cardinal *num_params )
 
6236
#endif /* _NO_PROTO */
 
6237
{
 
6238
  XmTextPosition position = 0, left, right;
 
6239
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
6240
  XmTextPosition cursorPos;
 
6241
 
 
6242
  _XmDataFieldDrawInsertionPoint(tf,False); /* Turn off I beam blink
 
6243
                                               during selection */
 
6244
 
 
6245
  XmTextF_orig_left(tf) = XmTextF_prim_pos_left(tf);
 
6246
  XmTextF_orig_right(tf) = XmTextF_prim_pos_right(tf);
 
6247
 
 
6248
  cursorPos = XmTextF_cursor_position(tf);
 
6249
  if (*num_params > 0 && (!strcmp(*params,"right") || !strcmp(*params, "left")))
 
6250
     df_SetAnchorBalancing(tf, cursorPos);
 
6251
 
 
6252
  XmTextF_extending(tf) = True;
 
6253
 
 
6254
  if (*num_params == 0) {
 
6255
     position = cursorPos;
 
6256
     df_ProcessSelectParams(w, event, &left, &right, &position);
 
6257
  } else if (*num_params > 0 && (!strcmp(*params, "right") ||
 
6258
                                 !strcmp(*params, "left"))) {
 
6259
     df_ProcessHorizontalParams(w, event, params, num_params, &left,
 
6260
                             &right, &position);
 
6261
  }
 
6262
 
 
6263
  cursorPos = position;
 
6264
 
 
6265
  if (position < 0 || position > XmTextF_string_length(tf)) {
 
6266
     _XmDataFieldDrawInsertionPoint(tf,True); /* Turn on I beam now
 
6267
                                                 that we are done */
 
6268
     return;
 
6269
  }
 
6270
 
 
6271
 /* shift anchor and direction to opposite end of the selection */
 
6272
  if (position > XmTextF_prim_anchor(tf)) {
 
6273
     right = cursorPos = position;
 
6274
     left = XmTextF_prim_anchor(tf);
 
6275
  } else {
 
6276
     left = cursorPos = position;
 
6277
     right = XmTextF_prim_anchor(tf);
 
6278
  }
 
6279
 
 
6280
  if (left > right) {
 
6281
     XmTextPosition tempIndex = left;
 
6282
     left = right;
 
6283
     right = tempIndex;
 
6284
  }
 
6285
 
 
6286
  if (XmTextF_has_primary(tf))
 
6287
     df_SetSelection(tf, left, right, True);
 
6288
  else
 
6289
     _XmDataFieldStartSelection(tf, left, right, event->xbutton.time);
 
6290
 
 
6291
  XmTextF_pending_off(tf) = False;
 
6292
 
 
6293
  _XmDataFielddf_SetCursorPosition(tf, event, cursorPos, True, True);
 
6294
  (void) df_SetDestination(w, cursorPos, False, event->xkey.time);
 
6295
 
 
6296
  XmTextF_orig_left(tf) = XmTextF_prim_pos_left(tf);
 
6297
  XmTextF_orig_right(tf) = XmTextF_prim_pos_right(tf);
 
6298
 
 
6299
  _XmDataFieldDrawInsertionPoint(tf,True); /* Turn on I beam now
 
6300
                                              that we are done */
 
6301
 
 
6302
}
 
6303
 
 
6304
/* ARGSUSED */
 
6305
static void 
 
6306
#ifdef _NO_PROTO
 
6307
df_TextFocusIn( w, event, params, num_params )
 
6308
        Widget w ;
 
6309
        XEvent *event ;
 
6310
        char **params ;
 
6311
        Cardinal *num_params ;
 
6312
#else
 
6313
df_TextFocusIn(
 
6314
        Widget w,
 
6315
        XEvent *event,
 
6316
        char **params,
 
6317
        Cardinal *num_params )
 
6318
#endif /* _NO_PROTO */
 
6319
{
 
6320
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
6321
   XmAnyCallbackStruct cb;
 
6322
   XPoint xmim_point;
 
6323
   XtWidgetProc bhl;
 
6324
   
 
6325
   if (event->xfocus.send_event && !(XmTextF_has_focus(tf))) {
 
6326
      if (!XmTextF_has_rect(tf)) _XmDataFieldSetClipRect(tf);
 
6327
      XmTextF_has_focus(tf) = True;
 
6328
      if (XtIsSensitive(w)) _XmDataFToggleCursorGC(w);
 
6329
      _XmDataFieldDrawInsertionPoint(tf, False);
 
6330
      XmTextF_blink_on(tf) = False;
 
6331
 
 
6332
      XmTextF_refresh_ibeam_off(tf) = True;
 
6333
 
 
6334
      if (_XmGetFocusPolicy(w) == XmEXPLICIT)
 
6335
      {
 
6336
         _XmProcessLock(); 
 
6337
         bhl = ((XmDataFieldWidgetClass)XtClass(w))->primitive_class.border_highlight;
 
6338
         _XmProcessUnlock();
 
6339
 
 
6340
         if (bhl)
 
6341
         {   
 
6342
            (*bhl)(w);
 
6343
         } 
 
6344
 
 
6345
         if (!XmTextF_has_destination(tf))
 
6346
         {
 
6347
            (void) df_SetDestination(w, XmTextF_cursor_position(tf), False, XtLastTimestampProcessed(XtDisplay(w)));
 
6348
         }
 
6349
      }
 
6350
 
 
6351
      if (tf->core.sensitive) df_ChangeBlinkBehavior(tf, True);
 
6352
      _XmDataFieldDrawInsertionPoint(tf, True);
 
6353
      (void) df_GetXYFromPos(tf, XmTextF_cursor_position(tf),
 
6354
                          &xmim_point.x, &xmim_point.y);
 
6355
      XmImVaSetFocusValues(w, XmNspotLocation, &xmim_point, NULL);
 
6356
 
 
6357
      cb.reason = XmCR_FOCUS;
 
6358
      cb.event = event;
 
6359
      XtCallCallbackList (w, XmTextF_focus_callback(tf), (XtPointer) &cb);
 
6360
   }
 
6361
 
 
6362
   _XmPrimitiveFocusIn(w, event, params, num_params);
 
6363
}
 
6364
 
 
6365
 
 
6366
/* ARGSUSED */
 
6367
static void 
 
6368
#ifdef _NO_PROTO
 
6369
df_TextFocusOut( w, event, params, num_params )
 
6370
        Widget w ;
 
6371
        XEvent *event ;
 
6372
        char **params ;
 
6373
        Cardinal *num_params ;
 
6374
#else
 
6375
df_TextFocusOut(
 
6376
        Widget w,
 
6377
        XEvent *event,
 
6378
        char **params,
 
6379
        Cardinal *num_params )
 
6380
#endif /* _NO_PROTO */
 
6381
{
 
6382
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
6383
   XtWidgetProc buhl;
 
6384
   
 
6385
   if (event->xfocus.send_event && XmTextF_has_focus(tf)) {
 
6386
      XmTextF_has_focus(tf) = False;
 
6387
      df_ChangeBlinkBehavior(tf, False);
 
6388
      _XmDataFieldDrawInsertionPoint(tf, False);
 
6389
      _XmDataFToggleCursorGC(w);
 
6390
      XmTextF_blink_on(tf) = True;
 
6391
      _XmDataFieldDrawInsertionPoint(tf, True);
 
6392
 
 
6393
      _XmProcessLock();
 
6394
      buhl = ((XmDataFieldWidgetClass) XtClass(tf))->primitive_class.border_unhighlight;
 
6395
      _XmProcessUnlock();
 
6396
 
 
6397
      if(buhl)
 
6398
      {
 
6399
          (*buhl)( (Widget) tf) ;
 
6400
      } 
 
6401
      XmImUnsetFocus(w);
 
6402
   }
 
6403
 
 
6404
   /* If traversal is on, then the leave verification callback is called in
 
6405
      the traversal event handler */
 
6406
   if (event->xfocus.send_event && !XmTextF_traversed(tf) &&
 
6407
       _XmGetFocusPolicy(w) == XmEXPLICIT) {
 
6408
        if (!df_VerifyLeave(tf, event)) {
 
6409
           if (XmTextF_verify_bell(tf)) XBell(XtDisplay(w), 0);
 
6410
           return;
 
6411
        }
 
6412
   } else
 
6413
        if (XmTextF_traversed(tf)) {
 
6414
           XmTextF_traversed(tf) = False;
 
6415
        }
 
6416
}
 
6417
 
 
6418
static void 
 
6419
#ifdef _NO_PROTO
 
6420
df_SetScanIndex( tf, event )
 
6421
        XmDataFieldWidget tf ;
 
6422
        XEvent *event ;
 
6423
#else
 
6424
df_SetScanIndex(
 
6425
        XmDataFieldWidget tf,
 
6426
        XEvent *event )
 
6427
#endif /* _NO_PROTO */
 
6428
{
 
6429
   Time sel_time;
 
6430
 
 
6431
   if (event->type == ButtonPress) sel_time = event->xbutton.time;
 
6432
   else sel_time = event->xkey.time;
 
6433
        
 
6434
        
 
6435
   if (sel_time > XmTextF_last_time(tf) &&
 
6436
        sel_time - XmTextF_last_time(tf) < XtGetMultiClickTime(XtDisplay(tf))) {
 
6437
/*
 
6438
 * Fix for HaL DTS 9841 - Increment the sarray_index first, then check to 
 
6439
 *                        see if it is greater that the count.  Otherwise,
 
6440
 *                        an error will occur.
 
6441
 */
 
6442
       XmTextF_sarray_index(tf)++;
 
6443
       if (XmTextF_sarray_index(tf) >= XmTextF_selection_array_count(tf)) {
 
6444
          XmTextF_sarray_index(tf) = 0;
 
6445
       }
 
6446
/*
 
6447
 * End fix for HaL DTS 9841
 
6448
 */
 
6449
    } else
 
6450
       XmTextF_sarray_index(tf) = 0;
 
6451
 
 
6452
    XmTextF_last_time(tf) = sel_time;
 
6453
}
 
6454
    
 
6455
static void 
 
6456
#ifdef _NO_PROTO
 
6457
df_ExtendScanSelection( tf, event )
 
6458
        XmDataFieldWidget tf ;
 
6459
        XEvent *event ;
 
6460
#else
 
6461
df_ExtendScanSelection(
 
6462
        XmDataFieldWidget tf,
 
6463
        XEvent *event )
 
6464
#endif /* _NO_PROTO */
 
6465
{
 
6466
   XmTextPosition pivot_left, pivot_right;
 
6467
   XmTextPosition left, right;
 
6468
   XmTextPosition new_position = df_GetPosFromX(tf, (Position) event->xbutton.x);
 
6469
   XmTextPosition cursorPos = XmTextF_cursor_position(tf);
 
6470
   Boolean pivot_modify = False;
 
6471
   float bal_point;
 
6472
 
 
6473
   if (!XmDataFieldGetSelectionPosition((Widget)tf, &left, &right) ||
 
6474
       left == right) {
 
6475
       XmTextF_orig_left(tf) = XmTextF_orig_right(tf) =
 
6476
           XmTextF_prim_anchor(tf) = XmTextF_cursor_position(tf);
 
6477
       bal_point = (float)XmTextF_orig_left(tf);
 
6478
   } else
 
6479
        bal_point = (float)(((float)(right - left) / 2.0) + (float)left);
 
6480
 
 
6481
   if (!XmTextF_extending(tf))
 
6482
   {
 
6483
      if ((float)new_position < bal_point) {
 
6484
         XmTextF_prim_anchor(tf) = XmTextF_orig_right(tf);
 
6485
      } else if ((float)new_position > bal_point) {
 
6486
         XmTextF_prim_anchor(tf) = XmTextF_orig_left(tf);
 
6487
      }
 
6488
  }
 
6489
 
 
6490
   XmTextF_extending(tf) = True;
 
6491
 
 
6492
   switch (XmTextF_selection_array(tf)[XmTextF_sarray_index(tf)]) {
 
6493
       case XmSELECT_POSITION:
 
6494
           if (XmTextF_has_primary(tf))
 
6495
              df_SetSelection(tf, XmTextF_prim_anchor(tf), new_position, True);
 
6496
           else if (new_position != XmTextF_prim_anchor(tf))
 
6497
              _XmDataFieldStartSelection(tf, XmTextF_prim_anchor(tf),
 
6498
                             new_position, event->xbutton.time);
 
6499
           XmTextF_pending_off(tf) = False;
 
6500
           cursorPos = new_position;
 
6501
           break;
 
6502
       case XmSELECT_WHITESPACE:
 
6503
       case XmSELECT_WORD:
 
6504
           df_FindWord(tf, new_position, &left, &right);
 
6505
           df_FindWord(tf, XmTextF_prim_anchor(tf),
 
6506
                    &pivot_left, &pivot_right);
 
6507
           XmTextF_pending_off(tf) = False;
 
6508
           if (left != pivot_left || right != pivot_right) {
 
6509
              if (left > pivot_left)
 
6510
                 left = pivot_left;
 
6511
              if (right < pivot_right)
 
6512
                 right = pivot_right;
 
6513
              pivot_modify = True;
 
6514
           }
 
6515
           if (XmTextF_has_primary(tf))
 
6516
              df_SetSelection(tf, left, right, True);
 
6517
           else
 
6518
              _XmDataFieldStartSelection(tf, left, right, event->xbutton.time);
 
6519
 
 
6520
           if (pivot_modify) {
 
6521
              if ((((right - left) / 2) + left) <= new_position) {
 
6522
                 cursorPos = right;
 
6523
              } else
 
6524
                 cursorPos = left;
 
6525
           } else {
 
6526
              if (left >= XmTextF_cursor_position(tf))
 
6527
                 cursorPos = left;
 
6528
              else
 
6529
                 cursorPos = right;
 
6530
           }
 
6531
           break;
 
6532
       default:
 
6533
           break;
 
6534
   }
 
6535
   if (cursorPos != XmTextF_cursor_position(tf)) {
 
6536
      (void) df_SetDestination((Widget)tf, cursorPos, False, event->xkey.time);
 
6537
      _XmDataFielddf_SetCursorPosition(tf, event, cursorPos, True, True);
 
6538
   }
 
6539
}
 
6540
 
 
6541
static void 
 
6542
#ifdef _NO_PROTO
 
6543
df_SetScanSelection( tf, event )
 
6544
        XmDataFieldWidget tf ;
 
6545
        XEvent *event ;
 
6546
#else
 
6547
df_SetScanSelection(
 
6548
        XmDataFieldWidget tf,
 
6549
        XEvent *event )
 
6550
#endif /* _NO_PROTO */
 
6551
{
 
6552
   XmTextPosition left, right;
 
6553
   XmTextPosition new_position = 0;
 
6554
   XmTextPosition cursorPos = XmTextF_cursor_position(tf);
 
6555
   Position dummy = 0;
 
6556
   Boolean update_position = False;
 
6557
  
 
6558
   df_SetScanIndex(tf, event);
 
6559
 
 
6560
   if (event->type == ButtonPress)
 
6561
       new_position = df_GetPosFromX(tf, (Position) event->xbutton.x);
 
6562
   else
 
6563
       new_position = XmTextF_cursor_position(tf);
 
6564
 
 
6565
   _XmDataFieldDrawInsertionPoint(tf,False); /* Turn off I beam
 
6566
                                                blink during selection */
 
6567
 
 
6568
   switch (XmTextF_selection_array(tf)[XmTextF_sarray_index(tf)]) {
 
6569
       case XmSELECT_POSITION:
 
6570
           XmTextF_prim_anchor(tf) = new_position;
 
6571
           if (XmTextF_has_primary(tf)) {
 
6572
              df_SetSelection(tf, new_position, new_position, True);
 
6573
              XmTextF_pending_off(tf) = False;
 
6574
           }
 
6575
           cursorPos = new_position;
 
6576
           update_position = True;
 
6577
           break;
 
6578
       case XmSELECT_WHITESPACE:
 
6579
       case XmSELECT_WORD:
 
6580
           df_FindWord(tf, XmTextF_cursor_position(tf), &left, &right);
 
6581
           if (XmTextF_has_primary(tf))
 
6582
              df_SetSelection(tf, left, right, True);
 
6583
           else
 
6584
              _XmDataFieldStartSelection(tf, left, right, event->xbutton.time);
 
6585
           XmTextF_pending_off(tf) = False;
 
6586
           if ((((right - left) / 2) + left) <= new_position)
 
6587
              cursorPos = right;
 
6588
           else
 
6589
              cursorPos = left;
 
6590
           break;
 
6591
       case XmSELECT_LINE:
 
6592
       case XmSELECT_OUT_LINE:
 
6593
       case XmSELECT_PARAGRAPH:
 
6594
       case XmSELECT_ALL:
 
6595
           if (XmTextF_has_primary(tf))
 
6596
              df_SetSelection(tf, 0, XmTextF_string_length(tf), True);
 
6597
           else
 
6598
              _XmDataFieldStartSelection(tf, 0, XmTextF_string_length(tf),
 
6599
                             event->xbutton.time);
 
6600
           XmTextF_pending_off(tf) = False;
 
6601
           if (event->type == ButtonPress)
 
6602
           {
 
6603
              if ((XmTextF_string_length(tf)) / 2 <= new_position)
 
6604
                 cursorPos = XmTextF_string_length(tf);
 
6605
              else
 
6606
                 cursorPos = 0;
 
6607
          }
 
6608
           break;
 
6609
   }
 
6610
 
 
6611
   (void) df_SetDestination((Widget)tf, cursorPos, False, event->xkey.time);
 
6612
   if (cursorPos != XmTextF_cursor_position(tf) || update_position) {
 
6613
      _XmDataFielddf_SetCursorPosition(tf, event, cursorPos, True, True);
 
6614
   }
 
6615
   df_GetXYFromPos(tf, cursorPos, &(XmTextF_select_pos_x(tf)),
 
6616
                &dummy);
 
6617
   _XmDataFieldDrawInsertionPoint(tf,True);
 
6618
}
 
6619
 
 
6620
 
 
6621
/* ARGSUSED */
 
6622
static void 
 
6623
#ifdef _NO_PROTO
 
6624
df_StartPrimary( w, event, params, num_params )
 
6625
        Widget w ;
 
6626
        XEvent *event ;
 
6627
        char **params ;
 
6628
        Cardinal *num_params ;
 
6629
#else
 
6630
df_StartPrimary(
 
6631
        Widget w,
 
6632
        XEvent *event,
 
6633
        char **params,
 
6634
        Cardinal *num_params )
 
6635
#endif /* _NO_PROTO */
 
6636
{
 
6637
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
6638
 
 
6639
  if (!XmTextF_has_focus(tf) && _XmGetFocusPolicy(w) == XmEXPLICIT)
 
6640
     (void) XmProcessTraversal(w, XmTRAVERSE_CURRENT);
 
6641
 
 
6642
  _XmDataFieldDrawInsertionPoint(tf,False);
 
6643
  df_SetScanSelection(tf, event); /* use scan type to set the selection */
 
6644
  _XmDataFieldDrawInsertionPoint(tf,True);
 
6645
}
 
6646
 
 
6647
 
 
6648
/* ARGSUSED */
 
6649
static void 
 
6650
#ifdef _NO_PROTO
 
6651
df_MoveDestination( w, event, params, num_params )
 
6652
        Widget w ;
 
6653
        XEvent *event ;
 
6654
        char **params ;
 
6655
        Cardinal *num_params ;
 
6656
#else
 
6657
df_MoveDestination(
 
6658
        Widget w,
 
6659
        XEvent *event,
 
6660
        char **params,
 
6661
        Cardinal *num_params )
 
6662
#endif /* _NO_PROTO */
 
6663
{
 
6664
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
6665
  XmTextPosition left, right;
 
6666
  XmTextPosition new_position;
 
6667
  Boolean old_has_focus = XmTextF_has_focus(tf);
 
6668
  Boolean reset_cursor = False;
 
6669
 
 
6670
  new_position = df_GetPosFromX(tf, (Position) event->xbutton.x);
 
6671
 
 
6672
  _XmDataFieldDrawInsertionPoint(tf, False);
 
6673
  if (XmDataFieldGetSelectionPosition(w, &left, &right) && (right != left))
 
6674
     (void) df_SetDestination(w, new_position, False, event->xbutton.time);
 
6675
 
 
6676
  XmTextF_pending_off(tf) = False;
 
6677
 
 
6678
  if (!XmTextF_has_focus(tf) && _XmGetFocusPolicy(w) == XmEXPLICIT)
 
6679
     (void) XmProcessTraversal(w, XmTRAVERSE_CURRENT);
 
6680
 
 
6681
  /* Doing the the df_MoveDestination caused a traversal into my, causing
 
6682
   * me to gain focus... Cursor is now on when it shouldn't be. */
 
6683
  if ((reset_cursor = !old_has_focus && XmTextF_has_focus(tf)) != False)
 
6684
     _XmDataFieldDrawInsertionPoint(tf, False);
 
6685
 
 
6686
  _XmDataFielddf_SetCursorPosition(tf, event, new_position,
 
6687
                                True, True);
 
6688
  if (new_position < left && new_position > right)
 
6689
     XmTextF_pending_off(tf) = True;
 
6690
 
 
6691
  /*
 
6692
   * if cursor was turned off as a result of the focus state changing
 
6693
   * then we need to undo the decrement to the cursor_on variable
 
6694
   * by redrawing the insertion point.
 
6695
   */
 
6696
  if (reset_cursor)
 
6697
     _XmDataFieldDrawInsertionPoint(tf, True);
 
6698
  _XmDataFieldDrawInsertionPoint(tf, True);
 
6699
}
 
6700
 
 
6701
/* ARGSUSED */
 
6702
static void 
 
6703
#ifdef _NO_PROTO
 
6704
df_ExtendPrimary( w, event, params, num_params )
 
6705
        Widget w ;
 
6706
        XEvent *event ;
 
6707
        char **params ;
 
6708
        Cardinal *num_params ;
 
6709
#else
 
6710
df_ExtendPrimary(
 
6711
        Widget w,
 
6712
        XEvent *event,
 
6713
        char **params,
 
6714
        Cardinal *num_params )
 
6715
#endif /* _NO_PROTO */
 
6716
{
 
6717
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
6718
 
 
6719
  if (XmTextF_cancel(tf)) return;
 
6720
 
 
6721
  _XmDataFieldDrawInsertionPoint(tf, False);
 
6722
  XmTextF_do_drop(tf) = False;
 
6723
 
 
6724
  if (!df_CheckTimerScrolling(w, event)){
 
6725
     if (event->type == ButtonPress)
 
6726
        df_DoExtendedSelection(w, event->xbutton.time);
 
6727
     else
 
6728
        df_DoExtendedSelection(w, event->xkey.time);
 
6729
  } else
 
6730
     df_ExtendScanSelection(tf, event); /* use scan type to set the selection */
 
6731
 
 
6732
  _XmDataFieldDrawInsertionPoint(tf, True);
 
6733
}
 
6734
 
 
6735
 
 
6736
/* ARGSUSED */
 
6737
static void 
 
6738
#ifdef _NO_PROTO
 
6739
df_ExtendEnd( w, event, params, num_params )
 
6740
        Widget w ;
 
6741
        XEvent *event ;
 
6742
        char **params ;
 
6743
        Cardinal *num_params ;
 
6744
#else
 
6745
df_ExtendEnd(
 
6746
        Widget w,
 
6747
        XEvent *event,
 
6748
        char **params,
 
6749
        Cardinal *num_params )
 
6750
#endif /* _NO_PROTO */
 
6751
{
 
6752
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
6753
 
 
6754
 
 
6755
  if (XmTextF_prim_pos_left(tf) == 0 && XmTextF_prim_pos_right(tf) == 0)
 
6756
     XmTextF_orig_left(tf) = XmTextF_orig_right(tf) = XmTextF_cursor_position(tf);
 
6757
  else {
 
6758
     XmTextF_orig_left(tf) = XmTextF_prim_pos_left(tf);
 
6759
     XmTextF_orig_right(tf) = XmTextF_prim_pos_right(tf);
 
6760
     XmTextF_cancel(tf) = False;
 
6761
  }
 
6762
 
 
6763
  if (XmTextF_select_id(tf)) {
 
6764
     XtRemoveTimeOut(XmTextF_select_id(tf));
 
6765
     XmTextF_select_id(tf) = 0;
 
6766
  }
 
6767
    XmTextF_select_pos_x(tf) = 0;
 
6768
    XmTextF_extending(tf) = False;
 
6769
}
 
6770
 
 
6771
/* ARGSUSED */
 
6772
static void
 
6773
#ifdef _NO_PROTO
 
6774
df_DoExtendedSelection(w, time)
 
6775
        Widget w;
 
6776
        Time time;
 
6777
#else
 
6778
df_DoExtendedSelection(
 
6779
        Widget w,
 
6780
        Time time )
 
6781
#endif /* _NO_PROTO */
 
6782
{
 
6783
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
6784
    XmTextPosition position, left, right, cursorPos;
 
6785
    XmTextPosition pivot_left, pivot_right;
 
6786
    Boolean pivot_modify = False;
 
6787
    float bal_point;
 
6788
 
 
6789
    if (XmTextF_cancel(tf)) {
 
6790
          if (XmTextF_select_id(tf)) XtRemoveTimeOut(XmTextF_select_id(tf));
 
6791
          XmTextF_select_id(tf) = 0;
 
6792
          return;
 
6793
    }
 
6794
 
 
6795
    cursorPos = XmTextF_cursor_position(tf);
 
6796
    _XmDataFieldDrawInsertionPoint(tf, False);
 
6797
    if (!(XmDataFieldGetSelectionPosition(w, &left, &right)) || left == right) {
 
6798
        XmTextF_prim_anchor(tf) = XmTextF_cursor_position(tf);
 
6799
        left = right = XmTextF_cursor_position(tf);
 
6800
        XmTextF_orig_left(tf) = XmTextF_orig_right(tf) = XmTextF_prim_anchor(tf);
 
6801
        bal_point = (float)XmTextF_prim_anchor(tf);
 
6802
    } else
 
6803
        bal_point = (float)(((float)(XmTextF_orig_right(tf) - XmTextF_orig_left(tf))
 
6804
                                     / 2.0) + (float)XmTextF_orig_left(tf));
 
6805
 
 
6806
    position = XmDataFieldXYToPos(w, XmTextF_select_pos_x(tf), 0);
 
6807
 
 
6808
   if (!XmTextF_extending(tf))
 
6809
   {
 
6810
      if ((float)position < bal_point) {
 
6811
         XmTextF_prim_anchor(tf) = XmTextF_orig_right(tf);
 
6812
      } else if ((float)position > bal_point) {
 
6813
         XmTextF_prim_anchor(tf) = XmTextF_orig_left(tf);
 
6814
      }
 
6815
  }
 
6816
   XmTextF_extending(tf) = True;
 
6817
 
 
6818
    /* Extend selection in same way as ExtendScan would do */
 
6819
 
 
6820
   switch (XmTextF_selection_array(tf)[XmTextF_sarray_index(tf)]) {
 
6821
       case XmSELECT_POSITION:
 
6822
           if (XmTextF_has_primary(tf))
 
6823
              df_SetSelection(tf, XmTextF_prim_anchor(tf), position, True);
 
6824
           else if (position != XmTextF_prim_anchor(tf))
 
6825
              _XmDataFieldStartSelection(tf, XmTextF_prim_anchor(tf),
 
6826
                             position, time);
 
6827
           XmTextF_pending_off(tf) = False;
 
6828
           cursorPos = position;
 
6829
           break;
 
6830
       case XmSELECT_WHITESPACE:
 
6831
       case XmSELECT_WORD:
 
6832
           df_FindWord(tf, position, &left, &right);
 
6833
           df_FindWord(tf, XmTextF_prim_anchor(tf),
 
6834
                    &pivot_left, &pivot_right);
 
6835
           XmTextF_pending_off(tf) = False;
 
6836
           if (left != pivot_left || right != pivot_right) {
 
6837
              if (left > pivot_left)
 
6838
                 left = pivot_left;
 
6839
              if (right < pivot_right)
 
6840
                 right = pivot_right;
 
6841
              pivot_modify = True;
 
6842
           }
 
6843
           if (XmTextF_has_primary(tf))
 
6844
              df_SetSelection(tf, left, right, True);
 
6845
           else
 
6846
              _XmDataFieldStartSelection(tf, left, right, time);
 
6847
 
 
6848
           if (pivot_modify) {
 
6849
              if ((((right - left) / 2) + left) <= position) {
 
6850
                 cursorPos = right;
 
6851
              } else
 
6852
                 cursorPos = left;
 
6853
           } else {
 
6854
              if (left >= XmTextF_cursor_position(tf))
 
6855
                 cursorPos = left;
 
6856
              else
 
6857
                 cursorPos = right;
 
6858
           }
 
6859
           break;
 
6860
       default:
 
6861
           break;
 
6862
   }
 
6863
   if (cursorPos != XmTextF_cursor_position(tf)) {
 
6864
      (void) df_SetDestination((Widget)tf, cursorPos, False, time);
 
6865
      _XmDataFielddf_SetCursorPosition(tf, NULL, cursorPos, True, True);
 
6866
   }
 
6867
    _XmDataFieldDrawInsertionPoint(tf, True);
 
6868
}
 
6869
 
 
6870
/* ARGSUSED */
 
6871
static void
 
6872
#ifdef _NO_PROTO
 
6873
df_DoSecondaryExtend(w, ev_time)
 
6874
        Widget w;
 
6875
        Time ev_time;
 
6876
#else
 
6877
df_DoSecondaryExtend(
 
6878
        Widget w,
 
6879
        Time ev_time )
 
6880
#endif /* _NO_PROTO */
 
6881
{
 
6882
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
6883
 
 
6884
    XmTextPosition position = XmDataFieldXYToPos(w, XmTextF_select_pos_x(tf), 0);
 
6885
 
 
6886
    if (XmTextF_cancel(tf)) return;
 
6887
 
 
6888
    if (position < XmTextF_sec_anchor(tf)) {
 
6889
       if (XmTextF_sec_pos_left(tf) > 0)
 
6890
          _XmDataFieldSetSel2(w, position, XmTextF_sec_anchor(tf), False, ev_time);
 
6891
       XmDataFieldShowPosition(w, XmTextF_sec_pos_left(tf));
 
6892
    } else if (position > XmTextF_sec_anchor(tf)) {
 
6893
       if (XmTextF_sec_pos_right(tf) < XmTextF_string_length(tf))
 
6894
       _XmDataFieldSetSel2(w, XmTextF_sec_anchor(tf), position, False, ev_time);
 
6895
       XmDataFieldShowPosition(w, XmTextF_sec_pos_right(tf));
 
6896
    } else {
 
6897
       _XmDataFieldSetSel2(w, position, position, False, ev_time);
 
6898
       XmDataFieldShowPosition(w, position);
 
6899
    }
 
6900
    df_ResetClipOrigin(tf, False);
 
6901
 
 
6902
    XmTextF_sec_extending(tf) = True;
 
6903
}
 
6904
 
 
6905
 
 
6906
 
 
6907
/************************************************************************
 
6908
 *                                                                      *
 
6909
 * df_BrowseScroll - timer proc that scrolls the list if the user has left *
 
6910
 *              the window with the button down. If the button has been *
 
6911
 *              released, call the standard click stuff.                *
 
6912
 *                                                                      *
 
6913
 ************************************************************************/
 
6914
/* ARGSUSED */
 
6915
static void
 
6916
#ifdef _NO_PROTO
 
6917
df_BrowseScroll( closure, id )
 
6918
        XtPointer closure ;
 
6919
        XtIntervalId *id ;
 
6920
#else
 
6921
df_BrowseScroll(
 
6922
        XtPointer closure,
 
6923
        XtIntervalId *id )
 
6924
#endif /* _NO_PROTO */
 
6925
{
 
6926
    Widget w = (Widget) closure ;
 
6927
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
6928
 
 
6929
    if (XmTextF_cancel(tf)) {
 
6930
       XmTextF_select_id(tf) = 0;
 
6931
       return;
 
6932
    }
 
6933
 
 
6934
    if (!XmTextF_select_id(tf)) return;
 
6935
 
 
6936
    _XmDataFieldDrawInsertionPoint(tf, False);
 
6937
    if (XmTextF_sec_extending(tf))
 
6938
      df_DoSecondaryExtend(w, XtLastTimestampProcessed(XtDisplay(w)));
 
6939
    else if (XmTextF_extending(tf))
 
6940
      df_DoExtendedSelection(w, XtLastTimestampProcessed(XtDisplay(w)));
 
6941
 
 
6942
    XSync (XtDisplay(w), False);
 
6943
 
 
6944
    _XmDataFieldDrawInsertionPoint(tf, True);
 
6945
 
 
6946
    XmTextF_select_id(tf) = XtAppAddTimeOut(XtWidgetToApplicationContext(w),
 
6947
                                 (unsigned long) PRIM_SCROLL_INTERVAL,
 
6948
                                 df_BrowseScroll, (XtPointer) w);
 
6949
}
 
6950
 
 
6951
 
 
6952
/* ARGSUSED */
 
6953
static Boolean
 
6954
#ifdef _NO_PROTO
 
6955
df_CheckTimerScrolling( w, event )
 
6956
        Widget w ;
 
6957
        XEvent *event ;
 
6958
#else
 
6959
df_CheckTimerScrolling(
 
6960
        Widget w,
 
6961
        XEvent *event )
 
6962
#endif /* _NO_PROTO */
 
6963
{
 
6964
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
6965
    Dimension margin_size = XmTextF_margin_width(tf) +
 
6966
                               tf->primitive.shadow_thickness +
 
6967
                               tf->primitive.highlight_thickness;
 
6968
    Dimension top_margin = XmTextF_margin_height(tf) +
 
6969
                            tf->primitive.shadow_thickness +
 
6970
                            tf->primitive.highlight_thickness;
 
6971
 
 
6972
    XmTextF_select_pos_x(tf) = event->xmotion.x;
 
6973
 
 
6974
    if ((event->xmotion.x > (int) margin_size) &&
 
6975
      (event->xmotion.x < (int) (tf->core.width - margin_size))  &&
 
6976
      (event->xmotion.y > (int) top_margin) &&
 
6977
        (event->xmotion.y < (int) (top_margin + XmTextF_font_ascent(tf) +
 
6978
                                 XmTextF_font_descent(tf)))) {
 
6979
 
 
6980
       if (XmTextF_select_id(tf)) {
 
6981
          XtRemoveTimeOut(XmTextF_select_id(tf));
 
6982
          XmTextF_select_id(tf) = 0;
 
6983
       }
 
6984
    } else {
 
6985
       /* to the left of the text */
 
6986
        if (event->xmotion.x <= (int) margin_size)
 
6987
           XmTextF_select_pos_x(tf) = (Position) (margin_size -
 
6988
                                          (XmTextF_average_char_width(tf) + 1));
 
6989
       /* to the right of the text */
 
6990
      else if (event->xmotion.x >= (int) (tf->core.width - margin_size))
 
6991
           XmTextF_select_pos_x(tf) = (Position) ((tf->core.width - margin_size) +
 
6992
                                           XmTextF_average_char_width(tf) + 1);
 
6993
       if (!XmTextF_select_id(tf))
 
6994
          XmTextF_select_id(tf) = XtAppAddTimeOut(XtWidgetToApplicationContext(w),
 
6995
                                       (unsigned long) SEC_SCROLL_INTERVAL,
 
6996
                                       df_BrowseScroll, (XtPointer) w);
 
6997
       return True;
 
6998
    }
 
6999
    return False;
 
7000
}
 
7001
 
 
7002
static void 
 
7003
#ifdef _NO_PROTO
 
7004
df_RestorePrimaryHighlight( tf, prim_left, prim_right )
 
7005
        XmDataFieldWidget tf ;
 
7006
        XmTextPosition prim_left ;
 
7007
        XmTextPosition prim_right ;
 
7008
#else
 
7009
df_RestorePrimaryHighlight(
 
7010
        XmDataFieldWidget tf,
 
7011
        XmTextPosition prim_left,
 
7012
        XmTextPosition prim_right )
 
7013
#endif /* _NO_PROTO */
 
7014
{
 
7015
   if (XmTextF_sec_pos_right(tf) >= prim_left &&
 
7016
       XmTextF_sec_pos_right(tf) <= prim_right) {
 
7017
     /* secondary selection is totally inside primary selection */
 
7018
      if (XmTextF_sec_pos_left(tf) >= prim_left) {
 
7019
         DataFieldSetHighlight(tf, prim_left, XmTextF_sec_pos_left(tf),
 
7020
                            XmHIGHLIGHT_SELECTED);
 
7021
         DataFieldSetHighlight(tf, XmTextF_sec_pos_left(tf),
 
7022
                               XmTextF_sec_pos_right(tf),
 
7023
                               XmHIGHLIGHT_NORMAL);
 
7024
         DataFieldSetHighlight(tf, XmTextF_sec_pos_right(tf), prim_right,
 
7025
                               XmHIGHLIGHT_SELECTED);
 
7026
     /* right side of secondary selection is inside primary selection */
 
7027
      } else {
 
7028
         DataFieldSetHighlight(tf, XmTextF_sec_pos_left(tf), prim_left,
 
7029
                               XmHIGHLIGHT_NORMAL);
 
7030
         DataFieldSetHighlight(tf, prim_left, XmTextF_sec_pos_right(tf),
 
7031
                               XmHIGHLIGHT_SELECTED);
 
7032
      }
 
7033
   } else {
 
7034
     /* left side of secondary selection is inside primary selection */
 
7035
      if (XmTextF_sec_pos_left(tf) <= prim_right &&
 
7036
          XmTextF_sec_pos_left(tf) >= prim_left) {
 
7037
         DataFieldSetHighlight(tf, XmTextF_sec_pos_left(tf), prim_right,
 
7038
                               XmHIGHLIGHT_SELECTED);
 
7039
         DataFieldSetHighlight(tf, prim_right, XmTextF_sec_pos_right(tf),
 
7040
                               XmHIGHLIGHT_NORMAL);
 
7041
      } else  {
 
7042
       /* secondary selection encompasses the primary selection */
 
7043
        if (XmTextF_sec_pos_left(tf) <= prim_left &&
 
7044
            XmTextF_sec_pos_right(tf) >= prim_right){
 
7045
           DataFieldSetHighlight(tf, XmTextF_sec_pos_left(tf), prim_left,
 
7046
                                 XmHIGHLIGHT_NORMAL);
 
7047
           DataFieldSetHighlight(tf, prim_left, prim_right,
 
7048
                                 XmHIGHLIGHT_SELECTED);
 
7049
           DataFieldSetHighlight(tf, prim_right, XmTextF_sec_pos_right(tf),
 
7050
                                 XmHIGHLIGHT_NORMAL);
 
7051
     /* secondary selection is outside primary selection */
 
7052
        } else {
 
7053
           DataFieldSetHighlight(tf, prim_left, prim_right,
 
7054
                                 XmHIGHLIGHT_SELECTED);
 
7055
           DataFieldSetHighlight(tf, XmTextF_sec_pos_left(tf),
 
7056
                                 XmTextF_sec_pos_right(tf),
 
7057
                                 XmHIGHLIGHT_NORMAL);
 
7058
        }
 
7059
      }
 
7060
   }
 
7061
}
 
7062
 
 
7063
void 
 
7064
#ifdef _NO_PROTO
 
7065
_XmDataFieldSetSel2( w, left, right, disown, sel_time )
 
7066
        Widget w ;
 
7067
        XmTextPosition left ;
 
7068
        XmTextPosition right ;
 
7069
        Boolean disown ;
 
7070
        Time sel_time ;
 
7071
#else
 
7072
_XmDataFieldSetSel2(
 
7073
        Widget w,
 
7074
        XmTextPosition left,
 
7075
        XmTextPosition right,
 
7076
        Boolean disown,
 
7077
        Time sel_time )
 
7078
#endif /* _NO_PROTO */
 
7079
{
 
7080
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
7081
    Boolean result;
 
7082
 
 
7083
    if (XmTextF_has_secondary(tf)) {
 
7084
       XmTextPosition prim_left, prim_right;
 
7085
 
 
7086
       if (left == XmTextF_sec_pos_left(tf) && right == XmTextF_sec_pos_right(tf))
 
7087
          return;
 
7088
 
 
7089
      /* If the widget has the primary selection, make sure the selection
 
7090
       * highlight is restored appropriately.
 
7091
       */
 
7092
       if (XmDataFieldGetSelectionPosition(w, &prim_left, &prim_right))
 
7093
          df_RestorePrimaryHighlight(tf, prim_left, prim_right);
 
7094
       else
 
7095
          DataFieldSetHighlight(tf, XmTextF_sec_pos_left(tf),
 
7096
                                  XmTextF_sec_pos_right(tf), XmHIGHLIGHT_NORMAL);
 
7097
    }
 
7098
 
 
7099
    if (left < right) {
 
7100
       if (!XmTextF_has_secondary(tf)) {
 
7101
          result = XtOwnSelection(w, XA_SECONDARY, sel_time, 
 
7102
                                  _XmDataFieldConvert,
 
7103
                                  _XmDataFieldLoseSelection,
 
7104
                                  (XtSelectionDoneProc) NULL);
 
7105
          XmTextF_sec_time(tf) = sel_time;
 
7106
          XmTextF_has_secondary(tf) = result;
 
7107
          if (result) {
 
7108
             XmTextF_sec_pos_left(tf) = left;
 
7109
             XmTextF_sec_pos_right(tf) = right;
 
7110
          } 
 
7111
       } else {
 
7112
          XmTextF_sec_pos_left(tf) = left;
 
7113
          XmTextF_sec_pos_right(tf) = right;
 
7114
       }
 
7115
       XmTextF_sec_drag(tf) = True;
 
7116
   } else {
 
7117
       XmTextF_sec_pos_left(tf) = XmTextF_sec_pos_right(tf) = left;
 
7118
       if (disown) {
 
7119
          XtDisownSelection(w, XA_SECONDARY, sel_time);
 
7120
          XmTextF_has_secondary(tf) = False;
 
7121
       }
 
7122
   }
 
7123
 
 
7124
   DataFieldSetHighlight((XmDataFieldWidget) w, XmTextF_sec_pos_left(tf),
 
7125
                      XmTextF_sec_pos_right(tf), XmHIGHLIGHT_SECONDARY_SELECTED);
 
7126
 
 
7127
  /* This can be optimized for performance enhancement */
 
7128
 
 
7129
    df_RedisplayText(tf, 0, XmTextF_string_length(tf));
 
7130
}
 
7131
 
 
7132
/* ARGSUSED */
 
7133
static void
 
7134
#ifdef _NO_PROTO
 
7135
df_StartDrag( w, event, params, num_params )
 
7136
        Widget w ;
 
7137
        XEvent *event ;
 
7138
        String *params ;
 
7139
        Cardinal *num_params ;
 
7140
#else
 
7141
df_StartDrag(
 
7142
        Widget w,
 
7143
        XEvent *event,
 
7144
        String *params,
 
7145
        Cardinal *num_params )
 
7146
#endif /* _NO_PROTO */
 
7147
{
 
7148
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
7149
    Atom targets[5];
 
7150
    char * tmp_string = "ABC";  /* these are characters in XPCS, so... safe */
 
7151
    XTextProperty tmp_prop;
 
7152
    int status = 0;
 
7153
    Cardinal num_targets = 0;
 
7154
    Widget drag_icon;
 
7155
    Arg args[10];
 
7156
    int n;
 
7157
 
 
7158
    tmp_prop.value = NULL;
 
7159
    status = XmbTextListToTextProperty(XtDisplay(w), &tmp_string, 1,
 
7160
                                      (XICCEncodingStyle)XTextStyle, &tmp_prop);
 
7161
    if (status == Success)
 
7162
       targets[num_targets++] = tmp_prop.encoding;
 
7163
    else
 
7164
       targets[num_targets++] = 99999; /* XmbTextList...  should never fail
 
7165
                                        * for XPCS characters.  But just in
 
7166
                                        * case someones Xlib is broken,
 
7167
                                        * this prevents a core dump.
 
7168
                                        */
 
7169
    if (tmp_prop.value != NULL) XFree((char *)tmp_prop.value);
 
7170
 
 
7171
#ifdef UTF8_SUPPORTED
 
7172
    targets[num_targets++] = XmInternAtom(XtDisplay(w), "UTF8_STRING", False);
 
7173
#endif
 
7174
    targets[num_targets++] = XmInternAtom(XtDisplay(w), "COMPOUND_TEXT", False);
 
7175
    targets[num_targets++] = XA_STRING;
 
7176
    targets[num_targets++] = XmInternAtom(XtDisplay(w), "TEXT", False);
 
7177
 
 
7178
    drag_icon = XmeGetTextualDragIcon(w);
 
7179
 
 
7180
    n = 0;
 
7181
    XtSetArg(args[n], XmNcursorBackground, tf->core.background_pixel);  n++;
 
7182
    XtSetArg(args[n], XmNcursorForeground, tf->primitive.foreground);  n++;
 
7183
    XtSetArg(args[n], XmNsourceCursorIcon, drag_icon);  n++;
 
7184
    XtSetArg(args[n], XmNexportTargets, targets);  n++;
 
7185
    XtSetArg(args[n], XmNnumExportTargets, num_targets);  n++;
 
7186
    XtSetArg(args[n], XmNconvertProc, _XmDataFieldConvert);  n++;
 
7187
    XtSetArg(args[n], XmNclientData, w);  n++;
 
7188
    if (XmTextF_editable(tf)) {
 
7189
       XtSetArg(args[n], XmNdragOperations, (XmDROP_MOVE | XmDROP_COPY)); n++;
 
7190
    } else {
 
7191
       XtSetArg(args[n], XmNdragOperations, XmDROP_COPY); n++;
 
7192
    }
 
7193
    (void) XmDragStart(w, event, args, n);
 
7194
}
 
7195
 
 
7196
/* ARGSUSED */
 
7197
static void 
 
7198
#ifdef _NO_PROTO
 
7199
df_StartSecondary( w, event, params, num_params )
 
7200
        Widget w ;
 
7201
        XEvent *event ;
 
7202
        char **params ;
 
7203
        Cardinal *num_params ;
 
7204
#else
 
7205
df_StartSecondary(
 
7206
        Widget w,
 
7207
        XEvent *event,
 
7208
        char **params,
 
7209
        Cardinal *num_params )
 
7210
#endif /* _NO_PROTO */
 
7211
{
 
7212
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
7213
  XmTextPosition position = df_GetPosFromX(tf, (Position) event->xbutton.x);
 
7214
  int status;
 
7215
 
 
7216
  XmTextF_sec_anchor(tf) = position;
 
7217
  XmTextF_selection_move(tf) = FALSE;
 
7218
 
 
7219
  status = XtGrabKeyboard(w, False, GrabModeAsync, GrabModeAsync,
 
7220
                          event->xbutton.time);
 
7221
 
 
7222
  if (status != GrabSuccess)
 
7223
     XmeWarning(w, GRABKBDERROR);
 
7224
}
 
7225
 
 
7226
 
 
7227
/* ARGSUSED */
 
7228
static void
 
7229
#ifdef _NO_PROTO
 
7230
df_ProcessBDrag( w, event, params, num_params )
 
7231
        Widget w ;
 
7232
        XEvent *event ;
 
7233
        char **params ;
 
7234
        Cardinal *num_params ;
 
7235
#else
 
7236
df_ProcessBDrag(
 
7237
        Widget w,
 
7238
        XEvent *event,
 
7239
        char **params,
 
7240
        Cardinal *num_params )
 
7241
#endif /* _NO_PROTO */
 
7242
{
 
7243
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
7244
    XmTextPosition position, left, right;
 
7245
    Position left_x, right_x, dummy;
 
7246
 
 
7247
    position = df_GetPosFromX(tf, (Position) event->xbutton.x);
 
7248
 
 
7249
    XmTextF_sec_pos_left(tf) = position;
 
7250
 
 
7251
    _XmDataFieldDrawInsertionPoint(tf, False);
 
7252
    if (XmDataFieldGetSelectionPosition(w, &left, &right) && 
 
7253
        left != right) {
 
7254
        if ((position > left && position < right) ||
 
7255
          /* Take care of border conditions */
 
7256
           (position == left &&
 
7257
            df_GetXYFromPos(tf, left, &left_x, &dummy) &&
 
7258
            event->xbutton.x > left_x) ||
 
7259
           (position == right &&
 
7260
            df_GetXYFromPos(tf, right, &right_x, &dummy) &&
 
7261
            event->xbutton.x < right_x)) {
 
7262
           XmTextF_sel_start(tf) = False;
 
7263
           df_StartDrag(w, event, params, num_params);
 
7264
        } else {
 
7265
           XmTextF_sel_start(tf) = True;
 
7266
           XAllowEvents(XtDisplay(w), AsyncBoth, event->xbutton.time);
 
7267
           df_StartSecondary(w, event, params, num_params);
 
7268
        }
 
7269
    } else {
 
7270
       XmTextF_sel_start(tf) = True;
 
7271
       XAllowEvents(XtDisplay(w), AsyncBoth, event->xbutton.time);
 
7272
       df_StartSecondary(w, event, params, num_params);
 
7273
    }
 
7274
    _XmDataFieldDrawInsertionPoint(tf, True);
 
7275
}
 
7276
 
 
7277
/* ARGSUSED */
 
7278
static void 
 
7279
#ifdef _NO_PROTO
 
7280
df_ExtendSecondary( w, event, params, num_params )
 
7281
        Widget w ;
 
7282
        XEvent *event ;
 
7283
        char **params ;
 
7284
        Cardinal *num_params ;
 
7285
#else
 
7286
df_ExtendSecondary(
 
7287
        Widget w,
 
7288
        XEvent *event,
 
7289
        char **params,
 
7290
        Cardinal *num_params )
 
7291
#endif /* _NO_PROTO */
 
7292
{
 
7293
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
7294
  XmTextPosition position = df_GetPosFromX(tf, (Position) event->xbutton.x);
 
7295
 
 
7296
  if (XmTextF_cancel(tf)) return;
 
7297
 
 
7298
  _XmDataFieldDrawInsertionPoint(tf, False);
 
7299
  if (position < XmTextF_sec_anchor(tf)) {
 
7300
     _XmDataFieldSetSel2(w, position, XmTextF_sec_anchor(tf),
 
7301
                         False, event->xbutton.time);
 
7302
  } else if (position > XmTextF_sec_anchor(tf)) {
 
7303
     _XmDataFieldSetSel2(w, XmTextF_sec_anchor(tf), position, 
 
7304
                         False, event->xbutton.time);
 
7305
  } else {
 
7306
     _XmDataFieldSetSel2(w, position, position, False, event->xbutton.time);
 
7307
  }
 
7308
 
 
7309
  XmTextF_sec_extending(tf) = True;
 
7310
 
 
7311
  if (!df_CheckTimerScrolling(w, event))
 
7312
     df_DoSecondaryExtend(w, event->xmotion.time);
 
7313
 
 
7314
  _XmDataFieldDrawInsertionPoint(tf, True);
 
7315
}
 
7316
 
 
7317
 
 
7318
/* ARGSUSED */
 
7319
static void 
 
7320
#ifdef _NO_PROTO
 
7321
df_DoStuff( w, closure, seltype, type, value, length, format )
 
7322
        Widget w ;
 
7323
        XtPointer closure ;
 
7324
        Atom *seltype ;
 
7325
        Atom *type ;
 
7326
        XtPointer value ;
 
7327
        unsigned long *length ;
 
7328
        int *format ;
 
7329
#else
 
7330
df_DoStuff(
 
7331
        Widget w,
 
7332
        XtPointer closure,
 
7333
        Atom *seltype,
 
7334
        Atom *type,
 
7335
        XtPointer value,
 
7336
        unsigned long *length,
 
7337
        int *format )
 
7338
#endif /* _NO_PROTO */
 
7339
{
 
7340
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
7341
    _XmTextPrimSelect *prim_select = (_XmTextPrimSelect *) closure;
 
7342
    Atom NULL_ATOM = XmInternAtom(XtDisplay(w), "NULL", False);
 
7343
    XmTextPosition right, left;
 
7344
    int prim_char_length = 0;
 
7345
    Boolean replace_res = False;
 
7346
    XTextProperty tmp_prop;
 
7347
    int i, status;
 
7348
    int malloc_size;
 
7349
    int num_vals;
 
7350
    char **tmp_value;
 
7351
    XmAnyCallbackStruct cb;
 
7352
 
 
7353
    if (!XmTextF_has_focus(tf) && _XmGetFocusPolicy(w) == XmEXPLICIT)
 
7354
       (void) XmProcessTraversal(w, XmTRAVERSE_CURRENT);
 
7355
 
 
7356
    if (!(*length) && *type != NULL_ATOM ) {
 
7357
      /* Backwards compatibility for 1.0 Selections */
 
7358
       if (prim_select->target == XmInternAtom(XtDisplay(w), "TEXT", False)) {
 
7359
          prim_select->target = XA_STRING;
 
7360
          XtGetSelectionValue(w, XA_PRIMARY, XA_STRING, df_DoStuff,
 
7361
                           (XtPointer)prim_select, prim_select->time);
 
7362
       }
 
7363
       XtFree((char *)value);
 
7364
       value = NULL;
 
7365
       return;
 
7366
    }
 
7367
 
 
7368
   /* if length == 0 and *type is the NULL atom we are assuming
 
7369
    * that a DELETE target is requested.
 
7370
    */
 
7371
    if (*type == NULL_ATOM ) {
 
7372
       if (prim_select->num_chars > 0 && XmTextF_selection_move(tf)) {
 
7373
          prim_char_length = prim_select->num_chars;
 
7374
          XmDataFieldSetSelection(w, prim_select->position,
 
7375
                                  prim_select->position + prim_char_length,
 
7376
                                  prim_select->time);
 
7377
          XmTextF_prim_anchor(tf) = prim_select->position;
 
7378
          (void) df_SetDestination(w, XmTextF_cursor_position(tf),
 
7379
                                False, prim_select->time);
 
7380
       }
 
7381
    } else {
 
7382
       int max_length = 0;
 
7383
       Boolean local = XmTextF_has_primary(tf);
 
7384
 
 
7385
       if (XmTextF_selection_move(tf) && local) {
 
7386
          max_length = XmTextF_max_length(tf);
 
7387
          XmTextF_max_length(tf) = INT_MAX;
 
7388
       }
 
7389
 
 
7390
       if (*type == XmInternAtom(XtDisplay(w), "COMPOUND_TEXT", False) ||
 
7391
#ifdef UTF8_SUPPORTED
 
7392
           *type == XmInternAtom(XtDisplay(w), "UTF8_STRING", False) ||
 
7393
#endif
 
7394
           *type == XA_STRING) {
 
7395
          tmp_prop.value = (unsigned char *) value;
 
7396
          tmp_prop.encoding = *type;
 
7397
          tmp_prop.format = *format;
 
7398
          tmp_prop.nitems = *length;
 
7399
          num_vals = 0;
 
7400
          status = XmbTextPropertyToTextList(XtDisplay(w), &tmp_prop,
 
7401
                                             &tmp_value, &num_vals);
 
7402
         /* if no conversion, num_vals is not changed */
 
7403
         /* status will be >0 if some characters could not be converted */
 
7404
          if (num_vals && (status == Success || status > 0)) {
 
7405
             if (XmTextF_max_char_size(tf) == 1){
 
7406
                char * total_tmp_value;
 
7407
 
 
7408
                for (i = 0, malloc_size = 1; i < num_vals ; i++)
 
7409
                   malloc_size += strlen(tmp_value[i]);
 
7410
                prim_select->num_chars = malloc_size - 1;
 
7411
                total_tmp_value = XtMalloc ((unsigned) malloc_size);
 
7412
                total_tmp_value[0] = '\0';
 
7413
                for (i = 0; i < num_vals ; i++)
 
7414
                   strcat(total_tmp_value, tmp_value[i]);
 
7415
                replace_res = _XmDataFieldReplaceText(tf, NULL, 
 
7416
                                                      prim_select->position,
 
7417
                                                      prim_select->position, 
 
7418
                                                      total_tmp_value,
 
7419
                                                      strlen(total_tmp_value),
 
7420
                                                      False);
 
7421
                XFreeStringList(tmp_value);
 
7422
                XtFree(total_tmp_value);
 
7423
             } else {
 
7424
                wchar_t * wc_value;
 
7425
 
 
7426
                prim_select->num_chars = 0;
 
7427
                for (i = 0, malloc_size = sizeof(wchar_t); i < num_vals ; i++)
 
7428
                   malloc_size += strlen(tmp_value[i]) * sizeof(wchar_t);
 
7429
                wc_value = (wchar_t*)XtMalloc ((unsigned) malloc_size);
 
7430
                for (i = 0; i < num_vals ; i++)
 
7431
                   prim_select->num_chars +=
 
7432
                                    mbstowcs(wc_value + prim_select->num_chars,
 
7433
                                             tmp_value[i],
 
7434
                                             (size_t)malloc_size -
 
7435
                                             prim_select->num_chars);
 
7436
                replace_res = _XmDataFieldReplaceText(tf, NULL, 
 
7437
                                                      prim_select->position,
 
7438
                                                      prim_select->position,
 
7439
                                                      (char*)wc_value, 
 
7440
                                                      prim_select->num_chars,
 
7441
                                                      False);
 
7442
                XtFree((char*)wc_value);
 
7443
             }
 
7444
          } else { /* initialize prim_select values for possible delete oper */
 
7445
             prim_select->num_chars = 0;
 
7446
          }
 
7447
       } else {
 
7448
             if (XmTextF_max_char_size(tf) == 1){
 
7449
               /* Note: *length may be truncated during cast to int */
 
7450
                prim_select->num_chars = (int) *length;
 
7451
                replace_res = _XmDataFieldReplaceText(tf, NULL, 
 
7452
                                                      prim_select->position,
 
7453
                                                      prim_select->position, 
 
7454
                                                      (char *) value, 
 
7455
                                                      prim_select->num_chars,
 
7456
                                                      False);
 
7457
             } else {
 
7458
                wchar_t * wc_value;
 
7459
 
 
7460
                wc_value = (wchar_t*)XtMalloc ((unsigned)
 
7461
                                               (*length * sizeof(wchar_t)));
 
7462
                prim_select->num_chars = mbstowcs(wc_value, (char *) value,
 
7463
                                         (size_t) *length);
 
7464
                replace_res = _XmDataFieldReplaceText(tf, NULL, 
 
7465
                                                      prim_select->position,
 
7466
                                                      prim_select->position,
 
7467
                                                      (char*)wc_value, 
 
7468
                                                      prim_select->num_chars,
 
7469
                                                      False);
 
7470
                XtFree((char*)wc_value);
 
7471
             }
 
7472
       }
 
7473
 
 
7474
       if (replace_res) {
 
7475
          XmTextPosition cursorPos;
 
7476
 
 
7477
          XmTextF_pending_off(tf) = FALSE;
 
7478
          cursorPos = prim_select->position + prim_select->num_chars; 
 
7479
          if (prim_select->num_chars > 0 && !XmTextF_selection_move(tf)){
 
7480
                (void) df_SetDestination(w, cursorPos, False, prim_select->time);
 
7481
                _XmDataFielddf_SetCursorPosition(tf, NULL, cursorPos, 
 
7482
                                              True, True);
 
7483
          }
 
7484
          if (XmDataFieldGetSelectionPosition(w, &left, &right)) {
 
7485
             if (XmTextF_selection_move(tf) && left < prim_select->position)
 
7486
                prim_select->position -= prim_select->num_chars;
 
7487
             if (left <= cursorPos && right >= cursorPos)
 
7488
                XmTextF_pending_off(tf) = TRUE;
 
7489
          } else {
 
7490
             if (!XmTextF_selection_move(tf) && !XmTextF_add_mode(tf) &&
 
7491
                 prim_select->num_chars != 0)
 
7492
                XmTextF_prim_anchor(tf) = prim_select->position;
 
7493
          }
 
7494
          if (XmTextF_selection_move(tf)) {
 
7495
              prim_select->ref_count++;
 
7496
              XtGetSelectionValue(w, XA_PRIMARY,
 
7497
                                  XmInternAtom(XtDisplay(w), "DELETE", False),
 
7498
                                  df_DoStuff, (XtPointer)prim_select,
 
7499
                                  prim_select->time);
 
7500
           }
 
7501
           cb.reason = XmCR_VALUE_CHANGED;
 
7502
           cb.event = (XEvent *)NULL;
 
7503
           XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
7504
                              (XtPointer) &cb);
 
7505
       }
 
7506
 
 
7507
       if (XmTextF_selection_move(tf) && local) {
 
7508
          XmTextF_max_length(tf) = max_length;
 
7509
       }
 
7510
    }
 
7511
 
 
7512
    XtFree((char *)value);
 
7513
    value = NULL;
 
7514
    if (--prim_select->ref_count == 0)
 
7515
       XtFree((char*)prim_select);
 
7516
}
 
7517
 
 
7518
 
 
7519
 
 
7520
/* ARGSUSED */
 
7521
static void 
 
7522
#ifdef _NO_PROTO
 
7523
df_Stuff( w, event, params, num_params )
 
7524
        Widget w ;
 
7525
        XEvent *event ;
 
7526
        char **params ;
 
7527
        Cardinal *num_params ;
 
7528
#else
 
7529
df_Stuff(
 
7530
        Widget w,
 
7531
        XEvent *event,
 
7532
        char **params,
 
7533
        Cardinal *num_params )
 
7534
#endif /* _NO_PROTO */
 
7535
{
 
7536
  _XmTextActionRec *tmp = (_XmTextActionRec*)XtMalloc(sizeof(_XmTextActionRec));
 
7537
 
 
7538
/* Request targets from the selection owner so you can decide what to
 
7539
 * request.  The decision process and request for the selection is
 
7540
 * taken care of in df_HandleTargets().
 
7541
 */
 
7542
 
 
7543
  tmp->event = (XEvent *) XtMalloc(sizeof(XEvent));
 
7544
  memcpy((void *)tmp->event, (void *)event, sizeof(XEvent));
 
7545
 
 
7546
  tmp->params = params;
 
7547
  tmp->num_params = num_params;
 
7548
 
 
7549
  XtGetSelectionValue(w, XA_PRIMARY,
 
7550
                      XmInternAtom(XtDisplay(w), "TARGETS", False),
 
7551
                      df_HandleTargets,
 
7552
                      (XtPointer)tmp, event->xbutton.time);
 
7553
}
 
7554
 
 
7555
 
 
7556
/* ARGSUSED */
 
7557
static void 
 
7558
#ifdef _NO_PROTO
 
7559
df_HandleSelectionReplies( w, closure, event, cont )
 
7560
        Widget w ;
 
7561
        XtPointer closure ;
 
7562
        XEvent *event ;
 
7563
        Boolean *cont ;
 
7564
#else
 
7565
df_HandleSelectionReplies(
 
7566
        Widget w,
 
7567
        XtPointer closure,
 
7568
        XEvent *event,
 
7569
        Boolean *cont )
 
7570
#endif /* _NO_PROTO */
 
7571
{
 
7572
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
7573
   Atom property = (Atom) closure;
 
7574
   TextFDestData dest_data;
 
7575
   XmTextPosition left, right;
 
7576
   int adjustment = 0;
 
7577
   XmAnyCallbackStruct cb;
 
7578
 
 
7579
   if (event->type != SelectionNotify) return;
 
7580
 
 
7581
   XtRemoveEventHandler(w, (EventMask) NULL, TRUE,
 
7582
                        df_HandleSelectionReplies,
 
7583
                       (XtPointer) XmInternAtom(XtDisplay(w),
 
7584
                                                "_XM_TEXT_I_S_PROP", False));
 
7585
 
 
7586
   dest_data = df_GetTextFDestData(w);
 
7587
 
 
7588
   if (event->xselection.property == None) {
 
7589
      (void) _XmDataFieldSetSel2(w, 0, 0, False, event->xselection.time);
 
7590
      XmTextF_selection_move(tf) = False;
 
7591
   } else {
 
7592
      if (dest_data->has_destination) {
 
7593
         adjustment = (int) (XmTextF_sec_pos_right(tf) - XmTextF_sec_pos_left(tf));
 
7594
 
 
7595
         XmDataFieldSetHighlight(w, XmTextF_sec_pos_left(tf),
 
7596
                                 XmTextF_sec_pos_right(tf), XmHIGHLIGHT_NORMAL);
 
7597
         if (dest_data->position <= XmTextF_sec_pos_left(tf)) {
 
7598
            XmTextF_sec_pos_left(tf) += adjustment - dest_data->replace_length;
 
7599
            XmTextF_sec_pos_right(tf) += adjustment - dest_data->replace_length;
 
7600
         } else if (dest_data->position > XmTextF_sec_pos_left(tf) &&
 
7601
                    dest_data->position < XmTextF_sec_pos_right(tf)) {
 
7602
            XmTextF_sec_pos_left(tf) -= dest_data->replace_length;
 
7603
            XmTextF_sec_pos_right(tf) += adjustment - dest_data->replace_length;
 
7604
         }
 
7605
      }
 
7606
 
 
7607
      left = XmTextF_sec_pos_left(tf);
 
7608
      right = XmTextF_sec_pos_right(tf);
 
7609
 
 
7610
      (void) _XmDataFieldSetSel2(w, 0, 0, False, event->xselection.time);
 
7611
      XmTextF_has_secondary(tf) = False;
 
7612
 
 
7613
      if (XmTextF_selection_move(tf)) {
 
7614
         if (_XmDataFieldReplaceText(tf, event, left, right, NULL, 0, False)) {
 
7615
           if (dest_data->has_destination && XmTextF_cursor_position(tf) > right){
 
7616
              XmTextPosition cursorPos;
 
7617
              cursorPos = XmTextF_cursor_position(tf) - (right - left);
 
7618
              if (!dest_data->quick_key)
 
7619
                _XmDataFielddf_SetCursorPosition(tf, event, cursorPos,
 
7620
                                              True, True);
 
7621
              (void) df_SetDestination((Widget) tf, cursorPos, False,
 
7622
                                                       event->xselection.time);
 
7623
           }
 
7624
           if (!dest_data->has_destination) {
 
7625
               XmTextF_prim_anchor(tf) = XmTextF_cursor_position(tf);
 
7626
               XmDataFieldSetAddMode(w, False); 
 
7627
           }
 
7628
           cb.reason = XmCR_VALUE_CHANGED;
 
7629
           cb.event = event;
 
7630
           XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
7631
                              (XtPointer) &cb);
 
7632
         }
 
7633
         XmTextF_selection_move(tf) = False;
 
7634
      }
 
7635
   }
 
7636
 
 
7637
   XDeleteProperty(XtDisplay(w), event->xselection.requestor, property);
 
7638
}
 
7639
 
 
7640
 
 
7641
/*
 
7642
 * Notify the primary selection that the secondary selection
 
7643
 * wants to insert it's selection data into the primary selection.
 
7644
 */
 
7645
   /* REQUEST TARGETS FROM SELECTION RECEIVER; THEN CALL HANDLETARGETS
 
7646
    * WHICH LOOKS AT THE TARGET LIST AND DETERMINE WHAT TARGET TO PLACE 
 
7647
    * IN THE PAIR.  IT WILL THEN DO ANY NECESSARY CONVERSIONS BEFORE 
 
7648
    * TELLING THE RECEIVER WHAT TO REQUEST AS THE SELECTION VALUE.
 
7649
    * THIS WILL GUARANTEE THE BEST CHANCE AT A SUCCESSFUL EXCHANGE.
 
7650
    */
 
7651
/* ARGSUSED */
 
7652
static void 
 
7653
#ifdef _NO_PROTO
 
7654
df_SecondaryNotify( w, event, params, num_params )
 
7655
        Widget w ;
 
7656
        XEvent *event ;
 
7657
        char **params ;
 
7658
        Cardinal *num_params ;
 
7659
#else
 
7660
df_SecondaryNotify(
 
7661
        Widget w,
 
7662
        XEvent *event,
 
7663
        char **params,
 
7664
        Cardinal *num_params )
 
7665
#endif /* _NO_PROTO */
 
7666
{
 
7667
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
7668
    Atom XM_TEXT_PROP = XmInternAtom(XtDisplay(w), "_XM_TEXT_I_S_PROP", False);
 
7669
    Atom CS_OF_LOCALE; /* to be initialized by XmbTextListToTextProperty */
 
7670
    char * tmp_string = "ABC";  /* these are characters in XPCS, so... safe */
 
7671
    TextFDestData dest_data;
 
7672
    XTextProperty tmp_prop;
 
7673
    _XmTextInsertPair tmp_pair[1];
 
7674
    _XmTextInsertPair *pair = tmp_pair;
 
7675
    XmTextPosition left, right;
 
7676
    int status = 0;
 
7677
 
 
7678
    if (XmTextF_selection_move(tf) == TRUE && XmTextF_has_destination(tf) &&
 
7679
        XmTextF_cursor_position(tf) >= XmTextF_sec_pos_left(tf) &&
 
7680
        XmTextF_cursor_position(tf) <= XmTextF_sec_pos_right(tf)) {
 
7681
       (void) _XmDataFieldSetSel2(w, 0, 0, False, event->xbutton.time);
 
7682
       return;
 
7683
    }
 
7684
 
 
7685
    status = XmbTextListToTextProperty(XtDisplay(w), &tmp_string, 1,
 
7686
                                      (XICCEncodingStyle)XTextStyle, &tmp_prop);
 
7687
    if (status == Success)
 
7688
       CS_OF_LOCALE = tmp_prop.encoding;
 
7689
    else
 
7690
       CS_OF_LOCALE = 99999; /* XmbTextList... should never fail for XPCS
 
7691
                                 * characters.  But just in case someones
 
7692
                                 * Xlib is broken, this prevents a core dump.
 
7693
                                 */
 
7694
    if (tmp_prop.value != NULL) XFree((char *)tmp_prop.value);
 
7695
 
 
7696
   /*
 
7697
    * Determine what the reciever supports so you can tell 'em what to
 
7698
    * request.
 
7699
    */
 
7700
 
 
7701
   /* fill in atom pair */
 
7702
    pair->selection = XA_SECONDARY;
 
7703
    pair->target = CS_OF_LOCALE;
 
7704
 
 
7705
   /* add the insert selection property on the text field widget's window */
 
7706
    XChangeProperty(XtDisplay(w), XtWindow(w), XM_TEXT_PROP, 
 
7707
                    XmInternAtom(XtDisplay(w), "ATOM_PAIR", False),
 
7708
                    32, PropModeReplace, (unsigned char *)pair, 2);
 
7709
 
 
7710
    dest_data = df_GetTextFDestData(w);
 
7711
 
 
7712
    dest_data->has_destination = XmTextF_has_destination(tf);
 
7713
    dest_data->position = XmTextF_cursor_position(tf);
 
7714
    dest_data->replace_length = 0;
 
7715
 
 
7716
    if (*(num_params) == 1) dest_data->quick_key = True;
 
7717
    else dest_data->quick_key = False;
 
7718
 
 
7719
    if (XmDataFieldGetSelectionPosition(w, &left, &right) && left != right) {
 
7720
       if (dest_data->position >= left && dest_data->position <= right)
 
7721
          dest_data->replace_length = (int) (right - left);
 
7722
    }
 
7723
 
 
7724
   /* add an event handler to handle selection notify events */
 
7725
    XtAddEventHandler(w, (EventMask) NULL, TRUE,
 
7726
                      df_HandleSelectionReplies, (XtPointer)XM_TEXT_PROP);
 
7727
 
 
7728
   /*
 
7729
    * Make a request for the primary selection to convert to 
 
7730
    * type INSERT_SELECTION as per ICCCM.
 
7731
    */ 
 
7732
    XConvertSelection(XtDisplay(w),
 
7733
                      XmInternAtom(XtDisplay(w), "MOTIF_DESTINATION", False),
 
7734
                      XmInternAtom(XtDisplay(w), "INSERT_SELECTION", False),
 
7735
                      XM_TEXT_PROP, XtWindow(w), event->xbutton.time);
 
7736
}
 
7737
 
 
7738
   /*
 
7739
    * LOOKS AT THE TARGET LIST AND DETERMINE WHAT TARGET TO PLACE 
 
7740
    * IN THE PAIR.  IT WILL THEN DO ANY NECESSARY CONVERSIONS BEFORE 
 
7741
    * TELLING THE RECEIVER WHAT TO REQUEST AS THE SELECTION VALUE.
 
7742
    * THIS WILL GUARANTEE THE BEST CHANCE AT A SUCCESSFUL EXCHANGE.
 
7743
    */
 
7744
 
 
7745
/* ARGSUSED */
 
7746
static void
 
7747
#ifdef _NO_PROTO
 
7748
df_HandleTargets( w, closure, seltype, type, value, length, format )
 
7749
        Widget w ;
 
7750
        XtPointer closure ;
 
7751
        Atom *seltype ;
 
7752
        Atom *type ;
 
7753
        XtPointer value ;
 
7754
        unsigned long *length ;
 
7755
        int *format ;
 
7756
#else
 
7757
df_HandleTargets(
 
7758
        Widget w,
 
7759
        XtPointer closure,
 
7760
        Atom *seltype,
 
7761
        Atom *type,
 
7762
        XtPointer value,
 
7763
        unsigned long *length,
 
7764
        int *format )
 
7765
#endif /* _NO_PROTO */
 
7766
{
 
7767
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
7768
    Atom CS_OF_LOCALE; /* to be initialized by XmbTextListToTextProperty */
 
7769
    Atom COMPOUND_TEXT = XmInternAtom(XtDisplay(w),"COMPOUND_TEXT", False);
 
7770
#ifdef UTF8_SUPPORTED
 
7771
    Atom UTF8_STRING = XmInternAtom(XtDisplay(w), XmSUTF8_STRING, False);
 
7772
#endif
 
7773
    XmTextPosition left, right;
 
7774
    Boolean supports_locale_data = False;
 
7775
    Boolean supports_CT = False;
 
7776
    Boolean supports_utf8_string = False;
 
7777
    Atom *atom_ptr;
 
7778
    _XmTextActionRec *tmp_action = (_XmTextActionRec *) closure;
 
7779
    _XmTextPrimSelect *prim_select;
 
7780
    char * tmp_string = "ABC";  /* these are characters in XPCS, so... safe */
 
7781
    XTextProperty tmp_prop;
 
7782
    int status = 0;
 
7783
    Atom targets[2];
 
7784
    XmTextPosition select_pos;
 
7785
    int i;
 
7786
 
 
7787
    if (!length) {
 
7788
       XtFree((char *)value);
 
7789
       value = NULL;
 
7790
       XtFree((char *)tmp_action->event);
 
7791
       XtFree((char *)tmp_action);
 
7792
       return; /* Supports no targets, so don't bother sending anything */
 
7793
    }
 
7794
 
 
7795
    atom_ptr = (Atom *)value;
 
7796
 
 
7797
    status = XmbTextListToTextProperty(XtDisplay(w), &tmp_string, 1,
 
7798
                                      (XICCEncodingStyle)XTextStyle, &tmp_prop);
 
7799
    if (status == Success)
 
7800
       CS_OF_LOCALE = tmp_prop.encoding;
 
7801
    else
 
7802
       CS_OF_LOCALE = 99999; /* XmbTextList... should never fail for XPCS
 
7803
                                 * characters.  But just in case someones
 
7804
                                 * Xlib is broken, this prevents a core dump.
 
7805
                                 */
 
7806
 
 
7807
    if (tmp_prop.value != NULL) XFree((char *)tmp_prop.value);
 
7808
 
 
7809
    for (i = 0; i < *length; i++, atom_ptr++) {
 
7810
      if (*atom_ptr == CS_OF_LOCALE) {
 
7811
         supports_locale_data = True;
 
7812
         break;
 
7813
      }
 
7814
      if (*atom_ptr == COMPOUND_TEXT)
 
7815
         supports_CT = True;
 
7816
#ifdef UTF8_SUPPORTED
 
7817
      if (*atom_ptr == UTF8_STRING)
 
7818
         supports_utf8_string = True;
 
7819
#endif
 
7820
    }
 
7821
 
 
7822
 
 
7823
  /*
 
7824
   * Set stuff position to the x and y position of
 
7825
   * the button pressed event for primary pastes.
 
7826
   */
 
7827
   if (tmp_action->event->type == ButtonRelease) {
 
7828
      select_pos =  df_GetPosFromX(tf, (Position)tmp_action->event->xbutton.x);
 
7829
   } else {
 
7830
      select_pos = XmTextF_cursor_position(tf);
 
7831
   }
 
7832
 
 
7833
   if (XmDataFieldGetSelectionPosition(w, &left, &right) &&
 
7834
       left != right && select_pos > left && select_pos < right) {
 
7835
      XtFree((char *)value);
 
7836
      value = NULL;
 
7837
      XtFree((char *)tmp_action->event);
 
7838
      XtFree((char *)tmp_action);
 
7839
      return;
 
7840
   }
 
7841
 
 
7842
   prim_select = (_XmTextPrimSelect *)
 
7843
                  XtMalloc((unsigned) sizeof(_XmTextPrimSelect));
 
7844
 
 
7845
   prim_select->position = select_pos;
 
7846
 
 
7847
   if (tmp_action->event->type == ButtonRelease) {
 
7848
      prim_select->time = tmp_action->event->xbutton.time;
 
7849
   } else {
 
7850
      prim_select->time = tmp_action->event->xkey.time;
 
7851
   }
 
7852
 
 
7853
   prim_select->num_chars = 0;
 
7854
 
 
7855
   if (supports_locale_data)
 
7856
      prim_select->target = targets[0] = XmInternAtom(XtDisplay(w), "TEXT",
 
7857
                                                      False);
 
7858
#ifdef UTF8_SUPPORTED
 
7859
   else if (supports_utf8_string)
 
7860
       prim_select->target = targets[0] = UTF8_STRING;
 
7861
#endif
 
7862
   else if (supports_CT)
 
7863
      prim_select->target = targets[0] = COMPOUND_TEXT;
 
7864
   else
 
7865
      prim_select->target = targets[0] = XA_STRING;
 
7866
 
 
7867
   prim_select->ref_count = 1;
 
7868
   /* Make request to call df_DoStuff() with the primary selection. */
 
7869
   XtGetSelectionValue(w, XA_PRIMARY, targets[0], df_DoStuff,
 
7870
                          (XtPointer)prim_select, 
 
7871
                          tmp_action->event->xbutton.time);
 
7872
 
 
7873
   XtFree((char *)value);
 
7874
   value = NULL;
 
7875
   XtFree((char *)tmp_action->event);
 
7876
   XtFree((char *)tmp_action);
 
7877
}
 
7878
 
 
7879
static void
 
7880
#ifdef _NO_PROTO
 
7881
df_ProcessBDragRelease( w, event, params, num_params )
 
7882
        Widget w ;
 
7883
        XEvent *event ;
 
7884
        String *params ;
 
7885
        Cardinal *num_params ;
 
7886
#else
 
7887
df_ProcessBDragRelease(
 
7888
        Widget w,
 
7889
        XEvent *event,
 
7890
        String *params,
 
7891
        Cardinal *num_params )
 
7892
#endif /* _NO_PROTO */
 
7893
{
 
7894
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
7895
    XButtonEvent      *ev = (XButtonEvent *) event;
 
7896
    XmTextPosition position;
 
7897
 
 
7898
   /* Work around for intrinsic bug.  Remove once bug is fixed. */
 
7899
    XtUngrabPointer(w, ev->time);
 
7900
 
 
7901
    _XmDataFieldDrawInsertionPoint(tf, False);
 
7902
    if (!XmTextF_cancel(tf)) XtUngrabKeyboard(w, CurrentTime);
 
7903
 
 
7904
    position = df_GetPosFromX(tf, (Position) event->xbutton.x);
 
7905
 
 
7906
    if (XmTextF_sel_start(tf)) {
 
7907
       if (XmTextF_has_secondary(tf) &&
 
7908
               XmTextF_sec_pos_left(tf) != XmTextF_sec_pos_right(tf)) {
 
7909
          if (ev->x > (int)tf->core.width || ev->x < 0 ||
 
7910
              ev->y > (int)tf->core.height || ev->x < 0) {
 
7911
             _XmDataFieldSetSel2(w, 0, 0, False, event->xkey.time);
 
7912
             XmTextF_has_secondary(tf) = False;
 
7913
          } else {
 
7914
             df_SecondaryNotify(w, event, params, num_params);
 
7915
          }
 
7916
       } else if (!XmTextF_sec_drag(tf) && !XmTextF_cancel(tf) &&
 
7917
                  XmTextF_sec_pos_left(tf) == position) {
 
7918
          XmTextF_stuff_pos(tf) =  df_GetPosFromX(tf, (Position) event->xbutton.x);
 
7919
        /*
 
7920
         * Copy contents of primary selection to the stuff position found above.
 
7921
         */
 
7922
          df_Stuff(w, event, params, num_params);
 
7923
       }
 
7924
    }
 
7925
 
 
7926
    if (XmTextF_select_id(tf)) {
 
7927
       XtRemoveTimeOut(XmTextF_select_id(tf));
 
7928
       XmTextF_select_id(tf) = 0;
 
7929
    }
 
7930
 
 
7931
    XmTextF_sec_extending(tf) = False;
 
7932
 
 
7933
    XmTextF_sec_drag(tf) = False;
 
7934
    XmTextF_sel_start(tf) = False;
 
7935
    XmTextF_cancel(tf) = False;
 
7936
    _XmDataFieldDrawInsertionPoint(tf, True);
 
7937
}
 
7938
 
 
7939
static void 
 
7940
#ifdef _NO_PROTO
 
7941
df_ProcessCopy( w, event, params, num_params )
 
7942
        Widget w ;
 
7943
        XEvent *event ;
 
7944
        char **params ;
 
7945
        Cardinal *num_params ;
 
7946
#else
 
7947
df_ProcessCopy(
 
7948
        Widget w,
 
7949
        XEvent *event,
 
7950
        char **params,
 
7951
        Cardinal *num_params )
 
7952
#endif /* _NO_PROTO */
 
7953
{
 
7954
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
7955
 
 
7956
    _XmDataFieldDrawInsertionPoint(tf, False);
 
7957
    XmTextF_selection_move(tf) = FALSE;
 
7958
    df_ProcessBDragRelease(w, event, params, num_params);
 
7959
    _XmDataFieldDrawInsertionPoint(tf, True);
 
7960
}
 
7961
 
 
7962
static void 
 
7963
#ifdef _NO_PROTO
 
7964
df_ProcessMove( w, event, params, num_params )
 
7965
        Widget w ;
 
7966
        XEvent *event ;
 
7967
        char **params ;
 
7968
        Cardinal *num_params ;
 
7969
#else
 
7970
df_ProcessMove(
 
7971
        Widget w,
 
7972
        XEvent *event,
 
7973
        char **params,
 
7974
        Cardinal *num_params )
 
7975
#endif /* _NO_PROTO */
 
7976
{
 
7977
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
7978
 
 
7979
    _XmDataFieldDrawInsertionPoint(tf, False);
 
7980
    XmTextF_selection_move(tf) = TRUE;
 
7981
    df_ProcessBDragRelease(w, event, params, num_params);
 
7982
    _XmDataFieldDrawInsertionPoint(tf, True);
 
7983
}
 
7984
 
 
7985
 
 
7986
/* ARGSUSED */
 
7987
static void 
 
7988
#ifdef _NO_PROTO
 
7989
df_DeleteSelection( w, event, params, num_params )
 
7990
        Widget w ;
 
7991
        XEvent *event ;
 
7992
        char **params ;
 
7993
        Cardinal *num_params ;
 
7994
#else
 
7995
df_DeleteSelection(
 
7996
        Widget w,
 
7997
        XEvent *event,
 
7998
        char **params,
 
7999
        Cardinal *num_params )
 
8000
#endif /* _NO_PROTO */
 
8001
{
 
8002
    (void) DataFieldRemove(w, event);
 
8003
}
 
8004
 
 
8005
/* ARGSUSED */
 
8006
static void 
 
8007
#ifdef _NO_PROTO
 
8008
df_ClearSelection( w, event, params, num_params )
 
8009
        Widget w ;
 
8010
        XEvent *event ;
 
8011
        char **params ;
 
8012
        Cardinal *num_params ;
 
8013
#else
 
8014
df_ClearSelection(
 
8015
        Widget w,
 
8016
        XEvent *event,
 
8017
        char **params,
 
8018
        Cardinal *num_params )
 
8019
#endif /* _NO_PROTO */
 
8020
{
 
8021
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8022
    XmTextPosition left = XmTextF_prim_pos_left(tf);
 
8023
    XmTextPosition right = XmTextF_prim_pos_right(tf);
 
8024
    int num_spaces = 0;
 
8025
    XmAnyCallbackStruct cb;
 
8026
    Boolean rep_result = False;
 
8027
 
 
8028
    if (left < right)
 
8029
       num_spaces = (int)(right - left);
 
8030
    else
 
8031
       num_spaces = (int)(left - right);
 
8032
 
 
8033
    if (num_spaces) {
 
8034
       _XmDataFieldDrawInsertionPoint(tf, False);
 
8035
       if (XmTextF_max_char_size(tf) == 1){
 
8036
          char spaces_cache[100];
 
8037
          Cardinal spaces_size;
 
8038
          char *spaces;
 
8039
          int i;
 
8040
 
 
8041
          spaces_size = num_spaces + 1;
 
8042
 
 
8043
          spaces = (char *)XmStackAlloc(spaces_size, spaces_cache);
 
8044
 
 
8045
          for (i = 0; i < num_spaces; i++) spaces[i] = ' ';
 
8046
          spaces[num_spaces] = 0;
 
8047
 
 
8048
          rep_result = _XmDataFieldReplaceText(tf, (XEvent *)event, left, right,
 
8049
                                               spaces, num_spaces, False);
 
8050
          if (XmTextF_cursor_position(tf) > left)
 
8051
             df_ResetClipOrigin(tf, False);     
 
8052
          XmStackFree((char *)spaces, spaces_cache);
 
8053
       } else {
 
8054
          wchar_t *wc_spaces;
 
8055
          int i;
 
8056
 
 
8057
          wc_spaces = (wchar_t *)XtMalloc((unsigned)
 
8058
                                          (num_spaces + 1) * sizeof(wchar_t));
 
8059
 
 
8060
          for (i = 0; i < num_spaces; i++){
 
8061
             (void)mbtowc(&wc_spaces[i], " ", 1);
 
8062
          }
 
8063
          
 
8064
          rep_result = _XmDataFieldReplaceText(tf, (XEvent *)event, left, right,
 
8065
                                               (char*)wc_spaces, num_spaces,
 
8066
                                               False);
 
8067
          if (XmTextF_cursor_position(tf) > left)
 
8068
             df_ResetClipOrigin(tf, False);     
 
8069
 
 
8070
          XtFree((char*)wc_spaces);
 
8071
       }
 
8072
       if (rep_result) {
 
8073
          cb.reason = XmCR_VALUE_CHANGED;
 
8074
          cb.event = event;
 
8075
          XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
8076
                             (XtPointer) &cb);
 
8077
       }
 
8078
       _XmDataFieldDrawInsertionPoint(tf, True);
 
8079
    }
 
8080
}
 
8081
 
 
8082
/* ARGSUSED */
 
8083
static void 
 
8084
#ifdef _NO_PROTO
 
8085
df_PageRight( w, event, params, num_params )
 
8086
        Widget w ;
 
8087
        XEvent *event ;
 
8088
        char **params ;
 
8089
        Cardinal *num_params ;
 
8090
#else
 
8091
df_PageRight(
 
8092
        Widget w,
 
8093
        XEvent *event,
 
8094
        char **params,
 
8095
        Cardinal *num_params )
 
8096
#endif /* _NO_PROTO */
 
8097
{
 
8098
    Position x, y;
 
8099
    int length = 0;
 
8100
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8101
    Dimension margin_width = XmTextF_margin_width(tf) +
 
8102
                             tf->primitive.shadow_thickness +
 
8103
                             tf->primitive.highlight_thickness;
 
8104
 
 
8105
    if (XmTextF_max_char_size(tf) != 1){
 
8106
       length = df_FindPixelLength(tf, (char*)XmTextF_wc_value(tf),
 
8107
                                XmTextF_string_length(tf));
 
8108
    } else {
 
8109
       length = df_FindPixelLength(tf, XmTextF_value(tf), XmTextF_string_length(tf));
 
8110
    }
 
8111
 
 
8112
    _XmDataFieldDrawInsertionPoint(tf, False);
 
8113
 
 
8114
    if (*num_params > 0 && !strcmp(*params, "extend"))
 
8115
       df_SetAnchorBalancing(tf, XmTextF_cursor_position(tf));
 
8116
 
 
8117
    df_GetXYFromPos(tf, XmTextF_cursor_position(tf), &x, &y);
 
8118
 
 
8119
    if (length - ((int)(tf->core.width - (2 * margin_width)) -
 
8120
         XmTextF_h_offset(tf)) > (int)(tf->core.width - (2 * margin_width)))
 
8121
       XmTextF_h_offset(tf) -= tf->core.width - (2 * margin_width);
 
8122
    else
 
8123
       XmTextF_h_offset(tf) = -(length - (tf->core.width - (2 * margin_width)));
 
8124
 
 
8125
    df_RedisplayText(tf, 0, XmTextF_string_length(tf));
 
8126
    _XmDataFielddf_SetCursorPosition(tf, event, df_GetPosFromX(tf, x), 
 
8127
                                  True, True);
 
8128
 
 
8129
    if (*num_params > 0 && !strcmp(*params, "extend"))
 
8130
       df_KeySelection(w, event, params, num_params);
 
8131
 
 
8132
    _XmDataFieldDrawInsertionPoint(tf, True);
 
8133
}
 
8134
 
 
8135
/* ARGSUSED */
 
8136
static void 
 
8137
#ifdef _NO_PROTO
 
8138
df_PageLeft( w, event, params, num_params )
 
8139
        Widget w ;
 
8140
        XEvent *event ;
 
8141
        char **params ;
 
8142
        Cardinal *num_params ;
 
8143
#else
 
8144
df_PageLeft(
 
8145
        Widget w,
 
8146
        XEvent *event,
 
8147
        char **params,
 
8148
        Cardinal *num_params )
 
8149
#endif /* _NO_PROTO */
 
8150
{
 
8151
    Position x, y;
 
8152
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8153
    int margin_width = (int)XmTextF_margin_width(tf) +
 
8154
                             tf->primitive.shadow_thickness +
 
8155
                             tf->primitive.highlight_thickness;
 
8156
 
 
8157
    _XmDataFieldDrawInsertionPoint(tf, False);
 
8158
 
 
8159
    if (*num_params > 0 && !strcmp(*params, "extend"))
 
8160
       df_SetAnchorBalancing(tf, XmTextF_cursor_position(tf));
 
8161
 
 
8162
    df_GetXYFromPos(tf, XmTextF_cursor_position(tf), &x, &y);
 
8163
    if (margin_width  <= XmTextF_h_offset(tf) +
 
8164
                            ((int)tf->core.width - (2 * margin_width)))
 
8165
       XmTextF_h_offset(tf) = margin_width;
 
8166
    else
 
8167
       XmTextF_h_offset(tf) += tf->core.width - (2 * margin_width);
 
8168
 
 
8169
    df_RedisplayText(tf, 0, XmTextF_string_length(tf));
 
8170
    _XmDataFielddf_SetCursorPosition(tf, event, df_GetPosFromX(tf, x),
 
8171
                                  True, True);
 
8172
 
 
8173
    if (*num_params > 0 && !strcmp(*params, "extend"))
 
8174
       df_KeySelection(w, event, params, num_params);
 
8175
 
 
8176
    _XmDataFieldDrawInsertionPoint(tf, True);
 
8177
}
 
8178
 
 
8179
static void 
 
8180
#ifdef _NO_PROTO
 
8181
df_CopyPrimary( w, event, params, num_params )
 
8182
        Widget w ;
 
8183
        XEvent *event ;
 
8184
        char **params ;
 
8185
        Cardinal *num_params ;
 
8186
#else
 
8187
df_CopyPrimary(
 
8188
        Widget w,
 
8189
        XEvent *event,
 
8190
        char **params,
 
8191
        Cardinal *num_params )
 
8192
#endif /* _NO_PROTO */
 
8193
{
 
8194
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8195
 
 
8196
    _XmDataFieldDrawInsertionPoint(tf, False);
 
8197
    XmTextF_selection_move(tf) = False;
 
8198
 
 
8199
   /* perform the primary paste action */
 
8200
    df_Stuff(w, event, params, num_params);
 
8201
    _XmDataFieldDrawInsertionPoint(tf, True);
 
8202
}
 
8203
 
 
8204
static void 
 
8205
#ifdef _NO_PROTO
 
8206
df_CutPrimary( w, event, params, num_params )
 
8207
        Widget w ;
 
8208
        XEvent *event ;
 
8209
        char **params ;
 
8210
        Cardinal *num_params ;
 
8211
#else
 
8212
df_CutPrimary(
 
8213
        Widget w,
 
8214
        XEvent *event,
 
8215
        char **params,
 
8216
        Cardinal *num_params )
 
8217
#endif /* _NO_PROTO */
 
8218
{
 
8219
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8220
 
 
8221
    _XmDataFieldDrawInsertionPoint(tf, False);
 
8222
    XmTextF_selection_move(tf) = True;
 
8223
    df_Stuff(w, event, params, num_params);
 
8224
    _XmDataFieldDrawInsertionPoint(tf, True);
 
8225
}
 
8226
 
 
8227
/* ARGSUSED */
 
8228
static void 
 
8229
#ifdef _NO_PROTO
 
8230
df_SetAnchor( w, event, params, num_params )
 
8231
        Widget w ;
 
8232
        XEvent *event ;
 
8233
        char **params ;
 
8234
        Cardinal *num_params ;
 
8235
#else
 
8236
df_SetAnchor(
 
8237
        Widget w,
 
8238
        XEvent *event,
 
8239
        char **params,
 
8240
        Cardinal *num_params )
 
8241
#endif /* _NO_PROTO */
 
8242
{
 
8243
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8244
    XmTextPosition left, right;
 
8245
 
 
8246
    XmTextF_prim_anchor(tf) = XmTextF_cursor_position(tf);
 
8247
    (void) df_SetDestination(w, XmTextF_prim_anchor(tf), False, event->xkey.time);
 
8248
    if (XmDataFieldGetSelectionPosition(w, &left, &right)) {
 
8249
       _XmDataFieldStartSelection(tf, XmTextF_prim_anchor(tf),
 
8250
                                  XmTextF_prim_anchor(tf), event->xkey.time);
 
8251
       XmDataFieldSetAddMode(w, False);
 
8252
    }
 
8253
}
 
8254
 
 
8255
/* ARGSUSED */
 
8256
static void 
 
8257
#ifdef _NO_PROTO
 
8258
df_ToggleOverstrike( w, event, params, num_params )
 
8259
        Widget w ;
 
8260
        XEvent *event ;
 
8261
        char **params ;
 
8262
        Cardinal *num_params ;
 
8263
#else
 
8264
df_ToggleOverstrike(
 
8265
        Widget w,
 
8266
        XEvent *event,
 
8267
        char **params,
 
8268
        Cardinal *num_params )
 
8269
#endif /* _NO_PROTO */
 
8270
{
 
8271
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8272
 
 
8273
    _XmDataFieldDrawInsertionPoint(tf, False);
 
8274
    XmTextF_overstrike(tf) = !XmTextF_overstrike(tf);
 
8275
    XmTextF_refresh_ibeam_off(tf) = True;
 
8276
    if (XmTextF_overstrike(tf))
 
8277
      XmTextF_cursor_width(tf) = XmTextF_cursor_height(tf) >> 1;
 
8278
    else {
 
8279
      XmTextF_cursor_width(tf) = 5;
 
8280
      if (XmTextF_cursor_height(tf) > 19) 
 
8281
        XmTextF_cursor_width(tf)++;
 
8282
      df_ResetClipOrigin(tf, False);
 
8283
    }
 
8284
    _XmDataFToggleCursorGC(w);
 
8285
    _XmDataFieldDrawInsertionPoint(tf, True);
 
8286
}
 
8287
 
 
8288
/* ARGSUSED */
 
8289
static void 
 
8290
#ifdef _NO_PROTO
 
8291
df_ToggleAddMode( w, event, params, num_params )
 
8292
        Widget w ;
 
8293
        XEvent *event ;
 
8294
        char **params ;
 
8295
        Cardinal *num_params ;
 
8296
#else
 
8297
df_ToggleAddMode(
 
8298
        Widget w,
 
8299
        XEvent *event,
 
8300
        char **params,
 
8301
        Cardinal *num_params )
 
8302
#endif /* _NO_PROTO */
 
8303
{
 
8304
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8305
    XmTextPosition left, right;
 
8306
 
 
8307
    _XmDataFieldDrawInsertionPoint(tf, False);
 
8308
 
 
8309
    XmDataFieldSetAddMode(w, !XmTextF_add_mode(tf));    
 
8310
    if (XmTextF_add_mode(tf) &&
 
8311
        (!(XmDataFieldGetSelectionPosition(w, &left, &right)) ||
 
8312
         left == right))
 
8313
       XmTextF_prim_anchor(tf) = XmTextF_cursor_position(tf);
 
8314
 
 
8315
    _XmDataFieldDrawInsertionPoint(tf, True);
 
8316
}
 
8317
 
 
8318
/* ARGSUSED */
 
8319
static void 
 
8320
#ifdef _NO_PROTO
 
8321
df_SelectAll( w, event, params, num_params )
 
8322
        Widget w ;
 
8323
        XEvent *event ;
 
8324
        char **params ;
 
8325
        Cardinal *num_params ;
 
8326
#else
 
8327
df_SelectAll(
 
8328
        Widget w,
 
8329
        XEvent *event,
 
8330
        char **params,
 
8331
        Cardinal *num_params )
 
8332
#endif /* _NO_PROTO */
 
8333
{
 
8334
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8335
 
 
8336
    _XmDataFieldDrawInsertionPoint(tf, False);
 
8337
    if (XmTextF_has_primary(tf))
 
8338
       df_SetSelection(tf, 0, XmTextF_string_length(tf), True);
 
8339
    else
 
8340
       _XmDataFieldStartSelection(tf, 0, XmTextF_string_length(tf),
 
8341
                                  event->xbutton.time);
 
8342
 
 
8343
    /* Call _XmDataFielddf_SetCursorPosition to force image gc to be updated
 
8344
     * in case the i-beam is contained within the selection */
 
8345
 
 
8346
    XmTextF_pending_off(tf) = False;
 
8347
 
 
8348
    _XmDataFielddf_SetCursorPosition(tf, NULL, XmTextF_cursor_position(tf),
 
8349
                                  False, False);
 
8350
    XmTextF_prim_anchor(tf) = 0;
 
8351
 
 
8352
    (void) df_SetDestination(w, XmTextF_cursor_position(tf),
 
8353
                          False, event->xkey.time);
 
8354
    _XmDataFieldDrawInsertionPoint(tf, True);
 
8355
}
 
8356
 
 
8357
/* ARGSUSED */
 
8358
static void 
 
8359
#ifdef _NO_PROTO
 
8360
df_DeselectAll( w, event, params, num_params )
 
8361
        Widget w ;
 
8362
        XEvent *event ;
 
8363
        char **params ;
 
8364
        Cardinal *num_params ;
 
8365
#else
 
8366
df_DeselectAll(
 
8367
        Widget w,
 
8368
        XEvent *event,
 
8369
        char **params,
 
8370
        Cardinal *num_params )
 
8371
#endif /* _NO_PROTO */
 
8372
{
 
8373
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8374
 
 
8375
    _XmDataFieldDrawInsertionPoint(tf, False);
 
8376
    df_SetSelection(tf, XmTextF_cursor_position(tf), XmTextF_cursor_position(tf), True);
 
8377
    XmTextF_pending_off(tf) = True;
 
8378
    _XmDataFielddf_SetCursorPosition(tf, event, XmTextF_cursor_position(tf),
 
8379
                                  True, True);
 
8380
    XmTextF_prim_anchor(tf) = XmTextF_cursor_position(tf);
 
8381
    (void) df_SetDestination(w, XmTextF_cursor_position(tf),
 
8382
                          False, event->xkey.time);
 
8383
    _XmDataFieldDrawInsertionPoint(tf, True);
 
8384
}
 
8385
 
 
8386
/* ARGSUSED */
 
8387
static void 
 
8388
#ifdef _NO_PROTO
 
8389
df_VoidAction( w, event, params, num_params )
 
8390
        Widget w ;
 
8391
        XEvent *event ;
 
8392
        char **params ;
 
8393
        Cardinal *num_params ;
 
8394
#else
 
8395
df_VoidAction(
 
8396
        Widget w,
 
8397
        XEvent *event,
 
8398
        char **params,
 
8399
        Cardinal *num_params )
 
8400
#endif /* _NO_PROTO */
 
8401
{
 
8402
  /* Do Nothing */
 
8403
}
 
8404
 
 
8405
/* ARGSUSED */
 
8406
static void 
 
8407
#ifdef _NO_PROTO
 
8408
df_CutClipboard( w, event, params, num_params )
 
8409
        Widget w ;
 
8410
        XEvent *event ;
 
8411
        char **params ;
 
8412
        Cardinal *num_params ;
 
8413
#else
 
8414
df_CutClipboard(
 
8415
        Widget w,
 
8416
        XEvent *event,
 
8417
        char **params,
 
8418
        Cardinal *num_params )
 
8419
#endif /* _NO_PROTO */
 
8420
{
 
8421
    _XmDataFieldDrawInsertionPoint((XmDataFieldWidget)w, False);
 
8422
    (void) XmDataFieldCut(w, event->xkey.time);
 
8423
    _XmDataFieldDrawInsertionPoint((XmDataFieldWidget)w, True);
 
8424
}
 
8425
 
 
8426
/* ARGSUSED */
 
8427
static void 
 
8428
#ifdef _NO_PROTO
 
8429
df_CopyClipboard( w, event, params, num_params )
 
8430
        Widget w ;
 
8431
        XEvent *event ;
 
8432
        char **params ;
 
8433
        Cardinal *num_params ;
 
8434
#else
 
8435
df_CopyClipboard(
 
8436
        Widget w,
 
8437
        XEvent *event,
 
8438
        char **params,
 
8439
        Cardinal *num_params )
 
8440
#endif /* _NO_PROTO */
 
8441
{
 
8442
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8443
 
 
8444
    _XmDataFieldDrawInsertionPoint(tf, False);
 
8445
    (void) XmDataFieldCopy(w, event->xkey.time);
 
8446
    (void) df_SetDestination(w, XmTextF_cursor_position(tf), False, event->xkey.time);
 
8447
    _XmDataFieldDrawInsertionPoint(tf, True);
 
8448
}
 
8449
 
 
8450
/* ARGSUSED */
 
8451
static void 
 
8452
#ifdef _NO_PROTO
 
8453
df_PasteClipboard( w, event, params, num_params )
 
8454
        Widget w ;
 
8455
        XEvent *event ;
 
8456
        char **params ;
 
8457
        Cardinal *num_params ;
 
8458
#else
 
8459
df_PasteClipboard(
 
8460
        Widget w,
 
8461
        XEvent *event,
 
8462
        char **params,
 
8463
        Cardinal *num_params )
 
8464
#endif /* _NO_PROTO */
 
8465
{
 
8466
    _XmDataFieldDrawInsertionPoint((XmDataFieldWidget)w, False);
 
8467
    (void) XmDataFieldPaste(w);
 
8468
    _XmDataFieldDrawInsertionPoint((XmDataFieldWidget)w, True);
 
8469
}
 
8470
 
 
8471
/* ARGSUSED */
 
8472
static void 
 
8473
#ifdef _NO_PROTO
 
8474
df_TraverseDown( w, event, params, num_params )
 
8475
        Widget w ;
 
8476
        XEvent *event ;
 
8477
        char **params ;
 
8478
        Cardinal *num_params ;
 
8479
#else
 
8480
df_TraverseDown(
 
8481
        Widget w,
 
8482
        XEvent *event,
 
8483
        char **params,
 
8484
        Cardinal *num_params )
 
8485
#endif /* _NO_PROTO */
 
8486
{
 
8487
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8488
 
 
8489
    if (tf->primitive.navigation_type == XmNONE && df_VerifyLeave(tf, event)) {
 
8490
       XmTextF_traversed(tf) = True;
 
8491
       if (!_XmMgrTraversal(w, XmTRAVERSE_DOWN))
 
8492
          XmTextF_traversed(tf) = False;
 
8493
    }
 
8494
}
 
8495
 
 
8496
 
 
8497
/* ARGSUSED */
 
8498
static void 
 
8499
#ifdef _NO_PROTO
 
8500
df_TraverseUp( w, event, params, num_params )
 
8501
        Widget w ;
 
8502
        XEvent *event ;
 
8503
        char **params ;
 
8504
        Cardinal *num_params ;
 
8505
#else
 
8506
df_TraverseUp(
 
8507
        Widget w,
 
8508
        XEvent *event,
 
8509
        char **params,
 
8510
        Cardinal *num_params )
 
8511
#endif /* _NO_PROTO */
 
8512
{
 
8513
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8514
 
 
8515
    if (tf->primitive.navigation_type == XmNONE && df_VerifyLeave(tf, event)) {
 
8516
       XmTextF_traversed(tf) = True;
 
8517
       if (!_XmMgrTraversal(w, XmTRAVERSE_UP))
 
8518
          XmTextF_traversed(tf) = False;
 
8519
    }
 
8520
}
 
8521
 
 
8522
/* ARGSUSED */
 
8523
static void 
 
8524
#ifdef _NO_PROTO
 
8525
df_TraverseHome( w, event, params, num_params )
 
8526
        Widget w ;
 
8527
        XEvent *event ;
 
8528
        char **params ;
 
8529
        Cardinal *num_params ;
 
8530
#else
 
8531
df_TraverseHome(
 
8532
        Widget w,
 
8533
        XEvent *event,
 
8534
        char **params,
 
8535
        Cardinal *num_params )
 
8536
#endif /* _NO_PROTO */
 
8537
{
 
8538
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8539
 
 
8540
   /* Allow the verification routine to control the traversal */
 
8541
    if (tf->primitive.navigation_type == XmNONE && df_VerifyLeave(tf, event)) {
 
8542
       XmTextF_traversed(tf) = True;
 
8543
       if (!_XmMgrTraversal(w, XmTRAVERSE_HOME))
 
8544
          XmTextF_traversed(tf) = False;
 
8545
    }
 
8546
}
 
8547
 
 
8548
 
 
8549
/* ARGSUSED */
 
8550
static void 
 
8551
#ifdef _NO_PROTO
 
8552
df_TraverseNextTabGroup( w, event, params, num_params )
 
8553
        Widget w ;
 
8554
        XEvent *event ;
 
8555
        char **params ;
 
8556
        Cardinal *num_params ;
 
8557
#else
 
8558
df_TraverseNextTabGroup(
 
8559
        Widget w,
 
8560
        XEvent *event,
 
8561
        char **params,
 
8562
        Cardinal *num_params )
 
8563
#endif /* _NO_PROTO */
 
8564
{
 
8565
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8566
 
 
8567
   /* Allow the verification routine to control the traversal */
 
8568
    if (df_VerifyLeave(tf, event)) {
 
8569
       XmTextF_traversed(tf) = True;
 
8570
       if (!_XmMgrTraversal(w, XmTRAVERSE_NEXT_TAB_GROUP))
 
8571
          XmTextF_traversed(tf) = False;
 
8572
    }
 
8573
}
 
8574
 
 
8575
 
 
8576
/* ARGSUSED */
 
8577
static void 
 
8578
#ifdef _NO_PROTO
 
8579
df_TraversePrevTabGroup( w, event, params, num_params )
 
8580
        Widget w ;
 
8581
        XEvent *event ;
 
8582
        char **params ;
 
8583
        Cardinal *num_params ;
 
8584
#else
 
8585
df_TraversePrevTabGroup(
 
8586
        Widget w,
 
8587
        XEvent *event,
 
8588
        char **params,
 
8589
        Cardinal *num_params )
 
8590
#endif /* _NO_PROTO */
 
8591
{
 
8592
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8593
 
 
8594
   /* Allow the verification routine to control the traversal */
 
8595
    if (df_VerifyLeave(tf, event)) {
 
8596
       XmTextF_traversed(tf) = True;
 
8597
       if (!_XmMgrTraversal(w, XmTRAVERSE_PREV_TAB_GROUP))
 
8598
          XmTextF_traversed(tf) = False;
 
8599
    }
 
8600
}
 
8601
 
 
8602
 
 
8603
/* ARGSUSED */
 
8604
static void 
 
8605
#ifdef _NO_PROTO
 
8606
df_TextEnter( w, event, params, num_params )
 
8607
        Widget w ;
 
8608
        XEvent *event ;
 
8609
        String *params ;
 
8610
        Cardinal *num_params ;
 
8611
#else
 
8612
df_TextEnter(
 
8613
        Widget w,
 
8614
        XEvent *event,
 
8615
        String *params,
 
8616
        Cardinal *num_params )
 
8617
#endif /* _NO_PROTO */
 
8618
{
 
8619
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8620
    XmAnyCallbackStruct cb;
 
8621
    XPoint xmim_point;
 
8622
 
 
8623
    /* Use != NotifyInferior along with event->xcrossing.focus to avoid
 
8624
     * sending input method info if reason for the event is pointer moving
 
8625
     * from TextF widget to over-the-spot window (case when over-the-spot
 
8626
     * is child of TextF widget). */
 
8627
    if (_XmGetFocusPolicy(w) != XmEXPLICIT && !(XmTextF_has_focus(tf)) &&
 
8628
        event->xcrossing.focus &&
 
8629
        (event->xcrossing.detail != NotifyInferior)) {
 
8630
       if (!XmTextF_has_rect(tf)) _XmDataFieldSetClipRect(tf);
 
8631
       _XmDataFieldDrawInsertionPoint(tf, False);
 
8632
       XmTextF_blink_on(tf) = False;
 
8633
       XmTextF_has_focus(tf) = True;
 
8634
       _XmDataFToggleCursorGC(w);
 
8635
       if (XtIsSensitive(w)) df_ChangeBlinkBehavior(tf, True);
 
8636
       _XmDataFieldDrawInsertionPoint(tf, True);
 
8637
       df_GetXYFromPos(tf, XmTextF_cursor_position(tf), &xmim_point.x, 
 
8638
                    &xmim_point.y);
 
8639
       XmImVaSetFocusValues(w, XmNspotLocation, &xmim_point, NULL);
 
8640
       cb.reason = XmCR_FOCUS;
 
8641
       cb.event = event;
 
8642
       XtCallCallbackList (w, XmTextF_focus_callback(tf), (XtPointer) &cb);
 
8643
    }
 
8644
 
 
8645
    _XmPrimitiveEnter(w, event, params, num_params);
 
8646
}
 
8647
 
 
8648
 
 
8649
/* ARGSUSED */
 
8650
static void 
 
8651
#ifdef _NO_PROTO
 
8652
df_TextLeave( w, event, params, num_params )
 
8653
        Widget w ;
 
8654
        XEvent *event ;
 
8655
        String *params ;
 
8656
        Cardinal *num_params ;
 
8657
#else
 
8658
df_TextLeave(
 
8659
        Widget w,
 
8660
        XEvent *event,
 
8661
        String *params,
 
8662
        Cardinal *num_params )
 
8663
#endif /* _NO_PROTO */
 
8664
{
 
8665
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
8666
 
 
8667
   /* use detail!= NotifyInferior to handle focus change due to pointer
 
8668
    * wandering into over-the-spot input window - we don't want to change
 
8669
    * IM's focus state in this case. */
 
8670
   if (_XmGetFocusPolicy(w) != XmEXPLICIT && XmTextF_has_focus(tf) &&
 
8671
       event->xcrossing.focus &&
 
8672
       (event->xcrossing.detail != NotifyInferior)) {
 
8673
      if (tf->core.sensitive) df_ChangeBlinkBehavior(tf, False);
 
8674
      _XmDataFieldDrawInsertionPoint(tf, False);
 
8675
      XmTextF_has_focus(tf) = False;
 
8676
      _XmDataFToggleCursorGC(w);
 
8677
      XmTextF_blink_on(tf) = True;
 
8678
      _XmDataFieldDrawInsertionPoint(tf, True);
 
8679
      (void) df_VerifyLeave(tf, event);
 
8680
      XmImUnsetFocus(w);
 
8681
   }
 
8682
 
 
8683
   _XmPrimitiveLeave(w, event, params, num_params);
 
8684
}
 
8685
 
 
8686
/****************************************************************
 
8687
 *
 
8688
 * Private definitions.
 
8689
 *
 
8690
 ****************************************************************/
 
8691
 
 
8692
/*
 
8693
 * df_ClassPartInitialize sets up the fast subclassing for the widget.i
 
8694
 * It also merges translation tables.
 
8695
 */
 
8696
static void 
 
8697
#ifdef _NO_PROTO
 
8698
df_ClassPartInitialize( w_class )
 
8699
        WidgetClass w_class ;
 
8700
#else
 
8701
df_ClassPartInitialize(
 
8702
        WidgetClass w_class )
 
8703
#endif /* _NO_PROTO */
 
8704
{
 
8705
    char *event_bindings;
 
8706
 
 
8707
    _XmFastSubclassInit (w_class, XmDATAFIELD_BIT);
 
8708
 
 
8709
  /* Install traits */
 
8710
  XmeTraitSet((XtPointer) w_class, XmQTaccessTextual, (XtPointer) &dataFieldCS);
 
8711
 
 
8712
    event_bindings = (char *)XtMalloc((unsigned) (strlen(EventBindings1) +
 
8713
                                      strlen(EventBindings2) +
 
8714
                                      strlen(EventBindings3) + strlen("\n") +
 
8715
                                      strlen(df_translations) + 1));
 
8716
 
 
8717
    strcpy(event_bindings, df_translations);
 
8718
    strcat(event_bindings, "\n");
 
8719
    strcat(event_bindings, EventBindings1);
 
8720
    strcat(event_bindings, EventBindings2);
 
8721
    strcat(event_bindings, EventBindings3);
 
8722
 
 
8723
    _XmProcessLock(); 
 
8724
    w_class->core_class.tm_table = (String) XtParseTranslationTable(event_bindings);
 
8725
    _XmProcessUnlock();
 
8726
 
 
8727
    XtFree(event_bindings);
 
8728
}
 
8729
 
 
8730
/****************************************************************
 
8731
 *
 
8732
 * Private functions used in df_Initialize.
 
8733
 *
 
8734
 ****************************************************************/
 
8735
 
 
8736
/*
 
8737
 * Verify that the resource settings are valid.  Print a warning
 
8738
 * message and reset the s if the are invalid.
 
8739
 */
 
8740
static void 
 
8741
#ifdef _NO_PROTO
 
8742
df_Validates( tf )
 
8743
        XmDataFieldWidget tf ;
 
8744
#else
 
8745
df_Validates(
 
8746
        XmDataFieldWidget tf )
 
8747
#endif /* _NO_PROTO */
 
8748
{
 
8749
    XtPointer temp_ptr;
 
8750
 
 
8751
    if (XmTextF_cursor_position(tf) < 0) {
 
8752
          XmeWarning ((Widget)tf, MSG1);
 
8753
          XmTextF_cursor_position(tf) = 0;
 
8754
    }
 
8755
 
 
8756
    if (XmTextF_columns(tf) <= 0) {
 
8757
          XmeWarning ((Widget)tf, MSG2);
 
8758
          XmTextF_columns(tf) = 20;
 
8759
    }
 
8760
 
 
8761
    if (XmTextF_selection_array(tf) == NULL) 
 
8762
       XmTextF_selection_array(tf) = (XmTextScanType *) df_sarray;
 
8763
 
 
8764
    if (XmTextF_selection_array_count(tf) <= 0) 
 
8765
       XmTextF_selection_array_count(tf) = XtNumber(df_sarray);
 
8766
 
 
8767
/*
 
8768
 * Fix for HaL DTS 9841 - copy the selectionArray into dedicated memory.
 
8769
 */
 
8770
    temp_ptr = (XtPointer)XmTextF_selection_array(tf);
 
8771
    XmTextF_selection_array(tf) = NULL;
 
8772
    
 
8773
    XmTextF_selection_array(tf) = (XmTextScanType *)XtMalloc (
 
8774
                 XmTextF_selection_array_count(tf) * sizeof(XmTextScanType));
 
8775
    memcpy((void *)XmTextF_selection_array(tf), (void *)temp_ptr,
 
8776
           (XmTextF_selection_array_count(tf) * sizeof(XmTextScanType)));
 
8777
/*
 
8778
 * End fix for HaL DTS 9841
 
8779
 */
 
8780
}
 
8781
 
 
8782
static Boolean 
 
8783
#ifdef _NO_PROTO
 
8784
df_LoadFontMetrics( tf )
 
8785
        XmDataFieldWidget tf ;
 
8786
#else
 
8787
df_LoadFontMetrics(
 
8788
        XmDataFieldWidget tf )
 
8789
#endif /* _NO_PROTO */
 
8790
{
 
8791
    XmFontContext context;
 
8792
    XmFontListEntry next_entry;
 
8793
    XmFontType type_return = XmFONT_IS_FONT;
 
8794
    XtPointer tmp_font;
 
8795
    Boolean have_font_struct = False;
 
8796
    Boolean have_font_set = False;
 
8797
#ifdef USE_XFT
 
8798
    Boolean have_xft_font = False;
 
8799
#endif
 
8800
    XFontSetExtents *fs_extents;
 
8801
    XFontStruct *font;
 
8802
    unsigned long charwidth = 0;
 
8803
    char* font_tag = NULL;
 
8804
    Boolean return_val = 1; /* non-zero == success */
 
8805
 
 
8806
    if (!XmFontListInitFontContext(&context, XmTextF_font_list(tf)))
 
8807
       XmeWarning ((Widget)tf, MSG3);
 
8808
 
 
8809
    do {
 
8810
       next_entry = XmFontListNextEntry(context);
 
8811
       if (next_entry) {
 
8812
          tmp_font = XmFontListEntryGetFont(next_entry, &type_return);
 
8813
          if (type_return == XmFONT_IS_FONTSET) { 
 
8814
             font_tag = XmFontListEntryGetTag(next_entry);
 
8815
             if (!have_font_set){ /* this saves the first fontset found, just in
 
8816
                                   * case we don't find a default tag set.
 
8817
                                   */
 
8818
                XmTextF_have_fontset(tf) = True;
 
8819
#ifdef USE_XFT
 
8820
                XmTextF_use_xft(tf) = False;
 
8821
#endif
 
8822
                tf->text.font = (XFontStruct *)tmp_font;
 
8823
                have_font_struct = True; /* we have a font set, so no need to 
 
8824
                                          * consider future font structs */
 
8825
                have_font_set = True;    /* we have a font set. */
 
8826
 
 
8827
                if (!strcmp(XmFONTLIST_DEFAULT_TAG, font_tag))
 
8828
                   break; /* Break out!  We've found the one we want. */
 
8829
 
 
8830
             } else if (!strcmp(XmFONTLIST_DEFAULT_TAG, font_tag)){
 
8831
                tf->text.font = (XFontStruct *)tmp_font;
 
8832
                have_font_set = True;    /* we have a font set. */
 
8833
                break; /* Break out!  We've found the one we want. */
 
8834
             }
 
8835
          } else if (type_return == XmFONT_IS_FONT && !have_font_struct) {
 
8836
             /* return_type must be XmFONT_IS_FONT */
 
8837
             XmTextF_have_fontset(tf) = False;
 
8838
#ifdef USE_XFT
 
8839
             XmTextF_use_xft(tf) = False;
 
8840
#endif
 
8841
             tf->text.font=(XFontStruct*)tmp_font; /* save the first font
 
8842
                                                     * struct in case no font 
 
8843
                                                     * set is found */
 
8844
             have_font_struct = True;                     
 
8845
#ifdef USE_XFT
 
8846
          } else if (type_return == XmFONT_IS_XFT && !have_xft_font) {
 
8847
             XmTextF_have_fontset(tf) = False;
 
8848
             XmTextF_use_xft(tf) = True;
 
8849
             have_xft_font = True;
 
8850
             tf->text.font = tmp_font;
 
8851
#endif
 
8852
          }
 
8853
       }
 
8854
    } while(next_entry != NULL);
 
8855
 
 
8856
#if USE_XFT
 
8857
    if (!have_font_struct && !have_font_set && !have_xft_font) {
 
8858
#else
 
8859
    if (!have_font_struct && !have_font_set) {
 
8860
#endif
 
8861
          XmeWarning ((Widget)tf, MSG4);
 
8862
    }
 
8863
 
 
8864
    if (XmTextF_max_char_size(tf) > 1 && !have_font_set){
 
8865
     /*XmeWarning((Widget)tf, MSGnnn); */
 
8866
     /* printf ("You've got the wrong font baby, Uh-Huh!\n"); */
 
8867
     /* Must have a font set, as text will be rendered only with new R5 calls 
 
8868
      * If df_LoadFontMetrics is called from df_SetValues and set
 
8869
      * values will retain use of old fontlist (which is presumed correct
 
8870
      * for the current locale). */
 
8871
 
 
8872
       return_val = 0; /* tell caller that this font won't work for MB_CUR_MAX*/
 
8873
    }
 
8874
    XmFontListFreeFontContext(context);
 
8875
 
 
8876
    if(XmTextF_have_fontset(tf)){
 
8877
       fs_extents = XExtentsOfFontSet((XFontSet)XmTextF_font(tf));
 
8878
        charwidth = (unsigned long)fs_extents->max_ink_extent.width;
 
8879
       /* max_ink_extent.y is number of pixels from origin to top of
 
8880
        * rectangle (i.e. y is negative) */
 
8881
       XmTextF_font_ascent(tf) = -fs_extents->max_ink_extent.y;
 
8882
       XmTextF_font_descent(tf) = fs_extents->max_ink_extent.height +
 
8883
                               fs_extents->max_ink_extent.y;
 
8884
#ifdef USE_XFT
 
8885
    } else if (XmTextF_use_xft(tf)) {
 
8886
        charwidth = XmTextF_xft_font(tf)->max_advance_width;
 
8887
#endif
 
8888
    } else {
 
8889
       font = XmTextF_font(tf);
 
8890
       if ((!XGetFontProperty(font, XA_QUAD_WIDTH, &charwidth)) ||
 
8891
            charwidth == 0) {
 
8892
          if (font->per_char && font->min_char_or_byte2 <= '0' &&
 
8893
                                font->max_char_or_byte2 >= '0')
 
8894
              charwidth = font->per_char['0' - font->min_char_or_byte2].width;
 
8895
          else
 
8896
              charwidth = font->max_bounds.width;
 
8897
       }
 
8898
       XmTextF_font_ascent(tf) = font->max_bounds.ascent;
 
8899
       XmTextF_font_descent(tf) = font->max_bounds.descent;
 
8900
    }
 
8901
    XmTextF_average_char_width(tf) = (Dimension) charwidth;
 
8902
    return (return_val);
 
8903
}
 
8904
 
 
8905
 
 
8906
/* df_ValidateString makes the following assumption:  if MB_CUR_MAX == 1, value
 
8907
 * is a char*, otherwise value is a wchar_t*.  The Boolean "is_wchar" indicates
 
8908
 * if value points to char* or wchar_t* data.
 
8909
 *
 
8910
 * It is df_ValidateString's task to verify that "value" contains only printing
 
8911
 * characters; all others are discarded.  df_ValidateString then mallocs data
 
8912
 * to store the value and assignes it to XmTextF_value(tf) (if MB_CUR_MAX == 1)
 
8913
 * or to XmTextF_wc_value(tf) (if MB_CUR_MAX != 1), setting the opposite
 
8914
 * pointer to NULL.  It is the callers responsibility to free data before
 
8915
 * calling df_ValidateString.
 
8916
 */
 
8917
static void 
 
8918
#ifdef _NO_PROTO
 
8919
df_ValidateString( tf, value, is_wchar )
 
8920
        XmDataFieldWidget tf ;
 
8921
        char *value ;
 
8922
        Boolean is_wchar;
 
8923
#else
 
8924
df_ValidateString(
 
8925
        XmDataFieldWidget tf,
 
8926
        char *value,
 
8927
#if NeedWidePrototypes
 
8928
        int is_wchar)
 
8929
#else
 
8930
        Boolean is_wchar)
 
8931
#endif /* NeedWidePrototypes */
 
8932
#endif /* _NO_PROTO */
 
8933
{
 
8934
   /* if value is wchar_t *, must count the characters; else use strlen */
 
8935
 
 
8936
   int str_len = 0;
 
8937
   int i, j;
 
8938
   char stack_cache[400];
 
8939
 
 
8940
   if (!is_wchar) {
 
8941
      char *temp_str, *curr_str, *start_temp;
 
8942
 
 
8943
      str_len = strlen(value);
 
8944
      temp_str = (char*)XmStackAlloc((Cardinal)str_len + 1, stack_cache);
 
8945
      start_temp = temp_str;
 
8946
      curr_str = value;
 
8947
 
 
8948
      for (i = 0; i < str_len;) {
 
8949
         if (XmTextF_max_char_size(tf) == 1){
 
8950
            if (df_FindPixelLength(tf, curr_str, 1)) {
 
8951
               *temp_str = *curr_str;
 
8952
               temp_str++;
 
8953
            } else {
 
8954
               char warn_str[52];
 
8955
               sprintf(warn_str, MSG5, *curr_str);
 
8956
               XmeWarning ((Widget)tf, warn_str);
 
8957
            }
 
8958
            curr_str++;
 
8959
            i++;
 
8960
         } else {
 
8961
            wchar_t tmp[XmTextF_max_char_size(tf)+1];
 
8962
            int num_conv;
 
8963
            num_conv = mbtowc(tmp, curr_str, XmTextF_max_char_size(tf));
 
8964
            if (num_conv >= 0 && df_FindPixelLength(tf, (char*) &tmp, 1)) {
 
8965
               for (j = 0; j < num_conv; j++) {
 
8966
                  *temp_str = *curr_str;
 
8967
                  temp_str++;
 
8968
                  curr_str++;
 
8969
                  i++; 
 
8970
                }
 
8971
            } else {
 
8972
               char warn_str[52];
 
8973
               sprintf(warn_str, MSG5, *curr_str);
 
8974
               XmeWarning ((Widget)tf, warn_str);
 
8975
               curr_str++;
 
8976
               i++;
 
8977
            }
 
8978
         }
 
8979
      }
 
8980
      *temp_str = '\0';
 
8981
 
 
8982
      /* value contains validated string; now stuff it into the proper
 
8983
       * instance pointer. */
 
8984
      if (XmTextF_max_char_size(tf) == 1) {
 
8985
         XmTextF_string_length(tf) = strlen(start_temp);
 
8986
        /* malloc the space for the text value */
 
8987
         XmTextF_value(tf) = (char *) memcpy(
 
8988
                             XtMalloc((unsigned)(XmTextF_string_length(tf) + 30)),
 
8989
                               (void *)start_temp, XmTextF_string_length(tf) + 1);
 
8990
         XmTextF_size_allocd(tf) = XmTextF_string_length(tf) + 30;
 
8991
         XmTextF_wc_value(tf) = NULL;
 
8992
      } else { /* Need wchar_t* data to set as the widget's value */
 
8993
         /* count number of wchar's */
 
8994
         str_len = strlen(start_temp);
 
8995
         XmTextF_string_length(tf) = str_len;
 
8996
 
 
8997
         XmTextF_size_allocd(tf) = (XmTextF_string_length(tf) + 30)*sizeof(wchar_t);
 
8998
         XmTextF_wc_value(tf) = (wchar_t*)XtMalloc((unsigned)XmTextF_size_allocd(tf));
 
8999
         XmTextF_string_length(tf) = mbstowcs(XmTextF_wc_value(tf), start_temp,
 
9000
                                           XmTextF_string_length(tf) + 30);
 
9001
         XmTextF_value(tf) = NULL;
 
9002
      }
 
9003
      XmStackFree((char *)start_temp, stack_cache);
 
9004
   } else {  /* pointer passed points to wchar_t* data */
 
9005
      wchar_t *wc_value, *wcs_temp_str, *wcs_start_temp, *wcs_curr_str;
 
9006
      char scratch[8];
 
9007
      int new_len = 0;
 
9008
      int csize = 1;
 
9009
 
 
9010
      wc_value = (wchar_t *) value;
 
9011
      for (str_len = 0, i = 0; *wc_value != (wchar_t)0L; str_len++)
 
9012
          wc_value++; /* count number of wchars */
 
9013
      wcs_temp_str=(wchar_t *)XmStackAlloc((Cardinal)
 
9014
                                           ((str_len+1) * sizeof(wchar_t)),
 
9015
                                           stack_cache);
 
9016
      wcs_start_temp = wcs_temp_str;
 
9017
      wcs_curr_str = (wchar_t *) value;
 
9018
 
 
9019
      for (i = 0; i < str_len; i++, wcs_curr_str++) {
 
9020
         if (XmTextF_max_char_size(tf) == 1){
 
9021
            csize = wctomb(scratch, *wcs_curr_str);
 
9022
            if (csize >= 0 && df_FindPixelLength(tf, scratch, csize)) {
 
9023
               *wcs_temp_str = *wcs_curr_str;
 
9024
               wcs_temp_str++;
 
9025
               new_len++;
 
9026
            } else {
 
9027
               char warn_str[52];
 
9028
               scratch[csize]= '\0';
 
9029
               sprintf(warn_str, WC_MSG1, scratch);
 
9030
               XmeWarning ((Widget)tf, warn_str);
 
9031
            }
 
9032
         } else {
 
9033
            if (df_FindPixelLength(tf, (char*)wcs_curr_str, 1)) {
 
9034
               *wcs_temp_str = *wcs_curr_str;
 
9035
               wcs_temp_str++;
 
9036
               new_len++;
 
9037
            } else {
 
9038
               char warn_str[52];
 
9039
               csize = wctomb(scratch, *wcs_curr_str);
 
9040
               if (csize >= 0)
 
9041
                  scratch[csize]= '\0';
 
9042
               else
 
9043
                  scratch[0] = '\0';
 
9044
               sprintf(warn_str, WC_MSG1, scratch);
 
9045
               XmeWarning ((Widget)tf, warn_str);
 
9046
            }
 
9047
         }
 
9048
      } 
 
9049
      str_len = new_len;
 
9050
 
 
9051
      *wcs_temp_str = (wchar_t)0L; /* terminate with a wchar_t NULL */
 
9052
 
 
9053
      XmTextF_string_length(tf) = str_len; /* This is *wrong* if MB_CUR_MAX > 2
 
9054
                                         * with no font set... but what can
 
9055
                                         * ya do? Spec says let it dump core. */
 
9056
 
 
9057
      XmTextF_size_allocd(tf) = (str_len + 30) * sizeof(wchar_t);
 
9058
      if (XmTextF_max_char_size(tf) == 1) { /* Need to store data as char* */
 
9059
         XmTextF_value(tf) = XtMalloc((unsigned)XmTextF_size_allocd(tf));
 
9060
         (void)wcstombs(XmTextF_value(tf), wcs_start_temp, XmTextF_size_allocd(tf));
 
9061
         XmTextF_wc_value(tf) = NULL;
 
9062
      } else { /* Need to store data as wchar_t* */
 
9063
         XmTextF_wc_value(tf) = (wchar_t*)memcpy(XtMalloc((unsigned)
 
9064
                                                       XmTextF_size_allocd(tf)),
 
9065
                                                       (void*)wcs_start_temp,
 
9066
                                                       (1 + str_len) *
 
9067
                                                       sizeof(wchar_t));
 
9068
         XmTextF_value(tf) = NULL;
 
9069
      }
 
9070
      XmStackFree((char *)wcs_start_temp, stack_cache);
 
9071
   }
 
9072
}
 
9073
 
 
9074
/* The following is a hack to overcome the buggy Motif from SGI on IM */
 
9075
#if defined(__sgi)
 
9076
static void /* CR03685 */
 
9077
#ifdef _NO_PROTO
 
9078
SGI_hack_XmImRegister(w)
 
9079
  Widget w;
 
9080
#else
 
9081
SGI_hack_XmImRegister(
 
9082
  Widget w )
 
9083
#endif /* _NO_PROTO */
 
9084
{
 
9085
  _XmProcessLock();
 
9086
  w->core.widget_class = xmTextFieldWidgetClass;
 
9087
  _XmProcessUnlock();
 
9088
 
 
9089
  XmImRegister(w, NULL);
 
9090
 
 
9091
  _XmProcessLock();
 
9092
  w->core.widget_class = xmDataFieldWidgetClass;
 
9093
  _XmProcessUnlock();
 
9094
}  
 
9095
#endif
 
9096
/*
 
9097
 * df_Initialize the s in the text fields instance record.
 
9098
 */
 
9099
static void 
 
9100
#ifdef _NO_PROTO
 
9101
df_InitializeTextStruct( tf )
 
9102
        XmDataFieldWidget tf ;
 
9103
#else
 
9104
df_InitializeTextStruct(
 
9105
        XmDataFieldWidget tf )
 
9106
#endif /* _NO_PROTO */
 
9107
{
 
9108
   /* Flag used in losing focus verification to indicate that a traversal
 
9109
    * key was pressed.  Must be initialized to False.
 
9110
    */
 
9111
    Arg args[6];  /* To set initial values to input method */
 
9112
    Cardinal n = 0;
 
9113
    XPoint xmim_point;
 
9114
 
 
9115
    XmTextF_traversed(tf) = False;
 
9116
    
 
9117
    XmTextF_add_mode(tf) = False;
 
9118
    XmTextF_has_focus(tf) = False;
 
9119
    XmTextF_blink_on(tf) = True;
 
9120
    XmTextF_cursor_on(tf) = 0;
 
9121
    XmTextF_has_rect(tf) = False;
 
9122
    XmTextF_has_primary(tf) = False;
 
9123
    XmTextF_has_secondary(tf) = False;
 
9124
    XmTextF_has_destination(tf) = False;
 
9125
    XmTextF_overstrike(tf) = False;
 
9126
    XmTextF_selection_move(tf) = False;
 
9127
    XmTextF_sel_start(tf) = False;
 
9128
    XmTextF_pending_off(tf) = True;
 
9129
    XmTextF_fontlist_created(tf) = False;
 
9130
    XmTextF_cancel(tf) = False;
 
9131
    XmTextF_extending(tf) = False;
 
9132
    XmTextF_prim_time(tf) = 0;
 
9133
    XmTextF_dest_time(tf) = 0;
 
9134
    XmTextF_select_id(tf) = 0;
 
9135
    XmTextF_select_pos_x(tf) = 0;
 
9136
    XmTextF_sec_extending(tf) = False;
 
9137
    XmTextF_sec_drag(tf) = False;
 
9138
    XmTextF_changed_visible(tf) = False;
 
9139
    XmTextF_refresh_ibeam_off(tf) = True;
 
9140
    XmTextF_in_setvalues(tf) = False;
 
9141
    XmTextF_do_resize(tf) = True;
 
9142
    XmTextF_have_inverted_image_gc(tf) = False;
 
9143
    XmTextF_margin_top(tf) = XmTextF_margin_height(tf);
 
9144
    XmTextF_margin_bottom(tf) = XmTextF_margin_height(tf);
 
9145
 
 
9146
    /* copy over the font list */
 
9147
    if (XmTextF_font_list(tf) == NULL) {
 
9148
       XmTextF_font_list(tf) = XmeGetDefaultRenderTable((Widget)tf,
 
9149
                                              (unsigned char) XmTEXT_FONTLIST);
 
9150
       XmTextF_fontlist_created(tf) = True;
 
9151
    }
 
9152
 
 
9153
    XmTextF_font_list(tf) = (XmFontList)XmFontListCopy(XmTextF_font_list(tf));
 
9154
 
 
9155
    XmTextF_max_char_size(tf) = MB_CUR_MAX;
 
9156
 
 
9157
    (void)df_LoadFontMetrics(tf);
 
9158
 
 
9159
    XmTextF_gc(tf) = NULL;
 
9160
    XmTextF_image_gc(tf) = NULL;
 
9161
    XmTextF_save_gc(tf) = NULL;
 
9162
 
 
9163
    if (XmDataField_alignment(tf) == XmALIGNMENT_END)
 
9164
        XmTextF_new_h_offset(tf) = XmTextF_h_offset(tf) = 0;
 
9165
    else
 
9166
        XmTextF_new_h_offset(tf) = XmTextF_h_offset(tf) = XmTextF_margin_width(tf) +
 
9167
            tf->primitive.shadow_thickness + tf->primitive.highlight_thickness;
 
9168
 
 
9169
    /* df_ValidateString will verify value contents, convert to appropriate
 
9170
     * storage form (i.e. char* or wchar_t*), place in the appropriate
 
9171
     * location (text.value or text.wc_value), and null out opposite
 
9172
     * pointer.  */
 
9173
 
 
9174
    if (XmTextF_wc_value(tf) != NULL) { /* XmNvalueWcs was set - it rules */
 
9175
       XmTextF_value(tf) = NULL;
 
9176
       df_ValidateString(tf, (char*)XmTextF_wc_value(tf), True);
 
9177
    } else if (XmTextF_value(tf) != NULL)
 
9178
       df_ValidateString(tf, XmTextF_value(tf), False);
 
9179
    else /* XmTextF_value(tf) is null pointer */
 
9180
       df_ValidateString(tf, "", False);
 
9181
 
 
9182
    if (XmTextF_cursor_position(tf) > XmTextF_string_length(tf))
 
9183
       XmTextF_cursor_position(tf) = XmTextF_string_length(tf);
 
9184
 
 
9185
    XmTextF_orig_left(tf) = XmTextF_orig_right(tf) = XmTextF_prim_pos_left(tf) =
 
9186
     XmTextF_prim_pos_right(tf) = XmTextF_prim_anchor(tf) = XmTextF_cursor_position(tf);
 
9187
 
 
9188
    XmTextF_sec_pos_left(tf) = XmTextF_sec_pos_right(tf) =
 
9189
        XmTextF_sec_anchor(tf) = XmTextF_cursor_position(tf);
 
9190
 
 
9191
    XmTextF_stuff_pos(tf) = XmTextF_cursor_position(tf);
 
9192
 
 
9193
    XmTextF_cursor_height(tf) = XmTextF_cursor_width(tf) = 0;
 
9194
    XmTextF_stipple_tile(tf) = None;
 
9195
    XmTextF_add_mode_cursor(tf) = XmUNSPECIFIED_PIXMAP;
 
9196
    XmTextF_cursor(tf) = XmUNSPECIFIED_PIXMAP;
 
9197
    XmTextF_ibeam_off(tf) = XmUNSPECIFIED_PIXMAP;
 
9198
    XmTextF_image_clip(tf) = XmUNSPECIFIED_PIXMAP;
 
9199
 
 
9200
    XmTextF_last_time(tf) = 0;
 
9201
 
 
9202
    XmTextF_sarray_index(tf) = 0;
 
9203
 
 
9204
   /* df_Initialize highlight elements */
 
9205
    XmTextF_highlight(tf).number = XmTextF_highlight(tf).maximum = 1;
 
9206
    XmTextF_highlight(tf).list = (_XmHighlightRec *)XtMalloc((unsigned)
 
9207
                                                 sizeof(_XmHighlightRec));
 
9208
    XmTextF_highlight(tf).list[0].position = 0;
 
9209
    XmTextF_highlight(tf).list[0].mode = XmHIGHLIGHT_NORMAL;
 
9210
 
 
9211
    XmTextF_timer_id(tf) = (XtIntervalId)0;
 
9212
 
 
9213
    if(XmDataField_picture_source(tf)) {
 
9214
        XmDataField_picture_source(tf) = XtNewString(XmDataField_picture_source(tf));
 
9215
        XmDataField_picture(tf) = XmParsePicture(XmDataField_picture_source(tf));
 
9216
        XtAddCallback((Widget)tf, XmNmodifyVerifyCallback,
 
9217
                          PictureVerifyCallback, NULL);
 
9218
    } else {
 
9219
        /* No picture specified */
 
9220
        XmDataField_picture(tf) = NULL;
 
9221
    }
 
9222
 
 
9223
    XmDataFieldSetEditable((Widget)tf, XmTextF_editable(tf));
 
9224
 
 
9225
    if (XmTextF_editable(tf)){
 
9226
#if defined(__sgi)
 
9227
      /* CR03685 */
 
9228
      SGI_hack_XmImRegister((Widget)tf);
 
9229
#else
 
9230
      XmImRegister((Widget)tf, (unsigned int) NULL);
 
9231
#endif
 
9232
      df_GetXYFromPos(tf, XmTextF_cursor_position(tf), &xmim_point.x, &xmim_point.y);
 
9233
      n = 0;
 
9234
      XtSetArg(args[n], XmNfontList, XmTextF_font_list(tf)); n++;
 
9235
      XtSetArg(args[n], XmNbackground, tf->core.background_pixel); n++;
 
9236
      XtSetArg(args[n], XmNforeground, tf->primitive.foreground); n++;
 
9237
      XtSetArg(args[n], XmNbackgroundPixmap,tf->core.background_pixmap);n++;
 
9238
      XtSetArg(args[n], XmNspotLocation, &xmim_point); n++;
 
9239
      XtSetArg(args[n], XmNlineSpace, 
 
9240
               XmTextF_font_ascent(tf)+ XmTextF_font_descent(tf)); n++;
 
9241
      XmImSetValues((Widget)tf, args, n);
 
9242
    }
 
9243
}
 
9244
 
 
9245
static Pixmap 
 
9246
#ifdef _NO_PROTO
 
9247
df_GetClipMask( tf, pixmap_name)
 
9248
        XmDataFieldWidget tf ;
 
9249
        char *pixmap_name ;
 
9250
#else
 
9251
df_GetClipMask(
 
9252
        XmDataFieldWidget tf,
 
9253
        char *pixmap_name)
 
9254
#endif /* _NO_PROTO */
 
9255
{
 
9256
   Display *dpy = XtDisplay(tf);
 
9257
   Screen *screen = XtScreen(tf);
 
9258
   XGCValues values;
 
9259
   GC fillGC;
 
9260
   Pixmap clip_mask;
 
9261
 
 
9262
   clip_mask = XCreatePixmap(dpy, RootWindowOfScreen(screen), 
 
9263
                             XmTextF_cursor_width(tf), XmTextF_cursor_height(tf), 1);
 
9264
 
 
9265
   values.foreground = 1;
 
9266
   values.background = 0;
 
9267
   fillGC = XCreateGC(dpy, clip_mask, GCForeground | GCBackground, &values);
 
9268
 
 
9269
   XFillRectangle(dpy, clip_mask, fillGC, 0, 0, XmTextF_cursor_width(tf),
 
9270
                  XmTextF_cursor_height(tf));
 
9271
 
 
9272
  /* Install the clipmask for pixmap caching */
 
9273
   (void) _XmCachePixmap(clip_mask, screen, pixmap_name, 1, 0, 0, 0, 0);
 
9274
 
 
9275
   XFreeGC(XtDisplay(tf), fillGC);
 
9276
 
 
9277
   return(clip_mask);
 
9278
}
 
9279
 
 
9280
/*
 
9281
 * Get the graphics context for filling the background, and for drawing
 
9282
 * and inverting text.  Used a unique pixmap so all text field widgets
 
9283
 * share common GCs.
 
9284
 */
 
9285
static void 
 
9286
#ifdef _NO_PROTO
 
9287
df_LoadGCs( tf, background, foreground )
 
9288
        XmDataFieldWidget tf ;
 
9289
        Pixel background ;
 
9290
        Pixel foreground ;
 
9291
#else
 
9292
df_LoadGCs(
 
9293
        XmDataFieldWidget tf,
 
9294
        Pixel background,
 
9295
        Pixel foreground )
 
9296
#endif /* _NO_PROTO */
 
9297
{
 
9298
   Display *display = XtDisplay((Widget)tf);
 
9299
   Screen *screen = XtScreen((Widget)tf);
 
9300
   XGCValues values;
 
9301
   static XContext context = 0;
 
9302
   static Pixmap tf_cache_pixmap;
 
9303
   unsigned long value_mask = (GCFunction | GCForeground | GCBackground | 
 
9304
                              GCClipMask | GCArcMode);
 
9305
   unsigned long dynamic_mask;
 
9306
 
 
9307
   if (XmTextF_stipple_tile(tf) != None)
 
9308
       XmDestroyPixmap(XtScreen(tf), XmTextF_stipple_tile(tf));
 
9309
       
 
9310
   XmTextF_stipple_tile(tf) = (Pixmap)
 
9311
       XmGetPixmapByDepth(XtScreen(tf),"50_foreground",
 
9312
                          tf->primitive.foreground, tf->core.background_pixel,
 
9313
                          tf->core.depth);
 
9314
 
 
9315
   if (context == 0)
 
9316
      context = XUniqueContext();
 
9317
 
 
9318
   if (XFindContext(display, (Window)screen, 
 
9319
                    context, (char **) &tf_cache_pixmap)){
 
9320
     XmTextContextData ctx_data;
 
9321
     Widget xm_display = (Widget) XmGetXmDisplay(display);
 
9322
 
 
9323
     ctx_data = (XmTextContextData) XtMalloc(sizeof(XmTextContextDataRec));
 
9324
 
 
9325
     ctx_data->screen = screen;
 
9326
     ctx_data->context = context;
 
9327
     ctx_data->type = _XM_IS_PIXMAP_CTX;
 
9328
 
 
9329
    /* Get the Pixmap identifier that the X Toolkit uses to cache our */
 
9330
    /* GC's.  We never actually use this Pixmap; just so long as it's */
 
9331
    /* a unique identifier. */
 
9332
     tf_cache_pixmap =  XCreatePixmap(display,
 
9333
                                     (Drawable) RootWindowOfScreen(screen),
 
9334
                                     (unsigned int) 1, (unsigned int) 1,
 
9335
                                     (unsigned int) 1);
 
9336
 
 
9337
     XtAddCallback(xm_display, XmNdestroyCallback, 
 
9338
                   (XtCallbackProc) df_FreeContextData, (XtPointer) ctx_data);
 
9339
 
 
9340
     XSaveContext(display, (Window)screen, context, (XPointer) tf_cache_pixmap);
 
9341
   }
 
9342
 
 
9343
   /* Used to be: values.clip_mask = tf_cache_pixmap; */
 
9344
   values.clip_mask = 0;    /* use in caching Text Field gc's */
 
9345
   values.arc_mode = ArcPieSlice; /* Used in differentiating from Text
 
9346
                                     widget GC caching */
 
9347
 
 
9348
   if (XmTextF_has_rect(tf)) {
 
9349
      TextFGCData gc_data = df_GetTextFGCData((Widget)tf);
 
9350
      XmTextF_has_rect(gc_data->tf) = False;
 
9351
      gc_data->tf = NULL;
 
9352
   }
 
9353
 
 
9354
  /*
 
9355
   * Get GC for saving area under the cursor.
 
9356
   */
 
9357
   values.function = GXcopy;
 
9358
   values.foreground = tf->primitive.foreground ;
 
9359
   values.background = tf->core.background_pixel;
 
9360
   if (XmTextF_save_gc(tf) != NULL)
 
9361
       XtReleaseGC((Widget)tf, XmTextF_save_gc(tf)); 
 
9362
   dynamic_mask = (GCClipMask);
 
9363
   XmTextF_save_gc(tf) = XtAllocateGC((Widget) tf,
 
9364
        tf->core.depth, value_mask,
 
9365
        &values, dynamic_mask, 0); 
 
9366
 
 
9367
   df_XmResetSaveGC(tf, XmTextF_save_gc(tf));
 
9368
  /*
 
9369
   * Get GC for drawing text.
 
9370
   */
 
9371
 
 
9372
#if USE_XFT
 
9373
   if (!XmTextF_have_fontset(tf) && !XmTextF_use_xft(tf)) {
 
9374
#else
 
9375
   if (!XmTextF_have_fontset(tf)) {
 
9376
#endif
 
9377
      value_mask |= GCFont | GCGraphicsExposures;
 
9378
      values.font = XmTextF_font(tf)->fid;
 
9379
   } else {
 
9380
      value_mask |= GCGraphicsExposures;
 
9381
   }
 
9382
   values.graphics_exposures = (Bool) TRUE;
 
9383
   values.foreground = foreground ^ background;
 
9384
   values.background = 0;
 
9385
   if (XmTextF_gc(tf) != NULL)
 
9386
        XtReleaseGC((Widget)tf, XmTextF_gc(tf)); 
 
9387
   dynamic_mask |=  GCForeground | GCBackground | GCFillStyle | GCTile;
 
9388
   XmTextF_gc(tf) = XtAllocateGC((Widget) tf,
 
9389
        tf->core.depth, value_mask,
 
9390
        &values, dynamic_mask, 0); 
 
9391
 
 
9392
   /* Create a temporary GC - change it later in make IBEAM */
 
9393
   value_mask |= GCTile;
 
9394
   values.tile = XmTextF_stipple_tile(tf);
 
9395
   if (XmTextF_image_gc(tf) != NULL)
 
9396
        XtReleaseGC((Widget)tf, XmTextF_image_gc(tf)); 
 
9397
   dynamic_mask = (GCForeground | GCBackground | GCStipple | GCFillStyle |
 
9398
                   GCTileStipXOrigin | GCTileStipYOrigin | GCFunction |
 
9399
                   GCClipMask | GCClipXOrigin | GCClipYOrigin);
 
9400
   XmTextF_image_gc(tf) = XtAllocateGC((Widget) tf,
 
9401
                           tf->core.depth, value_mask,
 
9402
                           &values, dynamic_mask, 0); 
 
9403
 
 
9404
}
 
9405
 
 
9406
static void 
 
9407
#ifdef _NO_PROTO
 
9408
df_MakeIBeamOffArea( tf, width, height )
 
9409
        XmDataFieldWidget tf ;
 
9410
        Dimension width ;
 
9411
        Dimension height ;
 
9412
#else
 
9413
df_MakeIBeamOffArea(
 
9414
        XmDataFieldWidget tf,
 
9415
#if NeedWidePrototypes
 
9416
        int width,
 
9417
        int height)
 
9418
#else
 
9419
        Dimension width,
 
9420
        Dimension height)
 
9421
#endif /* NeedWidePrototypes */
 
9422
#endif /* _NO_PROTO */
 
9423
{
 
9424
   Display *dpy = XtDisplay(tf);
 
9425
   Screen  *screen = XtScreen(tf);
 
9426
   GC fillGC;
 
9427
 
 
9428
  /* Create a pixmap for storing the screen data where the I-Beam will 
 
9429
   * be painted */
 
9430
 
 
9431
   XmTextF_ibeam_off(tf) = XCreatePixmap(dpy, RootWindowOfScreen(screen), width,
 
9432
                                      height, tf->core.depth);
 
9433
 
 
9434
  /* Create a GC for drawing 0's into the pixmap */
 
9435
   fillGC = XCreateGC(dpy, XmTextF_ibeam_off(tf), 0, (XGCValues *) NULL);
 
9436
 
 
9437
  /* df_Initialize the pixmap to 0's */
 
9438
   XFillRectangle(dpy, XmTextF_ibeam_off(tf), fillGC, 0, 0, width, height);
 
9439
 
 
9440
  /* Free the GC */
 
9441
   XFreeGC(XtDisplay(tf), fillGC);
 
9442
}
 
9443
 
 
9444
static void 
 
9445
#ifdef _NO_PROTO
 
9446
df_MakeIBeamStencil( tf, line_width )
 
9447
        XmDataFieldWidget tf ;
 
9448
        int line_width ;
 
9449
#else
 
9450
df_MakeIBeamStencil(
 
9451
        XmDataFieldWidget tf,
 
9452
        int line_width )
 
9453
#endif /* _NO_PROTO */
 
9454
{
 
9455
   Screen *screen = XtScreen(tf);
 
9456
   char pixmap_name[17];
 
9457
   XGCValues values;
 
9458
   unsigned long valuemask;
 
9459
 
 
9460
   if (!XmTextF_has_rect(tf)) _XmDataFieldSetClipRect(tf);
 
9461
   sprintf(pixmap_name, "_XmDataF_%d_%d", XmTextF_cursor_height(tf), line_width);
 
9462
   XmTextF_cursor(tf) = (Pixmap) XmGetPixmapByDepth(screen, pixmap_name, 1, 0, 1);
 
9463
 
 
9464
   if (XmTextF_cursor(tf) == XmUNSPECIFIED_PIXMAP) {
 
9465
      Display *dpy = XtDisplay(tf);
 
9466
      GC fillGC;
 
9467
      XSegment segments[3];
 
9468
      XRectangle ClipRect;
 
9469
 
 
9470
     /* Create a pixmap for the I-Beam stencil */
 
9471
      XmTextF_cursor(tf) = XCreatePixmap(dpy, XtWindow(tf), XmTextF_cursor_width(tf),
 
9472
                                      XmTextF_cursor_height(tf), 1);
 
9473
 
 
9474
     /* Create a GC for "cutting out" the I-Beam shape from the pixmap in
 
9475
      * order to create the stencil.
 
9476
      */
 
9477
      fillGC = XCreateGC(dpy, XmTextF_cursor(tf), 0, (XGCValues *)NULL);
 
9478
 
 
9479
     /* Fill in the stencil with a solid in preparation
 
9480
      * to "cut out" the I-Beam
 
9481
      */
 
9482
      XFillRectangle(dpy, XmTextF_cursor(tf), fillGC, 0, 0, XmTextF_cursor_width(tf),
 
9483
                     XmTextF_cursor_height(tf));
 
9484
 
 
9485
     /* Change the GC for use in "cutting out" the I-Beam shape */
 
9486
      values.foreground = 1;
 
9487
      values.line_width = line_width;
 
9488
      XChangeGC(dpy, fillGC, GCForeground | GCLineWidth, &values);
 
9489
 
 
9490
     /* Draw the segments of the I-Beam */
 
9491
     /* 1st segment is the top horizontal line of the 'I' */
 
9492
      segments[0].x1 = 0;
 
9493
      segments[0].y1 = line_width - 1;
 
9494
      segments[0].x2 = XmTextF_cursor_width(tf);
 
9495
      segments[0].y2 = line_width - 1;
 
9496
 
 
9497
     /* 2nd segment is the bottom horizontal line of the 'I' */
 
9498
      segments[1].x1 = 0;
 
9499
      segments[1].y1 = XmTextF_cursor_height(tf) - 1;
 
9500
      segments[1].x2 = XmTextF_cursor_width(tf);
 
9501
      segments[1].y2 = XmTextF_cursor_height(tf) - 1;
 
9502
 
 
9503
     /* 3rd segment is the vertical line of the 'I' */
 
9504
      segments[2].x1 = XmTextF_cursor_width(tf) >> 1;
 
9505
      segments[2].y1 = line_width;
 
9506
      segments[2].x2 = XmTextF_cursor_width(tf) >> 1;
 
9507
      segments[2].y2 = XmTextF_cursor_height(tf) - 1;
 
9508
 
 
9509
     /* Set the clipping rectangle of the image GC from drawing */
 
9510
      ClipRect.width = XmTextF_cursor_width(tf);
 
9511
      ClipRect.height = XmTextF_cursor_height(tf);
 
9512
      ClipRect.x = 0;
 
9513
      ClipRect.y = 0;
 
9514
 
 
9515
      XSetClipRectangles(XtDisplay(tf), fillGC, 0, 0, &ClipRect, 1, Unsorted);
 
9516
 
 
9517
     /* Draw the segments onto the cursor */
 
9518
      XDrawSegments(dpy, XmTextF_cursor(tf), fillGC, segments, 3);
 
9519
 
 
9520
    /* Install the cursor for pixmap caching */
 
9521
      (void) _XmCachePixmap(XmTextF_cursor(tf), XtScreen(tf), pixmap_name, 1, 0, 0, 0, 0);
 
9522
 
 
9523
     /* Free the fill GC */
 
9524
      XFreeGC(XtDisplay(tf), fillGC);
 
9525
   }
 
9526
 
 
9527
  /* Get/create the image_gc used to paint the I-Beam */
 
9528
 
 
9529
    sprintf(pixmap_name, "_XmText_CM_%d", XmTextF_cursor_height(tf));
 
9530
    XmTextF_image_clip(tf) = XmGetPixmapByDepth(XtScreen(tf), pixmap_name,
 
9531
                                             1, 0, 1);
 
9532
    if (XmTextF_image_clip(tf) == XmUNSPECIFIED_PIXMAP)
 
9533
       XmTextF_image_clip(tf) = df_GetClipMask(tf, pixmap_name);
 
9534
 
 
9535
    valuemask = (GCClipMask | GCStipple | GCForeground | GCBackground | 
 
9536
                 GCFillStyle);
 
9537
    if (!XmTextF_overstrike(tf)) {
 
9538
      values.foreground = tf->primitive.foreground;
 
9539
      values.background = tf->core.background_pixel;
 
9540
    } else 
 
9541
      values.background = values.foreground = 
 
9542
        tf->core.background_pixel ^ tf->primitive.foreground;
 
9543
    values.clip_mask = XmTextF_image_clip(tf);
 
9544
    values.stipple = XmTextF_cursor(tf);
 
9545
    values.fill_style = FillStippled;
 
9546
    XChangeGC(XtDisplay(tf), XmTextF_image_gc(tf), valuemask, &values);
 
9547
 
 
9548
}
 
9549
 
 
9550
 
 
9551
/* The IBeam Stencil must have already been created before this routine
 
9552
 * is called.
 
9553
 */
 
9554
 
 
9555
static void 
 
9556
#ifdef _NO_PROTO
 
9557
df_MakeAddModeCursor( tf, line_width )
 
9558
        XmDataFieldWidget tf ;
 
9559
        int line_width ;
 
9560
#else
 
9561
df_MakeAddModeCursor(
 
9562
        XmDataFieldWidget tf,
 
9563
        int line_width )
 
9564
#endif /* _NO_PROTO */
 
9565
{
 
9566
   Screen *screen = XtScreen(tf);
 
9567
   char pixmap_name[25];
 
9568
 
 
9569
   if (!XmTextF_has_rect(tf)) _XmDataFieldSetClipRect(tf);
 
9570
   sprintf(pixmap_name, "_XmDataF_AddMode_%d_%d",
 
9571
           XmTextF_cursor_height(tf), line_width);
 
9572
 
 
9573
   XmTextF_add_mode_cursor(tf) = (Pixmap) XmGetPixmapByDepth(screen, pixmap_name,
 
9574
                                                          1, 0, 1);
 
9575
 
 
9576
   if (XmTextF_add_mode_cursor(tf) == XmUNSPECIFIED_PIXMAP) {
 
9577
      GC fillGC;
 
9578
      XtGCMask  valueMask;
 
9579
      XGCValues values;
 
9580
      unsigned int pix_width, pix_height, unused;
 
9581
      Display *dpy = XtDisplay(tf);
 
9582
      Pixmap stipple;
 
9583
      XImage *image;
 
9584
      Pixmap pixmap;
 
9585
      int unused_origin;
 
9586
      Window    root;
 
9587
      
 
9588
      pixmap =  XmGetPixmapByDepth(screen, "50_foreground",
 
9589
                                   1, 0, 1);
 
9590
      
 
9591
      if (pixmap != XmUNSPECIFIED_PIXMAP) {
 
9592
        XGetGeometry(XtDisplay(tf), pixmap, &root, &unused_origin, 
 
9593
                     &unused_origin, &pix_width, &pix_height, 
 
9594
                     &unused, &unused);
 
9595
        image = XGetImage(XtDisplay(tf), (Drawable)pixmap, 0, 0,
 
9596
                          pix_width, pix_height, AllPlanes,
 
9597
                          XYPixmap);
 
9598
                        
 
9599
 
 
9600
        stipple = XCreatePixmap(dpy, XtWindow(tf), 
 
9601
                                image->width, image->height,1);
 
9602
 
 
9603
        XmTextF_add_mode_cursor(tf) =  XCreatePixmap(dpy, XtWindow(tf),
 
9604
                                                     XmTextF_cursor_width(tf),
 
9605
                                                     XmTextF_cursor_height(tf), 
 
9606
                                                     1);
 
9607
 
 
9608
        fillGC = XCreateGC(dpy, XmTextF_add_mode_cursor(tf), 0, 
 
9609
                           (XGCValues *)NULL);
 
9610
 
 
9611
        XPutImage(dpy, stipple, fillGC, image, 0, 0, 0, 0, image->width, 
 
9612
                  image->height);
 
9613
 
 
9614
        XCopyArea(dpy, XmTextF_cursor(tf), XmTextF_add_mode_cursor(tf), 
 
9615
                  fillGC, 0, 0, XmTextF_cursor_width(tf), 
 
9616
                  XmTextF_cursor_height(tf), 0, 0);
 
9617
 
 
9618
        valueMask = (GCTile | GCFillStyle | GCForeground |
 
9619
                     GCBackground | GCFunction);
 
9620
        values.function = GXand;
 
9621
        values.tile = stipple;
 
9622
        values.fill_style = FillTiled;
 
9623
        values.foreground = tf->primitive.foreground; 
 
9624
        values.background = tf->core.background_pixel;
 
9625
 
 
9626
        XChangeGC(XtDisplay(tf), fillGC, valueMask, &values);
 
9627
 
 
9628
        XFillRectangle(dpy, XmTextF_add_mode_cursor(tf), fillGC,
 
9629
                       0, 0, XmTextF_cursor_width(tf), 
 
9630
                       XmTextF_cursor_height(tf));
 
9631
 
 
9632
        /* Install the pixmap for pixmap caching */
 
9633
        _XmCachePixmap(XmTextF_add_mode_cursor(tf),
 
9634
                         XtScreen(tf), pixmap_name, 1, 0, 0, 0, 0);
 
9635
 
 
9636
        XFreePixmap(dpy, stipple);
 
9637
        XFreeGC(dpy, fillGC);
 
9638
     }
 
9639
  }
 
9640
}
 
9641
 
 
9642
static void 
 
9643
#ifdef _NO_PROTO
 
9644
df_MakeCursors( tf )
 
9645
        XmDataFieldWidget tf ;
 
9646
#else
 
9647
df_MakeCursors(
 
9648
        XmDataFieldWidget tf )
 
9649
#endif /* _NO_PROTO */
 
9650
{
 
9651
   Screen *screen = XtScreen(tf);
 
9652
   int line_width = 1;
 
9653
 
 
9654
   if (!XtIsRealized((Widget) tf)) return;
 
9655
 
 
9656
   XmTextF_cursor_width(tf) = 5;
 
9657
   XmTextF_cursor_height(tf) = XmTextF_font_ascent(tf) + XmTextF_font_descent(tf);
 
9658
 
 
9659
  /* setup parameters to make a thicker I-Beam */
 
9660
   if (XmTextF_cursor_height(tf) > 19) {
 
9661
      XmTextF_cursor_width(tf)++;
 
9662
      line_width = 2;
 
9663
   }
 
9664
 
 
9665
  /* Remove old ibeam off area */
 
9666
   if (XmTextF_ibeam_off(tf) != XmUNSPECIFIED_PIXMAP)
 
9667
      XFreePixmap(XtDisplay((Widget)tf), XmTextF_ibeam_off(tf));
 
9668
 
 
9669
  /* Remove old insert cursor */
 
9670
   if (XmTextF_cursor(tf) != XmUNSPECIFIED_PIXMAP) {
 
9671
       (void) XmDestroyPixmap(screen, XmTextF_cursor(tf));
 
9672
       XmTextF_cursor(tf) = XmUNSPECIFIED_PIXMAP;
 
9673
   }
 
9674
 
 
9675
  /* Remove old add mode cursor */
 
9676
   if (XmTextF_add_mode_cursor(tf) != XmUNSPECIFIED_PIXMAP) {
 
9677
       (void) XmDestroyPixmap(screen, XmTextF_add_mode_cursor(tf));
 
9678
       XmTextF_add_mode_cursor(tf) = XmUNSPECIFIED_PIXMAP;
 
9679
   }
 
9680
 
 
9681
  /* Remove old image_clip pixmap */
 
9682
   if (XmTextF_image_clip(tf) != XmUNSPECIFIED_PIXMAP) {
 
9683
       (void) XmDestroyPixmap(screen, XmTextF_image_clip(tf));
 
9684
       XmTextF_image_clip(tf) = XmUNSPECIFIED_PIXMAP;
 
9685
   }
 
9686
 
 
9687
  /* Create area in which to save text located underneath I beam */
 
9688
   df_MakeIBeamOffArea(tf, MAX(XmTextF_cursor_height(tf)>>1, XmTextF_cursor_height(tf)),
 
9689
                    XmTextF_cursor_height(tf));
 
9690
 
 
9691
  /* Create a new i-beam cursor */
 
9692
   df_MakeIBeamStencil(tf, line_width);
 
9693
 
 
9694
  /* Create a new add_mode cursor */
 
9695
   df_MakeAddModeCursor(tf, line_width);
 
9696
 
 
9697
   df_ResetClipOrigin(tf, False);
 
9698
 
 
9699
   if (XmTextF_overstrike(tf))
 
9700
     XmTextF_cursor_width(tf) = XmTextF_cursor_height(tf) >> 1;
 
9701
}
 
9702
 
 
9703
/* ARGSUSED */
 
9704
static void
 
9705
#ifdef _NO_PROTO
 
9706
df_DropDestroyCB(w, clientData, callData)
 
9707
    Widget      w;
 
9708
    XtPointer   clientData;
 
9709
    XtPointer   callData;
 
9710
#else
 
9711
df_DropDestroyCB(
 
9712
    Widget      w,
 
9713
    XtPointer   clientData,
 
9714
    XtPointer   callData )
 
9715
#endif /* NO_PROTO */
 
9716
{
 
9717
    df_DeleteDropContext(w);
 
9718
    XtFree((char *)clientData);
 
9719
}
 
9720
 
 
9721
 
 
9722
/* ARGSUSED */
 
9723
static void
 
9724
#ifdef _NO_PROTO
 
9725
df_DropTransferCallback( w, closure, seltype, type, value, length, format )
 
9726
        Widget w ;
 
9727
        XtPointer closure ;
 
9728
        Atom *seltype ;
 
9729
        Atom *type ;
 
9730
        XtPointer value ;
 
9731
        unsigned long *length ;
 
9732
        int *format ;
 
9733
#else
 
9734
df_DropTransferCallback(
 
9735
        Widget w,
 
9736
        XtPointer closure,
 
9737
        Atom *seltype,
 
9738
        Atom *type,
 
9739
        XtPointer value,
 
9740
        unsigned long *length,
 
9741
        int *format )
 
9742
#endif /* _NO_PROTO */
 
9743
{
 
9744
    _XmTextDropTransferRec *transfer_rec = (_XmTextDropTransferRec *) closure;
 
9745
    XmDataFieldWidget tf = (XmDataFieldWidget) transfer_rec->widget;
 
9746
    Atom COMPOUND_TEXT = XmInternAtom(XtDisplay(w), "COMPOUND_TEXT", False);
 
9747
#ifdef UTF8_SUPPORTED
 
9748
    Atom UTF8_STRING = XmInternAtom(XtDisplay(w), XmSUTF8_STRING, False);
 
9749
#endif
 
9750
    Atom CS_OF_LOCALE;
 
9751
    XmTextPosition insertPosLeft, insertPosRight, left, right, cursorPos;
 
9752
    int max_length = 0;
 
9753
    Boolean local = XmTextF_has_primary(tf);
 
9754
    char * total_tmp_value;
 
9755
    wchar_t * wc_total_tmp_value;
 
9756
    char ** tmp_value;
 
9757
    int malloc_size = 0;
 
9758
    int num_vals, status;
 
9759
    Arg args[8];
 
9760
    Cardinal n, i;
 
9761
    unsigned long total_length = 0;
 
9762
    char * tmp_string = "ABC";  /* these are characters in XPCS, so... safe */
 
9763
    XTextProperty tmp_prop;
 
9764
    Boolean replace = False;
 
9765
    XmAnyCallbackStruct cb;
 
9766
 
 
9767
   /* When type = NULL, we are assuming a DELETE request has been requested */
 
9768
    if (*type == XmInternAtom(XtDisplay(transfer_rec->widget), "NULL", False)) {
 
9769
       if (transfer_rec->num_chars > 0 && transfer_rec->move) {
 
9770
          XmTextF_prim_anchor(tf) = transfer_rec->insert_pos;
 
9771
          cursorPos = transfer_rec->insert_pos + transfer_rec->num_chars;
 
9772
          _XmDataFielddf_SetCursorPosition(tf, NULL, cursorPos,
 
9773
                                        False, True);
 
9774
          (void) df_SetDestination((Widget)tf, XmTextF_cursor_position(tf),
 
9775
                                False, transfer_rec->timestamp);
 
9776
          XmDataFieldSetSelection((Widget)tf, XmTextF_prim_anchor(tf),
 
9777
                                  XmTextF_cursor_position(tf),
 
9778
                                  transfer_rec->timestamp);
 
9779
       }
 
9780
       if (value) {
 
9781
          XtFree((char *)value);
 
9782
          value = NULL;
 
9783
       }
 
9784
       return;
 
9785
    }
 
9786
 
 
9787
    status = XmbTextListToTextProperty(XtDisplay(transfer_rec->widget),
 
9788
                                      &tmp_string, 1,
 
9789
                                      (XICCEncodingStyle)XTextStyle, &tmp_prop);
 
9790
    if (status == Success)
 
9791
       CS_OF_LOCALE = tmp_prop.encoding;
 
9792
    else
 
9793
       CS_OF_LOCALE = 99999; /* XmbTextList... should never fail for XPCS
 
9794
                              * characters.  But just in case someones
 
9795
                              * Xlib is broken, this prevents a core dump.
 
9796
                              */
 
9797
 
 
9798
    if (tmp_prop.value != NULL) XFree((char *)tmp_prop.value);
 
9799
 
 
9800
    if (!value || (*type != CS_OF_LOCALE && *type != COMPOUND_TEXT
 
9801
#ifdef UTF8_SUPPORTED
 
9802
                   && *type != XA_STRING && *type != UTF8_STRING
 
9803
#endif
 
9804
    )) {
 
9805
        n = 0;
 
9806
        XtSetArg(args[n], XmNtransferStatus, XmTRANSFER_FAILURE); n++;
 
9807
        XtSetArg(args[n], XmNnumDropTransfers, 0); n++;
 
9808
        XtSetValues(w, args, n);
 
9809
        if (value) {
 
9810
           XtFree((char *)value);
 
9811
           value = NULL;
 
9812
        }
 
9813
        return;
 
9814
    }
 
9815
 
 
9816
    insertPosLeft = insertPosRight = transfer_rec->insert_pos;
 
9817
 
 
9818
    if (*type == XA_STRING || *type == COMPOUND_TEXT
 
9819
#ifdef UTF8_SUPPORTED
 
9820
            || *type == UTF8_STRING
 
9821
#endif
 
9822
    ) {
 
9823
       /* value NEEDS TO BE FREED */
 
9824
       tmp_prop.value = (unsigned char *) value; 
 
9825
       tmp_prop.encoding = *type;
 
9826
       tmp_prop.format = 8;
 
9827
       tmp_prop.nitems = *length;
 
9828
       status = 0;
 
9829
 
 
9830
       status = XmbTextPropertyToTextList(XtDisplay(transfer_rec->widget),
 
9831
                                          &tmp_prop, &tmp_value, &num_vals);
 
9832
 
 
9833
      /* if no conversion, num_vals is not changed */
 
9834
       if (num_vals && (status == Success || status > 0)) {
 
9835
          for (i = 0; i < num_vals ; i++)
 
9836
              malloc_size += strlen(tmp_value[i]);
 
9837
 
 
9838
          total_tmp_value = XtMalloc ((unsigned) malloc_size + 1);
 
9839
          total_tmp_value[0] = '\0';
 
9840
          for (i = 0; i < num_vals ; i++)
 
9841
             strcat(total_tmp_value, tmp_value[i]);
 
9842
          total_length = strlen(total_tmp_value);
 
9843
          XFreeStringList(tmp_value);
 
9844
       } else  {
 
9845
          if (value) {
 
9846
             XtFree((char *)value);
 
9847
             value = NULL;
 
9848
          }
 
9849
          return;
 
9850
       }
 
9851
    } else {
 
9852
       total_tmp_value = (char *)value;
 
9853
       total_length = *length;
 
9854
    }
 
9855
 
 
9856
    if (XmTextF_pending_delete(tf) && XmTextF_has_primary(tf) &&
 
9857
       XmTextF_prim_pos_left(tf) != XmTextF_prim_pos_right(tf) &&
 
9858
       insertPosLeft > XmTextF_prim_pos_left(tf) &&
 
9859
       insertPosRight < XmTextF_prim_pos_right(tf)) {
 
9860
      insertPosLeft = XmTextF_prim_pos_left(tf);
 
9861
      insertPosRight = XmTextF_prim_pos_right(tf);
 
9862
    }
 
9863
 
 
9864
    transfer_rec->num_chars = _XmDataFieldCountCharacters(tf, total_tmp_value, 
 
9865
                                                          (int)total_length);
 
9866
 
 
9867
    _XmDataFieldDrawInsertionPoint(tf, False);
 
9868
 
 
9869
    if (transfer_rec->move && local) {
 
9870
       max_length = XmTextF_max_length(tf);
 
9871
       XmTextF_max_length(tf) = INT_MAX;
 
9872
    }
 
9873
 
 
9874
    if (XmTextF_max_char_size(tf) == 1) {
 
9875
       if (_XmDataFieldReplaceText(tf, NULL, insertPosLeft, insertPosRight,
 
9876
                                   (char *) total_tmp_value,
 
9877
                                   (int)total_length, False))
 
9878
          replace = True;
 
9879
    } else {
 
9880
       wc_total_tmp_value = (wchar_t*)XtMalloc((unsigned)
 
9881
                                               total_length * sizeof(wchar_t));
 
9882
      /* Note: casting total_length to an int may result in a truncation. */
 
9883
       total_length = mbstowcs(wc_total_tmp_value, total_tmp_value,
 
9884
                               (int)total_length);
 
9885
       if (_XmDataFieldReplaceText(tf, NULL, insertPosLeft, insertPosRight,
 
9886
                                   (char *) wc_total_tmp_value,
 
9887
                                   (int)total_length, False))
 
9888
          replace = True;
 
9889
       XtFree((char*)wc_total_tmp_value);
 
9890
    }
 
9891
 
 
9892
    if (replace) {
 
9893
       XmTextF_pending_off(tf) = FALSE;
 
9894
       if (transfer_rec->num_chars > 0 && !transfer_rec->move) {
 
9895
          cursorPos = transfer_rec->insert_pos + transfer_rec->num_chars;
 
9896
          _XmDataFielddf_SetCursorPosition(tf, NULL, cursorPos, 
 
9897
                                        False, True);
 
9898
          df_SetDestination((Widget)tf, XmTextF_cursor_position(tf), False,
 
9899
                         transfer_rec->timestamp);
 
9900
       }
 
9901
       if (XmDataFieldGetSelectionPosition((Widget)tf, &left, &right)) {
 
9902
          if (transfer_rec->move && left < transfer_rec->insert_pos)
 
9903
             transfer_rec->insert_pos -= transfer_rec->num_chars;
 
9904
          if (XmTextF_cursor_position(tf) < left ||
 
9905
              XmTextF_cursor_position(tf) > right)
 
9906
             XmTextF_pending_off(tf) = TRUE;
 
9907
       } else {
 
9908
          if (!transfer_rec->move && !XmTextF_add_mode(tf) &&
 
9909
              transfer_rec->num_chars != 0)
 
9910
             XmTextF_prim_anchor(tf) = insertPosLeft;
 
9911
       }
 
9912
       if (transfer_rec->move) {
 
9913
          XmDropTransferEntryRec transferEntries[1];
 
9914
 
 
9915
          transferEntries[0].client_data = (XtPointer) transfer_rec;
 
9916
          transferEntries[0].target = XmInternAtom(XtDisplay(w),"DELETE",False);
 
9917
          XmDropTransferAdd(w, transferEntries, 1);
 
9918
       }
 
9919
       cb.reason = XmCR_VALUE_CHANGED;
 
9920
       cb.event = (XEvent *)NULL;
 
9921
       XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
9922
                          (XtPointer) &cb);
 
9923
    }
 
9924
 
 
9925
    if (transfer_rec->move && local) {
 
9926
       XmTextF_max_length(tf) = max_length;
 
9927
    }
 
9928
 
 
9929
    XtFree(total_tmp_value);
 
9930
    _XmDataFieldDrawInsertionPoint(tf, True);
 
9931
}
 
9932
 
 
9933
 
 
9934
static void
 
9935
#ifdef _NO_PROTO
 
9936
df_HandleDrop(w, cb)
 
9937
        Widget w;
 
9938
        XmDropProcCallbackStruct *cb;
 
9939
#else
 
9940
df_HandleDrop(
 
9941
        Widget w,
 
9942
        XmDropProcCallbackStruct *cb )
 
9943
#endif /* _NO_PROTO */
 
9944
{
 
9945
    static XtCallbackRec dropdf_DestroyCB[] = { {df_DropDestroyCB, NULL},
 
9946
                                             {(XtCallbackProc)NULL, NULL} };
 
9947
    Widget drag_cont, initiator;
 
9948
    Cardinal numExportTargets, n;
 
9949
    Atom *exportTargets;
 
9950
    Arg args[10];
 
9951
    XmTextPosition insert_pos, left, right;
 
9952
    Display *display = XtDisplay(w);
 
9953
 
 
9954
    drag_cont = cb->dragContext;
 
9955
 
 
9956
    n = 0;
 
9957
    XtSetArg(args[n], XmNsourceWidget, &initiator); n++;
 
9958
    XtSetArg(args[n], XmNexportTargets, &exportTargets); n++;
 
9959
    XtSetArg(args[n], XmNnumExportTargets, &numExportTargets); n++;
 
9960
    XtGetValues((Widget) drag_cont, args, n);
 
9961
    
 
9962
    insert_pos = df_GetPosFromX((XmDataFieldWidget) w, cb->x);
 
9963
 
 
9964
    if (cb->operation & XmDROP_MOVE && w == initiator &&
 
9965
        XmDataFieldGetSelectionPosition(w, &left, &right) &&
 
9966
        left != right && insert_pos >= left && insert_pos <= right) {
 
9967
       XtSetArg(args[n], XmNtransferStatus, XmTRANSFER_FAILURE); n++;
 
9968
       XtSetArg(args[n], XmNnumDropTransfers, 0); n++;
 
9969
    } else {
 
9970
       XmDropTransferEntryRec transferEntries[2];
 
9971
       XmDropTransferEntryRec *transferList = NULL;
 
9972
       Atom TEXT = XmInternAtom(display, "TEXT", False);
 
9973
       Atom COMPOUND_TEXT = XmInternAtom(display, "COMPOUND_TEXT", False);
 
9974
#ifdef UTF8_SUPPORTED
 
9975
       Atom UTF8_STRING = XmInternAtom(display, "UTF8_STRING", False);
 
9976
#endif
 
9977
       Atom CS_OF_LOCALE;
 
9978
       char * tmp_string = "ABC"; /* these are characters in XPCS, so... safe */
 
9979
       XTextProperty tmp_prop;
 
9980
       _XmTextDropTransferRec *transfer_rec;
 
9981
       Cardinal numTransfers = 0;
 
9982
       Boolean locale_found = False;
 
9983
       Boolean c_text_found = False;
 
9984
       Boolean utf8_string_found = False;
 
9985
       Boolean string_found = False;
 
9986
       Boolean text_found = False;
 
9987
       int status;
 
9988
 
 
9989
       status = XmbTextListToTextProperty(display, &tmp_string, 1,
 
9990
                                      (XICCEncodingStyle)XTextStyle, &tmp_prop);
 
9991
       if (status == Success)
 
9992
          CS_OF_LOCALE = tmp_prop.encoding;
 
9993
       else
 
9994
          CS_OF_LOCALE = 99999; /* XmbTextList... should never fail for XPCS
 
9995
                                 * characters.  But just in case someones
 
9996
                                 * Xlib is broken, this prevents a core dump.
 
9997
                                 */
 
9998
       if (tmp_prop.value != NULL) XFree((char *)tmp_prop.value);
 
9999
 
 
10000
 
 
10001
      /* intialize data to send to drop transfer callback */
 
10002
       transfer_rec = (_XmTextDropTransferRec *)
 
10003
                       XtMalloc(sizeof(_XmTextDropTransferRec));
 
10004
       transfer_rec->widget = w;
 
10005
       transfer_rec->insert_pos = insert_pos;
 
10006
       transfer_rec->num_chars = 0;
 
10007
       transfer_rec->timestamp = cb->timeStamp;
 
10008
       transfer_rec->move = False;
 
10009
 
 
10010
       if (cb->operation & XmDROP_MOVE) {
 
10011
          transfer_rec->move = True;
 
10012
       } else {
 
10013
          transfer_rec->move = False;
 
10014
       }
 
10015
          
 
10016
       transferEntries[0].client_data = (XtPointer) transfer_rec;
 
10017
       transferList = transferEntries;
 
10018
       numTransfers = 1;
 
10019
 
 
10020
       for (n = 0; n < numExportTargets; n++) {
 
10021
         if (exportTargets[n] == CS_OF_LOCALE) {
 
10022
           transferEntries[0].target = CS_OF_LOCALE;
 
10023
           locale_found = True;
 
10024
           break;
 
10025
         }
 
10026
         if (exportTargets[n] == COMPOUND_TEXT) c_text_found = True;
 
10027
#ifdef UTF8_SUPPORTED
 
10028
         if (exportTargets[n] == UTF8_STRING) utf8_string_found = True;
 
10029
#endif
 
10030
         if (exportTargets[n] == XA_STRING) string_found = True;
 
10031
         if (exportTargets[n] == TEXT) text_found = True;
 
10032
       }
 
10033
       
 
10034
       n = 0;
 
10035
       if (locale_found || c_text_found || string_found || text_found) {
 
10036
         if (!locale_found) {
 
10037
#ifdef UTF8_SUPPORTED
 
10038
           if (utf8_string_found)
 
10039
             transferEntries[0].target = UTF8_STRING;
 
10040
           else
 
10041
#endif
 
10042
           if (c_text_found)
 
10043
             transferEntries[0].target = COMPOUND_TEXT;
 
10044
           else if (string_found)
 
10045
             transferEntries[0].target = XA_STRING;
 
10046
           else
 
10047
             transferEntries[0].target = TEXT;
 
10048
         }
 
10049
 
 
10050
         if (cb->operation & XmDROP_MOVE || cb->operation & XmDROP_COPY) {
 
10051
                XtSetArg(args[n], XmNdropTransfers, transferList); n++;
 
10052
                XtSetArg(args[n], XmNnumDropTransfers, numTransfers); n++;
 
10053
         } else {
 
10054
                XtSetArg(args[n], XmNtransferStatus, XmTRANSFER_FAILURE); n++;
 
10055
                XtSetArg(args[n], XmNnumDropTransfers, 0); n++;
 
10056
         }
 
10057
 
 
10058
       } else {
 
10059
         XtSetArg(args[n], XmNtransferStatus, XmTRANSFER_FAILURE); n++;
 
10060
         XtSetArg(args[n], XmNnumDropTransfers, 0); n++;
 
10061
       }
 
10062
 
 
10063
       dropdf_DestroyCB[0].closure = (XtPointer) transfer_rec;
 
10064
       XtSetArg(args[n], XmNdestroyCallback, dropdf_DestroyCB); n++;
 
10065
       XtSetArg(args[n], XmNtransferProc, df_DropTransferCallback); n++;
 
10066
    }
 
10067
    df_SetDropContext(w);
 
10068
    XmDropTransferStart(drag_cont, args, n);
 
10069
}
 
10070
 
 
10071
 
 
10072
/* ARGSUSED */
 
10073
static void
 
10074
#ifdef _NO_PROTO
 
10075
df_DragProcCallback(w, client, call)
 
10076
        Widget w;
 
10077
        XtPointer client;
 
10078
        XtPointer call;
 
10079
#else
 
10080
df_DragProcCallback(
 
10081
        Widget w,
 
10082
        XtPointer client,
 
10083
        XtPointer call )
 
10084
#endif /* _NO_PROTO */
 
10085
{
 
10086
    XmDragProcCallbackStruct *cb = (XmDragProcCallbackStruct *)call;
 
10087
    Widget drag_cont;
 
10088
    Atom targets[5];
 
10089
    char * tmp_string = "ABC";  /* these are characters in XPCS, so... safe */
 
10090
    XTextProperty tmp_prop;
 
10091
    Arg args[10];
 
10092
    Atom *exp_targets;
 
10093
    Cardinal num_exp_targets, n;
 
10094
    int status = 0;
 
10095
 
 
10096
    status = XmbTextListToTextProperty(XtDisplay(w), &tmp_string, 1,
 
10097
                                      (XICCEncodingStyle)XTextStyle, &tmp_prop);
 
10098
    if (status == Success)
 
10099
       targets[0] = tmp_prop.encoding;
 
10100
    else
 
10101
       targets[0] = 99999; /* XmbTextList... should never fail for XPCS
 
10102
                            * characters.  But just in case someones
 
10103
                            * Xlib is broken, this prevents a core dump.
 
10104
                            */
 
10105
    if (tmp_prop.value != NULL) XFree((char *)tmp_prop.value);
 
10106
 
 
10107
    targets[1] = XmInternAtom(XtDisplay(w), "COMPOUND_TEXT", False);
 
10108
    targets[2] = XA_STRING;
 
10109
    targets[3] = XmInternAtom(XtDisplay(w), "TEXT", False);
 
10110
#ifdef UTF8_SUPPORTED
 
10111
    targets[4] = XmInternAtom(XtDisplay(w), XmSUTF8_STRING, False);
 
10112
#endif
 
10113
 
 
10114
    drag_cont = cb->dragContext;
 
10115
 
 
10116
    n = 0;
 
10117
    XtSetArg(args[n], XmNexportTargets, &exp_targets); n++;
 
10118
    XtSetArg(args[n], XmNnumExportTargets, &num_exp_targets); n++;
 
10119
    XtGetValues(drag_cont, args, n);
 
10120
 
 
10121
    switch(cb->reason) {
 
10122
      case XmCR_DROP_SITE_ENTER_MESSAGE:
 
10123
          if (XmTargetsAreCompatible(XtDisplay(drag_cont), exp_targets,
 
10124
#ifdef UTF8_SUPPORTED
 
10125
                                     num_exp_targets, targets, 4))
 
10126
#else
 
10127
                                     num_exp_targets, targets, 3))
 
10128
#endif
 
10129
             cb->dropSiteStatus = XmVALID_DROP_SITE;
 
10130
          else
 
10131
             cb->dropSiteStatus = XmINVALID_DROP_SITE;
 
10132
          break;
 
10133
      case XmCR_DROP_SITE_LEAVE_MESSAGE:
 
10134
      case XmCR_DROP_SITE_MOTION_MESSAGE:
 
10135
      case XmCR_OPERATION_CHANGED:
 
10136
         /* we currently don't care about these messages */
 
10137
          break;
 
10138
      default:
 
10139
        /* other messages we consider invalid */
 
10140
          cb->dropSiteStatus = XmINVALID_DROP_SITE;
 
10141
          break;
 
10142
    }
 
10143
}
 
10144
 
 
10145
 
 
10146
/* ARGSUSED */
 
10147
static void
 
10148
#ifdef _NO_PROTO
 
10149
df_DropProcCallback(w, client, call)
 
10150
        Widget w;
 
10151
        XtPointer client;
 
10152
        XtPointer call;
 
10153
#else
 
10154
df_DropProcCallback(
 
10155
        Widget w,
 
10156
        XtPointer client,
 
10157
        XtPointer call )
 
10158
#endif /* _NO_PROTO */
 
10159
{
 
10160
    XmDropProcCallbackStruct *cb = (XmDropProcCallbackStruct *) call;
 
10161
 
 
10162
    if (cb->dropAction != XmDROP_HELP) {
 
10163
       df_HandleDrop(w, cb);
 
10164
    } else {
 
10165
       Arg args[2];
 
10166
 
 
10167
       XtSetArg(args[0], XmNtransferStatus, XmTRANSFER_FAILURE);
 
10168
       XtSetArg(args[1], XmNnumDropTransfers, 0);
 
10169
       XmDropTransferStart(cb->dragContext, args, 2);
 
10170
    }
 
10171
}
 
10172
 
 
10173
static void
 
10174
#ifdef _NO_PROTO
 
10175
df_RegisterDropSite(w)
 
10176
        Widget w ;
 
10177
#else
 
10178
df_RegisterDropSite(
 
10179
        Widget w )
 
10180
#endif /* _NO_PROTO */
 
10181
{
 
10182
    Atom targets[5];
 
10183
    Arg args[10];
 
10184
    int n;
 
10185
    char * tmp_string = "ABC";  /* these are characters in XPCS, so... safe */
 
10186
    XTextProperty tmp_prop;
 
10187
    int status = 0;
 
10188
 
 
10189
    status = XmbTextListToTextProperty(XtDisplay(w), &tmp_string, 1,
 
10190
                                      (XICCEncodingStyle)XTextStyle, &tmp_prop);
 
10191
    if (status == Success)
 
10192
       targets[0] = tmp_prop.encoding;
 
10193
    else
 
10194
       targets[0] = 99999; /* XmbTextList... should never fail for XPCS
 
10195
                            * characters.  But just in case someones
 
10196
                            * Xlib is broken, this prevents a core dump.
 
10197
                            */
 
10198
    if (tmp_prop.value != NULL) XFree((char *)tmp_prop.value);
 
10199
 
 
10200
    targets[1] = XmInternAtom(XtDisplay(w), "COMPOUND_TEXT", False);
 
10201
    targets[2] = XA_STRING;
 
10202
    targets[3] = XmInternAtom(XtDisplay(w), "TEXT", False);
 
10203
#ifdef UTF8_SUPPORTED
 
10204
    targets[4] = XmInternAtom(XtDisplay(w), XmSUTF8_STRING, False);
 
10205
#endif
 
10206
 
 
10207
    n = 0;
 
10208
    XtSetArg(args[n], XmNimportTargets, targets); n++;
 
10209
#ifdef UTF8_SUPPORTED
 
10210
    XtSetArg(args[n], XmNnumImportTargets, 4); n++;
 
10211
#else
 
10212
    XtSetArg(args[n], XmNnumImportTargets, 3); n++;
 
10213
#endif
 
10214
    XtSetArg(args[n], XmNdropProc, df_DragProcCallback); n++;
 
10215
    XtSetArg(args[n], XmNdropProc, df_DropProcCallback); n++;
 
10216
    XmDropSiteRegister(w, args, n);
 
10217
}
 
10218
 
 
10219
/*
 
10220
 * df_Initialize
 
10221
 *    Intializes the text data and ensures that the data in new
 
10222
 * is valid.
 
10223
 */
 
10224
/* ARGSUSED */
 
10225
static void 
 
10226
#ifdef _NO_PROTO
 
10227
df_Initialize( request, new_w, args, num_args )
 
10228
        Widget request ;
 
10229
        Widget new_w ;
 
10230
        ArgList args ;
 
10231
        Cardinal *num_args ;
 
10232
#else
 
10233
df_Initialize(
 
10234
        Widget request,
 
10235
        Widget new_w,
 
10236
        ArgList args,
 
10237
        Cardinal *num_args )
 
10238
#endif /* _NO_PROTO */
 
10239
{
 
10240
    XmDataFieldWidget req_tf = (XmDataFieldWidget) request;
 
10241
    XmDataFieldWidget new_tf = (XmDataFieldWidget) new_w;
 
10242
    Dimension width, height;
 
10243
  
 
10244
    df_Validates(new_tf);
 
10245
 
 
10246
    df_InitializeTextStruct(new_tf);
 
10247
 
 
10248
    df_LoadGCs(new_tf, new_tf->core.background_pixel, 
 
10249
            new_tf->primitive.foreground ); 
 
10250
 
 
10251
    df_ComputeSize(new_tf, &width, &height);
 
10252
  
 
10253
    if (req_tf->core.width == 0)
 
10254
       new_tf->core.width = width;
 
10255
    if (req_tf->core.height == 0)
 
10256
       new_tf->core.height = height;
 
10257
 
 
10258
    df_RegisterDropSite(new_w);
 
10259
 
 
10260
    if (XmTextF_verify_bell(new_tf) == (Boolean) XmDYNAMIC_BOOL)
 
10261
    {
 
10262
      if (_XmGetAudibleWarning(new_w) == XmBELL) 
 
10263
        XmTextF_verify_bell(new_tf) = True;
 
10264
      else
 
10265
        XmTextF_verify_bell(new_tf) = False;
 
10266
    }
 
10267
}
 
10268
 
 
10269
static void 
 
10270
#ifdef _NO_PROTO
 
10271
df_Realize( w, valueMask, attributes )
 
10272
        Widget w ;
 
10273
        XtValueMask *valueMask ;
 
10274
        XSetWindowAttributes *attributes ;
 
10275
#else
 
10276
df_Realize(
 
10277
        Widget w,
 
10278
        XtValueMask *valueMask,
 
10279
        XSetWindowAttributes *attributes )
 
10280
#endif /* _NO_PROTO */
 
10281
{
 
10282
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
10283
 
 
10284
   XtCreateWindow(w, (unsigned int) InputOutput,
 
10285
                   (Visual *) CopyFromParent, *valueMask, attributes);
 
10286
   df_MakeCursors(tf);
 
10287
   _XmDataFieldSetClipRect(tf);
 
10288
}
 
10289
 
 
10290
static void 
 
10291
#ifdef _NO_PROTO
 
10292
df_Destroy( wid )
 
10293
        Widget wid ;
 
10294
#else
 
10295
df_Destroy(
 
10296
        Widget wid )
 
10297
#endif /* _NO_PROTO */
 
10298
{
 
10299
    XmDataFieldWidget tf = (XmDataFieldWidget) wid ;
 
10300
    Widget dest = XmGetDestination(XtDisplay(wid));
 
10301
 
 
10302
    if (dest == wid)
 
10303
       _XmSetDestination(XtDisplay(wid), NULL); 
 
10304
 
 
10305
    if (XmTextF_timer_id(tf))
 
10306
        XtRemoveTimeOut(XmTextF_timer_id(tf));
 
10307
 
 
10308
    if (XmTextF_has_rect(tf)) {
 
10309
       TextFGCData gc_data = df_GetTextFGCData(wid);
 
10310
       gc_data->tf = NULL;
 
10311
    }
 
10312
 
 
10313
    if (XmTextF_max_char_size(tf) == 1)
 
10314
       XtFree(XmTextF_value(tf));
 
10315
    else
 
10316
       XtFree((char *)XmTextF_wc_value(tf));
 
10317
 
 
10318
    XmDestroyPixmap(XtScreen(tf), XmTextF_stipple_tile(tf));
 
10319
 
 
10320
    XtReleaseGC(wid, XmTextF_gc(tf));
 
10321
    XtReleaseGC(wid, XmTextF_image_gc(tf));
 
10322
    XtReleaseGC(wid, XmTextF_save_gc(tf)); 
 
10323
 
 
10324
    XtFree((char *)XmTextF_highlight(tf).list);
 
10325
 
 
10326
    if (XmTextF_fontlist_created(tf))
 
10327
       XmFontListFree((XmFontList)XmTextF_font_list(tf));
 
10328
 
 
10329
    if (XmTextF_add_mode_cursor(tf) != XmUNSPECIFIED_PIXMAP)
 
10330
       (void) XmDestroyPixmap(XtScreen(tf), XmTextF_add_mode_cursor(tf));
 
10331
 
 
10332
    if (XmTextF_cursor(tf) != XmUNSPECIFIED_PIXMAP)
 
10333
       (void) XmDestroyPixmap(XtScreen(tf), XmTextF_cursor(tf));
 
10334
 
 
10335
    if (XmTextF_ibeam_off(tf) != XmUNSPECIFIED_PIXMAP)
 
10336
       XFreePixmap(XtDisplay((Widget)tf), XmTextF_ibeam_off(tf));
 
10337
 
 
10338
    if (XmTextF_image_clip(tf) != XmUNSPECIFIED_PIXMAP)
 
10339
       XmDestroyPixmap(XtScreen(tf), XmTextF_image_clip(tf));
 
10340
 
 
10341
/*
 
10342
 * Fix for HaL DTS 9841 - release the data for the selectionArray.
 
10343
 */
 
10344
    XtFree((char *)XmTextF_selection_array(tf));
 
10345
 
 
10346
    XtRemoveAllCallbacks(wid, XmNactivateCallback);
 
10347
    XtRemoveAllCallbacks(wid, XmNlosingFocusCallback);
 
10348
    XtRemoveAllCallbacks(wid, XmNfocusCallback);
 
10349
    XtRemoveAllCallbacks(wid, XmNmodifyVerifyCallback);
 
10350
    XtRemoveAllCallbacks(wid, XmNmotionVerifyCallback);
 
10351
    XtRemoveAllCallbacks(wid, XmNvalueChangedCallback);
 
10352
    XtRemoveAllCallbacks(wid, XmNgainPrimaryCallback);
 
10353
    XtRemoveAllCallbacks(wid, XmNlosePrimaryCallback);
 
10354
 
 
10355
    XmImUnregister(wid);
 
10356
 
 
10357
    XtFree((char*)XmDataField_picture_source(tf));
 
10358
    if(XmDataField_picture(tf)) 
 
10359
            XmPictureDelete(XmDataField_picture(tf));
 
10360
}
 
10361
 
 
10362
static void 
 
10363
#ifdef _NO_PROTO
 
10364
df_Resize( w )
 
10365
        Widget w ;
 
10366
#else
 
10367
df_Resize(
 
10368
        Widget w )
 
10369
#endif /* _NO_PROTO */
 
10370
{
 
10371
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
10372
 
 
10373
  XmTextF_do_resize(tf) = False;
 
10374
 
 
10375
  _XmDataFieldSetClipRect(tf);
 
10376
 
 
10377
  if (XmDataField_alignment(tf) == XmALIGNMENT_END)
 
10378
      XmTextF_h_offset(tf) = 0;
 
10379
  else
 
10380
      XmTextF_h_offset(tf) = XmTextF_margin_width(tf) +
 
10381
          tf->primitive.shadow_thickness + tf->primitive.highlight_thickness;
 
10382
 
 
10383
  XmTextF_refresh_ibeam_off(tf) = True;
 
10384
 
 
10385
  (void) df_AdjustText(tf, XmTextF_cursor_position(tf), True);
 
10386
 
 
10387
  XmTextF_do_resize(tf) = True;
 
10388
}
 
10389
 
 
10390
 
 
10391
/************************************************************************
 
10392
 *
 
10393
 *  df_QueryGeometry
 
10394
 *
 
10395
 ************************************************************************/
 
10396
static XtGeometryResult 
 
10397
#ifdef _NO_PROTO
 
10398
df_QueryGeometry( widget, intended, desired )
 
10399
        Widget widget ;
 
10400
        XtWidgetGeometry *intended ;
 
10401
        XtWidgetGeometry *desired ;
 
10402
#else
 
10403
df_QueryGeometry(
 
10404
        Widget widget,
 
10405
        XtWidgetGeometry *intended,
 
10406
        XtWidgetGeometry *desired )
 
10407
#endif /* _NO_PROTO */
 
10408
{
 
10409
    /* this function deals with resizeWidth False */
 
10410
    df_ComputeSize((XmDataFieldWidget) widget, 
 
10411
                &desired->width, &desired->height);
 
10412
 
 
10413
    return XmeReplyToQueryGeometry(widget, intended, desired) ;
 
10414
}
 
10415
 
 
10416
 
 
10417
/*
 
10418
 * Redisplay will redraw shadows, borders, and text.
 
10419
 */
 
10420
/* ARGSUSED */
 
10421
static void 
 
10422
#ifdef _NO_PROTO
 
10423
DataFieldExpose( w, event, region )
 
10424
        Widget w ;
 
10425
        XEvent *event ;
 
10426
        Region region ;
 
10427
#else
 
10428
DataFieldExpose(
 
10429
        Widget w,
 
10430
        XEvent *event,
 
10431
        Region region )
 
10432
#endif /* _NO_PROTO */
 
10433
{
 
10434
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
10435
  XGCValues values;
 
10436
  
 
10437
 
 
10438
  if (event->xany.type != Expose) return;
 
10439
 
 
10440
  XmTextF_do_resize(tf) = False;
 
10441
 
 
10442
  if (!XmTextF_has_rect(tf)) _XmDataFieldSetClipRect(tf);
 
10443
 
 
10444
  /* I can get here even though the widget isn't visible (i.e. my parent is
 
10445
   * sized so that I have nothing visible.  In this case, capturing the putback
 
10446
   * area yields garbage...  And if this area is not in an area where text
 
10447
   * will be drawn (i.e. forcing something new/valid to be there next time I
 
10448
   * go to capture it) the garbage persists.  To prevent this, initialize the
 
10449
   * putback area and then update it to a solid background color.
 
10450
   */
 
10451
 
 
10452
  XmTextF_refresh_ibeam_off(tf) = False;
 
10453
  values.foreground = tf->core.background_pixel;
 
10454
  XChangeGC(XtDisplay(w), XmTextF_save_gc(tf), GCForeground, &values);
 
10455
  XFillRectangle(XtDisplay(w), XmTextF_ibeam_off(tf), XmTextF_save_gc(tf), 0, 0,
 
10456
                    XmTextF_cursor_width(tf), XmTextF_cursor_height(tf));
 
10457
  values.foreground = tf->primitive.foreground;
 
10458
  XChangeGC(XtDisplay(w), XmTextF_save_gc(tf), GCForeground, &values);
 
10459
 
 
10460
  _XmDataFieldDrawInsertionPoint(tf, False);
 
10461
 
 
10462
  if (XtIsRealized((Widget)tf)) {
 
10463
     if (tf->primitive.shadow_thickness > 0)
 
10464
       XmeDrawShadows(XtDisplay(tf), XtWindow(tf),
 
10465
             tf->primitive.bottom_shadow_GC, 
 
10466
             tf->primitive.top_shadow_GC,
 
10467
             (int) tf->primitive.highlight_thickness,
 
10468
             (int) tf->primitive.highlight_thickness,
 
10469
             (int) (tf->core.width - (2 * tf->primitive.highlight_thickness)),
 
10470
             (int) (tf->core.height - (2 * tf->primitive.highlight_thickness)),
 
10471
             (int) tf->primitive.shadow_thickness,
 
10472
             XmSHADOW_OUT);
 
10473
 
 
10474
 
 
10475
     if (tf->primitive.highlighted)
 
10476
     {
 
10477
         XtWidgetProc bhl;
 
10478
 
 
10479
         _XmProcessLock();
 
10480
         bhl = ((XmDataFieldWidgetClass) XtClass(tf))->primitive_class.border_highlight;
 
10481
         _XmProcessUnlock();
 
10482
         
 
10483
         if(bhl)
 
10484
         {   
 
10485
             (*bhl)( (Widget) tf) ;
 
10486
         } 
 
10487
     } 
 
10488
     else
 
10489
     {
 
10490
         XtWidgetProc buhl;
 
10491
 
 
10492
         _XmProcessLock();
 
10493
         buhl = ((XmDataFieldWidgetClass) XtClass(tf))->primitive_class.border_unhighlight;
 
10494
         _XmProcessUnlock();
 
10495
 
 
10496
         if(buhl)
 
10497
         {
 
10498
            (*buhl)( (Widget) tf) ;
 
10499
         } 
 
10500
     } 
 
10501
 
 
10502
     df_RedisplayText(tf, 0, XmTextF_string_length(tf));
 
10503
  }
 
10504
 
 
10505
  XmTextF_refresh_ibeam_off(tf) = True;
 
10506
 
 
10507
  _XmDataFieldDrawInsertionPoint(tf, True);
 
10508
 
 
10509
  XmTextF_do_resize(tf) = True;
 
10510
}
 
10511
 
 
10512
/*
 
10513
 *
 
10514
 * df_SetValues
 
10515
 *
 
10516
 *    Checks the new text data and ensures that the data is valid.
 
10517
 * Invalid values will be rejected and changed back to the old
 
10518
 * values.
 
10519
 *
 
10520
 */
 
10521
/* ARGSUSED */
 
10522
static Boolean 
 
10523
#ifdef _NO_PROTO
 
10524
df_SetValues( old, request, new_w, args, num_args )
 
10525
        Widget old ;
 
10526
        Widget request ;
 
10527
        Widget new_w ;
 
10528
        ArgList args ;
 
10529
        Cardinal *num_args ;
 
10530
#else
 
10531
df_SetValues(
 
10532
        Widget old,
 
10533
        Widget request,
 
10534
        Widget new_w,
 
10535
        ArgList args,
 
10536
        Cardinal *num_args )
 
10537
#endif /* _NO_PROTO */
 
10538
{
 
10539
    XmDataFieldWidget new_tf = (XmDataFieldWidget) new_w;
 
10540
    XmDataFieldWidget old_tf = (XmDataFieldWidget) old;
 
10541
    Boolean cursor_pos_set = False;
 
10542
    Boolean new_size = False;
 
10543
    Boolean redisplay = False;
 
10544
    Boolean redisplay_text = False;
 
10545
    Boolean new_font = False;
 
10546
    Boolean mod_ver_ret = False;
 
10547
    Boolean diff_values = False;
 
10548
    Dimension new_width = new_tf->core.width;
 
10549
    Dimension new_height = new_tf->core.height;
 
10550
    Arg im_args[6];
 
10551
    XPoint xmim_point;
 
10552
    XmTextPosition new_position = 0;
 
10553
    XmTextPosition newInsert;
 
10554
    int n = 0;
 
10555
 
 
10556
    if (new_w->core.being_destroyed) return False;
 
10557
 
 
10558
    XmTextF_in_setvalues(new_tf) = True;
 
10559
    XmTextF_redisplay(new_tf) = False;
 
10560
 
 
10561
     /************************************
 
10562
     * ICS DataField specific stuff here *
 
10563
     ************************************/
 
10564
    
 
10565
    /*
 
10566
     * This is a patch-around to a bug we seem to have exposed.
 
10567
     * The special redisplay handling has been broken somehow with the
 
10568
     * end result that the DataField doesn't redisplay itself
 
10569
     * correctly when its XmNvalue is set.  This just hacks around the
 
10570
     * problem.
 
10571
     */
 
10572
    if(XmTextF_value(old_tf) != XmTextF_value(new_tf)) {
 
10573
        redisplay = True;
 
10574
    }
 
10575
 
 
10576
    if (XmDataField_picture_source(old_tf) != XmDataField_picture_source(new_tf))
 
10577
    {
 
10578
        /*
 
10579
         * Delete what's there
 
10580
         */
 
10581
        XtFree((char*)XmDataField_picture_source(old_tf));
 
10582
        XmDataField_picture_source(new_tf) = XtNewString(XmDataField_picture_source(new_tf));
 
10583
        if(XmDataField_picture(new_tf)) {
 
10584
            XmPictureDelete(XmDataField_picture(new_tf));
 
10585
            XmDataField_picture(new_tf) = NULL;
 
10586
        }
 
10587
 
 
10588
        /*
 
10589
         * And make a new one if we have to
 
10590
         */
 
10591
        if(XmDataField_picture_source(new_tf)) {
 
10592
            XmDataField_picture(new_tf) = XmParsePicture(XmDataField_picture_source(new_tf));
 
10593
        }
 
10594
 
 
10595
        /*
 
10596
         * Finally register (or remove) the callback
 
10597
         */
 
10598
        if(XmDataField_picture(new_tf)) {
 
10599
            XtAddCallback((Widget)new_tf, XmNmodifyVerifyCallback,
 
10600
                          PictureVerifyCallback, NULL);
 
10601
        } else {
 
10602
            XtRemoveCallback((Widget)new_tf, XmNmodifyVerifyCallback,
 
10603
                             PictureVerifyCallback, NULL);
 
10604
        }
 
10605
 
 
10606
 
 
10607
    }
 
10608
 
 
10609
    if (XmDataField_alignment(old_tf) != XmDataField_alignment(new_tf))
 
10610
    {
 
10611
        if (XmDataField_alignment(new_tf) == XmALIGNMENT_END)
 
10612
            XmTextF_h_offset(new_tf) = XmTextF_new_h_offset(new_tf) = 0;
 
10613
        else
 
10614
            XmTextF_h_offset(new_tf) = XmTextF_new_h_offset(new_tf) = 
 
10615
                XmTextF_margin_width(new_tf) +
 
10616
                new_tf->primitive.shadow_thickness +
 
10617
                new_tf->primitive.highlight_thickness;
 
10618
 
 
10619
        redisplay = True;
 
10620
    }
 
10621
 
 
10622
   /* If new cursor position, copy the old cursor pos to the new widget
 
10623
    * so that when we turn off the i-beam, the current location (old
 
10624
    * widget) is used, but the new i-beam parameters (on/off, state, ...)
 
10625
    * are utilized.  Then move the cursor.  Otherwise, just turn off
 
10626
    * the i-beam. */
 
10627
 
 
10628
    if (XmTextF_cursor_position(new_tf) != XmTextF_cursor_position(old_tf)) {
 
10629
       new_position = XmTextF_cursor_position(new_tf) ;
 
10630
       XmTextF_cursor_position(new_tf) = XmTextF_cursor_position(old_tf);
 
10631
       _XmDataFieldDrawInsertionPoint(old_tf, False);
 
10632
       XmTextF_blink_on(new_tf) = XmTextF_blink_on(old_tf);
 
10633
       XmTextF_cursor_on(new_tf) = XmTextF_cursor_on(old_tf);
 
10634
       _XmDataFielddf_SetCursorPosition(new_tf, NULL, new_position,
 
10635
                                     True, True);
 
10636
       (void) df_SetDestination(new_w, XmTextF_cursor_position(new_tf), False,
 
10637
                             XtLastTimestampProcessed(XtDisplay(new_w)));
 
10638
       cursor_pos_set = True;
 
10639
    } else {
 
10640
      int ix;
 
10641
      
 
10642
      for (ix = 0; ix < *num_args; ix++)
 
10643
        if (strcmp(args[ix].name, XmNcursorPosition) == 0) {
 
10644
          cursor_pos_set = True;
 
10645
          new_position = XmTextF_cursor_position(new_tf);
 
10646
          break;
 
10647
        }
 
10648
      
 
10649
      _XmDataFieldDrawInsertionPoint(old_tf, False);
 
10650
      XmTextF_blink_on(new_tf) = XmTextF_blink_on(old_tf);
 
10651
      XmTextF_cursor_on(new_tf) = XmTextF_cursor_on(old_tf);
 
10652
    }
 
10653
 
 
10654
    if (new_w->core.sensitive == False &&
 
10655
        XmTextF_has_destination(new_tf)) {
 
10656
       (void) df_SetDestination(new_w, XmTextF_cursor_position(new_tf),
 
10657
                             True, XtLastTimestampProcessed(XtDisplay(new_w)));
 
10658
    }
 
10659
 
 
10660
    if (XmTextF_selection_array(new_tf) == NULL) 
 
10661
       XmTextF_selection_array(new_tf) = XmTextF_selection_array(old_tf);
 
10662
 
 
10663
    if (XmTextF_selection_array_count(new_tf) <= 0) 
 
10664
       XmTextF_selection_array_count(new_tf) = XmTextF_selection_array_count(old_tf);
 
10665
 
 
10666
/*
 
10667
 * Fix for HaL DTS 9841 - If the new and old selectionArrays do not match,
 
10668
 *                        free the old array and then copy the new array.
 
10669
 */
 
10670
    if (XmTextF_selection_array(new_tf) != XmTextF_selection_array(old_tf))
 
10671
    {
 
10672
      XtPointer temp_ptr;
 
10673
 
 
10674
      XtFree((char *)XmTextF_selection_array(old_tf));
 
10675
      temp_ptr = (XtPointer)XmTextF_selection_array(new_tf);
 
10676
      XmTextF_selection_array(new_tf) = (XmTextScanType *)XtMalloc (
 
10677
                 XmTextF_selection_array_count(new_tf) * sizeof(XmTextScanType));
 
10678
      memcpy((void *)XmTextF_selection_array(new_tf), (void *)temp_ptr,
 
10679
             (XmTextF_selection_array_count(new_tf) * sizeof(XmTextScanType)));
 
10680
    }
 
10681
/*
 
10682
 * End fix for HaL DTS 9841
 
10683
 */
 
10684
 
 
10685
 
 
10686
   /* Make sure the new_tf cursor position is a valid value.
 
10687
    */
 
10688
    if (XmTextF_cursor_position(new_tf) < 0) {
 
10689
       XmeWarning (new_w, MSG1);
 
10690
       XmTextF_cursor_position(new_tf) = XmTextF_cursor_position(old_tf);
 
10691
       cursor_pos_set = False;
 
10692
    }
 
10693
 
 
10694
    if (XmTextF_font_list(new_tf)!= XmTextF_font_list(old_tf)) {
 
10695
       new_font = True;
 
10696
       if (XmTextF_font_list(new_tf) == NULL)
 
10697
          XmTextF_font_list(new_tf) = XmeGetDefaultRenderTable(new_w, XmTEXT_FONTLIST);
 
10698
       XmTextF_font_list(new_tf) =
 
10699
                            (XmFontList)XmFontListCopy(XmTextF_font_list(new_tf));
 
10700
       if (!df_LoadFontMetrics(new_tf)){ /* Fails if font set required but not
 
10701
                                       * available. */
 
10702
          XmFontListFree((XmFontList)XmTextF_font_list(new_tf));
 
10703
          XmTextF_font_list(new_tf) = XmTextF_font_list(old_tf);
 
10704
          (void)df_LoadFontMetrics(new_tf); /* it *was* correct, so re-use it */
 
10705
          new_font = False;
 
10706
       } else {
 
10707
          XtSetArg(im_args[n], XmNfontList, XmTextF_font_list(new_tf)); n++;
 
10708
          redisplay = True;
 
10709
       }
 
10710
    }
 
10711
 
 
10712
    /* Four cases to handle for value:
 
10713
     *   1. user set both XmNvalue and XmNwcValue.
 
10714
     *   2. user set the opposite resource (i.e. value is a char*
 
10715
     *      and user set XmNwcValue, or vice versa).
 
10716
     *   3. user set the corresponding resource (i.e. value is a char*
 
10717
     *      and user set XmNValue, or vice versa).
 
10718
     *   4. user set neither XmNValue nor XmNwcValue
 
10719
     */
 
10720
 
 
10721
    /* OSF says:  if XmNvalueWcs set, it overrides all else */
 
10722
 
 
10723
     if (XmTextF_max_char_size(new_tf) == 1) {  
 
10724
       /* wc_value on new will be NULL unless XmNvalueWcs was set.   */
 
10725
        if (XmTextF_wc_value(new_tf) != NULL){ /* must be new if MB_CUR... == 1 */
 
10726
           df_ValidateString(new_tf, (char*) XmTextF_wc_value(new_tf), True);
 
10727
           diff_values = True;
 
10728
        } else if (XmTextF_value(new_tf) != XmTextF_value(old_tf)) {
 
10729
           diff_values = True;
 
10730
           if (XmTextF_value(new_tf) == NULL) {
 
10731
              df_ValidateString(new_tf, "", False);
 
10732
           } else
 
10733
              df_ValidateString(new_tf, XmTextF_value(new_tf), False);
 
10734
        } /* else, no change so don't do anything */
 
10735
     } else {
 
10736
        if (XmTextF_wc_value(new_tf) != XmTextF_wc_value(old_tf)) {
 
10737
           diff_values = True;
 
10738
           if (XmTextF_wc_value(new_tf) == NULL) {
 
10739
              XmTextF_wc_value(new_tf) = (wchar_t*) XtMalloc(sizeof(wchar_t));
 
10740
              *XmTextF_wc_value(new_tf) = (wchar_t)NULL;
 
10741
           }
 
10742
           df_ValidateString(new_tf, (char*)XmTextF_wc_value(new_tf), True);
 
10743
        } else if (XmTextF_value(new_tf) != XmTextF_value(old_tf)) {
 
10744
           /* Someone set XmNvalue */
 
10745
           diff_values = True;
 
10746
           if (XmTextF_value(new_tf) == NULL)
 
10747
              df_ValidateString(new_tf, "", True);
 
10748
           else
 
10749
              df_ValidateString(new_tf, XmTextF_value(new_tf), False);
 
10750
 
 
10751
        } /* else, no change so don't do anything */
 
10752
     }
 
10753
 
 
10754
    if (diff_values) { /* old value != new value */
 
10755
       Boolean do_it = True;
 
10756
      /* If there are modify verify callbacks, verify that we want to continue
 
10757
       * the action.
 
10758
       */
 
10759
       if (XmTextF_modify_verify_callback(new_tf) || 
 
10760
           XmTextF_wcs_modify_verify_callback(new_tf)) {
 
10761
         /* If the function df_ModifyVerify() returns false then don't
 
10762
          * continue with the action.
 
10763
          */
 
10764
          char *temp, *old;
 
10765
          int free_insert;
 
10766
          XmTextPosition fromPos = 0, toPos;
 
10767
          toPos = XmTextF_string_length(old_tf);
 
10768
          if (XmTextF_max_char_size(new_tf) == 1) {
 
10769
             temp = XmTextF_value(new_tf);
 
10770
             mod_ver_ret = df_ModifyVerify(new_tf, NULL, &fromPos, &toPos,
 
10771
                                        &temp, &XmTextF_string_length(new_tf),
 
10772
                                        &newInsert, &free_insert);
 
10773
          } else {
 
10774
             old = temp = XtMalloc((unsigned)((XmTextF_string_length(new_tf) + 1) *
 
10775
                                              XmTextF_max_char_size(new_tf)));
 
10776
             (void)wcstombs(temp, XmTextF_wc_value(new_tf), 
 
10777
                 (XmTextF_string_length(new_tf) + 1) * XmTextF_max_char_size(new_tf));
 
10778
             mod_ver_ret = df_ModifyVerify(new_tf, NULL, &fromPos, &toPos, &temp,
 
10779
                                        &XmTextF_string_length(new_tf), &newInsert,
 
10780
                                        &free_insert);
 
10781
             if (old != temp) XtFree (old);
 
10782
          }
 
10783
          if (free_insert) XtFree(temp);
 
10784
          if (!mod_ver_ret) {
 
10785
             if (XmTextF_verify_bell(new_tf)) XBell(XtDisplay(new_w), 0);
 
10786
             if (XmTextF_max_char_size(new_tf) == 1) {
 
10787
                XmTextF_value(new_tf) = (char *) memcpy(
 
10788
                                           XtRealloc(XmTextF_value(new_tf),
 
10789
                                           (unsigned)XmTextF_size_allocd(old_tf)),
 
10790
                                           (void*)XmTextF_value(old_tf),
 
10791
                                           XmTextF_string_length(old_tf) + 1);
 
10792
                XmTextF_string_length(new_tf) = XmTextF_string_length(old_tf);
 
10793
                XmTextF_size_allocd(new_tf) = XmTextF_size_allocd(old_tf);
 
10794
                XtFree(XmTextF_value(old_tf));
 
10795
             } else {
 
10796
                /* realloc to old size, cast to wchar_t*, and copy the data */
 
10797
                XmTextF_wc_value(new_tf) = (wchar_t*)memcpy(
 
10798
                       XtRealloc((char *)XmTextF_wc_value(new_tf),
 
10799
                       (unsigned)XmTextF_size_allocd(old_tf)),
 
10800
                       (void*)XmTextF_wc_value(old_tf),
 
10801
                       (unsigned) XmTextF_size_allocd(old_tf));
 
10802
 
 
10803
                XmTextF_string_length(new_tf) = XmTextF_string_length(old_tf);
 
10804
                XmTextF_size_allocd(new_tf) = XmTextF_size_allocd(old_tf);
 
10805
                XtFree((char *)XmTextF_wc_value(old_tf));
 
10806
             }
 
10807
             do_it = False;
 
10808
          }
 
10809
       }
 
10810
 
 
10811
 
 
10812
       if (do_it) {
 
10813
          XmAnyCallbackStruct cb;
 
10814
 
 
10815
          if (XmTextF_max_char_size(new_tf) == 1)
 
10816
             XtFree(XmTextF_value(old_tf));
 
10817
          else
 
10818
             XtFree((char *)XmTextF_wc_value(old_tf));
 
10819
 
 
10820
          XmDataFieldSetHighlight(new_w, XmTextF_prim_pos_left(new_tf),
 
10821
                                  XmTextF_prim_pos_right(new_tf),
 
10822
                                  XmHIGHLIGHT_NORMAL);
 
10823
 
 
10824
          XmTextF_pending_off(new_tf) = True;    
 
10825
 
 
10826
          /* if new_position was > XmTextF_string_length(old_tf), last time
 
10827
           * the df_SetCursorPosition didn't take.
 
10828
           */
 
10829
          if (!cursor_pos_set || new_position > XmTextF_string_length(old_tf)){
 
10830
             _XmDataFielddf_SetCursorPosition(new_tf, NULL, new_position,
 
10831
                                           True, False);
 
10832
             if (XmTextF_has_destination(new_tf))
 
10833
                (void) df_SetDestination(new_w, XmTextF_cursor_position(new_tf),
 
10834
                             False, XtLastTimestampProcessed(XtDisplay(new_w)));
 
10835
          }
 
10836
 
 
10837
          if (XmTextF_resize_width(new_tf) && XmTextF_do_resize(new_tf))
 
10838
             df_AdjustSize(new_tf);
 
10839
          else {
 
10840
              if (XmDataField_alignment(new_tf) == XmALIGNMENT_END)
 
10841
                  XmTextF_h_offset(new_tf) = 0;
 
10842
              else
 
10843
                  XmTextF_h_offset(new_tf) = XmTextF_margin_width(new_tf) + 
 
10844
                      new_tf->primitive.shadow_thickness +
 
10845
                      new_tf->primitive.highlight_thickness;
 
10846
 
 
10847
             if (!df_AdjustText(new_tf, XmTextF_cursor_position(new_tf), False))
 
10848
                redisplay_text = True;
 
10849
          }
 
10850
 
 
10851
          cb.reason = XmCR_VALUE_CHANGED;
 
10852
          cb.event = NULL;
 
10853
          XtCallCallbackList(new_w, XmTextF_value_changed_callback(new_tf),
 
10854
                             (XtPointer) &cb);
 
10855
 
 
10856
       }
 
10857
    }
 
10858
 
 
10859
    if (new_tf->primitive.foreground != old_tf->primitive.foreground ||
 
10860
        XmTextF_font_list(new_tf)!= XmTextF_font_list(old_tf) ||
 
10861
        new_tf->core.background_pixel != old_tf->core.background_pixel) {
 
10862
       df_LoadGCs(new_tf, new_tf->primitive.foreground,
 
10863
                         new_tf->core.background_pixel);
 
10864
       df_MakeCursors(new_tf);
 
10865
       _XmDataFieldSetClipRect(new_tf);
 
10866
       if (XmTextF_have_inverted_image_gc(new_tf)){
 
10867
          XmTextF_have_inverted_image_gc(new_tf) = False;
 
10868
          df_InvertImageGC(new_tf);
 
10869
       }
 
10870
       redisplay = True;
 
10871
       XtSetArg(im_args[n], XmNbackground, new_tf->core.background_pixel); n++;
 
10872
       XtSetArg(im_args[n], XmNforeground, new_tf->primitive.foreground); n++;
 
10873
    }
 
10874
 
 
10875
    if (XmTextF_has_focus(new_tf) && XtIsSensitive((Widget)new_tf) &&
 
10876
        XmTextF_blink_rate(new_tf) != XmTextF_blink_rate(old_tf)) {
 
10877
 
 
10878
        if (XmTextF_blink_rate(new_tf) == 0) {
 
10879
            XmTextF_blink_on(new_tf) = True;
 
10880
            if (XmTextF_timer_id(new_tf)) {
 
10881
                XtRemoveTimeOut(XmTextF_timer_id(new_tf));
 
10882
                XmTextF_timer_id(new_tf) = (XtIntervalId)0;
 
10883
            }
 
10884
        } else if (XmTextF_timer_id(new_tf) == (XtIntervalId)0) {
 
10885
           XmTextF_timer_id(new_tf) =
 
10886
                 XtAppAddTimeOut(XtWidgetToApplicationContext(new_w),
 
10887
                                 (unsigned long)XmTextF_blink_rate(new_tf),
 
10888
                                 df_HandleTimer,
 
10889
                                 (XtPointer) new_tf);
 
10890
        }
 
10891
        df_BlinkInsertionPoint(new_tf);
 
10892
    }
 
10893
 
 
10894
    if (XmTextF_margin_height(new_tf) != XmTextF_margin_height(old_tf)) {
 
10895
       XmTextF_margin_top(new_tf) = XmTextF_margin_height(new_tf);
 
10896
       XmTextF_margin_bottom(new_tf) = XmTextF_margin_height(new_tf);
 
10897
    }
 
10898
 
 
10899
    new_size = XmTextF_margin_width(new_tf) != XmTextF_margin_width(old_tf) ||
 
10900
               XmTextF_margin_height(new_tf) != XmTextF_margin_height(old_tf) ||
 
10901
               XmTextF_font_list(new_tf) != XmTextF_font_list(old_tf) ||
 
10902
               new_tf->primitive.highlight_thickness !=
 
10903
                 old_tf->primitive.highlight_thickness ||
 
10904
               new_tf->primitive.shadow_thickness !=
 
10905
                 old_tf->primitive.shadow_thickness;
 
10906
    
 
10907
 
 
10908
    if (XmTextF_columns(new_tf) < 0) {
 
10909
       XmeWarning (new_w, MSG7);
 
10910
       XmTextF_columns(new_tf) = XmTextF_columns(old_tf);
 
10911
    }
 
10912
 
 
10913
    if (!(new_width != old_tf->core.width &&
 
10914
          new_height != old_tf->core.height)) {
 
10915
       if (XmTextF_columns(new_tf) != XmTextF_columns(old_tf) || new_size) {
 
10916
          Dimension width, height;
 
10917
 
 
10918
          df_ComputeSize(new_tf, &width, &height);
 
10919
          df_AdjustText(new_tf, 0, False);
 
10920
 
 
10921
          if (new_width == old_tf->core.width)
 
10922
             new_w->core.width = width;
 
10923
          if (new_height == old_tf->core.height)
 
10924
             new_w->core.height = height;
 
10925
 
 
10926
          if (XmDataField_alignment(new_tf) == XmALIGNMENT_END)
 
10927
              XmTextF_h_offset(new_tf) = 0;
 
10928
          else
 
10929
              XmTextF_h_offset(new_tf) = XmTextF_margin_width(new_tf) +
 
10930
                  new_tf->primitive.shadow_thickness +
 
10931
                  new_tf->primitive.highlight_thickness;
 
10932
 
 
10933
          redisplay = True;
 
10934
       }
 
10935
    } else {
 
10936
       if (new_width != new_tf->core.width)
 
10937
          new_tf->core.width = new_width;
 
10938
       if (new_height != new_tf->core.height)
 
10939
          new_tf->core.height = new_height;
 
10940
    }
 
10941
 
 
10942
    XmTextF_refresh_ibeam_off(new_tf) = 1; /* force update of putback area */
 
10943
 
 
10944
    _XmDataFieldDrawInsertionPoint(new_tf, True);
 
10945
 
 
10946
    if (XtIsSensitive((Widget)new_tf) != XtIsSensitive((Widget)old_tf)) {
 
10947
       if (XtIsSensitive(new_w)) {
 
10948
          _XmDataFieldDrawInsertionPoint(new_tf, False);
 
10949
          XmTextF_blink_on(new_tf) = False;
 
10950
          _XmDataFToggleCursorGC(new_w);
 
10951
         _XmDataFieldDrawInsertionPoint(new_tf, True);
 
10952
       } else {
 
10953
          if (XmTextF_has_focus(new_tf)) {
 
10954
             XmTextF_has_focus(new_tf) = False;
 
10955
             df_ChangeBlinkBehavior(new_tf, False);
 
10956
             _XmDataFieldDrawInsertionPoint(new_tf, False);
 
10957
             _XmDataFToggleCursorGC(new_w);
 
10958
             XmTextF_blink_on(new_tf) = True;
 
10959
             _XmDataFieldDrawInsertionPoint(new_tf, True);
 
10960
          }
 
10961
       }
 
10962
       if (XmTextF_string_length(new_tf) > 0) redisplay = True;
 
10963
    }
 
10964
 
 
10965
    df_GetXYFromPos(new_tf, XmTextF_cursor_position(new_tf), &xmim_point.x, 
 
10966
                 &xmim_point.y);
 
10967
 
 
10968
    if (XmTextF_editable(old_tf) != XmTextF_editable(new_tf)) {
 
10969
       Boolean editable = XmTextF_editable(new_tf);
 
10970
       XmTextF_editable(new_tf) = XmTextF_editable(old_tf);
 
10971
       XmDataFieldSetEditable(new_w, editable);
 
10972
    }
 
10973
 
 
10974
    XtSetArg(im_args[n], XmNbackgroundPixmap,
 
10975
             new_tf->core.background_pixmap); n++;
 
10976
    XtSetArg(im_args[n], XmNspotLocation, &xmim_point); n++;
 
10977
    XtSetArg(im_args[n], XmNlineSpace, 
 
10978
             XmTextF_font_ascent(new_tf) + XmTextF_font_descent(new_tf)); n++;
 
10979
    XmImSetValues((Widget)new_tf, im_args, n);
 
10980
 
 
10981
    if (new_font) XmFontListFree((XmFontList)XmTextF_font_list(old_tf));
 
10982
 
 
10983
    if (!redisplay) redisplay = XmTextF_redisplay(new_tf);
 
10984
 
 
10985
    /* If I'm forced to redisplay, then actual widget won't be updated
 
10986
     * until the expose proc.  Force the ibeam putback to be refreshed
 
10987
     * at expose time so that it reflects true visual state of the
 
10988
     * widget.  */
 
10989
 
 
10990
    if (redisplay) XmTextF_refresh_ibeam_off(new_tf) = True;
 
10991
 
 
10992
    XmTextF_in_setvalues(new_tf) = False;
 
10993
 
 
10994
    /* 
 
10995
     * Force new clip rectangles to be computed during redisplay,
 
10996
     * *after* XtSetValues decides on final geometry. 
 
10997
     */
 
10998
    if (redisplay) XmTextF_has_rect(new_tf) = False; 
 
10999
 
 
11000
    if ((!XmTextF_editable(new_tf) || !XtIsSensitive(new_w)) &&
 
11001
        XmTextF_has_destination(new_tf))
 
11002
       (void) df_SetDestination(new_w, 0, False, (Time)0);
 
11003
 
 
11004
    /* don't shrink to nothing */
 
11005
    if (new_tf->core.width == 0) new_tf->core.width = old_tf->core.width;
 
11006
    if (new_tf->core.height == 0) new_tf->core.height = old_tf->core.height;
 
11007
 
 
11008
    if (!redisplay && redisplay_text) 
 
11009
      df_RedisplayText(new_tf, 0, XmTextF_string_length(new_tf));
 
11010
 
 
11011
    return redisplay;
 
11012
}
 
11013
 
 
11014
static Boolean 
 
11015
#ifdef _NO_PROTO
 
11016
DataFieldRemove( w, event)
 
11017
        Widget w ;
 
11018
        XEvent *event ;
 
11019
#else
 
11020
DataFieldRemove(
 
11021
        Widget w,
 
11022
        XEvent *event)
 
11023
#endif /* _NO_PROTO */
 
11024
{
 
11025
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
11026
   XmTextPosition left, right;
 
11027
   XmAnyCallbackStruct cb;
 
11028
 
 
11029
   if (XmTextF_editable(tf) == False)
 
11030
      return False;
 
11031
 
 
11032
   if (!XmDataFieldGetSelectionPosition(w, &left, &right) || left == right) {
 
11033
      XmTextF_prim_anchor(tf) = XmTextF_cursor_position(tf);
 
11034
      return False;
 
11035
   }
 
11036
 
 
11037
   if (_XmDataFieldReplaceText(tf, event, left, right, NULL, 0, True)){
 
11038
      XmDataFieldSetSelection(w, XmTextF_cursor_position(tf),
 
11039
                              XmTextF_cursor_position(tf),
 
11040
                              XtLastTimestampProcessed(XtDisplay(w)));
 
11041
      cb.reason = XmCR_VALUE_CHANGED;
 
11042
      cb.event = event;
 
11043
      XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
11044
                         (XtPointer) &cb);
 
11045
   }
 
11046
   XmTextF_prim_anchor(tf) = XmTextF_cursor_position(tf);
 
11047
 
 
11048
   return True;
 
11049
}
 
11050
 
 
11051
/********************************************
 
11052
 * AccessTextual trait method implementation 
 
11053
 ********************************************/
 
11054
 
 
11055
static XtPointer
 
11056
DataFieldGetValue(Widget w, int format) 
 
11057
{
 
11058
  char *str;
 
11059
  XmString tmp;
 
11060
  
 
11061
  switch(format) {
 
11062
  case XmFORMAT_XmSTRING:
 
11063
    str = XmDataFieldGetString(w);
 
11064
    tmp = XmStringCreateLocalized(str);
 
11065
    if (str != NULL) XtFree(str);
 
11066
    return((XtPointer) tmp);
 
11067
  case XmFORMAT_MBYTE:
 
11068
    return((XtPointer) XmDataFieldGetString(w));
 
11069
  case XmFORMAT_WCS:
 
11070
    return((XtPointer) XmDataFieldGetStringWcs(w));
 
11071
  }
 
11072
 
 
11073
  return(NULL);
 
11074
}
 
11075
 
 
11076
static void 
 
11077
DataFieldSetValue(Widget w, XtPointer s, int format)
 
11078
{
 
11079
  char *str;
 
11080
  
 
11081
  switch(format) 
 
11082
    {
 
11083
    case XmFORMAT_XmSTRING:
 
11084
      str = _XmStringGetTextConcat((XmString) s);
 
11085
      XmDataFieldSetString(w, str);
 
11086
      if (str != NULL) XtFree(str);
 
11087
      break;
 
11088
    case XmFORMAT_MBYTE:
 
11089
      XmDataFieldSetString(w, (char*) s);
 
11090
      break;
 
11091
    case XmFORMAT_WCS:
 
11092
      XmDataFieldSetStringWcs(w, (wchar_t *) s);
 
11093
    }
 
11094
}
 
11095
 
 
11096
/*ARGSUSED*/
 
11097
static int
 
11098
DataFieldPreferredValue(Widget w) /* unused */
 
11099
{
 
11100
  return(XmFORMAT_MBYTE);
 
11101
}
 
11102
 
 
11103
/*
 
11104
 * XmRCallProc routine for checking data.font_list before setting it to NULL
 
11105
 * if no value is specified for both XmNrenderTable and XmNfontList.
 
11106
 * If "check_set_render_table" == True, then function has been called twice
 
11107
 * on same widget, thus resource needs to be set NULL, otherwise leave it
 
11108
 * alone.
 
11109
 */
 
11110
/* ARGSUSED */
 
11111
static void 
 
11112
CheckSetRenderTable(Widget wid, int offset, XrmValue *value)
 
11113
{
 
11114
  XmDataFieldWidget df = (XmDataFieldWidget)wid;
 
11115
 
 
11116
  if (XmTextF_check_set_render_table(df))
 
11117
        value->addr = NULL;
 
11118
  else {
 
11119
        XmTextF_check_set_render_table(df) = True;
 
11120
        value->addr = (char*)&(XmTextF_font_list(df));
 
11121
  }
 
11122
}
 
11123
/***********************************<->***************************************
 
11124
 
 
11125
 *                              Public Functions                             *
 
11126
 ***********************************<->***************************************/
 
11127
 
 
11128
char * 
 
11129
#ifdef _NO_PROTO
 
11130
XmDataFieldGetString( w )
 
11131
        Widget w ;
 
11132
#else
 
11133
XmDataFieldGetString(
 
11134
        Widget w )
 
11135
#endif /* _NO_PROTO */
 
11136
{
 
11137
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
11138
    char *temp_str;
 
11139
    int ret_val = 0;
 
11140
 
 
11141
    _XmWidgetToAppContext(w);    
 
11142
    _XmAppLock(app);
 
11143
 
 
11144
    if (XmTextF_string_length(tf) > 0) 
 
11145
    {
 
11146
        if (XmTextF_max_char_size(tf) == 1) 
 
11147
        {
 
11148
            temp_str = XtNewString(XmTextF_value(tf));
 
11149
            _XmAppUnlock(app); 
 
11150
            return(temp_str);
 
11151
        } 
 
11152
        else 
 
11153
        {
 
11154
            temp_str = (char *) XtMalloc((unsigned) XmTextF_max_char_size(tf) * 
 
11155
                                         (XmTextF_string_length(tf) + 1));
 
11156
            ret_val = wcstombs(temp_str, XmTextF_wc_value(tf), 
 
11157
                               (XmTextF_string_length(tf) + 1) * 
 
11158
                               XmTextF_max_char_size(tf));
 
11159
            if (ret_val < 0) 
 
11160
            {
 
11161
                temp_str[0] = '\0';
 
11162
            }
 
11163
 
 
11164
            _XmAppUnlock(app);
 
11165
            return temp_str;
 
11166
        }
 
11167
    } else 
 
11168
    {
 
11169
      _XmAppUnlock(app);
 
11170
      return(XtNewString(""));
 
11171
    }
 
11172
}
 
11173
 
 
11174
int 
 
11175
#ifdef _NO_PROTO
 
11176
XmDataFieldGetSubstring( widget, start, num_chars, buf_size, buffer )
 
11177
        Widget widget;
 
11178
        XmTextPosition start;
 
11179
        int num_chars;
 
11180
        int buf_size;
 
11181
        char *buffer;
 
11182
#else
 
11183
XmDataFieldGetSubstring(
 
11184
        Widget widget,
 
11185
        XmTextPosition start,
 
11186
        int num_chars,
 
11187
        int buf_size,
 
11188
        char *buffer )
 
11189
#endif /* _NO_PROTO */
 
11190
{
 
11191
    XmDataFieldWidget tf = (XmDataFieldWidget) widget;
 
11192
    int ret_value = XmCOPY_SUCCEEDED;
 
11193
    int n_bytes = 0;
 
11194
    int wcs_ret = 0;
 
11195
 
 
11196
    _XmWidgetToAppContext(widget);    
 
11197
    _XmAppLock(app);
 
11198
 
 
11199
    if (XmTextF_max_char_size(tf) != 1)
 
11200
    {
 
11201
        n_bytes = _XmDataFieldCountBytes(tf, XmTextF_wc_value(tf)+start, num_chars);
 
11202
    }
 
11203
    else
 
11204
    {
 
11205
        n_bytes = num_chars; 
 
11206
    }
 
11207
 
 
11208
    if (buf_size < n_bytes + 1 )
 
11209
    {
 
11210
      _XmAppUnlock(app);
 
11211
      return XmCOPY_FAILED;
 
11212
    }
 
11213
 
 
11214
    if (start + num_chars > XmTextF_string_length(tf)) 
 
11215
    {
 
11216
        num_chars = (int) (XmTextF_string_length(tf) - start);
 
11217
        if (XmTextF_max_char_size(tf) != 1)
 
11218
        {
 
11219
            n_bytes = _XmDataFieldCountBytes(tf, XmTextF_wc_value(tf)+start,
 
11220
                                             num_chars);
 
11221
        }
 
11222
        else
 
11223
        {
 
11224
            n_bytes = num_chars; 
 
11225
        }
 
11226
        ret_value = XmCOPY_TRUNCATED;
 
11227
    }
 
11228
      
 
11229
    if (num_chars > 0) {
 
11230
        if (XmTextF_max_char_size(tf) == 1) 
 
11231
        {
 
11232
            (void)memcpy((void*)buffer, (void*)&XmTextF_value(tf)[start], num_chars);
 
11233
        } 
 
11234
        else 
 
11235
        {
 
11236
            wcs_ret = wcstombs(buffer, &XmTextF_wc_value(tf)[start], 
 
11237
                               n_bytes);
 
11238
            if (wcs_ret < 0) n_bytes = 0;
 
11239
        }
 
11240
        buffer[n_bytes] = '\0';
 
11241
    } 
 
11242
    else
 
11243
    {
 
11244
        ret_value = XmCOPY_FAILED;
 
11245
    }
 
11246
 
 
11247
    _XmAppUnlock(app);
 
11248
    return (ret_value);
 
11249
}
 
11250
 
 
11251
 
 
11252
wchar_t *
 
11253
#ifdef _NO_PROTO
 
11254
XmDataFieldGetStringWcs( w )
 
11255
        Widget w ;
 
11256
#else
 
11257
XmDataFieldGetStringWcs(
 
11258
        Widget w )
 
11259
#endif /* _NO_PROTO */
 
11260
{
 
11261
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
11262
    wchar_t *temp_wcs;
 
11263
    int num_wcs = 0;
 
11264
 
 
11265
    _XmWidgetToAppContext(w);    
 
11266
    _XmAppLock(app);
 
11267
 
 
11268
    if (XmTextF_string_length(tf) > 0) 
 
11269
    {
 
11270
        temp_wcs = (wchar_t*) XtMalloc((unsigned) sizeof(wchar_t) *
 
11271
                                       (XmTextF_string_length(tf) + 1));
 
11272
        if (XmTextF_max_char_size(tf) != 1) 
 
11273
        {
 
11274
            (void)memcpy((void*)temp_wcs, (void*)XmTextF_wc_value(tf), 
 
11275
                         sizeof(wchar_t) * (XmTextF_string_length(tf) + 1));
 
11276
        } 
 
11277
        else 
 
11278
        {
 
11279
            num_wcs = mbstowcs(temp_wcs, XmTextF_value(tf),
 
11280
                               XmTextF_string_length(tf) + 1);
 
11281
        }
 
11282
 
 
11283
        _XmAppUnlock(app);
 
11284
        return temp_wcs;
 
11285
    } 
 
11286
    else 
 
11287
      {
 
11288
        temp_wcs = (wchar_t*) XtMalloc((unsigned) sizeof(wchar_t));
 
11289
        temp_wcs[0] = (wchar_t)0L; /* put a wchar_t NULL in position 0 */
 
11290
        
 
11291
        _XmAppUnlock(app);
 
11292
        return temp_wcs;
 
11293
      }
 
11294
}
 
11295
 
 
11296
int 
 
11297
#ifdef _NO_PROTO
 
11298
XmDataFieldGetSubstringWcs( widget, start, num_chars, buf_size, buffer )
 
11299
        Widget widget;
 
11300
        XmTextPosition start;
 
11301
        int num_chars;
 
11302
        int buf_size;
 
11303
        wchar_t *buffer;
 
11304
#else
 
11305
XmDataFieldGetSubstringWcs(
 
11306
        Widget widget,
 
11307
        XmTextPosition start,
 
11308
        int num_chars,
 
11309
        int buf_size,
 
11310
        wchar_t *buffer )
 
11311
#endif /* _NO_PROTO */
 
11312
{
 
11313
    XmDataFieldWidget tf = (XmDataFieldWidget) widget;
 
11314
    int ret_value = XmCOPY_SUCCEEDED;
 
11315
    int num_wcs = 0;
 
11316
 
 
11317
    _XmWidgetToAppContext(widget);    
 
11318
    _XmAppLock(app);
 
11319
    
 
11320
    if (start + num_chars > XmTextF_string_length(tf)) 
 
11321
    {
 
11322
        num_chars = (int) (XmTextF_string_length(tf) - start);
 
11323
        ret_value = XmCOPY_TRUNCATED;
 
11324
    }
 
11325
      
 
11326
    if (buf_size < num_chars + 1 ) 
 
11327
    {
 
11328
      _XmAppUnlock(app);
 
11329
      return XmCOPY_FAILED;
 
11330
    }
 
11331
 
 
11332
    if (num_chars > 0) 
 
11333
    {
 
11334
        if (XmTextF_max_char_size(tf) == 1) 
 
11335
        {
 
11336
            num_wcs = mbstowcs(buffer, &XmTextF_value(tf)[start], num_chars);
 
11337
            if (num_wcs < 0) num_chars = 0;
 
11338
        } 
 
11339
        else 
 
11340
        {
 
11341
            (void)memcpy((void*)buffer, (void*)&XmTextF_wc_value(tf)[start], 
 
11342
                         (size_t) num_chars * sizeof(wchar_t));
 
11343
        }
 
11344
        buffer[num_chars] = '\0';
 
11345
    } else if (num_chars == 0) {
 
11346
        buffer[num_chars] = '\0';
 
11347
    } 
 
11348
    else
 
11349
    {
 
11350
      ret_value = XmCOPY_FAILED;
 
11351
    }
 
11352
 
 
11353
    _XmAppUnlock(app);
 
11354
    return (ret_value);
 
11355
}
 
11356
 
 
11357
 
 
11358
XmTextPosition 
 
11359
#ifdef _NO_PROTO
 
11360
XmDataFieldGetLastPosition( w )
 
11361
        Widget w ;
 
11362
#else
 
11363
XmDataFieldGetLastPosition(
 
11364
        Widget w )
 
11365
#endif /* _NO_PROTO */
 
11366
{
 
11367
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
11368
    XmTextPosition ret_val;
 
11369
 
 
11370
    _XmWidgetToAppContext(w);    
 
11371
    _XmAppLock(app);
 
11372
 
 
11373
    ret_val = XmTextF_string_length(tf);
 
11374
 
 
11375
    _XmAppUnlock(app);
 
11376
    return(ret_val);
 
11377
}
 
11378
 
 
11379
void 
 
11380
#ifdef _NO_PROTO
 
11381
XmDataFieldSetString( w, value )
 
11382
        Widget w ;
 
11383
        char *value ;
 
11384
#else
 
11385
XmDataFieldSetString(
 
11386
        Widget w,
 
11387
        char *value )
 
11388
#endif /* _NO_PROTO */
 
11389
{
 
11390
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
11391
    XmAnyCallbackStruct cb;
 
11392
    XmTextPosition fromPos, toPos, newInsert;
 
11393
    int length;
 
11394
    int free_insert = False;
 
11395
    int ret_val = 0;
 
11396
    char * tmp_ptr;
 
11397
    char * mod_value = NULL;
 
11398
 
 
11399
    _XmWidgetToAppContext(w);    
 
11400
    _XmAppLock(app);
 
11401
 
 
11402
    fromPos = 0;
 
11403
 
 
11404
    if (value == NULL) value = "";
 
11405
    toPos = XmTextF_string_length(tf);
 
11406
 
 
11407
    if (XmTextF_max_char_size(tf) == 1)
 
11408
    {
 
11409
        length = strlen(value);
 
11410
    }
 
11411
    else
 
11412
    {
 
11413
        length = mbstowcs(NULL, value, 0);
 
11414
    }
 
11415
 
 
11416
    if (tf->core.sensitive && XmTextF_has_focus(tf)) 
 
11417
    {
 
11418
        df_ChangeBlinkBehavior(tf, False);
 
11419
    }
 
11420
    _XmDataFieldDrawInsertionPoint(tf, False);
 
11421
 
 
11422
    if (XmTextF_modify_verify_callback(tf) || 
 
11423
        XmTextF_wcs_modify_verify_callback(tf)) 
 
11424
    {
 
11425
        /* 
 
11426
         * If the function df_ModifyVerify() returns 
 
11427
         * false then don't continue with the action.
 
11428
         */
 
11429
        if (!df_ModifyVerify(tf, NULL, &fromPos, &toPos,
 
11430
                             &value, &length, &newInsert, &free_insert)) 
 
11431
        {
 
11432
            if (XmTextF_verify_bell(tf)) XBell(XtDisplay(w), 0);
 
11433
            if (free_insert) XtFree(value);
 
11434
            _XmAppUnlock(app);
 
11435
            return;
 
11436
        }
 
11437
    }
 
11438
 
 
11439
    XmDataFieldSetHighlight(w, 0, XmTextF_string_length(tf),
 
11440
                            XmHIGHLIGHT_NORMAL);
 
11441
 
 
11442
    if (XmTextF_max_char_size(tf) == 1) 
 
11443
    {
 
11444
        XtFree(XmTextF_value(tf));
 
11445
    }
 
11446
    else   /* convert to wchar_t before calling df_ValidateString */
 
11447
    {
 
11448
        XtFree((char *)XmTextF_wc_value(tf));
 
11449
    }
 
11450
 
 
11451
    df_ValidateString(tf, value, False);
 
11452
    XmTextF_pending_off(tf) = True;    
 
11453
 
 
11454
    df_SetCursorPosition(tf, NULL, 0, True, True, False);
 
11455
 
 
11456
    if (XmTextF_resize_width(tf) && XmTextF_do_resize(tf))
 
11457
    {
 
11458
        df_AdjustSize(tf);
 
11459
    }
 
11460
    else 
 
11461
    {
 
11462
        if (XmDataField_alignment(tf) == XmALIGNMENT_END)
 
11463
        {
 
11464
            XmTextF_h_offset(tf) = 0;
 
11465
        } 
 
11466
        else
 
11467
        {
 
11468
            XmTextF_h_offset(tf) = XmTextF_margin_width(tf) + 
 
11469
                tf->primitive.shadow_thickness +
 
11470
                tf->primitive.highlight_thickness;
 
11471
        }
 
11472
        if (!df_AdjustText(tf, XmTextF_cursor_position(tf), False)) 
 
11473
        {
 
11474
            df_RedisplayText(tf, 0, XmTextF_string_length(tf));
 
11475
        }    
 
11476
    }
 
11477
 
 
11478
    cb.reason = XmCR_VALUE_CHANGED;
 
11479
    cb.event = NULL;
 
11480
    XtCallCallbackList(w, XmTextF_value_changed_callback(tf), (XtPointer) &cb);
 
11481
 
 
11482
    XmTextF_refresh_ibeam_off(tf) = True;
 
11483
    
 
11484
    if (tf->core.sensitive && XmTextF_has_focus(tf))
 
11485
    {
 
11486
        df_ChangeBlinkBehavior(tf, True);
 
11487
    }
 
11488
    
 
11489
    _XmDataFieldDrawInsertionPoint(tf, True);
 
11490
    if (free_insert) XtFree(value);
 
11491
    
 
11492
    _XmAppUnlock(app);
 
11493
}
 
11494
 
 
11495
static void 
 
11496
#ifdef _NO_PROTO
 
11497
XmDataFieldSetStringWcs( w, wc_value )
 
11498
        Widget w;
 
11499
        wchar_t *wc_value;
 
11500
#else
 
11501
XmDataFieldSetStringWcs(
 
11502
        Widget w,
 
11503
        wchar_t *wc_value )
 
11504
#endif /* _NO_PROTO */
 
11505
{
 
11506
 
 
11507
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
11508
   char * tmp;
 
11509
   wchar_t *tmp_wc;
 
11510
   int num_chars = 0;
 
11511
   int result;
 
11512
 
 
11513
   _XmWidgetToAppContext(w);    
 
11514
   _XmAppLock(app);
 
11515
 
 
11516
    for (num_chars = 0, tmp_wc = wc_value; *tmp_wc != (wchar_t)0L; num_chars++)
 
11517
        tmp_wc++;  /* count number of wchar_t's */
 
11518
 
 
11519
   tmp = XtMalloc((unsigned) (num_chars + 1) * XmTextF_max_char_size(tf));
 
11520
   result = wcstombs(tmp, wc_value, (num_chars + 1) * XmTextF_max_char_size(tf));
 
11521
 
 
11522
   if (result == (size_t) -1) /* if wcstombs fails, it returns (size_t) -1 */
 
11523
       tmp = "";               /* if invalid data, pass in the empty string */
 
11524
 
 
11525
   XmDataFieldSetString(w, tmp);
 
11526
   
 
11527
   XtFree(tmp);
 
11528
   _XmAppUnlock(app);   
 
11529
}
 
11530
 
 
11531
 
 
11532
void 
 
11533
#ifdef _NO_PROTO
 
11534
XmDataFieldReplace( w, from_pos, to_pos, value )
 
11535
        Widget w ;
 
11536
        XmTextPosition from_pos ;
 
11537
        XmTextPosition to_pos ;
 
11538
        char *value ;
 
11539
#else
 
11540
XmDataFieldReplace(
 
11541
        Widget w,
 
11542
        XmTextPosition from_pos,
 
11543
        XmTextPosition to_pos,
 
11544
        char *value )
 
11545
#endif /* _NO_PROTO */
 
11546
{
 
11547
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
11548
 
 
11549
    int save_maxlength = XmTextF_max_length(tf);
 
11550
    Boolean save_editable = XmTextF_editable(tf);
 
11551
    Boolean deselected = False;
 
11552
    Boolean rep_result = False;
 
11553
    wchar_t *wc_value;
 
11554
    int length = 0;
 
11555
    XmAnyCallbackStruct cb;
 
11556
 
 
11557
    _XmWidgetToAppContext(w);    
 
11558
    _XmAppLock(app);   
 
11559
 
 
11560
    if (value == NULL) value = "";
 
11561
 
 
11562
    df_VerifyBounds(tf, &from_pos, &to_pos);
 
11563
 
 
11564
    if (XmTextF_has_primary(tf)) {
 
11565
       if ((XmTextF_prim_pos_left(tf) > from_pos && 
 
11566
            XmTextF_prim_pos_left(tf) < to_pos) || 
 
11567
           (XmTextF_prim_pos_right(tf) >from_pos && 
 
11568
            XmTextF_prim_pos_right(tf) < to_pos) ||
 
11569
           (XmTextF_prim_pos_left(tf) <= from_pos && 
 
11570
            XmTextF_prim_pos_right(tf) >= to_pos)) {
 
11571
         _XmDataFieldDeselectSelection(w, False,
 
11572
                                       XtLastTimestampProcessed(XtDisplay(w)));
 
11573
         deselected = True;
 
11574
       }
 
11575
    }
 
11576
    
 
11577
    XmTextF_editable(tf) = True;
 
11578
    XmTextF_max_length(tf) = INT_MAX;
 
11579
    if (XmTextF_max_char_size(tf) == 1) {
 
11580
       length = strlen(value);
 
11581
       rep_result = _XmDataFieldReplaceText(tf, NULL, from_pos, 
 
11582
                                            to_pos, value, length, False);
 
11583
    } else { /* need to convert to wchar_t* before calling Replace */
 
11584
       wc_value = (wchar_t *) XtMalloc((unsigned) sizeof(wchar_t) *
 
11585
                                       (1 + strlen(value)));
 
11586
       length = mbstowcs(wc_value, value, (unsigned) (strlen(value) + 1));
 
11587
       rep_result = _XmDataFieldReplaceText(tf, NULL, from_pos, to_pos, 
 
11588
                                      (char*)wc_value, length, False);
 
11589
       XtFree((char *)wc_value);
 
11590
    }
 
11591
    if (from_pos <= XmTextF_cursor_position(tf)) {
 
11592
      XmTextPosition cursorPos;
 
11593
      /* Replace will not move us, we still want this to happen */
 
11594
      if (XmTextF_cursor_position(tf) < to_pos) {
 
11595
        if (XmTextF_cursor_position(tf) - from_pos <= length)
 
11596
          cursorPos = XmTextF_cursor_position(tf);
 
11597
        else
 
11598
          cursorPos = from_pos + length;
 
11599
      } else {
 
11600
        cursorPos = XmTextF_cursor_position(tf) - (to_pos - from_pos) + length;
 
11601
      }
 
11602
      XmDataFieldSetInsertionPosition((Widget)tf, cursorPos);
 
11603
    }
 
11604
    XmTextF_editable(tf) = save_editable;
 
11605
    XmTextF_max_length(tf) = save_maxlength;
 
11606
 
 
11607
    /* 
 
11608
     * Replace Text utilizes an optimization in deciding which text to redraw;
 
11609
     * in the case that the selection has been changed (as above), this can
 
11610
     * cause part/all of the replaced text to NOT be redrawn.  The following
 
11611
     * df_AdjustText call ensures that it IS drawn in this case.
 
11612
     */
 
11613
 
 
11614
    if (deselected)
 
11615
       df_AdjustText(tf, from_pos, True);
 
11616
 
 
11617
    (void) df_SetDestination(w, XmTextF_cursor_position(tf), False,
 
11618
                          XtLastTimestampProcessed(XtDisplay(w)));
 
11619
    if (rep_result) {
 
11620
       cb.reason = XmCR_VALUE_CHANGED;
 
11621
       cb.event = (XEvent *)NULL;
 
11622
       XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
11623
                          (XtPointer) &cb);
 
11624
    }
 
11625
 
 
11626
    _XmAppUnlock(app);  
 
11627
}
 
11628
 
 
11629
/* TOM - XmDataFieldReplaceWcs not converted */
 
11630
void 
 
11631
#ifdef _NO_PROTO
 
11632
XmDataFieldReplaceWcs( w, from_pos, to_pos, wc_value )
 
11633
        Widget w ;
 
11634
        XmTextPosition from_pos ;
 
11635
        XmTextPosition to_pos ;
 
11636
        wchar_t *wc_value ;
 
11637
#else
 
11638
XmDataFieldReplaceWcs(
 
11639
        Widget w,
 
11640
        XmTextPosition from_pos,
 
11641
        XmTextPosition to_pos,
 
11642
        wchar_t *wc_value )
 
11643
#endif /* _NO_PROTO */
 
11644
{
 
11645
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
11646
    int save_maxlength = XmTextF_max_length(tf);
 
11647
    Boolean save_editable = XmTextF_editable(tf);
 
11648
    Boolean deselected = False;
 
11649
    Boolean rep_result = False;
 
11650
    wchar_t *tmp_wc;
 
11651
    char *tmp;
 
11652
    int wc_length = 0;
 
11653
    XmAnyCallbackStruct cb;
 
11654
 
 
11655
   _XmWidgetToAppContext(w);    
 
11656
   _XmAppLock(app);
 
11657
 
 
11658
    if (wc_value == NULL) wc_value = (wchar_t*)"";
 
11659
 
 
11660
    df_VerifyBounds(tf, &from_pos, &to_pos);
 
11661
 
 
11662
    if (XmTextF_has_primary(tf)) {
 
11663
       if ((XmTextF_prim_pos_left(tf) > from_pos &&
 
11664
              XmTextF_prim_pos_left(tf) < to_pos) ||
 
11665
           (XmTextF_prim_pos_right(tf) >from_pos &&
 
11666
              XmTextF_prim_pos_right(tf) < to_pos) ||
 
11667
           (XmTextF_prim_pos_left(tf) <= from_pos &&
 
11668
              XmTextF_prim_pos_right(tf) >= to_pos)) {
 
11669
                _XmDataFieldDeselectSelection(w, False,
 
11670
                                        XtLastTimestampProcessed(XtDisplay(w)));
 
11671
                deselected = True;
 
11672
       }
 
11673
    }
 
11674
 
 
11675
   /* Count the number of wide chars in the array */
 
11676
    for (wc_length = 0, tmp_wc = wc_value; *tmp_wc != (wchar_t)0L; wc_length++)
 
11677
        tmp_wc++;  /* count number of wchar_t's */
 
11678
 
 
11679
    XmTextF_editable(tf) = True;
 
11680
    XmTextF_max_length(tf) = INT_MAX;
 
11681
 
 
11682
    if (XmTextF_max_char_size(tf) != 1) 
 
11683
    {
 
11684
        rep_result = _XmDataFieldReplaceText(tf, NULL, from_pos, to_pos,
 
11685
                                             (char*)wc_value, wc_length, False);
 
11686
    } 
 
11687
    else 
 
11688
    {     /* need to convert to char* before calling Replace */
 
11689
        tmp = XtMalloc((unsigned) (wc_length + 1) * XmTextF_max_char_size(tf));
 
11690
        wc_length = wcstombs(tmp, wc_value, 
 
11691
                             (wc_length + 1) * XmTextF_max_char_size(tf));
 
11692
 
 
11693
       if (wc_length == (size_t) -1){ /* if wcstombs fails, it returns -1 */
 
11694
          tmp = "";                   /* if invalid data, pass in the empty 
 
11695
                                       * string */
 
11696
          wc_length = 0;
 
11697
       }
 
11698
       rep_result = _XmDataFieldReplaceText(tf, NULL, from_pos, to_pos,
 
11699
                                            (char*)tmp, wc_length, False);
 
11700
       XtFree(tmp);
 
11701
    }
 
11702
    if (from_pos <= XmTextF_cursor_position(tf)) {
 
11703
      XmTextPosition cursorPos;
 
11704
      /* Replace will not move us, we still want this to happen */
 
11705
      if (XmTextF_cursor_position(tf) < to_pos) {
 
11706
        if (XmTextF_cursor_position(tf) - from_pos <= wc_length)
 
11707
          cursorPos = XmTextF_cursor_position(tf);
 
11708
        else
 
11709
          cursorPos = from_pos + wc_length;
 
11710
      } else {
 
11711
        cursorPos = XmTextF_cursor_position(tf) - (to_pos - from_pos) + wc_length;
 
11712
      }
 
11713
      XmDataFieldSetInsertionPosition((Widget)tf, cursorPos);
 
11714
    }
 
11715
    XmTextF_editable(tf) = save_editable;
 
11716
    XmTextF_max_length(tf) = save_maxlength;
 
11717
 
 
11718
    /*
 
11719
     * Replace Text utilizes an optimization in deciding which text to redraw;
 
11720
     * in the case that the selection has been changed (as above), this can
 
11721
     * cause part/all of the replaced text to NOT be redrawn.  The following
 
11722
     * df_AdjustText call ensures that it IS drawn in this case.
 
11723
     */
 
11724
 
 
11725
    if (deselected)
 
11726
       df_AdjustText(tf, from_pos, True);
 
11727
 
 
11728
    (void) df_SetDestination(w, XmTextF_cursor_position(tf), False,
 
11729
                          XtLastTimestampProcessed(XtDisplay(w)));
 
11730
    if (rep_result) {
 
11731
       cb.reason = XmCR_VALUE_CHANGED;
 
11732
       cb.event = (XEvent *)NULL;
 
11733
       XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
11734
                          (XtPointer) &cb);
 
11735
    }
 
11736
 
 
11737
    _XmAppUnlock(app); 
 
11738
}
 
11739
 
 
11740
 
 
11741
void 
 
11742
#ifdef _NO_PROTO
 
11743
XmDataFieldInsert( w, position, value )
 
11744
        Widget w ;
 
11745
        XmTextPosition position ;
 
11746
        char *value ;
 
11747
#else
 
11748
XmDataFieldInsert(
 
11749
        Widget w,
 
11750
        XmTextPosition position,
 
11751
        char *value )
 
11752
#endif /* _NO_PROTO */
 
11753
{
 
11754
  _XmWidgetToAppContext(w);    
 
11755
  _XmAppLock(app);  
 
11756
 
 
11757
  /* XmDataFieldReplace takes care of converting to wchar_t* if needed */
 
11758
  XmDataFieldReplace(w, position, position, value);
 
11759
 
 
11760
  _XmAppUnlock(app); 
 
11761
}
 
11762
 
 
11763
void 
 
11764
#ifdef _NO_PROTO
 
11765
XmDataFieldInsertWcs( w, position, wcstring )
 
11766
        Widget w ;
 
11767
        XmTextPosition position ;
 
11768
        wchar_t *wcstring ;
 
11769
#else
 
11770
XmDataFieldInsertWcs(
 
11771
        Widget w,
 
11772
        XmTextPosition position,
 
11773
        wchar_t *wcstring )
 
11774
#endif /* _NO_PROTO */
 
11775
{
 
11776
  _XmWidgetToAppContext(w);    
 
11777
  _XmAppLock(app);    
 
11778
 
 
11779
  /* XmDataFieldReplaceWcs takes care of converting to wchar_t* if needed */
 
11780
  XmDataFieldReplaceWcs(w, position, position, wcstring);
 
11781
 
 
11782
  _XmAppUnlock(app);
 
11783
}
 
11784
 
 
11785
void 
 
11786
#ifdef _NO_PROTO
 
11787
XmDataFieldSetAddMode( w, state )
 
11788
        Widget w ;
 
11789
        Boolean state ;
 
11790
#else
 
11791
XmDataFieldSetAddMode(
 
11792
        Widget w,
 
11793
        Boolean state )
 
11794
#endif /* _NO_PROTO */
 
11795
{
 
11796
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
11797
 
 
11798
  _XmWidgetToAppContext(w);    
 
11799
  _XmAppLock(app);    
 
11800
 
 
11801
   if (XmTextF_add_mode(tf) == state) 
 
11802
   {
 
11803
     _XmAppUnlock(app);
 
11804
     return;
 
11805
   }
 
11806
 
 
11807
   _XmDataFieldDrawInsertionPoint(tf, False);
 
11808
   XmTextF_add_mode(tf) = state;
 
11809
   _XmDataFToggleCursorGC(w);
 
11810
   _XmDataFieldDrawInsertionPoint(tf, True);
 
11811
 
 
11812
   _XmAppUnlock(app);
 
11813
}
 
11814
 
 
11815
Boolean 
 
11816
#ifdef _NO_PROTO
 
11817
XmDataFieldGetAddMode( w )
 
11818
        Widget w ;
 
11819
#else
 
11820
XmDataFieldGetAddMode(
 
11821
        Widget w )
 
11822
#endif /* _NO_PROTO */
 
11823
{
 
11824
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
11825
   Boolean ret_val;
 
11826
 
 
11827
   _XmWidgetToAppContext(w);    
 
11828
   _XmAppLock(app);   
 
11829
   
 
11830
   ret_val = XmTextF_add_mode(tf);
 
11831
   
 
11832
   _XmAppUnlock(app);
 
11833
   return (ret_val);
 
11834
}
 
11835
 
 
11836
Boolean 
 
11837
#ifdef _NO_PROTO
 
11838
XmDataFieldGetEditable( w )
 
11839
        Widget w ;
 
11840
#else
 
11841
XmDataFieldGetEditable(
 
11842
        Widget w )
 
11843
#endif /* _NO_PROTO */
 
11844
{
 
11845
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
11846
   Boolean ret_val;
 
11847
 
 
11848
   _XmWidgetToAppContext(w);    
 
11849
   _XmAppLock(app);   
 
11850
 
 
11851
   ret_val = XmTextF_editable(tf);    
 
11852
 
 
11853
   _XmAppUnlock(app);
 
11854
   return ret_val;
 
11855
}
 
11856
 
 
11857
void 
 
11858
#ifdef _NO_PROTO
 
11859
XmDataFieldSetEditable( w, editable )
 
11860
        Widget w ;
 
11861
        Boolean editable ;
 
11862
#else
 
11863
XmDataFieldSetEditable(
 
11864
        Widget w,
 
11865
        Boolean editable )
 
11866
#endif /* _NO_PROTO */
 
11867
{
 
11868
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
11869
    XPoint xmim_point;
 
11870
    Arg args[6];  /* To set initial values to input method */
 
11871
    Cardinal n = 0;
 
11872
 
 
11873
   _XmWidgetToAppContext(w);    
 
11874
   _XmAppLock(app);   
 
11875
 
 
11876
   /* if widget previously wasn't editable, no input method has yet been */
 
11877
   /* registered.  So, if we're making it editable now, register the IM  */
 
11878
   /* give the IM the relevent values.                                   */
 
11879
   
 
11880
   if (!XmTextF_editable(tf) && editable)
 
11881
     { 
 
11882
#if defined(__sgi)
 
11883
       /* CR03685 */
 
11884
       SGI_hack_XmImRegister((Widget)tf);
 
11885
#else
 
11886
       XmImRegister((Widget)tf, (unsigned int) NULL);
 
11887
#endif
 
11888
       df_GetXYFromPos(tf, XmTextF_cursor_position(tf), &xmim_point.x, 
 
11889
                       &xmim_point.y);
 
11890
       n = 0;
 
11891
       XtSetArg(args[n], XmNfontList, XmTextF_font_list(tf)); n++;
 
11892
       XtSetArg(args[n], XmNbackground, tf->core.background_pixel); n++;
 
11893
       XtSetArg(args[n], XmNforeground, tf->primitive.foreground); n++;
 
11894
       XtSetArg(args[n], XmNbackgroundPixmap,tf->core.background_pixmap);n++;
 
11895
       XtSetArg(args[n], XmNspotLocation, &xmim_point); n++;
 
11896
       XtSetArg(args[n], XmNlineSpace,
 
11897
                 XmTextF_font_ascent(tf)+ XmTextF_font_descent(tf)); n++;
 
11898
        XmImSetValues((Widget)tf, args, n);
 
11899
     } else if (XmTextF_editable(tf) && !editable){
 
11900
       XmImUnregister(w);
 
11901
    }
 
11902
 
 
11903
    XmTextF_editable(tf) = editable;
 
11904
    
 
11905
    n = 0;
 
11906
    if (editable) {
 
11907
        XtSetArg(args[n], XmNdropSiteActivity, XmDROP_SITE_ACTIVE); n++;
 
11908
    } else {
 
11909
        XtSetArg(args[n], XmNdropSiteActivity, XmDROP_SITE_INACTIVE); n++;
 
11910
    }   
 
11911
 
 
11912
    XmDropSiteUpdate((Widget)tf, args, n);
 
11913
    _XmAppUnlock(app);
 
11914
}
 
11915
 
 
11916
int 
 
11917
#ifdef _NO_PROTO
 
11918
XmDataFieldGetMaxLength( w )
 
11919
        Widget w ;
 
11920
#else
 
11921
XmDataFieldGetMaxLength(
 
11922
        Widget w )
 
11923
#endif /* _NO_PROTO */
 
11924
{
 
11925
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
11926
    int ret_val;
 
11927
 
 
11928
    _XmWidgetToAppContext(w);    
 
11929
    _XmAppLock(app);   
 
11930
   
 
11931
    ret_val = XmTextF_max_length(tf);
 
11932
    
 
11933
    _XmAppUnlock(app);
 
11934
    return ret_val;
 
11935
}
 
11936
 
 
11937
void 
 
11938
#ifdef _NO_PROTO
 
11939
XmDataFieldSetMaxLength( w, max_length )
 
11940
        Widget w ;
 
11941
        int max_length ;
 
11942
#else
 
11943
XmDataFieldSetMaxLength(
 
11944
        Widget w,
 
11945
        int max_length )
 
11946
#endif /* _NO_PROTO */
 
11947
{
 
11948
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
11949
 
 
11950
   _XmWidgetToAppContext(w);    
 
11951
   _XmAppLock(app);   
 
11952
 
 
11953
   XmTextF_max_length(tf) = max_length;
 
11954
 
 
11955
   _XmAppUnlock(app);
 
11956
}
 
11957
 
 
11958
XmTextPosition 
 
11959
#ifdef _NO_PROTO
 
11960
XmDataFieldGetCursorPosition( w )
 
11961
        Widget w ;
 
11962
#else
 
11963
XmDataFieldGetCursorPosition(
 
11964
        Widget w )
 
11965
#endif /* _NO_PROTO */
 
11966
{
 
11967
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
11968
   XmTextPosition ret_val;
 
11969
   
 
11970
   _XmWidgetToAppContext(w);    
 
11971
   _XmAppLock(app);
 
11972
 
 
11973
   ret_val = XmTextF_cursor_position(tf);
 
11974
 
 
11975
   _XmAppUnlock(app);
 
11976
   return ret_val;
 
11977
}
 
11978
 
 
11979
XmTextPosition 
 
11980
#ifdef _NO_PROTO
 
11981
XmDataFieldGetInsertionPosition( w )
 
11982
        Widget w ;
 
11983
#else
 
11984
XmDataFieldGetInsertionPosition(
 
11985
        Widget w )
 
11986
#endif /* _NO_PROTO */
 
11987
{
 
11988
    XmTextPosition ret_val;
 
11989
 
 
11990
   _XmWidgetToAppContext(w);    
 
11991
   _XmAppLock(app);
 
11992
 
 
11993
    ret_val = XmDataFieldGetCursorPosition(w);
 
11994
 
 
11995
    _XmAppUnlock(app);
 
11996
    return ret_val;
 
11997
}
 
11998
 
 
11999
/* Obsolete - shouldn't be here ! */
 
12000
void 
 
12001
#ifdef _NO_PROTO
 
12002
XmDataFielddf_SetCursorPosition( w, position )
 
12003
        Widget w ;
 
12004
        XmTextPosition position ;
 
12005
#else
 
12006
XmDataFielddf_SetCursorPosition(
 
12007
        Widget w,
 
12008
        XmTextPosition position )
 
12009
#endif /* _NO_PROTO */
 
12010
{
 
12011
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
12012
 
 
12013
   _XmWidgetToAppContext(w);    
 
12014
   _XmAppLock(app);
 
12015
 
 
12016
    df_SetCursorPosition(tf, NULL, position, True, False, False);
 
12017
    _XmAppUnlock(app);
 
12018
}
 
12019
 
 
12020
void 
 
12021
#ifdef _NO_PROTO
 
12022
XmDataFieldSetInsertionPosition( w, position )
 
12023
        Widget w ;
 
12024
        XmTextPosition position ;
 
12025
#else
 
12026
XmDataFieldSetInsertionPosition(
 
12027
        Widget w,
 
12028
        XmTextPosition position )
 
12029
#endif /* _NO_PROTO */
 
12030
{
 
12031
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
12032
 
 
12033
   _XmWidgetToAppContext(w);    
 
12034
   _XmAppLock(app);
 
12035
 
 
12036
   df_SetCursorPosition(tf, NULL, position, True, True, False);
 
12037
 
 
12038
   _XmAppUnlock(app);
 
12039
}
 
12040
 
 
12041
Boolean 
 
12042
#ifdef _NO_PROTO
 
12043
XmDataFieldGetSelectionPosition( w, left, right )
 
12044
        Widget w ;
 
12045
        XmTextPosition *left ;
 
12046
        XmTextPosition *right ;
 
12047
#else
 
12048
XmDataFieldGetSelectionPosition(
 
12049
        Widget w,
 
12050
        XmTextPosition *left,
 
12051
        XmTextPosition *right )
 
12052
#endif /* _NO_PROTO */
 
12053
{
 
12054
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
12055
 
 
12056
   _XmWidgetToAppContext(w);    
 
12057
   _XmAppLock(app);
 
12058
 
 
12059
   if (!XmTextF_has_primary(tf)) {
 
12060
     _XmAppUnlock(app); 
 
12061
       return False;
 
12062
   }
 
12063
 
 
12064
   *left = XmTextF_prim_pos_left(tf);
 
12065
   *right = XmTextF_prim_pos_right(tf);
 
12066
 
 
12067
   _XmAppUnlock(app); 
 
12068
   return True;
 
12069
}
 
12070
 
 
12071
char * 
 
12072
#ifdef _NO_PROTO
 
12073
XmDataFieldGetSelection( w )
 
12074
        Widget w ;
 
12075
#else
 
12076
XmDataFieldGetSelection(
 
12077
        Widget w )
 
12078
#endif /* _NO_PROTO */
 
12079
{
 
12080
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
12081
   size_t length, num_chars;
 
12082
   char *value;
 
12083
 
 
12084
   _XmWidgetToAppContext(w);    
 
12085
   _XmAppLock(app);
 
12086
 
 
12087
    if (XmTextF_prim_pos_left(tf) == XmTextF_prim_pos_right(tf))
 
12088
    {
 
12089
      _XmAppUnlock(app);
 
12090
      return NULL;
 
12091
    }
 
12092
 
 
12093
    num_chars = (size_t) (XmTextF_prim_pos_right(tf) \
 
12094
                          - XmTextF_prim_pos_left(tf));
 
12095
    length = num_chars;
 
12096
 
 
12097
    if (XmTextF_max_char_size(tf) == 1) 
 
12098
    {
 
12099
        value = XtMalloc((unsigned) num_chars + 1);
 
12100
        (void) memcpy((void*)value, 
 
12101
                      (void*)(XmTextF_value(tf) + 
 
12102
                              XmTextF_prim_pos_left(tf)), num_chars);
 
12103
    } 
 
12104
    else 
 
12105
    {
 
12106
        value = XtMalloc((unsigned) ((num_chars + 1) * XmTextF_max_char_size(tf)));
 
12107
        length = wcstombs(value, XmTextF_wc_value(tf) + XmTextF_prim_pos_left(tf), 
 
12108
                          (num_chars + 1) * XmTextF_max_char_size(tf));
 
12109
        if (length == (size_t) -1) 
 
12110
        {
 
12111
            length = 0;
 
12112
        } 
 
12113
        else 
 
12114
        {
 
12115
            for (length = 0;num_chars > 0; num_chars--) 
 
12116
            {
 
12117
                length += mblen(&value[length], XmTextF_max_char_size(tf));
 
12118
            }
 
12119
        }
 
12120
    }
 
12121
    value[length] = (char)'\0';
 
12122
 
 
12123
    _XmAppUnlock(app);
 
12124
    return value;
 
12125
}
 
12126
 
 
12127
wchar_t *
 
12128
#ifdef _NO_PROTO
 
12129
XmDataFieldGetSelectionWcs( w )
 
12130
        Widget w ;
 
12131
#else
 
12132
XmDataFieldGetSelectionWcs(
 
12133
        Widget w )
 
12134
#endif /* _NO_PROTO */
 
12135
{
 
12136
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
12137
   size_t length;
 
12138
   wchar_t *wc_value;
 
12139
   int return_val;
 
12140
 
 
12141
   _XmWidgetToAppContext(w);    
 
12142
   _XmAppLock(app);
 
12143
 
 
12144
   if (XmTextF_prim_pos_left(tf) == XmTextF_prim_pos_right(tf))
 
12145
   {
 
12146
     _XmAppUnlock(app);
 
12147
     return NULL;
 
12148
   }
 
12149
 
 
12150
   length = (size_t)(XmTextF_prim_pos_right(tf) - 
 
12151
                     XmTextF_prim_pos_left(tf));
 
12152
 
 
12153
   wc_value = (wchar_t*)XtMalloc((unsigned) (length + 1) * sizeof(wchar_t));
 
12154
 
 
12155
   if (XmTextF_max_char_size(tf) == 1) 
 
12156
   {
 
12157
       return_val = mbstowcs(wc_value, XmTextF_value(tf) + 
 
12158
                             XmTextF_prim_pos_left(tf), length);
 
12159
       if (return_val < 0) length = 0;
 
12160
   } 
 
12161
   else 
 
12162
   {
 
12163
      (void)memcpy((void*)wc_value, 
 
12164
                   (void*)(XmTextF_wc_value(tf) + XmTextF_prim_pos_left(tf)), 
 
12165
                   length * sizeof(wchar_t));
 
12166
   }
 
12167
   wc_value[length] = (wchar_t)0L;
 
12168
 
 
12169
   _XmAppUnlock(app);
 
12170
   return (wc_value);
 
12171
}
 
12172
 
 
12173
 
 
12174
Boolean 
 
12175
#ifdef _NO_PROTO
 
12176
XmDataFieldRemove( w )
 
12177
        Widget w ;
 
12178
#else
 
12179
XmDataFieldRemove(
 
12180
        Widget w )
 
12181
#endif /* _NO_PROTO */
 
12182
{
 
12183
    Boolean ret_val;
 
12184
 
 
12185
   _XmWidgetToAppContext(w);    
 
12186
   _XmAppLock(app);
 
12187
    
 
12188
    ret_val = DataFieldRemove(w, NULL);
 
12189
 
 
12190
    _XmAppUnlock(app);
 
12191
    return ret_val;
 
12192
}
 
12193
 
 
12194
Boolean 
 
12195
#ifdef _NO_PROTO
 
12196
XmDataFieldCopy( w, clip_time )
 
12197
        Widget w ;
 
12198
        Time clip_time ;
 
12199
#else
 
12200
XmDataFieldCopy(
 
12201
        Widget w,
 
12202
        Time clip_time )
 
12203
#endif /* _NO_PROTO */
 
12204
{
 
12205
    /* XmDataFieldGetSelection gets char* rep of data, so no special handling
 
12206
     * needed
 
12207
     */
 
12208
    char * selected_string = XmDataFieldGetSelection(w); /* text selection */
 
12209
    long item_id = 0L;                      /* clipboard item id */
 
12210
    long data_id = 0;                        /* clipboard data id */
 
12211
    int status = 0;                         /* clipboard status  */
 
12212
    XmString clip_label;
 
12213
    XTextProperty tmp_prop;
 
12214
    Display *display = XtDisplay(w);
 
12215
    Window window = XtWindow(w);
 
12216
    char *atom_name;
 
12217
 
 
12218
   _XmWidgetToAppContext(w);    
 
12219
   _XmAppLock(app);
 
12220
    
 
12221
    /* using the clipboard facilities, copy the selected text to the clipboard */
 
12222
    if (selected_string != NULL) 
 
12223
    {
 
12224
        clip_label = XmStringCreateLtoR ("XM_TEXT_FIELD",
 
12225
                                         XmFONTLIST_DEFAULT_TAG);
 
12226
 
 
12227
        /* start copy to clipboard */
 
12228
        status = XmClipboardStartCopy(display, window, clip_label, clip_time,
 
12229
                                      w, (XmCutPasteProc)NULL, &item_id);
 
12230
 
 
12231
        if (status != ClipboardSuccess) 
 
12232
        {
 
12233
            XtFree(selected_string);
 
12234
            XmStringFree(clip_label);
 
12235
            _XmAppUnlock(app);
 
12236
            return False;
 
12237
        }
 
12238
 
 
12239
        status = XmbTextListToTextProperty(display, &selected_string, 1,
 
12240
                                           (XICCEncodingStyle)XStdICCTextStyle,
 
12241
                                           &tmp_prop);
 
12242
 
 
12243
        if (status != Success && status <= 0) 
 
12244
        {
 
12245
            XmClipboardCancelCopy(display, window, item_id);
 
12246
            XtFree(selected_string);
 
12247
            XmStringFree(clip_label);
 
12248
            _XmAppUnlock(app);
 
12249
            return False;
 
12250
        }
 
12251
 
 
12252
        atom_name = XGetAtomName(display, tmp_prop.encoding);
 
12253
 
 
12254
        /* move the data to the clipboard */
 
12255
        status = XmClipboardCopy(display, window, item_id, atom_name,
 
12256
                                 (XtPointer)tmp_prop.value, tmp_prop.nitems,
 
12257
                                 0, &data_id);
 
12258
 
 
12259
        XtFree(atom_name);
 
12260
        
 
12261
        if (status != ClipboardSuccess) 
 
12262
        {
 
12263
            XmClipboardCancelCopy(XtDisplay(w), XtWindow(w), item_id);
 
12264
            XtFree(selected_string);
 
12265
            XmStringFree(clip_label);
 
12266
            _XmAppUnlock(app);
 
12267
            return False;
 
12268
        }
 
12269
 
 
12270
        /* end the copy to the clipboard */
 
12271
        status = XmClipboardEndCopy(display, window, item_id);
 
12272
        
 
12273
        XtFree((char*)tmp_prop.value);
 
12274
        XmStringFree(clip_label);
 
12275
 
 
12276
        if (status != ClipboardSuccess) 
 
12277
        {
 
12278
            XtFree (selected_string);
 
12279
            _XmAppUnlock(app);
 
12280
            return False;
 
12281
        }
 
12282
        
 
12283
    }    
 
12284
    else
 
12285
      {
 
12286
        _XmAppUnlock(app);
 
12287
        return False;
 
12288
      }
 
12289
 
 
12290
    if (selected_string != NULL)
 
12291
    {
 
12292
        XtFree (selected_string);
 
12293
    }
 
12294
 
 
12295
    _XmAppUnlock(app);
 
12296
    return True;
 
12297
}
 
12298
 
 
12299
Boolean 
 
12300
#ifdef _NO_PROTO
 
12301
XmDataFieldCut( w, clip_time )
 
12302
        Widget w ;
 
12303
        Time clip_time ;
 
12304
#else
 
12305
XmDataFieldCut(
 
12306
        Widget w,
 
12307
        Time clip_time )
 
12308
#endif /* _NO_PROTO */
 
12309
{
 
12310
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
12311
    Boolean success = False;
 
12312
 
 
12313
   _XmWidgetToAppContext(w);    
 
12314
   _XmAppLock(app);
 
12315
    
 
12316
    if (XmTextF_editable(tf) == False)
 
12317
    {
 
12318
      _XmAppUnlock(app);
 
12319
      return False;
 
12320
    }
 
12321
 
 
12322
    if (XmDataFieldCopy(w, clip_time))
 
12323
    {
 
12324
        if (XmDataFieldRemove(w))
 
12325
        {
 
12326
            success = True;
 
12327
        }
 
12328
    }
 
12329
 
 
12330
    _XmAppUnlock(app);
 
12331
    return success;
 
12332
}
 
12333
 
 
12334
 
 
12335
/*
 
12336
 * Retrieves the current data from the clipboard
 
12337
 * and paste it at the current cursor position
 
12338
 */
 
12339
Boolean 
 
12340
#ifdef _NO_PROTO
 
12341
XmDataFieldPaste( w )
 
12342
        Widget w ;
 
12343
#else
 
12344
XmDataFieldPaste(
 
12345
        Widget w )
 
12346
#endif /* _NO_PROTO */
 
12347
{
 
12348
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
12349
    XmTextPosition sel_left = 0;
 
12350
    XmTextPosition sel_right = 0;
 
12351
    XmTextPosition paste_pos_left, paste_pos_right;
 
12352
    int status = 0;                            /* clipboard status        */
 
12353
    char* buffer;                              /* temporary text buffer   */
 
12354
    unsigned long length;                      /* length of buffer        */
 
12355
    unsigned long outlength = 0L;              /* length of bytes copied  */
 
12356
    long private_id = 0;                       /* id of item on clipboard */
 
12357
    Boolean dest_disjoint = True;
 
12358
    Boolean rep_status = False;                /* did Replace succeed? */
 
12359
    Display *display = XtDisplay(w);
 
12360
    Window window = XtWindow(w);
 
12361
    Boolean get_ct = False;
 
12362
    Boolean get_us = False;
 
12363
    XTextProperty tmp_prop;
 
12364
    int malloc_size = 0;
 
12365
    int num_vals;
 
12366
    char **tmp_value;
 
12367
    int i;
 
12368
    XmAnyCallbackStruct cb;
 
12369
 
 
12370
   _XmWidgetToAppContext(w);    
 
12371
   _XmAppLock(app);
 
12372
    
 
12373
    if (XmTextF_editable(tf) == False) 
 
12374
    {
 
12375
      _XmAppUnlock(app);
 
12376
      return False;
 
12377
    }
 
12378
 
 
12379
    paste_pos_left = paste_pos_right = XmTextF_cursor_position(tf);
 
12380
 
 
12381
    status = XmClipboardInquireLength(display, window, "STRING", &length);
 
12382
 
 
12383
    if (status == ClipboardNoData || length == 0) 
 
12384
    {
 
12385
        status = XmClipboardInquireLength(display, 
 
12386
                                          window, "COMPOUND_TEXT",
 
12387
                                          &length);
 
12388
        if (status == ClipboardNoData || length == 0) 
 
12389
        {
 
12390
#ifdef UTF8_SUPPORTED
 
12391
          status = XmClipboardInquireLength(display, window,
 
12392
                                            XmSUTF8_STRING, &length);
 
12393
#endif
 
12394
          if (status == ClipboardNoData || length == 0)
 
12395
          {
 
12396
            _XmAppUnlock(app);
 
12397
            return False;
 
12398
          }
 
12399
          get_us = True;
 
12400
        } else {
 
12401
          get_ct = True;
 
12402
        }
 
12403
   }
 
12404
 
 
12405
   /* malloc length of clipboard data */
 
12406
   buffer = XtMalloc((unsigned) length);
 
12407
 
 
12408
   if (!get_ct && !get_us) 
 
12409
   {
 
12410
       status = XmClipboardRetrieve(display, window, "STRING", buffer,
 
12411
                                    length, &outlength, &private_id);
 
12412
   } 
 
12413
#ifdef UTF8_SUPPORTED
 
12414
   else if (!get_ct && get_us) {
 
12415
       status = XmClipboardRetrieve(display, window, XmSUTF8_STRING, buffer,
 
12416
                                    length, &outlength, &private_id);
 
12417
   }
 
12418
#endif
 
12419
   else 
 
12420
   {
 
12421
       status = XmClipboardRetrieve(display, window, "COMPOUND_TEXT", buffer,
 
12422
                                    length, &outlength, &private_id);
 
12423
   }    
 
12424
 
 
12425
   if (status != ClipboardSuccess) 
 
12426
   {
 
12427
       XmClipboardEndRetrieve(display, window);
 
12428
       XtFree(buffer);
 
12429
       _XmAppUnlock(app);
 
12430
       return False;
 
12431
   }
 
12432
 
 
12433
   if (XmDataFieldGetSelectionPosition(w, &sel_left, &sel_right)) 
 
12434
   {
 
12435
       if (XmTextF_pending_delete(tf) &&
 
12436
           paste_pos_left >= sel_left && paste_pos_right <= sel_right) 
 
12437
       {
 
12438
           paste_pos_left = sel_left;
 
12439
           paste_pos_right = sel_right;
 
12440
           dest_disjoint = False;
 
12441
       }
 
12442
   }
 
12443
 
 
12444
   tmp_prop.value = (unsigned char *) buffer;
 
12445
 
 
12446
   if (!get_ct)
 
12447
   {
 
12448
       tmp_prop.encoding = XA_STRING;
 
12449
   }
 
12450
   else
 
12451
   {
 
12452
       tmp_prop.encoding = XmInternAtom(display, "COMPOUND_TEXT", False);
 
12453
   }
 
12454
 
 
12455
   tmp_prop.format = 8;
 
12456
   tmp_prop.nitems = outlength;
 
12457
   num_vals = 0;
 
12458
 
 
12459
   status = XmbTextPropertyToTextList(display, &tmp_prop, &tmp_value,
 
12460
                                      &num_vals);
 
12461
 
 
12462
  /* add new text */
 
12463
   if (num_vals && (status == Success || status > 0)) 
 
12464
   {
 
12465
       if (XmTextF_max_char_size(tf) == 1)
 
12466
       {
 
12467
           char * total_tmp_value;
 
12468
 
 
12469
           for (i = 0, malloc_size = 1; i < num_vals ; i++) 
 
12470
           {
 
12471
               malloc_size += strlen(tmp_value[i]);
 
12472
           }
 
12473
           total_tmp_value = XtMalloc ((unsigned) malloc_size);
 
12474
           total_tmp_value[0] = '\0';
 
12475
           for (i = 0; i < num_vals ; i++)
 
12476
           {
 
12477
               strcat(total_tmp_value, tmp_value[i]);
 
12478
           }
 
12479
           rep_status = _XmDataFieldReplaceText(tf, NULL, paste_pos_left,
 
12480
                                                paste_pos_right, 
 
12481
                                                total_tmp_value,
 
12482
                                                strlen(total_tmp_value), True);
 
12483
           XFreeStringList(tmp_value);
 
12484
           if (malloc_size) XtFree(total_tmp_value);
 
12485
       } else {
 
12486
         wchar_t * wc_value;
 
12487
         int num_chars = 0;
 
12488
 
 
12489
         for (i = 0, malloc_size = sizeof(wchar_t); i < num_vals ; i++)
 
12490
         {
 
12491
             malloc_size += strlen(tmp_value[i]);
 
12492
         }
 
12493
         wc_value = (wchar_t*)XtMalloc((unsigned)malloc_size * sizeof(wchar_t));
 
12494
         /* change malloc_size to the number of wchars available in wc_value */
 
12495
         for (i = 0; i < num_vals ; i++)
 
12496
             num_chars +=
 
12497
                 mbstowcs(wc_value + num_chars, tmp_value[i],
 
12498
                          (size_t)malloc_size - num_chars);
 
12499
         rep_status = _XmDataFieldReplaceText(tf, NULL, paste_pos_left,
 
12500
                                              paste_pos_right,
 
12501
                                              (char*)wc_value, 
 
12502
                                              num_chars, True);
 
12503
         if (malloc_size) XtFree((char*)wc_value);
 
12504
       }
 
12505
   }
 
12506
 
 
12507
   if (rep_status) {
 
12508
       XmTextF_prim_anchor(tf) = sel_left;
 
12509
       (void) df_SetDestination(w, XmTextF_cursor_position(tf), False,
 
12510
                                XtLastTimestampProcessed(display));
 
12511
       if (sel_left != sel_right) 
 
12512
       {
 
12513
           if (!dest_disjoint || !XmTextF_add_mode(tf)) 
 
12514
           {
 
12515
               XmDataFieldSetSelection(w, XmTextF_cursor_position(tf),
 
12516
                                       XmTextF_cursor_position(tf),
 
12517
                                       XtLastTimestampProcessed(display));
 
12518
           }
 
12519
       }
 
12520
       cb.reason = XmCR_VALUE_CHANGED;
 
12521
       cb.event = (XEvent *)NULL;
 
12522
       XtCallCallbackList((Widget) tf, XmTextF_value_changed_callback(tf),
 
12523
                          (XtPointer) &cb);
 
12524
   }
 
12525
   XtFree(buffer);
 
12526
 
 
12527
   _XmAppUnlock(app);
 
12528
   return True;
 
12529
}
 
12530
 
 
12531
void 
 
12532
#ifdef _NO_PROTO
 
12533
XmDataFielddf_ClearSelection( w, sel_time )
 
12534
        Widget w ;
 
12535
        Time sel_time ;
 
12536
#else
 
12537
XmDataFielddf_ClearSelection(
 
12538
        Widget w,
 
12539
        Time sel_time )
 
12540
#endif /* _NO_PROTO */
 
12541
{  
 
12542
  _XmWidgetToAppContext(w);    
 
12543
  _XmAppLock(app);
 
12544
 
 
12545
  _XmDataFieldDeselectSelection(w, False, sel_time);
 
12546
 
 
12547
  _XmAppUnlock(app);
 
12548
}
 
12549
 
 
12550
void 
 
12551
#ifdef _NO_PROTO
 
12552
XmDataFieldSetSelection( w, first, last, sel_time )
 
12553
        Widget w ;
 
12554
        XmTextPosition first ;
 
12555
        XmTextPosition last ;
 
12556
        Time sel_time ;
 
12557
#else
 
12558
XmDataFieldSetSelection(
 
12559
        Widget w,
 
12560
        XmTextPosition first,
 
12561
        XmTextPosition last,
 
12562
        Time sel_time )
 
12563
#endif /* _NO_PROTO */
 
12564
{
 
12565
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
12566
 
 
12567
  _XmWidgetToAppContext(w);    
 
12568
  _XmAppLock(app);
 
12569
 
 
12570
  _XmDataFieldStartSelection(tf, first, last, sel_time);
 
12571
  XmTextF_pending_off(tf) = False;
 
12572
  df_SetCursorPosition(tf, NULL, last, True, True, False);
 
12573
 
 
12574
  _XmAppUnlock(app);
 
12575
}
 
12576
 
 
12577
/* ARGSUSED */
 
12578
XmTextPosition 
 
12579
#ifdef _NO_PROTO
 
12580
XmDataFieldXYToPos( w, x, y )
 
12581
        Widget w ;
 
12582
        Position x ;
 
12583
        Position y ;
 
12584
#else
 
12585
XmDataFieldXYToPos(
 
12586
        Widget w,
 
12587
        Position x,
 
12588
        Position y )
 
12589
#endif /* _NO_PROTO */
 
12590
{
 
12591
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
12592
    XmTextPosition ret_val;
 
12593
 
 
12594
  _XmWidgetToAppContext(w);    
 
12595
  _XmAppLock(app);
 
12596
 
 
12597
    ret_val = df_GetPosFromX(tf, x);
 
12598
 
 
12599
    _XmAppUnlock(app);
 
12600
    return(ret_val);
 
12601
}
 
12602
 
 
12603
Boolean 
 
12604
#ifdef _NO_PROTO
 
12605
XmDataFieldPosToXY( w, position, x, y )
 
12606
     Widget w ;
 
12607
     XmTextPosition position ;
 
12608
     Position *x ;
 
12609
     Position *y ;
 
12610
#else  
 
12611
XmDataFieldPosToXY(
 
12612
                   Widget w,
 
12613
                   XmTextPosition position,
 
12614
                   Position *x,
 
12615
                   Position *y )
 
12616
#endif /* _NO_PROTO */
 
12617
{
 
12618
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
12619
  Boolean ret_val;
 
12620
 
 
12621
  _XmWidgetToAppContext(w);    
 
12622
  _XmAppLock(app);
 
12623
 
 
12624
  ret_val = df_GetXYFromPos(tf, position, x, y);
 
12625
 
 
12626
  _XmAppUnlock(app);
 
12627
  return(ret_val);
 
12628
}
 
12629
 
 
12630
/*
 
12631
 * Force the given position to be displayed.  If position < 0, then don't force
 
12632
 * any position to be displayed.
 
12633
 */
 
12634
void 
 
12635
#ifdef _NO_PROTO
 
12636
XmDataFieldShowPosition( w, position )
 
12637
        Widget w ;
 
12638
        XmTextPosition position ;
 
12639
#else
 
12640
XmDataFieldShowPosition(
 
12641
        Widget w,
 
12642
        XmTextPosition position )
 
12643
#endif /* _NO_PROTO */
 
12644
{
 
12645
  XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
12646
 
 
12647
  _XmWidgetToAppContext(w);    
 
12648
  _XmAppLock(app);
 
12649
    
 
12650
  if (position < 0) {
 
12651
    _XmAppUnlock(app); 
 
12652
    return;
 
12653
  }
 
12654
 
 
12655
  df_AdjustText(tf, position, True);
 
12656
 
 
12657
  _XmAppUnlock(app);
 
12658
}
 
12659
 
 
12660
/* ARGSUSED */
 
12661
void 
 
12662
#ifdef _NO_PROTO
 
12663
XmDataFieldSetHighlight( w, left, right, mode )
 
12664
        Widget w ;
 
12665
        XmTextPosition left ;
 
12666
        XmTextPosition right ;
 
12667
        XmHighlightMode mode ;
 
12668
#else
 
12669
XmDataFieldSetHighlight(
 
12670
        Widget w,
 
12671
        XmTextPosition left,
 
12672
        XmTextPosition right,
 
12673
        XmHighlightMode mode )
 
12674
#endif /* _NO_PROTO */
 
12675
{
 
12676
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
12677
 
 
12678
    _XmWidgetToAppContext(w);    
 
12679
    _XmAppLock(app);
 
12680
 
 
12681
    if (left >= right || right <= 0) {
 
12682
      _XmAppUnlock(app);
 
12683
      return;
 
12684
    }
 
12685
 
 
12686
    if (left < 0) left = 0;
 
12687
 
 
12688
    if (right > XmTextF_string_length(tf)) 
 
12689
    {
 
12690
        right = XmTextF_string_length(tf);
 
12691
    }
 
12692
 
 
12693
    DataFieldSetHighlight(tf, left, right, mode);
 
12694
 
 
12695
    df_RedisplayText(tf, left, right);
 
12696
    _XmAppUnlock(app);
 
12697
}
 
12698
 
 
12699
/* ARGSUSED */
 
12700
static Boolean 
 
12701
#ifdef _NO_PROTO
 
12702
DataFieldGetBaselines( w, baselines, line_count )
 
12703
        Widget w ;
 
12704
        Dimension ** baselines;
 
12705
        int *line_count;
 
12706
#else
 
12707
DataFieldGetBaselines(
 
12708
        Widget w,
 
12709
        Dimension ** baselines,
 
12710
        int *line_count )
 
12711
#endif /* _NO_PROTO */
 
12712
{
 
12713
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
12714
    Dimension *base_array;
 
12715
 
 
12716
    _XmWidgetToAppContext(w);    
 
12717
    _XmAppLock(app);
 
12718
 
 
12719
    *line_count = 1;
 
12720
    base_array = (Dimension *) XtMalloc(sizeof(Dimension));
 
12721
    base_array[0] = XmTextF_margin_top(tf) + tf->primitive.shadow_thickness +
 
12722
        tf->primitive.highlight_thickness + XmTextF_font_ascent(tf);
 
12723
 
 
12724
    *baselines = base_array;
 
12725
 
 
12726
    _XmAppUnlock(app);
 
12727
    return (TRUE);
 
12728
}
 
12729
 
 
12730
int 
 
12731
#ifdef _NO_PROTO
 
12732
XmDataFieldGetBaseline( w )
 
12733
        Widget w ;
 
12734
#else
 
12735
XmDataFieldGetBaseline(
 
12736
        Widget w )
 
12737
#endif /* _NO_PROTO */
 
12738
{
 
12739
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
12740
    Dimension margin_top;
 
12741
    int ret_val;
 
12742
 
 
12743
    _XmWidgetToAppContext(w);    
 
12744
    _XmAppLock(app);
 
12745
 
 
12746
    margin_top = XmTextF_margin_top(tf) +
 
12747
        tf->primitive.shadow_thickness +
 
12748
        tf->primitive.highlight_thickness;
 
12749
 
 
12750
    ret_val = (int) margin_top + (int) XmTextF_font_ascent(tf);
 
12751
 
 
12752
    _XmAppUnlock(app);
 
12753
    return(ret_val);
 
12754
}
 
12755
 
 
12756
static Boolean
 
12757
#ifdef _NO_PROTO
 
12758
DataFieldGetDisplayRect( w, display_rect )
 
12759
        Widget w;
 
12760
        XRectangle * display_rect;
 
12761
#else
 
12762
DataFieldGetDisplayRect(
 
12763
        Widget w,
 
12764
        XRectangle * display_rect )
 
12765
#endif /* _NO_PROTO */
 
12766
{
 
12767
   XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
12768
 
 
12769
   Position margin_width = XmTextF_margin_width(tf) +
 
12770
                           tf->primitive.shadow_thickness +
 
12771
                           tf->primitive.highlight_thickness;
 
12772
   Position margin_top = XmTextF_margin_top(tf) + tf->primitive.shadow_thickness +
 
12773
                         tf->primitive.highlight_thickness;
 
12774
   Position margin_bottom = XmTextF_margin_bottom(tf) +
 
12775
                            tf->primitive.shadow_thickness +
 
12776
                            tf->primitive.highlight_thickness;
 
12777
   (*display_rect).x = margin_width;
 
12778
   (*display_rect).y = margin_top;
 
12779
   (*display_rect).width = tf->core.width - (2 * margin_width);
 
12780
   (*display_rect).height = tf->core.height - (margin_top + margin_bottom);
 
12781
 
 
12782
   return(TRUE);
 
12783
}
 
12784
 
 
12785
 
 
12786
/* ARGSUSED */
 
12787
static void
 
12788
#ifdef _NO_PROTO
 
12789
DataFieldMarginsProc( w, margins_rec )
 
12790
        Widget w ;
 
12791
        XmBaselineMargins *margins_rec;
 
12792
#else
 
12793
DataFieldMarginsProc(
 
12794
        Widget w,
 
12795
        XmBaselineMargins *margins_rec )
 
12796
#endif /* _NO_PROTO */
 
12797
{
 
12798
    XmDataFieldWidget tf = (XmDataFieldWidget) w;
 
12799
 
 
12800
    if (margins_rec->get_or_set == XmBASELINE_SET) {
 
12801
       XmTextF_margin_top(tf) = margins_rec->margin_top;
 
12802
       XmTextF_margin_bottom(tf) = margins_rec->margin_bottom;
 
12803
    } else {
 
12804
       margins_rec->margin_top = XmTextF_margin_top(tf);
 
12805
       margins_rec->margin_bottom = XmTextF_margin_bottom(tf);
 
12806
       margins_rec->text_height = XmTextF_font_ascent(tf) + XmTextF_font_descent(tf);
 
12807
       margins_rec->shadow = tf->primitive.shadow_thickness;
 
12808
       margins_rec->highlight = tf->primitive.highlight_thickness;
 
12809
    }
 
12810
}
 
12811
 
 
12812
/*
 
12813
 * Text Field w creation convienence routine.
 
12814
 */
 
12815
 
 
12816
Widget 
 
12817
#ifdef _NO_PROTO
 
12818
XmCreateDataField( parent, name, arglist, argcount )
 
12819
        Widget parent ;
 
12820
        char *name ;
 
12821
        ArgList arglist ;
 
12822
        Cardinal argcount ;
 
12823
#else
 
12824
XmCreateDataField(
 
12825
        Widget parent,
 
12826
        char *name,
 
12827
        ArgList arglist,
 
12828
        Cardinal argcount )
 
12829
#endif /* _NO_PROTO */
 
12830
{
 
12831
    return (XtCreateWidget(name, xmDataFieldWidgetClass,
 
12832
                           parent, arglist, argcount));
 
12833
}
 
12834
 
 
12835
Widget 
 
12836
XmVaCreateDataField(
 
12837
        Widget parent,
 
12838
        char *name,
 
12839
        ...)
 
12840
{
 
12841
    register Widget w;
 
12842
    va_list var;
 
12843
    int count;
 
12844
    
 
12845
    Va_start(var,name);
 
12846
    count = XmeCountVaListSimple(var);
 
12847
    va_end(var);
 
12848
 
 
12849
    
 
12850
    Va_start(var, name);
 
12851
    w = XmeVLCreateWidget(name, 
 
12852
                         xmDataFieldWidgetClass,
 
12853
                         parent, False, 
 
12854
                         var, count);
 
12855
    va_end(var);   
 
12856
    return w;
 
12857
}
 
12858
 
 
12859
Widget
 
12860
XmVaCreateManagedDataField(
 
12861
        Widget parent,
 
12862
        char *name,
 
12863
        ...)
 
12864
{
 
12865
    Widget w = NULL;
 
12866
    va_list var;
 
12867
    int count;
 
12868
    
 
12869
    Va_start(var, name);
 
12870
    count = XmeCountVaListSimple(var);
 
12871
    va_end(var);
 
12872
    
 
12873
    Va_start(var, name);
 
12874
    w = XmeVLCreateWidget(name, 
 
12875
                         xmDataFieldWidgetClass,
 
12876
                         parent, True, 
 
12877
                         var, count);
 
12878
    va_end(var);   
 
12879
    return w;
 
12880
}