2 /* WINGs WMText: multi-line/font/color/graphic text widget, by Nwanua. */
6 #include <X11/keysym.h>
12 * - FIX wrap... long lines that don't fit are not char wrapped yet.
13 * - hrm... something to do with already having tbs...
14 * - selection code... selects can be funny if it crosses over. use rect?
15 * - also inspect behaviour for WACenter and WARight
16 * - FIX: graphix blocks MUST be skipped if monoFont even though they exist!
17 * - check if support for Horizontal Scroll is complete
18 * - assess danger of destroying widgets whose actions link to other pages
19 * - Tabs now are simply replaced by 4 spaces...
20 * - redo blink code to reduce paint event... use pixmap buffer...
21 * - add paragraph support (full) and '\n' code in getStream..
25 /* a Section is a section of a TextBlock that describes what parts
26 of a TextBlock has been laid out on which "line"...
27 o this greatly aids redraw, scroll and selection.
28 o this is created during layoutLine, but may be later modified.
29 o there may be many Sections per TextBlock, hence the array */
31 unsigned int x
, y
; /* where to draw it from */
32 unsigned short w
, h
; /* its width and height */
33 unsigned short begin
; /* where the layout begins */
34 unsigned short end
; /* where it ends */
35 unsigned short max_d
; /* a quick hack for layOut if(laidOut) */
36 unsigned short last
:1; /* is it the last section on a "line"? */
37 unsigned int _y
:31; /* the "line" it and other textblocks are on */
41 /* a TextBlock is a node in a doubly-linked list of TextBlocks containing:
42 o text for the block, color and font
43 o or a pointer to the pixmap
44 o OR a pointer to the widget and the (text) description for its graphic
47 typedef struct _TextBlock
{
48 struct _TextBlock
*next
; /* next text block in linked list */
49 struct _TextBlock
*prior
; /* prior text block in linked list */
51 char *text
; /* pointer to text (could be kanji) */
52 /* or to the object's description */
54 WMFont
*font
; /* the font */
55 WMWidget
*widget
; /* the embedded widget */
56 WMPixmap
*pixmap
; /* the pixmap */
57 } d
; /* description */
59 unsigned short used
; /* number of chars in this block */
60 unsigned short allocated
; /* size of allocation (in chars) */
61 WMColor
*color
; /* the color */
63 Section
*sections
; /* the region for layouts (a growable array) */
64 /* an _array_! of size _nsections_ */
66 unsigned short s_begin
; /* where the selection begins */
67 unsigned short s_end
; /* where it ends */
69 unsigned int first
:1; /* first TextBlock in paragraph */
70 unsigned int blank
:1; /* ie. blank paragraph */
71 unsigned int kanji
:1; /* is of 16-bit characters or not */
72 unsigned int graphic
:1; /* graphic or text: text=0 */
73 unsigned int object
:1; /* embedded object or pixmap */
74 unsigned int underlined
:1; /* underlined or not */
75 unsigned int selected
:1; /* selected or not */
76 unsigned int nsections
:8; /* over how many "lines" a TextBlock wraps */
77 int script
:8; /* script in points: negative for subscript */
78 unsigned int marginN
:8; /* which of the margins in the tPtr to use */
79 unsigned int nClicks
:2; /* single, double, triple clicks */
80 unsigned int RESERVED
:7;
84 /* I'm lazy: visible.h vs. visible.size.height :-) */
93 typedef struct W_Text
{
94 W_Class widgetClass
; /* the class number of this widget */
95 W_View
*view
; /* the view referring to this instance */
97 WMRuler
*ruler
; /* the ruler widget to manipulate paragraphs */
99 WMScroller
*vS
; /* the vertical scroller */
100 unsigned int vpos
; /* the current vertical position */
101 unsigned int prevVpos
; /* the previous vertical position */
103 WMScroller
*hS
; /* the horizontal scroller */
104 unsigned int hpos
; /* the current horizontal position */
105 unsigned int prevHpos
; /* the previous horizontal position */
107 WMFont
*dFont
; /* the default font */
108 WMColor
*dColor
; /* the default color */
109 WMPixmap
*dBulletPix
; /* the default pixmap for bullets */
111 GC bgGC
; /* the background GC to draw with */
112 GC fgGC
; /* the foreground GC to draw with */
113 Pixmap db
; /* the buffer on which to draw */
115 myRect visible
; /* the actual rectangle that can be drawn into */
116 myRect cursor
; /* the position and (height) of cursor */
117 myRect sel
; /* the selection rectangle */
119 WMPoint clicked
; /* where in the _document_ was clicked */
121 unsigned short tpos
; /* the position in the currentTextBlock */
122 unsigned short docWidth
; /* the width of the entire document */
123 unsigned int docHeight
; /* the height of the entire document */
125 TextBlock
*firstTextBlock
;
126 TextBlock
*lastTextBlock
;
127 TextBlock
*currentTextBlock
;
129 WMArray
*gfxItems
; /* a nice array of graphic items */
132 WMHandlerID timerID
; /* for nice twinky-winky */
137 WMTextDelegate
*delegate
;
140 WMRulerMargins
*margins
; /* an array of margins */
142 unsigned int nMargins
:7; /* the total number of margins in use */
144 unsigned int monoFont
:1; /* whether to ignore formats and graphic */
145 unsigned int focused
:1; /* whether this instance has input focus */
146 unsigned int editable
:1; /* "silly user, you can't edit me" */
147 unsigned int ownsSelection
:1; /* "I ownz the current selection!" */
148 unsigned int pointerGrabbed
:1;/* "heh, gib me pointer" */
149 unsigned int extendSelection
:1; /* shift-drag to select more regions */
151 unsigned int rulerShown
:1; /* whether the ruler is shown or not */
152 unsigned int frozen
:1; /* whether screen updates are to be made */
153 unsigned int cursorShown
:1; /* whether to show the cursor */
154 unsigned int acceptsGraphic
:1;/* accept graphic when dropped */
155 unsigned int horizOnDemand
:1;/* if a large image should appear*/
156 unsigned int needsLayOut
:1; /* in case of Append/Deletes */
157 unsigned int ignoreNewLine
:1;/* turn it into a ' ' in streams > 1 */
158 unsigned int indentNewLine
:1;/* add " " for a newline typed */
159 unsigned int laidOut
:1; /* have the TextBlocks all been laid out */
160 unsigned int waitingForSelection
:1; /* I don't wanna wait in vain... */
161 unsigned int prepend
:1; /* prepend=1, append=0 (for parsers) */
162 WMAlignment alignment
:2; /* the alignment for text */
163 WMReliefType relief
:3; /* the relief to display with */
164 unsigned int isOverGraphic
:2;/* the mouse is over a graphic */
165 unsigned int first
:1; /* for plain text parsing, newline? */
166 /* unsigned int RESERVED:1; */
171 #define NOTIFY(T,C,N,A) { WMNotification *notif = WMCreateNotification(N,T,A);\
172 if ((T)->delegate && (T)->delegate->C)\
173 (*(T)->delegate->C)((T)->delegate,notif);\
174 WMPostNotification(notif);\
175 WMReleaseNotification(notif);}
181 output(char *ptr
, int len
)
186 /* printf(" s is [%s] (%d)\n", s, strlen(s)); */
192 #define CURSOR_BLINK_ON_DELAY 600
193 #define CURSOR_BLINK_OFF_DELAY 400
196 static char *default_bullet
[] = {
198 " c None s None", ". c black",
199 "X c white", "o c #808080",
207 static void handleEvents(XEvent
*event
, void *data
);
208 static void layOutDocument(Text
*tPtr
);
209 static void updateScrollers(Text
*tPtr
);
213 getMarginNumber(Text
*tPtr
, WMRulerMargins
*margins
)
217 for(i
=0; i
< tPtr
->nMargins
; i
++) {
219 if(WMIsMarginEqualToMargin(&tPtr
->margins
[i
], margins
))
229 newMargin(Text
*tPtr
, WMRulerMargins
*margins
)
234 tPtr
->margins
[0].retainCount
++;
238 n
= getMarginNumber(tPtr
, margins
);
242 tPtr
->margins
= wrealloc(tPtr
->margins
,
243 (++tPtr
->nMargins
)*sizeof(WMRulerMargins
));
245 n
= tPtr
->nMargins
-1;
246 tPtr
->margins
[n
].left
= margins
->left
;
247 tPtr
->margins
[n
].first
= margins
->first
;
248 tPtr
->margins
[n
].body
= margins
->body
;
249 tPtr
->margins
[n
].right
= margins
->right
;
250 /* for each tab... */
251 tPtr
->margins
[n
].retainCount
= 1;
253 tPtr
->margins
[n
].retainCount
++;
260 sectionWasSelected(Text
*tPtr
, TextBlock
*tb
, XRectangle
*rect
, int s
)
262 unsigned short i
, w
, lw
, selected
= False
, extend
= False
;
266 /* if selection rectangle completely encloses the section */
267 if ((tb
->sections
[s
]._y
>= tPtr
->visible
.y
+ tPtr
->sel
.y
)
268 && (tb
->sections
[s
]._y
+ tb
->sections
[s
].h
269 <= tPtr
->visible
.y
+ tPtr
->sel
.y
+ tPtr
->sel
.h
) ) {
271 sel
.w
= tPtr
->visible
.w
;
272 selected
= extend
= True
;
274 /* or if it starts on a line and then goes further down */
275 } else if ((tb
->sections
[s
]._y
<= tPtr
->visible
.y
+ tPtr
->sel
.y
)
276 && (tb
->sections
[s
]._y
+ tb
->sections
[s
].h
277 <= tPtr
->visible
.y
+ tPtr
->sel
.y
+ tPtr
->sel
.h
)
278 && (tb
->sections
[s
]._y
+ tb
->sections
[s
].h
279 >= tPtr
->visible
.y
+ tPtr
->sel
.y
) ) {
280 sel
.x
= WMAX(tPtr
->sel
.x
, tPtr
->clicked
.x
);
281 sel
.w
= tPtr
->visible
.w
;
282 selected
= extend
= True
;
284 /* or if it begins before a line, but ends on it */
285 } else if ((tb
->sections
[s
]._y
>= tPtr
->visible
.y
+ tPtr
->sel
.y
)
286 && (tb
->sections
[s
]._y
+ tb
->sections
[s
].h
287 >= tPtr
->visible
.y
+ tPtr
->sel
.y
+ tPtr
->sel
.h
)
288 && (tb
->sections
[s
]._y
289 <= tPtr
->visible
.y
+ tPtr
->sel
.y
+ tPtr
->sel
.h
) ) {
291 if (1||tPtr
->sel
.x
+ tPtr
->sel
.w
> tPtr
->clicked
.x
)
292 sel
.w
= tPtr
->sel
.x
+ tPtr
->sel
.w
;
299 /* or if the selection rectangle lies entirely within a line */
300 } else if ((tb
->sections
[s
]._y
<= tPtr
->visible
.y
+ tPtr
->sel
.y
)
301 && (tPtr
->sel
.w
>= 2)
302 && (tb
->sections
[s
]._y
+ tb
->sections
[s
].h
303 >= tPtr
->visible
.y
+ tPtr
->sel
.y
+ tPtr
->sel
.h
) ) {
312 /* if not within (modified) selection rectangle */
313 if ( tb
->sections
[s
].x
> sel
.x
+ sel
.w
314 || tb
->sections
[s
].x
+ tb
->sections
[s
].w
< sel
.x
)
318 if ( tb
->sections
[s
].x
+ tb
->sections
[s
].w
<= sel
.x
+ sel
.w
319 && tb
->sections
[s
].x
>= sel
.x
) {
320 rect
->width
= tb
->sections
[s
].w
;
321 rect
->x
= tb
->sections
[s
].x
;
326 i
= tb
->sections
[s
].begin
;
329 if (0&& tb
->sections
[s
].x
>= sel
.x
) {
330 tb
->s_begin
= tb
->sections
[s
].begin
;
334 while (++i
<= tb
->sections
[s
].end
) {
336 w
= WMWidthOfString(tb
->d
.font
, &(tb
->text
[i
-1]), 1);
339 if (lw
+ tb
->sections
[s
].x
>= sel
.x
340 || i
== tb
->sections
[s
].end
) {
343 tb
->s_begin
= (tb
->selected
? WMIN(tb
->s_begin
, i
) : i
);
348 if (i
> tb
->sections
[s
].end
) {
349 printf("WasSelected: (i > tb->sections[s].end) \n");
353 _selEnd
: rect
->x
= tb
->sections
[s
].x
+ lw
;
355 while(++i
<= tb
->sections
[s
].end
) {
357 w
= WMWidthOfString(tb
->d
.font
, &(tb
->text
[i
-1]), 1);
360 if (lw
+ rect
->x
>= sel
.x
+ sel
.w
361 || i
== tb
->sections
[s
].end
) {
363 if (i
!= tb
->sections
[s
].end
) {
369 if (tb
->sections
[s
].last
&& sel
.x
+ sel
.w
370 >= tb
->sections
[s
].x
+ tb
->sections
[s
].w
372 rect
->width
+= (tPtr
->visible
.w
- rect
->x
- lw
);
375 tb
->s_end
= (tb
->selected
? WMAX(tb
->s_end
, i
) : i
);
381 rect
->y
= tb
->sections
[s
]._y
- tPtr
->vpos
;
382 rect
->height
= tb
->sections
[s
].h
;
383 if(tb
->graphic
) { printf("graphic s%d h%d\n", s
,tb
->sections
[s
].h
);}
390 setSelectionProperty(WMText
*tPtr
, WMFont
*font
, WMColor
*color
, int underlined
)
395 tb
= tPtr
->firstTextBlock
;
396 if (!tb
|| !tPtr
->flags
.ownsSelection
)
399 if(font
&& (!color
|| underlined
==-1))
403 if (tPtr
->flags
.monoFont
|| tb
->selected
) {
405 if (tPtr
->flags
.monoFont
|| (tb
->s_end
- tb
->s_begin
== tb
->used
)
410 WMReleaseFont(tb
->d
.font
);
411 tb
->d
.font
= WMRetainFont(font
);
413 } else if(underlined
!=-1) {
414 tb
->underlined
= underlined
;
416 WMReleaseColor(tb
->color
);
417 tb
->color
= WMRetainColor(color
);
420 } else if (tb
->s_end
<= tb
->used
&& tb
->s_begin
< tb
->s_end
) {
422 TextBlock
*midtb
, *otb
= tb
;
424 if(underlined
!= -1) {
425 midtb
= (TextBlock
*) WMCreateTextBlockWithText(tPtr
,
426 &(tb
->text
[tb
->s_begin
]), tb
->d
.font
, tb
->color
,
427 False
, (tb
->s_end
- tb
->s_begin
));
429 midtb
= (TextBlock
*) WMCreateTextBlockWithText(tPtr
,
430 &(tb
->text
[tb
->s_begin
]),
431 (isFont
?font
:tb
->d
.font
),
432 (isFont
?tb
->color
:color
),
433 False
, (tb
->s_end
- tb
->s_begin
));
438 if(underlined
!= -1) {
439 midtb
->underlined
= underlined
;
441 midtb
->underlined
= otb
->underlined
;
444 midtb
->selected
= !True
;
446 midtb
->s_end
= midtb
->used
;
447 tPtr
->currentTextBlock
= tb
;
448 WMAppendTextBlock(tPtr
, midtb
);
449 tb
= tPtr
->currentTextBlock
;
452 if (otb
->used
- otb
->s_end
> 0) {
455 WMCreateTextBlockWithText(tPtr
,
456 &(otb
->text
[otb
->s_end
]), otb
->d
.font
, otb
->color
,
457 False
, otb
->used
- otb
->s_end
);
460 ntb
->underlined
= otb
->underlined
;
461 ntb
->selected
= False
;
462 WMAppendTextBlock(tPtr
, ntb
);
463 tb
= tPtr
->currentTextBlock
;
468 tPtr
->currentTextBlock
= midtb
;
471 otb
->selected
= False
;
472 otb
->used
= otb
->s_begin
;
479 tPtr
->flags
.needsLayOut
= True
;
482 /* in case the size changed... */
483 if(isFont
&& tPtr
->currentTextBlock
) {
484 TextBlock
*tb
= tPtr
->currentTextBlock
;
486 printf("%d %d %d\n", tPtr
->sel
.y
, tPtr
->sel
.h
, tPtr
->sel
.w
);
487 tPtr
->sel
.y
= 3 + tb
->sections
[0]._y
;
488 tPtr
->sel
.h
= tb
->sections
[tb
->nsections
-1]._y
- tb
->sections
[0]._y
;
489 tPtr
->sel
.w
= tb
->sections
[tb
->nsections
-1].w
;
490 if(tb
->sections
[tb
->nsections
-1]._y
!= tb
->sections
[0]._y
) {
493 printf("%d %d %d\n\n\n", tPtr
->sel
.y
, tPtr
->sel
.h
, tPtr
->sel
.w
);
500 removeSelection(Text
*tPtr
)
502 TextBlock
*tb
= NULL
;
505 if (!(tb
= tPtr
->firstTextBlock
))
510 if(!first
&& !tb
->graphic
) {
511 WMReleaseFont(tPtr
->dFont
);
512 tPtr
->dFont
= WMRetainFont(tb
->d
.font
);
516 if ( (tb
->s_end
- tb
->s_begin
== tb
->used
) || tb
->graphic
) {
517 tPtr
->currentTextBlock
= tb
;
518 WMDestroyTextBlock(tPtr
, WMRemoveTextBlock(tPtr
));
519 tb
= tPtr
->currentTextBlock
;
524 } else if (tb
->s_end
<= tb
->used
) {
525 memmove(&(tb
->text
[tb
->s_begin
]),
526 &(tb
->text
[tb
->s_end
]), tb
->used
- tb
->s_end
);
527 tb
->used
-= (tb
->s_end
- tb
->s_begin
);
528 tb
->selected
= False
;
529 tPtr
->tpos
= tb
->s_begin
;
540 getFirstNonGraphicBlockFor(TextBlock
*tb
, short dir
)
542 TextBlock
*hold
= tb
;
550 tb
= (dir
? tb
->next
: tb
->prior
);
558 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
);
579 tPtr
->currentTextBlock
=
580 (dir
? tPtr
->lastTextBlock
: tPtr
->firstTextBlock
);
586 *dir
= !(y
<= tb
->sections
[0].y
);
588 if ( ( y
<= tb
->sections
[0]._y
+ tb
->sections
[0].h
)
589 && (y
>= tb
->sections
[0]._y
) ) {
590 /* if it's on the same line */
591 if(x
< tb
->sections
[0].x
)
595 if ( ( y
<= tb
->sections
[tb
->nsections
-1]._y
596 + tb
->sections
[tb
->nsections
-1].h
)
597 && (y
>= tb
->sections
[tb
->nsections
-1]._y
) ) {
598 /* if it's on the same line */
599 if(x
> tb
->sections
[tb
->nsections
-1].x
)
609 paintText(Text
*tPtr
)
615 int len
, y
, c
, s
, done
=False
, prev_y
=-23, dir
/* 1 = down */;
616 WMScreen
*scr
= tPtr
->view
->screen
;
617 Display
*dpy
= tPtr
->view
->screen
->display
;
618 Window win
= tPtr
->view
->window
;
620 if (!tPtr
->view
->flags
.realized
|| !tPtr
->db
|| tPtr
->flags
.frozen
)
623 XFillRectangle(dpy
, tPtr
->db
, tPtr
->bgGC
,
624 0, 0, tPtr
->visible
.w
, tPtr
->visible
.h
);
626 if (! (tb
= tPtr
->currentTextBlock
)) {
627 if (! (tb
= tPtr
->firstTextBlock
)) {
632 if (tPtr
->flags
.ownsSelection
)
633 greyGC
= WMColorGC(WMGrayColor(scr
));
639 /* first, which direction? Don't waste time looking all over,
640 since the parts to be drawn will most likely be near what
641 was previously drawn */
642 if(!updateStartForCurrentTextBlock(tPtr
, 0, tPtr
->vpos
, &dir
, tb
))
647 if (tb
->graphic
&& tPtr
->flags
.monoFont
)
651 if(tPtr
->vpos
<= tb
->sections
[tb
->nsections
-1]._y
652 + tb
->sections
[tb
->nsections
-1].h
)
655 if(tPtr
->vpos
>= tb
->sections
[tb
->nsections
-1]._y
656 + tb
->sections
[tb
->nsections
-1].h
)
673 /* first, place all text that can be viewed */
674 while (!done
&& tb
) {
676 /* paragraph diagnostic
677 if(tb->blank) {tb->text[0] = 'F'; } */
684 tb
->selected
= False
;
686 for(s
=0; s
<tb
->nsections
&& !done
; s
++) {
688 if (tb
->sections
[s
]._y
> tPtr
->vpos
+ tPtr
->visible
.h
) {
693 if ( tb
->sections
[s
].y
+ tb
->sections
[s
].h
< tPtr
->vpos
)
696 if (tPtr
->flags
.monoFont
) {
701 gc
= WMColorGC(tb
->color
);
704 if (tPtr
->flags
.ownsSelection
) {
707 if ( sectionWasSelected(tPtr
, tb
, &rect
, s
)) {
709 XFillRectangle(dpy
, tPtr
->db
, greyGC
,
710 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
714 prev_y
= tb
->sections
[s
]._y
;
716 len
= tb
->sections
[s
].end
- tb
->sections
[s
].begin
;
717 text
= &(tb
->text
[tb
->sections
[s
].begin
]);
718 y
= tb
->sections
[s
].y
- tPtr
->vpos
;
719 WMDrawString(scr
, tPtr
->db
, gc
, font
,
720 tb
->sections
[s
].x
- tPtr
->hpos
, y
, text
, len
);
722 if (!tPtr
->flags
.monoFont
&& tb
->underlined
) {
723 XDrawLine(dpy
, tPtr
->db
, gc
,
724 tb
->sections
[s
].x
- tPtr
->hpos
,
726 tb
->sections
[s
].x
+ tb
->sections
[s
].w
- tPtr
->hpos
,
732 tb
= (!done
? tb
->next
: NULL
);
736 /* now , show all graphic items that can be viewed */
737 c
= WMGetArrayItemCount(tPtr
->gfxItems
);
738 if (c
> 0 && !tPtr
->flags
.monoFont
) {
742 tb
= (TextBlock
*) WMGetFromArray(tPtr
->gfxItems
, j
);
744 /* if it's not viewable, and mapped, unmap it */
745 if (tb
->sections
[0]._y
+ tb
->sections
[0].h
<= tPtr
->vpos
746 || tb
->sections
[0]._y
>= tPtr
->vpos
+ tPtr
->visible
.h
) {
749 if ((W_VIEW(tb
->d
.widget
))->flags
.mapped
) {
750 WMUnmapWidget(tb
->d
.widget
);
754 /* if it's viewable, and not mapped, map it */
756 W_View
*view
= W_VIEW(tb
->d
.widget
);
758 if (!view
->flags
.realized
)
759 WMRealizeWidget(tb
->d
.widget
);
760 if(!view
->flags
.mapped
) {
761 XMapWindow(view
->screen
->display
, view
->window
);
762 XFlush(view
->screen
->display
);
763 view
->flags
.mapped
= 1;
767 if (tPtr
->flags
.ownsSelection
) {
770 if ( sectionWasSelected(tPtr
, tb
, &rect
, 0)) {
772 XFillRectangle(dpy
, tPtr
->db
, greyGC
,
773 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
778 WMMoveWidget(tb
->d
.widget
,
779 tb
->sections
[0].x
+ tPtr
->visible
.x
- tPtr
->hpos
,
780 tb
->sections
[0].y
+ tPtr
->visible
.y
- tPtr
->vpos
);
781 h
= WMWidgetHeight(tb
->d
.widget
) + 1;
784 WMDrawPixmap(tb
->d
.pixmap
, tPtr
->db
,
785 tb
->sections
[0].x
- tPtr
->hpos
,
786 tb
->sections
[0].y
- tPtr
->vpos
);
787 h
= tb
->d
.pixmap
->height
+ 1;
791 if (!tPtr
->flags
.monoFont
&& tb
->underlined
) {
792 XDrawLine(dpy
, tPtr
->db
, WMColorGC(tb
->color
),
793 tb
->sections
[0].x
- tPtr
->hpos
,
794 tb
->sections
[0].y
+ h
- tPtr
->vpos
,
795 tb
->sections
[0].x
+ tb
->sections
[0].w
- tPtr
->hpos
,
796 tb
->sections
[0].y
+ h
- tPtr
->vpos
);
801 if (tPtr
->flags
.editable
&& tPtr
->flags
.cursorShown
802 && tPtr
->cursor
.x
!= -23 && tPtr
->flags
.focused
) {
803 int y
= tPtr
->cursor
.y
- tPtr
->vpos
;
804 XDrawLine(dpy
, tPtr
->db
, tPtr
->fgGC
,
806 tPtr
->cursor
.x
, y
+ tPtr
->cursor
.h
);
809 XCopyArea(dpy
, tPtr
->db
, win
, tPtr
->bgGC
, 0, 0,
810 tPtr
->visible
.w
, tPtr
->visible
.h
,
811 tPtr
->visible
.x
, tPtr
->visible
.y
);
813 W_DrawRelief(scr
, win
, 0, 0,
814 tPtr
->view
->size
.width
, tPtr
->view
->size
.height
,
817 if (tPtr
->ruler
&& tPtr
->flags
.rulerShown
)
818 XDrawLine(dpy
, win
, tPtr
->fgGC
,
819 2, 42, tPtr
->view
->size
.width
-4, 42);
824 mouseOverObject(Text
*tPtr
, int x
, int y
)
829 x
-= tPtr
->visible
.x
;
831 y
-= tPtr
->visible
.y
;
834 if(tPtr
->flags
.ownsSelection
) {
837 && tPtr
->sel
.x
+ tPtr
->sel
.w
>= x
838 && tPtr
->sel
.y
+ tPtr
->sel
.h
>= y
) {
839 tPtr
->flags
.isOverGraphic
= 1;
846 int j
, c
= WMGetArrayItemCount(tPtr
->gfxItems
);
849 tPtr
->flags
.isOverGraphic
= 0;
853 tb
= (TextBlock
*) WMGetFromArray(tPtr
->gfxItems
, j
);
855 if(!tb
|| !tb
->sections
) {
856 tPtr
->flags
.isOverGraphic
= 0;
861 if(tb
->sections
[0].x
<= x
862 && tb
->sections
[0].y
<= y
863 && tb
->sections
[0].x
+ tb
->sections
[0].w
>= x
864 && tb
->sections
[0].y
+ tb
->d
.pixmap
->height
>= y
) {
865 tPtr
->flags
.isOverGraphic
= 3;
876 tPtr
->flags
.isOverGraphic
= 0;
879 tPtr
->view
->attribs
.cursor
= (result
?
880 tPtr
->view
->screen
->defaultCursor
881 : tPtr
->view
->screen
->textCursor
);
883 XSetWindowAttributes attribs
;
884 attribs
.cursor
= tPtr
->view
->attribs
.cursor
;
885 XChangeWindowAttributes(tPtr
->view
->screen
->display
,
886 tPtr
->view
->window
, CWCursor
,
894 blinkCursor(void *data
)
896 Text
*tPtr
= (Text
*)data
;
898 if (tPtr
->flags
.cursorShown
) {
899 tPtr
->timerID
= WMAddTimerHandler(CURSOR_BLINK_OFF_DELAY
,
902 tPtr
->timerID
= WMAddTimerHandler(CURSOR_BLINK_ON_DELAY
,
906 tPtr
->flags
.cursorShown
= !tPtr
->flags
.cursorShown
;
911 updateCursorPosition(Text
*tPtr
)
913 TextBlock
*tb
= NULL
;
916 if(tPtr
->flags
.needsLayOut
)
917 layOutDocument(tPtr
);
919 if (! (tb
= tPtr
->currentTextBlock
)) {
920 if (! (tb
= tPtr
->firstTextBlock
)) {
922 tPtr
->cursor
.h
= tPtr
->dFont
->height
;
932 y
= tb
->sections
[0].y
;
933 h
= tb
->sections
[0].h
;
934 x
= tb
->sections
[0].x
;
936 } else if(tb
->graphic
) {
937 y
= tb
->sections
[0].y
;
938 h
= tb
->sections
[0].h
;
939 x
= tb
->sections
[0].x
;
942 if(tPtr
->tpos
> tb
->used
)
943 tPtr
->tpos
= tb
->used
;
945 for(s
=0; s
<tb
->nsections
-1; s
++) {
947 if(tPtr
->tpos
>= tb
->sections
[s
].begin
948 && tPtr
->tpos
<= tb
->sections
[s
].end
)
952 y
= tb
->sections
[s
]._y
;
953 h
= tb
->sections
[s
].h
;
954 x
= tb
->sections
[s
].x
+ WMWidthOfString(
955 (tPtr
->flags
.monoFont
?tPtr
->dFont
:tb
->d
.font
),
956 &tb
->text
[tb
->sections
[s
].begin
],
957 tPtr
->tpos
- tb
->sections
[s
].begin
);
965 /* scroll the bars if the cursor is not visible */
966 if(tPtr
->flags
.editable
&& tPtr
->cursor
.x
!= -23) {
967 if(tPtr
->cursor
.y
+tPtr
->cursor
.h
968 > tPtr
->vpos
+tPtr
->visible
.y
+tPtr
->visible
.h
) {
970 (tPtr
->cursor
.y
+tPtr
->cursor
.h
+10
971 - (tPtr
->vpos
+tPtr
->visible
.y
+tPtr
->visible
.h
));
972 } else if(tPtr
->cursor
.y
< tPtr
->vpos
+tPtr
->visible
.y
) {
973 tPtr
->vpos
-= (tPtr
->vpos
+tPtr
->visible
.y
-tPtr
->cursor
.y
);
978 updateScrollers(tPtr
);
983 cursorToTextPosition(Text
*tPtr
, int x
, int y
)
985 TextBlock
*tb
= NULL
;
986 int done
=False
, s
, pos
, len
, _w
, _y
, dir
=1; /* 1 == "down" */
989 if(tPtr
->flags
.needsLayOut
)
990 layOutDocument(tPtr
);
992 y
+= (tPtr
->vpos
- tPtr
->visible
.y
);
996 x
-= (tPtr
->visible
.x
- 2);
1000 /* clicked is relative to document, not window... */
1001 tPtr
->clicked
.x
= x
;
1002 tPtr
->clicked
.y
= y
;
1004 if (! (tb
= tPtr
->currentTextBlock
)) {
1005 if (! (tb
= tPtr
->firstTextBlock
)) {
1007 tPtr
->cursor
.h
= tPtr
->dFont
->height
;
1014 /* first, which direction? Most likely, newly clicked
1015 position will be close to previous */
1016 if(!updateStartForCurrentTextBlock(tPtr
, x
, y
, &dir
, tb
))
1020 s
= (dir
? 0 : tb
->nsections
-1);
1021 if ( y
>= tb
->sections
[s
]._y
1022 && y
<= tb
->sections
[s
]._y
+ tb
->sections
[s
].h
) {
1026 /* get the first (or last) section of the TextBlock that
1027 lies about the vertical click point */
1029 while (!done
&& tb
) {
1031 if (tPtr
->flags
.monoFont
&& tb
->graphic
) {
1032 if( (dir
?tb
->next
:tb
->prior
))
1033 tb
= (dir
?tb
->next
:tb
->prior
);
1037 s
= (dir
? 0 : tb
->nsections
-1);
1038 while (!done
&& (dir
? (s
<tb
->nsections
) : (s
>=0) )) {
1040 if ( (dir
? (y
<= tb
->sections
[s
]._y
+ tb
->sections
[s
].h
) :
1041 ( y
>= tb
->sections
[s
]._y
) ) ) {
1049 if ( (dir
? tb
->next
: tb
->prior
)) {
1050 tb
= (dir
? tb
->next
: tb
->prior
);
1053 break; /* goto _doneH; */
1059 if (s
<0 || s
>=tb
->nsections
) {
1060 s
= (dir
? tb
->nsections
-1 : 0);
1064 /* we have the line, which TextBlock on that line is it? */
1065 pos
= (dir
?0:tb
->sections
[s
].begin
);
1066 if (tPtr
->flags
.monoFont
&& tb
->graphic
) {
1067 TextBlock
*hold
= tb
;
1068 tb
= getFirstNonGraphicBlockFor(hold
, dir
);
1082 _y
= tb
->sections
[s
]._y
;
1086 if (tPtr
->flags
.monoFont
&& tb
->graphic
) {
1087 tb
= (dir
? tb
->next
: tb
->prior
);
1094 _w
= WMWidgetWidth(tb
->d
.widget
)-5;
1096 _w
= tb
->d
.pixmap
->width
-5;
1098 text
= &(tb
->text
[tb
->sections
[s
].begin
]);
1099 len
= tb
->sections
[s
].end
- tb
->sections
[s
].begin
;
1100 _w
= WMWidthOfString(tb
->d
.font
, text
, len
);
1101 if (tb
->sections
[s
].x
+ _w
>= x
)
1106 if (tb
->sections
[s
].x
<= x
)
1110 if ((dir
? tb
->next
: tb
->prior
)) {
1111 TextBlock
*nxt
= (dir
? tb
->next
: tb
->prior
);
1112 if (tPtr
->flags
.monoFont
&& nxt
->graphic
) {
1113 nxt
= getFirstNonGraphicBlockFor(nxt
, dir
);
1115 pos
= (dir
?0:tb
->sections
[s
].begin
);
1116 tPtr
->cursor
.x
= tb
->sections
[s
].x
;
1121 if (_y
!= nxt
->sections
[dir
?0:nxt
->nsections
-1]._y
) {
1122 /* this must be the last/first on this line. stop */
1123 pos
= (dir
? tb
->sections
[s
].end
: 0);
1124 tPtr
->cursor
.x
= tb
->sections
[s
].x
;
1128 tPtr
->cursor
.x
+= WMWidgetWidth(tb
->d
.widget
);
1130 tPtr
->cursor
.x
+= tb
->d
.pixmap
->width
;
1131 } else if (pos
> tb
->sections
[s
].begin
) {
1133 WMWidthOfString(tb
->d
.font
,
1134 &(tb
->text
[tb
->sections
[s
].begin
]),
1135 pos
- tb
->sections
[s
].begin
);
1142 if ( (dir
? tb
->next
: tb
->prior
)) {
1143 tb
= (dir
? tb
->next
: tb
->prior
);
1150 s
= (dir
? 0 : tb
->nsections
-1);
1153 /* we have said TextBlock, now where within it? */
1154 if (tb
&& !tb
->graphic
) {
1155 WMFont
*f
= tb
->d
.font
;
1156 len
= tb
->sections
[s
].end
- tb
->sections
[s
].begin
;
1157 text
= &(tb
->text
[tb
->sections
[s
].begin
]);
1159 _w
= x
- tb
->sections
[s
].x
;
1162 while (pos
<len
&& WMWidthOfString(f
, text
, pos
+1) < _w
)
1165 tPtr
->cursor
.x
= tb
->sections
[s
].x
+
1166 (pos
? WMWidthOfString(f
, text
, pos
) : 0);
1168 pos
+= tb
->sections
[s
].begin
;
1170 tPtr
->tpos
= (pos
<tb
->used
)? pos
: tb
->used
;
1175 printf("...for this app will surely crash :-)\n");
1177 tPtr
->currentTextBlock
= tb
;
1178 tPtr
->cursor
.h
= tb
->sections
[s
].h
;
1179 tPtr
->cursor
.y
= tb
->sections
[s
]._y
;
1181 /* scroll the bars if the cursor is not visible */
1182 if(tPtr
->flags
.editable
&& tPtr
->cursor
.x
!= -23) {
1183 if(tPtr
->cursor
.y
+tPtr
->cursor
.h
1184 > tPtr
->vpos
+tPtr
->visible
.y
+tPtr
->visible
.h
) {
1186 (tPtr
->cursor
.y
+tPtr
->cursor
.h
+10
1187 - (tPtr
->vpos
+tPtr
->visible
.y
+tPtr
->visible
.h
));
1188 updateScrollers(tPtr
);
1189 } else if(tPtr
->cursor
.y
< tPtr
->vpos
+tPtr
->visible
.y
) {
1190 tPtr
->vpos
-= (tPtr
->vpos
+tPtr
->visible
.y
-tPtr
->cursor
.y
);
1191 updateScrollers(tPtr
);
1199 autoSelectText(Text
*tPtr
, int clicks
)
1203 char *mark
= NULL
, behind
, ahead
;
1205 if(!(tb
= tPtr
->currentTextBlock
))
1211 switch(tb
->text
[tPtr
->tpos
]) {
1214 case '<': case '>': behind = '<'; ahead = '>'; break;
1215 case '{': case '}': behind = '{'; ahead = '}'; break;
1216 case '[': case ']': behind = '['; ahead = ']'; break;
1218 default: behind
= ahead
= ' ';
1221 tPtr
->sel
.y
= tPtr
->cursor
.y
+5;
1222 tPtr
->sel
.h
= 6;/*tPtr->cursor.h-10;*/
1225 tPtr
->sel
.x
= tb
->sections
[0].x
;
1226 tPtr
->sel
.w
= tb
->sections
[0].w
;
1228 WMFont
*font
= tPtr
->flags
.monoFont
?tPtr
->dFont
:tb
->d
.font
;
1231 while(start
> 0 && tb
->text
[start
-1] != behind
)
1235 if(tPtr
->tpos
> start
){
1236 x
-= WMWidthOfString(font
, &tb
->text
[start
],
1237 tPtr
->tpos
- start
);
1239 tPtr
->sel
.x
= (x
<0?0:x
)+1;
1241 if((mark
= strchr(&tb
->text
[start
], ahead
))) {
1242 tPtr
->sel
.w
= WMWidthOfString(font
, &tb
->text
[start
],
1243 (int)(mark
- &tb
->text
[start
]));
1244 } else if(tb
->used
> start
) {
1245 tPtr
->sel
.w
= WMWidthOfString(font
, &tb
->text
[start
],
1250 } else if(clicks
== 3) {
1251 TextBlock
*cur
= tb
;
1253 while(tb
&& !tb
->first
) {
1256 tPtr
->sel
.y
= tb
->sections
[0]._y
;
1259 while(tb
->next
&& !tb
->next
->first
) {
1262 tPtr
->sel
.h
= tb
->sections
[tb
->nsections
-1]._y
1266 tPtr
->sel
.w
= tPtr
->docWidth
;
1267 tPtr
->clicked
.x
= 0; /* only for now, fix sel. code */
1270 tPtr
->flags
.ownsSelection
= True
;
1277 updateScrollers(Text
*tPtr
)
1280 if (tPtr
->flags
.frozen
)
1284 if (tPtr
->docHeight
< tPtr
->visible
.h
) {
1285 WMSetScrollerParameters(tPtr
->vS
, 0, 1);
1288 float hmax
= (float)(tPtr
->docHeight
);
1289 WMSetScrollerParameters(tPtr
->vS
,
1290 ((float)tPtr
->vpos
)/(hmax
- (float)tPtr
->visible
.h
),
1291 (float)tPtr
->visible
.h
/hmax
);
1293 } else tPtr
->vpos
= 0;
1296 if (tPtr
->docWidth
< tPtr
->visible
.w
) {
1297 WMSetScrollerParameters(tPtr
->hS
, 0, 1);
1300 float wmax
= (float)(tPtr
->docWidth
);
1301 WMSetScrollerParameters(tPtr
->hS
,
1302 ((float)tPtr
->hpos
)/(wmax
- (float)tPtr
->visible
.w
),
1303 (float)tPtr
->visible
.w
/wmax
);
1305 } else tPtr
->hpos
= 0;
1309 scrollersCallBack(WMWidget
*w
, void *self
)
1311 Text
*tPtr
= (Text
*)self
;
1312 Bool scroll
= False
;
1315 if (!tPtr
->view
->flags
.realized
|| tPtr
->flags
.frozen
)
1318 if (w
== tPtr
->vS
) {
1320 height
= tPtr
->visible
.h
;
1322 which
= WMGetScrollerHitPart(tPtr
->vS
);
1325 case WSDecrementLine
:
1326 if (tPtr
->vpos
> 0) {
1327 if (tPtr
->vpos
>16) tPtr
->vpos
-=16;
1333 case WSIncrementLine
: {
1334 int limit
= tPtr
->docHeight
- height
;
1335 if (tPtr
->vpos
< limit
) {
1336 if (tPtr
->vpos
<limit
-16) tPtr
->vpos
+=16;
1337 else tPtr
->vpos
=limit
;
1343 case WSDecrementPage
:
1344 if(((int)tPtr
->vpos
- (int)height
) >= 0)
1345 tPtr
->vpos
-= height
;
1352 case WSIncrementPage
:
1353 tPtr
->vpos
+= height
;
1354 if (tPtr
->vpos
> (tPtr
->docHeight
- height
))
1355 tPtr
->vpos
= tPtr
->docHeight
- height
;
1361 tPtr
->vpos
= WMGetScrollerValue(tPtr
->vS
)
1362 * (float)(tPtr
->docHeight
- height
);
1370 scroll
= (tPtr
->vpos
!= tPtr
->prevVpos
);
1371 tPtr
->prevVpos
= tPtr
->vpos
;
1375 if (w
== tPtr
->hS
) {
1376 int width
= tPtr
->visible
.w
;
1378 which
= WMGetScrollerHitPart(tPtr
->hS
);
1381 case WSDecrementLine
:
1382 if (tPtr
->hpos
> 0) {
1383 if (tPtr
->hpos
>16) tPtr
->hpos
-=16;
1388 case WSIncrementLine
: {
1389 int limit
= tPtr
->docWidth
- width
;
1390 if (tPtr
->hpos
< limit
) {
1391 if (tPtr
->hpos
<limit
-16) tPtr
->hpos
+=16;
1392 else tPtr
->hpos
=limit
;
1396 case WSDecrementPage
:
1397 if(((int)tPtr
->hpos
- (int)width
) >= 0)
1398 tPtr
->hpos
-= width
;
1405 case WSIncrementPage
:
1406 tPtr
->hpos
+= width
;
1407 if (tPtr
->hpos
> (tPtr
->docWidth
- width
))
1408 tPtr
->hpos
= tPtr
->docWidth
- width
;
1414 tPtr
->hpos
= WMGetScrollerValue(tPtr
->hS
)
1415 * (float)(tPtr
->docWidth
- width
);
1423 scroll
= (tPtr
->hpos
!= tPtr
->prevHpos
);
1424 tPtr
->prevHpos
= tPtr
->hpos
;
1428 updateScrollers(tPtr
);
1437 unsigned short begin
, end
; /* what part of the text block */
1442 layOutLine(Text
*tPtr
, myLineItems
*items
, int nitems
, int x
, int y
)
1444 int i
, j
=0, lw
= 0, line_height
=0, max_d
=0, len
, n
;
1447 TextBlock
*tb
, *tbsame
=NULL
;
1449 if(!items
|| nitems
== 0)
1452 for(i
=0; i
<nitems
; i
++) {
1456 if (!tPtr
->flags
.monoFont
) {
1458 WMWidget
*wdt
= tb
->d
.widget
;
1459 line_height
= WMAX(line_height
, WMWidgetHeight(wdt
));
1460 if (tPtr
->flags
.alignment
!= WALeft
)
1461 lw
+= WMWidgetWidth(wdt
);
1463 line_height
= WMAX(line_height
,
1464 tb
->d
.pixmap
->height
+ max_d
);
1465 if (tPtr
->flags
.alignment
!= WALeft
)
1466 lw
+= tb
->d
.pixmap
->width
;
1471 font
= (tPtr
->flags
.monoFont
)?tPtr
->dFont
: tb
->d
.font
;
1472 max_d
= WMAX(max_d
, abs(font
->height
-font
->y
));
1473 line_height
= WMAX(line_height
, font
->height
+ max_d
);
1474 text
= &(tb
->text
[items
[i
].begin
]);
1475 len
= items
[i
].end
- items
[i
].begin
;
1476 if (tPtr
->flags
.alignment
!= WALeft
)
1477 lw
+= WMWidthOfString(font
, text
, len
);
1481 if (tPtr
->flags
.alignment
== WARight
) {
1482 j
= tPtr
->visible
.w
- lw
;
1483 } else if (tPtr
->flags
.alignment
== WACenter
) {
1484 j
= (int) ((float)(tPtr
->visible
.w
- lw
))/2.0;
1487 for(i
=0; i
<nitems
; i
++) {
1490 if (tbsame
== tb
) { /* extend it, since it's on same line */
1491 tb
->sections
[tb
->nsections
-1].end
= items
[i
].end
;
1492 n
= tb
->nsections
-1;
1494 tb
->sections
= wrealloc(tb
->sections
,
1495 (++tb
->nsections
)*sizeof(Section
));
1496 n
= tb
->nsections
-1;
1497 tb
->sections
[n
]._y
= y
+ max_d
;
1498 tb
->sections
[n
].max_d
= max_d
;
1499 tb
->sections
[n
].x
= x
+j
;
1500 tb
->sections
[n
].h
= line_height
;
1501 tb
->sections
[n
].begin
= items
[i
].begin
;
1502 tb
->sections
[n
].end
= items
[i
].end
;
1505 tb
->sections
[n
].last
= (i
+1 == nitems
);
1508 if (!tPtr
->flags
.monoFont
) {
1510 WMWidget
*wdt
= tb
->d
.widget
;
1511 tb
->sections
[n
].y
= max_d
+ y
1512 + line_height
- WMWidgetHeight(wdt
);
1513 tb
->sections
[n
].w
= WMWidgetWidth(wdt
);
1515 tb
->sections
[n
].y
= y
+ line_height
1516 + max_d
- tb
->d
.pixmap
->height
;
1517 tb
->sections
[n
].w
= tb
->d
.pixmap
->width
;
1519 x
+= tb
->sections
[n
].w
;
1522 font
= (tPtr
->flags
.monoFont
)? tPtr
->dFont
: tb
->d
.font
;
1523 len
= items
[i
].end
- items
[i
].begin
;
1524 text
= &(tb
->text
[items
[i
].begin
]);
1526 tb
->sections
[n
].y
= y
+line_height
-font
->y
;
1528 WMWidthOfString(font
,
1529 &(tb
->text
[tb
->sections
[n
].begin
]),
1530 tb
->sections
[n
].end
- tb
->sections
[n
].begin
);
1532 x
+= WMWidthOfString(font
, text
, len
);
1544 layOutDocument(Text
*tPtr
)
1547 myLineItems
*items
= NULL
;
1548 unsigned int itemsSize
=0, nitems
=0, begin
, end
;
1550 unsigned int x
, y
=0, lw
= 0, width
=0, bmargin
;
1551 char *start
=NULL
, *mark
=NULL
;
1553 if ( tPtr
->flags
.frozen
|| (!(tb
= tPtr
->firstTextBlock
)) )
1556 tPtr
->docWidth
= tPtr
->visible
.w
;
1557 x
= tPtr
->margins
[tb
->marginN
].first
;
1558 bmargin
= tPtr
->margins
[tb
->marginN
].body
;
1560 /* only partial layOut needed: re-Lay only affected textblocks */
1561 if (tPtr
->flags
.laidOut
) {
1562 tb
= tPtr
->currentTextBlock
;
1564 /* search backwards for textblocks on same line */
1566 if (!tb
->sections
|| tb
->nsections
<1) {
1567 tb
= tPtr
->firstTextBlock
;
1568 tPtr
->flags
.laidOut
= False
;
1573 if(!tb
->prior
->sections
|| tb
->prior
->nsections
<1) {
1574 tb
= tPtr
->firstTextBlock
;
1575 tPtr
->flags
.laidOut
= False
;
1580 if (tb
->sections
[0]._y
!=
1581 tb
->prior
->sections
[tb
->prior
->nsections
-1]._y
) {
1587 if(tb
->prior
&& tb
->prior
->sections
&& tb
->prior
->nsections
>0) {
1588 y
= tb
->prior
->sections
[tb
->prior
->nsections
-1]._y
+
1589 tb
->prior
->sections
[tb
->prior
->nsections
-1].h
-
1590 tb
->prior
->sections
[tb
->prior
->nsections
-1].max_d
;
1599 if (tb
->sections
&& tb
->nsections
>0) {
1600 wfree(tb
->sections
);
1601 tb
->sections
= NULL
;
1605 if (tb
->blank
&& tb
->next
&& !tb
->next
->first
) {
1606 TextBlock
*next
= tb
->next
;
1607 tPtr
->currentTextBlock
= tb
;
1608 WMDestroyTextBlock(tPtr
, WMRemoveTextBlock(tPtr
));
1614 if (tb
->first
&& tb
!= tPtr
->firstTextBlock
) {
1615 y
+= layOutLine(tPtr
, items
, nitems
, x
, y
);
1616 x
= tPtr
->margins
[tb
->marginN
].first
;
1617 bmargin
= tPtr
->margins
[tb
->marginN
].body
;
1623 if (!tPtr
->flags
.monoFont
) {
1625 width
= WMWidgetWidth(tb
->d
.widget
);
1627 width
= tb
->d
.pixmap
->width
;
1629 if (width
> tPtr
->docWidth
)
1630 tPtr
->docWidth
= width
;
1633 if (lw
>= tPtr
->visible
.w
- x
) {
1634 y
+= layOutLine(tPtr
, items
, nitems
, x
, y
);
1640 if(nitems
+ 1> itemsSize
) {
1641 items
= wrealloc(items
,
1642 (++itemsSize
)*sizeof(myLineItems
));
1645 items
[nitems
].tb
= tb
;
1646 items
[nitems
].begin
= 0;
1647 items
[nitems
].end
= 0;
1651 } else if ((start
= tb
->text
)) {
1653 font
= tPtr
->flags
.monoFont
?tPtr
->dFont
:tb
->d
.font
;
1656 mark
= strchr(start
, ' ');
1658 end
+= (int)(mark
-start
)+1;
1661 end
+= strlen(start
);
1668 if (end
-begin
> 0) {
1670 width
= WMWidthOfString(font
,
1671 &tb
->text
[begin
], end
-begin
);
1673 /* if it won't fit, break it up */
1674 if (width
> tPtr
->visible
.w
) {
1675 char *t
= &tb
->text
[begin
];
1676 int l
=end
-begin
, i
=0;
1678 width
= WMWidthOfString(font
, t
, ++i
);
1679 } while (width
< tPtr
->visible
.w
&& i
< l
);
1688 if (lw
>= tPtr
->visible
.w
- x
) {
1689 y
+= layOutLine(tPtr
, items
, nitems
, x
, y
);
1695 if(nitems
+ 1 > itemsSize
) {
1696 items
= wrealloc(items
,
1697 (++itemsSize
)*sizeof(myLineItems
));
1700 items
[nitems
].tb
= tb
;
1701 items
[nitems
].begin
= begin
;
1702 items
[nitems
].end
= end
;
1710 /* not yet fully ready. but is already VERY FAST for a 3Mbyte file ;-) */
1711 if(0&&tPtr
->flags
.laidOut
1712 && tb
->next
&& tb
->next
->sections
&& tb
->next
->nsections
>0
1713 && (tPtr
->vpos
+ tPtr
->visible
.h
1714 < tb
->next
->sections
[0]._y
)) {
1715 if(tPtr
->lastTextBlock
->sections
1716 && tPtr
->lastTextBlock
->nsections
> 0 ) {
1717 TextBlock
*ltb
= tPtr
->lastTextBlock
;
1718 int ly
= ltb
->sections
[ltb
->nsections
-1]._y
;
1719 int lh
= ltb
->sections
[ltb
->nsections
-1].h
;
1722 lh
+= 1 + tPtr
->visible
.y
+ ltb
->sections
[ltb
->nsections
-1].max_d
;
1723 printf("it's %d\n", tPtr
->visible
.y
+ ltb
->sections
[ltb
->nsections
-1].max_d
);
1725 y
+= layOutLine(tPtr
, items
, nitems
, x
, y
);
1727 sd
= tPtr
->docHeight
-y
;
1729 printf("dif %d-%d: %d\n", ss
, sd
, ss
-sd
);
1730 y
+= tb
->next
->sections
[0]._y
-y
;
1732 printf("nitems%d\n", nitems
);
1734 y
= tPtr
->docHeight
+ss
-sd
;
1738 tPtr
->flags
.laidOut
= False
;
1747 y
+= layOutLine(tPtr
, items
, nitems
, x
, y
);
1749 if (tPtr
->docHeight
!= y
+10) {
1750 tPtr
->docHeight
= y
+10;
1751 updateScrollers(tPtr
);
1754 if(tPtr
->docWidth
> tPtr
->visible
.w
&& !tPtr
->hS
) {
1757 tPtr
->flags
.horizOnDemand
= True
;
1758 WMSetTextHasHorizontalScroller((WMText
*)tPtr
, True
);
1759 event
.type
= Expose
;
1760 handleEvents(&event
, (void *)tPtr
);
1762 } else if(tPtr
->docWidth
<= tPtr
->visible
.w
1763 && tPtr
->hS
&& tPtr
->flags
.horizOnDemand
) {
1764 tPtr
->flags
.horizOnDemand
= False
;
1765 WMSetTextHasHorizontalScroller((WMText
*)tPtr
, False
);
1768 tPtr
->flags
.laidOut
= True
;
1770 if(items
&& itemsSize
> 0)
1776 textDidResize(W_ViewDelegate
*self
, WMView
*view
)
1778 Text
*tPtr
= (Text
*)view
->self
;
1779 unsigned short w
= tPtr
->view
->size
.width
;
1780 unsigned short h
= tPtr
->view
->size
.height
;
1781 unsigned short rh
= 0, vw
= 0, rel
;
1783 rel
= (tPtr
->flags
.relief
== WRFlat
);
1785 if (tPtr
->ruler
&& tPtr
->flags
.rulerShown
) {
1786 WMMoveWidget(tPtr
->ruler
, 2, 2);
1787 WMResizeWidget(tPtr
->ruler
, w
- 4, 40);
1792 WMMoveWidget(tPtr
->vS
, 1 - (rel
?1:0), rh
+ 1 - (rel
?1:0));
1793 WMResizeWidget(tPtr
->vS
, 20, h
- rh
- 2 + (rel
?2:0));
1795 WMSetRulerOffset(tPtr
->ruler
,22);
1796 } else WMSetRulerOffset(tPtr
->ruler
, 2);
1800 WMMoveWidget(tPtr
->hS
, vw
, h
- 21);
1801 WMResizeWidget(tPtr
->hS
, w
- vw
- 1, 20);
1803 WMMoveWidget(tPtr
->hS
, vw
+1, h
- 21);
1804 WMResizeWidget(tPtr
->hS
, w
- vw
- 2, 20);
1808 tPtr
->visible
.x
= (tPtr
->vS
)?24:4;
1809 tPtr
->visible
.y
= (tPtr
->ruler
&& tPtr
->flags
.rulerShown
)?43:3;
1810 tPtr
->visible
.w
= tPtr
->view
->size
.width
- tPtr
->visible
.x
- 8;
1811 tPtr
->visible
.h
= tPtr
->view
->size
.height
- tPtr
->visible
.y
;
1812 tPtr
->visible
.h
-= (tPtr
->hS
)?20:0;
1813 tPtr
->margins
[0].right
= tPtr
->visible
.w
;
1815 if (tPtr
->view
->flags
.realized
) {
1818 XFreePixmap(tPtr
->view
->screen
->display
, tPtr
->db
);
1819 tPtr
->db
= (Pixmap
) NULL
;
1822 if (tPtr
->visible
.w
< 40)
1823 tPtr
->visible
.w
= 40;
1824 if (tPtr
->visible
.h
< 20)
1825 tPtr
->visible
.h
= 20;
1828 tPtr
->db
= XCreatePixmap(tPtr
->view
->screen
->display
,
1829 tPtr
->view
->window
, tPtr
->visible
.w
,
1830 tPtr
->visible
.h
, tPtr
->view
->screen
->depth
);
1837 W_ViewDelegate _TextViewDelegate
=
1845 /* nice, divisble-by-16 blocks */
1846 static inline unsigned short
1847 reqBlockSize(unsigned short requested
)
1849 return requested
+ 16 - (requested
%16);
1854 clearText(Text
*tPtr
)
1856 tPtr
->vpos
= tPtr
->hpos
= 0;
1857 tPtr
->docHeight
= tPtr
->docWidth
= 0;
1859 if (!tPtr
->firstTextBlock
)
1862 while (tPtr
->currentTextBlock
)
1863 WMDestroyTextBlock(tPtr
, WMRemoveTextBlock(tPtr
));
1865 tPtr
->firstTextBlock
= NULL
;
1866 tPtr
->currentTextBlock
= NULL
;
1867 tPtr
->lastTextBlock
= NULL
;
1868 WMEmptyArray(tPtr
->gfxItems
);
1872 deleteTextInteractively(Text
*tPtr
, KeySym ksym
)
1875 Bool back
= (Bool
) (ksym
== XK_BackSpace
);
1879 if (!tPtr
->flags
.editable
) {
1880 XBell(tPtr
->view
->screen
->display
, 0);
1884 if ( !(tb
= tPtr
->currentTextBlock
) )
1887 if (tPtr
->flags
.ownsSelection
) {
1888 if(removeSelection(tPtr
))
1889 layOutDocument(tPtr
);
1893 wasFirst
= tb
->first
;
1894 if (back
&& tPtr
->tpos
< 1) {
1896 if(tb
->prior
->blank
) {
1897 tPtr
->currentTextBlock
= tb
->prior
;
1898 WMRemoveTextBlock(tPtr
);
1899 tPtr
->currentTextBlock
= tb
;
1901 layOutDocument(tPtr
);
1905 TextBlock
*prior
= tb
->prior
;
1906 tPtr
->currentTextBlock
= tb
;
1907 WMRemoveTextBlock(tPtr
);
1913 tPtr
->tpos
= tb
->used
;
1914 tPtr
->currentTextBlock
= tb
;
1918 tb
->next
->first
= False
;
1919 layOutDocument(tPtr
);
1926 if ( (tb
->used
> 0) && ((back
?tPtr
->tpos
> 0:1))
1927 && (tPtr
->tpos
<= tb
->used
) && !tb
->graphic
) {
1930 memmove(&(tb
->text
[tPtr
->tpos
]),
1931 &(tb
->text
[tPtr
->tpos
+ 1]), tb
->used
- tPtr
->tpos
);
1936 if ( (back
? (tPtr
->tpos
< 1 && !done
) : ( tPtr
->tpos
>= tb
->used
))
1939 TextBlock
*sibling
= (back
? tb
->prior
: tb
->next
);
1941 if(tb
->used
== 0 || tb
->graphic
)
1942 WMDestroyTextBlock(tPtr
, WMRemoveTextBlock(tPtr
));
1945 tPtr
->currentTextBlock
= sibling
;
1946 tPtr
->tpos
= (back
? sibling
->used
: 0);
1950 layOutDocument(tPtr
);
1955 insertTextInteractively(Text
*tPtr
, char *text
, int len
)
1958 char *newline
= NULL
;
1960 if (!tPtr
->flags
.editable
) {
1961 XBell(tPtr
->view
->screen
->display
, 0);
1965 if (len
< 1 || !text
)
1969 if(tPtr
->flags
.ignoreNewLine
&& *text
== '\n' && len
== 1)
1973 if (tPtr
->flags
.ownsSelection
)
1974 removeSelection(tPtr
);
1977 if (tPtr
->flags
.ignoreNewLine
) {
1979 for(i
=0; i
<len
; i
++) {
1980 if (text
[i
] == '\n')
1985 tb
= tPtr
->currentTextBlock
;
1986 if (!tb
|| tb
->graphic
) {
1988 WMAppendTextStream(tPtr
, text
);
1989 layOutDocument(tPtr
);
1993 if ((newline
= strchr(text
, '\n'))) {
1994 int nlen
= (int)(newline
-text
);
1995 int s
= tb
->used
- tPtr
->tpos
;
1997 if (!tb
->blank
&& nlen
>0) {
1999 memcpy(save
, &tb
->text
[tPtr
->tpos
], s
);
2000 tb
->used
-= (tb
->used
- tPtr
->tpos
);
2002 insertTextInteractively(tPtr
, text
, nlen
);
2004 WMAppendTextStream(tPtr
, newline
);
2006 insertTextInteractively(tPtr
, save
, s
);
2009 if (tPtr
->tpos
>0 && tPtr
->tpos
< tb
->used
2010 && !tb
->graphic
&& tb
->text
) {
2012 void *ntb
= WMCreateTextBlockWithText(
2013 tPtr
, &tb
->text
[tPtr
->tpos
],
2014 tb
->d
.font
, tb
->color
, True
, tb
->used
- tPtr
->tpos
);
2015 tb
->used
= tPtr
->tpos
;
2016 WMAppendTextBlock(tPtr
, ntb
);
2019 } else if (tPtr
->tpos
== tb
->used
|| tPtr
->tpos
== 0) {
2020 if(tPtr
->flags
.indentNewLine
) {
2021 WMAppendTextBlock(tPtr
, WMCreateTextBlockWithText(tPtr
,
2022 " ", tb
->d
.font
, tb
->color
, True
, 4));
2025 WMAppendTextBlock(tPtr
, WMCreateTextBlockWithText(tPtr
,
2026 NULL
, tb
->d
.font
, tb
->color
, True
, 0));
2033 if (tb
->used
+ len
>= tb
->allocated
) {
2034 tb
->allocated
= reqBlockSize(tb
->used
+len
);
2035 tb
->text
= wrealloc(tb
->text
, tb
->allocated
);
2039 memcpy(tb
->text
, text
, len
);
2042 tb
->text
[tb
->used
] = 0;
2046 memmove(&(tb
->text
[tPtr
->tpos
+len
]), &tb
->text
[tPtr
->tpos
],
2047 tb
->used
-tPtr
->tpos
+1);
2048 memmove(&tb
->text
[tPtr
->tpos
], text
, len
);
2051 tb
->text
[tb
->used
] = 0;
2056 layOutDocument(tPtr
);
2061 selectRegion(Text
*tPtr
, int x
, int y
)
2067 y
+= (tPtr
->flags
.rulerShown
? 40: 0);
2070 y
-= 10; /* the original offset */
2072 x
-= tPtr
->visible
.x
-2;
2076 tPtr
->sel
.x
= WMAX(0, WMIN(tPtr
->clicked
.x
, x
));
2077 tPtr
->sel
.w
= abs(tPtr
->clicked
.x
- x
);
2078 tPtr
->sel
.y
= WMAX(0, WMIN(tPtr
->clicked
.y
, y
));
2079 tPtr
->sel
.h
= abs(tPtr
->clicked
.y
- y
);
2081 tPtr
->flags
.ownsSelection
= True
;
2087 releaseSelection(Text
*tPtr
)
2089 TextBlock
*tb
= tPtr
->firstTextBlock
;
2092 tb
->selected
= False
;
2095 tPtr
->flags
.ownsSelection
= False
;
2096 WMDeleteSelectionHandler(tPtr
->view
, XA_PRIMARY
,
2104 requestHandler(WMView
*view
, Atom selection
, Atom target
, void *cdata
,
2107 Text
*tPtr
= view
->self
;
2108 Display
*dpy
= tPtr
->view
->screen
->display
;
2110 Atom TEXT
= XInternAtom(dpy
, "TEXT", False
);
2111 Atom COMPOUND_TEXT
= XInternAtom(dpy
, "COMPOUND_TEXT", False
);
2112 WMData
*data
= NULL
;
2115 if (target
== XA_STRING
|| target
== TEXT
|| target
== COMPOUND_TEXT
) {
2116 char *text
= WMGetTextSelectedStream(tPtr
);
2119 printf("got text [%s]\n", text
);
2120 data
= WMCreateDataWithBytes(text
, strlen(text
));
2121 WMSetDataFormat(data
, TYPETEXT
);
2125 } else printf("didn't get it\n");
2127 _TARGETS
= XInternAtom(dpy
, "TARGETS", False
);
2128 if (target
== _TARGETS
) {
2131 ptr
= wmalloc(4 * sizeof(Atom
));
2135 ptr
[3] = COMPOUND_TEXT
;
2137 data
= WMCreateDataWithBytes(ptr
, 4*4);
2138 WMSetDataFormat(data
, 32);
2148 lostHandler(WMView
*view
, Atom selection
, void *cdata
)
2150 releaseSelection((WMText
*)view
->self
);
2153 static WMSelectionProcs selectionHandler
= {
2154 requestHandler
, lostHandler
, NULL
2159 ownershipObserver(void *observerData
, WMNotification
*notification
)
2161 if (observerData
!= WMGetNotificationClientData(notification
))
2162 lostHandler(WMWidgetView(observerData
), XA_PRIMARY
, NULL
);
2167 fontChanged(void *observerData
, WMNotification
*notification
)
2169 WMText
*tPtr
= (WMText
*) observerData
;
2170 WMFont
*font
= (WMFont
*)WMGetNotificationClientData(notification
);
2171 printf("fontChanged\n");
2176 if (tPtr
->flags
.ownsSelection
)
2177 WMSetTextSelectionFont(tPtr
, font
);
2182 handleTextKeyPress(Text
*tPtr
, XEvent
*event
)
2186 int control_pressed
= False
;
2187 TextBlock
*tb
= NULL
;
2189 if (((XKeyEvent
*) event
)->state
& ControlMask
)
2190 control_pressed
= True
;
2191 buffer
[XLookupString(&event
->xkey
, buffer
, 1, &ksym
, NULL
)] = 0;
2196 if(!(tb
= tPtr
->currentTextBlock
))
2202 L_imaGFX
: if(tb
->prior
) {
2203 tPtr
->currentTextBlock
= tb
->prior
;
2204 tPtr
->tpos
= tPtr
->currentTextBlock
->used
-1;
2205 } else tPtr
->tpos
= 0;
2206 } else tPtr
->tpos
--;
2207 updateCursorPosition(tPtr
);
2212 if(!(tb
= tPtr
->currentTextBlock
))
2216 if(tPtr
->tpos
== tb
->used
) {
2217 R_imaGFX
: if(tb
->next
) {
2218 tPtr
->currentTextBlock
= tb
->next
;
2220 } else tPtr
->tpos
= tb
->used
;
2221 } else tPtr
->tpos
++;
2222 updateCursorPosition(tPtr
);
2227 cursorToTextPosition(tPtr
, tPtr
->cursor
.x
+ tPtr
->visible
.x
,
2228 tPtr
->clicked
.y
+ tPtr
->cursor
.h
- tPtr
->vpos
);
2233 cursorToTextPosition(tPtr
, tPtr
->cursor
.x
+ tPtr
->visible
.x
,
2234 tPtr
->visible
.y
+ tPtr
->cursor
.y
- tPtr
->vpos
- 3);
2241 deleteTextInteractively(tPtr
, ksym
);
2242 updateCursorPosition(tPtr
);
2248 control_pressed
= True
;
2252 insertTextInteractively(tPtr
, " ", 4);
2253 updateCursorPosition(tPtr
);
2260 if (buffer
[0] != 0 && !control_pressed
) {
2261 insertTextInteractively(tPtr
, buffer
, 1);
2262 updateCursorPosition(tPtr
);
2265 } else if (control_pressed
&& ksym
==XK_r
) {
2266 Bool i
= !tPtr
->flags
.rulerShown
;
2267 WMShowTextRuler(tPtr
, i
);
2268 tPtr
->flags
.rulerShown
= i
;
2270 else if (control_pressed
&& buffer
[0] == '\a')
2271 XBell(tPtr
->view
->screen
->display
, 0);
2274 if (!control_pressed
&& tPtr
->flags
.ownsSelection
)
2275 releaseSelection(tPtr
);
2279 handleWidgetPress(XEvent
*event
, void *data
)
2281 TextBlock
*tb
= (TextBlock
*)data
;
2289 tPtr
->currentTextBlock
= tb
;
2290 tPtr
->flags
.isOverGraphic
= 2;
2292 output(tb
->text
, tb
->used
);
2294 if (!tPtr
->flags
.focused
) {
2295 WMSetFocusToWidget(tPtr
);
2296 tPtr
->flags
.focused
= True
;
2303 handleActionEvents(XEvent
*event
, void *data
)
2305 Text
*tPtr
= (Text
*)data
;
2306 Display
*dpy
= event
->xany
.display
;
2310 switch (event
->type
) {
2312 ksym
= XLookupKeysym((XKeyEvent
*)event
, 0);
2313 if (ksym
== XK_Shift_R
|| ksym
== XK_Shift_L
) {
2314 tPtr
->flags
.extendSelection
= True
;
2318 if (tPtr
->flags
.focused
) {
2319 XGrabPointer(dpy
, W_VIEW(tPtr
)->window
, False
,
2320 PointerMotionMask
|ButtonPressMask
|ButtonReleaseMask
,
2321 GrabModeAsync
, GrabModeAsync
, None
,
2322 tPtr
->view
->screen
->invisibleCursor
, CurrentTime
);
2323 tPtr
->flags
.pointerGrabbed
= True
;
2324 handleTextKeyPress(tPtr
, event
);
2329 ksym
= XLookupKeysym((XKeyEvent
*)event
, 0);
2330 if (ksym
== XK_Shift_R
|| ksym
== XK_Shift_L
) {
2331 tPtr
->flags
.extendSelection
= False
;
2333 /* end modify flag so selection can be extended */
2340 if (tPtr
->flags
.pointerGrabbed
) {
2341 tPtr
->flags
.pointerGrabbed
= False
;
2342 XUngrabPointer(dpy
, CurrentTime
);
2345 if(tPtr
->flags
.waitingForSelection
)
2348 if ((event
->xmotion
.state
& Button1Mask
)) {
2349 if (!tPtr
->flags
.ownsSelection
) {
2350 WMCreateSelectionHandler(tPtr
->view
,
2351 XA_PRIMARY
, event
->xbutton
.time
,
2352 &selectionHandler
, NULL
);
2353 tPtr
->flags
.ownsSelection
= True
;
2355 selectRegion(tPtr
, event
->xmotion
.x
, event
->xmotion
.y
);
2359 mouseOverObject(tPtr
, event
->xmotion
.x
, event
->xmotion
.y
);
2365 if (tPtr
->flags
.pointerGrabbed
) {
2366 tPtr
->flags
.pointerGrabbed
= False
;
2367 XUngrabPointer(dpy
, CurrentTime
);
2371 if (tPtr
->flags
.waitingForSelection
)
2374 if (tPtr
->flags
.extendSelection
) {
2375 selectRegion(tPtr
, event
->xmotion
.x
, event
->xmotion
.y
);
2380 if (event
->xbutton
.button
== Button1
) {
2382 if(WMIsDoubleClick(event
)) {
2383 TextBlock
*tb
= tPtr
->currentTextBlock
;
2385 if(tb
&& tb
->graphic
&& !tb
->object
) {
2386 char desc
[tb
->used
+1];
2387 memcpy(desc
, tb
->text
, tb
->used
);
2389 if(tPtr
->delegate
) {
2390 if(tPtr
->delegate
->didDoubleClickOnPicture
)
2391 (*tPtr
->delegate
->didDoubleClickOnPicture
)
2392 (tPtr
->delegate
, desc
);
2395 autoSelectText(tPtr
, 2);
2397 tPtr
->lastClickTime
= event
->xbutton
.time
;
2399 } else if(event
->xbutton
.time
- tPtr
->lastClickTime
2400 < WINGsConfiguration
.doubleClickDelay
) {
2401 autoSelectText(tPtr
, 3);
2405 if (!tPtr
->flags
.focused
) {
2406 WMSetFocusToWidget(tPtr
);
2407 tPtr
->flags
.focused
= True
;
2410 if (tPtr
->flags
.ownsSelection
)
2411 releaseSelection(tPtr
);
2413 tPtr
->lastClickTime
= event
->xbutton
.time
;
2414 cursorToTextPosition(tPtr
, event
->xmotion
.x
, event
->xmotion
.y
);
2418 if (event
->xbutton
.button
2419 == WINGsConfiguration
.mouseWheelDown
) {
2420 WMScrollText(tPtr
, 16);
2424 if (event
->xbutton
.button
2425 == WINGsConfiguration
.mouseWheelUp
) {
2426 WMScrollText(tPtr
, -16);
2430 if (event
->xbutton
.button
== Button2
) {
2434 if (!tPtr
->flags
.editable
) {
2440 if (!WMRequestSelection(tPtr
->view
, XA_PRIMARY
, XA_STRING
,
2441 event
->xbutton
.time
, pasteText
, NULL
)) {
2445 text
= XFetchBuffer(tPtr
->view
->screen
->display
, &n
, 0);
2451 (tPtr
->parser
) (tPtr
, (void *) text
);
2453 insertTextInteractively(tPtr
, text
, n
);
2457 NOTIFY(tPtr
, didChange
, WMTextDidChangeNotification
,
2458 (void*)WMInsertTextEvent
);
2462 tPtr
->flags
.waitingForSelection
= True
;
2471 if (tPtr
->flags
.pointerGrabbed
) {
2472 tPtr
->flags
.pointerGrabbed
= False
;
2473 XUngrabPointer(dpy
, CurrentTime
);
2477 if (tPtr
->flags
.waitingForSelection
)
2485 handleEvents(XEvent
*event
, void *data
)
2487 Text
*tPtr
= (Text
*)data
;
2489 switch(event
->type
) {
2492 if (event
->xexpose
.count
!=0)
2496 if (!(W_VIEW(tPtr
->hS
))->flags
.realized
)
2497 WMRealizeWidget(tPtr
->hS
);
2501 if (!(W_VIEW(tPtr
->vS
))->flags
.realized
)
2502 WMRealizeWidget(tPtr
->vS
);
2506 if (!(W_VIEW(tPtr
->ruler
))->flags
.realized
)
2507 WMRealizeWidget(tPtr
->ruler
);
2512 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
2518 if (W_FocusedViewOfToplevel(W_TopLevelOfView(tPtr
->view
))
2521 tPtr
->flags
.focused
= True
;
2523 if (tPtr
->flags
.editable
&& !tPtr
->timerID
) {
2524 tPtr
->timerID
= WMAddTimerHandler(12+0*CURSOR_BLINK_ON_DELAY
,
2532 tPtr
->flags
.focused
= False
;
2535 if (tPtr
->timerID
) {
2536 WMDeleteTimerHandler(tPtr
->timerID
);
2537 tPtr
->timerID
= NULL
;
2546 XFreePixmap(tPtr
->view
->screen
->display
, tPtr
->db
);
2548 WMEmptyArray(tPtr
->gfxItems
);
2551 WMDeleteTimerHandler(tPtr
->timerID
);
2553 WMReleaseFont(tPtr
->dFont
);
2554 WMReleaseColor(tPtr
->dColor
);
2555 WMDeleteSelectionHandler(tPtr
->view
, XA_PRIMARY
, CurrentTime
);
2556 WMRemoveNotificationObserver(tPtr
);
2567 insertPlainText(Text
*tPtr
, char *text
)
2574 mark
= strchr(start
, '\n');
2576 tb
= WMCreateTextBlockWithText(tPtr
,
2578 tPtr
->dColor
, tPtr
->flags
.first
, (int)(mark
-start
));
2580 tPtr
->flags
.first
= True
;
2582 if (start
&& strlen(start
)) {
2583 tb
= WMCreateTextBlockWithText(tPtr
, start
, tPtr
->dFont
,
2584 tPtr
->dColor
, tPtr
->flags
.first
, strlen(start
));
2586 tPtr
->flags
.first
= False
;
2590 if (tPtr
->flags
.prepend
)
2591 WMPrependTextBlock(tPtr
, tb
);
2593 WMAppendTextBlock(tPtr
, tb
);
2601 rulerMoveCallBack(WMWidget
*w
, void *self
)
2603 Text
*tPtr
= (Text
*)self
;
2606 if (W_CLASS(tPtr
) != WC_Text
)
2614 rulerReleaseCallBack(WMWidget
*w
, void *self
)
2616 Text
*tPtr
= (Text
*)self
;
2619 if (W_CLASS(tPtr
) != WC_Text
)
2628 draggingEntered(WMView
*self
, WMDraggingInfo
*info
)
2630 printf("draggingEntered\n");
2631 return WDOperationCopy
;
2636 draggingUpdated(WMView
*self
, WMDraggingInfo
*info
)
2638 return WDOperationCopy
;
2643 draggingExited(WMView
*self
, WMDraggingInfo
*info
)
2645 printf("draggingExited\n");
2649 prepareForDragOperation(WMView
*self
, WMDraggingInfo
*info
)
2651 printf("prepareForDragOperation\n");
2659 receivedData(WMView
*view
, Atom selection
, Atom target
, Time timestamp
,
2660 void *cdata
, WMData
*data
)
2662 badbadbad
= wstrdup((char *)WMDataBytes(data
));
2666 /* when it's done in WINGs, remove this */
2668 Bool
requestDroppedData(WMView
*view
, WMDraggingInfo
*info
, char *type
)
2670 WMScreen
*scr
= W_VIEW_SCREEN(view
);
2672 if (!WMRequestSelection(scr
->dragInfo
.destView
,
2673 scr
->xdndSelectionAtom
,
2674 XInternAtom(scr
->display
, type
, False
),
2675 scr
->dragInfo
.timestamp
,
2676 receivedData
, &scr
->dragInfo
)) {
2677 wwarning("could not request data for dropped data");
2684 ev
.type
= ClientMessage
;
2685 ev
.xclient
.message_type
= scr
->xdndFinishedAtom
;
2686 ev
.xclient
.format
= 32;
2687 ev
.xclient
.window
= info
->destinationWindow
;
2688 ev
.xclient
.data
.l
[0] = 0;
2689 ev
.xclient
.data
.l
[1] = 0;
2690 ev
.xclient
.data
.l
[2] = 0;
2691 ev
.xclient
.data
.l
[3] = 0;
2692 ev
.xclient
.data
.l
[4] = 0;
2694 XSendEvent(scr
->display
, info
->sourceWindow
, False
, 0, &ev
);
2695 XFlush(scr
->display
);
2701 performDragOperation(WMView
*self
, WMDraggingInfo
*info
, WMData
*data
)
2704 WMText
*tPtr
= (WMText
*)self
->self
;
2709 requestDroppedData(tPtr
->view
, info
, "application/X-color");
2710 color
= WMCreateNamedColor(W_VIEW_SCREEN(self
), badbadbad
, True
);
2712 WMSetTextSelectionColor(tPtr
, color
);
2713 WMReleaseColor(color
);
2722 concludeDragOperation(WMView
*self
, WMDraggingInfo
*info
)
2724 printf("concludeDragOperation\n");
2728 static WMDragDestinationProcs _DragDestinationProcs
= {
2732 prepareForDragOperation
,
2733 performDragOperation
,
2734 concludeDragOperation
2739 getStream(WMText
*tPtr
, int sel
, int array
)
2741 TextBlock
*tb
= NULL
;
2743 unsigned long where
= 0;
2748 if (!(tb
= tPtr
->firstTextBlock
))
2752 (tPtr
->writer
) (tPtr
, (void *) text
);
2756 tb
= tPtr
->firstTextBlock
;
2759 if (!tb
->graphic
|| (tb
->graphic
&& !tPtr
->flags
.monoFont
)) {
2761 if (!sel
|| (tb
->graphic
&& tb
->selected
)) {
2763 if (!tPtr
->flags
.ignoreNewLine
&& (tb
->first
|| tb
->blank
)
2764 && tb
!= tPtr
->firstTextBlock
) {
2765 text
= wrealloc(text
, where
+1);
2766 text
[where
++] = '\n';
2772 if(tb
->graphic
&& array
) {
2773 text
= wrealloc(text
, where
+4);
2774 text
[where
++] = 0xFA;
2775 text
[where
++] = (tb
->used
>>8)&0x0ff;
2776 text
[where
++] = tb
->used
&0x0ff;
2777 text
[where
++] = tb
->allocated
; /* extra info */
2779 text
= wrealloc(text
, where
+tb
->used
);
2780 memcpy(&text
[where
], tb
->text
, tb
->used
);
2784 } else if (sel
&& tb
->selected
) {
2786 if (!tPtr
->flags
.ignoreNewLine
&& (tb
->first
|| tb
->blank
)
2787 && tb
!= tPtr
->firstTextBlock
) {
2788 text
= wrealloc(text
, where
+1);
2789 text
[where
++] = '\n';
2795 text
= wrealloc(text
, where
+(tb
->s_end
- tb
->s_begin
));
2796 memcpy(&text
[where
], &tb
->text
[tb
->s_begin
],
2797 tb
->s_end
- tb
->s_begin
);
2798 where
+= tb
->s_end
- tb
->s_begin
;
2803 _gSnext
:tb
= tb
->next
;
2806 /* +1 for the end of string, let's be nice */
2807 text
= wrealloc(text
, where
+1);
2814 releaseStreamObjects(void *data
)
2821 getStreamObjects(WMText
*tPtr
, int sel
)
2823 WMArray
*array
= WMCreateArrayWithDestructor(4, releaseStreamObjects
);
2827 char *start
, *fa
, *desc
;
2829 stream
= getStream(tPtr
, sel
, 1);
2836 fa
= strchr(start
, 0xFA);
2838 if((int)(fa
- start
)>0) {
2840 desc
[(int)(fa
- start
)] = 0;
2841 data
= WMCreateDataWithBytes((void *)desc
, (int)(fa
- start
));
2842 WMSetDataFormat(data
, TYPETEXT
);
2843 WMAddToArray(array
, (void *) data
);
2846 len
= *(fa
+1)*0xff + *(fa
+2);
2847 data
= WMCreateDataWithBytes((void *)(fa
+4), len
);
2848 WMSetDataFormat(data
, *(fa
+3));
2849 WMAddToArray(array
, (void *) data
);
2850 start
= fa
+ len
+ 4;
2853 if (start
&& strlen(start
)) {
2854 data
= WMCreateDataWithBytes((void *)start
, strlen(start
));
2855 WMSetDataFormat(data
, TYPETEXT
);
2856 WMAddToArray(array
, (void *) data
);
2869 WMCreateTextForDocumentType(WMWidget
*parent
,
2870 WMAction
*parser
, WMAction
*writer
)
2872 Text
*tPtr
= wmalloc(sizeof(Text
));
2874 printf("could not create text widget\n");
2879 memset(tPtr
, 0, sizeof(Text
));
2880 tPtr
->widgetClass
= WC_Text
;
2881 tPtr
->view
= W_CreateView(W_VIEW(parent
));
2883 perror("could not create text's view\n");
2887 tPtr
->view
->self
= tPtr
;
2888 tPtr
->view
->attribs
.cursor
= tPtr
->view
->screen
->textCursor
;
2889 tPtr
->view
->attribFlags
|= CWOverrideRedirect
| CWCursor
;
2890 W_ResizeView(tPtr
->view
, 250, 200);
2892 tPtr
->dColor
= WMWhiteColor(tPtr
->view
->screen
);
2893 tPtr
->bgGC
= WMColorGC(tPtr
->dColor
);
2894 W_SetViewBackgroundColor(tPtr
->view
, tPtr
->dColor
);
2895 WMReleaseColor(tPtr
->dColor
);
2897 tPtr
->dColor
= WMBlackColor(tPtr
->view
->screen
);
2898 tPtr
->fgGC
= WMColorGC(tPtr
->dColor
);
2904 tPtr
->dFont
= WMRetainFont(WMSystemFontOfSize(tPtr
->view
->screen
, 12));
2906 tPtr
->view
->delegate
= &_TextViewDelegate
;
2908 tPtr
->delegate
= NULL
;
2911 tPtr
->timerID
= NULL
;
2914 WMCreateEventHandler(tPtr
->view
, ExposureMask
|StructureNotifyMask
2915 |EnterWindowMask
|LeaveWindowMask
|FocusChangeMask
,
2916 handleEvents
, tPtr
);
2918 WMCreateEventHandler(tPtr
->view
, ButtonReleaseMask
|ButtonPressMask
2919 |KeyReleaseMask
|KeyPressMask
|Button1MotionMask
,
2920 handleActionEvents
, tPtr
);
2922 WMAddNotificationObserver(ownershipObserver
, tPtr
,
2923 "_lostOwnership", tPtr
);
2926 char *types
[2] = {"application/X-color", NULL
};
2927 WMSetViewDragDestinationProcs(tPtr
->view
, &_DragDestinationProcs
);
2928 WMRegisterViewForDraggedTypes(tPtr
->view
, types
);
2931 WMAddNotificationObserver(fontChanged
, tPtr
,
2932 "WMFontPanelDidChangeNotification", tPtr
);
2934 tPtr
->firstTextBlock
= NULL
;
2935 tPtr
->lastTextBlock
= NULL
;
2936 tPtr
->currentTextBlock
= NULL
;
2939 tPtr
->gfxItems
= WMCreateArray(4);
2941 tPtr
->parser
= parser
;
2942 tPtr
->writer
= writer
;
2944 tPtr
->sel
.x
= tPtr
->sel
.y
= 2;
2945 tPtr
->sel
.w
= tPtr
->sel
.h
= 0;
2947 tPtr
->clicked
.x
= tPtr
->clicked
.y
= 2;
2949 tPtr
->visible
.x
= tPtr
->visible
.y
= 2;
2950 tPtr
->visible
.h
= tPtr
->view
->size
.height
;
2951 tPtr
->visible
.w
= tPtr
->view
->size
.width
- 4;
2953 tPtr
->cursor
.x
= -23;
2956 tPtr
->docHeight
= 0;
2957 tPtr
->dBulletPix
= WMCreatePixmapFromXPMData(tPtr
->view
->screen
,
2959 tPtr
->db
= (Pixmap
) NULL
;
2961 tPtr
->margins
= WMGetRulerMargins(NULL
);
2962 tPtr
->margins
->right
= tPtr
->visible
.w
;
2965 tPtr
->flags
.rulerShown
= False
;
2966 tPtr
->flags
.monoFont
= False
;
2967 tPtr
->flags
.focused
= False
;
2968 tPtr
->flags
.editable
= True
;
2969 tPtr
->flags
.ownsSelection
= False
;
2970 tPtr
->flags
.pointerGrabbed
= False
;
2971 tPtr
->flags
.extendSelection
= False
;
2972 tPtr
->flags
.frozen
= False
;
2973 tPtr
->flags
.cursorShown
= True
;
2974 tPtr
->flags
.acceptsGraphic
= False
;
2975 tPtr
->flags
.horizOnDemand
= False
;
2976 tPtr
->flags
.needsLayOut
= False
;
2977 tPtr
->flags
.ignoreNewLine
= False
;
2978 tPtr
->flags
.indentNewLine
= False
;
2979 tPtr
->flags
.laidOut
= False
;
2980 tPtr
->flags
.waitingForSelection
= False
;
2981 tPtr
->flags
.prepend
= False
;
2982 tPtr
->flags
.isOverGraphic
= False
;
2983 tPtr
->flags
.relief
= WRSunken
;
2984 tPtr
->flags
.isOverGraphic
= 0;
2985 tPtr
->flags
.alignment
= WALeft
;
2986 tPtr
->flags
.first
= True
;
2992 WMPrependTextStream(WMText
*tPtr
, char *text
)
2994 CHECK_CLASS(tPtr
, WC_Text
);
2997 if(tPtr
->flags
.ownsSelection
)
2998 releaseSelection(tPtr
);
3001 updateScrollers(tPtr
);
3006 tPtr
->flags
.prepend
= True
;
3007 if (text
&& tPtr
->parser
)
3008 (tPtr
->parser
) (tPtr
, (void *) text
);
3010 insertPlainText(tPtr
, text
);
3012 tPtr
->flags
.needsLayOut
= True
;
3018 WMAppendTextStream(WMText
*tPtr
, char *text
)
3020 CHECK_CLASS(tPtr
, WC_Text
);
3023 if(tPtr
->flags
.ownsSelection
)
3024 releaseSelection(tPtr
);
3027 updateScrollers(tPtr
);
3032 tPtr
->flags
.prepend
= False
;
3033 if (text
&& tPtr
->parser
)
3034 (tPtr
->parser
) (tPtr
, (void *) text
);
3036 insertPlainText(tPtr
, text
);
3038 tPtr
->flags
.needsLayOut
= True
;
3039 if(tPtr
->currentTextBlock
)
3040 tPtr
->tpos
= tPtr
->currentTextBlock
->used
;
3047 WMGetTextStream(WMText
*tPtr
)
3049 CHECK_CLASS(tPtr
, WC_Text
);
3050 return getStream(tPtr
, 0, 0);
3054 WMGetTextSelectedStream(WMText
*tPtr
)
3056 CHECK_CLASS(tPtr
, WC_Text
);
3057 return getStream(tPtr
, 1, 0);
3061 WMGetTextObjects(WMText
*tPtr
)
3063 CHECK_CLASS(tPtr
, WC_Text
);
3064 return getStreamObjects(tPtr
, 0);
3068 WMGetTextSelectedObjects(WMText
*tPtr
)
3070 CHECK_CLASS(tPtr
, WC_Text
);
3071 return getStreamObjects(tPtr
, 1);
3076 WMSetTextDelegate(WMText
*tPtr
, WMTextDelegate
*delegate
)
3078 CHECK_CLASS(tPtr
, WC_Text
);
3080 tPtr
->delegate
= delegate
;
3085 WMCreateTextBlockWithObject(WMText
*tPtr
, WMWidget
*w
,
3086 char *description
, WMColor
*color
,
3087 unsigned short first
, unsigned short extraInfo
)
3091 if (!w
|| !description
|| !color
)
3094 tb
= wmalloc(sizeof(TextBlock
));
3098 tb
->text
= wstrdup(description
);
3099 tb
->used
= strlen(description
);
3102 tb
->color
= WMRetainColor(color
);
3103 tb
->marginN
= newMargin(tPtr
, NULL
);
3104 tb
->allocated
= extraInfo
;
3109 tb
->underlined
= False
;
3110 tb
->selected
= False
;
3112 tb
->sections
= NULL
;
3122 WMCreateTextBlockWithPixmap(WMText
*tPtr
, WMPixmap
*p
,
3123 char *description
, WMColor
*color
,
3124 unsigned short first
, unsigned short extraInfo
)
3128 if (!p
|| !description
|| !color
)
3131 tb
= wmalloc(sizeof(TextBlock
));
3135 tb
->text
= wstrdup(description
);
3136 tb
->used
= strlen(description
);
3138 tb
->d
.pixmap
= WMRetainPixmap(p
);
3139 tb
->color
= WMRetainColor(color
);
3140 tb
->marginN
= newMargin(tPtr
, NULL
);
3141 tb
->allocated
= extraInfo
;
3146 tb
->underlined
= False
;
3147 tb
->selected
= False
;
3149 tb
->sections
= NULL
;
3158 WMCreateTextBlockWithText(WMText
*tPtr
, char *text
, WMFont
*font
, WMColor
*color
,
3159 unsigned short first
, unsigned short len
)
3163 if (!font
|| !color
)
3166 tb
= wmalloc(sizeof(TextBlock
));
3170 tb
->allocated
= reqBlockSize(len
);
3171 tb
->text
= (char *)wmalloc(tb
->allocated
);
3172 memset(tb
->text
, 0, tb
->allocated
);
3174 if (len
< 1|| !text
|| (*text
== '\n' && len
==1 )) {
3179 memcpy(tb
->text
, text
, len
);
3183 tb
->text
[tb
->used
] = 0;
3185 tb
->d
.font
= WMRetainFont(font
);
3186 tb
->color
= WMRetainColor(color
);
3187 tb
->marginN
= newMargin(tPtr
, NULL
);
3190 tb
->graphic
= False
;
3191 tb
->underlined
= False
;
3192 tb
->selected
= False
;
3194 tb
->sections
= NULL
;
3202 WMSetTextBlockProperties(WMText
*tPtr
, void *vtb
, unsigned int first
,
3203 unsigned int kanji
, unsigned int underlined
, int script
,
3204 WMRulerMargins
*margins
)
3206 TextBlock
*tb
= (TextBlock
*) vtb
;
3212 tb
->underlined
= underlined
;
3213 tb
->script
= script
;
3214 tb
->marginN
= newMargin(tPtr
, margins
);
3218 WMGetTextBlockProperties(WMText
*tPtr
, void *vtb
, unsigned int *first
,
3219 unsigned int *kanji
, unsigned int *underlined
, int *script
,
3220 WMRulerMargins
*margins
)
3222 TextBlock
*tb
= (TextBlock
*) vtb
;
3226 if (first
) *first
= tb
->first
;
3227 if (kanji
) *kanji
= tb
->kanji
;
3228 if (underlined
) *underlined
= tb
->underlined
;
3229 if (script
) *script
= tb
->script
;
3230 if (margins
) margins
= &tPtr
->margins
[tb
->marginN
];
3236 WMPrependTextBlock(WMText
*tPtr
, void *vtb
)
3238 TextBlock
*tb
= (TextBlock
*)vtb
;
3245 WMWidget
*w
= tb
->d
.widget
;
3246 WMCreateEventHandler(W_VIEW(w
), ButtonPressMask
,
3247 handleWidgetPress
, tb
);
3248 if (W_CLASS(w
) != WC_TextField
&& W_CLASS(w
) != WC_Text
) {
3249 (W_VIEW(w
))->attribs
.cursor
= tPtr
->view
->screen
->defaultCursor
;
3250 (W_VIEW(w
))->attribFlags
|= CWOverrideRedirect
| CWCursor
;
3253 WMAddToArray(tPtr
->gfxItems
, (void *)tb
);
3255 } else tPtr
->tpos
= tb
->used
;
3257 if (!tPtr
->lastTextBlock
|| !tPtr
->firstTextBlock
) {
3258 tb
->next
= tb
->prior
= NULL
;
3260 tPtr
->lastTextBlock
= tPtr
->firstTextBlock
3261 = tPtr
->currentTextBlock
= tb
;
3266 tb
->marginN
= tPtr
->currentTextBlock
->marginN
;
3269 tb
->next
= tPtr
->currentTextBlock
;
3270 tb
->prior
= tPtr
->currentTextBlock
->prior
;
3271 if (tPtr
->currentTextBlock
->prior
)
3272 tPtr
->currentTextBlock
->prior
->next
= tb
;
3274 tPtr
->currentTextBlock
->prior
= tb
;
3276 tPtr
->firstTextBlock
= tb
;
3278 tPtr
->currentTextBlock
= tb
;
3283 WMAppendTextBlock(WMText
*tPtr
, void *vtb
)
3285 TextBlock
*tb
= (TextBlock
*)vtb
;
3292 WMWidget
*w
= tb
->d
.widget
;
3293 WMCreateEventHandler(W_VIEW(w
), ButtonPressMask
,
3294 handleWidgetPress
, tb
);
3295 if (W_CLASS(w
) != WC_TextField
&& W_CLASS(w
) != WC_Text
) {
3296 (W_VIEW(w
))->attribs
.cursor
=
3297 tPtr
->view
->screen
->defaultCursor
;
3298 (W_VIEW(w
))->attribFlags
|= CWOverrideRedirect
| CWCursor
;
3301 WMAddToArray(tPtr
->gfxItems
, (void *)tb
);
3303 } else tPtr
->tpos
= tb
->used
;
3305 if (!tPtr
->lastTextBlock
|| !tPtr
->firstTextBlock
) {
3306 tb
->next
= tb
->prior
= NULL
;
3308 tPtr
->lastTextBlock
= tPtr
->firstTextBlock
3309 = tPtr
->currentTextBlock
= tb
;
3314 tb
->marginN
= tPtr
->currentTextBlock
->marginN
;
3317 tb
->next
= tPtr
->currentTextBlock
->next
;
3318 tb
->prior
= tPtr
->currentTextBlock
;
3319 if (tPtr
->currentTextBlock
->next
)
3320 tPtr
->currentTextBlock
->next
->prior
= tb
;
3322 tPtr
->currentTextBlock
->next
= tb
;
3325 tPtr
->lastTextBlock
= tb
;
3327 tPtr
->currentTextBlock
= tb
;
3331 WMRemoveTextBlock(WMText
*tPtr
)
3333 TextBlock
*tb
= NULL
;
3335 if (!tPtr
|| !tPtr
->firstTextBlock
|| !tPtr
->lastTextBlock
3336 || !tPtr
->currentTextBlock
) {
3337 printf("cannot remove non existent TextBlock!\b");
3341 tb
= tPtr
->currentTextBlock
;
3343 WMRemoveFromArray(tPtr
->gfxItems
, (void *)tb
);
3346 WMDeleteEventHandler(W_VIEW(tb
->d
.widget
), ButtonPressMask
,
3347 handleWidgetPress
, tb
);
3348 WMUnmapWidget(tb
->d
.widget
);
3352 if (tPtr
->currentTextBlock
== tPtr
->firstTextBlock
) {
3353 if (tPtr
->currentTextBlock
->next
)
3354 tPtr
->currentTextBlock
->next
->prior
= NULL
;
3356 tPtr
->firstTextBlock
= tPtr
->currentTextBlock
->next
;
3357 tPtr
->currentTextBlock
= tPtr
->firstTextBlock
;
3359 } else if (tPtr
->currentTextBlock
== tPtr
->lastTextBlock
) {
3360 tPtr
->currentTextBlock
->prior
->next
= NULL
;
3361 tPtr
->lastTextBlock
= tPtr
->currentTextBlock
->prior
;
3362 tPtr
->currentTextBlock
= tPtr
->lastTextBlock
;
3364 tPtr
->currentTextBlock
->prior
->next
= tPtr
->currentTextBlock
->next
;
3365 tPtr
->currentTextBlock
->next
->prior
= tPtr
->currentTextBlock
->prior
;
3366 tPtr
->currentTextBlock
= tPtr
->currentTextBlock
->next
;
3373 WMDestroyTextBlock(WMText
*tPtr
, void *vtb
)
3375 TextBlock
*tb
= (TextBlock
*)vtb
;
3381 /* naturally, there's a danger to destroying
3382 widgets whose action brings us here:
3383 ie. press a button to destroy it... need to
3384 find a safer way. till then... this stays commented out */
3385 /* WMDestroyWidget(tb->d.widget);
3386 wfree(tb->d.widget); */
3387 tb
->d
.widget
= NULL
;
3389 WMReleasePixmap(tb
->d
.pixmap
);
3390 tb
->d
.pixmap
= NULL
;
3393 WMReleaseFont(tb
->d
.font
);
3396 WMReleaseColor(tb
->color
);
3397 if (tb
->sections
&& tb
->nsections
> 0)
3398 wfree(tb
->sections
);
3407 WMSetTextForegroundColor(WMText
*tPtr
, WMColor
*color
)
3413 tPtr
->fgGC
= WMColorGC(color
);
3415 tPtr
->fgGC
= WMColorGC(WMBlackColor(tPtr
->view
->screen
));
3421 WMSetTextBackgroundColor(WMText
*tPtr
, WMColor
*color
)
3427 tPtr
->bgGC
= WMColorGC(color
);
3428 W_SetViewBackgroundColor(tPtr
->view
, color
);
3430 tPtr
->bgGC
= WMColorGC(WMWhiteColor(tPtr
->view
->screen
));
3431 W_SetViewBackgroundColor(tPtr
->view
,
3432 WMWhiteColor(tPtr
->view
->screen
));
3439 WMSetTextRelief(WMText
*tPtr
, WMReliefType relief
)
3443 tPtr
->flags
.relief
= relief
;
3444 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
3448 WMSetTextHasHorizontalScroller(WMText
*tPtr
, Bool shouldhave
)
3453 if (shouldhave
&& !tPtr
->hS
) {
3454 tPtr
->hS
= WMCreateScroller(tPtr
);
3455 (W_VIEW(tPtr
->hS
))->attribs
.cursor
= tPtr
->view
->screen
->defaultCursor
;
3456 (W_VIEW(tPtr
->hS
))->attribFlags
|= CWOverrideRedirect
| CWCursor
;
3457 WMSetScrollerArrowsPosition(tPtr
->hS
, WSAMinEnd
);
3458 WMSetScrollerAction(tPtr
->hS
, scrollersCallBack
, tPtr
);
3459 WMMapWidget(tPtr
->hS
);
3460 } else if (!shouldhave
&& tPtr
->hS
) {
3461 WMUnmapWidget(tPtr
->hS
);
3462 WMDestroyWidget(tPtr
->hS
);
3468 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
3473 WMSetTextHasRuler(WMText
*tPtr
, Bool shouldhave
)
3478 if(shouldhave
&& !tPtr
->ruler
) {
3479 tPtr
->ruler
= WMCreateRuler(tPtr
);
3480 (W_VIEW(tPtr
->ruler
))->attribs
.cursor
=
3481 tPtr
->view
->screen
->defaultCursor
;
3482 (W_VIEW(tPtr
->ruler
))->attribFlags
|= CWOverrideRedirect
| CWCursor
;
3483 WMSetRulerReleaseAction(tPtr
->ruler
, rulerReleaseCallBack
, tPtr
);
3484 WMSetRulerMoveAction(tPtr
->ruler
, rulerMoveCallBack
, tPtr
);
3485 } else if(!shouldhave
&& tPtr
->ruler
) {
3486 WMShowTextRuler(tPtr
, False
);
3487 WMDestroyWidget(tPtr
->ruler
);
3490 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
3494 WMShowTextRuler(WMText
*tPtr
, Bool show
)
3501 if(tPtr
->flags
.monoFont
)
3504 tPtr
->flags
.rulerShown
= show
;
3506 WMMapWidget(tPtr
->ruler
);
3508 WMUnmapWidget(tPtr
->ruler
);
3511 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
3515 WMGetTextRulerShown(WMText
*tPtr
)
3523 return tPtr
->flags
.rulerShown
;
3528 WMSetTextHasVerticalScroller(WMText
*tPtr
, Bool shouldhave
)
3533 if (shouldhave
&& !tPtr
->vS
) {
3534 tPtr
->vS
= WMCreateScroller(tPtr
);
3535 (W_VIEW(tPtr
->vS
))->attribs
.cursor
= tPtr
->view
->screen
->defaultCursor
;
3536 (W_VIEW(tPtr
->vS
))->attribFlags
|= CWOverrideRedirect
| CWCursor
;
3537 WMSetScrollerArrowsPosition(tPtr
->vS
, WSAMaxEnd
);
3538 WMSetScrollerAction(tPtr
->vS
, scrollersCallBack
, tPtr
);
3539 WMMapWidget(tPtr
->vS
);
3540 } else if (!shouldhave
&& tPtr
->vS
) {
3541 WMUnmapWidget(tPtr
->vS
);
3542 WMDestroyWidget(tPtr
->vS
);
3548 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
3554 WMScrollText(WMText
*tPtr
, int amount
)
3559 if (amount
== 0 || !tPtr
->view
->flags
.realized
)
3563 if (tPtr
->vpos
> 0) {
3564 if (tPtr
->vpos
> abs(amount
)) tPtr
->vpos
+= amount
;
3568 int limit
= tPtr
->docHeight
- tPtr
->visible
.h
;
3569 if (tPtr
->vpos
< limit
) {
3570 if (tPtr
->vpos
< limit
-amount
) tPtr
->vpos
+= amount
;
3571 else tPtr
->vpos
= limit
;
3575 if (scroll
&& tPtr
->vpos
!= tPtr
->prevVpos
) {
3576 updateScrollers(tPtr
);
3579 tPtr
->prevVpos
= tPtr
->vpos
;
3584 WMPageText(WMText
*tPtr
, Bool direction
)
3586 if (!tPtr
) return False
;
3587 if (!tPtr
->view
->flags
.realized
) return False
;
3589 return WMScrollText(tPtr
, direction
?tPtr
->visible
.h
:-tPtr
->visible
.h
);
3593 WMSetTextEditable(WMText
*tPtr
, Bool editable
)
3597 tPtr
->flags
.editable
= editable
;
3601 WMGetTextEditable(WMText
*tPtr
)
3605 return tPtr
->flags
.editable
;
3609 WMSetTextIndentNewLines(WMText
*tPtr
, Bool indent
)
3613 tPtr
->flags
.indentNewLine
= indent
;
3617 WMSetTextIgnoresNewline(WMText
*tPtr
, Bool ignore
)
3621 tPtr
->flags
.ignoreNewLine
= ignore
;
3625 WMGetTextIgnoresNewline(WMText
*tPtr
)
3629 return tPtr
->flags
.ignoreNewLine
;
3633 WMSetTextUsesMonoFont(WMText
*tPtr
, Bool mono
)
3639 if(tPtr
->flags
.rulerShown
)
3640 WMShowTextRuler(tPtr
, False
);
3641 if(tPtr
->flags
.alignment
!= WALeft
)
3642 tPtr
->flags
.alignment
= WALeft
;
3645 tPtr
->flags
.monoFont
= mono
;
3646 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
3650 WMGetTextUsesMonoFont(WMText
*tPtr
)
3654 return tPtr
->flags
.monoFont
;
3659 WMSetTextDefaultFont(WMText
*tPtr
, WMFont
*font
)
3664 WMReleaseFont(tPtr
->dFont
);
3666 tPtr
->dFont
= WMRetainFont(font
);
3668 tPtr
->dFont
= WMRetainFont(WMSystemFontOfSize(tPtr
->view
->screen
, 12));
3672 WMGetTextDefaultFont(WMText
*tPtr
)
3677 return WMRetainFont(tPtr
->dFont
);
3681 WMSetTextDefaultColor(WMText
*tPtr
, WMColor
*color
)
3686 WMReleaseColor(tPtr
->dColor
);
3688 tPtr
->dColor
= WMRetainColor(color
);
3690 tPtr
->dColor
= WMBlackColor(tPtr
->view
->screen
);
3694 WMGetTextDefaultColor(WMText
*tPtr
)
3699 return WMRetainColor(tPtr
->dColor
);
3703 WMSetTextAlignment(WMText
*tPtr
, WMAlignment alignment
)
3707 if(tPtr
->flags
.monoFont
)
3708 tPtr
->flags
.alignment
= WALeft
;
3710 tPtr
->flags
.alignment
= alignment
;
3715 WMGetTextInsertType(WMText
*tPtr
)
3719 return tPtr
->flags
.prepend
;
3724 WMSetTextSelectionColor(WMText
*tPtr
, WMColor
*color
)
3726 if (!tPtr
|| !color
)
3729 setSelectionProperty(tPtr
, NULL
, color
, -1);
3733 WMGetTextSelectionColor(WMText
*tPtr
)
3740 tb
= tPtr
->currentTextBlock
;
3742 if (!tb
|| !tPtr
->flags
.ownsSelection
)
3753 WMSetTextSelectionFont(WMText
*tPtr
, WMFont
*font
)
3758 setSelectionProperty(tPtr
, font
, NULL
, -1) ;
3762 WMGetTextSelectionFont(WMText
*tPtr
)
3769 tb
= tPtr
->currentTextBlock
;
3771 if (!tb
|| !tPtr
->flags
.ownsSelection
)
3778 tb
= getFirstNonGraphicBlockFor(tb
, 1);
3782 return (tb
->selected
? tb
->d
.font
: NULL
);
3787 WMSetTextSelectionUnderlined(WMText
*tPtr
, int underlined
)
3789 if (!tPtr
|| (underlined
!=0 && underlined
!=1))
3792 setSelectionProperty(tPtr
, NULL
, NULL
, underlined
);
3797 WMGetTextSelectionUnderlined(WMText
*tPtr
)
3804 tb
= tPtr
->currentTextBlock
;
3806 if (!tb
|| !tPtr
->flags
.ownsSelection
)
3812 return tb
->underlined
;
3817 WMFreezeText(WMText
*tPtr
)
3822 tPtr
->flags
.frozen
= True
;
3827 WMThawText(WMText
*tPtr
)
3832 tPtr
->flags
.frozen
= False
;
3834 if(tPtr
->flags
.monoFont
) {
3835 int j
, c
= WMGetArrayItemCount(tPtr
->gfxItems
);
3838 /* make sure to unmap widgets no matter where they are */
3839 /* they'll be later remapped if needed by paintText */
3840 for(j
=0; j
<c
; j
++) {
3841 if ((tb
= (TextBlock
*) WMGetFromArray(tPtr
->gfxItems
, j
))) {
3842 if (tb
->object
&& ((W_VIEW(tb
->d
.widget
))->flags
.mapped
))
3843 WMUnmapWidget(tb
->d
.widget
);
3849 tPtr
->flags
.laidOut
= False
;
3850 layOutDocument(tPtr
);
3851 updateScrollers(tPtr
);
3853 tPtr
->flags
.needsLayOut
= False
;
3859 mystrrstr(char *haystack
, char *needle
, unsigned short len
, char *end
,
3864 if(!haystack
|| !needle
)
3867 for (ptr
= haystack
-2; ptr
> end
; ptr
--) {
3869 if (*ptr
== *needle
&& !strncmp(ptr
, needle
, len
))
3872 if (tolower(*ptr
) == tolower(*needle
) &&
3873 strncasecmp(ptr
, needle
, len
))
3883 WMFindInTextStream(WMText
*tPtr
, char *needle
, Bool direction
,
3890 if (!tPtr
|| !needle
)
3893 if (! (tb
= tPtr
->currentTextBlock
)) {
3894 if (! (tb
= ( (direction
> 0) ?
3895 tPtr
->firstTextBlock
: tPtr
->lastTextBlock
) ) ){
3899 /* if(tb != ((direction>0) ?tPtr->firstTextBlock : tPtr->lastTextBlock))
3900 tb = (direction>0) ? tb->next : tb->prior; */
3901 if(tb
!= tPtr
->lastTextBlock
)
3909 if(pos
+1 < tb
->used
)
3912 if(tb
->used
- pos
> 0 && pos
> 0) {
3913 char tmp
= tb
->text
[tb
->used
];
3914 tb
->text
[tb
->used
] = 0;
3916 output(&tb
->text
[pos
], tb
->used
- pos
);
3918 mark
= strstr(&tb
->text
[pos
], needle
);
3920 mark
= mystrrstr(&tb
->text
[pos
], needle
,
3921 strlen(needle
), tb
->text
, caseSensitive
);
3923 tb
->text
[tb
->used
] = tmp
;
3930 WMFont
*font
= tPtr
->flags
.monoFont
?tPtr
->dFont
:tb
->d
.font
;
3932 tPtr
->tpos
= (int)(mark
- tb
->text
);
3933 tPtr
->currentTextBlock
= tb
;
3934 updateCursorPosition(tPtr
);
3935 tPtr
->sel
.y
= tPtr
->cursor
.y
+5;
3936 tPtr
->sel
.h
= tPtr
->cursor
.h
-10;
3937 tPtr
->sel
.x
= tPtr
->cursor
.x
+1;
3938 tPtr
->sel
.w
= WMIN(WMWidthOfString(font
,
3939 &tb
->text
[tPtr
->tpos
], strlen(needle
)),
3940 tPtr
->docWidth
- tPtr
->sel
.x
);
3941 tPtr
->flags
.ownsSelection
= True
;
3948 tb
= (direction
>0) ? tb
->next
: tb
->prior
;