2 /* WINGs WMText: multi-line/font/color/graphic text widget, by Nwanua. */
6 #include <X11/keysym.h>
13 * - FIX wrap... long lines that don't fit are not char wrapped yet.
14 * - hrm... something to do with already having tbs...
15 * - selection code... selects can be funny if it crosses over. use rect?
16 *- also inspect behaviour for WACenter and WARight
17 * - FIX: graphix blocks MUST be skipped if monoFont even though they exist!
18 * - check if support for Horizontal Scroll is complete
19 * - FIX html parser: 1. <b>foo</i> should STILL BE BOLD!
20 * - 2. " foo > bar " should not confuse it.
21 * - assess danger of destroying widgets whose actions link to other pages
22 * - Tabs now are simply replaced by 4 spaces...
23 * - redo blink code to reduce paint event... use pixmap buffer...
24 * - add paragraph support (full) and '\n' code in getStream..
28 /* a Section is a section of a TextBlock that describes what parts
29 of a TextBlock has been laid out on which "line"...
30 o this greatly aids redraw, scroll and selection.
31 o this is created during layoutLine, but may be later modified.
32 o there may be many Sections per TextBlock, hence the array */
34 unsigned int x
, y
; /* where to draw it from */
35 unsigned short w
, h
; /* its width and height */
36 unsigned short begin
; /* where the layout begins */
37 unsigned short end
; /* where it ends */
38 unsigned short max_d
; /* a quick hack for layOut if(laidOut) */
39 unsigned short last
:1; /* is it the last section on a "line"? */
40 unsigned int _y
:31; /* the "line" it and other textblocks are on */
44 /* a TextBlock is a doubly-linked list of TextBlocks containing:
45 o text for the block, color and font
46 o or a pointer to the pixmap
47 o OR a pointer to the widget and the (text) description for its graphic
50 typedef struct _TextBlock
{
51 struct _TextBlock
*next
; /* next text block in linked list */
52 struct _TextBlock
*prior
; /* prior text block in linked list */
54 char *text
; /* pointer to text (could be kanji) */
55 /* or to the object's description */
57 WMFont
*font
; /* the font */
58 WMWidget
*widget
; /* the embedded widget */
59 WMPixmap
*pixmap
; /* the pixmap */
60 } d
; /* description */
62 unsigned short used
; /* number of chars in this block */
63 unsigned short allocated
; /* size of allocation (in chars) */
64 WMColor
*color
; /* the color */
66 Section
*sections
; /* the region for layouts (a growable array) */
67 /* an _array_! of size _nsections_ */
69 unsigned short s_begin
; /* where the selection begins */
70 unsigned short s_end
; /* where it ends */
72 unsigned int first
:1; /* first TextBlock in paragraph */
73 unsigned int blank
:1; /* ie. blank paragraph */
74 unsigned int kanji
:1; /* is of 16-bit characters or not */
75 unsigned int graphic
:1; /* graphic or text: text=0 */
76 unsigned int object
:1; /* embedded object or pixmap */
77 unsigned int underlined
:1; /* underlined or not */
78 unsigned int selected
:1; /* selected or not */
79 unsigned int nsections
:8; /* over how many "lines" a TextBlock wraps */
80 int script
:8; /* script in points: negative for subscript */
81 unsigned int marginN
:8; /* which of the margins in the tPtr to use */
82 unsigned int nClicks
:2; /* single, double, triple clicks */
83 unsigned int RESERVED
:7;
87 /* I'm lazy: visible.h vs. visible.size.height :-) */
96 typedef struct W_Text
{
97 W_Class widgetClass
; /* the class number of this widget */
98 W_View
*view
; /* the view referring to this instance */
100 WMRuler
*ruler
; /* the ruler widget to manipulate paragraphs */
102 WMScroller
*vS
; /* the vertical scroller */
103 unsigned int vpos
; /* the current vertical position */
104 unsigned int prevVpos
; /* the previous vertical position */
106 WMScroller
*hS
; /* the horizontal scroller */
107 unsigned int hpos
; /* the current horizontal position */
108 unsigned int prevHpos
; /* the previous horizontal position */
110 WMFont
*dFont
; /* the default font */
111 WMColor
*dColor
; /* the default color */
112 WMPixmap
*dBulletPix
; /* the default pixmap for bullets */
114 GC bgGC
; /* the background GC to draw with */
115 GC fgGC
; /* the foreground GC to draw with */
116 Pixmap db
; /* the buffer on which to draw */
118 myRect visible
; /* the actual rectangle that can be drawn into */
119 myRect cursor
; /* the position and (height) of cursor */
120 myRect sel
; /* the selection rectangle */
122 WMPoint clicked
; /* where in the _document_ was clicked */
124 unsigned short tpos
; /* the position in the currentTextBlock */
125 unsigned short docWidth
; /* the width of the entire document */
126 unsigned int docHeight
; /* the height of the entire document */
128 TextBlock
*firstTextBlock
;
129 TextBlock
*lastTextBlock
;
130 TextBlock
*currentTextBlock
;
132 WMArray
*gfxItems
; /* a nice array of graphic items */
135 WMHandlerID timerID
; /* for nice twinky-winky */
140 WMTextDelegate
*delegate
;
143 WMRulerMargins
*margins
; /* an array of margins */
145 unsigned int nMargins
:8; /* the total number of margins in use */
147 unsigned int monoFont
:1; /* whether to ignore formats and graphic */
148 unsigned int focused
:1; /* whether this instance has input focus */
149 unsigned int editable
:1; /* "silly user, you can't edit me" */
150 unsigned int ownsSelection
:1; /* "I ownz the current selection!" */
151 unsigned int pointerGrabbed
:1;/* "heh, gib me pointer" */
152 unsigned int extendSelection
:1; /* shift-drag to select more regions */
154 unsigned int rulerShown
:1; /* whether the ruler is shown or not */
155 unsigned int frozen
:1; /* whether screen updates are to be made */
156 unsigned int cursorShown
:1; /* whether to show the cursor */
157 unsigned int acceptsGraphic
:1;/* accept graphic when dropped */
158 unsigned int horizOnDemand
:1;/* if a large image should appear*/
159 unsigned int needsLayOut
:1; /* in case of Append/Deletes */
160 unsigned int ignoreNewLine
:1;/* turn it into a ' ' in streams > 1 */
161 unsigned int laidOut
:1; /* have the TextBlocks all been laid out */
162 unsigned int waitingForSelection
:1; /* I don't wanna wait in vain... */
163 unsigned int prepend
:1; /* prepend=1, append=0 (for parsers) */
164 WMAlignment alignment
:2; /* the alignment for text */
165 WMReliefType relief
:3; /* the relief to display with */
166 unsigned int isOverGraphic
:2;/* the mouse is over a graphic */
167 unsigned int RESERVED
:1;
172 #define NOTIFY(T,C,N,A) { WMNotification *notif = WMCreateNotification(N,T,A);\
173 if ((T)->delegate && (T)->delegate->C)\
174 (*(T)->delegate->C)((T)->delegate,notif);\
175 WMPostNotification(notif);\
176 WMReleaseNotification(notif);}
182 output(char *ptr
, int len
)
187 /* printf(" s is [%s] (%d)\n", s, strlen(s)); */
193 #define CURSOR_BLINK_ON_DELAY 600
194 #define CURSOR_BLINK_OFF_DELAY 400
197 static char *default_bullet
[] = {
199 " c None s None", ". c black",
200 "X c white", "o c #808080",
208 static void handleEvents(XEvent
*event
, void *data
);
209 static void layOutDocument(Text
*tPtr
);
210 static void updateScrollers(Text
*tPtr
);
214 getMarginNumber(Text
*tPtr
, WMRulerMargins
*margins
)
218 for(i
=0; i
< tPtr
->nMargins
; i
++) {
220 if(WMIsMarginEqualToMargin(&tPtr
->margins
[i
], margins
))
230 newMargin(Text
*tPtr
, WMRulerMargins
*margins
)
235 tPtr
->margins
[0].retainCount
++;
239 n
= getMarginNumber(tPtr
, margins
);
243 tPtr
->margins
= wrealloc(tPtr
->margins
,
244 (++tPtr
->nMargins
)*sizeof(WMRulerMargins
));
246 n
= tPtr
->nMargins
-1;
247 tPtr
->margins
[n
].left
= margins
->left
;
248 tPtr
->margins
[n
].first
= margins
->first
;
249 tPtr
->margins
[n
].body
= margins
->body
;
250 tPtr
->margins
[n
].right
= margins
->right
;
251 /* for each tab... */
252 tPtr
->margins
[n
].retainCount
= 1;
254 tPtr
->margins
[n
].retainCount
++;
261 sectionWasSelected(Text
*tPtr
, TextBlock
*tb
, XRectangle
*rect
, int s
)
263 unsigned short i
, w
, lw
, selected
= False
, extend
= False
;
267 /* if selection rectangle completely encloses the section */
268 if ((tb
->sections
[s
]._y
>= tPtr
->visible
.y
+ tPtr
->sel
.y
)
269 && (tb
->sections
[s
]._y
+ tb
->sections
[s
].h
270 <= tPtr
->visible
.y
+ tPtr
->sel
.y
+ tPtr
->sel
.h
) ) {
272 sel
.w
= tPtr
->visible
.w
;
273 selected
= extend
= True
;
275 /* or if it starts on a line and then goes further down */
276 } else if ((tb
->sections
[s
]._y
<= tPtr
->visible
.y
+ tPtr
->sel
.y
)
277 && (tb
->sections
[s
]._y
+ tb
->sections
[s
].h
278 <= tPtr
->visible
.y
+ tPtr
->sel
.y
+ tPtr
->sel
.h
)
279 && (tb
->sections
[s
]._y
+ tb
->sections
[s
].h
280 >= tPtr
->visible
.y
+ tPtr
->sel
.y
) ) {
281 sel
.x
= WMAX(tPtr
->sel
.x
, tPtr
->clicked
.x
);
282 sel
.w
= tPtr
->visible
.w
;
283 selected
= extend
= True
;
285 /* or if it begins before a line, but ends on it */
286 } else if ((tb
->sections
[s
]._y
>= tPtr
->visible
.y
+ tPtr
->sel
.y
)
287 && (tb
->sections
[s
]._y
+ tb
->sections
[s
].h
288 >= tPtr
->visible
.y
+ tPtr
->sel
.y
+ tPtr
->sel
.h
)
289 && (tb
->sections
[s
]._y
290 <= tPtr
->visible
.y
+ tPtr
->sel
.y
+ tPtr
->sel
.h
) ) {
292 if (1||tPtr
->sel
.x
+ tPtr
->sel
.w
> tPtr
->clicked
.x
)
293 sel
.w
= tPtr
->sel
.x
+ tPtr
->sel
.w
;
300 /* or if the selection rectangle lies entirely within a line */
301 } else if ((tb
->sections
[s
]._y
<= tPtr
->visible
.y
+ tPtr
->sel
.y
)
302 && (tPtr
->sel
.w
>= 2)
303 && (tb
->sections
[s
]._y
+ tb
->sections
[s
].h
304 >= tPtr
->visible
.y
+ tPtr
->sel
.y
+ tPtr
->sel
.h
) ) {
313 /* if not within (modified) selection rectangle */
314 if ( tb
->sections
[s
].x
> sel
.x
+ sel
.w
315 || tb
->sections
[s
].x
+ tb
->sections
[s
].w
< sel
.x
)
319 if ( tb
->sections
[s
].x
+ tb
->sections
[s
].w
<= sel
.x
+ sel
.w
320 && tb
->sections
[s
].x
>= sel
.x
) {
321 rect
->width
= tb
->sections
[s
].w
;
322 rect
->x
= tb
->sections
[s
].x
;
327 i
= tb
->sections
[s
].begin
;
330 if (0&& tb
->sections
[s
].x
>= sel
.x
) {
331 tb
->s_begin
= tb
->sections
[s
].begin
;
335 while (++i
<= tb
->sections
[s
].end
) {
337 w
= WMWidthOfString(tb
->d
.font
, &(tb
->text
[i
-1]), 1);
340 if (lw
+ tb
->sections
[s
].x
>= sel
.x
341 || i
== tb
->sections
[s
].end
) {
344 tb
->s_begin
= (tb
->selected
? WMIN(tb
->s_begin
, i
) : i
);
349 if (i
> tb
->sections
[s
].end
) {
350 printf("WasSelected: (i > tb->sections[s].end) \n");
354 _selEnd
: rect
->x
= tb
->sections
[s
].x
+ lw
;
356 while(++i
<= tb
->sections
[s
].end
) {
358 w
= WMWidthOfString(tb
->d
.font
, &(tb
->text
[i
-1]), 1);
361 if (lw
+ rect
->x
>= sel
.x
+ sel
.w
362 || i
== tb
->sections
[s
].end
) {
364 if (i
!= tb
->sections
[s
].end
) {
370 if (tb
->sections
[s
].last
&& sel
.x
+ sel
.w
371 >= tb
->sections
[s
].x
+ tb
->sections
[s
].w
373 rect
->width
+= (tPtr
->visible
.w
- rect
->x
- lw
);
376 tb
->s_end
= (tb
->selected
? WMAX(tb
->s_end
, i
) : i
);
382 rect
->y
= tb
->sections
[s
]._y
- tPtr
->vpos
;
383 rect
->height
= tb
->sections
[s
].h
;
384 if(tb
->graphic
) { printf("graphic s%d h%d\n", s
,tb
->sections
[s
].h
);}
391 setSelectionProperty(WMText
*tPtr
, WMFont
*font
, WMColor
*color
, int underlined
)
396 tb
= tPtr
->firstTextBlock
;
397 if (!tb
|| !tPtr
->flags
.ownsSelection
)
400 if(font
&& (!color
|| underlined
==-1))
404 if (tPtr
->flags
.monoFont
|| tb
->selected
) {
406 if (tPtr
->flags
.monoFont
|| (tb
->s_end
- tb
->s_begin
== tb
->used
)
411 WMReleaseFont(tb
->d
.font
);
412 tb
->d
.font
= WMRetainFont(font
);
414 } else if(underlined
!=-1) {
415 tb
->underlined
= underlined
;
417 WMReleaseColor(tb
->color
);
418 tb
->color
= WMRetainColor(color
);
421 } else if (tb
->s_end
<= tb
->used
&& tb
->s_begin
< tb
->s_end
) {
423 TextBlock
*midtb
, *otb
= tb
;
425 if(underlined
!= -1) {
426 midtb
= (TextBlock
*) WMCreateTextBlockWithText(tPtr
,
427 &(tb
->text
[tb
->s_begin
]), tb
->d
.font
, tb
->color
,
428 False
, (tb
->s_end
- tb
->s_begin
));
430 midtb
= (TextBlock
*) WMCreateTextBlockWithText(tPtr
,
431 &(tb
->text
[tb
->s_begin
]),
432 (isFont
?font
:tb
->d
.font
),
433 (isFont
?tb
->color
:color
),
434 False
, (tb
->s_end
- tb
->s_begin
));
439 if(underlined
!= -1) {
440 midtb
->underlined
= underlined
;
442 midtb
->underlined
= otb
->underlined
;
445 midtb
->selected
= !True
;
447 midtb
->s_end
= midtb
->used
;
448 tPtr
->currentTextBlock
= tb
;
449 WMAppendTextBlock(tPtr
, midtb
);
450 tb
= tPtr
->currentTextBlock
;
453 if (otb
->used
- otb
->s_end
> 0) {
456 WMCreateTextBlockWithText(tPtr
,
457 &(otb
->text
[otb
->s_end
]), otb
->d
.font
, otb
->color
,
458 False
, otb
->used
- otb
->s_end
);
461 ntb
->underlined
= otb
->underlined
;
462 ntb
->selected
= False
;
463 WMAppendTextBlock(tPtr
, ntb
);
464 tb
= tPtr
->currentTextBlock
;
469 tPtr
->currentTextBlock
= midtb
;
472 otb
->selected
= False
;
473 otb
->used
= otb
->s_begin
;
480 tPtr
->flags
.needsLayOut
= True
;
483 /* in case the size changed... */
484 if(isFont
&& tPtr
->currentTextBlock
) {
485 TextBlock
*tb
= tPtr
->currentTextBlock
;
487 printf("%d %d %d\n", tPtr
->sel
.y
, tPtr
->sel
.h
, tPtr
->sel
.w
);
488 tPtr
->sel
.y
= 3 + tb
->sections
[0]._y
;
489 tPtr
->sel
.h
= tb
->sections
[tb
->nsections
-1]._y
- tb
->sections
[0]._y
;
490 tPtr
->sel
.w
= tb
->sections
[tb
->nsections
-1].w
;
491 if(tb
->sections
[tb
->nsections
-1]._y
!= tb
->sections
[0]._y
) {
494 printf("%d %d %d\n\n\n", tPtr
->sel
.y
, tPtr
->sel
.h
, tPtr
->sel
.w
);
501 removeSelection(Text
*tPtr
)
503 TextBlock
*tb
= NULL
;
506 if (!(tb
= tPtr
->firstTextBlock
))
511 if(!first
&& !tb
->graphic
) {
512 WMReleaseFont(tPtr
->dFont
);
513 tPtr
->dFont
= WMRetainFont(tb
->d
.font
);
517 if ( (tb
->s_end
- tb
->s_begin
== tb
->used
) || tb
->graphic
) {
518 tPtr
->currentTextBlock
= tb
;
519 WMDestroyTextBlock(tPtr
, WMRemoveTextBlock(tPtr
));
520 tb
= tPtr
->currentTextBlock
;
525 } else if (tb
->s_end
<= tb
->used
) {
526 memmove(&(tb
->text
[tb
->s_begin
]),
527 &(tb
->text
[tb
->s_end
]), tb
->used
- tb
->s_end
);
528 tb
->used
-= (tb
->s_end
- tb
->s_begin
);
529 tb
->selected
= False
;
530 tPtr
->tpos
= tb
->s_begin
;
541 getFirstNonGraphicBlockFor(TextBlock
*tb
, short dir
)
543 TextBlock
*hold
= tb
;
551 tb
= (dir
? tb
->next
: tb
->prior
);
559 tb
= (dir
? tb
->prior
: tb
->next
);
570 updateStartForCurrentTextBlock(Text
*tPtr
, int x
, int y
, int *dir
,
573 if (tPtr
->flags
.monoFont
&& tb
->graphic
) {
574 tb
= getFirstNonGraphicBlockFor(tb
, *dir
);
576 tPtr
->currentTextBlock
=
577 (dir
? tPtr
->lastTextBlock
: tPtr
->firstTextBlock
);
583 *dir
= !(y
<= tb
->sections
[0].y
);
585 if ( ( y
<= tb
->sections
[0]._y
+ tb
->sections
[0].h
)
586 && (y
>= tb
->sections
[0]._y
) ) {
587 /* if it's on the same line */
588 if(x
< tb
->sections
[0].x
)
592 if ( ( y
<= tb
->sections
[tb
->nsections
-1]._y
593 + tb
->sections
[tb
->nsections
-1].h
)
594 && (y
>= tb
->sections
[tb
->nsections
-1]._y
) ) {
595 /* if it's on the same line */
596 if(x
> tb
->sections
[tb
->nsections
-1].x
)
606 paintText(Text
*tPtr
)
612 int len
, y
, c
, s
, done
=False
, prev_y
=-23, dir
/* 1 = down */;
613 WMScreen
*scr
= tPtr
->view
->screen
;
614 Display
*dpy
= tPtr
->view
->screen
->display
;
615 Window win
= tPtr
->view
->window
;
617 if (!tPtr
->view
->flags
.realized
|| !tPtr
->db
|| tPtr
->flags
.frozen
)
620 XFillRectangle(dpy
, tPtr
->db
, tPtr
->bgGC
,
621 0, 0, tPtr
->visible
.w
, tPtr
->visible
.h
);
623 if (! (tb
= tPtr
->currentTextBlock
)) {
624 if (! (tb
= tPtr
->firstTextBlock
)) {
629 if (tPtr
->flags
.ownsSelection
)
630 greyGC
= WMColorGC(WMGrayColor(scr
));
636 /* first, which direction? Don't waste time looking all over,
637 since the parts to be drawn will most likely be near what
638 was previously drawn */
639 if(!updateStartForCurrentTextBlock(tPtr
, 0, tPtr
->vpos
, &dir
, tb
))
644 if (tb
->graphic
&& tPtr
->flags
.monoFont
)
648 if(tPtr
->vpos
<= tb
->sections
[tb
->nsections
-1]._y
649 + tb
->sections
[tb
->nsections
-1].h
)
652 if(tPtr
->vpos
>= tb
->sections
[tb
->nsections
-1]._y
653 + tb
->sections
[tb
->nsections
-1].h
)
670 /* first, place all text that can be viewed */
671 while (!done
&& tb
) {
673 /* paragraph diagnostic
674 if(tb->blank) {tb->text[0] = 'F'; } */
681 tb
->selected
= False
;
683 for(s
=0; s
<tb
->nsections
&& !done
; s
++) {
685 if (tb
->sections
[s
]._y
> tPtr
->vpos
+ tPtr
->visible
.h
) {
690 if ( tb
->sections
[s
].y
+ tb
->sections
[s
].h
< tPtr
->vpos
)
693 if (tPtr
->flags
.monoFont
) {
698 gc
= WMColorGC(tb
->color
);
701 if (tPtr
->flags
.ownsSelection
) {
704 if ( sectionWasSelected(tPtr
, tb
, &rect
, s
)) {
706 XFillRectangle(dpy
, tPtr
->db
, greyGC
,
707 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
711 prev_y
= tb
->sections
[s
]._y
;
713 len
= tb
->sections
[s
].end
- tb
->sections
[s
].begin
;
714 text
= &(tb
->text
[tb
->sections
[s
].begin
]);
715 y
= tb
->sections
[s
].y
- tPtr
->vpos
;
716 WMDrawString(scr
, tPtr
->db
, gc
, font
,
717 tb
->sections
[s
].x
- tPtr
->hpos
, y
, text
, len
);
719 if (tb
->underlined
) {
720 XDrawLine(dpy
, tPtr
->db
, gc
,
721 tb
->sections
[s
].x
- tPtr
->hpos
,
723 tb
->sections
[s
].x
+ tb
->sections
[s
].w
- tPtr
->hpos
,
729 tb
= (!done
? tb
->next
: NULL
);
733 /* now , show all graphic items that can be viewed */
734 c
= WMGetArrayItemCount(tPtr
->gfxItems
);
735 if (c
> 0 && !tPtr
->flags
.monoFont
) {
739 tb
= (TextBlock
*) WMGetFromArray(tPtr
->gfxItems
, j
);
741 /* if it's not viewable, and mapped, unmap it */
742 if (tb
->sections
[0]._y
+ tb
->sections
[0].h
<= tPtr
->vpos
743 || tb
->sections
[0]._y
>= tPtr
->vpos
+ tPtr
->visible
.h
) {
746 if ((W_VIEW(tb
->d
.widget
))->flags
.mapped
) {
747 WMUnmapWidget(tb
->d
.widget
);
751 /* if it's viewable, and not mapped, map it */
753 W_View
*view
= W_VIEW(tb
->d
.widget
);
755 if (!view
->flags
.realized
)
756 WMRealizeWidget(tb
->d
.widget
);
757 if(!view
->flags
.mapped
) {
758 XMapWindow(view
->screen
->display
, view
->window
);
759 XFlush(view
->screen
->display
);
760 view
->flags
.mapped
= 1;
764 if (tPtr
->flags
.ownsSelection
) {
767 if ( sectionWasSelected(tPtr
, tb
, &rect
, 0)) {
769 XFillRectangle(dpy
, tPtr
->db
, greyGC
,
770 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
775 WMMoveWidget(tb
->d
.widget
,
776 tb
->sections
[0].x
+ tPtr
->visible
.x
- tPtr
->hpos
,
777 tb
->sections
[0].y
+ tPtr
->visible
.y
- tPtr
->vpos
);
778 h
= WMWidgetHeight(tb
->d
.widget
) + 1;
781 WMDrawPixmap(tb
->d
.pixmap
, tPtr
->db
,
782 tb
->sections
[0].x
- tPtr
->hpos
,
783 tb
->sections
[0].y
- tPtr
->vpos
);
784 h
= tb
->d
.pixmap
->height
+ 1;
788 if (tb
->underlined
) {
789 XDrawLine(dpy
, tPtr
->db
, WMColorGC(tb
->color
),
790 tb
->sections
[0].x
- tPtr
->hpos
,
791 tb
->sections
[0].y
+ h
- tPtr
->vpos
,
792 tb
->sections
[0].x
+ tb
->sections
[0].w
- tPtr
->hpos
,
793 tb
->sections
[0].y
+ h
- tPtr
->vpos
);
798 if (tPtr
->flags
.editable
&& tPtr
->flags
.cursorShown
799 && tPtr
->cursor
.x
!= -23 && tPtr
->flags
.focused
) {
800 int y
= tPtr
->cursor
.y
- tPtr
->vpos
;
801 XDrawLine(dpy
, tPtr
->db
, tPtr
->fgGC
,
803 tPtr
->cursor
.x
, y
+ tPtr
->cursor
.h
);
806 XCopyArea(dpy
, tPtr
->db
, win
, tPtr
->bgGC
, 0, 0,
807 tPtr
->visible
.w
, tPtr
->visible
.h
,
808 tPtr
->visible
.x
, tPtr
->visible
.y
);
810 W_DrawRelief(scr
, win
, 0, 0,
811 tPtr
->view
->size
.width
, tPtr
->view
->size
.height
,
814 if (tPtr
->ruler
&& tPtr
->flags
.rulerShown
)
815 XDrawLine(dpy
, win
, tPtr
->fgGC
,
816 2, 42, tPtr
->view
->size
.width
-4, 42);
821 mouseOverObject(Text
*tPtr
, int x
, int y
)
826 x
-= tPtr
->visible
.x
;
828 y
-= tPtr
->visible
.y
;
831 if(tPtr
->flags
.ownsSelection
) {
834 && tPtr
->sel
.x
+ tPtr
->sel
.w
>= x
835 && tPtr
->sel
.y
+ tPtr
->sel
.h
>= y
) {
836 tPtr
->flags
.isOverGraphic
= 1;
843 int j
, c
= WMGetArrayItemCount(tPtr
->gfxItems
);
846 tPtr
->flags
.isOverGraphic
= 0;
851 tb
= (TextBlock
*) WMGetFromArray(tPtr
->gfxItems
, j
);
853 if(!tb
|| !tb
->sections
) {
854 tPtr
->flags
.isOverGraphic
= 0;
859 if(tb
->sections
[0].x
<= x
860 && tb
->sections
[0].y
<= y
861 && tb
->sections
[0].x
+ tb
->sections
[0].w
>= x
862 && tb
->sections
[0].y
+ tb
->d
.pixmap
->height
>= y
) {
863 tPtr
->flags
.isOverGraphic
= 3;
873 tPtr
->flags
.isOverGraphic
= 0;
876 tPtr
->view
->attribs
.cursor
= (result
?
877 tPtr
->view
->screen
->defaultCursor
878 : tPtr
->view
->screen
->textCursor
);
880 XSetWindowAttributes attribs
;
881 attribs
.cursor
= tPtr
->view
->attribs
.cursor
;
882 XChangeWindowAttributes(tPtr
->view
->screen
->display
,
883 tPtr
->view
->window
, CWCursor
,
891 blinkCursor(void *data
)
893 Text
*tPtr
= (Text
*)data
;
895 if (tPtr
->flags
.cursorShown
) {
896 tPtr
->timerID
= WMAddTimerHandler(CURSOR_BLINK_OFF_DELAY
,
899 tPtr
->timerID
= WMAddTimerHandler(CURSOR_BLINK_ON_DELAY
,
903 tPtr
->flags
.cursorShown
= !tPtr
->flags
.cursorShown
;
908 updateCursorPosition(Text
*tPtr
)
910 TextBlock
*tb
= NULL
;
913 if(tPtr
->flags
.needsLayOut
)
914 layOutDocument(tPtr
);
916 if (! (tb
= tPtr
->currentTextBlock
)) {
917 if (! (tb
= tPtr
->firstTextBlock
)) {
919 tPtr
->cursor
.h
= tPtr
->dFont
->height
;
929 y
= tb
->sections
[0].y
;
930 h
= tb
->sections
[0].h
;
931 x
= tb
->sections
[0].x
;
933 } else if(tb
->graphic
) {
934 y
= tb
->sections
[0].y
;
935 h
= tb
->sections
[0].h
;
936 x
= tb
->sections
[0].x
;
939 if(tPtr
->tpos
> tb
->used
)
940 tPtr
->tpos
= tb
->used
;
942 for(s
=0; s
<tb
->nsections
-1; s
++) {
944 if(tPtr
->tpos
>= tb
->sections
[s
].begin
945 && tPtr
->tpos
<= tb
->sections
[s
].end
)
949 y
= tb
->sections
[s
]._y
;
950 h
= tb
->sections
[s
].h
;
951 x
= tb
->sections
[s
].x
+ WMWidthOfString(
952 (tPtr
->flags
.monoFont
?tPtr
->dFont
:tb
->d
.font
),
953 &tb
->text
[tb
->sections
[s
].begin
],
954 tPtr
->tpos
- tb
->sections
[s
].begin
);
962 /* scroll the bars if the cursor is not visible */
963 if(tPtr
->flags
.editable
&& tPtr
->cursor
.x
!= -23) {
964 if(tPtr
->cursor
.y
+tPtr
->cursor
.h
965 > tPtr
->vpos
+tPtr
->visible
.y
+tPtr
->visible
.h
) {
967 (tPtr
->cursor
.y
+tPtr
->cursor
.h
+10
968 - (tPtr
->vpos
+tPtr
->visible
.y
+tPtr
->visible
.h
));
969 } else if(tPtr
->cursor
.y
< tPtr
->vpos
+tPtr
->visible
.y
) {
970 tPtr
->vpos
-= (tPtr
->vpos
+tPtr
->visible
.y
-tPtr
->cursor
.y
);
975 updateScrollers(tPtr
);
980 cursorToTextPosition(Text
*tPtr
, int x
, int y
)
982 TextBlock
*tb
= NULL
;
983 int done
=False
, s
, pos
, len
, _w
, _y
, dir
=1; /* 1 == "down" */
986 if(tPtr
->flags
.needsLayOut
)
987 layOutDocument(tPtr
);
989 y
+= (tPtr
->vpos
- tPtr
->visible
.y
);
993 x
-= (tPtr
->visible
.x
- 2);
997 /* clicked is relative to document, not window... */
1001 if (! (tb
= tPtr
->currentTextBlock
)) {
1002 if (! (tb
= tPtr
->firstTextBlock
)) {
1004 tPtr
->cursor
.h
= tPtr
->dFont
->height
;
1011 /* first, which direction? Most likely, newly clicked
1012 position will be close to previous */
1013 if(!updateStartForCurrentTextBlock(tPtr
, x
, y
, &dir
, tb
))
1017 s
= (dir
? 0 : tb
->nsections
-1);
1018 if ( y
>= tb
->sections
[s
]._y
1019 && y
<= tb
->sections
[s
]._y
+ tb
->sections
[s
].h
) {
1023 /* get the first (or last) section of the TextBlock that
1024 lies about the vertical click point */
1026 while (!done
&& tb
) {
1028 if (tPtr
->flags
.monoFont
&& tb
->graphic
) {
1029 if( (dir
?tb
->next
:tb
->prior
))
1030 tb
= (dir
?tb
->next
:tb
->prior
);
1034 s
= (dir
? 0 : tb
->nsections
-1);
1035 while (!done
&& (dir
? (s
<tb
->nsections
) : (s
>=0) )) {
1037 if ( (dir
? (y
<= tb
->sections
[s
]._y
+ tb
->sections
[s
].h
) :
1038 ( y
>= tb
->sections
[s
]._y
) ) ) {
1046 if ( (dir
? tb
->next
: tb
->prior
)) {
1047 tb
= (dir
? tb
->next
: tb
->prior
);
1050 break; /* goto _doneH; */
1056 if (s
<0 || s
>=tb
->nsections
) {
1057 s
= (dir
? tb
->nsections
-1 : 0);
1061 /* we have the line, which TextBlock on that line is it? */
1062 pos
= (dir
?0:tb
->sections
[s
].begin
);
1063 if (tPtr
->flags
.monoFont
&& tb
->graphic
)
1064 tb
= getFirstNonGraphicBlockFor(tb
, dir
);
1069 _y
= tb
->sections
[s
]._y
;
1073 if (tPtr
->flags
.monoFont
&& tb
->graphic
) {
1074 tb
= (dir
? tb
->next
: tb
->prior
);
1081 _w
= WMWidgetWidth(tb
->d
.widget
)-5;
1083 _w
= tb
->d
.pixmap
->width
-5;
1085 text
= &(tb
->text
[tb
->sections
[s
].begin
]);
1086 len
= tb
->sections
[s
].end
- tb
->sections
[s
].begin
;
1087 _w
= WMWidthOfString(tb
->d
.font
, text
, len
);
1088 if (tb
->sections
[s
].x
+ _w
>= x
)
1093 if (tb
->sections
[s
].x
<= x
)
1097 if ((dir
? tb
->next
: tb
->prior
)) {
1098 TextBlock
*nxt
= (dir
? tb
->next
: tb
->prior
);
1099 if (tPtr
->flags
.monoFont
&& nxt
->graphic
) {
1100 nxt
= getFirstNonGraphicBlockFor(nxt
, dir
);
1102 pos
= (dir
?0:tb
->sections
[s
].begin
);
1103 tPtr
->cursor
.x
= tb
->sections
[s
].x
;
1108 if (_y
!= nxt
->sections
[dir
?0:nxt
->nsections
-1]._y
) {
1109 /* this must be the last/first on this line. stop */
1110 pos
= (dir
? tb
->sections
[s
].end
: 0);
1111 tPtr
->cursor
.x
= tb
->sections
[s
].x
;
1115 tPtr
->cursor
.x
+= WMWidgetWidth(tb
->d
.widget
);
1117 tPtr
->cursor
.x
+= tb
->d
.pixmap
->width
;
1118 } else if (pos
> tb
->sections
[s
].begin
) {
1120 WMWidthOfString(tb
->d
.font
,
1121 &(tb
->text
[tb
->sections
[s
].begin
]),
1122 pos
- tb
->sections
[s
].begin
);
1129 if ( (dir
? tb
->next
: tb
->prior
)) {
1130 tb
= (dir
? tb
->next
: tb
->prior
);
1137 s
= (dir
? 0 : tb
->nsections
-1);
1140 /* we have said TextBlock, now where within it? */
1141 if (tb
&& !tb
->graphic
) {
1142 WMFont
*f
= tb
->d
.font
;
1143 len
= tb
->sections
[s
].end
- tb
->sections
[s
].begin
;
1144 text
= &(tb
->text
[tb
->sections
[s
].begin
]);
1146 _w
= x
- tb
->sections
[s
].x
;
1149 while (pos
<len
&& WMWidthOfString(f
, text
, pos
+1) < _w
)
1152 tPtr
->cursor
.x
= tb
->sections
[s
].x
+
1153 (pos
? WMWidthOfString(f
, text
, pos
) : 0);
1155 pos
+= tb
->sections
[s
].begin
;
1157 tPtr
->tpos
= (pos
<tb
->used
)? pos
: tb
->used
;
1161 printf("...for this app will surely crash :-)\n");
1163 tPtr
->currentTextBlock
= tb
;
1164 tPtr
->cursor
.h
= tb
->sections
[s
].h
;
1165 tPtr
->cursor
.y
= tb
->sections
[s
]._y
;
1167 /* scroll the bars if the cursor is not visible */
1168 if(tPtr
->flags
.editable
&& tPtr
->cursor
.x
!= -23) {
1169 if(tPtr
->cursor
.y
+tPtr
->cursor
.h
1170 > tPtr
->vpos
+tPtr
->visible
.y
+tPtr
->visible
.h
) {
1172 (tPtr
->cursor
.y
+tPtr
->cursor
.h
+10
1173 - (tPtr
->vpos
+tPtr
->visible
.y
+tPtr
->visible
.h
));
1174 updateScrollers(tPtr
);
1175 } else if(tPtr
->cursor
.y
< tPtr
->vpos
+tPtr
->visible
.y
) {
1176 tPtr
->vpos
-= (tPtr
->vpos
+tPtr
->visible
.y
-tPtr
->cursor
.y
);
1177 updateScrollers(tPtr
);
1185 autoSelectText(Text
*tPtr
, int clicks
)
1189 char *mark
= NULL
, behind
, ahead
;
1191 if(!(tb
= tPtr
->currentTextBlock
))
1197 switch(tb
->text
[tPtr
->tpos
]) {
1200 case '<': case '>': behind = '<'; ahead = '>'; break;
1201 case '{': case '}': behind = '{'; ahead = '}'; break;
1202 case '[': case ']': behind = '['; ahead = ']'; break;
1204 default: behind
= ahead
= ' ';
1207 tPtr
->sel
.y
= tPtr
->cursor
.y
+5;
1208 tPtr
->sel
.h
= 6;/*tPtr->cursor.h-10;*/
1211 tPtr
->sel
.x
= tb
->sections
[0].x
;
1212 tPtr
->sel
.w
= tb
->sections
[0].w
;
1214 WMFont
*font
= tPtr
->flags
.monoFont
?tPtr
->dFont
:tb
->d
.font
;
1217 while(start
> 0 && tb
->text
[start
-1] != behind
)
1221 if(tPtr
->tpos
> start
){
1222 x
-= WMWidthOfString(font
, &tb
->text
[start
],
1223 tPtr
->tpos
- start
);
1225 tPtr
->sel
.x
= (x
<0?0:x
)+1;
1227 if((mark
= strchr(&tb
->text
[start
], ahead
))) {
1228 tPtr
->sel
.w
= WMWidthOfString(font
, &tb
->text
[start
],
1229 (int)(mark
- &tb
->text
[start
]));
1230 } else if(tb
->used
> start
) {
1231 tPtr
->sel
.w
= WMWidthOfString(font
, &tb
->text
[start
],
1236 } else if(clicks
== 3) {
1237 TextBlock
*cur
= tb
;
1239 while(tb
&& !tb
->first
) {
1242 tPtr
->sel
.y
= tb
->sections
[0]._y
;
1245 while(tb
->next
&& !tb
->next
->first
) {
1248 tPtr
->sel
.h
= tb
->sections
[tb
->nsections
-1]._y
1252 tPtr
->sel
.w
= tPtr
->docWidth
;
1253 tPtr
->clicked
.x
= 0; /* only for now, fix sel. code */
1256 tPtr
->flags
.ownsSelection
= True
;
1263 updateScrollers(Text
*tPtr
)
1266 if (tPtr
->flags
.frozen
)
1270 if (tPtr
->docHeight
< tPtr
->visible
.h
) {
1271 WMSetScrollerParameters(tPtr
->vS
, 0, 1);
1274 float hmax
= (float)(tPtr
->docHeight
);
1275 WMSetScrollerParameters(tPtr
->vS
,
1276 ((float)tPtr
->vpos
)/(hmax
- (float)tPtr
->visible
.h
),
1277 (float)tPtr
->visible
.h
/hmax
);
1279 } else tPtr
->vpos
= 0;
1282 if (tPtr
->docWidth
< tPtr
->visible
.w
) {
1283 WMSetScrollerParameters(tPtr
->hS
, 0, 1);
1286 float wmax
= (float)(tPtr
->docWidth
);
1287 WMSetScrollerParameters(tPtr
->hS
,
1288 ((float)tPtr
->hpos
)/(wmax
- (float)tPtr
->visible
.w
),
1289 (float)tPtr
->visible
.w
/wmax
);
1291 } else tPtr
->hpos
= 0;
1295 scrollersCallBack(WMWidget
*w
, void *self
)
1297 Text
*tPtr
= (Text
*)self
;
1298 Bool scroll
= False
;
1301 if (!tPtr
->view
->flags
.realized
|| tPtr
->flags
.frozen
)
1304 if (w
== tPtr
->vS
) {
1306 height
= tPtr
->visible
.h
;
1308 which
= WMGetScrollerHitPart(tPtr
->vS
);
1311 case WSDecrementLine
:
1312 if (tPtr
->vpos
> 0) {
1313 if (tPtr
->vpos
>16) tPtr
->vpos
-=16;
1318 case WSIncrementLine
: {
1319 int limit
= tPtr
->docHeight
- height
;
1320 if (tPtr
->vpos
< limit
) {
1321 if (tPtr
->vpos
<limit
-16) tPtr
->vpos
+=16;
1322 else tPtr
->vpos
=limit
;
1326 case WSDecrementPage
:
1327 if(((int)tPtr
->vpos
- (int)height
) >= 0)
1328 tPtr
->vpos
-= height
;
1335 case WSIncrementPage
:
1336 tPtr
->vpos
+= height
;
1337 if (tPtr
->vpos
> (tPtr
->docHeight
- height
))
1338 tPtr
->vpos
= tPtr
->docHeight
- height
;
1344 tPtr
->vpos
= WMGetScrollerValue(tPtr
->vS
)
1345 * (float)(tPtr
->docHeight
- height
);
1353 scroll
= (tPtr
->vpos
!= tPtr
->prevVpos
);
1354 tPtr
->prevVpos
= tPtr
->vpos
;
1358 if (w
== tPtr
->hS
) {
1359 int width
= tPtr
->visible
.w
;
1361 which
= WMGetScrollerHitPart(tPtr
->hS
);
1364 case WSDecrementLine
:
1365 if (tPtr
->hpos
> 0) {
1366 if (tPtr
->hpos
>16) tPtr
->hpos
-=16;
1371 case WSIncrementLine
: {
1372 int limit
= tPtr
->docWidth
- width
;
1373 if (tPtr
->hpos
< limit
) {
1374 if (tPtr
->hpos
<limit
-16) tPtr
->hpos
+=16;
1375 else tPtr
->hpos
=limit
;
1379 case WSDecrementPage
:
1380 if(((int)tPtr
->hpos
- (int)width
) >= 0)
1381 tPtr
->hpos
-= width
;
1388 case WSIncrementPage
:
1389 tPtr
->hpos
+= width
;
1390 if (tPtr
->hpos
> (tPtr
->docWidth
- width
))
1391 tPtr
->hpos
= tPtr
->docWidth
- width
;
1397 tPtr
->hpos
= WMGetScrollerValue(tPtr
->hS
)
1398 * (float)(tPtr
->docWidth
- width
);
1406 scroll
= (tPtr
->hpos
!= tPtr
->prevHpos
);
1407 tPtr
->prevHpos
= tPtr
->hpos
;
1411 updateScrollers(tPtr
);
1420 unsigned short begin
, end
; /* what part of the text block */
1425 layOutLine(Text
*tPtr
, myLineItems
*items
, int nitems
, int x
, int y
)
1427 int i
, j
=0, lw
= 0, line_height
=0, max_d
=0, len
, n
;
1431 TextBlock
*tbsame
=NULL
;
1433 if(!items
|| nitems
== 0)
1436 for(i
=0; i
<nitems
; i
++) {
1440 if (!tPtr
->flags
.monoFont
) {
1442 WMWidget
*wdt
= tb
->d
.widget
;
1443 line_height
= WMAX(line_height
, WMWidgetHeight(wdt
));
1444 if (tPtr
->flags
.alignment
!= WALeft
)
1445 lw
+= WMWidgetWidth(wdt
);
1447 line_height
= WMAX(line_height
,
1448 tb
->d
.pixmap
->height
+ max_d
);
1449 if (tPtr
->flags
.alignment
!= WALeft
)
1450 lw
+= tb
->d
.pixmap
->width
;
1455 font
= (tPtr
->flags
.monoFont
)?tPtr
->dFont
: tb
->d
.font
;
1456 max_d
= WMAX(max_d
, abs(font
->height
-font
->y
));
1457 line_height
= WMAX(line_height
, font
->height
+ max_d
);
1458 text
= &(tb
->text
[items
[i
].begin
]);
1459 len
= items
[i
].end
- items
[i
].begin
;
1460 if (tPtr
->flags
.alignment
!= WALeft
)
1461 lw
+= WMWidthOfString(font
, text
, len
);
1465 if (tPtr
->flags
.alignment
== WARight
) {
1466 j
= tPtr
->visible
.w
- lw
;
1467 } else if (tPtr
->flags
.alignment
== WACenter
) {
1468 j
= (int) ((float)(tPtr
->visible
.w
- lw
))/2.0;
1471 for(i
=0; i
<nitems
; i
++) {
1474 if (tbsame
== tb
) { /* extend it, since it's on same line */
1475 tb
->sections
[tb
->nsections
-1].end
= items
[i
].end
;
1476 n
= tb
->nsections
-1;
1478 tb
->sections
= wrealloc(tb
->sections
,
1479 (++tb
->nsections
)*sizeof(Section
));
1480 n
= tb
->nsections
-1;
1481 tb
->sections
[n
]._y
= y
+ max_d
;
1482 tb
->sections
[n
].max_d
= max_d
;
1483 tb
->sections
[n
].x
= x
+j
;
1484 tb
->sections
[n
].h
= line_height
;
1485 tb
->sections
[n
].begin
= items
[i
].begin
;
1486 tb
->sections
[n
].end
= items
[i
].end
;
1489 tb
->sections
[n
].last
= (i
+1 == nitems
);
1492 if (!tPtr
->flags
.monoFont
) {
1494 WMWidget
*wdt
= tb
->d
.widget
;
1495 tb
->sections
[n
].y
= max_d
+ y
1496 + line_height
- WMWidgetHeight(wdt
);
1497 tb
->sections
[n
].w
= WMWidgetWidth(wdt
);
1499 tb
->sections
[n
].y
= y
+ line_height
1500 + max_d
- tb
->d
.pixmap
->height
;
1501 tb
->sections
[n
].w
= tb
->d
.pixmap
->width
;
1503 x
+= tb
->sections
[n
].w
;
1506 font
= (tPtr
->flags
.monoFont
)? tPtr
->dFont
: tb
->d
.font
;
1507 len
= items
[i
].end
- items
[i
].begin
;
1508 text
= &(tb
->text
[items
[i
].begin
]);
1510 tb
->sections
[n
].y
= y
+line_height
-font
->y
;
1512 WMWidthOfString(font
,
1513 &(tb
->text
[tb
->sections
[n
].begin
]),
1514 tb
->sections
[n
].end
- tb
->sections
[n
].begin
);
1516 x
+= WMWidthOfString(font
, text
, len
);
1528 layOutDocument(Text
*tPtr
)
1531 myLineItems
*items
= NULL
;
1532 unsigned int itemsSize
=0, nitems
=0, begin
, end
;
1534 unsigned int x
, y
=0, lw
= 0, width
=0, bmargin
;
1535 char *start
=NULL
, *mark
=NULL
;
1537 if ( tPtr
->flags
.frozen
|| (!(tb
= tPtr
->firstTextBlock
)) )
1540 tPtr
->docWidth
= tPtr
->visible
.w
;
1541 x
= tPtr
->margins
[tb
->marginN
].first
;
1542 bmargin
= tPtr
->margins
[tb
->marginN
].body
;
1544 /* only partial layOut needed: re-Lay only affected textblocks */
1545 if (tPtr
->flags
.laidOut
) {
1546 tb
= tPtr
->currentTextBlock
;
1548 /* search backwards for textblocks on same line */
1550 if (!tb
->sections
|| tb
->nsections
<1) {
1551 tb
= tPtr
->firstTextBlock
;
1552 tPtr
->flags
.laidOut
= False
;
1557 if(!tb
->prior
->sections
|| tb
->prior
->nsections
<1) {
1558 tb
= tPtr
->firstTextBlock
;
1559 tPtr
->flags
.laidOut
= False
;
1564 if (tb
->sections
[0]._y
!=
1565 tb
->prior
->sections
[tb
->prior
->nsections
-1]._y
) {
1571 if(tb
->prior
&& tb
->prior
->sections
&& tb
->prior
->nsections
>0) {
1572 y
= tb
->prior
->sections
[tb
->prior
->nsections
-1]._y
+
1573 tb
->prior
->sections
[tb
->prior
->nsections
-1].h
-
1574 tb
->prior
->sections
[tb
->prior
->nsections
-1].max_d
;
1583 if (tb
->sections
&& tb
->nsections
>0) {
1584 wfree(tb
->sections
);
1585 tb
->sections
= NULL
;
1589 if (tb
->blank
&& tb
->next
&& !tb
->next
->first
) {
1590 TextBlock
*next
= tb
->next
;
1591 tPtr
->currentTextBlock
= tb
;
1592 WMDestroyTextBlock(tPtr
, WMRemoveTextBlock(tPtr
));
1598 if (tb
->first
&& tb
!= tPtr
->firstTextBlock
) {
1599 y
+= layOutLine(tPtr
, items
, nitems
, x
, y
);
1600 x
= tPtr
->margins
[tb
->marginN
].first
;
1601 bmargin
= tPtr
->margins
[tb
->marginN
].body
;
1607 if (!tPtr
->flags
.monoFont
) {
1609 width
= WMWidgetWidth(tb
->d
.widget
);
1611 width
= tb
->d
.pixmap
->width
;
1613 if (width
> tPtr
->docWidth
)
1614 tPtr
->docWidth
= width
;
1617 if (lw
>= tPtr
->visible
.w
- x
) {
1618 y
+= layOutLine(tPtr
, items
, nitems
, x
, y
);
1624 if(nitems
+ 1> itemsSize
) {
1625 items
= wrealloc(items
,
1626 (++itemsSize
)*sizeof(myLineItems
));
1629 items
[nitems
].tb
= tb
;
1630 items
[nitems
].begin
= 0;
1631 items
[nitems
].end
= 0;
1635 } else if ((start
= tb
->text
)) {
1637 font
= tPtr
->flags
.monoFont
?tPtr
->dFont
:tb
->d
.font
;
1640 mark
= strchr(start
, ' ');
1642 end
+= (int)(mark
-start
)+1;
1645 end
+= strlen(start
);
1652 if (end
-begin
> 0) {
1654 width
= WMWidthOfString(font
,
1655 &tb
->text
[begin
], end
-begin
);
1657 /* if it won't fit, break it up */
1658 if (width
> tPtr
->visible
.w
) {
1659 char *t
= &tb
->text
[begin
];
1660 int l
=end
-begin
, i
=0;
1662 width
= WMWidthOfString(font
, t
, ++i
);
1663 } while (width
< tPtr
->visible
.w
&& i
< l
);
1672 if (lw
>= tPtr
->visible
.w
- x
) {
1673 y
+= layOutLine(tPtr
, items
, nitems
, x
, y
);
1679 if(nitems
+ 1 > itemsSize
) {
1680 items
= wrealloc(items
,
1681 (++itemsSize
)*sizeof(myLineItems
));
1684 items
[nitems
].tb
= tb
;
1685 items
[nitems
].begin
= begin
;
1686 items
[nitems
].end
= end
;
1694 /* not yet fully ready. but is already VERY FAST for a 3Mbyte file ;-) */
1695 if(0&&tPtr
->flags
.laidOut
1696 && tb
->next
&& tb
->next
->sections
&& tb
->next
->nsections
>0
1697 && (tPtr
->vpos
+ tPtr
->visible
.h
1698 < tb
->next
->sections
[0]._y
)) {
1699 if(tPtr
->lastTextBlock
->sections
1700 && tPtr
->lastTextBlock
->nsections
> 0 ) {
1701 TextBlock
*ltb
= tPtr
->lastTextBlock
;
1702 int ly
= ltb
->sections
[ltb
->nsections
-1]._y
;
1703 int lh
= ltb
->sections
[ltb
->nsections
-1].h
;
1706 lh
+= 1 + tPtr
->visible
.y
+ ltb
->sections
[ltb
->nsections
-1].max_d
;
1707 printf("it's %d\n", tPtr
->visible
.y
+ ltb
->sections
[ltb
->nsections
-1].max_d
);
1709 y
+= layOutLine(tPtr
, items
, nitems
, x
, y
);
1711 sd
= tPtr
->docHeight
-y
;
1713 printf("dif %d-%d: %d\n", ss
, sd
, ss
-sd
);
1714 y
+= tb
->next
->sections
[0]._y
-y
;
1716 printf("nitems%d\n", nitems
);
1718 y
= tPtr
->docHeight
+ss
-sd
;
1722 tPtr
->flags
.laidOut
= False
;
1731 y
+= layOutLine(tPtr
, items
, nitems
, x
, y
);
1733 if (tPtr
->docHeight
!= y
+10) {
1734 tPtr
->docHeight
= y
+10;
1735 updateScrollers(tPtr
);
1738 if(tPtr
->docWidth
> tPtr
->visible
.w
&& !tPtr
->hS
) {
1741 tPtr
->flags
.horizOnDemand
= True
;
1742 WMSetTextHasHorizontalScroller((WMText
*)tPtr
, True
);
1743 event
.type
= Expose
;
1744 handleEvents(&event
, (void *)tPtr
);
1746 } else if(tPtr
->docWidth
<= tPtr
->visible
.w
1747 && tPtr
->hS
&& tPtr
->flags
.horizOnDemand
) {
1748 tPtr
->flags
.horizOnDemand
= False
;
1749 WMSetTextHasHorizontalScroller((WMText
*)tPtr
, False
);
1752 tPtr
->flags
.laidOut
= True
;
1754 if(items
&& itemsSize
> 0)
1760 textDidResize(W_ViewDelegate
*self
, WMView
*view
)
1762 Text
*tPtr
= (Text
*)view
->self
;
1763 unsigned short w
= tPtr
->view
->size
.width
;
1764 unsigned short h
= tPtr
->view
->size
.height
;
1765 unsigned short rh
= 0, vw
= 0, rel
;
1767 rel
= (tPtr
->flags
.relief
== WRFlat
);
1769 if (tPtr
->ruler
&& tPtr
->flags
.rulerShown
) {
1770 WMMoveWidget(tPtr
->ruler
, 2, 2);
1771 WMResizeWidget(tPtr
->ruler
, w
- 4, 40);
1776 WMMoveWidget(tPtr
->vS
, 1 - (rel
?1:0), rh
+ 1 - (rel
?1:0));
1777 WMResizeWidget(tPtr
->vS
, 20, h
- rh
- 2 + (rel
?2:0));
1779 WMSetRulerOffset(tPtr
->ruler
,22);
1780 } else WMSetRulerOffset(tPtr
->ruler
, 2);
1784 WMMoveWidget(tPtr
->hS
, vw
, h
- 21);
1785 WMResizeWidget(tPtr
->hS
, w
- vw
- 1, 20);
1787 WMMoveWidget(tPtr
->hS
, vw
+1, h
- 21);
1788 WMResizeWidget(tPtr
->hS
, w
- vw
- 2, 20);
1792 tPtr
->visible
.x
= (tPtr
->vS
)?24:4;
1793 tPtr
->visible
.y
= (tPtr
->ruler
&& tPtr
->flags
.rulerShown
)?43:3;
1794 tPtr
->visible
.w
= tPtr
->view
->size
.width
- tPtr
->visible
.x
- 8;
1795 tPtr
->visible
.h
= tPtr
->view
->size
.height
- tPtr
->visible
.y
;
1796 tPtr
->visible
.h
-= (tPtr
->hS
)?20:0;
1797 tPtr
->margins
[0].right
= tPtr
->visible
.w
;
1799 if (tPtr
->view
->flags
.realized
) {
1802 XFreePixmap(tPtr
->view
->screen
->display
, tPtr
->db
);
1803 tPtr
->db
= (Pixmap
) NULL
;
1806 if (tPtr
->visible
.w
< 40)
1807 tPtr
->visible
.w
= 40;
1808 if (tPtr
->visible
.h
< 20)
1809 tPtr
->visible
.h
= 20;
1812 tPtr
->db
= XCreatePixmap(tPtr
->view
->screen
->display
,
1813 tPtr
->view
->window
, tPtr
->visible
.w
,
1814 tPtr
->visible
.h
, tPtr
->view
->screen
->depth
);
1821 W_ViewDelegate _TextViewDelegate
=
1829 /* nice, divisble-by-16 blocks */
1830 static inline unsigned short
1831 reqBlockSize(unsigned short requested
)
1833 return requested
+ 16 - (requested
%16);
1838 clearText(Text
*tPtr
)
1840 if (!tPtr
->firstTextBlock
)
1843 while (tPtr
->currentTextBlock
)
1844 WMDestroyTextBlock(tPtr
, WMRemoveTextBlock(tPtr
));
1846 tPtr
->firstTextBlock
= NULL
;
1847 tPtr
->currentTextBlock
= NULL
;
1848 tPtr
->lastTextBlock
= NULL
;
1852 deleteTextInteractively(Text
*tPtr
, KeySym ksym
)
1855 Bool back
= (Bool
) (ksym
== XK_BackSpace
);
1859 if (!tPtr
->flags
.editable
) {
1860 XBell(tPtr
->view
->screen
->display
, 0);
1864 if ( !(tb
= tPtr
->currentTextBlock
) )
1867 if (tPtr
->flags
.ownsSelection
) {
1868 if(removeSelection(tPtr
))
1869 layOutDocument(tPtr
);
1873 wasFirst
= tb
->first
;
1874 if (back
&& tPtr
->tpos
< 1) {
1876 if(tb
->prior
->blank
) {
1877 tPtr
->currentTextBlock
= tb
->prior
;
1878 WMRemoveTextBlock(tPtr
);
1879 tPtr
->currentTextBlock
= tb
;
1881 layOutDocument(tPtr
);
1885 TextBlock
*prior
= tb
->prior
;
1886 tPtr
->currentTextBlock
= tb
;
1887 WMRemoveTextBlock(tPtr
);
1893 tPtr
->tpos
= tb
->used
;
1894 tPtr
->currentTextBlock
= tb
;
1898 tb
->next
->first
= False
;
1899 layOutDocument(tPtr
);
1906 if ( (tb
->used
> 0) && ((back
?tPtr
->tpos
> 0:1))
1907 && (tPtr
->tpos
<= tb
->used
) && !tb
->graphic
) {
1910 memmove(&(tb
->text
[tPtr
->tpos
]),
1911 &(tb
->text
[tPtr
->tpos
+ 1]), tb
->used
- tPtr
->tpos
);
1916 if ( (back
? (tPtr
->tpos
< 1 && !done
) : ( tPtr
->tpos
>= tb
->used
))
1919 TextBlock
*sibling
= (back
? tb
->prior
: tb
->next
);
1921 if(tb
->used
== 0 || tb
->graphic
)
1922 WMDestroyTextBlock(tPtr
, WMRemoveTextBlock(tPtr
));
1925 tPtr
->currentTextBlock
= sibling
;
1926 tPtr
->tpos
= (back
? sibling
->used
: 0);
1930 layOutDocument(tPtr
);
1935 insertTextInteractively(Text
*tPtr
, char *text
, int len
)
1938 char *newline
= NULL
;
1940 if (!tPtr
->flags
.editable
) {
1941 XBell(tPtr
->view
->screen
->display
, 0);
1945 if (len
< 1 || !text
)
1949 if(tPtr
->flags
.ignoreNewLine
&& *text
== '\n' && len
== 1)
1952 if (tPtr
->flags
.ownsSelection
)
1953 removeSelection(tPtr
);
1956 if (tPtr
->flags
.ignoreNewLine
) {
1958 for(i
=0; i
<len
; i
++) {
1959 if (text
[i
] == '\n')
1964 tb
= tPtr
->currentTextBlock
;
1965 if (!tb
|| tb
->graphic
) {
1967 WMAppendTextStream(tPtr
, text
);
1968 tPtr
->tpos
= tPtr
->currentTextBlock
->used
;
1969 layOutDocument(tPtr
);
1973 if ((newline
= strchr(text
, '\n'))) {
1974 int nlen
= (int)(newline
-text
);
1975 int s
= tb
->used
- tPtr
->tpos
;
1977 if (!tb
->blank
&& nlen
>0) {
1979 memcpy(save
, &tb
->text
[tPtr
->tpos
], s
);
1980 tb
->used
-= (tb
->used
- tPtr
->tpos
);
1983 insertTextInteractively(tPtr
, text
, nlen
);
1985 WMAppendTextStream(tPtr
, newline
);
1987 insertTextInteractively(tPtr
, save
, s
);
1990 if (tPtr
->tpos
>0 && tPtr
->tpos
< tb
->used
1991 && !tb
->graphic
&& tb
->text
) {
1993 void *ntb
= WMCreateTextBlockWithText(
1994 tPtr
, &tb
->text
[tPtr
->tpos
],
1995 tb
->d
.font
, tb
->color
, True
, tb
->used
- tPtr
->tpos
);
1996 tb
->used
= tPtr
->tpos
;
1997 WMAppendTextBlock(tPtr
, ntb
);
2000 } else if (tPtr
->tpos
== tb
->used
|| tPtr
->tpos
== 0) {
2001 void *ntb
= WMCreateTextBlockWithText(tPtr
,
2002 NULL
, tb
->d
.font
, tb
->color
, True
, 0);
2003 WMAppendTextBlock(tPtr
, ntb
);
2009 if (tb
->used
+ len
>= tb
->allocated
) {
2010 tb
->allocated
= reqBlockSize(tb
->used
+len
);
2011 tb
->text
= wrealloc(tb
->text
, tb
->allocated
);
2015 memcpy(tb
->text
, text
, len
);
2018 tb
->text
[tb
->used
] = 0;
2022 memmove(&(tb
->text
[tPtr
->tpos
+len
]), &tb
->text
[tPtr
->tpos
],
2023 tb
->used
-tPtr
->tpos
+1);
2024 memmove(&tb
->text
[tPtr
->tpos
], text
, len
);
2027 tb
->text
[tb
->used
] = 0;
2032 layOutDocument(tPtr
);
2037 selectRegion(Text
*tPtr
, int x
, int y
)
2043 y
+= (tPtr
->flags
.rulerShown
? 40: 0);
2046 y
-= 10; /* the original offset */
2048 x
-= tPtr
->visible
.x
-2;
2052 tPtr
->sel
.x
= WMAX(0, WMIN(tPtr
->clicked
.x
, x
));
2053 tPtr
->sel
.w
= abs(tPtr
->clicked
.x
- x
);
2054 tPtr
->sel
.y
= WMAX(0, WMIN(tPtr
->clicked
.y
, y
));
2055 tPtr
->sel
.h
= abs(tPtr
->clicked
.y
- y
);
2057 tPtr
->flags
.ownsSelection
= True
;
2063 releaseSelection(Text
*tPtr
)
2065 TextBlock
*tb
= tPtr
->firstTextBlock
;
2068 tb
->selected
= False
;
2071 tPtr
->flags
.ownsSelection
= False
;
2072 WMDeleteSelectionHandler(tPtr
->view
, XA_PRIMARY
,
2080 requestHandler(WMView
*view
, Atom selection
, Atom target
, void *cdata
,
2083 Text
*tPtr
= view
->self
;
2084 Display
*dpy
= tPtr
->view
->screen
->display
;
2086 Atom TEXT
= XInternAtom(dpy
, "TEXT", False
);
2087 Atom COMPOUND_TEXT
= XInternAtom(dpy
, "COMPOUND_TEXT", False
);
2088 WMData
*data
= NULL
;
2091 if (target
== XA_STRING
|| target
== TEXT
|| target
== COMPOUND_TEXT
) {
2092 char *text
= WMGetTextSelectedStream(tPtr
);
2095 printf("got text [%s]\n", text
);
2096 data
= WMCreateDataWithBytes(text
, strlen(text
));
2097 WMSetDataFormat(data
, TYPETEXT
);
2101 } else printf("didn't get it\n");
2103 _TARGETS
= XInternAtom(dpy
, "TARGETS", False
);
2104 if (target
== _TARGETS
) {
2107 ptr
= wmalloc(4 * sizeof(Atom
));
2111 ptr
[3] = COMPOUND_TEXT
;
2113 data
= WMCreateDataWithBytes(ptr
, 4*4);
2114 WMSetDataFormat(data
, 32);
2124 lostHandler(WMView
*view
, Atom selection
, void *cdata
)
2126 releaseSelection((WMText
*)view
->self
);
2129 static WMSelectionProcs selectionHandler
= {
2130 requestHandler
, lostHandler
, NULL
2135 ownershipObserver(void *observerData
, WMNotification
*notification
)
2137 if (observerData
!= WMGetNotificationClientData(notification
))
2138 lostHandler(WMWidgetView(observerData
), XA_PRIMARY
, NULL
);
2143 fontChanged(void *observerData
, WMNotification
*notification
)
2145 WMText
*tPtr
= (WMText
*) observerData
;
2146 WMFont
*font
= (WMFont
*)WMGetNotificationClientData(notification
);
2147 printf("fontChanged\n");
2152 if (tPtr
->flags
.ownsSelection
)
2153 WMSetTextSelectionFont(tPtr
, font
);
2158 handleTextKeyPress(Text
*tPtr
, XEvent
*event
)
2162 int control_pressed
= False
;
2163 TextBlock
*tb
= NULL
;
2165 if (((XKeyEvent
*) event
)->state
& ControlMask
)
2166 control_pressed
= True
;
2167 buffer
[XLookupString(&event
->xkey
, buffer
, 1, &ksym
, NULL
)] = 0;
2172 if(!(tb
= tPtr
->currentTextBlock
))
2178 L_imaGFX
: if(tb
->prior
) {
2179 tPtr
->currentTextBlock
= tb
->prior
;
2180 tPtr
->tpos
= tPtr
->currentTextBlock
->used
-1;
2181 } else tPtr
->tpos
= 0;
2182 } else tPtr
->tpos
--;
2183 updateCursorPosition(tPtr
);
2188 if(!(tb
= tPtr
->currentTextBlock
))
2192 if(tPtr
->tpos
== tb
->used
) {
2193 R_imaGFX
: if(tb
->next
) {
2194 tPtr
->currentTextBlock
= tb
->next
;
2196 } else tPtr
->tpos
= tb
->used
;
2197 } else tPtr
->tpos
++;
2198 updateCursorPosition(tPtr
);
2203 cursorToTextPosition(tPtr
, tPtr
->cursor
.x
+ tPtr
->visible
.x
,
2204 tPtr
->clicked
.y
+ tPtr
->cursor
.h
- tPtr
->vpos
);
2209 cursorToTextPosition(tPtr
, tPtr
->cursor
.x
+ tPtr
->visible
.x
,
2210 tPtr
->visible
.y
+ tPtr
->cursor
.y
- tPtr
->vpos
- 3);
2217 deleteTextInteractively(tPtr
, ksym
);
2218 updateCursorPosition(tPtr
);
2224 control_pressed
= True
;
2228 insertTextInteractively(tPtr
, " ", 4);
2229 updateCursorPosition(tPtr
);
2236 if (buffer
[0] != 0 && !control_pressed
) {
2237 insertTextInteractively(tPtr
, buffer
, 1);
2238 updateCursorPosition(tPtr
);
2241 } else if (control_pressed
&& ksym
==XK_r
) {
2242 Bool i
= !tPtr
->flags
.rulerShown
;
2243 WMShowTextRuler(tPtr
, i
);
2244 tPtr
->flags
.rulerShown
= i
;
2246 else if (control_pressed
&& buffer
[0] == '\a')
2247 XBell(tPtr
->view
->screen
->display
, 0);
2250 if (!control_pressed
&& tPtr
->flags
.ownsSelection
)
2251 releaseSelection(tPtr
);
2255 handleWidgetPress(XEvent
*event
, void *data
)
2257 TextBlock
*tb
= (TextBlock
*)data
;
2265 tPtr
->currentTextBlock
= tb
;
2266 tPtr
->flags
.isOverGraphic
= 2;
2268 output(tb
->text
, tb
->used
);
2270 if (!tPtr
->flags
.focused
) {
2271 WMSetFocusToWidget(tPtr
);
2272 tPtr
->flags
.focused
= True
;
2279 handleActionEvents(XEvent
*event
, void *data
)
2281 Text
*tPtr
= (Text
*)data
;
2282 Display
*dpy
= event
->xany
.display
;
2286 switch (event
->type
) {
2288 ksym
= XLookupKeysym((XKeyEvent
*)event
, 0);
2289 if (ksym
== XK_Shift_R
|| ksym
== XK_Shift_L
) {
2290 tPtr
->flags
.extendSelection
= True
;
2294 if (tPtr
->flags
.focused
) {
2295 XGrabPointer(dpy
, W_VIEW(tPtr
)->window
, False
,
2296 PointerMotionMask
|ButtonPressMask
|ButtonReleaseMask
,
2297 GrabModeAsync
, GrabModeAsync
, None
,
2298 tPtr
->view
->screen
->invisibleCursor
, CurrentTime
);
2299 tPtr
->flags
.pointerGrabbed
= True
;
2300 handleTextKeyPress(tPtr
, event
);
2305 ksym
= XLookupKeysym((XKeyEvent
*)event
, 0);
2306 if (ksym
== XK_Shift_R
|| ksym
== XK_Shift_L
) {
2307 tPtr
->flags
.extendSelection
= False
;
2309 /* end modify flag so selection can be extended */
2316 if (tPtr
->flags
.pointerGrabbed
) {
2317 tPtr
->flags
.pointerGrabbed
= False
;
2318 XUngrabPointer(dpy
, CurrentTime
);
2321 if(tPtr
->flags
.waitingForSelection
)
2324 if ((event
->xmotion
.state
& Button1Mask
)) {
2325 if (!tPtr
->flags
.ownsSelection
) {
2326 WMCreateSelectionHandler(tPtr
->view
,
2327 XA_PRIMARY
, event
->xbutton
.time
,
2328 &selectionHandler
, NULL
);
2329 tPtr
->flags
.ownsSelection
= True
;
2331 selectRegion(tPtr
, event
->xmotion
.x
, event
->xmotion
.y
);
2335 mouseOverObject(tPtr
, event
->xmotion
.x
, event
->xmotion
.y
);
2341 if (tPtr
->flags
.pointerGrabbed
) {
2342 tPtr
->flags
.pointerGrabbed
= False
;
2343 XUngrabPointer(dpy
, CurrentTime
);
2347 if (tPtr
->flags
.waitingForSelection
)
2350 if (tPtr
->flags
.extendSelection
) {
2351 selectRegion(tPtr
, event
->xmotion
.x
, event
->xmotion
.y
);
2356 if (event
->xbutton
.button
== Button1
) {
2358 if(WMIsDoubleClick(event
)) {
2359 TextBlock
*tb
= tPtr
->currentTextBlock
;
2361 if(tb
&& tb
->graphic
&& !tb
->object
) {
2362 char desc
[tb
->used
+1];
2363 memcpy(desc
, tb
->text
, tb
->used
);
2365 if(tPtr
->delegate
) {
2366 if(tPtr
->delegate
->didDoubleClickOnPicture
)
2367 (*tPtr
->delegate
->didDoubleClickOnPicture
)
2368 (tPtr
->delegate
, desc
);
2371 autoSelectText(tPtr
, 2);
2373 tPtr
->lastClickTime
= event
->xbutton
.time
;
2375 } else if(event
->xbutton
.time
- tPtr
->lastClickTime
2376 < WINGsConfiguration
.doubleClickDelay
) {
2377 autoSelectText(tPtr
, 3);
2381 if (!tPtr
->flags
.focused
) {
2382 WMSetFocusToWidget(tPtr
);
2383 tPtr
->flags
.focused
= True
;
2386 if (tPtr
->flags
.ownsSelection
)
2387 releaseSelection(tPtr
);
2389 tPtr
->lastClickTime
= event
->xbutton
.time
;
2390 cursorToTextPosition(tPtr
, event
->xmotion
.x
, event
->xmotion
.y
);
2394 if (event
->xbutton
.button
2395 == WINGsConfiguration
.mouseWheelDown
) {
2396 WMScrollText(tPtr
, -16);
2400 if (event
->xbutton
.button
2401 == WINGsConfiguration
.mouseWheelUp
) {
2402 WMScrollText(tPtr
, 16);
2406 if (event
->xbutton
.button
== Button2
) {
2410 if (!tPtr
->flags
.editable
) {
2416 if (!WMRequestSelection(tPtr
->view
, XA_PRIMARY
, XA_STRING
,
2417 event
->xbutton
.time
, pasteText
, NULL
)) {
2421 text
= XFetchBuffer(tPtr
->view
->screen
->display
, &n
, 0);
2427 (tPtr
->parser
) (tPtr
, (void *) text
);
2429 insertTextInteractively(tPtr
, text
, n
);
2433 NOTIFY(tPtr
, didChange
, WMTextDidChangeNotification
,
2434 (void*)WMInsertTextEvent
);
2438 tPtr
->flags
.waitingForSelection
= True
;
2447 if (tPtr
->flags
.pointerGrabbed
) {
2448 tPtr
->flags
.pointerGrabbed
= False
;
2449 XUngrabPointer(dpy
, CurrentTime
);
2453 if (tPtr
->flags
.waitingForSelection
)
2461 handleEvents(XEvent
*event
, void *data
)
2463 Text
*tPtr
= (Text
*)data
;
2465 switch(event
->type
) {
2468 if (event
->xexpose
.count
!=0)
2472 if (!(W_VIEW(tPtr
->hS
))->flags
.realized
)
2473 WMRealizeWidget(tPtr
->hS
);
2477 if (!(W_VIEW(tPtr
->vS
))->flags
.realized
)
2478 WMRealizeWidget(tPtr
->vS
);
2482 if (!(W_VIEW(tPtr
->ruler
))->flags
.realized
)
2483 WMRealizeWidget(tPtr
->ruler
);
2488 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
2494 if (W_FocusedViewOfToplevel(W_TopLevelOfView(tPtr
->view
))
2497 tPtr
->flags
.focused
= True
;
2499 if (tPtr
->flags
.editable
&& !tPtr
->timerID
) {
2500 tPtr
->timerID
= WMAddTimerHandler(12+0*CURSOR_BLINK_ON_DELAY
,
2508 tPtr
->flags
.focused
= False
;
2511 if (tPtr
->timerID
) {
2512 WMDeleteTimerHandler(tPtr
->timerID
);
2513 tPtr
->timerID
= NULL
;
2522 WMDestroyWidget(tPtr
->hS
);
2524 WMDestroyWidget(tPtr
->vS
);
2526 WMDestroyWidget(tPtr
->ruler
);
2528 XFreePixmap(tPtr
->view
->screen
->display
, tPtr
->db
);
2530 WMFreeArray(tPtr
->gfxItems
);
2533 WMDeleteTimerHandler(tPtr
->timerID
);
2535 WMReleaseFont(tPtr
->dFont
);
2536 WMReleaseColor(tPtr
->dColor
);
2537 WMDeleteSelectionHandler(tPtr
->view
, XA_PRIMARY
, CurrentTime
);
2538 WMRemoveNotificationObserver(tPtr
);
2549 insertText(WMText
*tPtr
, char *stream
)
2561 mark
= strchr(start
, '\n');
2563 tb
= WMCreateTextBlockWithText(tPtr
,
2565 tPtr
->dColor
, True
, (int)(mark
-start
));
2568 if (start
&& strlen(start
)) {
2569 tb
= WMCreateTextBlockWithText(tPtr
, start
, tPtr
->dFont
,
2570 tPtr
->dColor
, False
, strlen(start
));
2575 if (tPtr
->flags
.prepend
)
2576 WMPrependTextBlock(tPtr
, tb
);
2578 WMAppendTextBlock(tPtr
, tb
);
2586 rulerMoveCallBack(WMWidget
*w
, void *self
)
2588 Text
*tPtr
= (Text
*)self
;
2591 if (W_CLASS(tPtr
) != WC_Text
)
2599 rulerReleaseCallBack(WMWidget
*w
, void *self
)
2601 Text
*tPtr
= (Text
*)self
;
2604 if (W_CLASS(tPtr
) != WC_Text
)
2613 draggingEntered(WMView
*self
, WMDraggingInfo
*info
)
2615 printf("draggingEntered\n");
2616 return WDOperationCopy
;
2621 draggingUpdated(WMView
*self
, WMDraggingInfo
*info
)
2623 return WDOperationCopy
;
2628 draggingExited(WMView
*self
, WMDraggingInfo
*info
)
2630 printf("draggingExited\n");
2634 prepareForDragOperation(WMView
*self
, WMDraggingInfo
*info
)
2636 printf("prepareForDragOperation\n");
2644 receivedData(WMView
*view
, Atom selection
, Atom target
, Time timestamp
,
2645 void *cdata
, WMData
*data
)
2647 badbadbad
= wstrdup((char *)WMDataBytes(data
));
2651 /* when it's done in WINGs, remove this */
2653 Bool
requestDroppedData(WMView
*view
, WMDraggingInfo
*info
, char *type
)
2655 WMScreen
*scr
= W_VIEW_SCREEN(view
);
2657 if (!WMRequestSelection(scr
->dragInfo
.destView
,
2658 scr
->xdndSelectionAtom
,
2659 XInternAtom(scr
->display
, type
, False
),
2660 scr
->dragInfo
.timestamp
,
2661 receivedData
, &scr
->dragInfo
)) {
2662 wwarning("could not request data for dropped data");
2669 ev
.type
= ClientMessage
;
2670 ev
.xclient
.message_type
= scr
->xdndFinishedAtom
;
2671 ev
.xclient
.format
= 32;
2672 ev
.xclient
.window
= info
->destinationWindow
;
2673 ev
.xclient
.data
.l
[0] = 0;
2674 ev
.xclient
.data
.l
[1] = 0;
2675 ev
.xclient
.data
.l
[2] = 0;
2676 ev
.xclient
.data
.l
[3] = 0;
2677 ev
.xclient
.data
.l
[4] = 0;
2679 XSendEvent(scr
->display
, info
->sourceWindow
, False
, 0, &ev
);
2680 XFlush(scr
->display
);
2686 performDragOperation(WMView
*self
, WMDraggingInfo
*info
, WMData
*data
)
2689 WMText
*tPtr
= (WMText
*)self
->self
;
2694 requestDroppedData(tPtr
->view
, info
, "application/X-color");
2695 color
= WMCreateNamedColor(W_VIEW_SCREEN(self
), badbadbad
, True
);
2697 WMSetTextSelectionColor(tPtr
, color
);
2698 WMReleaseColor(color
);
2707 concludeDragOperation(WMView
*self
, WMDraggingInfo
*info
)
2709 printf("concludeDragOperation\n");
2713 static WMDragDestinationProcs _DragDestinationProcs
= {
2717 prepareForDragOperation
,
2718 performDragOperation
,
2719 concludeDragOperation
2724 getStream(WMText
*tPtr
, int sel
, int array
)
2726 TextBlock
*tb
= NULL
;
2728 unsigned long where
= 0;
2733 if (!(tb
= tPtr
->firstTextBlock
))
2737 (tPtr
->writer
) (tPtr
, (void *) text
);
2741 tb
= tPtr
->firstTextBlock
;
2744 if (!tb
->graphic
|| (tb
->graphic
&& !tPtr
->flags
.monoFont
)) {
2746 if (!sel
|| (tb
->graphic
&& tb
->selected
)) {
2748 if (!tPtr
->flags
.ignoreNewLine
&& (tb
->first
|| tb
->blank
)
2749 && tb
!= tPtr
->firstTextBlock
) {
2750 text
= wrealloc(text
, where
+1);
2751 text
[where
++] = '\n';
2757 if(tb
->graphic
&& array
) {
2758 text
= wrealloc(text
, where
+4);
2759 text
[where
++] = 0xFA;
2760 text
[where
++] = (tb
->used
>>8)&0x0ff;
2761 text
[where
++] = tb
->used
&0x0ff;
2762 text
[where
++] = tb
->allocated
; /* extra info */
2764 text
= wrealloc(text
, where
+tb
->used
);
2765 memcpy(&text
[where
], tb
->text
, tb
->used
);
2769 } else if (sel
&& tb
->selected
) {
2771 if (!tPtr
->flags
.ignoreNewLine
&& (tb
->first
|| tb
->blank
)
2772 && tb
!= tPtr
->firstTextBlock
) {
2773 text
= wrealloc(text
, where
+1);
2774 text
[where
++] = '\n';
2780 text
= wrealloc(text
, where
+(tb
->s_end
- tb
->s_begin
));
2781 memcpy(&text
[where
], &tb
->text
[tb
->s_begin
],
2782 tb
->s_end
- tb
->s_begin
);
2783 where
+= tb
->s_end
- tb
->s_begin
;
2788 _gSnext
:tb
= tb
->next
;
2791 /* +1 for the end of string, let's be nice */
2792 text
= wrealloc(text
, where
+1);
2799 releaseStreamObjects(void *data
)
2806 getStreamObjects(WMText
*tPtr
, int sel
)
2808 WMArray
*array
= WMCreateArrayWithDestructor(4, releaseStreamObjects
);
2812 char *start
, *fa
, *desc
;
2814 stream
= getStream(tPtr
, sel
, 1);
2821 fa
= strchr(start
, 0xFA);
2823 if((int)(fa
- start
)>0) {
2825 desc
[(int)(fa
- start
)] = 0;
2826 data
= WMCreateDataWithBytes((void *)desc
, (int)(fa
- start
));
2827 WMSetDataFormat(data
, TYPETEXT
);
2828 WMAddToArray(array
, (void *) data
);
2831 len
= *(fa
+1)*0xff + *(fa
+2);
2832 data
= WMCreateDataWithBytes((void *)(fa
+4), len
);
2833 WMSetDataFormat(data
, *(fa
+3));
2834 WMAddToArray(array
, (void *) data
);
2835 start
= fa
+ len
+ 4;
2838 if (start
&& strlen(start
)) {
2839 data
= WMCreateDataWithBytes((void *)start
, strlen(start
));
2840 WMSetDataFormat(data
, TYPETEXT
);
2841 WMAddToArray(array
, (void *) data
);
2854 WMCreateTextForDocumentType(WMWidget
*parent
,
2855 WMAction
*parser
, WMAction
*writer
)
2857 Text
*tPtr
= wmalloc(sizeof(Text
));
2859 printf("could not create text widget\n");
2864 memset(tPtr
, 0, sizeof(Text
));
2865 tPtr
->widgetClass
= WC_Text
;
2866 tPtr
->view
= W_CreateView(W_VIEW(parent
));
2868 perror("could not create text's view\n");
2872 tPtr
->view
->self
= tPtr
;
2873 tPtr
->view
->attribs
.cursor
= tPtr
->view
->screen
->textCursor
;
2874 tPtr
->view
->attribFlags
|= CWOverrideRedirect
| CWCursor
;
2875 W_ResizeView(tPtr
->view
, 250, 200);
2877 tPtr
->dColor
= WMWhiteColor(tPtr
->view
->screen
);
2878 tPtr
->bgGC
= WMColorGC(tPtr
->dColor
);
2879 W_SetViewBackgroundColor(tPtr
->view
, tPtr
->dColor
);
2880 WMReleaseColor(tPtr
->dColor
);
2882 tPtr
->dColor
= WMBlackColor(tPtr
->view
->screen
);
2883 tPtr
->fgGC
= WMColorGC(tPtr
->dColor
);
2889 tPtr
->dFont
= WMRetainFont(WMSystemFontOfSize(tPtr
->view
->screen
, 12));
2891 tPtr
->view
->delegate
= &_TextViewDelegate
;
2893 tPtr
->delegate
= NULL
;
2896 tPtr
->timerID
= NULL
;
2899 WMCreateEventHandler(tPtr
->view
, ExposureMask
|StructureNotifyMask
2900 |EnterWindowMask
|LeaveWindowMask
|FocusChangeMask
,
2901 handleEvents
, tPtr
);
2903 WMCreateEventHandler(tPtr
->view
, ButtonReleaseMask
|ButtonPressMask
2904 |KeyReleaseMask
|KeyPressMask
|Button1MotionMask
,
2905 handleActionEvents
, tPtr
);
2907 WMAddNotificationObserver(ownershipObserver
, tPtr
,
2908 "_lostOwnership", tPtr
);
2910 WMSetViewDragDestinationProcs(tPtr
->view
, &_DragDestinationProcs
);
2912 char *types
[2] = {"application/X-color", NULL
};
2913 WMRegisterViewForDraggedTypes(tPtr
->view
, types
);
2916 WMAddNotificationObserver(fontChanged
, tPtr
,
2917 "WMFontPanelDidChangeNotification", tPtr
);
2919 tPtr
->firstTextBlock
= NULL
;
2920 tPtr
->lastTextBlock
= NULL
;
2921 tPtr
->currentTextBlock
= NULL
;
2924 tPtr
->gfxItems
= WMCreateArray(4);
2926 tPtr
->parser
= parser
;
2927 tPtr
->writer
= writer
;
2929 tPtr
->sel
.x
= tPtr
->sel
.y
= 2;
2930 tPtr
->sel
.w
= tPtr
->sel
.h
= 0;
2932 tPtr
->clicked
.x
= tPtr
->clicked
.y
= 2;
2934 tPtr
->visible
.x
= tPtr
->visible
.y
= 2;
2935 tPtr
->visible
.h
= tPtr
->view
->size
.height
;
2936 tPtr
->visible
.w
= tPtr
->view
->size
.width
- 4;
2938 tPtr
->cursor
.x
= -23;
2941 tPtr
->docHeight
= 0;
2942 tPtr
->dBulletPix
= WMCreatePixmapFromXPMData(tPtr
->view
->screen
,
2944 tPtr
->db
= (Pixmap
) NULL
;
2946 tPtr
->margins
= WMGetRulerMargins(NULL
);
2947 tPtr
->margins
->right
= tPtr
->visible
.w
;
2950 tPtr
->flags
.rulerShown
= False
;
2951 tPtr
->flags
.monoFont
= False
;
2952 tPtr
->flags
.focused
= False
;
2953 tPtr
->flags
.editable
= True
;
2954 tPtr
->flags
.ownsSelection
= False
;
2955 tPtr
->flags
.pointerGrabbed
= False
;
2956 tPtr
->flags
.extendSelection
= False
;
2957 tPtr
->flags
.frozen
= False
;
2958 tPtr
->flags
.cursorShown
= True
;
2959 tPtr
->flags
.acceptsGraphic
= False
;
2960 tPtr
->flags
.horizOnDemand
= False
;
2961 tPtr
->flags
.needsLayOut
= False
;
2962 tPtr
->flags
.ignoreNewLine
= False
;
2963 tPtr
->flags
.laidOut
= False
;
2964 tPtr
->flags
.waitingForSelection
= False
;
2965 tPtr
->flags
.prepend
= False
;
2966 tPtr
->flags
.isOverGraphic
= False
;
2967 tPtr
->flags
.relief
= WRSunken
;
2968 tPtr
->flags
.isOverGraphic
= 0;
2969 tPtr
->flags
.alignment
= WALeft
;
2975 WMPrependTextStream(WMText
*tPtr
, char *text
)
2977 CHECK_CLASS(tPtr
, WC_Text
);
2980 if(tPtr
->flags
.ownsSelection
)
2981 releaseSelection(tPtr
);
2986 tPtr
->flags
.prepend
= True
;
2987 if (text
&& tPtr
->parser
)
2988 (tPtr
->parser
) (tPtr
, (void *) text
);
2990 insertText(tPtr
, text
);
2992 tPtr
->flags
.needsLayOut
= True
;
2997 WMAppendTextStream(WMText
*tPtr
, char *text
)
2999 CHECK_CLASS(tPtr
, WC_Text
);
3002 if(tPtr
->flags
.ownsSelection
)
3003 releaseSelection(tPtr
);
3008 tPtr
->flags
.prepend
= False
;
3009 if (text
&& tPtr
->parser
)
3010 (tPtr
->parser
) (tPtr
, (void *) text
);
3012 insertText(tPtr
, text
);
3014 tPtr
->flags
.needsLayOut
= True
;
3020 WMGetTextStream(WMText
*tPtr
)
3022 CHECK_CLASS(tPtr
, WC_Text
);
3023 return getStream(tPtr
, 0, 0);
3027 WMGetTextSelectedStream(WMText
*tPtr
)
3029 CHECK_CLASS(tPtr
, WC_Text
);
3030 return getStream(tPtr
, 1, 0);
3034 WMGetTextObjects(WMText
*tPtr
)
3036 CHECK_CLASS(tPtr
, WC_Text
);
3037 return getStreamObjects(tPtr
, 0);
3041 WMGetTextSelectedObjects(WMText
*tPtr
)
3043 CHECK_CLASS(tPtr
, WC_Text
);
3044 return getStreamObjects(tPtr
, 1);
3049 WMSetTextDelegate(WMText
*tPtr
, WMTextDelegate
*delegate
)
3051 CHECK_CLASS(tPtr
, WC_Text
);
3053 tPtr
->delegate
= delegate
;
3058 WMCreateTextBlockWithObject(WMText
*tPtr
, WMWidget
*w
,
3059 char *description
, WMColor
*color
,
3060 unsigned short first
, unsigned short extraInfo
)
3065 if (!w
|| !description
|| !color
)
3068 tb
= wmalloc(sizeof(TextBlock
));
3072 len
= strlen(description
);
3073 tb
->text
= (char *)wmalloc(len
);
3074 memset(tb
->text
, 0, len
);
3075 memcpy(tb
->text
, description
, len
);
3077 tb
->text
[tb
->used
] = 0;
3080 tb
->color
= WMRetainColor(color
);
3081 tb
->marginN
= newMargin(tPtr
, NULL
);
3082 tb
->allocated
= extraInfo
;
3087 tb
->underlined
= False
;
3088 tb
->selected
= False
;
3090 tb
->sections
= NULL
;
3100 WMCreateTextBlockWithPixmap(WMText
*tPtr
, WMPixmap
*p
,
3101 char *description
, WMColor
*color
,
3102 unsigned short first
, unsigned short extraInfo
)
3107 if (!p
|| !description
|| !color
)
3110 tb
= wmalloc(sizeof(TextBlock
));
3114 len
= strlen(description
);
3115 tb
->text
= (char *)wmalloc(len
);
3116 memset(tb
->text
, 0, len
);
3117 memcpy(tb
->text
, description
, len
);
3119 tb
->text
[tb
->used
] = 0;
3121 tb
->d
.pixmap
= WMRetainPixmap(p
);
3122 tb
->color
= WMRetainColor(color
);
3123 tb
->marginN
= newMargin(tPtr
, NULL
);
3124 tb
->allocated
= extraInfo
;
3129 tb
->underlined
= False
;
3130 tb
->selected
= False
;
3132 tb
->sections
= NULL
;
3141 WMCreateTextBlockWithText(WMText
*tPtr
, char *text
, WMFont
*font
, WMColor
*color
,
3142 unsigned short first
, unsigned short len
)
3146 if (!font
|| !color
)
3149 tb
= wmalloc(sizeof(TextBlock
));
3153 tb
->allocated
= reqBlockSize(len
);
3154 tb
->text
= (char *)wmalloc(tb
->allocated
);
3155 memset(tb
->text
, 0, tb
->allocated
);
3157 if (len
< 1|| !text
|| (*text
== '\n' && len
==1 )) {
3162 memcpy(tb
->text
, text
, len
);
3166 tb
->text
[tb
->used
] = 0;
3168 tb
->d
.font
= WMRetainFont(font
);
3169 tb
->color
= WMRetainColor(color
);
3170 tb
->marginN
= newMargin(tPtr
, NULL
);
3173 tb
->graphic
= False
;
3174 tb
->underlined
= False
;
3175 tb
->selected
= False
;
3177 tb
->sections
= NULL
;
3185 WMSetTextBlockProperties(WMText
*tPtr
, void *vtb
, unsigned int first
,
3186 unsigned int kanji
, unsigned int underlined
, int script
,
3187 WMRulerMargins
*margins
)
3189 TextBlock
*tb
= (TextBlock
*) vtb
;
3195 tb
->underlined
= underlined
;
3196 tb
->script
= script
;
3197 tb
->marginN
= newMargin(tPtr
, margins
);
3201 WMGetTextBlockProperties(WMText
*tPtr
, void *vtb
, unsigned int *first
,
3202 unsigned int *kanji
, unsigned int *underlined
, int *script
,
3203 WMRulerMargins
*margins
)
3205 TextBlock
*tb
= (TextBlock
*) vtb
;
3209 if (first
) *first
= tb
->first
;
3210 if (kanji
) *kanji
= tb
->kanji
;
3211 if (underlined
) *underlined
= tb
->underlined
;
3212 if (script
) *script
= tb
->script
;
3213 if (margins
) margins
= &tPtr
->margins
[tb
->marginN
];
3219 WMPrependTextBlock(WMText
*tPtr
, void *vtb
)
3221 TextBlock
*tb
= (TextBlock
*)vtb
;
3228 WMWidget
*w
= tb
->d
.widget
;
3229 WMCreateEventHandler(W_VIEW(w
), ButtonPressMask
,
3230 handleWidgetPress
, tb
);
3231 if (W_CLASS(w
) != WC_TextField
&& W_CLASS(w
) != WC_Text
) {
3232 (W_VIEW(w
))->attribs
.cursor
= tPtr
->view
->screen
->defaultCursor
;
3233 (W_VIEW(w
))->attribFlags
|= CWOverrideRedirect
| CWCursor
;
3236 WMAddToArray(tPtr
->gfxItems
, (void *)tb
);
3238 } else tPtr
->tpos
= tb
->used
;
3240 if (!tPtr
->lastTextBlock
|| !tPtr
->firstTextBlock
) {
3241 tb
->next
= tb
->prior
= NULL
;
3243 tPtr
->lastTextBlock
= tPtr
->firstTextBlock
3244 = tPtr
->currentTextBlock
= tb
;
3249 tb
->marginN
= tPtr
->currentTextBlock
->marginN
;
3252 tb
->next
= tPtr
->currentTextBlock
;
3253 tb
->prior
= tPtr
->currentTextBlock
->prior
;
3254 if (tPtr
->currentTextBlock
->prior
)
3255 tPtr
->currentTextBlock
->prior
->next
= tb
;
3257 tPtr
->currentTextBlock
->prior
= tb
;
3259 tPtr
->firstTextBlock
= tb
;
3261 tPtr
->currentTextBlock
= tb
;
3266 WMAppendTextBlock(WMText
*tPtr
, void *vtb
)
3268 TextBlock
*tb
= (TextBlock
*)vtb
;
3275 WMWidget
*w
= tb
->d
.widget
;
3276 WMCreateEventHandler(W_VIEW(w
), ButtonPressMask
,
3277 handleWidgetPress
, tb
);
3278 if (W_CLASS(w
) != WC_TextField
&& W_CLASS(w
) != WC_Text
) {
3279 (W_VIEW(w
))->attribs
.cursor
=
3280 tPtr
->view
->screen
->defaultCursor
;
3281 (W_VIEW(w
))->attribFlags
|= CWOverrideRedirect
| CWCursor
;
3284 WMAddToArray(tPtr
->gfxItems
, (void *)tb
);
3286 } else tPtr
->tpos
= tb
->used
;
3288 if (!tPtr
->lastTextBlock
|| !tPtr
->firstTextBlock
) {
3289 tb
->next
= tb
->prior
= NULL
;
3291 tPtr
->lastTextBlock
= tPtr
->firstTextBlock
3292 = tPtr
->currentTextBlock
= tb
;
3297 tb
->marginN
= tPtr
->currentTextBlock
->marginN
;
3300 tb
->next
= tPtr
->currentTextBlock
->next
;
3301 tb
->prior
= tPtr
->currentTextBlock
;
3302 if (tPtr
->currentTextBlock
->next
)
3303 tPtr
->currentTextBlock
->next
->prior
= tb
;
3305 tPtr
->currentTextBlock
->next
= tb
;
3308 tPtr
->lastTextBlock
= tb
;
3310 tPtr
->currentTextBlock
= tb
;
3314 WMRemoveTextBlock(WMText
*tPtr
)
3316 TextBlock
*tb
= NULL
;
3318 if (!tPtr
|| !tPtr
->firstTextBlock
|| !tPtr
->lastTextBlock
3319 || !tPtr
->currentTextBlock
) {
3320 printf("cannot remove non existent TextBlock!\b");
3324 tb
= tPtr
->currentTextBlock
;
3326 WMRemoveFromArray(tPtr
->gfxItems
, (void *)tb
);
3329 WMDeleteEventHandler(W_VIEW(tb
->d
.widget
), ButtonPressMask
,
3330 handleWidgetPress
, tb
);
3331 WMUnmapWidget(tb
->d
.widget
);
3335 if (tPtr
->currentTextBlock
== tPtr
->firstTextBlock
) {
3336 if (tPtr
->currentTextBlock
->next
)
3337 tPtr
->currentTextBlock
->next
->prior
= NULL
;
3339 tPtr
->firstTextBlock
= tPtr
->currentTextBlock
->next
;
3340 tPtr
->currentTextBlock
= tPtr
->firstTextBlock
;
3342 } else if (tPtr
->currentTextBlock
== tPtr
->lastTextBlock
) {
3343 tPtr
->currentTextBlock
->prior
->next
= NULL
;
3344 tPtr
->lastTextBlock
= tPtr
->currentTextBlock
->prior
;
3345 tPtr
->currentTextBlock
= tPtr
->lastTextBlock
;
3347 tPtr
->currentTextBlock
->prior
->next
= tPtr
->currentTextBlock
->next
;
3348 tPtr
->currentTextBlock
->next
->prior
= tPtr
->currentTextBlock
->prior
;
3349 tPtr
->currentTextBlock
= tPtr
->currentTextBlock
->next
;
3356 WMDestroyTextBlock(WMText
*tPtr
, void *vtb
)
3358 TextBlock
*tb
= (TextBlock
*)vtb
;
3364 /* naturally, there's a danger to destroying
3365 widgets whose action brings us here:
3366 ie. press a button to destroy it... need to
3367 find a safer way. till then... this stays commented out */
3368 /* WMDestroyWidget(tb->d.widget);
3369 wfree(tb->d.widget); */
3370 tb
->d
.widget
= NULL
;
3372 WMReleasePixmap(tb
->d
.pixmap
);
3373 tb
->d
.pixmap
= NULL
;
3376 WMReleaseFont(tb
->d
.font
);
3379 WMReleaseColor(tb
->color
);
3380 if (tb
->sections
&& tb
->nsections
> 0)
3381 wfree(tb
->sections
);
3390 WMSetTextForegroundColor(WMText
*tPtr
, WMColor
*color
)
3396 tPtr
->fgGC
= WMColorGC(color
);
3398 tPtr
->fgGC
= WMColorGC(WMBlackColor(tPtr
->view
->screen
));
3404 WMSetTextBackgroundColor(WMText
*tPtr
, WMColor
*color
)
3410 tPtr
->bgGC
= WMColorGC(color
);
3411 W_SetViewBackgroundColor(tPtr
->view
, color
);
3413 tPtr
->bgGC
= WMColorGC(WMWhiteColor(tPtr
->view
->screen
));
3414 W_SetViewBackgroundColor(tPtr
->view
,
3415 WMWhiteColor(tPtr
->view
->screen
));
3422 WMSetTextRelief(WMText
*tPtr
, WMReliefType relief
)
3426 tPtr
->flags
.relief
= relief
;
3427 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
3431 WMSetTextHasHorizontalScroller(WMText
*tPtr
, Bool shouldhave
)
3436 if (shouldhave
&& !tPtr
->hS
) {
3437 tPtr
->hS
= WMCreateScroller(tPtr
);
3438 (W_VIEW(tPtr
->hS
))->attribs
.cursor
= tPtr
->view
->screen
->defaultCursor
;
3439 (W_VIEW(tPtr
->hS
))->attribFlags
|= CWOverrideRedirect
| CWCursor
;
3440 WMSetScrollerArrowsPosition(tPtr
->hS
, WSAMinEnd
);
3441 WMSetScrollerAction(tPtr
->hS
, scrollersCallBack
, tPtr
);
3442 WMMapWidget(tPtr
->hS
);
3443 } else if (!shouldhave
&& tPtr
->hS
) {
3444 WMUnmapWidget(tPtr
->hS
);
3445 WMDestroyWidget(tPtr
->hS
);
3451 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
3456 WMSetTextHasRuler(WMText
*tPtr
, Bool shouldhave
)
3461 if(shouldhave
&& !tPtr
->ruler
) {
3462 tPtr
->ruler
= WMCreateRuler(tPtr
);
3463 (W_VIEW(tPtr
->ruler
))->attribs
.cursor
=
3464 tPtr
->view
->screen
->defaultCursor
;
3465 (W_VIEW(tPtr
->ruler
))->attribFlags
|= CWOverrideRedirect
| CWCursor
;
3466 WMSetRulerReleaseAction(tPtr
->ruler
, rulerReleaseCallBack
, tPtr
);
3467 WMSetRulerMoveAction(tPtr
->ruler
, rulerMoveCallBack
, tPtr
);
3468 } else if(!shouldhave
&& tPtr
->ruler
) {
3469 WMShowTextRuler(tPtr
, False
);
3470 WMDestroyWidget(tPtr
->ruler
);
3473 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
3477 WMShowTextRuler(WMText
*tPtr
, Bool show
)
3484 if(tPtr
->flags
.monoFont
)
3487 tPtr
->flags
.rulerShown
= show
;
3489 WMMapWidget(tPtr
->ruler
);
3491 WMUnmapWidget(tPtr
->ruler
);
3494 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
3498 WMGetTextRulerShown(WMText
*tPtr
)
3506 return tPtr
->flags
.rulerShown
;
3511 WMSetTextHasVerticalScroller(WMText
*tPtr
, Bool shouldhave
)
3516 if (shouldhave
&& !tPtr
->vS
) {
3517 tPtr
->vS
= WMCreateScroller(tPtr
);
3518 (W_VIEW(tPtr
->vS
))->attribs
.cursor
= tPtr
->view
->screen
->defaultCursor
;
3519 (W_VIEW(tPtr
->vS
))->attribFlags
|= CWOverrideRedirect
| CWCursor
;
3520 WMSetScrollerArrowsPosition(tPtr
->vS
, WSAMaxEnd
);
3521 WMSetScrollerAction(tPtr
->vS
, scrollersCallBack
, tPtr
);
3522 WMMapWidget(tPtr
->vS
);
3523 } else if (!shouldhave
&& tPtr
->vS
) {
3524 WMUnmapWidget(tPtr
->vS
);
3525 WMDestroyWidget(tPtr
->vS
);
3531 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
3537 WMScrollText(WMText
*tPtr
, int amount
)
3542 if (amount
== 0 || !tPtr
->view
->flags
.realized
)
3546 if (tPtr
->vpos
> 0) {
3547 if (tPtr
->vpos
> abs(amount
)) tPtr
->vpos
+= amount
;
3551 int limit
= tPtr
->docHeight
- tPtr
->visible
.h
;
3552 if (tPtr
->vpos
< limit
) {
3553 if (tPtr
->vpos
< limit
-amount
) tPtr
->vpos
+= amount
;
3554 else tPtr
->vpos
= limit
;
3558 if (scroll
&& tPtr
->vpos
!= tPtr
->prevVpos
) {
3559 updateScrollers(tPtr
);
3562 tPtr
->prevVpos
= tPtr
->vpos
;
3567 WMPageText(WMText
*tPtr
, Bool direction
)
3569 if (!tPtr
) return False
;
3570 if (!tPtr
->view
->flags
.realized
) return False
;
3572 return WMScrollText(tPtr
, direction
?tPtr
->visible
.h
:-tPtr
->visible
.h
);
3576 WMSetTextEditable(WMText
*tPtr
, Bool editable
)
3580 tPtr
->flags
.editable
= editable
;
3584 WMGetTextEditable(WMText
*tPtr
)
3588 return tPtr
->flags
.editable
;
3592 WMSetTextIgnoresNewline(WMText
*tPtr
, Bool ignore
)
3596 tPtr
->flags
.ignoreNewLine
= ignore
;
3600 WMGetTextIgnoresNewline(WMText
*tPtr
)
3604 return tPtr
->flags
.ignoreNewLine
;
3608 WMSetTextUsesMonoFont(WMText
*tPtr
, Bool mono
)
3612 if (mono
&& tPtr
->flags
.rulerShown
)
3613 WMShowTextRuler(tPtr
, False
);
3615 tPtr
->flags
.monoFont
= mono
;
3620 WMGetTextUsesMonoFont(WMText
*tPtr
)
3624 return tPtr
->flags
.monoFont
;
3629 WMSetTextDefaultFont(WMText
*tPtr
, WMFont
*font
)
3634 WMReleaseFont(tPtr
->dFont
);
3636 tPtr
->dFont
= WMRetainFont(font
);
3638 tPtr
->dFont
= WMRetainFont(WMSystemFontOfSize(tPtr
->view
->screen
, 12));
3642 WMGetTextDefaultFont(WMText
*tPtr
)
3651 WMSetTextAlignment(WMText
*tPtr
, WMAlignment alignment
)
3655 tPtr
->flags
.alignment
= alignment
;
3660 WMGetTextInsertType(WMText
*tPtr
)
3664 return tPtr
->flags
.prepend
;
3669 WMSetTextSelectionColor(WMText
*tPtr
, WMColor
*color
)
3671 if (!tPtr
|| !color
)
3674 setSelectionProperty(tPtr
, NULL
, color
, -1);
3678 WMSetTextSelectionFont(WMText
*tPtr
, WMFont
*font
)
3683 setSelectionProperty(tPtr
, font
, NULL
, -1) ;
3687 WMSetTextSelectionUnderlined(WMText
*tPtr
, int underlined
)
3689 if (!tPtr
|| (underlined
!=0 && underlined
!=1))
3692 setSelectionProperty(tPtr
, NULL
, NULL
, underlined
);
3699 WMFreezeText(WMText
*tPtr
)
3704 tPtr
->flags
.frozen
= True
;
3709 WMThawText(WMText
*tPtr
)
3714 tPtr
->flags
.frozen
= False
;
3716 if(tPtr
->flags
.monoFont
) {
3717 int j
, c
= WMGetArrayItemCount(tPtr
->gfxItems
);
3720 /* make sure to unmap widgets no matter where they are */
3721 /* they'll be later remapped if needed by paintText */
3722 for(j
=0; j
<c
; j
++) {
3723 if ((tb
= (TextBlock
*) WMGetFromArray(tPtr
->gfxItems
, j
))) {
3724 if (tb
->object
&& ((W_VIEW(tb
->d
.widget
))->flags
.mapped
))
3725 WMUnmapWidget(tb
->d
.widget
);
3731 tPtr
->flags
.laidOut
= False
;
3732 layOutDocument(tPtr
);
3733 updateScrollers(tPtr
);
3735 tPtr
->flags
.needsLayOut
= False
;
3741 mystrrstr(char *haystack
, char *needle
, unsigned short len
, char *end
,
3746 if(!haystack
|| !needle
)
3749 for (ptr
= haystack
-2; ptr
> end
; ptr
--) {
3751 if (*ptr
== *needle
&& !strncmp(ptr
, needle
, len
))
3754 if (tolower(*ptr
) == tolower(*needle
) &&
3755 strncasecmp(ptr
, needle
, len
))
3765 WMFindInTextStream(WMText
*tPtr
, char *needle
, Bool direction
,
3772 if (!tPtr
|| !needle
)
3775 if (! (tb
= tPtr
->currentTextBlock
)) {
3776 if (! (tb
= ( (direction
> 0) ?
3777 tPtr
->firstTextBlock
: tPtr
->lastTextBlock
) ) ){
3781 /* if(tb != ((direction>0) ?tPtr->firstTextBlock : tPtr->lastTextBlock))
3782 tb = (direction>0) ? tb->next : tb->prior; */
3783 if(tb
!= tPtr
->lastTextBlock
)
3791 if(pos
+1 < tb
->used
)
3794 if(tb
->used
- pos
> 0 && pos
> 0) {
3795 char tmp
= tb
->text
[tb
->used
];
3796 tb
->text
[tb
->used
] = 0;
3798 output(&tb
->text
[pos
], tb
->used
- pos
);
3800 mark
= strstr(&tb
->text
[pos
], needle
);
3802 mark
= mystrrstr(&tb
->text
[pos
], needle
,
3803 strlen(needle
), tb
->text
, caseSensitive
);
3805 tb
->text
[tb
->used
] = tmp
;
3812 WMFont
*font
= tPtr
->flags
.monoFont
?tPtr
->dFont
:tb
->d
.font
;
3814 tPtr
->tpos
= (int)(mark
- tb
->text
);
3815 tPtr
->currentTextBlock
= tb
;
3816 updateCursorPosition(tPtr
);
3817 tPtr
->sel
.y
= tPtr
->cursor
.y
+5;
3818 tPtr
->sel
.h
= tPtr
->cursor
.h
-10;
3819 tPtr
->sel
.x
= tPtr
->cursor
.x
+1;
3820 tPtr
->sel
.w
= WMIN(WMWidthOfString(font
,
3821 &tb
->text
[tPtr
->tpos
], strlen(needle
)),
3822 tPtr
->docWidth
- tPtr
->sel
.x
);
3823 tPtr
->flags
.ownsSelection
= True
;
3830 tb
= (direction
>0) ? tb
->next
: tb
->prior
;