📄 helpreswinc.c
字号:
// Add new value// line += ":\t"; line += val;//// Create a new entry and add it to the alternate list// edit->entry = new ResEntryC(line); edit->w = rec->w; list2.add(edit->entry); } // End if no edit entry exists } // End if new value is different than original//// If the new value is the same as the original value and an edit entry exists,// delete it// else if ( edit->entry ) { list2.remove(edit->entry); delete edit->entry; edit->entry = NULL; }} // End CheckResVal/*----------------------------------------------------------------- * Callback to pick a widget and load the resources */voidHelpResWinC::DoWidgetPick(Widget, HelpResWinC *This, XtPointer){ XEvent ev; Widget w = XmTrackingEvent(*This, This->pickCursor, False, &ev); XmUpdateDisplay(*This); XFlush(halApp->display); XSync(halApp->display, False); if ( !w ) return; halApp->BusyCursor(True);//// If this widget isn't in the list, generate a list for the shell containing// the widget.// WidgetRecC *rec = This->GetWidgetRec(w); if ( !rec ) { Widget shell = XtParent(w); while ( shell && !XtIsShell(shell) ) shell = XtParent(shell); This->Clear(); This->widgetBox->RemoveAllItems(); This->LoadWidget(shell, /*all=*/True); This->ClearMessage(); }//// Display the info for this widget// This->ShowWidgetInfo(w); halApp->BusyCursor(False);} // End DoWidgetPick/*----------------------------------------------------------------- * Callback to load the parent of the current widget */voidHelpResWinC::DoParentLoad(Widget, HelpResWinC *This, XtPointer){ if ( !This->curWidget ) return; Widget par = XtParent(This->curWidget->w); if ( !par ) return; This->ShowWidgetInfo(par);}/*----------------------------------------------------------------- * Callback to load the widget specified in the quick help source widget field */voidHelpResWinC::DoQuickLoad(Widget, HelpResWinC *This, XtPointer){ EntryDataC* data = This->curWidget->QuickData(); This->ShowWidgetInfo(data->w);}/*----------------------------------------------------------------- * Callback to load the widget specified in the context help source widget field */voidHelpResWinC::DoContLoad(Widget, HelpResWinC *This, XtPointer){ EntryDataC* data = This->curWidget->ContData(); This->ShowWidgetInfo(data->w);}/*----------------------------------------------------------------- * Callback to load the widget specified in the help button source widget field */voidHelpResWinC::DoHelpLoad(Widget, HelpResWinC *This, XtPointer){ EntryDataC* data = This->curWidget->HelpData(); This->ShowWidgetInfo(data->w);}/*----------------------------------------------------------------- * Callback to view the helpcard specified in the context helpcard field */voidHelpResWinC::DoContCard(Widget, HelpResWinC *This, XtPointer){ This->BusyCursor(True); char *cs = XmTextFieldGetString(This->contCardTF); StringC name(cs); XtFree(cs); HelpCardC *card = halApp->HelpWin()->FindCard(name); halApp->HelpWin()->ShowCard(card, *This); This->BusyCursor(False);}/*----------------------------------------------------------------- * Callback to view the helpcard specified in the help button helpcard field */voidHelpResWinC::DoHelpCard(Widget, HelpResWinC *This, XtPointer){ This->BusyCursor(True); char *cs = XmTextFieldGetString(This->helpCardTF); StringC name(cs); XtFree(cs); HelpCardC *card = halApp->HelpWin()->FindCard(name); halApp->HelpWin()->ShowCard(card, *This); This->BusyCursor(False);}/*----------------------------------------------------------------- * Callback to show resources for next widget in list */voidHelpResWinC::DoWidgetNext(Widget, HelpResWinC *This, XtPointer){ VItemListC& items = This->widgetBox->VisItems(); u_int icount = items.size(); if ( icount == 0 ) return; VItemC *item = NULL; VItemListC& selItems = This->widgetBox->SelItems(); u_int scount = selItems.size(); if ( scount == 0 ) { item = items[0]; } else { item = selItems[scount-1]; int index = items.indexOf(item) + 1; if ( index >= icount ) index = 0; item = items[index]; } if ( item ) { WidgetRecC *rec = (WidgetRecC*)item->UserData(); This->ShowWidgetInfo(rec); }}/*----------------------------------------------------------------- * Callback to show resources for previous widget in list */voidHelpResWinC::DoWidgetPrev(Widget, HelpResWinC *This, XtPointer){ VItemListC& items = This->widgetBox->VisItems(); u_int icount = items.size(); if ( icount == 0 ) return; VItemC *item = NULL; VItemListC& selItems = This->widgetBox->SelItems(); u_int scount = selItems.size(); if ( scount == 0 ) { item = items[0]; } else { item = selItems[0]; int index = items.indexOf(item) - 1; if ( index < 0 ) index = icount-1; item = items[index]; } if ( item ) { WidgetRecC *rec = (WidgetRecC*)item->UserData(); This->ShowWidgetInfo(rec); }}/*----------------------------------------------------------------- * Callback to reset resources for current widget */voidHelpResWinC::DoWidgetReset(Widget, HelpResWinC *This, XtPointer){ if ( This->curWidget ) { This->curWidget->Reset(); This->changed = True; This->ShowWidgetInfo(This->curWidget); }}#if 0/*----------------------------------------------------------------- * Callback to delete resources for current widget */voidHelpResWinC::DoWidgetDel(Widget, HelpResWinC *This, XtPointer){}#endif/*--------------------------------------------------------------- * Callback routine to handle response in a question dialog */static voidAnswerQuery(Widget, int *answer, XmAnyCallbackStruct *cbs){ *answer = cbs->reason;}/*------------------------------------------------------------------------ * Trap window manager close */static voidWmClose(Widget, int *answer, XtPointer){ *answer = XmCR_CANCEL;}/*--------------------------------------------------------------- * Method to save resources */voidHelpResWinC::DoSave(Widget, HelpResWinC *This, XtPointer){//// Prompt for a file name// WArgList args; args.DialogStyle(XmDIALOG_FULL_APPLICATION_MODAL); if ( halApp->questionPM ) args.SymbolPixmap(halApp->questionPM); Widget dialog = XmCreatePromptDialog(*This, "fileNameWin", ARGS); int answer; XtAddCallback(dialog, XmNokCallback, (XtCallbackProc)AnswerQuery, (XtPointer)&answer); XtAddCallback(dialog, XmNcancelCallback, (XtCallbackProc)AnswerQuery, (XtPointer)&answer); XtUnmanageChild(XmSelectionBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));//// Trap window manager close function// XmAddWMProtocolCallback(XtParent(dialog), halApp->delWinAtom, (XtCallbackProc)WmClose, (caddr_t)&answer);//// Display dialog// XtManageChild(dialog); StringC file; while ( file.size() == 0 ) {//// Wait for answer// answer = XmCR_NONE; while ( answer == XmCR_NONE ) { XtAppProcessEvent(halApp->context, XtIMXEvent); XSync(halApp->display, False); }//// Read file name from text field// if ( answer != XmCR_CANCEL ) { XmString str; XtVaGetValues(dialog, XmNtextString, &str, NULL); WXmString wstr(str); char *cs = (char*)wstr; file = cs; file.Trim(); XtFree(cs); XmStringFree(str); if ( file.size() == 0 ) { This->PopupMessage("Please enter a file name"); set_invalid(XmSelectionBoxGetChild(dialog, XmDIALOG_TEXT), True, True); } } } XtUnmanageChild(dialog); XtDestroyWidget(dialog); XSync(halApp->display, False); if ( answer == XmCR_CANCEL ) return;//// Create file// FILE *fp = fopen(file, "w"); if ( !fp ) { StringC errmsg = "Could not create "; errmsg += file; This->PopupMessage(errmsg); return; }//// Write out quick help// fprintf(fp, "\n"); fprintf(fp, "!--------------------------------------------------\n"); fprintf(fp, "! Quick Help\n"); fprintf(fp, "!--------------------------------------------------\n"); fprintf(fp, "\n"); Boolean error = False; error = !This->WriteResources(fp, This->quickList, This->quickList2); //// Write out context help// if ( !error ) { fprintf(fp, "\n"); fprintf(fp, "!--------------------------------------------------\n"); fprintf(fp, "! Context Help\n"); fprintf(fp, "!--------------------------------------------------\n"); fprintf(fp, "\n"); error = !This->WriteResources(fp, This->contList, This->contList2); } //// Write out helpcards// if ( !error ) { fprintf(fp, "\n"); fprintf(fp, "!--------------------------------------------------\n"); fprintf(fp, "! Help Button Helpcards\n"); fprintf(fp, "!--------------------------------------------------\n"); fprintf(fp, "\n"); error = !This->WriteResources(fp, This->helpList, This->helpList2); } fclose(fp); error = (errno != 0); if ( error ) { StringC errmsg = "Could not write "; errmsg += file; errmsg += '\n'; errmsg += SystemErrorMessage(errno); This->PopupMessage(errmsg); return; }//// Write new resources to the database and move them to the original list// This->MergeLists(This->quickList, This->quickList2); This->MergeLists(This->contList, This->contList2); This->MergeLists(This->helpList, This->helpList2);//// Update widget rec entry pointers// u_int count = This->widgetList.size(); for (int i=0; i<count; i++) { WidgetRecC *rec = (WidgetRecC*)This->widgetList[i]; if ( rec->edit.quick.entry ) { rec->orig.quick.entry = rec->edit.quick.entry; rec->edit.quick.entry = NULL; } if ( rec->edit.cont.entry ) { rec->orig.cont.entry = rec->edit.cont.entry; rec->edit.cont.entry = NULL; } if ( rec->edit.help.entry ) { rec->orig.help.entry = rec->edit.help.entry; rec->edit.help.entry = NULL; } }} // End DoSave/*--------------------------------------------------------------- * Method to close window */voidHelpResWinC::DoDone(Widget, HelpResWinC *This, XtPointer){ Boolean needSave; if ( !This->QuerySave(&needSave, /*cancelOk=*/True) ) return; if ( needSave ) DoSave(NULL, This, NULL); This->Hide();}/*------------------------------------------------------------------------ * Check for changes that need to be saved */BooleanHelpResWinC::QuerySave(Boolean *doSave, Boolean cancelOk){ *doSave = False; if ( quickList2.size() == 0 && contList2.size() == 0 && helpList2.size() == 0 ) return True;//// Ask about saving changes// WArgList args; args.DialogStyle(XmDIALOG_FULL_APPLICATION_MODAL); if ( halApp->questionPM ) args.SymbolPixmap(halApp->questionPM); Widget dialog = XmCreateQuestionDialog(*this, "saveChangesWin", ARGS); int answer; Widget noPB = XmCreatePushButton(dialog, "noPB", 0,0); XtManageChild(noPB); XtAddCallback(dialog, XmNokCallback, (XtCallbackProc)AnswerQuery, (XtPointer)&answer); XtAddCallback(noPB, XmNactivateCallback, (XtCallbackProc)AnswerQuery, (XtPointer)&answer); if ( cancelOk ) XtAddCallback(dialog, XmNcancelCallback, (XtCallbackProc)AnswerQuery, (XtPointer)&answer); else XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON)); XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));//// Trap window manager close function// XmAddWMProtocolCallback(XtParent(dialog), halApp->delWinAtom, (XtCallbackProc)WmClose, (caddr_t)&answer);//// Display dialog// XtManageChild(dialog);//// Wait for answer// answer = XmCR_NONE; while ( answer == XmCR_NONE ) { XtAppProcessEvent(halApp->context, XtIMXEvent); XSync(halApp->display, False); } XtUnmanageChild(dialog); XtDestroyWidget(dialog); XSync(halApp->display, False); if ( answer == XmCR_CANCEL ) return False; *doSave = (answer == XmCR_OK); return True;} // End QuerySave/*------------------------------------------------------------------------ * Write out resources from original and edit lists */BooleanHelpResWinC::WriteResources(FILE *fp, PtrList2& origList, PtrList2& editList){ ResEntryC *ent; CharC nl("\n");//// Write original entries if they don't appear in edit list.// u_int count = origList.size(); Boolean error = False; int i; for (i=0; !error && i<count; i++) { ent = (ResEntryC*)origList[i]; if ( EntryIndex(ent, editList) == -1 ) error = (!ent->full.WriteFile(fp) || !nl.WriteFile(fp)); }//// Write edit entries// if ( !error ) { CharC marker("!--------------------------------------------------\n"); error = !marker.WriteFile(fp); } count = editList.size(); for (i=0; !error && i<count; i++) { ent = (ResEntryC*)editList[i]; error = (!ent->full.WriteFile(fp) || !nl.WriteFile(fp)); } return !error;} // End WriteResources/*------------------------------------------------------------------------ * See if an exact match for this entry exists in the list */intHelpResWinC::EntryIndex(ResEntryC *thisEnt, PtrList2& list){ u_int count = list.size(); for (int i=0; i<count; i++) { ResEntryC *thatEnt = (ResEntryC*)list[i]; if ( thatEnt->wspec == thisEnt->wspec ) return i; } return -1;} // End EntryIndex/*------------------------------------------------------------------------ * Merge the edits into the orignal list */voidHelpResWinC::MergeLists(PtrList2& origList, PtrList2& editList){ XrmDatabase db = XtDatabase(halApp->display); u_int count = editList.size(); for (int i=0; i<count; i++) { ResEntryC *editEnt = (ResEntryC*)editList[i]; int index = EntryIndex(editEnt, origList); if ( index >= 0 ) { ResEntryC *origEnt = (ResEntryC*)origList[index]; origList.replace(editEnt, index); delete origEnt; } else origList.append(editEnt); XrmPutLineResource(&db, editEnt->full); } editList.removeAll();} // End MergeLists
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -