/* * Print the tag of a menu-item */ static void print_tag(WINDOW *win, char **items, int choice, int selected) { int my_x = item_x; int my_y = ItemToRow(choice); int tag_width = (my_x - tag_x - GUTTER); const int *cols; const int *indx; int limit; unsigned prefix; cols = dlg_index_columns(ItemName(0)); indx = dlg_index_wchars(ItemName(0)); limit = dlg_count_wchars(ItemName(0)); prefix = indx[1] - indx[0]; /* highlight first char of the tag to be special */ (void) wmove(win, my_y, tag_x); wattrset(win, selected ? tag_key_selected_attr : tag_key_attr); if (strlen(ItemName(0)) != 0) (void) waddnstr(win, ItemName(0), prefix); /* print rest of the string */ wattrset(win, selected ? tag_selected_attr : tag_attr); if (strlen(ItemName(0)) > prefix) { limit = dlg_limit_columns(ItemName(0), tag_width, 1); if (limit > 0) (void) waddnstr(win, ItemName(0) + indx[1], indx[limit] - indx[1]); } }
/** * Get the value of a particular item in the model */ void BOM_TABLE_MODEL::GetValue( wxVariant& aVariant, const wxDataViewItem& aItem, unsigned int aFieldId ) const { auto row = ItemToRow( aItem ); if( row ) { aVariant = row->GetFieldValue( aFieldId ); } }
/** * Returns true if the supplied item has children */ bool BOM_TABLE_MODEL::IsContainer( const wxDataViewItem& aItem ) const { auto row = ItemToRow( aItem ); if( row ) { return row->HasChildren(); } return true; }
bool BOM_TABLE_MODEL::GetAttr( const wxDataViewItem& aItem, unsigned int aFieldId, wxDataViewItemAttr& aAttr ) const { auto row = aItem.IsOk() ? ItemToRow( aItem ) : nullptr; if( row ) { return row->GetAttr( aFieldId, aAttr ); } return false; }
/** * Return the parent item for a given item in the model. * If no parent is found (or the item is invalid) return an invalid item. */ wxDataViewItem BOM_TABLE_MODEL::GetParent( const wxDataViewItem& aItem ) const { auto row = ItemToRow( aItem ); auto parent = row ? row->GetParent() : nullptr; if( parent ) { return RowToItem( parent ); } // Return an invalid item return wxDataViewItem(); }
/* * Print menu item */ static void print_item(WINDOW *win, char **items, int choice, int selected) { int n; int my_width = menu_width; int my_x = item_x; int my_y = ItemToRow(choice); chtype attr = A_NORMAL; if (items == 0) return; /* Clear 'residue' of last item and mark current current item */ if (dialog_vars.input_menu) { wattrset(win, selected ? item_selected_attr : item_attr); for (n = my_y - 1; n < my_y + INPUT_ROWS - 1; n++) { wmove(win, n, 0); wprintw(win, "%*s", my_width, " "); } } else { wattrset(win, menubox_attr); wmove(win, my_y, 0); wprintw(win, "%*s", my_width, " "); } print_tag(win, items, choice, selected); /* Draw the input field box (only for inputmenu) */ (void) wmove(win, my_y, my_x); if (dialog_vars.input_menu) { my_width -= 1; draw_box(win, my_y - 1, my_x, INPUT_ROWS, my_width - my_x - tag_x, selected ? item_selected_attr : item_attr, selected ? item_selected_attr : item_attr); my_width -= 1; ++my_x; } /* print actual item */ wmove(win, my_y, my_x); wattrset(win, selected ? item_selected_attr : item_attr); dlg_print_text(win, ItemText(0), my_width - my_x, &attr); if (selected) { dlg_item_help(ItemHelp(0)); } }
static char * input_menu_edit(WINDOW *win, char **items, int choice) { char *result; int offset = 0; int key = 0, fkey; int first = TRUE; /* see above */ int y = ItemToRow(choice); result = malloc(dialog_vars.max_input); assert_ptr(result, "input_menu_edit"); dialog_vars.max_input = dialog_vars.max_input; /* original item is used to initialize the input string. */ result[0] = '\0'; strcpy(result, ItemText(0)); print_tag(win, items, choice, TRUE); /* taken out of inputbox.c - but somewhat modified */ while (key != '\n' && key != '\r') { if (!first) key = mouse_wgetch(win, &fkey); if (dlg_edit_string(result, &offset, key, fkey, first)) { /* * menu_width - 2 ..... it's the actual number of maximal * possible characters could be written * to the screen. * * item_x - tag_x - 2 . same as "name_width" * ( see in dialog_menu() ) */ dlg_show_string(win, result, offset, item_selected_attr, y, item_x + 1, menu_width - item_x - 3, FALSE, first); first = FALSE; } } return result; }
/** * Push all children of the supplied item into the list * If the supplied item is invalid, push all the top-level items */ unsigned int BOM_TABLE_MODEL::GetChildren( const wxDataViewItem& aItem, wxDataViewItemArray& aChildren ) const { auto row = aItem.IsOk() ? ItemToRow( aItem ) : nullptr; // Valid row, return its children if( row ) { return row->GetChildren( aChildren ); } else { for( auto& group : Groups ) { aChildren.Add( RowToItem( &*group ) ); } return aChildren.size(); } }
/** * Custom comparison function for improved column sorting * Alphanumeric sorting is not sufficient for correct ordering of some fields * Some columns are sorted numerically, others with more complex rules. */ int BOM_TABLE_MODEL::Compare( const wxDataViewItem& aItem1, const wxDataViewItem& aItem2, unsigned int aColumnId, bool aAscending ) const { if( !aItem1.IsOk() || !aItem2.IsOk() ) return 0; int result = 0; auto row1 = ItemToRow( aItem1 ); auto row2 = ItemToRow( aItem2 ); if( !row1 || !row2 ) return 0; if( row1->GetParent() != row2->GetParent() ) return 0; wxString strVal1 = row1->GetFieldValue( aColumnId ); wxString strVal2 = row2->GetFieldValue( aColumnId ); long numVal1; long numVal2; switch( aColumnId ) { // Reference column sorted by reference val case BOM_COL_ID_REFERENCE: result = BOM_TABLE_GROUP::SortReferences( strVal1, strVal2 ); break; case BOM_COL_ID_VALUE: result = BOM_TABLE_GROUP::SortValues( strVal1, strVal2 ); break; // These columns are sorted numerically case BOM_COL_ID_QUANTITY: if( strVal1.ToLong( &numVal1 ) && strVal2.ToLong( &numVal2 ) ) { result = numVal1 - numVal2; } else { result = strVal1.Cmp( strVal2 ); } break; default: // Default comparison (no special case) result = strVal1.Cmp( strVal2 ); break; } // If initial sorting failed, sort secondly by reference if( result == 0 && aColumnId != BOM_COL_ID_REFERENCE ) { result = BOM_TABLE_GROUP::SortReferences( row1->GetFieldValue( BOM_COL_ID_REFERENCE ), row2->GetFieldValue( BOM_COL_ID_REFERENCE ) ); } // If sorting still failed, sort thirdly by value if( result == 0 && aColumnId != BOM_COL_ID_VALUE ) { result = BOM_TABLE_GROUP::SortValues( row1->GetFieldValue( BOM_COL_ID_VALUE ), row2->GetFieldValue( BOM_COL_ID_VALUE ) ); } if( !aAscending ) { result *= -1; } return result; }