propgrid.cpp 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: samples/propgrid/propgrid.cpp
  3. // Purpose: wxPropertyGrid sample
  4. // Author: Jaakko Salli
  5. // Modified by:
  6. // Created: 2004-09-25
  7. // Copyright: (c) Jaakko Salli
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. //
  11. //
  12. // NOTES
  13. //
  14. // * Examples of custom property classes are in sampleprops.cpp.
  15. //
  16. // * Additional ones can be found below.
  17. //
  18. // * Currently there is no example of a custom property editor. However,
  19. // SpinCtrl editor sample is well-commented. It can be found in
  20. // src/propgrid/advprops.cpp.
  21. //
  22. // * To find code that populates the grid with properties, search for
  23. // string "::Populate".
  24. //
  25. // * To find code that handles property grid changes, search for string
  26. // "::OnPropertyGridChange".
  27. //
  28. // For compilers that support precompilation, includes "wx/wx.h".
  29. #include "wx/wxprec.h"
  30. #ifdef __BORLANDC__
  31. #pragma hdrstop
  32. #endif
  33. // for all others, include the necessary headers (this file is usually all you
  34. // need because it includes almost all "standard" wxWidgets headers)
  35. #ifndef WX_PRECOMP
  36. #include "wx/wx.h"
  37. #endif
  38. #if !wxUSE_PROPGRID
  39. #error "Please set wxUSE_PROPGRID to 1 and rebuild the library."
  40. #endif
  41. #include <wx/numdlg.h>
  42. // -----------------------------------------------------------------------
  43. // Main propertygrid header.
  44. #include <wx/propgrid/propgrid.h>
  45. // Extra property classes.
  46. #include <wx/propgrid/advprops.h>
  47. // This defines wxPropertyGridManager.
  48. #include <wx/propgrid/manager.h>
  49. #include "propgrid.h"
  50. #include "sampleprops.h"
  51. #if wxUSE_DATEPICKCTRL
  52. #include <wx/datectrl.h>
  53. #endif
  54. #include <wx/artprov.h>
  55. #ifndef wxHAS_IMAGES_IN_RESOURCES
  56. #include "../sample.xpm"
  57. #endif
  58. #include <wx/popupwin.h>
  59. // -----------------------------------------------------------------------
  60. // wxSampleMultiButtonEditor
  61. // A sample editor class that has multiple buttons.
  62. // -----------------------------------------------------------------------
  63. class wxSampleMultiButtonEditor : public wxPGTextCtrlEditor
  64. {
  65. wxDECLARE_DYNAMIC_CLASS(wxSampleMultiButtonEditor);
  66. public:
  67. wxSampleMultiButtonEditor() {}
  68. virtual ~wxSampleMultiButtonEditor() {}
  69. virtual wxPGWindowList CreateControls( wxPropertyGrid* propGrid,
  70. wxPGProperty* property,
  71. const wxPoint& pos,
  72. const wxSize& sz ) const;
  73. virtual bool OnEvent( wxPropertyGrid* propGrid,
  74. wxPGProperty* property,
  75. wxWindow* ctrl,
  76. wxEvent& event ) const;
  77. };
  78. IMPLEMENT_DYNAMIC_CLASS(wxSampleMultiButtonEditor, wxPGTextCtrlEditor)
  79. wxPGWindowList wxSampleMultiButtonEditor::CreateControls( wxPropertyGrid* propGrid,
  80. wxPGProperty* property,
  81. const wxPoint& pos,
  82. const wxSize& sz ) const
  83. {
  84. // Create and populate buttons-subwindow
  85. wxPGMultiButton* buttons = new wxPGMultiButton( propGrid, sz );
  86. // Add two regular buttons
  87. buttons->Add( "..." );
  88. buttons->Add( "A" );
  89. // Add a bitmap button
  90. buttons->Add( wxArtProvider::GetBitmap(wxART_FOLDER) );
  91. // Create the 'primary' editor control (textctrl in this case)
  92. wxPGWindowList wndList = wxPGTextCtrlEditor::CreateControls
  93. ( propGrid, property, pos,
  94. buttons->GetPrimarySize() );
  95. // Finally, move buttons-subwindow to correct position and make sure
  96. // returned wxPGWindowList contains our custom button list.
  97. buttons->Finalize(propGrid, pos);
  98. wndList.SetSecondary( buttons );
  99. return wndList;
  100. }
  101. bool wxSampleMultiButtonEditor::OnEvent( wxPropertyGrid* propGrid,
  102. wxPGProperty* property,
  103. wxWindow* ctrl,
  104. wxEvent& event ) const
  105. {
  106. if ( event.GetEventType() == wxEVT_BUTTON )
  107. {
  108. wxPGMultiButton* buttons = (wxPGMultiButton*) propGrid->GetEditorControlSecondary();
  109. if ( event.GetId() == buttons->GetButtonId(0) )
  110. {
  111. // Do something when the first button is pressed
  112. wxLogDebug("First button pressed");
  113. return false; // Return false since value did not change
  114. }
  115. if ( event.GetId() == buttons->GetButtonId(1) )
  116. {
  117. // Do something when the second button is pressed
  118. wxMessageBox("Second button pressed");
  119. return false; // Return false since value did not change
  120. }
  121. if ( event.GetId() == buttons->GetButtonId(2) )
  122. {
  123. // Do something when the third button is pressed
  124. wxMessageBox("Third button pressed");
  125. return false; // Return false since value did not change
  126. }
  127. }
  128. return wxPGTextCtrlEditor::OnEvent(propGrid, property, ctrl, event);
  129. }
  130. // -----------------------------------------------------------------------
  131. // Validator for wxValidator use sample
  132. // -----------------------------------------------------------------------
  133. #if wxUSE_VALIDATORS
  134. // wxValidator for testing
  135. class wxInvalidWordValidator : public wxValidator
  136. {
  137. public:
  138. wxInvalidWordValidator( const wxString& invalidWord )
  139. : wxValidator(), m_invalidWord(invalidWord)
  140. {
  141. }
  142. virtual wxObject* Clone() const
  143. {
  144. return new wxInvalidWordValidator(m_invalidWord);
  145. }
  146. virtual bool Validate(wxWindow* WXUNUSED(parent))
  147. {
  148. wxTextCtrl* tc = wxDynamicCast(GetWindow(), wxTextCtrl);
  149. wxCHECK_MSG(tc, true, wxT("validator window must be wxTextCtrl"));
  150. wxString val = tc->GetValue();
  151. if ( val.find(m_invalidWord) == wxString::npos )
  152. return true;
  153. ::wxMessageBox(wxString::Format(wxT("%s is not allowed word"),m_invalidWord.c_str()),
  154. wxT("Validation Failure"));
  155. return false;
  156. }
  157. private:
  158. wxString m_invalidWord;
  159. };
  160. #endif // wxUSE_VALIDATORS
  161. // -----------------------------------------------------------------------
  162. // wxVectorProperty
  163. // -----------------------------------------------------------------------
  164. // See propgridsample.h for wxVector3f class
  165. WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxVector3f)
  166. WX_PG_IMPLEMENT_PROPERTY_CLASS(wxVectorProperty,wxPGProperty,
  167. wxVector3f,const wxVector3f&,TextCtrl)
  168. wxVectorProperty::wxVectorProperty( const wxString& label,
  169. const wxString& name,
  170. const wxVector3f& value )
  171. : wxPGProperty(label,name)
  172. {
  173. SetValue( WXVARIANT(value) );
  174. AddPrivateChild( new wxFloatProperty(wxT("X"),wxPG_LABEL,value.x) );
  175. AddPrivateChild( new wxFloatProperty(wxT("Y"),wxPG_LABEL,value.y) );
  176. AddPrivateChild( new wxFloatProperty(wxT("Z"),wxPG_LABEL,value.z) );
  177. }
  178. wxVectorProperty::~wxVectorProperty() { }
  179. void wxVectorProperty::RefreshChildren()
  180. {
  181. if ( !GetChildCount() ) return;
  182. const wxVector3f& vector = wxVector3fRefFromVariant(m_value);
  183. Item(0)->SetValue( vector.x );
  184. Item(1)->SetValue( vector.y );
  185. Item(2)->SetValue( vector.z );
  186. }
  187. wxVariant wxVectorProperty::ChildChanged( wxVariant& thisValue,
  188. int childIndex,
  189. wxVariant& childValue ) const
  190. {
  191. wxVector3f vector;
  192. vector << thisValue;
  193. switch ( childIndex )
  194. {
  195. case 0: vector.x = childValue.GetDouble(); break;
  196. case 1: vector.y = childValue.GetDouble(); break;
  197. case 2: vector.z = childValue.GetDouble(); break;
  198. }
  199. wxVariant newVariant;
  200. newVariant << vector;
  201. return newVariant;
  202. }
  203. // -----------------------------------------------------------------------
  204. // wxTriangleProperty
  205. // -----------------------------------------------------------------------
  206. // See propgridsample.h for wxTriangle class
  207. WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxTriangle)
  208. WX_PG_IMPLEMENT_PROPERTY_CLASS(wxTriangleProperty,wxPGProperty,
  209. wxTriangle,const wxTriangle&,TextCtrl)
  210. wxTriangleProperty::wxTriangleProperty( const wxString& label,
  211. const wxString& name,
  212. const wxTriangle& value)
  213. : wxPGProperty(label,name)
  214. {
  215. SetValue( WXVARIANT(value) );
  216. AddPrivateChild( new wxVectorProperty(wxT("A"),wxPG_LABEL,value.a) );
  217. AddPrivateChild( new wxVectorProperty(wxT("B"),wxPG_LABEL,value.b) );
  218. AddPrivateChild( new wxVectorProperty(wxT("C"),wxPG_LABEL,value.c) );
  219. }
  220. wxTriangleProperty::~wxTriangleProperty() { }
  221. void wxTriangleProperty::RefreshChildren()
  222. {
  223. if ( !GetChildCount() ) return;
  224. const wxTriangle& triangle = wxTriangleRefFromVariant(m_value);
  225. Item(0)->SetValue( WXVARIANT(triangle.a) );
  226. Item(1)->SetValue( WXVARIANT(triangle.b) );
  227. Item(2)->SetValue( WXVARIANT(triangle.c) );
  228. }
  229. wxVariant wxTriangleProperty::ChildChanged( wxVariant& thisValue,
  230. int childIndex,
  231. wxVariant& childValue ) const
  232. {
  233. wxTriangle triangle;
  234. triangle << thisValue;
  235. const wxVector3f& vector = wxVector3fRefFromVariant(childValue);
  236. switch ( childIndex )
  237. {
  238. case 0: triangle.a = vector; break;
  239. case 1: triangle.b = vector; break;
  240. case 2: triangle.c = vector; break;
  241. }
  242. wxVariant newVariant;
  243. newVariant << triangle;
  244. return newVariant;
  245. }
  246. // -----------------------------------------------------------------------
  247. // wxSingleChoiceDialogAdapter (wxPGEditorDialogAdapter sample)
  248. // -----------------------------------------------------------------------
  249. class wxSingleChoiceDialogAdapter : public wxPGEditorDialogAdapter
  250. {
  251. public:
  252. wxSingleChoiceDialogAdapter( const wxPGChoices& choices )
  253. : wxPGEditorDialogAdapter(), m_choices(choices)
  254. {
  255. }
  256. virtual bool DoShowDialog( wxPropertyGrid* WXUNUSED(propGrid),
  257. wxPGProperty* WXUNUSED(property) )
  258. {
  259. wxString s = ::wxGetSingleChoice(wxT("Message"),
  260. wxT("Caption"),
  261. m_choices.GetLabels());
  262. if ( !s.empty() )
  263. {
  264. SetValue(s);
  265. return true;
  266. }
  267. return false;
  268. }
  269. protected:
  270. const wxPGChoices& m_choices;
  271. };
  272. class SingleChoiceProperty : public wxStringProperty
  273. {
  274. public:
  275. SingleChoiceProperty( const wxString& label,
  276. const wxString& name = wxPG_LABEL,
  277. const wxString& value = wxEmptyString )
  278. : wxStringProperty(label, name, value)
  279. {
  280. // Prepare choices
  281. m_choices.Add(wxT("Cat"));
  282. m_choices.Add(wxT("Dog"));
  283. m_choices.Add(wxT("Gibbon"));
  284. m_choices.Add(wxT("Otter"));
  285. }
  286. // Set editor to have button
  287. virtual const wxPGEditor* DoGetEditorClass() const
  288. {
  289. return wxPGEditor_TextCtrlAndButton;
  290. }
  291. // Set what happens on button click
  292. virtual wxPGEditorDialogAdapter* GetEditorDialog() const
  293. {
  294. return new wxSingleChoiceDialogAdapter(m_choices);
  295. }
  296. protected:
  297. wxPGChoices m_choices;
  298. };
  299. // -----------------------------------------------------------------------
  300. // Menu IDs
  301. // -----------------------------------------------------------------------
  302. enum
  303. {
  304. PGID = 1,
  305. TCID,
  306. ID_ABOUT,
  307. ID_QUIT,
  308. ID_APPENDPROP,
  309. ID_APPENDCAT,
  310. ID_INSERTPROP,
  311. ID_INSERTCAT,
  312. ID_ENABLE,
  313. ID_SETREADONLY,
  314. ID_HIDE,
  315. ID_DELETE,
  316. ID_DELETER,
  317. ID_DELETEALL,
  318. ID_UNSPECIFY,
  319. ID_ITERATE1,
  320. ID_ITERATE2,
  321. ID_ITERATE3,
  322. ID_ITERATE4,
  323. ID_CLEARMODIF,
  324. ID_FREEZE,
  325. ID_DUMPLIST,
  326. ID_COLOURSCHEME1,
  327. ID_COLOURSCHEME2,
  328. ID_COLOURSCHEME3,
  329. ID_CATCOLOURS,
  330. ID_SETBGCOLOUR,
  331. ID_SETBGCOLOURRECUR,
  332. ID_STATICLAYOUT,
  333. ID_POPULATE1,
  334. ID_POPULATE2,
  335. ID_COLLAPSE,
  336. ID_COLLAPSEALL,
  337. ID_GETVALUES,
  338. ID_SETVALUES,
  339. ID_SETVALUES2,
  340. ID_RUNTESTFULL,
  341. ID_RUNTESTPARTIAL,
  342. ID_FITCOLUMNS,
  343. ID_CHANGEFLAGSITEMS,
  344. ID_TESTINSERTCHOICE,
  345. ID_TESTDELETECHOICE,
  346. ID_INSERTPAGE,
  347. ID_REMOVEPAGE,
  348. ID_SETSPINCTRLEDITOR,
  349. ID_SETPROPERTYVALUE,
  350. ID_TESTREPLACE,
  351. ID_SETCOLUMNS,
  352. ID_TESTXRC,
  353. ID_ENABLECOMMONVALUES,
  354. ID_SELECTSTYLE,
  355. ID_SAVESTATE,
  356. ID_RESTORESTATE,
  357. ID_RUNMINIMAL,
  358. ID_ENABLELABELEDITING,
  359. ID_VETOCOLDRAG,
  360. ID_SHOWHEADER,
  361. ID_ONEXTENDEDKEYNAV,
  362. ID_SHOWPOPUP,
  363. ID_POPUPGRID
  364. };
  365. // -----------------------------------------------------------------------
  366. // Event table
  367. // -----------------------------------------------------------------------
  368. wxBEGIN_EVENT_TABLE(FormMain, wxFrame)
  369. EVT_IDLE(FormMain::OnIdle)
  370. EVT_MOVE(FormMain::OnMove)
  371. EVT_SIZE(FormMain::OnResize)
  372. // This occurs when a property is selected
  373. EVT_PG_SELECTED( PGID, FormMain::OnPropertyGridSelect )
  374. // This occurs when a property value changes
  375. EVT_PG_CHANGED( PGID, FormMain::OnPropertyGridChange )
  376. // This occurs just prior a property value is changed
  377. EVT_PG_CHANGING( PGID, FormMain::OnPropertyGridChanging )
  378. // This occurs when a mouse moves over another property
  379. EVT_PG_HIGHLIGHTED( PGID, FormMain::OnPropertyGridHighlight )
  380. // This occurs when mouse is right-clicked.
  381. EVT_PG_RIGHT_CLICK( PGID, FormMain::OnPropertyGridItemRightClick )
  382. // This occurs when mouse is double-clicked.
  383. EVT_PG_DOUBLE_CLICK( PGID, FormMain::OnPropertyGridItemDoubleClick )
  384. // This occurs when propgridmanager's page changes.
  385. EVT_PG_PAGE_CHANGED( PGID, FormMain::OnPropertyGridPageChange )
  386. // This occurs when user starts editing a property label
  387. EVT_PG_LABEL_EDIT_BEGIN( PGID,
  388. FormMain::OnPropertyGridLabelEditBegin )
  389. // This occurs when user stops editing a property label
  390. EVT_PG_LABEL_EDIT_ENDING( PGID,
  391. FormMain::OnPropertyGridLabelEditEnding )
  392. // This occurs when property's editor button (if any) is clicked.
  393. EVT_BUTTON( PGID, FormMain::OnPropertyGridButtonClick )
  394. EVT_PG_ITEM_COLLAPSED( PGID, FormMain::OnPropertyGridItemCollapse )
  395. EVT_PG_ITEM_EXPANDED( PGID, FormMain::OnPropertyGridItemExpand )
  396. EVT_PG_COL_BEGIN_DRAG( PGID, FormMain::OnPropertyGridColBeginDrag )
  397. EVT_PG_COL_DRAGGING( PGID, FormMain::OnPropertyGridColDragging )
  398. EVT_PG_COL_END_DRAG( PGID, FormMain::OnPropertyGridColEndDrag )
  399. EVT_TEXT( PGID, FormMain::OnPropertyGridTextUpdate )
  400. //
  401. // Rest of the events are not property grid specific
  402. EVT_KEY_DOWN( FormMain::OnPropertyGridKeyEvent )
  403. EVT_KEY_UP( FormMain::OnPropertyGridKeyEvent )
  404. EVT_MENU( ID_APPENDPROP, FormMain::OnAppendPropClick )
  405. EVT_MENU( ID_APPENDCAT, FormMain::OnAppendCatClick )
  406. EVT_MENU( ID_INSERTPROP, FormMain::OnInsertPropClick )
  407. EVT_MENU( ID_INSERTCAT, FormMain::OnInsertCatClick )
  408. EVT_MENU( ID_DELETE, FormMain::OnDelPropClick )
  409. EVT_MENU( ID_DELETER, FormMain::OnDelPropRClick )
  410. EVT_MENU( ID_UNSPECIFY, FormMain::OnMisc )
  411. EVT_MENU( ID_DELETEALL, FormMain::OnClearClick )
  412. EVT_MENU( ID_ENABLE, FormMain::OnEnableDisable )
  413. EVT_MENU( ID_SETREADONLY, FormMain::OnSetReadOnly )
  414. EVT_MENU( ID_HIDE, FormMain::OnHide )
  415. EVT_MENU( ID_ITERATE1, FormMain::OnIterate1Click )
  416. EVT_MENU( ID_ITERATE2, FormMain::OnIterate2Click )
  417. EVT_MENU( ID_ITERATE3, FormMain::OnIterate3Click )
  418. EVT_MENU( ID_ITERATE4, FormMain::OnIterate4Click )
  419. EVT_MENU( ID_ONEXTENDEDKEYNAV, FormMain::OnExtendedKeyNav )
  420. EVT_MENU( ID_SETBGCOLOUR, FormMain::OnSetBackgroundColour )
  421. EVT_MENU( ID_SETBGCOLOURRECUR, FormMain::OnSetBackgroundColour )
  422. EVT_MENU( ID_CLEARMODIF, FormMain::OnClearModifyStatusClick )
  423. EVT_MENU( ID_FREEZE, FormMain::OnFreezeClick )
  424. EVT_MENU( ID_ENABLELABELEDITING, FormMain::OnEnableLabelEditing )
  425. EVT_MENU( ID_SHOWHEADER, FormMain::OnShowHeader )
  426. EVT_MENU( ID_DUMPLIST, FormMain::OnDumpList )
  427. EVT_MENU( ID_COLOURSCHEME1, FormMain::OnColourScheme )
  428. EVT_MENU( ID_COLOURSCHEME2, FormMain::OnColourScheme )
  429. EVT_MENU( ID_COLOURSCHEME3, FormMain::OnColourScheme )
  430. EVT_MENU( ID_COLOURSCHEME4, FormMain::OnColourScheme )
  431. EVT_MENU( ID_ABOUT, FormMain::OnAbout )
  432. EVT_MENU( ID_QUIT, FormMain::OnCloseClick )
  433. EVT_MENU( ID_CATCOLOURS, FormMain::OnCatColours )
  434. EVT_MENU( ID_SETCOLUMNS, FormMain::OnSetColumns )
  435. EVT_MENU( ID_TESTXRC, FormMain::OnTestXRC )
  436. EVT_MENU( ID_ENABLECOMMONVALUES, FormMain::OnEnableCommonValues )
  437. EVT_MENU( ID_SELECTSTYLE, FormMain::OnSelectStyle )
  438. EVT_MENU( ID_STATICLAYOUT, FormMain::OnMisc )
  439. EVT_MENU( ID_COLLAPSE, FormMain::OnMisc )
  440. EVT_MENU( ID_COLLAPSEALL, FormMain::OnMisc )
  441. EVT_MENU( ID_POPULATE1, FormMain::OnPopulateClick )
  442. EVT_MENU( ID_POPULATE2, FormMain::OnPopulateClick )
  443. EVT_MENU( ID_GETVALUES, FormMain::OnMisc )
  444. EVT_MENU( ID_SETVALUES, FormMain::OnMisc )
  445. EVT_MENU( ID_SETVALUES2, FormMain::OnMisc )
  446. EVT_MENU( ID_FITCOLUMNS, FormMain::OnFitColumnsClick )
  447. EVT_MENU( ID_CHANGEFLAGSITEMS, FormMain::OnChangeFlagsPropItemsClick )
  448. EVT_MENU( ID_RUNTESTFULL, FormMain::OnMisc )
  449. EVT_MENU( ID_RUNTESTPARTIAL, FormMain::OnMisc )
  450. EVT_MENU( ID_TESTINSERTCHOICE, FormMain::OnInsertChoice )
  451. EVT_MENU( ID_TESTDELETECHOICE, FormMain::OnDeleteChoice )
  452. EVT_MENU( ID_INSERTPAGE, FormMain::OnInsertPage )
  453. EVT_MENU( ID_REMOVEPAGE, FormMain::OnRemovePage )
  454. EVT_MENU( ID_SAVESTATE, FormMain::OnSaveState )
  455. EVT_MENU( ID_RESTORESTATE, FormMain::OnRestoreState )
  456. EVT_MENU( ID_SETSPINCTRLEDITOR, FormMain::OnSetSpinCtrlEditorClick )
  457. EVT_MENU( ID_TESTREPLACE, FormMain::OnTestReplaceClick )
  458. EVT_MENU( ID_SETPROPERTYVALUE, FormMain::OnSetPropertyValue )
  459. EVT_MENU( ID_RUNMINIMAL, FormMain::OnRunMinimalClick )
  460. EVT_CONTEXT_MENU( FormMain::OnContextMenu )
  461. EVT_BUTTON(ID_SHOWPOPUP, FormMain::OnShowPopup)
  462. wxEND_EVENT_TABLE()
  463. // -----------------------------------------------------------------------
  464. void FormMain::OnMove( wxMoveEvent& event )
  465. {
  466. if ( !m_pPropGridManager )
  467. {
  468. // this check is here so the frame layout can be tested
  469. // without creating propertygrid
  470. event.Skip();
  471. return;
  472. }
  473. // Update position properties
  474. int x, y;
  475. GetPosition(&x,&y);
  476. wxPGProperty* id;
  477. // Must check if properties exist (as they may be deleted).
  478. // Using m_pPropGridManager, we can scan all pages automatically.
  479. id = m_pPropGridManager->GetPropertyByName( wxT("X") );
  480. if ( id )
  481. m_pPropGridManager->SetPropertyValue( id, x );
  482. id = m_pPropGridManager->GetPropertyByName( wxT("Y") );
  483. if ( id )
  484. m_pPropGridManager->SetPropertyValue( id, y );
  485. id = m_pPropGridManager->GetPropertyByName( wxT("Position") );
  486. if ( id )
  487. m_pPropGridManager->SetPropertyValue( id, WXVARIANT(wxPoint(x,y)) );
  488. // Should always call event.Skip() in frame's MoveEvent handler
  489. event.Skip();
  490. }
  491. // -----------------------------------------------------------------------
  492. void FormMain::OnResize( wxSizeEvent& event )
  493. {
  494. if ( !m_pPropGridManager )
  495. {
  496. // this check is here so the frame layout can be tested
  497. // without creating propertygrid
  498. event.Skip();
  499. return;
  500. }
  501. // Update size properties
  502. int w, h;
  503. GetSize(&w,&h);
  504. wxPGProperty* id;
  505. wxPGProperty* p;
  506. // Must check if properties exist (as they may be deleted).
  507. // Using m_pPropGridManager, we can scan all pages automatically.
  508. p = m_pPropGridManager->GetPropertyByName( wxT("Width") );
  509. if ( p && !p->IsValueUnspecified() )
  510. m_pPropGridManager->SetPropertyValue( p, w );
  511. p = m_pPropGridManager->GetPropertyByName( wxT("Height") );
  512. if ( p && !p->IsValueUnspecified() )
  513. m_pPropGridManager->SetPropertyValue( p, h );
  514. id = m_pPropGridManager->GetPropertyByName ( wxT("Size") );
  515. if ( id )
  516. m_pPropGridManager->SetPropertyValue( id, WXVARIANT(wxSize(w,h)) );
  517. // Should always call event.Skip() in frame's SizeEvent handler
  518. event.Skip();
  519. }
  520. // -----------------------------------------------------------------------
  521. void FormMain::OnPropertyGridChanging( wxPropertyGridEvent& event )
  522. {
  523. wxPGProperty* p = event.GetProperty();
  524. if ( p->GetName() == wxT("Font") )
  525. {
  526. int res =
  527. wxMessageBox(wxString::Format(wxT("'%s' is about to change (to variant of type '%s')\n\nAllow or deny?"),
  528. p->GetName().c_str(),event.GetValue().GetType().c_str()),
  529. wxT("Testing wxEVT_PG_CHANGING"), wxYES_NO, m_pPropGridManager);
  530. if ( res == wxNO )
  531. {
  532. wxASSERT(event.CanVeto());
  533. event.Veto();
  534. // Since we ask a question, it is better if we omit any validation
  535. // failure behaviour.
  536. event.SetValidationFailureBehavior(0);
  537. }
  538. }
  539. }
  540. //
  541. // Note how we use three types of value getting in this method:
  542. // A) event.GetPropertyValueAsXXX
  543. // B) event.GetPropertValue, and then variant's GetXXX
  544. // C) grid's GetPropertyValueAsXXX(id)
  545. //
  546. void FormMain::OnPropertyGridChange( wxPropertyGridEvent& event )
  547. {
  548. wxPGProperty* property = event.GetProperty();
  549. const wxString& name = property->GetName();
  550. // Properties store values internally as wxVariants, but it is preferred
  551. // to use the more modern wxAny at the interface level
  552. wxAny value = property->GetValue();
  553. // Don't handle 'unspecified' values
  554. if ( value.IsNull() )
  555. return;
  556. //
  557. // FIXME-VC6: In order to compile on Visual C++ 6.0, wxANY_AS()
  558. // macro is used. Unless you want to support this old
  559. // compiler in your own code, you can use the more
  560. // nicer form value.As<FOO>() instead of
  561. // wxANY_AS(value, FOO).
  562. //
  563. // Some settings are disabled outside Windows platform
  564. if ( name == wxT("X") )
  565. SetSize( wxANY_AS(value, int), -1, -1, -1, wxSIZE_USE_EXISTING );
  566. else if ( name == wxT("Y") )
  567. // wxPGVariantToInt is safe long int value getter
  568. SetSize ( -1, wxANY_AS(value, int), -1, -1, wxSIZE_USE_EXISTING );
  569. else if ( name == wxT("Width") )
  570. SetSize ( -1, -1, wxANY_AS(value, int), -1, wxSIZE_USE_EXISTING );
  571. else if ( name == wxT("Height") )
  572. SetSize ( -1, -1, -1, wxANY_AS(value, int), wxSIZE_USE_EXISTING );
  573. else if ( name == wxT("Label") )
  574. {
  575. SetTitle( wxANY_AS(value, wxString) );
  576. }
  577. else if ( name == wxT("Password") )
  578. {
  579. static int pwdMode = 0;
  580. //m_pPropGridManager->SetPropertyAttribute(property, wxPG_STRING_PASSWORD, (long)pwdMode);
  581. pwdMode++;
  582. pwdMode &= 1;
  583. }
  584. else
  585. if ( name == wxT("Font") )
  586. {
  587. wxFont font = wxANY_AS(value, wxFont);
  588. wxASSERT( font.IsOk() );
  589. m_pPropGridManager->SetFont( font );
  590. }
  591. else
  592. if ( name == wxT("Margin Colour") )
  593. {
  594. wxColourPropertyValue cpv = wxANY_AS(value, wxColourPropertyValue);
  595. m_pPropGridManager->GetGrid()->SetMarginColour( cpv.m_colour );
  596. }
  597. else if ( name == wxT("Cell Colour") )
  598. {
  599. wxColourPropertyValue cpv = wxANY_AS(value, wxColourPropertyValue);
  600. m_pPropGridManager->GetGrid()->SetCellBackgroundColour( cpv.m_colour );
  601. }
  602. else if ( name == wxT("Line Colour") )
  603. {
  604. wxColourPropertyValue cpv = wxANY_AS(value, wxColourPropertyValue);
  605. m_pPropGridManager->GetGrid()->SetLineColour( cpv.m_colour );
  606. }
  607. else if ( name == wxT("Cell Text Colour") )
  608. {
  609. wxColourPropertyValue cpv = wxANY_AS(value, wxColourPropertyValue);
  610. m_pPropGridManager->GetGrid()->SetCellTextColour( cpv.m_colour );
  611. }
  612. }
  613. // -----------------------------------------------------------------------
  614. void FormMain::OnPropertyGridSelect( wxPropertyGridEvent& event )
  615. {
  616. wxPGProperty* property = event.GetProperty();
  617. if ( property )
  618. {
  619. m_itemEnable->Enable( TRUE );
  620. if ( property->IsEnabled() )
  621. m_itemEnable->SetItemLabel( wxT("Disable") );
  622. else
  623. m_itemEnable->SetItemLabel( wxT("Enable") );
  624. }
  625. else
  626. {
  627. m_itemEnable->Enable( FALSE );
  628. }
  629. #if wxUSE_STATUSBAR
  630. wxPGProperty* prop = event.GetProperty();
  631. wxStatusBar* sb = GetStatusBar();
  632. if ( prop )
  633. {
  634. wxString text(wxT("Selected: "));
  635. text += m_pPropGridManager->GetPropertyLabel( prop );
  636. sb->SetStatusText ( text );
  637. }
  638. #endif
  639. }
  640. // -----------------------------------------------------------------------
  641. void FormMain::OnPropertyGridPageChange( wxPropertyGridEvent& WXUNUSED(event) )
  642. {
  643. #if wxUSE_STATUSBAR
  644. wxStatusBar* sb = GetStatusBar();
  645. wxString text(wxT("Page Changed: "));
  646. text += m_pPropGridManager->GetPageName(m_pPropGridManager->GetSelectedPage());
  647. sb->SetStatusText( text );
  648. #endif
  649. }
  650. // -----------------------------------------------------------------------
  651. void FormMain::OnPropertyGridLabelEditBegin( wxPropertyGridEvent& event )
  652. {
  653. wxLogMessage("wxPG_EVT_LABEL_EDIT_BEGIN(%s)",
  654. event.GetProperty()->GetLabel().c_str());
  655. }
  656. // -----------------------------------------------------------------------
  657. void FormMain::OnPropertyGridLabelEditEnding( wxPropertyGridEvent& event )
  658. {
  659. wxLogMessage("wxPG_EVT_LABEL_EDIT_ENDING(%s)",
  660. event.GetProperty()->GetLabel().c_str());
  661. }
  662. // -----------------------------------------------------------------------
  663. void FormMain::OnPropertyGridHighlight( wxPropertyGridEvent& WXUNUSED(event) )
  664. {
  665. }
  666. // -----------------------------------------------------------------------
  667. void FormMain::OnPropertyGridItemRightClick( wxPropertyGridEvent& event )
  668. {
  669. #if wxUSE_STATUSBAR
  670. wxPGProperty* prop = event.GetProperty();
  671. wxStatusBar* sb = GetStatusBar();
  672. if ( prop )
  673. {
  674. wxString text(wxT("Right-clicked: "));
  675. text += prop->GetLabel();
  676. text += wxT(", name=");
  677. text += m_pPropGridManager->GetPropertyName(prop);
  678. sb->SetStatusText( text );
  679. }
  680. else
  681. {
  682. sb->SetStatusText( wxEmptyString );
  683. }
  684. #endif
  685. }
  686. // -----------------------------------------------------------------------
  687. void FormMain::OnPropertyGridItemDoubleClick( wxPropertyGridEvent& event )
  688. {
  689. #if wxUSE_STATUSBAR
  690. wxPGProperty* prop = event.GetProperty();
  691. wxStatusBar* sb = GetStatusBar();
  692. if ( prop )
  693. {
  694. wxString text(wxT("Double-clicked: "));
  695. text += prop->GetLabel();
  696. text += wxT(", name=");
  697. text += m_pPropGridManager->GetPropertyName(prop);
  698. sb->SetStatusText ( text );
  699. }
  700. else
  701. {
  702. sb->SetStatusText ( wxEmptyString );
  703. }
  704. #endif
  705. }
  706. // -----------------------------------------------------------------------
  707. void FormMain::OnPropertyGridButtonClick ( wxCommandEvent& )
  708. {
  709. #if wxUSE_STATUSBAR
  710. wxPGProperty* prop = m_pPropGridManager->GetSelection();
  711. wxStatusBar* sb = GetStatusBar();
  712. if ( prop )
  713. {
  714. wxString text(wxT("Button clicked: "));
  715. text += m_pPropGridManager->GetPropertyLabel(prop);
  716. text += wxT(", name=");
  717. text += m_pPropGridManager->GetPropertyName(prop);
  718. sb->SetStatusText( text );
  719. }
  720. else
  721. {
  722. ::wxMessageBox(wxT("SHOULD NOT HAPPEN!!!"));
  723. }
  724. #endif
  725. }
  726. // -----------------------------------------------------------------------
  727. void FormMain::OnPropertyGridItemCollapse( wxPropertyGridEvent& )
  728. {
  729. wxLogMessage(wxT("Item was Collapsed"));
  730. }
  731. // -----------------------------------------------------------------------
  732. void FormMain::OnPropertyGridItemExpand( wxPropertyGridEvent& )
  733. {
  734. wxLogMessage(wxT("Item was Expanded"));
  735. }
  736. // -----------------------------------------------------------------------
  737. void FormMain::OnPropertyGridColBeginDrag( wxPropertyGridEvent& event )
  738. {
  739. if ( m_itemVetoDragging->IsChecked() )
  740. {
  741. wxLogMessage("Splitter %i resize was vetoed", event.GetColumn());
  742. event.Veto();
  743. }
  744. else
  745. {
  746. wxLogMessage("Splitter %i resize began", event.GetColumn());
  747. }
  748. }
  749. // -----------------------------------------------------------------------
  750. void FormMain::OnPropertyGridColDragging( wxPropertyGridEvent& event )
  751. {
  752. wxUnusedVar(event);
  753. // For now, let's not spam the log output
  754. //wxLogMessage("Splitter %i is being resized", event.GetColumn());
  755. }
  756. // -----------------------------------------------------------------------
  757. void FormMain::OnPropertyGridColEndDrag( wxPropertyGridEvent& event )
  758. {
  759. wxLogMessage("Splitter %i resize ended", event.GetColumn());
  760. }
  761. // -----------------------------------------------------------------------
  762. // EVT_TEXT handling
  763. void FormMain::OnPropertyGridTextUpdate( wxCommandEvent& event )
  764. {
  765. event.Skip();
  766. }
  767. // -----------------------------------------------------------------------
  768. void FormMain::OnPropertyGridKeyEvent( wxKeyEvent& WXUNUSED(event) )
  769. {
  770. // Occurs on wxGTK mostly, but not wxMSW.
  771. }
  772. // -----------------------------------------------------------------------
  773. void FormMain::OnLabelTextChange( wxCommandEvent& WXUNUSED(event) )
  774. {
  775. // Uncomment following to allow property label modify in real-time
  776. // wxPGProperty& p = m_pPropGridManager->GetGrid()->GetSelection();
  777. // if ( !p.IsOk() ) return;
  778. // m_pPropGridManager->SetPropertyLabel( p, m_tcPropLabel->DoGetValue() );
  779. }
  780. // -----------------------------------------------------------------------
  781. static const wxChar* _fs_windowstyle_labels[] = {
  782. wxT("wxSIMPLE_BORDER"),
  783. wxT("wxDOUBLE_BORDER"),
  784. wxT("wxSUNKEN_BORDER"),
  785. wxT("wxRAISED_BORDER"),
  786. wxT("wxNO_BORDER"),
  787. wxT("wxTRANSPARENT_WINDOW"),
  788. wxT("wxTAB_TRAVERSAL"),
  789. wxT("wxWANTS_CHARS"),
  790. #if wxNO_FULL_REPAINT_ON_RESIZE
  791. wxT("wxNO_FULL_REPAINT_ON_RESIZE"),
  792. #endif
  793. wxT("wxVSCROLL"),
  794. wxT("wxALWAYS_SHOW_SB"),
  795. wxT("wxCLIP_CHILDREN"),
  796. #if wxFULL_REPAINT_ON_RESIZE
  797. wxT("wxFULL_REPAINT_ON_RESIZE"),
  798. #endif
  799. (const wxChar*) NULL // terminator is always needed
  800. };
  801. static const long _fs_windowstyle_values[] = {
  802. wxSIMPLE_BORDER,
  803. wxDOUBLE_BORDER,
  804. wxSUNKEN_BORDER,
  805. wxRAISED_BORDER,
  806. wxNO_BORDER,
  807. wxTRANSPARENT_WINDOW,
  808. wxTAB_TRAVERSAL,
  809. wxWANTS_CHARS,
  810. #if wxNO_FULL_REPAINT_ON_RESIZE
  811. wxNO_FULL_REPAINT_ON_RESIZE,
  812. #endif
  813. wxVSCROLL,
  814. wxALWAYS_SHOW_SB,
  815. wxCLIP_CHILDREN,
  816. #if wxFULL_REPAINT_ON_RESIZE
  817. wxFULL_REPAINT_ON_RESIZE
  818. #endif
  819. };
  820. static const wxChar* _fs_framestyle_labels[] = {
  821. wxT("wxCAPTION"),
  822. wxT("wxMINIMIZE"),
  823. wxT("wxMAXIMIZE"),
  824. wxT("wxCLOSE_BOX"),
  825. wxT("wxSTAY_ON_TOP"),
  826. wxT("wxSYSTEM_MENU"),
  827. wxT("wxRESIZE_BORDER"),
  828. wxT("wxFRAME_TOOL_WINDOW"),
  829. wxT("wxFRAME_NO_TASKBAR"),
  830. wxT("wxFRAME_FLOAT_ON_PARENT"),
  831. wxT("wxFRAME_SHAPED"),
  832. (const wxChar*) NULL
  833. };
  834. static const long _fs_framestyle_values[] = {
  835. wxCAPTION,
  836. wxMINIMIZE,
  837. wxMAXIMIZE,
  838. wxCLOSE_BOX,
  839. wxSTAY_ON_TOP,
  840. wxSYSTEM_MENU,
  841. wxRESIZE_BORDER,
  842. wxFRAME_TOOL_WINDOW,
  843. wxFRAME_NO_TASKBAR,
  844. wxFRAME_FLOAT_ON_PARENT,
  845. wxFRAME_SHAPED
  846. };
  847. // -----------------------------------------------------------------------
  848. void FormMain::OnTestXRC(wxCommandEvent& WXUNUSED(event))
  849. {
  850. wxMessageBox(wxT("Sorrt, not yet implemented"));
  851. }
  852. void FormMain::OnEnableCommonValues(wxCommandEvent& WXUNUSED(event))
  853. {
  854. wxPGProperty* prop = m_pPropGridManager->GetSelection();
  855. if ( prop )
  856. prop->EnableCommonValue();
  857. else
  858. wxMessageBox(wxT("First select a property"));
  859. }
  860. void FormMain::PopulateWithStandardItems ()
  861. {
  862. wxPropertyGridManager* pgman = m_pPropGridManager;
  863. wxPropertyGridPage* pg = pgman->GetPage(wxT("Standard Items"));
  864. // Append is ideal way to add items to wxPropertyGrid.
  865. pg->Append( new wxPropertyCategory(wxT("Appearance"),wxPG_LABEL) );
  866. pg->Append( new wxStringProperty(wxT("Label"),wxPG_LABEL,GetTitle()) );
  867. pg->Append( new wxFontProperty(wxT("Font"),wxPG_LABEL) );
  868. pg->SetPropertyHelpString ( wxT("Font"), wxT("Editing this will change font used in the property grid.") );
  869. pg->Append( new wxSystemColourProperty(wxT("Margin Colour"),wxPG_LABEL,
  870. pg->GetGrid()->GetMarginColour()) );
  871. pg->Append( new wxSystemColourProperty(wxT("Cell Colour"),wxPG_LABEL,
  872. pg->GetGrid()->GetCellBackgroundColour()) );
  873. pg->Append( new wxSystemColourProperty(wxT("Cell Text Colour"),wxPG_LABEL,
  874. pg->GetGrid()->GetCellTextColour()) );
  875. pg->Append( new wxSystemColourProperty(wxT("Line Colour"),wxPG_LABEL,
  876. pg->GetGrid()->GetLineColour()) );
  877. pg->Append( new wxFlagsProperty(wxT("Window Styles"),wxPG_LABEL,
  878. m_combinedFlags, GetWindowStyle()) );
  879. //pg->SetPropertyAttribute(wxT("Window Styles"),wxPG_BOOL_USE_CHECKBOX,true,wxPG_RECURSE);
  880. pg->Append( new wxCursorProperty(wxT("Cursor"),wxPG_LABEL) );
  881. pg->Append( new wxPropertyCategory(wxT("Position"),wxT("PositionCategory")) );
  882. pg->SetPropertyHelpString( wxT("PositionCategory"), wxT("Change in items in this category will cause respective changes in frame.") );
  883. // Let's demonstrate 'Units' attribute here
  884. // Note that we use many attribute constants instead of strings here
  885. // (for instance, wxPG_ATTR_MIN, instead of wxT("min")).
  886. // Using constant may reduce binary size.
  887. pg->Append( new wxIntProperty(wxT("Height"),wxPG_LABEL,480) );
  888. pg->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MIN, (long)10 );
  889. pg->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MAX, (long)2048 );
  890. pg->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_UNITS, wxT("Pixels") );
  891. // Set value to unspecified so that Hint attribute will be demonstrated
  892. pg->SetPropertyValueUnspecified("Height");
  893. pg->SetPropertyAttribute("Height", wxPG_ATTR_HINT,
  894. "Enter new height for window" );
  895. // Difference between hint and help string is that the hint is shown in
  896. // an empty value cell, while help string is shown either in the
  897. // description text box, as a tool tip, or on the status bar.
  898. pg->SetPropertyHelpString("Height",
  899. "This property uses attributes \"Units\" and \"Hint\"." );
  900. pg->Append( new wxIntProperty(wxT("Width"),wxPG_LABEL,640) );
  901. pg->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MIN, (long)10 );
  902. pg->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MAX, (long)2048 );
  903. pg->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_UNITS, wxT("Pixels") );
  904. pg->SetPropertyValueUnspecified(wxT("Width"));
  905. pg->SetPropertyAttribute("Width", wxPG_ATTR_HINT,
  906. "Enter new width for window" );
  907. pg->SetPropertyHelpString("Width",
  908. "This property uses attributes \"Units\" and \"Hint\"." );
  909. pg->Append( new wxIntProperty(wxT("X"),wxPG_LABEL,10) );
  910. pg->SetPropertyAttribute(wxT("X"), wxPG_ATTR_UNITS, wxT("Pixels") );
  911. pg->SetPropertyHelpString(wxT("X"), wxT("This property uses \"Units\" attribute.") );
  912. pg->Append( new wxIntProperty(wxT("Y"),wxPG_LABEL,10) );
  913. pg->SetPropertyAttribute(wxT("Y"), wxPG_ATTR_UNITS, wxT("Pixels") );
  914. pg->SetPropertyHelpString(wxT("Y"), wxT("This property uses \"Units\" attribute.") );
  915. const wxChar* disabledHelpString = wxT("This property is simply disabled. In order to have label disabled as well, ")
  916. wxT("you need to set wxPG_EX_GREY_LABEL_WHEN_DISABLED using SetExtraStyle.");
  917. pg->Append( new wxPropertyCategory(wxT("Environment"),wxPG_LABEL) );
  918. pg->Append( new wxStringProperty(wxT("Operating System"),wxPG_LABEL,::wxGetOsDescription()) );
  919. pg->Append( new wxStringProperty(wxT("User Id"),wxPG_LABEL,::wxGetUserId()) );
  920. pg->Append( new wxDirProperty(wxT("User Home"),wxPG_LABEL,::wxGetUserHome()) );
  921. pg->Append( new wxStringProperty(wxT("User Name"),wxPG_LABEL,::wxGetUserName()) );
  922. // Disable some of them
  923. pg->DisableProperty( wxT("Operating System") );
  924. pg->DisableProperty( wxT("User Id") );
  925. pg->DisableProperty( wxT("User Name") );
  926. pg->SetPropertyHelpString( wxT("Operating System"), disabledHelpString );
  927. pg->SetPropertyHelpString( wxT("User Id"), disabledHelpString );
  928. pg->SetPropertyHelpString( wxT("User Name"), disabledHelpString );
  929. pg->Append( new wxPropertyCategory(wxT("More Examples"),wxPG_LABEL) );
  930. pg->Append( new wxFontDataProperty( wxT("FontDataProperty"), wxPG_LABEL) );
  931. pg->SetPropertyHelpString( wxT("FontDataProperty"),
  932. wxT("This demonstrates wxFontDataProperty class defined in this sample app. ")
  933. wxT("It is exactly like wxFontProperty from the library, but also has colour sub-property.")
  934. );
  935. pg->Append( new wxDirsProperty(wxT("DirsProperty"),wxPG_LABEL) );
  936. pg->SetPropertyHelpString( wxT("DirsProperty"),
  937. wxT("This demonstrates wxDirsProperty class defined in this sample app. ")
  938. wxT("It is built with WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR macro, ")
  939. wxT("with custom action (dir dialog popup) defined.")
  940. );
  941. wxArrayDouble arrdbl;
  942. arrdbl.Add(-1.0);
  943. arrdbl.Add(-0.5);
  944. arrdbl.Add(0.0);
  945. arrdbl.Add(0.5);
  946. arrdbl.Add(1.0);
  947. pg->Append( new wxArrayDoubleProperty(wxT("ArrayDoubleProperty"),wxPG_LABEL,arrdbl) );
  948. //pg->SetPropertyAttribute(wxT("ArrayDoubleProperty"),wxPG_FLOAT_PRECISION,(long)2);
  949. pg->SetPropertyHelpString( wxT("ArrayDoubleProperty"),
  950. wxT("This demonstrates wxArrayDoubleProperty class defined in this sample app. ")
  951. wxT("It is an example of a custom list editor property.")
  952. );
  953. pg->Append( new wxLongStringProperty(wxT("Information"),wxPG_LABEL,
  954. wxT("Editing properties will have immediate effect on this window, ")
  955. wxT("and vice versa (atleast in most cases, that is).")
  956. ) );
  957. pg->SetPropertyHelpString( wxT("Information"),
  958. wxT("This property is read-only.") );
  959. pg->SetPropertyReadOnly( wxT("Information"), true );
  960. //
  961. // Set test information for cells in columns 3 and 4
  962. // (reserve column 2 for displaying units)
  963. wxPropertyGridIterator it;
  964. wxBitmap bmp = wxArtProvider::GetBitmap(wxART_FOLDER);
  965. for ( it = pg->GetGrid()->GetIterator();
  966. !it.AtEnd();
  967. it++ )
  968. {
  969. wxPGProperty* p = *it;
  970. if ( p->IsCategory() )
  971. continue;
  972. pg->SetPropertyCell( p, 3, wxT("Cell 3"), bmp );
  973. pg->SetPropertyCell( p, 4, wxT("Cell 4"), wxNullBitmap, *wxWHITE, *wxBLACK );
  974. }
  975. }
  976. // -----------------------------------------------------------------------
  977. void FormMain::PopulateWithExamples ()
  978. {
  979. wxPropertyGridManager* pgman = m_pPropGridManager;
  980. wxPropertyGridPage* pg = pgman->GetPage(wxT("Examples"));
  981. wxPGProperty* pid;
  982. wxPGProperty* prop;
  983. //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
  984. //pg->SetPropertyHelpString ( wxT("Examples"), wxT("This category has example of (almost) every built-in property class.") );
  985. #if wxUSE_SPINBTN
  986. pg->Append( new wxIntProperty ( wxT("SpinCtrl"), wxPG_LABEL, 0 ) );
  987. pg->SetPropertyEditor( wxT("SpinCtrl"), wxPGEditor_SpinCtrl );
  988. pg->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MIN, (long)-10 ); // Use constants instead of string
  989. pg->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MAX, (long)16384 ); // for reduced binary size.
  990. pg->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Step"), (long)2 );
  991. pg->SetPropertyAttribute( wxT("SpinCtrl"), wxT("MotionSpin"), true );
  992. //pg->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Wrap"), true );
  993. pg->SetPropertyHelpString( wxT("SpinCtrl"),
  994. wxT("This is regular wxIntProperty, which editor has been ")
  995. wxT("changed to wxPGEditor_SpinCtrl. Note however that ")
  996. wxT("static wxPropertyGrid::RegisterAdditionalEditors() ")
  997. wxT("needs to be called prior to using it."));
  998. #endif
  999. // Add bool property
  1000. pg->Append( new wxBoolProperty( wxT("BoolProperty"), wxPG_LABEL, false ) );
  1001. // Add bool property with check box
  1002. pg->Append( new wxBoolProperty( wxT("BoolProperty with CheckBox"), wxPG_LABEL, false ) );
  1003. pg->SetPropertyAttribute( wxT("BoolProperty with CheckBox"),
  1004. wxPG_BOOL_USE_CHECKBOX,
  1005. true );
  1006. pg->SetPropertyHelpString( wxT("BoolProperty with CheckBox"),
  1007. wxT("Property attribute wxPG_BOOL_USE_CHECKBOX has been set to true.") );
  1008. prop = pg->Append( new wxFloatProperty("FloatProperty",
  1009. wxPG_LABEL,
  1010. 1234500.23) );
  1011. prop->SetAttribute("Min", -100.12);
  1012. // A string property that can be edited in a separate editor dialog.
  1013. pg->Append( new wxLongStringProperty( wxT("LongStringProperty"), wxT("LongStringProp"),
  1014. wxT("This is much longer string than the first one. Edit it by clicking the button.") ) );
  1015. // A property that edits a wxArrayString.
  1016. wxArrayString example_array;
  1017. example_array.Add( wxT("String 1"));
  1018. example_array.Add( wxT("String 2"));
  1019. example_array.Add( wxT("String 3"));
  1020. pg->Append( new wxArrayStringProperty( wxT("ArrayStringProperty"), wxPG_LABEL,
  1021. example_array) );
  1022. // Test adding same category multiple times ( should not actually create a new one )
  1023. //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
  1024. // A file selector property. Note that argument between name
  1025. // and initial value is wildcard (format same as in wxFileDialog).
  1026. prop = new wxFileProperty( wxT("FileProperty"), wxT("TextFile") );
  1027. pg->Append( prop );
  1028. prop->SetAttribute(wxPG_FILE_WILDCARD,wxT("Text Files (*.txt)|*.txt"));
  1029. prop->SetAttribute(wxPG_FILE_DIALOG_TITLE,wxT("Custom File Dialog Title"));
  1030. prop->SetAttribute(wxPG_FILE_SHOW_FULL_PATH,false);
  1031. #ifdef __WXMSW__
  1032. prop->SetAttribute(wxPG_FILE_SHOW_RELATIVE_PATH,wxT("C:\\Windows"));
  1033. pg->SetPropertyValue(prop,wxT("C:\\Windows\\System32\\msvcrt71.dll"));
  1034. #endif
  1035. #if wxUSE_IMAGE
  1036. // An image file property. Arguments are just like for FileProperty, but
  1037. // wildcard is missing (it is autogenerated from supported image formats).
  1038. // If you really need to override it, create property separately, and call
  1039. // its SetWildcard method.
  1040. pg->Append( new wxImageFileProperty( wxT("ImageFile"), wxPG_LABEL ) );
  1041. #endif
  1042. pid = pg->Append( new wxColourProperty(wxT("ColourProperty"),wxPG_LABEL,*wxRED) );
  1043. pg->SetPropertyEditor( wxT("ColourProperty"), wxPGEditor_ComboBox );
  1044. pg->GetProperty(wxT("ColourProperty"))->SetAutoUnspecified(true);
  1045. pg->SetPropertyHelpString( wxT("ColourProperty"),
  1046. wxT("wxPropertyGrid::SetPropertyEditor method has been used to change ")
  1047. wxT("editor of this property to wxPGEditor_ComboBox)"));
  1048. pid = pg->Append( new wxColourProperty("ColourPropertyWithAlpha",
  1049. wxPG_LABEL,
  1050. wxColour(15, 200, 95, 128)) );
  1051. pg->SetPropertyAttribute("ColourPropertyWithAlpha", "HasAlpha", true);
  1052. pg->SetPropertyHelpString("ColourPropertyWithAlpha",
  1053. "Attribute \"HasAlpha\" is set to true for this property.");
  1054. //
  1055. // This demonstrates using alternative editor for colour property
  1056. // to trigger colour dialog directly from button.
  1057. pg->Append( new wxColourProperty(wxT("ColourProperty2"),wxPG_LABEL,*wxGREEN) );
  1058. //
  1059. // wxEnumProperty does not store strings or even list of strings
  1060. // ( so that's why they are static in function ).
  1061. static const wxChar* enum_prop_labels[] = { wxT("One Item"),
  1062. wxT("Another Item"), wxT("One More"), wxT("This Is Last"), NULL };
  1063. // this value array would be optional if values matched string indexes
  1064. static long enum_prop_values[] = { 40, 80, 120, 160 };
  1065. // note that the initial value (the last argument) is the actual value,
  1066. // not index or anything like that. Thus, our value selects "Another Item".
  1067. //
  1068. // 0 before value is number of items. If it is 0, like in our example,
  1069. // number of items is calculated, and this requires that the string pointer
  1070. // array is terminated with NULL.
  1071. pg->Append( new wxEnumProperty(wxT("EnumProperty"),wxPG_LABEL,
  1072. enum_prop_labels, enum_prop_values, 80 ) );
  1073. wxPGChoices soc;
  1074. // use basic table from our previous example
  1075. // can also set/add wxArrayStrings and wxArrayInts directly.
  1076. soc.Set( enum_prop_labels, enum_prop_values );
  1077. // add extra items
  1078. soc.Add( wxT("Look, it continues"), 200 );
  1079. soc.Add( wxT("Even More"), 240 );
  1080. soc.Add( wxT("And More"), 280 );
  1081. soc.Add( "", 300 );
  1082. soc.Add( wxT("True End of the List"), 320 );
  1083. // Test custom colours ([] operator of wxPGChoices returns
  1084. // references to wxPGChoiceEntry).
  1085. soc[1].SetFgCol(*wxRED);
  1086. soc[1].SetBgCol(*wxLIGHT_GREY);
  1087. soc[2].SetFgCol(*wxGREEN);
  1088. soc[2].SetBgCol(*wxLIGHT_GREY);
  1089. soc[3].SetFgCol(*wxBLUE);
  1090. soc[3].SetBgCol(*wxLIGHT_GREY);
  1091. soc[4].SetBitmap(wxArtProvider::GetBitmap(wxART_FOLDER));
  1092. pg->Append( new wxEnumProperty(wxT("EnumProperty 2"),
  1093. wxPG_LABEL,
  1094. soc,
  1095. 240) );
  1096. pg->GetProperty(wxT("EnumProperty 2"))->AddChoice(wxT("Testing Extra"), 360);
  1097. // Here we only display the original 'soc' choices
  1098. pg->Append( new wxEnumProperty(wxT("EnumProperty 3"),wxPG_LABEL,
  1099. soc, 240 ) );
  1100. // Test Hint attribute in EnumProperty
  1101. pg->GetProperty("EnumProperty 3")->SetAttribute("Hint", "Dummy Hint");
  1102. pg->SetPropertyHelpString("EnumProperty 3",
  1103. "This property uses \"Hint\" attribute.");
  1104. // 'soc' plus one exclusive extra choice "4th only"
  1105. pg->Append( new wxEnumProperty(wxT("EnumProperty 4"),wxPG_LABEL,
  1106. soc, 240 ) );
  1107. pg->GetProperty(wxT("EnumProperty 4"))->AddChoice(wxT("4th only"), 360);
  1108. pg->SetPropertyHelpString(wxT("EnumProperty 4"),
  1109. wxT("Should have one extra item when compared to EnumProperty 3"));
  1110. // Password property example.
  1111. pg->Append( new wxStringProperty(wxT("Password"),wxPG_LABEL, wxT("password")) );
  1112. pg->SetPropertyAttribute( wxT("Password"), wxPG_STRING_PASSWORD, true );
  1113. pg->SetPropertyHelpString( wxT("Password"),
  1114. wxT("Has attribute wxPG_STRING_PASSWORD set to true") );
  1115. // String editor with dir selector button. Uses wxEmptyString as name, which
  1116. // is allowed (naturally, in this case property cannot be accessed by name).
  1117. pg->Append( new wxDirProperty( wxT("DirProperty"), wxPG_LABEL, ::wxGetUserHome()) );
  1118. pg->SetPropertyAttribute( wxT("DirProperty"),
  1119. wxPG_DIR_DIALOG_MESSAGE,
  1120. wxT("This is a custom dir dialog message") );
  1121. // Add string property - first arg is label, second name, and third initial value
  1122. pg->Append( new wxStringProperty ( wxT("StringProperty"), wxPG_LABEL ) );
  1123. pg->SetPropertyMaxLength( wxT("StringProperty"), 6 );
  1124. pg->SetPropertyHelpString( wxT("StringProperty"),
  1125. wxT("Max length of this text has been limited to 6, using wxPropertyGrid::SetPropertyMaxLength.") );
  1126. // Set value after limiting so that it will be applied
  1127. pg->SetPropertyValue( wxT("StringProperty"), wxT("some text") );
  1128. //
  1129. // Demonstrate "AutoComplete" attribute
  1130. pg->Append( new wxStringProperty( "StringProperty AutoComplete",
  1131. wxPG_LABEL ) );
  1132. wxArrayString autoCompleteStrings;
  1133. autoCompleteStrings.Add("One choice");
  1134. autoCompleteStrings.Add("Another choice");
  1135. autoCompleteStrings.Add("Another choice, yeah");
  1136. autoCompleteStrings.Add("Yet another choice");
  1137. autoCompleteStrings.Add("Yet another choice, bear with me");
  1138. pg->SetPropertyAttribute( "StringProperty AutoComplete",
  1139. "AutoComplete",
  1140. autoCompleteStrings );
  1141. pg->SetPropertyHelpString( "StringProperty AutoComplete",
  1142. "AutoComplete attribute has been set for this property "
  1143. "(try writing something beginning with 'a', 'o' or 'y').");
  1144. // Add string property with arbitrarily wide bitmap in front of it. We
  1145. // intentionally lower-than-typical row height here so that the ugly
  1146. // scaling code wont't be run.
  1147. pg->Append( new wxStringProperty( wxT("StringPropertyWithBitmap"),
  1148. wxPG_LABEL,
  1149. wxT("Test Text")) );
  1150. wxBitmap myTestBitmap(60, 15, 32);
  1151. wxMemoryDC mdc;
  1152. mdc.SelectObject(myTestBitmap);
  1153. mdc.Clear();
  1154. mdc.SetPen(*wxBLACK);
  1155. mdc.DrawLine(0, 0, 60, 15);
  1156. mdc.SelectObject(wxNullBitmap);
  1157. pg->SetPropertyImage( wxT("StringPropertyWithBitmap"), myTestBitmap );
  1158. // this value array would be optional if values matched string indexes
  1159. //long flags_prop_values[] = { wxICONIZE, wxCAPTION, wxMINIMIZE_BOX, wxMAXIMIZE_BOX };
  1160. //pg->Append( wxFlagsProperty(wxT("Example of FlagsProperty"),wxT("FlagsProp"),
  1161. // flags_prop_labels, flags_prop_values, 0, GetWindowStyle() ) );
  1162. // Multi choice dialog.
  1163. wxArrayString tchoices;
  1164. tchoices.Add(wxT("Cabbage"));
  1165. tchoices.Add(wxT("Carrot"));
  1166. tchoices.Add(wxT("Onion"));
  1167. tchoices.Add(wxT("Potato"));
  1168. tchoices.Add(wxT("Strawberry"));
  1169. wxArrayString tchoicesValues;
  1170. tchoicesValues.Add(wxT("Carrot"));
  1171. tchoicesValues.Add(wxT("Potato"));
  1172. pg->Append( new wxEnumProperty(wxT("EnumProperty X"),wxPG_LABEL, tchoices ) );
  1173. pg->Append( new wxMultiChoiceProperty( wxT("MultiChoiceProperty"), wxPG_LABEL,
  1174. tchoices, tchoicesValues ) );
  1175. pg->SetPropertyAttribute( wxT("MultiChoiceProperty"), wxT("UserStringMode"), true );
  1176. pg->Append( new wxSizeProperty( wxT("SizeProperty"), wxT("Size"), GetSize() ) );
  1177. pg->Append( new wxPointProperty( wxT("PointProperty"), wxT("Position"), GetPosition() ) );
  1178. // UInt samples
  1179. pg->Append( new wxUIntProperty( wxT("UIntProperty"), wxPG_LABEL, wxULongLong(wxULL(0xFEEEFEEEFEEE))));
  1180. pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX, wxPG_PREFIX_NONE );
  1181. pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE, wxPG_BASE_HEX );
  1182. //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX, wxPG_PREFIX_NONE );
  1183. //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE, wxPG_BASE_OCT );
  1184. //
  1185. // wxEditEnumProperty
  1186. wxPGChoices eech;
  1187. eech.Add(wxT("Choice 1"));
  1188. eech.Add(wxT("Choice 2"));
  1189. eech.Add(wxT("Choice 3"));
  1190. pg->Append( new wxEditEnumProperty("EditEnumProperty",
  1191. wxPG_LABEL,
  1192. eech,
  1193. "Choice not in the list") );
  1194. // Test Hint attribute in EditEnumProperty
  1195. pg->GetProperty("EditEnumProperty")->SetAttribute("Hint", "Dummy Hint");
  1196. //wxString v_;
  1197. //wxTextValidator validator1(wxFILTER_NUMERIC,&v_);
  1198. //pg->SetPropertyValidator( wxT("EditEnumProperty"), validator1 );
  1199. #if wxUSE_DATETIME
  1200. //
  1201. // wxDateTimeProperty
  1202. pg->Append( new wxDateProperty(wxT("DateProperty"), wxPG_LABEL, wxDateTime::Now() ) );
  1203. #if wxUSE_DATEPICKCTRL
  1204. pg->SetPropertyAttribute( wxT("DateProperty"), wxPG_DATE_PICKER_STYLE,
  1205. (long)(wxDP_DROPDOWN |
  1206. wxDP_SHOWCENTURY |
  1207. wxDP_ALLOWNONE) );
  1208. pg->SetPropertyHelpString( wxT("DateProperty"),
  1209. wxT("Attribute wxPG_DATE_PICKER_STYLE has been set to (long)")
  1210. wxT("(wxDP_DROPDOWN | wxDP_SHOWCENTURY | wxDP_ALLOWNONE).") );
  1211. #endif
  1212. #endif
  1213. //
  1214. // Add Triangle properties as both wxTriangleProperty and
  1215. // a generic parent property (using wxStringProperty).
  1216. //
  1217. wxPGProperty* topId = pg->Append( new wxStringProperty(wxT("3D Object"), wxPG_LABEL, wxT("<composed>")) );
  1218. pid = pg->AppendIn( topId, new wxStringProperty(wxT("Triangle 1"), wxT("Triangle 1"), wxT("<composed>")) );
  1219. pg->AppendIn( pid, new wxVectorProperty( wxT("A"), wxPG_LABEL ) );
  1220. pg->AppendIn( pid, new wxVectorProperty( wxT("B"), wxPG_LABEL ) );
  1221. pg->AppendIn( pid, new wxVectorProperty( wxT("C"), wxPG_LABEL ) );
  1222. pg->AppendIn( topId, new wxTriangleProperty( wxT("Triangle 2"), wxT("Triangle 2") ) );
  1223. pg->SetPropertyHelpString( wxT("3D Object"),
  1224. wxT("3D Object is wxStringProperty with value \"<composed>\". Two of its children are similar wxStringProperties with ")
  1225. wxT("three wxVectorProperty children, and other two are custom wxTriangleProperties.") );
  1226. pid = pg->AppendIn( topId, new wxStringProperty(wxT("Triangle 3"), wxT("Triangle 3"), wxT("<composed>")) );
  1227. pg->AppendIn( pid, new wxVectorProperty( wxT("A"), wxPG_LABEL ) );
  1228. pg->AppendIn( pid, new wxVectorProperty( wxT("B"), wxPG_LABEL ) );
  1229. pg->AppendIn( pid, new wxVectorProperty( wxT("C"), wxPG_LABEL ) );
  1230. pg->AppendIn( topId, new wxTriangleProperty( wxT("Triangle 4"), wxT("Triangle 4") ) );
  1231. //
  1232. // This snippet is a doc sample test
  1233. //
  1234. wxPGProperty* carProp = pg->Append(new wxStringProperty(wxT("Car"),
  1235. wxPG_LABEL,
  1236. wxT("<composed>")));
  1237. pg->AppendIn(carProp, new wxStringProperty(wxT("Model"),
  1238. wxPG_LABEL,
  1239. wxT("Lamborghini Diablo SV")));
  1240. pg->AppendIn(carProp, new wxIntProperty(wxT("Engine Size (cc)"),
  1241. wxPG_LABEL,
  1242. 5707) );
  1243. wxPGProperty* speedsProp = pg->AppendIn(carProp,
  1244. new wxStringProperty(wxT("Speeds"),
  1245. wxPG_LABEL,
  1246. wxT("<composed>")));
  1247. pg->AppendIn( speedsProp, new wxIntProperty(wxT("Max. Speed (mph)"),
  1248. wxPG_LABEL,290) );
  1249. pg->AppendIn( speedsProp, new wxFloatProperty(wxT("0-100 mph (sec)"),
  1250. wxPG_LABEL,3.9) );
  1251. pg->AppendIn( speedsProp, new wxFloatProperty(wxT("1/4 mile (sec)"),
  1252. wxPG_LABEL,8.6) );
  1253. // This is how child property can be referred to by name
  1254. pg->SetPropertyValue( wxT("Car.Speeds.Max. Speed (mph)"), 300 );
  1255. pg->AppendIn(carProp, new wxIntProperty(wxT("Price ($)"),
  1256. wxPG_LABEL,
  1257. 300000) );
  1258. pg->AppendIn(carProp, new wxBoolProperty(wxT("Convertible"),
  1259. wxPG_LABEL,
  1260. false) );
  1261. // Displayed value of "Car" property is now very close to this:
  1262. // "Lamborghini Diablo SV; 5707 [300; 3.9; 8.6] 300000"
  1263. //
  1264. // Test wxSampleMultiButtonEditor
  1265. pg->Append( new wxLongStringProperty(wxT("MultipleButtons"), wxPG_LABEL) );
  1266. pg->SetPropertyEditor(wxT("MultipleButtons"), m_pSampleMultiButtonEditor );
  1267. // Test SingleChoiceProperty
  1268. pg->Append( new SingleChoiceProperty(wxT("SingleChoiceProperty")) );
  1269. //
  1270. // Test adding variable height bitmaps in wxPGChoices
  1271. wxPGChoices bc;
  1272. bc.Add(wxT("Wee"), wxBitmap(16, 16));
  1273. bc.Add(wxT("Not so wee"), wxBitmap(32, 32));
  1274. bc.Add(wxT("Friggin' huge"), wxBitmap(64, 64));
  1275. pg->Append( new wxEnumProperty(wxT("Variable Height Bitmaps"),
  1276. wxPG_LABEL,
  1277. bc,
  1278. 0) );
  1279. //
  1280. // Test how non-editable composite strings appear
  1281. pid = new wxStringProperty(wxT("wxWidgets Traits"), wxPG_LABEL, wxT("<composed>"));
  1282. pg->SetPropertyReadOnly(pid);
  1283. //
  1284. // For testing purposes, combine two methods of adding children
  1285. //
  1286. pid->AppendChild( new wxStringProperty(wxT("Latest Release"),
  1287. wxPG_LABEL,
  1288. wxT("2.8.10")));
  1289. pid->AppendChild( new wxBoolProperty(wxT("Win API"),
  1290. wxPG_LABEL,
  1291. true) );
  1292. pg->Append( pid );
  1293. pg->AppendIn(pid, new wxBoolProperty(wxT("QT"), wxPG_LABEL, false) );
  1294. pg->AppendIn(pid, new wxBoolProperty(wxT("Cocoa"), wxPG_LABEL, true) );
  1295. pg->AppendIn(pid, new wxBoolProperty(wxT("BeOS"), wxPG_LABEL, false) );
  1296. pg->AppendIn(pid, new wxStringProperty(wxT("SVN Trunk Version"), wxPG_LABEL, wxT("2.9.0")) );
  1297. pg->AppendIn(pid, new wxBoolProperty(wxT("GTK+"), wxPG_LABEL, true) );
  1298. pg->AppendIn(pid, new wxBoolProperty(wxT("Sky OS"), wxPG_LABEL, false) );
  1299. pg->AppendIn(pid, new wxBoolProperty(wxT("QT"), wxPG_LABEL, false) );
  1300. AddTestProperties(pg);
  1301. }
  1302. // -----------------------------------------------------------------------
  1303. void FormMain::PopulateWithLibraryConfig ()
  1304. {
  1305. wxPropertyGridManager* pgman = m_pPropGridManager;
  1306. wxPropertyGridPage* pg = pgman->GetPage(wxT("wxWidgets Library Config"));
  1307. // Set custom column proportions (here in the sample app we need
  1308. // to check if the grid has wxPG_SPLITTER_AUTO_CENTER style. You usually
  1309. // need not to do it in your application).
  1310. if ( pgman->HasFlag(wxPG_SPLITTER_AUTO_CENTER) )
  1311. {
  1312. pg->SetColumnProportion(0, 3);
  1313. pg->SetColumnProportion(1, 1);
  1314. }
  1315. wxPGProperty* cat;
  1316. wxBitmap bmp = wxArtProvider::GetBitmap(wxART_REPORT_VIEW);
  1317. wxPGProperty* pid;
  1318. wxFont italicFont = pgman->GetGrid()->GetCaptionFont();
  1319. italicFont.SetStyle(wxFONTSTYLE_ITALIC);
  1320. wxString italicFontHelp = "Font of this property's wxPGCell has "
  1321. "been modified. Obtain property's cell "
  1322. "with wxPGProperty::"
  1323. "GetOrCreateCell(column).";
  1324. #define ADD_WX_LIB_CONF_GROUP(A) \
  1325. cat = pg->AppendIn( pid, new wxPropertyCategory(A) ); \
  1326. pg->SetPropertyCell( cat, 0, wxPG_LABEL, bmp ); \
  1327. cat->GetCell(0).SetFont(italicFont); \
  1328. cat->SetHelpString(italicFontHelp);
  1329. #define ADD_WX_LIB_CONF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)((A>0)?true:false)));
  1330. #define ADD_WX_LIB_CONF_NODEF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)false) ); \
  1331. pg->DisableProperty(wxT(#A));
  1332. pid = pg->Append( new wxPropertyCategory( wxT("wxWidgets Library Configuration") ) );
  1333. pg->SetPropertyCell( pid, 0, wxPG_LABEL, bmp );
  1334. // Both of following lines would set a label for the second column
  1335. pg->SetPropertyCell( pid, 1, "Is Enabled" );
  1336. pid->SetValue("Is Enabled");
  1337. ADD_WX_LIB_CONF_GROUP(wxT("Global Settings"))
  1338. ADD_WX_LIB_CONF( wxUSE_GUI )
  1339. ADD_WX_LIB_CONF_GROUP(wxT("Compatibility Settings"))
  1340. #if defined(WXWIN_COMPATIBILITY_2_2)
  1341. ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_2 )
  1342. #endif
  1343. #if defined(WXWIN_COMPATIBILITY_2_4)
  1344. ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_4 )
  1345. #endif
  1346. #if defined(WXWIN_COMPATIBILITY_2_6)
  1347. ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_6 )
  1348. #endif
  1349. #if defined(WXWIN_COMPATIBILITY_2_8)
  1350. ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_8 )
  1351. #endif
  1352. #ifdef wxFONT_SIZE_COMPATIBILITY
  1353. ADD_WX_LIB_CONF( wxFONT_SIZE_COMPATIBILITY )
  1354. #else
  1355. ADD_WX_LIB_CONF_NODEF ( wxFONT_SIZE_COMPATIBILITY )
  1356. #endif
  1357. #ifdef wxDIALOG_UNIT_COMPATIBILITY
  1358. ADD_WX_LIB_CONF( wxDIALOG_UNIT_COMPATIBILITY )
  1359. #else
  1360. ADD_WX_LIB_CONF_NODEF ( wxDIALOG_UNIT_COMPATIBILITY )
  1361. #endif
  1362. ADD_WX_LIB_CONF_GROUP(wxT("Debugging Settings"))
  1363. ADD_WX_LIB_CONF( wxUSE_DEBUG_CONTEXT )
  1364. ADD_WX_LIB_CONF( wxUSE_MEMORY_TRACING )
  1365. ADD_WX_LIB_CONF( wxUSE_GLOBAL_MEMORY_OPERATORS )
  1366. ADD_WX_LIB_CONF( wxUSE_DEBUG_NEW_ALWAYS )
  1367. ADD_WX_LIB_CONF( wxUSE_ON_FATAL_EXCEPTION )
  1368. ADD_WX_LIB_CONF_GROUP(wxT("Unicode Support"))
  1369. ADD_WX_LIB_CONF( wxUSE_UNICODE )
  1370. ADD_WX_LIB_CONF( wxUSE_UNICODE_MSLU )
  1371. ADD_WX_LIB_CONF_GROUP(wxT("Global Features"))
  1372. ADD_WX_LIB_CONF( wxUSE_EXCEPTIONS )
  1373. ADD_WX_LIB_CONF( wxUSE_EXTENDED_RTTI )
  1374. ADD_WX_LIB_CONF( wxUSE_STL )
  1375. ADD_WX_LIB_CONF( wxUSE_LOG )
  1376. ADD_WX_LIB_CONF( wxUSE_LOGWINDOW )
  1377. ADD_WX_LIB_CONF( wxUSE_LOGGUI )
  1378. ADD_WX_LIB_CONF( wxUSE_LOG_DIALOG )
  1379. ADD_WX_LIB_CONF( wxUSE_CMDLINE_PARSER )
  1380. ADD_WX_LIB_CONF( wxUSE_THREADS )
  1381. ADD_WX_LIB_CONF( wxUSE_STREAMS )
  1382. ADD_WX_LIB_CONF( wxUSE_STD_IOSTREAM )
  1383. ADD_WX_LIB_CONF_GROUP(wxT("Non-GUI Features"))
  1384. ADD_WX_LIB_CONF( wxUSE_LONGLONG )
  1385. ADD_WX_LIB_CONF( wxUSE_FILE )
  1386. ADD_WX_LIB_CONF( wxUSE_FFILE )
  1387. ADD_WX_LIB_CONF( wxUSE_FSVOLUME )
  1388. ADD_WX_LIB_CONF( wxUSE_TEXTBUFFER )
  1389. ADD_WX_LIB_CONF( wxUSE_TEXTFILE )
  1390. ADD_WX_LIB_CONF( wxUSE_INTL )
  1391. ADD_WX_LIB_CONF( wxUSE_DATETIME )
  1392. ADD_WX_LIB_CONF( wxUSE_TIMER )
  1393. ADD_WX_LIB_CONF( wxUSE_STOPWATCH )
  1394. ADD_WX_LIB_CONF( wxUSE_CONFIG )
  1395. #ifdef wxUSE_CONFIG_NATIVE
  1396. ADD_WX_LIB_CONF( wxUSE_CONFIG_NATIVE )
  1397. #else
  1398. ADD_WX_LIB_CONF_NODEF ( wxUSE_CONFIG_NATIVE )
  1399. #endif
  1400. ADD_WX_LIB_CONF( wxUSE_DIALUP_MANAGER )
  1401. ADD_WX_LIB_CONF( wxUSE_DYNLIB_CLASS )
  1402. ADD_WX_LIB_CONF( wxUSE_DYNAMIC_LOADER )
  1403. ADD_WX_LIB_CONF( wxUSE_SOCKETS )
  1404. ADD_WX_LIB_CONF( wxUSE_FILESYSTEM )
  1405. ADD_WX_LIB_CONF( wxUSE_FS_ZIP )
  1406. ADD_WX_LIB_CONF( wxUSE_FS_INET )
  1407. ADD_WX_LIB_CONF( wxUSE_ZIPSTREAM )
  1408. ADD_WX_LIB_CONF( wxUSE_ZLIB )
  1409. ADD_WX_LIB_CONF( wxUSE_APPLE_IEEE )
  1410. ADD_WX_LIB_CONF( wxUSE_JOYSTICK )
  1411. ADD_WX_LIB_CONF( wxUSE_FONTMAP )
  1412. ADD_WX_LIB_CONF( wxUSE_MIMETYPE )
  1413. ADD_WX_LIB_CONF( wxUSE_PROTOCOL )
  1414. ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FILE )
  1415. ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FTP )
  1416. ADD_WX_LIB_CONF( wxUSE_PROTOCOL_HTTP )
  1417. ADD_WX_LIB_CONF( wxUSE_URL )
  1418. #ifdef wxUSE_URL_NATIVE
  1419. ADD_WX_LIB_CONF( wxUSE_URL_NATIVE )
  1420. #else
  1421. ADD_WX_LIB_CONF_NODEF ( wxUSE_URL_NATIVE )
  1422. #endif
  1423. ADD_WX_LIB_CONF( wxUSE_REGEX )
  1424. ADD_WX_LIB_CONF( wxUSE_SYSTEM_OPTIONS )
  1425. ADD_WX_LIB_CONF( wxUSE_SOUND )
  1426. #ifdef wxUSE_XRC
  1427. ADD_WX_LIB_CONF( wxUSE_XRC )
  1428. #else
  1429. ADD_WX_LIB_CONF_NODEF ( wxUSE_XRC )
  1430. #endif
  1431. ADD_WX_LIB_CONF( wxUSE_XML )
  1432. // Set them to use check box.
  1433. pg->SetPropertyAttribute(pid,wxPG_BOOL_USE_CHECKBOX,true,wxPG_RECURSE);
  1434. }
  1435. //
  1436. // Handle events of the third page here.
  1437. class wxMyPropertyGridPage : public wxPropertyGridPage
  1438. {
  1439. public:
  1440. // Return false here to indicate unhandled events should be
  1441. // propagated to manager's parent, as normal.
  1442. virtual bool IsHandlingAllEvents() const { return false; }
  1443. protected:
  1444. virtual wxPGProperty* DoInsert( wxPGProperty* parent,
  1445. int index,
  1446. wxPGProperty* property )
  1447. {
  1448. return wxPropertyGridPage::DoInsert(parent,index,property);
  1449. }
  1450. void OnPropertySelect( wxPropertyGridEvent& event );
  1451. void OnPropertyChanging( wxPropertyGridEvent& event );
  1452. void OnPropertyChange( wxPropertyGridEvent& event );
  1453. void OnPageChange( wxPropertyGridEvent& event );
  1454. private:
  1455. wxDECLARE_EVENT_TABLE();
  1456. };
  1457. wxBEGIN_EVENT_TABLE(wxMyPropertyGridPage, wxPropertyGridPage)
  1458. EVT_PG_SELECTED( wxID_ANY, wxMyPropertyGridPage::OnPropertySelect )
  1459. EVT_PG_CHANGING( wxID_ANY, wxMyPropertyGridPage::OnPropertyChanging )
  1460. EVT_PG_CHANGED( wxID_ANY, wxMyPropertyGridPage::OnPropertyChange )
  1461. EVT_PG_PAGE_CHANGED( wxID_ANY, wxMyPropertyGridPage::OnPageChange )
  1462. wxEND_EVENT_TABLE()
  1463. void wxMyPropertyGridPage::OnPropertySelect( wxPropertyGridEvent& WXUNUSED(event) )
  1464. {
  1465. wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertySelect()"));
  1466. }
  1467. void wxMyPropertyGridPage::OnPropertyChange( wxPropertyGridEvent& event )
  1468. {
  1469. wxPGProperty* p = event.GetProperty();
  1470. wxLogVerbose(wxT("wxMyPropertyGridPage::OnPropertyChange('%s', to value '%s')"),
  1471. p->GetName().c_str(),
  1472. p->GetDisplayedString().c_str());
  1473. }
  1474. void wxMyPropertyGridPage::OnPropertyChanging( wxPropertyGridEvent& event )
  1475. {
  1476. wxPGProperty* p = event.GetProperty();
  1477. wxLogVerbose(wxT("wxMyPropertyGridPage::OnPropertyChanging('%s', to value '%s')"),
  1478. p->GetName().c_str(),
  1479. event.GetValue().GetString().c_str());
  1480. }
  1481. void wxMyPropertyGridPage::OnPageChange( wxPropertyGridEvent& WXUNUSED(event) )
  1482. {
  1483. wxLogDebug(wxT("wxMyPropertyGridPage::OnPageChange()"));
  1484. }
  1485. class wxPGKeyHandler : public wxEvtHandler
  1486. {
  1487. public:
  1488. void OnKeyEvent( wxKeyEvent& event )
  1489. {
  1490. wxMessageBox(wxString::Format(wxT("%i"),event.GetKeyCode()));
  1491. event.Skip();
  1492. }
  1493. private:
  1494. wxDECLARE_EVENT_TABLE();
  1495. };
  1496. wxBEGIN_EVENT_TABLE(wxPGKeyHandler,wxEvtHandler)
  1497. EVT_KEY_DOWN( wxPGKeyHandler::OnKeyEvent )
  1498. wxEND_EVENT_TABLE()
  1499. // -----------------------------------------------------------------------
  1500. void FormMain::InitPanel()
  1501. {
  1502. if ( m_panel )
  1503. m_panel->Destroy();
  1504. wxWindow* panel = new wxPanel(this, wxID_ANY,
  1505. wxPoint(0, 0), wxSize(400, 400),
  1506. wxTAB_TRAVERSAL);
  1507. m_panel = panel;
  1508. // Column
  1509. wxBoxSizer* topSizer = new wxBoxSizer ( wxVERTICAL );
  1510. m_topSizer = topSizer;
  1511. }
  1512. void FormMain::FinalizePanel( bool wasCreated )
  1513. {
  1514. // Button for tab traversal testing
  1515. m_topSizer->Add( new wxButton(m_panel, wxID_ANY,
  1516. wxS("Should be able to move here with Tab")),
  1517. 0, wxEXPAND );
  1518. m_topSizer->Add( new wxButton(m_panel, ID_SHOWPOPUP,
  1519. wxS("Show Popup")),
  1520. 0, wxEXPAND );
  1521. m_panel->SetSizer( m_topSizer );
  1522. m_topSizer->SetSizeHints( m_panel );
  1523. wxBoxSizer* panelSizer = new wxBoxSizer( wxHORIZONTAL );
  1524. panelSizer->Add( m_panel, 1, wxEXPAND|wxFIXED_MINSIZE );
  1525. SetSizer( panelSizer );
  1526. panelSizer->SetSizeHints( this );
  1527. if ( wasCreated )
  1528. FinalizeFramePosition();
  1529. }
  1530. void FormMain::PopulateGrid()
  1531. {
  1532. wxPropertyGridManager* pgman = m_pPropGridManager;
  1533. pgman->AddPage(wxT("Standard Items"));
  1534. PopulateWithStandardItems();
  1535. pgman->AddPage(wxT("wxWidgets Library Config"));
  1536. PopulateWithLibraryConfig();
  1537. wxPropertyGridPage* myPage = new wxMyPropertyGridPage();
  1538. myPage->Append( new wxIntProperty ( wxT("IntProperty"), wxPG_LABEL, 12345678 ) );
  1539. // Use wxMyPropertyGridPage (see above) to test the
  1540. // custom wxPropertyGridPage feature.
  1541. pgman->AddPage(wxT("Examples"),wxNullBitmap,myPage);
  1542. PopulateWithExamples();
  1543. }
  1544. void FormMain::CreateGrid( int style, int extraStyle )
  1545. {
  1546. //
  1547. // This function (re)creates the property grid in our sample
  1548. //
  1549. if ( style == -1 )
  1550. style = // default style
  1551. wxPG_BOLD_MODIFIED |
  1552. wxPG_SPLITTER_AUTO_CENTER |
  1553. wxPG_AUTO_SORT |
  1554. //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
  1555. //wxPG_TOOLTIPS |
  1556. //wxPG_HIDE_CATEGORIES |
  1557. //wxPG_LIMITED_EDITING |
  1558. wxPG_TOOLBAR |
  1559. wxPG_DESCRIPTION;
  1560. if ( extraStyle == -1 )
  1561. // default extra style
  1562. extraStyle = wxPG_EX_MODE_BUTTONS |
  1563. wxPG_EX_MULTIPLE_SELECTION;
  1564. //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
  1565. //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
  1566. //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
  1567. //| wxPG_EX_HELP_AS_TOOLTIPS
  1568. bool wasCreated = m_panel ? false : true;
  1569. InitPanel();
  1570. //
  1571. // This shows how to combine two static choice descriptors
  1572. m_combinedFlags.Add( _fs_windowstyle_labels, _fs_windowstyle_values );
  1573. m_combinedFlags.Add( _fs_framestyle_labels, _fs_framestyle_values );
  1574. wxPropertyGridManager* pgman = m_pPropGridManager =
  1575. new wxPropertyGridManager(m_panel,
  1576. // Don't change this into wxID_ANY in the sample, or the
  1577. // event handling will obviously be broken.
  1578. PGID, /*wxID_ANY*/
  1579. wxDefaultPosition,
  1580. wxSize(100, 100), // FIXME: wxDefaultSize gives assertion in propgrid.
  1581. // But calling SetInitialSize in manager changes the code
  1582. // order to the grid gets created immediately, before SetExtraStyle
  1583. // is called.
  1584. style );
  1585. m_propGrid = pgman->GetGrid();
  1586. pgman->SetExtraStyle(extraStyle);
  1587. // This is the default validation failure behaviour
  1588. m_pPropGridManager->SetValidationFailureBehavior( wxPG_VFB_MARK_CELL |
  1589. wxPG_VFB_SHOW_MESSAGEBOX );
  1590. m_pPropGridManager->GetGrid()->SetVerticalSpacing( 2 );
  1591. //
  1592. // Set somewhat different unspecified value appearance
  1593. wxPGCell cell;
  1594. cell.SetText("Unspecified");
  1595. cell.SetFgCol(*wxLIGHT_GREY);
  1596. m_propGrid->SetUnspecifiedValueAppearance(cell);
  1597. PopulateGrid();
  1598. // Change some attributes in all properties
  1599. //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING,true);
  1600. //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_CHECKBOX,true);
  1601. //m_pPropGridManager->SetSplitterLeft(true);
  1602. //m_pPropGridManager->SetSplitterPosition(137);
  1603. /*
  1604. // This would setup event handling without event table entries
  1605. Connect(m_pPropGridManager->GetId(), wxEVT_PG_SELECTED,
  1606. wxPropertyGridEventHandler(FormMain::OnPropertyGridSelect) );
  1607. Connect(m_pPropGridManager->GetId(), wxEVT_PG_CHANGED,
  1608. wxPropertyGridEventHandler(FormMain::OnPropertyGridChange) );
  1609. */
  1610. m_topSizer->Add( m_pPropGridManager, 1, wxEXPAND );
  1611. FinalizePanel(wasCreated);
  1612. }
  1613. // -----------------------------------------------------------------------
  1614. FormMain::FormMain(const wxString& title, const wxPoint& pos, const wxSize& size) :
  1615. wxFrame((wxFrame *)NULL, -1, title, pos, size,
  1616. (wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCAPTION|
  1617. wxTAB_TRAVERSAL|wxCLOSE_BOX|wxNO_FULL_REPAINT_ON_RESIZE) )
  1618. {
  1619. SetIcon(wxICON(sample));
  1620. m_propGrid = NULL;
  1621. m_panel = NULL;
  1622. #ifdef __WXMAC__
  1623. // we need this in order to allow the about menu relocation, since ABOUT is
  1624. // not the default id of the about menu
  1625. wxApp::s_macAboutMenuItemId = ID_ABOUT;
  1626. #endif
  1627. #if wxUSE_IMAGE
  1628. // This is here to really test the wxImageFileProperty.
  1629. wxInitAllImageHandlers();
  1630. #endif
  1631. // Register all editors (SpinCtrl etc.)
  1632. m_pPropGridManager->RegisterAdditionalEditors();
  1633. // Register our sample custom editors
  1634. m_pSampleMultiButtonEditor =
  1635. wxPropertyGrid::RegisterEditorClass(new wxSampleMultiButtonEditor());
  1636. CreateGrid( // style
  1637. wxPG_BOLD_MODIFIED |
  1638. wxPG_SPLITTER_AUTO_CENTER |
  1639. wxPG_AUTO_SORT |
  1640. //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
  1641. //wxPG_TOOLTIPS |
  1642. //wxPG_HIDE_CATEGORIES |
  1643. //wxPG_LIMITED_EDITING |
  1644. wxPG_TOOLBAR |
  1645. wxPG_DESCRIPTION,
  1646. // extra style
  1647. wxPG_EX_MODE_BUTTONS |
  1648. wxPG_EX_MULTIPLE_SELECTION
  1649. //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
  1650. //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
  1651. //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
  1652. //| wxPG_EX_HELP_AS_TOOLTIPS
  1653. );
  1654. //
  1655. // Create menubar
  1656. wxMenu *menuFile = new wxMenu(wxEmptyString, wxMENU_TEAROFF);
  1657. wxMenu *menuTry = new wxMenu;
  1658. wxMenu *menuTools1 = new wxMenu;
  1659. wxMenu *menuTools2 = new wxMenu;
  1660. wxMenu *menuHelp = new wxMenu;
  1661. menuHelp->Append(ID_ABOUT, wxT("&About"), wxT("Show about dialog") );
  1662. menuTools1->Append(ID_APPENDPROP, wxT("Append New Property") );
  1663. menuTools1->Append(ID_APPENDCAT, wxT("Append New Category\tCtrl-S") );
  1664. menuTools1->AppendSeparator();
  1665. menuTools1->Append(ID_INSERTPROP, wxT("Insert New Property\tCtrl-Q") );
  1666. menuTools1->Append(ID_INSERTCAT, wxT("Insert New Category\tCtrl-W") );
  1667. menuTools1->AppendSeparator();
  1668. menuTools1->Append(ID_DELETE, wxT("Delete Selected") );
  1669. menuTools1->Append(ID_DELETER, wxT("Delete Random") );
  1670. menuTools1->Append(ID_DELETEALL, wxT("Delete All") );
  1671. menuTools1->AppendSeparator();
  1672. menuTools1->Append(ID_SETBGCOLOUR, wxT("Set Bg Colour") );
  1673. menuTools1->Append(ID_SETBGCOLOURRECUR, wxT("Set Bg Colour (Recursively)") );
  1674. menuTools1->Append(ID_UNSPECIFY, "Set Value to Unspecified");
  1675. menuTools1->AppendSeparator();
  1676. m_itemEnable = menuTools1->Append(ID_ENABLE, wxT("Enable"),
  1677. wxT("Toggles item's enabled state.") );
  1678. m_itemEnable->Enable( FALSE );
  1679. menuTools1->Append(ID_HIDE, "Hide", "Hides a property" );
  1680. menuTools1->Append(ID_SETREADONLY, "Set as Read-Only",
  1681. "Set property as read-only" );
  1682. menuTools2->Append(ID_ITERATE1, wxT("Iterate Over Properties") );
  1683. menuTools2->Append(ID_ITERATE2, wxT("Iterate Over Visible Items") );
  1684. menuTools2->Append(ID_ITERATE3, wxT("Reverse Iterate Over Properties") );
  1685. menuTools2->Append(ID_ITERATE4, wxT("Iterate Over Categories") );
  1686. menuTools2->AppendSeparator();
  1687. menuTools2->Append(ID_ONEXTENDEDKEYNAV, "Extend Keyboard Navigation",
  1688. "This will set Enter to navigate to next property, "
  1689. "and allows arrow keys to navigate even when in "
  1690. "editor control.");
  1691. menuTools2->AppendSeparator();
  1692. menuTools2->Append(ID_SETPROPERTYVALUE, wxT("Set Property Value") );
  1693. menuTools2->Append(ID_CLEARMODIF, wxT("Clear Modified Status"), wxT("Clears wxPG_MODIFIED flag from all properties.") );
  1694. menuTools2->AppendSeparator();
  1695. m_itemFreeze = menuTools2->AppendCheckItem(ID_FREEZE, wxT("Freeze"),
  1696. wxT("Disables painting, auto-sorting, etc.") );
  1697. menuTools2->AppendSeparator();
  1698. menuTools2->Append(ID_DUMPLIST, wxT("Display Values as wxVariant List"), wxT("Tests GetAllValues method and wxVariant conversion.") );
  1699. menuTools2->AppendSeparator();
  1700. menuTools2->Append(ID_GETVALUES, wxT("Get Property Values"), wxT("Stores all property values.") );
  1701. menuTools2->Append(ID_SETVALUES, wxT("Set Property Values"), wxT("Reverts property values to those last stored.") );
  1702. menuTools2->Append(ID_SETVALUES2, wxT("Set Property Values 2"), wxT("Adds property values that should not initially be as items (so new items are created).") );
  1703. menuTools2->AppendSeparator();
  1704. menuTools2->Append(ID_SAVESTATE, wxT("Save Editable State") );
  1705. menuTools2->Append(ID_RESTORESTATE, wxT("Restore Editable State") );
  1706. menuTools2->AppendSeparator();
  1707. menuTools2->Append(ID_ENABLECOMMONVALUES, wxT("Enable Common Value"),
  1708. wxT("Enable values that are common to all properties, for selected property."));
  1709. menuTools2->AppendSeparator();
  1710. menuTools2->Append(ID_COLLAPSE, wxT("Collapse Selected") );
  1711. menuTools2->Append(ID_COLLAPSEALL, wxT("Collapse All") );
  1712. menuTools2->AppendSeparator();
  1713. menuTools2->Append(ID_INSERTPAGE, wxT("Add Page") );
  1714. menuTools2->Append(ID_REMOVEPAGE, wxT("Remove Page") );
  1715. menuTools2->AppendSeparator();
  1716. menuTools2->Append(ID_FITCOLUMNS, wxT("Fit Columns") );
  1717. m_itemVetoDragging =
  1718. menuTools2->AppendCheckItem(ID_VETOCOLDRAG,
  1719. "Veto Column Dragging");
  1720. menuTools2->AppendSeparator();
  1721. menuTools2->Append(ID_CHANGEFLAGSITEMS, wxT("Change Children of FlagsProp") );
  1722. menuTools2->AppendSeparator();
  1723. menuTools2->Append(ID_TESTINSERTCHOICE, wxT("Test InsertPropertyChoice") );
  1724. menuTools2->Append(ID_TESTDELETECHOICE, wxT("Test DeletePropertyChoice") );
  1725. menuTools2->AppendSeparator();
  1726. menuTools2->Append(ID_SETSPINCTRLEDITOR, wxT("Use SpinCtrl Editor") );
  1727. menuTools2->Append(ID_TESTREPLACE, wxT("Test ReplaceProperty") );
  1728. menuTry->Append(ID_SELECTSTYLE, wxT("Set Window Style"),
  1729. wxT("Select window style flags used by the grid."));
  1730. menuTry->Append(ID_ENABLELABELEDITING, "Enable label editing",
  1731. "This calls wxPropertyGrid::MakeColumnEditable(0)");
  1732. menuTry->AppendCheckItem(ID_SHOWHEADER,
  1733. "Enable header",
  1734. "This calls wxPropertyGridManager::ShowHeader()");
  1735. menuTry->AppendSeparator();
  1736. menuTry->AppendRadioItem( ID_COLOURSCHEME1, wxT("Standard Colour Scheme") );
  1737. menuTry->AppendRadioItem( ID_COLOURSCHEME2, wxT("White Colour Scheme") );
  1738. menuTry->AppendRadioItem( ID_COLOURSCHEME3, wxT(".NET Colour Scheme") );
  1739. menuTry->AppendRadioItem( ID_COLOURSCHEME4, wxT("Cream Colour Scheme") );
  1740. menuTry->AppendSeparator();
  1741. m_itemCatColours = menuTry->AppendCheckItem(ID_CATCOLOURS, wxT("Category Specific Colours"),
  1742. wxT("Switches between category-specific cell colours and default scheme (actually done using SetPropertyTextColour and SetPropertyBackgroundColour).") );
  1743. menuTry->AppendSeparator();
  1744. menuTry->AppendCheckItem(ID_STATICLAYOUT, wxT("Static Layout"),
  1745. wxT("Switches between user-modifiedable and static layouts.") );
  1746. menuTry->Append(ID_SETCOLUMNS, wxT("Set Number of Columns") );
  1747. menuTry->AppendSeparator();
  1748. menuTry->Append(ID_TESTXRC, wxT("Display XRC sample") );
  1749. menuTry->AppendSeparator();
  1750. menuTry->Append(ID_RUNTESTFULL, wxT("Run Tests (full)") );
  1751. menuTry->Append(ID_RUNTESTPARTIAL, wxT("Run Tests (fast)") );
  1752. menuFile->Append(ID_RUNMINIMAL, wxT("Run Minimal Sample") );
  1753. menuFile->AppendSeparator();
  1754. menuFile->Append(ID_QUIT, wxT("E&xit\tAlt-X"), wxT("Quit this program") );
  1755. // Now append the freshly created menu to the menu bar...
  1756. wxMenuBar *menuBar = new wxMenuBar();
  1757. menuBar->Append(menuFile, wxT("&File") );
  1758. menuBar->Append(menuTry, wxT("&Try These!") );
  1759. menuBar->Append(menuTools1, wxT("&Basic") );
  1760. menuBar->Append(menuTools2, wxT("&Advanced") );
  1761. menuBar->Append(menuHelp, wxT("&Help") );
  1762. // ... and attach this menu bar to the frame
  1763. SetMenuBar(menuBar);
  1764. #if wxUSE_STATUSBAR
  1765. // create a status bar
  1766. CreateStatusBar(1);
  1767. SetStatusText(wxEmptyString);
  1768. #endif // wxUSE_STATUSBAR
  1769. FinalizeFramePosition();
  1770. #if wxUSE_LOGWINDOW
  1771. // Create log window
  1772. m_logWindow = new wxLogWindow(this, "Log Messages", false);
  1773. m_logWindow->GetFrame()->Move(GetPosition().x + GetSize().x + 10,
  1774. GetPosition().y);
  1775. m_logWindow->Show();
  1776. #endif
  1777. }
  1778. void FormMain::FinalizeFramePosition()
  1779. {
  1780. wxSize frameSize((wxSystemSettings::GetMetric(wxSYS_SCREEN_X)/10)*4,
  1781. (wxSystemSettings::GetMetric(wxSYS_SCREEN_Y)/10)*8);
  1782. if ( frameSize.x > 500 )
  1783. frameSize.x = 500;
  1784. SetSize(frameSize);
  1785. Centre();
  1786. }
  1787. //
  1788. // Normally, wxPropertyGrid does not check whether item with identical
  1789. // label already exists. However, since in this sample we use labels for
  1790. // identifying properties, we have to be sure not to generate identical
  1791. // labels.
  1792. //
  1793. void GenerateUniquePropertyLabel( wxPropertyGridManager* pg, wxString& baselabel )
  1794. {
  1795. int count = -1;
  1796. wxString newlabel;
  1797. if ( pg->GetPropertyByLabel( baselabel ) )
  1798. {
  1799. for (;;)
  1800. {
  1801. count++;
  1802. newlabel.Printf(wxT("%s%i"),baselabel.c_str(),count);
  1803. if ( !pg->GetPropertyByLabel( newlabel ) ) break;
  1804. }
  1805. }
  1806. if ( count >= 0 )
  1807. {
  1808. baselabel = newlabel;
  1809. }
  1810. }
  1811. // -----------------------------------------------------------------------
  1812. void FormMain::OnInsertPropClick( wxCommandEvent& WXUNUSED(event) )
  1813. {
  1814. wxString propLabel;
  1815. if ( !m_pPropGridManager->GetGrid()->GetRoot()->GetChildCount() )
  1816. {
  1817. wxMessageBox(wxT("No items to relate - first add some with Append."));
  1818. return;
  1819. }
  1820. wxPGProperty* id = m_pPropGridManager->GetGrid()->GetSelection();
  1821. if ( !id )
  1822. {
  1823. wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
  1824. return;
  1825. }
  1826. if ( propLabel.Len() < 1 ) propLabel = wxT("Property");
  1827. GenerateUniquePropertyLabel( m_pPropGridManager, propLabel );
  1828. m_pPropGridManager->Insert( m_pPropGridManager->GetPropertyParent(id),
  1829. id->GetIndexInParent(),
  1830. new wxStringProperty(propLabel) );
  1831. }
  1832. // -----------------------------------------------------------------------
  1833. void FormMain::OnAppendPropClick( wxCommandEvent& WXUNUSED(event) )
  1834. {
  1835. wxString propLabel;
  1836. if ( propLabel.Len() < 1 ) propLabel = wxT("Property");
  1837. GenerateUniquePropertyLabel( m_pPropGridManager, propLabel );
  1838. m_pPropGridManager->Append( new wxStringProperty(propLabel) );
  1839. m_pPropGridManager->Refresh();
  1840. }
  1841. // -----------------------------------------------------------------------
  1842. void FormMain::OnClearClick( wxCommandEvent& WXUNUSED(event) )
  1843. {
  1844. m_pPropGridManager->GetGrid()->Clear();
  1845. }
  1846. // -----------------------------------------------------------------------
  1847. void FormMain::OnAppendCatClick( wxCommandEvent& WXUNUSED(event) )
  1848. {
  1849. wxString propLabel;
  1850. if ( propLabel.Len() < 1 ) propLabel = wxT("Category");
  1851. GenerateUniquePropertyLabel( m_pPropGridManager, propLabel );
  1852. m_pPropGridManager->Append( new wxPropertyCategory (propLabel) );
  1853. m_pPropGridManager->Refresh();
  1854. }
  1855. // -----------------------------------------------------------------------
  1856. void FormMain::OnInsertCatClick( wxCommandEvent& WXUNUSED(event) )
  1857. {
  1858. wxString propLabel;
  1859. if ( !m_pPropGridManager->GetGrid()->GetRoot()->GetChildCount() )
  1860. {
  1861. wxMessageBox(wxT("No items to relate - first add some with Append."));
  1862. return;
  1863. }
  1864. wxPGProperty* id = m_pPropGridManager->GetGrid()->GetSelection();
  1865. if ( !id )
  1866. {
  1867. wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
  1868. return;
  1869. }
  1870. if ( propLabel.Len() < 1 ) propLabel = wxT("Category");
  1871. GenerateUniquePropertyLabel( m_pPropGridManager, propLabel );
  1872. m_pPropGridManager->Insert( m_pPropGridManager->GetPropertyParent(id),
  1873. id->GetIndexInParent(),
  1874. new wxPropertyCategory (propLabel) );
  1875. }
  1876. // -----------------------------------------------------------------------
  1877. void FormMain::OnDelPropClick( wxCommandEvent& WXUNUSED(event) )
  1878. {
  1879. wxPGProperty* id = m_pPropGridManager->GetGrid()->GetSelection();
  1880. if ( !id )
  1881. {
  1882. wxMessageBox(wxT("First select a property."));
  1883. return;
  1884. }
  1885. m_pPropGridManager->DeleteProperty( id );
  1886. }
  1887. // -----------------------------------------------------------------------
  1888. void FormMain::OnDelPropRClick( wxCommandEvent& WXUNUSED(event) )
  1889. {
  1890. // Delete random property
  1891. wxPGProperty* p = m_pPropGridManager->GetGrid()->GetRoot();
  1892. for (;;)
  1893. {
  1894. if ( !p->IsCategory() )
  1895. {
  1896. m_pPropGridManager->DeleteProperty( p );
  1897. break;
  1898. }
  1899. if ( !p->GetChildCount() )
  1900. break;
  1901. int n = rand() % ((int)p->GetChildCount());
  1902. p = p->Item(n);
  1903. }
  1904. }
  1905. // -----------------------------------------------------------------------
  1906. void FormMain::OnContextMenu( wxContextMenuEvent& event )
  1907. {
  1908. wxLogDebug(wxT("FormMain::OnContextMenu(%i,%i)"),
  1909. event.GetPosition().x,event.GetPosition().y);
  1910. wxUnusedVar(event);
  1911. //event.Skip();
  1912. }
  1913. // -----------------------------------------------------------------------
  1914. void FormMain::OnCloseClick( wxCommandEvent& WXUNUSED(event) )
  1915. {
  1916. /*#ifdef __WXDEBUG__
  1917. m_pPropGridManager->GetGrid()->DumpAllocatedChoiceSets();
  1918. wxLogDebug(wxT("\\-> Don't worry, this is perfectly normal in this sample."));
  1919. #endif*/
  1920. Close(false);
  1921. }
  1922. // -----------------------------------------------------------------------
  1923. int IterateMessage( wxPGProperty* prop )
  1924. {
  1925. wxString s;
  1926. s.Printf( wxT("\"%s\" class = %s, valuetype = %s"), prop->GetLabel().c_str(),
  1927. prop->GetClassInfo()->GetClassName(), prop->GetValueType().c_str() );
  1928. return wxMessageBox( s, wxT("Iterating... (press CANCEL to end)"), wxOK|wxCANCEL );
  1929. }
  1930. // -----------------------------------------------------------------------
  1931. void FormMain::OnIterate1Click( wxCommandEvent& WXUNUSED(event) )
  1932. {
  1933. wxPropertyGridIterator it;
  1934. for ( it = m_pPropGridManager->GetCurrentPage()->
  1935. GetIterator();
  1936. !it.AtEnd();
  1937. it++ )
  1938. {
  1939. wxPGProperty* p = *it;
  1940. int res = IterateMessage( p );
  1941. if ( res == wxCANCEL ) break;
  1942. }
  1943. }
  1944. // -----------------------------------------------------------------------
  1945. void FormMain::OnIterate2Click( wxCommandEvent& WXUNUSED(event) )
  1946. {
  1947. wxPropertyGridIterator it;
  1948. for ( it = m_pPropGridManager->GetCurrentPage()->
  1949. GetIterator( wxPG_ITERATE_VISIBLE );
  1950. !it.AtEnd();
  1951. it++ )
  1952. {
  1953. wxPGProperty* p = *it;
  1954. int res = IterateMessage( p );
  1955. if ( res == wxCANCEL ) break;
  1956. }
  1957. }
  1958. // -----------------------------------------------------------------------
  1959. void FormMain::OnIterate3Click( wxCommandEvent& WXUNUSED(event) )
  1960. {
  1961. // iterate over items in reverse order
  1962. wxPropertyGridIterator it;
  1963. for ( it = m_pPropGridManager->GetCurrentPage()->
  1964. GetIterator( wxPG_ITERATE_DEFAULT, wxBOTTOM );
  1965. !it.AtEnd();
  1966. it-- )
  1967. {
  1968. wxPGProperty* p = *it;
  1969. int res = IterateMessage( p );
  1970. if ( res == wxCANCEL ) break;
  1971. }
  1972. }
  1973. // -----------------------------------------------------------------------
  1974. void FormMain::OnIterate4Click( wxCommandEvent& WXUNUSED(event) )
  1975. {
  1976. wxPropertyGridIterator it;
  1977. for ( it = m_pPropGridManager->GetCurrentPage()->
  1978. GetIterator( wxPG_ITERATE_CATEGORIES );
  1979. !it.AtEnd();
  1980. it++ )
  1981. {
  1982. wxPGProperty* p = *it;
  1983. int res = IterateMessage( p );
  1984. if ( res == wxCANCEL ) break;
  1985. }
  1986. }
  1987. // -----------------------------------------------------------------------
  1988. void FormMain::OnExtendedKeyNav( wxCommandEvent& WXUNUSED(event) )
  1989. {
  1990. // Use AddActionTrigger() and DedicateKey() to set up Enter,
  1991. // Up, and Down keys for navigating between properties.
  1992. wxPropertyGrid* propGrid = m_pPropGridManager->GetGrid();
  1993. propGrid->AddActionTrigger(wxPG_ACTION_NEXT_PROPERTY,
  1994. WXK_RETURN);
  1995. propGrid->DedicateKey(WXK_RETURN);
  1996. // Up and Down keys are alredy associated with navigation,
  1997. // but we must also prevent them from being eaten by
  1998. // editor controls.
  1999. propGrid->DedicateKey(WXK_UP);
  2000. propGrid->DedicateKey(WXK_DOWN);
  2001. }
  2002. // -----------------------------------------------------------------------
  2003. void FormMain::OnFitColumnsClick( wxCommandEvent& WXUNUSED(event) )
  2004. {
  2005. wxPropertyGridPage* page = m_pPropGridManager->GetCurrentPage();
  2006. // Remove auto-centering
  2007. m_pPropGridManager->SetWindowStyle( m_pPropGridManager->GetWindowStyle() & ~wxPG_SPLITTER_AUTO_CENTER);
  2008. // Grow manager size just prior fit - otherwise
  2009. // column information may be lost.
  2010. wxSize oldGridSize = m_pPropGridManager->GetGrid()->GetClientSize();
  2011. wxSize oldFullSize = GetSize();
  2012. SetSize(1000, oldFullSize.y);
  2013. wxSize newSz = page->FitColumns();
  2014. int dx = oldFullSize.x - oldGridSize.x;
  2015. int dy = oldFullSize.y - oldGridSize.y;
  2016. newSz.x += dx;
  2017. newSz.y += dy;
  2018. SetSize(newSz);
  2019. }
  2020. // -----------------------------------------------------------------------
  2021. void FormMain::OnChangeFlagsPropItemsClick( wxCommandEvent& WXUNUSED(event) )
  2022. {
  2023. wxPGProperty* p = m_pPropGridManager->GetPropertyByName(wxT("Window Styles"));
  2024. wxPGChoices newChoices;
  2025. newChoices.Add(wxT("Fast"),0x1);
  2026. newChoices.Add(wxT("Powerful"),0x2);
  2027. newChoices.Add(wxT("Safe"),0x4);
  2028. newChoices.Add(wxT("Sleek"),0x8);
  2029. p->SetChoices(newChoices);
  2030. }
  2031. // -----------------------------------------------------------------------
  2032. void FormMain::OnEnableDisable( wxCommandEvent& )
  2033. {
  2034. wxPGProperty* id = m_pPropGridManager->GetGrid()->GetSelection();
  2035. if ( !id )
  2036. {
  2037. wxMessageBox(wxT("First select a property."));
  2038. return;
  2039. }
  2040. if ( m_pPropGridManager->IsPropertyEnabled( id ) )
  2041. {
  2042. m_pPropGridManager->DisableProperty ( id );
  2043. m_itemEnable->SetItemLabel( wxT("Enable") );
  2044. }
  2045. else
  2046. {
  2047. m_pPropGridManager->EnableProperty ( id );
  2048. m_itemEnable->SetItemLabel( wxT("Disable") );
  2049. }
  2050. }
  2051. // -----------------------------------------------------------------------
  2052. void FormMain::OnSetReadOnly( wxCommandEvent& WXUNUSED(event) )
  2053. {
  2054. wxPGProperty* p = m_pPropGridManager->GetGrid()->GetSelection();
  2055. if ( !p )
  2056. {
  2057. wxMessageBox(wxT("First select a property."));
  2058. return;
  2059. }
  2060. m_pPropGridManager->SetPropertyReadOnly(p);
  2061. }
  2062. // -----------------------------------------------------------------------
  2063. void FormMain::OnHide( wxCommandEvent& WXUNUSED(event) )
  2064. {
  2065. wxPGProperty* id = m_pPropGridManager->GetGrid()->GetSelection();
  2066. if ( !id )
  2067. {
  2068. wxMessageBox(wxT("First select a property."));
  2069. return;
  2070. }
  2071. m_pPropGridManager->HideProperty( id, true );
  2072. }
  2073. // -----------------------------------------------------------------------
  2074. #include "wx/colordlg.h"
  2075. void
  2076. FormMain::OnSetBackgroundColour( wxCommandEvent& event )
  2077. {
  2078. wxPropertyGrid* pg = m_pPropGridManager->GetGrid();
  2079. wxPGProperty* prop = pg->GetSelection();
  2080. if ( !prop )
  2081. {
  2082. wxMessageBox(wxT("First select a property."));
  2083. return;
  2084. }
  2085. wxColour col = ::wxGetColourFromUser(this, *wxWHITE, "Choose colour");
  2086. if ( col.IsOk() )
  2087. {
  2088. bool recursively = (event.GetId()==ID_SETBGCOLOURRECUR) ? true : false;
  2089. pg->SetPropertyBackgroundColour(prop, col, recursively);
  2090. }
  2091. }
  2092. // -----------------------------------------------------------------------
  2093. void FormMain::OnInsertPage( wxCommandEvent& WXUNUSED(event) )
  2094. {
  2095. m_pPropGridManager->AddPage(wxT("New Page"));
  2096. }
  2097. // -----------------------------------------------------------------------
  2098. void FormMain::OnRemovePage( wxCommandEvent& WXUNUSED(event) )
  2099. {
  2100. m_pPropGridManager->RemovePage(m_pPropGridManager->GetSelectedPage());
  2101. }
  2102. // -----------------------------------------------------------------------
  2103. void FormMain::OnSaveState( wxCommandEvent& WXUNUSED(event) )
  2104. {
  2105. m_savedState = m_pPropGridManager->SaveEditableState();
  2106. wxLogDebug(wxT("Saved editable state string: \"%s\""), m_savedState.c_str());
  2107. }
  2108. // -----------------------------------------------------------------------
  2109. void FormMain::OnRestoreState( wxCommandEvent& WXUNUSED(event) )
  2110. {
  2111. m_pPropGridManager->RestoreEditableState(m_savedState);
  2112. }
  2113. // -----------------------------------------------------------------------
  2114. void FormMain::OnSetSpinCtrlEditorClick( wxCommandEvent& WXUNUSED(event) )
  2115. {
  2116. #if wxUSE_SPINBTN
  2117. wxPGProperty* pgId = m_pPropGridManager->GetSelection();
  2118. if ( pgId )
  2119. m_pPropGridManager->SetPropertyEditor( pgId, wxPGEditor_SpinCtrl );
  2120. else
  2121. wxMessageBox(wxT("First select a property"));
  2122. #endif
  2123. }
  2124. // -----------------------------------------------------------------------
  2125. void FormMain::OnTestReplaceClick( wxCommandEvent& WXUNUSED(event) )
  2126. {
  2127. wxPGProperty* pgId = m_pPropGridManager->GetSelection();
  2128. if ( pgId )
  2129. {
  2130. wxPGChoices choices;
  2131. choices.Add(wxT("Flag 0"),0x0001);
  2132. choices.Add(wxT("Flag 1"),0x0002);
  2133. choices.Add(wxT("Flag 2"),0x0004);
  2134. choices.Add(wxT("Flag 3"),0x0008);
  2135. wxPGProperty* newId = m_pPropGridManager->ReplaceProperty( pgId,
  2136. new wxFlagsProperty(wxT("ReplaceFlagsProperty"), wxPG_LABEL, choices, 0x0003) );
  2137. m_pPropGridManager->SetPropertyAttribute( newId,
  2138. wxPG_BOOL_USE_CHECKBOX,
  2139. true,
  2140. wxPG_RECURSE );
  2141. }
  2142. else
  2143. wxMessageBox(wxT("First select a property"));
  2144. }
  2145. // -----------------------------------------------------------------------
  2146. void FormMain::OnClearModifyStatusClick( wxCommandEvent& WXUNUSED(event) )
  2147. {
  2148. m_pPropGridManager->ClearModifiedStatus();
  2149. }
  2150. // -----------------------------------------------------------------------
  2151. // Freeze check-box checked?
  2152. void FormMain::OnFreezeClick( wxCommandEvent& event )
  2153. {
  2154. if ( !m_pPropGridManager ) return;
  2155. if ( event.IsChecked() )
  2156. {
  2157. if ( !m_pPropGridManager->IsFrozen() )
  2158. {
  2159. m_pPropGridManager->Freeze();
  2160. }
  2161. }
  2162. else
  2163. {
  2164. if ( m_pPropGridManager->IsFrozen() )
  2165. {
  2166. m_pPropGridManager->Thaw();
  2167. m_pPropGridManager->Refresh();
  2168. }
  2169. }
  2170. }
  2171. // -----------------------------------------------------------------------
  2172. void FormMain::OnEnableLabelEditing( wxCommandEvent& WXUNUSED(event) )
  2173. {
  2174. m_propGrid->MakeColumnEditable(0);
  2175. }
  2176. // -----------------------------------------------------------------------
  2177. void FormMain::OnShowHeader( wxCommandEvent& event )
  2178. {
  2179. m_pPropGridManager->ShowHeader(event.IsChecked());
  2180. m_pPropGridManager->SetColumnTitle(2, _("Units"));
  2181. }
  2182. // -----------------------------------------------------------------------
  2183. void FormMain::OnAbout(wxCommandEvent& WXUNUSED(event))
  2184. {
  2185. wxString msg;
  2186. msg.Printf( wxT("wxPropertyGrid Sample")
  2187. #if wxUSE_UNICODE
  2188. #if defined(wxUSE_UNICODE_UTF8) && wxUSE_UNICODE_UTF8
  2189. wxT(" <utf-8>")
  2190. #else
  2191. wxT(" <unicode>")
  2192. #endif
  2193. #else
  2194. wxT(" <ansi>")
  2195. #endif
  2196. #ifdef __WXDEBUG__
  2197. wxT(" <debug>")
  2198. #else
  2199. wxT(" <release>")
  2200. #endif
  2201. wxT("\n\n")
  2202. wxT("Programmed by %s\n\n")
  2203. wxT("Using %s\n\n"),
  2204. wxT("Jaakko Salli"), wxVERSION_STRING
  2205. );
  2206. wxMessageBox(msg, wxT("About"), wxOK | wxICON_INFORMATION, this);
  2207. }
  2208. // -----------------------------------------------------------------------
  2209. void FormMain::OnColourScheme( wxCommandEvent& event )
  2210. {
  2211. int id = event.GetId();
  2212. if ( id == ID_COLOURSCHEME1 )
  2213. {
  2214. m_pPropGridManager->GetGrid()->ResetColours();
  2215. }
  2216. else if ( id == ID_COLOURSCHEME2 )
  2217. {
  2218. // white
  2219. wxColour my_grey_1(212,208,200);
  2220. wxColour my_grey_3(113,111,100);
  2221. m_pPropGridManager->Freeze();
  2222. m_pPropGridManager->GetGrid()->SetMarginColour( *wxWHITE );
  2223. m_pPropGridManager->GetGrid()->SetCaptionBackgroundColour( *wxWHITE );
  2224. m_pPropGridManager->GetGrid()->SetCellBackgroundColour( *wxWHITE );
  2225. m_pPropGridManager->GetGrid()->SetCellTextColour( my_grey_3 );
  2226. m_pPropGridManager->GetGrid()->SetLineColour( my_grey_1 ); //wxColour(160,160,160)
  2227. m_pPropGridManager->Thaw();
  2228. }
  2229. else if ( id == ID_COLOURSCHEME3 )
  2230. {
  2231. // .NET
  2232. wxColour my_grey_1(212,208,200);
  2233. wxColour my_grey_2(236,233,216);
  2234. m_pPropGridManager->Freeze();
  2235. m_pPropGridManager->GetGrid()->SetMarginColour( my_grey_1 );
  2236. m_pPropGridManager->GetGrid()->SetCaptionBackgroundColour( my_grey_1 );
  2237. m_pPropGridManager->GetGrid()->SetLineColour( my_grey_1 );
  2238. m_pPropGridManager->Thaw();
  2239. }
  2240. else if ( id == ID_COLOURSCHEME4 )
  2241. {
  2242. // cream
  2243. wxColour my_grey_1(212,208,200);
  2244. wxColour my_grey_2(241,239,226);
  2245. wxColour my_grey_3(113,111,100);
  2246. m_pPropGridManager->Freeze();
  2247. m_pPropGridManager->GetGrid()->SetMarginColour( *wxWHITE );
  2248. m_pPropGridManager->GetGrid()->SetCaptionBackgroundColour( *wxWHITE );
  2249. m_pPropGridManager->GetGrid()->SetCellBackgroundColour( my_grey_2 );
  2250. m_pPropGridManager->GetGrid()->SetCellBackgroundColour( my_grey_2 );
  2251. m_pPropGridManager->GetGrid()->SetCellTextColour( my_grey_3 );
  2252. m_pPropGridManager->GetGrid()->SetLineColour( my_grey_1 );
  2253. m_pPropGridManager->Thaw();
  2254. }
  2255. }
  2256. // -----------------------------------------------------------------------
  2257. void FormMain::OnCatColours( wxCommandEvent& event )
  2258. {
  2259. wxPropertyGrid* pg = m_pPropGridManager->GetGrid();
  2260. m_pPropGridManager->Freeze();
  2261. if ( event.IsChecked() )
  2262. {
  2263. // Set custom colours.
  2264. pg->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,0), false );
  2265. pg->SetPropertyBackgroundColour( wxT("Appearance"), wxColour(255,255,183) );
  2266. pg->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,183) );
  2267. pg->SetPropertyTextColour( wxT("PositionCategory"), wxColour(0,255,0), false );
  2268. pg->SetPropertyBackgroundColour( wxT("PositionCategory"), wxColour(255,226,190) );
  2269. pg->SetPropertyTextColour( wxT("PositionCategory"), wxColour(255,0,190) );
  2270. pg->SetPropertyTextColour( wxT("Environment"), wxColour(0,0,255), false );
  2271. pg->SetPropertyBackgroundColour( wxT("Environment"), wxColour(208,240,175) );
  2272. pg->SetPropertyTextColour( wxT("Environment"), wxColour(255,255,255) );
  2273. pg->SetPropertyBackgroundColour( wxT("More Examples"), wxColour(172,237,255) );
  2274. pg->SetPropertyTextColour( wxT("More Examples"), wxColour(172,0,255) );
  2275. }
  2276. else
  2277. {
  2278. // Revert to original.
  2279. pg->SetPropertyColoursToDefault( wxT("Appearance") );
  2280. pg->SetPropertyColoursToDefault( wxT("PositionCategory") );
  2281. pg->SetPropertyColoursToDefault( wxT("Environment") );
  2282. pg->SetPropertyColoursToDefault( wxT("More Examples") );
  2283. }
  2284. m_pPropGridManager->Thaw();
  2285. m_pPropGridManager->Refresh();
  2286. }
  2287. // -----------------------------------------------------------------------
  2288. #define ADD_FLAG(FLAG) \
  2289. chs.Add(wxT(#FLAG)); \
  2290. vls.Add(FLAG); \
  2291. if ( (flags & FLAG) == FLAG ) sel.Add(ind); \
  2292. ind++;
  2293. void FormMain::OnSelectStyle( wxCommandEvent& WXUNUSED(event) )
  2294. {
  2295. int style = 0;
  2296. int extraStyle = 0;
  2297. {
  2298. wxArrayString chs;
  2299. wxArrayInt vls;
  2300. wxArrayInt sel;
  2301. unsigned int ind = 0;
  2302. int flags = m_pPropGridManager->GetWindowStyle();
  2303. ADD_FLAG(wxPG_HIDE_CATEGORIES)
  2304. ADD_FLAG(wxPG_AUTO_SORT)
  2305. ADD_FLAG(wxPG_BOLD_MODIFIED)
  2306. ADD_FLAG(wxPG_SPLITTER_AUTO_CENTER)
  2307. ADD_FLAG(wxPG_TOOLTIPS)
  2308. ADD_FLAG(wxPG_STATIC_SPLITTER)
  2309. ADD_FLAG(wxPG_HIDE_MARGIN)
  2310. ADD_FLAG(wxPG_LIMITED_EDITING)
  2311. ADD_FLAG(wxPG_TOOLBAR)
  2312. ADD_FLAG(wxPG_DESCRIPTION)
  2313. ADD_FLAG(wxPG_NO_INTERNAL_BORDER)
  2314. wxMultiChoiceDialog dlg( this, wxT("Select window styles to use"),
  2315. wxT("wxPropertyGrid Window Style"), chs );
  2316. dlg.SetSelections(sel);
  2317. if ( dlg.ShowModal() == wxID_CANCEL )
  2318. return;
  2319. flags = 0;
  2320. sel = dlg.GetSelections();
  2321. for ( ind = 0; ind < sel.size(); ind++ )
  2322. flags |= vls[sel[ind]];
  2323. style = flags;
  2324. }
  2325. {
  2326. wxArrayString chs;
  2327. wxArrayInt vls;
  2328. wxArrayInt sel;
  2329. unsigned int ind = 0;
  2330. int flags = m_pPropGridManager->GetExtraStyle();
  2331. ADD_FLAG(wxPG_EX_INIT_NOCAT)
  2332. ADD_FLAG(wxPG_EX_NO_FLAT_TOOLBAR)
  2333. ADD_FLAG(wxPG_EX_MODE_BUTTONS)
  2334. ADD_FLAG(wxPG_EX_HELP_AS_TOOLTIPS)
  2335. ADD_FLAG(wxPG_EX_NATIVE_DOUBLE_BUFFERING)
  2336. ADD_FLAG(wxPG_EX_AUTO_UNSPECIFIED_VALUES)
  2337. ADD_FLAG(wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES)
  2338. ADD_FLAG(wxPG_EX_HIDE_PAGE_BUTTONS)
  2339. ADD_FLAG(wxPG_EX_MULTIPLE_SELECTION)
  2340. ADD_FLAG(wxPG_EX_ENABLE_TLP_TRACKING)
  2341. ADD_FLAG(wxPG_EX_NO_TOOLBAR_DIVIDER)
  2342. ADD_FLAG(wxPG_EX_TOOLBAR_SEPARATOR)
  2343. wxMultiChoiceDialog dlg( this, wxT("Select extra window styles to use"),
  2344. wxT("wxPropertyGrid Extra Style"), chs );
  2345. dlg.SetSelections(sel);
  2346. if ( dlg.ShowModal() == wxID_CANCEL )
  2347. return;
  2348. flags = 0;
  2349. sel = dlg.GetSelections();
  2350. for ( ind = 0; ind < sel.size(); ind++ )
  2351. flags |= vls[sel[ind]];
  2352. extraStyle = flags;
  2353. }
  2354. CreateGrid( style, extraStyle );
  2355. FinalizeFramePosition();
  2356. }
  2357. // -----------------------------------------------------------------------
  2358. void FormMain::OnSetColumns( wxCommandEvent& WXUNUSED(event) )
  2359. {
  2360. long colCount = ::wxGetNumberFromUser(wxT("Enter number of columns (2-20)."),wxT("Columns:"),
  2361. wxT("Change Columns"),m_pPropGridManager->GetColumnCount(),
  2362. 2,20);
  2363. if ( colCount >= 2 )
  2364. {
  2365. m_pPropGridManager->SetColumnCount(colCount);
  2366. }
  2367. }
  2368. // -----------------------------------------------------------------------
  2369. void FormMain::OnSetPropertyValue( wxCommandEvent& WXUNUSED(event) )
  2370. {
  2371. wxPropertyGrid* pg = m_pPropGridManager->GetGrid();
  2372. wxPGProperty* selected = pg->GetSelection();
  2373. if ( selected )
  2374. {
  2375. wxString value = ::wxGetTextFromUser( wxT("Enter new value:") );
  2376. pg->SetPropertyValue( selected, value );
  2377. }
  2378. }
  2379. // -----------------------------------------------------------------------
  2380. void FormMain::OnInsertChoice( wxCommandEvent& WXUNUSED(event) )
  2381. {
  2382. wxPropertyGrid* pg = m_pPropGridManager->GetGrid();
  2383. wxPGProperty* selected = pg->GetSelection();
  2384. const wxPGChoices& choices = selected->GetChoices();
  2385. // Insert new choice to the center of list
  2386. if ( choices.IsOk() )
  2387. {
  2388. int pos = choices.GetCount() / 2;
  2389. selected->InsertChoice(wxT("New Choice"), pos);
  2390. }
  2391. else
  2392. {
  2393. ::wxMessageBox(wxT("First select a property with some choices."));
  2394. }
  2395. }
  2396. // -----------------------------------------------------------------------
  2397. void FormMain::OnDeleteChoice( wxCommandEvent& WXUNUSED(event) )
  2398. {
  2399. wxPropertyGrid* pg = m_pPropGridManager->GetGrid();
  2400. wxPGProperty* selected = pg->GetSelection();
  2401. const wxPGChoices& choices = selected->GetChoices();
  2402. // Deletes choice from the center of list
  2403. if ( choices.IsOk() )
  2404. {
  2405. int pos = choices.GetCount() / 2;
  2406. selected->DeleteChoice(pos);
  2407. }
  2408. else
  2409. {
  2410. ::wxMessageBox(wxT("First select a property with some choices."));
  2411. }
  2412. }
  2413. // -----------------------------------------------------------------------
  2414. #include <wx/colordlg.h>
  2415. void FormMain::OnMisc ( wxCommandEvent& event )
  2416. {
  2417. int id = event.GetId();
  2418. if ( id == ID_STATICLAYOUT )
  2419. {
  2420. long wsf = m_pPropGridManager->GetWindowStyleFlag();
  2421. if ( event.IsChecked() ) m_pPropGridManager->SetWindowStyleFlag( wsf|wxPG_STATIC_LAYOUT );
  2422. else m_pPropGridManager->SetWindowStyleFlag( wsf&~(wxPG_STATIC_LAYOUT) );
  2423. }
  2424. else if ( id == ID_COLLAPSEALL )
  2425. {
  2426. wxPGVIterator it;
  2427. wxPropertyGrid* pg = m_pPropGridManager->GetGrid();
  2428. for ( it = pg->GetVIterator( wxPG_ITERATE_ALL ); !it.AtEnd(); it.Next() )
  2429. it.GetProperty()->SetExpanded( false );
  2430. pg->RefreshGrid();
  2431. }
  2432. else if ( id == ID_GETVALUES )
  2433. {
  2434. m_storedValues = m_pPropGridManager->GetGrid()->GetPropertyValues(wxT("Test"),
  2435. m_pPropGridManager->GetGrid()->GetRoot(),
  2436. wxPG_KEEP_STRUCTURE|wxPG_INC_ATTRIBUTES);
  2437. }
  2438. else if ( id == ID_SETVALUES )
  2439. {
  2440. if ( m_storedValues.GetType() == wxT("list") )
  2441. {
  2442. m_pPropGridManager->GetGrid()->SetPropertyValues(m_storedValues);
  2443. }
  2444. else
  2445. wxMessageBox(wxT("First use Get Property Values."));
  2446. }
  2447. else if ( id == ID_SETVALUES2 )
  2448. {
  2449. wxVariant list;
  2450. list.NullList();
  2451. list.Append( wxVariant((long)1234,wxT("VariantLong")) );
  2452. list.Append( wxVariant((bool)TRUE,wxT("VariantBool")) );
  2453. list.Append( wxVariant(wxT("Test Text"),wxT("VariantString")) );
  2454. m_pPropGridManager->GetGrid()->SetPropertyValues(list);
  2455. }
  2456. else if ( id == ID_COLLAPSE )
  2457. {
  2458. // Collapses selected.
  2459. wxPGProperty* id = m_pPropGridManager->GetSelection();
  2460. if ( id )
  2461. {
  2462. m_pPropGridManager->Collapse(id);
  2463. }
  2464. }
  2465. else if ( id == ID_RUNTESTFULL )
  2466. {
  2467. // Runs a regression test.
  2468. RunTests(true);
  2469. }
  2470. else if ( id == ID_RUNTESTPARTIAL )
  2471. {
  2472. // Runs a regression test.
  2473. RunTests(false);
  2474. }
  2475. else if ( id == ID_UNSPECIFY )
  2476. {
  2477. wxPGProperty* prop = m_pPropGridManager->GetSelection();
  2478. if ( prop )
  2479. {
  2480. m_pPropGridManager->SetPropertyValueUnspecified(prop);
  2481. prop->RefreshEditor();
  2482. }
  2483. }
  2484. }
  2485. // -----------------------------------------------------------------------
  2486. void FormMain::OnPopulateClick( wxCommandEvent& event )
  2487. {
  2488. int id = event.GetId();
  2489. m_propGrid->Clear();
  2490. m_propGrid->Freeze();
  2491. if ( id == ID_POPULATE1 )
  2492. {
  2493. PopulateWithStandardItems();
  2494. }
  2495. else if ( id == ID_POPULATE2 )
  2496. {
  2497. PopulateWithLibraryConfig();
  2498. }
  2499. m_propGrid->Thaw();
  2500. }
  2501. // -----------------------------------------------------------------------
  2502. void DisplayMinimalFrame(wxWindow* parent); // in minimal.cpp
  2503. void FormMain::OnRunMinimalClick( wxCommandEvent& WXUNUSED(event) )
  2504. {
  2505. DisplayMinimalFrame(this);
  2506. }
  2507. // -----------------------------------------------------------------------
  2508. FormMain::~FormMain()
  2509. {
  2510. }
  2511. // -----------------------------------------------------------------------
  2512. IMPLEMENT_APP(cxApplication)
  2513. bool cxApplication::OnInit()
  2514. {
  2515. //wxLocale Locale;
  2516. //Locale.Init(wxLANGUAGE_FINNISH);
  2517. FormMain* frame = Form1 = new FormMain( wxT("wxPropertyGrid Sample"), wxPoint(0,0), wxSize(300,500) );
  2518. frame->Show(true);
  2519. //
  2520. // Parse command-line
  2521. wxApp& app = wxGetApp();
  2522. if ( app.argc > 1 )
  2523. {
  2524. wxString s = app.argv[1];
  2525. if ( s == wxT("--run-tests") )
  2526. {
  2527. //
  2528. // Run tests
  2529. bool testResult = frame->RunTests(true);
  2530. if ( testResult )
  2531. return false;
  2532. }
  2533. }
  2534. return true;
  2535. }
  2536. // -----------------------------------------------------------------------
  2537. void FormMain::OnIdle( wxIdleEvent& event )
  2538. {
  2539. /*
  2540. // This code is useful for debugging focus problems
  2541. static wxWindow* last_focus = (wxWindow*) NULL;
  2542. wxWindow* cur_focus = ::wxWindow::FindFocus();
  2543. if ( cur_focus != last_focus )
  2544. {
  2545. const wxChar* class_name = wxT("<none>");
  2546. if ( cur_focus )
  2547. class_name = cur_focus->GetClassInfo()->GetClassName();
  2548. last_focus = cur_focus;
  2549. wxLogDebug( wxT("FOCUSED: %s %X"),
  2550. class_name,
  2551. (unsigned int)cur_focus);
  2552. }
  2553. */
  2554. event.Skip();
  2555. }
  2556. // -----------------------------------------------------------------------
  2557. wxPGProperty* GetRealRoot(wxPropertyGrid *grid)
  2558. {
  2559. wxPGProperty *property = grid->GetRoot();
  2560. return property ? grid->GetFirstChild(property) : NULL;
  2561. }
  2562. void GetColumnWidths(wxClientDC &dc, wxPropertyGrid *grid, wxPGProperty *root, int width[3])
  2563. {
  2564. wxPropertyGridPageState *state = grid->GetState();
  2565. width[0] =
  2566. width[1] =
  2567. width[2] = 0;
  2568. int minWidths[3] = { state->GetColumnMinWidth(0),
  2569. state->GetColumnMinWidth(1),
  2570. state->GetColumnMinWidth(2) };
  2571. unsigned ii;
  2572. for (ii = 0; ii < root->GetChildCount(); ++ii)
  2573. {
  2574. wxPGProperty* p = root->Item(ii);
  2575. width[0] = wxMax(width[0], state->GetColumnFullWidth(dc, p, 0));
  2576. width[1] = wxMax(width[1], state->GetColumnFullWidth(dc, p, 1));
  2577. width[2] = wxMax(width[2], state->GetColumnFullWidth(dc, p, 2));
  2578. }
  2579. for (ii = 0; ii < root->GetChildCount(); ++ii)
  2580. {
  2581. wxPGProperty* p = root->Item(ii);
  2582. if (p->IsExpanded())
  2583. {
  2584. int w[3];
  2585. GetColumnWidths(dc, grid, p, w);
  2586. width[0] = wxMax(width[0], w[0]);
  2587. width[1] = wxMax(width[1], w[1]);
  2588. width[2] = wxMax(width[2], w[2]);
  2589. }
  2590. }
  2591. width[0] = wxMax(width[0], minWidths[0]);
  2592. width[1] = wxMax(width[1], minWidths[1]);
  2593. width[2] = wxMax(width[2], minWidths[2]);
  2594. }
  2595. void GetColumnWidths(wxPropertyGrid *grid, wxPGProperty *root, int width[3])
  2596. {
  2597. wxClientDC dc(grid);
  2598. dc.SetFont(grid->GetFont());
  2599. GetColumnWidths(dc, grid, root, width);
  2600. }
  2601. void SetMinSize(wxPropertyGrid *grid)
  2602. {
  2603. wxPGProperty *p = GetRealRoot(grid);
  2604. wxPGProperty *first = grid->wxPropertyGridInterface::GetFirst(wxPG_ITERATE_ALL);
  2605. wxPGProperty *last = grid->GetLastItem(wxPG_ITERATE_DEFAULT);
  2606. wxRect rect = grid->GetPropertyRect(first, last);
  2607. int height = rect.height + 2 * grid->GetVerticalSpacing();
  2608. // add some height when the root item is collapsed,
  2609. // this is needed to prevent the vertical scroll from showing
  2610. if (!grid->IsPropertyExpanded(p))
  2611. height += 2 * grid->GetVerticalSpacing();
  2612. int width[3];
  2613. GetColumnWidths(grid, grid->GetRoot(), width);
  2614. rect.width = width[0]+width[1]+width[2];
  2615. int minWidth = (wxSystemSettings::GetMetric(wxSYS_SCREEN_X, grid->GetParent())*3)/2;
  2616. int minHeight = (wxSystemSettings::GetMetric(wxSYS_SCREEN_Y, grid->GetParent())*3)/2;
  2617. wxSize size(wxMin(minWidth, rect.width + grid->GetMarginWidth()), wxMin(minHeight, height));
  2618. grid->SetMinSize(size);
  2619. int proportions[3];
  2620. proportions[0] = static_cast<int>(floor((double)width[0]/size.x*100.0+0.5));
  2621. proportions[1] = static_cast<int>(floor((double)width[1]/size.x*100.0+0.5));
  2622. proportions[2]= wxMax(100 - proportions[0] - proportions[1], 0);
  2623. grid->SetColumnProportion(0, proportions[0]);
  2624. grid->SetColumnProportion(1, proportions[1]);
  2625. grid->SetColumnProportion(2, proportions[2]);
  2626. grid->ResetColumnSizes(true);
  2627. }
  2628. struct PropertyGridPopup : wxPopupWindow
  2629. {
  2630. wxScrolledWindow *m_panel;
  2631. wxPropertyGrid *m_grid;
  2632. wxBoxSizer *m_sizer;
  2633. PropertyGridPopup(wxWindow *parent) : wxPopupWindow(parent, wxBORDER_NONE|wxWANTS_CHARS)
  2634. {
  2635. m_panel = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxSize(200, 200));
  2636. m_grid = new wxPropertyGrid(m_panel, ID_POPUPGRID, wxDefaultPosition, wxSize(400,400), wxPG_SPLITTER_AUTO_CENTER);
  2637. m_grid->SetColumnCount(3);
  2638. wxPGProperty *prop=m_grid->Append(new wxStringProperty("test_name", wxPG_LABEL, "test_value"));
  2639. m_grid->SetPropertyAttribute(prop, wxT("Units"), "type");
  2640. wxPGProperty *prop1 = m_grid->AppendIn(prop, new wxStringProperty("sub_name1", wxPG_LABEL, "sub_value1"));
  2641. m_grid->AppendIn(prop1, new wxSystemColourProperty(wxT("Cell Colour"),wxPG_LABEL, m_grid->GetGrid()->GetCellBackgroundColour()));
  2642. wxPGProperty *prop2 = m_grid->AppendIn(prop, new wxStringProperty("sub_name2", wxPG_LABEL, "sub_value2"));
  2643. m_grid->AppendIn(prop2, new wxStringProperty("sub_name21", wxPG_LABEL, "sub_value21"));
  2644. wxArrayDouble arrdbl;
  2645. arrdbl.Add(-1.0); arrdbl.Add(-0.5); arrdbl.Add(0.0); arrdbl.Add(0.5); arrdbl.Add(1.0);
  2646. m_grid->AppendIn(prop, new wxArrayDoubleProperty(wxT("ArrayDoubleProperty"),wxPG_LABEL,arrdbl) );
  2647. m_grid->AppendIn(prop, new wxFontProperty(wxT("Font"),wxPG_LABEL));
  2648. m_grid->AppendIn(prop2, new wxStringProperty("sub_name22", wxPG_LABEL, "sub_value22"));
  2649. m_grid->AppendIn(prop2, new wxStringProperty("sub_name23", wxPG_LABEL, "sub_value23"));
  2650. prop2->SetExpanded(false);
  2651. ::SetMinSize(m_grid);
  2652. m_sizer = new wxBoxSizer( wxVERTICAL );
  2653. m_sizer->Add(m_grid, 0, wxALL | wxEXPAND, 0);
  2654. m_panel->SetAutoLayout(true);
  2655. m_panel->SetSizer(m_sizer);
  2656. m_sizer->Fit(m_panel);
  2657. m_sizer->Fit(this);
  2658. }
  2659. void OnCollapse(wxPropertyGridEvent& WXUNUSED(event))
  2660. {
  2661. wxLogMessage("OnCollapse");
  2662. Fit();
  2663. }
  2664. void OnExpand(wxPropertyGridEvent& WXUNUSED(event))
  2665. {
  2666. wxLogMessage("OnExpand");
  2667. Fit();
  2668. }
  2669. void Fit()
  2670. {
  2671. ::SetMinSize(m_grid);
  2672. m_sizer->Fit(m_panel);
  2673. wxPoint pos = GetScreenPosition();
  2674. wxSize size = m_panel->GetScreenRect().GetSize();
  2675. SetSize(pos.x, pos.y, size.x, size.y);
  2676. }
  2677. wxDECLARE_ABSTRACT_CLASS(PropertyGridPopup);
  2678. wxDECLARE_EVENT_TABLE();
  2679. };
  2680. IMPLEMENT_CLASS(PropertyGridPopup, wxPopupWindow)
  2681. wxBEGIN_EVENT_TABLE(PropertyGridPopup, wxPopupWindow)
  2682. EVT_PG_ITEM_COLLAPSED(ID_POPUPGRID, PropertyGridPopup::OnCollapse)
  2683. EVT_PG_ITEM_EXPANDED(ID_POPUPGRID, PropertyGridPopup::OnExpand)
  2684. wxEND_EVENT_TABLE()
  2685. void FormMain::OnShowPopup(wxCommandEvent& WXUNUSED(event))
  2686. {
  2687. static PropertyGridPopup *popup = NULL;
  2688. if ( popup )
  2689. {
  2690. delete popup;
  2691. popup = NULL;
  2692. return;
  2693. }
  2694. popup = new PropertyGridPopup(this);
  2695. wxPoint pt = wxGetMousePosition();
  2696. popup->Position(pt, wxSize(0, 0));
  2697. popup->Show();
  2698. }