itemlistwnd.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. //PORTABLE
  2. #ifndef _ITEMLIST_H
  3. #define _ITEMLIST_H
  4. #include "listwnd.h"
  5. #include "../canvas.h"
  6. #include "../named.h"
  7. #include "../ptrlist.h"
  8. #include "../string.h"
  9. #include "../../studio/metacb.h"
  10. class FilenameNC;
  11. class DragItemI;
  12. class ContextMenu;
  13. // this class just handles rendering the various properties of playitems
  14. // in a listwnd... the rest is up to you, just override the convert fn
  15. // abstract base class to render something in a column for a playstring
  16. /**
  17. Class
  18. @short
  19. @author Nullsoft
  20. @ver 1.0
  21. @see
  22. */
  23. class NOVTABLE ItemListColumn : public ListColumn {
  24. protected:
  25. /**
  26. Method
  27. @see
  28. @ret
  29. @param
  30. */
  31. ItemListColumn(const wchar_t *name=NULL) : ListColumn(name) {}
  32. public:
  33. /**
  34. Method
  35. @see
  36. @ret
  37. @param
  38. */
  39. virtual ~ItemListColumn() {}
  40. /**
  41. Method
  42. @see
  43. @ret
  44. @param
  45. */
  46. virtual void render(int pos, const wchar_t *playstring, Canvas &c, RECT &r)=0;
  47. /**
  48. Method
  49. @see
  50. @ret
  51. @param
  52. */
  53. virtual void columnToText(int pos, const wchar_t *playstring, wchar_t *str, int maxlen)=0;
  54. };
  55. #define ITEMLISTWND_PARENT ListWnd
  56. /**
  57. Class
  58. @short
  59. @author Nullsoft
  60. @ver 1.0
  61. @see
  62. */
  63. class ItemListWnd : public ListWnd, private MetaCallbackI {
  64. friend class ItemListColumn_Callback;
  65. public:
  66. /**
  67. Method
  68. @see
  69. @ret
  70. @param
  71. */
  72. ItemListWnd();
  73. /**
  74. Method
  75. @see
  76. @ret
  77. @param
  78. */
  79. virtual ~ItemListWnd();
  80. /**
  81. Method
  82. @see
  83. @ret
  84. @param
  85. */
  86. virtual int onInit();
  87. /**
  88. Method
  89. @see
  90. @ret
  91. @param
  92. */
  93. int insertColumn(ItemListColumn *column, int width, int pos=-1);
  94. protected:
  95. // override and return 0 to suppress auto-dragging from window
  96. /**
  97. Method
  98. @see
  99. @ret
  100. @param
  101. */
  102. virtual int wantAutoDrag() { return 1; }
  103. // handles auto-adding all selected rows and calls addDragTypes
  104. // so you can add more via addDragItem()
  105. /**
  106. Method
  107. @see
  108. @ret
  109. @param
  110. */
  111. virtual int onBeginDrag(int);
  112. // if you return 0, the Filename version will be auto-added, otherwise not
  113. /**
  114. Method
  115. @see
  116. @ret
  117. @param
  118. */
  119. virtual int addMoreDragTypes(int pos) { return 0; }
  120. /**
  121. Method
  122. @see
  123. @ret
  124. @param
  125. */
  126. virtual int dragComplete(int success);
  127. // tell ListWnd we do our own drawing
  128. /**
  129. Method
  130. @see
  131. @ret
  132. @param
  133. */
  134. virtual int ownerDraw(Canvas *canvas, int pos, RECT *r, LPARAM lParam, int isselected, int isfocused);
  135. // ItemListColumn_Callback calls this to do its rendering, lParam is what you
  136. // gave it to pass back to you
  137. /**
  138. Method
  139. @see
  140. @ret
  141. @param
  142. */
  143. virtual void userRender(int pos, const wchar_t *playstring, Canvas &c, RECT &r, LPARAM lParam) {}
  144. // ItemListColumn_Callback calls this to get the column text, lParam is what you
  145. // gave it to pass back to you
  146. /**
  147. Method
  148. @see
  149. @ret
  150. @param
  151. */
  152. virtual void userColumnToText(int pos, const wchar_t *playstring, LPARAM lParam, wchar_t *str, int maxlen) {}
  153. // override this to turn the ownerdraw into a playstring
  154. virtual const wchar_t *convertlParam(LPARAM lParam)=0;
  155. virtual void convertlParamColumn(int col, int pos, LPARAM lParam, wchar_t *str, int maxlen);
  156. // override this and return 1 if you want a "current" box around item
  157. /**
  158. Method
  159. @see
  160. @ret
  161. @param
  162. */
  163. virtual int getSelected(LPARAM lParam) { return 0; }
  164. // virtual int onRightClick(int itemnum, int x, int y);
  165. // automatically generated context menu (uses Filename)
  166. /**
  167. Method
  168. @see
  169. @ret
  170. @param
  171. */
  172. virtual int onContextMenu(int x, int y);
  173. // return optional DragItemI for context menu (will be deleted for you)
  174. virtual DragItemI *itemlistwnd_getDragItem(int x, int y) { return NULL; }
  175. virtual DragItemI *itemlistwnd_getSecondDragItem(int n) { return NULL; }
  176. virtual void itemlistwnd_addCustomContextMenuCommands(ContextMenu *cm) { }
  177. virtual void itemlistwnd_contextMenuResult(int res) { }
  178. // return TRUE if it's ok to edit in place
  179. /**
  180. Method
  181. @see
  182. @ret
  183. @param
  184. */
  185. virtual int allowEdition(const wchar_t *playstring, wchar_t *field) { return 0; }
  186. /**
  187. Method
  188. @see
  189. @ret
  190. @param
  191. */
  192. virtual void resort() {
  193. //TODO> implement me!
  194. }
  195. protected:
  196. // implement this if you want to know when an item's metadata changed
  197. /**
  198. Method
  199. @see
  200. @ret
  201. @param
  202. */
  203. virtual void onItemChange(int pos, const wchar_t *playstring) { }
  204. /**
  205. Method
  206. @see
  207. @ret
  208. @param
  209. */
  210. virtual void onItemDel(int pos, const wchar_t *playstring) { }
  211. /**
  212. Method
  213. @see
  214. @ret
  215. @param
  216. */
  217. virtual void metacb_onItemChange(const wchar_t *playstring, const wchar_t *tag);
  218. /**
  219. Method
  220. @see
  221. @ret
  222. @param
  223. */
  224. virtual void metacb_onItemDel(const wchar_t *);
  225. private:
  226. PtrList<FilenameNC> *keep;
  227. };
  228. // column class to ask ItemListWnd to do the rendering
  229. /**
  230. Class
  231. @short
  232. @author Nullsoft
  233. @ver 1.0
  234. @see
  235. */
  236. class ItemListColumn_Callback : public ItemListColumn {
  237. public:
  238. /**
  239. Method
  240. @see
  241. @ret
  242. @param
  243. */
  244. ItemListColumn_Callback(ItemListWnd *_parent, LPARAM _lparam, const wchar_t *name=NULL);
  245. /**
  246. Method
  247. @see
  248. @ret
  249. @param
  250. */
  251. virtual void render(int pos, const wchar_t *playstring, Canvas &c, RECT &r);
  252. virtual void columnToText(int pos, const wchar_t *playstring, wchar_t *str, int maxlen);
  253. private:
  254. ItemListWnd *parent;
  255. LPARAM lparam;
  256. };
  257. // column class to render a metatag
  258. /**
  259. Class
  260. @short
  261. @author Nullsoft
  262. @ver 1.0
  263. @see
  264. */
  265. class ItemListColumn_MetaTag : public ItemListColumn {
  266. public:
  267. /**
  268. Method
  269. @see
  270. @ret
  271. @param
  272. */
  273. ItemListColumn_MetaTag(const wchar_t *tag, int center=0, const wchar_t *label=NULL);
  274. /**
  275. Method
  276. @see
  277. @ret
  278. @param
  279. */
  280. virtual ~ItemListColumn_MetaTag() {}
  281. /**
  282. Method
  283. @see
  284. @ret
  285. @param
  286. */
  287. virtual void render(int pos, const wchar_t *playstring, Canvas &c, RECT &r);
  288. virtual void columnToText(int pos, const wchar_t *playstring, wchar_t *str, int maxlen);
  289. const wchar_t *getTag();
  290. private:
  291. StringW tag;
  292. int center;
  293. int datatype;
  294. };
  295. // this just renders the position of the item, starting from 1
  296. /**
  297. Class
  298. @short
  299. @author Nullsoft
  300. @ver 1.0
  301. @see
  302. */
  303. class ItemListColumn_Numbered : public ItemListColumn {
  304. public:
  305. /**
  306. Method
  307. @see
  308. @ret
  309. @param
  310. */
  311. ItemListColumn_Numbered(int _offset=0) : offset(_offset) {}
  312. /**
  313. Method
  314. @see
  315. @ret
  316. @param
  317. */
  318. virtual void render(int pos, const wchar_t *playstring, Canvas &c, RECT &r);
  319. virtual void columnToText(int pos, const wchar_t *playstring, wchar_t *str, int maxlen);
  320. private:
  321. int offset;
  322. };
  323. #endif