/*ARGSUSED*/ static void File_ListCB(Widget widget, int data, XtPointer call_data) { XmListCallbackStruct *cbs= (XmListCallbackStruct *) call_data; char *text; int nbvisible, first_visible ; Arg al[10]; int ac; /* First, check that the selected file is really visible in the list */ ac=0; XtSetArg(al[ac],XmNtopItemPosition,&first_visible); ac++; XtSetArg(al[ac],XmNvisibleItemCount,&nbvisible); ac++; XtGetValues(widget, al, ac); if ( ( first_visible > cbs->item_position) || ((first_visible+nbvisible) <= cbs->item_position)) XmListSetPos(widget, cbs->item_position); /* Tell the application to play the requested file */ XmStringGetLtoR(cbs->item,char_set,&text); m_pipe_int_write(MOTIF_PLAY_FILE); m_pipe_string_write(text); file_number_to_play=cbs->item_position; XtFree(text); }
/*********************************************************************** * * * Clear the selector columns. * * * ***********************************************************************/ void clear_selector_columns(int option) { if (selector_dialog) { if (option == 0 || option == 1) { XmListSetPos(var1NtSList, 1); XmListDeselectAllItems(var1NtSList); XmListDeleteAllItems(var1NtSList); XmListSelectPos(var1NtSList, 1, False); } if (option == 0 || option == 2) { XmListSetPos(var2NtSList, 1); XmListDeselectAllItems(var2NtSList); XmListDeleteAllItems(var2NtSList); } } }
void wxListBox::DoSetFirstItem( int N ) { int count, length; if (N < 0) return; XtVaGetValues ((Widget) m_mainWidget, XmNvisibleItemCount, &count, XmNitemCount, &length, NULL); if ((N + count) >= length) N = length - count; XmListSetPos ((Widget) m_mainWidget, N + 1); }
/*********************************************************************** * * * Reset the right list. * * * ***********************************************************************/ static void reset_cb(Widget w, XtPointer cd, XmAnyCallbackStruct *cbs) { int icnt; XmString *items; if (w == deleteNtSButton) { XtVaGetValues(var2NtSList, XmNselectedItemCount, &icnt, XmNselectedItems, &items, NULL); XmListDeleteItems(var2NtSList, items, icnt); } else if (w == resetNtSButton) { XmListSetPos(var2NtSList, 1); XmListDeselectAllItems(var2NtSList); XmListDeleteAllItems(var2NtSList); } }
/*********************************************************************** * * * Show (manage) the column selector dialog. * * * ***********************************************************************/ void show_columnSelector(Widget w, XtPointer cd, XmAnyCallbackStruct *call_data) { MenuCbStruct *scan_button; int icnt; XmString *items; if (!selector_dialog) { selector_dialog = create_columnSelection(w); /* * Install callbacks */ scan_button = make_menuStruct(w, selector_dialog); InstallMwmCloseCallback(XtParent(selector_dialog), (XtCallbackProc)cancel_cb, (XtPointer)scan_button); /* * Install event handler on EnterNotify events */ XtAddEventHandler(XtParent(selector_dialog), EnterWindowMask, False, (XtEventHandler)enter_ntuple_viewer, NULL); XtAddCallback(exprNtSText, XmNactivateCallback, (XtCallbackProc)copy_cb, NULL); XtAddCallback(copyNtSButton, XmNactivateCallback, (XtCallbackProc)copy_cb, NULL); XtAddCallback(copyAllNtSButton, XmNactivateCallback, (XtCallbackProc)copy_cb, NULL); XtAddCallback(var1NtSList, XmNdefaultActionCallback, (XtCallbackProc)copy_cb, NULL); XtAddCallback(scanNtSButton, XmNactivateCallback, (XtCallbackProc)show_ntupleScanner, NULL); XtAddCallback(deleteNtSButton, XmNactivateCallback, (XtCallbackProc)reset_cb, NULL); XtAddCallback(resetNtSButton, XmNactivateCallback, (XtCallbackProc)reset_cb, NULL); XtAddCallback(cancelNtSButton, XmNactivateCallback, (XtCallbackProc)cancel_cb, scan_button); /* store MenuCbSruct in userData */ XtVaSetValues(selector_dialog, XmNuserData, scan_button, NULL); } /* clear left list */ XmListSetPos(var1NtSList, 1); XmListDeselectAllItems(var1NtSList); XmListDeleteAllItems(var1NtSList); /* * Copy var list from ntupleBrowser to left list of columnSelection * dialog. In case there are no variables in the ntupleBrowser return. */ XtVaGetValues(varNtList, XmNitemCount, &icnt, XmNitems, &items, NULL); if (!icnt) return; XmListAddItems(var1NtSList, items, icnt, 1); XmListSelectPos(var1NtSList, 1, False); /* Make scan button on ntupleBrowser insensitive and popup dialog */ XtSetSensitive(w, False); XtManageChild(selector_dialog); }
/*ARGSUSED*/ void _XmCommandUpOrDown( Widget wid, XEvent *event, /* unused */ String *argv, Cardinal *argc ) /* unused */ { XmCommandWidget cmd = (XmCommandWidget) wid ; int visible ; int top ; int key_pressed ; Widget list ; int * position ; int count ; Arg av[5] ; Cardinal ac ; int selected_count ; /****************/ if( !(list = cmd->selection_box.list) ) { return ; } ac = 0 ; XtSetArg( av[ac], XmNitemCount, &count) ; ++ac ; XtSetArg( av[ac], XmNtopItemPosition, &top) ; ++ac ; XtSetArg( av[ac], XmNvisibleItemCount, &visible) ; ++ac ; XtSetArg( av[ac], XmNselectedItemCount, &selected_count); ac++; XtGetValues( (Widget) list, av, ac) ; if( !count || (cmd->command.error && (count <= 2)) ) { return ; } /* * Fix for 5237 - Check the selected_count to ensure that a selection * exists. No items may be selected if the application * has run XmListDeselect* routine. If no items in the * list are selected, set list_selected_item_position to 0. */ if (!selected_count) cmd->selection_box.list_selected_item_position = 0; if (_XmConvertActionParamToRepTypeId((Widget) cmd, XmRID_COMMAND_SELECTION_BOX_UP_OR_DOWN_ACTION_PARAMS, argv[0], True, &key_pressed) == False) { /* We couldn't convert the value. Just assume a value of 0. */ key_pressed = 0; } position = &(cmd->selection_box.list_selected_item_position) ; if( *position == 0 ) { /* If error is visible, select last item - 2. Otherwise, select * last item in list. */ if( cmd->command.error ) { *position = count - 2 ; } else { *position = count ; } XmListSelectPos( list, *position, True) ; } else { if( !key_pressed && (*position > 1) ) { /* up */ XmListDeselectPos( list, *position) ; XmListSelectPos( list, --*position, True) ; } else { if( (key_pressed == 1) && (*position < count) ) { /* down */ XmListDeselectPos( list, *position) ; XmListSelectPos( list, ++*position, True) ; } else { if( key_pressed == 2 ) { /* home */ XmListDeselectPos( list, *position) ; *position = 1 ; XmListSelectPos( list, *position, True) ; } else { if( key_pressed == 3 ) { /* end */ XmListDeselectPos( list, *position) ; *position = count ; XmListSelectPos( list, *position, True) ; } } } } } if( top > *position ) { XmListSetPos( list, *position) ; } else { if( (top + visible) <= *position ) { XmListSetBottomPos( list, *position) ; } } return ; }
void AliasListUiItem::handleAddButtonPress() { char *key_str = NULL; char *value_str = NULL; PropStringPair *new_pair = NULL; XtVaGetValues(key_widget, XmNvalue, &key_str, NULL); XtVaGetValues(value_widget, XmNvalue, &value_str, NULL); if(key_str != NULL) if(strlen(key_str) > 0) { new_pair = new PropStringPair; int *pos_list, num_pos; new_pair->label = strdup(key_str); if(value_str != NULL) new_pair->value = strdup(value_str); else new_pair->value = NULL; if(XmListGetSelectedPos(this->getWidget(), &pos_list, &num_pos)) { if(list_items == NULL) list_items = new DtVirtArray<PropStringPair *>(10); list_items->insert(new_pair,pos_list[0] - 1); XmListAddItem(this->getWidget(), XmStringCreateLocalized( formatPropPair( new_pair->label, new_pair->value)), pos_list[0]); XmListSelectPos(this->getWidget(), pos_list[0], TRUE); XmListSetPos(this->getWidget(), pos_list[0]); } else { if(list_items == NULL) list_items = new DtVirtArray<PropStringPair *>(10); list_items->insert(new_pair,0); XmListAddItem(this->getWidget(), XmStringCreateLocalized( formatPropPair( new_pair->label, new_pair->value)), 1); XmListSelectPos(this->getWidget(), 1, TRUE); XmListSetPos(this->getWidget(), 1); } props_changed = TRUE; } }
/* ** Action procedure for processing characters typed in a list, finds the ** first item matching the characters typed so far. */ static int nKeystrokes = 0; /* Global key stroke history counter */ static void listCharEH(Widget w, XtPointer callData, XEvent *event, Boolean *continueDispatch) { char charString[5], c, *itemString; int nChars, nItems, i, cmp, selectPos, topPos, nVisible; XmString *items; KeySym kSym; char name[MAXPATHLEN], path[MAXPATHLEN]; static char keystrokes[MAX_LIST_KEYSTROKES]; static Time lastKeyTime = 0; /* Get the ascii character code represented by the event */ nChars = XLookupString((XKeyEvent *)event, charString, sizeof(charString), &kSym, NULL); c = charString[0]; /* Process selected control keys, but otherwise ignore the keystroke if it isn't a single printable ascii character */ *continueDispatch = False; if (kSym==XK_BackSpace || kSym==XK_Delete) { nKeystrokes = nKeystrokes > 0 ? nKeystrokes-1 : 0; return; } else if (kSym==XK_Clear || kSym==XK_Cancel || kSym==XK_Break) { nKeystrokes = 0; return; } else if (nChars!=1 || c<0x021 || c>0x07e) { *continueDispatch = True; return; } /* Throw out keystrokes and start keystroke accumulation over from scratch if user waits more than MAX_LIST_KESTROKE_WAIT milliseconds */ if (((XKeyEvent *)event)->time - lastKeyTime > MAX_LIST_KESTROKE_WAIT) nKeystrokes = 0; lastKeyTime = ((XKeyEvent *)event)->time; /* Accumulate the current keystroke, just beep if there are too many */ if (nKeystrokes >= MAX_LIST_KEYSTROKES) XBell(XtDisplay(w), 0); else #ifdef VMS keystrokes[nKeystrokes++] = toupper(c); #else keystrokes[nKeystrokes++] = c; #endif /* Get the items (filenames) in the list widget */ XtVaGetValues(w, XmNitems, &items, XmNitemCount, &nItems, NULL); /* compare them with the accumulated user keystrokes & decide the appropriate line in the list widget to select */ selectPos = 0; for (i=0; i<nItems; i++) { XmStringGetLtoR(items[i], XmSTRING_DEFAULT_CHARSET, &itemString); if (ParseFilename(itemString, name, path) != 0) { XtFree(itemString); return; } XtFree(itemString); cmp = strncmp(name, keystrokes, nKeystrokes); if (cmp == 0) { selectPos = i+1; break; } else if (cmp > 0) { selectPos = i; break; } } /* Make the selection, and make sure it will be visible */ XmListSelectPos(w, selectPos, True); if (selectPos == 0) /* XmListSelectPos curiously returns 0 for last item */ selectPos = nItems + 1; XtVaGetValues(w, XmNtopItemPosition, &topPos, XmNvisibleItemCount, &nVisible, NULL); if (selectPos < topPos) XmListSetPos(w, selectPos-2 > 1 ? selectPos-2 : 1); else if (selectPos > topPos+nVisible-1) XmListSetBottomPos(w, selectPos+2 <= nItems ? selectPos+2 : 0); /* For LessTif 0.89.9. Obsolete now? */ XmListSelectPos(w, selectPos, True); }