2 * WINGs WMText: multi-line/font/color/graphic text widget
4 * Copyright (c) 1999-2000 Nwanua Elumeze <nwanua@windowmaker.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <X11/keysym.h>
24 #include <X11/Xatom.h>
31 * - FIX wrap... long lines that don't fit are not char wrapped yet.
32 * - FIX html parser: 1. <b>foo</i> should STILL BE BOLD!
33 * - 2. " foo > bar " should not confuse it.
34 * - change Array stuffs to WMArray
35 * - assess danger of destroying widgets whose actions link to other pages
36 * - integrate WMConvertFontTo* functions into WINGs proper (fontpanel)?
37 * - change cursor shape around pixmaps
38 * - redo blink code to reduce paint event... use pixmap buffer...
39 * - add paragraph support (full) and '\n' code in getStream..
40 * - use currentTextBlock and neighbours for fast paint and layout
41 * - replace copious uses of Refreshtext with appropriate layOut()...
42 * - WMFindInTextStream should also highlight found text...
43 * - add full support for Horizontal Scroll
47 /* a Section is a section of a TextBlock that describes what parts
48 of a TextBlock has been laid out on which "line"...
49 o this greatly aids redraw, scroll and selection.
50 o this is created during layoutLine, but may be later modified.
51 o there may be many Sections per TextBlock, hence the array */
53 unsigned int x
, y
; /* where to draw it from */
54 unsigned short w
, h
; /* its width and height */
55 unsigned short begin
; /* where the layout begins */
56 unsigned short end
; /* where it ends */
57 unsigned short last
:1; /* is it the last section on a "line"? */
58 unsigned int _y
:31; /* the "line" it and other textblocks are on */
62 /* a TextBlock is a doubly-linked list of TextBlocks containing:
63 o text for the block, color and font
64 o or a pointer to the pixmap
65 o OR a pointer to the widget and the (text) description for its graphic
68 typedef struct _TextBlock
{
69 struct _TextBlock
*next
; /* next text block in linked list */
70 struct _TextBlock
*prior
; /* prior text block in linked list */
72 char *text
; /* pointer to text (could be kanji) */
73 /* or to the object's description */
75 WMFont
*font
; /* the font */
76 WMWidget
*widget
; /* the embedded widget */
77 WMPixmap
*pixmap
; /* the pixmap */
78 } d
; /* description */
80 unsigned short used
; /* number of chars in this block */
81 unsigned short allocated
; /* size of allocation (in chars) */
82 WMColor
*color
; /* the color */
84 Section
*sections
; /* the region for layouts (a growable array) */
85 /* an _array_! of size _nsections_ */
87 unsigned short s_begin
; /* where the selection begins */
88 unsigned short s_end
; /* where it ends */
90 unsigned int first
:1; /* first TextBlock in paragraph */
91 unsigned int blank
:1; /* ie. blank paragraph */
92 unsigned int kanji
:1; /* is of 16-bit characters or not */
93 unsigned int graphic
:1; /* graphic or text: text=0 */
94 unsigned int object
:1; /* embedded object or pixmap */
95 unsigned int underlined
:1; /* underlined or not */
96 unsigned int selected
:1; /* selected or not */
97 unsigned int nsections
:8; /* over how many "lines" a TextBlock wraps */
98 int script
:8; /* script in points: negative for subscript */
99 unsigned int marginN
:8; /* which of the margins in the tPtr to use */
100 unsigned int nClicks
:2; /* single, double, triple clicks */
101 unsigned int RESERVED
:7;
105 /* somehow visible.h beats the hell outta visible.size.height :-) */
114 typedef struct W_Text
{
115 W_Class widgetClass
; /* the class number of this widget */
116 W_View
*view
; /* the view referring to this instance */
118 WMRuler
*ruler
; /* the ruler widget to manipulate paragraphs */
120 WMScroller
*vS
; /* the vertical scroller */
121 unsigned int vpos
; /* the current vertical position */
122 unsigned int prevVpos
; /* the previous vertical position */
124 WMScroller
*hS
; /* the horizontal scroller */
125 unsigned int hpos
; /* the current horizontal position */
126 unsigned int prevHpos
; /* the previous horizontal position */
128 WMFont
*dFont
; /* the default font */
129 WMColor
*dColor
; /* the default color */
130 WMPixmap
*dBulletPix
; /* the default pixmap for bullets */
132 GC bgGC
; /* the background GC to draw with */
133 GC fgGC
; /* the foreground GC to draw with */
134 Pixmap db
; /* the buffer on which to draw */
136 myRect visible
; /* the actual rectangle that can be drawn into */
137 myRect cursor
; /* the position and (height) of cursor */
138 myRect sel
; /* the selection rectangle */
140 WMPoint clicked
; /* where in the _document_ was clicked */
142 unsigned short tpos
; /* the position in the currentTextBlock */
143 unsigned short docWidth
; /* the width of the entire document */
144 unsigned int docHeight
; /* the height of the entire document */
146 TextBlock
*firstTextBlock
;
147 TextBlock
*lastTextBlock
;
148 TextBlock
*currentTextBlock
;
150 WMArray
*gfxItems
; /* a nice array of graphic items */
153 WMHandlerID timerID
; /* for nice twinky-winky */
158 WMTextDelegate
*delegate
;
161 WMRulerMargins
*margins
; /* an array of margins */
163 unsigned int nMargins
:8; /* the total number of margins in use */
165 unsigned int monoFont
:1; /* whether to ignore formats */
166 unsigned int focused
:1; /* whether this instance has input focus */
167 unsigned int editable
:1; /* "silly user, you can't edit me" */
168 unsigned int ownsSelection
:1; /* "I ownz the current selection!" */
169 unsigned int pointerGrabbed
:1;/* "heh, gib me pointer" */
170 unsigned int buttonHeld
:1; /* the user is holding down the button */
171 unsigned int extendSelection
:1; /* shift-drag to select more regions */
173 unsigned int rulerShown
:1; /* whether the ruler is shown or not */
174 unsigned int frozen
:1; /* whether screen updates are to be made */
175 unsigned int cursorShown
:1; /* whether to show the cursor */
176 unsigned int clickPos
:1; /* clicked before=0 or after=1 a graphic: */
177 /* (within counts as after too) */
179 unsigned int horizOnDemand
:1;/* if a large image should appear*/
180 unsigned int needsRefresh
:1; /* in case of Append/Deletes */
181 unsigned int ignoreNewLine
:1;/* turn it into a ' ' in streams > 1 */
182 unsigned int laidOut
:1; /* have the TextBlocks all been laid out */
183 unsigned int waitingForSelection
:1; /* I don't wanna wait in vain... */
184 unsigned int prepend
:1; /* prepend=1, append=0 (for parsers) */
185 unsigned int parsingHTML
:1; /* how to interpret a stream of text */
186 WMAlignment alignment
:2; /* the alignment for text */
187 WMReliefType relief
:3; /* the relief to display with */
188 unsigned int RESERVED
:2;
193 #define NOTIFY(T,C,N,A) { WMNotification *notif = WMCreateNotification(N,T,A);\
194 if ((T)->delegate && (T)->delegate->C)\
195 (*(T)->delegate->C)((T)->delegate,notif);\
196 WMPostNotification(notif);\
197 WMReleaseNotification(notif);}
202 * A hack to speed up caseless_equal. Thanks to Quincey Koziol for
203 * developing it for the "chimera" folks so I could use it 7 years later ;-)
204 * Constraint: nothing but '\0' may map to 0
206 static unsigned char map_table
[256] = {
207 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,
208 28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,
209 52,53,54,55,56,57,58,59,60,61,62,63,64,97,98,99,100,101,102,103,104,105,
210 106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,91,
211 92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
212 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,
213 130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,
214 148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,
215 166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,
216 184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,
217 202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,
218 220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,
219 238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255};
221 void HTMLParser(Text
*tPtr
, char *stream
);
222 #define MAX_TOKEN_SIZE 255
223 #define MAX_TEXT_SIZE 1023
225 #define TOLOWER(x) (map_table[(int)x])
227 #define ISALNUM(x) ( ((x>='0') && (x<='9')) \
228 || ((x>='a') && (x<='z')) || ((x>='A') && x<='Z'))
231 output(char *ptr
, int len
)
236 /* printf(" s is [%s] (%d)\n", s, strlen(s)); */
241 /* tb->text doesn't necessarily end in '\0' hmph! (strchr) */
243 mystrchr(char *s
, char needle
, unsigned short len
)
247 if (!haystack
|| len
< 1)
250 while ( (int) (haystack
- s
) < len
) {
251 if (*haystack
== needle
)
258 /* tb->text doesn't necessarily end in '\0' hmph! (strstr) */
260 mystrstr(char *haystack
, char *needle
, unsigned short len
)
262 if (!haystack
|| !needle
|| len
< 1) {
265 char *s
= wmalloc(len
+1);
268 memcpy(s
, haystack
, len
);
270 r
= (strstr(s
, needle
));
277 mystrcasecmp(const unsigned char *s1
, const unsigned char *s2
,
278 int len
, Bool caseSensitive
)
280 if (!*s1
|| !*s2
|| len
<1)
283 while (*s2
!= '\0' && len
>0) {
284 if ( (caseSensitive
? (*s1
) : TOLOWER (*s1
))
285 != (caseSensitive
? (*s2
) : TOLOWER (*s2
)))
292 return (*s1
=='\0' || !ISALNUM(*s1
))?1:0;
298 #define CURSOR_BLINK_ON_DELAY 600
299 #define CURSOR_BLINK_OFF_DELAY 400
302 static char *default_bullet
[] = {
304 " c None s None", ". c black",
305 "X c white", "o c #808080",
314 handleEvents(XEvent
*event
, void *data
);
318 getMarginNumber(Text
*tPtr
, WMRulerMargins
*margins
)
322 for(i
=0; i
< tPtr
->nMargins
; i
++) {
324 if(WMIsMarginEqualToMargin(&tPtr
->margins
[i
], margins
))
334 newMargin(Text
*tPtr
, WMRulerMargins
*margins
)
339 tPtr
->margins
[0].retainCount
++;
343 n
= getMarginNumber(tPtr
, margins
);
347 tPtr
->margins
= wrealloc(tPtr
->margins
,
348 (++tPtr
->nMargins
)*sizeof(WMRulerMargins
));
350 n
= tPtr
->nMargins
-1;
351 tPtr
->margins
[n
].left
= margins
->left
;
352 tPtr
->margins
[n
].first
= margins
->first
;
353 tPtr
->margins
[n
].body
= margins
->body
;
354 tPtr
->margins
[n
].right
= margins
->right
;
355 /* for each tab... */
356 tPtr
->margins
[n
].retainCount
= 1;
358 tPtr
->margins
[n
].retainCount
++;
365 sectionWasSelected(Text
*tPtr
, TextBlock
*tb
, XRectangle
*rect
, int s
)
367 unsigned short i
, w
, lw
, selected
= False
, extend
= False
;
371 /* if selection rectangle completely encloses the section */
372 if ((tb
->sections
[s
]._y
>= tPtr
->visible
.y
+ tPtr
->sel
.y
)
373 && (tb
->sections
[s
]._y
+ tb
->sections
[s
].h
374 <= tPtr
->visible
.y
+ tPtr
->sel
.y
+ tPtr
->sel
.h
) ) {
376 sel
.w
= tPtr
->visible
.w
;
377 selected
= extend
= True
;
379 /* or if it starts on a line and then goes further down */
380 } else if ((tb
->sections
[s
]._y
<= tPtr
->visible
.y
+ tPtr
->sel
.y
)
381 && (tb
->sections
[s
]._y
+ tb
->sections
[s
].h
382 <= tPtr
->visible
.y
+ tPtr
->sel
.y
+ tPtr
->sel
.h
)
383 && (tb
->sections
[s
]._y
+ tb
->sections
[s
].h
384 >= tPtr
->visible
.y
+ tPtr
->sel
.y
) ) {
385 sel
.x
= WMAX(tPtr
->sel
.x
, tPtr
->clicked
.x
);
386 sel
.w
= tPtr
->visible
.w
;
387 selected
= extend
= True
;
389 /* or if it begins before a line, but ends on it */
390 } else if ((tb
->sections
[s
]._y
>= tPtr
->visible
.y
+ tPtr
->sel
.y
)
391 && (tb
->sections
[s
]._y
+ tb
->sections
[s
].h
392 >= tPtr
->visible
.y
+ tPtr
->sel
.y
+ tPtr
->sel
.h
)
393 && (tb
->sections
[s
]._y
394 <= tPtr
->visible
.y
+ tPtr
->sel
.y
+ tPtr
->sel
.h
) ) {
396 if (1||tPtr
->sel
.x
+ tPtr
->sel
.w
> tPtr
->clicked
.x
)
397 sel
.w
= tPtr
->sel
.x
+ tPtr
->sel
.w
;
404 /* or if the selection rectangle lies entirely within a line */
405 } else if ((tb
->sections
[s
]._y
<= tPtr
->visible
.y
+ tPtr
->sel
.y
)
406 && (tPtr
->sel
.w
>= 2)
407 && (tb
->sections
[s
]._y
+ tb
->sections
[s
].h
408 >= tPtr
->visible
.y
+ tPtr
->sel
.y
+ tPtr
->sel
.h
) ) {
417 /* if not within (modified) selection rectangle */
418 if ( tb
->sections
[s
].x
> sel
.x
+ sel
.w
419 || tb
->sections
[s
].x
+ tb
->sections
[s
].w
< sel
.x
)
423 if ( tb
->sections
[s
].x
+ tb
->sections
[s
].w
<= sel
.x
+ sel
.w
424 && tb
->sections
[s
].x
>= sel
.x
) {
425 rect
->width
= tb
->sections
[s
].w
;
426 rect
->x
= tb
->sections
[s
].x
;
431 i
= tb
->sections
[s
].begin
;
434 if (0&& tb
->sections
[s
].x
>= sel
.x
) {
435 tb
->s_begin
= tb
->sections
[s
].begin
;
439 while (++i
<= tb
->sections
[s
].end
) {
441 w
= WMWidthOfString(tb
->d
.font
, &(tb
->text
[i
-1]), 1);
444 if (lw
+ tb
->sections
[s
].x
>= sel
.x
445 || i
== tb
->sections
[s
].end
) {
448 tb
->s_begin
= (tb
->selected
? WMIN(tb
->s_begin
, i
) : i
);
453 if (i
> tb
->sections
[s
].end
) {
454 printf("WasSelected: (i > tb->sections[s].end) \n");
458 _selEnd
: rect
->x
= tb
->sections
[s
].x
+ lw
;
460 while(++i
<= tb
->sections
[s
].end
) {
462 w
= WMWidthOfString(tb
->d
.font
, &(tb
->text
[i
-1]), 1);
465 if (lw
+ rect
->x
>= sel
.x
+ sel
.w
466 || i
== tb
->sections
[s
].end
) {
468 if (i
!= tb
->sections
[s
].end
) {
474 if (tb
->sections
[s
].last
&& sel
.x
+ sel
.w
475 >= tb
->sections
[s
].x
+ tb
->sections
[s
].w
477 rect
->width
+= (tPtr
->visible
.w
- rect
->x
- lw
);
480 tb
->s_end
= (tb
->selected
? WMAX(tb
->s_end
, i
) : i
);
486 rect
->y
= tb
->sections
[s
]._y
- tPtr
->vpos
;
487 rect
->height
= tb
->sections
[s
].h
;
488 if(tb
->graphic
) { printf("graphic s%d h%d\n", s
,tb
->sections
[s
].h
);}
495 setSelectionProperty(WMText
*tPtr
, WMFont
*font
, WMColor
*color
)
500 if((font
&& color
) || (!font
&& !color
))
506 tb
= tPtr
->firstTextBlock
;
507 if (!tb
|| !tPtr
->flags
.ownsSelection
)
511 if (tPtr
->flags
.monoFont
|| tb
->selected
) {
513 if (tPtr
->flags
.monoFont
|| (tb
->s_end
- tb
->s_begin
== tb
->used
)
518 WMReleaseFont(tb
->d
.font
);
519 tb
->d
.font
= WMRetainFont(font
);
522 WMReleaseColor(tb
->color
);
523 tb
->color
= WMRetainColor(color
);
526 } else if (tb
->s_end
<= tb
->used
&& tb
->s_begin
< tb
->s_end
) {
530 TextBlock
*ntb
= (TextBlock
*)
531 WMCreateTextBlockWithText(tPtr
,
532 &(tb
->text
[tb
->s_begin
]),
533 (isFont
?font
:tb
->d
.font
),
534 (isFont
?tb
->color
:color
),
535 False
, (tb
->s_end
- tb
->s_begin
));
538 ntb
->selected
= True
;
540 ntb
->s_end
= ntb
->used
;
541 tPtr
->currentTextBlock
= tb
;
542 WMAppendTextBlock(tPtr
, ntb
);
543 tb
= tPtr
->currentTextBlock
;
546 if (otb
->used
- otb
->s_end
> 0) {
548 WMCreateTextBlockWithText(tPtr
,
549 &(otb
->text
[otb
->s_end
]), otb
->d
.font
, otb
->color
,
550 False
, otb
->used
- otb
->s_end
);
553 ntb
->selected
= False
;
554 WMAppendTextBlock(tPtr
, ntb
);
555 tb
= tPtr
->currentTextBlock
;
559 otb
->selected
= False
;
560 otb
->used
= otb
->s_begin
;
567 WMRefreshText(tPtr
, tPtr
->vpos
, tPtr
->hpos
);
572 removeSelection(Text
*tPtr
)
574 TextBlock
*tb
= NULL
;
576 if (!(tb
= tPtr
->firstTextBlock
))
582 if ( (tb
->s_end
- tb
->s_begin
== tb
->used
) || tb
->graphic
) {
583 tPtr
->currentTextBlock
= tb
;
584 WMDestroyTextBlock(tPtr
, WMRemoveTextBlock(tPtr
));
585 tb
= tPtr
->currentTextBlock
;
590 } else if (tb
->s_end
<= tb
->used
) {
591 memmove(&(tb
->text
[tb
->s_begin
]),
592 &(tb
->text
[tb
->s_end
]), tb
->used
- tb
->s_end
);
593 tb
->used
-= (tb
->s_end
- tb
->s_begin
);
594 tb
->selected
= False
;
595 tPtr
->tpos
= tb
->s_begin
;
606 paintText(Text
*tPtr
)
612 int len
, y
, c
, s
, done
=False
, prev_y
=-23;
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
->firstTextBlock
))
626 if (tPtr
->flags
.ownsSelection
)
627 greyGC
= WMColorGC(WMGrayColor(scr
));
631 /* first, place all text that can be viewed */
632 while (!done
&& tb
) {
639 tb
->selected
= False
;
641 for(s
=0; s
<tb
->nsections
&& !done
; s
++) {
643 if (tb
->sections
[s
]._y
> tPtr
->vpos
+ tPtr
->visible
.h
) {
648 if ( tb
->sections
[s
].y
+ tb
->sections
[s
].h
< tPtr
->vpos
)
651 if (tPtr
->flags
.monoFont
) {
656 gc
= WMColorGC(tb
->color
);
659 if (tPtr
->flags
.ownsSelection
) {
662 if ( sectionWasSelected(tPtr
, tb
, &rect
, s
)) {
664 XFillRectangle(dpy
, tPtr
->db
, greyGC
,
665 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
669 prev_y
= tb
->sections
[s
]._y
;
671 len
= tb
->sections
[s
].end
- tb
->sections
[s
].begin
;
672 text
= &(tb
->text
[tb
->sections
[s
].begin
]);
673 y
= tb
->sections
[s
].y
- tPtr
->vpos
;
674 WMDrawString(scr
, tPtr
->db
, gc
, font
,
675 tb
->sections
[s
].x
- tPtr
->hpos
, y
, text
, len
);
677 if (tb
->underlined
) {
678 XDrawLine(dpy
, tPtr
->db
, gc
,
679 tb
->sections
[s
].x
- tPtr
->hpos
,
681 tb
->sections
[s
].x
+ tb
->sections
[s
].w
- tPtr
->hpos
,
687 tb
= (!done
? tb
->next
: NULL
);
691 /* now , show all graphic items that can be viewed */
692 c
= WMGetArrayItemCount(tPtr
->gfxItems
);
693 if (c
> 0 && !tPtr
->flags
.monoFont
) {
697 tb
= (TextBlock
*) WMGetFromArray(tPtr
->gfxItems
, j
);
698 if (tb
->sections
[0]._y
+ tb
->sections
[0].h
<= tPtr
->vpos
699 || tb
->sections
[0]._y
>= tPtr
->vpos
+ tPtr
->visible
.h
) {
702 if ((W_VIEW(tb
->d
.widget
))->flags
.mapped
) {
703 WMUnmapWidget(tb
->d
.widget
);
708 if (!(W_VIEW(tb
->d
.widget
))->flags
.mapped
) {
709 if (!(W_VIEW(tb
->d
.widget
))->flags
.realized
)
710 WMRealizeWidget(tb
->d
.widget
);
711 WMMapWidget(tb
->d
.widget
);
712 WMLowerWidget(tb
->d
.widget
);
716 if (tPtr
->flags
.ownsSelection
) {
719 if ( sectionWasSelected(tPtr
, tb
, &rect
, s
)) {
721 XFillRectangle(dpy
, tPtr
->db
, greyGC
,
722 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
727 WMMoveWidget(tb
->d
.widget
,
728 tb
->sections
[0].x
- tPtr
->hpos
,
729 tb
->sections
[0].y
- tPtr
->vpos
);
730 h
= WMWidgetHeight(tb
->d
.widget
) + 1;
733 WMDrawPixmap(tb
->d
.pixmap
, tPtr
->db
,
734 tb
->sections
[0].x
- tPtr
->hpos
,
735 tb
->sections
[0].y
- tPtr
->vpos
);
736 h
= tb
->d
.pixmap
->height
+ 1;
740 if (tb
->underlined
) {
741 XDrawLine(dpy
, tPtr
->db
, WMColorGC(tb
->color
),
743 tb
->sections
[0].y
+ h
,
744 tb
->sections
[0].x
+ tb
->sections
[0].w
,
745 tb
->sections
[0].y
+ h
);
750 if (tPtr
->flags
.editable
&& tPtr
->flags
.cursorShown
751 && tPtr
->cursor
.x
!= -23 && tPtr
->flags
.focused
) {
752 int y
= tPtr
->cursor
.y
- tPtr
->vpos
;
753 XDrawLine(dpy
, tPtr
->db
, tPtr
->fgGC
,
755 tPtr
->cursor
.x
, y
+ tPtr
->cursor
.h
);
758 XCopyArea(dpy
, tPtr
->db
, win
, tPtr
->bgGC
, 0, 0,
759 tPtr
->visible
.w
, tPtr
->visible
.h
,
760 tPtr
->visible
.x
, tPtr
->visible
.y
);
762 W_DrawRelief(scr
, win
, 0, 0,
763 tPtr
->view
->size
.width
, tPtr
->view
->size
.height
,
766 if (tPtr
->ruler
&& tPtr
->flags
.rulerShown
)
767 XDrawLine(dpy
, win
, tPtr
->fgGC
,
768 2, 42, tPtr
->view
->size
.width
-4, 42);
776 blinkCursor(void *data
)
778 Text
*tPtr
= (Text
*)data
;
780 if (tPtr
->flags
.cursorShown
) {
781 tPtr
->timerID
= WMAddTimerHandler(CURSOR_BLINK_OFF_DELAY
,
784 tPtr
->timerID
= WMAddTimerHandler(CURSOR_BLINK_ON_DELAY
,
788 tPtr
->flags
.cursorShown
= !tPtr
->flags
.cursorShown
;
793 getFirstNonGraphicBlockFor(TextBlock
*tb
, short dir
)
800 tb
= (dir
? tb
->next
: tb
->prior
);
808 updateCursorPosition(Text
*tPtr
)
810 TextBlock
*tb
= NULL
;
813 if(tPtr
->flags
.needsRefresh
)
814 WMRefreshText(tPtr
, tPtr
->vpos
, tPtr
->hpos
);
816 if (! (tb
= tPtr
->currentTextBlock
)) {
817 if (! (tb
= tPtr
->firstTextBlock
)) {
819 tPtr
->cursor
.h
= tPtr
->dFont
->height
;
827 y
= tb
->sections
[0].y
;
828 h
= tb
->sections
[0].h
;
829 x
= tb
->sections
[0].x
;
831 if(tPtr
->tpos
> tb
->used
)
832 tPtr
->tpos
= tb
->used
;
834 for(s
=0; s
<tb
->nsections
; s
++) {
836 if(tPtr
->tpos
>= tb
->sections
[s
].begin
837 && tPtr
->tpos
<= tb
->sections
[s
].end
)
841 y
= tb
->sections
[s
]._y
;
842 h
= tb
->sections
[s
].h
;
843 x
= tb
->sections
[s
].x
+ WMWidthOfString(
844 (tPtr
->flags
.monoFont
?tPtr
->dFont
:tb
->d
.font
),
845 &tb
->text
[tb
->sections
[s
].begin
],
846 tPtr
->tpos
- tb
->sections
[s
].begin
);
857 cursorToTextPosition(Text
*tPtr
, int x
, int y
)
859 TextBlock
*tb
= NULL
;
860 int done
=False
, s
, pos
, len
, _w
, _y
, dir
=1; /* 1 == "down" */
863 if(tPtr
->flags
.needsRefresh
)
864 WMRefreshText(tPtr
, tPtr
->vpos
, tPtr
->hpos
);
866 y
+= (tPtr
->vpos
- tPtr
->visible
.y
);
870 x
-= (tPtr
->visible
.x
- 2);
874 /* clicked is relative to document, not window... */
878 if (! (tb
= tPtr
->currentTextBlock
)) {
879 if (! (tb
= tPtr
->firstTextBlock
)) {
881 tPtr
->cursor
.h
= tPtr
->dFont
->height
;
888 /* first, which direction? Most likely, newly clicked
889 position will be close to previous */
890 dir
= !(y
<= tb
->sections
[0].y
);
891 if ( ( y
<= tb
->sections
[0]._y
+ tb
->sections
[0].h
)
892 && (y
>= tb
->sections
[0]._y
) ) {
893 /* if it's on the same line */
894 if(x
< tb
->sections
[0].x
)
896 if(x
>= tb
->sections
[0].x
)
900 tb
= tPtr
->firstTextBlock
;
903 if (tPtr
->flags
.monoFont
&& tb
->graphic
) {
904 tb
= getFirstNonGraphicBlockFor(tb
, 1);
906 tPtr
->currentTextBlock
=
907 (dir
? tPtr
->lastTextBlock
: tPtr
->firstTextBlock
);
913 s
= (dir
? 0 : tb
->nsections
-1);
914 if ( y
>= tb
->sections
[s
]._y
915 && y
<= tb
->sections
[s
]._y
+ tb
->sections
[s
].h
) {
919 /* get the first section of the TextBlock that lies about
920 the vertical click point */
922 while (!done
&& tb
) {
924 if (tPtr
->flags
.monoFont
&& tb
->graphic
) {
930 s
= (dir
? 0 : tb
->nsections
-1);
931 while (!done
&& (dir
? (s
<tb
->nsections
) : (s
>=0) )) {
933 if ( (dir
? (y
<= tb
->sections
[s
]._y
+ tb
->sections
[s
].h
) :
934 ( y
>= tb
->sections
[s
]._y
) ) ) {
942 if ( (dir
? tb
->next
: tb
->prior
)) {
943 tb
= (dir
? tb
->next
: tb
->prior
);
946 break; /* goto _doneH; */
952 if (s
<0 || s
>=tb
->nsections
) {
953 s
= (dir
? tb
->nsections
-1 : 0);
957 /* we have the line, which TextBlock on that line is it? */
959 if (tPtr
->flags
.monoFont
&& tb
->graphic
)
960 tb
= getFirstNonGraphicBlockFor(tb
, dir
);
962 if ((dir
? tb
->sections
[s
].x
>= x
: tb
->sections
[s
].x
< x
))
970 text
= &(tb
->text
[tb
->sections
[s
].begin
]);
971 len
= tb
->sections
[s
].end
- tb
->sections
[s
].begin
;
972 _w
= WMWidthOfString(tb
->d
.font
, text
, len
);
974 printf("here %d %d \n", tb
->sections
[s
].x
+ _w
, x
);
975 if ((dir
? tb
->sections
[s
].x
+ _w
< x
: tb
->sections
[s
].x
+ _w
>= x
)) {
976 pos
= tb
->sections
[s
].end
;
977 tPtr
->cursor
.x
= tb
->sections
[s
].x
+ _w
;
981 _y
= tb
->sections
[s
]._y
;
986 if (tPtr
->flags
.monoFont
&& tb
->graphic
) {
987 tb
= (dir
? tb
->next
: tb
->prior
);
994 _w
= WMWidgetWidth(tb
->d
.widget
);
996 _w
= tb
->d
.pixmap
->width
;
998 text
= &(tb
->text
[tb
->sections
[s
].begin
]);
999 len
= tb
->sections
[s
].end
- tb
->sections
[s
].begin
;
1000 _w
= WMWidthOfString(tb
->d
.font
, text
, len
);
1001 if (tb
->sections
[s
].x
+ _w
>= x
)
1006 if (tb
->sections
[s
].x
<= x
)
1010 if ((dir
? tb
->next
: tb
->prior
)) {
1011 TextBlock
*nxt
= (dir
? tb
->next
: tb
->prior
);
1012 if (tPtr
->flags
.monoFont
&& nxt
->graphic
) {
1013 nxt
= getFirstNonGraphicBlockFor(nxt
, dir
);
1016 tPtr
->cursor
.x
= tb
->sections
[s
].x
;
1021 if (_y
!= nxt
->sections
[0]._y
) {
1022 /* this must be the last/first on this line. stop */
1023 pos
= (dir
? tb
->sections
[s
].end
: 0);
1024 tPtr
->cursor
.x
= tb
->sections
[s
].x
;
1028 tPtr
->cursor
.x
+= WMWidgetWidth(tb
->d
.widget
);
1030 tPtr
->cursor
.x
+= tb
->d
.pixmap
->width
;
1031 } else if (pos
> tb
->sections
[s
].begin
) {
1033 WMWidthOfString(tb
->d
.font
,
1034 &(tb
->text
[tb
->sections
[s
].begin
]),
1035 pos
- tb
->sections
[s
].begin
);
1042 if ( (dir
? tb
->next
: tb
->prior
)) {
1043 tb
= (dir
? tb
->next
: tb
->prior
);
1050 s
= (dir
? 0 : tb
->nsections
-1);
1053 /* we have said TextBlock, now where within it? */
1054 if (tb
&& !tb
->graphic
) {
1055 WMFont
*f
= tb
->d
.font
;
1056 len
= tb
->sections
[s
].end
- tb
->sections
[s
].begin
;
1057 text
= &(tb
->text
[tb
->sections
[s
].begin
]);
1059 _w
= x
- tb
->sections
[s
].x
;
1062 while (pos
<len
&& WMWidthOfString(f
, text
, pos
+1) < _w
)
1065 tPtr
->cursor
.x
= tb
->sections
[s
].x
+
1066 (pos
? WMWidthOfString(f
, text
, pos
) : 0);
1068 pos
+= tb
->sections
[s
].begin
;
1070 tPtr
->tpos
= (pos
<tb
->used
)? pos
: tb
->used
;
1074 printf("this app will surely crash :-)\n");
1076 tPtr
->currentTextBlock
= tb
;
1077 tPtr
->cursor
.h
= tb
->sections
[s
].h
;
1078 tPtr
->cursor
.y
= tb
->sections
[s
]._y
;
1083 autoSelectText(Text
*tPtr
, int clicks
)
1090 if(!(tb
= tPtr
->currentTextBlock
))
1095 if(tb
->text
[tPtr
->tpos
] == ' ')
1098 tPtr
->sel
.y
= tPtr
->cursor
.y
+5;
1099 tPtr
->sel
.h
= tPtr
->cursor
.h
-10;
1102 tPtr
->sel
.x
= tb
->sections
[0].x
;
1103 tPtr
->sel
.w
= tb
->sections
[0].w
;
1105 WMFont
*font
= tPtr
->flags
.monoFont
?tPtr
->dFont
:tb
->d
.font
;
1108 while(start
> 0 && tb
->text
[start
-1] != ' ')
1111 x
= tPtr
->cursor
.x
+ 0*WMWidthOfString(font
, &tb
->text
[start
], 1);
1112 if(tPtr
->tpos
> start
){
1113 output(&tb
->text
[start
], tPtr
->tpos
- start
);
1114 x
-= WMWidthOfString(font
, &tb
->text
[start
],
1115 tPtr
->tpos
- start
);
1117 tPtr
->sel
.x
= (x
<0?0:x
);
1119 if((mark
= mystrchr(&tb
->text
[start
], ' ', tb
->used
-start
))) {
1120 tPtr
->sel
.w
= WMWidthOfString(font
, &tb
->text
[start
],
1121 (int)(mark
- &tb
->text
[start
]));
1123 tPtr
->sel
.w
= tPtr
->docWidth
- tPtr
->sel
.x
;
1127 } else if(clicks
== 3) {
1128 tPtr
->sel
.x
= tPtr
->visible
.x
;
1129 tPtr
->sel
.w
= tPtr
->docWidth
;
1132 tPtr
->flags
.ownsSelection
= True
;
1138 updateScrollers(Text
*tPtr
)
1141 if (tPtr
->flags
.frozen
)
1145 if (tPtr
->docHeight
< tPtr
->visible
.h
) {
1146 WMSetScrollerParameters(tPtr
->vS
, 0, 1);
1149 float hmax
= (float)(tPtr
->docHeight
);
1150 WMSetScrollerParameters(tPtr
->vS
,
1151 ((float)tPtr
->vpos
)/(hmax
- (float)tPtr
->visible
.h
),
1152 (float)tPtr
->visible
.h
/hmax
);
1154 } else tPtr
->vpos
= 0;
1157 if (tPtr
->docWidth
< tPtr
->visible
.w
) {
1158 WMSetScrollerParameters(tPtr
->hS
, 0, 1);
1161 float wmax
= (float)(tPtr
->docWidth
);
1162 WMSetScrollerParameters(tPtr
->hS
,
1163 ((float)tPtr
->hpos
)/(wmax
- (float)tPtr
->visible
.w
),
1164 (float)tPtr
->visible
.w
/wmax
);
1166 } else tPtr
->hpos
= 0;
1170 scrollersCallBack(WMWidget
*w
, void *self
)
1172 Text
*tPtr
= (Text
*)self
;
1173 Bool scroll
= False
;
1174 Bool dimple
= False
;
1177 if (!tPtr
->view
->flags
.realized
|| tPtr
->flags
.frozen
)
1180 if (w
== tPtr
->vS
) {
1182 height
= tPtr
->visible
.h
;
1184 which
= WMGetScrollerHitPart(tPtr
->vS
);
1186 case WSDecrementLine
:
1187 if (tPtr
->vpos
> 0) {
1188 if (tPtr
->vpos
>16) tPtr
->vpos
-=16;
1192 case WSIncrementLine
: {
1193 int limit
= tPtr
->docHeight
- height
;
1194 if (tPtr
->vpos
< limit
) {
1195 if (tPtr
->vpos
<limit
-16) tPtr
->vpos
+=16;
1196 else tPtr
->vpos
=limit
;
1199 case WSDecrementPage
:
1200 tPtr
->vpos
-= height
;
1206 printf("dimple needs to jump to mouse location ;-/\n");
1208 case WSIncrementPage
:
1209 tPtr
->vpos
+= height
;
1210 if (tPtr
->vpos
> (tPtr
->docHeight
- height
))
1211 tPtr
->vpos
= tPtr
->docHeight
- height
;
1214 printf("dimple needs to jump to mouse location ;-/\n");
1219 tPtr
->vpos
= WMGetScrollerValue(tPtr
->vS
)
1220 * (float)(tPtr
->docHeight
- height
);
1226 printf("WSNoPart, WSKnobSlot\n");
1228 float hmax
= (float)(tPtr
->docHeight
);
1229 ((float)tPtr
->vpos
)/(hmax
- (float)tPtr
->visible
.h
),
1230 (float)tPtr
->visible
.h
/hmax
;
1231 dimple
=where mouse is
.
1235 scroll
= (tPtr
->vpos
!= tPtr
->prevVpos
);
1236 tPtr
->prevVpos
= tPtr
->vpos
;
1239 if (w
== tPtr
->hS
) {
1240 int width
= tPtr
->visible
.w
;
1242 which
= WMGetScrollerHitPart(tPtr
->hS
);
1244 case WSDecrementLine
:
1245 if (tPtr
->hpos
> 0) {
1246 if (tPtr
->hpos
>16) tPtr
->hpos
-=16;
1250 case WSIncrementLine
: {
1251 int limit
= tPtr
->docWidth
- width
;
1252 if (tPtr
->hpos
< limit
) {
1253 if (tPtr
->hpos
<limit
-16) tPtr
->hpos
+=16;
1254 else tPtr
->hpos
=limit
;
1257 case WSDecrementPage
:
1258 tPtr
->hpos
-= width
;
1264 printf("dimple needs to jump to mouse location ;-/\n");
1266 case WSIncrementPage
:
1267 tPtr
->hpos
+= width
;
1268 if (tPtr
->hpos
> (tPtr
->docWidth
- width
))
1269 tPtr
->hpos
= tPtr
->docWidth
- width
;
1272 printf("dimple needs to jump to mouse location ;-/\n");
1277 tPtr
->hpos
= WMGetScrollerValue(tPtr
->hS
)
1278 * (float)(tPtr
->docWidth
- width
);
1284 printf("WSNoPart, WSKnobSlot\n");
1286 float wmax
= (float)(tPtr
->docWidth
);
1287 ((float)tPtr
->vpos
)/(wmax
- (float)tPtr
->visible
.w
),
1288 (float)tPtr
->visible
.w
/wmax
;
1289 dimple
=where mouse is
.
1293 scroll
= (tPtr
->hpos
!= tPtr
->prevHpos
);
1294 tPtr
->prevHpos
= tPtr
->hpos
;
1300 if (tPtr->rulerShown)
1301 XClearArea(tPtr->view->screen->display, tPtr->view->window, 22, 47,
1302 tPtr->view->size.width-24, tPtr->view->size.height-49, True);
1304 XClearArea(tPtr->view->screen->display, tPtr->view->window, 22, 2,
1305 tPtr->view->size.width-24, tPtr->view->size.height-4, True);
1308 if (dimple
|| which
== WSDecrementLine
|| which
== WSIncrementLine
)
1309 updateScrollers(tPtr
);
1318 unsigned short begin
, end
; /* what part of the text block */
1323 layOutLine(Text
*tPtr
, myLineItems
*items
, int nitems
, int x
, int y
)
1325 int i
, j
=0, lw
= 0, line_height
=0, max_d
=0, len
, n
;
1329 TextBlock
*tbsame
=NULL
;
1331 if(!items
|| nitems
== 0)
1334 for(i
=0; i
<nitems
; i
++) {
1338 if (!tPtr
->flags
.monoFont
) {
1340 WMWidget
*wdt
= tb
->d
.widget
;
1341 line_height
= WMAX(line_height
, WMWidgetHeight(wdt
));
1342 if (tPtr
->flags
.alignment
!= WALeft
)
1343 lw
+= WMWidgetWidth(wdt
);
1345 line_height
= WMAX(line_height
, tb
->d
.pixmap
->height
+ max_d
);
1346 if (tPtr
->flags
.alignment
!= WALeft
)
1347 lw
+= tb
->d
.pixmap
->width
;
1352 font
= (tPtr
->flags
.monoFont
)?tPtr
->dFont
: tb
->d
.font
;
1353 max_d
= WMAX(max_d
, abs(font
->height
-font
->y
));
1354 line_height
= WMAX(line_height
, font
->height
+ max_d
);
1355 text
= &(tb
->text
[items
[i
].begin
]);
1356 len
= items
[i
].end
- items
[i
].begin
;
1357 if (tPtr
->flags
.alignment
!= WALeft
)
1358 lw
+= WMWidthOfString(font
, text
, len
);
1362 if (tPtr
->flags
.alignment
== WARight
) {
1363 j
= tPtr
->visible
.w
- lw
;
1364 } else if (tPtr
->flags
.alignment
== WACenter
) {
1365 j
= (int) ((float)(tPtr
->visible
.w
- lw
))/2.0;
1368 for(i
=0; i
<nitems
; i
++) {
1371 if (tbsame
== tb
) { /*extend it, since it's on same line */
1372 tb
->sections
[tb
->nsections
-1].end
= items
[i
].end
;
1373 n
= tb
->nsections
-1;
1375 tb
->sections
= wrealloc(tb
->sections
,
1376 (++tb
->nsections
)*sizeof(Section
));
1377 n
= tb
->nsections
-1;
1378 tb
->sections
[n
]._y
= y
+ max_d
;
1379 tb
->sections
[n
].x
= x
+j
;
1380 tb
->sections
[n
].h
= line_height
;
1381 tb
->sections
[n
].begin
= items
[i
].begin
;
1382 tb
->sections
[n
].end
= items
[i
].end
;
1384 if (tb
->graphic
&& tb
->object
) {
1385 tb
->sections
[n
].x
+= tPtr
->visible
.x
;
1386 tb
->sections
[n
].y
+= tPtr
->visible
.y
;
1390 tb
->sections
[n
].last
= (i
+1 == nitems
);
1393 if (!tPtr
->flags
.monoFont
) {
1395 WMWidget
*wdt
= tb
->d
.widget
;
1396 tb
->sections
[n
].y
= max_d
+ y
1397 + line_height
- WMWidgetHeight(wdt
);
1398 tb
->sections
[n
].w
= WMWidgetWidth(wdt
);
1400 tb
->sections
[n
].y
= y
+ max_d
;
1401 tb
->sections
[n
].w
= tb
->d
.pixmap
->width
;
1403 x
+= tb
->sections
[n
].w
;
1406 font
= (tPtr
->flags
.monoFont
)? tPtr
->dFont
: tb
->d
.font
;
1407 len
= items
[i
].end
- items
[i
].begin
;
1408 text
= &(tb
->text
[items
[i
].begin
]);
1410 tb
->sections
[n
].y
= y
+line_height
-font
->y
;
1412 WMWidthOfString(font
,
1413 &(tb
->text
[tb
->sections
[n
].begin
]),
1414 tb
->sections
[n
].end
- tb
->sections
[n
].begin
);
1416 x
+= WMWidthOfString(font
, text
, len
);
1428 layOutDocument(Text
*tPtr
)
1431 myLineItems
*items
= NULL
;
1432 unsigned int itemsSize
=0, nitems
=0;
1434 unsigned int x
, y
=0, prev_y
, lw
= 0, width
=0, bmargin
;
1437 Bool lhc
= !tPtr
->flags
.laidOut
; /* line height changed? */
1439 char *start
=NULL
, *mark
=NULL
;
1440 unsigned int begin
, end
;
1442 if (tPtr
->flags
.frozen
)
1445 if (!(tb
= tPtr
->firstTextBlock
))
1448 tPtr
->docWidth
= tPtr
->visible
.w
;
1449 x
= 0; /* tPtr->margins[tb->marginN].first; */
1450 printf("x:%d\n", x
);
1451 bmargin
= tPtr
->margins
[tb
->marginN
].body
;
1453 if (0&&tPtr
->flags
.laidOut
) {
1454 tb
= tPtr
->currentTextBlock
;
1455 if (tb
->sections
&& tb
->nsections
>0)
1456 prev_y
= tb
->sections
[tb
->nsections
-1]._y
;
1458 printf("1 prev_y %d \n", prev_y
);
1460 /* search backwards for textblocks on same line */
1462 if (!tb
->sections
|| tb
->nsections
<1) {
1463 tb
= tPtr
->firstTextBlock
;
1466 if (tb
->sections
[tb
->nsections
-1]._y
!= prev_y
) {
1470 /* prev_y = tb->sections[tb->nsections-1]._y; */
1473 y
= 0; /* tb->sections[tb->nsections-1]._y; */
1474 printf("2 prev_y %d \n\n", tb
->sections
[tb
->nsections
-1]._y
);
1480 if (tb
->sections
&& tb
->nsections
>0) {
1481 wfree(tb
->sections
);
1482 tb
->sections
= NULL
;
1486 if (tb
->first
&& tb
!= tPtr
->firstTextBlock
) {
1487 y
+= layOutLine(tPtr
, items
, nitems
, x
, y
);
1488 x
= 0*tPtr
->margins
[tb
->marginN
].first
;
1489 bmargin
= tPtr
->margins
[tb
->marginN
].body
;
1495 if (!tPtr
->flags
.monoFont
) {
1497 width
= WMWidgetWidth(tb
->d
.widget
);
1499 width
= tb
->d
.pixmap
->width
;
1501 if (width
> tPtr
->docWidth
)
1502 tPtr
->docWidth
= width
;
1505 if (lw
>= tPtr
->visible
.w
- x
) {
1506 y
+= layOutLine(tPtr
, items
, nitems
, x
, y
);
1512 if(nitems
+ 1> itemsSize
) {
1513 items
= wrealloc(items
,
1514 (++itemsSize
)*sizeof(myLineItems
));
1517 items
[nitems
].tb
= tb
;
1518 items
[nitems
].begin
= 0;
1519 items
[nitems
].end
= 0;
1523 } else if ((start
= tb
->text
)) {
1525 font
= tPtr
->flags
.monoFont
?tPtr
->dFont
:tb
->d
.font
;
1528 mark
= mystrchr(start
, ' ', tb
->used
);
1530 end
+= (int)(mark
-start
)+1;
1533 end
+= strlen(start
);
1540 if (end
-begin
> 0) {
1542 width
= WMWidthOfString(font
,
1543 &tb
->text
[begin
], end
-begin
);
1545 /* if it won't fit, break it up */
1546 if (width
> tPtr
->visible
.w
) {
1547 char *t
= &tb
->text
[begin
];
1548 int l
=end
-begin
, i
=0;
1550 width
= WMWidthOfString(font
, t
, ++i
);
1551 } while (width
< tPtr
->visible
.w
&& i
< l
);
1560 if (lw
>= tPtr
->visible
.w
- x
) {
1561 y
+= layOutLine(tPtr
, items
, nitems
, x
, y
);
1567 if(nitems
+ 1 > itemsSize
) {
1568 items
= wrealloc(items
,
1569 (++itemsSize
)*sizeof(myLineItems
));
1572 items
[nitems
].tb
= tb
;
1573 items
[nitems
].begin
= begin
;
1574 items
[nitems
].end
= end
;
1585 y
+= layOutLine(tPtr
, items
, nitems
, x
, y
);
1587 tPtr
->docHeight
= y
+10;
1588 updateScrollers(tPtr
);
1591 if(tPtr
->docWidth
> tPtr
->visible
.w
&& !tPtr
->hS
) {
1594 tPtr
->flags
.horizOnDemand
= True
;
1595 WMSetTextHasHorizontalScroller((WMText
*)tPtr
, True
);
1596 event
.type
= Expose
;
1597 handleEvents(&event
, (void *)tPtr
);
1599 } else if(tPtr
->docWidth
<= tPtr
->visible
.w
1600 && tPtr
->hS
&& tPtr
->flags
.horizOnDemand
) {
1601 tPtr
->flags
.horizOnDemand
= False
;
1602 WMSetTextHasHorizontalScroller((WMText
*)tPtr
, False
);
1604 tPtr
->flags
.laidOut
= True
;
1607 if(items
&& itemsSize
> 0)
1613 textDidResize(W_ViewDelegate
*self
, WMView
*view
)
1615 Text
*tPtr
= (Text
*)view
->self
;
1616 unsigned short w
= tPtr
->view
->size
.width
;
1617 unsigned short h
= tPtr
->view
->size
.height
;
1618 unsigned short rh
= 0, vw
= 0;
1620 if (tPtr
->ruler
&& tPtr
->flags
.rulerShown
) {
1621 WMMoveWidget(tPtr
->ruler
, 2, 2);
1622 WMResizeWidget(tPtr
->ruler
, w
- 4, 40);
1627 WMMoveWidget(tPtr
->vS
, 1, rh
+ 1);
1628 WMResizeWidget(tPtr
->vS
, 20, h
- rh
- 2);
1630 WMSetRulerOffset(tPtr
->ruler
,22);
1631 } else WMSetRulerOffset(tPtr
->ruler
, 2);
1635 WMMoveWidget(tPtr
->hS
, vw
, h
- 21);
1636 WMResizeWidget(tPtr
->hS
, w
- vw
- 1, 20);
1638 WMMoveWidget(tPtr
->hS
, vw
+1, h
- 21);
1639 WMResizeWidget(tPtr
->hS
, w
- vw
- 2, 20);
1643 tPtr
->visible
.x
= (tPtr
->vS
)?24:4;
1644 tPtr
->visible
.y
= (tPtr
->ruler
&& tPtr
->flags
.rulerShown
)?43:3;
1645 tPtr
->visible
.w
= tPtr
->view
->size
.width
- tPtr
->visible
.x
- 8;
1646 tPtr
->visible
.h
= tPtr
->view
->size
.height
- tPtr
->visible
.y
;
1647 tPtr
->visible
.h
-= (tPtr
->hS
)?20:0;
1648 tPtr
->margins
[0].right
= tPtr
->visible
.w
;
1650 if (tPtr
->view
->flags
.realized
) {
1653 XFreePixmap(tPtr
->view
->screen
->display
, tPtr
->db
);
1654 tPtr
->db
= (Pixmap
) NULL
;
1657 if (tPtr
->visible
.w
< 40)
1658 tPtr
->visible
.w
= 40;
1659 if (tPtr
->visible
.h
< 20)
1660 tPtr
->visible
.h
= 20;
1663 tPtr
->db
= XCreatePixmap(tPtr
->view
->screen
->display
,
1664 tPtr
->view
->window
, tPtr
->visible
.w
,
1665 tPtr
->visible
.h
, tPtr
->view
->screen
->depth
);
1669 WMRefreshText(tPtr
, tPtr
->vpos
, tPtr
->hpos
);
1672 W_ViewDelegate _TextViewDelegate
=
1680 /* nice, divisble-by-16 blocks */
1681 static inline unsigned short
1682 reqBlockSize(unsigned short requested
)
1684 return requested
+ 16 - (requested
%16);
1689 clearText(Text
*tPtr
)
1691 if (!tPtr
->firstTextBlock
)
1694 while (tPtr
->currentTextBlock
)
1695 WMDestroyTextBlock(tPtr
, WMRemoveTextBlock(tPtr
));
1697 tPtr
->firstTextBlock
= NULL
;
1698 tPtr
->currentTextBlock
= NULL
;
1699 tPtr
->lastTextBlock
= NULL
;
1703 deleteTextInteractively(Text
*tPtr
, KeySym ksym
)
1705 TextBlock
*tb
= tPtr
->currentTextBlock
;
1706 Bool back
= (Bool
) (ksym
== XK_BackSpace
);
1709 if (!tPtr
->flags
.editable
|| tPtr
->flags
.buttonHeld
) {
1710 XBell(tPtr
->view
->screen
->display
, 0);
1717 tPtr
->flags
.needsRefresh
= True
;
1719 if (tPtr
->flags
.ownsSelection
) {
1720 removeSelection(tPtr
);
1724 if (back
&& tPtr
->tpos
< 1) {
1728 tPtr
->tpos
= tb
->used
;
1729 tPtr
->currentTextBlock
= tb
;
1734 if ( (tb
->used
> 0) && ((back
?tPtr
->tpos
> 0:1))
1735 && (tPtr
->tpos
<= tb
->used
) && !tb
->graphic
) {
1738 memmove(&(tb
->text
[tPtr
->tpos
]),
1739 &(tb
->text
[tPtr
->tpos
+ 1]), tb
->used
- tPtr
->tpos
);
1744 if ( (back
? (tPtr
->tpos
< 1 && !done
) : ( tPtr
->tpos
>= tb
->used
))
1747 TextBlock
*sibling
= (back
? tb
->prior
: tb
->next
);
1749 if(tb
->used
== 0 || tb
->graphic
)
1750 WMDestroyTextBlock(tPtr
, WMRemoveTextBlock(tPtr
));
1753 tPtr
->currentTextBlock
= sibling
;
1754 tPtr
->tpos
= (back
? sibling
->used
: 0);
1758 WMRefreshText(tPtr
, tPtr
->vpos
, tPtr
->hpos
);
1763 insertTextInteractively(Text
*tPtr
, char *text
, int len
)
1766 char *newline
= NULL
;
1768 if (!tPtr
->flags
.editable
|| tPtr
->flags
.buttonHeld
) {
1769 XBell(tPtr
->view
->screen
->display
, 0);
1773 if (len
< 1 || !text
)
1777 if(tPtr
->flags
.ignoreNewLine
&& *text
== '\n' && len
== 1)
1780 if (tPtr
->flags
.ownsSelection
)
1781 removeSelection(tPtr
);
1783 tPtr
->flags
.needsRefresh
= True
;
1785 if (tPtr
->flags
.ignoreNewLine
) {
1787 for(i
=0; i
<len
; i
++) {
1788 if (text
[i
] == '\n')
1793 tb
= tPtr
->currentTextBlock
;
1794 if (!tb
|| tb
->graphic
) {
1796 WMAppendTextStream(tPtr
, text
);
1797 if (tPtr
->currentTextBlock
) {
1798 tPtr
->tpos
= tPtr
->currentTextBlock
->used
;
1800 WMRefreshText(tPtr
, tPtr
->vpos
, tPtr
->hpos
);
1804 if ((newline
= mystrchr(text
, '\n', len
))) {
1805 int nlen
= (int)(newline
-text
);
1806 int s
= tb
->used
- tPtr
->tpos
;
1809 if (!tb
->blank
&& nlen
>0) {
1811 memcpy(save
, &tb
->text
[tPtr
->tpos
], s
);
1812 tb
->used
-= (tb
->used
- tPtr
->tpos
);
1815 insertTextInteractively(tPtr
, text
, nlen
);
1817 WMAppendTextStream(tPtr
, newline
);
1819 insertTextInteractively(tPtr
, save
, s
);
1822 if (tPtr
->tpos
>0 && tPtr
->tpos
< tb
->used
1823 && !tb
->graphic
&& tb
->text
) {
1825 void *ntb
= WMCreateTextBlockWithText(
1826 tPtr
, &tb
->text
[tPtr
->tpos
],
1827 tb
->d
.font
, tb
->color
, True
, tb
->used
- tPtr
->tpos
);
1828 tb
->used
= tPtr
->tpos
;
1829 WMAppendTextBlock(tPtr
, ntb
);
1831 } else if (tPtr
->tpos
== tb
->used
|| tPtr
->tpos
== 0) {
1832 void *ntb
= WMCreateTextBlockWithText(tPtr
,
1833 NULL
, tb
->d
.font
, tb
->color
, True
, 0);
1836 WMAppendTextBlock(tPtr
, ntb
);
1838 WMPrependTextBlock(tPtr
, ntb
);
1845 if (tb
->used
+ len
>= tb
->allocated
) {
1846 tb
->allocated
= reqBlockSize(tb
->used
+len
);
1847 tb
->text
= wrealloc(tb
->text
, tb
->allocated
);
1851 memcpy(tb
->text
, text
, len
);
1856 memmove(&(tb
->text
[tPtr
->tpos
+len
]), &tb
->text
[tPtr
->tpos
],
1857 tb
->used
-tPtr
->tpos
+1);
1858 memmove(&tb
->text
[tPtr
->tpos
], text
, len
);
1865 WMRefreshText(tPtr
, tPtr
->vpos
, tPtr
->hpos
);
1870 selectRegion(Text
*tPtr
, int x
, int y
)
1876 y
+= (tPtr
->flags
.rulerShown
? 40: 0);
1879 y
-= 10; /* the original offset */
1881 x
-= tPtr
->visible
.x
-2;
1885 tPtr
->sel
.x
= WMAX(0, WMIN(tPtr
->clicked
.x
, x
));
1886 tPtr
->sel
.w
= abs(tPtr
->clicked
.x
- x
);
1887 tPtr
->sel
.y
= WMAX(0, WMIN(tPtr
->clicked
.y
, y
));
1888 tPtr
->sel
.h
= abs(tPtr
->clicked
.y
- y
);
1890 tPtr
->flags
.ownsSelection
= True
;
1896 releaseSelection(Text
*tPtr
)
1898 TextBlock
*tb
= tPtr
->firstTextBlock
;
1901 tb
->selected
= False
;
1904 tPtr
->flags
.ownsSelection
= False
;
1905 WMDeleteSelectionHandler(tPtr
->view
, XA_PRIMARY
,
1908 WMRefreshText(tPtr
, tPtr
->vpos
, tPtr
->hpos
);
1913 requestHandler(WMView
*view
, Atom selection
, Atom target
, void *cdata
,
1916 Text
*tPtr
= view
->self
;
1917 Display
*dpy
= tPtr
->view
->screen
->display
;
1919 Atom TEXT
= XInternAtom(dpy
, "TEXT", False
);
1920 Atom COMPOUND_TEXT
= XInternAtom(dpy
, "COMPOUND_TEXT", False
);
1921 WMData
*data
= NULL
;
1924 if (target
== XA_STRING
|| target
== TEXT
|| target
== COMPOUND_TEXT
) {
1925 char *text
= WMGetTextSelected(tPtr
);
1928 printf("got text [%s]\n", text
);
1929 data
= WMCreateDataWithBytes(text
, strlen(text
));
1930 WMSetDataFormat(data
, 8);
1934 } else printf("didn't get it\n");
1936 _TARGETS
= XInternAtom(dpy
, "TARGETS", False
);
1937 if (target
== _TARGETS
) {
1940 ptr
= wmalloc(4 * sizeof(Atom
));
1944 ptr
[3] = COMPOUND_TEXT
;
1946 data
= WMCreateDataWithBytes(ptr
, 4*4);
1947 WMSetDataFormat(data
, 32);
1957 lostHandler(WMView
*view
, Atom selection
, void *cdata
)
1959 releaseSelection((WMText
*)view
->self
);
1962 static WMSelectionProcs selectionHandler
= {
1963 requestHandler
, lostHandler
, NULL
1968 ownershipObserver(void *observerData
, WMNotification
*notification
)
1970 if (observerData
!= WMGetNotificationClientData(notification
))
1971 lostHandler(WMWidgetView(observerData
), XA_PRIMARY
, NULL
);
1976 fontChanged(void *observerData
, WMNotification
*notification
)
1978 WMText
*tPtr
= (WMText
*) observerData
;
1979 WMFont
*font
= (WMFont
*)WMGetNotificationClientData(notification
);
1980 printf("fontChanged\n");
1985 if (tPtr
->flags
.ownsSelection
)
1986 WMSetTextSelectionFont(tPtr
, font
);
1991 handleTextKeyPress(Text
*tPtr
, XEvent
*event
)
1995 int control_pressed
= False
;
1996 TextBlock
*tb
= NULL
;
1998 if (((XKeyEvent
*) event
)->state
& ControlMask
)
1999 control_pressed
= True
;
2000 buffer
[XLookupString(&event
->xkey
, buffer
, 1, &ksym
, NULL
)] = 0;
2005 if(!(tb
= tPtr
->currentTextBlock
))
2011 L_imaGFX
: if(tb
->prior
) {
2012 tPtr
->currentTextBlock
= tb
->prior
;
2013 tPtr
->tpos
= tPtr
->currentTextBlock
->used
-1;
2014 } else tPtr
->tpos
= 0;
2015 } else tPtr
->tpos
--;
2016 updateCursorPosition(tPtr
);
2020 printf("foind %d \n", WMFindInTextStream(tPtr
, "It", 1, 0));
2022 if(!(tb
= tPtr
->currentTextBlock
))
2026 if(tPtr
->tpos
== tb
->used
) {
2027 R_imaGFX
: if(tb
->next
) {
2028 tPtr
->currentTextBlock
= tb
->next
;
2030 } else tPtr
->tpos
= tb
->used
;
2031 } else tPtr
->tpos
++;
2032 updateCursorPosition(tPtr
);
2036 cursorToTextPosition(tPtr
, tPtr
->cursor
.x
+ tPtr
->visible
.x
,
2037 tPtr
->clicked
.y
+ tPtr
->cursor
.h
- tPtr
->vpos
);
2042 cursorToTextPosition(tPtr
, tPtr
->cursor
.x
+ tPtr
->visible
.x
,
2043 tPtr
->visible
.y
+ tPtr
->cursor
.y
- tPtr
->vpos
- 3);
2050 deleteTextInteractively(tPtr
, ksym
);
2051 updateCursorPosition(tPtr
);
2056 control_pressed
= True
;
2062 if (buffer
[0] != 0 && !control_pressed
) {
2063 insertTextInteractively(tPtr
, buffer
, 1);
2064 updateCursorPosition(tPtr
);
2066 } else if (control_pressed
&& ksym
==XK_r
) {
2067 Bool i
= !tPtr
->flags
.rulerShown
;
2068 WMShowTextRuler(tPtr
, i
);
2069 tPtr
->flags
.rulerShown
= i
;
2071 else if (control_pressed
&& buffer
[0] == '\a')
2072 XBell(tPtr
->view
->screen
->display
, 0);
2075 if (!control_pressed
&& tPtr
->flags
.ownsSelection
)
2076 releaseSelection(tPtr
);
2080 handleWidgetPress(XEvent
*event
, void *data
)
2082 TextBlock
*tb
= (TextBlock
*)data
;
2088 /* this little bit of nastiness here saves a boatload of trouble */
2089 w
= (WMWidget
*)(((W_VIEW(tb
->d
.widget
))->parent
)->self
);
2090 if (W_CLASS(w
) != WC_Text
)
2093 tPtr
->currentTextBlock
= getFirstNonGraphicBlockFor(tb
, 1);
2094 if (!tPtr
->currentTextBlock
)
2095 tPtr
->currentTextBlock
= tb
;
2097 output(tPtr
->currentTextBlock
->text
, tPtr
->currentTextBlock
->used
);
2099 if (!tPtr
->flags
.focused
) {
2100 WMSetFocusToWidget(tPtr
);
2101 tPtr
->flags
.focused
= True
;
2108 handleActionEvents(XEvent
*event
, void *data
)
2110 Text
*tPtr
= (Text
*)data
;
2111 Display
*dpy
= event
->xany
.display
;
2115 switch (event
->type
) {
2117 ksym
= XLookupKeysym((XKeyEvent
*)event
, 0);
2118 if (ksym
== XK_Shift_R
|| ksym
== XK_Shift_L
) {
2119 tPtr
->flags
.extendSelection
= True
;
2123 if (tPtr
->flags
.focused
) {
2124 XGrabPointer(dpy
, W_VIEW(tPtr
)->window
, False
,
2125 PointerMotionMask
|ButtonPressMask
|ButtonReleaseMask
,
2126 GrabModeAsync
, GrabModeAsync
, None
,
2127 tPtr
->view
->screen
->invisibleCursor
, CurrentTime
);
2128 tPtr
->flags
.pointerGrabbed
= True
;
2129 handleTextKeyPress(tPtr
, event
);
2134 ksym
= XLookupKeysym((XKeyEvent
*)event
, 0);
2135 if (ksym
== XK_Shift_R
|| ksym
== XK_Shift_L
) {
2136 tPtr
->flags
.extendSelection
= False
;
2138 /* end modify flag so selection can be extended */
2145 if (tPtr
->flags
.pointerGrabbed
) {
2146 tPtr
->flags
.pointerGrabbed
= False
;
2147 XUngrabPointer(dpy
, CurrentTime
);
2150 if(tPtr
->flags
.waitingForSelection
)
2153 if ((event
->xmotion
.state
& Button1Mask
)) {
2154 if (!tPtr
->flags
.ownsSelection
) {
2155 WMCreateSelectionHandler(tPtr
->view
,
2156 XA_PRIMARY
, event
->xbutton
.time
,
2157 &selectionHandler
, NULL
);
2158 tPtr
->flags
.ownsSelection
= True
;
2160 selectRegion(tPtr
, event
->xmotion
.x
, event
->xmotion
.y
);
2167 tPtr
->flags
.buttonHeld
= True
;
2169 if (tPtr
->flags
.pointerGrabbed
) {
2170 tPtr
->flags
.pointerGrabbed
= False
;
2171 XUngrabPointer(dpy
, CurrentTime
);
2175 if (tPtr
->flags
.waitingForSelection
)
2178 if (tPtr
->flags
.extendSelection
) {
2179 selectRegion(tPtr
, event
->xmotion
.x
, event
->xmotion
.y
);
2184 if (event
->xbutton
.button
== Button1
) {
2186 if(WMIsDoubleClick(event
)) {
2187 printf("lastClickTime: %d \n", event
->xbutton
.time
-tPtr
->lastClickTime
);
2188 autoSelectText(tPtr
, 2);
2189 tPtr
->lastClickTime
= event
->xbutton
.time
;
2192 if(0&&event
->xbutton
.time
- tPtr
->lastClickTime
2193 < 1.5*WINGsConfiguration
.doubleClickDelay
) {
2194 ;// autoSelectText(tPtr, 3);
2198 //WMGetTextStreamIntoArray(tPtr);
2200 if (!tPtr
->flags
.focused
) {
2201 WMSetFocusToWidget(tPtr
);
2202 tPtr
->flags
.focused
= True
;
2205 if (tPtr
->flags
.ownsSelection
)
2206 releaseSelection(tPtr
);
2208 tPtr
->lastClickTime
= event
->xbutton
.time
;
2209 cursorToTextPosition(tPtr
, event
->xmotion
.x
, event
->xmotion
.y
);
2213 if (event
->xbutton
.button
2214 == WINGsConfiguration
.mouseWheelDown
) {
2215 WMScrollText(tPtr
, -16);
2219 if (event
->xbutton
.button
2220 == WINGsConfiguration
.mouseWheelUp
) {
2221 WMScrollText(tPtr
, 16);
2225 if (event
->xbutton
.button
== Button2
) {
2229 if (!tPtr
->flags
.editable
) {
2235 if (!WMRequestSelection(tPtr
->view
, XA_PRIMARY
, XA_STRING
,
2236 event
->xbutton
.time
, pasteText
, NULL
)) {
2240 text
= XFetchBuffer(tPtr
->view
->screen
->display
, &n
, 0);
2246 (tPtr
->parser
) (tPtr
, (void *) text
);
2248 insertTextInteractively(tPtr
, text
, n
);
2251 NOTIFY(tPtr
, didChange
, WMTextDidChangeNotification
,
2252 (void*)WMInsertTextEvent
);
2255 tPtr
->flags
.waitingForSelection
= True
;
2264 tPtr
->flags
.buttonHeld
= False
;
2266 if (tPtr
->flags
.pointerGrabbed
) {
2267 tPtr
->flags
.pointerGrabbed
= False
;
2268 XUngrabPointer(dpy
, CurrentTime
);
2272 if (tPtr
->flags
.waitingForSelection
)
2280 handleEvents(XEvent
*event
, void *data
)
2282 Text
*tPtr
= (Text
*)data
;
2284 switch(event
->type
) {
2287 if (event
->xexpose
.count
!=0)
2291 if (!(W_VIEW(tPtr
->hS
))->flags
.realized
)
2292 WMRealizeWidget(tPtr
->hS
);
2293 if (!((W_VIEW(tPtr
->hS
))->flags
.mapped
))
2294 WMMapWidget(tPtr
->hS
);
2298 if (!(W_VIEW(tPtr
->vS
))->flags
.realized
)
2299 WMRealizeWidget(tPtr
->vS
);
2300 if (!((W_VIEW(tPtr
->vS
))->flags
.mapped
))
2301 WMMapWidget(tPtr
->vS
);
2305 if (!(W_VIEW(tPtr
->ruler
))->flags
.realized
)
2306 WMRealizeWidget(tPtr
->ruler
);
2308 if (!((W_VIEW(tPtr
->ruler
))->flags
.mapped
)
2309 && tPtr
->flags
.rulerShown
)
2310 WMMapWidget(tPtr
->ruler
);
2314 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
2320 if (W_FocusedViewOfToplevel(W_TopLevelOfView(tPtr
->view
))
2323 tPtr
->flags
.focused
= True
;
2325 if (tPtr
->flags
.editable
&& !tPtr
->timerID
) {
2326 tPtr
->timerID
= WMAddTimerHandler(12+0*CURSOR_BLINK_ON_DELAY
,
2334 tPtr
->flags
.focused
= False
;
2337 if (tPtr
->timerID
) {
2338 WMDeleteTimerHandler(tPtr
->timerID
);
2339 tPtr
->timerID
= NULL
;
2348 WMDestroyWidget(tPtr
->hS
);
2350 WMDestroyWidget(tPtr
->vS
);
2352 WMDestroyWidget(tPtr
->ruler
);
2354 XFreePixmap(tPtr
->view
->screen
->display
, tPtr
->db
);
2356 WMFreeArray(tPtr
->gfxItems
);
2359 WMDeleteTimerHandler(tPtr
->timerID
);
2361 WMReleaseFont(tPtr
->dFont
);
2362 WMReleaseColor(tPtr
->dColor
);
2363 WMDeleteSelectionHandler(tPtr
->view
, XA_PRIMARY
, CurrentTime
);
2364 WMRemoveNotificationObserver(tPtr
);
2375 insertText(WMText
*tPtr
, char *stream
)
2377 char *ptr
, *begin
, *end
;
2380 char b
, e
, again
=False
;
2381 unsigned long tokenLength
, tk
;
2382 unsigned long textLength
, tx
;
2389 WMAppendTextBlock(tPtr
,
2390 WMCreateTextBlockWithText(tPtr
, stream
, tPtr
->dFont
, tPtr
->dColor
,
2391 1, strlen(stream
)));
2398 begin
= strchr(ptr
, b
);
2400 end
= strchr(begin
+1, e
);
2402 if((int)(end
-begin
)-1 > 1)
2403 output(begin
+1, (int)(end
-begin
)-1);
2412 if (ptr
&& strlen(ptr
)) {
2420 while( (c
=*(stream
++))) {
2422 if((c
== '\n' && tPtr
->flags
.parsingHTML
) || c
=='\t')
2423 //c = ' '; //continue;
2432 parseToken(tPtr
, token
, -1);
2434 } else if(c
== '<' && !open
) {
2438 tb
= WMCreateTextBlockWithText(tPtr
, text
, cfmt
.cfont
,
2439 cfmt
.ccolor
, cfmt
.first
, textlen
);
2440 //WMSetTextBlockProperties(tb, cfmt.first, False, (cfmt.u?1:0), 0, cfmt.margins);
2441 WMAppendTextBlock(tPtr
, tb
);
2443 //printf("%s\n", text);
2446 } else if(c
== '>' && open
) {
2448 if(tk
>0) parseToken(tPtr
, token
, tk
);
2453 if(tk
< MAX_TOKEN_SIZE
) token
[tk
++] = c
;
2454 } else if(textlen
< MAX_TEXT_SIZE
) text
[textlen
++] = c
;
2458 if(tk
>0) { token
[tk
] = 0; parseToken(tPtr
, token
, tk
);}
2461 //printf("%s\n", text);
2462 tb
= WMCreateTextBlockWithText(tPtr
, text
,
2463 (WMFont
*)WMGetFromArray(cfmt
.fonts
,
2464 WMGetArrayItemCount(cfmt
.fonts
)-1),
2465 (WMColor
*)WMGetFromArray(cfmt
.colors
,
2466 WMGetArrayItemCount(cfmt
.colors
)-1),
2467 cfmt
.first
, textlen
);
2468 //WMSetTextBlockProperties(tb, cfmt.first, False, (cfmt.u?1:0), 0, cfmt.margins);
2469 WMAppendTextBlock(tPtr
, tb
);
2480 mark
= strchr(start
, '\n');
2482 tb
= WMCreateTextBlockWithText(tPtr
,
2484 tPtr
->dColor
, True
, (int)(mark
-start
));
2487 if (start
&& strlen(start
)) {
2488 tb
= WMCreateTextBlockWithText(tPtr
, start
, tPtr
->dFont
,
2489 tPtr
->dColor
, False
, strlen(start
));
2494 if (tPtr
->flags
.prepend
)
2495 WMPrependTextBlock(tPtr
, tb
);
2497 WMAppendTextBlock(tPtr
, tb
);
2506 rulerMoveCallBack(WMWidget
*w
, void *self
)
2508 Text
*tPtr
= (Text
*)self
;
2511 if (W_CLASS(tPtr
) != WC_Text
)
2519 rulerReleaseCallBack(WMWidget
*w
, void *self
)
2521 Text
*tPtr
= (Text
*)self
;
2524 if (W_CLASS(tPtr
) != WC_Text
)
2527 WMRefreshText(tPtr
, tPtr
->vpos
, tPtr
->hpos
);
2533 draggingEntered(WMView
*self
, WMDraggingInfo
*info
)
2535 printf("draggingEntered\n");
2536 return WDOperationCopy
;
2541 draggingUpdated(WMView
*self
, WMDraggingInfo
*info
)
2543 return WDOperationCopy
;
2548 draggingExited(WMView
*self
, WMDraggingInfo
*info
)
2550 printf("draggingExited\n");
2554 prepareForDragOperation(WMView
*self
, WMDraggingInfo
*info
)
2556 printf("prepareForDragOperation\n");
2563 receivedData(WMView
*view
, Atom selection
, Atom target
, Time timestamp
,
2564 void *cdata
, WMData
*data
)
2566 badbadbad
= wstrdup((char *)WMDataBytes(data
));
2570 /* when it's done in WINGs, remove this */
2572 Bool
requestDroppedData(WMView
*view
, WMDraggingInfo
*info
, char *type
)
2574 WMScreen
*scr
= W_VIEW_SCREEN(view
);
2576 if (!WMRequestSelection(scr
->dragInfo
.destView
,
2577 scr
->xdndSelectionAtom
,
2578 XInternAtom(scr
->display
, type
, False
),
2579 scr
->dragInfo
.timestamp
,
2580 receivedData
, &scr
->dragInfo
)) {
2581 wwarning("could not request data for dropped data");
2588 ev
.type
= ClientMessage
;
2589 ev
.xclient
.message_type
= scr
->xdndFinishedAtom
;
2590 ev
.xclient
.format
= 32;
2591 ev
.xclient
.window
= info
->destinationWindow
;
2592 ev
.xclient
.data
.l
[0] = 0;
2593 ev
.xclient
.data
.l
[1] = 0;
2594 ev
.xclient
.data
.l
[2] = 0;
2595 ev
.xclient
.data
.l
[3] = 0;
2596 ev
.xclient
.data
.l
[4] = 0;
2598 XSendEvent(scr
->display
, info
->sourceWindow
, False
, 0, &ev
);
2599 XFlush(scr
->display
);
2604 performDragOperation(WMView
*self
, WMDraggingInfo
*info
, WMData
*data
)
2607 WMText
*tPtr
= (WMText
*)self
->self
;
2612 requestDroppedData(tPtr
->view
, info
, "application/X-color");
2613 color
= WMCreateNamedColor(W_VIEW_SCREEN(self
), badbadbad
, True
);
2615 WMSetTextSelectionColor(tPtr
, color
);
2616 WMReleaseColor(color
);
2625 concludeDragOperation(WMView
*self
, WMDraggingInfo
*info
)
2627 printf("concludeDragOperation\n");
2631 static WMDragDestinationProcs _DragDestinationProcs
= {
2635 prepareForDragOperation
,
2636 performDragOperation
,
2637 concludeDragOperation
2641 releaseArrayData(void *data
)
2649 getStream(WMText
*tPtr
, int sel
, int array
)
2651 TextBlock
*tb
= NULL
;
2653 unsigned long where
= 0;
2658 if (!(tb
= tPtr
->firstTextBlock
))
2661 /* this might be tricky to get right... not yet implemented */
2663 (tPtr
->writer
) (tPtr
, (void *) text
);
2667 tb
= tPtr
->firstTextBlock
;
2670 if (!tb
->graphic
|| (tb
->graphic
&& !tPtr
->flags
.monoFont
)) {
2672 if (!sel
|| (tb
->graphic
&& tb
->selected
)) {
2674 if (!tPtr
->flags
.ignoreNewLine
&& (tb
->first
|| tb
->blank
)) {
2675 text
= wrealloc(text
, where
+1);
2676 text
[where
++] = '\n';
2679 if(tb
->graphic
&& array
) {
2680 text
= wrealloc(text
, where
+3);
2681 text
[where
++] = 'G';//0xFA;
2682 text
[where
++] = 'A';//tb->used;
2683 text
[where
++] = 'H';//18+tb->allocated;
2686 text
= wrealloc(text
, where
+tb
->used
);
2687 memcpy(&text
[where
], tb
->text
, tb
->used
);
2691 } else if (sel
&& tb
->selected
) {
2693 if (!tPtr
->flags
.ignoreNewLine
&& (tb
->first
|| tb
->blank
)) {
2694 text
= wrealloc(text
, where
+1);
2695 text
[where
++] = '\n';
2698 text
= wrealloc(text
, where
+(tb
->s_end
- tb
->s_begin
));
2699 memcpy(&text
[where
], &tb
->text
[tb
->s_begin
],
2700 tb
->s_end
- tb
->s_begin
);
2701 where
+= tb
->s_end
- tb
->s_begin
;
2709 /* +1 for the end of string, let's be nice */
2710 text
= wrealloc(text
, where
+1);
2718 getStreamIntoArray(WMText
*tPtr
, int sel
)
2720 WMArray
*array
= WMCreateArray(4);
2723 unsigned long loc
=0, len
;
2728 stream
= getStream(tPtr
, sel
, 0);
2735 end
= strlen(stream
);
2738 data
= WMCreateDataWithBytes((void *)(fa
+2), len
);
2739 WMSetDataFormat(data
, 32);
2740 WMAddToArray(array
, (void *) data
);
2741 start
= fa
+ len
+ 2;
2744 if (start
&& strlen(start
)) {
2745 data
= WMCreateDataWithBytes((void *)start
, strlen(start
));
2746 WMSetDataFormat(data
, 8);
2747 WMAddToArray(array
, (void *) data
);
2761 WMCreateText(WMWidget
*parent
)
2763 Text
*tPtr
= wmalloc(sizeof(Text
));
2765 printf("could not create text widget\n");
2770 memset(tPtr
, 0, sizeof(Text
));
2771 tPtr
->widgetClass
= WC_Text
;
2772 tPtr
->view
= W_CreateView(W_VIEW(parent
));
2774 perror("could not create text's view\n");
2778 tPtr
->view
->self
= tPtr
;
2779 tPtr
->view
->attribs
.cursor
= tPtr
->view
->screen
->textCursor
;
2780 tPtr
->view
->attribFlags
|= CWOverrideRedirect
| CWCursor
;
2781 W_ResizeView(tPtr
->view
, 250, 200);
2783 tPtr
->dColor
= WMWhiteColor(tPtr
->view
->screen
);
2784 tPtr
->bgGC
= WMColorGC(tPtr
->dColor
);
2785 W_SetViewBackgroundColor(tPtr
->view
, tPtr
->dColor
);
2786 WMReleaseColor(tPtr
->dColor
);
2788 tPtr
->dColor
= WMBlackColor(tPtr
->view
->screen
);
2789 tPtr
->fgGC
= WMColorGC(tPtr
->dColor
);
2795 tPtr
->dFont
= WMRetainFont(WMSystemFontOfSize(tPtr
->view
->screen
, 12));
2797 tPtr
->view
->delegate
= &_TextViewDelegate
;
2800 tPtr
->timerID
= NULL
;
2803 WMCreateEventHandler(tPtr
->view
, ExposureMask
|StructureNotifyMask
2804 |EnterWindowMask
|LeaveWindowMask
|FocusChangeMask
,
2805 handleEvents
, tPtr
);
2807 WMCreateEventHandler(tPtr
->view
, ButtonReleaseMask
|ButtonPressMask
2808 |KeyReleaseMask
|KeyPressMask
|Button1MotionMask
,
2809 handleActionEvents
, tPtr
);
2811 WMAddNotificationObserver(ownershipObserver
, tPtr
,
2812 "_lostOwnership", tPtr
);
2814 WMSetViewDragDestinationProcs(tPtr
->view
, &_DragDestinationProcs
);
2816 char *types
[2] = {"application/X-color", NULL
};
2817 WMRegisterViewForDraggedTypes(tPtr
->view
, types
);
2820 WMAddNotificationObserver(fontChanged
, tPtr
,
2821 "WMFontPanelDidChangeNotification", tPtr
);
2823 tPtr
->firstTextBlock
= NULL
;
2824 tPtr
->lastTextBlock
= NULL
;
2825 tPtr
->currentTextBlock
= NULL
;
2828 tPtr
->gfxItems
= WMCreateArray(4);
2830 tPtr
->parser
= NULL
;
2831 tPtr
->writer
= NULL
;
2833 tPtr
->sel
.x
= tPtr
->sel
.y
= 2;
2834 tPtr
->sel
.w
= tPtr
->sel
.h
= 0;
2836 tPtr
->clicked
.x
= tPtr
->clicked
.y
= 2;
2838 tPtr
->visible
.x
= tPtr
->visible
.y
= 2;
2839 tPtr
->visible
.h
= tPtr
->view
->size
.height
;
2840 tPtr
->visible
.w
= tPtr
->view
->size
.width
- 4;
2842 tPtr
->cursor
.x
= -23;
2845 tPtr
->docHeight
= 0;
2846 tPtr
->dBulletPix
= WMCreatePixmapFromXPMData(tPtr
->view
->screen
,
2848 tPtr
->db
= (Pixmap
) NULL
;
2850 tPtr
->margins
= WMGetRulerMargins(NULL
);
2851 tPtr
->margins
->right
= tPtr
->visible
.w
;
2854 tPtr
->flags
.rulerShown
= False
;
2855 tPtr
->flags
.monoFont
= False
;
2856 tPtr
->flags
.focused
= False
;
2857 tPtr
->flags
.editable
= True
;
2858 tPtr
->flags
.ownsSelection
= False
;
2859 tPtr
->flags
.pointerGrabbed
= False
;
2860 tPtr
->flags
.buttonHeld
= False
;
2861 tPtr
->flags
.extendSelection
= False
;
2862 tPtr
->flags
.frozen
= False
;
2863 tPtr
->flags
.cursorShown
= True
;
2864 tPtr
->flags
.clickPos
= 1;
2865 tPtr
->flags
.horizOnDemand
= False
;
2866 tPtr
->flags
.needsRefresh
= False
;
2867 tPtr
->flags
.ignoreNewLine
= False
;
2868 tPtr
->flags
.laidOut
= False
;
2869 tPtr
->flags
.waitingForSelection
= False
;
2870 tPtr
->flags
.prepend
= False
;
2871 tPtr
->flags
.parsingHTML
= False
;
2872 tPtr
->flags
.relief
= WRSunken
;
2873 tPtr
->flags
.alignment
= WALeft
;
2879 WMPrependTextStream(WMText
*tPtr
, char *text
)
2881 CHECK_CLASS(tPtr
, WC_Text
);
2884 releaseSelection(tPtr
);
2886 tPtr
->flags
.prepend
= True
;
2887 if (text
&& tPtr
->parser
)
2888 (tPtr
->parser
) (tPtr
, (void *) text
);
2890 insertText(tPtr
, text
);
2892 tPtr
->flags
.needsRefresh
= True
;
2897 WMAppendTextStream(WMText
*tPtr
, char *text
)
2899 CHECK_CLASS(tPtr
, WC_Text
);
2902 releaseSelection(tPtr
);
2904 tPtr
->flags
.prepend
= False
;
2905 if (text
&& tPtr
->parser
)
2906 (tPtr
->parser
) (tPtr
, (void *) text
);
2908 insertText(tPtr
, text
);
2910 tPtr
->flags
.needsRefresh
= True
;
2916 WMGetTextStream(WMText
*tPtr
)
2918 CHECK_CLASS(tPtr
, WC_Text
);
2919 return getStream(tPtr
, 0, 0);
2923 WMGetTextSelected(WMText
*tPtr
)
2925 CHECK_CLASS(tPtr
, WC_Text
);
2926 return getStream(tPtr
, 1, 0);
2930 WMGetTextStreamIntoArray(WMText
*tPtr
)
2932 CHECK_CLASS(tPtr
, WC_Text
);
2933 return getStreamIntoArray(tPtr
, 0);
2937 WMGetTextSelectedIntoArray(WMText
*tPtr
)
2939 CHECK_CLASS(tPtr
, WC_Text
);
2940 return getStreamIntoArray(tPtr
, 1);
2945 WMSetTextDelegate(WMText
*tPtr
, WMTextDelegate
*delegate
)
2947 CHECK_CLASS(tPtr
, WC_Text
);
2949 tPtr
->delegate
= delegate
;
2954 WMCreateTextBlockWithObject(WMText
*tPtr
, WMWidget
*w
,
2955 char *description
, WMColor
*color
,
2956 unsigned short first
, unsigned short extraInfo
)
2959 unsigned short length
;
2961 if (!w
|| !description
|| !color
)
2964 tb
= wmalloc(sizeof(TextBlock
));
2968 length
= strlen(description
);
2969 tb
->text
= (char *)wmalloc(length
);
2970 memset(tb
->text
, 0, length
);
2971 memcpy(tb
->text
, description
, length
);
2975 tb
->color
= WMRetainColor(color
);
2976 tb
->marginN
= newMargin(tPtr
, NULL
);
2977 tb
->allocated
= extraInfo
;
2982 tb
->underlined
= False
;
2983 tb
->selected
= False
;
2985 tb
->sections
= NULL
;
2995 WMCreateTextBlockWithPixmap(WMText
*tPtr
, WMPixmap
*p
,
2996 char *description
, WMColor
*color
,
2997 unsigned short first
, unsigned short extraInfo
)
3000 unsigned short length
;
3002 if (!p
|| !description
|| !color
)
3005 tb
= wmalloc(sizeof(TextBlock
));
3009 length
= strlen(description
);
3010 tb
->text
= (char *)wmalloc(length
);
3011 memset(tb
->text
, 0, length
);
3012 memcpy(tb
->text
, description
, length
);
3016 tb
->color
= WMRetainColor(color
);
3017 tb
->marginN
= newMargin(tPtr
, NULL
);
3018 tb
->allocated
= extraInfo
;
3023 tb
->underlined
= False
;
3024 tb
->selected
= False
;
3026 tb
->sections
= NULL
;
3035 WMCreateTextBlockWithText(WMText
*tPtr
, char *text
, WMFont
*font
, WMColor
*color
,
3036 unsigned short first
, unsigned short length
)
3040 if (!font
|| !color
)
3043 tb
= wmalloc(sizeof(TextBlock
));
3047 tb
->allocated
= reqBlockSize(length
);
3048 tb
->text
= (char *)wmalloc(tb
->allocated
);
3049 memset(tb
->text
, 0, tb
->allocated
);
3051 if (length
< 1|| !text
) {
3056 memcpy(tb
->text
, text
, length
);
3061 tb
->d
.font
= WMRetainFont(font
);
3062 tb
->color
= WMRetainColor(color
);
3063 tb
->marginN
= newMargin(tPtr
, NULL
);
3066 tb
->graphic
= False
;
3067 tb
->underlined
= False
;
3068 tb
->selected
= False
;
3070 tb
->sections
= NULL
;
3078 WMSetTextBlockProperties(WMText
*tPtr
, void *vtb
, unsigned int first
,
3079 unsigned int kanji
, unsigned int underlined
, int script
,
3080 WMRulerMargins
*margins
)
3082 TextBlock
*tb
= (TextBlock
*) vtb
;
3088 tb
->underlined
= underlined
;
3089 tb
->script
= script
;
3090 tb
->marginN
= newMargin(tPtr
, margins
);
3094 WMGetTextBlockProperties(WMText
*tPtr
, void *vtb
, unsigned int *first
,
3095 unsigned int *kanji
, unsigned int *underlined
, int *script
,
3096 WMRulerMargins
*margins
)
3098 TextBlock
*tb
= (TextBlock
*) vtb
;
3102 if (first
) *first
= tb
->first
;
3103 if (kanji
) *kanji
= tb
->kanji
;
3104 if (underlined
) *underlined
= tb
->underlined
;
3105 if (script
) *script
= tb
->script
;
3106 if (margins
) margins
= &tPtr
->margins
[tb
->marginN
];
3112 WMPrependTextBlock(WMText
*tPtr
, void *vtb
)
3114 TextBlock
*tb
= (TextBlock
*)vtb
;
3121 WMWidget
*w
= tb
->d
.widget
;
3122 WMCreateEventHandler(W_VIEW(w
), ButtonPressMask
,
3123 handleWidgetPress
, tb
);
3124 if (W_CLASS(w
) != WC_TextField
&& W_CLASS(w
) != WC_Text
) {
3125 (W_VIEW(w
))->attribs
.cursor
= tPtr
->view
->screen
->defaultCursor
;
3126 (W_VIEW(w
))->attribFlags
|= CWOverrideRedirect
| CWCursor
;
3129 WMAddToArray(tPtr
->gfxItems
, (void *)tb
);
3131 } else tPtr
->tpos
= tb
->used
;
3133 if (!tPtr
->lastTextBlock
|| !tPtr
->firstTextBlock
) {
3134 tb
->next
= tb
->prior
= NULL
;
3136 tPtr
->lastTextBlock
= tPtr
->firstTextBlock
3137 = tPtr
->currentTextBlock
= tb
;
3142 tb
->marginN
= tPtr
->currentTextBlock
->marginN
;
3145 tb
->next
= tPtr
->currentTextBlock
;
3146 tb
->prior
= tPtr
->currentTextBlock
->prior
;
3147 if (tPtr
->currentTextBlock
->prior
)
3148 tPtr
->currentTextBlock
->prior
->next
= tb
;
3150 tPtr
->currentTextBlock
->prior
= tb
;
3152 tPtr
->firstTextBlock
= tb
;
3154 tPtr
->currentTextBlock
= tb
;
3159 WMAppendTextBlock(WMText
*tPtr
, void *vtb
)
3161 TextBlock
*tb
= (TextBlock
*)vtb
;
3168 WMWidget
*w
= tb
->d
.widget
;
3169 WMCreateEventHandler(W_VIEW(w
), ButtonPressMask
,
3170 handleWidgetPress
, tb
);
3171 if (W_CLASS(w
) != WC_TextField
&& W_CLASS(w
) != WC_Text
) {
3172 (W_VIEW(w
))->attribs
.cursor
=
3173 tPtr
->view
->screen
->defaultCursor
;
3174 (W_VIEW(w
))->attribFlags
|= CWOverrideRedirect
| CWCursor
;
3177 WMAddToArray(tPtr
->gfxItems
, (void *)tb
);
3179 } else tPtr
->tpos
= tb
->used
;
3181 if (!tPtr
->lastTextBlock
|| !tPtr
->firstTextBlock
) {
3182 tb
->next
= tb
->prior
= NULL
;
3184 tPtr
->lastTextBlock
= tPtr
->firstTextBlock
3185 = tPtr
->currentTextBlock
= tb
;
3190 tb
->marginN
= tPtr
->currentTextBlock
->marginN
;
3193 tb
->next
= tPtr
->currentTextBlock
->next
;
3194 tb
->prior
= tPtr
->currentTextBlock
;
3195 if (tPtr
->currentTextBlock
->next
)
3196 tPtr
->currentTextBlock
->next
->prior
= tb
;
3198 tPtr
->currentTextBlock
->next
= tb
;
3201 tPtr
->lastTextBlock
= tb
;
3203 tPtr
->currentTextBlock
= tb
;
3207 WMRemoveTextBlock(WMText
*tPtr
)
3209 TextBlock
*tb
= NULL
;
3211 if (!tPtr
|| !tPtr
->firstTextBlock
|| !tPtr
->lastTextBlock
3212 || !tPtr
->currentTextBlock
) {
3213 printf("cannot remove non existent TextBlock!\b");
3217 tb
= tPtr
->currentTextBlock
;
3219 WMRemoveFromArray(tPtr
->gfxItems
, (void *)tb
);
3222 WMDeleteEventHandler(W_VIEW(tb
->d
.widget
), ButtonPressMask
,
3223 handleWidgetPress
, tb
);
3224 WMUnmapWidget(tb
->d
.widget
);
3228 if (tPtr
->currentTextBlock
== tPtr
->firstTextBlock
) {
3229 if (tPtr
->currentTextBlock
->next
)
3230 tPtr
->currentTextBlock
->next
->prior
= NULL
;
3232 tPtr
->firstTextBlock
= tPtr
->currentTextBlock
->next
;
3233 tPtr
->currentTextBlock
= tPtr
->firstTextBlock
;
3235 } else if (tPtr
->currentTextBlock
== tPtr
->lastTextBlock
) {
3236 tPtr
->currentTextBlock
->prior
->next
= NULL
;
3237 tPtr
->lastTextBlock
= tPtr
->currentTextBlock
->prior
;
3238 tPtr
->currentTextBlock
= tPtr
->lastTextBlock
;
3240 tPtr
->currentTextBlock
->prior
->next
= tPtr
->currentTextBlock
->next
;
3241 tPtr
->currentTextBlock
->next
->prior
= tPtr
->currentTextBlock
->prior
;
3242 tPtr
->currentTextBlock
= tPtr
->currentTextBlock
->next
;
3249 WMDestroyTextBlock(WMText
*tPtr
, void *vtb
)
3251 TextBlock
*tb
= (TextBlock
*)vtb
;
3257 /* naturally, there's a danger to destroying
3258 widgets whose action brings us here:
3259 ie. press a button to destroy it... need to
3260 find a safer way. till then... this stays commented out */
3261 /* WMDestroyWidget(tb->d.widget);
3262 wfree(tb->d.widget); */
3263 tb
->d
.widget
= NULL
;
3265 WMReleasePixmap(tb
->d
.pixmap
);
3266 tb
->d
.pixmap
= NULL
;
3269 WMReleaseFont(tb
->d
.font
);
3272 WMReleaseColor(tb
->color
);
3273 if (tb
->sections
&& tb
->nsections
> 0)
3274 wfree(tb
->sections
);
3282 WMRefreshText(WMText
*tPtr
, int vpos
, int hpos
)
3284 if (!tPtr
|| vpos
<0 || hpos
<0)
3287 if (tPtr
->flags
.frozen
&& !tPtr
->flags
.needsRefresh
)
3290 if(tPtr
->flags
.monoFont
) {
3291 int j
, c
= WMGetArrayItemCount(tPtr
->gfxItems
);
3294 /* make sure to unmap widgets no matter where they are */
3295 for(j
=0; j
<c
; j
++) {
3296 if ((tb
= (TextBlock
*) WMGetFromArray(tPtr
->gfxItems
, j
))) {
3297 if (tb
->object
&& ((W_VIEW(tb
->d
.widget
))->flags
.mapped
))
3298 WMUnmapWidget(tb
->d
.widget
);
3304 if (tPtr
->vpos
!= vpos
) {
3305 if (vpos
< 0 || tPtr
->docHeight
< tPtr
->visible
.h
) {
3307 } else if(tPtr
->docHeight
- vpos
> tPtr
->visible
.h
- tPtr
->visible
.y
) {
3310 tPtr
->vpos
= tPtr
->docHeight
- tPtr
->visible
.h
;
3314 if (tPtr
->hpos
!= hpos
) {
3315 if (hpos
< 0 || tPtr
->docWidth
< tPtr
->visible
.w
) {
3317 } else if(tPtr
->docWidth
- hpos
> tPtr
->visible
.w
- tPtr
->visible
.x
) {
3320 tPtr
->hpos
= tPtr
->docWidth
- tPtr
->visible
.w
;
3325 tPtr
->flags
.laidOut
= False
;
3326 layOutDocument(tPtr
);
3327 updateScrollers(tPtr
);
3329 tPtr
->flags
.needsRefresh
= False
;
3334 WMSetTextForegroundColor(WMText
*tPtr
, WMColor
*color
)
3340 tPtr
->fgGC
= WMColorGC(color
);
3342 tPtr
->fgGC
= WMColorGC(WMBlackColor(tPtr
->view
->screen
));
3344 WMRefreshText(tPtr
, tPtr
->vpos
, tPtr
->hpos
);
3348 WMSetTextBackgroundColor(WMText
*tPtr
, WMColor
*color
)
3354 tPtr
->bgGC
= WMColorGC(color
);
3355 W_SetViewBackgroundColor(tPtr
->view
, color
);
3357 tPtr
->bgGC
= WMColorGC(WMWhiteColor(tPtr
->view
->screen
));
3358 W_SetViewBackgroundColor(tPtr
->view
,
3359 WMWhiteColor(tPtr
->view
->screen
));
3362 WMRefreshText(tPtr
, tPtr
->vpos
, tPtr
->hpos
);
3366 WMSetTextRelief(WMText
*tPtr
, WMReliefType relief
)
3370 tPtr
->flags
.relief
= relief
;
3375 WMSetTextHasHorizontalScroller(WMText
*tPtr
, Bool shouldhave
)
3380 if (shouldhave
&& !tPtr
->hS
) {
3381 tPtr
->hS
= WMCreateScroller(tPtr
);
3382 (W_VIEW(tPtr
->hS
))->attribs
.cursor
= tPtr
->view
->screen
->defaultCursor
;
3383 (W_VIEW(tPtr
->hS
))->attribFlags
|= CWOverrideRedirect
| CWCursor
;
3384 WMSetScrollerArrowsPosition(tPtr
->hS
, WSAMinEnd
);
3385 WMSetScrollerAction(tPtr
->hS
, scrollersCallBack
, tPtr
);
3386 WMMapWidget(tPtr
->hS
);
3387 } else if (!shouldhave
&& tPtr
->hS
) {
3388 WMUnmapWidget(tPtr
->hS
);
3389 WMDestroyWidget(tPtr
->hS
);
3395 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
3400 WMSetTextHasRuler(WMText
*tPtr
, Bool shouldhave
)
3405 if(shouldhave
&& !tPtr
->ruler
) {
3406 tPtr
->ruler
= WMCreateRuler(tPtr
);
3407 (W_VIEW(tPtr
->ruler
))->attribs
.cursor
=
3408 tPtr
->view
->screen
->defaultCursor
;
3409 (W_VIEW(tPtr
->ruler
))->attribFlags
|= CWOverrideRedirect
| CWCursor
;
3410 WMSetRulerReleaseAction(tPtr
->ruler
, rulerReleaseCallBack
, tPtr
);
3411 WMSetRulerMoveAction(tPtr
->ruler
, rulerMoveCallBack
, tPtr
);
3412 } else if(!shouldhave
&& tPtr
->ruler
) {
3413 WMShowTextRuler(tPtr
, False
);
3414 WMDestroyWidget(tPtr
->ruler
);
3417 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
3421 WMShowTextRuler(WMText
*tPtr
, Bool show
)
3428 if(tPtr
->flags
.monoFont
)
3431 tPtr
->flags
.rulerShown
= show
;
3433 WMMapWidget(tPtr
->ruler
);
3435 WMUnmapWidget(tPtr
->ruler
);
3438 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
3442 WMGetTextRulerShown(WMText
*tPtr
)
3450 return tPtr
->flags
.rulerShown
;
3455 WMSetTextHasVerticalScroller(WMText
*tPtr
, Bool shouldhave
)
3460 if (shouldhave
&& !tPtr
->vS
) {
3461 tPtr
->vS
= WMCreateScroller(tPtr
);
3462 (W_VIEW(tPtr
->vS
))->attribs
.cursor
= tPtr
->view
->screen
->defaultCursor
;
3463 (W_VIEW(tPtr
->vS
))->attribFlags
|= CWOverrideRedirect
| CWCursor
;
3464 WMSetScrollerArrowsPosition(tPtr
->vS
, WSAMaxEnd
);
3465 WMSetScrollerAction(tPtr
->vS
, scrollersCallBack
, tPtr
);
3466 WMMapWidget(tPtr
->vS
);
3467 } else if (!shouldhave
&& tPtr
->vS
) {
3468 WMUnmapWidget(tPtr
->vS
);
3469 WMDestroyWidget(tPtr
->vS
);
3475 textDidResize(tPtr
->view
->delegate
, tPtr
->view
);
3481 WMScrollText(WMText
*tPtr
, int amount
)
3486 if (amount
== 0 || !tPtr
->view
->flags
.realized
)
3490 if (tPtr
->vpos
> 0) {
3491 if (tPtr
->vpos
> abs(amount
)) tPtr
->vpos
+= amount
;
3495 int limit
= tPtr
->docHeight
- tPtr
->visible
.h
;
3496 if (tPtr
->vpos
< limit
) {
3497 if (tPtr
->vpos
< limit
-amount
) tPtr
->vpos
+= amount
;
3498 else tPtr
->vpos
= limit
;
3502 if (scroll
&& tPtr
->vpos
!= tPtr
->prevVpos
) {
3503 updateScrollers(tPtr
);
3506 tPtr
->prevVpos
= tPtr
->vpos
;
3511 WMPageText(WMText
*tPtr
, Bool direction
)
3513 if (!tPtr
) return False
;
3514 if (!tPtr
->view
->flags
.realized
) return False
;
3516 return WMScrollText(tPtr
, direction
?tPtr
->visible
.h
:-tPtr
->visible
.h
);
3520 WMSetTextEditable(WMText
*tPtr
, Bool editable
)
3524 tPtr
->flags
.editable
= editable
;
3528 WMGetTextEditable(WMText
*tPtr
)
3532 return tPtr
->flags
.editable
;
3536 WMSetTextIgnoresNewline(WMText
*tPtr
, Bool ignore
)
3540 tPtr
->flags
.ignoreNewLine
= ignore
;
3544 WMGetTextIgnoresNewline(WMText
*tPtr
)
3548 return tPtr
->flags
.ignoreNewLine
;
3552 WMSetTextUsesMonoFont(WMText
*tPtr
, Bool mono
)
3556 if (mono
&& tPtr
->flags
.rulerShown
)
3557 WMShowTextRuler(tPtr
, False
);
3559 tPtr
->flags
.monoFont
= mono
;
3560 WMRefreshText(tPtr
, tPtr
->vpos
, tPtr
->hpos
);
3564 WMGetTextUsesMonoFont(WMText
*tPtr
)
3568 return tPtr
->flags
.monoFont
;
3573 WMSetTextDefaultFont(WMText
*tPtr
, WMFont
*font
)
3578 WMReleaseFont(tPtr
->dFont
);
3580 tPtr
->dFont
= WMRetainFont(font
);
3582 tPtr
->dFont
= WMRetainFont(WMSystemFontOfSize(tPtr
->view
->screen
, 12));
3586 WMGetTextDefaultFont(WMText
*tPtr
)
3595 WMSetTextAlignment(WMText
*tPtr
, WMAlignment alignment
)
3599 tPtr
->flags
.alignment
= alignment
;
3600 WMRefreshText(tPtr
, tPtr
->vpos
, tPtr
->hpos
);
3604 WMSetTextParser(WMText
*tPtr
, WMAction
*parser
)
3608 tPtr
->parser
= parser
;
3612 WMSetTextWriter(WMText
*tPtr
, WMAction
*writer
)
3616 tPtr
->writer
= writer
;
3620 WMGetTextInsertType(WMText
*tPtr
)
3624 return tPtr
->flags
.prepend
;
3629 WMSetTextSelectionColor(WMText
*tPtr
, WMColor
*color
)
3631 if (!tPtr
|| !color
)
3634 setSelectionProperty(tPtr
, NULL
, color
);
3640 WMSetTextSelectionFont(WMText
*tPtr
, WMFont
*font
)
3645 setSelectionProperty(tPtr
, font
, NULL
);
3650 WMFreezeText(WMText
*tPtr
)
3655 tPtr
->flags
.frozen
= True
;
3659 WMThawText(WMText
*tPtr
)
3664 tPtr
->flags
.frozen
= False
;
3669 WMFindInTextStream(WMText
*tPtr
, char *needle
, Bool direction
,
3672 TextBlock
*tb
= NULL
;
3673 char *haystack
= NULL
, *mark
= NULL
;
3676 if (!tPtr
|| !needle
)
3679 if (! (tb
= tPtr
->currentTextBlock
)) {
3680 if (! (tb
= ( (direction
> 0) ?
3681 tPtr
->firstTextBlock
: tPtr
->lastTextBlock
) ) ){
3685 if(tb
!= ((direction
>0) ?tPtr
->firstTextBlock
: tPtr
->lastTextBlock
))
3686 tb
= (direction
>0) ? tb
->next
: tb
->prior
;
3689 printf("\n%p\n\n", tb
);
3694 if(pos
+1 < tb
->used
)
3697 output(tb
->text
, tb
->used
);
3698 mark
= strstr(&tb
->text
[pos
], needle
); //, tb->used);
3700 tPtr
->currentTextBlock
= tb
;
3701 tPtr
->tpos
= (int)(mark
- tb
->text
);
3702 updateCursorPosition(tPtr
);
3706 tb
= (direction
>0) ? tb
->next
: tb
->prior
;
3714 typedef struct _currentFormat
{
3719 WMRulerMargins margins
;
3720 //WMArray *aligns; // for tables...
3721 /* the following are "nested"
3722 i.e.: <b><b><i></b><b></i>
3723 1 2 1 1 2 0 get it? */
3731 WMAlignment align
:2;
3732 short ul
:3; /* how "nested"... up to 8 levels deep */
3733 short comment
:1; /* ignore text till --> */
3741 getArg(char *t
, short type
, void *arg
)
3744 while(*(++t
) && !d
) {
3746 if(*t
>='0' && *t
<='9') {
3747 sscanf(t
, "%d", arg
);
3748 while(*t
&& (*t
<'0' || *t
>'9'))
3758 parseToken(WMText
*tPtr
, char *token
, short tk
)
3760 short open
=0; /* 0 starts, 1 closes */
3762 int prepend
= WMGetTextInsertType(tPtr
);
3763 WMScreen
*scr
= tPtr
->view
->screen
;
3766 WMAppendTextBlock(tPtr
, WMCreateTextBlockWithText(tPtr
,
3767 NULL
, cfmt
.cfont
, cfmt
.ccolor
, True
, 0));
3772 while(*token
&& *token
== ' ')
3779 while(*token
== ' ')
3783 if(!tPtr
->flags
.parsingHTML
) {
3784 if(mystrcasecmp(token
, "html", 4, False
)) {
3785 printf("got HTMLLLL: [%s]\n", token
);
3786 tPtr
->flags
.parsingHTML
= True
;
3788 WMAppendTextBlock(tPtr
, WMCreateTextBlockWithText(tPtr
,
3789 token
, cfmt
.cfont
, cfmt
.ccolor
, cfmt
.first
, strlen(token
)));
3796 if(strlen(token
)==1) {
3797 /* nice and fast for small tokens... no need for too much brain
3799 switch(TOLOWER(*token
)) {
3802 cfmt
.cfont
= WMConvertFontToItalic(scr
, cfmt
.cfont
);
3803 WMAddToArray(cfmt
.fonts
, (void *)cfmt
.cfont
);
3804 } else { /*dun wanna remove the baseFont eh? */
3805 int count
= WMGetArrayItemCount(cfmt
.fonts
);
3807 WMDeleteFromArray(cfmt
.fonts
, count
-1);
3809 cfmt
.cfont
= (WMFont
*)WMGetFromArray(cfmt
.fonts
,
3810 WMGetArrayItemCount(cfmt
.fonts
)-1);
3811 }printf("i\n"); break;
3815 cfmt
.cfont
= WMConvertFontToBold(scr
, cfmt
.cfont
);
3816 WMAddToArray(cfmt
.fonts
, (void *)cfmt
.cfont
);
3817 } else { /*dun wanna remove the baseFont eh? */
3818 int count
= WMGetArrayItemCount(cfmt
.fonts
);
3820 WMDeleteFromArray(cfmt
.fonts
, count
-1);
3821 cfmt
.cfont
= (WMFont
*)WMGetFromArray(cfmt
.fonts
,
3822 WMGetArrayItemCount(cfmt
.fonts
)-1);
3826 tb
= WMCreateTextBlockWithText(tPtr
, NULL
, cfmt
.cfont
,
3827 cfmt
.ccolor
, cfmt
.first
, 0);
3828 // WMSetTextBlockProperties(tb, cfmt.first, False, (cfmt.u?1:0), 0, cfmt.margins);
3829 WMAppendTextBlock(tPtr
, tb
);
3832 case 'u': cfmt
.u
= !open
; break;
3835 if(mystrcasecmp(token
, "br", 2, False
)) {
3838 else if(mystrcasecmp(token
, "ul", 2, False
)) {
3840 if(cfmt
.ul
>1) cfmt
.ul
--;
3843 cfmt
.bmargin
= cfmt
.ul
*30;
3844 cfmt
.fmargin
= cfmt
.bmargin
-10;
3845 } else cfmt
.fmargin
= cfmt
.bmargin
= 0;
3846 } else if(mystrcasecmp(token
, "li", 2, False
)) {
3848 //change margins... create a new margin....
3849 //(cfmt.fmargin, cfmt.bmargin,
3850 } else if(mystrcasecmp(token
, "html", 4, False
)) {
3851 tPtr
->flags
.parsingHTML
= !open
;
3853 } else if(mystrcasecmp(token
, "align", 5, False
))
3855 else if(mystrcasecmp(token
, "img", 3, False
)) {
3860 while(*token
== ' ') token
++;
3862 switch(TOLOWER(*token
)) {
3864 if(TOLOWER(*(1+token
)) == 'r' && TOLOWER(*(2+token
)) == 'c') {
3865 mark
= strchr(token
, '=');
3867 char img
[256], *iptr
;
3870 sscanf(token
, "%s", img
);
3872 if(*img
== '\"') { img
[strlen(img
)-1] = 0; iptr
++;}
3873 pixmap
= WMCreatePixmapFromFile(scr
, iptr
);
3875 tb
= WMCreateTextBlockWithPixmap(tPtr
, pixmap
,
3876 iptr
, cfmt
.ccolor
, cfmt
.first
, 0);
3877 // WMSetTextBlockProperties(tb, cfmt.first,
3878 // False, (cfmt.u?1:0), 0, cfmt.margins);
3879 WMAppendTextBlock(tPtr
, tb
);
3882 //printf("[%s]\n", iptr);
3883 } } break; } } while(*(token
++));
3885 } else if(mystrcasecmp(token
, "font", 4, False
)) {
3888 cfmt
.cfont
= (WMFont
*)WMGetFromArray(cfmt
.fonts
,
3889 WMGetArrayItemCount(cfmt
.fonts
)-1);
3891 (WMColor
*)WMGetFromArray(cfmt
.colors
,
3892 WMGetArrayItemCount(cfmt
.colors
)-1),
3895 else if(mystrcasecmp(token
, "center", 6, False
)) {
3897 if(open
) cfmt
.align
= WALeft
;
3898 else cfmt
.align
= WACenter
;
3907 //printf("parse token (%s)[%s]\n", open?"close":"open", token);
3910 //while(*token && !isspace(*(token))) token++;
3911 //printf("A:%d a:%d z%d Z%d\n", '1', 'a', 'Z', 'z');
3914 if(c
>=65 && c
<=122) { major
[i
++] = c
;
3915 } else if(c
==' ' || c
=='='){ major
[i
] = 0; i
=0; mm
=1;
3916 printf("\nmajor: [%s]", major
);}
3920 } else { minor
[i
] = 0; i
=0; printf(" minor: [%s] ", minor
);}
3922 }while((c
= *(++token
)));
3926 //printf("parse token (%s)[%s]\n", open?"close":"open", token);