Avoid icon change to default on winspector save
[wmaker-crm.git] / WINGs / wtextfield.c
blob4d4c6458dd4c0e6bd884cf474f5a2b95392f6d1f
2 #include "WINGsP.h"
3 #include "wconfig.h"
5 #include <X11/keysym.h>
6 #include <X11/Xatom.h>
8 #include <ctype.h>
10 #define CURSOR_BLINK_ON_DELAY 600
11 #define CURSOR_BLINK_OFF_DELAY 300
13 char *WMTextDidChangeNotification = "WMTextDidChangeNotification";
14 char *WMTextDidBeginEditingNotification = "WMTextDidBeginEditingNotification";
15 char *WMTextDidEndEditingNotification = "WMTextDidEndEditingNotification";
17 typedef struct W_TextField {
18 W_Class widgetClass;
19 W_View *view;
21 #if 0
22 struct W_TextField *nextField; /* next textfield in the chain */
23 struct W_TextField *prevField;
24 #endif
26 char *text;
27 int textLen; /* size of text */
28 int bufferSize; /* memory allocated for text */
30 int viewPosition; /* position of text being shown */
32 int cursorPosition; /* position of the insertion cursor */
34 short usableWidth;
35 short offsetWidth; /* offset of text from border */
37 WMRange selection;
39 WMFont *font;
41 WMTextFieldDelegate *delegate;
43 #if 0
44 WMHandlerID timerID; /* for cursor blinking */
45 #endif
46 struct {
47 WMAlignment alignment:2;
49 unsigned int bordered:1;
51 unsigned int beveled:1;
53 unsigned int enabled:1;
55 unsigned int focused:1;
57 unsigned int cursorOn:1;
59 unsigned int secure:1; /* password entry style */
61 unsigned int pointerGrabbed:1;
63 unsigned int ownsSelection:1;
65 unsigned int waitingSelection:1; /* requested selection, but
66 * didnt get yet */
68 unsigned int notIllegalMovement:1;
69 } flags;
70 } TextField;
72 #define NOTIFY(T,C,N,A) { WMNotification *notif = WMCreateNotification(N,T,A);\
73 if ((T)->delegate && (T)->delegate->C)\
74 (*(T)->delegate->C)((T)->delegate,notif);\
75 WMPostNotification(notif);\
76 WMReleaseNotification(notif);}
78 #define MIN_TEXT_BUFFER 2
79 #define TEXT_BUFFER_INCR 8
81 #define WM_EMACSKEYMASK ControlMask
83 #define WM_EMACSKEY_LEFT XK_b
84 #define WM_EMACSKEY_RIGHT XK_f
85 #define WM_EMACSKEY_HOME XK_a
86 #define WM_EMACSKEY_END XK_e
87 #define WM_EMACSKEY_BS XK_h
88 #define WM_EMACSKEY_DEL XK_d
90 #define DEFAULT_WIDTH 60
91 #define DEFAULT_HEIGHT 20
92 #define DEFAULT_BORDERED True
93 #define DEFAULT_ALIGNMENT WALeft
95 static void destroyTextField(TextField * tPtr);
96 static void paintTextField(TextField * tPtr);
98 static void handleEvents(XEvent * event, void *data);
99 static void handleTextFieldActionEvents(XEvent * event, void *data);
100 static void didResizeTextField();
102 struct W_ViewDelegate _TextFieldViewDelegate = {
103 NULL,
104 NULL,
105 didResizeTextField,
106 NULL,
107 NULL
110 static void lostSelection(WMView * view, Atom selection, void *cdata);
112 static WMData *requestHandler(WMView * view, Atom selection, Atom target, void *cdata, Atom * type);
114 static WMSelectionProcs selectionHandler = {
115 requestHandler,
116 lostSelection,
117 NULL
120 #define TEXT_WIDTH(tPtr, start) (WMWidthOfString((tPtr)->font, \
121 &((tPtr)->text[(start)]), (tPtr)->textLen - (start)))
123 #define TEXT_WIDTH2(tPtr, start, end) (WMWidthOfString((tPtr)->font, \
124 &((tPtr)->text[(start)]), (end) - (start)))
126 static INLINE int oneUTF8CharBackward(char *str, int len)
128 unsigned char *ustr = (unsigned char *)str;
129 int pos = 0;
131 while (len-- > 0 && ustr[--pos] >= 0x80 && ustr[pos] <= 0xbf) ;
132 return pos;
135 static INLINE int oneUTF8CharForward(char *str, int len)
137 unsigned char *ustr = (unsigned char *)str;
138 int pos = 0;
140 while (len-- > 0 && ustr[++pos] >= 0x80 && ustr[pos] <= 0xbf) ;
141 return pos;
144 // find the beginning of the UTF8 char pointed by str
145 static INLINE int seekUTF8CharStart(char *str, int len)
147 unsigned char *ustr = (unsigned char *)str;
148 int pos = 0;
150 while (len-- > 0 && ustr[pos] >= 0x80 && ustr[pos] <= 0xbf)
151 --pos;
152 return pos;
155 static void normalizeRange(TextField * tPtr, WMRange * range)
157 if (range->position < 0 && range->count < 0)
158 range->count = 0;
160 if (range->count == 0) {
161 /*range->position = 0; why is this? */
162 return;
165 /* (1,-2) ~> (0,1) ; (1,-1) ~> (0,1) ; (2,-1) ~> (1,1) */
166 if (range->count < 0) { /* && range->position >= 0 */
167 if (range->position + range->count < 0) {
168 range->count = range->position;
169 range->position = 0;
170 } else {
171 range->count = -range->count;
172 range->position -= range->count;
174 /* (-2,1) ~> (0,0) ; (-1,1) ~> (0,0) ; (-1,2) ~> (0,1) */
175 } else if (range->position < 0) { /* && range->count > 0 */
176 if (range->position + range->count < 0) {
177 range->position = range->count = 0;
178 } else {
179 range->count += range->position;
180 range->position = 0;
184 if (range->position + range->count > tPtr->textLen)
185 range->count = tPtr->textLen - range->position;
188 static void memmv(char *dest, char *src, int size)
190 int i;
192 if (dest > src) {
193 for (i = size - 1; i >= 0; i--) {
194 dest[i] = src[i];
196 } else if (dest < src) {
197 for (i = 0; i < size; i++) {
198 dest[i] = src[i];
203 static int incrToFit(TextField * tPtr)
205 int vp = tPtr->viewPosition;
207 while (TEXT_WIDTH(tPtr, tPtr->viewPosition) > tPtr->usableWidth) {
208 tPtr->viewPosition += oneUTF8CharForward(&tPtr->text[tPtr->viewPosition],
209 tPtr->textLen - tPtr->viewPosition);
211 return vp != tPtr->viewPosition;
214 static int incrToFit2(TextField * tPtr)
216 int vp = tPtr->viewPosition;
218 while (TEXT_WIDTH2(tPtr, tPtr->viewPosition, tPtr->cursorPosition)
219 >= tPtr->usableWidth)
220 tPtr->viewPosition += oneUTF8CharForward(&tPtr->text[tPtr->viewPosition],
221 tPtr->cursorPosition - tPtr->viewPosition);
222 return vp != tPtr->viewPosition;
225 static void decrToFit(TextField * tPtr)
227 int vp = tPtr->viewPosition;
229 while (vp > 0 && (vp += oneUTF8CharBackward(&tPtr->text[vp], vp),
230 TEXT_WIDTH(tPtr, vp)) < tPtr->usableWidth) {
231 tPtr->viewPosition = vp;
235 #undef TEXT_WIDTH
236 #undef TEXT_WIDTH2
238 static WMData *requestHandler(WMView * view, Atom selection, Atom target, void *cdata, Atom * type)
240 TextField *tPtr = view->self;
241 int count;
242 Display *dpy = tPtr->view->screen->display;
243 Atom _TARGETS;
244 Atom TEXT = XInternAtom(dpy, "TEXT", False);
245 Atom COMPOUND_TEXT = XInternAtom(dpy, "COMPOUND_TEXT", False);
246 WMData *data;
248 count = tPtr->selection.count < 0
249 ? tPtr->selection.position + tPtr->selection.count : tPtr->selection.position;
251 if (target == XA_STRING || target == TEXT || target == COMPOUND_TEXT) {
253 data = WMCreateDataWithBytes(&(tPtr->text[count]), abs(tPtr->selection.count));
254 WMSetDataFormat(data, 8);
255 *type = target;
257 return data;
260 _TARGETS = XInternAtom(dpy, "TARGETS", False);
261 if (target == _TARGETS) {
262 Atom *ptr;
264 ptr = wmalloc(4 * sizeof(Atom));
265 ptr[0] = _TARGETS;
266 ptr[1] = XA_STRING;
267 ptr[2] = TEXT;
268 ptr[3] = COMPOUND_TEXT;
270 data = WMCreateDataWithBytes(ptr, 4 * 4);
271 WMSetDataFormat(data, 32);
273 *type = target;
274 return data;
277 return NULL;
281 static void lostSelection(WMView * view, Atom selection, void *cdata)
283 TextField *tPtr = (WMTextField *) view->self;
285 if (tPtr->flags.ownsSelection) {
286 WMDeleteSelectionHandler(view, selection, CurrentTime);
287 tPtr->flags.ownsSelection = 0;
289 if (tPtr->selection.count != 0) {
290 tPtr->selection.count = 0;
291 paintTextField(tPtr);
295 static void selectionNotification(void *observerData, WMNotification * notification)
297 WMView *observerView = (WMView *) observerData;
298 WMView *newOwnerView = (WMView *) WMGetNotificationClientData(notification);
300 if (observerView != newOwnerView) {
302 //if (tPtr->flags.ownsSelection)
303 // WMDeleteSelectionHandler(observerView, XA_PRIMARY, CurrentTime);
305 lostSelection(observerView, XA_PRIMARY, NULL);
309 static void realizeObserver(void *self, WMNotification * not)
311 W_CreateIC(((TextField *) self)->view);
314 WMTextField *WMCreateTextField(WMWidget * parent)
316 TextField *tPtr;
318 tPtr = wmalloc(sizeof(TextField));
319 tPtr->widgetClass = WC_TextField;
321 tPtr->view = W_CreateView(W_VIEW(parent));
322 if (!tPtr->view) {
323 wfree(tPtr);
324 return NULL;
326 tPtr->view->self = tPtr;
328 tPtr->view->delegate = &_TextFieldViewDelegate;
330 tPtr->view->attribFlags |= CWCursor;
331 tPtr->view->attribs.cursor = tPtr->view->screen->textCursor;
333 W_SetViewBackgroundColor(tPtr->view, tPtr->view->screen->white);
335 tPtr->text = wmalloc(MIN_TEXT_BUFFER);
336 tPtr->textLen = 0;
337 tPtr->bufferSize = MIN_TEXT_BUFFER;
339 tPtr->flags.enabled = 1;
341 WMCreateEventHandler(tPtr->view, ExposureMask | StructureNotifyMask | FocusChangeMask, handleEvents, tPtr);
343 tPtr->font = WMRetainFont(tPtr->view->screen->normalFont);
345 tPtr->flags.bordered = DEFAULT_BORDERED;
346 tPtr->flags.beveled = True;
347 tPtr->flags.alignment = DEFAULT_ALIGNMENT;
348 tPtr->offsetWidth = WMAX((tPtr->view->size.height - WMFontHeight(tPtr->font)) / 2, 1);
350 W_ResizeView(tPtr->view, DEFAULT_WIDTH, DEFAULT_HEIGHT);
352 WMCreateEventHandler(tPtr->view, EnterWindowMask | LeaveWindowMask
353 | ButtonReleaseMask | ButtonPressMask | KeyPressMask | Button1MotionMask,
354 handleTextFieldActionEvents, tPtr);
356 WMAddNotificationObserver(selectionNotification, tPtr->view,
357 WMSelectionOwnerDidChangeNotification, (void *)XA_PRIMARY);
359 WMAddNotificationObserver(realizeObserver, tPtr, WMViewRealizedNotification, tPtr->view);
361 tPtr->flags.cursorOn = 1;
363 return tPtr;
366 void WMSetTextFieldDelegate(WMTextField * tPtr, WMTextFieldDelegate * delegate)
368 CHECK_CLASS(tPtr, WC_TextField);
370 tPtr->delegate = delegate;
373 WMTextFieldDelegate *WMGetTextFieldDelegate(WMTextField * tPtr)
375 CHECK_CLASS(tPtr, WC_TextField);
377 return tPtr->delegate;
380 void WMInsertTextFieldText(WMTextField * tPtr, char *text, int position)
382 int len;
384 CHECK_CLASS(tPtr, WC_TextField);
386 if (!text)
387 return;
389 len = strlen(text);
391 /* check if buffer will hold the text */
392 if (len + tPtr->textLen >= tPtr->bufferSize) {
393 tPtr->bufferSize = tPtr->textLen + len + TEXT_BUFFER_INCR;
394 tPtr->text = wrealloc(tPtr->text, tPtr->bufferSize);
397 if (position < 0 || position >= tPtr->textLen) {
398 /* append the text at the end */
399 wstrlcat(tPtr->text, text, tPtr->bufferSize);
400 tPtr->textLen += len;
401 tPtr->cursorPosition += len;
402 incrToFit(tPtr);
403 } else {
404 /* insert text at position */
405 memmv(&(tPtr->text[position + len]), &(tPtr->text[position]), tPtr->textLen - position + 1);
407 memcpy(&(tPtr->text[position]), text, len);
409 tPtr->textLen += len;
410 if (position >= tPtr->cursorPosition) {
411 tPtr->cursorPosition += len;
412 incrToFit2(tPtr);
413 } else {
414 incrToFit(tPtr);
418 paintTextField(tPtr);
421 void WMDeleteTextFieldRange(WMTextField * tPtr, WMRange range)
423 CHECK_CLASS(tPtr, WC_TextField);
425 normalizeRange(tPtr, &range);
427 if (!range.count)
428 return;
430 memmv(&(tPtr->text[range.position]), &(tPtr->text[range.position + range.count]),
431 tPtr->textLen - (range.position + range.count) + 1);
433 /* better than nothing ;) */
434 if (tPtr->cursorPosition > range.position)
435 tPtr->viewPosition += oneUTF8CharBackward(&tPtr->text[tPtr->viewPosition], tPtr->viewPosition);
436 tPtr->textLen -= range.count;
437 tPtr->cursorPosition = range.position;
439 decrToFit(tPtr);
441 paintTextField(tPtr);
444 char *WMGetTextFieldText(WMTextField * tPtr)
446 CHECK_CLASS(tPtr, WC_TextField);
448 return wstrdup(tPtr->text);
451 void WMSetTextFieldText(WMTextField * tPtr, char *text)
453 CHECK_CLASS(tPtr, WC_TextField);
455 if ((text && strcmp(tPtr->text, text) == 0) || (!text && tPtr->textLen == 0))
456 return;
458 if (text == NULL) {
459 tPtr->text[0] = 0;
460 tPtr->textLen = 0;
461 } else {
462 tPtr->textLen = strlen(text);
464 if (tPtr->textLen >= tPtr->bufferSize) {
465 tPtr->bufferSize = tPtr->textLen + TEXT_BUFFER_INCR;
466 tPtr->text = wrealloc(tPtr->text, tPtr->bufferSize);
468 wstrlcpy(tPtr->text, text, tPtr->bufferSize);
471 tPtr->cursorPosition = tPtr->selection.position = tPtr->textLen;
472 tPtr->viewPosition = 0;
473 tPtr->selection.count = 0;
475 if (tPtr->view->flags.realized)
476 paintTextField(tPtr);
479 void WMSetTextFieldAlignment(WMTextField * tPtr, WMAlignment alignment)
481 CHECK_CLASS(tPtr, WC_TextField);
483 tPtr->flags.alignment = alignment;
485 if (alignment != WALeft) {
486 wwarning("only left alignment is supported in textfields");
487 return;
490 if (tPtr->view->flags.realized) {
491 paintTextField(tPtr);
495 void WMSetTextFieldBordered(WMTextField * tPtr, Bool bordered)
497 CHECK_CLASS(tPtr, WC_TextField);
499 tPtr->flags.bordered = bordered;
501 if (tPtr->view->flags.realized) {
502 paintTextField(tPtr);
506 void WMSetTextFieldBeveled(WMTextField * tPtr, Bool flag)
508 CHECK_CLASS(tPtr, WC_TextField);
510 tPtr->flags.beveled = ((flag == 0) ? 0 : 1);
512 if (tPtr->view->flags.realized) {
513 paintTextField(tPtr);
517 void WMSetTextFieldSecure(WMTextField * tPtr, Bool flag)
519 CHECK_CLASS(tPtr, WC_TextField);
521 tPtr->flags.secure = ((flag == 0) ? 0 : 1);
523 if (tPtr->view->flags.realized) {
524 paintTextField(tPtr);
528 Bool WMGetTextFieldEditable(WMTextField * tPtr)
530 CHECK_CLASS(tPtr, WC_TextField);
532 return tPtr->flags.enabled;
535 void WMSetTextFieldEditable(WMTextField * tPtr, Bool flag)
537 CHECK_CLASS(tPtr, WC_TextField);
539 tPtr->flags.enabled = ((flag == 0) ? 0 : 1);
541 if (tPtr->view->flags.realized) {
542 paintTextField(tPtr);
546 void WMSelectTextFieldRange(WMTextField * tPtr, WMRange range)
548 CHECK_CLASS(tPtr, WC_TextField);
550 if (tPtr->flags.enabled) {
551 normalizeRange(tPtr, &range);
553 tPtr->selection = range;
555 tPtr->cursorPosition = range.position + range.count;
557 if (tPtr->view->flags.realized) {
558 paintTextField(tPtr);
563 void WMSetTextFieldCursorPosition(WMTextField * tPtr, unsigned int position)
565 CHECK_CLASS(tPtr, WC_TextField);
567 if (tPtr->flags.enabled) {
568 if (position > tPtr->textLen)
569 position = tPtr->textLen;
571 tPtr->cursorPosition = position;
572 if (tPtr->view->flags.realized) {
573 paintTextField(tPtr);
578 unsigned WMGetTextFieldCursorPosition(WMTextField *tPtr)
580 CHECK_CLASS(tPtr, WC_TextField);
582 return tPtr->cursorPosition;
585 void WMSetTextFieldNextTextField(WMTextField * tPtr, WMTextField * next)
587 CHECK_CLASS(tPtr, WC_TextField);
588 if (next == NULL) {
589 if (tPtr->view->nextFocusChain)
590 tPtr->view->nextFocusChain->prevFocusChain = NULL;
591 tPtr->view->nextFocusChain = NULL;
592 return;
595 CHECK_CLASS(next, WC_TextField);
597 if (tPtr->view->nextFocusChain)
598 tPtr->view->nextFocusChain->prevFocusChain = NULL;
599 if (next->view->prevFocusChain)
600 next->view->prevFocusChain->nextFocusChain = NULL;
602 tPtr->view->nextFocusChain = next->view;
603 next->view->prevFocusChain = tPtr->view;
606 void WMSetTextFieldPrevTextField(WMTextField * tPtr, WMTextField * prev)
608 CHECK_CLASS(tPtr, WC_TextField);
609 if (prev == NULL) {
610 if (tPtr->view->prevFocusChain)
611 tPtr->view->prevFocusChain->nextFocusChain = NULL;
612 tPtr->view->prevFocusChain = NULL;
613 return;
616 CHECK_CLASS(prev, WC_TextField);
618 if (tPtr->view->prevFocusChain)
619 tPtr->view->prevFocusChain->nextFocusChain = NULL;
620 if (prev->view->nextFocusChain)
621 prev->view->nextFocusChain->prevFocusChain = NULL;
623 tPtr->view->prevFocusChain = prev->view;
624 prev->view->nextFocusChain = tPtr->view;
627 void WMSetTextFieldFont(WMTextField * tPtr, WMFont * font)
629 CHECK_CLASS(tPtr, WC_TextField);
631 if (tPtr->font)
632 WMReleaseFont(tPtr->font);
633 tPtr->font = WMRetainFont(font);
635 tPtr->offsetWidth = WMAX((tPtr->view->size.height - WMFontHeight(tPtr->font)) / 2, 1);
637 if (tPtr->view->flags.realized) {
638 paintTextField(tPtr);
642 WMFont *WMGetTextFieldFont(WMTextField * tPtr)
644 return tPtr->font;
647 static void didResizeTextField(W_ViewDelegate * self, WMView * view)
649 WMTextField *tPtr = (WMTextField *) view->self;
651 tPtr->offsetWidth = WMAX((tPtr->view->size.height - WMFontHeight(tPtr->font)) / 2, 1);
653 tPtr->usableWidth = tPtr->view->size.width - 2 * tPtr->offsetWidth /*+ 2 */ ;
656 static char *makeHiddenString(int length)
658 char *data = wmalloc(length + 1);
660 memset(data, '*', length);
661 data[length] = '\0';
663 return data;
666 static void paintCursor(TextField * tPtr)
668 int cx;
669 WMScreen *screen = tPtr->view->screen;
670 int textWidth;
671 char *text;
673 if (tPtr->flags.secure)
674 text = makeHiddenString(strlen(tPtr->text));
675 else
676 text = tPtr->text;
678 cx = WMWidthOfString(tPtr->font, &(text[tPtr->viewPosition]), tPtr->cursorPosition - tPtr->viewPosition);
680 switch (tPtr->flags.alignment) {
681 case WARight:
682 textWidth = WMWidthOfString(tPtr->font, text, tPtr->textLen);
683 if (textWidth < tPtr->usableWidth)
684 cx += tPtr->offsetWidth + tPtr->usableWidth - textWidth + 1;
685 else
686 cx += tPtr->offsetWidth + 1;
687 break;
688 case WALeft:
689 cx += tPtr->offsetWidth + 1;
690 break;
691 case WAJustified:
692 /* not supported */
693 case WACenter:
694 textWidth = WMWidthOfString(tPtr->font, text, tPtr->textLen);
695 if (textWidth < tPtr->usableWidth)
696 cx += tPtr->offsetWidth + (tPtr->usableWidth - textWidth) / 2;
697 else
698 cx += tPtr->offsetWidth;
699 break;
702 XDrawRectangle(screen->display, tPtr->view->window, screen->xorGC,
703 cx, tPtr->offsetWidth, 1,
704 tPtr->view->size.height - 2*tPtr->offsetWidth - 1);
705 printf("%d %d\n",cx,tPtr->cursorPosition);
708 XDrawLine(screen->display, tPtr->view->window, screen->xorGC,
709 cx, tPtr->offsetWidth, cx, tPtr->view->size.height - tPtr->offsetWidth - 1);
711 W_SetPreeditPositon(tPtr->view, cx, 0);
713 if (tPtr->flags.secure) {
714 wfree(text);
718 static void drawRelief(WMView * view, Bool beveled)
720 WMScreen *scr = view->screen;
721 Display *dpy = scr->display;
722 GC wgc;
723 GC lgc;
724 GC dgc;
725 int width = view->size.width;
726 int height = view->size.height;
728 dgc = WMColorGC(scr->darkGray);
730 if (!beveled) {
731 XDrawRectangle(dpy, view->window, dgc, 0, 0, width - 1, height - 1);
733 return;
735 wgc = WMColorGC(scr->white);
736 lgc = WMColorGC(scr->gray);
738 /* top left */
739 XDrawLine(dpy, view->window, dgc, 0, 0, width - 1, 0);
740 XDrawLine(dpy, view->window, dgc, 0, 1, width - 2, 1);
742 XDrawLine(dpy, view->window, dgc, 0, 0, 0, height - 2);
743 XDrawLine(dpy, view->window, dgc, 1, 0, 1, height - 3);
745 /* bottom right */
746 XDrawLine(dpy, view->window, wgc, 0, height - 1, width - 1, height - 1);
747 XDrawLine(dpy, view->window, lgc, 1, height - 2, width - 2, height - 2);
749 XDrawLine(dpy, view->window, wgc, width - 1, 0, width - 1, height - 1);
750 XDrawLine(dpy, view->window, lgc, width - 2, 1, width - 2, height - 3);
753 static void paintTextField(TextField * tPtr)
755 W_Screen *screen = tPtr->view->screen;
756 W_View *view = tPtr->view;
757 W_View viewbuffer;
758 int tx, ty, tw;
759 int rx;
760 int bd;
761 int totalWidth;
762 char *text;
763 Pixmap drawbuffer;
764 WMColor *color;
766 if (!view->flags.realized || !view->flags.mapped)
767 return;
769 if (!tPtr->flags.bordered) {
770 bd = 0;
771 } else {
772 bd = 2;
775 if (tPtr->flags.secure) {
776 text = makeHiddenString(strlen(tPtr->text));
777 } else {
778 text = tPtr->text;
781 totalWidth = tPtr->view->size.width - 2 * bd;
783 drawbuffer = XCreatePixmap(screen->display, view->window,
784 view->size.width, view->size.height, screen->depth);
785 XFillRectangle(screen->display, drawbuffer, WMColorGC(screen->white),
786 0, 0, view->size.width, view->size.height);
787 /* this is quite dirty */
788 viewbuffer.screen = view->screen;
789 viewbuffer.size = view->size;
790 viewbuffer.window = drawbuffer;
792 if (tPtr->textLen > 0) {
793 tw = WMWidthOfString(tPtr->font, &(text[tPtr->viewPosition]), tPtr->textLen - tPtr->viewPosition);
795 ty = tPtr->offsetWidth;
796 switch (tPtr->flags.alignment) {
797 case WALeft:
798 tx = tPtr->offsetWidth + 1;
799 if (tw < tPtr->usableWidth)
800 XFillRectangle(screen->display, drawbuffer,
801 WMColorGC(screen->white),
802 bd + tw, bd, totalWidth - tw, view->size.height - 2 * bd);
803 break;
805 case WACenter:
806 tx = tPtr->offsetWidth + (tPtr->usableWidth - tw) / 2;
807 if (tw < tPtr->usableWidth)
808 XClearArea(screen->display, view->window, bd, bd,
809 totalWidth, view->size.height - 2 * bd, False);
810 break;
812 default:
813 case WARight:
814 tx = tPtr->offsetWidth + tPtr->usableWidth - tw - 1;
815 if (tw < tPtr->usableWidth)
816 XClearArea(screen->display, view->window, bd, bd,
817 totalWidth - tw, view->size.height - 2 * bd, False);
818 break;
821 color = tPtr->flags.enabled ? screen->black : screen->darkGray;
823 WMDrawImageString(screen, drawbuffer, color, screen->white,
824 tPtr->font, tx, ty, &(text[tPtr->viewPosition]),
825 tPtr->textLen - tPtr->viewPosition);
827 if (tPtr->selection.count) {
828 int count, count2;
830 count = tPtr->selection.count < 0
831 ? tPtr->selection.position + tPtr->selection.count : tPtr->selection.position;
832 count2 = abs(tPtr->selection.count);
833 if (count < tPtr->viewPosition) {
834 count2 = abs(count2 - abs(tPtr->viewPosition - count));
835 count = tPtr->viewPosition;
838 rx = tPtr->offsetWidth + 1 + WMWidthOfString(tPtr->font, text, count)
839 - WMWidthOfString(tPtr->font, text, tPtr->viewPosition);
841 WMDrawImageString(screen, drawbuffer, color, screen->gray,
842 tPtr->font, rx, ty, &(text[count]), count2);
844 } else {
845 XFillRectangle(screen->display, drawbuffer, WMColorGC(screen->white),
846 bd, bd, totalWidth, view->size.height - 2 * bd);
849 /* draw relief */
850 if (tPtr->flags.bordered) {
851 drawRelief(&viewbuffer, tPtr->flags.beveled);
854 if (tPtr->flags.secure)
855 wfree(text);
856 XCopyArea(screen->display, drawbuffer, view->window,
857 screen->copyGC, 0, 0, view->size.width, view->size.height, 0, 0);
858 XFreePixmap(screen->display, drawbuffer);
860 /* draw cursor */
861 if (tPtr->flags.focused && tPtr->flags.enabled && tPtr->flags.cursorOn) {
862 paintCursor(tPtr);
866 #if 0
867 static void blinkCursor(void *data)
869 TextField *tPtr = (TextField *) data;
871 if (tPtr->flags.cursorOn) {
872 tPtr->timerID = WMAddTimerHandler(CURSOR_BLINK_OFF_DELAY, blinkCursor, data);
873 } else {
874 tPtr->timerID = WMAddTimerHandler(CURSOR_BLINK_ON_DELAY, blinkCursor, data);
876 paintCursor(tPtr);
877 tPtr->flags.cursorOn = !tPtr->flags.cursorOn;
879 #endif
881 static void handleEvents(XEvent * event, void *data)
883 TextField *tPtr = (TextField *) data;
885 CHECK_CLASS(data, WC_TextField);
887 switch (event->type) {
888 case FocusIn:
889 W_FocusIC(tPtr->view);
890 if (W_FocusedViewOfToplevel(W_TopLevelOfView(tPtr->view)) != tPtr->view)
891 return;
892 tPtr->flags.focused = 1;
893 #if 0
894 if (!tPtr->timerID) {
895 tPtr->timerID = WMAddTimerHandler(CURSOR_BLINK_ON_DELAY, blinkCursor, tPtr);
897 #endif
898 paintTextField(tPtr);
900 NOTIFY(tPtr, didBeginEditing, WMTextDidBeginEditingNotification, NULL);
902 tPtr->flags.notIllegalMovement = 0;
903 break;
905 case FocusOut:
906 W_UnFocusIC(tPtr->view);
907 tPtr->flags.focused = 0;
908 #if 0
909 if (tPtr->timerID)
910 WMDeleteTimerHandler(tPtr->timerID);
911 tPtr->timerID = NULL;
912 #endif
914 paintTextField(tPtr);
915 if (!tPtr->flags.notIllegalMovement) {
916 NOTIFY(tPtr, didEndEditing, WMTextDidEndEditingNotification,
917 (void *)WMIllegalTextMovement);
919 break;
921 case Expose:
922 if (event->xexpose.count != 0)
923 break;
924 paintTextField(tPtr);
925 break;
927 case DestroyNotify:
928 destroyTextField(tPtr);
929 break;
933 static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
935 char buffer[64];
936 KeySym ksym;
937 char *textEvent = NULL;
938 void *data = NULL;
939 int count, refresh = 0;
940 int control_pressed = 0;
941 int cancelSelection = 1;
942 Bool shifted, controled, modified;
943 Bool relay = True;
945 /*printf("(%d,%d) -> ", tPtr->selection.position, tPtr->selection.count); */
946 if (((XKeyEvent *) event)->state & WM_EMACSKEYMASK)
947 control_pressed = 1;
949 shifted = (event->xkey.state & ShiftMask ? True : False);
950 controled = (event->xkey.state & ControlMask ? True : False);
951 modified = shifted || controled;
953 count = W_LookupString(tPtr->view, &event->xkey, buffer, 63, &ksym, NULL);
954 //count = XLookupString(&event->xkey, buffer, 63, &ksym, NULL);
955 buffer[count] = '\0';
957 switch (ksym) {
958 case XK_Tab:
959 #ifdef XK_ISO_Left_Tab
960 case XK_ISO_Left_Tab:
961 #endif
962 if (!controled) {
963 if (shifted) {
964 if (tPtr->view->prevFocusChain) {
965 W_SetFocusOfTopLevel(W_TopLevelOfView(tPtr->view),
966 tPtr->view->prevFocusChain);
967 tPtr->flags.notIllegalMovement = 1;
969 data = (void *)WMBacktabTextMovement;
970 } else {
971 if (tPtr->view->nextFocusChain) {
972 W_SetFocusOfTopLevel(W_TopLevelOfView(tPtr->view),
973 tPtr->view->nextFocusChain);
974 tPtr->flags.notIllegalMovement = 1;
976 data = (void *)WMTabTextMovement;
978 textEvent = WMTextDidEndEditingNotification;
980 cancelSelection = 0;
982 relay = False;
984 break;
986 case XK_Escape:
987 if (!modified) {
988 data = (void *)WMEscapeTextMovement;
989 textEvent = WMTextDidEndEditingNotification;
991 relay = False;
993 break;
995 case XK_Return:
996 if (!modified) {
997 data = (void *)WMReturnTextMovement;
998 textEvent = WMTextDidEndEditingNotification;
1000 relay = False;
1002 break;
1004 case WM_EMACSKEY_LEFT:
1005 if (!control_pressed)
1006 goto normal_key;
1007 else
1008 controled = False;
1010 #ifdef XK_KP_Left
1011 case XK_KP_Left:
1012 #endif
1013 case XK_Left:
1014 if (tPtr->cursorPosition > 0) {
1015 int i;
1016 paintCursor(tPtr);
1018 i = tPtr->cursorPosition;
1019 i += oneUTF8CharBackward(&tPtr->text[i], i);
1020 if (controled) {
1021 while (i > 0 && tPtr->text[i] != ' ')
1022 i--;
1023 while (i > 0 && tPtr->text[i] == ' ')
1024 i--;
1026 tPtr->cursorPosition = (i > 0) ? i + 1 : 0;
1027 } else
1028 tPtr->cursorPosition = i;
1030 if (tPtr->cursorPosition < tPtr->viewPosition) {
1031 tPtr->viewPosition = tPtr->cursorPosition;
1032 refresh = 1;
1033 } else
1034 paintCursor(tPtr);
1036 if (shifted)
1037 cancelSelection = 0;
1039 relay = False;
1041 break;
1043 case WM_EMACSKEY_RIGHT:
1044 if (!control_pressed)
1045 goto normal_key;
1046 else
1047 controled = False;
1049 #ifdef XK_KP_Right
1050 case XK_KP_Right:
1051 #endif
1052 case XK_Right:
1053 if (tPtr->cursorPosition < tPtr->textLen) {
1054 int i;
1055 paintCursor(tPtr);
1057 i = tPtr->cursorPosition;
1058 if (controled) {
1059 while (tPtr->text[i] && tPtr->text[i] != ' ')
1060 i++;
1061 while (tPtr->text[i] == ' ')
1062 i++;
1063 } else {
1064 i += oneUTF8CharForward(&tPtr->text[i], tPtr->textLen - i);
1066 tPtr->cursorPosition = i;
1068 refresh = incrToFit2(tPtr);
1070 if (!refresh)
1071 paintCursor(tPtr);
1073 if (shifted)
1074 cancelSelection = 0;
1076 relay = False;
1078 break;
1080 case WM_EMACSKEY_HOME:
1081 if (!control_pressed)
1082 goto normal_key;
1083 else
1084 controled = False;
1086 #ifdef XK_KP_Home
1087 case XK_KP_Home:
1088 #endif
1089 case XK_Home:
1090 if (!controled) {
1091 if (tPtr->cursorPosition > 0) {
1092 paintCursor(tPtr);
1093 tPtr->cursorPosition = 0;
1094 if (tPtr->viewPosition > 0) {
1095 tPtr->viewPosition = 0;
1096 refresh = 1;
1097 } else
1098 paintCursor(tPtr);
1100 if (shifted)
1101 cancelSelection = 0;
1103 relay = False;
1105 break;
1107 case WM_EMACSKEY_END:
1108 if (!control_pressed)
1109 goto normal_key;
1110 else
1111 controled = False;
1113 #ifdef XK_KP_End
1114 case XK_KP_End:
1115 #endif
1116 case XK_End:
1117 if (!controled) {
1118 if (tPtr->cursorPosition < tPtr->textLen) {
1119 paintCursor(tPtr);
1120 tPtr->cursorPosition = tPtr->textLen;
1121 tPtr->viewPosition = 0;
1123 refresh = incrToFit(tPtr);
1125 if (!refresh)
1126 paintCursor(tPtr);
1128 if (shifted)
1129 cancelSelection = 0;
1131 relay = False;
1133 break;
1135 case WM_EMACSKEY_BS:
1136 if (!control_pressed)
1137 goto normal_key;
1138 else
1139 modified = False;
1141 case XK_BackSpace:
1142 if (!modified) {
1143 if (tPtr->selection.count) {
1144 WMDeleteTextFieldRange(tPtr, tPtr->selection);
1145 data = (void *)WMDeleteTextEvent;
1146 textEvent = WMTextDidChangeNotification;
1147 } else if (tPtr->cursorPosition > 0) {
1148 int i = oneUTF8CharBackward(&tPtr->text[tPtr->cursorPosition],
1149 tPtr->cursorPosition);
1150 WMRange range;
1151 range.position = tPtr->cursorPosition + i;
1152 range.count = -i;
1153 WMDeleteTextFieldRange(tPtr, range);
1154 data = (void *)WMDeleteTextEvent;
1155 textEvent = WMTextDidChangeNotification;
1158 relay = False;
1160 break;
1162 case WM_EMACSKEY_DEL:
1163 if (!control_pressed)
1164 goto normal_key;
1165 else
1166 modified = False;
1168 #ifdef XK_KP_Delete
1169 case XK_KP_Delete:
1170 #endif
1171 case XK_Delete:
1172 if (!modified) {
1173 if (tPtr->selection.count) {
1174 WMDeleteTextFieldRange(tPtr, tPtr->selection);
1175 data = (void *)WMDeleteTextEvent;
1176 textEvent = WMTextDidChangeNotification;
1177 } else if (tPtr->cursorPosition < tPtr->textLen) {
1178 WMRange range;
1179 range.position = tPtr->cursorPosition;
1180 range.count = oneUTF8CharForward(&tPtr->text[tPtr->cursorPosition],
1181 tPtr->textLen - tPtr->cursorPosition);
1182 WMDeleteTextFieldRange(tPtr, range);
1183 data = (void *)WMDeleteTextEvent;
1184 textEvent = WMTextDidChangeNotification;
1187 relay = False;
1189 break;
1191 normal_key:
1192 default:
1193 if (!controled) {
1194 if (count > 0 && !iscntrl(buffer[0])) {
1195 if (tPtr->selection.count)
1196 WMDeleteTextFieldRange(tPtr, tPtr->selection);
1197 WMInsertTextFieldText(tPtr, buffer, tPtr->cursorPosition);
1198 data = (void *)WMInsertTextEvent;
1199 textEvent = WMTextDidChangeNotification;
1201 relay = False;
1204 break;
1207 if (relay) {
1208 WMRelayToNextResponder(W_VIEW(tPtr), event);
1209 return;
1212 /* Do not allow text selection in secure text fields */
1213 if (cancelSelection || tPtr->flags.secure) {
1214 lostSelection(tPtr->view, XA_PRIMARY, NULL);
1216 if (tPtr->selection.count) {
1217 tPtr->selection.count = 0;
1218 refresh = 1;
1220 tPtr->selection.position = tPtr->cursorPosition;
1221 } else {
1222 if (tPtr->selection.count != tPtr->cursorPosition - tPtr->selection.position) {
1224 tPtr->selection.count = tPtr->cursorPosition - tPtr->selection.position;
1226 refresh = 1;
1230 /*printf("(%d,%d)\n", tPtr->selection.position, tPtr->selection.count); */
1232 if (textEvent) {
1233 WMNotification *notif = WMCreateNotification(textEvent, tPtr, data);
1235 if (tPtr->delegate) {
1236 if (textEvent == WMTextDidBeginEditingNotification && tPtr->delegate->didBeginEditing)
1237 (*tPtr->delegate->didBeginEditing) (tPtr->delegate, notif);
1239 else if (textEvent == WMTextDidEndEditingNotification && tPtr->delegate->didEndEditing)
1240 (*tPtr->delegate->didEndEditing) (tPtr->delegate, notif);
1242 else if (textEvent == WMTextDidChangeNotification && tPtr->delegate->didChange)
1243 (*tPtr->delegate->didChange) (tPtr->delegate, notif);
1246 WMPostNotification(notif);
1247 WMReleaseNotification(notif);
1250 if (refresh)
1251 paintTextField(tPtr);
1253 /*printf("(%d,%d)\n", tPtr->selection.position, tPtr->selection.count); */
1256 static int pointToCursorPosition(TextField * tPtr, int x)
1258 int a, b, pos, prev, tw;
1260 if (tPtr->flags.bordered)
1261 x -= 2;
1263 if (WMWidthOfString(tPtr->font, &(tPtr->text[tPtr->viewPosition]),
1264 tPtr->textLen - tPtr->viewPosition) <= x)
1265 return tPtr->textLen;
1267 a = tPtr->viewPosition;
1268 b = tPtr->textLen;
1270 /* we halve the text until we get into a 10 byte vicinity of x */
1271 while (b - a > 10) {
1272 pos = (a + b) / 2;
1273 pos += seekUTF8CharStart(&tPtr->text[pos], pos - a);
1274 tw = WMWidthOfString(tPtr->font, &(tPtr->text[tPtr->viewPosition]), pos - tPtr->viewPosition);
1275 if (tw > x) {
1276 b = pos;
1277 } else if (tw < x) {
1278 a = pos;
1279 } else {
1280 return pos;
1284 /* at this point x can be positioned on any glyph between 'a' and 'b-1'
1285 * inclusive, with the exception of the left border of the 'a' glyph and
1286 * the right border or the 'b-1' glyph
1288 * ( <--- range for x's position ---> )
1289 * a a+1 .......................... b-1 b
1291 pos = prev = a;
1292 while (pos <= b) {
1293 tw = WMWidthOfString(tPtr->font, &(tPtr->text[tPtr->viewPosition]), pos - tPtr->viewPosition);
1294 if (tw > x) {
1295 return prev;
1296 } else if (pos == b) {
1297 break;
1299 prev = pos;
1300 pos += oneUTF8CharForward(&tPtr->text[pos], b - pos);
1303 return b;
1306 static void pasteText(WMView * view, Atom selection, Atom target, Time timestamp, void *cdata, WMData * data)
1308 TextField *tPtr = (TextField *) view->self;
1309 char *str;
1311 tPtr->flags.waitingSelection = 0;
1313 if (data != NULL) {
1314 str = (char *)WMDataBytes(data);
1316 WMInsertTextFieldText(tPtr, str, tPtr->cursorPosition);
1317 NOTIFY(tPtr, didChange, WMTextDidChangeNotification, (void *)WMInsertTextEvent);
1318 } else {
1319 int n;
1321 str = XFetchBuffer(tPtr->view->screen->display, &n, 0);
1323 if (str != NULL) {
1324 str[n] = 0;
1325 WMInsertTextFieldText(tPtr, str, tPtr->cursorPosition);
1326 XFree(str);
1327 NOTIFY(tPtr, didChange, WMTextDidChangeNotification, (void *)WMInsertTextEvent);
1332 static void handleTextFieldActionEvents(XEvent * event, void *data)
1334 TextField *tPtr = (TextField *) data;
1335 static Time lastButtonReleasedEvent = 0;
1336 static Time lastButtonReleasedEvent2 = 0;
1337 Display *dpy = event->xany.display;
1339 CHECK_CLASS(data, WC_TextField);
1341 switch (event->type) {
1342 case KeyPress:
1343 if (tPtr->flags.waitingSelection) {
1344 return;
1346 if (tPtr->flags.enabled && tPtr->flags.focused) {
1347 handleTextFieldKeyPress(tPtr, event);
1348 XDefineCursor(dpy, W_VIEW(tPtr)->window, W_VIEW(tPtr)->screen->invisibleCursor);
1349 tPtr->flags.pointerGrabbed = 1;
1351 break;
1353 case MotionNotify:
1355 if (tPtr->flags.pointerGrabbed) {
1356 tPtr->flags.pointerGrabbed = 0;
1357 XDefineCursor(dpy, W_VIEW(tPtr)->window, W_VIEW(tPtr)->screen->textCursor);
1359 if (tPtr->flags.waitingSelection) {
1360 return;
1363 if (tPtr->flags.enabled && (event->xmotion.state & Button1Mask)) {
1365 if (tPtr->viewPosition < tPtr->textLen && event->xmotion.x > tPtr->usableWidth) {
1366 if (WMWidthOfString(tPtr->font,
1367 &(tPtr->text[tPtr->viewPosition]),
1368 tPtr->cursorPosition - tPtr->viewPosition)
1369 > tPtr->usableWidth) {
1370 tPtr->viewPosition += oneUTF8CharForward(&tPtr->text[tPtr->viewPosition],
1371 tPtr->textLen -
1372 tPtr->viewPosition);
1374 } else if (tPtr->viewPosition > 0 && event->xmotion.x < 0) {
1375 paintCursor(tPtr);
1376 tPtr->viewPosition += oneUTF8CharBackward(&tPtr->text[tPtr->viewPosition],
1377 tPtr->viewPosition);
1380 tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xmotion.x);
1382 /* Do not allow text selection in secure textfields */
1383 if (tPtr->flags.secure) {
1384 tPtr->selection.position = tPtr->cursorPosition;
1387 tPtr->selection.count = tPtr->cursorPosition - tPtr->selection.position;
1389 paintCursor(tPtr);
1390 paintTextField(tPtr);
1393 break;
1395 case ButtonPress:
1396 if (tPtr->flags.pointerGrabbed) {
1397 tPtr->flags.pointerGrabbed = 0;
1398 XDefineCursor(dpy, W_VIEW(tPtr)->window, W_VIEW(tPtr)->screen->textCursor);
1399 break;
1402 if (tPtr->flags.waitingSelection) {
1403 break;
1406 switch (tPtr->flags.alignment) {
1407 int textWidth;
1408 case WARight:
1409 textWidth = WMWidthOfString(tPtr->font, tPtr->text, tPtr->textLen);
1410 if (tPtr->flags.enabled && !tPtr->flags.focused) {
1411 WMSetFocusToWidget(tPtr);
1413 if (tPtr->flags.focused) {
1414 tPtr->selection.position = tPtr->cursorPosition;
1415 tPtr->selection.count = 0;
1417 if (textWidth < tPtr->usableWidth) {
1418 tPtr->cursorPosition = pointToCursorPosition(tPtr,
1419 event->xbutton.x - tPtr->usableWidth
1420 + textWidth);
1421 } else
1422 tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xbutton.x);
1424 paintTextField(tPtr);
1425 break;
1427 case WALeft:
1428 if (tPtr->flags.enabled && !tPtr->flags.focused) {
1429 WMSetFocusToWidget(tPtr);
1431 if (tPtr->flags.focused && event->xbutton.button == Button1) {
1432 tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xbutton.x);
1433 tPtr->selection.position = tPtr->cursorPosition;
1434 tPtr->selection.count = 0;
1435 paintTextField(tPtr);
1437 if (event->xbutton.button == Button2 && tPtr->flags.enabled) {
1438 char *text;
1439 int n;
1441 if (!WMRequestSelection(tPtr->view, XA_PRIMARY, XA_STRING,
1442 event->xbutton.time, pasteText, NULL)) {
1443 text = XFetchBuffer(tPtr->view->screen->display, &n, 0);
1445 if (text) {
1446 text[n] = 0;
1447 WMInsertTextFieldText(tPtr, text, tPtr->cursorPosition);
1448 XFree(text);
1449 NOTIFY(tPtr, didChange, WMTextDidChangeNotification,
1450 (void *)WMInsertTextEvent);
1452 } else {
1453 tPtr->flags.waitingSelection = 1;
1456 break;
1457 default:
1458 break;
1460 break;
1462 case ButtonRelease:
1463 if (tPtr->flags.pointerGrabbed) {
1464 tPtr->flags.pointerGrabbed = 0;
1465 XDefineCursor(dpy, W_VIEW(tPtr)->window, W_VIEW(tPtr)->screen->textCursor);
1467 if (tPtr->flags.waitingSelection) {
1468 break;
1471 if (!tPtr->flags.secure && tPtr->selection.count != 0) {
1472 int start, count;
1473 XRotateBuffers(dpy, 1);
1475 count = abs(tPtr->selection.count);
1476 if (tPtr->selection.count < 0)
1477 start = tPtr->selection.position - count;
1478 else
1479 start = tPtr->selection.position;
1481 XStoreBuffer(dpy, &tPtr->text[start], count, 0);
1484 if (!tPtr->flags.secure &&
1485 event->xbutton.time - lastButtonReleasedEvent <= WINGsConfiguration.doubleClickDelay) {
1487 if (event->xbutton.time - lastButtonReleasedEvent2 <=
1488 2 * WINGsConfiguration.doubleClickDelay) {
1489 tPtr->selection.position = 0;
1490 tPtr->selection.count = tPtr->textLen;
1491 } else {
1492 int pos, cnt;
1493 char *txt;
1494 pos = tPtr->selection.position;
1495 cnt = tPtr->selection.count;
1496 txt = tPtr->text;
1497 while (pos >= 0) {
1498 if (txt[pos] == ' ' || txt[pos] == '\t')
1499 break;
1500 pos--;
1502 pos++;
1504 while (pos + cnt < tPtr->textLen) {
1505 if (txt[pos + cnt] == ' ' || txt[pos + cnt] == '\t')
1506 break;
1507 cnt++;
1509 tPtr->selection.position = pos;
1510 tPtr->selection.count = cnt;
1512 paintTextField(tPtr);
1514 if (!tPtr->flags.ownsSelection) {
1515 tPtr->flags.ownsSelection =
1516 WMCreateSelectionHandler(tPtr->view,
1517 XA_PRIMARY,
1518 event->xbutton.time, &selectionHandler, NULL);
1520 } else if (!tPtr->flags.secure && tPtr->selection.count != 0 && !tPtr->flags.ownsSelection) {
1521 tPtr->flags.ownsSelection =
1522 WMCreateSelectionHandler(tPtr->view,
1523 XA_PRIMARY, event->xbutton.time, &selectionHandler, NULL);
1526 lastButtonReleasedEvent2 = lastButtonReleasedEvent;
1527 lastButtonReleasedEvent = event->xbutton.time;
1529 break;
1533 static void destroyTextField(TextField * tPtr)
1535 #if 0
1536 if (tPtr->timerID)
1537 WMDeleteTimerHandler(tPtr->timerID);
1538 #endif
1540 W_DestroyIC(tPtr->view);
1542 WMReleaseFont(tPtr->font);
1543 /*// use lostSelection() instead of WMDeleteSelectionHandler here? */
1544 WMDeleteSelectionHandler(tPtr->view, XA_PRIMARY, CurrentTime);
1545 WMRemoveNotificationObserver(tPtr);
1547 if (tPtr->text)
1548 wfree(tPtr->text);
1550 wfree(tPtr);