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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289
|
/*******************************************************************************
* *
* fontsel.c -- Nirvana Font Selector *
* *
* Copyright (C) 1999 Mark Edel *
* *
* This 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 2 of the License, or (at your option) any later *
* version. In addition, you may distribute version of this program linked to *
* Motif or Open Motif. See README for details. *
* *
* 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 *
* software; if not, write to the Free Software Foundation, Inc., 59 Temple *
* Place, Suite 330, Boston, MA 02111-1307 USA *
* *
* Nirvana Text Editor *
* June 2, 1993 *
* *
* Written by Suresh Ravoor (assisted by Mark Edel) *
* *
*******************************************************************************/
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
#include "fontsel.h"
#include "misc.h"
#include "nedit_malloc.h"
#include "DialogF.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xm/PushB.h>
#include <Xm/List.h>
#include <Xm/Label.h>
#include <Xm/Text.h>
#include <Xm/TextF.h>
#include <Xm/ToggleB.h>
#include <Xm/MessageB.h>
#include <Xm/DialogS.h>
#ifdef HAVE_DEBUG_H
#include "../debug.h"
#endif
#define MAX_ARGS 20
#define MAX_NUM_FONTS 32767
#define MAX_FONT_NAME_LEN 256
#define MAX_ENTRIES_IN_LIST 5000
#define MAX_DISPLAY_SIZE 150
#define DELIM '-'
#define NUM_COMPONENTS_FONT_NAME 14
#define TEMP_BUF_SIZE 256
#define DISPLAY_HEIGHT 90
enum listSpecifier { NONE, FONT, STYLE, SIZE };
/* local data structures and types */
typedef struct
{
Widget form; /* widget id */
Widget okButton; /* widget id */
Widget cancelButton; /* widget id */
Widget fontList; /* widget id */
Widget styleList; /* widget id */
Widget sizeList; /* widget id */
Widget fontNameField; /* widget id */
Widget sizeToggle; /* widget id */
Widget propFontToggle; /* widget id */
Widget dispField; /* widget id */
char **fontData; /* font name info */
int numFonts; /* number of fonts */
char *sel1; /* selection from list 1 */
char *sel2; /* selection from list 2 */
char *sel3; /* selection from list 3 */
int showPropFonts; /* toggle state - show prop fonts */
int showSizeInPixels;/* toggle state - size in pixels */
char *fontName; /* current font name */
XFontStruct *oldFont; /* font data structure for dispSample */
XmFontList oldFontList; /* font data structure for dispSample */
int exitFlag; /* used for program exit control */
int destroyedFlag; /* used to prevent double destruction */
Pixel sampleFG; /* Colors for the sample field */
Pixel sampleBG;
} xfselControlBlkType;
/* local function prototypes */
static void getStringComponent(const char *inStr, int pos, char *outStr);
static void setupScrollLists(int dontChange, xfselControlBlkType ctrlBlk);
static int notPropFont(const char *font);
static int styleMatch(xfselControlBlkType *ctrlBlk, const char *font);
static int sizeMatch(xfselControlBlkType *ctrlBlk, const char *font);
static int fontMatch(xfselControlBlkType *ctrlBlk, const char *font);
static void addItemToList(char **buf, const char *item, int *count);
static void getFontPart(const char *font, char *buff1);
static void getStylePart(const char *font, char *buff1);
static void getSizePart(const char *font, char *buff1, int inPixels);
static void propFontToggleAction(Widget widget,
xfselControlBlkType *ctrlBlk,
XmToggleButtonCallbackStruct *call_data);
static void sizeToggleAction(Widget widget,
xfselControlBlkType *ctrlBlk,
XmToggleButtonCallbackStruct *call_data);
static void fontAction(Widget widget, xfselControlBlkType *ctrlBlk,
XmListCallbackStruct *call_data);
static void styleAction(Widget widget, xfselControlBlkType *ctrlBlk,
XmListCallbackStruct *call_data);
static void sizeAction(Widget widget, xfselControlBlkType *ctrlBlk,
XmListCallbackStruct *call_data);
static void choiceMade(xfselControlBlkType *ctrlBlk);
static void dispSample(xfselControlBlkType *ctrlBlk);
static void destroyCB(Widget widget, xfselControlBlkType *ctrlBlk,
XmListCallbackStruct *call_data);
static void cancelAction(Widget widget, xfselControlBlkType *ctrlBlk,
XmListCallbackStruct *call_data);
static void okAction(Widget widget, xfselControlBlkType *ctrlBlk,
XmPushButtonCallbackStruct *call_data);
static void startupFont(xfselControlBlkType *ctrlBlk, const char *font);
static void setFocus(Widget w, xfselControlBlkType *ctrlBlk, XEvent *event,
Boolean *continueToDispatch);
static void FindBigFont(xfselControlBlkType *ctrlBlk, char *bigFont);
static void enableSample(xfselControlBlkType *ctrlBlk, Bool turn_on,
XmFontList *fontList);
/*******************************************************************************
* *
* FontSel () *
* *
* *
* Function to put up a modal font selection dialog box. The purpose *
* of this routine is to allow the user to interactively view sample *
* fonts and to choose a font for current use. *
* *
* Arguments: *
* *
* Widget parent - parent widget ID *
* *
* int showPropFont - ONLY_FIXED : shows only fixed fonts *
* doesn't show prop font *
* toggle button also. *
* PREF_FIXED : can select either fixed *
* or proportional fonts; *
* but starting option is *
* Fixed fonts. *
* PREF_PROP : can select either fixed *
* or proportional fonts; *
* but starting option is *
* proportional fonts. *
* *
* char * currFont - ASCII string that contains the name *
* of the currently selected font. *
* *
* Pixel sampleFG, sampleBG - Foreground/Background colors in *
* which to display the sample *
* text. *
* *
* *
* Returns: *
* *
* pointer to an ASCII character string that contains the name of *
* the selected font (in X format for naming fonts); it is the users *
* responsibility to free the space allocated to this string. *
* *
* Comments: *
* *
* The calling function has to call the appropriate routines to set *
* the current font to the one represented by the returned string. *
* *
*******************************************************************************/
char *FontSel(Widget parent, int showPropFonts, const char *currFont,
Pixel sampleFG, Pixel sampleBG)
{
Widget dialog, form, okButton, cancelButton;
Widget styleList, sizeList, fontName, fontList;
Widget sizeToggle, propFontToggle = NULL, dispField;
Widget nameLabel, sampleLabel;
Arg args[MAX_ARGS];
int n;
XmString tempStr;
char bigFont[MAX_FONT_NAME_LEN];
xfselControlBlkType ctrlBlk;
Display *theDisplay;
ctrlBlk.fontData = XListFonts(XtDisplay(parent),
"-*-*-*-*-*-*-*-*-*-*-*-*-*-*",
MAX_NUM_FONTS, &ctrlBlk.numFonts);
FindBigFont(&ctrlBlk, bigFont);
ctrlBlk.oldFont = XLoadQueryFont(XtDisplay(parent), bigFont);
ctrlBlk.oldFontList = XmFontListCreate(ctrlBlk.oldFont,
XmSTRING_DEFAULT_CHARSET);
ctrlBlk.sampleFG = sampleFG;
ctrlBlk.sampleBG = sampleBG;
dialog = CreateDialogShell(parent, "Font Selector", args, 0);
/* Set up window sizes for form widget */
n = 0;
XtSetArg(args[n], XmNautoUnmanage, FALSE); n++;
XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
/* Create form popup dialog widget */
form = XtCreateWidget ("Font Selector", xmFormWidgetClass, dialog,
args, n);
/* Create pushbutton widgets */
n = 0;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNbottomOffset, 4); n++;
XtSetArg(args[n], XmNtopOffset, 1); n++;
XtSetArg(args[n], XmNrightPosition, 45); n++;
XtSetArg(args[n], XmNwidth, 110); n++;
XtSetArg(args[n], XmNheight, 28); n++;
XtSetArg(args[n], XmNshowAsDefault, TRUE); n++;
okButton = XtCreateManagedWidget("OK", xmPushButtonWidgetClass, form,
args, n);
n = 0;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
XtSetArg(args[n], XmNtopWidget, okButton); n++;
XtSetArg(args[n], XmNbottomWidget, okButton); n++;
XtSetArg(args[n], XmNleftPosition, 55); n++;
XtSetArg(args[n], XmNwidth, 110); n++;
XtSetArg(args[n], XmNheight, 28); n++;
cancelButton = XtCreateManagedWidget("Cancel", xmPushButtonWidgetClass,
form, args, n);
/* create font name text widget and the corresponding label */
n = 0;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNbottomWidget, okButton); n++;
XtSetArg(args[n], XmNleftPosition, 1); n++;
XtSetArg(args[n], XmNrightPosition, 99); n++;
XtSetArg(args[n], XmNeditable, True); n++;
XtSetArg(args[n], XmNeditMode, XmSINGLE_LINE_EDIT); n++;
XtSetArg(args[n], XmNmaxLength, MAX_FONT_NAME_LEN); n++;
fontName = XtCreateManagedWidget("fontname", xmTextWidgetClass, form,
args, n);
RemapDeleteKey(fontName); /* kludge to handle delete and BS */
n = 0;
tempStr = XmStringCreate("Font Name:", XmSTRING_DEFAULT_CHARSET);
XtSetArg(args[n], XmNlabelString, tempStr); n++;
XtSetArg(args[n], XmNmnemonic, 'N'); n++;
XtSetArg(args[n], XmNuserData, fontName); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNleftWidget, fontName); n++;
XtSetArg(args[n], XmNbottomWidget, fontName); n++;
XtSetArg(args[n], XmNtopOffset, 1); n++;
nameLabel = XtCreateManagedWidget("Font Name:", xmLabelWidgetClass,
form, args, n);
XmStringFree(tempStr);
/* create sample display text field widget */
n = 0;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNrightPosition, 99); n++;
XtSetArg(args[n], XmNbottomWidget, nameLabel); n++;
XtSetArg(args[n], XmNleftPosition, 1); n++;
XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
XtSetArg(args[n], XmNvalue,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789");
n++;
XtSetArg(args[n], XmNforeground, sampleFG); n++;
XtSetArg(args[n], XmNbackground, sampleBG); n++;
dispField = XtCreateManagedWidget(" ", xmTextFieldWidgetClass, form,
args, n);
n = 0;
tempStr = XmStringCreate("Sample:", XmSTRING_DEFAULT_CHARSET);
XtSetArg(args[n], XmNlabelString, tempStr); n++;
XtSetArg(args[n], XmNmnemonic, 'S'); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNleftWidget, dispField); n++;
XtSetArg(args[n], XmNbottomWidget, dispField); n++;
XtSetArg(args[n], XmNtopOffset, 1); n++;
sampleLabel = XtCreateManagedWidget("Font Name:", xmLabelWidgetClass,
form, args, n);
XmStringFree(tempStr);
/* create toggle buttons */
n = 0;
tempStr = XmStringCreate("Show Size in Points",
XmSTRING_DEFAULT_CHARSET);
XtSetArg(args[n], XmNlabelString, tempStr); n++;
XtSetArg(args[n], XmNmnemonic, 'P'); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNleftPosition, 2); n++;
XtSetArg(args[n], XmNtopOffset, 1); n++;
XtSetArg(args[n], XmNbottomWidget, sampleLabel); n++;
sizeToggle = XtCreateManagedWidget("sizetoggle",
xmToggleButtonWidgetClass, form, args, n);
XmStringFree(tempStr);
if (showPropFonts != ONLY_FIXED)
{
n = 0;
tempStr = XmStringCreate("Show Proportional Width Fonts",
XmSTRING_DEFAULT_CHARSET);
XtSetArg(args[n], XmNlabelString, tempStr); n++;
XtSetArg(args[n], XmNmnemonic, 'W'); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNtopAttachment,
XmATTACH_OPPOSITE_WIDGET); n++;
XtSetArg(args[n], XmNbottomAttachment,
XmATTACH_OPPOSITE_WIDGET); n++;
XtSetArg(args[n], XmNrightPosition, 98); n++;
XtSetArg(args[n], XmNtopWidget, sizeToggle); n++;
XtSetArg(args[n], XmNbottomWidget, sizeToggle); n++;
XtSetArg(args[n], XmNtopOffset, 1); n++;
propFontToggle = XtCreateManagedWidget("propfonttoggle",
xmToggleButtonWidgetClass, form, args, n);
XmStringFree(tempStr);
}
/* create scroll list widgets */
/* "Font" list */
n = 0;
tempStr = XmStringCreate("Font:", XmSTRING_DEFAULT_CHARSET);
XtSetArg(args[n], XmNlabelString, tempStr); n++;
XtSetArg(args[n], XmNmnemonic, 'F'); n++;
XtSetArg(args[n], XmNtopOffset, 2); n++;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNleftPosition, 1); n++;
nameLabel = XtCreateManagedWidget("Font:", xmLabelWidgetClass, form,
args, n);
XmStringFree(tempStr);
n = 0;
XtSetArg(args[n], XmNvisibleItemCount, 15); n++;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNbottomWidget, sizeToggle); n++;
XtSetArg(args[n], XmNtopWidget, nameLabel); n++;
XtSetArg(args[n], XmNleftWidget, nameLabel); n++;
XtSetArg(args[n], XmNrightPosition, 52); n++;
fontList = XmCreateScrolledList(form, "fontlist", args, n);
AddMouseWheelSupport(fontList);
XtManageChild(fontList);
XtVaSetValues(nameLabel, XmNuserData, fontList, NULL);
/* "Style" list */
n = 0;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNtopWidget, nameLabel); n++;
XtSetArg(args[n], XmNleftOffset, 5); n++;
XtSetArg(args[n], XmNleftWidget, XtParent(fontList)); n++;
XtSetArg(args[n], XmNbottomWidget, XtParent(fontList)); n++;
XtSetArg(args[n], XmNrightPosition, 85); n++;
styleList = XmCreateScrolledList(form, "stylelist", args, n);
AddMouseWheelSupport(styleList);
XtManageChild(styleList);
n = 0;
tempStr = XmStringCreate("Style:", XmSTRING_DEFAULT_CHARSET);
XtSetArg(args[n], XmNmnemonic, 'y'); n++;
XtSetArg(args[n], XmNuserData, styleList); n++;
XtSetArg(args[n], XmNlabelString, tempStr); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
XtSetArg(args[n], XmNbottomWidget, XtParent(styleList)); n++;
XtSetArg(args[n], XmNleftWidget, XtParent(styleList)); n++;
XtCreateManagedWidget("Style:", xmLabelWidgetClass, form, args, n);
XmStringFree(tempStr);
/* "Size" list */
n = 0;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
XtSetArg(args[n], XmNtopWidget, nameLabel); n++;
XtSetArg(args[n], XmNleftWidget, XtParent(styleList)); n++;
XtSetArg(args[n], XmNbottomWidget, XtParent(fontList)); n++;
XtSetArg(args[n], XmNleftOffset, 5); n++;
XtSetArg(args[n], XmNrightPosition, 99); n++;
sizeList = XmCreateScrolledList(form, "sizelist", args, n);
AddMouseWheelSupport(sizeList);
XtManageChild(sizeList);
n = 0;
tempStr = XmStringCreate("Size:", XmSTRING_DEFAULT_CHARSET);
XtSetArg(args[n], XmNlabelString, tempStr); n++;
XtSetArg(args[n], XmNmnemonic, 'z'); n++;
XtSetArg(args[n], XmNuserData, sizeList); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
XtSetArg(args[n], XmNbottomWidget, XtParent(sizeList)); n++;
XtSetArg(args[n], XmNleftWidget, XtParent(sizeList)); n++;
XtCreateManagedWidget("Size:", xmLabelWidgetClass, form, args, n);
XmStringFree(tempStr);
/* update form widgets cancel button */
n = 0;
XtSetArg(args[n], XmNcancelButton, cancelButton); n++;
XtSetValues(form, args, n);
/* update application's control block structure */
ctrlBlk.form = form;
ctrlBlk.okButton = okButton;
ctrlBlk.cancelButton = cancelButton;
ctrlBlk.fontList = fontList;
ctrlBlk.styleList = styleList;
ctrlBlk.sizeList = sizeList;
ctrlBlk.fontNameField = fontName;
ctrlBlk.sizeToggle = sizeToggle;
if (showPropFonts != ONLY_FIXED)
ctrlBlk.propFontToggle = propFontToggle;
ctrlBlk.dispField = dispField;
ctrlBlk.exitFlag = FALSE;
ctrlBlk.destroyedFlag = FALSE;
ctrlBlk.showPropFonts = showPropFonts;
ctrlBlk.showSizeInPixels = TRUE;
ctrlBlk.sel1 = NULL;
ctrlBlk.sel2 = NULL;
ctrlBlk.sel3 = NULL;
ctrlBlk.fontName = NULL;
setupScrollLists(NONE, ctrlBlk); /* update scroll lists */
if (showPropFonts == PREF_PROP)
XmToggleButtonSetState(propFontToggle, TRUE, FALSE);
/* Register callback functions */
if (showPropFonts != ONLY_FIXED)
XtAddCallback(propFontToggle, XmNvalueChangedCallback,
(XtCallbackProc)propFontToggleAction, (char *)&ctrlBlk);
XtAddCallback(sizeToggle, XmNvalueChangedCallback,
(XtCallbackProc)sizeToggleAction, (char *)&ctrlBlk);
XtAddCallback(fontList, XmNbrowseSelectionCallback,
(XtCallbackProc)fontAction, (char *)&ctrlBlk);
XtAddCallback(styleList, XmNbrowseSelectionCallback,
(XtCallbackProc)styleAction, (char *)&ctrlBlk);
XtAddCallback(sizeList, XmNbrowseSelectionCallback,
(XtCallbackProc)sizeAction, (char *)&ctrlBlk);
XtAddCallback(okButton, XmNactivateCallback,
(XtCallbackProc)okAction, (char *)&ctrlBlk);
XtAddCallback(cancelButton, XmNactivateCallback,
(XtCallbackProc)cancelAction, (char *)&ctrlBlk);
/* add event handler to setup input focus at start to scroll list */
XtAddEventHandler(fontList, FocusChangeMask, FALSE,
(XtEventHandler)setFocus, (char *)&ctrlBlk);
XmProcessTraversal(fontList, XmTRAVERSE_CURRENT);
/* setup tabgroups */
XmAddTabGroup(fontList);
XmAddTabGroup(styleList);
XmAddTabGroup(sizeList);
XmAddTabGroup(sizeToggle);
if (showPropFonts != ONLY_FIXED)
XmAddTabGroup(propFontToggle);
XmAddTabGroup(fontName);
XmAddTabGroup(okButton);
XmAddTabGroup(cancelButton);
/* Make sure that we don't try to access the dialog if the user
destroyed it (possibly indirectly, by destroying the parent). */
XtAddCallback(dialog, XmNdestroyCallback,
(XtCallbackProc)destroyCB, (char *)&ctrlBlk);
/* Link Motif Close option to cancel action */
AddMotifCloseCallback(dialog, (XtCallbackProc)cancelAction, &ctrlBlk);
/* Handle dialog mnemonics */
AddDialogMnemonicHandler(form, FALSE);
/* Realize Widgets */
ManageDialogCenteredOnPointer(form);
/* set up current font parameters */
if (currFont[0] != '\0')
startupFont(&ctrlBlk, currFont);
/* Make sure that we can still access the display in case the form
gets destroyed */
theDisplay = XtDisplay(form);
/* enter event loop */
while (! ctrlBlk.exitFlag && ! ctrlBlk.destroyedFlag)
XtAppProcessEvent(XtWidgetToApplicationContext(form), XtIMAll);
if (! ctrlBlk.destroyedFlag) {
/* Don't let the callback destroy the font name */
XtRemoveCallback(dialog, XmNdestroyCallback,
(XtCallbackProc)destroyCB, (char *)&ctrlBlk);
XtDestroyWidget(dialog);
}
if (ctrlBlk.oldFont != NULL)
{
XFreeFont(theDisplay, ctrlBlk.oldFont);
XmFontListFree(ctrlBlk.oldFontList);
}
return(ctrlBlk.fontName);
}
/* gets a specific substring from a string */
static void getStringComponent(const char *inStr, int pos, char *outStr)
{
int i, j;
*outStr = '\0';
if (pos > NUM_COMPONENTS_FONT_NAME)
{
fprintf(stderr, "Warning: getStringComponent being used for ");
fprintf(stderr, "pos > %d\nIf such ", NUM_COMPONENTS_FONT_NAME);
fprintf(stderr, "use is intended remove these warning lines\n");
}
for (i = 0; (pos > 0) && (inStr[i] != '\0'); i++)
if (inStr[i] == DELIM)
pos--;
if (inStr[i] == '\0')
return;
for (j = 0; (inStr[i] != DELIM) && (inStr[i] != '\0'); i++, j++)
outStr[j] = inStr[i];
outStr[j] = '\0';
}
/* parse through the fontlist data and set up the three scroll lists */
static void setupScrollLists(int dontChange, xfselControlBlkType ctrlBlk)
{
char *itemBuf1[MAX_ENTRIES_IN_LIST];
char *itemBuf2[MAX_ENTRIES_IN_LIST];
char *itemBuf3[MAX_ENTRIES_IN_LIST];
int itemCount1, itemCount2, itemCount3;
char buff1[TEMP_BUF_SIZE];
XmString items[MAX_ENTRIES_IN_LIST];
int i;
itemCount1 = 0;
itemCount2 = 0;
itemCount3 = 0;
for (i = 0; i < ctrlBlk.numFonts && i < MAX_ENTRIES_IN_LIST; i++)
{
if ((dontChange != FONT) &&
(styleMatch(&ctrlBlk, ctrlBlk.fontData[i])) &&
(sizeMatch (&ctrlBlk, ctrlBlk.fontData[i])) &&
((ctrlBlk.showPropFonts == PREF_PROP) ||
(notPropFont(ctrlBlk.fontData[i]))))
{
getFontPart(ctrlBlk.fontData[i], buff1);
addItemToList(itemBuf1, buff1, &itemCount1);
}
if ((dontChange != STYLE) &&
(fontMatch(&ctrlBlk, ctrlBlk.fontData[i])) &&
(sizeMatch (&ctrlBlk, ctrlBlk.fontData[i])) &&
((ctrlBlk.showPropFonts == PREF_PROP) ||
(notPropFont(ctrlBlk.fontData[i]))))
{
getStylePart(ctrlBlk.fontData[i], buff1);
addItemToList(itemBuf2, buff1, &itemCount2);
}
if ((dontChange != SIZE) &&
(fontMatch(&ctrlBlk, ctrlBlk.fontData[i])) &&
(styleMatch (&ctrlBlk, ctrlBlk.fontData[i])) &&
((ctrlBlk.showPropFonts == PREF_PROP) ||
(notPropFont(ctrlBlk.fontData[i]))))
{
getSizePart(ctrlBlk.fontData[i], buff1, ctrlBlk.showSizeInPixels);
addItemToList(itemBuf3, buff1, &itemCount3);
}
} /* end - for (i = 0; i < ctrlBlk.numFonts; i++) */
/* recreate all three scroll lists where necessary */
if (dontChange != FONT)
{
for (i = 0; i < itemCount1; i++)
{
items[i] = XmStringCreate(itemBuf1[i], XmSTRING_DEFAULT_CHARSET);
NEditFree(itemBuf1[i]);
}
XmListDeleteAllItems(ctrlBlk.fontList);
XmListAddItems(ctrlBlk.fontList, items, itemCount1, 1);
if (ctrlBlk.sel1 != NULL)
{
XmStringFree(items[0]);
items[0] = XmStringCreate(ctrlBlk.sel1, XmSTRING_DEFAULT_CHARSET);
XmListSelectItem(ctrlBlk.fontList, items[0], FALSE);
XmListSetBottomItem(ctrlBlk.fontList, items[0]);
}
for (i = 0; i < itemCount1; i++)
XmStringFree(items[i]);
}
if (dontChange != STYLE)
{
for (i = 0; i < itemCount2; i++)
{
items[i] = XmStringCreate(itemBuf2[i], XmSTRING_DEFAULT_CHARSET);
NEditFree(itemBuf2[i]);
}
XmListDeleteAllItems(ctrlBlk.styleList);
XmListAddItems(ctrlBlk.styleList, items, itemCount2, 1);
if (ctrlBlk.sel2 != NULL)
{
XmStringFree(items[0]);
items[0] = XmStringCreate(ctrlBlk.sel2, XmSTRING_DEFAULT_CHARSET);
XmListSelectItem(ctrlBlk.styleList, items[0], FALSE);
XmListSetBottomItem(ctrlBlk.styleList, items[0]);
}
for (i = 0; i < itemCount2; i++)
XmStringFree(items[i]);
}
if (dontChange != SIZE)
{
for (i = 0; i < itemCount3; i++)
{
items[i] = XmStringCreate(itemBuf3[i],
XmSTRING_DEFAULT_CHARSET);
NEditFree(itemBuf3[i]);
}
XmListDeleteAllItems(ctrlBlk.sizeList);
XmListAddItems(ctrlBlk.sizeList, items, itemCount3, 1);
if (ctrlBlk.sel3 != NULL)
{
XmStringFree(items[0]);
items[0] = XmStringCreate(ctrlBlk.sel3, XmSTRING_DEFAULT_CHARSET);
XmListSelectItem(ctrlBlk.sizeList, items[0], FALSE);
XmListSetBottomItem(ctrlBlk.sizeList, items[0]);
}
for (i = 0; i < itemCount3; i++)
XmStringFree(items[i]);
}
}
/* returns TRUE if argument is not name of a proportional font */
static int notPropFont(const char *font)
{
char buff1[TEMP_BUF_SIZE];
getStringComponent(font, 11, buff1);
if ((strcmp(buff1, "p") == 0) || (strcmp(buff1, "P") == 0))
return(FALSE);
else
return(TRUE);
}
/* returns TRUE if the style portion of the font matches the currently
selected style */
static int styleMatch(xfselControlBlkType *ctrlBlk, const char *font)
{
char buff[TEMP_BUF_SIZE];
if (ctrlBlk->sel2 == NULL)
return(TRUE);
getStylePart(font, buff);
if (strcmp(buff, ctrlBlk->sel2) == 0)
return(TRUE);
else
return(FALSE);
}
/* returns TRUE if the size portion of the font matches the currently
selected size */
static int sizeMatch(xfselControlBlkType *ctrlBlk, const char *font)
{
char buff[TEMP_BUF_SIZE];
if (ctrlBlk->sel3 == NULL)
return(TRUE);
getSizePart(font, buff, ctrlBlk->showSizeInPixels);
if (strcmp(buff, ctrlBlk->sel3) == 0)
return(TRUE);
else
return(FALSE);
}
/* returns TRUE if the font portion of the font matches the currently
selected font */
static int fontMatch(xfselControlBlkType *ctrlBlk, const char *font)
{
char buff[TEMP_BUF_SIZE];
if (ctrlBlk->sel1 == NULL)
return(TRUE);
getFontPart(font, buff);
if (strcmp(buff, ctrlBlk->sel1) == 0)
return(TRUE);
else
return(FALSE);
}
/* inserts a string into correct sorted position in a list */
static void addItemToList(char **buf, const char *item, int *count)
{
int i, j;
if (*count == MAX_ENTRIES_IN_LIST)
{
fprintf(stderr, "Trying to add more than MAX_ENTRIES_IN_LIST ");
fprintf(stderr, "(%d) entries to array\n", MAX_ENTRIES_IN_LIST);
return;
}
for (i = 0; i < *count; i++)
{
if (strcmp(buf[i], item) == 0)
return;
if (strcmp(buf[i], item) > 0)
break;
}
for (j = *count; j > i; j--)
buf[j] = buf[j-1];
buf[i] = NEditStrdup(item);
(*count)++;
}
/* given a font name this function returns the part used in the first
scroll list */
static void getFontPart(const char *font, char *buff1)
{
char buff2[TEMP_BUF_SIZE], buff3[TEMP_BUF_SIZE];
char buff4[TEMP_BUF_SIZE];
getStringComponent(font, 2, buff1);
getStringComponent(font, 1, buff2);
sprintf(buff3, "%s (%s", buff1, buff2);
getStringComponent(font, 13, buff1);
getStringComponent(font, 14, buff4);
if (((strncmp(buff1, "iso8859", 7) == 0) ||
(strncmp(buff1, "ISO8859", 7) == 0)) && (strcmp(buff4, "1") == 0))
sprintf(buff1, "%s)", buff3);
else
{
sprintf(buff2, "%s, %s,", buff3, buff1);
sprintf(buff1, "%s %s)", buff2, buff4);
}
}
/* given a font name this function returns the part used in the second
scroll list */
static void getStylePart(const char *font, char *buff1)
{
char buff2[TEMP_BUF_SIZE], buff3[TEMP_BUF_SIZE];
getStringComponent(font, 3, buff3);
getStringComponent(font, 5, buff2);
if ((strcmp(buff2, "normal") != 0) && (strcmp(buff2, "Normal") != 0) &&
(strcmp(buff2, "NORMAL") != 0))
sprintf(buff1, "%s %s", buff3, buff2);
else
strcpy(buff1, buff3);
getStringComponent(font, 6, buff2);
if (buff2[0] != '\0')
sprintf(buff3, "%s %s", buff1, buff2);
else
strcpy(buff3, buff1);
getStringComponent(font, 4, buff2);
if ((strcmp(buff2, "o") == 0) || (strcmp(buff2, "O") == 0))
sprintf(buff1, "%s oblique", buff3);
else if ((strcmp(buff2, "i") == 0) || (strcmp(buff2, "I") == 0))
sprintf(buff1, "%s italic", buff3);
if (strcmp(buff1, " ") == 0)
strcpy(buff1, "-");
}
/* given a font name this function returns the part used in the third
scroll list */
static void getSizePart(const char *font, char *buff1, int inPixels)
{
int size;
if (inPixels)
{
getStringComponent(font, 7, buff1);
size = atoi(buff1);
sprintf(buff1, "%2d", size);
}
else
{
double temp;
getStringComponent(font, 8, buff1);
size = atoi(buff1);
temp = (double)size / 10.0;
if (buff1[strlen(buff1) - 1] == '0')
{
size = (int)floor(temp+0.5);
sprintf(buff1, "%2d", size);
}
else
sprintf(buff1, "%4.1f", temp);
}
}
/* Call back functions start from here - suffix Action in the function name
is for the callback function for the corresponding widget */
static void propFontToggleAction(Widget widget,
xfselControlBlkType *ctrlBlk,
XmToggleButtonCallbackStruct *call_data)
{
if (call_data->reason == XmCR_VALUE_CHANGED)
{
if (ctrlBlk->showPropFonts == PREF_FIXED)
ctrlBlk->showPropFonts = PREF_PROP;
else
ctrlBlk->showPropFonts = PREF_FIXED;
NEditFree(ctrlBlk->sel1);
ctrlBlk->sel1 = NULL;
NEditFree(ctrlBlk->sel2);
ctrlBlk->sel2 = NULL;
NEditFree(ctrlBlk->sel3);
ctrlBlk->sel3 = NULL;
setupScrollLists(NONE, *ctrlBlk);
XmTextSetString(ctrlBlk->fontNameField, "");
enableSample(ctrlBlk, False, NULL);
}
}
static void sizeToggleAction(Widget widget,
xfselControlBlkType *ctrlBlk,
XmToggleButtonCallbackStruct *call_data)
{
int i, makeSelection;
char newSize[10];
XmString str;
if (call_data->reason == XmCR_VALUE_CHANGED)
{
makeSelection = (ctrlBlk->sel3 != NULL);
for (i = 0; (makeSelection) && (i < ctrlBlk->numFonts); i++)
if ((fontMatch(ctrlBlk, ctrlBlk->fontData[i])) &&
(styleMatch(ctrlBlk, ctrlBlk->fontData[i])) &&
(sizeMatch(ctrlBlk, ctrlBlk->fontData[i])))
{
getSizePart(ctrlBlk->fontData[i], newSize,
!ctrlBlk->showSizeInPixels);
break;
}
if (ctrlBlk->showSizeInPixels)
ctrlBlk->showSizeInPixels = FALSE;
else
ctrlBlk->showSizeInPixels = TRUE;
NEditFree(ctrlBlk->sel3);
ctrlBlk->sel3 = NULL;
setupScrollLists(NONE, *ctrlBlk);
if (makeSelection)
{
str = XmStringCreate(newSize, XmSTRING_DEFAULT_CHARSET);
XmListSelectItem(ctrlBlk->sizeList, str, TRUE);
XmListSetBottomItem(ctrlBlk->sizeList, str);
XmStringFree(str);
}
}
}
static void enableSample(xfselControlBlkType *ctrlBlk, Bool turn_on,
XmFontList *fontList)
{
int n=0;
Arg args[4];
XtSetArg(args[n], XmNeditable, turn_on); n++;
XtSetArg(args[n], XmNcursorPositionVisible, turn_on); n++;
if( turn_on ) {
if( !fontList ) {
fprintf(stderr, "nedit: Internal error in fontsel.c, line %i\n", \
__LINE__);
} else {
XtSetArg(args[n], XmNfontList, *fontList); n++;
}
XtSetArg(args[n], XmNforeground, ctrlBlk->sampleFG); n++;
} else {
XtSetArg(args[n], XmNforeground, ctrlBlk->sampleBG); n++;
}
XtSetValues(ctrlBlk->dispField, args, n);
/* Make sure the sample area gets resized if the font size changes */
XtUnmanageChild(ctrlBlk->dispField);
XtManageChild(ctrlBlk->dispField);
}
static void fontAction(Widget widget, xfselControlBlkType *ctrlBlk,
XmListCallbackStruct *call_data)
{
char *sel;
XmStringGetLtoR(call_data->item, XmSTRING_DEFAULT_CHARSET, &sel);
if (ctrlBlk->sel1 == NULL)
{
ctrlBlk->sel1 = NEditStrdup(sel);
}
else
{
if (strcmp(ctrlBlk->sel1, sel) == 0)
{ /* Unselecting current selection */
NEditFree(ctrlBlk->sel1);
ctrlBlk->sel1 = NULL;
XmListDeselectItem(widget, call_data->item);
}
else
{
NEditFree(ctrlBlk->sel1);
ctrlBlk->sel1 = NEditStrdup(sel);
}
}
NEditFree(sel);
setupScrollLists(FONT, *ctrlBlk);
if ((ctrlBlk->sel1 != NULL) && (ctrlBlk->sel2 != NULL) &&
(ctrlBlk->sel3 != NULL))
choiceMade(ctrlBlk);
else
{
enableSample(ctrlBlk, False, NULL);
XmTextSetString(ctrlBlk->fontNameField, "");
}
}
static void styleAction(Widget widget, xfselControlBlkType *ctrlBlk,
XmListCallbackStruct *call_data)
{
char *sel;
XmStringGetLtoR(call_data->item, XmSTRING_DEFAULT_CHARSET, &sel);
if (ctrlBlk->sel2 == NULL)
{
ctrlBlk->sel2 = NEditStrdup(sel);
}
else
{
if (strcmp(ctrlBlk->sel2, sel) == 0)
{ /* unselecting current selection */
NEditFree(ctrlBlk->sel2);
ctrlBlk->sel2 = NULL;
XmListDeselectItem(widget, call_data->item);
}
else
{
NEditFree(ctrlBlk->sel2);
ctrlBlk->sel2 = NEditStrdup(sel);
}
}
NEditFree(sel);
setupScrollLists(STYLE, *ctrlBlk);
if ((ctrlBlk->sel1 != NULL) && (ctrlBlk->sel2 != NULL) &&
(ctrlBlk->sel3 != NULL))
choiceMade(ctrlBlk);
else
{
enableSample(ctrlBlk, False, NULL);
XmTextSetString(ctrlBlk->fontNameField, "");
}
}
static void sizeAction(Widget widget, xfselControlBlkType *ctrlBlk,
XmListCallbackStruct *call_data)
{
char *sel;
XmStringGetLtoR(call_data->item, XmSTRING_DEFAULT_CHARSET, &sel);
if (ctrlBlk->sel3 == NULL)
{
ctrlBlk->sel3 = NEditStrdup(sel);
}
else
{
if (strcmp(ctrlBlk->sel3, sel) == 0)
{ /* unselecting current selection */
NEditFree(ctrlBlk->sel3);
ctrlBlk->sel3 = NULL;
XmListDeselectItem(widget, call_data->item);
}
else
{
NEditFree(ctrlBlk->sel3);
ctrlBlk->sel3 = NEditStrdup(sel);
}
}
NEditFree(sel);
setupScrollLists(SIZE, *ctrlBlk);
if ((ctrlBlk->sel1 != NULL) && (ctrlBlk->sel2 != NULL) &&
(ctrlBlk->sel3 != NULL))
choiceMade(ctrlBlk);
else
{
enableSample(ctrlBlk, False, NULL);
XmTextSetString(ctrlBlk->fontNameField, "");
}
}
/* function called when all three choices have been made; sets up font
name and displays sample font */
static void choiceMade(xfselControlBlkType *ctrlBlk)
{
int i;
NEditFree(ctrlBlk->fontName);
ctrlBlk->fontName = NULL;
for (i = 0; i < ctrlBlk->numFonts; i++)
{
if ((fontMatch(ctrlBlk, ctrlBlk->fontData[i])) &&
(styleMatch(ctrlBlk, ctrlBlk->fontData[i])) &&
(sizeMatch (ctrlBlk, ctrlBlk->fontData[i])))
{
ctrlBlk->fontName = NEditStrdup(ctrlBlk->fontData[i]);
break;
}
}
if (ctrlBlk->fontName != NULL)
{
XmTextSetString(ctrlBlk->fontNameField, ctrlBlk->fontName);
dispSample(ctrlBlk);
}
else
{
DialogF (DF_ERR, ctrlBlk->form, 1, "Font Specification",
"Invalid Font Specification", "OK");
}
}
/* loads selected font and displays sample text in that font */
static void dispSample(xfselControlBlkType *ctrlBlk)
{
XFontStruct *font;
XmFontList fontList;
Display *display;
display = XtDisplay(ctrlBlk->form);
font = XLoadQueryFont(display, ctrlBlk->fontName);
fontList = XmFontListCreate(font, XmSTRING_DEFAULT_CHARSET);
enableSample(ctrlBlk, True, &fontList);
if (ctrlBlk->oldFont != NULL)
{
XFreeFont(display, ctrlBlk->oldFont);
XmFontListFree(ctrlBlk->oldFontList);
}
ctrlBlk->oldFont = font;
ctrlBlk->oldFontList = fontList;
}
static void destroyCB(Widget widget, xfselControlBlkType *ctrlBlk,
XmListCallbackStruct *call_data)
{
/* Prevent double destruction of the font selection dialog */
ctrlBlk->destroyedFlag = TRUE;
cancelAction(widget, ctrlBlk, call_data);
}
static void cancelAction(Widget widget, xfselControlBlkType *ctrlBlk,
XmListCallbackStruct *call_data)
{
NEditFree(ctrlBlk->sel1);
NEditFree(ctrlBlk->sel2);
NEditFree(ctrlBlk->sel3);
NEditFree(ctrlBlk->fontName);
ctrlBlk->fontName = NULL;
XFreeFontNames(ctrlBlk->fontData);
ctrlBlk->exitFlag = TRUE;
}
static void okAction(Widget widget, xfselControlBlkType *ctrlBlk,
XmPushButtonCallbackStruct *call_data)
{
char *fontPattern;
char **fontName;
int i;
fontPattern = XmTextGetString(ctrlBlk->fontNameField);
fontName = XListFonts(XtDisplay(ctrlBlk->form), fontPattern, 1, &i);
NEditFree(fontPattern);
if ((fontName == NULL) || (i == 0))
{
DialogF (DF_ERR, ctrlBlk->okButton, 1, "Font Specification",
"Invalid Font Specification", "OK");
XFreeFontNames(fontName);
}
else
{
NEditFree(ctrlBlk->fontName);
ctrlBlk->fontName = NEditStrdup(fontName[0]);
NEditFree(ctrlBlk->sel1);
NEditFree(ctrlBlk->sel2);
NEditFree(ctrlBlk->sel3);
XFreeFontNames(fontName);
XFreeFontNames(ctrlBlk->fontData);
ctrlBlk->exitFlag = TRUE;
}
}
/* if current font is passed as an argument then this function is
invoked and sets up initial entries */
static void startupFont(xfselControlBlkType *ctrlBlk, const char *font)
{
int i;
char **fontName;
char part[TEMP_BUF_SIZE];
XmString str;
fontName = XListFonts(XtDisplay(ctrlBlk->form), font, 1, &i);
if ((fontName == NULL) || (i == 0))
{ /* invalid font passed in at startup */
XFreeFontNames(fontName);
return;
}
ctrlBlk->fontName = NEditStrdup(fontName[0]);
getFontPart(fontName[0], part);
XFreeFontNames(fontName);
str = XmStringCreate(part, XmSTRING_DEFAULT_CHARSET);
XmListSetBottomItem(ctrlBlk->fontList, str);
XmListSelectItem(ctrlBlk->fontList, str, TRUE);
XmListSelectItem(ctrlBlk->fontList, str, TRUE);
XmStringFree(str);
dispSample(ctrlBlk);
XmTextSetString(ctrlBlk->fontNameField, ctrlBlk->fontName);
}
/* hacked code to move initial input focus to first scroll list and at the
same time have the OK button as the default button */
static void setFocus(Widget w, xfselControlBlkType *ctrlBlk, XEvent *event,
Boolean *continueToDispatch)
{
int n;
Arg args[2];
*continueToDispatch = TRUE;
n = 0;
XtSetArg(args[n], XmNdefaultButton, ctrlBlk->okButton); n++;
XtSetValues(ctrlBlk->form, args, n);
}
/* finds the name of the biggest font less than the given limit
MAX_DISPLAY_SIZE used to set up the initial height of the display widget
*/
static void FindBigFont(xfselControlBlkType *ctrlBlk, char *bigFont)
{
int i, maxSize, ind = -1, size;
char sizeStr[10];
for (i = 0, maxSize = 0; i < ctrlBlk->numFonts; i++)
{
getStringComponent(ctrlBlk->fontData[i], 7, sizeStr);
size = atoi(sizeStr);
if ((size > maxSize) && (size < MAX_DISPLAY_SIZE))
{
ind = i;
maxSize = size;
}
}
if (ind >= 0) {
strcpy(bigFont, ctrlBlk->fontData[ind]);
}
else {
bigFont[0] = 0;
}
}
|