grid.h 155 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: grid.h
  3. // Purpose: interface of wxGrid and related classes
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxGridCellRenderer
  9. This class is responsible for actually drawing the cell in the grid. You
  10. may pass it to the wxGridCellAttr (below) to change the format of one given
  11. cell or to wxGrid::SetDefaultRenderer() to change the view of all cells.
  12. This is an abstract class, and you will normally use one of the predefined
  13. derived classes or derive your own class from it.
  14. @library{wxadv}
  15. @category{grid}
  16. @see wxGridCellAutoWrapStringRenderer, wxGridCellBoolRenderer,
  17. wxGridCellDateTimeRenderer, wxGridCellEnumRenderer,
  18. wxGridCellFloatRenderer, wxGridCellNumberRenderer,
  19. wxGridCellStringRenderer
  20. */
  21. class wxGridCellRenderer : public wxClientDataContainer, public wxRefCounter
  22. {
  23. public:
  24. wxGridCellRenderer();
  25. /**
  26. This function must be implemented in derived classes to return a copy
  27. of itself.
  28. */
  29. virtual wxGridCellRenderer* Clone() const = 0;
  30. /**
  31. Draw the given cell on the provided DC inside the given rectangle using
  32. the style specified by the attribute and the default or selected state
  33. corresponding to the isSelected value.
  34. This pure virtual function has a default implementation which will
  35. prepare the DC using the given attribute: it will draw the rectangle
  36. with the background colour from attr and set the text colour and font.
  37. */
  38. virtual void Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
  39. const wxRect& rect, int row, int col,
  40. bool isSelected) = 0;
  41. /**
  42. Get the preferred size of the cell for its contents.
  43. */
  44. virtual wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
  45. int row, int col) = 0;
  46. protected:
  47. /**
  48. The destructor is private because only DecRef() can delete us.
  49. */
  50. virtual ~wxGridCellRenderer();
  51. };
  52. /**
  53. @class wxGridCellAutoWrapStringRenderer
  54. This class may be used to format string data in a cell. The too
  55. long lines are wrapped to be shown entirely at word boundaries.
  56. @library{wxadv}
  57. @category{grid}
  58. @see wxGridCellRenderer, wxGridCellBoolRenderer,
  59. wxGridCellDateTimeRenderer, wxGridCellEnumRenderer,
  60. wxGridCellFloatRenderer, wxGridCellNumberRenderer,
  61. wxGridCellStringRenderer
  62. */
  63. class wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
  64. {
  65. public:
  66. /**
  67. Default constructor.
  68. */
  69. wxGridCellAutoWrapStringRenderer();
  70. };
  71. /**
  72. @class wxGridCellBoolRenderer
  73. This class may be used to format boolean data in a cell.
  74. @library{wxadv}
  75. @category{grid}
  76. @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer,
  77. wxGridCellDateTimeRenderer, wxGridCellEnumRenderer,
  78. wxGridCellFloatRenderer, wxGridCellNumberRenderer,
  79. wxGridCellStringRenderer
  80. */
  81. class wxGridCellBoolRenderer : public wxGridCellRenderer
  82. {
  83. public:
  84. /**
  85. Default constructor.
  86. */
  87. wxGridCellBoolRenderer();
  88. };
  89. /**
  90. @class wxGridCellDateTimeRenderer
  91. This class may be used to format a date/time data in a cell.
  92. The class wxDateTime is used internally to display the local date/time
  93. or to parse the string date entered in the cell thanks to the defined format.
  94. @library{wxadv}
  95. @category{grid}
  96. @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer,
  97. wxGridCellBoolRenderer, wxGridCellEnumRenderer,
  98. wxGridCellFloatRenderer, wxGridCellNumberRenderer,
  99. wxGridCellStringRenderer
  100. */
  101. class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
  102. {
  103. public:
  104. /**
  105. Date/time renderer constructor.
  106. @param outformat
  107. strptime()-like format string used the parse the output date/time.
  108. @param informat
  109. strptime()-like format string used to parse the string entered in the cell.
  110. */
  111. wxGridCellDateTimeRenderer(const wxString& outformat = wxDefaultDateTimeFormat,
  112. const wxString& informat = wxDefaultDateTimeFormat);
  113. /**
  114. Sets the strptime()-like format string which will be used to parse
  115. the date/time.
  116. @param params
  117. strptime()-like format string used to parse the date/time.
  118. */
  119. virtual void SetParameters(const wxString& params);
  120. };
  121. /**
  122. @class wxGridCellEnumRenderer
  123. This class may be used to render in a cell a number as a textual
  124. equivalent.
  125. The corresponding text strings are specified as comma-separated items in
  126. the string passed to this renderer ctor or SetParameters() method. For
  127. example, if this string is @c "John,Fred,Bob" the cell will be rendered as
  128. "John", "Fred" or "Bob" if its contents is 0, 1 or 2 respectively.
  129. @library{wxadv}
  130. @category{grid}
  131. @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer,
  132. wxGridCellBoolRenderer, wxGridCellDateTimeRenderer,
  133. wxGridCellFloatRenderer, wxGridCellNumberRenderer,
  134. wxGridCellStringRenderer
  135. */
  136. class wxGridCellEnumRenderer : public wxGridCellStringRenderer
  137. {
  138. public:
  139. /**
  140. Enum renderer ctor.
  141. @param choices
  142. Comma separated string parameters "item1[,item2[...,itemN]]".
  143. */
  144. wxGridCellEnumRenderer( const wxString& choices = wxEmptyString );
  145. /**
  146. Sets the comma separated string content of the enum.
  147. @param params
  148. Comma separated string parameters "item1[,item2[...,itemN]]".
  149. */
  150. virtual void SetParameters(const wxString& params);
  151. };
  152. /**
  153. Specifier used to format the data to string for the numbers handled by
  154. wxGridCellFloatRenderer and wxGridCellFloatEditor.
  155. @since 2.9.3
  156. */
  157. enum wxGridCellFloatFormat
  158. {
  159. /// Decimal floating point (%f).
  160. wxGRID_FLOAT_FORMAT_FIXED = 0x0010,
  161. /// Scientific notation (mantissa/exponent) using e character (%e).
  162. wxGRID_FLOAT_FORMAT_SCIENTIFIC = 0x0020,
  163. /// Use the shorter of %e or %f (%g).
  164. wxGRID_FLOAT_FORMAT_COMPACT = 0x0040,
  165. /// To use in combination with one of the above formats for the upper
  166. /// case version (%F/%E/%G)
  167. wxGRID_FLOAT_FORMAT_UPPER = 0x0080,
  168. /// The format used by default (wxGRID_FLOAT_FORMAT_FIXED).
  169. wxGRID_FLOAT_FORMAT_DEFAULT = wxGRID_FLOAT_FORMAT_FIXED
  170. };
  171. /**
  172. @class wxGridCellFloatRenderer
  173. This class may be used to format floating point data in a cell.
  174. @library{wxadv}
  175. @category{grid}
  176. @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer,
  177. wxGridCellBoolRenderer, wxGridCellDateTimeRenderer,
  178. wxGridCellEnumRenderer, wxGridCellNumberRenderer,
  179. wxGridCellStringRenderer
  180. */
  181. class wxGridCellFloatRenderer : public wxGridCellStringRenderer
  182. {
  183. public:
  184. /**
  185. Float cell renderer ctor.
  186. @param width
  187. Minimum number of characters to be shown.
  188. @param precision
  189. Number of digits after the decimal dot.
  190. @param format
  191. The format used to display the string, must be a combination of
  192. ::wxGridCellFloatFormat enum elements. This parameter is only
  193. available since wxWidgets 2.9.3.
  194. */
  195. wxGridCellFloatRenderer(int width = -1, int precision = -1,
  196. int format = wxGRID_FLOAT_FORMAT_DEFAULT);
  197. /**
  198. Returns the specifier used to format the data to string.
  199. The returned value is a combination of ::wxGridCellFloatFormat elements.
  200. @since 2.9.3
  201. */
  202. int GetFormat() const;
  203. /**
  204. Returns the precision.
  205. */
  206. int GetPrecision() const;
  207. /**
  208. Returns the width.
  209. */
  210. int GetWidth() const;
  211. /**
  212. Set the format to use for display the number.
  213. @param format
  214. Must be a combination of ::wxGridCellFloatFormat enum elements.
  215. @since 2.9.3
  216. */
  217. void SetFormat(int format);
  218. /**
  219. The parameters string format is "width[,precision[,format]]" where
  220. @c format should be chosen between f|e|g|E|G (f is used by default)
  221. */
  222. virtual void SetParameters(const wxString& params);
  223. /**
  224. Sets the precision.
  225. */
  226. void SetPrecision(int precision);
  227. /**
  228. Sets the width.
  229. */
  230. void SetWidth(int width);
  231. };
  232. /**
  233. @class wxGridCellNumberRenderer
  234. This class may be used to format integer data in a cell.
  235. @library{wxadv}
  236. @category{grid}
  237. @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer,
  238. wxGridCellBoolRenderer, wxGridCellDateTimeRenderer,
  239. wxGridCellEnumRenderer, wxGridCellFloatRenderer,
  240. wxGridCellStringRenderer
  241. */
  242. class wxGridCellNumberRenderer : public wxGridCellStringRenderer
  243. {
  244. public:
  245. /**
  246. Default constructor.
  247. */
  248. wxGridCellNumberRenderer();
  249. };
  250. /**
  251. @class wxGridCellStringRenderer
  252. This class may be used to format string data in a cell; it is the default
  253. for string cells.
  254. @library{wxadv}
  255. @category{grid}
  256. @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer,
  257. wxGridCellBoolRenderer, wxGridCellDateTimeRenderer,
  258. wxGridCellEnumRenderer, wxGridCellFloatRenderer,
  259. wxGridCellNumberRenderer
  260. */
  261. class wxGridCellStringRenderer : public wxGridCellRenderer
  262. {
  263. public:
  264. /**
  265. Default constructor.
  266. */
  267. wxGridCellStringRenderer();
  268. };
  269. /**
  270. @class wxGridCellEditor
  271. This class is responsible for providing and manipulating the in-place edit
  272. controls for the grid. Instances of wxGridCellEditor (actually, instances
  273. of derived classes since it is an abstract class) can be associated with
  274. the cell attributes for individual cells, rows, columns, or even for the
  275. entire grid.
  276. @library{wxadv}
  277. @category{grid}
  278. @see wxGridCellAutoWrapStringEditor, wxGridCellBoolEditor,
  279. wxGridCellChoiceEditor, wxGridCellEnumEditor,
  280. wxGridCellFloatEditor, wxGridCellNumberEditor,
  281. wxGridCellTextEditor
  282. */
  283. class wxGridCellEditor : public wxClientDataContainer, public wxRefCounter
  284. {
  285. public:
  286. /**
  287. Default constructor.
  288. */
  289. wxGridCellEditor();
  290. /**
  291. Fetch the value from the table and prepare the edit control to begin
  292. editing.
  293. This function should save the original value of the grid cell at the
  294. given @a row and @a col and show the control allowing the user to
  295. change it.
  296. @see EndEdit()
  297. */
  298. virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
  299. /**
  300. Create a new object which is the copy of this one.
  301. */
  302. virtual wxGridCellEditor* Clone() const = 0;
  303. /**
  304. Creates the actual edit control.
  305. */
  306. virtual void Create(wxWindow* parent, wxWindowID id,
  307. wxEvtHandler* evtHandler) = 0;
  308. /**
  309. Final cleanup.
  310. */
  311. virtual void Destroy();
  312. /**
  313. End editing the cell.
  314. This function must check if the current value of the editing control is
  315. valid and different from the original value (available as @a oldval in
  316. its string form and possibly saved internally using its real type by
  317. BeginEdit()). If it isn't, it just returns @false, otherwise it must do
  318. the following:
  319. - Save the new value internally so that ApplyEdit() could apply it.
  320. - Fill @a newval (which is never @NULL) with the string
  321. representation of the new value.
  322. - Return @true
  323. Notice that it must @em not modify the grid as the change could still
  324. be vetoed.
  325. If the user-defined wxEVT_GRID_CELL_CHANGING event handler doesn't veto
  326. this change, ApplyEdit() will be called next.
  327. */
  328. virtual bool EndEdit(int row, int col, const wxGrid* grid,
  329. const wxString& oldval, wxString* newval) = 0;
  330. /**
  331. Effectively save the changes in the grid.
  332. This function should save the value of the control in the grid. It is
  333. called only after EndEdit() returns @true.
  334. */
  335. virtual void ApplyEdit(int row, int col, wxGrid* grid) = 0;
  336. /**
  337. Some types of controls on some platforms may need some help with the
  338. Return key.
  339. */
  340. virtual void HandleReturn(wxKeyEvent& event);
  341. /**
  342. Returns @true if the edit control has been created.
  343. */
  344. bool IsCreated();
  345. /**
  346. Draws the part of the cell not occupied by the control: the base class
  347. version just fills it with background colour from the attribute.
  348. */
  349. virtual void PaintBackground(wxDC& dc, const wxRect& rectCell, wxGridCellAttr& attr);
  350. /**
  351. Reset the value in the control back to its starting value.
  352. */
  353. virtual void Reset() = 0;
  354. /**
  355. Size and position the edit control.
  356. */
  357. virtual void SetSize(const wxRect& rect);
  358. /**
  359. Show or hide the edit control, use the specified attributes to set
  360. colours/fonts for it.
  361. */
  362. virtual void Show(bool show, wxGridCellAttr* attr = NULL);
  363. /**
  364. If the editor is enabled by clicking on the cell, this method will be
  365. called.
  366. */
  367. virtual void StartingClick();
  368. /**
  369. If the editor is enabled by pressing keys on the grid, this will be
  370. called to let the editor do something about that first key if desired.
  371. */
  372. virtual void StartingKey(wxKeyEvent& event);
  373. /**
  374. Returns the value currently in the editor control.
  375. */
  376. virtual wxString GetValue() const = 0;
  377. /**
  378. Get the wxControl used by this editor.
  379. */
  380. wxControl* GetControl() const;
  381. /**
  382. Set the wxControl that will be used by this cell editor for editing the
  383. value.
  384. */
  385. void SetControl(wxControl* control);
  386. protected:
  387. /**
  388. The destructor is private because only DecRef() can delete us.
  389. */
  390. virtual ~wxGridCellEditor();
  391. };
  392. /**
  393. @class wxGridCellAutoWrapStringEditor
  394. Grid cell editor for wrappable string/text data.
  395. @library{wxadv}
  396. @category{grid}
  397. @see wxGridCellEditor, wxGridCellBoolEditor, wxGridCellChoiceEditor,
  398. wxGridCellEnumEditor, wxGridCellFloatEditor,
  399. wxGridCellNumberEditor, wxGridCellTextEditor
  400. */
  401. class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
  402. {
  403. public:
  404. wxGridCellAutoWrapStringEditor();
  405. };
  406. /**
  407. @class wxGridCellBoolEditor
  408. Grid cell editor for boolean data.
  409. @library{wxadv}
  410. @category{grid}
  411. @see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
  412. wxGridCellChoiceEditor, wxGridCellEnumEditor,
  413. wxGridCellFloatEditor, wxGridCellNumberEditor,
  414. wxGridCellTextEditor
  415. */
  416. class wxGridCellBoolEditor : public wxGridCellEditor
  417. {
  418. public:
  419. /**
  420. Default constructor.
  421. */
  422. wxGridCellBoolEditor();
  423. /**
  424. Returns @true if the given @a value is equal to the string
  425. representation of the truth value we currently use (see
  426. UseStringValues()).
  427. */
  428. static bool IsTrueValue(const wxString& value);
  429. /**
  430. This method allows you to customize the values returned by GetValue()
  431. for the cell using this editor. By default, the default values of the
  432. arguments are used, i.e. @c "1" is returned if the cell is checked and
  433. an empty string otherwise.
  434. */
  435. static void UseStringValues(const wxString& valueTrue = "1",
  436. const wxString& valueFalse = wxEmptyString);
  437. };
  438. /**
  439. @class wxGridCellChoiceEditor
  440. Grid cell editor for string data providing the user a choice from a list of
  441. strings.
  442. @library{wxadv}
  443. @category{grid}
  444. @see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
  445. wxGridCellBoolEditor, wxGridCellEnumEditor,
  446. wxGridCellFloatEditor, wxGridCellNumberEditor,
  447. wxGridCellTextEditor
  448. */
  449. class wxGridCellChoiceEditor : public wxGridCellEditor
  450. {
  451. public:
  452. /**
  453. Choice cell renderer ctor.
  454. @param count
  455. Number of strings from which the user can choose.
  456. @param choices
  457. An array of strings from which the user can choose.
  458. @param allowOthers
  459. If allowOthers is @true, the user can type a string not in choices
  460. array.
  461. */
  462. wxGridCellChoiceEditor(size_t count = 0,
  463. const wxString choices[] = NULL,
  464. bool allowOthers = false);
  465. /**
  466. Choice cell renderer ctor.
  467. @param choices
  468. An array of strings from which the user can choose.
  469. @param allowOthers
  470. If allowOthers is @true, the user can type a string not in choices
  471. array.
  472. */
  473. wxGridCellChoiceEditor(const wxArrayString& choices,
  474. bool allowOthers = false);
  475. /**
  476. Parameters string format is "item1[,item2[...,itemN]]"
  477. */
  478. virtual void SetParameters(const wxString& params);
  479. };
  480. /**
  481. @class wxGridCellEnumEditor
  482. Grid cell editor which displays an enum number as a textual equivalent
  483. (eg. data in cell is 0,1,2 ... n the cell could be displayed as
  484. "John","Fred"..."Bob" in the combo choice box).
  485. @library{wxadv}
  486. @category{grid}
  487. @see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
  488. wxGridCellBoolEditor, wxGridCellChoiceEditor,
  489. wxGridCellTextEditor, wxGridCellFloatEditor,
  490. wxGridCellNumberEditor
  491. */
  492. class wxGridCellEnumEditor : public wxGridCellChoiceEditor
  493. {
  494. public:
  495. /**
  496. Enum cell editor ctor.
  497. @param choices
  498. Comma separated choice parameters "item1[,item2[...,itemN]]".
  499. */
  500. wxGridCellEnumEditor( const wxString& choices = wxEmptyString );
  501. };
  502. /**
  503. @class wxGridCellTextEditor
  504. Grid cell editor for string/text data.
  505. @library{wxadv}
  506. @category{grid}
  507. @see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
  508. wxGridCellBoolEditor, wxGridCellChoiceEditor,
  509. wxGridCellEnumEditor, wxGridCellFloatEditor,
  510. wxGridCellNumberEditor
  511. */
  512. class wxGridCellTextEditor : public wxGridCellEditor
  513. {
  514. public:
  515. /**
  516. Text cell editor constructor.
  517. @param maxChars
  518. Maximum width of text (this parameter is supported starting since
  519. wxWidgets 2.9.5).
  520. */
  521. explicit wxGridCellTextEditor(size_t maxChars = 0);
  522. /**
  523. The parameters string format is "n" where n is a number representing
  524. the maximum width.
  525. */
  526. virtual void SetParameters(const wxString& params);
  527. /**
  528. Set validator to validate user input.
  529. @since 2.9.5
  530. */
  531. virtual void SetValidator(const wxValidator& validator);
  532. };
  533. /**
  534. @class wxGridCellFloatEditor
  535. The editor for floating point numbers data.
  536. @library{wxadv}
  537. @category{grid}
  538. @see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
  539. wxGridCellBoolEditor, wxGridCellChoiceEditor,
  540. wxGridCellEnumEditor, wxGridCellNumberEditor,
  541. wxGridCellTextEditor
  542. */
  543. class wxGridCellFloatEditor : public wxGridCellTextEditor
  544. {
  545. public:
  546. /**
  547. Float cell editor ctor.
  548. @param width
  549. Minimum number of characters to be shown.
  550. @param precision
  551. Number of digits after the decimal dot.
  552. @param format
  553. The format to use for displaying the number, a combination of
  554. ::wxGridCellFloatFormat enum elements. This parameter is only
  555. available since wxWidgets 2.9.3.
  556. */
  557. wxGridCellFloatEditor(int width = -1, int precision = -1,
  558. int format = wxGRID_FLOAT_FORMAT_DEFAULT);
  559. /**
  560. The parameters string format is "width[,precision[,format]]" where
  561. @c format should be chosen between f|e|g|E|G (f is used by default)
  562. */
  563. virtual void SetParameters(const wxString& params);
  564. };
  565. /**
  566. @class wxGridCellNumberEditor
  567. Grid cell editor for numeric integer data.
  568. @library{wxadv}
  569. @category{grid}
  570. @see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
  571. wxGridCellBoolEditor, wxGridCellChoiceEditor,
  572. wxGridCellEnumEditor, wxGridCellFloatEditor,
  573. wxGridCellTextEditor
  574. */
  575. class wxGridCellNumberEditor : public wxGridCellTextEditor
  576. {
  577. public:
  578. /**
  579. Allows you to specify the range for acceptable data. Values equal to
  580. -1 for both @a min and @a max indicate that no range checking should be
  581. done.
  582. */
  583. wxGridCellNumberEditor(int min = -1, int max = -1);
  584. /**
  585. Parameters string format is "min,max".
  586. */
  587. virtual void SetParameters(const wxString& params);
  588. protected:
  589. /**
  590. If the return value is @true, the editor uses a wxSpinCtrl to get user
  591. input, otherwise it uses a wxTextCtrl.
  592. */
  593. bool HasRange() const;
  594. /**
  595. String representation of the value.
  596. */
  597. wxString GetString() const;
  598. };
  599. /**
  600. @class wxGridCellAttr
  601. This class can be used to alter the cells' appearance in the grid by
  602. changing their attributes from the defaults. An object of this class may be
  603. returned by wxGridTableBase::GetAttr().
  604. @library{wxadv}
  605. @category{grid}
  606. */
  607. class wxGridCellAttr : public wxClientDataContainer, public wxRefCounter
  608. {
  609. public:
  610. /**
  611. Kind of the attribute to retrieve.
  612. @see wxGridCellAttrProvider::GetAttr(), wxGridTableBase::GetAttr()
  613. */
  614. enum wxAttrKind
  615. {
  616. /// Return the combined effective attribute for the cell.
  617. Any,
  618. /// Return the attribute explicitly set for this cell.
  619. Cell,
  620. /// Return the attribute set for this cells row.
  621. Row,
  622. /// Return the attribute set for this cells column.
  623. Col
  624. };
  625. /**
  626. Default constructor.
  627. */
  628. wxGridCellAttr(wxGridCellAttr* attrDefault = NULL);
  629. /**
  630. Constructor specifying some of the often used attributes.
  631. */
  632. wxGridCellAttr(const wxColour& colText, const wxColour& colBack,
  633. const wxFont& font, int hAlign, int vAlign);
  634. /**
  635. Creates a new copy of this object.
  636. */
  637. wxGridCellAttr* Clone() const;
  638. /**
  639. This class is reference counted: it is created with ref count of 1, so
  640. calling DecRef() once will delete it. Calling IncRef() allows to lock
  641. it until the matching DecRef() is called.
  642. */
  643. void DecRef();
  644. /**
  645. Get the alignment to use for the cell with the given attribute.
  646. If this attribute doesn't specify any alignment, the default attribute
  647. alignment is used (which can be changed using
  648. wxGrid::SetDefaultCellAlignment() but is left and top by default).
  649. Notice that @a hAlign and @a vAlign values are always overwritten by
  650. this function, use GetNonDefaultAlignment() if this is not desirable.
  651. @param hAlign
  652. Horizontal alignment is returned here if this argument is non-@NULL.
  653. It is one of wxALIGN_LEFT, wxALIGN_CENTRE or wxALIGN_RIGHT.
  654. @param vAlign
  655. Vertical alignment is returned here if this argument is non-@NULL.
  656. It is one of wxALIGN_TOP, wxALIGN_CENTRE or wxALIGN_BOTTOM.
  657. */
  658. void GetAlignment(int* hAlign, int* vAlign) const;
  659. /**
  660. Returns the background colour.
  661. */
  662. const wxColour& GetBackgroundColour() const;
  663. /**
  664. Returns the cell editor.
  665. */
  666. wxGridCellEditor* GetEditor(const wxGrid* grid, int row, int col) const;
  667. /**
  668. Returns the font.
  669. */
  670. const wxFont& GetFont() const;
  671. /**
  672. Get the alignment defined by this attribute.
  673. Unlike GetAlignment() this function only modifies @a hAlign and @a
  674. vAlign if this attribute does define a non-default alignment. This
  675. means that they must be initialized before calling this function and
  676. that their values will be preserved unchanged if they are different
  677. from wxALIGN_INVALID.
  678. For example, the following fragment can be used to use the cell
  679. alignment if one is defined but right-align its contents by default
  680. (instead of left-aligning it by default) while still using the default
  681. vertical alignment:
  682. @code
  683. int hAlign = wxALIGN_RIGHT,
  684. vAlign = wxALIGN_INVALID;
  685. attr.GetNonDefaultAlignment(&hAlign, &vAlign);
  686. @endcode
  687. @since 2.9.1
  688. */
  689. void GetNonDefaultAlignment(int *hAlign, int *vAlign) const;
  690. /**
  691. Returns the cell renderer.
  692. */
  693. wxGridCellRenderer* GetRenderer(const wxGrid* grid, int row, int col) const;
  694. /**
  695. Returns the text colour.
  696. */
  697. const wxColour& GetTextColour() const;
  698. /**
  699. Returns @true if this attribute has a valid alignment set.
  700. */
  701. bool HasAlignment() const;
  702. /**
  703. Returns @true if this attribute has a valid background colour set.
  704. */
  705. bool HasBackgroundColour() const;
  706. /**
  707. Returns @true if this attribute has a valid cell editor set.
  708. */
  709. bool HasEditor() const;
  710. /**
  711. Returns @true if this attribute has a valid font set.
  712. */
  713. bool HasFont() const;
  714. /**
  715. Returns @true if this attribute has a valid cell renderer set.
  716. */
  717. bool HasRenderer() const;
  718. /**
  719. Returns @true if this attribute has a valid text colour set.
  720. */
  721. bool HasTextColour() const;
  722. /**
  723. This class is reference counted: it is created with ref count of 1, so
  724. calling DecRef() once will delete it. Calling IncRef() allows to lock
  725. it until the matching DecRef() is called.
  726. */
  727. void IncRef();
  728. /**
  729. Returns @true if this cell is set as read-only.
  730. */
  731. bool IsReadOnly() const;
  732. /**
  733. Sets the alignment. @a hAlign can be one of @c wxALIGN_LEFT,
  734. @c wxALIGN_CENTRE or @c wxALIGN_RIGHT and @a vAlign can be one of
  735. @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM.
  736. */
  737. void SetAlignment(int hAlign, int vAlign);
  738. /**
  739. Sets the background colour.
  740. */
  741. void SetBackgroundColour(const wxColour& colBack);
  742. /**
  743. @todo Needs documentation.
  744. */
  745. void SetDefAttr(wxGridCellAttr* defAttr);
  746. /**
  747. Sets the editor to be used with the cells with this attribute.
  748. */
  749. void SetEditor(wxGridCellEditor* editor);
  750. /**
  751. Sets the font.
  752. */
  753. void SetFont(const wxFont& font);
  754. /**
  755. Sets the cell as read-only.
  756. */
  757. void SetReadOnly(bool isReadOnly = true);
  758. /**
  759. Sets the renderer to be used for cells with this attribute. Takes
  760. ownership of the pointer.
  761. */
  762. void SetRenderer(wxGridCellRenderer* renderer);
  763. /**
  764. Sets the text colour.
  765. */
  766. void SetTextColour(const wxColour& colText);
  767. protected:
  768. /**
  769. The destructor is private because only DecRef() can delete us.
  770. */
  771. virtual ~wxGridCellAttr();
  772. };
  773. /**
  774. Base class for corner window renderer.
  775. This is the simplest of all header renderers and only has a single
  776. function.
  777. @see wxGridCellAttrProvider::GetCornerRenderer()
  778. @since 2.9.1
  779. */
  780. class wxGridCornerHeaderRenderer
  781. {
  782. public:
  783. /**
  784. Called by the grid to draw the corner window border.
  785. This method is responsible for drawing the border inside the given @a
  786. rect and adjusting the rectangle size to correspond to the area inside
  787. the border, i.e. usually call wxRect::Deflate() to account for the
  788. border width.
  789. @param grid
  790. The grid whose corner window is being drawn.
  791. @param dc
  792. The device context to use for drawing.
  793. @param rect
  794. Input/output parameter which contains the border rectangle on input
  795. and should be updated to contain the area inside the border on
  796. function return.
  797. */
  798. virtual void DrawBorder(const wxGrid& grid,
  799. wxDC& dc,
  800. wxRect& rect) const = 0;
  801. };
  802. /**
  803. Common base class for row and column headers renderers.
  804. @see wxGridColumnHeaderRenderer, wxGridRowHeaderRenderer
  805. @since 2.9.1
  806. */
  807. class wxGridHeaderLabelsRenderer : public wxGridCornerHeaderRenderer
  808. {
  809. public:
  810. /**
  811. Called by the grid to draw the specified label.
  812. Notice that the base class DrawBorder() method is called before this
  813. one.
  814. The default implementation uses wxGrid::GetLabelTextColour() and
  815. wxGrid::GetLabelFont() to draw the label.
  816. */
  817. virtual void DrawLabel(const wxGrid& grid,
  818. wxDC& dc,
  819. const wxString& value,
  820. const wxRect& rect,
  821. int horizAlign,
  822. int vertAlign,
  823. int textOrientation) const;
  824. };
  825. /**
  826. Base class for row headers renderer.
  827. This is the same as wxGridHeaderLabelsRenderer currently but we still use a
  828. separate class for it to distinguish it from wxGridColumnHeaderRenderer.
  829. @see wxGridRowHeaderRendererDefault
  830. @see wxGridCellAttrProvider::GetRowHeaderRenderer()
  831. @since 2.9.1
  832. */
  833. class wxGridRowHeaderRenderer : public wxGridHeaderLabelsRenderer
  834. {
  835. };
  836. /**
  837. Base class for column headers renderer.
  838. This is the same as wxGridHeaderLabelsRenderer currently but we still use a
  839. separate class for it to distinguish it from wxGridRowHeaderRenderer.
  840. @see wxGridColumnHeaderRendererDefault
  841. @see wxGridCellAttrProvider::GetColumnHeaderRenderer()
  842. @since 2.9.1
  843. */
  844. class wxGridColumnHeaderRenderer : public wxGridHeaderLabelsRenderer
  845. {
  846. };
  847. /**
  848. Default row header renderer.
  849. You may derive from this class if you need to only override one of its
  850. methods (i.e. either DrawLabel() or DrawBorder()) but continue to use the
  851. default implementation for the other one.
  852. @see wxGridColumnHeaderRendererDefault
  853. @since 2.9.1
  854. */
  855. class wxGridRowHeaderRendererDefault : public wxGridRowHeaderRenderer
  856. {
  857. public:
  858. /// Implement border drawing for the row labels.
  859. virtual void DrawBorder(const wxGrid& grid,
  860. wxDC& dc,
  861. wxRect& rect) const;
  862. };
  863. /**
  864. Default column header renderer.
  865. @see wxGridRowHeaderRendererDefault
  866. @since 2.9.1
  867. */
  868. class wxGridColumnHeaderRendererDefault : public wxGridColumnHeaderRenderer
  869. {
  870. public:
  871. /// Implement border drawing for the column labels.
  872. virtual void DrawBorder(const wxGrid& grid,
  873. wxDC& dc,
  874. wxRect& rect) const;
  875. };
  876. /**
  877. Default corner window renderer.
  878. @see wxGridColumnHeaderRendererDefault, wxGridRowHeaderRendererDefault
  879. @since 2.9.1
  880. */
  881. class wxGridCornerHeaderRendererDefault : public wxGridCornerHeaderRenderer
  882. {
  883. public:
  884. /// Implement border drawing for the corner window.
  885. virtual void DrawBorder(const wxGrid& grid,
  886. wxDC& dc,
  887. wxRect& rect) const;
  888. };
  889. /**
  890. Class providing attributes to be used for the grid cells.
  891. This class both defines an interface which grid cell attributes providers
  892. should implement -- and which can be implemented differently in derived
  893. classes -- and a default implementation of this interface which is often
  894. good enough to be used without modification, especially with not very large
  895. grids for which the efficiency of attributes storage hardly matters (see
  896. the discussion below).
  897. An object of this class can be associated with a wxGrid using
  898. wxGridTableBase::SetAttrProvider() but it's not necessary to call it if you
  899. intend to use the default provider as it is used by wxGridTableBase by
  900. default anyhow.
  901. Notice that while attributes provided by this class can be set for
  902. individual cells using SetAttr() or the entire rows or columns using
  903. SetRowAttr() and SetColAttr() they are always retrieved using GetAttr()
  904. function.
  905. The default implementation of this class stores the attributes passed to
  906. its SetAttr(), SetRowAttr() and SetColAttr() in a straightforward way. A
  907. derived class may use its knowledge about how the attributes are used in
  908. your program to implement it much more efficiently: for example, using a
  909. special background colour for all even-numbered rows can be implemented by
  910. simply returning the same attribute from GetAttr() if the row number is
  911. even instead of having to store N/2 row attributes where N is the total
  912. number of rows in the grid.
  913. Notice that objects of this class can't be copied.
  914. */
  915. class wxGridCellAttrProvider : public wxClientDataContainer
  916. {
  917. public:
  918. /// Trivial default constructor.
  919. wxGridCellAttrProvider();
  920. /// Destructor releases any attributes held by this class.
  921. virtual ~wxGridCellAttrProvider();
  922. /**
  923. Get the attribute to use for the specified cell.
  924. If wxGridCellAttr::Any is used as @a kind value, this function combines
  925. the attributes set for this cell using SetAttr() and those for its row
  926. or column (set with SetRowAttr() or SetColAttr() respectively), with
  927. the cell attribute having the highest precedence.
  928. Notice that the caller must call DecRef() on the returned pointer if it
  929. is non-@NULL.
  930. @param row
  931. The row of the cell.
  932. @param col
  933. The column of the cell.
  934. @param kind
  935. The kind of the attribute to return.
  936. @return
  937. The attribute to use which should be DecRef()'d by caller or @NULL
  938. if no attributes are defined for this cell.
  939. */
  940. virtual wxGridCellAttr *GetAttr(int row, int col,
  941. wxGridCellAttr::wxAttrKind kind) const;
  942. /**
  943. Setting attributes.
  944. All these functions take ownership of the attribute passed to them,
  945. i.e. will call DecRef() on it themselves later and so it should not be
  946. destroyed by the caller. And the attribute can be @NULL to reset a
  947. previously set value.
  948. */
  949. //@{
  950. /// Set attribute for the specified cell.
  951. virtual void SetAttr(wxGridCellAttr *attr, int row, int col);
  952. /// Set attribute for the specified row.
  953. virtual void SetRowAttr(wxGridCellAttr *attr, int row);
  954. /// Set attribute for the specified column.
  955. virtual void SetColAttr(wxGridCellAttr *attr, int col);
  956. //@}
  957. /**
  958. Getting header renderers.
  959. These functions return the renderers for the given row or column header
  960. label and the corner window. Unlike cell attributes, these objects are
  961. not reference counted and are never @NULL so they are returned by
  962. reference and not pointer and DecRef() shouldn't (and can't) be called
  963. for them.
  964. All these functions were added in wxWidgets 2.9.1.
  965. */
  966. //@{
  967. /**
  968. Return the renderer used for drawing column headers.
  969. By default wxGridColumnHeaderRendererDefault is returned.
  970. @see wxGrid::SetUseNativeColLabels(), wxGrid::UseNativeColHeader()
  971. @since 2.9.1
  972. */
  973. virtual const wxGridColumnHeaderRenderer& GetColumnHeaderRenderer(int col);
  974. /**
  975. Return the renderer used for drawing row headers.
  976. By default wxGridRowHeaderRendererDefault is returned.
  977. @since 2.9.1
  978. */
  979. virtual const wxGridRowHeaderRenderer& GetRowHeaderRenderer(int row);
  980. /**
  981. Return the renderer used for drawing the corner window.
  982. By default wxGridCornerHeaderRendererDefault is returned.
  983. @since 2.9.1
  984. */
  985. virtual const wxGridCornerHeaderRenderer& GetCornerRenderer();
  986. //@}
  987. };
  988. /**
  989. Represents coordinates of a grid cell.
  990. An object of this class is simply a (row, column) pair.
  991. */
  992. class wxGridCellCoords
  993. {
  994. public:
  995. /**
  996. Default constructor initializes the object to invalid state.
  997. Initially the row and column are both invalid (-1) and so operator!()
  998. for an uninitialized wxGridCellCoords returns false.
  999. */
  1000. wxGridCellCoords();
  1001. /**
  1002. Constructor taking a row and a column.
  1003. */
  1004. wxGridCellCoords(int row, int col);
  1005. /**
  1006. Return the row of the coordinate.
  1007. */
  1008. int GetRow() const;
  1009. /**
  1010. Set the row of the coordinate.
  1011. */
  1012. void SetRow(int n);
  1013. /**
  1014. Return the column of the coordinate.
  1015. */
  1016. int GetCol() const;
  1017. /**
  1018. Set the column of the coordinate.
  1019. */
  1020. void SetCol(int n);
  1021. /**
  1022. Set the row and column of the coordinate.
  1023. */
  1024. void Set(int row, int col);
  1025. /**
  1026. Assignment operator for coordinate types.
  1027. */
  1028. wxGridCellCoords& operator=(const wxGridCellCoords& other);
  1029. /**
  1030. Equality operator.
  1031. */
  1032. bool operator==(const wxGridCellCoords& other) const;
  1033. /**
  1034. Inequality operator.
  1035. */
  1036. bool operator!=(const wxGridCellCoords& other) const;
  1037. /**
  1038. Checks whether the coordinates are invalid.
  1039. Returns false only if both row and column are -1. Notice that if either
  1040. row or column (but not both) are -1, this method returns true even if
  1041. the object is invalid. This is done because objects in such state
  1042. should actually never exist, i.e. either both coordinates should be -1
  1043. or none of them should be -1.
  1044. */
  1045. bool operator!() const;
  1046. };
  1047. /**
  1048. @class wxGridTableBase
  1049. The almost abstract base class for grid tables.
  1050. A grid table is responsible for storing the grid data and, indirectly, grid
  1051. cell attributes. The data can be stored in the way most convenient for the
  1052. application but has to be provided in string form to wxGrid. It is also
  1053. possible to provide cells values in other formats if appropriate, e.g. as
  1054. numbers.
  1055. This base class is not quite abstract as it implements a trivial strategy
  1056. for storing the attributes by forwarding it to wxGridCellAttrProvider and
  1057. also provides stubs for some other functions. However it does have a number
  1058. of pure virtual methods which must be implemented in the derived classes.
  1059. @see wxGridStringTable
  1060. @library{wxadv}
  1061. @category{grid}
  1062. */
  1063. class wxGridTableBase : public wxObject
  1064. {
  1065. public:
  1066. /**
  1067. Default constructor.
  1068. */
  1069. wxGridTableBase();
  1070. /**
  1071. Destructor frees the attribute provider if it was created.
  1072. */
  1073. virtual ~wxGridTableBase();
  1074. /**
  1075. Must be overridden to return the number of rows in the table.
  1076. For backwards compatibility reasons, this method is not const.
  1077. Use GetRowsCount() instead of it in const methods of derived table
  1078. classes.
  1079. */
  1080. virtual int GetNumberRows() = 0;
  1081. /**
  1082. Must be overridden to return the number of columns in the table.
  1083. For backwards compatibility reasons, this method is not const.
  1084. Use GetColsCount() instead of it in const methods of derived table
  1085. classes,
  1086. */
  1087. virtual int GetNumberCols() = 0;
  1088. /**
  1089. Return the number of rows in the table.
  1090. This method is not virtual and is only provided as a convenience for
  1091. the derived classes which can't call GetNumberRows() without a
  1092. @c const_cast from their const methods.
  1093. */
  1094. int GetRowsCount() const;
  1095. /**
  1096. Return the number of columns in the table.
  1097. This method is not virtual and is only provided as a convenience for
  1098. the derived classes which can't call GetNumberCols() without a
  1099. @c const_cast from their const methods.
  1100. */
  1101. int GetColsCount() const;
  1102. /**
  1103. @name Table Cell Accessors
  1104. */
  1105. //@{
  1106. /**
  1107. May be overridden to implement testing for empty cells.
  1108. This method is used by the grid to test if the given cell is not used
  1109. and so whether a neighbouring cell may overflow into it. By default it
  1110. only returns true if the value of the given cell, as returned by
  1111. GetValue(), is empty.
  1112. */
  1113. virtual bool IsEmptyCell(int row, int col);
  1114. /**
  1115. Same as IsEmptyCell() but taking wxGridCellCoords.
  1116. Notice that this method is not virtual, only IsEmptyCell() should be
  1117. overridden.
  1118. */
  1119. bool IsEmpty(const wxGridCellCoords& coords);
  1120. /**
  1121. Must be overridden to implement accessing the table values as text.
  1122. */
  1123. virtual wxString GetValue(int row, int col) = 0;
  1124. /**
  1125. Must be overridden to implement setting the table values as text.
  1126. */
  1127. virtual void SetValue(int row, int col, const wxString& value) = 0;
  1128. /**
  1129. Returns the type of the value in the given cell.
  1130. By default all cells are strings and this method returns
  1131. @c wxGRID_VALUE_STRING.
  1132. */
  1133. virtual wxString GetTypeName(int row, int col);
  1134. /**
  1135. Returns true if the value of the given cell can be accessed as if it
  1136. were of the specified type.
  1137. By default the cells can only be accessed as strings. Note that a cell
  1138. could be accessible in different ways, e.g. a numeric cell may return
  1139. @true for @c wxGRID_VALUE_NUMBER but also for @c wxGRID_VALUE_STRING
  1140. indicating that the value can be coerced to a string form.
  1141. */
  1142. virtual bool CanGetValueAs(int row, int col, const wxString& typeName);
  1143. /**
  1144. Returns true if the value of the given cell can be set as if it were of
  1145. the specified type.
  1146. @see CanGetValueAs()
  1147. */
  1148. virtual bool CanSetValueAs(int row, int col, const wxString& typeName);
  1149. /**
  1150. Returns the value of the given cell as a long.
  1151. This should only be called if CanGetValueAs() returns @true when called
  1152. with @c wxGRID_VALUE_NUMBER argument. Default implementation always
  1153. return 0.
  1154. */
  1155. virtual long GetValueAsLong(int row, int col);
  1156. /**
  1157. Returns the value of the given cell as a double.
  1158. This should only be called if CanGetValueAs() returns @true when called
  1159. with @c wxGRID_VALUE_FLOAT argument. Default implementation always
  1160. return 0.0.
  1161. */
  1162. virtual double GetValueAsDouble(int row, int col);
  1163. /**
  1164. Returns the value of the given cell as a boolean.
  1165. This should only be called if CanGetValueAs() returns @true when called
  1166. with @c wxGRID_VALUE_BOOL argument. Default implementation always
  1167. return false.
  1168. */
  1169. virtual bool GetValueAsBool(int row, int col);
  1170. /**
  1171. Returns the value of the given cell as a user-defined type.
  1172. This should only be called if CanGetValueAs() returns @true when called
  1173. with @a typeName. Default implementation always return @NULL.
  1174. */
  1175. virtual void *GetValueAsCustom(int row, int col, const wxString& typeName);
  1176. /**
  1177. Sets the value of the given cell as a long.
  1178. This should only be called if CanSetValueAs() returns @true when called
  1179. with @c wxGRID_VALUE_NUMBER argument. Default implementation doesn't do
  1180. anything.
  1181. */
  1182. virtual void SetValueAsLong(int row, int col, long value);
  1183. /**
  1184. Sets the value of the given cell as a double.
  1185. This should only be called if CanSetValueAs() returns @true when called
  1186. with @c wxGRID_VALUE_FLOAT argument. Default implementation doesn't do
  1187. anything.
  1188. */
  1189. virtual void SetValueAsDouble(int row, int col, double value);
  1190. /**
  1191. Sets the value of the given cell as a boolean.
  1192. This should only be called if CanSetValueAs() returns @true when called
  1193. with @c wxGRID_VALUE_BOOL argument. Default implementation doesn't do
  1194. anything.
  1195. */
  1196. virtual void SetValueAsBool( int row, int col, bool value );
  1197. /**
  1198. Sets the value of the given cell as a user-defined type.
  1199. This should only be called if CanSetValueAs() returns @true when called
  1200. with @a typeName. Default implementation doesn't do anything.
  1201. */
  1202. virtual void SetValueAsCustom(int row, int col, const wxString& typeName,
  1203. void *value);
  1204. //@}
  1205. /**
  1206. Called by the grid when the table is associated with it.
  1207. The default implementation stores the pointer and returns it from its
  1208. GetView() and so only makes sense if the table cannot be associated
  1209. with more than one grid at a time.
  1210. */
  1211. virtual void SetView(wxGrid *grid);
  1212. /**
  1213. Returns the last grid passed to SetView().
  1214. */
  1215. virtual wxGrid *GetView() const;
  1216. /**
  1217. @name Table Structure Modifiers
  1218. Notice that none of these functions are pure virtual as they don't have
  1219. to be implemented if the table structure is never modified after
  1220. creation, i.e. neither rows nor columns are never added or deleted but
  1221. that you do need to implement them if they are called, i.e. if your
  1222. code either calls them directly or uses the matching wxGrid methods, as
  1223. by default they simply do nothing which is definitely inappropriate.
  1224. */
  1225. //@{
  1226. /**
  1227. Clear the table contents.
  1228. This method is used by wxGrid::ClearGrid().
  1229. */
  1230. virtual void Clear();
  1231. /**
  1232. Insert additional rows into the table.
  1233. @param pos
  1234. The position of the first new row.
  1235. @param numRows
  1236. The number of rows to insert.
  1237. */
  1238. virtual bool InsertRows(size_t pos = 0, size_t numRows = 1);
  1239. /**
  1240. Append additional rows at the end of the table.
  1241. This method is provided in addition to InsertRows() as some data models
  1242. may only support appending rows to them but not inserting them at
  1243. arbitrary locations. In such case you may implement this method only
  1244. and leave InsertRows() unimplemented.
  1245. @param numRows
  1246. The number of rows to add.
  1247. */
  1248. virtual bool AppendRows(size_t numRows = 1);
  1249. /**
  1250. Delete rows from the table.
  1251. Notice that currently deleting a row intersecting a multi-cell (see
  1252. SetCellSize()) is not supported and will result in a crash.
  1253. @param pos
  1254. The first row to delete.
  1255. @param numRows
  1256. The number of rows to delete.
  1257. */
  1258. virtual bool DeleteRows(size_t pos = 0, size_t numRows = 1);
  1259. /**
  1260. Exactly the same as InsertRows() but for columns.
  1261. */
  1262. virtual bool InsertCols(size_t pos = 0, size_t numCols = 1);
  1263. /**
  1264. Exactly the same as AppendRows() but for columns.
  1265. */
  1266. virtual bool AppendCols(size_t numCols = 1);
  1267. /**
  1268. Exactly the same as DeleteRows() but for columns.
  1269. */
  1270. virtual bool DeleteCols(size_t pos = 0, size_t numCols = 1);
  1271. //@}
  1272. /**
  1273. @name Table Row and Column Labels
  1274. By default the numbers are used for labeling rows and Latin letters for
  1275. labeling columns. If the table has more than 26 columns, the pairs of
  1276. letters are used starting from the 27-th one and so on, i.e. the
  1277. sequence of labels is A, B, ..., Z, AA, AB, ..., AZ, BA, ..., ..., ZZ,
  1278. AAA, ...
  1279. */
  1280. //@{
  1281. /**
  1282. Return the label of the specified row.
  1283. */
  1284. virtual wxString GetRowLabelValue(int row);
  1285. /**
  1286. Return the label of the specified column.
  1287. */
  1288. virtual wxString GetColLabelValue(int col);
  1289. /**
  1290. Set the given label for the specified row.
  1291. The default version does nothing, i.e. the label is not stored. You
  1292. must override this method in your derived class if you wish
  1293. wxGrid::SetRowLabelValue() to work.
  1294. */
  1295. virtual void SetRowLabelValue(int row, const wxString& label);
  1296. /**
  1297. Exactly the same as SetRowLabelValue() but for columns.
  1298. */
  1299. virtual void SetColLabelValue(int col, const wxString& label);
  1300. //@}
  1301. /**
  1302. @name Attributes Management
  1303. By default the attributes management is delegated to
  1304. wxGridCellAttrProvider class. You may override the methods in this
  1305. section to handle the attributes directly if, for example, they can be
  1306. computed from the cell values.
  1307. */
  1308. //@{
  1309. /**
  1310. Associate this attributes provider with the table.
  1311. The table takes ownership of @a attrProvider pointer and will delete it
  1312. when it doesn't need it any more. The pointer can be @NULL, however
  1313. this won't disable attributes management in the table but will just
  1314. result in a default attributes being recreated the next time any of the
  1315. other functions in this section is called. To completely disable the
  1316. attributes support, should this be needed, you need to override
  1317. CanHaveAttributes() to return @false.
  1318. */
  1319. void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
  1320. /**
  1321. Returns the attribute provider currently being used.
  1322. This function may return @NULL if the attribute provider hasn't been
  1323. neither associated with this table by SetAttrProvider() nor created on
  1324. demand by any other methods.
  1325. */
  1326. wxGridCellAttrProvider *GetAttrProvider() const;
  1327. /**
  1328. Return the attribute for the given cell.
  1329. By default this function is simply forwarded to
  1330. wxGridCellAttrProvider::GetAttr() but it may be overridden to handle
  1331. attributes directly in the table.
  1332. */
  1333. virtual wxGridCellAttr *GetAttr(int row, int col,
  1334. wxGridCellAttr::wxAttrKind kind);
  1335. /**
  1336. Set attribute of the specified cell.
  1337. By default this function is simply forwarded to
  1338. wxGridCellAttrProvider::SetAttr().
  1339. The table takes ownership of @a attr, i.e. will call DecRef() on it.
  1340. */
  1341. virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
  1342. /**
  1343. Set attribute of the specified row.
  1344. By default this function is simply forwarded to
  1345. wxGridCellAttrProvider::SetRowAttr().
  1346. The table takes ownership of @a attr, i.e. will call DecRef() on it.
  1347. */
  1348. virtual void SetRowAttr(wxGridCellAttr *attr, int row);
  1349. /**
  1350. Set attribute of the specified column.
  1351. By default this function is simply forwarded to
  1352. wxGridCellAttrProvider::SetColAttr().
  1353. The table takes ownership of @a attr, i.e. will call DecRef() on it.
  1354. */
  1355. virtual void SetColAttr(wxGridCellAttr *attr, int col);
  1356. //@}
  1357. /**
  1358. Returns true if this table supports attributes or false otherwise.
  1359. By default, the table automatically creates a wxGridCellAttrProvider
  1360. when this function is called if it had no attribute provider before and
  1361. returns @true.
  1362. */
  1363. virtual bool CanHaveAttributes();
  1364. };
  1365. enum wxGridTableRequest
  1366. {
  1367. wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
  1368. wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
  1369. wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
  1370. wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
  1371. wxGRIDTABLE_NOTIFY_ROWS_DELETED,
  1372. wxGRIDTABLE_NOTIFY_COLS_INSERTED,
  1373. wxGRIDTABLE_NOTIFY_COLS_APPENDED,
  1374. wxGRIDTABLE_NOTIFY_COLS_DELETED
  1375. };
  1376. /**
  1377. @class wxGridTableMessage
  1378. A simple class used to pass messages from the table to the grid.
  1379. @library{wxadv}
  1380. @category{grid}
  1381. */
  1382. class wxGridTableMessage
  1383. {
  1384. public:
  1385. wxGridTableMessage();
  1386. wxGridTableMessage( wxGridTableBase *table, int id,
  1387. int comInt1 = -1,
  1388. int comInt2 = -1 );
  1389. void SetTableObject( wxGridTableBase *table );
  1390. wxGridTableBase * GetTableObject() const;
  1391. void SetId( int id );
  1392. int GetId();
  1393. void SetCommandInt( int comInt1 );
  1394. int GetCommandInt();
  1395. void SetCommandInt2( int comInt2 );
  1396. int GetCommandInt2();
  1397. };
  1398. /**
  1399. @class wxGridStringTable
  1400. Simplest type of data table for a grid for small tables of strings
  1401. that are stored in memory
  1402. */
  1403. class wxGridStringTable : public wxGridTableBase
  1404. {
  1405. public:
  1406. wxGridStringTable();
  1407. wxGridStringTable( int numRows, int numCols );
  1408. // these are pure virtual in wxGridTableBase
  1409. virtual int GetNumberRows();
  1410. virtual int GetNumberCols();
  1411. virtual wxString GetValue( int row, int col );
  1412. virtual void SetValue( int row, int col, const wxString& value );
  1413. // overridden functions from wxGridTableBase
  1414. void Clear();
  1415. bool InsertRows( size_t pos = 0, size_t numRows = 1 );
  1416. bool AppendRows( size_t numRows = 1 );
  1417. bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
  1418. bool InsertCols( size_t pos = 0, size_t numCols = 1 );
  1419. bool AppendCols( size_t numCols = 1 );
  1420. bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
  1421. void SetRowLabelValue( int row, const wxString& );
  1422. void SetColLabelValue( int col, const wxString& );
  1423. wxString GetRowLabelValue( int row );
  1424. wxString GetColLabelValue( int col );
  1425. };
  1426. /**
  1427. @class wxGridSizesInfo
  1428. wxGridSizesInfo stores information about sizes of all wxGrid rows or
  1429. columns.
  1430. It assumes that most of the rows or columns (which are both called elements
  1431. here as the difference between them doesn't matter at this class level)
  1432. have the default size and so stores it separately. And it uses a wxHashMap
  1433. to store the sizes of all elements which have the non-default size.
  1434. This structure is particularly useful for serializing the sizes of all
  1435. wxGrid elements at once.
  1436. @library{wxadv}
  1437. @category{grid}
  1438. */
  1439. struct wxGridSizesInfo
  1440. {
  1441. /**
  1442. Default constructor.
  1443. m_sizeDefault and m_customSizes must be initialized later.
  1444. */
  1445. wxGridSizesInfo();
  1446. /**
  1447. Constructor.
  1448. This constructor is used by wxGrid::GetRowSizes() and GetColSizes()
  1449. methods. User code will usually use the default constructor instead.
  1450. @param defSize
  1451. The default element size.
  1452. @param allSizes
  1453. Array containing the sizes of @em all elements, including those
  1454. which have the default size.
  1455. */
  1456. wxGridSizesInfo(int defSize, const wxArrayInt& allSizes);
  1457. /**
  1458. Get the element size.
  1459. @param pos
  1460. The index of the element.
  1461. @return
  1462. The size for this element, using m_customSizes if @a pos is in it
  1463. or m_sizeDefault otherwise.
  1464. */
  1465. int GetSize(unsigned pos) const;
  1466. /// Default size
  1467. int m_sizeDefault;
  1468. /**
  1469. Map with element indices as keys and their sizes as values.
  1470. This map only contains the elements with non-default size.
  1471. */
  1472. wxUnsignedToIntHashMap m_customSizes;
  1473. };
  1474. /**
  1475. Rendering styles supported by wxGrid::Render() method.
  1476. @since 2.9.4
  1477. */
  1478. enum wxGridRenderStyle
  1479. {
  1480. /// Draw grid row header labels.
  1481. wxGRID_DRAW_ROWS_HEADER = 0x001,
  1482. /// Draw grid column header labels.
  1483. wxGRID_DRAW_COLS_HEADER = 0x002,
  1484. /// Draw grid cell border lines.
  1485. wxGRID_DRAW_CELL_LINES = 0x004,
  1486. /**
  1487. Draw a bounding rectangle around the rendered cell area.
  1488. Useful where row or column headers are not drawn or where there is
  1489. multi row or column cell clipping and therefore no cell border at
  1490. the rendered outer boundary.
  1491. */
  1492. wxGRID_DRAW_BOX_RECT = 0x008,
  1493. /**
  1494. Draw the grid cell selection highlight if a selection is present.
  1495. At present the highlight colour drawn depends on whether the grid
  1496. window loses focus before drawing begins.
  1497. */
  1498. wxGRID_DRAW_SELECTION = 0x010,
  1499. /**
  1500. The default render style.
  1501. Includes all except wxGRID_DRAW_SELECTION.
  1502. */
  1503. wxGRID_DRAW_DEFAULT = wxGRID_DRAW_ROWS_HEADER |
  1504. wxGRID_DRAW_COLS_HEADER |
  1505. wxGRID_DRAW_CELL_LINES |
  1506. wxGRID_DRAW_BOX_RECT
  1507. };
  1508. /**
  1509. @class wxGrid
  1510. wxGrid and its related classes are used for displaying and editing tabular
  1511. data. They provide a rich set of features for display, editing, and
  1512. interacting with a variety of data sources. For simple applications, and to
  1513. help you get started, wxGrid is the only class you need to refer to
  1514. directly. It will set up default instances of the other classes and manage
  1515. them for you. For more complex applications you can derive your own classes
  1516. for custom grid views, grid data tables, cell editors and renderers. The
  1517. @ref overview_grid has examples of simple and more complex applications,
  1518. explains the relationship between the various grid classes and has a
  1519. summary of the keyboard shortcuts and mouse functions provided by wxGrid.
  1520. A wxGridTableBase class holds the actual data to be displayed by a wxGrid
  1521. class. One or more wxGrid classes may act as a view for one table class.
  1522. The default table class is called wxGridStringTable and holds an array of
  1523. strings. An instance of such a class is created by CreateGrid().
  1524. wxGridCellRenderer is the abstract base class for rendering contents in a
  1525. cell. The following renderers are predefined:
  1526. - wxGridCellBoolRenderer
  1527. - wxGridCellFloatRenderer
  1528. - wxGridCellNumberRenderer
  1529. - wxGridCellStringRenderer
  1530. The look of a cell can be further defined using wxGridCellAttr. An object
  1531. of this type may be returned by wxGridTableBase::GetAttr().
  1532. wxGridCellEditor is the abstract base class for editing the value of a
  1533. cell. The following editors are predefined:
  1534. - wxGridCellBoolEditor
  1535. - wxGridCellChoiceEditor
  1536. - wxGridCellFloatEditor
  1537. - wxGridCellNumberEditor
  1538. - wxGridCellTextEditor
  1539. Please see wxGridEvent, wxGridSizeEvent, wxGridRangeSelectEvent, and
  1540. wxGridEditorCreatedEvent for the documentation of all event types you can
  1541. use with wxGrid.
  1542. @library{wxadv}
  1543. @category{grid}
  1544. @see @ref overview_grid, wxGridUpdateLocker
  1545. */
  1546. class wxGrid : public wxScrolledWindow
  1547. {
  1548. public:
  1549. /**
  1550. Different selection modes supported by the grid.
  1551. */
  1552. enum wxGridSelectionModes
  1553. {
  1554. /**
  1555. The default selection mode allowing selection of the individual
  1556. cells as well as of the entire rows and columns.
  1557. */
  1558. wxGridSelectCells,
  1559. /**
  1560. The selection mode allowing the selection of the entire rows only.
  1561. The user won't be able to select any cells or columns in this mode.
  1562. */
  1563. wxGridSelectRows,
  1564. /**
  1565. The selection mode allowing the selection of the entire columns only.
  1566. The user won't be able to select any cells or rows in this mode.
  1567. */
  1568. wxGridSelectColumns,
  1569. /**
  1570. The selection mode allowing the user to select either the entire
  1571. columns or the entire rows but not individual cells nor blocks.
  1572. Notice that while this constant is defined as @code
  1573. wxGridSelectColumns | wxGridSelectRows @endcode this doesn't mean
  1574. that all the other combinations are valid -- at least currently
  1575. they are not.
  1576. @since 2.9.1
  1577. */
  1578. wxGridSelectRowsOrColumns
  1579. };
  1580. /**
  1581. Return values for GetCellSize().
  1582. @since 2.9.1
  1583. */
  1584. enum CellSpan
  1585. {
  1586. /// This cell is inside a span covered by another cell.
  1587. CellSpan_Inside = -1,
  1588. /// This is a normal, non-spanning cell.
  1589. CellSpan_None = 0,
  1590. /// This cell spans several physical wxGrid cells.
  1591. CellSpan_Main
  1592. };
  1593. /**
  1594. Constants defining different support built-in TAB handling behaviours.
  1595. The elements of this enum determine what happens when TAB is pressed
  1596. when the cursor is in the rightmost column (or Shift-TAB is pressed
  1597. when the cursor is in the leftmost one).
  1598. @see SetTabBehaviour(), @c wxEVT_GRID_TABBING
  1599. @since 2.9.5
  1600. */
  1601. enum TabBehaviour
  1602. {
  1603. /// Do nothing, this is default.
  1604. Tab_Stop,
  1605. /// Move to the beginning of the next (or the end of the previous) row.
  1606. Tab_Wrap,
  1607. /// Move to the next (or the previous) control after the grid.
  1608. Tab_Leave
  1609. };
  1610. /**
  1611. @name Constructors and Initialization
  1612. */
  1613. //@{
  1614. /**
  1615. Default constructor.
  1616. You must call Create() to really create the grid window and also call
  1617. CreateGrid() or SetTable() to initialize the grid contents.
  1618. */
  1619. wxGrid();
  1620. /**
  1621. Constructor creating the grid window.
  1622. You must call either CreateGrid() or SetTable() to initialize the grid
  1623. contents before using it.
  1624. */
  1625. wxGrid(wxWindow* parent, wxWindowID id,
  1626. const wxPoint& pos = wxDefaultPosition,
  1627. const wxSize& size = wxDefaultSize,
  1628. long style = wxWANTS_CHARS,
  1629. const wxString& name = wxGridNameStr);
  1630. /**
  1631. Destructor.
  1632. This will also destroy the associated grid table unless you passed a
  1633. table object to the grid and specified that the grid should not take
  1634. ownership of the table (see SetTable()).
  1635. */
  1636. virtual ~wxGrid();
  1637. /**
  1638. Creates the grid window for an object initialized using the default
  1639. constructor.
  1640. You must call either CreateGrid() or SetTable() to initialize the grid
  1641. contents before using it.
  1642. */
  1643. bool Create(wxWindow* parent, wxWindowID id,
  1644. const wxPoint& pos = wxDefaultPosition,
  1645. const wxSize& size = wxDefaultSize,
  1646. long style = wxWANTS_CHARS,
  1647. const wxString& name = wxGridNameStr);
  1648. /**
  1649. Creates a grid with the specified initial number of rows and columns.
  1650. Call this directly after the grid constructor. When you use this
  1651. function wxGrid will create and manage a simple table of string values
  1652. for you. All of the grid data will be stored in memory.
  1653. For applications with more complex data types or relationships, or for
  1654. dealing with very large datasets, you should derive your own grid table
  1655. class and pass a table object to the grid with SetTable().
  1656. */
  1657. bool CreateGrid(int numRows, int numCols,
  1658. wxGridSelectionModes selmode = wxGridSelectCells);
  1659. /**
  1660. Passes a pointer to a custom grid table to be used by the grid.
  1661. This should be called after the grid constructor and before using the
  1662. grid object. If @a takeOwnership is set to @true then the table will be
  1663. deleted by the wxGrid destructor.
  1664. Use this function instead of CreateGrid() when your application
  1665. involves complex or non-string data or data sets that are too large to
  1666. fit wholly in memory.
  1667. */
  1668. bool SetTable(wxGridTableBase* table, bool takeOwnership = false,
  1669. wxGridSelectionModes selmode = wxGridSelectCells);
  1670. /**
  1671. Receive and handle a message from the table.
  1672. */
  1673. bool ProcessTableMessage(wxGridTableMessage& msg);
  1674. //@}
  1675. /**
  1676. @name Grid Line Formatting
  1677. */
  1678. //@{
  1679. /**
  1680. Turns the drawing of grid lines on or off.
  1681. */
  1682. void EnableGridLines(bool enable = true);
  1683. /**
  1684. Returns the pen used for vertical grid lines.
  1685. This virtual function may be overridden in derived classes in order to
  1686. change the appearance of individual grid lines for the given column
  1687. @a col.
  1688. See GetRowGridLinePen() for an example.
  1689. */
  1690. virtual wxPen GetColGridLinePen(int col);
  1691. /**
  1692. Returns the pen used for grid lines.
  1693. This virtual function may be overridden in derived classes in order to
  1694. change the appearance of grid lines. Note that currently the pen width
  1695. must be 1.
  1696. @see GetColGridLinePen(), GetRowGridLinePen()
  1697. */
  1698. virtual wxPen GetDefaultGridLinePen();
  1699. /**
  1700. Returns the colour used for grid lines.
  1701. @see GetDefaultGridLinePen()
  1702. */
  1703. wxColour GetGridLineColour() const;
  1704. /**
  1705. Returns the pen used for horizontal grid lines.
  1706. This virtual function may be overridden in derived classes in order to
  1707. change the appearance of individual grid line for the given @a row.
  1708. Example:
  1709. @code
  1710. // in a grid displaying music notation, use a solid black pen between
  1711. // octaves (C0=row 127, C1=row 115 etc.)
  1712. wxPen MidiGrid::GetRowGridLinePen(int row)
  1713. {
  1714. if ( row % 12 == 7 )
  1715. return wxPen(*wxBLACK, 1, wxSOLID);
  1716. else
  1717. return GetDefaultGridLinePen();
  1718. }
  1719. @endcode
  1720. */
  1721. virtual wxPen GetRowGridLinePen(int row);
  1722. /**
  1723. Returns @true if drawing of grid lines is turned on, @false otherwise.
  1724. */
  1725. bool GridLinesEnabled() const;
  1726. /**
  1727. Sets the colour used to draw grid lines.
  1728. */
  1729. void SetGridLineColour(const wxColour& colour);
  1730. //@}
  1731. /**
  1732. @name Label Values and Formatting
  1733. */
  1734. //@{
  1735. /**
  1736. Sets the arguments to the current column label alignment values.
  1737. Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE
  1738. or @c wxALIGN_RIGHT.
  1739. Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or
  1740. @c wxALIGN_BOTTOM.
  1741. */
  1742. void GetColLabelAlignment(int* horiz, int* vert) const;
  1743. /**
  1744. Returns the orientation of the column labels (either @c wxHORIZONTAL or
  1745. @c wxVERTICAL).
  1746. */
  1747. int GetColLabelTextOrientation() const;
  1748. /**
  1749. Returns the specified column label.
  1750. The default grid table class provides column labels of the form
  1751. A,B...Z,AA,AB...ZZ,AAA... If you are using a custom grid table you can
  1752. override wxGridTableBase::GetColLabelValue() to provide your own
  1753. labels.
  1754. */
  1755. wxString GetColLabelValue(int col) const;
  1756. /**
  1757. Returns the colour used for the background of row and column labels.
  1758. */
  1759. wxColour GetLabelBackgroundColour() const;
  1760. /**
  1761. Returns the font used for row and column labels.
  1762. */
  1763. wxFont GetLabelFont() const;
  1764. /**
  1765. Returns the colour used for row and column label text.
  1766. */
  1767. wxColour GetLabelTextColour() const;
  1768. /**
  1769. Returns the alignment used for row labels.
  1770. Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE
  1771. or @c wxALIGN_RIGHT.
  1772. Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or
  1773. @c wxALIGN_BOTTOM.
  1774. */
  1775. void GetRowLabelAlignment(int* horiz, int* vert) const;
  1776. /**
  1777. Returns the specified row label.
  1778. The default grid table class provides numeric row labels. If you are
  1779. using a custom grid table you can override
  1780. wxGridTableBase::GetRowLabelValue() to provide your own labels.
  1781. */
  1782. wxString GetRowLabelValue(int row) const;
  1783. /**
  1784. Hides the column labels by calling SetColLabelSize() with a size of 0.
  1785. Show labels again by calling that method with a width greater than 0.
  1786. */
  1787. void HideColLabels();
  1788. /**
  1789. Hides the row labels by calling SetRowLabelSize() with a size of 0.
  1790. The labels can be shown again by calling SetRowLabelSize() with a width
  1791. greater than 0.
  1792. */
  1793. void HideRowLabels();
  1794. /**
  1795. Sets the horizontal and vertical alignment of column label text.
  1796. Horizontal alignment should be one of @c wxALIGN_LEFT,
  1797. @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. Vertical alignment should be one
  1798. of @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM.
  1799. */
  1800. void SetColLabelAlignment(int horiz, int vert);
  1801. /**
  1802. Sets the orientation of the column labels (either @c wxHORIZONTAL or
  1803. @c wxVERTICAL).
  1804. */
  1805. void SetColLabelTextOrientation(int textOrientation);
  1806. /**
  1807. Set the value for the given column label.
  1808. If you are using a custom grid table you must override
  1809. wxGridTableBase::SetColLabelValue() for this to have any effect.
  1810. */
  1811. void SetColLabelValue(int col, const wxString& value);
  1812. /**
  1813. Sets the background colour for row and column labels.
  1814. */
  1815. void SetLabelBackgroundColour(const wxColour& colour);
  1816. /**
  1817. Sets the font for row and column labels.
  1818. */
  1819. void SetLabelFont(const wxFont& font);
  1820. /**
  1821. Sets the colour for row and column label text.
  1822. */
  1823. void SetLabelTextColour(const wxColour& colour);
  1824. /**
  1825. Sets the horizontal and vertical alignment of row label text.
  1826. Horizontal alignment should be one of @c wxALIGN_LEFT,
  1827. @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. Vertical alignment should be one
  1828. of @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM.
  1829. */
  1830. void SetRowLabelAlignment(int horiz, int vert);
  1831. /**
  1832. Sets the value for the given row label.
  1833. If you are using a derived grid table you must override
  1834. wxGridTableBase::SetRowLabelValue() for this to have any effect.
  1835. */
  1836. void SetRowLabelValue(int row, const wxString& value);
  1837. /**
  1838. Call this in order to make the column labels use a native look by using
  1839. wxRendererNative::DrawHeaderButton() internally.
  1840. There is no equivalent method for drawing row columns as there is not
  1841. native look for that. This option is useful when using wxGrid for
  1842. displaying tables and not as a spread-sheet.
  1843. @see UseNativeColHeader()
  1844. */
  1845. void SetUseNativeColLabels(bool native = true);
  1846. /**
  1847. Enable the use of native header window for column labels.
  1848. If this function is called with @true argument, a wxHeaderCtrl is used
  1849. instead to display the column labels instead of drawing them in wxGrid
  1850. code itself. This has the advantage of making the grid look and feel
  1851. perfectly the same as native applications (using SetUseNativeColLabels()
  1852. the grid can be made to look more natively but it still doesn't feel
  1853. natively, notably the column resizing and dragging still works slightly
  1854. differently as it is implemented in wxWidgets itself) but results in
  1855. different behaviour for column and row headers, for which there is no
  1856. equivalent function, and, most importantly, is unsuitable for grids
  1857. with huge numbers of columns as wxHeaderCtrl doesn't support virtual
  1858. mode. Because of this, by default the grid does not use the native
  1859. header control but you should call this function to enable it if you
  1860. are using the grid to display tabular data and don't have thousands of
  1861. columns in it.
  1862. Another difference between the default behaviour and the native header
  1863. behaviour is that the latter provides the user with a context menu
  1864. (which appears on right clicking the header) allowing to rearrange the
  1865. grid columns if CanDragColMove() returns @true. If you want to prevent
  1866. this from happening for some reason, you need to define a handler for
  1867. @c wxEVT_GRID_LABEL_RIGHT_CLICK event which simply does nothing (in
  1868. particular doesn't skip the event) as this will prevent the default
  1869. right click handling from working.
  1870. Also note that currently @c wxEVT_GRID_LABEL_RIGHT_DCLICK event is not
  1871. generated for the column labels if the native columns header is used
  1872. (but this limitation could possibly be lifted in the future).
  1873. */
  1874. void UseNativeColHeader(bool native = true);
  1875. //@}
  1876. /**
  1877. @name Cell Formatting
  1878. Note that wxGridCellAttr can be used alternatively to most of these
  1879. methods. See the "Attributes Management" of wxGridTableBase.
  1880. */
  1881. //@{
  1882. /**
  1883. Sets the arguments to the horizontal and vertical text alignment values
  1884. for the grid cell at the specified location.
  1885. Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE
  1886. or @c wxALIGN_RIGHT.
  1887. Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or
  1888. @c wxALIGN_BOTTOM.
  1889. */
  1890. void GetCellAlignment(int row, int col, int* horiz, int* vert) const;
  1891. /**
  1892. Returns the background colour of the cell at the specified location.
  1893. */
  1894. wxColour GetCellBackgroundColour(int row, int col) const;
  1895. /**
  1896. Returns the font for text in the grid cell at the specified location.
  1897. */
  1898. wxFont GetCellFont(int row, int col) const;
  1899. /**
  1900. Returns the text colour for the grid cell at the specified location.
  1901. */
  1902. wxColour GetCellTextColour(int row, int col) const;
  1903. /**
  1904. Returns the default cell alignment.
  1905. Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE
  1906. or @c wxALIGN_RIGHT.
  1907. Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or
  1908. @c wxALIGN_BOTTOM.
  1909. @see SetDefaultCellAlignment()
  1910. */
  1911. void GetDefaultCellAlignment(int* horiz, int* vert) const;
  1912. /**
  1913. Returns the current default background colour for grid cells.
  1914. */
  1915. wxColour GetDefaultCellBackgroundColour() const;
  1916. /**
  1917. Returns the current default font for grid cell text.
  1918. */
  1919. wxFont GetDefaultCellFont() const;
  1920. /**
  1921. Returns the current default colour for grid cell text.
  1922. */
  1923. wxColour GetDefaultCellTextColour() const;
  1924. /**
  1925. Sets the horizontal and vertical alignment for grid cell text at the
  1926. specified location.
  1927. Horizontal alignment should be one of @c wxALIGN_LEFT,
  1928. @c wxALIGN_CENTRE or @c wxALIGN_RIGHT.
  1929. Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE
  1930. or @c wxALIGN_BOTTOM.
  1931. */
  1932. void SetCellAlignment(int row, int col, int horiz, int vert);
  1933. /**
  1934. Sets the horizontal and vertical alignment for grid cell text at the
  1935. specified location.
  1936. Horizontal alignment should be one of @c wxALIGN_LEFT,
  1937. @c wxALIGN_CENTRE or @c wxALIGN_RIGHT.
  1938. Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE
  1939. or @c wxALIGN_BOTTOM.
  1940. */
  1941. void SetCellAlignment(int align, int row, int col);
  1942. /**
  1943. Set the background colour for the given cell or all cells by default.
  1944. */
  1945. void SetCellBackgroundColour(int row, int col, const wxColour& colour);
  1946. /**
  1947. Sets the font for text in the grid cell at the specified location.
  1948. */
  1949. void SetCellFont(int row, int col, const wxFont& font);
  1950. /**
  1951. Sets the text colour for the given cell.
  1952. */
  1953. void SetCellTextColour(int row, int col, const wxColour& colour);
  1954. /**
  1955. Sets the text colour for the given cell.
  1956. */
  1957. void SetCellTextColour(const wxColour& val, int row, int col);
  1958. /**
  1959. Sets the text colour for all cells by default.
  1960. */
  1961. void SetCellTextColour(const wxColour& colour);
  1962. /**
  1963. Sets the default horizontal and vertical alignment for grid cell text.
  1964. Horizontal alignment should be one of @c wxALIGN_LEFT,
  1965. @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. Vertical alignment should be one
  1966. of @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM.
  1967. */
  1968. void SetDefaultCellAlignment(int horiz, int vert);
  1969. /**
  1970. Sets the default background colour for grid cells.
  1971. */
  1972. void SetDefaultCellBackgroundColour(const wxColour& colour);
  1973. /**
  1974. Sets the default font to be used for grid cell text.
  1975. */
  1976. void SetDefaultCellFont(const wxFont& font);
  1977. /**
  1978. Sets the current default colour for grid cell text.
  1979. */
  1980. void SetDefaultCellTextColour(const wxColour& colour);
  1981. //@}
  1982. /**
  1983. @name Cell Values, Editors, and Renderers
  1984. Note that wxGridCellAttr can be used alternatively to most of these
  1985. methods. See the "Attributes Management" of wxGridTableBase.
  1986. */
  1987. //@{
  1988. /**
  1989. Returns @true if the in-place edit control for the current grid cell
  1990. can be used and @false otherwise.
  1991. This function always returns @false for the read-only cells.
  1992. */
  1993. bool CanEnableCellControl() const;
  1994. /**
  1995. Disables in-place editing of grid cells.
  1996. Equivalent to calling EnableCellEditControl(@false).
  1997. */
  1998. void DisableCellEditControl();
  1999. /**
  2000. Enables or disables in-place editing of grid cell data.
  2001. The grid will issue either a @c wxEVT_GRID_EDITOR_SHOWN or
  2002. @c wxEVT_GRID_EDITOR_HIDDEN event.
  2003. */
  2004. void EnableCellEditControl(bool enable = true);
  2005. /**
  2006. Makes the grid globally editable or read-only.
  2007. If the edit argument is @false this function sets the whole grid as
  2008. read-only. If the argument is @true the grid is set to the default
  2009. state where cells may be editable. In the default state you can set
  2010. single grid cells and whole rows and columns to be editable or
  2011. read-only via wxGridCellAttr::SetReadOnly(). For single cells you
  2012. can also use the shortcut function SetReadOnly().
  2013. For more information about controlling grid cell attributes see the
  2014. wxGridCellAttr class and the @ref overview_grid.
  2015. */
  2016. void EnableEditing(bool edit);
  2017. /**
  2018. Returns a pointer to the editor for the cell at the specified location.
  2019. See wxGridCellEditor and the @ref overview_grid for more information
  2020. about cell editors and renderers.
  2021. The caller must call DecRef() on the returned pointer.
  2022. */
  2023. wxGridCellEditor* GetCellEditor(int row, int col) const;
  2024. /**
  2025. Returns a pointer to the renderer for the grid cell at the specified
  2026. location.
  2027. See wxGridCellRenderer and the @ref overview_grid for more information
  2028. about cell editors and renderers.
  2029. The caller must call DecRef() on the returned pointer.
  2030. */
  2031. wxGridCellRenderer* GetCellRenderer(int row, int col) const;
  2032. /**
  2033. Returns the string contained in the cell at the specified location.
  2034. For simple applications where a grid object automatically uses a
  2035. default grid table of string values you use this function together with
  2036. SetCellValue() to access cell values. For more complex applications
  2037. where you have derived your own grid table class that contains various
  2038. data types (e.g. numeric, boolean or user-defined custom types) then
  2039. you only use this function for those cells that contain string values.
  2040. See wxGridTableBase::CanGetValueAs() and the @ref overview_grid for
  2041. more information.
  2042. */
  2043. wxString GetCellValue(int row, int col) const;
  2044. /**
  2045. Returns the string contained in the cell at the specified location.
  2046. For simple applications where a grid object automatically uses a
  2047. default grid table of string values you use this function together with
  2048. SetCellValue() to access cell values. For more complex applications
  2049. where you have derived your own grid table class that contains various
  2050. data types (e.g. numeric, boolean or user-defined custom types) then
  2051. you only use this function for those cells that contain string values.
  2052. See wxGridTableBase::CanGetValueAs() and the @ref overview_grid for
  2053. more information.
  2054. */
  2055. wxString GetCellValue(const wxGridCellCoords& coords) const;
  2056. /**
  2057. Returns a pointer to the current default grid cell editor.
  2058. See wxGridCellEditor and the @ref overview_grid for more information
  2059. about cell editors and renderers.
  2060. */
  2061. wxGridCellEditor* GetDefaultEditor() const;
  2062. /**
  2063. Returns the default editor for the specified cell.
  2064. The base class version returns the editor appropriate for the current
  2065. cell type but this method may be overridden in the derived classes to
  2066. use custom editors for some cells by default.
  2067. Notice that the same may be achieved in a usually simpler way by
  2068. associating a custom editor with the given cell or cells.
  2069. The caller must call DecRef() on the returned pointer.
  2070. */
  2071. virtual wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
  2072. /**
  2073. Returns the default editor for the specified cell.
  2074. The base class version returns the editor appropriate for the current
  2075. cell type but this method may be overridden in the derived classes to
  2076. use custom editors for some cells by default.
  2077. Notice that the same may be achieved in a usually simpler way by
  2078. associating a custom editor with the given cell or cells.
  2079. The caller must call DecRef() on the returned pointer.
  2080. */
  2081. wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const;
  2082. /**
  2083. Returns the default editor for the cells containing values of the given
  2084. type.
  2085. The base class version returns the editor which was associated with the
  2086. specified @a typeName when it was registered RegisterDataType() but
  2087. this function may be overridden to return something different. This
  2088. allows to override an editor used for one of the standard types.
  2089. The caller must call DecRef() on the returned pointer.
  2090. */
  2091. virtual wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
  2092. /**
  2093. Returns a pointer to the current default grid cell renderer.
  2094. See wxGridCellRenderer and the @ref overview_grid for more information
  2095. about cell editors and renderers.
  2096. The caller must call DecRef() on the returned pointer.
  2097. */
  2098. wxGridCellRenderer* GetDefaultRenderer() const;
  2099. /**
  2100. Returns the default renderer for the given cell.
  2101. The base class version returns the renderer appropriate for the current
  2102. cell type but this method may be overridden in the derived classes to
  2103. use custom renderers for some cells by default.
  2104. The caller must call DecRef() on the returned pointer.
  2105. */
  2106. virtual wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
  2107. /**
  2108. Returns the default renderer for the cell containing values of the
  2109. given type.
  2110. @see GetDefaultEditorForType()
  2111. */
  2112. virtual wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
  2113. /**
  2114. Hides the in-place cell edit control.
  2115. */
  2116. void HideCellEditControl();
  2117. /**
  2118. Returns @true if the in-place edit control is currently enabled.
  2119. */
  2120. bool IsCellEditControlEnabled() const;
  2121. /**
  2122. Returns @true if the current cell is read-only.
  2123. @see SetReadOnly(), IsReadOnly()
  2124. */
  2125. bool IsCurrentCellReadOnly() const;
  2126. /**
  2127. Returns @false if the whole grid has been set as read-only or @true
  2128. otherwise.
  2129. See EnableEditing() for more information about controlling the editing
  2130. status of grid cells.
  2131. */
  2132. bool IsEditable() const;
  2133. /**
  2134. Returns @true if the cell at the specified location can't be edited.
  2135. @see SetReadOnly(), IsCurrentCellReadOnly()
  2136. */
  2137. bool IsReadOnly(int row, int col) const;
  2138. /**
  2139. Register a new data type.
  2140. The data types allow to naturally associate specific renderers and
  2141. editors to the cells containing values of the given type. For example,
  2142. the grid automatically registers a data type with the name
  2143. @c wxGRID_VALUE_STRING which uses wxGridCellStringRenderer and
  2144. wxGridCellTextEditor as its renderer and editor respectively -- this is
  2145. the data type used by all the cells of the default wxGridStringTable,
  2146. so this renderer and editor are used by default for all grid cells.
  2147. However if a custom table returns @c wxGRID_VALUE_BOOL from its
  2148. wxGridTableBase::GetTypeName() method, then wxGridCellBoolRenderer and
  2149. wxGridCellBoolEditor are used for it because the grid also registers a
  2150. boolean data type with this name.
  2151. And as this mechanism is completely generic, you may register your own
  2152. data types using your own custom renderers and editors. Just remember
  2153. that the table must identify a cell as being of the given type for them
  2154. to be used for this cell.
  2155. @param typeName
  2156. Name of the new type. May be any string, but if the type name is
  2157. the same as the name of an already registered type, including one
  2158. of the standard ones (which are @c wxGRID_VALUE_STRING, @c
  2159. wxGRID_VALUE_BOOL, @c wxGRID_VALUE_NUMBER, @c wxGRID_VALUE_FLOAT
  2160. and @c wxGRID_VALUE_CHOICE), then the new registration information
  2161. replaces the previously used renderer and editor.
  2162. @param renderer
  2163. The renderer to use for the cells of this type. Its ownership is
  2164. taken by the grid, i.e. it will call DecRef() on this pointer when
  2165. it doesn't need it any longer.
  2166. @param editor
  2167. The editor to use for the cells of this type. Its ownership is also
  2168. taken by the grid.
  2169. */
  2170. void RegisterDataType(const wxString& typeName,
  2171. wxGridCellRenderer* renderer,
  2172. wxGridCellEditor* editor);
  2173. /**
  2174. Sets the value of the current grid cell to the current in-place edit
  2175. control value.
  2176. This is called automatically when the grid cursor moves from the
  2177. current cell to a new cell. It is also a good idea to call this
  2178. function when closing a grid since any edits to the final cell location
  2179. will not be saved otherwise.
  2180. */
  2181. void SaveEditControlValue();
  2182. /**
  2183. Sets the editor for the grid cell at the specified location.
  2184. The grid will take ownership of the pointer.
  2185. See wxGridCellEditor and the @ref overview_grid for more information
  2186. about cell editors and renderers.
  2187. */
  2188. void SetCellEditor(int row, int col, wxGridCellEditor* editor);
  2189. /**
  2190. Sets the renderer for the grid cell at the specified location.
  2191. The grid will take ownership of the pointer.
  2192. See wxGridCellRenderer and the @ref overview_grid for more information
  2193. about cell editors and renderers.
  2194. */
  2195. void SetCellRenderer(int row, int col, wxGridCellRenderer* renderer);
  2196. /**
  2197. Sets the string value for the cell at the specified location.
  2198. For simple applications where a grid object automatically uses a
  2199. default grid table of string values you use this function together with
  2200. GetCellValue() to access cell values. For more complex applications
  2201. where you have derived your own grid table class that contains various
  2202. data types (e.g. numeric, boolean or user-defined custom types) then
  2203. you only use this function for those cells that contain string values.
  2204. See wxGridTableBase::CanSetValueAs() and the @ref overview_grid for
  2205. more information.
  2206. */
  2207. void SetCellValue(int row, int col, const wxString& s);
  2208. /**
  2209. Sets the string value for the cell at the specified location.
  2210. For simple applications where a grid object automatically uses a
  2211. default grid table of string values you use this function together with
  2212. GetCellValue() to access cell values. For more complex applications
  2213. where you have derived your own grid table class that contains various
  2214. data types (e.g. numeric, boolean or user-defined custom types) then
  2215. you only use this function for those cells that contain string values.
  2216. See wxGridTableBase::CanSetValueAs() and the @ref overview_grid for
  2217. more information.
  2218. */
  2219. void SetCellValue(const wxGridCellCoords& coords, const wxString& s);
  2220. /**
  2221. @deprecated Please use SetCellValue(int,int,const wxString&) or
  2222. SetCellValue(const wxGridCellCoords&,const wxString&)
  2223. instead.
  2224. Sets the string value for the cell at the specified location.
  2225. For simple applications where a grid object automatically uses a
  2226. default grid table of string values you use this function together with
  2227. GetCellValue() to access cell values. For more complex applications
  2228. where you have derived your own grid table class that contains various
  2229. data types (e.g. numeric, boolean or user-defined custom types) then
  2230. you only use this function for those cells that contain string values.
  2231. See wxGridTableBase::CanSetValueAs() and the @ref overview_grid for
  2232. more information.
  2233. */
  2234. void SetCellValue(const wxString& val, int row, int col);
  2235. /**
  2236. Sets the specified column to display boolean values.
  2237. @see SetColFormatCustom()
  2238. */
  2239. void SetColFormatBool(int col);
  2240. /**
  2241. Sets the specified column to display data in a custom format.
  2242. This method provides an alternative to defining a custom grid table
  2243. which would return @a typeName from its GetTypeName() method for the
  2244. cells in this column: while it doesn't really change the type of the
  2245. cells in this column, it does associate the renderer and editor used
  2246. for the cells of the specified type with them.
  2247. See the @ref overview_grid for more information on working with custom
  2248. data types.
  2249. */
  2250. void SetColFormatCustom(int col, const wxString& typeName);
  2251. /**
  2252. Sets the specified column to display floating point values with the
  2253. given width and precision.
  2254. @see SetColFormatCustom()
  2255. */
  2256. void SetColFormatFloat(int col, int width = -1, int precision = -1);
  2257. /**
  2258. Sets the specified column to display integer values.
  2259. @see SetColFormatCustom()
  2260. */
  2261. void SetColFormatNumber(int col);
  2262. /**
  2263. Sets the default editor for grid cells.
  2264. The grid will take ownership of the pointer.
  2265. See wxGridCellEditor and the @ref overview_grid for more information
  2266. about cell editors and renderers.
  2267. */
  2268. void SetDefaultEditor(wxGridCellEditor* editor);
  2269. /**
  2270. Sets the default renderer for grid cells.
  2271. The grid will take ownership of the pointer.
  2272. See wxGridCellRenderer and the @ref overview_grid for more information
  2273. about cell editors and renderers.
  2274. */
  2275. void SetDefaultRenderer(wxGridCellRenderer* renderer);
  2276. /**
  2277. Makes the cell at the specified location read-only or editable.
  2278. @see IsReadOnly()
  2279. */
  2280. void SetReadOnly(int row, int col, bool isReadOnly = true);
  2281. /**
  2282. Displays the in-place cell edit control for the current cell.
  2283. */
  2284. void ShowCellEditControl();
  2285. //@}
  2286. /**
  2287. @name Column and Row Sizes
  2288. @see @ref overview_grid_resizing
  2289. */
  2290. //@{
  2291. /**
  2292. Automatically sets the height and width of all rows and columns to fit
  2293. their contents.
  2294. */
  2295. void AutoSize();
  2296. /**
  2297. Automatically adjusts width of the column to fit its label.
  2298. */
  2299. void AutoSizeColLabelSize(int col);
  2300. /**
  2301. Automatically sizes the column to fit its contents. If @a setAsMin is
  2302. @true the calculated width will also be set as the minimal width for
  2303. the column.
  2304. */
  2305. void AutoSizeColumn(int col, bool setAsMin = true);
  2306. /**
  2307. Automatically sizes all columns to fit their contents. If @a setAsMin
  2308. is @true the calculated widths will also be set as the minimal widths
  2309. for the columns.
  2310. */
  2311. void AutoSizeColumns(bool setAsMin = true);
  2312. /**
  2313. Automatically sizes the row to fit its contents. If @a setAsMin is
  2314. @true the calculated height will also be set as the minimal height for
  2315. the row.
  2316. */
  2317. void AutoSizeRow(int row, bool setAsMin = true);
  2318. /**
  2319. Automatically adjusts height of the row to fit its label.
  2320. */
  2321. void AutoSizeRowLabelSize(int col);
  2322. /**
  2323. Automatically sizes all rows to fit their contents. If @a setAsMin is
  2324. @true the calculated heights will also be set as the minimal heights
  2325. for the rows.
  2326. */
  2327. void AutoSizeRows(bool setAsMin = true);
  2328. /**
  2329. Returns @true if the cell value can overflow.
  2330. A cell can overflow if the next cell in the row is empty.
  2331. */
  2332. bool GetCellOverflow(int row, int col) const;
  2333. /**
  2334. Returns the current height of the column labels.
  2335. */
  2336. int GetColLabelSize() const;
  2337. /**
  2338. Returns the minimal width to which a column may be resized.
  2339. Use SetColMinimalAcceptableWidth() to change this value globally or
  2340. SetColMinimalWidth() to do it for individual columns.
  2341. @see GetRowMinimalAcceptableHeight()
  2342. */
  2343. int GetColMinimalAcceptableWidth() const;
  2344. /**
  2345. Returns the width of the specified column.
  2346. */
  2347. int GetColSize(int col) const;
  2348. /**
  2349. Returns @true if the specified column is not currently hidden.
  2350. */
  2351. bool IsColShown(int col) const;
  2352. /**
  2353. Returns @true if the cells can overflow by default.
  2354. */
  2355. bool GetDefaultCellOverflow() const;
  2356. /**
  2357. Returns the default height for column labels.
  2358. */
  2359. int GetDefaultColLabelSize() const;
  2360. /**
  2361. Returns the current default width for grid columns.
  2362. */
  2363. int GetDefaultColSize() const;
  2364. /**
  2365. Returns the default width for the row labels.
  2366. */
  2367. int GetDefaultRowLabelSize() const;
  2368. /**
  2369. Returns the current default height for grid rows.
  2370. */
  2371. int GetDefaultRowSize() const;
  2372. /**
  2373. Returns the minimal size to which rows can be resized.
  2374. Use SetRowMinimalAcceptableHeight() to change this value globally or
  2375. SetRowMinimalHeight() to do it for individual cells.
  2376. @see GetColMinimalAcceptableWidth()
  2377. */
  2378. int GetRowMinimalAcceptableHeight() const;
  2379. /**
  2380. Returns the current width of the row labels.
  2381. */
  2382. int GetRowLabelSize() const;
  2383. /**
  2384. Returns the height of the specified row.
  2385. */
  2386. int GetRowSize(int row) const;
  2387. /**
  2388. Returns @true if the specified row is not currently hidden.
  2389. */
  2390. bool IsRowShown(int row) const;
  2391. /**
  2392. Sets the overflow permission of the cell.
  2393. */
  2394. void SetCellOverflow(int row, int col, bool allow);
  2395. /**
  2396. Sets the height of the column labels.
  2397. If @a height equals to @c wxGRID_AUTOSIZE then height is calculated
  2398. automatically so that no label is truncated. Note that this could be
  2399. slow for a large table.
  2400. */
  2401. void SetColLabelSize(int height);
  2402. /**
  2403. Sets the minimal @a width to which the user can resize columns.
  2404. @see GetColMinimalAcceptableWidth()
  2405. */
  2406. void SetColMinimalAcceptableWidth(int width);
  2407. /**
  2408. Sets the minimal @a width for the specified column @a col.
  2409. It is usually best to call this method during grid creation as calling
  2410. it later will not resize the column to the given minimal width even if
  2411. it is currently narrower than it.
  2412. @a width must be greater than the minimal acceptable column width as
  2413. returned by GetColMinimalAcceptableWidth().
  2414. */
  2415. void SetColMinimalWidth(int col, int width);
  2416. /**
  2417. Sets the width of the specified column.
  2418. @param col
  2419. The column index.
  2420. @param width
  2421. The new column width in pixels, 0 to hide the column or -1 to fit
  2422. the column width to its label width.
  2423. */
  2424. void SetColSize(int col, int width);
  2425. /**
  2426. Hides the specified column.
  2427. To show the column later you need to call SetColSize() with non-0
  2428. width or ShowCol() to restore the previous column width.
  2429. If the column is already hidden, this method doesn't do anything.
  2430. @param col
  2431. The column index.
  2432. */
  2433. void HideCol(int col);
  2434. /**
  2435. Shows the previously hidden column by resizing it to non-0 size.
  2436. The column is shown again with the same width that it had before
  2437. HideCol() call.
  2438. If the column is currently shown, this method doesn't do anything.
  2439. @see HideCol(), SetColSize()
  2440. */
  2441. void ShowCol(int col);
  2442. /**
  2443. Sets the default overflow permission of the cells.
  2444. */
  2445. void SetDefaultCellOverflow( bool allow );
  2446. /**
  2447. Sets the default width for columns in the grid.
  2448. This will only affect columns subsequently added to the grid unless
  2449. @a resizeExistingCols is @true.
  2450. If @a width is less than GetColMinimalAcceptableWidth(), then the
  2451. minimal acceptable width is used instead of it.
  2452. */
  2453. void SetDefaultColSize(int width, bool resizeExistingCols = false);
  2454. /**
  2455. Sets the default height for rows in the grid.
  2456. This will only affect rows subsequently added to the grid unless
  2457. @a resizeExistingRows is @true.
  2458. If @a height is less than GetRowMinimalAcceptableHeight(), then the
  2459. minimal acceptable height is used instead of it.
  2460. */
  2461. void SetDefaultRowSize(int height, bool resizeExistingRows = false);
  2462. /**
  2463. Sets the width of the row labels.
  2464. If @a width equals @c wxGRID_AUTOSIZE then width is calculated
  2465. automatically so that no label is truncated. Note that this could be
  2466. slow for a large table.
  2467. */
  2468. void SetRowLabelSize(int width);
  2469. /**
  2470. Sets the minimal row @a height used by default.
  2471. See SetColMinimalAcceptableWidth() for more information.
  2472. */
  2473. void SetRowMinimalAcceptableHeight(int height);
  2474. /**
  2475. Sets the minimal @a height for the specified @a row.
  2476. See SetColMinimalWidth() for more information.
  2477. */
  2478. void SetRowMinimalHeight(int row, int height);
  2479. /**
  2480. Sets the height of the specified row.
  2481. See SetColSize() for more information.
  2482. */
  2483. void SetRowSize(int row, int height);
  2484. /**
  2485. Hides the specified row.
  2486. To show the row later you need to call SetRowSize() with non-0
  2487. width or ShowRow() to restore its original height.
  2488. If the row is already hidden, this method doesn't do anything.
  2489. @param col
  2490. The row index.
  2491. */
  2492. void HideRow(int col);
  2493. /**
  2494. Shows the previously hidden row.
  2495. The row is shown again with the same height that it had before
  2496. HideRow() call.
  2497. If the row is currently shown, this method doesn't do anything.
  2498. @see HideRow(), SetRowSize()
  2499. */
  2500. void ShowRow(int col);
  2501. /**
  2502. Get size information for all columns at once.
  2503. This method is useful when the information about all column widths
  2504. needs to be saved. The widths can be later restored using
  2505. SetColSizes().
  2506. @sa wxGridSizesInfo, GetRowSizes()
  2507. */
  2508. wxGridSizesInfo GetColSizes() const;
  2509. /**
  2510. Get size information for all row at once.
  2511. @sa wxGridSizesInfo, GetColSizes()
  2512. */
  2513. wxGridSizesInfo GetRowSizes() const;
  2514. /**
  2515. Restore all columns sizes.
  2516. This is usually called with wxGridSizesInfo object previously returned
  2517. by GetColSizes().
  2518. @sa SetRowSizes()
  2519. */
  2520. void SetColSizes(const wxGridSizesInfo& sizeInfo);
  2521. /**
  2522. Restore all rows sizes.
  2523. @sa SetColSizes()
  2524. */
  2525. void SetRowSizes(const wxGridSizesInfo& sizeInfo);
  2526. /**
  2527. Set the size of the cell.
  2528. Specifying a value of more than 1 in @a num_rows or @a num_cols will
  2529. make the cell at (@a row, @a col) span the block of the specified size,
  2530. covering the other cells which would be normally shown in it. Passing 1
  2531. for both arguments resets the cell to normal appearance.
  2532. @see GetCellSize()
  2533. @param row
  2534. The row of the cell.
  2535. @param col
  2536. The column of the cell.
  2537. @param num_rows
  2538. Number of rows to be occupied by this cell, must be >= 1.
  2539. @param num_cols
  2540. Number of columns to be occupied by this cell, must be >= 1.
  2541. */
  2542. void SetCellSize(int row, int col, int num_rows, int num_cols);
  2543. /**
  2544. Get the size of the cell in number of cells covered by it.
  2545. For normal cells, the function fills both @a num_rows and @a num_cols
  2546. with 1 and returns CellSpan_None. For cells which span multiple cells, i.e.
  2547. for which SetCellSize() had been called, the returned values are the
  2548. same ones as were passed to SetCellSize() call and the function return
  2549. value is CellSpan_Main.
  2550. More unexpectedly, perhaps, the returned values may be @em negative for
  2551. the cells which are inside a span covered by a cell occupying multiple
  2552. rows or columns. They correspond to the offset of the main cell of the
  2553. span from the cell passed to this functions and the function returns
  2554. CellSpan_Inside value to indicate this.
  2555. As an example, consider a 3*3 grid with the cell (1, 1) (the one in the
  2556. middle) having a span of 2 rows and 2 columns, i.e. the grid looks like
  2557. @code
  2558. +----+----+----+
  2559. | | | |
  2560. +----+----+----+
  2561. | | |
  2562. +----+ |
  2563. | | |
  2564. +----+----+----+
  2565. @endcode
  2566. Then the function returns 2 and 2 in @a num_rows and @a num_cols for
  2567. the cell (1, 1) itself and -1 and -1 for the cell (2, 2) as well as -1
  2568. and 0 for the cell (2, 1).
  2569. @param row
  2570. The row of the cell.
  2571. @param col
  2572. The column of the cell.
  2573. @param num_rows
  2574. Pointer to variable receiving the number of rows, must not be @NULL.
  2575. @param num_cols
  2576. Pointer to variable receiving the number of columns, must not be
  2577. @NULL.
  2578. @return
  2579. The kind of this cell span (the return value is new in wxWidgets
  2580. 2.9.1, this function was void in previous wxWidgets versions).
  2581. */
  2582. CellSpan GetCellSize( int row, int col, int *num_rows, int *num_cols ) const;
  2583. /**
  2584. Get the number of rows and columns allocated for this cell.
  2585. This overload doesn't return a CellSpan value but the values returned
  2586. may still be negative, see GetCellSize(int, int, int *, int *) for
  2587. details.
  2588. */
  2589. wxSize GetCellSize(const wxGridCellCoords& coords);
  2590. //@}
  2591. /**
  2592. @name User-Resizing and Dragging
  2593. Functions controlling various interactive mouse operations.
  2594. By default, columns and rows can be resized by dragging the edges of
  2595. their labels (this can be disabled using DisableDragColSize() and
  2596. DisableDragRowSize() methods). And if grid line dragging is enabled with
  2597. EnableDragGridSize() they can also be resized by dragging the right or
  2598. bottom edge of the grid cells.
  2599. Columns can also be moved to interactively change their order but this
  2600. needs to be explicitly enabled with EnableDragColMove().
  2601. */
  2602. //@{
  2603. /**
  2604. Return @true if the dragging of cells is enabled or @false otherwise.
  2605. */
  2606. bool CanDragCell() const;
  2607. /**
  2608. Returns @true if columns can be moved by dragging with the mouse.
  2609. Columns can be moved by dragging on their labels.
  2610. */
  2611. bool CanDragColMove() const;
  2612. /**
  2613. Returns @true if the given column can be resized by dragging with the
  2614. mouse.
  2615. This function returns @true if resizing the columns interactively is
  2616. globally enabled, i.e. if DisableDragColSize() hadn't been called, and
  2617. if this column wasn't explicitly marked as non-resizable with
  2618. DisableColResize().
  2619. */
  2620. bool CanDragColSize(int col) const;
  2621. /**
  2622. Return @true if the dragging of grid lines to resize rows and columns
  2623. is enabled or @false otherwise.
  2624. */
  2625. bool CanDragGridSize() const;
  2626. /**
  2627. Returns @true if the given row can be resized by dragging with the
  2628. mouse.
  2629. This is the same as CanDragColSize() but for rows.
  2630. */
  2631. bool CanDragRowSize(int row) const;
  2632. /**
  2633. Disable interactive resizing of the specified column.
  2634. This method allows to disable resizing of an individual column in a
  2635. grid where the columns are otherwise resizable (which is the case by
  2636. default).
  2637. Notice that currently there is no way to make some columns resizable in
  2638. a grid where columns can't be resized by default as there doesn't seem
  2639. to be any need for this in practice. There is also no way to make the
  2640. column marked as fixed using this method resizable again because it is
  2641. supposed that fixed columns are used for static parts of the grid and
  2642. so should remain fixed during the entire grid lifetime.
  2643. Also notice that disabling interactive column resizing will not prevent
  2644. the program from changing the column size.
  2645. @see EnableDragColSize()
  2646. */
  2647. void DisableColResize(int col);
  2648. /**
  2649. Disable interactive resizing of the specified row.
  2650. This is the same as DisableColResize() but for rows.
  2651. @see EnableDragRowSize()
  2652. */
  2653. void DisableRowResize(int row);
  2654. /**
  2655. Disables column moving by dragging with the mouse.
  2656. Equivalent to passing @false to EnableDragColMove().
  2657. */
  2658. void DisableDragColMove();
  2659. /**
  2660. Disables column sizing by dragging with the mouse.
  2661. Equivalent to passing @false to EnableDragColSize().
  2662. */
  2663. void DisableDragColSize();
  2664. /**
  2665. Disable mouse dragging of grid lines to resize rows and columns.
  2666. Equivalent to passing @false to EnableDragGridSize()
  2667. */
  2668. void DisableDragGridSize();
  2669. /**
  2670. Disables row sizing by dragging with the mouse.
  2671. Equivalent to passing @false to EnableDragRowSize().
  2672. */
  2673. void DisableDragRowSize();
  2674. /**
  2675. Enables or disables cell dragging with the mouse.
  2676. */
  2677. void EnableDragCell(bool enable = true);
  2678. /**
  2679. Enables or disables column moving by dragging with the mouse.
  2680. */
  2681. void EnableDragColMove(bool enable = true);
  2682. /**
  2683. Enables or disables column sizing by dragging with the mouse.
  2684. @see DisableColResize()
  2685. */
  2686. void EnableDragColSize(bool enable = true);
  2687. /**
  2688. Enables or disables row and column resizing by dragging gridlines with
  2689. the mouse.
  2690. */
  2691. void EnableDragGridSize(bool enable = true);
  2692. /**
  2693. Enables or disables row sizing by dragging with the mouse.
  2694. @see DisableRowResize()
  2695. */
  2696. void EnableDragRowSize(bool enable = true);
  2697. /**
  2698. Returns the column ID of the specified column position.
  2699. */
  2700. int GetColAt(int colPos) const;
  2701. /**
  2702. Returns the position of the specified column.
  2703. */
  2704. int GetColPos(int colID) const;
  2705. /**
  2706. Sets the position of the specified column.
  2707. */
  2708. void SetColPos(int colID, int newPos);
  2709. /**
  2710. Sets the positions of all columns at once.
  2711. This method takes an array containing the indices of the columns in
  2712. their display order, i.e. uses the same convention as
  2713. wxHeaderCtrl::SetColumnsOrder().
  2714. */
  2715. void SetColumnsOrder(const wxArrayInt& order);
  2716. /**
  2717. Resets the position of the columns to the default.
  2718. */
  2719. void ResetColPos();
  2720. //@}
  2721. /**
  2722. @name Cursor Movement
  2723. */
  2724. //@{
  2725. /**
  2726. Returns the current grid cell column position.
  2727. */
  2728. int GetGridCursorCol() const;
  2729. /**
  2730. Returns the current grid cell row position.
  2731. */
  2732. int GetGridCursorRow() const;
  2733. /**
  2734. Make the given cell current and ensure it is visible.
  2735. This method is equivalent to calling MakeCellVisible() and
  2736. SetGridCursor() and so, as with the latter, a @c wxEVT_GRID_SELECT_CELL
  2737. event is generated by it and the selected cell doesn't change if the
  2738. event is vetoed.
  2739. */
  2740. void GoToCell(int row, int col);
  2741. /**
  2742. Make the given cell current and ensure it is visible.
  2743. This method is equivalent to calling MakeCellVisible() and
  2744. SetGridCursor() and so, as with the latter, a @c wxEVT_GRID_SELECT_CELL
  2745. event is generated by it and the selected cell doesn't change if the
  2746. event is vetoed.
  2747. */
  2748. void GoToCell(const wxGridCellCoords& coords);
  2749. /**
  2750. Moves the grid cursor down by one row.
  2751. If a block of cells was previously selected it will expand if the
  2752. argument is @true or be cleared if the argument is @false.
  2753. */
  2754. bool MoveCursorDown(bool expandSelection);
  2755. /**
  2756. Moves the grid cursor down in the current column such that it skips to
  2757. the beginning or end of a block of non-empty cells.
  2758. If a block of cells was previously selected it will expand if the
  2759. argument is @true or be cleared if the argument is @false.
  2760. */
  2761. bool MoveCursorDownBlock(bool expandSelection);
  2762. /**
  2763. Moves the grid cursor left by one column.
  2764. If a block of cells was previously selected it will expand if the
  2765. argument is @true or be cleared if the argument is @false.
  2766. */
  2767. bool MoveCursorLeft(bool expandSelection);
  2768. /**
  2769. Moves the grid cursor left in the current row such that it skips to the
  2770. beginning or end of a block of non-empty cells.
  2771. If a block of cells was previously selected it will expand if the
  2772. argument is @true or be cleared if the argument is @false.
  2773. */
  2774. bool MoveCursorLeftBlock(bool expandSelection);
  2775. /**
  2776. Moves the grid cursor right by one column.
  2777. If a block of cells was previously selected it will expand if the
  2778. argument is @true or be cleared if the argument is @false.
  2779. */
  2780. bool MoveCursorRight(bool expandSelection);
  2781. /**
  2782. Moves the grid cursor right in the current row such that it skips to
  2783. the beginning or end of a block of non-empty cells.
  2784. If a block of cells was previously selected it will expand if the
  2785. argument is @true or be cleared if the argument is @false.
  2786. */
  2787. bool MoveCursorRightBlock(bool expandSelection);
  2788. /**
  2789. Moves the grid cursor up by one row.
  2790. If a block of cells was previously selected it will expand if the
  2791. argument is @true or be cleared if the argument is @false.
  2792. */
  2793. bool MoveCursorUp(bool expandSelection);
  2794. /**
  2795. Moves the grid cursor up in the current column such that it skips to
  2796. the beginning or end of a block of non-empty cells.
  2797. If a block of cells was previously selected it will expand if the
  2798. argument is @true or be cleared if the argument is @false.
  2799. */
  2800. bool MoveCursorUpBlock(bool expandSelection);
  2801. /**
  2802. Moves the grid cursor down by some number of rows so that the previous
  2803. bottom visible row becomes the top visible row.
  2804. */
  2805. bool MovePageDown();
  2806. /**
  2807. Moves the grid cursor up by some number of rows so that the previous
  2808. top visible row becomes the bottom visible row.
  2809. */
  2810. bool MovePageUp();
  2811. /**
  2812. Set the grid cursor to the specified cell.
  2813. The grid cursor indicates the current cell and can be moved by the user
  2814. using the arrow keys or the mouse.
  2815. Calling this function generates a @c wxEVT_GRID_SELECT_CELL event and
  2816. if the event handler vetoes this event, the cursor is not moved.
  2817. This function doesn't make the target call visible, use GoToCell() to
  2818. do this.
  2819. */
  2820. void SetGridCursor(int row, int col);
  2821. /**
  2822. Set the grid cursor to the specified cell.
  2823. The grid cursor indicates the current cell and can be moved by the user
  2824. using the arrow keys or the mouse.
  2825. Calling this function generates a @c wxEVT_GRID_SELECT_CELL event and
  2826. if the event handler vetoes this event, the cursor is not moved.
  2827. This function doesn't make the target call visible, use GoToCell() to
  2828. do this.
  2829. */
  2830. void SetGridCursor(const wxGridCellCoords& coords);
  2831. /**
  2832. Set the grid's behaviour when the user presses the TAB key.
  2833. Pressing the TAB key moves the grid cursor right in the current row, if
  2834. there is a cell at the right and, similarly, Shift-TAB moves the cursor
  2835. to the left in the current row if it's not in the first column.
  2836. What happens if the cursor can't be moved because it it's already at
  2837. the beginning or end of the row can be configured using this function,
  2838. see wxGrid::TabBehaviour documentation for the detailed description.
  2839. IF none of the standard behaviours is appropriate, you can always
  2840. handle @c wxEVT_GRID_TABBING event directly to implement a custom
  2841. TAB-handling logic.
  2842. @since 2.9.5
  2843. */
  2844. void SetTabBehaviour(TabBehaviour behaviour);
  2845. //@}
  2846. /**
  2847. @name User Selection
  2848. */
  2849. //@{
  2850. /**
  2851. Deselects all cells that are currently selected.
  2852. */
  2853. void ClearSelection();
  2854. /**
  2855. Returns an array of individually selected cells.
  2856. Notice that this array does @em not contain all the selected cells in
  2857. general as it doesn't include the cells selected as part of column, row
  2858. or block selection. You must use this method, GetSelectedCols(),
  2859. GetSelectedRows() and GetSelectionBlockTopLeft() and
  2860. GetSelectionBlockBottomRight() methods to obtain the entire selection
  2861. in general.
  2862. Please notice this behaviour is by design and is needed in order to
  2863. support grids of arbitrary size (when an entire column is selected in
  2864. a grid with a million of columns, we don't want to create an array with
  2865. a million of entries in this function, instead it returns an empty
  2866. array and GetSelectedCols() returns an array containing one element).
  2867. */
  2868. wxGridCellCoordsArray GetSelectedCells() const;
  2869. /**
  2870. Returns an array of selected columns.
  2871. Please notice that this method alone is not sufficient to find all the
  2872. selected columns as it contains only the columns which were
  2873. individually selected but not those being part of the block selection
  2874. or being selected in virtue of all of their cells being selected
  2875. individually, please see GetSelectedCells() for more details.
  2876. */
  2877. wxArrayInt GetSelectedCols() const;
  2878. /**
  2879. Returns an array of selected rows.
  2880. Please notice that this method alone is not sufficient to find all the
  2881. selected rows as it contains only the rows which were individually
  2882. selected but not those being part of the block selection or being
  2883. selected in virtue of all of their cells being selected individually,
  2884. please see GetSelectedCells() for more details.
  2885. */
  2886. wxArrayInt GetSelectedRows() const;
  2887. /**
  2888. Returns the colour used for drawing the selection background.
  2889. */
  2890. wxColour GetSelectionBackground() const;
  2891. /**
  2892. Returns an array of the bottom right corners of blocks of selected
  2893. cells.
  2894. Please see GetSelectedCells() for more information about the selection
  2895. representation in wxGrid.
  2896. @see GetSelectionBlockTopLeft()
  2897. */
  2898. wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
  2899. /**
  2900. Returns an array of the top left corners of blocks of selected cells.
  2901. Please see GetSelectedCells() for more information about the selection
  2902. representation in wxGrid.
  2903. @see GetSelectionBlockBottomRight()
  2904. */
  2905. wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
  2906. /**
  2907. Returns the colour used for drawing the selection foreground.
  2908. */
  2909. wxColour GetSelectionForeground() const;
  2910. /**
  2911. Returns the current selection mode.
  2912. @see SetSelectionMode().
  2913. */
  2914. wxGridSelectionModes GetSelectionMode() const;
  2915. /**
  2916. Returns @true if the given cell is selected.
  2917. */
  2918. bool IsInSelection(int row, int col) const;
  2919. /**
  2920. Returns @true if the given cell is selected.
  2921. */
  2922. bool IsInSelection(const wxGridCellCoords& coords) const;
  2923. /**
  2924. Returns @true if there are currently any selected cells, rows, columns
  2925. or blocks.
  2926. */
  2927. bool IsSelection() const;
  2928. /**
  2929. Selects all cells in the grid.
  2930. */
  2931. void SelectAll();
  2932. /**
  2933. Selects a rectangular block of cells.
  2934. If @a addToSelected is @false then any existing selection will be
  2935. deselected; if @true the column will be added to the existing
  2936. selection.
  2937. */
  2938. void SelectBlock(int topRow, int leftCol, int bottomRow, int rightCol,
  2939. bool addToSelected = false);
  2940. /**
  2941. Selects a rectangular block of cells.
  2942. If @a addToSelected is @false then any existing selection will be
  2943. deselected; if @true the column will be added to the existing
  2944. selection.
  2945. */
  2946. void SelectBlock(const wxGridCellCoords& topLeft,
  2947. const wxGridCellCoords& bottomRight,
  2948. bool addToSelected = false);
  2949. /**
  2950. Selects the specified column.
  2951. If @a addToSelected is @false then any existing selection will be
  2952. deselected; if @true the column will be added to the existing
  2953. selection.
  2954. This method won't select anything if the current selection mode is
  2955. wxGridSelectRows.
  2956. */
  2957. void SelectCol(int col, bool addToSelected = false);
  2958. /**
  2959. Selects the specified row.
  2960. If @a addToSelected is @false then any existing selection will be
  2961. deselected; if @true the row will be added to the existing selection.
  2962. This method won't select anything if the current selection mode is
  2963. wxGridSelectColumns.
  2964. */
  2965. void SelectRow(int row, bool addToSelected = false);
  2966. /**
  2967. Set the colour to be used for drawing the selection background.
  2968. */
  2969. void SetSelectionBackground(const wxColour& c);
  2970. /**
  2971. Set the colour to be used for drawing the selection foreground.
  2972. */
  2973. void SetSelectionForeground(const wxColour& c);
  2974. /**
  2975. Set the selection behaviour of the grid.
  2976. The existing selection is converted to conform to the new mode if
  2977. possible and discarded otherwise (e.g. any individual selected cells
  2978. are deselected if the new mode allows only the selection of the entire
  2979. rows or columns).
  2980. */
  2981. void SetSelectionMode(wxGridSelectionModes selmode);
  2982. //@}
  2983. /**
  2984. @name Scrolling
  2985. */
  2986. //@{
  2987. /**
  2988. Returns the number of pixels per horizontal scroll increment.
  2989. The default is 15.
  2990. @see GetScrollLineY(), SetScrollLineX(), SetScrollLineY()
  2991. */
  2992. int GetScrollLineX() const;
  2993. /**
  2994. Returns the number of pixels per vertical scroll increment.
  2995. The default is 15.
  2996. @see GetScrollLineX(), SetScrollLineX(), SetScrollLineY()
  2997. */
  2998. int GetScrollLineY() const;
  2999. /**
  3000. Returns @true if a cell is either entirely or at least partially
  3001. visible in the grid window.
  3002. By default, the cell must be entirely visible for this function to
  3003. return @true but if @a wholeCellVisible is @false, the function returns
  3004. @true even if the cell is only partially visible.
  3005. */
  3006. bool IsVisible(int row, int col, bool wholeCellVisible = true) const;
  3007. /**
  3008. Returns @true if a cell is either entirely or at least partially
  3009. visible in the grid window.
  3010. By default, the cell must be entirely visible for this function to
  3011. return @true but if @a wholeCellVisible is @false, the function returns
  3012. @true even if the cell is only partially visible.
  3013. */
  3014. bool IsVisible(const wxGridCellCoords& coords,
  3015. bool wholeCellVisible = true) const;
  3016. /**
  3017. Brings the specified cell into the visible grid cell area with minimal
  3018. scrolling.
  3019. Does nothing if the cell is already visible.
  3020. */
  3021. void MakeCellVisible(int row, int col);
  3022. /**
  3023. Brings the specified cell into the visible grid cell area with minimal
  3024. scrolling.
  3025. Does nothing if the cell is already visible.
  3026. */
  3027. void MakeCellVisible(const wxGridCellCoords& coords);
  3028. /**
  3029. Sets the number of pixels per horizontal scroll increment.
  3030. The default is 15.
  3031. @see GetScrollLineX(), GetScrollLineY(), SetScrollLineY()
  3032. */
  3033. void SetScrollLineX(int x);
  3034. /**
  3035. Sets the number of pixels per vertical scroll increment.
  3036. The default is 15.
  3037. @see GetScrollLineX(), GetScrollLineY(), SetScrollLineX()
  3038. */
  3039. void SetScrollLineY(int y);
  3040. //@}
  3041. /**
  3042. @name Cell and Device Coordinate Translation
  3043. */
  3044. //@{
  3045. /**
  3046. Convert grid cell coordinates to grid window pixel coordinates.
  3047. This function returns the rectangle that encloses the block of cells
  3048. limited by @a topLeft and @a bottomRight cell in device coords and
  3049. clipped to the client size of the grid window.
  3050. @see CellToRect()
  3051. */
  3052. wxRect BlockToDeviceRect(const wxGridCellCoords& topLeft,
  3053. const wxGridCellCoords& bottomRight) const;
  3054. /**
  3055. Return the rectangle corresponding to the grid cell's size and position
  3056. in logical coordinates.
  3057. @see BlockToDeviceRect()
  3058. */
  3059. wxRect CellToRect(int row, int col) const;
  3060. /**
  3061. Return the rectangle corresponding to the grid cell's size and position
  3062. in logical coordinates.
  3063. @see BlockToDeviceRect()
  3064. */
  3065. wxRect CellToRect(const wxGridCellCoords& coords) const;
  3066. /**
  3067. Returns the column at the given pixel position.
  3068. @param x
  3069. The x position to evaluate.
  3070. @param clipToMinMax
  3071. If @true, rather than returning @c wxNOT_FOUND, it returns either
  3072. the first or last column depending on whether @a x is too far to
  3073. the left or right respectively.
  3074. @return
  3075. The column index or @c wxNOT_FOUND.
  3076. */
  3077. int XToCol(int x, bool clipToMinMax = false) const;
  3078. /**
  3079. Returns the column whose right hand edge is close to the given logical
  3080. @a x position.
  3081. If no column edge is near to this position @c wxNOT_FOUND is returned.
  3082. */
  3083. int XToEdgeOfCol(int x) const;
  3084. /**
  3085. Translates logical pixel coordinates to the grid cell coordinates.
  3086. Notice that this function expects logical coordinates on input so if
  3087. you use this function in a mouse event handler you need to translate
  3088. the mouse position, which is expressed in device coordinates, to
  3089. logical ones.
  3090. @see XToCol(), YToRow()
  3091. */
  3092. wxGridCellCoords XYToCell(int x, int y) const;
  3093. /**
  3094. Translates logical pixel coordinates to the grid cell coordinates.
  3095. Notice that this function expects logical coordinates on input so if
  3096. you use this function in a mouse event handler you need to translate
  3097. the mouse position, which is expressed in device coordinates, to
  3098. logical ones.
  3099. @see XToCol(), YToRow()
  3100. */
  3101. wxGridCellCoords XYToCell(const wxPoint& pos) const;
  3102. // XYToCell(int, int, wxGridCellCoords&) overload is intentionally
  3103. // undocumented, using it is ugly and non-const reference parameters are
  3104. // not used in wxWidgets API
  3105. /**
  3106. Returns the row whose bottom edge is close to the given logical @a y
  3107. position.
  3108. If no row edge is near to this position @c wxNOT_FOUND is returned.
  3109. */
  3110. int YToEdgeOfRow(int y) const;
  3111. /**
  3112. Returns the grid row that corresponds to the logical @a y coordinate.
  3113. Returns @c wxNOT_FOUND if there is no row at the @a y position.
  3114. */
  3115. int YToRow(int y, bool clipToMinMax = false) const;
  3116. //@}
  3117. /**
  3118. @name Miscellaneous Functions
  3119. */
  3120. //@{
  3121. /**
  3122. Appends one or more new columns to the right of the grid.
  3123. The @a updateLabels argument is not used at present. If you are using a
  3124. derived grid table class you will need to override
  3125. wxGridTableBase::AppendCols(). See InsertCols() for further
  3126. information.
  3127. @return @true on success or @false if appending columns failed.
  3128. */
  3129. bool AppendCols(int numCols = 1, bool updateLabels = true);
  3130. /**
  3131. Appends one or more new rows to the bottom of the grid.
  3132. The @a updateLabels argument is not used at present. If you are using a
  3133. derived grid table class you will need to override
  3134. wxGridTableBase::AppendRows(). See InsertRows() for further
  3135. information.
  3136. @return @true on success or @false if appending rows failed.
  3137. */
  3138. bool AppendRows(int numRows = 1, bool updateLabels = true);
  3139. /**
  3140. Return @true if the horizontal grid lines stop at the last column
  3141. boundary or @false if they continue to the end of the window.
  3142. The default is to clip grid lines.
  3143. @see ClipHorzGridLines(), AreVertGridLinesClipped()
  3144. */
  3145. bool AreHorzGridLinesClipped() const;
  3146. /**
  3147. Return @true if the vertical grid lines stop at the last row
  3148. boundary or @false if they continue to the end of the window.
  3149. The default is to clip grid lines.
  3150. @see ClipVertGridLines(), AreHorzGridLinesClipped()
  3151. */
  3152. bool AreVertGridLinesClipped() const;
  3153. /**
  3154. Increments the grid's batch count.
  3155. When the count is greater than zero repainting of the grid is
  3156. suppressed. Each call to BeginBatch must be matched by a later call to
  3157. EndBatch(). Code that does a lot of grid modification can be enclosed
  3158. between BeginBatch() and EndBatch() calls to avoid screen flicker. The
  3159. final EndBatch() call will cause the grid to be repainted.
  3160. Notice that you should use wxGridUpdateLocker which ensures that there
  3161. is always a matching EndBatch() call for this BeginBatch() if possible
  3162. instead of calling this method directly.
  3163. */
  3164. void BeginBatch();
  3165. /**
  3166. Clears all data in the underlying grid table and repaints the grid.
  3167. The table is not deleted by this function. If you are using a derived
  3168. table class then you need to override wxGridTableBase::Clear() for this
  3169. function to have any effect.
  3170. */
  3171. void ClearGrid();
  3172. /**
  3173. Change whether the horizontal grid lines are clipped by the end of the
  3174. last column.
  3175. By default the grid lines are not drawn beyond the end of the last
  3176. column but after calling this function with @a clip set to @false they
  3177. will be drawn across the entire grid window.
  3178. @see AreHorzGridLinesClipped(), ClipVertGridLines()
  3179. */
  3180. void ClipHorzGridLines(bool clip);
  3181. /**
  3182. Change whether the vertical grid lines are clipped by the end of the
  3183. last row.
  3184. By default the grid lines are not drawn beyond the end of the last
  3185. row but after calling this function with @a clip set to @false they
  3186. will be drawn across the entire grid window.
  3187. @see AreVertGridLinesClipped(), ClipHorzGridLines()
  3188. */
  3189. void ClipVertGridLines(bool clip);
  3190. /**
  3191. Deletes one or more columns from a grid starting at the specified
  3192. position.
  3193. The @a updateLabels argument is not used at present. If you are using a
  3194. derived grid table class you will need to override
  3195. wxGridTableBase::DeleteCols(). See InsertCols() for further
  3196. information.
  3197. @return @true on success or @false if deleting columns failed.
  3198. */
  3199. bool DeleteCols(int pos = 0, int numCols = 1, bool updateLabels = true);
  3200. /**
  3201. Deletes one or more rows from a grid starting at the specified
  3202. position.
  3203. The @a updateLabels argument is not used at present. If you are using a
  3204. derived grid table class you will need to override
  3205. wxGridTableBase::DeleteRows(). See InsertRows() for further
  3206. information.
  3207. @return @true on success or @false if appending rows failed.
  3208. */
  3209. bool DeleteRows(int pos = 0, int numRows = 1, bool updateLabels = true);
  3210. /**
  3211. Decrements the grid's batch count.
  3212. When the count is greater than zero repainting of the grid is
  3213. suppressed. Each previous call to BeginBatch() must be matched by a
  3214. later call to EndBatch(). Code that does a lot of grid modification can
  3215. be enclosed between BeginBatch() and EndBatch() calls to avoid screen
  3216. flicker. The final EndBatch() will cause the grid to be repainted.
  3217. @see wxGridUpdateLocker
  3218. */
  3219. void EndBatch();
  3220. /**
  3221. Overridden wxWindow method.
  3222. */
  3223. virtual void Fit();
  3224. /**
  3225. Causes immediate repainting of the grid.
  3226. Use this instead of the usual wxWindow::Refresh().
  3227. */
  3228. void ForceRefresh();
  3229. /**
  3230. Returns the number of times that BeginBatch() has been called without
  3231. (yet) matching calls to EndBatch(). While the grid's batch count is
  3232. greater than zero the display will not be updated.
  3233. */
  3234. int GetBatchCount();
  3235. /**
  3236. Returns the total number of grid columns.
  3237. This is the same as the number of columns in the underlying grid table.
  3238. */
  3239. int GetNumberCols() const;
  3240. /**
  3241. Returns the total number of grid rows.
  3242. This is the same as the number of rows in the underlying grid table.
  3243. */
  3244. int GetNumberRows() const;
  3245. /**
  3246. Returns the attribute for the given cell creating one if necessary.
  3247. If the cell already has an attribute, it is returned. Otherwise a new
  3248. attribute is created, associated with the cell and returned. In any
  3249. case the caller must call DecRef() on the returned pointer.
  3250. This function may only be called if CanHaveAttributes() returns @true.
  3251. */
  3252. wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const;
  3253. /**
  3254. Returns a base pointer to the current table object.
  3255. The returned pointer is still owned by the grid.
  3256. */
  3257. wxGridTableBase *GetTable() const;
  3258. /**
  3259. Inserts one or more new columns into a grid with the first new column
  3260. at the specified position.
  3261. Notice that inserting the columns in the grid requires grid table
  3262. cooperation: when this method is called, grid object begins by
  3263. requesting the underlying grid table to insert new columns. If this is
  3264. successful the table notifies the grid and the grid updates the
  3265. display. For a default grid (one where you have called CreateGrid())
  3266. this process is automatic. If you are using a custom grid table
  3267. (specified with SetTable()) then you must override
  3268. wxGridTableBase::InsertCols() in your derived table class.
  3269. @param pos
  3270. The position which the first newly inserted column will have.
  3271. @param numCols
  3272. The number of columns to insert.
  3273. @param updateLabels
  3274. Currently not used.
  3275. @return
  3276. @true if the columns were successfully inserted, @false if an error
  3277. occurred (most likely the table couldn't be updated).
  3278. */
  3279. bool InsertCols(int pos = 0, int numCols = 1, bool updateLabels = true);
  3280. /**
  3281. Inserts one or more new rows into a grid with the first new row at the
  3282. specified position.
  3283. Notice that you must implement wxGridTableBase::InsertRows() if you use
  3284. a grid with a custom table, please see InsertCols() for more
  3285. information.
  3286. @param pos
  3287. The position which the first newly inserted row will have.
  3288. @param numRows
  3289. The number of rows to insert.
  3290. @param updateLabels
  3291. Currently not used.
  3292. @return
  3293. @true if the rows were successfully inserted, @false if an error
  3294. occurred (most likely the table couldn't be updated).
  3295. */
  3296. bool InsertRows(int pos = 0, int numRows = 1, bool updateLabels = true);
  3297. /**
  3298. Invalidates the cached attribute for the given cell.
  3299. For efficiency reasons, wxGrid may cache the recently used attributes
  3300. (currently it caches only the single most recently used one, in fact)
  3301. which can result in the cell appearance not being refreshed even when
  3302. the attribute returned by your custom wxGridCellAttrProvider-derived
  3303. class has changed. To force the grid to refresh the cell attribute,
  3304. this function may be used. Notice that calling it will not result in
  3305. actually redrawing the cell, you still need to call
  3306. wxWindow::RefreshRect() to invalidate the area occupied by the cell in
  3307. the window to do this. Also note that you don't need to call this
  3308. function if you store the attributes in wxGrid itself, i.e. use its
  3309. SetAttr() and similar methods, it is only useful when using a separate
  3310. custom attributes provider.
  3311. @param row
  3312. The row of the cell whose attribute needs to be queried again.
  3313. @param col
  3314. The column of the cell whose attribute needs to be queried again.
  3315. @since 2.9.2
  3316. */
  3317. void RefreshAttr(int row, int col);
  3318. /**
  3319. Draws part or all of a wxGrid on a wxDC for printing or display.
  3320. Pagination can be accomplished by using sequential Render() calls
  3321. with appropriate values in wxGridCellCoords topLeft and bottomRight.
  3322. @param dc
  3323. The wxDC to be drawn on.
  3324. @param pos
  3325. The position on the wxDC where rendering should begin. If not
  3326. specified drawing will begin at the wxDC MaxX() and MaxY().
  3327. @param size
  3328. The size of the area on the wxDC that the rendered wxGrid should
  3329. occupy. If not specified the drawing will be scaled to fit the
  3330. available dc width or height. The wxGrid's aspect ratio is
  3331. maintained whether or not size is specified.
  3332. @param topLeft
  3333. The top left cell of the block to be drawn. Defaults to ( 0, 0 ).
  3334. @param bottomRight
  3335. The bottom right cell of the block to be drawn. Defaults to row and
  3336. column counts.
  3337. @param style
  3338. A combination of values from wxGridRenderStyle.
  3339. @since 2.9.4
  3340. */
  3341. void Render( wxDC& dc,
  3342. const wxPoint& pos = wxDefaultPosition,
  3343. const wxSize& size = wxDefaultSize,
  3344. const wxGridCellCoords& topLeft = wxGridCellCoords( -1, -1 ),
  3345. const wxGridCellCoords& bottomRight = wxGridCellCoords( -1, -1 ),
  3346. int style = wxGRID_DRAW_DEFAULT );
  3347. /**
  3348. Sets the cell attributes for all cells in the specified column.
  3349. For more information about controlling grid cell attributes see the
  3350. wxGridCellAttr cell attribute class and the @ref overview_grid.
  3351. */
  3352. void SetColAttr(int col, wxGridCellAttr* attr);
  3353. /**
  3354. Sets the extra margins used around the grid area.
  3355. A grid may occupy more space than needed for its data display and
  3356. this function allows to set how big this extra space is
  3357. */
  3358. void SetMargins(int extraWidth, int extraHeight);
  3359. /**
  3360. Sets the cell attributes for all cells in the specified row.
  3361. The grid takes ownership of the attribute pointer.
  3362. See the wxGridCellAttr class for more information about controlling
  3363. cell attributes.
  3364. */
  3365. void SetRowAttr(int row, wxGridCellAttr* attr);
  3366. wxArrayInt CalcRowLabelsExposed( const wxRegion& reg );
  3367. wxArrayInt CalcColLabelsExposed( const wxRegion& reg );
  3368. wxGridCellCoordsArray CalcCellsExposed( const wxRegion& reg );
  3369. //@}
  3370. /**
  3371. @name Sorting support.
  3372. wxGrid doesn't provide any support for sorting the data but it does
  3373. generate events allowing the user code to sort it and supports
  3374. displaying the sort indicator in the column used for sorting.
  3375. To use wxGrid sorting support you need to handle wxEVT_GRID_COL_SORT
  3376. event (and not veto it) and resort the data displayed in the grid. The
  3377. grid will automatically update the sorting indicator on the column
  3378. which was clicked.
  3379. You can also call the functions in this section directly to update the
  3380. sorting indicator. Once again, they don't do anything with the grid
  3381. data, it remains your responsibility to actually sort it appropriately.
  3382. */
  3383. //@{
  3384. /**
  3385. Return the column in which the sorting indicator is currently
  3386. displayed.
  3387. Returns @c wxNOT_FOUND if sorting indicator is not currently displayed
  3388. at all.
  3389. @see SetSortingColumn()
  3390. */
  3391. int GetSortingColumn() const;
  3392. /**
  3393. Return @true if this column is currently used for sorting.
  3394. @see GetSortingColumn()
  3395. */
  3396. bool IsSortingBy(int col) const;
  3397. /**
  3398. Return @true if the current sorting order is ascending or @false if it
  3399. is descending.
  3400. It only makes sense to call this function if GetSortingColumn() returns
  3401. a valid column index and not @c wxNOT_FOUND.
  3402. @see SetSortingColumn()
  3403. */
  3404. bool IsSortOrderAscending() const;
  3405. /**
  3406. Set the column to display the sorting indicator in and its direction.
  3407. @param col
  3408. The column to display the sorting indicator in or @c wxNOT_FOUND to
  3409. remove any currently displayed sorting indicator.
  3410. @param ascending
  3411. If @true, display the ascending sort indicator, otherwise display
  3412. the descending sort indicator.
  3413. @see GetSortingColumn(), IsSortOrderAscending()
  3414. */
  3415. void SetSortingColumn(int col, bool ascending = true);
  3416. /**
  3417. Remove any currently shown sorting indicator.
  3418. This is equivalent to calling SetSortingColumn() with @c wxNOT_FOUND
  3419. first argument.
  3420. */
  3421. void UnsetSortingColumn();
  3422. //@}
  3423. /**
  3424. @name Accessors for component windows.
  3425. Return the various child windows of wxGrid.
  3426. wxGrid is an empty parent window for 4 children representing the column
  3427. labels window (top), the row labels window (left), the corner window
  3428. (top left) and the main grid window. It may be necessary to use these
  3429. individual windows and not the wxGrid window itself if you need to
  3430. handle events for them (this can be done using wxEvtHandler::Connect()
  3431. or wxWindow::PushEventHandler()) or do something else requiring the use
  3432. of the correct window pointer. Notice that you should not, however,
  3433. change these windows (e.g. reposition them or draw over them) because
  3434. they are managed by wxGrid itself.
  3435. */
  3436. //@{
  3437. /**
  3438. Return the main grid window containing the grid cells.
  3439. This window is always shown.
  3440. */
  3441. wxWindow *GetGridWindow() const;
  3442. /**
  3443. Return the row labels window.
  3444. This window is not shown if the row labels were hidden using
  3445. HideRowLabels().
  3446. */
  3447. wxWindow *GetGridRowLabelWindow() const;
  3448. /**
  3449. Return the column labels window.
  3450. This window is not shown if the columns labels were hidden using
  3451. HideColLabels().
  3452. Depending on whether UseNativeColHeader() was called or not this can be
  3453. either a wxHeaderCtrl or a plain wxWindow. This function returns a valid
  3454. window pointer in either case but in the former case you can also use
  3455. GetGridColHeader() to access it if you need wxHeaderCtrl-specific
  3456. functionality.
  3457. */
  3458. wxWindow *GetGridColLabelWindow() const;
  3459. /**
  3460. Return the window in the top left grid corner.
  3461. This window is shown only of both columns and row labels are shown and
  3462. normally doesn't contain anything. Clicking on it is handled by wxGrid
  3463. however and can be used to select the entire grid.
  3464. */
  3465. wxWindow *GetGridCornerLabelWindow() const;
  3466. /**
  3467. Return the header control used for column labels display.
  3468. This function can only be called if UseNativeColHeader() had been
  3469. called.
  3470. */
  3471. wxHeaderCtrl *GetGridColHeader() const;
  3472. //@}
  3473. virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
  3474. virtual void DrawRowLabels( wxDC& dc, const wxArrayInt& rows );
  3475. virtual void DrawRowLabel( wxDC& dc, int row );
  3476. virtual void DrawColLabels( wxDC& dc, const wxArrayInt& cols );
  3477. virtual void DrawColLabel( wxDC& dc, int col );
  3478. virtual void DrawCornerLabel(wxDC& dc);
  3479. void DrawTextRectangle( wxDC& dc, const wxString& text, const wxRect& rect,
  3480. int horizontalAlignment = wxALIGN_LEFT,
  3481. int verticalAlignment = wxALIGN_TOP,
  3482. int textOrientation = wxHORIZONTAL ) const;
  3483. void DrawTextRectangle( wxDC& dc, const wxArrayString& lines, const wxRect& rect,
  3484. int horizontalAlignment = wxALIGN_LEFT,
  3485. int verticalAlignment = wxALIGN_TOP,
  3486. int textOrientation = wxHORIZONTAL ) const;
  3487. wxColour GetCellHighlightColour() const;
  3488. int GetCellHighlightPenWidth() const;
  3489. int GetCellHighlightROPenWidth() const;
  3490. void SetCellHighlightColour( const wxColour& );
  3491. void SetCellHighlightPenWidth(int width);
  3492. void SetCellHighlightROPenWidth(int width);
  3493. protected:
  3494. /**
  3495. Returns @true if this grid has support for cell attributes.
  3496. The grid supports attributes if it has the associated table which, in
  3497. turn, has attributes support, i.e. wxGridTableBase::CanHaveAttributes()
  3498. returns @true.
  3499. */
  3500. bool CanHaveAttributes() const;
  3501. /**
  3502. Get the minimal width of the given column/row.
  3503. The value returned by this function may be different than that returned
  3504. by GetColMinimalAcceptableWidth() if SetColMinimalWidth() had been
  3505. called for this column.
  3506. */
  3507. int GetColMinimalWidth(int col) const;
  3508. /**
  3509. Returns the coordinate of the right border specified column.
  3510. */
  3511. int GetColRight(int col) const;
  3512. /**
  3513. Returns the coordinate of the left border specified column.
  3514. */
  3515. int GetColLeft(int col) const;
  3516. /**
  3517. Returns the minimal size for the given column.
  3518. The value returned by this function may be different than that returned
  3519. by GetRowMinimalAcceptableHeight() if SetRowMinimalHeight() had been
  3520. called for this row.
  3521. */
  3522. int GetRowMinimalHeight(int col) const;
  3523. };
  3524. /**
  3525. @class wxGridUpdateLocker
  3526. This small class can be used to prevent wxGrid from redrawing during its
  3527. lifetime by calling wxGrid::BeginBatch() in its constructor and
  3528. wxGrid::EndBatch() in its destructor. It is typically used in a function
  3529. performing several operations with a grid which would otherwise result in
  3530. flicker. For example:
  3531. @code
  3532. void MyFrame::Foo()
  3533. {
  3534. m_grid = new wxGrid(this, ...);
  3535. wxGridUpdateLocker noUpdates(m_grid);
  3536. m_grid-AppendColumn();
  3537. // ... many other operations with m_grid ...
  3538. m_grid-AppendRow();
  3539. // destructor called, grid refreshed
  3540. }
  3541. @endcode
  3542. Using this class is easier and safer than calling wxGrid::BeginBatch() and
  3543. wxGrid::EndBatch() because you don't risk missing the call the latter (due
  3544. to an exception for example).
  3545. @library{wxadv}
  3546. @category{grid}
  3547. */
  3548. class wxGridUpdateLocker
  3549. {
  3550. public:
  3551. /**
  3552. Creates an object preventing the updates of the specified @a grid. The
  3553. parameter could be @NULL in which case nothing is done. If @a grid is
  3554. non-@NULL then the grid must exist for longer than this
  3555. wxGridUpdateLocker object itself.
  3556. The default constructor could be followed by a call to Create() to set
  3557. the grid object later.
  3558. */
  3559. wxGridUpdateLocker(wxGrid* grid = NULL);
  3560. /**
  3561. Destructor reenables updates for the grid this object is associated
  3562. with.
  3563. */
  3564. ~wxGridUpdateLocker();
  3565. /**
  3566. This method can be called if the object had been constructed using the
  3567. default constructor. It must not be called more than once.
  3568. */
  3569. void Create(wxGrid* grid);
  3570. };
  3571. /**
  3572. @class wxGridEvent
  3573. This event class contains information about various grid events.
  3574. Notice that all grid event table macros are available in two versions:
  3575. @c EVT_GRID_XXX and @c EVT_GRID_CMD_XXX. The only difference between the
  3576. two is that the former doesn't allow to specify the grid window identifier
  3577. and so takes a single parameter, the event handler, but is not suitable if
  3578. there is more than one grid control in the window where the event table is
  3579. used (as it would catch the events from all the grids). The version with @c
  3580. CMD takes the id as first argument and the event handler as the second one
  3581. and so can be used with multiple grids as well. Otherwise there are no
  3582. difference between the two and only the versions without the id are
  3583. documented below for brevity.
  3584. @beginEventTable{wxGridEvent}
  3585. @event{EVT_GRID_CELL_CHANGING(func)}
  3586. The user is about to change the data in a cell. The new cell value as
  3587. string is available from GetString() event object method. This event
  3588. can be vetoed if the change is not allowed.
  3589. Processes a @c wxEVT_GRID_CELL_CHANGING event type.
  3590. @event{EVT_GRID_CELL_CHANGED(func)}
  3591. The user changed the data in a cell. The old cell value as string is
  3592. available from GetString() event object method. Notice that vetoing
  3593. this event still works for backwards compatibility reasons but any new
  3594. code should only veto EVT_GRID_CELL_CHANGING event and not this one.
  3595. Processes a @c wxEVT_GRID_CELL_CHANGED event type.
  3596. @event{EVT_GRID_CELL_LEFT_CLICK(func)}
  3597. The user clicked a cell with the left mouse button. Processes a
  3598. @c wxEVT_GRID_CELL_LEFT_CLICK event type.
  3599. @event{EVT_GRID_CELL_LEFT_DCLICK(func)}
  3600. The user double-clicked a cell with the left mouse button. Processes a
  3601. @c wxEVT_GRID_CELL_LEFT_DCLICK event type.
  3602. @event{EVT_GRID_CELL_RIGHT_CLICK(func)}
  3603. The user clicked a cell with the right mouse button. Processes a
  3604. @c wxEVT_GRID_CELL_RIGHT_CLICK event type.
  3605. @event{EVT_GRID_CELL_RIGHT_DCLICK(func)}
  3606. The user double-clicked a cell with the right mouse button. Processes a
  3607. @c wxEVT_GRID_CELL_RIGHT_DCLICK event type.
  3608. @event{EVT_GRID_EDITOR_HIDDEN(func)}
  3609. The editor for a cell was hidden. Processes a
  3610. @c wxEVT_GRID_EDITOR_HIDDEN event type.
  3611. @event{EVT_GRID_EDITOR_SHOWN(func)}
  3612. The editor for a cell was shown. Processes a
  3613. @c wxEVT_GRID_EDITOR_SHOWN event type.
  3614. @event{EVT_GRID_LABEL_LEFT_CLICK(func)}
  3615. The user clicked a label with the left mouse button. Processes a
  3616. @c wxEVT_GRID_LABEL_LEFT_CLICK event type.
  3617. @event{EVT_GRID_LABEL_LEFT_DCLICK(func)}
  3618. The user double-clicked a label with the left mouse button. Processes a
  3619. @c wxEVT_GRID_LABEL_LEFT_DCLICK event type.
  3620. @event{EVT_GRID_LABEL_RIGHT_CLICK(func)}
  3621. The user clicked a label with the right mouse button. Processes a
  3622. @c wxEVT_GRID_LABEL_RIGHT_CLICK event type.
  3623. @event{EVT_GRID_LABEL_RIGHT_DCLICK(func)}
  3624. The user double-clicked a label with the right mouse button. Processes
  3625. a @c wxEVT_GRID_LABEL_RIGHT_DCLICK event type.
  3626. @event{EVT_GRID_SELECT_CELL(func)}
  3627. The given cell was made current, either by user or by the program via a
  3628. call to SetGridCursor() or GoToCell(). Processes a
  3629. @c wxEVT_GRID_SELECT_CELL event type.
  3630. @event{EVT_GRID_COL_MOVE(func)}
  3631. The user tries to change the order of the columns in the grid by
  3632. dragging the column specified by GetCol(). This event can be vetoed to
  3633. either prevent the user from reordering the column change completely
  3634. (but notice that if you don't want to allow it at all, you simply
  3635. shouldn't call wxGrid::EnableDragColMove() in the first place), vetoed
  3636. but handled in some way in the handler, e.g. by really moving the
  3637. column to the new position at the associated table level, or allowed to
  3638. proceed in which case wxGrid::SetColPos() is used to reorder the
  3639. columns display order without affecting the use of the column indices
  3640. otherwise.
  3641. This event macro corresponds to @c wxEVT_GRID_COL_MOVE event type.
  3642. @event{EVT_GRID_COL_SORT(func)}
  3643. This event is generated when a column is clicked by the user and its
  3644. name is explained by the fact that the custom reaction to a click on a
  3645. column is to sort the grid contents by this column. However the grid
  3646. itself has no special support for sorting and it's up to the handler of
  3647. this event to update the associated table. But if the event is handled
  3648. (and not vetoed) the grid supposes that the table was indeed resorted
  3649. and updates the column to indicate the new sort order and refreshes
  3650. itself.
  3651. This event macro corresponds to @c wxEVT_GRID_COL_SORT event type.
  3652. @event{EVT_GRID_TABBING(func)}
  3653. This event is generated when the user presses TAB or Shift-TAB in the
  3654. grid. It can be used to customize the simple default TAB handling
  3655. logic, e.g. to go to the next non-empty cell instead of just the next
  3656. cell. See also wxGrid::SetTabBehaviour(). This event is new since
  3657. wxWidgets 2.9.5.
  3658. @endEventTable
  3659. @library{wxadv}
  3660. @category{grid,events}
  3661. */
  3662. class wxGridEvent : public wxNotifyEvent
  3663. {
  3664. public:
  3665. /**
  3666. Default constructor.
  3667. */
  3668. wxGridEvent();
  3669. /**
  3670. Constructor for initializing all event attributes.
  3671. */
  3672. wxGridEvent(int id, wxEventType type, wxObject* obj,
  3673. int row = -1, int col = -1, int x = -1, int y = -1,
  3674. bool sel = true, const wxKeyboardState& kbd = wxKeyboardState());
  3675. /**
  3676. Returns @true if the Alt key was down at the time of the event.
  3677. */
  3678. bool AltDown() const;
  3679. /**
  3680. Returns @true if the Control key was down at the time of the event.
  3681. */
  3682. bool ControlDown() const;
  3683. /**
  3684. Column at which the event occurred.
  3685. Notice that for a @c wxEVT_GRID_SELECT_CELL event this column is the
  3686. column of the newly selected cell while the previously selected cell
  3687. can be retrieved using wxGrid::GetGridCursorCol().
  3688. */
  3689. virtual int GetCol();
  3690. /**
  3691. Position in pixels at which the event occurred.
  3692. */
  3693. wxPoint GetPosition();
  3694. /**
  3695. Row at which the event occurred.
  3696. Notice that for a @c wxEVT_GRID_SELECT_CELL event this row is the row
  3697. of the newly selected cell while the previously selected cell can be
  3698. retrieved using wxGrid::GetGridCursorRow().
  3699. */
  3700. virtual int GetRow();
  3701. /**
  3702. Returns @true if the Meta key was down at the time of the event.
  3703. */
  3704. bool MetaDown() const;
  3705. /**
  3706. Returns @true if the user is selecting grid cells, or @false if
  3707. deselecting.
  3708. */
  3709. bool Selecting();
  3710. /**
  3711. Returns @true if the Shift key was down at the time of the event.
  3712. */
  3713. bool ShiftDown() const;
  3714. };
  3715. /**
  3716. @class wxGridSizeEvent
  3717. This event class contains information about a row/column resize event.
  3718. @beginEventTable{wxGridSizeEvent}
  3719. @event{EVT_GRID_CMD_COL_SIZE(id, func)}
  3720. The user resized a column, corresponds to @c wxEVT_GRID_COL_SIZE event
  3721. type.
  3722. @event{EVT_GRID_CMD_ROW_SIZE(id, func)}
  3723. The user resized a row, corresponds to @c wxEVT_GRID_ROW_SIZE event
  3724. type.
  3725. @event{EVT_GRID_COL_SIZE(func)}
  3726. Same as EVT_GRID_CMD_COL_SIZE() but uses `wxID_ANY` id.
  3727. @event{EVT_GRID_COL_AUTO_SIZE(func)}
  3728. This event is sent when a column must be resized to its best size, e.g.
  3729. when the user double clicks the column divider. The default
  3730. implementation simply resizes the column to fit the column label (but
  3731. not its contents as this could be too slow for big grids). This macro
  3732. corresponds to @c wxEVT_GRID_COL_AUTO_SIZE event type and is new since
  3733. wxWidgets 2.9.5.
  3734. @event{EVT_GRID_ROW_SIZE(func)}
  3735. Same as EVT_GRID_CMD_ROW_SIZE() but uses `wxID_ANY` id.
  3736. @endEventTable
  3737. @library{wxadv}
  3738. @category{grid,events}
  3739. */
  3740. class wxGridSizeEvent : public wxNotifyEvent
  3741. {
  3742. public:
  3743. /**
  3744. Default constructor.
  3745. */
  3746. wxGridSizeEvent();
  3747. /**
  3748. Constructor for initializing all event attributes.
  3749. */
  3750. wxGridSizeEvent(int id, wxEventType type, wxObject* obj,
  3751. int rowOrCol = -1, int x = -1, int y = -1,
  3752. const wxKeyboardState& kbd = wxKeyboardState());
  3753. /**
  3754. Returns @true if the Alt key was down at the time of the event.
  3755. */
  3756. bool AltDown() const;
  3757. /**
  3758. Returns @true if the Control key was down at the time of the event.
  3759. */
  3760. bool ControlDown() const;
  3761. /**
  3762. Position in pixels at which the event occurred.
  3763. */
  3764. wxPoint GetPosition();
  3765. /**
  3766. Row or column at that was resized.
  3767. */
  3768. int GetRowOrCol();
  3769. /**
  3770. Returns @true if the Meta key was down at the time of the event.
  3771. */
  3772. bool MetaDown() const;
  3773. /**
  3774. Returns @true if the Shift key was down at the time of the event.
  3775. */
  3776. bool ShiftDown() const;
  3777. };
  3778. /**
  3779. @class wxGridRangeSelectEvent
  3780. @beginEventTable{wxGridRangeSelectEvent}
  3781. @event{EVT_GRID_RANGE_SELECT(func)}
  3782. The user selected a group of contiguous cells. Processes a
  3783. @c wxEVT_GRID_RANGE_SELECT event type.
  3784. @event{EVT_GRID_CMD_RANGE_SELECT(id, func)}
  3785. The user selected a group of contiguous cells; variant taking a window
  3786. identifier. Processes a @c wxEVT_GRID_RANGE_SELECT event type.
  3787. @endEventTable
  3788. @library{wxadv}
  3789. @category{grid,events}
  3790. */
  3791. class wxGridRangeSelectEvent : public wxNotifyEvent
  3792. {
  3793. public:
  3794. /**
  3795. Default constructor.
  3796. */
  3797. wxGridRangeSelectEvent();
  3798. /**
  3799. Constructor for initializing all event attributes.
  3800. */
  3801. wxGridRangeSelectEvent(int id, wxEventType type,
  3802. wxObject* obj,
  3803. const wxGridCellCoords& topLeft,
  3804. const wxGridCellCoords& bottomRight,
  3805. bool sel = true, const wxKeyboardState& kbd = wxKeyboardState());
  3806. /**
  3807. Returns @true if the Alt key was down at the time of the event.
  3808. */
  3809. bool AltDown() const;
  3810. /**
  3811. Returns @true if the Control key was down at the time of the event.
  3812. */
  3813. bool ControlDown() const;
  3814. /**
  3815. Top left corner of the rectangular area that was (de)selected.
  3816. */
  3817. wxGridCellCoords GetBottomRightCoords();
  3818. /**
  3819. Bottom row of the rectangular area that was (de)selected.
  3820. */
  3821. int GetBottomRow();
  3822. /**
  3823. Left column of the rectangular area that was (de)selected.
  3824. */
  3825. int GetLeftCol();
  3826. /**
  3827. Right column of the rectangular area that was (de)selected.
  3828. */
  3829. int GetRightCol();
  3830. /**
  3831. Top left corner of the rectangular area that was (de)selected.
  3832. */
  3833. wxGridCellCoords GetTopLeftCoords();
  3834. /**
  3835. Top row of the rectangular area that was (de)selected.
  3836. */
  3837. int GetTopRow();
  3838. /**
  3839. Returns @true if the Meta key was down at the time of the event.
  3840. */
  3841. bool MetaDown() const;
  3842. /**
  3843. Returns @true if the area was selected, @false otherwise.
  3844. */
  3845. bool Selecting();
  3846. /**
  3847. Returns @true if the Shift key was down at the time of the event.
  3848. */
  3849. bool ShiftDown() const;
  3850. };
  3851. /**
  3852. @class wxGridEditorCreatedEvent
  3853. @beginEventTable{wxGridEditorCreatedEvent}
  3854. @event{EVT_GRID_EDITOR_CREATED(func)}
  3855. The editor for a cell was created. Processes a
  3856. @c wxEVT_GRID_EDITOR_CREATED event type.
  3857. @event{EVT_GRID_CMD_EDITOR_CREATED(id, func)}
  3858. The editor for a cell was created; variant taking a window identifier.
  3859. Processes a @c wxEVT_GRID_EDITOR_CREATED event type.
  3860. @endEventTable
  3861. @library{wxadv}
  3862. @category{grid,events}
  3863. */
  3864. class wxGridEditorCreatedEvent : public wxCommandEvent
  3865. {
  3866. public:
  3867. /**
  3868. Default constructor.
  3869. */
  3870. wxGridEditorCreatedEvent();
  3871. /**
  3872. Constructor for initializing all event attributes.
  3873. */
  3874. wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
  3875. int row, int col, wxControl* ctrl);
  3876. /**
  3877. Returns the column at which the event occurred.
  3878. */
  3879. int GetCol();
  3880. /**
  3881. Returns the edit control.
  3882. */
  3883. wxControl* GetControl();
  3884. /**
  3885. Returns the row at which the event occurred.
  3886. */
  3887. int GetRow();
  3888. /**
  3889. Sets the column at which the event occurred.
  3890. */
  3891. void SetCol(int col);
  3892. /**
  3893. Sets the edit control.
  3894. */
  3895. void SetControl(wxControl* ctrl);
  3896. /**
  3897. Sets the row at which the event occurred.
  3898. */
  3899. void SetRow(int row);
  3900. };
  3901. wxEventType wxEVT_GRID_CELL_LEFT_CLICK;
  3902. wxEventType wxEVT_GRID_CELL_RIGHT_CLICK;
  3903. wxEventType wxEVT_GRID_CELL_LEFT_DCLICK;
  3904. wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK;
  3905. wxEventType wxEVT_GRID_LABEL_LEFT_CLICK;
  3906. wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK;
  3907. wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK;
  3908. wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK;
  3909. wxEventType wxEVT_GRID_ROW_SIZE;
  3910. wxEventType wxEVT_GRID_COL_SIZE;
  3911. wxEventType wxEVT_GRID_COL_AUTO_SIZE;
  3912. wxEventType wxEVT_GRID_RANGE_SELECT;
  3913. wxEventType wxEVT_GRID_CELL_CHANGING;
  3914. wxEventType wxEVT_GRID_CELL_CHANGED;
  3915. wxEventType wxEVT_GRID_SELECT_CELL;
  3916. wxEventType wxEVT_GRID_EDITOR_SHOWN;
  3917. wxEventType wxEVT_GRID_EDITOR_HIDDEN;
  3918. wxEventType wxEVT_GRID_EDITOR_CREATED;
  3919. wxEventType wxEVT_GRID_CELL_BEGIN_DRAG;
  3920. wxEventType wxEVT_GRID_COL_MOVE;
  3921. wxEventType wxEVT_GRID_COL_SORT;
  3922. wxEventType wxEVT_GRID_TABBING;