📄 vboxc.c
字号:
if ( realized && view ) { view->PlaceItems(); UpdateScrollBars(); view->Draw(visRect); } SetLabel(totalVal, items.size()); SetLabel(dispVal, visItems.size()); SetLabel(selVal, selItems.size()); if ( selectButton ) XtSetSensitive(selectButton, visItems.size() && (selItems.size() != visItems.size()));} // End Refresh/*---------------------------------------------------------------------- * Set a flag so that routines know that more items are going to be * selected. This keeps work from being repeated and the select change * callbacks from being called too many times. */voidVBoxC::PartialSelect(Boolean on){ if ( on ) { partialSelect++; // Up the count } else if ( partialSelect > 0 ) { partialSelect--; // Lower the count FinishSelect(); // Only does work if partialSelect==0 }} // End PartialSelect/*----------------------------------------------------------------------- * Perform final updates after selection */voidVBoxC::FinishSelect(){//// If there is more to be selected, just return// if ( partialSelect>0 ) return;//// Update the status label// SetLabel(selVal, selItems.size());//// Update the button sensitivities// if ( selectButton ) { XtSetSensitive(selectButton, visItems.size() && (selItems.size() != visItems.size())); XtSetSensitive(deselectButton, selItems.size() > 0 ); }//// Redraw the box box// Refresh();//// Call the selection-change callbacks for view box// CallSelectChangeCallbacks();} // End FinishSelect/*----------------------------------------------------------------------- * Specify a new dialog for the sort function */voidVBoxC::SetSortDialog(HalDialogC *ad){ Boolean shown = False; if ( sortDialog && sortDialog->IsShown() ) { sortDialog->Hide(); shown = True; } sortDialog = ad ? ad : defSortDialog; if ( shown ) ad->Show();} // End SetSortDialog/*----------------------------------------------------------------------- * Specify a new dialog for the filter function */voidVBoxC::SetFilterDialog(HalDialogC *ad){ Boolean shown = False; if ( filtDialog && filtDialog->IsShown() ) { filtDialog->Hide(); shown = True; } filtDialog = ad ? ad : defFiltDialog; if ( shown ) ad->Show();} // End SetFilterDialog/*----------------------------------------------------------------------- * Specify a new dialog for the find function */voidVBoxC::SetFindDialog(HalDialogC *ad){ Boolean shown = False; if ( findDialog && findDialog->IsShown() ) { findDialog->Hide(); shown = True; } findDialog = ad ? ad : defFindDialog; if ( shown ) ad->Show();} // End SetFindDialog/*----------------------------------------------------------------------- * Specify a new comparison function for view items */voidVBoxC::SetCompareFunction(CompareFn comp){ //cout <<"Setting compFunc to " <<(void*)comp <<endl; compFunc = comp;//// Set compare function for view items// unsigned count = items.size(); for (int i=0; i<count; i++) { items[i]->SetCompareFunction(comp); }} // End SetCompareFunction/*----------------------------------------------------------------------- * This method resorts the visible items */voidVBoxC::Sort(){ if ( !compFunc ) return; visItems.sort(compFunc); changed = True;} // End Sort/*----------------------------------------------------------------------- * Change the filter output option */voidVBoxC::FilterOutput(FilterOutputT type){ if ( filterOutput == type ) return; filterOutput = type;} // End FilterOutput/*----------------------------------------------------------------------- * Filter the list */voidVBoxC::Filter(){ if ( !filtFunc ) return;//// See if we're displaying or selecting// if ( filterOutput == DISPLAY_FILTER_OUTPUT ) {//// Pass all items through filter. Create lists of items that need to be// shown and those that need to be hidden// VItemListC showList, hideList; int count = items.size(); for (int i=0; i<count; i++) { VItemC *item = items[i];//// If item passes, make it visible// if ( (*filtFunc)(*item) ) { showList.append(item); } else { hideList.append(item); } } // End for each item//// Update view// DeselectItems(hideList); // Hidden items cannot be selected HideItems(hideList); ShowItems(showList); } // End if display output else /* if ( filterOutput == SELECT_FILTER_OUTPUT ) */ {//// Make all items visible// ShowItems(items);//// Pass all items through filter. Keep a list of items that need to be// selected// VItemListC selList; unsigned count = items.size(); for (int i=0; i<count; i++) { VItemC *item = items[i];//// Apply filter. If item passes, select it.// if ( (*filtFunc)(*item) ) { selList.append(item); } } // End for each view item//// Make selection changes// SelectItemsOnly(selList); } // End if select output} // End Filter/*----------------------------------------------------------------------- * Find the first item that passes the find proc */voidVBoxC::FindFirst(){//// Reset the search position and call FindNext// findPos = 0; FindNext();} // End FindFirst/*----------------------------------------------------------------------- * Find the next item that passes the find proc */voidVBoxC::FindNext(){ if ( !findFunc ) return; unsigned count = visItems.size(); unsigned remaining = count; Boolean found = False; VItemC *item;//// Loop through visible items, starting at the current search pos. Wrap at// the end of the list. Stop when the current pos is reached again.// while ( !found && remaining>0 ) { if(findPos > visItems.size())findPos = 0; item = visItems[findPos]; if ( (*findFunc)(*item) ) { if ( view ) view->FlashItem(item); found = True; }//// Advance to next item// findPos++; if ( findPos >= count ) findPos = 0; remaining--; } // End for each view item} // End FindNext/*----------------------------------------------------------------------- * Change the label string for a view item */voidVBoxC::SetItemLabel(VItemC& item, const char *lab){ item.Label(lab);}/*----------------------------------------------------------------------- * Change the pixmaps for a view item */voidVBoxC::SetItemPixmaps(VItemC& item, const char *lg, const char *sm){ item.SetPixmaps(lg, sm);}voidVBoxC::SetItemPixmaps(VItemC& item, const XbmT *lg, const XbmT *sm){ item.SetPixmaps(lg, sm);}voidVBoxC::SetItemPixmaps(VItemC& item, const XpmT lg, const XpmT sm){ item.SetPixmaps(lg, sm);}/*----------------------------------------------------------------------- * Public method to remove an item from this view box */voidVBoxC::RemoveItem(const char *name){ StringC tname(name); RemoveItem(tname);} // End RemoveItemvoidVBoxC::RemoveItem(const StringC& name){//// Find all items with the given name// VItemListC list; unsigned count = items.size(); for (int i=0; i<count; i++) { VItemC *item = items[i]; if ( item->Name() == name ) { list.append(item); } }//// Remove the matching items// if ( list.size() > 0 ) { RemoveItems(list); }} // End RemoveItemvoidVBoxC::RemoveItem(VItemC& item){ Boolean wasSelected = selItems.includes(&item);//// Remove it from the lists// _RemoveItem(item);//// Remove item from current view// if ( realized && view ) view->RemoveItem(item); if ( wasSelected ) FinishSelect(); changed = True;} // End RemoveItem/*----------------------------------------------------------------------- * Private method to remove an item from this view box */voidVBoxC::_RemoveItem(VItemC& item){ items.remove(&item); visItems.remove(&item); selItems.remove(&item);//// Remove callbacks// item.RemoveFieldChangeCallback ((CallbackFn *)ItemFieldChanged, this); item.RemoveLabelChangeCallback ((CallbackFn *)ItemLabelChanged, this); item.RemovePixmapChangeCallback((CallbackFn *)ItemPixmapChanged, this);} // End _RemoveItem/*----------------------------------------------------------------------- * Remove items from this view box */voidVBoxC::RemoveItems(VItemListC& list){//// Remove items from current view// if ( realized && view ) view->RemoveItems(list);//// Remove items from lists// unsigned selCount = selItems.size(); unsigned count = list.size(); for (int i=count-1; i>=0; i--) { VItemC *item = list[i]; _RemoveItem(*item); } if ( selCount != selItems.size() ) FinishSelect(); changed = True;} // End RemoveItems/*----------------------------------------------------------------------- * Remove all selected items from this view box */voidVBoxC::RemoveSelectedItems(){//// Copy the selected list since it will get modified in the process// Copy it in reverse order so that items will be removed from the end// VItemListC remItems; unsigned count = selItems.size(); for (int i=count-1; i>=0; i--) { remItems.append(selItems[i]); } RemoveItems(remItems);} // End RemoveSelectedItems/*----------------------------------------------------------------------- * Remove all items from this view box */voidVBoxC::RemoveAllItems(){//// Remove items from current view// if ( realized && view ) { view->RemoveItems(items); }//// Remove callbacks// unsigned selCount = selItems.size(); unsigned count = items.size(); for (int i=0; i<count; i++) { VItemC *item = items[i]; item->RemoveFieldChangeCallback ((CallbackFn *)ItemFieldChanged, this); item->RemoveLabelChangeCallback ((CallbackFn *)ItemLabelChanged, this); item->RemovePixmapChangeCallback((CallbackFn *)ItemPixmapChanged, this); }//// Remove items from lists// items.removeAll(); visItems.removeAll(); selItems.removeAll(); if ( selCount ) FinishSelect(); changed = True;} // End RemoveAllItems/*----------------------------------------------------------------------- * Callbacks for sort, filter and find buttons */voidVBoxC::DoSort(Widget, VBoxC *This, XtPointer){ This->sortDialog->Show();}voidVBoxC::DoFilt(Widget, VBoxC *This, XtPointer){ This->filtDialog->Show();}voidVBoxC::DoFind(Widget, VBoxC *This, XtPointer){ This->findDialog->Show();}voidVBoxC::DoMoveJoyStick(void*, VBoxC* This){ int px, py; This->joyStick->GetMovePercentage(&px, &py); int new_x = This->hScrollValue; int new_y = This->vScrollValue; if ( This->hScrollInc > 1 ) { float dx = ((float)px*(float)This->hScrollInc) * 0.01; new_x += (int)(dx+0.5); } else if ( px > 0 ) { new_x += 1; } else if ( px < 0 ) { new_x -= 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -