📄 buttprefwinc.c
字号:
XtSetSensitive(This->remAB, listData->selected_item_count > 0);}/*--------------------------------------------------------------- * Callback to handle edit of a used button */voidButtPrefWinC::HandleEdit(Widget, ButtPrefWinC *This, XmListCallbackStruct *listData){ if ( !This->editWin ) { This->editWin = new ButtonEditWinC(*This); This->editWin->AddApplyCallback((CallbackFn*)ApplyEdit, This); } This->editEntry = This->usedList[listData->item_position-1]; This->saveEntry = *This->editEntry; This->editWin->Show(This->editEntry);} // End HandleEdit/*--------------------------------------------------------------- * Callback to apply of button edit */voidButtPrefWinC::ApplyEdit(ButtonEditWinC*, ButtPrefWinC *This){//// See if the abbreviation has changed// if ( This->editEntry->abbrev != This->saveEntry.abbrev ) { WXmString wstr = (char*)This->editEntry->abbrev; XmString xstr = wstr; int oldIndex = This->usedList.indexOf(This->editEntry); XmListReplaceItemsPos(This->usedListW, &xstr, 1, oldIndex+1); }//// See if the position index has changed// if ( This->editEntry->posIndex > This->usedList.size() ) This->editEntry->posIndex = This->usedList.size(); if ( This->editEntry->posIndex < 1 ) This->editEntry->posIndex = 1; if ( This->editEntry->posIndex != This->saveEntry.posIndex ) { int oldIndex = This->usedList.indexOf(This->editEntry); This->usedList.remove(oldIndex); XmListDeletePos(This->usedListW, oldIndex+1); This->usedList.insert(This->editEntry, This->editEntry->posIndex-1); WXmString wstr = (char*)This->editEntry->abbrev; XmListAddItem(This->usedListW, wstr, This->editEntry->posIndex);//// Update position indexes after the one that changed// int start = This->editEntry->posIndex; int count = This->usedList.size(); for (int i=start; i<count; i++) { ButtonEntryC *entry = This->usedList[i]; entry->posIndex = i+1; } } int itemCount; XtVaGetValues(This->usedListW, XmNselectedItemCount, &itemCount, NULL); XtSetSensitive(This->remAB, itemCount>0); This->saveEntry = *This->editEntry;} // End ApplyEdit/*----------------------------------------------------------------------- * Handle drop event in used list */voidButtPrefWinC::HandleDrop(Widget w, XtPointer, XmDropProcCallbackStruct *dp){ WArgList args;//// See if this is a valid drop// unsigned char status = XmTRANSFER_FAILURE; if ( dp->dropSiteStatus == XmVALID_DROP_SITE ) {//// See what was dropped// Atom *expAtoms; Cardinal atomCount; XtVaGetValues(dp->dragContext, XmNexportTargets, &expAtoms, XmNnumExportTargets, &atomCount, NULL); if ( atomCount > 0 ) { Atom textAtom = XmInternAtom(halApp->display, "COMPOUND_TEXT", False); if ( expAtoms[0] == textAtom ) {//// Get the window pointer// ButtPrefWinC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->dropY = dp->y; XmDropTransferEntryRec transferEntries[1]; XmDropTransferEntry transferList; transferEntries[0].target = textAtom; transferEntries[0].client_data = (XtPointer)w; transferList = transferEntries; args.DropTransfers(transferList); args.NumDropTransfers(1); args.TransferProc((XtSelectionCallbackProc)FinishDrop); status = XmTRANSFER_SUCCESS; } } // End if there are dropped atoms } // End if this is a valid drop site//// Drop must be acknowledged// args.TransferStatus(status); XmDropTransferStart(dp->dragContext, ARGS);} // End HandleDrop/*----------------------------------------------------------------------- * Handle drop event */voidButtPrefWinC::FinishDrop(Widget, Widget dropListW, Atom*, Atom*, XtPointer value, unsigned long *len, int){//// Get the window pointer// ButtPrefWinC *This; XtVaGetValues(dropListW, XmNuserData, &This, NULL);//// Find the source positions of the items that were dropped// IntListC posList; Widget dragListW; This->GetDragPositions(value, *len, &dragListW, posList);//// See which list we're dropping in// if ( dropListW == This->usedListW ) {//// Find the position of the drop// int dropPos = XmListYToPos(dropListW, This->dropY); if ( debuglev > 1 ) cout <<posList.size() <<" items dropped on used list at position " <<dropPos <<endl; if ( dragListW == This->usedListW ) This->UsedToUsed(posList.start(), posList.size(), dropPos); else This->AvailToUsed(posList.start(), posList.size(), dropPos); } else if ( dragListW == This->usedListW ) { if ( debuglev > 1 ) cout <<posList.size() <<" items dropped on available list" <<endl; This->UsedToAvail(posList.start(), posList.size()); }//// Update arrow button sensitivities// int count; XtVaGetValues(This->availListW, XmNselectedItemCount, &count, NULL); XtSetSensitive(This->addAB, count>0); XtVaGetValues(This->usedListW, XmNselectedItemCount, &count, NULL); XtSetSensitive(This->remAB, count>0);} // End FinishDrop/*----------------------------------------------------------------------- * Method to return the button entry with the given real widget */intButtPrefWinC::EntryIndex(ButtonEntryListC& list, const char *name){ unsigned count = list.size(); for (int i=0; i<count; i++) { ButtonEntryC *entry = list[i]; if ( entry && entry->name == name ) return i; } return list.NULL_INDEX;}/*--------------------------------------------------------------- * Method to move one or more entries from the available list to * the used list. */voidButtPrefWinC::AvailToUsed(int *srcList, int srcCount, int dstPos){//// Loop through source items// WXmString wstr; ButtonEntryC *entry; int i; for (i=0; i<srcCount; i++) { int srcPos = srcList[i]; entry = availList[srcPos-1];//// Add item to used list widget// wstr = entry->abbrev; XmListAddItem(usedListW, wstr, dstPos);//// Add entry to used list// if ( dstPos == 0 ) usedList.add(entry); else { usedList.insert(entry, dstPos-1); dstPos++; } availList.replace(NULL, srcPos-1); } // End for each moved entry//// Remove the entries from the available list// availList.removeNulls(); XmListDeletePositions(availListW, srcList, srcCount);//// Update positions in the used list// u_int count = usedList.size(); for (i=0; i<count; i++) { entry = usedList[i]; entry->posIndex = i+1; }} // End AvailToUsed/*--------------------------------------------------------------- * Method to move one or more entries from the used list to * the available list. */voidButtPrefWinC::UsedToAvail(int *srcList, int srcCount){//// Add items to the available list// ButtonEntryC *entry; int srcPos; int i; for (i=0; i<srcCount; i++) { srcPos = srcList[i]; entry = usedList[srcPos-1]; availList.add(entry); }//// Sort the available list// availList.sort(SortByLabel);//// Add items to available list widget// WXmString wstr; for (i=0; i<srcCount; i++) { srcPos = srcList[i]; entry = usedList[srcPos-1]; int index = availList.indexOf(entry); wstr = (char*)entry->label; XmListAddItem(availListW, wstr, index+1);//// Remove entry from used list// entry->posIndex = 1; usedList.replace(NULL, srcPos-1); } // End for each selected item//// Remove the entries from the used list// usedList.removeNulls(); XmListDeletePositions(usedListW, srcList, srcCount);//// Update positions in the used list// u_int count = usedList.size(); for (i=0; i<count; i++) { entry = usedList[i]; entry->posIndex = i+1; }} // UsedToAvail/*--------------------------------------------------------------- * Method to move one or more entries to another location in the * used list. */voidButtPrefWinC::UsedToUsed(int *srcList, int srcCount, int dstPos){ if ( srcCount <= 0 || srcList[0] == dstPos ) return;//// Remove all entries from their old positions// ButtonEntryListC moveList; ButtonEntryC *entry; int i; for (i=0; i<srcCount; i++) { int srcPos = srcList[i]; entry = usedList[srcPos-1]; usedList.replace(NULL, srcPos-1); moveList.add(entry); } // End for each moved entry//// Add entries in new positions// WXmString wstr; u_int count = moveList.size(); for (i=0; i<count; i++) { entry = moveList[i]; wstr = (char*)entry->abbrev; XmListAddItem(usedListW, wstr, dstPos); if ( dstPos == 0 ) { usedList.add(entry); } else { usedList.insert(entry, dstPos-1); dstPos++; } }//// Find new positions of null entries// count = usedList.size(); int index = 0; for (i=0; i<count; i++) { if ( usedList[i] == NULL ) srcList[index++] = i+1; }//// Finally remove nulls and update screen// usedList.removeNulls(); XmListDeletePositions(usedListW, srcList, srcCount);//// Update position indexes// count = usedList.size(); for (i=0; i<count; i++) { entry = usedList[i]; entry->posIndex = i+1; }} // End UsedToUsed/*--------------------------------------------------------------- * Method to loop through the compound text input (a list of names) * and return the source list positions of the names. */voidButtPrefWinC::GetDragPositions(XtPointer value, u_long len, Widget *dragListW, IntListC& posList){//// Get the string that was dropped// StringC str; StringListC nameList; StringC name; WXmString wstr; XctData ctData = XctCreate((XctString)value, (int)len, 0); XctResult result; while ( (result=XctNextItem(ctData)) != XctError && result != XctEndOfText ) { if ( result != XctSegment ) continue; str.Set((char*)ctData->item, ctData->item_length);//// Build a list of names// char *namep = strtok(str, "\n"); if ( namep ) { while ( namep ) { name = namep; nameList.add(name); namep = strtok(NULL, "\n"); } } else { nameList.add(str); }//// Loop through names// u_int count = nameList.size(); for (int i=0; i<count; i++) { name = *nameList[i]; wstr = (char*)name; int pos = XmListItemPos(usedListW, wstr); if ( pos > 0 ) { posList.add(pos); *dragListW = usedListW; } else { *dragListW = availListW; pos = XmListItemPos(availListW, wstr); if ( pos > 0 ) posList.add(pos); } } } // End while more compound text XctFree(ctData);} // End GetDragPositions
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -