📄 buttprefwinc.c
字号:
availList.add(be); } } // End for each pulldown child} // End ProcessCascade/*--------------------------------------------------------------- * Callback routine to handle initial display. */voidButtPrefWinC::DoPopup(Widget, ButtPrefWinC *This, XtPointer){ XtRemoveCallback(This->shell, XmNpopupCallback, (XtCallbackProc)DoPopup, (XtPointer)This);//// Fix sizes of panes// Dimension ht; XtVaGetValues(This->arrowForm, XmNheight, &ht, NULL); XtVaSetValues(This->arrowForm, XmNpaneMinimum, ht, XmNpaneMaximum, ht, 0); This->gravRC->Refresh(); XtVaGetValues(This->placeForm, XmNheight, &ht, NULL); XtVaSetValues(This->placeForm, XmNpaneMinimum, ht, XmNpaneMaximum, ht, 0);} // End DoPopup/*--------------------------------------------------------------- * Method to display window */voidButtPrefWinC::Show(){ Show(XtParent(*this));}voidButtPrefWinC::Show(Widget w){ if ( shown ) return;//// Move used entries back to available list// Boolean sortNeeded = False; if ( usedList.size() > 0 ) { unsigned count = usedList.size(); for (int i=0; i<count; i++) { ButtonEntryC *entry = usedList[i]; availList.add(entry); } sortNeeded = True; usedList.removeAll(); }//// Find out which buttons are to be used// WidgetList custList; Cardinal custCount; XtVaGetValues(buttMgr->ButtonBox(), XmNnumChildren, &custCount, XmNchildren, &custList, NULL); ButtonEntryC *entry; int i; for (i=0; i<custCount; i++) {//// Get widget id of real button// Widget pb = custList[i]; short posIndex; XmString xstr; XtVaGetValues(pb, XmNpositionIndex, &posIndex, XmNlabelString, &xstr, 0);//// See which entry uses this button// int index = EntryIndex(availList, XtName(pb)); if ( index == availList.NULL_INDEX ) continue;//// Move this button to the used list// entry = availList[index]; usedList.add(entry); availList.replace(NULL, index); entry->posIndex = posIndex;//// Display the user's label// WXmString wstr = xstr; char *cs = wstr; entry->abbrev = cs; XtFree(cs); sortNeeded = True; } // End for each used button if ( sortNeeded ) { availList.removeNulls(); availList.sort(SortByLabel); usedList.sort(SortByIndex); }//// Add names to avail list// XmListDeleteAllItems(availListW); WXmString wstr; unsigned count = availList.size(); for (i=0; i<count; i++) { entry = availList[i]; wstr = (char*)entry->label; XmListAddItem(availListW, wstr, 0); }//// Add names to used list// XmListDeleteAllItems(usedListW); count = usedList.size(); for (i=0; i<count; i++) { entry = usedList[i]; wstr = (char*)entry->abbrev; XmListAddItem(usedListW, wstr, 0); }//// Initialize placement info// switch ( buttMgr->Gravity() ) { case (WestGravity): XmToggleButtonSetState(westTB, True, True); break; case (EastGravity): XmToggleButtonSetState(eastTB, True, True); break; case (NorthGravity): XmToggleButtonSetState(northTB, True, True); break; case (SouthGravity): default: XmToggleButtonSetState(southTB, True, True); break; } // End switch gravity Boolean sameSize; XtVaGetValues(buttMgr->ButtonBox(), BbNuniformCols, &sameSize, NULL); XmToggleButtonSetState(sameSizeTB, sameSize, True); OptWinC::Show(w);} // End Show/*--------------------------------------------------------------- * Callback to handle press of North button */voidButtPrefWinC::DoNorth(Widget, ButtPrefWinC *This, XmToggleButtonCallbackStruct *tb){ if ( tb->set ) { XmToggleButtonSetState(This->southTB, False, False); XmToggleButtonSetState(This->eastTB, False, False); XmToggleButtonSetState(This->westTB, False, False); } else { XmToggleButtonSetState(This->northTB, True, False); }} // End DoNorth/*--------------------------------------------------------------- * Callback to handle press of South button */voidButtPrefWinC::DoSouth(Widget, ButtPrefWinC *This, XmToggleButtonCallbackStruct *tb){ if ( tb->set ) { XmToggleButtonSetState(This->northTB, False, False); XmToggleButtonSetState(This->eastTB, False, False); XmToggleButtonSetState(This->westTB, False, False); } else { XmToggleButtonSetState(This->southTB, True, False); }} // End DoSouth/*--------------------------------------------------------------- * Callback to handle press of East button */voidButtPrefWinC::DoEast(Widget, ButtPrefWinC *This, XmToggleButtonCallbackStruct *tb){ if ( tb->set ) { XmToggleButtonSetState(This->northTB, False, False); XmToggleButtonSetState(This->southTB, False, False); XmToggleButtonSetState(This->westTB, False, False); } else { XmToggleButtonSetState(This->eastTB, True, False); }} // End DoEast/*--------------------------------------------------------------- * Callback to handle press of West button */voidButtPrefWinC::DoWest(Widget, ButtPrefWinC *This, XmToggleButtonCallbackStruct *tb){ if ( tb->set ) { XmToggleButtonSetState(This->northTB, False, False); XmToggleButtonSetState(This->southTB, False, False); XmToggleButtonSetState(This->eastTB, False, False); } else { XmToggleButtonSetState(This->westTB, True, False); }} // End DoWest/*--------------------------------------------------------------- * Method to apply settings */BooleanButtPrefWinC::Apply(){ BusyCursor(True);//// Read button gravity// int gravity; if ( XmToggleButtonGetState(northTB) ) gravity = NorthGravity; else if ( XmToggleButtonGetState(eastTB) ) gravity = EastGravity; else if ( XmToggleButtonGetState(westTB) ) gravity = WestGravity; else gravity = SouthGravity; Boolean sameSize = XmToggleButtonGetState(sameSizeTB);//// Loop for each button manager// u_int mgrCount = buttMgrList.size(); for (int m=0; m<mgrCount; m++) { ButtonMgrC *mgr = (ButtonMgrC*)*buttMgrList[m];//// Read list of existing buttons// WidgetList custList; Cardinal custCount; XtVaGetValues(mgr->ButtonBox(), XmNnumChildren, &custCount, XmNchildren, &custList, NULL);//// Build list of button names and copy the widget ids. When we change the// position index, the original list gets rearranged.// StringC name; StringListC nameList; WidgetListC buttList; nameList.SetSorted(FALSE); nameList.AllowDuplicates(TRUE); int i; for (i=0; i<custCount; i++) { Widget pb = custList[i]; name = XtName(pb); nameList.add(name); buttList.add(pb); } u_int nameCount = nameList.size();//// Remove any buttons that are no longer needed// WidgetListC remList; for (i=0; i<nameCount; i++) {//// If "name" doesn't appear in used list, it's not needed// int index = EntryIndex(usedList, *nameList[i]); if ( index == usedList.NULL_INDEX ) remList.add(*buttList[i]); }//// Delete obsolete buttons// if ( remList.size() > 0 ) mgr->RemoveButtons(remList.start(), remList.size());//// Loop through the buttons we need// WArgList args; u_int count = usedList.size(); for (i=0; i<count; i++) { ButtonEntryC *entry = usedList[i]; int index = nameList.indexOf(entry->name);//// Add button if not present// if ( index == nameList.NULL_INDEX ) {//// Set the label string and position index// XmString xmstr = XmStringCreateLtoR(entry->abbrev, XmFONTLIST_DEFAULT_TAG); args.LabelString(xmstr); args.PositionIndex(entry->posIndex);//// Add a new button to the manager// Widget pb = mgr->AddButton(entry->name, args); XmStringFree(xmstr); } // End if a button for this entry does not exist//// Update label and position index if button is already present// else { WXmString wstr = (char*)entry->abbrev; XmString xstr = wstr; short posIndex = entry->posIndex; XtVaSetValues(*buttList[index], XmNlabelString, xstr, XmNpositionIndex, posIndex, NULL); } } // End for each used entry//// Update the button placement// XtVaSetValues(mgr->ButtonBox(), BbNuniformCols, sameSize, BbNuniformRows, sameSize, NULL); mgr->SetGravity(gravity);//// Turn on the buttons// mgr->ManageButtons(); } // End for each button manager//// Write to database and file if necessary// Write(); BusyCursor(False); return True;} // End Apply/*--------------------------------------------------------------- * Add a button manager to the list */voidButtPrefWinC::AddManager(ButtonMgrC *mgr){ if ( !buttMgr ) buttMgr = mgr; void *tmp = (void*)mgr; buttMgrList.add(tmp);}/*--------------------------------------------------------------- * Remove a button manager from the list */voidButtPrefWinC::RemoveManager(ButtonMgrC *mgr){ void *tmp = (void*)mgr; buttMgrList.remove(tmp);}/*--------------------------------------------------------------- * Callback to handle selection of available buttons */voidButtPrefWinC::SelectAvail(Widget,ButtPrefWinC *This, XmListCallbackStruct *listData){ XtSetSensitive(This->addAB, listData->selected_item_count > 0);}/*--------------------------------------------------------------- * Callback to handle press of down arrow */voidButtPrefWinC::HandleAdd(Widget, ButtPrefWinC *This, XtPointer){//// Get positions of selected items in available list// int *posList; int posCount; XmListGetSelectedPos(This->availListW, &posList, &posCount); This->AvailToUsed(posList, posCount, 0); XtSetSensitive(This->addAB, False);} // End HandleAdd/*--------------------------------------------------------------- * Callback to handle press of up arrow */voidButtPrefWinC::HandleRem(Widget, ButtPrefWinC *This, XtPointer){//// Get positions of selected items in used list// int *posList; int posCount; XmListGetSelectedPos(This->usedListW, &posList, &posCount); This->UsedToAvail(posList, posCount); XtSetSensitive(This->remAB, False);} // End HandleRem/*--------------------------------------------------------------- * Callback to handle selection of used buttons */voidButtPrefWinC::SelectUsed(Widget, ButtPrefWinC *This, XmListCallbackStruct *listData){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -