📄 fontprefwinc.c
字号:
/* * $Id: FontPrefWinC.C,v 1.2 2000/05/07 12:26:11 fnevgeny Exp $ * * Copyright (c) 1994 HAL Computer Systems International, Ltd. * * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. * 1315 Dell Avenue * Campbell, CA 95008 * * Author: Greg Hilton * Contributors: Tom Lang, Frank Bieser, and others * * This 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 2 * of the License, or (at your option) any later version. * * This program 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. * * http://www.gnu.org/copyleft/gpl.html * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include <config.h>#include "FontPrefWinC.h"#include "FontPrefC.h"#include "IshAppC.h"#include "MainWinC.h"#include <hgl/WArgList.h>#include <hgl/WXmString.h>#include <hgl/TBoxC.h>#include <hgl/VBoxC.h>#include <hgl/rsrc.h>#include <hgl/RowColC.h>#include <hgl/MimeRichTextC.h>#include <hgl/StrCase.h>#include <hgl/TextMisc.h>#include <hgl/FontChooserC.h>#include <hgl/FontDataC.h>#include <Xm/Label.h>#include <Xm/TextF.h>#include <Xm/RowColumn.h>#include <Xm/PushB.h>#include <Xm/CascadeB.h>#include <Xm/Text.h>#include <Xm/List.h>#include <Xm/Separator.h>#include <X11/IntrinsicP.h>#include <X11/CoreP.h>#define SHOW_MENU 0/*--------------------------------------------------------------- * Main window constructor */FontPrefWinC::FontPrefWinC(Widget par) : OptWinC(par, "fontWin"){ WArgList args; Widget wlist[16]; pbFont = NULL; labelFont = NULL; textFont = NULL; richFont = NULL; listFont = NULL; chooser = NULL; curTF = NULL;//// Create appForm hierarchy//// appForm// RowColC fontRC// Label pbLabel// TextField pbTF// PushButton pbChoosePB// Label labelLabel// TextField labelTF// PushButton labelChoosePB// Label textLabel// TextField textTF// PushButton textChoosePB// Label richLabel// TextField richTF// PushButton richChoosePB// Label listLabel// TextField listTF// PushButton listChoosePB// args.Reset(); args.TopAttachment(XmATTACH_FORM); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_NONE); RowColC *fontRC = new RowColC(appForm, "fontRC", ARGS); fontRC->Defer(True);//// Set up 3 columns// fontRC->SetOrientation(RcROW_MAJOR); fontRC->SetColCount(3); fontRC->SetColAlignment(XmALIGNMENT_CENTER); fontRC->SetColAlignment(0, XmALIGNMENT_END); fontRC->SetColWidthAdjust(0, RcADJUST_NONE); fontRC->SetColWidthAdjust(1, RcADJUST_ATTACH); fontRC->SetColWidthAdjust(2, RcADJUST_EQUAL); fontRC->SetColResize(False); fontRC->SetColResize(1, True); pbLabel = XmCreateLabel (*fontRC, "pbLabel", 0,0); pbTF = CreateTextField (*fontRC, "pbTF", 0,0); pbChoosePB = XmCreatePushButton(*fontRC, "pbChoosePB", 0,0); labelLabel = XmCreateLabel (*fontRC, "labelLabel", 0,0); labelTF = CreateTextField (*fontRC, "labelTF", 0,0); labelChoosePB = XmCreatePushButton(*fontRC, "labelChoosePB", 0,0); textLabel = XmCreateLabel (*fontRC, "textLabel", 0,0); textTF = CreateTextField (*fontRC, "textTF", 0,0); textChoosePB = XmCreatePushButton(*fontRC, "textChoosePB", 0,0); richLabel = XmCreateLabel (*fontRC, "richLabel", 0,0); richTF = CreateTextField (*fontRC, "richTF", 0,0); richChoosePB = XmCreatePushButton(*fontRC, "richChoosePB", 0,0); listLabel = XmCreateLabel (*fontRC, "listLabel", 0,0); listTF = CreateTextField (*fontRC, "listTF", 0,0); listChoosePB = XmCreatePushButton(*fontRC, "listChoosePB", 0,0); XtAddCallback(pbChoosePB, XmNactivateCallback, (XtCallbackProc)PickFont, (XtPointer)this); XtAddCallback(labelChoosePB, XmNactivateCallback, (XtCallbackProc)PickFont, (XtPointer)this); XtAddCallback(textChoosePB, XmNactivateCallback, (XtCallbackProc)PickFont, (XtPointer)this); XtAddCallback(richChoosePB, XmNactivateCallback, (XtCallbackProc)PickFont, (XtPointer)this); XtAddCallback(listChoosePB, XmNactivateCallback, (XtCallbackProc)PickFont, (XtPointer)this); Cardinal wcount = 0; wlist[wcount++] = pbLabel; wlist[wcount++] = pbTF; wlist[wcount++] = pbChoosePB; wlist[wcount++] = labelLabel; wlist[wcount++] = labelTF; wlist[wcount++] = labelChoosePB; wlist[wcount++] = textLabel; wlist[wcount++] = textTF; wlist[wcount++] = textChoosePB; wlist[wcount++] = richLabel; wlist[wcount++] = richTF; wlist[wcount++] = richChoosePB; wlist[wcount++] = listLabel; wlist[wcount++] = listTF; wlist[wcount++] = listChoosePB; fontRC->SetChildren(wlist, wcount); XtManageChild(*fontRC); // appForm children fontRC->Defer(False); HandleHelp();//// Initialize fields// FontPrefC *prefs = ishApp->fontPrefs; XmTextFieldSetString(pbTF, prefs->buttonFont); XmTextFieldSetString(labelTF, prefs->labelFont); XmTextFieldSetString(textTF, prefs->textFont); XmTextFieldSetString(richTF, prefs->richFont); XmTextFieldSetString(listTF, prefs->listFont);} // End constructor/*--------------------------------------------------------------- * Main window destructor */FontPrefWinC::~FontPrefWinC(){ delete pbFont; delete labelFont; delete textFont; delete richFont; delete listFont;}/*--------------------------------------------------------------- * Method to apply changes */BooleanFontPrefWinC::Apply(){ BusyCursor(True); FontPrefC *prefs = ishApp->fontPrefs;//// Read the name of the pushbutton font// char *cs = XmTextFieldGetString(pbTF); StringC pbFontStr(cs); XtFree(cs); pbFontStr.Trim(); if ( pbFontStr == prefs->buttonFont ) pbFontStr.Clear(); if ( pbFontStr.size() > 0 ) { if ( debuglev > 0 ) cout <<"Push button font is: " <<pbFontStr <<endl; if ( pbFont ) *pbFont = pbFontStr; else pbFont = new FontDataC(pbFontStr);//// Try to load this font// if ( !pbFont->loaded ) { StringC msg("Can't load font: "); msg += pbFontStr; set_invalid(pbTF, True, True); PopupMessage(msg); BusyCursor(False); return False; } }//// Read the name of the label font// cs = XmTextFieldGetString(labelTF); StringC labelFontStr(cs); XtFree(cs); labelFontStr.Trim(); if ( labelFontStr == prefs->labelFont ) labelFontStr.Clear(); if ( labelFontStr.size() > 0 ) { if ( debuglev > 0 ) cout <<"Label font is: " <<labelFontStr <<endl; if ( labelFont ) *labelFont = labelFontStr; else labelFont = new FontDataC(labelFontStr);//// Try to load this font// if ( !labelFont->loaded ) { StringC msg("Can't load font: "); msg += labelFontStr; set_invalid(labelTF, True, True); PopupMessage(msg); BusyCursor(False); return False; } }//// Read the name of the text font// cs = XmTextFieldGetString(textTF); StringC textFontStr(cs); XtFree(cs); textFontStr.Trim(); if ( textFontStr == prefs->textFont ) textFontStr.Clear(); if ( textFontStr.size() > 0 ) { if ( debuglev > 0 ) cout <<"Text font is: " <<textFontStr <<endl; if ( textFont ) *textFont = textFontStr; else textFont = new FontDataC(textFontStr);//// Try to load this font// if ( !textFont->loaded ) { StringC msg("Can't load font: "); msg += textFontStr; set_invalid(textTF, True, True); PopupMessage(msg); BusyCursor(False); return False; } }//// Read the name of the rich font// cs = XmTextFieldGetString(richTF); StringC richFontStr(cs); XtFree(cs); richFontStr.Trim(); if ( richFontStr == prefs->richFont ) richFontStr.Clear(); if ( richFontStr.size() > 0 ) { if ( debuglev > 0 ) cout <<"Rich font is: " <<richFontStr <<endl; if ( richFont ) *richFont = richFontStr; else richFont = new FontDataC(richFontStr);//// Try to load this font// if ( !richFont->loaded ) { StringC msg("Can't load font: "); msg += richFontStr; set_invalid(richTF, True, True); PopupMessage(msg); BusyCursor(False); return False; } }//// Read the name of the message list font// cs = XmTextFieldGetString(listTF); StringC listFontStr(cs); XtFree(cs); listFontStr.Trim(); if ( listFontStr == prefs->listFont ) listFontStr.Clear(); if ( listFontStr.size() > 0 ) { if ( debuglev > 0 ) cout <<"Message list font is: " <<listFontStr <<endl; if ( listFont ) *listFont = listFontStr; else listFont = new FontDataC(listFontStr);//// Try to load this font// if ( !listFont->loaded ) { StringC msg("Can't load font: "); msg += listFontStr; set_invalid(listTF, True, True); PopupMessage(msg); BusyCursor(False); return False; } }//// Update resources// if ( pbFont && pbFont->loaded && pbFontStr.size() > 0 ) prefs->buttonFont = pbFontStr; if ( labelFont && labelFont->loaded && labelFontStr.size() > 0 ) prefs->labelFont = labelFontStr; if ( textFont && textFont->loaded && textFontStr.size() > 0 ) prefs->textFont = textFontStr; if ( richFont && richFont->loaded && richFontStr.size() > 0 ) prefs->richFont = richFontStr; if ( listFont && listFont->loaded && listFontStr.size() > 0 ) prefs->listFont = listFontStr; prefs->WriteDatabase(); if ( applyAll ) prefs->WriteFile(); WArgList args;//// Update the push button font// if ( pbFont && pbFont->loaded && pbFontStr.size() > 0 ) {//// Create a font list// XmFontListEntry fent = XmFontListEntryCreate(XmFONTLIST_DEFAULT_TAG, XmFONT_IS_FONT, pbFont->xfont); XmFontList flist = XmFontListAppendEntry(NULL, fent);//// Update the resource for all existing buttons// args.FontList(flist); UpdateButtons(*halApp, ARGS); } // End if there is a push button font//// Update the label font// if ( labelFont && labelFont->loaded && labelFontStr.size() > 0 ) {//// Create a font list// XmFontListEntry fent = XmFontListEntryCreate(XmFONTLIST_DEFAULT_TAG, XmFONT_IS_FONT, labelFont->xfont); XmFontList flist = XmFontListAppendEntry(NULL, fent);//// Update the resource for all existing buttons// args.FontList(flist); UpdateLabels(*halApp, ARGS); } // End if there is a label font//// Update the text font// if ( textFontStr.size() > 0 ) { if ( textFont && textFont->loaded ) {//// Create a font list// XmFontListEntry fent = XmFontListEntryCreate(XmFONTLIST_DEFAULT_TAG, XmFONT_IS_FONT, textFont->xfont); XmFontList flist = XmFontListAppendEntry(NULL, fent);//// Update the resource for all existing buttons// args.FontList(flist); UpdateText(*halApp, ARGS); } UpdateRichFixed(*halApp, textFontStr); } // End if there is a text font
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -