1 /* Changes: 2 * 18 Apr 1999: Added changeItem() function. 3 * 13 Feb 2000: Items are represented by winItems i/o charpointers. 4 * 5 */ 6 #ifndef _SCROLLWIN_CLASS_ 7 #define _SCROLLWIN_CLASS_ 8 9 #include "mp3blaster.h" 10 #include NCURSES_HEADER 11 #include "winitem.h" 12 #include "exceptions.h" 13 #include <stdio.h> 14 15 enum sw_searchflags { SW_SEARCH_NONE, SW_SEARCH_CASE_INSENSITIVE }; 16 17 class scrollWin 18 { 19 public: 20 /* Function Name: scrollWin::scrollWin 21 * Description : Creates a new selection-window, setting width and 22 * : height, items in this window, and whether or not the 23 * : entire path to each item should be displayed. 24 * Arguments : sw : selection-window to create 25 * : lines : amount of lines for this window 26 * : ncols : amount of columns for this window 27 * : begin_y : y-coordinate of topleft corner from this window 28 * : : in stdscr. 29 * : begin_x : as begin_y, but now x-coordinate. 30 * : arr : array of strings containing items for this 31 * : : window. May be NULL if narr is 0. 32 * : narr : amount of items. 33 * : color : Default colourpair to use 34 * : x_offset: 1 if window has a (left-)border of 1, 0 otherwise. 35 * Throws : IllegalArgumentsException when size requirements have not 36 * : been met 37 */ 38 scrollWin(int lines, int ncols, int begin_y, int begin_x, char **arr, 39 int narr, short color, short x_offset); 40 41 virtual ~scrollWin(); 42 43 /* Function : resize 44 * Description: Resizes the window 45 * Parameters : width 46 * : new width 47 * : height 48 * : new height 49 * Returns : Nothing. 50 * SideEffects: None. 51 * Throws : IllegalArgumentsException when size requirements have not 52 * : been met 53 */ 54 virtual void resize(int width, int height); 55 56 void changeSelection(int); 57 void invertSelection(); 58 void selectItem(int which = -1); 59 void deselectItem(int); 60 void deselectItems(); //deselect *all* items 61 void selectItems(const char *pattern, const char *type = "regex", 62 sw_searchflags flags = SW_SEARCH_CASE_INSENSITIVE, 63 short display_index = 0); 64 void setTitle(const char*); 65 const char *getTitle(); 66 void swRefresh(short); 67 virtual short addItem(const char*, short status=0, short colour=0, int index=-1, 68 short before=0, void *object=NULL, itemtype type=TEXT); 69 virtual short addItem(const char **, short *, short colour=0, int index=-1, 70 short before=0, void *object=NULL, itemtype type=TEXT); 71 int findItem(const char *, short nameindex = 0); 72 void changeItem(int, const char *, short nameindex=0); 73 void changeItem(int, char *(*)(void *), void *arg=NULL, short nameindex=0); 74 void replaceItem(int, winItem *newitem); 75 void setItem(int); 76 virtual void delItem(int, int del=1); 77 void delItems(); 78 void setBorder(chtype, chtype, chtype, chtype, 79 chtype, chtype, chtype, chtype); 80 void pageDown(); 81 void pageUp(); 82 int isSelected(int); 83 int getNitems(); 84 const char *getSelectedItem(short nameindex=0); 85 char **getSelectedItems(int *itemcount, short nameindex=0); 86 const char *getItem(int index, short name_index=0); 87 char **getItems(short nameindex=0); 88 void dump_contents(); 89 void dump_info(); 90 void setDisplayMode(short mode); getDisplayMode()91 short getDisplayMode() { return dispindex; } 92 void setDefaultColor(short color); 93 short moveItem(int index_from, int index_to, short before=0); 94 short moveSelectedItems(int index_to, short before=0); 95 void clearwin(); 96 void drawBorder(); 97 void drawTitleInBorder(int); itemWidth()98 int itemWidth() { return width - (xoffset ? 2 : 0); } hideScrollbar()99 void hideScrollbar() { hide_bar = 1; } 100 /* setWrap: if enabled, list will wrap at boundaries when moving the 101 * scrollbar with changeSelection */ setWrap(bool want_wrap)102 void setWrap(bool want_wrap) { wrap = (want_wrap ? 1 : 0); } enableScreenUpdates()103 void enableScreenUpdates() { enable_updates = 1; } disableScreenUpdates()104 void disableScreenUpdates() { enable_updates = 0; } 105 int sw_selection; 106 107 /* Added by Douglas Richard <fmluder@imsa.edu> - March 11, 2002 */ 108 void resetPan(); 109 void pan(short); 110 void jumpTop(); 111 void jumpBottom(); 112 /* End Add */ 113 114 protected: 115 void init(int, int, int, int, short, short); 116 short addItem(winItem *newitem, int index=-1, short before=0); 117 winItem *getWinItem(int); 118 winItem **getSelectedWinItems(int*); scrollWin()119 scrollWin() {}; 120 winItem *first, *last; 121 122 private: 123 void checkSize(const int lines, const int ncols, const int x_offset); 124 125 int nitems; 126 int hide_bar; 127 char *sw_title; 128 int nselected; 129 int width; 130 int height; 131 int by, bx; 132 int showpath; 133 int border[8]; 134 int shown_range[2]; 135 char *sw_emptyline; 136 short xoffset; 137 short wrap; 138 short want_border; 139 short max_pan_offset; /* maximum pansize */ 140 short dispindex; //which of the NAMEDIM names of each item to show 141 short colour; //which (global) colourpair to use for drawing items 142 int selectID; //increases after each select, used to sort selected items 143 //in the order they were selected. 144 int draw_title; //1 if title should be drawn in border 145 146 /* enable_updates determines whether functions in this class will call 147 * call swRefresh after altering this window's content. If zero, one 148 * should always call swRefresh(1) after calling a function that messes 149 * with content/layout. Default is to allow updates from within the class. 150 * You might want to disable it temporarily when performing lots of 151 * addItems() in a loop, etc. 152 */ 153 short enable_updates; 154 155 int panoffset; 156 }; 157 158 #endif /* _SCROLLWIN_CLASS_ */ 159