00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <stdio.h>
00041 #include <ctype.h>
00042 #include <X11/IntrinsicP.h>
00043 #include <X11/StringDefs.h>
00044 #include <X11/Xaw3d/XawInit.h>
00045 #include <X11/Xaw3d/TextSinkP.h>
00046 #include <X11/Xaw3d/TextP.h>
00047
00048
00049
00050
00051
00052
00053
00054 static void ClassPartInitialize(), Initialize(), Destroy();
00055 static Boolean SetValues();
00056
00057 static int MaxHeight(), MaxLines();
00058 static void DisplayText(), InsertCursor(), ClearToBackground(), FindPosition();
00059 static void FindDistance(), Resolve(), SetTabs(), GetCursorBounds();
00060
00061 #define offset(field) XtOffsetOf(TextSinkRec, text_sink.field)
00062 static XtResource resources[] = {
00063 {XtNforeground, XtCForeground, XtRPixel, sizeof (Pixel),
00064 offset(foreground), XtRString, XtDefaultForeground},
00065 {XtNbackground, XtCBackground, XtRPixel, sizeof (Pixel),
00066 offset(background), XtRString, XtDefaultBackground},
00067 };
00068 #undef offset
00069
00070 #define SuperClass (&objectClassRec)
00071 TextSinkClassRec textSinkClassRec = {
00072 {
00073
00074 (WidgetClass) SuperClass,
00075 "TextSink",
00076 sizeof(TextSinkRec),
00077 XawInitializeWidgetSet,
00078 ClassPartInitialize,
00079 FALSE,
00080 Initialize,
00081 NULL,
00082 NULL,
00083 NULL,
00084 0,
00085 resources,
00086 XtNumber(resources),
00087 NULLQUARK,
00088 FALSE,
00089 FALSE,
00090 FALSE,
00091 FALSE,
00092 Destroy,
00093 NULL,
00094 NULL,
00095 SetValues,
00096 NULL,
00097 NULL,
00098 NULL,
00099 NULL,
00100 XtVersion,
00101 NULL,
00102 NULL,
00103 NULL,
00104 NULL,
00105 NULL
00106 },
00107
00108 {
00109 DisplayText,
00110 InsertCursor,
00111 ClearToBackground,
00112 FindPosition,
00113 FindDistance,
00114 Resolve,
00115 MaxLines,
00116 MaxHeight,
00117 SetTabs,
00118 GetCursorBounds,
00119 }
00120 };
00121
00122 WidgetClass textSinkObjectClass = (WidgetClass)&textSinkClassRec;
00123
00124 static void
00125 ClassPartInitialize(wc)
00126 WidgetClass wc;
00127 {
00128 TextSinkObjectClass t_src, superC;
00129
00130 t_src = (TextSinkObjectClass) wc;
00131 superC = (TextSinkObjectClass) t_src->object_class.superclass;
00132
00133
00134
00135
00136
00137
00138 if (t_src->text_sink_class.DisplayText == XtInheritDisplayText)
00139 t_src->text_sink_class.DisplayText = superC->text_sink_class.DisplayText;
00140
00141 if (t_src->text_sink_class.InsertCursor == XtInheritInsertCursor)
00142 t_src->text_sink_class.InsertCursor =
00143 superC->text_sink_class.InsertCursor;
00144
00145 if (t_src->text_sink_class.ClearToBackground== XtInheritClearToBackground)
00146 t_src->text_sink_class.ClearToBackground =
00147 superC->text_sink_class.ClearToBackground;
00148
00149 if (t_src->text_sink_class.FindPosition == XtInheritFindPosition)
00150 t_src->text_sink_class.FindPosition =
00151 superC->text_sink_class.FindPosition;
00152
00153 if (t_src->text_sink_class.FindDistance == XtInheritFindDistance)
00154 t_src->text_sink_class.FindDistance =
00155 superC->text_sink_class.FindDistance;
00156
00157 if (t_src->text_sink_class.Resolve == XtInheritResolve)
00158 t_src->text_sink_class.Resolve = superC->text_sink_class.Resolve;
00159
00160 if (t_src->text_sink_class.MaxLines == XtInheritMaxLines)
00161 t_src->text_sink_class.MaxLines = superC->text_sink_class.MaxLines;
00162
00163 if (t_src->text_sink_class.MaxHeight == XtInheritMaxHeight)
00164 t_src->text_sink_class.MaxHeight = superC->text_sink_class.MaxHeight;
00165
00166 if (t_src->text_sink_class.SetTabs == XtInheritSetTabs)
00167 t_src->text_sink_class.SetTabs = superC->text_sink_class.SetTabs;
00168
00169 if (t_src->text_sink_class.GetCursorBounds == XtInheritGetCursorBounds)
00170 t_src->text_sink_class.GetCursorBounds =
00171 superC->text_sink_class.GetCursorBounds;
00172 }
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 static void
00184 Initialize(request, new, args, num_args)
00185 Widget request, new;
00186 ArgList args;
00187 Cardinal *num_args;
00188 {
00189 TextSinkObject sink = (TextSinkObject) new;
00190
00191 sink->text_sink.tab_count = 0;
00192 sink->text_sink.tabs = NULL;
00193 sink->text_sink.char_tabs = NULL;
00194 }
00195
00196
00197
00198
00199
00200
00201
00202
00203 static void
00204 Destroy(w)
00205 Widget w;
00206 {
00207 TextSinkObject sink = (TextSinkObject) w;
00208
00209 XtFree((char *) sink->text_sink.tabs);
00210 XtFree((char *) sink->text_sink.char_tabs);
00211 }
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 static Boolean
00223 SetValues(current, request, new, args, num_args)
00224 Widget current, request, new;
00225 ArgList args;
00226 Cardinal *num_args;
00227 {
00228 TextSinkObject w = (TextSinkObject) new;
00229 TextSinkObject old_w = (TextSinkObject) current;
00230
00231 if (w->text_sink.foreground != old_w->text_sink.foreground)
00232 ((TextWidget)XtParent(new))->text.redisplay_needed = True;
00233
00234 return FALSE;
00235 }
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 static void
00258 DisplayText(w, x, y, pos1, pos2, highlight)
00259 Widget w;
00260 Position x, y;
00261 Boolean highlight;
00262 XawTextPosition pos1, pos2;
00263 {
00264 return;
00265 }
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 static void
00280 InsertCursor(w, x, y, state)
00281 Widget w;
00282 Position x, y;
00283 XawTextInsertState state;
00284 {
00285 return;
00286 }
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 static void
00299 ClearToBackground (w, x, y, width, height)
00300 Widget w;
00301 Position x, y;
00302 Dimension width, height;
00303 {
00304
00305
00306
00307
00308
00309 if ( (height == 0) || (width == 0) ) return;
00310 XClearArea(XtDisplayOfObject(w), XtWindowOfObject(w),
00311 x, y, width, height, False);
00312 }
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328 static void
00329 FindPosition(w, fromPos, fromx, width, stopAtWordBreak,
00330 resPos, resWidth, resHeight)
00331 Widget w;
00332 XawTextPosition fromPos;
00333 int fromx, width;
00334 Boolean stopAtWordBreak;
00335 XawTextPosition *resPos;
00336 int *resWidth, *resHeight;
00337 {
00338 *resPos = fromPos;
00339 *resHeight = *resWidth = 0;
00340 }
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355 static void
00356 FindDistance (w, fromPos, fromx, toPos, resWidth, resPos, resHeight)
00357 Widget w;
00358 XawTextPosition fromPos;
00359 int fromx;
00360 XawTextPosition toPos;
00361 int *resWidth;
00362 XawTextPosition *resPos;
00363 int *resHeight;
00364 {
00365 *resWidth = *resHeight = 0;
00366 *resPos = fromPos;
00367 }
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380 static void
00381 Resolve (w, pos, fromx, width, resPos)
00382 Widget w;
00383 XawTextPosition pos;
00384 int fromx, width;
00385 XawTextPosition *resPos;
00386 {
00387 *resPos = pos;
00388 }
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399 static int
00400 MaxLines(w, height)
00401 Widget w;
00402 Dimension height;
00403 {
00404
00405
00406
00407
00408
00409
00410 return 0;
00411 }
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422 static int
00423 MaxHeight(w, lines)
00424 Widget w;
00425 int lines;
00426 {
00427 return 0;
00428 }
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439 static void
00440 SetTabs(w, tab_count, tabs)
00441 Widget w;
00442 int tab_count;
00443 short *tabs;
00444 {
00445 return;
00446 }
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456 static void
00457 GetCursorBounds(w, rect)
00458 Widget w;
00459 XRectangle * rect;
00460 {
00461 rect->x = rect->y = rect->width = rect->height = 0;
00462 }
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484 void
00485 #if NeedFunctionPrototypes
00486 XawTextSinkDisplayText(Widget w,
00487 #if NeedWidePrototypes
00488 int x, int y,
00489 #else
00490 Position x, Position y,
00491 #endif
00492 XawTextPosition pos1, XawTextPosition pos2,
00493 #if NeedWidePrototypes
00494 int highlight)
00495 #else
00496 Boolean highlight)
00497 #endif
00498 #else
00499 XawTextSinkDisplayText(w, x, y, pos1, pos2, highlight)
00500 Widget w;
00501 Position x, y;
00502 Boolean highlight;
00503 XawTextPosition pos1, pos2;
00504 #endif
00505 {
00506 TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
00507
00508 (*class->text_sink_class.DisplayText)(w, x, y, pos1, pos2, highlight);
00509 }
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523 void
00524 #if NeedFunctionPrototypes
00525 XawTextSinkInsertCursor(Widget w,
00526 #if NeedWidePrototypes
00527 int x, int y, int state)
00528 #else
00529 Position x, Position y, XawTextInsertState state)
00530 #endif
00531 #else
00532 XawTextSinkInsertCursor(w, x, y, state)
00533 Widget w;
00534 Position x, y;
00535 XawTextInsertState state;
00536 #endif
00537 {
00538 TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
00539
00540 (*class->text_sink_class.InsertCursor)(w, x, y, state);
00541 }
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556 void
00557 #if NeedFunctionPrototypes
00558 XawTextSinkClearToBackground (Widget w,
00559 #if NeedWidePrototypes
00560 int x, int y, int width, int height)
00561 #else
00562 Position x, Position y,
00563 Dimension width, Dimension height)
00564 #endif
00565 #else
00566 XawTextSinkClearToBackground (w, x, y, width, height)
00567 Widget w;
00568 Position x, y;
00569 Dimension width, height;
00570 #endif
00571 {
00572 TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
00573
00574 (*class->text_sink_class.ClearToBackground)(w, x, y, width, height);
00575 }
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591 void
00592 #if NeedFunctionPrototypes
00593 XawTextSinkFindPosition(Widget w, XawTextPosition fromPos, int fromx,
00594 int width,
00595 #if NeedWidePrototypes
00596 int stopAtWordBreak,
00597 #else
00598 Boolean stopAtWordBreak,
00599 #endif
00600 XawTextPosition *resPos, int *resWidth, int *resHeight)
00601 #else
00602 XawTextSinkFindPosition(w, fromPos, fromx, width, stopAtWordBreak,
00603 resPos, resWidth, resHeight)
00604 Widget w;
00605 XawTextPosition fromPos;
00606 int fromx, width;
00607 Boolean stopAtWordBreak;
00608 XawTextPosition *resPos;
00609 int *resWidth, *resHeight;
00610 #endif
00611 {
00612 TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
00613
00614 (*class->text_sink_class.FindPosition)(w, fromPos, fromx, width,
00615 stopAtWordBreak,
00616 resPos, resWidth, resHeight);
00617 }
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632 void
00633 #if NeedFunctionPrototypes
00634 XawTextSinkFindDistance (Widget w, XawTextPosition fromPos, int fromx,
00635 XawTextPosition toPos, int *resWidth,
00636 XawTextPosition *resPos, int *resHeight)
00637 #else
00638 XawTextSinkFindDistance (w, fromPos, fromx, toPos, resWidth, resPos, resHeight)
00639 Widget w;
00640 XawTextPosition fromPos, toPos, *resPos;
00641 int fromx, *resWidth, *resHeight;
00642 #endif
00643 {
00644 TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
00645
00646 (*class->text_sink_class.FindDistance)(w, fromPos, fromx, toPos,
00647 resWidth, resPos, resHeight);
00648 }
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661 void
00662 #if NeedFunctionPrototypes
00663 XawTextSinkResolve(Widget w, XawTextPosition pos, int fromx, int width,
00664 XawTextPosition *resPos)
00665 #else
00666 XawTextSinkResolve(w, pos, fromx, width, resPos)
00667 Widget w;
00668 XawTextPosition pos;
00669 int fromx, width;
00670 XawTextPosition *resPos;
00671 #endif
00672 {
00673 TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
00674
00675 (*class->text_sink_class.Resolve)(w, pos, fromx, width, resPos);
00676 }
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687 int
00688 #if NeedFunctionPrototypes
00689 XawTextSinkMaxLines(Widget w,
00690 #if NeedWidePrototypes
00691 int height)
00692 #else
00693 Dimension height)
00694 #endif
00695 #else
00696 XawTextSinkMaxLines(w, height)
00697 Widget w;
00698 Dimension height;
00699 #endif
00700 {
00701 TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
00702
00703 return((*class->text_sink_class.MaxLines)(w, height));
00704 }
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715 int
00716 #if NeedFunctionPrototypes
00717 XawTextSinkMaxHeight(Widget w, int lines)
00718 #else
00719 XawTextSinkMaxHeight(w, lines)
00720 Widget w;
00721 int lines;
00722 #endif
00723 {
00724 TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
00725
00726 return((*class->text_sink_class.MaxHeight)(w, lines));
00727 }
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737 void
00738 #if NeedFunctionPrototypes
00739 XawTextSinkSetTabs(Widget w, int tab_count, int *tabs)
00740 #else
00741 XawTextSinkSetTabs(w, tab_count, tabs)
00742 Widget w;
00743 int tab_count, *tabs;
00744 #endif
00745 {
00746 if (tab_count > 0) {
00747 TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
00748 short *char_tabs = (short*)XtMalloc( (unsigned)tab_count*sizeof(short) );
00749 short *tab;
00750 int i;
00751
00752 for (i = tab_count, tab = char_tabs; i; i--) *tab++ = (short)*tabs++;
00753
00754 (*class->text_sink_class.SetTabs)(w, tab_count, char_tabs);
00755 XtFree((char *)char_tabs);
00756 }
00757 }
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767 void
00768 #if NeedFunctionPrototypes
00769 XawTextSinkGetCursorBounds(Widget w, XRectangle *rect)
00770 #else
00771 XawTextSinkGetCursorBounds(w, rect)
00772 Widget w;
00773 XRectangle * rect;
00774 #endif
00775 {
00776 TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
00777
00778 (*class->text_sink_class.GetCursorBounds)(w, rect);
00779 }