propgrid.h 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/propgrid/propgrid.h
  3. // Purpose: wxPropertyGrid
  4. // Author: Jaakko Salli
  5. // Modified by:
  6. // Created: 2004-09-25
  7. // Copyright: (c) Jaakko Salli
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_PROPGRID_PROPGRID_H_
  11. #define _WX_PROPGRID_PROPGRID_H_
  12. #include "wx/defs.h"
  13. #if wxUSE_PROPGRID
  14. #include "wx/thread.h"
  15. #include "wx/dcclient.h"
  16. #include "wx/control.h"
  17. #include "wx/scrolwin.h"
  18. #include "wx/tooltip.h"
  19. #include "wx/datetime.h"
  20. #include "wx/recguard.h"
  21. #include "wx/propgrid/property.h"
  22. #include "wx/propgrid/propgridiface.h"
  23. #ifndef SWIG
  24. extern WXDLLIMPEXP_DATA_PROPGRID(const char) wxPropertyGridNameStr[];
  25. #endif
  26. class wxPGComboBox;
  27. #if wxUSE_STATUSBAR
  28. class WXDLLIMPEXP_FWD_CORE wxStatusBar;
  29. #endif
  30. // -----------------------------------------------------------------------
  31. // Global variables
  32. // -----------------------------------------------------------------------
  33. // This is required for sharing common global variables.
  34. class WXDLLIMPEXP_PROPGRID wxPGGlobalVarsClass
  35. {
  36. public:
  37. wxPGGlobalVarsClass();
  38. ~wxPGGlobalVarsClass();
  39. #if wxUSE_THREADS
  40. // Critical section for handling the globals. Generally it is not needed
  41. // since GUI code is supposed to be in single thread. However,
  42. // we do want the user to be able to convey wxPropertyGridEvents to other
  43. // threads.
  44. wxCriticalSection m_critSect;
  45. #endif
  46. // Used by advprops, but here to make things easier.
  47. wxString m_pDefaultImageWildcard;
  48. // Map of editor class instances (keys are name string).
  49. wxPGHashMapS2P m_mapEditorClasses;
  50. #if wxUSE_VALIDATORS
  51. wxVector<wxValidator*> m_arrValidators; // These wxValidators need to be freed
  52. #endif
  53. wxPGHashMapS2P m_dictPropertyClassInfo; // PropertyName -> ClassInfo
  54. wxPGChoices* m_fontFamilyChoices;
  55. // Replace with your own to affect all properties using default renderer.
  56. wxPGCellRenderer* m_defaultRenderer;
  57. wxPGChoices m_boolChoices;
  58. wxVariant m_vEmptyString;
  59. wxVariant m_vZero;
  60. wxVariant m_vMinusOne;
  61. wxVariant m_vTrue;
  62. wxVariant m_vFalse;
  63. // Cached constant strings
  64. wxPGCachedString m_strstring;
  65. wxPGCachedString m_strlong;
  66. wxPGCachedString m_strbool;
  67. wxPGCachedString m_strlist;
  68. wxPGCachedString m_strDefaultValue;
  69. wxPGCachedString m_strMin;
  70. wxPGCachedString m_strMax;
  71. wxPGCachedString m_strUnits;
  72. wxPGCachedString m_strHint;
  73. #if wxPG_COMPATIBILITY_1_4
  74. wxPGCachedString m_strInlineHelp;
  75. #endif
  76. // If true then some things are automatically translated
  77. bool m_autoGetTranslation;
  78. // > 0 if errors cannot or should not be shown in statusbar etc.
  79. int m_offline;
  80. int m_extraStyle; // global extra style
  81. int m_warnings;
  82. int HasExtraStyle( int style ) const { return (m_extraStyle & style); }
  83. };
  84. extern WXDLLIMPEXP_DATA_PROPGRID(wxPGGlobalVarsClass*) wxPGGlobalVars;
  85. #define wxPGVariant_EmptyString (wxPGGlobalVars->m_vEmptyString)
  86. #define wxPGVariant_Zero (wxPGGlobalVars->m_vZero)
  87. #define wxPGVariant_MinusOne (wxPGGlobalVars->m_vMinusOne)
  88. #define wxPGVariant_True (wxPGGlobalVars->m_vTrue)
  89. #define wxPGVariant_False (wxPGGlobalVars->m_vFalse)
  90. #define wxPGVariant_Bool(A) (A?wxPGVariant_True:wxPGVariant_False)
  91. // When wxPG is loaded dynamically after the application is already running
  92. // then the built-in module system won't pick this one up. Add it manually.
  93. WXDLLIMPEXP_PROPGRID void wxPGInitResourceModule();
  94. // -----------------------------------------------------------------------
  95. /** @section propgrid_window_styles wxPropertyGrid Window Styles
  96. SetWindowStyleFlag method can be used to modify some of these at run-time.
  97. @{
  98. */
  99. enum wxPG_WINDOW_STYLES
  100. {
  101. /** This will cause Sort() automatically after an item is added.
  102. When inserting a lot of items in this mode, it may make sense to
  103. use Freeze() before operations and Thaw() afterwards to increase
  104. performance.
  105. */
  106. wxPG_AUTO_SORT = 0x00000010,
  107. /** Categories are not initially shown (even if added).
  108. IMPORTANT NOTE: If you do not plan to use categories, then this
  109. style will waste resources.
  110. This flag can also be changed using wxPropertyGrid::EnableCategories method.
  111. */
  112. wxPG_HIDE_CATEGORIES = 0x00000020,
  113. /* This style combines non-categoric mode and automatic sorting.
  114. */
  115. wxPG_ALPHABETIC_MODE = (wxPG_HIDE_CATEGORIES|wxPG_AUTO_SORT),
  116. /** Modified values are shown in bold font. Changing this requires Refresh()
  117. to show changes.
  118. */
  119. wxPG_BOLD_MODIFIED = 0x00000040,
  120. /** Using this style, the column splitters move automatically based on column
  121. proportions (default is equal proportion for every column). This behaviour
  122. stops once the user manually moves a splitter, and returns when a
  123. splitter is double-clicked.
  124. @see wxPropertyGridInterface::SetColumnProportion().
  125. */
  126. wxPG_SPLITTER_AUTO_CENTER = 0x00000080,
  127. /** Display tooltips for cell text that cannot be shown completely. If
  128. wxUSE_TOOLTIPS is 0, then this doesn't have any effect.
  129. */
  130. wxPG_TOOLTIPS = 0x00000100,
  131. /** Disables margin and hides all expand/collapse buttons that would appear
  132. outside the margin (for sub-properties). Toggling this style automatically
  133. expands all collapsed items.
  134. */
  135. wxPG_HIDE_MARGIN = 0x00000200,
  136. /** This style prevents user from moving the splitter.
  137. */
  138. wxPG_STATIC_SPLITTER = 0x00000400,
  139. /** Combination of other styles that make it impossible for user to modify
  140. the layout.
  141. */
  142. wxPG_STATIC_LAYOUT = (wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER),
  143. /** Disables wxTextCtrl based editors for properties which
  144. can be edited in another way.
  145. Equals calling wxPropertyGrid::LimitPropertyEditing for all added
  146. properties.
  147. */
  148. wxPG_LIMITED_EDITING = 0x00000800,
  149. /** wxPropertyGridManager only: Show toolbar for mode and page selection. */
  150. wxPG_TOOLBAR = 0x00001000,
  151. /** wxPropertyGridManager only: Show adjustable text box showing description
  152. or help text, if available, for currently selected property.
  153. */
  154. wxPG_DESCRIPTION = 0x00002000,
  155. /** wxPropertyGridManager only: don't show an internal border around the
  156. property grid. Recommended if you use a header.
  157. */
  158. wxPG_NO_INTERNAL_BORDER = 0x00004000
  159. };
  160. #if wxPG_COMPATIBILITY_1_4
  161. // In wxPG 1.4 this was used to enable now-default theme border support
  162. // in wxPropertyGridManager.
  163. #define wxPG_THEME_BORDER 0x00000000
  164. #endif
  165. enum wxPG_EX_WINDOW_STYLES
  166. {
  167. /**
  168. NOTE: wxPG_EX_xxx are extra window styles and must be set using
  169. SetExtraStyle() member function.
  170. Speeds up switching to wxPG_HIDE_CATEGORIES mode. Initially, if
  171. wxPG_HIDE_CATEGORIES is not defined, the non-categorized data storage is
  172. not activated, and switching the mode first time becomes somewhat slower.
  173. wxPG_EX_INIT_NOCAT activates the non-categorized data storage right away.
  174. IMPORTANT NOTE: If you do plan not switching to non-categoric mode, or if
  175. you don't plan to use categories at all, then using this style will result
  176. in waste of resources.
  177. */
  178. wxPG_EX_INIT_NOCAT = 0x00001000,
  179. /** Extended window style that sets wxPropertyGridManager toolbar to not
  180. use flat style.
  181. */
  182. wxPG_EX_NO_FLAT_TOOLBAR = 0x00002000,
  183. /** Shows alphabetic/categoric mode buttons from toolbar.
  184. */
  185. wxPG_EX_MODE_BUTTONS = 0x00008000,
  186. /** Show property help strings as tool tips instead as text on the status bar.
  187. You can set the help strings using SetPropertyHelpString member function.
  188. */
  189. wxPG_EX_HELP_AS_TOOLTIPS = 0x00010000,
  190. /** Prevent TAB from focusing to wxButtons. This behaviour was default
  191. in version 1.2.0 and earlier.
  192. NOTE! Tabbing to button doesn't work yet. Problem seems to be that on wxMSW
  193. atleast the button doesn't properly propagate key events (yes, I'm using
  194. wxWANTS_CHARS).
  195. */
  196. //wxPG_EX_NO_TAB_TO_BUTTON = 0x00020000,
  197. /** Allows relying on native double-buffering.
  198. */
  199. wxPG_EX_NATIVE_DOUBLE_BUFFERING = 0x00080000,
  200. /** Set this style to let user have ability to set values of properties to
  201. unspecified state. Same as setting wxPG_PROP_AUTO_UNSPECIFIED for
  202. all properties.
  203. */
  204. wxPG_EX_AUTO_UNSPECIFIED_VALUES = 0x00200000,
  205. /**
  206. If this style is used, built-in attributes (such as wxPG_FLOAT_PRECISION
  207. and wxPG_STRING_PASSWORD) are not stored into property's attribute storage
  208. (thus they are not readable).
  209. Note that this option is global, and applies to all wxPG property
  210. containers.
  211. */
  212. wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES = 0x00400000,
  213. /** Hides page selection buttons from toolbar.
  214. */
  215. wxPG_EX_HIDE_PAGE_BUTTONS = 0x01000000,
  216. /** Allows multiple properties to be selected by user (by pressing SHIFT
  217. when clicking on a property, or by dragging with left mouse button
  218. down).
  219. You can get array of selected properties with
  220. wxPropertyGridInterface::GetSelectedProperties(). In multiple selection
  221. mode wxPropertyGridInterface::GetSelection() returns
  222. property which has editor active (usually the first one
  223. selected). Other useful member functions are ClearSelection(),
  224. AddToSelection() and RemoveFromSelection().
  225. */
  226. wxPG_EX_MULTIPLE_SELECTION = 0x02000000,
  227. /**
  228. This enables top-level window tracking which allows wxPropertyGrid to
  229. notify the application of last-minute property value changes by user.
  230. This style is not enabled by default because it may cause crashes when
  231. wxPropertyGrid is used in with wxAUI or similar system.
  232. @remarks If you are not in fact using any system that may change
  233. wxPropertyGrid's top-level parent window on its own, then you
  234. are recommended to enable this style.
  235. */
  236. wxPG_EX_ENABLE_TLP_TRACKING = 0x04000000,
  237. /** Don't show divider above toolbar, on Windows.
  238. */
  239. wxPG_EX_NO_TOOLBAR_DIVIDER = 0x08000000,
  240. /** Show a separator below the toolbar.
  241. */
  242. wxPG_EX_TOOLBAR_SEPARATOR = 0x10000000
  243. };
  244. #if wxPG_COMPATIBILITY_1_4
  245. #define wxPG_EX_DISABLE_TLP_TRACKING 0x00000000
  246. #endif
  247. /** Combines various styles.
  248. */
  249. #define wxPG_DEFAULT_STYLE (0)
  250. /** Combines various styles.
  251. */
  252. #define wxPGMAN_DEFAULT_STYLE (0)
  253. /** @}
  254. */
  255. // -----------------------------------------------------------------------
  256. //
  257. // Ids for sub-controls
  258. // NB: It should not matter what these are.
  259. #define wxPG_SUBID1 2
  260. #define wxPG_SUBID2 3
  261. #define wxPG_SUBID_TEMP1 4
  262. // -----------------------------------------------------------------------
  263. /** @class wxPGCommonValue
  264. wxPropertyGrid stores information about common values in these
  265. records.
  266. NB: Common value feature is not complete, and thus not mentioned in
  267. documentation.
  268. */
  269. class WXDLLIMPEXP_PROPGRID wxPGCommonValue
  270. {
  271. public:
  272. wxPGCommonValue( const wxString& label, wxPGCellRenderer* renderer )
  273. {
  274. m_label = label;
  275. m_renderer = renderer;
  276. renderer->IncRef();
  277. }
  278. virtual ~wxPGCommonValue()
  279. {
  280. m_renderer->DecRef();
  281. }
  282. virtual wxString GetEditableText() const { return m_label; }
  283. const wxString& GetLabel() const { return m_label; }
  284. wxPGCellRenderer* GetRenderer() const { return m_renderer; }
  285. protected:
  286. wxString m_label;
  287. wxPGCellRenderer* m_renderer;
  288. };
  289. // -----------------------------------------------------------------------
  290. /** @section propgrid_vfbflags wxPropertyGrid Validation Failure behaviour Flags
  291. @{
  292. */
  293. enum wxPG_VALIDATION_FAILURE_BEHAVIOR_FLAGS
  294. {
  295. /** Prevents user from leaving property unless value is valid. If this
  296. behaviour flag is not used, then value change is instead cancelled.
  297. */
  298. wxPG_VFB_STAY_IN_PROPERTY = 0x01,
  299. /** Calls wxBell() on validation failure.
  300. */
  301. wxPG_VFB_BEEP = 0x02,
  302. /** Cell with invalid value will be marked (with red colour).
  303. */
  304. wxPG_VFB_MARK_CELL = 0x04,
  305. /**
  306. Display a text message explaining the situation.
  307. To customize the way the message is displayed, you need to
  308. reimplement wxPropertyGrid::DoShowPropertyError() in a
  309. derived class. Default behaviour is to display the text on
  310. the top-level frame's status bar, if present, and otherwise
  311. using wxMessageBox.
  312. */
  313. wxPG_VFB_SHOW_MESSAGE = 0x08,
  314. /**
  315. Similar to wxPG_VFB_SHOW_MESSAGE, except always displays the
  316. message using wxMessageBox.
  317. */
  318. wxPG_VFB_SHOW_MESSAGEBOX = 0x10,
  319. /**
  320. Similar to wxPG_VFB_SHOW_MESSAGE, except always displays the
  321. message on the status bar (when present - you can reimplement
  322. wxPropertyGrid::GetStatusBar() in a derived class to specify
  323. this yourself).
  324. */
  325. wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR = 0x20,
  326. /** Defaults. */
  327. wxPG_VFB_DEFAULT = wxPG_VFB_MARK_CELL |
  328. wxPG_VFB_SHOW_MESSAGEBOX,
  329. /** Only used internally. */
  330. wxPG_VFB_UNDEFINED = 0x80
  331. };
  332. /** @}
  333. */
  334. // Having this as define instead of wxByte typedef makes things easier for
  335. // wxPython bindings (ignoring and redefining it in SWIG interface file
  336. // seemed rather tricky)
  337. #define wxPGVFBFlags unsigned char
  338. /**
  339. wxPGValidationInfo
  340. Used to convey validation information to and from functions that
  341. actually perform validation. Mostly used in custom property
  342. classes.
  343. */
  344. class WXDLLIMPEXP_PROPGRID wxPGValidationInfo
  345. {
  346. friend class wxPropertyGrid;
  347. public:
  348. wxPGValidationInfo()
  349. {
  350. m_failureBehavior = 0;
  351. m_isFailing = false;
  352. }
  353. ~wxPGValidationInfo()
  354. {
  355. }
  356. /**
  357. @return Returns failure behaviour which is a combination of
  358. @ref propgrid_vfbflags.
  359. */
  360. wxPGVFBFlags GetFailureBehavior() const
  361. { return m_failureBehavior; }
  362. /**
  363. Returns current failure message.
  364. */
  365. const wxString& GetFailureMessage() const
  366. { return m_failureMessage; }
  367. /**
  368. Returns reference to pending value.
  369. */
  370. wxVariant& GetValue()
  371. {
  372. wxASSERT(m_pValue);
  373. return *m_pValue;
  374. }
  375. /** Set validation failure behaviour
  376. @param failureBehavior
  377. Mixture of @ref propgrid_vfbflags.
  378. */
  379. void SetFailureBehavior(wxPGVFBFlags failureBehavior)
  380. { m_failureBehavior = failureBehavior; }
  381. /**
  382. Set current failure message.
  383. */
  384. void SetFailureMessage(const wxString& message)
  385. { m_failureMessage = message; }
  386. private:
  387. /** Value to be validated.
  388. */
  389. wxVariant* m_pValue;
  390. /** Message displayed on validation failure.
  391. */
  392. wxString m_failureMessage;
  393. /** Validation failure behaviour. Use wxPG_VFB_XXX flags.
  394. */
  395. wxPGVFBFlags m_failureBehavior;
  396. // True when validation is currently failing.
  397. bool m_isFailing;
  398. };
  399. // -----------------------------------------------------------------------
  400. /** @section propgrid_pgactions wxPropertyGrid Action Identifiers
  401. These are used with wxPropertyGrid::AddActionTrigger() and
  402. wxPropertyGrid::ClearActionTriggers().
  403. @{
  404. */
  405. enum wxPG_KEYBOARD_ACTIONS
  406. {
  407. wxPG_ACTION_INVALID = 0,
  408. /** Select the next property. */
  409. wxPG_ACTION_NEXT_PROPERTY,
  410. /** Select the previous property. */
  411. wxPG_ACTION_PREV_PROPERTY,
  412. /** Expand the selected property, if it has child items. */
  413. wxPG_ACTION_EXPAND_PROPERTY,
  414. /** Collapse the selected property, if it has child items. */
  415. wxPG_ACTION_COLLAPSE_PROPERTY,
  416. /** Cancel and undo any editing done in the currently active property
  417. editor.
  418. */
  419. wxPG_ACTION_CANCEL_EDIT,
  420. /** Move focus to the editor control of the currently selected
  421. property.
  422. */
  423. wxPG_ACTION_EDIT,
  424. /** Causes editor's button (if any) to be pressed. */
  425. wxPG_ACTION_PRESS_BUTTON,
  426. wxPG_ACTION_MAX
  427. };
  428. /** @}
  429. */
  430. // -----------------------------------------------------------------------
  431. // wxPropertyGrid::DoSelectProperty flags (selFlags)
  432. // Focuses to created editor
  433. #define wxPG_SEL_FOCUS 0x0001
  434. // Forces deletion and recreation of editor
  435. #define wxPG_SEL_FORCE 0x0002
  436. // For example, doesn't cause EnsureVisible
  437. #define wxPG_SEL_NONVISIBLE 0x0004
  438. // Do not validate editor's value before selecting
  439. #define wxPG_SEL_NOVALIDATE 0x0008
  440. // Property being deselected is about to be deleted
  441. #define wxPG_SEL_DELETING 0x0010
  442. // Property's values was set to unspecified by the user
  443. #define wxPG_SEL_SETUNSPEC 0x0020
  444. // Property's event handler changed the value
  445. #define wxPG_SEL_DIALOGVAL 0x0040
  446. // Set to disable sending of wxEVT_PG_SELECTED event
  447. #define wxPG_SEL_DONT_SEND_EVENT 0x0080
  448. // Don't make any graphics updates
  449. #define wxPG_SEL_NO_REFRESH 0x0100
  450. // -----------------------------------------------------------------------
  451. // DoSetSplitterPosition() flags
  452. enum wxPG_SET_SPLITTER_POSITION_SPLITTER_FLAGS
  453. {
  454. wxPG_SPLITTER_REFRESH = 0x0001,
  455. wxPG_SPLITTER_ALL_PAGES = 0x0002,
  456. wxPG_SPLITTER_FROM_EVENT = 0x0004,
  457. wxPG_SPLITTER_FROM_AUTO_CENTER = 0x0008
  458. };
  459. // -----------------------------------------------------------------------
  460. // Internal flags
  461. #define wxPG_FL_INITIALIZED 0x0001
  462. // Set when creating editor controls if it was clicked on.
  463. #define wxPG_FL_ACTIVATION_BY_CLICK 0x0002
  464. #define wxPG_FL_DONT_CENTER_SPLITTER 0x0004
  465. #define wxPG_FL_FOCUSED 0x0008
  466. #define wxPG_FL_MOUSE_CAPTURED 0x0010
  467. #define wxPG_FL_MOUSE_INSIDE 0x0020
  468. #define wxPG_FL_VALUE_MODIFIED 0x0040
  469. // don't clear background of m_wndEditor
  470. #define wxPG_FL_PRIMARY_FILLS_ENTIRE 0x0080
  471. // currently active editor uses custom image
  472. #define wxPG_FL_CUR_USES_CUSTOM_IMAGE 0x0100
  473. // cell colours override selection colours for selected cell
  474. #define wxPG_FL_CELL_OVERRIDES_SEL 0x0200
  475. #define wxPG_FL_SCROLLED 0x0400
  476. // set when all added/inserted properties get hideable flag
  477. #define wxPG_FL_ADDING_HIDEABLES 0x0800
  478. // Disables showing help strings on statusbar.
  479. #define wxPG_FL_NOSTATUSBARHELP 0x1000
  480. // Marks that we created the state, so we have to destroy it too.
  481. #define wxPG_FL_CREATEDSTATE 0x2000
  482. // Set if scrollbar's existence was detected in last onresize.
  483. #define wxPG_FL_SCROLLBAR_DETECTED 0x4000
  484. // Set if wxPGMan requires redrawing of description text box.
  485. #define wxPG_FL_DESC_REFRESH_REQUIRED 0x8000
  486. // Set if contained in wxPropertyGridManager
  487. #define wxPG_FL_IN_MANAGER 0x00020000
  488. // Set after wxPropertyGrid is shown in its initial good size
  489. #define wxPG_FL_GOOD_SIZE_SET 0x00040000
  490. // Set when in SelectProperty.
  491. #define wxPG_FL_IN_SELECT_PROPERTY 0x00100000
  492. // Set when help string is shown in status bar
  493. #define wxPG_FL_STRING_IN_STATUSBAR 0x00200000
  494. // Auto sort is enabled (for categorized mode)
  495. #define wxPG_FL_CATMODE_AUTO_SORT 0x01000000
  496. // Set after page has been inserted to manager
  497. #define wxPG_MAN_FL_PAGE_INSERTED 0x02000000
  498. // Active editor control is abnormally large
  499. #define wxPG_FL_ABNORMAL_EDITOR 0x04000000
  500. // Recursion guard for HandleCustomEditorEvent
  501. #define wxPG_FL_IN_HANDLECUSTOMEDITOREVENT 0x08000000
  502. #define wxPG_FL_VALUE_CHANGE_IN_EVENT 0x10000000
  503. // Editor control width should not change on resize
  504. #define wxPG_FL_FIXED_WIDTH_EDITOR 0x20000000
  505. // Width of panel can be different than width of grid
  506. #define wxPG_FL_HAS_VIRTUAL_WIDTH 0x40000000
  507. // Prevents RecalculateVirtualSize re-entrancy
  508. #define wxPG_FL_RECALCULATING_VIRTUAL_SIZE 0x80000000
  509. #if !defined(__wxPG_SOURCE_FILE__)
  510. // Reduce compile time, but still include in user app
  511. #include "wx/propgrid/props.h"
  512. #endif
  513. // -----------------------------------------------------------------------
  514. /** @class wxPropertyGrid
  515. wxPropertyGrid is a specialized grid for editing properties
  516. such as strings, numbers, flagsets, fonts, and colours. wxPropertySheet
  517. used to do the very same thing, but it hasn't been updated for a while
  518. and it is currently deprecated.
  519. Please note that most member functions are inherited and as such not
  520. documented on this page. This means you will probably also want to read
  521. wxPropertyGridInterface class reference.
  522. See also @ref overview_propgrid.
  523. @section propgrid_window_styles_ Window Styles
  524. See @ref propgrid_window_styles.
  525. @section propgrid_event_handling Event Handling
  526. To process input from a propertygrid control, use these event handler
  527. macros to direct input to member functions that take a wxPropertyGridEvent
  528. argument.
  529. @beginEventTable{wxPropertyGridEvent}
  530. @event{EVT_PG_SELECTED (id, func)}
  531. Respond to wxEVT_PG_SELECTED event, generated when a property selection
  532. has been changed, either by user action or by indirect program
  533. function. For instance, collapsing a parent property programmatically
  534. causes any selected child property to become unselected, and may
  535. therefore cause this event to be generated.
  536. @event{EVT_PG_CHANGING(id, func)}
  537. Respond to wxEVT_PG_CHANGING event, generated when property value
  538. is about to be changed by user. Use wxPropertyGridEvent::GetValue()
  539. to take a peek at the pending value, and wxPropertyGridEvent::Veto()
  540. to prevent change from taking place, if necessary.
  541. @event{EVT_PG_HIGHLIGHTED(id, func)}
  542. Respond to wxEVT_PG_HIGHLIGHTED event, which occurs when mouse
  543. moves over a property. Event's property is NULL if hovered area does
  544. not belong to any property.
  545. @event{EVT_PG_RIGHT_CLICK(id, func)}
  546. Respond to wxEVT_PG_RIGHT_CLICK event, which occurs when property is
  547. clicked on with right mouse button.
  548. @event{EVT_PG_DOUBLE_CLICK(id, func)}
  549. Respond to wxEVT_PG_DOUBLE_CLICK event, which occurs when property is
  550. double-clicked onwith left mouse button.
  551. @event{EVT_PG_ITEM_COLLAPSED(id, func)}
  552. Respond to wxEVT_PG_ITEM_COLLAPSED event, generated when user collapses
  553. a property or category..
  554. @event{EVT_PG_ITEM_EXPANDED(id, func)}
  555. Respond to wxEVT_PG_ITEM_EXPANDED event, generated when user expands
  556. a property or category..
  557. @event{EVT_PG_LABEL_EDIT_BEGIN(id, func)}
  558. Respond to wxEVT_PG_LABEL_EDIT_BEGIN event, generated when is about to
  559. begin editing a property label. You can veto this event to prevent the
  560. action.
  561. @event{EVT_PG_LABEL_EDIT_ENDING(id, func)}
  562. Respond to wxEVT_PG_LABEL_EDIT_ENDING event, generated when is about to
  563. end editing of a property label. You can veto this event to prevent the
  564. action.
  565. @event{EVT_PG_COL_BEGIN_DRAG(id, func)}
  566. Respond to wxEVT_PG_COL_BEGIN_DRAG event, generated when user
  567. starts resizing a column - can be vetoed.
  568. @event{EVT_PG_COL_DRAGGING,(id, func)}
  569. Respond to wxEVT_PG_COL_DRAGGING, event, generated when a
  570. column resize by user is in progress. This event is also generated
  571. when user double-clicks the splitter in order to recenter
  572. it.
  573. @event{EVT_PG_COL_END_DRAG(id, func)}
  574. Respond to wxEVT_PG_COL_END_DRAG event, generated after column
  575. resize by user has finished.
  576. @endEventTable
  577. @remarks
  578. - Use Freeze() and Thaw() respectively to disable and enable drawing. This
  579. will also delay sorting etc. miscellaneous calculations to the last
  580. possible moment.
  581. @library{wxpropgrid}
  582. @category{propgrid}
  583. */
  584. class WXDLLIMPEXP_PROPGRID wxPropertyGrid : public wxControl,
  585. public wxScrollHelper,
  586. public wxPropertyGridInterface
  587. {
  588. friend class wxPropertyGridEvent;
  589. friend class wxPropertyGridPageState;
  590. friend class wxPropertyGridInterface;
  591. friend class wxPropertyGridManager;
  592. friend class wxPGHeaderCtrl;
  593. DECLARE_DYNAMIC_CLASS(wxPropertyGrid)
  594. public:
  595. #ifndef SWIG
  596. /**
  597. Two step constructor.
  598. Call Create when this constructor is called to build up the
  599. wxPropertyGrid
  600. */
  601. wxPropertyGrid();
  602. #endif
  603. /** The default constructor. The styles to be used are styles valid for
  604. the wxWindow.
  605. @see @link wndflags Additional Window Styles @endlink
  606. */
  607. wxPropertyGrid( wxWindow *parent, wxWindowID id = wxID_ANY,
  608. const wxPoint& pos = wxDefaultPosition,
  609. const wxSize& size = wxDefaultSize,
  610. long style = wxPG_DEFAULT_STYLE,
  611. const wxString& name = wxPropertyGridNameStr );
  612. /** Destructor */
  613. virtual ~wxPropertyGrid();
  614. /** Adds given key combination to trigger given action.
  615. Here is a sample code to make Enter key press move focus to
  616. the next property.
  617. @code
  618. propGrid->AddActionTrigger(wxPG_ACTION_NEXT_PROPERTY,
  619. WXK_RETURN);
  620. propGrid->DedicateKey(WXK_RETURN);
  621. @endcode
  622. @param action
  623. Which action to trigger. See @ref propgrid_keyboard_actions.
  624. @param keycode
  625. Which keycode triggers the action.
  626. @param modifiers
  627. Which key event modifiers, in addition to keycode, are needed to
  628. trigger the action.
  629. */
  630. void AddActionTrigger( int action, int keycode, int modifiers = 0 );
  631. /**
  632. Dedicates a specific keycode to wxPropertyGrid. This means that such
  633. key presses will not be redirected to editor controls.
  634. Using this function allows, for example, navigation between
  635. properties using arrow keys even when the focus is in the editor
  636. control.
  637. */
  638. void DedicateKey( int keycode )
  639. {
  640. m_dedicatedKeys.push_back(keycode);
  641. }
  642. /**
  643. This static function enables or disables automatic use of
  644. wxGetTranslation for following strings: wxEnumProperty list labels,
  645. wxFlagsProperty sub-property labels.
  646. Default is false.
  647. */
  648. static void AutoGetTranslation( bool enable );
  649. /**
  650. Changes value of a property, as if from an editor.
  651. Use this instead of SetPropertyValue() if you need the value to run
  652. through validation process, and also send the property change event.
  653. @return
  654. Returns true if value was successfully changed.
  655. */
  656. bool ChangePropertyValue( wxPGPropArg id, wxVariant newValue );
  657. /**
  658. Centers the splitter.
  659. @param enableAutoResizing
  660. If @true, automatic column resizing is enabled (only applicapple
  661. if window style wxPG_SPLITTER_AUTO_CENTER is used).
  662. */
  663. void CenterSplitter( bool enableAutoResizing = false );
  664. /** Deletes all properties.
  665. */
  666. virtual void Clear();
  667. /** Clears action triggers for given action.
  668. @param action
  669. Which action to trigger. See @link pgactions List of list of
  670. wxPropertyGrid actions@endlink.
  671. */
  672. void ClearActionTriggers( int action );
  673. /** Forces updating the value of property from the editor control.
  674. Note that wxEVT_PG_CHANGING and wxEVT_PG_CHANGED are dispatched using
  675. ProcessEvent, meaning your event handlers will be called immediately.
  676. @return
  677. Returns true if anything was changed.
  678. */
  679. virtual bool CommitChangesFromEditor( wxUint32 flags = 0 );
  680. /**
  681. Two step creation.
  682. Whenever the control is created without any parameters, use Create to
  683. actually create it. Don't access the control's public methods before
  684. this is called @see @link wndflags Additional Window Styles@endlink
  685. */
  686. bool Create( wxWindow *parent, wxWindowID id = wxID_ANY,
  687. const wxPoint& pos = wxDefaultPosition,
  688. const wxSize& size = wxDefaultSize,
  689. long style = wxPG_DEFAULT_STYLE,
  690. const wxString& name = wxPropertyGridNameStr );
  691. /**
  692. Call when editor widget's contents is modified.
  693. For example, this is called when changes text in wxTextCtrl (used in
  694. wxStringProperty and wxIntProperty).
  695. @remarks
  696. This function should only be called by custom properties.
  697. @see wxPGProperty::OnEvent()
  698. */
  699. void EditorsValueWasModified() { m_iFlags |= wxPG_FL_VALUE_MODIFIED; }
  700. /** Reverse of EditorsValueWasModified().
  701. @remarks
  702. This function should only be called by custom properties.
  703. */
  704. void EditorsValueWasNotModified()
  705. {
  706. m_iFlags &= ~(wxPG_FL_VALUE_MODIFIED);
  707. }
  708. /**
  709. Enables or disables (shows/hides) categories according to parameter
  710. enable.
  711. */
  712. bool EnableCategories( bool enable );
  713. /** Scrolls and/or expands items to ensure that the given item is visible.
  714. Returns true if something was actually done.
  715. */
  716. bool EnsureVisible( wxPGPropArg id );
  717. /**
  718. Reduces column sizes to minimum possible that contents are still
  719. visibly (naturally some margin space will be applied as well).
  720. @return
  721. Minimum size for the grid to still display everything.
  722. @remarks
  723. Does not work well with wxPG_SPLITTER_AUTO_CENTER window style.
  724. This function only works properly if grid size prior to call was already
  725. fairly large.
  726. Note that you can also get calculated column widths by calling
  727. GetState->GetColumnWidth() immediately after this function returns.
  728. */
  729. wxSize FitColumns()
  730. {
  731. wxSize sz = m_pState->DoFitColumns();
  732. return sz;
  733. }
  734. /**
  735. Returns wxWindow that the properties are painted on, and which should
  736. be used as the parent for editor controls.
  737. */
  738. wxWindow* GetPanel()
  739. {
  740. return this;
  741. }
  742. /** Returns current category caption background colour. */
  743. wxColour GetCaptionBackgroundColour() const { return m_colCapBack; }
  744. wxFont& GetCaptionFont() { return m_captionFont; }
  745. const wxFont& GetCaptionFont() const { return m_captionFont; }
  746. /** Returns current category caption text colour. */
  747. wxColour GetCaptionForegroundColour() const { return m_colCapFore; }
  748. /** Returns current cell background colour. */
  749. wxColour GetCellBackgroundColour() const { return m_colPropBack; }
  750. /** Returns current cell text colour when disabled. */
  751. wxColour GetCellDisabledTextColour() const { return m_colDisPropFore; }
  752. /** Returns current cell text colour. */
  753. wxColour GetCellTextColour() const { return m_colPropFore; }
  754. /**
  755. Returns number of columns currently on grid.
  756. */
  757. unsigned int GetColumnCount() const
  758. {
  759. return (unsigned int) m_pState->m_colWidths.size();
  760. }
  761. /** Returns colour of empty space below properties. */
  762. wxColour GetEmptySpaceColour() const { return m_colEmptySpace; }
  763. /** Returns height of highest characters of used font. */
  764. int GetFontHeight() const { return m_fontHeight; }
  765. /** Returns pointer to itself. Dummy function that enables same kind
  766. of code to use wxPropertyGrid and wxPropertyGridManager.
  767. */
  768. wxPropertyGrid* GetGrid() { return this; }
  769. /** Returns rectangle of custom paint image.
  770. */
  771. wxRect GetImageRect( wxPGProperty* p, int item ) const;
  772. /** Returns size of the custom paint image in front of property.
  773. If no argument is given, returns preferred size.
  774. */
  775. wxSize GetImageSize( wxPGProperty* p = NULL, int item = -1 ) const;
  776. //@{
  777. /** Returns last item which could be iterated using given flags.
  778. @param flags
  779. See @ref propgrid_iterator_flags.
  780. */
  781. wxPGProperty* GetLastItem( int flags = wxPG_ITERATE_DEFAULT )
  782. {
  783. return m_pState->GetLastItem(flags);
  784. }
  785. const wxPGProperty* GetLastItem( int flags = wxPG_ITERATE_DEFAULT ) const
  786. {
  787. return m_pState->GetLastItem(flags);
  788. }
  789. //@}
  790. /** Returns colour of lines between cells. */
  791. wxColour GetLineColour() const { return m_colLine; }
  792. /** Returns background colour of margin. */
  793. wxColour GetMarginColour() const { return m_colMargin; }
  794. /** Returns margin width. */
  795. int GetMarginWidth() const { return m_marginWidth; }
  796. /**
  797. Returns most up-to-date value of selected property. This will return
  798. value different from GetSelectedProperty()->GetValue() only when text
  799. editor is activate and string edited by user represents valid,
  800. uncommitted property value.
  801. */
  802. wxVariant GetUncommittedPropertyValue();
  803. /** Returns "root property". It does not have name, etc. and it is not
  804. visible. It is only useful for accessing its children.
  805. */
  806. wxPGProperty* GetRoot() const { return m_pState->m_properties; }
  807. /** Returns height of a single grid row (in pixels). */
  808. int GetRowHeight() const { return m_lineHeight; }
  809. /** Returns currently selected property. */
  810. wxPGProperty* GetSelectedProperty() const { return GetSelection(); }
  811. /** Returns current selection background colour. */
  812. wxColour GetSelectionBackgroundColour() const { return m_colSelBack; }
  813. /** Returns current selection text colour. */
  814. wxColour GetSelectionForegroundColour() const { return m_colSelFore; }
  815. /**
  816. Returns current splitter x position.
  817. */
  818. int GetSplitterPosition( unsigned int splitterIndex = 0 ) const
  819. {
  820. return m_pState->DoGetSplitterPosition(splitterIndex);
  821. }
  822. /** Returns wxTextCtrl active in currently selected property, if any. Takes
  823. into account wxOwnerDrawnComboBox.
  824. */
  825. wxTextCtrl* GetEditorTextCtrl() const;
  826. wxPGValidationInfo& GetValidationInfo()
  827. {
  828. return m_validationInfo;
  829. }
  830. /** Returns current vertical spacing. */
  831. int GetVerticalSpacing() const { return (int)m_vspacing; }
  832. /**
  833. Returns @true if a property editor control has focus.
  834. */
  835. bool IsEditorFocused() const;
  836. /** Returns true if editor's value was marked modified.
  837. */
  838. bool IsEditorsValueModified() const
  839. { return ( m_iFlags & wxPG_FL_VALUE_MODIFIED ) ? true : false; }
  840. /**
  841. Returns information about arbitrary position in the grid.
  842. @param pt
  843. Coordinates in the virtual grid space. You may need to use
  844. wxScrolled<T>::CalcScrolledPosition() for translating
  845. wxPropertyGrid client coordinates into something this member
  846. function can use.
  847. */
  848. wxPropertyGridHitTestResult HitTest( const wxPoint& pt ) const;
  849. /** Returns true if any property has been modified by the user. */
  850. bool IsAnyModified() const { return (m_pState->m_anyModified>0); }
  851. /**
  852. Returns true if updating is frozen (ie Freeze() called but not yet
  853. Thaw() ).
  854. */
  855. bool IsFrozen() const { return (m_frozen>0)?true:false; }
  856. /**
  857. It is recommended that you call this function any time your code causes
  858. wxPropertyGrid's top-level parent to change. wxPropertyGrid's OnIdle()
  859. handler should be able to detect most changes, but it is not perfect.
  860. @param newTLP
  861. New top-level parent that is about to be set. Old top-level parent
  862. window should still exist as the current one.
  863. @remarks This function is automatically called from wxPropertyGrid::
  864. Reparent() and wxPropertyGridManager::Reparent(). You only
  865. need to use it if you reparent wxPropertyGrid indirectly.
  866. */
  867. void OnTLPChanging( wxWindow* newTLP );
  868. /** Redraws given property.
  869. */
  870. virtual void RefreshProperty( wxPGProperty* p );
  871. /** Registers a new editor class.
  872. @return
  873. Pointer to the editor class instance that should be used.
  874. */
  875. static wxPGEditor* RegisterEditorClass( wxPGEditor* editor,
  876. bool noDefCheck = false )
  877. {
  878. return DoRegisterEditorClass(editor, wxEmptyString, noDefCheck);
  879. }
  880. static wxPGEditor* DoRegisterEditorClass( wxPGEditor* editorClass,
  881. const wxString& editorName,
  882. bool noDefCheck = false );
  883. /** Resets all colours to the original system values.
  884. */
  885. void ResetColours();
  886. /**
  887. Resets column sizes and splitter positions, based on proportions.
  888. @param enableAutoResizing
  889. If @true, automatic column resizing is enabled (only applicapple
  890. if window style wxPG_SPLITTER_AUTO_CENTER is used).
  891. @see wxPropertyGridInterface::SetColumnProportion()
  892. */
  893. void ResetColumnSizes( bool enableAutoResizing = false );
  894. /**
  895. Selects a property.
  896. Editor widget is automatically created, but not focused unless focus is
  897. true.
  898. @param id
  899. Property to select.
  900. @return
  901. True if selection finished successfully. Usually only fails if
  902. current value in editor is not valid.
  903. @remarks In wxPropertyGrid 1.4, this member function used to generate
  904. wxEVT_PG_SELECTED. In wxWidgets 2.9 and later, it no longer
  905. does that.
  906. @remarks This clears any previous selection.
  907. */
  908. bool SelectProperty( wxPGPropArg id, bool focus = false );
  909. /**
  910. Set entire new selection from given list of properties.
  911. */
  912. void SetSelection( const wxArrayPGProperty& newSelection )
  913. {
  914. DoSetSelection( newSelection, wxPG_SEL_DONT_SEND_EVENT );
  915. }
  916. /**
  917. Adds given property into selection. If wxPG_EX_MULTIPLE_SELECTION
  918. extra style is not used, then this has same effect as
  919. calling SelectProperty().
  920. @remarks Multiple selection is not supported for categories. This
  921. means that if you have properties selected, you cannot
  922. add category to selection, and also if you have category
  923. selected, you cannot add other properties to selection.
  924. This member function will fail silently in these cases,
  925. even returning true.
  926. */
  927. bool AddToSelection( wxPGPropArg id )
  928. {
  929. wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
  930. return DoAddToSelection(p, wxPG_SEL_DONT_SEND_EVENT);
  931. }
  932. /**
  933. Removes given property from selection. If property is not selected,
  934. an assertion failure will occur.
  935. */
  936. bool RemoveFromSelection( wxPGPropArg id )
  937. {
  938. wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
  939. return DoRemoveFromSelection(p, wxPG_SEL_DONT_SEND_EVENT);
  940. }
  941. /**
  942. Makes given column editable by user.
  943. @param editable
  944. Using @false here will disable column from being editable.
  945. */
  946. void MakeColumnEditable( unsigned int column, bool editable = true );
  947. /**
  948. Creates label editor wxTextCtrl for given column, for property
  949. that is currently selected. When multiple selection is
  950. enabled, this applies to whatever property GetSelection()
  951. returns.
  952. @param colIndex
  953. Which column's label to edit. Note that you should not
  954. use value 1, which is reserved for property value
  955. column.
  956. @see EndLabelEdit(), MakeColumnEditable()
  957. */
  958. void BeginLabelEdit( unsigned int column = 0 )
  959. {
  960. DoBeginLabelEdit(column, wxPG_SEL_DONT_SEND_EVENT);
  961. }
  962. /**
  963. Destroys label editor wxTextCtrl, if any.
  964. @param commit
  965. Use @true (default) to store edited label text in
  966. property cell data.
  967. @see BeginLabelEdit(), MakeColumnEditable()
  968. */
  969. void EndLabelEdit( bool commit = true )
  970. {
  971. DoEndLabelEdit(commit, wxPG_SEL_DONT_SEND_EVENT);
  972. }
  973. /**
  974. Returns currently active label editor, NULL if none.
  975. */
  976. wxTextCtrl* GetLabelEditor() const
  977. {
  978. return m_labelEditor;
  979. }
  980. /** Sets category caption background colour. */
  981. void SetCaptionBackgroundColour(const wxColour& col);
  982. /** Sets category caption text colour. */
  983. void SetCaptionTextColour(const wxColour& col);
  984. /** Sets default cell background colour - applies to property cells.
  985. Note that appearance of editor widgets may not be affected.
  986. */
  987. void SetCellBackgroundColour(const wxColour& col);
  988. /** Sets cell text colour for disabled properties.
  989. */
  990. void SetCellDisabledTextColour(const wxColour& col);
  991. /** Sets default cell text colour - applies to property name and value text.
  992. Note that appearance of editor widgets may not be affected.
  993. */
  994. void SetCellTextColour(const wxColour& col);
  995. /** Set number of columns (2 or more).
  996. */
  997. void SetColumnCount( int colCount )
  998. {
  999. m_pState->SetColumnCount(colCount);
  1000. Refresh();
  1001. }
  1002. /**
  1003. Sets the 'current' category - Append will add non-category properties
  1004. under it.
  1005. */
  1006. void SetCurrentCategory( wxPGPropArg id )
  1007. {
  1008. wxPG_PROP_ARG_CALL_PROLOG()
  1009. wxPropertyCategory* pc = wxDynamicCast(p, wxPropertyCategory);
  1010. wxASSERT(pc);
  1011. m_pState->m_currentCategory = pc;
  1012. }
  1013. /** Sets colour of empty space below properties. */
  1014. void SetEmptySpaceColour(const wxColour& col);
  1015. /** Sets colour of lines between cells. */
  1016. void SetLineColour(const wxColour& col);
  1017. /** Sets background colour of margin. */
  1018. void SetMarginColour(const wxColour& col);
  1019. /**
  1020. Sets selection background colour - applies to selected property name
  1021. background.
  1022. */
  1023. void SetSelectionBackgroundColour(const wxColour& col);
  1024. /**
  1025. Sets selection foreground colour - applies to selected property name
  1026. text.
  1027. */
  1028. void SetSelectionTextColour(const wxColour& col);
  1029. /** Sets x coordinate of the splitter.
  1030. @remarks
  1031. Splitter position cannot exceed grid size, and therefore setting it
  1032. during form creation may fail as initial grid size is often smaller
  1033. than desired splitter position, especially when sizers are being used.
  1034. */
  1035. void SetSplitterPosition( int newXPos, int col = 0 )
  1036. {
  1037. DoSetSplitterPosition(newXPos, col, wxPG_SPLITTER_REFRESH);
  1038. }
  1039. /**
  1040. Sets the property sorting function.
  1041. @param sortFunction
  1042. The sorting function to be used. It should return a value greater
  1043. than 0 if position of p1 is after p2. So, for instance, when
  1044. comparing property names, you can use following implementation:
  1045. @code
  1046. int MyPropertySortFunction(wxPropertyGrid* propGrid,
  1047. wxPGProperty* p1,
  1048. wxPGProperty* p2)
  1049. {
  1050. return p1->GetBaseName().compare( p2->GetBaseName() );
  1051. }
  1052. @endcode
  1053. @remarks
  1054. Default property sort function sorts properties by their labels
  1055. (case-insensitively).
  1056. @see GetSortFunction, wxPropertyGridInterface::Sort,
  1057. wxPropertyGridInterface::SortChildren
  1058. */
  1059. void SetSortFunction( wxPGSortCallback sortFunction )
  1060. {
  1061. m_sortFunction = sortFunction;
  1062. }
  1063. /**
  1064. Returns the property sort function (default is @NULL).
  1065. @see SetSortFunction
  1066. */
  1067. wxPGSortCallback GetSortFunction() const
  1068. {
  1069. return m_sortFunction;
  1070. }
  1071. /**
  1072. Sets appearance of value cells representing an unspecified property
  1073. value. Default appearance is blank.
  1074. @remarks If you set the unspecified value to have any
  1075. textual representation, then that will override
  1076. "InlineHelp" attribute.
  1077. @see wxPGProperty::SetValueToUnspecified(),
  1078. wxPGProperty::IsValueUnspecified()
  1079. */
  1080. void SetUnspecifiedValueAppearance( const wxPGCell& cell )
  1081. {
  1082. m_unspecifiedAppearance = m_propertyDefaultCell;
  1083. m_unspecifiedAppearance.MergeFrom(cell);
  1084. }
  1085. /**
  1086. Returns current appearance of unspecified value cells.
  1087. @see SetUnspecifiedValueAppearance()
  1088. */
  1089. const wxPGCell& GetUnspecifiedValueAppearance() const
  1090. {
  1091. return m_unspecifiedAppearance;
  1092. }
  1093. /**
  1094. Returns (visual) text representation of the unspecified
  1095. property value.
  1096. @param argFlags For internal use only.
  1097. */
  1098. wxString GetUnspecifiedValueText( int argFlags = 0 ) const;
  1099. /** Set virtual width for this particular page. Width -1 indicates that the
  1100. virtual width should be disabled. */
  1101. void SetVirtualWidth( int width );
  1102. /**
  1103. Moves splitter as left as possible, while still allowing all
  1104. labels to be shown in full.
  1105. @param privateChildrenToo
  1106. If @false, will still allow private children to be cropped.
  1107. */
  1108. void SetSplitterLeft( bool privateChildrenToo = false )
  1109. {
  1110. m_pState->SetSplitterLeft(privateChildrenToo);
  1111. }
  1112. /** Sets vertical spacing. Can be 1, 2, or 3 - a value relative to font
  1113. height. Value of 2 should be default on most platforms.
  1114. */
  1115. void SetVerticalSpacing( int vspacing )
  1116. {
  1117. m_vspacing = (unsigned char)vspacing;
  1118. CalculateFontAndBitmapStuff( vspacing );
  1119. if ( !m_pState->m_itemsAdded ) Refresh();
  1120. }
  1121. /** Shows an brief error message that is related to a property. */
  1122. void ShowPropertyError( wxPGPropArg id, const wxString& msg )
  1123. {
  1124. wxPG_PROP_ARG_CALL_PROLOG()
  1125. DoShowPropertyError(p, msg);
  1126. }
  1127. /////////////////////////////////////////////////////////////////
  1128. //
  1129. // Following methods do not need to be (currently) documented
  1130. //
  1131. /////////////////////////////////////////////////////////////////
  1132. bool HasVirtualWidth() const
  1133. { return (m_iFlags & wxPG_FL_HAS_VIRTUAL_WIDTH) ? true : false; }
  1134. const wxPGCommonValue* GetCommonValue( unsigned int i ) const
  1135. {
  1136. return (wxPGCommonValue*) m_commonValues[i];
  1137. }
  1138. /** Returns number of common values.
  1139. */
  1140. unsigned int GetCommonValueCount() const
  1141. {
  1142. return (unsigned int) m_commonValues.size();
  1143. }
  1144. /** Returns label of given common value.
  1145. */
  1146. wxString GetCommonValueLabel( unsigned int i ) const
  1147. {
  1148. wxASSERT( GetCommonValue(i) );
  1149. return GetCommonValue(i)->GetLabel();
  1150. }
  1151. /**
  1152. Returns index of common value that will truly change value to
  1153. unspecified.
  1154. */
  1155. int GetUnspecifiedCommonValue() const { return m_cvUnspecified; }
  1156. /** Set index of common value that will truly change value to unspecified.
  1157. Using -1 will set none to have such effect.
  1158. Default is 0.
  1159. */
  1160. void SetUnspecifiedCommonValue( int index ) { m_cvUnspecified = index; }
  1161. /**
  1162. Shortcut for creating dialog-caller button. Used, for example, by
  1163. wxFontProperty.
  1164. @remarks
  1165. This should only be called by properties.
  1166. */
  1167. wxWindow* GenerateEditorButton( const wxPoint& pos, const wxSize& sz );
  1168. /** Fixes position of wxTextCtrl-like control (wxSpinCtrl usually
  1169. fits as one). Call after control has been created (but before
  1170. shown).
  1171. */
  1172. void FixPosForTextCtrl( wxWindow* ctrl,
  1173. unsigned int forColumn = 1,
  1174. const wxPoint& offset = wxPoint(0, 0) );
  1175. /** Shortcut for creating text editor widget.
  1176. @param pos
  1177. Same as pos given for CreateEditor.
  1178. @param sz
  1179. Same as sz given for CreateEditor.
  1180. @param value
  1181. Initial text for wxTextCtrl.
  1182. @param secondary
  1183. If right-side control, such as button, also created, then create it
  1184. first and pass it as this parameter.
  1185. @param extraStyle
  1186. Extra style flags to pass for wxTextCtrl.
  1187. @remarks
  1188. Note that this should generally be called only by new classes derived
  1189. from wxPGProperty.
  1190. */
  1191. wxWindow* GenerateEditorTextCtrl( const wxPoint& pos,
  1192. const wxSize& sz,
  1193. const wxString& value,
  1194. wxWindow* secondary,
  1195. int extraStyle = 0,
  1196. int maxLen = 0,
  1197. unsigned int forColumn = 1 );
  1198. /* Generates both textctrl and button.
  1199. */
  1200. wxWindow* GenerateEditorTextCtrlAndButton( const wxPoint& pos,
  1201. const wxSize& sz, wxWindow** psecondary, int limited_editing,
  1202. wxPGProperty* property );
  1203. /** Generates position for a widget editor dialog box.
  1204. @param p
  1205. Property for which dialog is positioned.
  1206. @param sz
  1207. Known or over-approximated size of the dialog.
  1208. @return
  1209. Position for dialog.
  1210. */
  1211. wxPoint GetGoodEditorDialogPosition( wxPGProperty* p,
  1212. const wxSize& sz );
  1213. // Converts escape sequences in src_str to newlines,
  1214. // tabs, etc. and copies result to dst_str.
  1215. static wxString& ExpandEscapeSequences( wxString& dst_str,
  1216. wxString& src_str );
  1217. // Converts newlines, tabs, etc. in src_str to escape
  1218. // sequences, and copies result to dst_str.
  1219. static wxString& CreateEscapeSequences( wxString& dst_str,
  1220. wxString& src_str );
  1221. /**
  1222. Returns rectangle that fully contains properties between and including
  1223. p1 and p2. Rectangle is in virtual scrolled window coordinates.
  1224. */
  1225. wxRect GetPropertyRect( const wxPGProperty* p1,
  1226. const wxPGProperty* p2 ) const;
  1227. /** Returns pointer to current active primary editor control (NULL if none).
  1228. */
  1229. wxWindow* GetEditorControl() const;
  1230. wxWindow* GetPrimaryEditor() const
  1231. {
  1232. return GetEditorControl();
  1233. }
  1234. /**
  1235. Returns pointer to current active secondary editor control (NULL if
  1236. none).
  1237. */
  1238. wxWindow* GetEditorControlSecondary() const
  1239. {
  1240. return m_wndEditor2;
  1241. }
  1242. /**
  1243. Refreshes any active editor control.
  1244. */
  1245. void RefreshEditor();
  1246. // Events from editor controls are forward to this function
  1247. bool HandleCustomEditorEvent( wxEvent &event );
  1248. // Mostly useful for page switching.
  1249. void SwitchState( wxPropertyGridPageState* pNewState );
  1250. long GetInternalFlags() const { return m_iFlags; }
  1251. bool HasInternalFlag( long flag ) const
  1252. { return (m_iFlags & flag) ? true : false; }
  1253. void SetInternalFlag( long flag ) { m_iFlags |= flag; }
  1254. void ClearInternalFlag( long flag ) { m_iFlags &= ~(flag); }
  1255. void IncFrozen() { m_frozen++; }
  1256. void DecFrozen() { m_frozen--; }
  1257. void OnComboItemPaint( const wxPGComboBox* pCb,
  1258. int item,
  1259. wxDC* pDc,
  1260. wxRect& rect,
  1261. int flags );
  1262. /** Standardized double-to-string conversion.
  1263. */
  1264. static const wxString& DoubleToString( wxString& target,
  1265. double value,
  1266. int precision,
  1267. bool removeZeroes,
  1268. wxString* precTemplate = NULL );
  1269. /**
  1270. Call this from wxPGProperty::OnEvent() to cause property value to be
  1271. changed after the function returns (with true as return value).
  1272. ValueChangeInEvent() must be used if you wish the application to be
  1273. able to use wxEVT_PG_CHANGING to potentially veto the given value.
  1274. */
  1275. void ValueChangeInEvent( wxVariant variant )
  1276. {
  1277. m_changeInEventValue = variant;
  1278. m_iFlags |= wxPG_FL_VALUE_CHANGE_IN_EVENT;
  1279. }
  1280. /**
  1281. You can use this member function, for instance, to detect in
  1282. wxPGProperty::OnEvent() if wxPGProperty::SetValueInEvent() was
  1283. already called in wxPGEditor::OnEvent(). It really only detects
  1284. if was value was changed using wxPGProperty::SetValueInEvent(), which
  1285. is usually used when a 'picker' dialog is displayed. If value was
  1286. written by "normal means" in wxPGProperty::StringToValue() or
  1287. IntToValue(), then this function will return false (on the other hand,
  1288. wxPGProperty::OnEvent() is not even called in those cases).
  1289. */
  1290. bool WasValueChangedInEvent() const
  1291. {
  1292. return (m_iFlags & wxPG_FL_VALUE_CHANGE_IN_EVENT) ? true : false;
  1293. }
  1294. /** Returns true if given event is from first of an array of buttons
  1295. (as can be in case when wxPGMultiButton is used).
  1296. */
  1297. bool IsMainButtonEvent( const wxEvent& event )
  1298. {
  1299. return (event.GetEventType() == wxEVT_BUTTON)
  1300. && (m_wndSecId == event.GetId());
  1301. }
  1302. /** Pending value is expected to be passed in PerformValidation().
  1303. */
  1304. virtual bool DoPropertyChanged( wxPGProperty* p,
  1305. unsigned int selFlags = 0 );
  1306. /** Called when validation for given property fails.
  1307. @param invalidValue
  1308. Value which failed in validation.
  1309. @return
  1310. Return true if user is allowed to change to another property even
  1311. if current has invalid value.
  1312. @remarks
  1313. To add your own validation failure behaviour, override
  1314. wxPropertyGrid::DoOnValidationFailure().
  1315. */
  1316. bool OnValidationFailure( wxPGProperty* property,
  1317. wxVariant& invalidValue );
  1318. /** Called to indicate property and editor has valid value now.
  1319. */
  1320. void OnValidationFailureReset( wxPGProperty* property )
  1321. {
  1322. if ( property && property->HasFlag(wxPG_PROP_INVALID_VALUE) )
  1323. {
  1324. DoOnValidationFailureReset(property);
  1325. property->ClearFlag(wxPG_PROP_INVALID_VALUE);
  1326. }
  1327. m_validationInfo.m_failureMessage.clear();
  1328. }
  1329. /**
  1330. Override in derived class to display error messages in custom manner
  1331. (these message usually only result from validation failure).
  1332. @remarks If you implement this, then you also need to implement
  1333. DoHidePropertyError() - possibly to do nothing, if error
  1334. does not need hiding (e.g. it was logged or shown in a
  1335. message box).
  1336. @see DoHidePropertyError()
  1337. */
  1338. virtual void DoShowPropertyError( wxPGProperty* property,
  1339. const wxString& msg );
  1340. /**
  1341. Override in derived class to hide an error displayed by
  1342. DoShowPropertyError().
  1343. @see DoShowPropertyError()
  1344. */
  1345. virtual void DoHidePropertyError( wxPGProperty* property );
  1346. #if wxUSE_STATUSBAR
  1347. /**
  1348. Return wxStatusBar that is used by this wxPropertyGrid. You can
  1349. reimplement this member function in derived class to override
  1350. the default behaviour of using the top-level wxFrame's status
  1351. bar, if any.
  1352. */
  1353. virtual wxStatusBar* GetStatusBar();
  1354. #endif
  1355. /** Override to customize property validation failure behaviour.
  1356. @param invalidValue
  1357. Value which failed in validation.
  1358. @return
  1359. Return true if user is allowed to change to another property even
  1360. if current has invalid value.
  1361. */
  1362. virtual bool DoOnValidationFailure( wxPGProperty* property,
  1363. wxVariant& invalidValue );
  1364. /** Override to customize resetting of property validation failure status.
  1365. @remarks
  1366. Property is guaranteed to have flag wxPG_PROP_INVALID_VALUE set.
  1367. */
  1368. virtual void DoOnValidationFailureReset( wxPGProperty* property );
  1369. int GetSpacingY() const { return m_spacingy; }
  1370. /**
  1371. Must be called in wxPGEditor::CreateControls() if primary editor window
  1372. is wxTextCtrl, just before textctrl is created.
  1373. @param text
  1374. Initial text value of created wxTextCtrl.
  1375. */
  1376. void SetupTextCtrlValue( const wxString text ) { m_prevTcValue = text; }
  1377. /**
  1378. Unfocuses or closes editor if one was open, but does not deselect
  1379. property.
  1380. */
  1381. bool UnfocusEditor();
  1382. virtual void SetWindowStyleFlag( long style );
  1383. void DrawItems( const wxPGProperty* p1, const wxPGProperty* p2 );
  1384. void DrawItem( wxPGProperty* p )
  1385. {
  1386. DrawItems(p,p);
  1387. }
  1388. virtual void DrawItemAndChildren( wxPGProperty* p );
  1389. /**
  1390. Draws item, children, and consequtive parents as long as category is
  1391. not met.
  1392. */
  1393. void DrawItemAndValueRelated( wxPGProperty* p );
  1394. protected:
  1395. /**
  1396. wxPropertyGridPageState used by the grid is created here.
  1397. If grid is used in wxPropertyGridManager, there is no point overriding
  1398. this - instead, set custom wxPropertyGridPage classes.
  1399. */
  1400. virtual wxPropertyGridPageState* CreateState() const;
  1401. enum PerformValidationFlags
  1402. {
  1403. SendEvtChanging = 0x0001,
  1404. IsStandaloneValidation = 0x0002 // Not called in response to event
  1405. };
  1406. /**
  1407. Runs all validation functionality (includes sending wxEVT_PG_CHANGING).
  1408. Returns true if all tests passed. Implement in derived class to
  1409. add additional validation behaviour.
  1410. */
  1411. virtual bool PerformValidation( wxPGProperty* p,
  1412. wxVariant& pendingValue,
  1413. int flags = SendEvtChanging );
  1414. public:
  1415. // Control font changer helper.
  1416. void SetCurControlBoldFont();
  1417. wxPGCell& GetPropertyDefaultCell()
  1418. {
  1419. return m_propertyDefaultCell;
  1420. }
  1421. wxPGCell& GetCategoryDefaultCell()
  1422. {
  1423. return m_categoryDefaultCell;
  1424. }
  1425. //
  1426. // Public methods for semi-public use
  1427. //
  1428. bool DoSelectProperty( wxPGProperty* p, unsigned int flags = 0 );
  1429. // Overridden functions.
  1430. virtual bool Destroy();
  1431. // Returns property at given y coordinate (relative to grid's top left).
  1432. wxPGProperty* GetItemAtY( int y ) const { return DoGetItemAtY(y); }
  1433. virtual void Refresh( bool eraseBackground = true,
  1434. const wxRect *rect = (const wxRect *) NULL );
  1435. virtual bool SetFont( const wxFont& font );
  1436. virtual void Freeze();
  1437. virtual void SetExtraStyle( long exStyle );
  1438. virtual void Thaw();
  1439. virtual bool Reparent( wxWindowBase *newParent );
  1440. protected:
  1441. virtual wxSize DoGetBestSize() const;
  1442. #ifndef wxPG_ICON_WIDTH
  1443. wxBitmap *m_expandbmp, *m_collbmp;
  1444. #endif
  1445. wxCursor *m_cursorSizeWE;
  1446. /** wxWindow pointers to editor control(s). */
  1447. wxWindow *m_wndEditor;
  1448. wxWindow *m_wndEditor2;
  1449. wxBitmap *m_doubleBuffer;
  1450. /** Local time ms when control was created. */
  1451. wxLongLong m_timeCreated;
  1452. /** wxPGProperty::OnEvent can change value by setting this. */
  1453. wxVariant m_changeInEventValue;
  1454. /** Id of m_wndEditor2, or its first child, if any. */
  1455. int m_wndSecId;
  1456. /** Extra Y spacing between the items. */
  1457. int m_spacingy;
  1458. /** Control client area width; updated on resize. */
  1459. int m_width;
  1460. /** Control client area height; updated on resize. */
  1461. int m_height;
  1462. /** Current non-client width (needed when auto-centering). */
  1463. int m_ncWidth;
  1464. /** Non-client width (auto-centering helper). */
  1465. //int m_fWidth;
  1466. /** Previously recorded scroll start position. */
  1467. int m_prevVY;
  1468. /**
  1469. The gutter spacing in front and back of the image.
  1470. This determines the amount of spacing in front of each item
  1471. */
  1472. int m_gutterWidth;
  1473. /** Includes separator line. */
  1474. int m_lineHeight;
  1475. /** Gutter*2 + image width. */
  1476. int m_marginWidth;
  1477. // y spacing for expand/collapse button.
  1478. int m_buttonSpacingY;
  1479. /** Extra margin for expanded sub-group items. */
  1480. int m_subgroup_extramargin;
  1481. /**
  1482. The image width of the [+] icon.
  1483. This is also calculated in the gutter
  1484. */
  1485. int m_iconWidth;
  1486. #ifndef wxPG_ICON_WIDTH
  1487. /**
  1488. The image height of the [+] icon.
  1489. This is calculated as minimal size and to align
  1490. */
  1491. int m_iconHeight;
  1492. #endif
  1493. /** Current cursor id. */
  1494. int m_curcursor;
  1495. // Caption font. Same as normal font plus bold style.
  1496. wxFont m_captionFont;
  1497. int m_fontHeight; // Height of the font.
  1498. /** m_splitterx when drag began. */
  1499. int m_startingSplitterX;
  1500. /**
  1501. Index to splitter currently being dragged (0=one after the first
  1502. column).
  1503. */
  1504. int m_draggedSplitter;
  1505. /** Changed property, calculated in PerformValidation(). */
  1506. wxPGProperty* m_chgInfo_changedProperty;
  1507. /**
  1508. Lowest property for which editing happened, but which does not have
  1509. aggregate parent
  1510. */
  1511. wxPGProperty* m_chgInfo_baseChangedProperty;
  1512. /** Changed property value, calculated in PerformValidation(). */
  1513. wxVariant m_chgInfo_pendingValue;
  1514. /** Passed to SetValue. */
  1515. wxVariant m_chgInfo_valueList;
  1516. /** Validation information. */
  1517. wxPGValidationInfo m_validationInfo;
  1518. /** Actions and keys that trigger them. */
  1519. wxPGHashMapI2I m_actionTriggers;
  1520. /** Appearance of currently active editor. */
  1521. wxPGCell m_editorAppearance;
  1522. /** Appearance of a unspecified value cell. */
  1523. wxPGCell m_unspecifiedAppearance;
  1524. /** List of properties to be deleted/removed in idle event handler. */
  1525. wxArrayPGProperty m_deletedProperties;
  1526. wxArrayPGProperty m_removedProperties;
  1527. /** List of key codes that will not be handed over to editor controls. */
  1528. // FIXME: Make this a hash set once there is template-based wxHashSet.
  1529. wxVector<int> m_dedicatedKeys;
  1530. //
  1531. // Temporary values
  1532. //
  1533. /** Bits are used to indicate which colours are customized. */
  1534. unsigned short m_coloursCustomized;
  1535. /** x - m_splitterx. */
  1536. signed char m_dragOffset;
  1537. /** 0 = not dragging, 1 = drag just started, 2 = drag in progress */
  1538. unsigned char m_dragStatus;
  1539. /** 0 = margin, 1 = label, 2 = value. */
  1540. unsigned char m_mouseSide;
  1541. /** True when editor control is focused. */
  1542. unsigned char m_editorFocused;
  1543. /** 1 if m_latsCaption is also the bottommost caption. */
  1544. //unsigned char m_lastCaptionBottomnest;
  1545. /** Set to 1 when graphics frozen. */
  1546. unsigned char m_frozen;
  1547. unsigned char m_vspacing;
  1548. // Used to track when Alt/Ctrl+Key was consumed.
  1549. unsigned char m_keyComboConsumed;
  1550. /** 1 if in DoPropertyChanged() */
  1551. bool m_inDoPropertyChanged;
  1552. /** 1 if in CommitChangesFromEditor() */
  1553. bool m_inCommitChangesFromEditor;
  1554. /** 1 if in DoSelectProperty() */
  1555. bool m_inDoSelectProperty;
  1556. bool m_inOnValidationFailure;
  1557. wxPGVFBFlags m_permanentValidationFailureBehavior; // Set by app
  1558. // DoEditorValidate() recursion guard
  1559. wxRecursionGuardFlag m_validatingEditor;
  1560. /** Internal flags - see wxPG_FL_XXX constants. */
  1561. wxUint32 m_iFlags;
  1562. /** When drawing next time, clear this many item slots at the end. */
  1563. int m_clearThisMany;
  1564. // Mouse is hovering over this column (index)
  1565. unsigned int m_colHover;
  1566. // pointer to property that has mouse hovering
  1567. wxPGProperty* m_propHover;
  1568. // Active label editor
  1569. wxTextCtrl* m_labelEditor;
  1570. // For which property the label editor is active
  1571. wxPGProperty* m_labelEditorProperty;
  1572. // EventObject for wxPropertyGridEvents
  1573. wxWindow* m_eventObject;
  1574. // What (global) window is currently focused (needed to resolve event
  1575. // handling mess).
  1576. wxWindow* m_curFocused;
  1577. // Event currently being sent - NULL if none at the moment
  1578. wxPropertyGridEvent* m_processedEvent;
  1579. // Last known top-level parent
  1580. wxWindow* m_tlp;
  1581. // Last closed top-level parent
  1582. wxWindow* m_tlpClosed;
  1583. // Local time ms when tlp was closed.
  1584. wxLongLong m_tlpClosedTime;
  1585. // Sort function
  1586. wxPGSortCallback m_sortFunction;
  1587. // y coordinate of property that mouse hovering
  1588. int m_propHoverY;
  1589. // Which column's editor is selected (usually 1)?
  1590. unsigned int m_selColumn;
  1591. // x relative to splitter (needed for resize).
  1592. int m_ctrlXAdjust;
  1593. // lines between cells
  1594. wxColour m_colLine;
  1595. // property labels and values are written in this colour
  1596. wxColour m_colPropFore;
  1597. // or with this colour when disabled
  1598. wxColour m_colDisPropFore;
  1599. // background for m_colPropFore
  1600. wxColour m_colPropBack;
  1601. // text color for captions
  1602. wxColour m_colCapFore;
  1603. // background color for captions
  1604. wxColour m_colCapBack;
  1605. // foreground for selected property
  1606. wxColour m_colSelFore;
  1607. // background for selected property (actually use background color when
  1608. // control out-of-focus)
  1609. wxColour m_colSelBack;
  1610. // background colour for margin
  1611. wxColour m_colMargin;
  1612. // background colour for empty space below the grid
  1613. wxColour m_colEmptySpace;
  1614. // Default property colours
  1615. wxPGCell m_propertyDefaultCell;
  1616. // Default property category
  1617. wxPGCell m_categoryDefaultCell;
  1618. // Backup of selected property's cells
  1619. wxVector<wxPGCell> m_propCellsBackup;
  1620. // NB: These *cannot* be moved to globals.
  1621. // labels when properties use common values
  1622. wxVector<wxPGCommonValue*> m_commonValues;
  1623. // array of live events
  1624. wxVector<wxPropertyGridEvent*> m_liveEvents;
  1625. // Which cv selection really sets value to unspecified?
  1626. int m_cvUnspecified;
  1627. // Used to skip excess text editor events
  1628. wxString m_prevTcValue;
  1629. protected:
  1630. // Sets some members to defaults (called constructors).
  1631. void Init1();
  1632. // Initializes some members (called by Create and complex constructor).
  1633. void Init2();
  1634. void OnPaint(wxPaintEvent &event );
  1635. // main event receivers
  1636. void OnMouseMove( wxMouseEvent &event );
  1637. void OnMouseClick( wxMouseEvent &event );
  1638. void OnMouseRightClick( wxMouseEvent &event );
  1639. void OnMouseDoubleClick( wxMouseEvent &event );
  1640. void OnMouseUp( wxMouseEvent &event );
  1641. void OnKey( wxKeyEvent &event );
  1642. void OnResize( wxSizeEvent &event );
  1643. // event handlers
  1644. bool HandleMouseMove( int x, unsigned int y, wxMouseEvent &event );
  1645. bool HandleMouseClick( int x, unsigned int y, wxMouseEvent &event );
  1646. bool HandleMouseRightClick( int x, unsigned int y, wxMouseEvent &event );
  1647. bool HandleMouseDoubleClick( int x, unsigned int y, wxMouseEvent &event );
  1648. bool HandleMouseUp( int x, unsigned int y, wxMouseEvent &event );
  1649. void HandleKeyEvent( wxKeyEvent &event, bool fromChild );
  1650. void OnMouseEntry( wxMouseEvent &event );
  1651. void OnIdle( wxIdleEvent &event );
  1652. void OnFocusEvent( wxFocusEvent &event );
  1653. void OnChildFocusEvent( wxChildFocusEvent& event );
  1654. bool OnMouseCommon( wxMouseEvent &event, int* px, int *py );
  1655. bool OnMouseChildCommon( wxMouseEvent &event, int* px, int *py );
  1656. // sub-control event handlers
  1657. void OnMouseClickChild( wxMouseEvent &event );
  1658. void OnMouseRightClickChild( wxMouseEvent &event );
  1659. void OnMouseMoveChild( wxMouseEvent &event );
  1660. void OnMouseUpChild( wxMouseEvent &event );
  1661. void OnChildKeyDown( wxKeyEvent &event );
  1662. void OnCaptureChange( wxMouseCaptureChangedEvent &event );
  1663. void OnScrollEvent( wxScrollWinEvent &event );
  1664. void OnSysColourChanged( wxSysColourChangedEvent &event );
  1665. void OnTLPClose( wxCloseEvent& event );
  1666. protected:
  1667. bool AddToSelectionFromInputEvent( wxPGProperty* prop,
  1668. unsigned int colIndex,
  1669. wxMouseEvent* event = NULL,
  1670. int selFlags = 0 );
  1671. /**
  1672. Adjust the centering of the bitmap icons (collapse / expand) when the
  1673. caption font changes.
  1674. They need to be centered in the middle of the font, so a bit of deltaY
  1675. adjustment is needed. On entry, m_captionFont must be set to window
  1676. font. It will be modified properly.
  1677. */
  1678. void CalculateFontAndBitmapStuff( int vspacing );
  1679. wxRect GetEditorWidgetRect( wxPGProperty* p, int column ) const;
  1680. void CorrectEditorWidgetSizeX();
  1681. /** Called in RecalculateVirtualSize() to reposition control
  1682. on virtual height changes.
  1683. */
  1684. void CorrectEditorWidgetPosY();
  1685. int DoDrawItems( wxDC& dc,
  1686. const wxRect* itemsRect,
  1687. bool isBuffered ) const;
  1688. /** Draws an expand/collapse (ie. +/-) button.
  1689. */
  1690. virtual void DrawExpanderButton( wxDC& dc, const wxRect& rect,
  1691. wxPGProperty* property ) const;
  1692. /** Draws items from topitemy to bottomitemy */
  1693. void DrawItems( wxDC& dc,
  1694. unsigned int topItemY,
  1695. unsigned int bottomItemY,
  1696. const wxRect* itemsRect = NULL );
  1697. // Translate wxKeyEvent to wxPG_ACTION_XXX
  1698. int KeyEventToActions(wxKeyEvent &event, int* pSecond) const;
  1699. int KeyEventToAction(wxKeyEvent &event) const
  1700. {
  1701. return KeyEventToActions(event, NULL);
  1702. }
  1703. void ImprovedClientToScreen( int* px, int* py );
  1704. // Called by focus event handlers. newFocused is the window that becomes
  1705. // focused.
  1706. void HandleFocusChange( wxWindow* newFocused );
  1707. /** Reloads all non-customized colours from system settings. */
  1708. void RegainColours();
  1709. virtual bool DoEditorValidate();
  1710. // Similar to DoSelectProperty() but also works on columns
  1711. // other than 1. Does not active editor if column is not
  1712. // editable.
  1713. bool DoSelectAndEdit( wxPGProperty* prop,
  1714. unsigned int colIndex,
  1715. unsigned int selFlags );
  1716. void DoSetSelection( const wxArrayPGProperty& newSelection,
  1717. int selFlags = 0 );
  1718. void DoSetSplitterPosition( int newxpos,
  1719. int splitterIndex = 0,
  1720. int flags = wxPG_SPLITTER_REFRESH );
  1721. bool DoAddToSelection( wxPGProperty* prop,
  1722. int selFlags = 0 );
  1723. bool DoRemoveFromSelection( wxPGProperty* prop,
  1724. int selFlags = 0 );
  1725. void DoBeginLabelEdit( unsigned int colIndex, int selFlags = 0 );
  1726. void DoEndLabelEdit( bool commit, int selFlags = 0 );
  1727. void OnLabelEditorEnterPress( wxCommandEvent& event );
  1728. void OnLabelEditorKeyPress( wxKeyEvent& event );
  1729. wxPGProperty* DoGetItemAtY( int y ) const;
  1730. void DestroyEditorWnd( wxWindow* wnd );
  1731. void FreeEditors();
  1732. virtual bool DoExpand( wxPGProperty* p, bool sendEvent = false );
  1733. virtual bool DoCollapse( wxPGProperty* p, bool sendEvent = false );
  1734. // Returns nearest paint visible property (such that will be painted unless
  1735. // window is scrolled or resized). If given property is paint visible, then
  1736. // it itself will be returned.
  1737. wxPGProperty* GetNearestPaintVisible( wxPGProperty* p ) const;
  1738. static void RegisterDefaultEditors();
  1739. // Sets up basic event handling for child control
  1740. void SetupChildEventHandling( wxWindow* wnd );
  1741. void CustomSetCursor( int type, bool override = false );
  1742. /**
  1743. Repositions scrollbar and underlying panel according to changed virtual
  1744. size.
  1745. */
  1746. void RecalculateVirtualSize( int forceXPos = -1 );
  1747. void SetEditorAppearance( const wxPGCell& cell,
  1748. bool unspecified = false );
  1749. void ResetEditorAppearance()
  1750. {
  1751. wxPGCell cell;
  1752. cell.SetEmptyData();
  1753. SetEditorAppearance(cell, false);
  1754. }
  1755. void PrepareAfterItemsAdded();
  1756. /**
  1757. Send event from the property grid.
  1758. Omit the wxPG_SEL_NOVALIDATE flag to allow vetoing the event
  1759. */
  1760. bool SendEvent( int eventType, wxPGProperty* p,
  1761. wxVariant* pValue = NULL,
  1762. unsigned int selFlags = wxPG_SEL_NOVALIDATE,
  1763. unsigned int column = 1 );
  1764. // This function only moves focus to the wxPropertyGrid if it already
  1765. // was on one of its child controls.
  1766. void SetFocusOnCanvas();
  1767. bool DoHideProperty( wxPGProperty* p, bool hide, int flags );
  1768. private:
  1769. bool ButtonTriggerKeyTest( int action, wxKeyEvent& event );
  1770. DECLARE_EVENT_TABLE()
  1771. };
  1772. // -----------------------------------------------------------------------
  1773. //
  1774. // Bunch of inlines that need to resolved after all classes have been defined.
  1775. //
  1776. inline bool wxPropertyGridPageState::IsDisplayed() const
  1777. {
  1778. return ( this == m_pPropGrid->GetState() );
  1779. }
  1780. inline unsigned int wxPropertyGridPageState::GetActualVirtualHeight() const
  1781. {
  1782. return DoGetRoot()->GetChildrenHeight(GetGrid()->GetRowHeight());
  1783. }
  1784. inline wxString wxPGProperty::GetHintText() const
  1785. {
  1786. wxVariant vHintText = GetAttribute(wxPGGlobalVars->m_strHint);
  1787. #if wxPG_COMPATIBILITY_1_4
  1788. // Try the old, deprecated "InlineHelp"
  1789. if ( vHintText.IsNull() )
  1790. vHintText = GetAttribute(wxPGGlobalVars->m_strInlineHelp);
  1791. #endif
  1792. if ( !vHintText.IsNull() )
  1793. return vHintText.GetString();
  1794. return wxEmptyString;
  1795. }
  1796. inline int wxPGProperty::GetDisplayedCommonValueCount() const
  1797. {
  1798. if ( HasFlag(wxPG_PROP_USES_COMMON_VALUE) )
  1799. {
  1800. wxPropertyGrid* pg = GetGrid();
  1801. if ( pg )
  1802. return (int) pg->GetCommonValueCount();
  1803. }
  1804. return 0;
  1805. }
  1806. inline void wxPGProperty::SetDefaultValue( wxVariant& value )
  1807. {
  1808. SetAttribute(wxPG_ATTR_DEFAULT_VALUE, value);
  1809. }
  1810. inline void wxPGProperty::SetEditor( const wxString& editorName )
  1811. {
  1812. m_customEditor = wxPropertyGridInterface::GetEditorByName(editorName);
  1813. }
  1814. inline bool wxPGProperty::SetMaxLength( int maxLen )
  1815. {
  1816. return GetGrid()->SetPropertyMaxLength(this,maxLen);
  1817. }
  1818. // -----------------------------------------------------------------------
  1819. #define wxPG_BASE_EVT_PRE_ID 1775
  1820. #ifndef SWIG
  1821. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_SELECTED, wxPropertyGridEvent );
  1822. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_CHANGING, wxPropertyGridEvent );
  1823. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_CHANGED, wxPropertyGridEvent );
  1824. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_HIGHLIGHTED, wxPropertyGridEvent );
  1825. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_RIGHT_CLICK, wxPropertyGridEvent );
  1826. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_PAGE_CHANGED, wxPropertyGridEvent );
  1827. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_ITEM_COLLAPSED, wxPropertyGridEvent );
  1828. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_ITEM_EXPANDED, wxPropertyGridEvent );
  1829. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_DOUBLE_CLICK, wxPropertyGridEvent );
  1830. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID,
  1831. wxEVT_PG_LABEL_EDIT_BEGIN, wxPropertyGridEvent );
  1832. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID,
  1833. wxEVT_PG_LABEL_EDIT_ENDING, wxPropertyGridEvent );
  1834. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID,
  1835. wxEVT_PG_COL_BEGIN_DRAG, wxPropertyGridEvent );
  1836. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID,
  1837. wxEVT_PG_COL_DRAGGING, wxPropertyGridEvent );
  1838. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID,
  1839. wxEVT_PG_COL_END_DRAG, wxPropertyGridEvent );
  1840. #else
  1841. enum {
  1842. wxEVT_PG_SELECTED = wxPG_BASE_EVT_PRE_ID,
  1843. wxEVT_PG_CHANGING,
  1844. wxEVT_PG_CHANGED,
  1845. wxEVT_PG_HIGHLIGHTED,
  1846. wxEVT_PG_RIGHT_CLICK,
  1847. wxEVT_PG_PAGE_CHANGED,
  1848. wxEVT_PG_ITEM_COLLAPSED,
  1849. wxEVT_PG_ITEM_EXPANDED,
  1850. wxEVT_PG_DOUBLE_CLICK,
  1851. wxEVT_PG_LABEL_EDIT_BEGIN,
  1852. wxEVT_PG_LABEL_EDIT_ENDING,
  1853. wxEVT_PG_COL_BEGIN_DRAG,
  1854. wxEVT_PG_COL_DRAGGING,
  1855. wxEVT_PG_COL_END_DRAG
  1856. };
  1857. #endif
  1858. #define wxPG_BASE_EVT_TYPE wxEVT_PG_SELECTED
  1859. #define wxPG_MAX_EVT_TYPE (wxPG_BASE_EVT_TYPE+30)
  1860. #ifndef SWIG
  1861. typedef void (wxEvtHandler::*wxPropertyGridEventFunction)(wxPropertyGridEvent&);
  1862. #define EVT_PG_SELECTED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_SELECTED, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
  1863. #define EVT_PG_CHANGING(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_CHANGING, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
  1864. #define EVT_PG_CHANGED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_CHANGED, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
  1865. #define EVT_PG_HIGHLIGHTED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_HIGHLIGHTED, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
  1866. #define EVT_PG_RIGHT_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_RIGHT_CLICK, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
  1867. #define EVT_PG_DOUBLE_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_DOUBLE_CLICK, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
  1868. #define EVT_PG_PAGE_CHANGED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_PAGE_CHANGED, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
  1869. #define EVT_PG_ITEM_COLLAPSED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_ITEM_COLLAPSED, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
  1870. #define EVT_PG_ITEM_EXPANDED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_ITEM_EXPANDED, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
  1871. #define EVT_PG_LABEL_EDIT_BEGIN(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_LABEL_EDIT_BEGIN, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
  1872. #define EVT_PG_LABEL_EDIT_ENDING(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_LABEL_EDIT_ENDING, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
  1873. #define EVT_PG_COL_BEGIN_DRAG(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_COL_BEGIN_DRAG, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
  1874. #define EVT_PG_COL_DRAGGING(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_COL_DRAGGING, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
  1875. #define EVT_PG_COL_END_DRAG(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_COL_END_DRAG, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
  1876. #define wxPropertyGridEventHandler(fn) \
  1877. wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn )
  1878. #endif
  1879. /** @class wxPropertyGridEvent
  1880. A propertygrid event holds information about events associated with
  1881. wxPropertyGrid objects.
  1882. @library{wxpropgrid}
  1883. @category{propgrid}
  1884. */
  1885. class WXDLLIMPEXP_PROPGRID wxPropertyGridEvent : public wxCommandEvent
  1886. {
  1887. public:
  1888. /** Constructor. */
  1889. wxPropertyGridEvent(wxEventType commandType=0, int id=0);
  1890. /** Copy constructor. */
  1891. wxPropertyGridEvent(const wxPropertyGridEvent& event);
  1892. /** Destructor. */
  1893. ~wxPropertyGridEvent();
  1894. /** Copyer. */
  1895. virtual wxEvent* Clone() const;
  1896. /**
  1897. Returns the column index associated with this event.
  1898. For the column dragging events, it is the column to the left
  1899. of the splitter being dragged
  1900. */
  1901. unsigned int GetColumn() const
  1902. {
  1903. return m_column;
  1904. }
  1905. wxPGProperty* GetMainParent() const
  1906. {
  1907. wxASSERT(m_property);
  1908. return m_property->GetMainParent();
  1909. }
  1910. /** Returns id of associated property. */
  1911. wxPGProperty* GetProperty() const
  1912. {
  1913. return m_property;
  1914. }
  1915. wxPGValidationInfo& GetValidationInfo()
  1916. {
  1917. wxASSERT(m_validationInfo);
  1918. return *m_validationInfo;
  1919. }
  1920. /** Returns true if you can veto the action that the event is signaling.
  1921. */
  1922. bool CanVeto() const { return m_canVeto; }
  1923. /**
  1924. Call this from your event handler to veto action that the event is
  1925. signaling.
  1926. You can only veto a shutdown if wxPropertyGridEvent::CanVeto returns
  1927. true.
  1928. @remarks
  1929. Currently only wxEVT_PG_CHANGING supports vetoing.
  1930. */
  1931. void Veto( bool veto = true ) { m_wasVetoed = veto; }
  1932. /**
  1933. Returns name of the associated property.
  1934. @remarks Property name is stored in event, so it remains
  1935. accessible even after the associated property or
  1936. the property grid has been deleted.
  1937. */
  1938. wxString GetPropertyName() const
  1939. {
  1940. return m_propertyName;
  1941. }
  1942. /**
  1943. Returns value of the associated property. Works for all event
  1944. types, but for wxEVT_PG_CHANGING this member function returns
  1945. the value that is pending, so you can call Veto() if the
  1946. value is not satisfactory.
  1947. @remarks Property value is stored in event, so it remains
  1948. accessible even after the associated property or
  1949. the property grid has been deleted.
  1950. */
  1951. wxVariant GetPropertyValue() const
  1952. {
  1953. if ( m_validationInfo )
  1954. return m_validationInfo->GetValue();
  1955. return m_value;
  1956. }
  1957. /**
  1958. Returns value of the associated property.
  1959. @see GetPropertyValue
  1960. */
  1961. wxVariant GetValue() const
  1962. {
  1963. return GetPropertyValue();
  1964. }
  1965. /**
  1966. Set override validation failure behaviour.
  1967. Only effective if Veto was also called, and only allowed if event type
  1968. is wxEVT_PG_CHANGING.
  1969. */
  1970. void SetValidationFailureBehavior( wxPGVFBFlags flags )
  1971. {
  1972. wxASSERT( GetEventType() == wxEVT_PG_CHANGING );
  1973. m_validationInfo->SetFailureBehavior( flags );
  1974. }
  1975. /** Sets custom failure message for this time only. Only applies if
  1976. wxPG_VFB_SHOW_MESSAGE is set in validation failure flags.
  1977. */
  1978. void SetValidationFailureMessage( const wxString& message )
  1979. {
  1980. wxASSERT( GetEventType() == wxEVT_PG_CHANGING );
  1981. m_validationInfo->SetFailureMessage( message );
  1982. }
  1983. wxPGVFBFlags GetValidationFailureBehavior() const
  1984. {
  1985. wxASSERT( GetEventType() == wxEVT_PG_CHANGING );
  1986. return m_validationInfo->GetFailureBehavior();
  1987. }
  1988. void SetColumn( unsigned int column )
  1989. {
  1990. m_column = column;
  1991. }
  1992. void SetCanVeto( bool canVeto ) { m_canVeto = canVeto; }
  1993. bool WasVetoed() const { return m_wasVetoed; }
  1994. /** Changes the associated property. */
  1995. void SetProperty( wxPGProperty* p )
  1996. {
  1997. m_property = p;
  1998. if ( p )
  1999. m_propertyName = p->GetName();
  2000. }
  2001. void SetPropertyValue( wxVariant value )
  2002. {
  2003. m_value = value;
  2004. }
  2005. void SetPropertyGrid( wxPropertyGrid* pg )
  2006. {
  2007. m_pg = pg;
  2008. OnPropertyGridSet();
  2009. }
  2010. void SetupValidationInfo()
  2011. {
  2012. wxASSERT(m_pg);
  2013. wxASSERT( GetEventType() == wxEVT_PG_CHANGING );
  2014. m_validationInfo = &m_pg->GetValidationInfo();
  2015. m_value = m_validationInfo->GetValue();
  2016. }
  2017. private:
  2018. void Init();
  2019. void OnPropertyGridSet();
  2020. DECLARE_DYNAMIC_CLASS(wxPropertyGridEvent)
  2021. wxPGProperty* m_property;
  2022. wxPropertyGrid* m_pg;
  2023. wxPGValidationInfo* m_validationInfo;
  2024. wxString m_propertyName;
  2025. wxVariant m_value;
  2026. unsigned int m_column;
  2027. bool m_canVeto;
  2028. bool m_wasVetoed;
  2029. };
  2030. // -----------------------------------------------------------------------
  2031. /** @class wxPropertyGridPopulator
  2032. @ingroup classes
  2033. Allows populating wxPropertyGrid from arbitrary text source.
  2034. */
  2035. class WXDLLIMPEXP_PROPGRID wxPropertyGridPopulator
  2036. {
  2037. public:
  2038. /** Default constructor.
  2039. */
  2040. wxPropertyGridPopulator();
  2041. /** Destructor. */
  2042. virtual ~wxPropertyGridPopulator();
  2043. void SetState( wxPropertyGridPageState* state );
  2044. void SetGrid( wxPropertyGrid* pg );
  2045. /** Appends a new property under bottommost parent.
  2046. @param propClass
  2047. Property class as string.
  2048. */
  2049. wxPGProperty* Add( const wxString& propClass,
  2050. const wxString& propLabel,
  2051. const wxString& propName,
  2052. const wxString* propValue,
  2053. wxPGChoices* pChoices = NULL );
  2054. /**
  2055. Pushes property to the back of parent array (ie it becomes bottommost
  2056. parent), and starts scanning/adding children for it.
  2057. When finished, parent array is returned to the original state.
  2058. */
  2059. void AddChildren( wxPGProperty* property );
  2060. /** Adds attribute to the bottommost property.
  2061. @param type
  2062. Allowed values: "string", (same as string), "int", "bool". Empty string
  2063. mean autodetect.
  2064. */
  2065. bool AddAttribute( const wxString& name,
  2066. const wxString& type,
  2067. const wxString& value );
  2068. /** Called once in AddChildren.
  2069. */
  2070. virtual void DoScanForChildren() = 0;
  2071. /**
  2072. Returns id of parent property for which children can currently be
  2073. added.
  2074. */
  2075. wxPGProperty* GetCurParent() const
  2076. {
  2077. return (wxPGProperty*) m_propHierarchy[m_propHierarchy.size()-1];
  2078. }
  2079. wxPropertyGridPageState* GetState() { return m_state; }
  2080. const wxPropertyGridPageState* GetState() const { return m_state; }
  2081. /** Like wxString::ToLong, except allows N% in addition of N.
  2082. */
  2083. static bool ToLongPCT( const wxString& s, long* pval, long max );
  2084. /** Parses strings of format "choice1"[=value1] ... "choiceN"[=valueN] into
  2085. wxPGChoices. Registers parsed result using idString (if not empty).
  2086. Also, if choices with given id already registered, then don't parse but
  2087. return those choices instead.
  2088. */
  2089. wxPGChoices ParseChoices( const wxString& choicesString,
  2090. const wxString& idString );
  2091. /** Implement in derived class to do custom process when an error occurs.
  2092. Default implementation uses wxLogError.
  2093. */
  2094. virtual void ProcessError( const wxString& msg );
  2095. protected:
  2096. /** Used property grid. */
  2097. wxPropertyGrid* m_pg;
  2098. /** Used property grid state. */
  2099. wxPropertyGridPageState* m_state;
  2100. /** Tree-hierarchy of added properties (that can have children). */
  2101. wxArrayPGProperty m_propHierarchy;
  2102. /** Hashmap for string-id to wxPGChoicesData mapping. */
  2103. wxPGHashMapS2P m_dictIdChoices;
  2104. };
  2105. // -----------------------------------------------------------------------
  2106. //
  2107. // Undefine macros that are not needed outside propertygrid sources
  2108. //
  2109. #ifndef __wxPG_SOURCE_FILE__
  2110. #undef wxPG_FL_DESC_REFRESH_REQUIRED
  2111. #undef wxPG_FL_SCROLLBAR_DETECTED
  2112. #undef wxPG_FL_CREATEDSTATE
  2113. #undef wxPG_FL_NOSTATUSBARHELP
  2114. #undef wxPG_FL_SCROLLED
  2115. #undef wxPG_FL_FOCUS_INSIDE_CHILD
  2116. #undef wxPG_FL_FOCUS_INSIDE
  2117. #undef wxPG_FL_MOUSE_INSIDE_CHILD
  2118. #undef wxPG_FL_CUR_USES_CUSTOM_IMAGE
  2119. #undef wxPG_FL_PRIMARY_FILLS_ENTIRE
  2120. #undef wxPG_FL_VALUE_MODIFIED
  2121. #undef wxPG_FL_MOUSE_INSIDE
  2122. #undef wxPG_FL_FOCUSED
  2123. #undef wxPG_FL_MOUSE_CAPTURED
  2124. #undef wxPG_FL_INITIALIZED
  2125. #undef wxPG_FL_ACTIVATION_BY_CLICK
  2126. #undef wxPG_SUPPORT_TOOLTIPS
  2127. #undef wxPG_ICON_WIDTH
  2128. #undef wxPG_USE_RENDERER_NATIVE
  2129. // Following are needed by the manager headers
  2130. // #undef const wxString&
  2131. #endif
  2132. // -----------------------------------------------------------------------
  2133. #endif
  2134. #endif // _WX_PROPGRID_PROPGRID_H_