PropertyList.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /*=========================================================================
  2. Program: WXDialog - wxWidgets X-platform GUI Front-End for CMake
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Author: Jorgen Bodde
  8. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  9. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  10. This software is distributed WITHOUT ANY WARRANTY; without even
  11. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12. PURPOSE. See the above copyright notices for more information.
  13. =========================================================================*/
  14. #ifndef __WXPROPERTYLIST_H
  15. #define __WXPROPERTYLIST_H
  16. #ifndef WX_PRECOMP
  17. #include "wx/wx.h"
  18. #endif
  19. #include <wx/dynarray.h>
  20. #include <wx/grid.h>
  21. #include "../cmStandardIncludes.h"
  22. #ifdef __LINUX__
  23. #define MC_DEFAULT_WILDCARD "*"
  24. #else
  25. #define MC_DEFAULT_WILDCARD "*.*"
  26. #endif
  27. #if 0
  28. // the editor for string/text data
  29. class wxGridCellPathEditor : public wxGridCellEditor
  30. {
  31. public:
  32. wxGridCellPathEditor();
  33. virtual void Create(wxWindow* parent,
  34. wxWindowID id,
  35. wxEvtHandler* evtHandler);
  36. virtual void SetSize(const wxRect& rect);
  37. virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
  38. virtual bool IsAcceptedKey(wxKeyEvent& event);
  39. virtual void BeginEdit(int row, int col, wxGrid* grid);
  40. virtual bool EndEdit(int row, int col, wxGrid* grid);
  41. virtual void Reset();
  42. virtual void StartingKey(wxKeyEvent& event);
  43. virtual void HandleReturn(wxKeyEvent& event);
  44. // parameters string format is "max_width"
  45. virtual void SetParameters(const wxString& params);
  46. virtual wxGridCellEditor *Clone() const
  47. { return new wxGridCellPathEditor; }
  48. // DJC MAPTEK
  49. // added GetValue so we can get the value which is in the control
  50. virtual wxString GetValue() const;
  51. protected:
  52. wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
  53. // parts of our virtual functions reused by the derived classes
  54. void DoBeginEdit(const wxString& startValue);
  55. void DoReset(const wxString& startValue);
  56. private:
  57. size_t m_maxChars; // max number of chars allowed
  58. wxString m_startValue;
  59. DECLARE_NO_COPY_CLASS(wxGridCellPathEditor)
  60. };
  61. #endif
  62. /////////////////////////////////////////////////////////////////////////////
  63. //wxPropertyItem Items
  64. class wxPropertyItem
  65. {
  66. public:
  67. wxPropertyItem(const wxString &propName, const wxString &curValue,
  68. const wxString &helpString, int nItemType, const wxString &cmbItems)
  69. : m_NewValue(true)
  70. , m_HelpString(helpString)
  71. , m_Removed(false)
  72. , m_propName(propName)
  73. , m_curValue(curValue)
  74. , m_nItemType(nItemType)
  75. , m_cmbItems(cmbItems)
  76. , m_Advanced(false)
  77. {
  78. //m_NewValue = true;
  79. //m_HelpString = helpString;
  80. //m_Removed = false;
  81. //m_propName = propName;
  82. //m_curValue = curValue;
  83. //m_nItemType = nItemType;
  84. //m_cmbItems = cmbItems;
  85. //m_Advanced = false;
  86. }
  87. const wxString &GetCurValue() const {
  88. return m_curValue;
  89. };
  90. const wxString &GetPropName() const {
  91. return m_propName;
  92. };
  93. void SetCurValue(const char *str) {
  94. m_curValue = str;
  95. };
  96. void SetPropName(const char *str) {
  97. m_propName = str;
  98. };
  99. void SetAdvanced(bool value) {
  100. m_Advanced = value;
  101. };
  102. void SetHelpString(const char *str) {
  103. m_HelpString = str;
  104. };
  105. bool GetAdvanced() const {
  106. return m_Advanced;
  107. };
  108. void SetNewValue(bool value) {
  109. m_NewValue = value;
  110. };
  111. bool GetNewValue() const {
  112. return m_NewValue;
  113. };
  114. int GetItemType() const {
  115. return m_nItemType;
  116. };
  117. const wxString &GetHelpString() const {
  118. return m_HelpString;
  119. };
  120. // returns true when this property item is a filepath
  121. bool IsFilePath();
  122. // returns true when this property item is a dir path
  123. bool IsDirPath();
  124. private:
  125. wxString m_HelpString;
  126. wxString m_propName;
  127. wxString m_curValue;
  128. int m_nItemType;
  129. wxString m_cmbItems;
  130. bool m_NewValue;
  131. bool m_Removed;
  132. bool m_Advanced;
  133. };
  134. WX_DEFINE_ARRAY(wxPropertyItem *, wxPropertyItems);
  135. /////////////////////////////////////////////////////////////////////////////
  136. // wxPropertyList Grid
  137. class wxPropertyList : public wxGrid
  138. {
  139. // Construction
  140. public:
  141. wxPropertyList(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition,
  142. const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS,
  143. const wxString& name = wxPanelNameStr)
  144. : wxGrid(parent, id, pos, size, style, name)
  145. {
  146. };
  147. enum ItemType
  148. {
  149. COMBO = 0,
  150. EDIT,
  151. COLOR,
  152. FONT,
  153. FILE,
  154. CHECKBOX,
  155. PATH
  156. };
  157. virtual ~wxPropertyList();
  158. public:
  159. bool GetShowAdvanced() const {
  160. return m_ShowAdvanced;
  161. };
  162. void SetProjectGenerated(bool value) {
  163. m_generatedProjects = value;
  164. };
  165. bool IsGenerated() {
  166. return m_generatedProjects;
  167. };
  168. int AddItem(const wxString &txt);
  169. void AddProperty(const char* name, const char* value, const char* helpString, int type,
  170. const char* comboItems, bool reverseOrder, bool advanced);
  171. void RemoveProperty(wxPropertyItem *pItem);
  172. void HideControls();
  173. void ShowAdvanced();
  174. void HideAdvanced();
  175. void RemoveAll();
  176. wxPropertyItem* GetItem(size_t index) {
  177. wxCHECK(index < GetCount(), 0);
  178. return m_PropertyItems[index];
  179. };
  180. size_t GetCount() const {
  181. return m_PropertyItems.Count();
  182. };
  183. const wxPropertyItems &GetItems() {
  184. return m_PropertyItems;
  185. };
  186. void SetShowAdvanced(bool value) {
  187. m_ShowAdvanced = value;
  188. };
  189. bool UpdatePropertyItem(wxPropertyItem *pItem, int row);
  190. /** Returns the row of the grid on which the item is found. -1 is returned when not found */
  191. int FindProperty(wxPropertyItem *pItem);
  192. /** Returns true when the cache is still dirty, which means
  193. after a configuration run, there are still new items */
  194. bool IsCacheDirty() {
  195. // check if we have items that are new
  196. for(size_t i = 0; i < m_PropertyItems.Count(); i++)
  197. {
  198. //if((m_PropertyItems[i]->GetNewValue() && m_ShowAdvanced && m_PropertyItems[i]->GetAdvanced()) ||
  199. // (m_PropertyItems[i]->GetNewValue() && !m_ShowAdvanced))
  200. if(m_PropertyItems[i]->GetNewValue())
  201. return true;
  202. }
  203. // return flag if generated cache or not
  204. return false;
  205. };
  206. /** Returns the property item from the current row. 0 if no property item found */
  207. wxPropertyItem *GetPropertyItemFromRow(int row);
  208. /** Finds the property by name and returns the property item */
  209. wxPropertyItem *FindPropertyByName(const wxString &name);
  210. /** Sets the search filter. Making sure that the items currently displayed
  211. match this substring query */
  212. void SetQuery(const wxString &query) {
  213. m_strQuery = query;
  214. UpdateGridView();
  215. };
  216. /** Returns the last used query. */
  217. const wxString &GetQuery() {
  218. return m_strQuery;
  219. };
  220. /** Function that tries to browse for the item that is selected */
  221. void BrowseSelectedItem();
  222. /** Returns true when the item is browsable (file or path) and only one item is
  223. selected */
  224. bool IsSelectedItemBrowsable(int row = -1);
  225. private:
  226. // order = 0 sorted
  227. // order = 1 add to top
  228. // order = 2 add to bottom
  229. int AddPropItem(wxPropertyItem* pItem, int order);
  230. /** Adds the property item to the grid. */
  231. int AddPropertyToGrid(wxPropertyItem *pItem, int order) ;
  232. /** Adds / removes all the items that are currently (not) matching the
  233. query filter */
  234. void UpdateGridView();
  235. void OnSelectCell( wxGridEvent& event );
  236. void OnCellChange( wxGridEvent& event );
  237. void OnCellPopup( wxGridEvent& event );
  238. void OnIgnoreCache( wxCommandEvent& event );
  239. void OnDeleteCache( wxCommandEvent& event );
  240. void OnSizeGrid( wxSizeEvent &event );
  241. void OnBrowseItem( wxCommandEvent& event );
  242. void OnKeyPressed( wxKeyEvent &event );
  243. int m_curSel;
  244. int m_prevSel;
  245. int m_nDivider;
  246. int m_nDivTop;
  247. int m_nDivBtm;
  248. int m_nOldDivX;
  249. int m_nLastBox;
  250. bool m_bTracking;
  251. bool m_bDivIsSet;
  252. bool m_ShowAdvanced;
  253. // flag to indicate the last cache load has resulted
  254. // in generating a valid project
  255. bool m_generatedProjects;
  256. wxString m_strQuery;
  257. wxPropertyItems m_PropertyItems;
  258. DECLARE_EVENT_TABLE()
  259. };
  260. #endif