-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.c
1062 lines (908 loc) · 26.5 KB
/
display.c
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* (C) 1996 by Marcin Dalecki <[email protected]>
*
* This file is part of the Motif Info browser.
*
* The MInfo program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <Xm/MainW.h>
#include <Xm/PanedW.h>
#include <Xm/Form.h>
#include <Xm/RowColumn.h>
#include <Xm/PushBG.h>
#include <Xm/LabelG.h>
#include <Xm/ScrolledW.h>
#include <Xm/List.h>
#include <Xm/Text.h>
#include <Xm/TextP.h>
#include <Xm/TextOutP.h>
#include <Xm/TextF.h>
#include <Xm/Label.h>
#include <Xm/MessageB.h>
#include <Xm/FileSB.h>
#include <stdio.h>
#include <string.h>
#include "parse.h"
#include "display.h"
#include "fops.h"
Widget node_text;
Widget location_text;
Widget back_button;
Widget fwrd_button;
Widget prev_button;
Widget top_button;
Widget next_button;
Widget home_button;
Widget search_button;
Widget top_menu_button;
Widget next_menu_button;
Widget prev_menu_button;
Widget home_menu_button;
Widget menu_menu_pullright;
Widget menu_item_button;
Widget menu_node_button;
Widget xref_menu_pullright;
Widget xref_item_button;
Widget xref_node_button;
Widget popup_next;
Widget popup_prev;
Widget popup_top;
/*
* This isn't quite the right place for the definition...
* Perhaps we should move the whole handling of bookmark's to this
* file.
*/
Widget bookmark_menu;
struct page *current_page;
struct page_stack *page_stack;
struct page_stack *fwrd_stack;
/*
* Used by the drawing routines for special elements
*/
Pixel trough_pixel;
Pixel background_pixel;
Pixel top_pixel;
Pixel bottom_pixel;
void display_page(struct page *page)
{
char label[512];
char *s[10];
int i, n;
Boolean set;
Widget w;
/*
* Update the sesitivity of the all the navigation buttons.
*/
set = (page->Prev != NULL);
XtSetSensitive(prev_button, set);
XtSetSensitive(prev_menu_button, set);
XtSetSensitive(popup_prev, set);
set = (page->Up != NULL);
XtSetSensitive(top_button, set);
XtSetSensitive(top_menu_button, set);
XtSetSensitive(popup_top, set);
set = (page->Next != NULL);
XtSetSensitive(next_button, set);
XtSetSensitive(next_menu_button, set);
XtSetSensitive(popup_next, set);
set = (page->menu != NULL);
XtSetSensitive(menu_item_button, set);
XtSetSensitive(menu_node_button, set);
XtSetSensitive(menu_menu_pullright, set);
set = (page->note != NULL);
XtSetSensitive(xref_item_button, set);
XtSetSensitive(xref_node_button, set);
XtSetSensitive(xref_menu_pullright, set);
/*
* Inform the user where we are currently
*/
label[0] = '\0';
n = 0;
if (page->File) {
s[n++] = strdup("File ");
s[n++] = strdup(page->File);
}
if (page->Node) {
s[n++] = strdup(", Node ");
s[n++] = strdup(page->Node);
}
if (page->Next) {
s[n++] = strdup(", Next ");
s[n++] = strdup(page->Next);
}
if (page->Prev) {
s[n++] = strdup(", Prev ");
s[n++] = strdup(page->Prev);
}
if (page->Up) {
s[n++] = strdup(", Up ");
s[n++] = strdup(page->Up);
}
for (i = 0; i < n; ++i) {
strcat(label, s[i]);
free(s[i]);
}
XmTextFieldSetString(location_text, label);
XtVaGetValues(XtParent(node_text), XmNverticalScrollBar, &w, NULL);
/*
* preserve current position vales
*/
if (current_page) {
current_page->saved_pos = XmTextGetInsertionPosition(node_text);
if (w)
XtVaGetValues(w, XmNvalue, ¤t_page->saved_sbar, NULL);
}
XmTextClearSelection(node_text,
XtLastTimestampProcessed(XtDisplay(top_level)));
/*
* Make sure it doesn't try anything cute until we're ready
*/
XmTextDisableRedisplay(node_text);
XmTextSetString(node_text, page->text);
/*
* Make sure we return to the previous position if we had
* already visited this page.
*/
XmTextSetInsertionPosition(node_text, page->saved_pos);
XmTextScroll(node_text, page->saved_sbar);
/*
* Update the page stack.
*/
if (current_page) {
struct page_stack *stack;
stack = (struct page_stack *) malloc(sizeof(struct page_stack));
stack->page = current_page;
stack->prev = page_stack;
page_stack = stack;
XtSetSensitive(back_button, True);
}
current_page = page;
/* Go for redisplay */
XmTextEnableRedisplay(node_text);
}
/*
* Customized drawing routines for our widget
*/
/*
* Graphis context setup used to draw normal text
*/
static void set_normal_gc(XmTextWidget tw, GC gc)
{
XGCValues gcv;
gcv.background = tw->core.background_pixel;
gcv.foreground = tw->primitive.foreground;
XChangeGC(XtDisplay(tw), gc, GCForeground | GCBackground, &gcv);
}
/*
* Graphics context used to fill out normal text areas.
*/
static void set_inverse_gc(XmTextWidget tw, GC gc)
{
XGCValues gcv;
gcv.foreground = tw->core.background_pixel;
gcv.background = tw->primitive.foreground;
XChangeGC(XtDisplay(tw), gc, GCForeground | GCBackground, &gcv);
}
/*
* Graphics context used to fill out areas in selections.
*/
static void set_selection_gc(XmTextWidget tw, GC gc)
{
XGCValues gcv;
gcv.foreground = app_data.hbgpixel;
gcv.background = app_data.hfgpixel;
XChangeGC(XtDisplay(tw), gc, GCForeground | GCBackground, &gcv);
}
/*
* Graphics context used to draw text in selections and non visited links.
*/
static void set_highlight_gc(XmTextWidget tw, GC gc)
{
XGCValues gcv;
gcv.foreground = app_data.hfgpixel;
gcv.background = app_data.hbgpixel;
XChangeGC(XtDisplay(tw), gc, GCForeground | GCBackground, &gcv);
}
/*
* Graphics context setup for links which had been already visited
* during this session.
*/
static void set_visited_gc(XmTextWidget tw, GC gc)
{
XGCValues gcv;
gcv.foreground = app_data.vfgpixel;
gcv.background = app_data.hbgpixel;
XChangeGC(XtDisplay(tw), gc, GCForeground | GCBackground, &gcv);
}
static void set_margin_clip(XmTextWidget tw, GC gc)
{
XRectangle rect;
Dimension mwidth = tw->text.margin_width +
tw->primitive.shadow_thickness +
tw->primitive.highlight_thickness;
Dimension mheight = tw->text.margin_height +
tw->primitive.shadow_thickness +
tw->primitive.highlight_thickness;
if (mwidth < tw->core.width)
rect.x = mwidth;
else
rect.x = tw->core.width;
if (mheight < tw->core.height)
rect.y = mheight;
else
rect.y = tw->core.height;
if (2 * mwidth < tw->core.width)
rect.width = tw->core.width - 2 * mwidth;
else
rect.width = 0;
if (2 * mheight < tw->core.height)
rect.height = tw->core.height - 2 * mheight;
else
rect.height = 0;
XSetClipRectangles(XtDisplay(tw), gc, 0, 0, &rect, 1, Unsorted);
}
static void set_full_clip(XmTextWidget tw, GC gc)
{
XRectangle rect;
int shade = tw->primitive.highlight_thickness
+ tw->primitive.shadow_thickness;
rect.y = rect.x = shade;
rect.width = tw->core.width - 2 * shade;
rect.height = tw->core.height - 2 * shade;
XSetClipRectangles(XtDisplay(tw), gc, 0, 0, &rect, 1, Unsorted);
}
/*
* Routines used to draw non texttrual elements.
*/
static void draw_dot(Display * d, Window w, GC gc,
int x, int y,
int width)
{
XFillArc(d, w, gc, x, y, width, width, 0, 23040);
XDrawArc(d, w, gc, x, y, width, width, 0, 23040);
}
static void draw_odot(Display * d, Window w, GC gc,
int x, int y,
int width)
{
XDrawArc(d, w, gc, x, y, width, width, 0, 23040);
}
static void draw_shade_line(Display * d, Window w, GC gc,
int x, int y, int width)
{
XGCValues gcv;
gcv.foreground = background_pixel;
XChangeGC(d, gc, GCForeground, &gcv);
XDrawLine(d, w, gc, x, y, x + width, y);
gcv.foreground = top_pixel;
XChangeGC(d, gc, GCForeground, &gcv);
XDrawLine(d, w, gc, x, y - 1, x + width, y - 1);
XDrawPoint(d, w, gc, x, y);
XDrawPoint(d, w, gc, x, y + 1);
gcv.foreground = bottom_pixel;
XChangeGC(d, gc, GCForeground, &gcv);
XDrawLine(d, w, gc, x + 1, y + 1, x + width, y + 1);
XDrawPoint(d, w, gc, x + width - 1, y);
}
static void draw_arrow(Display * d, Window w, GC gc,
int x, int y,
int width, int height)
{
XGCValues gcv;
XPoint segs[8];
segs[0].x = x;
segs[0].y = y + height / 4;
segs[1].x = x;
segs[1].y = y - height / 4;
segs[2].x = x + width - height / 2 - 1;
segs[2].y = y - height / 4;
segs[3].x = x + width - height / 2 - 1;
segs[3].y = y - height / 2;
segs[4].x = x + width - 1;
segs[4].y = y;
segs[5].x = x + width - height / 2 - 1;
segs[5].y = y + height / 2;
segs[6].x = x + width - height / 2 - 1;
segs[6].y = y + height / 4; /* remove +1 if using XDrawLines */
segs[7].x = x;
segs[7].y = y + height / 4; /* remove +1 if using XDrawLines */
gcv.foreground = background_pixel;
XChangeGC(d, gc, GCForeground, &gcv);
XFillPolygon(d, w, gc, segs, 8, Complex, CoordModeOrigin);
gcv.foreground = top_pixel;
XChangeGC(d, gc, GCForeground, &gcv);
XDrawLines(d, w, gc, segs, 5, CoordModeOrigin);
XDrawPoints(d, w, gc, segs, 5, CoordModeOrigin);
gcv.foreground = bottom_pixel;
XChangeGC(d, gc, GCForeground, &gcv);
XDrawLines(d, w, gc, segs + 4, 4, CoordModeOrigin);
XDrawPoints(d, w, gc, segs + 4, 4, CoordModeOrigin);
}
/*
* Determine the displaying width of a particular character
*/
static int character_width(XmTextWidget tw, XFontStruct * font,
int x,
XmTextBlock block,
int from, int to)
{
OutputData data = tw->text.output->data;
char *ptr;
unsigned char c;
int i;
int result = 0;
for (i = from, ptr = block->ptr + from; i < to; i++, ptr++) {
c = (unsigned char) *ptr;
if (c == '\t')
result += (data->tabwidth -
((x + result - data->leftmargin) % data->tabwidth));
else {
if (font->per_char) {
if (c >= font->min_char_or_byte2 && c <= font->max_char_or_byte2)
result += font->per_char[c - font->min_char_or_byte2].width;
else if (font->default_char >= font->min_char_or_byte2 &&
font->default_char <= font->max_char_or_byte2)
result += font->per_char[font->default_char -
font->min_char_or_byte2].width;
else
result += font->min_bounds.width;
} else
result += font->min_bounds.width;
}
}
return result;
}
/*
* Check if we are inside the refference chain initiated by xref.
* Return the refference we are in or NULL otherwise.
*
* This routine is used in the resolving of click's too.
*/
struct menu *check_in_xref(struct menu *xref, int start, int stop)
{
while (xref) {
if ((xref->start >= start && xref->start <= stop)
|| (xref->stop >= start && xref->stop <= stop)
|| (start >= xref->start && stop <= xref->stop))
return xref;
xref = xref->next;
}
return NULL;
}
/*
* Check if we are inside the underlined part of a refference chain
* initiated by xref. Return the refference we are in or NULL otherwise.
*/
static struct menu *check_in_uline(struct menu *xref, int start, int stop)
{
while (xref) {
if ((xref->ustart >= start && xref->ustart <= stop)
|| (xref->ustop >= start && xref->ustop <= stop)
|| (start >= xref->ustart && stop <= xref->ustop))
return xref;
xref = xref->next;
}
return NULL;
}
/*
* Check if we are inside of some special drawing area.
*/
static enum chunk_kind check_in_chunk(struct page *page, int start, int stop, struct chunk **chunk)
{
struct chunk *c;
if (!page)
return 0;
for (c = page->chunk; c; c = c->next)
if (start >= c->start && stop <= c->stop) {
*chunk = c;
return c->kind;
}
*chunk = NULL;
return NO_CHUNK;
}
/*
* Get the text from the previous line above the index positions
* between start and stop.
* The is needed to fixup compleatly the redrawing of underlines in
* headers. Otherise, we would get some blank areas.
*/
static int get_above(char *text, int start)
{
int i;
int delta;
i = start - 1;
while (i >= 0 && text[i] != '\n')
--i;
if (i < 0)
return -1;
delta = start - i;
do
--i;
while (i >= 0 && text[i] != '\n');
return i + delta;
}
/*
* This is the main drawing routine, which will be substitued
* as the drawing engine of the motif Text widget, which we are
* using to display our text.
*
* Pleas don't get the impression that I'm always writing such
* messy code. This here isn't jsut going to control any aeroplain,
* so I did it in a hurry of one day. Just coding ahead to make
* it produce somehow reasonable result.
*
* In fact currently I'm already quite pleased by the result's.
*/
void do_draw(XmTextWidget tw, LineNum line,
XmTextPosition start, XmTextPosition end,
XmHighlightMode highlight)
{
OutputData data = tw->text.output->data;
XmTextPosition linestart, nextlinestart;
LineTableExtra extra;
XmTextBlockRec block;
int x, y, length, newx, i;
int text_border;
int rightedge;
Boolean stipple = False;
int width, height;
int rec_width = 0;
int rec_height = 0;
Boolean cleartoend;
Boolean cleartobottom;
XmHighlightMode endhighlight = highlight;
/*
* Some Motif internal functins, we can't miss here
*/
extern void _XmTextLineInfo();
extern void _XmTextAdjustGC();
/*
* Variables used to determine the position of strings drawn in the
* text source.
*/
int text_start;
int text_stop;
char *text;
/*
* Variables used for code abbreviation.
*/
Dimension ctxt_width;
Dimension ctxt_height;
Window w;
Display *d;
int font_height;
int stop;
char *old_ptr;
int old_start;
/*
* Variables used to determine the drawing method for headers;
*/
enum chunk_kind in_chunk = NO_CHUNK;
Boolean in_head;
Boolean in_uline;
XFontStruct *font;
int head_bias; /* The amount, by which we let header lines
protrude into the next line */
struct chunk *chunk; /* Used to remember the whole chunk we are in */
/*
* Deffensive, as we are...
*/
if (!XtIsRealized((Widget) tw))
return;
if (!current_page)
return;
text = current_page->text;
stop = end;
ctxt_width = tw->text.inner_widget->core.width - data->rightmargin;
ctxt_height = tw->text.inner_widget->core.height - data->bottommargin;
w = XtWindow(tw->text.inner_widget);
d = XtDisplay(tw);
rightedge = ctxt_width + data->hoffset;
_XmTextLineInfo(tw, line + 1, &nextlinestart, &extra);
_XmTextLineInfo(tw, line, &linestart, &extra);
_XmTextAdjustGC(tw);
if (!XtIsSensitive((Widget) tw))
stipple = True;
if (linestart == PASTENDPOS) {
start = end = nextlinestart = PASTENDPOS;
cleartoend = cleartobottom = True;
} else if (nextlinestart == PASTENDPOS) {
nextlinestart = (*tw->text.source->Scan) (tw->text.source, 0,
XmSELECT_ALL, XmsdRight, 1,
False);
cleartoend = cleartobottom = (end >= nextlinestart);
if (start >= nextlinestart)
endhighlight = highlight = XmHIGHLIGHT_NORMAL;
else if (cleartoend)
endhighlight = XmHIGHLIGHT_NORMAL;
} else {
cleartobottom = False;
cleartoend = (end >= nextlinestart);
if (cleartoend && (!extra || !extra->wrappedbychar))
end = (*tw->text.source->Scan) (tw->text.source, nextlinestart,
XmSELECT_POSITION, XmsdLeft, 1, True);
}
y = data->topmargin + line * data->lineheight + data->font_ascent;
x = data->leftmargin;
font = data->font;
font_height = font->ascent + font->descent;
/*
* Determine the drawing method and setup corresponding values.
*/
in_chunk = check_in_chunk(current_page, start, end, &chunk);
in_uline = (in_chunk == ULINE1 || in_chunk == ULINE2 || in_chunk == ULINE3 || in_chunk == ULINE4);
in_head = (in_chunk == HEAD1 || in_chunk == HEAD2 || in_chunk == HEAD3 || in_chunk == HEAD4);
if (in_chunk == HEAD1 || in_chunk == ULINE1)
font = app_data.h1_font;
else if (in_chunk == HEAD2 || in_chunk == ULINE2)
font = app_data.h2_font;
else if (in_chunk == HEAD3 || in_chunk == ULINE3)
font = app_data.h3_font;
else if (in_chunk == HEAD4 || in_chunk == ULINE4)
font = app_data.h4_font;
else if (in_chunk == MENUHEAD)
font = app_data.h4_font;
head_bias = 0;
if (font != data->font)
head_bias = font->ascent + font->descent -
data->font->ascent - data->font->descent;
if (head_bias < 0)
head_bias = 0;
XSetFont(d, data->gc, font->fid);
while (linestart < start && x <= rightedge) {
linestart = (*tw->text.source->ReadSource) (tw->text.source,
linestart, start, &block);
x += character_width(tw, font, x, &block, 0, block.length);
}
newx = x;
while (start < end && x <= rightedge) {
old_start = start;
start = (*tw->text.source->ReadSource) (tw->text.source, start,
end, &block);
old_ptr = block.ptr;
while (block.length > 0) {
/*
* Drawing of tabs is handled in this loop
*/
while (block.ptr[0] == '\t') {
newx = x;
while (block.length > 0 && newx - data->hoffset < data->leftmargin) {
width = character_width(tw, font, newx, &block, 0, 1);
newx += width;
if (newx - data->hoffset < data->leftmargin) {
block.length--;
block.ptr++;
x = newx;
}
}
if (block.length <= 0 || block.ptr[0] != '\t')
break;
width = character_width(tw, font, x, &block, 0, 1);
if (highlight == XmHIGHLIGHT_SELECTED)
set_selection_gc(tw, data->gc);
else
set_inverse_gc(tw, data->gc);
set_full_clip(tw, data->gc);
if (((x - data->hoffset) + width) > ctxt_width)
rec_width = ctxt_width - (x - data->hoffset);
else
rec_width = width;
if (y + data->font_descent > ctxt_height)
rec_height = ctxt_height - y;
else
rec_height = font_height;
XFillRectangle(d, w, data->gc,
x - data->hoffset, y - data->font_ascent,
rec_width, rec_height);
set_margin_clip(tw, data->gc);
x += width;
block.length--;
block.ptr++;
if (block.length <= 0)
break;
}
if (block.length <= 0)
break;
for (length = 0; length < block.length; length++) {
if (block.ptr[length] == '\t')
break;
}
newx = x;
while (length > 0 && newx - data->hoffset < data->leftmargin) {
newx += character_width(tw, font, newx, &block, 0, 1);
if (newx - data->hoffset < data->leftmargin) {
--length;
--block.length;
++block.ptr;
x = newx;
}
}
if (!length)
continue;
newx = x + character_width(tw, font, x, &block, 0, length);
if (newx > rightedge) {
newx = x;
for (i = 0; i < length && newx <= rightedge; ++i)
newx += character_width(tw, font, newx, &block, i, i + 1);
goto clear_left_margin;
}
if (highlight == XmHIGHLIGHT_SELECTED) {
/* Draw the inverse background, then draw the text over it */
set_selection_gc(tw, data->gc);
set_full_clip(tw, data->gc);
if (((x - data->hoffset) + (newx - x)) > ctxt_width)
rec_width = ctxt_width - (x - data->hoffset);
else
rec_width = newx - x;
if (y + data->font_descent > ctxt_height)
rec_height = ctxt_height - (y - data->font_ascent);
else
rec_height = font_height;
XFillRectangle(d, w,
data->gc, x - data->hoffset,
y - data->font_ascent, rec_width, rec_height);
set_highlight_gc(tw, data->gc);
set_margin_clip(tw, data->gc);
text_start = old_start + block.ptr - old_ptr;
if (in_uline) {
int above;
above = get_above(text, text_start);
if (above >= 0)
XDrawString(d, w, data->gc,
x - data->hoffset,
y + head_bias - font_height,
text + above, length);
} else
XDrawString(d, w, data->gc,
x - data->hoffset, y + head_bias,
block.ptr, length);
} else {
/*
* First clear the area we will draw
*/
set_inverse_gc(tw, data->gc);
if (newx > x) {
if (y + data->font_descent > ctxt_height)
rec_height = ctxt_height - (y - data->font_ascent);
else
rec_height = font_height;
XFillRectangle(d, w,
data->gc, x - data->hoffset,
y - data->font_ascent, newx - x,
rec_height);
}
/*
* And now redraw the string over it
*/
set_normal_gc(tw, data->gc);
text_start = old_start + block.ptr - old_ptr;
text_stop = text_start + length;
if (in_uline) {
int above;
above = get_above(text, text_start);
if (above >= 0)
XDrawString(d, w, data->gc,
x - data->hoffset,
y + head_bias - font_height,
text + above, length);
} else if (in_chunk == FOOTNOTE) {
draw_shade_line(d, w, data->gc,
x - data->hoffset,
y,
character_width(tw, font, x, &block, 0, length));
} else
XDrawString(d, w, data->gc,
x - data->hoffset, y + head_bias,
block.ptr, length);
/*
* Clear the '*' from "* Menu:"
*/
if (in_chunk == MENUHEAD && text_start == chunk->start) {
set_inverse_gc(tw, data->gc);
XDrawString(d, w, data->gc,
x - data->hoffset, y,
"*", 1);
}
if (in_chunk == LISTITEM && text_start >= chunk->start
&& text_start <= chunk->start + 3) {
int tmpx;
int width = (font->max_bounds.lbearing +
font->max_bounds.rbearing) / 2;
tmpx = x - data->hoffset + XTextWidth(font, " ",
3 - (text_start - chunk->start));
set_inverse_gc(tw, data->gc);
XDrawString(d, w, data->gc, tmpx, y, "*", 1);
set_normal_gc(tw, data->gc);
draw_dot(d, w, data->gc, tmpx,
y - width / 2 - font->ascent / 2,
width);
}
if (in_chunk == SUBITEM && text_start >= chunk->start
&& text_start <= chunk->start + 3) {
int tmpx;
int width = (font->max_bounds.lbearing +
font->max_bounds.rbearing) / 2;
tmpx = x - data->hoffset + XTextWidth(font, " ",
3 - (text_start - chunk->start));
set_inverse_gc(tw, data->gc);
XDrawString(d, w, data->gc, tmpx, y, "-", 1);
set_normal_gc(tw, data->gc);
draw_odot(d, w, data->gc, tmpx,
y - width / 2 - font->ascent / 2,
width);
}
/*
* Determine if we are drawing inside of some
* note and overdraw it with highlight as needed.
*/
{
int i;
struct menu *xref;
xref = current_page->note;
for (i = 0; i < 2; ++i) {
while ((xref = check_in_xref(xref,
text_start,
text_stop))) {
int first;
int last;
int tmpx = x;
if (xref->start > text_start) {
first = xref->start;
tmpx += character_width(tw, font, tmpx, &block,
0,
first - text_start);
} else
first = text_start;
if (xref->stop > text_stop)
last = text_stop;
else
last = xref->stop;
tmpx -= data->hoffset;
if (xref->visited)
set_visited_gc(tw, data->gc);
else
set_highlight_gc(tw, data->gc);
XDrawString(d, w, data->gc,
tmpx, y,
block.ptr + first - text_start,
last - first);
/*
* Delete the asterix and draw a nice circle
* instead.
*/
if (first == xref->start) {
int width = (font->max_bounds.lbearing +
font->max_bounds.rbearing) / 2;
int height;
set_inverse_gc(tw, data->gc);
XDrawString(d, w, data->gc,
tmpx, y,
"*", 1);
if (i == 0) {
XDrawString(d, w, data->gc,
tmpx, y,
"*note", 5);
XDrawString(d, w, data->gc,
tmpx, y,
"*Note", 5);
}
if (xref->visited)
set_visited_gc(tw, data->gc);
else
set_highlight_gc(tw, data->gc);
XSetLineAttributes(d, data->gc, 1,
LineSolid, CapButt, JoinBevel);
if (i == 0) {
height = font->ascent;
width = XTextWidth(font, "*note", 5);
draw_arrow(d, w, data->gc,
tmpx, y - font->ascent / 2,
width, height);
} else
draw_dot(d, w, data->gc, tmpx,
y - width / 2 - font->ascent / 2,
width);
}
xref = xref->next;
}
xref = current_page->menu;
}
/*
* Now draw the underlines, in a much similiar way.
*/
xref = current_page->note;
for (i = 0; i < 2; ++i) {
while ((xref = check_in_uline(xref,
text_start,
text_stop))) {
int first;
int last;
int tmpx = x;
if (xref->ustart > text_start) {
first = xref->ustart;
tmpx += character_width(tw, font, tmpx, &block,
0,
first - text_start);
} else
first = text_start;
if (xref->ustop > text_stop)
last = text_stop;
else
last = xref->ustop;
if (xref->visited)