listtest.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: listctrl.h
  3. // Purpose: wxListCtrl sample
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 04/01/98
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. // not all ports have support for EVT_CONTEXT_MENU yet, don't define
  11. // USE_CONTEXT_MENU for those which don't
  12. #if defined(__WXMOTIF__) || defined(__WXPM__) || defined(__WXX11__)
  13. #define USE_CONTEXT_MENU 0
  14. #else
  15. #define USE_CONTEXT_MENU 1
  16. #endif
  17. // Define a new application type
  18. class MyApp: public wxApp
  19. {
  20. public:
  21. MyApp() { }
  22. virtual bool OnInit();
  23. private:
  24. wxDECLARE_NO_COPY_CLASS(MyApp);
  25. };
  26. class MyListCtrl: public wxListCtrl
  27. {
  28. public:
  29. MyListCtrl(wxWindow *parent,
  30. const wxWindowID id,
  31. const wxPoint& pos,
  32. const wxSize& size,
  33. long style)
  34. : wxListCtrl(parent, id, pos, size, style)
  35. {
  36. m_updated = -1;
  37. #ifdef __POCKETPC__
  38. EnableContextMenu();
  39. #endif
  40. }
  41. // add one item to the listctrl in report mode
  42. void InsertItemInReportView(int i);
  43. void OnColClick(wxListEvent& event);
  44. void OnColRightClick(wxListEvent& event);
  45. void OnColBeginDrag(wxListEvent& event);
  46. void OnColDragging(wxListEvent& event);
  47. void OnColEndDrag(wxListEvent& event);
  48. void OnBeginDrag(wxListEvent& event);
  49. void OnBeginRDrag(wxListEvent& event);
  50. void OnBeginLabelEdit(wxListEvent& event);
  51. void OnEndLabelEdit(wxListEvent& event);
  52. void OnDeleteItem(wxListEvent& event);
  53. void OnDeleteAllItems(wxListEvent& event);
  54. void OnSelected(wxListEvent& event);
  55. void OnDeselected(wxListEvent& event);
  56. void OnListKeyDown(wxListEvent& event);
  57. void OnActivated(wxListEvent& event);
  58. void OnFocused(wxListEvent& event);
  59. void OnCacheHint(wxListEvent& event);
  60. void OnChar(wxKeyEvent& event);
  61. #if USE_CONTEXT_MENU
  62. void OnContextMenu(wxContextMenuEvent& event);
  63. #endif
  64. void OnRightClick(wxMouseEvent& event);
  65. private:
  66. void ShowContextMenu(const wxPoint& pos);
  67. wxLog *m_logOld;
  68. void SetColumnImage(int col, int image);
  69. void LogEvent(const wxListEvent& event, const wxChar *eventName);
  70. void LogColEvent(const wxListEvent& event, const wxChar *eventName);
  71. virtual wxString OnGetItemText(long item, long column) const;
  72. virtual int OnGetItemColumnImage(long item, long column) const;
  73. virtual wxListItemAttr *OnGetItemAttr(long item) const;
  74. long m_updated;
  75. wxDECLARE_NO_COPY_CLASS(MyListCtrl);
  76. wxDECLARE_EVENT_TABLE();
  77. };
  78. // Define a new frame type
  79. class MyFrame: public wxFrame
  80. {
  81. public:
  82. MyFrame(const wxChar *title);
  83. virtual ~MyFrame();
  84. void DoSize();
  85. protected:
  86. void OnSize(wxSizeEvent& event);
  87. void OnQuit(wxCommandEvent& event);
  88. void OnAbout(wxCommandEvent& event);
  89. void OnListView(wxCommandEvent& event);
  90. void OnReportView(wxCommandEvent& event);
  91. void OnIconView(wxCommandEvent& event);
  92. void OnIconTextView(wxCommandEvent& event);
  93. void OnSmallIconView(wxCommandEvent& event);
  94. void OnSmallIconTextView(wxCommandEvent& event);
  95. void OnVirtualView(wxCommandEvent& event);
  96. void OnSmallVirtualView(wxCommandEvent& event);
  97. void OnSetItemsCount(wxCommandEvent& event);
  98. void OnGoTo(wxCommandEvent& event);
  99. void OnFocusLast(wxCommandEvent& event);
  100. void OnToggleFirstSel(wxCommandEvent& event);
  101. void OnDeselectAll(wxCommandEvent& event);
  102. void OnSelectAll(wxCommandEvent& event);
  103. void OnAdd(wxCommandEvent& event);
  104. void OnEdit(wxCommandEvent& event);
  105. void OnDelete(wxCommandEvent& event);
  106. void OnDeleteAll(wxCommandEvent& event);
  107. void OnSort(wxCommandEvent& event);
  108. void OnSetFgColour(wxCommandEvent& event);
  109. void OnSetBgColour(wxCommandEvent& event);
  110. void OnSetRowLines(wxCommandEvent& event);
  111. void OnToggleMultiSel(wxCommandEvent& event);
  112. void OnShowColInfo(wxCommandEvent& event);
  113. void OnShowSelInfo(wxCommandEvent& event);
  114. void OnShowViewRect(wxCommandEvent& event);
  115. #ifdef wxHAS_LISTCTRL_COLUMN_ORDER
  116. void OnSetColOrder(wxCommandEvent& event);
  117. void OnGetColOrder(wxCommandEvent& event);
  118. #endif // wxHAS_LISTCTRL_COLUMN_ORDER
  119. void OnFreeze(wxCommandEvent& event);
  120. void OnThaw(wxCommandEvent& event);
  121. void OnToggleLines(wxCommandEvent& event);
  122. void OnToggleHeader(wxCommandEvent& event);
  123. void OnToggleBell(wxCommandEvent& event);
  124. #ifdef __WXOSX__
  125. void OnToggleMacUseGeneric(wxCommandEvent& event);
  126. #endif // __WXOSX__
  127. void OnFind(wxCommandEvent& event);
  128. void OnUpdateUIEnableInReport(wxUpdateUIEvent& event);
  129. void OnUpdateToggleMultiSel(wxUpdateUIEvent& event);
  130. void OnUpdateToggleHeader(wxUpdateUIEvent& event);
  131. void OnUpdateRowLines(wxUpdateUIEvent& event);
  132. wxImageList *m_imageListNormal;
  133. wxImageList *m_imageListSmall;
  134. wxPanel *m_panel;
  135. MyListCtrl *m_listCtrl;
  136. wxTextCtrl *m_logWindow;
  137. private:
  138. // recreate the list control with the new flags
  139. void RecreateList(long flags, bool withText = true);
  140. // fill the control with items depending on the view
  141. void InitWithListItems();
  142. void InitWithReportItems();
  143. void InitWithIconItems(bool withText, bool sameIcon = false);
  144. void InitWithVirtualItems();
  145. // return true if the control is not in virtual view, give an error message
  146. // and return false if it is
  147. bool CheckNonVirtual() const;
  148. wxLog *m_logOld;
  149. bool m_smallVirtual;
  150. // number of items to initialize list/report view with
  151. int m_numListItems;
  152. wxDECLARE_NO_COPY_CLASS(MyFrame);
  153. wxDECLARE_EVENT_TABLE();
  154. };
  155. // IDs for the menu commands
  156. enum
  157. {
  158. LIST_ABOUT = wxID_ABOUT,
  159. LIST_QUIT = wxID_EXIT,
  160. LIST_LIST_VIEW = wxID_HIGHEST,
  161. LIST_ICON_VIEW,
  162. LIST_ICON_TEXT_VIEW,
  163. LIST_SMALL_ICON_VIEW,
  164. LIST_SMALL_ICON_TEXT_VIEW,
  165. LIST_REPORT_VIEW,
  166. LIST_VIRTUAL_VIEW,
  167. LIST_SMALL_VIRTUAL_VIEW,
  168. LIST_SET_ITEMS_COUNT,
  169. LIST_DESELECT_ALL,
  170. LIST_SELECT_ALL,
  171. LIST_DELETE_ALL,
  172. LIST_DELETE,
  173. LIST_ADD,
  174. LIST_EDIT,
  175. LIST_SORT,
  176. LIST_FIND,
  177. LIST_SET_FG_COL,
  178. LIST_SET_BG_COL,
  179. LIST_ROW_LINES,
  180. LIST_TOGGLE_MULTI_SEL,
  181. LIST_TOGGLE_HEADER,
  182. LIST_TOGGLE_BELL,
  183. LIST_TOGGLE_FIRST,
  184. LIST_SHOW_COL_INFO,
  185. LIST_SHOW_SEL_INFO,
  186. LIST_SHOW_VIEW_RECT,
  187. #ifdef wxHAS_LISTCTRL_COLUMN_ORDER
  188. LIST_SET_COL_ORDER,
  189. LIST_GET_COL_ORDER,
  190. #endif // wxHAS_LISTCTRL_COLUMN_ORDER
  191. LIST_GOTO,
  192. LIST_FOCUS_LAST,
  193. LIST_FREEZE,
  194. LIST_THAW,
  195. LIST_TOGGLE_LINES,
  196. #ifdef __WXOSX__
  197. LIST_MAC_USE_GENERIC,
  198. #endif
  199. LIST_CTRL = 1000
  200. };