listwnd.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. #ifndef _LISTWND_H
  2. #define _LISTWND_H
  3. #include <api/wnd/wndclass/scbkgwnd.h>
  4. #include <bfc/common.h>
  5. #include <bfc/freelist.h>
  6. #include "SelItemList.h"
  7. #define POS_LAST -1
  8. #define LISTWND_PARENT ScrlBkgWnd
  9. #define LW_HT_DONTKNOW (-1)
  10. #define LW_HT_ABOVE (-10)
  11. #define LW_HT_BELOW (-20)
  12. #define COL_LEFTALIGN 0
  13. #define COL_CENTERALIGN 1
  14. #define COL_RIGHTALIGN 2
  15. class listItem;
  16. class ListWnd;
  17. class CompareListItem;
  18. class ListColumn : public NamedW
  19. {
  20. friend class ListWnd;
  21. public:
  22. ListColumn(const wchar_t *name=NULL, int isdynamic=FALSE);
  23. virtual ~ListColumn() { }
  24. int getWidth();
  25. void setWidth(int newwidth);
  26. const wchar_t *getLabel();
  27. void setLabel(const wchar_t *newlabel);
  28. virtual int customDrawHeader(Canvas *c, RECT *cr, const Wasabi::FontInfo *fontInfo);
  29. virtual int onHeaderClick() { return 0; }//return 1 if you override
  30. virtual int onColumnLeftClick(int pos) { return 0; }//return 1 if you override
  31. int getNumeric() { return numeric; }
  32. void setDynamic(int isdynamic);
  33. int isDynamic() { return dynamic; }
  34. void setAlignment(int _align) { align = _align; }
  35. int getAlignment() { return align; }
  36. protected:
  37. void setIndex(int i);
  38. int getIndex();
  39. void setList(ListWnd *list);
  40. ListWnd *getList();
  41. void setNumeric(int n) { numeric=n; }
  42. private:
  43. int width;
  44. int index;
  45. int numeric;
  46. int dynamic;
  47. ListWnd *list;
  48. int align;
  49. };
  50. //class SelItemList;
  51. class ListWnd : public ScrlBkgWnd
  52. {
  53. friend class ListColumn;
  54. friend class SelItemList;
  55. public:
  56. ListWnd();
  57. virtual ~ListWnd();
  58. virtual int onInit();
  59. virtual int onPostOnInit();
  60. virtual int onPaint(Canvas *canvas);
  61. virtual int onResize();
  62. virtual int onLeftButtonDown(int x, int y);
  63. virtual int onLeftButtonUp(int x, int y);
  64. virtual int onRightButtonDown(int x, int y);
  65. virtual int onRightButtonUp(int x, int y);
  66. virtual int onMouseMove(int x, int y);
  67. virtual int onLeftButtonDblClk(int x, int y);
  68. virtual int onChar(unsigned int c);
  69. virtual int onKeyDown(int keyCode);
  70. virtual int onContextMenu (int x, int y);
  71. virtual int wantAutoContextMenu();
  72. virtual int onMouseWheelUp(int click, int lines);
  73. virtual int onMouseWheelDown(int click, int lines);
  74. virtual int wantAutoDeselect() { return wantautodeselect; }
  75. virtual void setWantAutoDeselect(int want) { wantautodeselect = want; }
  76. void onSetVisible(int show);
  77. void setAutoSort(bool dosort);
  78. void setOwnerDraw(bool doownerdraw);
  79. virtual void timerCallback(int id);
  80. void next(int wantcb=1);
  81. void selectCurrent();
  82. void selectFirstEntry(int wantcb=1);
  83. void previous(int wantcb=1);
  84. void pagedown(int wantcb=1);
  85. void pageup(int wantcb=1);
  86. void home(int wantcb=1);
  87. void end(int wantcb=1);
  88. void setItemCount(int c);
  89. void reset();
  90. void setShowColumnsHeaders(int show);
  91. int addColumn(const wchar_t *name, int width, int numeric=0, int align=COL_LEFTALIGN); // adds to end
  92. ListColumn *getColumn(int n);
  93. int getNumColumns();
  94. int getColumnWidth(int col);
  95. bool setRedraw(bool redraw); // returns prev state
  96. bool getRedraw();
  97. void setMinimumSize(int size);
  98. virtual int addItem(const wchar_t *label, LPARAM lParam);
  99. virtual int insertItem(int pos, const wchar_t *label, LPARAM lParam);
  100. virtual int getLastAddedItemPos();
  101. virtual void setSubItem(int pos, int subpos, const wchar_t *txt);
  102. virtual void deleteAllItems();
  103. virtual int deleteByPos(int pos);
  104. int getNumItems(void);
  105. virtual int getItemLabel(int pos, int subpos, wchar_t *text, int textmax);
  106. virtual void setItemLabel(int pos, const wchar_t *text);
  107. virtual LPARAM getItemData(int pos);
  108. virtual int getItemRect(int pos, RECT *r);
  109. virtual int getItemSelected(int pos); // returns 1 if selected
  110. virtual int getItemFocused(int pos); // returns 1 if focused
  111. virtual int getItemFocused(); // returns focused item
  112. void setItemFocused(int pos, int ensure_visible=TRUE);
  113. void ensureItemVisible(int pos);
  114. void invalidateColumns();
  115. virtual int scrollAbsolute(int x);
  116. virtual int scrollRelative(int x);
  117. virtual void scrollLeft(int lines=1);
  118. virtual void scrollRight(int lines=1);
  119. virtual void scrollUp(int lines=1);
  120. virtual void scrollDown(int lines=1);
  121. virtual const wchar_t *getSubitemText(int pos, int subpos);
  122. int getFirstItemSelected();
  123. int getNextItemSelected(int lastpos); // next item AFTER given pos
  124. virtual int selectAll(int cb=1); // force all items selected
  125. virtual int deselectAll(int cb=1); // force all items to be deselected
  126. virtual int invertSelection(int cb=1); // invert all selections
  127. virtual int hitTest(POINT pos, int drag=0);
  128. /**
  129. Method
  130. @see
  131. @ret
  132. */
  133. virtual int hitTest(int x, int y, int drag=0);
  134. /**
  135. Method
  136. @see
  137. @ret
  138. */
  139. virtual int invalidateItem(int pos);
  140. virtual int locateData(LPARAM data);
  141. // -1 if we've never been drawn yet
  142. /**
  143. Method
  144. @see
  145. @ret
  146. */
  147. int getFirstItemVisible() const { return firstItemVisible; }
  148. /**
  149. Method
  150. @see
  151. @ret
  152. */
  153. int getLastItemVisible() const { return lastItemVisible; }
  154. virtual int setFontSize(int size);
  155. virtual int getFontSize();
  156. virtual void jumpToNext(wchar_t c);
  157. int wantFocus() { return 1; }
  158. void scrollToItem(int pos);
  159. virtual void resort();
  160. int getSortDirection();
  161. /**
  162. Method
  163. @see
  164. @ret
  165. */
  166. int getSortColumn();
  167. void setSortColumn(int col);
  168. void setSortDirection(int dir);
  169. int findItemByParam(LPARAM param);
  170. void setItemParam(int pos, LPARAM param);
  171. int getItemCount() { return getNumItems(); }
  172. void setSelectionStart(int pos, int wantcb=1);
  173. /**
  174. Method
  175. @see
  176. @ret
  177. */
  178. virtual void setSelectionEnd(int pos);
  179. void setSelected(int pos, int selected, int cb=1);
  180. void toggleSelection(int pos, int setfocus=TRUE, int cb=1);
  181. virtual int getHeaderHeight();
  182. // this sort function just provides string/numeric comparison
  183. // if you need more types, just override and provide your own
  184. virtual int sortCompareItem(listItem *p1, listItem *p2);
  185. int getPreventMultipleSelection() { return preventMultipleSelection; }
  186. int setPreventMultipleSelection(int val) { return preventMultipleSelection = val; }
  187. void moveItem(int from, int to);
  188. virtual int onAcceleratorEvent(const wchar_t *name);
  189. // override this to turn the LPARAM into a text
  190. virtual const wchar_t *convertlParam(LPARAM lParam) { return NULL; }
  191. virtual void convertlParamColumn(int col, int pos, LPARAM param, wchar_t *str, int maxlen) { };
  192. protected:
  193. /*static */void CreateXMLParameters(int master_handle);
  194. // return 1 if you override this
  195. virtual int ownerDraw(Canvas *canvas, int pos, RECT *r, LPARAM lParam, int selected, int focused) { return 0; };
  196. virtual void onPreItemDraw(Canvas *canvas, int pos, RECT *r, LPARAM lParam, int selected, int focused) { }
  197. virtual void onPostItemDraw(Canvas *canvas, int pos, RECT *r, LPARAM lParam, int selected, int focused) { };
  198. virtual ARGB32 getTextColor(LPARAM lParam);
  199. int getTextAntialias(LPARAM lParam) { return antialias; }
  200. virtual int getTextBold(LPARAM lParam) { return 0; }
  201. virtual int getTextItalic(LPARAM lParam) { return 0; }
  202. virtual ARGB32 getSelBgColor(LPARAM lParam);
  203. virtual ARGB32 getSelFgColor(LPARAM lParam);
  204. virtual ARGB32 getBgColor();
  205. virtual ARGB32 getFocusColor(LPARAM lParam);
  206. virtual ARGB32 getFocusRectColor(LPARAM lParam);
  207. virtual int needFocusRect(LPARAM lParam) { return 0; }
  208. virtual ARGB32 getColumnSepColor();
  209. virtual int wantColSepOnItems();
  210. virtual int getXShift();
  211. public:
  212. int insertColumn(ListColumn *col, int pos=-1, int alignment=COL_LEFTALIGN);// -1 is add to end
  213. // void deleteColumn(int pos);
  214. void deleteAllColumns();
  215. void setHoverSelect(int a) { hoverselect = a; }
  216. int getHoverSelect() { return hoverselect; }
  217. void setSelectOnUpDown(int i) { selectonupdown = i; }
  218. int getSelectOnUpDown() { return selectonupdown; }
  219. virtual int onAction(const wchar_t *action, const wchar_t *param=NULL, int x=-1, int y=-1, intptr_t p1=0, intptr_t p2=0, void *data=NULL, size_t datalen=0, ifc_window *source=NULL);
  220. /**
  221. Method
  222. Will only work with simple text lists, be forwarned!!!
  223. @see
  224. @ret
  225. */
  226. int getItemHeight();
  227. void setItemHeight(int height, bool forceInvalidate = true);
  228. int getIconWidth();
  229. void setIconWidth(int width);
  230. int getIconHeight();
  231. void setIconHeight(int height);
  232. protected:
  233. virtual int getColumnsHeight();
  234. virtual int getColumnsWidth();
  235. virtual int getContentsWidth();
  236. virtual int getContentsHeight();
  237. virtual void drawBackground(Canvas *canvas);
  238. void drawColumnHeaders(Canvas *c);
  239. void drawItems(Canvas *canvas);
  240. void updateScrollX();
  241. void updateScrollY();
  242. int doJumpToNext(wchar_t c, bool fromTop);
  243. int fullyVisible(int pos);
  244. virtual int onBeginDrag(int iItem);
  245. virtual int dragOver(int x, int y, ifc_window *sourceWnd);
  246. virtual void onSelectAll(); // hit Control-A
  247. virtual void onDelete(); // hit 'delete'
  248. virtual void onItemDelete(LPARAM lparam) {}
  249. virtual void onDoubleClick(int itemnum); // double-click on an item
  250. // this is called with the selected item#
  251. virtual void onLeftClick(int itemnum); // left-click
  252. // the second time you click on an already-focused item
  253. virtual void onSecondLeftClick(int itemnum);
  254. // this is called once for the item under cursor on click
  255. virtual int onRightClick(int itemnum); // right-click on item
  256. virtual int onIconLeftClick(int itemnum, int x, int y); // Returns 1 if we should not invoke onLeftClick()
  257. // override this to be notified of item selections & deselections
  258. virtual void onItemSelection(int itemnum, int selected);
  259. virtual int onColumnDblClick(int col, int x, int y) { return 0; }
  260. virtual int onColumnLabelClick(int col, int x, int y);
  261. void selectRect(int x1, int y1, int x2, int y2);
  262. void drawRect(int x1, int y1, int x2, int y2);
  263. // interface to Freelist
  264. listItem *createListItem();
  265. void deleteListItem(listItem *item);
  266. ListColumn *enumListColumn(int pos);
  267. int getColumnPosByName(const wchar_t *name);
  268. int delColumnByPos(int pos);
  269. public: // Martin> dunno why these were protected...
  270. void setShowIcons(int icons);
  271. int getShowIcons(); // Maybe useful or not
  272. SkinBitmap *getItemIcon(int item);
  273. void setItemIcon(int pos, const wchar_t *bitmapid);
  274. protected:
  275. int item_invalidate_border;
  276. bool showColumnsHeaders;
  277. void recalcHeaders();
  278. void itemSelection(int itemnum, int selected);
  279. private:
  280. int doAddItem(const wchar_t *label, LPARAM lParam, int pos);
  281. int hitTestColumns(POINT p, int *origin=NULL);
  282. int hitTestColumnClient(int x);
  283. int hitTestColumnsLabel(POINT p);
  284. void drawXorLine(int x);
  285. void calcNewColWidth(int col, int x);
  286. void calcBounds();
  287. void onDragTimer();
  288. void notifySelChanged(int item=-1, int sel=-1);
  289. virtual int wantResizeCols() { return 1; }
  290. int autosort, ownerdraw;
  291. int textsize;
  292. int itemHeight;
  293. int iconWidth; // If it's still negative use itemHeight instead -- better user getIconWidth()
  294. int iconHeight;
  295. bool metrics_ok;
  296. bool redraw;
  297. int columnsHeight;
  298. int dragtimeron;
  299. int antialias;
  300. PtrList<ListColumn> columnsList;
  301. PtrListQuickSorted<listItem,CompareListItem> itemList;
  302. int firstItemVisible;
  303. int lastItemVisible;
  304. listItem *lastItemFocused;
  305. int lastItemFocusedPos;
  306. listItem *lastAddedItem;
  307. SelItemList selItemList;
  308. int dragskip;
  309. int dragskipcount;
  310. int selectionStart;
  311. int colresize;
  312. POINT colresizept;
  313. bool resizing_col;
  314. int colresizeo;
  315. bool processbup;
  316. bool bdown;
  317. bool nodrag;
  318. int bdownx, bdowny;
  319. bool firstComplete, lastComplete;
  320. int rectselecting;
  321. POINT selectStart;
  322. POINT selectLast;
  323. int sortdir, sortcol, lastcolsort;
  324. int preventMultipleSelection;
  325. Freelist<listItem> listItem_freelist;
  326. int wantautodeselect;
  327. int hoverselect;
  328. int selectonupdown;
  329. PtrList<ifc_window> tempselectnotifies;
  330. StringW accessibleItemName;
  331. int showicons;
  332. private:
  333. /* XML Parameters */
  334. static XMLParamPair params[];
  335. int xuihandle;
  336. bool hasUserBg;
  337. enum
  338. {
  339. LIST_ANTIALIAS = 0,
  340. LIST_BACKGROUND,
  341. LIST_TILE,
  342. LIST_NOCOLHEADER,
  343. };
  344. protected:
  345. int setXuiParam(int xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *value);
  346. };
  347. #endif