📄 helpc.c
字号:
/* * $Id: HelpC.C,v 1.2 2000/05/07 12:26:10 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 "HalAppC.h"#include "HelpC.h"#include "HelpDbC.h"#include "StringC.h"#include "rsrc.h"#include "WArgList.h"#include "WXmString.h"#include "MimeRichTextC.h"#include "TextMisc.h"#include "SysErr.h"#include "HelpResWinC.h"#include <Xm/MessageB.h>#include <Xm/Form.h>#include <Xm/Label.h>#include <Xm/Text.h>#include <Xm/TextF.h>#include <Xm/PushB.h>#include <Xm/List.h>#include <Xm/ScrolledW.h>#include <Xm/RowColumn.h>#include <Xm/CascadeB.h>#include <Xm/Protocols.h>#include <Xm/SelectioB.h>#include <Xm/AtomMgr.h>#include <X11/IntrinsicP.h>#include <X11/CoreP.h>#include <errno.h>#include <unistd.h>extern int debuglev;/*----------------------------------------------------------------------- * Constructor */HelpC::HelpC(Boolean editOk){ helpWin = NULL; glossWin = NULL; indexWin = NULL; indexList = NULL; curCard = NULL; helpResWin = NULL; showOlias = True; enriched = False; edit = editOk; changed = False; if ( debuglev > 0 ) { if ( Editable() ) cout <<"Helpcards can be edited" <<endl; else cout <<"Helpcards cannot be edited" <<endl; } StringC defname = halApp->name + ".hlp"; StringC files = get_string(*halApp, "helpcardDbFiles", defname);//// Create a database for each file// char *name = strtok(files, " "); while (name) { HelpDbC *db = new HelpDbC(name); if ( db->loaded ) { if ( debuglev > 1 ) cout <<"Loaded help db: " <<db <<endl; void *tmp = (void*)db; dbList.add(tmp); } else delete db; name = strtok(NULL, " "); } isActive = (dbList.size() > 0);} // End Constructor/*----------------------------------------------------------------------- * Destructor */HelpC::~HelpC(){#if EDIT_OK if ( CheckChanges(/*cancelOk=*/False) ) DoFileSave(NULL, this, NULL);#endif unsigned count = dbList.size(); for (int i=0; i<count; i++) { HelpDbC *db = (HelpDbC*)*dbList[i]; delete db; } delete helpResWin;} // End Destructor/*----------------------------------------------------------------------- * Method to display a helpcard for the specified widget */voidHelpC::ShowCard(const Widget w, const char *res, Widget parent){ if ( !isActive ) { StringC msg = "There are no help files available."; ShowMessage(msg, parent); return; } StringC name = CardName(w, res); if ( name.size() == 0 ) { StringC msg = "I could not find a \""; msg += res; msg += "\" resource for the widget \""; msg += XtName(w); msg += "\""; ShowMessage(msg, parent); return; }//// Look through each database for the card// unsigned count = dbList.size(); int i; for (i=0; i<count; i++) { HelpDbC *db = (HelpDbC*)*dbList[i]; if ( debuglev > 1 ) cout <<"Checking help db: " <<db <<endl; HelpCardC *card = db->FindCard(name); if ( card ) { if ( card->IsGlossary() ) ShowGlossary(card, parent); else ShowCard(card, parent); return; } } StringC msg = "I could not find the help card \""; msg += name; msg += "\" for the widget \""; msg += XtName(w); msg += "\"\n"; if ( dbList.size() > 1 ) { msg += "in any of the help files:\n"; count = dbList.size(); for (i=0; i<count; i++) { HelpDbC *db = (HelpDbC*)*dbList[i]; msg += " " + db->file + "\n"; } } else { HelpDbC *db = (HelpDbC*)*dbList[0]; msg += "in the help file: " + db->file; } ShowMessage(msg, parent);} // End ShowCard/*----------------------------------------------------------------------- * Method to create the helpcard window */voidHelpC::CreateHelpWin(){ if ( helpWin ) return; WArgList args; args.AutoUnmanage(False); if ( Editable() ) { args.DefaultButtonType(XmDIALOG_NONE); args.MinimizeButtons(False); args.DefaultButton(NULL); } if ( halApp->messagePM ) args.SymbolPixmap(halApp->messagePM); helpWin = XmCreateTemplateDialog(*halApp, "helpWin", ARGS); XtAddCallback(helpWin, XmNokCallback, (XtCallbackProc)DoHelpIndex,this); XtAddCallback(helpWin, XmNhelpCallback, (XtCallbackProc)DoHelpHelp, this);// Get the defaultButtonShadowThickness from the cancel button Dimension defShadow; Widget okPB = XmMessageBoxGetChild(helpWin, XmDIALOG_OK_BUTTON); XtVaGetValues(okPB, XmNdefaultButtonShadowThickness, &defShadow, NULL); args.Reset(); args.DefaultButtonShadowThickness(defShadow); Widget donePB = XmCreatePushButton(helpWin, "donePB", ARGS); XtAddCallback(donePB, XmNactivateCallback,(XtCallbackProc)DoHelpDone, this); showOlias = get_boolean(helpWin, "showOliasButton", False); if ( showOlias ) XtAddCallback(helpWin, XmNcancelCallback, (XtCallbackProc)DoHelpOlias, this); else { Widget oliasPB = XmMessageBoxGetChild(helpWin, XmDIALOG_CANCEL_BUTTON); if ( oliasPB ) XtUnmanageChild(oliasPB); } XtVaSetValues(helpWin, XmNdefaultButton, donePB, NULL); enriched = get_boolean(helpWin, "enrichedText", False); XtManageChild(donePB); Widget form = XmCreateForm(helpWin, "helpForm", 0,0); if ( Editable() ) {#if EDIT_OK args.Reset(); args.TopAttachment(XmATTACH_FORM); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_NONE); args.BottomAttachment(XmATTACH_NONE); Widget nameLabel = XmCreateLabel(form, "nameLabel", ARGS); XtManageChild(nameLabel); args.Reset(); args.TopAttachment(XmATTACH_OPPOSITE_WIDGET, nameLabel); args.LeftAttachment(XmATTACH_WIDGET, nameLabel); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_NONE); nameTF = CreateTextField(form, "nameTF", ARGS); XtManageChild(nameTF); XtAddCallback(nameTF, XmNmodifyVerifyCallback, (XtCallbackProc)ModifyName, this); XtAddCallback(nameTF, XmNactivateCallback, (XtCallbackProc)EnterName, this); args.Reset(); args.TopAttachment(XmATTACH_WIDGET, nameTF); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_NONE); args.BottomAttachment(XmATTACH_NONE); Widget locLabel = XmCreateLabel(form, "locLabel", ARGS); XtManageChild(locLabel); args.Reset(); args.TopAttachment(XmATTACH_OPPOSITE_WIDGET, locLabel); args.LeftAttachment(XmATTACH_WIDGET, locLabel); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_NONE); locTF = CreateTextField(form, "locTF", ARGS); XtManageChild(locTF); XtAddCallback(locTF, XmNvalueChangedCallback, (XtCallbackProc)TextChanged, this); args.Reset(); args.TopAttachment(XmATTACH_WIDGET, locTF); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_NONE); args.BottomAttachment(XmATTACH_NONE); Widget titleLabel = XmCreateLabel(form, "titleLabel", ARGS); XtManageChild(titleLabel); args.Reset(); args.TopAttachment(XmATTACH_OPPOSITE_WIDGET, titleLabel); args.LeftAttachment(XmATTACH_WIDGET, titleLabel); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_NONE); helpTitle = CreateTextField(form, "helpTitle", ARGS); XtManageChild(helpTitle); XtAddCallback(helpTitle, XmNvalueChangedCallback, (XtCallbackProc)TextChanged, this); Dimension maxWd, wd; XtVaGetValues(nameLabel, XmNwidth, &maxWd, NULL); XtVaGetValues(locLabel, XmNwidth, &wd, NULL); if (wd>maxWd) maxWd = wd; XtVaGetValues(titleLabel, XmNwidth, &wd, NULL); if (wd>maxWd) maxWd = wd; args.Reset(); args.Alignment(XmALIGNMENT_END); args.Width(maxWd); args.Resizable(False); XtSetValues(nameLabel, ARGS); XtSetValues(locLabel, ARGS); XtSetValues(titleLabel, ARGS);#endif } else { helpTitle = XmCreateLabel(form, "helpTitle", 0,0); XtManageChild(helpTitle); } args.Reset(); args.TopAttachment(XmATTACH_WIDGET, helpTitle); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_FORM); if ( enriched ) { richText = new MimeRichTextC(form, "richText", ARGS); richText->SetTextType(TT_ENRICHED); richText->SetEditable(Editable()); richText->ResizeWidth(False); richText->AddLinkAccessCallback((CallbackFn*)DoGlossaryCard, (void*)this); XtManageChild(richText->MainWidget()); } else { args.Editable(Editable()); args.EditMode(XmMULTI_LINE_EDIT); args.ScrollHorizontal(False); args.CursorPositionVisible(False); args.WordWrap(True); args.ResizeWidth(False); helpText = CreateScrolledText(form, "helpText", ARGS); XtManageChild(helpText); }#if EDIT_OK if ( Editable() ) { args.Reset(); Widget menuBar = XmCreateMenuBar(helpWin, "menuBar", 0,0); XtManageChild(menuBar);//// File menu// Widget filePD = XmCreatePulldownMenu(menuBar, "filePD", 0,0); args.SubMenuId(filePD); Widget fileCB = XmCreateCascadeButton(menuBar, "fileCB", ARGS); XtManageChild(fileCB);#if 0 Widget fileNewPB = XmCreatePushButton(filePD, "fileNewPB", 0,0); XtManageChild(fileNewPB); XtAddCallback(fileNewPB, XmNactivateCallback, (XtCallbackProc)DoFileNew, this); Widget fileDelPB = XmCreatePushButton(filePD, "fileDelPB", 0,0); XtManageChild(fileDelPB); XtAddCallback(fileDelPB, XmNactivateCallback, (XtCallbackProc)DoFileDel, this);#endif Widget fileSavePB = XmCreatePushButton(filePD, "fileSavePB", 0,0); XtManageChild(fileSavePB); XtAddCallback(fileSavePB, XmNactivateCallback, (XtCallbackProc)DoFileSave, this); if ( enriched ) { richText->AddTextChangeCallback((CallbackFn*)RichTextChanged, (void*)this);//// Edit menu// Widget editPD = XmCreatePulldownMenu(menuBar, "editPD", 0,0); args.SubMenuId(editPD); Widget editCB = XmCreateCascadeButton(menuBar, "editCB", ARGS); XtManageChild(editCB); Widget editPlainPB = XmCreatePushButton(editPD, "editPlainPB", 0,0); XtManageChild(editPlainPB); XtAddCallback(editPlainPB, XmNactivateCallback, (XtCallbackProc)DoEditPlain, this); Widget editBoldPB = XmCreatePushButton(editPD, "editBoldPB", 0,0); XtManageChild(editBoldPB); XtAddCallback(editBoldPB, XmNactivateCallback, (XtCallbackProc)DoEditBold, this); Widget editItalicPB = XmCreatePushButton(editPD, "editItalicPB", 0,0); XtManageChild(editItalicPB); XtAddCallback(editItalicPB, XmNactivateCallback, (XtCallbackProc)DoEditItalic, this); Widget editFixedPB = XmCreatePushButton(editPD, "editFixedPB", 0,0); XtManageChild(editFixedPB); XtAddCallback(editFixedPB, XmNactivateCallback, (XtCallbackProc)DoEditFixed, this); Widget editUnderPB = XmCreatePushButton(editPD, "editUnderPB", 0,0); XtManageChild(editUnderPB); XtAddCallback(editUnderPB, XmNactivateCallback, (XtCallbackProc)DoEditUnder, this); Widget editBigPB = XmCreatePushButton(editPD, "editBigPB", 0,0); XtManageChild(editBigPB); XtAddCallback(editBigPB, XmNactivateCallback, (XtCallbackProc)DoEditBig, this); Widget editSmallPB = XmCreatePushButton(editPD, "editSmallPB", 0,0); XtManageChild(editSmallPB); XtAddCallback(editSmallPB, XmNactivateCallback, (XtCallbackProc)DoEditSmall, this); Widget editUndelPB = XmCreatePushButton(editPD, "editUndelPB", 0,0); XtManageChild(editUndelPB); XtAddCallback(editUndelPB, XmNactivateCallback, (XtCallbackProc)DoEditUndel, this);//// Justify menu// Widget justPD = XmCreatePulldownMenu(menuBar, "justPD", 0,0); args.SubMenuId(justPD); Widget justCB = XmCreateCascadeButton(menuBar, "justCB", ARGS); XtManageChild(justCB); Widget justLeftPB = XmCreatePushButton(justPD, "justLeftPB", 0,0); XtManageChild(justLeftPB); XtAddCallback(justLeftPB, XmNactivateCallback, (XtCallbackProc)DoJustLeft, this); Widget justRightPB = XmCreatePushButton(justPD, "justRightPB", 0,0); XtManageChild(justRightPB); XtAddCallback(justRightPB, XmNactivateCallback, (XtCallbackProc)DoJustRight, this); Widget justCenterPB = XmCreatePushButton(justPD, "justCenterPB", 0,0); XtManageChild(justCenterPB); XtAddCallback(justCenterPB, XmNactivateCallback, (XtCallbackProc)DoJustCenter, this);//// Indent menu// Widget indentPD = XmCreatePulldownMenu(menuBar, "indentPD", 0,0); args.SubMenuId(indentPD); Widget indentCB = XmCreateCascadeButton(menuBar, "indentCB", ARGS); XtManageChild(indentCB); Widget indentLeftMorePB = XmCreatePushButton(indentPD, "indentLeftMorePB", 0,0); XtManageChild(indentLeftMorePB); XtAddCallback(indentLeftMorePB, XmNactivateCallback, (XtCallbackProc)DoIndentLeftMore, this); Widget indentLeftLessPB = XmCreatePushButton(indentPD, "indentLeftLessPB", 0,0); XtManageChild(indentLeftLessPB); XtAddCallback(indentLeftLessPB, XmNactivateCallback, (XtCallbackProc)DoIndentLeftLess, this); Widget indentRightMorePB = XmCreatePushButton(indentPD, "indentRightMorePB", 0,0); XtManageChild(indentRightMorePB); XtAddCallback(indentRightMorePB, XmNactivateCallback, (XtCallbackProc)DoIndentRightMore, this); Widget indentRightLessPB = XmCreatePushButton(indentPD, "indentRightLessPB", 0,0); XtManageChild(indentRightLessPB); XtAddCallback(indentRightLessPB, XmNactivateCallback, (XtCallbackProc)DoIndentRightLess, this);//// Color menu// Widget colorPD = XmCreatePulldownMenu(menuBar, "colorPD", 0,0); args.SubMenuId(colorPD); Widget colorCB = XmCreateCascadeButton(menuBar, "colorCB", ARGS); XtManageChild(colorCB); Widget colorRedPB = XmCreatePushButton(colorPD, "colorRedPB", 0,0); XtManageChild(colorRedPB); XtAddCallback(colorRedPB, XmNactivateCallback, (XtCallbackProc)DoColorRed, this); Widget colorGreenPB = XmCreatePushButton(colorPD, "colorGreenPB", 0,0); XtManageChild(colorGreenPB); XtAddCallback(colorGreenPB, XmNactivateCallback, (XtCallbackProc)DoColorGreen, this); Widget colorBluePB = XmCreatePushButton(colorPD, "colorBluePB", 0,0); XtManageChild(colorBluePB); XtAddCallback(colorBluePB, XmNactivateCallback, (XtCallbackProc)DoColorBlue, this); Widget colorYellowPB = XmCreatePushButton(colorPD, "colorYellowPB", 0,0); XtManageChild(colorYellowPB); XtAddCallback(colorYellowPB, XmNactivateCallback, (XtCallbackProc)DoColorYellow, this); Widget colorMagentaPB = XmCreatePushButton(colorPD, "colorMagentaPB", 0,0); XtManageChild(colorMagentaPB); XtAddCallback(colorMagentaPB, XmNactivateCallback, (XtCallbackProc)DoColorMagenta, this); Widget colorCyanPB = XmCreatePushButton(colorPD, "colorCyanPB", 0,0); XtManageChild(colorCyanPB); XtAddCallback(colorCyanPB, XmNactivateCallback, (XtCallbackProc)DoColorCyan, this); Widget colorBlackPB = XmCreatePushButton(colorPD, "colorBlackPB", 0,0); XtManageChild(colorBlackPB); XtAddCallback(colorBlackPB, XmNactivateCallback, (XtCallbackProc)DoColorBlack, this); Widget colorWhitePB = XmCreatePushButton(colorPD, "colorWhitePB", 0,0); XtManageChild(colorWhitePB); XtAddCallback(colorWhitePB, XmNactivateCallback, (XtCallbackProc)DoColorWhite, this); Widget colorNonePB = XmCreatePushButton(colorPD, "colorNonePB", 0,0); XtManageChild(colorNonePB); XtAddCallback(colorNonePB, XmNactivateCallback, (XtCallbackProc)DoColorNone, this);//// Modified label// modLabel = XmCreateCascadeButton(menuBar, "modLabel", 0,0); XtManageChild(modLabel);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -