⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fontsel.c

📁 nedit 是一款linux下的开发源码的功能强大的编辑器
💻 C
📖 第 1 页 / 共 4 页
字号:
static const char CVSID[] = "$Id: fontsel.c,v 1.25 2003/05/02 19:19:03 edg Exp $";/********************************************************************************                                                                              ** 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.                                                                     **                                                                              ** 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 "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                  90enum 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; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -