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 #include <X11/IntrinsicP.h>
00040 #include <X11/StringDefs.h>
00041 #include <X11/Xutil.h>
00042 #include <X11/Xaw3d/XawInit.h>
00043 #include <X11/Xaw3d/TextSrcP.h>
00044 #include <X11/Xmu/Atoms.h>
00045 #include <X11/Xmu/CharSet.h>
00046 #include "XawI18n.h"
00047 #include <stdio.h>
00048 #include <ctype.h>
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 #define offset(field) XtOffsetOf(TextSrcRec, textSrc.field)
00059 static XtResource resources[] = {
00060 {XtNeditType, XtCEditType, XtREditMode, sizeof(XawTextEditType),
00061 offset(edit_mode), XtRString, "read"},
00062 };
00063
00064 static void ClassInitialize(), ClassPartInitialize(), SetSelection();
00065 static void CvtStringToEditMode();
00066 static Boolean ConvertSelection();
00067 static XawTextPosition Search(), Scan(), Read();
00068 static int Replace();
00069
00070 #define SuperClass (&objectClassRec)
00071 TextSrcClassRec textSrcClassRec = {
00072 {
00073
00074 (WidgetClass) SuperClass,
00075 "TextSrc",
00076 sizeof(TextSrcRec),
00077 ClassInitialize,
00078 ClassPartInitialize,
00079 FALSE,
00080 NULL,
00081 NULL,
00082 NULL,
00083 NULL,
00084 0,
00085 resources,
00086 XtNumber(resources),
00087 NULLQUARK,
00088 FALSE,
00089 FALSE,
00090 FALSE,
00091 FALSE,
00092 NULL,
00093 NULL,
00094 NULL,
00095 NULL,
00096 NULL,
00097 NULL,
00098 NULL,
00099 NULL,
00100 XtVersion,
00101 NULL,
00102 NULL,
00103 NULL,
00104 NULL,
00105 NULL,
00106 },
00107
00108 {
00109 Read,
00110 Replace,
00111 Scan,
00112 Search,
00113 SetSelection,
00114 ConvertSelection
00115 }
00116 };
00117
00118 WidgetClass textSrcObjectClass = (WidgetClass)&textSrcClassRec;
00119
00120 static void
00121 ClassInitialize ()
00122 {
00123 XawInitializeWidgetSet ();
00124 XtAddConverter(XtRString, XtREditMode, CvtStringToEditMode, NULL, 0);
00125 }
00126
00127
00128 static void
00129 ClassPartInitialize(wc)
00130 WidgetClass wc;
00131 {
00132 TextSrcObjectClass t_src, superC;
00133
00134 t_src = (TextSrcObjectClass) wc;
00135 superC = (TextSrcObjectClass) t_src->object_class.superclass;
00136
00137
00138
00139
00140
00141 if (t_src->textSrc_class.Read == XtInheritRead)
00142 t_src->textSrc_class.Read = superC->textSrc_class.Read;
00143
00144 if (t_src->textSrc_class.Replace == XtInheritReplace)
00145 t_src->textSrc_class.Replace = superC->textSrc_class.Replace;
00146
00147 if (t_src->textSrc_class.Scan == XtInheritScan)
00148 t_src->textSrc_class.Scan = superC->textSrc_class.Scan;
00149
00150 if (t_src->textSrc_class.Search == XtInheritSearch)
00151 t_src->textSrc_class.Search = superC->textSrc_class.Search;
00152
00153 if (t_src->textSrc_class.SetSelection == XtInheritSetSelection)
00154 t_src->textSrc_class.SetSelection = superC->textSrc_class.SetSelection;
00155
00156 if (t_src->textSrc_class.ConvertSelection == XtInheritConvertSelection)
00157 t_src->textSrc_class.ConvertSelection =
00158 superC->textSrc_class.ConvertSelection;
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 static XawTextPosition
00178 Read(w, pos, text, length)
00179 Widget w;
00180 XawTextPosition pos;
00181 XawTextBlock *text;
00182 int length;
00183 {
00184 XtAppError(XtWidgetToApplicationContext(w),
00185 "TextSrc Object: No read function is defined.");
00186
00187 return( (XawTextPosition) 0 );
00188 }
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 static int
00200 Replace (w, startPos, endPos, text)
00201 Widget w;
00202 XawTextPosition startPos, endPos;
00203 XawTextBlock *text;
00204 {
00205 return(XawEditError);
00206 }
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 static
00224 XawTextPosition
00225 Scan (w, position, type, dir, count, include)
00226 Widget w;
00227 XawTextPosition position;
00228 XawTextScanType type;
00229 XawTextScanDirection dir;
00230 int count;
00231 Boolean include;
00232 {
00233 XtAppError(XtWidgetToApplicationContext(w),
00234 "TextSrc Object: No SCAN function is defined.");
00235
00236 return( (XawTextPosition) 0 );
00237 }
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 static XawTextPosition
00250 Search(w, position, dir, text)
00251 Widget w;
00252 XawTextPosition position;
00253 XawTextScanDirection dir;
00254 XawTextBlock * text;
00255 {
00256 return(XawTextSearchError);
00257 }
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 static Boolean
00273 ConvertSelection(w, selection, target, type, value, length, format)
00274 Widget w;
00275 Atom * selection, * target, * type;
00276 XtPointer * value;
00277 unsigned long * length;
00278 int * format;
00279 {
00280 return(FALSE);
00281 }
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292 static void
00293 SetSelection(w, left, right, selection)
00294 Widget w;
00295 XawTextPosition left, right;
00296 Atom selection;
00297 {
00298
00299 }
00300
00301
00302
00303 static void
00304 CvtStringToEditMode(args, num_args, fromVal, toVal)
00305 XrmValuePtr args;
00306 Cardinal *num_args;
00307 XrmValuePtr fromVal;
00308 XrmValuePtr toVal;
00309 {
00310 static XawTextEditType editType;
00311 static XrmQuark QRead, QAppend, QEdit;
00312 XrmQuark q;
00313 char lowerName[40];
00314 static Boolean inited = FALSE;
00315
00316 if ( !inited ) {
00317 QRead = XrmPermStringToQuark(XtEtextRead);
00318 QAppend = XrmPermStringToQuark(XtEtextAppend);
00319 QEdit = XrmPermStringToQuark(XtEtextEdit);
00320 inited = TRUE;
00321 }
00322
00323 if (strlen ((char*) fromVal->addr) < sizeof lowerName) {
00324 XmuCopyISOLatin1Lowered (lowerName, (char *)fromVal->addr);
00325 q = XrmStringToQuark(lowerName);
00326
00327 if (q == QRead) editType = XawtextRead;
00328 else if (q == QAppend) editType = XawtextAppend;
00329 else if (q == QEdit) editType = XawtextEdit;
00330 else {
00331 toVal->size = 0;
00332 toVal->addr = NULL;
00333 return;
00334 }
00335 toVal->size = sizeof editType;
00336 toVal->addr = (XPointer) &editType;
00337 return;
00338 }
00339 toVal->size = 0;
00340 toVal->addr = NULL;
00341 }
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360 XawTextPosition
00361 #if NeedFunctionPrototypes
00362 XawTextSourceRead(Widget w, XawTextPosition pos, XawTextBlock *text,
00363 int length)
00364 #else
00365 XawTextSourceRead(w, pos, text, length)
00366 Widget w;
00367 XawTextPosition pos;
00368 XawTextBlock *text;
00369 int length;
00370 #endif
00371 {
00372 TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class;
00373
00374 if ( !XtIsSubclass( w, textSrcObjectClass ) )
00375 XtErrorMsg("bad argument", "textSource", "XawError",
00376 "XawTextSourceRead's 1st parameter must be subclass of asciiSrc.",
00377 NULL, NULL);
00378
00379 return((*class->textSrc_class.Read)(w, pos, text, length));
00380 }
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391 int
00392 #if NeedFunctionPrototypes
00393 XawTextSourceReplace (Widget w, XawTextPosition startPos,
00394 XawTextPosition endPos, XawTextBlock *text)
00395 #else
00396 XawTextSourceReplace (w, startPos, endPos, text)
00397 Widget w;
00398 XawTextPosition startPos, endPos;
00399 XawTextBlock *text;
00400 #endif
00401 {
00402 TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class;
00403
00404 if ( !XtIsSubclass( w, textSrcObjectClass ) )
00405 XtErrorMsg("bad argument", "textSource", "XawError",
00406 "XawTextSourceReplace's 1st parameter must be subclass of asciiSrc.",
00407 NULL, NULL);
00408
00409 return((*class->textSrc_class.Replace)(w, startPos, endPos, text));
00410 }
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426 XawTextPosition
00427 #if NeedFunctionPrototypes
00428 XawTextSourceScan(Widget w, XawTextPosition position,
00429 #if NeedWidePrototypes
00430 int type, int dir,
00431 #else
00432 XawTextScanType type, XawTextScanDirection dir,
00433 #endif
00434 int count,
00435 #if NeedWidePrototypes
00436 int include)
00437 #else
00438 Boolean include)
00439 #endif
00440 #else
00441 XawTextSourceScan(w, position, type, dir, count, include)
00442 Widget w;
00443 XawTextPosition position;
00444 XawTextScanType type;
00445 XawTextScanDirection dir;
00446 int count;
00447 Boolean include;
00448 #endif
00449 {
00450 TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class;
00451
00452 if ( !XtIsSubclass( w, textSrcObjectClass ) )
00453 XtErrorMsg("bad argument", "textSource", "XawError",
00454 "XawTextSourceScan's 1st parameter must be subclass of asciiSrc.",
00455 NULL, NULL);
00456
00457 return((*class->textSrc_class.Scan)(w, position, type, dir, count, include));
00458 }
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470 XawTextPosition
00471 #if NeedFunctionPrototypes
00472 XawTextSourceSearch(Widget w, XawTextPosition position,
00473 #if NeedWidePrototypes
00474 int dir,
00475 #else
00476 XawTextScanDirection dir,
00477 #endif
00478 XawTextBlock *text)
00479 #else
00480 XawTextSourceSearch(w, position, dir, text)
00481 Widget w;
00482 XawTextPosition position;
00483 XawTextScanDirection dir;
00484 XawTextBlock * text;
00485 #endif
00486 {
00487 TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class;
00488
00489 if ( !XtIsSubclass( w, textSrcObjectClass ) )
00490 XtErrorMsg("bad argument", "textSource", "XawError",
00491 "XawTextSourceSearch's 1st parameter must be subclass of asciiSrc.",
00492 NULL, NULL);
00493
00494 return((*class->textSrc_class.Search)(w, position, dir, text));
00495 }
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509 Boolean
00510 #if NeedFunctionPrototypes
00511 XawTextSourceConvertSelection(Widget w, Atom *selection, Atom *target,
00512 Atom *type, XtPointer *value,
00513 unsigned long *length, int *format)
00514 #else
00515 XawTextSourceConvertSelection(w, selection,
00516 target, type, value, length, format)
00517 Widget w;
00518 Atom * selection, * target, * type;
00519 XtPointer * value;
00520 unsigned long * length;
00521 int * format;
00522 #endif
00523 {
00524 TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class;
00525
00526 if ( !XtIsSubclass( w, textSrcObjectClass ) )
00527 XtErrorMsg("bad argument", "textSource", "XawError",
00528 "XawTextSourceConvertSelectionXawTextSourceConvertSelection's 1st parameter must be subclass of asciiSrc.",
00529 NULL, NULL);
00530
00531 return((*class->textSrc_class.ConvertSelection)(w, selection, target, type,
00532 value, length, format));
00533 }
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543 void
00544 #if NeedFunctionPrototypes
00545 XawTextSourceSetSelection(Widget w, XawTextPosition left,
00546 XawTextPosition right, Atom selection)
00547 #else
00548 XawTextSourceSetSelection(w, left, right, selection)
00549 Widget w;
00550 XawTextPosition left, right;
00551 Atom selection;
00552 #endif
00553 {
00554 TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class;
00555
00556 if ( !XtIsSubclass( w, textSrcObjectClass ) )
00557 XtErrorMsg("bad argument", "textSource", "XawError",
00558 "'s 1st parameter must be subclass of asciiSrc.",
00559 NULL, NULL);
00560
00561 (*class->textSrc_class.SetSelection)(w, left, right, selection);
00562 }
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575 XrmQuark
00576 #if NeedFunctionPrototypes
00577 _XawTextFormat(TextWidget tw)
00578 #else
00579 _XawTextFormat(tw)
00580 TextWidget tw;
00581 #endif
00582 {
00583 return (((TextSrcObject)(tw->text.source))->textSrc.text_format);
00584 }
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598 char *
00599 _XawTextWCToMB( d, wstr, len_in_out )
00600 Display* d;
00601 wchar_t* wstr;
00602 int* len_in_out;
00603
00604 {
00605 XTextProperty textprop;
00606 if (XwcTextListToTextProperty(d, (wchar_t**)&wstr, 1,
00607 XTextStyle, &textprop) < Success) {
00608 XtWarningMsg("convertError", "textSource", "XawError",
00609 "Non-character code(s) in buffer.", NULL, NULL);
00610 *len_in_out = 0;
00611 return( NULL );
00612 }
00613 *len_in_out = textprop.nitems;
00614 return((char *)textprop.value);
00615 }
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628 wchar_t* _XawTextMBToWC( d, str, len_in_out )
00629 Display *d;
00630 char *str;
00631 int *len_in_out;
00632 {
00633 if (*len_in_out == 0) {
00634 return(NULL);
00635 } else {
00636 XTextProperty textprop;
00637 char *buf;
00638 wchar_t **wlist, *wstr;
00639 int count;
00640 buf = XtMalloc(*len_in_out + 1);
00641 if (!buf) {
00642 XtErrorMsg("convertError", "multiSourceCreate", "XawError",
00643 "No Memory", NULL, NULL);
00644 *len_in_out = 0;
00645 return (NULL);
00646 }
00647 strncpy(buf, str, *len_in_out);
00648 *(buf + *len_in_out) = '\0';
00649 if (XmbTextListToTextProperty(d, &buf, 1, XTextStyle, &textprop)
00650 != Success) {
00651 XtWarningMsg("convertError", "textSource", "XawError",
00652 "No Memory, or Locale not supported.", NULL, NULL);
00653 XtFree(buf);
00654 *len_in_out = 0;
00655 return (NULL);
00656 }
00657 XtFree(buf);
00658 if (XwcTextPropertyToTextList(d, &textprop,
00659 (wchar_t***)&wlist, &count) != Success) {
00660 XtWarningMsg("convertError", "multiSourceCreate", "XawError",
00661 "Non-character code(s) in source.", NULL, NULL);
00662 *len_in_out = 0;
00663 return (NULL);
00664 }
00665 wstr = wlist[0];
00666 *len_in_out = wcslen(wstr);
00667 XFree((char**)wlist);
00668 return(wstr);
00669 }
00670 }
00671