grid.h 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/generic/grid.h
  3. // Purpose: wxGrid and related classes
  4. // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
  5. // Modified by: Santiago Palacios
  6. // Created: 1/08/1999
  7. // Copyright: (c) Michael Bedward
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_GENERIC_GRID_H_
  11. #define _WX_GENERIC_GRID_H_
  12. #include "wx/defs.h"
  13. #if wxUSE_GRID
  14. #include "wx/hashmap.h"
  15. #include "wx/scrolwin.h"
  16. // ----------------------------------------------------------------------------
  17. // constants
  18. // ----------------------------------------------------------------------------
  19. extern WXDLLIMPEXP_DATA_ADV(const char) wxGridNameStr[];
  20. // Default parameters for wxGrid
  21. //
  22. #define WXGRID_DEFAULT_NUMBER_ROWS 10
  23. #define WXGRID_DEFAULT_NUMBER_COLS 10
  24. #if defined(__WXMSW__) || defined(__WXGTK20__)
  25. #define WXGRID_DEFAULT_ROW_HEIGHT 25
  26. #else
  27. #define WXGRID_DEFAULT_ROW_HEIGHT 30
  28. #endif // __WXMSW__
  29. #define WXGRID_DEFAULT_COL_WIDTH 80
  30. #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32
  31. #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82
  32. #define WXGRID_LABEL_EDGE_ZONE 2
  33. #define WXGRID_MIN_ROW_HEIGHT 15
  34. #define WXGRID_MIN_COL_WIDTH 15
  35. #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16
  36. // type names for grid table values
  37. #define wxGRID_VALUE_STRING wxT("string")
  38. #define wxGRID_VALUE_BOOL wxT("bool")
  39. #define wxGRID_VALUE_NUMBER wxT("long")
  40. #define wxGRID_VALUE_FLOAT wxT("double")
  41. #define wxGRID_VALUE_CHOICE wxT("choice")
  42. #define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING
  43. #define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER
  44. // magic constant which tells (to some functions) to automatically calculate
  45. // the appropriate size
  46. #define wxGRID_AUTOSIZE (-1)
  47. // many wxGrid methods work either with columns or rows, this enum is used for
  48. // the parameter indicating which one should it be
  49. enum wxGridDirection
  50. {
  51. wxGRID_COLUMN,
  52. wxGRID_ROW
  53. };
  54. // Flags used with wxGrid::Render() to select parts of the grid to draw.
  55. enum wxGridRenderStyle
  56. {
  57. wxGRID_DRAW_ROWS_HEADER = 0x001,
  58. wxGRID_DRAW_COLS_HEADER = 0x002,
  59. wxGRID_DRAW_CELL_LINES = 0x004,
  60. wxGRID_DRAW_BOX_RECT = 0x008,
  61. wxGRID_DRAW_SELECTION = 0x010,
  62. wxGRID_DRAW_DEFAULT = wxGRID_DRAW_ROWS_HEADER |
  63. wxGRID_DRAW_COLS_HEADER |
  64. wxGRID_DRAW_CELL_LINES |
  65. wxGRID_DRAW_BOX_RECT
  66. };
  67. // ----------------------------------------------------------------------------
  68. // forward declarations
  69. // ----------------------------------------------------------------------------
  70. class WXDLLIMPEXP_FWD_ADV wxGrid;
  71. class WXDLLIMPEXP_FWD_ADV wxGridCellAttr;
  72. class WXDLLIMPEXP_FWD_ADV wxGridCellAttrProviderData;
  73. class WXDLLIMPEXP_FWD_ADV wxGridColLabelWindow;
  74. class WXDLLIMPEXP_FWD_ADV wxGridCornerLabelWindow;
  75. class WXDLLIMPEXP_FWD_ADV wxGridRowLabelWindow;
  76. class WXDLLIMPEXP_FWD_ADV wxGridWindow;
  77. class WXDLLIMPEXP_FWD_ADV wxGridTypeRegistry;
  78. class WXDLLIMPEXP_FWD_ADV wxGridSelection;
  79. class WXDLLIMPEXP_FWD_CORE wxHeaderCtrl;
  80. class WXDLLIMPEXP_FWD_CORE wxCheckBox;
  81. class WXDLLIMPEXP_FWD_CORE wxComboBox;
  82. class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
  83. #if wxUSE_SPINCTRL
  84. class WXDLLIMPEXP_FWD_CORE wxSpinCtrl;
  85. #endif
  86. class wxGridFixedIndicesSet;
  87. class wxGridOperations;
  88. class wxGridRowOperations;
  89. class wxGridColumnOperations;
  90. class wxGridDirectionOperations;
  91. // ----------------------------------------------------------------------------
  92. // macros
  93. // ----------------------------------------------------------------------------
  94. #define wxSafeIncRef(p) if ( p ) (p)->IncRef()
  95. #define wxSafeDecRef(p) if ( p ) (p)->DecRef()
  96. // ----------------------------------------------------------------------------
  97. // wxGridCellWorker: common base class for wxGridCellRenderer and
  98. // wxGridCellEditor
  99. //
  100. // NB: this is more an implementation convenience than a design issue, so this
  101. // class is not documented and is not public at all
  102. // ----------------------------------------------------------------------------
  103. class WXDLLIMPEXP_ADV wxGridCellWorker : public wxClientDataContainer, public wxRefCounter
  104. {
  105. public:
  106. wxGridCellWorker() { }
  107. // interpret renderer parameters: arbitrary string whose interpretation is
  108. // left to the derived classes
  109. virtual void SetParameters(const wxString& params);
  110. protected:
  111. // virtual dtor for any base class - private because only DecRef() can
  112. // delete us
  113. virtual ~wxGridCellWorker();
  114. private:
  115. // suppress the stupid gcc warning about the class having private dtor and
  116. // no friends
  117. friend class wxGridCellWorkerDummyFriend;
  118. };
  119. // ----------------------------------------------------------------------------
  120. // wxGridCellRenderer: this class is responsible for actually drawing the cell
  121. // in the grid. You may pass it to the wxGridCellAttr (below) to change the
  122. // format of one given cell or to wxGrid::SetDefaultRenderer() to change the
  123. // view of all cells. This is an ABC, you will normally use one of the
  124. // predefined derived classes or derive your own class from it.
  125. // ----------------------------------------------------------------------------
  126. class WXDLLIMPEXP_ADV wxGridCellRenderer : public wxGridCellWorker
  127. {
  128. public:
  129. // draw the given cell on the provided DC inside the given rectangle
  130. // using the style specified by the attribute and the default or selected
  131. // state corresponding to the isSelected value.
  132. //
  133. // this pure virtual function has a default implementation which will
  134. // prepare the DC using the given attribute: it will draw the rectangle
  135. // with the bg colour from attr and set the text colour and font
  136. virtual void Draw(wxGrid& grid,
  137. wxGridCellAttr& attr,
  138. wxDC& dc,
  139. const wxRect& rect,
  140. int row, int col,
  141. bool isSelected) = 0;
  142. // get the preferred size of the cell for its contents
  143. virtual wxSize GetBestSize(wxGrid& grid,
  144. wxGridCellAttr& attr,
  145. wxDC& dc,
  146. int row, int col) = 0;
  147. // create a new object which is the copy of this one
  148. virtual wxGridCellRenderer *Clone() const = 0;
  149. };
  150. // ----------------------------------------------------------------------------
  151. // wxGridCellEditor: This class is responsible for providing and manipulating
  152. // the in-place edit controls for the grid. Instances of wxGridCellEditor
  153. // (actually, instances of derived classes since it is an ABC) can be
  154. // associated with the cell attributes for individual cells, rows, columns, or
  155. // even for the entire grid.
  156. // ----------------------------------------------------------------------------
  157. class WXDLLIMPEXP_ADV wxGridCellEditor : public wxGridCellWorker
  158. {
  159. public:
  160. wxGridCellEditor();
  161. bool IsCreated() const { return m_control != NULL; }
  162. wxControl* GetControl() const { return m_control; }
  163. void SetControl(wxControl* control) { m_control = control; }
  164. wxGridCellAttr* GetCellAttr() const { return m_attr; }
  165. void SetCellAttr(wxGridCellAttr* attr) { m_attr = attr; }
  166. // Creates the actual edit control
  167. virtual void Create(wxWindow* parent,
  168. wxWindowID id,
  169. wxEvtHandler* evtHandler) = 0;
  170. // Size and position the edit control
  171. virtual void SetSize(const wxRect& rect);
  172. // Show or hide the edit control, use the specified attributes to set
  173. // colours/fonts for it
  174. virtual void Show(bool show, wxGridCellAttr *attr = NULL);
  175. // Draws the part of the cell not occupied by the control: the base class
  176. // version just fills it with background colour from the attribute
  177. virtual void PaintBackground(wxDC& dc,
  178. const wxRect& rectCell,
  179. const wxGridCellAttr& attr);
  180. // The methods called by wxGrid when a cell is edited: first BeginEdit() is
  181. // called, then EndEdit() is and if it returns true and if the change is
  182. // not vetoed by a user-defined event handler, finally ApplyEdit() is called
  183. // Fetch the value from the table and prepare the edit control
  184. // to begin editing. Set the focus to the edit control.
  185. virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
  186. // Returns false if nothing changed, otherwise returns true and return the
  187. // new value in its string form in the newval output parameter.
  188. //
  189. // This should also store the new value in its real type internally so that
  190. // it could be used by ApplyEdit() but it must not modify the grid as the
  191. // change could still be vetoed.
  192. virtual bool EndEdit(int row, int col, const wxGrid *grid,
  193. const wxString& oldval, wxString *newval) = 0;
  194. // Complete the editing of the current cell by storing the value saved by
  195. // the previous call to EndEdit() in the grid
  196. virtual void ApplyEdit(int row, int col, wxGrid* grid) = 0;
  197. // Reset the value in the control back to its starting value
  198. virtual void Reset() = 0;
  199. // return true to allow the given key to start editing: the base class
  200. // version only checks that the event has no modifiers. The derived
  201. // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in
  202. // their IsAcceptedKey() implementation, although, of course, it is not a
  203. // mandatory requirment.
  204. //
  205. // NB: if the key is F2 (special), editing will always start and this
  206. // method will not be called at all (but StartingKey() will)
  207. virtual bool IsAcceptedKey(wxKeyEvent& event);
  208. // If the editor is enabled by pressing keys on the grid, this will be
  209. // called to let the editor do something about that first key if desired
  210. virtual void StartingKey(wxKeyEvent& event);
  211. // if the editor is enabled by clicking on the cell, this method will be
  212. // called
  213. virtual void StartingClick();
  214. // Some types of controls on some platforms may need some help
  215. // with the Return key.
  216. virtual void HandleReturn(wxKeyEvent& event);
  217. // Final cleanup
  218. virtual void Destroy();
  219. // create a new object which is the copy of this one
  220. virtual wxGridCellEditor *Clone() const = 0;
  221. // added GetValue so we can get the value which is in the control
  222. virtual wxString GetValue() const = 0;
  223. protected:
  224. // the dtor is private because only DecRef() can delete us
  225. virtual ~wxGridCellEditor();
  226. // the control we show on screen
  227. wxControl* m_control;
  228. // a temporary pointer to the attribute being edited
  229. wxGridCellAttr* m_attr;
  230. // if we change the colours/font of the control from the default ones, we
  231. // must restore the default later and we save them here between calls to
  232. // Show(true) and Show(false)
  233. wxColour m_colFgOld,
  234. m_colBgOld;
  235. wxFont m_fontOld;
  236. // suppress the stupid gcc warning about the class having private dtor and
  237. // no friends
  238. friend class wxGridCellEditorDummyFriend;
  239. wxDECLARE_NO_COPY_CLASS(wxGridCellEditor);
  240. };
  241. // ----------------------------------------------------------------------------
  242. // wxGridHeaderRenderer and company: like wxGridCellRenderer but for headers
  243. // ----------------------------------------------------------------------------
  244. // Base class for corner window renderer: it is the simplest of all renderers
  245. // and only has a single function
  246. class WXDLLIMPEXP_ADV wxGridCornerHeaderRenderer
  247. {
  248. public:
  249. // Draw the border around the corner window.
  250. virtual void DrawBorder(const wxGrid& grid,
  251. wxDC& dc,
  252. wxRect& rect) const = 0;
  253. // make the dtor of a class with virtual functions virtual to avoid g++
  254. // warnings, even though this class is not supposed to be used
  255. // polymorphically
  256. virtual ~wxGridCornerHeaderRenderer() { }
  257. };
  258. // Base class for the row/column header cells renderers
  259. class WXDLLIMPEXP_ADV wxGridHeaderLabelsRenderer
  260. : public wxGridCornerHeaderRenderer
  261. {
  262. public:
  263. // Draw header cell label
  264. virtual void DrawLabel(const wxGrid& grid,
  265. wxDC& dc,
  266. const wxString& value,
  267. const wxRect& rect,
  268. int horizAlign,
  269. int vertAlign,
  270. int textOrientation) const;
  271. };
  272. // Currently the row/column/corner renders don't need any methods other than
  273. // those already in wxGridHeaderLabelsRenderer but still define separate classes
  274. // for them for future extensions and also for better type safety (i.e. to
  275. // avoid inadvertently using a column header renderer for the row headers)
  276. class WXDLLIMPEXP_ADV wxGridRowHeaderRenderer
  277. : public wxGridHeaderLabelsRenderer
  278. {
  279. };
  280. class WXDLLIMPEXP_ADV wxGridColumnHeaderRenderer
  281. : public wxGridHeaderLabelsRenderer
  282. {
  283. };
  284. // Also define the default renderers which are used by wxGridCellAttrProvider
  285. // by default
  286. class WXDLLIMPEXP_ADV wxGridRowHeaderRendererDefault
  287. : public wxGridRowHeaderRenderer
  288. {
  289. public:
  290. virtual void DrawBorder(const wxGrid& grid,
  291. wxDC& dc,
  292. wxRect& rect) const;
  293. };
  294. // Column header cells renderers
  295. class WXDLLIMPEXP_ADV wxGridColumnHeaderRendererDefault
  296. : public wxGridColumnHeaderRenderer
  297. {
  298. public:
  299. virtual void DrawBorder(const wxGrid& grid,
  300. wxDC& dc,
  301. wxRect& rect) const;
  302. };
  303. // Header corner renderer
  304. class WXDLLIMPEXP_ADV wxGridCornerHeaderRendererDefault
  305. : public wxGridCornerHeaderRenderer
  306. {
  307. public:
  308. virtual void DrawBorder(const wxGrid& grid,
  309. wxDC& dc,
  310. wxRect& rect) const;
  311. };
  312. // ----------------------------------------------------------------------------
  313. // wxGridCellAttr: this class can be used to alter the cells appearance in
  314. // the grid by changing their colour/font/... from default. An object of this
  315. // class may be returned by wxGridTable::GetAttr().
  316. // ----------------------------------------------------------------------------
  317. class WXDLLIMPEXP_ADV wxGridCellAttr : public wxClientDataContainer, public wxRefCounter
  318. {
  319. public:
  320. enum wxAttrKind
  321. {
  322. Any,
  323. Default,
  324. Cell,
  325. Row,
  326. Col,
  327. Merged
  328. };
  329. // ctors
  330. wxGridCellAttr(wxGridCellAttr *attrDefault = NULL)
  331. {
  332. Init(attrDefault);
  333. SetAlignment(wxALIGN_INVALID, wxALIGN_INVALID);
  334. }
  335. // VZ: considering the number of members wxGridCellAttr has now, this ctor
  336. // seems to be pretty useless... may be we should just remove it?
  337. wxGridCellAttr(const wxColour& colText,
  338. const wxColour& colBack,
  339. const wxFont& font,
  340. int hAlign,
  341. int vAlign)
  342. : m_colText(colText), m_colBack(colBack), m_font(font)
  343. {
  344. Init();
  345. SetAlignment(hAlign, vAlign);
  346. }
  347. // creates a new copy of this object
  348. wxGridCellAttr *Clone() const;
  349. void MergeWith(wxGridCellAttr *mergefrom);
  350. // setters
  351. void SetTextColour(const wxColour& colText) { m_colText = colText; }
  352. void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; }
  353. void SetFont(const wxFont& font) { m_font = font; }
  354. void SetAlignment(int hAlign, int vAlign)
  355. {
  356. m_hAlign = hAlign;
  357. m_vAlign = vAlign;
  358. }
  359. void SetSize(int num_rows, int num_cols);
  360. void SetOverflow(bool allow = true)
  361. { m_overflow = allow ? Overflow : SingleCell; }
  362. void SetReadOnly(bool isReadOnly = true)
  363. { m_isReadOnly = isReadOnly ? ReadOnly : ReadWrite; }
  364. // takes ownership of the pointer
  365. void SetRenderer(wxGridCellRenderer *renderer)
  366. { wxSafeDecRef(m_renderer); m_renderer = renderer; }
  367. void SetEditor(wxGridCellEditor* editor)
  368. { wxSafeDecRef(m_editor); m_editor = editor; }
  369. void SetKind(wxAttrKind kind) { m_attrkind = kind; }
  370. // accessors
  371. bool HasTextColour() const { return m_colText.IsOk(); }
  372. bool HasBackgroundColour() const { return m_colBack.IsOk(); }
  373. bool HasFont() const { return m_font.IsOk(); }
  374. bool HasAlignment() const
  375. {
  376. return m_hAlign != wxALIGN_INVALID || m_vAlign != wxALIGN_INVALID;
  377. }
  378. bool HasRenderer() const { return m_renderer != NULL; }
  379. bool HasEditor() const { return m_editor != NULL; }
  380. bool HasReadWriteMode() const { return m_isReadOnly != Unset; }
  381. bool HasOverflowMode() const { return m_overflow != UnsetOverflow; }
  382. bool HasSize() const { return m_sizeRows != 1 || m_sizeCols != 1; }
  383. const wxColour& GetTextColour() const;
  384. const wxColour& GetBackgroundColour() const;
  385. const wxFont& GetFont() const;
  386. void GetAlignment(int *hAlign, int *vAlign) const;
  387. // unlike GetAlignment() which always overwrites its output arguments with
  388. // the alignment values to use, falling back on default alignment if this
  389. // attribute doesn't have any, this function will preserve the values of
  390. // parameters on entry if the corresponding alignment is not set in this
  391. // attribute meaning that they can be initialized to default alignment (and
  392. // also that they must be initialized, unlike with GetAlignment())
  393. void GetNonDefaultAlignment(int *hAlign, int *vAlign) const;
  394. void GetSize(int *num_rows, int *num_cols) const;
  395. bool GetOverflow() const
  396. { return m_overflow != SingleCell; }
  397. wxGridCellRenderer *GetRenderer(const wxGrid* grid, int row, int col) const;
  398. wxGridCellEditor *GetEditor(const wxGrid* grid, int row, int col) const;
  399. bool IsReadOnly() const { return m_isReadOnly == wxGridCellAttr::ReadOnly; }
  400. wxAttrKind GetKind() { return m_attrkind; }
  401. void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; }
  402. protected:
  403. // the dtor is private because only DecRef() can delete us
  404. virtual ~wxGridCellAttr()
  405. {
  406. wxSafeDecRef(m_renderer);
  407. wxSafeDecRef(m_editor);
  408. }
  409. private:
  410. enum wxAttrReadMode
  411. {
  412. Unset = -1,
  413. ReadWrite,
  414. ReadOnly
  415. };
  416. enum wxAttrOverflowMode
  417. {
  418. UnsetOverflow = -1,
  419. Overflow,
  420. SingleCell
  421. };
  422. // the common part of all ctors
  423. void Init(wxGridCellAttr *attrDefault = NULL);
  424. wxColour m_colText,
  425. m_colBack;
  426. wxFont m_font;
  427. int m_hAlign,
  428. m_vAlign;
  429. int m_sizeRows,
  430. m_sizeCols;
  431. wxAttrOverflowMode m_overflow;
  432. wxGridCellRenderer* m_renderer;
  433. wxGridCellEditor* m_editor;
  434. wxGridCellAttr* m_defGridAttr;
  435. wxAttrReadMode m_isReadOnly;
  436. wxAttrKind m_attrkind;
  437. // use Clone() instead
  438. wxDECLARE_NO_COPY_CLASS(wxGridCellAttr);
  439. // suppress the stupid gcc warning about the class having private dtor and
  440. // no friends
  441. friend class wxGridCellAttrDummyFriend;
  442. };
  443. // ----------------------------------------------------------------------------
  444. // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
  445. // cell attributes.
  446. // ----------------------------------------------------------------------------
  447. // implementation note: we separate it from wxGridTableBase because we wish to
  448. // avoid deriving a new table class if possible, and sometimes it will be
  449. // enough to just derive another wxGridCellAttrProvider instead
  450. //
  451. // the default implementation is reasonably efficient for the generic case,
  452. // but you might still wish to implement your own for some specific situations
  453. // if you have performance problems with the stock one
  454. class WXDLLIMPEXP_ADV wxGridCellAttrProvider : public wxClientDataContainer
  455. {
  456. public:
  457. wxGridCellAttrProvider();
  458. virtual ~wxGridCellAttrProvider();
  459. // DecRef() must be called on the returned pointer
  460. virtual wxGridCellAttr *GetAttr(int row, int col,
  461. wxGridCellAttr::wxAttrKind kind ) const;
  462. // all these functions take ownership of the pointer, don't call DecRef()
  463. // on it
  464. virtual void SetAttr(wxGridCellAttr *attr, int row, int col);
  465. virtual void SetRowAttr(wxGridCellAttr *attr, int row);
  466. virtual void SetColAttr(wxGridCellAttr *attr, int col);
  467. // these functions must be called whenever some rows/cols are deleted
  468. // because the internal data must be updated then
  469. void UpdateAttrRows( size_t pos, int numRows );
  470. void UpdateAttrCols( size_t pos, int numCols );
  471. // get renderers for the given row/column header label and the corner
  472. // window: unlike cell renderers, these objects are not reference counted
  473. // and are never NULL so they are returned by reference
  474. virtual const wxGridColumnHeaderRenderer& GetColumnHeaderRenderer(int col);
  475. virtual const wxGridRowHeaderRenderer& GetRowHeaderRenderer(int row);
  476. virtual const wxGridCornerHeaderRenderer& GetCornerRenderer();
  477. private:
  478. void InitData();
  479. wxGridCellAttrProviderData *m_data;
  480. wxDECLARE_NO_COPY_CLASS(wxGridCellAttrProvider);
  481. };
  482. // ----------------------------------------------------------------------------
  483. // wxGridCellCoords: location of a cell in the grid
  484. // ----------------------------------------------------------------------------
  485. class WXDLLIMPEXP_ADV wxGridCellCoords
  486. {
  487. public:
  488. wxGridCellCoords() { m_row = m_col = -1; }
  489. wxGridCellCoords( int r, int c ) { m_row = r; m_col = c; }
  490. // default copy ctor is ok
  491. int GetRow() const { return m_row; }
  492. void SetRow( int n ) { m_row = n; }
  493. int GetCol() const { return m_col; }
  494. void SetCol( int n ) { m_col = n; }
  495. void Set( int row, int col ) { m_row = row; m_col = col; }
  496. wxGridCellCoords& operator=( const wxGridCellCoords& other )
  497. {
  498. if ( &other != this )
  499. {
  500. m_row=other.m_row;
  501. m_col=other.m_col;
  502. }
  503. return *this;
  504. }
  505. bool operator==( const wxGridCellCoords& other ) const
  506. {
  507. return (m_row == other.m_row && m_col == other.m_col);
  508. }
  509. bool operator!=( const wxGridCellCoords& other ) const
  510. {
  511. return (m_row != other.m_row || m_col != other.m_col);
  512. }
  513. bool operator!() const
  514. {
  515. return (m_row == -1 && m_col == -1 );
  516. }
  517. private:
  518. int m_row;
  519. int m_col;
  520. };
  521. // For comparisons...
  522. //
  523. extern WXDLLIMPEXP_ADV wxGridCellCoords wxGridNoCellCoords;
  524. extern WXDLLIMPEXP_ADV wxRect wxGridNoCellRect;
  525. // An array of cell coords...
  526. //
  527. WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellCoords, wxGridCellCoordsArray,
  528. class WXDLLIMPEXP_ADV);
  529. // ----------------------------------------------------------------------------
  530. // Grid table classes
  531. // ----------------------------------------------------------------------------
  532. // the abstract base class
  533. class WXDLLIMPEXP_ADV wxGridTableBase : public wxObject,
  534. public wxClientDataContainer
  535. {
  536. public:
  537. wxGridTableBase();
  538. virtual ~wxGridTableBase();
  539. // You must override these functions in a derived table class
  540. //
  541. // return the number of rows and columns in this table
  542. virtual int GetNumberRows() = 0;
  543. virtual int GetNumberCols() = 0;
  544. // the methods above are unfortunately non-const even though they should
  545. // have been const -- but changing it now is not possible any longer as it
  546. // would break the existing code overriding them, so instead we provide
  547. // these const synonyms which can be used from const-correct code
  548. int GetRowsCount() const
  549. { return const_cast<wxGridTableBase *>(this)->GetNumberRows(); }
  550. int GetColsCount() const
  551. { return const_cast<wxGridTableBase *>(this)->GetNumberCols(); }
  552. virtual bool IsEmptyCell( int row, int col )
  553. {
  554. return GetValue(row, col).empty();
  555. }
  556. bool IsEmpty(const wxGridCellCoords& coord)
  557. {
  558. return IsEmptyCell(coord.GetRow(), coord.GetCol());
  559. }
  560. virtual wxString GetValue( int row, int col ) = 0;
  561. virtual void SetValue( int row, int col, const wxString& value ) = 0;
  562. // Data type determination and value access
  563. virtual wxString GetTypeName( int row, int col );
  564. virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
  565. virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
  566. virtual long GetValueAsLong( int row, int col );
  567. virtual double GetValueAsDouble( int row, int col );
  568. virtual bool GetValueAsBool( int row, int col );
  569. virtual void SetValueAsLong( int row, int col, long value );
  570. virtual void SetValueAsDouble( int row, int col, double value );
  571. virtual void SetValueAsBool( int row, int col, bool value );
  572. // For user defined types
  573. virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
  574. virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
  575. // Overriding these is optional
  576. //
  577. virtual void SetView( wxGrid *grid ) { m_view = grid; }
  578. virtual wxGrid * GetView() const { return m_view; }
  579. virtual void Clear() {}
  580. virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
  581. virtual bool AppendRows( size_t numRows = 1 );
  582. virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
  583. virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
  584. virtual bool AppendCols( size_t numCols = 1 );
  585. virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
  586. virtual wxString GetRowLabelValue( int row );
  587. virtual wxString GetColLabelValue( int col );
  588. virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {}
  589. virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {}
  590. // Attribute handling
  591. //
  592. // give us the attr provider to use - we take ownership of the pointer
  593. void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
  594. // get the currently used attr provider (may be NULL)
  595. wxGridCellAttrProvider *GetAttrProvider() const { return m_attrProvider; }
  596. // Does this table allow attributes? Default implementation creates
  597. // a wxGridCellAttrProvider if necessary.
  598. virtual bool CanHaveAttributes();
  599. // by default forwarded to wxGridCellAttrProvider if any. May be
  600. // overridden to handle attributes directly in the table.
  601. virtual wxGridCellAttr *GetAttr( int row, int col,
  602. wxGridCellAttr::wxAttrKind kind );
  603. // these functions take ownership of the pointer
  604. virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
  605. virtual void SetRowAttr(wxGridCellAttr *attr, int row);
  606. virtual void SetColAttr(wxGridCellAttr *attr, int col);
  607. private:
  608. wxGrid * m_view;
  609. wxGridCellAttrProvider *m_attrProvider;
  610. DECLARE_ABSTRACT_CLASS(wxGridTableBase)
  611. wxDECLARE_NO_COPY_CLASS(wxGridTableBase);
  612. };
  613. // ----------------------------------------------------------------------------
  614. // wxGridTableMessage
  615. // ----------------------------------------------------------------------------
  616. // IDs for messages sent from grid table to view
  617. //
  618. enum wxGridTableRequest
  619. {
  620. wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
  621. wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
  622. wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
  623. wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
  624. wxGRIDTABLE_NOTIFY_ROWS_DELETED,
  625. wxGRIDTABLE_NOTIFY_COLS_INSERTED,
  626. wxGRIDTABLE_NOTIFY_COLS_APPENDED,
  627. wxGRIDTABLE_NOTIFY_COLS_DELETED
  628. };
  629. class WXDLLIMPEXP_ADV wxGridTableMessage
  630. {
  631. public:
  632. wxGridTableMessage();
  633. wxGridTableMessage( wxGridTableBase *table, int id,
  634. int comInt1 = -1,
  635. int comInt2 = -1 );
  636. void SetTableObject( wxGridTableBase *table ) { m_table = table; }
  637. wxGridTableBase * GetTableObject() const { return m_table; }
  638. void SetId( int id ) { m_id = id; }
  639. int GetId() { return m_id; }
  640. void SetCommandInt( int comInt1 ) { m_comInt1 = comInt1; }
  641. int GetCommandInt() { return m_comInt1; }
  642. void SetCommandInt2( int comInt2 ) { m_comInt2 = comInt2; }
  643. int GetCommandInt2() { return m_comInt2; }
  644. private:
  645. wxGridTableBase *m_table;
  646. int m_id;
  647. int m_comInt1;
  648. int m_comInt2;
  649. wxDECLARE_NO_COPY_CLASS(wxGridTableMessage);
  650. };
  651. // ------ wxGridStringArray
  652. // A 2-dimensional array of strings for data values
  653. //
  654. WX_DECLARE_OBJARRAY_WITH_DECL(wxArrayString, wxGridStringArray,
  655. class WXDLLIMPEXP_ADV);
  656. // ------ wxGridStringTable
  657. //
  658. // Simplest type of data table for a grid for small tables of strings
  659. // that are stored in memory
  660. //
  661. class WXDLLIMPEXP_ADV wxGridStringTable : public wxGridTableBase
  662. {
  663. public:
  664. wxGridStringTable();
  665. wxGridStringTable( int numRows, int numCols );
  666. // these are pure virtual in wxGridTableBase
  667. //
  668. virtual int GetNumberRows() { return static_cast<int>(m_data.size()); }
  669. virtual int GetNumberCols() { return m_numCols; }
  670. virtual wxString GetValue( int row, int col );
  671. virtual void SetValue( int row, int col, const wxString& s );
  672. // overridden functions from wxGridTableBase
  673. //
  674. void Clear();
  675. bool InsertRows( size_t pos = 0, size_t numRows = 1 );
  676. bool AppendRows( size_t numRows = 1 );
  677. bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
  678. bool InsertCols( size_t pos = 0, size_t numCols = 1 );
  679. bool AppendCols( size_t numCols = 1 );
  680. bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
  681. void SetRowLabelValue( int row, const wxString& );
  682. void SetColLabelValue( int col, const wxString& );
  683. wxString GetRowLabelValue( int row );
  684. wxString GetColLabelValue( int col );
  685. private:
  686. wxGridStringArray m_data;
  687. // notice that while we don't need to store the number of our rows as it's
  688. // always equal to the size of m_data array, we do need to store the number
  689. // of our columns as we can't retrieve it from m_data when the number of
  690. // rows is 0 (see #10818)
  691. int m_numCols;
  692. // These only get used if you set your own labels, otherwise the
  693. // GetRow/ColLabelValue functions return wxGridTableBase defaults
  694. //
  695. wxArrayString m_rowLabels;
  696. wxArrayString m_colLabels;
  697. DECLARE_DYNAMIC_CLASS_NO_COPY( wxGridStringTable )
  698. };
  699. // ============================================================================
  700. // Grid view classes
  701. // ============================================================================
  702. // ----------------------------------------------------------------------------
  703. // wxGridSizesInfo stores information about sizes of the rows or columns.
  704. //
  705. // It assumes that most of the columns or rows have default size and so stores
  706. // the default size separately and uses a hash to map column or row numbers to
  707. // their non default size for those which don't have the default size.
  708. // ----------------------------------------------------------------------------
  709. // hash map to store positions as the keys and sizes as the values
  710. WX_DECLARE_HASH_MAP_WITH_DECL( unsigned, int, wxIntegerHash, wxIntegerEqual,
  711. wxUnsignedToIntHashMap, class WXDLLIMPEXP_ADV );
  712. struct WXDLLIMPEXP_ADV wxGridSizesInfo
  713. {
  714. // default ctor, initialize m_sizeDefault and m_customSizes later
  715. wxGridSizesInfo() { }
  716. // ctor used by wxGrid::Get{Col,Row}Sizes()
  717. wxGridSizesInfo(int defSize, const wxArrayInt& allSizes);
  718. // default copy ctor, assignment operator and dtor are ok
  719. // Get the size of the element with the given index
  720. int GetSize(unsigned pos) const;
  721. // default size
  722. int m_sizeDefault;
  723. // position -> size map containing all elements with non-default size
  724. wxUnsignedToIntHashMap m_customSizes;
  725. };
  726. // ----------------------------------------------------------------------------
  727. // wxGrid
  728. // ----------------------------------------------------------------------------
  729. class WXDLLIMPEXP_ADV wxGrid : public wxScrolledWindow
  730. {
  731. public:
  732. // possible selection modes
  733. enum wxGridSelectionModes
  734. {
  735. wxGridSelectCells = 0, // allow selecting anything
  736. wxGridSelectRows = 1, // allow selecting only entire rows
  737. wxGridSelectColumns = 2, // allow selecting only entire columns
  738. wxGridSelectRowsOrColumns = wxGridSelectRows | wxGridSelectColumns
  739. };
  740. // Different behaviour of the TAB key when the end (or the beginning, for
  741. // Shift-TAB) of the current row is reached:
  742. enum TabBehaviour
  743. {
  744. Tab_Stop, // Do nothing, this is default.
  745. Tab_Wrap, // Move to the next (or previous) row.
  746. Tab_Leave // Move to the next (or previous) control.
  747. };
  748. // creation and destruction
  749. // ------------------------
  750. // ctor and Create() create the grid window, as with the other controls
  751. wxGrid() { Init(); }
  752. wxGrid(wxWindow *parent,
  753. wxWindowID id,
  754. const wxPoint& pos = wxDefaultPosition,
  755. const wxSize& size = wxDefaultSize,
  756. long style = wxWANTS_CHARS,
  757. const wxString& name = wxGridNameStr)
  758. {
  759. Init();
  760. Create(parent, id, pos, size, style, name);
  761. }
  762. bool Create(wxWindow *parent,
  763. wxWindowID id,
  764. const wxPoint& pos = wxDefaultPosition,
  765. const wxSize& size = wxDefaultSize,
  766. long style = wxWANTS_CHARS,
  767. const wxString& name = wxGridNameStr);
  768. virtual ~wxGrid();
  769. // however to initialize grid data either CreateGrid() or SetTable() must
  770. // be also called
  771. // this is basically equivalent to
  772. //
  773. // SetTable(new wxGridStringTable(numRows, numCols), true, selmode)
  774. //
  775. bool CreateGrid( int numRows, int numCols,
  776. wxGridSelectionModes selmode = wxGridSelectCells );
  777. bool SetTable( wxGridTableBase *table,
  778. bool takeOwnership = false,
  779. wxGridSelectionModes selmode = wxGridSelectCells );
  780. bool ProcessTableMessage(wxGridTableMessage&);
  781. wxGridTableBase *GetTable() const { return m_table; }
  782. void SetSelectionMode(wxGridSelectionModes selmode);
  783. wxGridSelectionModes GetSelectionMode() const;
  784. // ------ grid dimensions
  785. //
  786. int GetNumberRows() const { return m_numRows; }
  787. int GetNumberCols() const { return m_numCols; }
  788. // ------ display update functions
  789. //
  790. wxArrayInt CalcRowLabelsExposed( const wxRegion& reg ) const;
  791. wxArrayInt CalcColLabelsExposed( const wxRegion& reg ) const;
  792. wxGridCellCoordsArray CalcCellsExposed( const wxRegion& reg ) const;
  793. void ClearGrid();
  794. bool InsertRows(int pos = 0, int numRows = 1, bool updateLabels = true)
  795. {
  796. return DoModifyLines(&wxGridTableBase::InsertRows,
  797. pos, numRows, updateLabels);
  798. }
  799. bool InsertCols(int pos = 0, int numCols = 1, bool updateLabels = true)
  800. {
  801. return DoModifyLines(&wxGridTableBase::InsertCols,
  802. pos, numCols, updateLabels);
  803. }
  804. bool AppendRows(int numRows = 1, bool updateLabels = true)
  805. {
  806. return DoAppendLines(&wxGridTableBase::AppendRows, numRows, updateLabels);
  807. }
  808. bool AppendCols(int numCols = 1, bool updateLabels = true)
  809. {
  810. return DoAppendLines(&wxGridTableBase::AppendCols, numCols, updateLabels);
  811. }
  812. bool DeleteRows(int pos = 0, int numRows = 1, bool updateLabels = true)
  813. {
  814. return DoModifyLines(&wxGridTableBase::DeleteRows,
  815. pos, numRows, updateLabels);
  816. }
  817. bool DeleteCols(int pos = 0, int numCols = 1, bool updateLabels = true)
  818. {
  819. return DoModifyLines(&wxGridTableBase::DeleteCols,
  820. pos, numCols, updateLabels);
  821. }
  822. void DrawGridCellArea( wxDC& dc , const wxGridCellCoordsArray& cells );
  823. void DrawGridSpace( wxDC& dc );
  824. void DrawCellBorder( wxDC& dc, const wxGridCellCoords& );
  825. void DrawAllGridLines( wxDC& dc, const wxRegion & reg );
  826. void DrawCell( wxDC& dc, const wxGridCellCoords& );
  827. void DrawHighlight(wxDC& dc, const wxGridCellCoordsArray& cells);
  828. // this function is called when the current cell highlight must be redrawn
  829. // and may be overridden by the user
  830. virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
  831. virtual void DrawRowLabels( wxDC& dc, const wxArrayInt& rows );
  832. virtual void DrawRowLabel( wxDC& dc, int row );
  833. virtual void DrawColLabels( wxDC& dc, const wxArrayInt& cols );
  834. virtual void DrawColLabel( wxDC& dc, int col );
  835. virtual void DrawCornerLabel(wxDC& dc);
  836. // ------ Cell text drawing functions
  837. //
  838. void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
  839. int horizontalAlignment = wxALIGN_LEFT,
  840. int verticalAlignment = wxALIGN_TOP,
  841. int textOrientation = wxHORIZONTAL ) const;
  842. void DrawTextRectangle( wxDC& dc, const wxArrayString& lines, const wxRect&,
  843. int horizontalAlignment = wxALIGN_LEFT,
  844. int verticalAlignment = wxALIGN_TOP,
  845. int textOrientation = wxHORIZONTAL ) const;
  846. // ------ grid render function for printing
  847. //
  848. void Render( wxDC& dc,
  849. const wxPoint& pos = wxDefaultPosition,
  850. const wxSize& size = wxDefaultSize,
  851. const wxGridCellCoords& topLeft = wxGridCellCoords(-1, -1),
  852. const wxGridCellCoords& bottomRight = wxGridCellCoords(-1, -1),
  853. int style = wxGRID_DRAW_DEFAULT );
  854. // Split a string containing newline characters into an array of
  855. // strings and return the number of lines
  856. //
  857. void StringToLines( const wxString& value, wxArrayString& lines ) const;
  858. void GetTextBoxSize( const wxDC& dc,
  859. const wxArrayString& lines,
  860. long *width, long *height ) const;
  861. // ------
  862. // Code that does a lot of grid modification can be enclosed
  863. // between BeginBatch() and EndBatch() calls to avoid screen
  864. // flicker
  865. //
  866. void BeginBatch() { m_batchCount++; }
  867. void EndBatch();
  868. int GetBatchCount() { return m_batchCount; }
  869. virtual void Refresh(bool eraseb = true, const wxRect* rect = NULL);
  870. // Use this, rather than wxWindow::Refresh(), to force an
  871. // immediate repainting of the grid. Has no effect if you are
  872. // already inside a BeginBatch / EndBatch block.
  873. //
  874. // This function is necessary because wxGrid has a minimal OnPaint()
  875. // handler to reduce screen flicker.
  876. //
  877. void ForceRefresh();
  878. // ------ edit control functions
  879. //
  880. bool IsEditable() const { return m_editable; }
  881. void EnableEditing( bool edit );
  882. void EnableCellEditControl( bool enable = true );
  883. void DisableCellEditControl() { EnableCellEditControl(false); }
  884. bool CanEnableCellControl() const;
  885. bool IsCellEditControlEnabled() const;
  886. bool IsCellEditControlShown() const;
  887. bool IsCurrentCellReadOnly() const;
  888. void ShowCellEditControl();
  889. void HideCellEditControl();
  890. void SaveEditControlValue();
  891. // ------ grid location functions
  892. // Note that all of these functions work with the logical coordinates of
  893. // grid cells and labels so you will need to convert from device
  894. // coordinates for mouse events etc.
  895. //
  896. wxGridCellCoords XYToCell(int x, int y) const;
  897. void XYToCell(int x, int y, wxGridCellCoords& coords) const
  898. { coords = XYToCell(x, y); }
  899. wxGridCellCoords XYToCell(const wxPoint& pos) const
  900. { return XYToCell(pos.x, pos.y); }
  901. // these functions return the index of the row/columns corresponding to the
  902. // given logical position in pixels
  903. //
  904. // if clipToMinMax is false (default, wxNOT_FOUND is returned if the
  905. // position is outside any row/column, otherwise the first/last element is
  906. // returned in this case
  907. int YToRow( int y, bool clipToMinMax = false ) const;
  908. int XToCol( int x, bool clipToMinMax = false ) const;
  909. int YToEdgeOfRow( int y ) const;
  910. int XToEdgeOfCol( int x ) const;
  911. wxRect CellToRect( int row, int col ) const;
  912. wxRect CellToRect( const wxGridCellCoords& coords ) const
  913. { return CellToRect( coords.GetRow(), coords.GetCol() ); }
  914. int GetGridCursorRow() const { return m_currentCellCoords.GetRow(); }
  915. int GetGridCursorCol() const { return m_currentCellCoords.GetCol(); }
  916. // check to see if a cell is either wholly visible (the default arg) or
  917. // at least partially visible in the grid window
  918. //
  919. bool IsVisible( int row, int col, bool wholeCellVisible = true ) const;
  920. bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = true ) const
  921. { return IsVisible( coords.GetRow(), coords.GetCol(), wholeCellVisible ); }
  922. void MakeCellVisible( int row, int col );
  923. void MakeCellVisible( const wxGridCellCoords& coords )
  924. { MakeCellVisible( coords.GetRow(), coords.GetCol() ); }
  925. // ------ grid cursor movement functions
  926. //
  927. void SetGridCursor(int row, int col) { SetCurrentCell(row, col); }
  928. void SetGridCursor(const wxGridCellCoords& c) { SetCurrentCell(c); }
  929. void GoToCell(int row, int col)
  930. {
  931. if ( SetCurrentCell(row, col) )
  932. MakeCellVisible(row, col);
  933. }
  934. void GoToCell(const wxGridCellCoords& coords)
  935. {
  936. if ( SetCurrentCell(coords) )
  937. MakeCellVisible(coords);
  938. }
  939. bool MoveCursorUp( bool expandSelection );
  940. bool MoveCursorDown( bool expandSelection );
  941. bool MoveCursorLeft( bool expandSelection );
  942. bool MoveCursorRight( bool expandSelection );
  943. bool MovePageDown();
  944. bool MovePageUp();
  945. bool MoveCursorUpBlock( bool expandSelection );
  946. bool MoveCursorDownBlock( bool expandSelection );
  947. bool MoveCursorLeftBlock( bool expandSelection );
  948. bool MoveCursorRightBlock( bool expandSelection );
  949. void SetTabBehaviour(TabBehaviour behaviour) { m_tabBehaviour = behaviour; }
  950. // ------ label and gridline formatting
  951. //
  952. int GetDefaultRowLabelSize() const { return WXGRID_DEFAULT_ROW_LABEL_WIDTH; }
  953. int GetRowLabelSize() const { return m_rowLabelWidth; }
  954. int GetDefaultColLabelSize() const { return WXGRID_DEFAULT_COL_LABEL_HEIGHT; }
  955. int GetColLabelSize() const { return m_colLabelHeight; }
  956. wxColour GetLabelBackgroundColour() const { return m_labelBackgroundColour; }
  957. wxColour GetLabelTextColour() const { return m_labelTextColour; }
  958. wxFont GetLabelFont() const { return m_labelFont; }
  959. void GetRowLabelAlignment( int *horiz, int *vert ) const;
  960. void GetColLabelAlignment( int *horiz, int *vert ) const;
  961. int GetColLabelTextOrientation() const;
  962. wxString GetRowLabelValue( int row ) const;
  963. wxString GetColLabelValue( int col ) const;
  964. wxColour GetCellHighlightColour() const { return m_cellHighlightColour; }
  965. int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth; }
  966. int GetCellHighlightROPenWidth() const { return m_cellHighlightROPenWidth; }
  967. // this one will use wxHeaderCtrl for the column labels
  968. void UseNativeColHeader(bool native = true);
  969. // this one will still draw them manually but using the native renderer
  970. // instead of using the same appearance as for the row labels
  971. void SetUseNativeColLabels( bool native = true );
  972. void SetRowLabelSize( int width );
  973. void SetColLabelSize( int height );
  974. void HideRowLabels() { SetRowLabelSize( 0 ); }
  975. void HideColLabels() { SetColLabelSize( 0 ); }
  976. void SetLabelBackgroundColour( const wxColour& );
  977. void SetLabelTextColour( const wxColour& );
  978. void SetLabelFont( const wxFont& );
  979. void SetRowLabelAlignment( int horiz, int vert );
  980. void SetColLabelAlignment( int horiz, int vert );
  981. void SetColLabelTextOrientation( int textOrientation );
  982. void SetRowLabelValue( int row, const wxString& );
  983. void SetColLabelValue( int col, const wxString& );
  984. void SetCellHighlightColour( const wxColour& );
  985. void SetCellHighlightPenWidth(int width);
  986. void SetCellHighlightROPenWidth(int width);
  987. // interactive grid mouse operations control
  988. // -----------------------------------------
  989. // functions globally enabling row/column interactive resizing (enabled by
  990. // default)
  991. void EnableDragRowSize( bool enable = true );
  992. void DisableDragRowSize() { EnableDragRowSize( false ); }
  993. void EnableDragColSize( bool enable = true );
  994. void DisableDragColSize() { EnableDragColSize( false ); }
  995. // if interactive resizing is enabled, some rows/columns can still have
  996. // fixed size
  997. void DisableRowResize(int row) { DoDisableLineResize(row, m_setFixedRows); }
  998. void DisableColResize(int col) { DoDisableLineResize(col, m_setFixedCols); }
  999. // these functions return whether the given row/column can be
  1000. // effectively resized: for this interactive resizing must be enabled
  1001. // and this index must not have been passed to DisableRow/ColResize()
  1002. bool CanDragRowSize(int row) const
  1003. { return m_canDragRowSize && DoCanResizeLine(row, m_setFixedRows); }
  1004. bool CanDragColSize(int col) const
  1005. { return m_canDragColSize && DoCanResizeLine(col, m_setFixedCols); }
  1006. // interactive column reordering (disabled by default)
  1007. void EnableDragColMove( bool enable = true );
  1008. void DisableDragColMove() { EnableDragColMove( false ); }
  1009. bool CanDragColMove() const { return m_canDragColMove; }
  1010. // interactive resizing of grid cells (enabled by default)
  1011. void EnableDragGridSize(bool enable = true);
  1012. void DisableDragGridSize() { EnableDragGridSize(false); }
  1013. bool CanDragGridSize() const { return m_canDragGridSize; }
  1014. // interactive dragging of cells (disabled by default)
  1015. void EnableDragCell( bool enable = true );
  1016. void DisableDragCell() { EnableDragCell( false ); }
  1017. bool CanDragCell() const { return m_canDragCell; }
  1018. // grid lines
  1019. // ----------
  1020. // enable or disable drawing of the lines
  1021. void EnableGridLines(bool enable = true);
  1022. bool GridLinesEnabled() const { return m_gridLinesEnabled; }
  1023. // by default grid lines stop at last column/row, but this may be changed
  1024. void ClipHorzGridLines(bool clip)
  1025. { DoClipGridLines(m_gridLinesClipHorz, clip); }
  1026. void ClipVertGridLines(bool clip)
  1027. { DoClipGridLines(m_gridLinesClipVert, clip); }
  1028. bool AreHorzGridLinesClipped() const { return m_gridLinesClipHorz; }
  1029. bool AreVertGridLinesClipped() const { return m_gridLinesClipVert; }
  1030. // this can be used to change the global grid lines colour
  1031. void SetGridLineColour(const wxColour& col);
  1032. wxColour GetGridLineColour() const { return m_gridLineColour; }
  1033. // these methods may be overridden to customize individual grid lines
  1034. // appearance
  1035. virtual wxPen GetDefaultGridLinePen();
  1036. virtual wxPen GetRowGridLinePen(int row);
  1037. virtual wxPen GetColGridLinePen(int col);
  1038. // attributes
  1039. // ----------
  1040. // this sets the specified attribute for this cell or in this row/col
  1041. void SetAttr(int row, int col, wxGridCellAttr *attr);
  1042. void SetRowAttr(int row, wxGridCellAttr *attr);
  1043. void SetColAttr(int col, wxGridCellAttr *attr);
  1044. // the grid can cache attributes for the recently used cells (currently it
  1045. // only caches one attribute for the most recently used one) and might
  1046. // notice that its value in the attribute provider has changed -- if this
  1047. // happens, call this function to force it
  1048. void RefreshAttr(int row, int col);
  1049. // returns the attribute we may modify in place: a new one if this cell
  1050. // doesn't have any yet or the existing one if it does
  1051. //
  1052. // DecRef() must be called on the returned pointer, as usual
  1053. wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const;
  1054. // shortcuts for setting the column parameters
  1055. // set the format for the data in the column: default is string
  1056. void SetColFormatBool(int col);
  1057. void SetColFormatNumber(int col);
  1058. void SetColFormatFloat(int col, int width = -1, int precision = -1);
  1059. void SetColFormatCustom(int col, const wxString& typeName);
  1060. // ------ row and col formatting
  1061. //
  1062. int GetDefaultRowSize() const;
  1063. int GetRowSize( int row ) const;
  1064. bool IsRowShown(int row) const { return GetRowSize(row) != 0; }
  1065. int GetDefaultColSize() const;
  1066. int GetColSize( int col ) const;
  1067. bool IsColShown(int col) const { return GetColSize(col) != 0; }
  1068. wxColour GetDefaultCellBackgroundColour() const;
  1069. wxColour GetCellBackgroundColour( int row, int col ) const;
  1070. wxColour GetDefaultCellTextColour() const;
  1071. wxColour GetCellTextColour( int row, int col ) const;
  1072. wxFont GetDefaultCellFont() const;
  1073. wxFont GetCellFont( int row, int col ) const;
  1074. void GetDefaultCellAlignment( int *horiz, int *vert ) const;
  1075. void GetCellAlignment( int row, int col, int *horiz, int *vert ) const;
  1076. bool GetDefaultCellOverflow() const;
  1077. bool GetCellOverflow( int row, int col ) const;
  1078. // this function returns 1 in num_rows and num_cols for normal cells,
  1079. // positive numbers for a cell spanning multiple columns/rows (as set with
  1080. // SetCellSize()) and _negative_ numbers corresponding to the offset of the
  1081. // top left cell of the span from this one for the other cells covered by
  1082. // this cell
  1083. //
  1084. // the return value is CellSpan_None, CellSpan_Main or CellSpan_Inside for
  1085. // each of these cases respectively
  1086. enum CellSpan
  1087. {
  1088. CellSpan_Inside = -1,
  1089. CellSpan_None = 0,
  1090. CellSpan_Main
  1091. };
  1092. CellSpan GetCellSize( int row, int col, int *num_rows, int *num_cols ) const;
  1093. wxSize GetCellSize(const wxGridCellCoords& coords)
  1094. {
  1095. wxSize s;
  1096. GetCellSize(coords.GetRow(), coords.GetCol(), &s.x, &s.y);
  1097. return s;
  1098. }
  1099. // ------ row and col sizes
  1100. void SetDefaultRowSize( int height, bool resizeExistingRows = false );
  1101. void SetRowSize( int row, int height );
  1102. void HideRow(int row) { DoSetRowSize(row, 0); }
  1103. void ShowRow(int row) { DoSetRowSize(row, -1); }
  1104. void SetDefaultColSize( int width, bool resizeExistingCols = false );
  1105. void SetColSize( int col, int width );
  1106. void HideCol(int col) { DoSetColSize(col, 0); }
  1107. void ShowCol(int col) { DoSetColSize(col, -1); }
  1108. // the row and column sizes can be also set all at once using
  1109. // wxGridSizesInfo which holds all of them at once
  1110. wxGridSizesInfo GetColSizes() const
  1111. { return wxGridSizesInfo(GetDefaultColSize(), m_colWidths); }
  1112. wxGridSizesInfo GetRowSizes() const
  1113. { return wxGridSizesInfo(GetDefaultRowSize(), m_rowHeights); }
  1114. void SetColSizes(const wxGridSizesInfo& sizeInfo);
  1115. void SetRowSizes(const wxGridSizesInfo& sizeInfo);
  1116. // ------- columns (only, for now) reordering
  1117. // columns index <-> positions mapping: by default, the position of the
  1118. // column is the same as its index, but the columns can also be reordered
  1119. // (either by calling SetColPos() explicitly or by the user dragging the
  1120. // columns around) in which case their indices don't correspond to their
  1121. // positions on display any longer
  1122. //
  1123. // internally we always work with indices except for the functions which
  1124. // have "Pos" in their names (and which work with columns, not pixels) and
  1125. // only the display and hit testing code really cares about display
  1126. // positions at all
  1127. // set the positions of all columns at once (this method uses the same
  1128. // conventions as wxHeaderCtrl::SetColumnsOrder() for the order array)
  1129. void SetColumnsOrder(const wxArrayInt& order);
  1130. // return the column index corresponding to the given (valid) position
  1131. int GetColAt(int pos) const
  1132. {
  1133. return m_colAt.empty() ? pos : m_colAt[pos];
  1134. }
  1135. // reorder the columns so that the column with the given index is now shown
  1136. // as the position pos
  1137. void SetColPos(int idx, int pos);
  1138. // return the position at which the column with the given index is
  1139. // displayed: notice that this is a slow operation as we don't maintain the
  1140. // reverse mapping currently
  1141. int GetColPos(int idx) const
  1142. {
  1143. if ( m_colAt.IsEmpty() )
  1144. return idx;
  1145. for ( int i = 0; i < m_numCols; i++ )
  1146. {
  1147. if ( m_colAt[i] == idx )
  1148. return i;
  1149. }
  1150. wxFAIL_MSG( "invalid column index" );
  1151. return wxNOT_FOUND;
  1152. }
  1153. // reset the columns positions to the default order
  1154. void ResetColPos();
  1155. // automatically size the column or row to fit to its contents, if
  1156. // setAsMin is true, this optimal width will also be set as minimal width
  1157. // for this column
  1158. void AutoSizeColumn( int col, bool setAsMin = true )
  1159. { AutoSizeColOrRow(col, setAsMin, wxGRID_COLUMN); }
  1160. void AutoSizeRow( int row, bool setAsMin = true )
  1161. { AutoSizeColOrRow(row, setAsMin, wxGRID_ROW); }
  1162. // auto size all columns (very ineffective for big grids!)
  1163. void AutoSizeColumns( bool setAsMin = true )
  1164. { (void)SetOrCalcColumnSizes(false, setAsMin); }
  1165. void AutoSizeRows( bool setAsMin = true )
  1166. { (void)SetOrCalcRowSizes(false, setAsMin); }
  1167. // auto size the grid, that is make the columns/rows of the "right" size
  1168. // and also set the grid size to just fit its contents
  1169. void AutoSize();
  1170. // Note for both AutoSizeRowLabelSize and AutoSizeColLabelSize:
  1171. // If col equals to wxGRID_AUTOSIZE value then function autosizes labels column
  1172. // instead of data column. Note that this operation may be slow for large
  1173. // tables.
  1174. // autosize row height depending on label text
  1175. void AutoSizeRowLabelSize( int row );
  1176. // autosize column width depending on label text
  1177. void AutoSizeColLabelSize( int col );
  1178. // column won't be resized to be lesser width - this must be called during
  1179. // the grid creation because it won't resize the column if it's already
  1180. // narrower than the minimal width
  1181. void SetColMinimalWidth( int col, int width );
  1182. void SetRowMinimalHeight( int row, int width );
  1183. /* These members can be used to query and modify the minimal
  1184. * acceptable size of grid rows and columns. Call this function in
  1185. * your code which creates the grid if you want to display cells
  1186. * with a size smaller than the default acceptable minimum size.
  1187. * Like the members SetColMinimalWidth and SetRowMinimalWidth,
  1188. * the existing rows or columns will not be checked/resized.
  1189. */
  1190. void SetColMinimalAcceptableWidth( int width );
  1191. void SetRowMinimalAcceptableHeight( int width );
  1192. int GetColMinimalAcceptableWidth() const;
  1193. int GetRowMinimalAcceptableHeight() const;
  1194. void SetDefaultCellBackgroundColour( const wxColour& );
  1195. void SetCellBackgroundColour( int row, int col, const wxColour& );
  1196. void SetDefaultCellTextColour( const wxColour& );
  1197. void SetCellTextColour( int row, int col, const wxColour& );
  1198. void SetDefaultCellFont( const wxFont& );
  1199. void SetCellFont( int row, int col, const wxFont& );
  1200. void SetDefaultCellAlignment( int horiz, int vert );
  1201. void SetCellAlignment( int row, int col, int horiz, int vert );
  1202. void SetDefaultCellOverflow( bool allow );
  1203. void SetCellOverflow( int row, int col, bool allow );
  1204. void SetCellSize( int row, int col, int num_rows, int num_cols );
  1205. // takes ownership of the pointer
  1206. void SetDefaultRenderer(wxGridCellRenderer *renderer);
  1207. void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
  1208. wxGridCellRenderer *GetDefaultRenderer() const;
  1209. wxGridCellRenderer* GetCellRenderer(int row, int col) const;
  1210. // takes ownership of the pointer
  1211. void SetDefaultEditor(wxGridCellEditor *editor);
  1212. void SetCellEditor(int row, int col, wxGridCellEditor *editor);
  1213. wxGridCellEditor *GetDefaultEditor() const;
  1214. wxGridCellEditor* GetCellEditor(int row, int col) const;
  1215. // ------ cell value accessors
  1216. //
  1217. wxString GetCellValue( int row, int col ) const
  1218. {
  1219. if ( m_table )
  1220. {
  1221. return m_table->GetValue( row, col );
  1222. }
  1223. else
  1224. {
  1225. return wxEmptyString;
  1226. }
  1227. }
  1228. wxString GetCellValue( const wxGridCellCoords& coords ) const
  1229. { return GetCellValue( coords.GetRow(), coords.GetCol() ); }
  1230. void SetCellValue( int row, int col, const wxString& s );
  1231. void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
  1232. { SetCellValue( coords.GetRow(), coords.GetCol(), s ); }
  1233. // returns true if the cell can't be edited
  1234. bool IsReadOnly(int row, int col) const;
  1235. // make the cell editable/readonly
  1236. void SetReadOnly(int row, int col, bool isReadOnly = true);
  1237. // ------ select blocks of cells
  1238. //
  1239. void SelectRow( int row, bool addToSelected = false );
  1240. void SelectCol( int col, bool addToSelected = false );
  1241. void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
  1242. bool addToSelected = false );
  1243. void SelectBlock( const wxGridCellCoords& topLeft,
  1244. const wxGridCellCoords& bottomRight,
  1245. bool addToSelected = false )
  1246. { SelectBlock( topLeft.GetRow(), topLeft.GetCol(),
  1247. bottomRight.GetRow(), bottomRight.GetCol(),
  1248. addToSelected ); }
  1249. void SelectAll();
  1250. bool IsSelection() const;
  1251. // ------ deselect blocks or cells
  1252. //
  1253. void DeselectRow( int row );
  1254. void DeselectCol( int col );
  1255. void DeselectCell( int row, int col );
  1256. void ClearSelection();
  1257. bool IsInSelection( int row, int col ) const;
  1258. bool IsInSelection( const wxGridCellCoords& coords ) const
  1259. { return IsInSelection( coords.GetRow(), coords.GetCol() ); }
  1260. wxGridCellCoordsArray GetSelectedCells() const;
  1261. wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
  1262. wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
  1263. wxArrayInt GetSelectedRows() const;
  1264. wxArrayInt GetSelectedCols() const;
  1265. // This function returns the rectangle that encloses the block of cells
  1266. // limited by TopLeft and BottomRight cell in device coords and clipped
  1267. // to the client size of the grid window.
  1268. //
  1269. wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
  1270. const wxGridCellCoords & bottomRight ) const;
  1271. // Access or update the selection fore/back colours
  1272. wxColour GetSelectionBackground() const
  1273. { return m_selectionBackground; }
  1274. wxColour GetSelectionForeground() const
  1275. { return m_selectionForeground; }
  1276. void SetSelectionBackground(const wxColour& c) { m_selectionBackground = c; }
  1277. void SetSelectionForeground(const wxColour& c) { m_selectionForeground = c; }
  1278. // Methods for a registry for mapping data types to Renderers/Editors
  1279. void RegisterDataType(const wxString& typeName,
  1280. wxGridCellRenderer* renderer,
  1281. wxGridCellEditor* editor);
  1282. // DJC MAPTEK
  1283. virtual wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
  1284. wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
  1285. { return GetDefaultEditorForCell(c.GetRow(), c.GetCol()); }
  1286. virtual wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
  1287. virtual wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
  1288. virtual wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
  1289. // grid may occupy more space than needed for its rows/columns, this
  1290. // function allows to set how big this extra space is
  1291. void SetMargins(int extraWidth, int extraHeight)
  1292. {
  1293. m_extraWidth = extraWidth;
  1294. m_extraHeight = extraHeight;
  1295. CalcDimensions();
  1296. }
  1297. // Accessors for component windows
  1298. wxWindow* GetGridWindow() const { return (wxWindow*)m_gridWin; }
  1299. wxWindow* GetGridRowLabelWindow() const { return (wxWindow*)m_rowLabelWin; }
  1300. wxWindow* GetGridColLabelWindow() const { return m_colWindow; }
  1301. wxWindow* GetGridCornerLabelWindow() const { return (wxWindow*)m_cornerLabelWin; }
  1302. // This one can only be called if we are using the native header window
  1303. wxHeaderCtrl *GetGridColHeader() const
  1304. {
  1305. wxASSERT_MSG( m_useNativeHeader, "no column header window" );
  1306. // static_cast<> doesn't work without the full class declaration in
  1307. // view and we prefer to avoid adding more compile-time dependencies
  1308. // even at the cost of using reinterpret_cast<>
  1309. return reinterpret_cast<wxHeaderCtrl *>(m_colWindow);
  1310. }
  1311. // Allow adjustment of scroll increment. The default is (15, 15).
  1312. void SetScrollLineX(int x) { m_xScrollPixelsPerLine = x; }
  1313. void SetScrollLineY(int y) { m_yScrollPixelsPerLine = y; }
  1314. int GetScrollLineX() const { return m_xScrollPixelsPerLine; }
  1315. int GetScrollLineY() const { return m_yScrollPixelsPerLine; }
  1316. // ------- drag and drop
  1317. #if wxUSE_DRAG_AND_DROP
  1318. virtual void SetDropTarget(wxDropTarget *dropTarget);
  1319. #endif // wxUSE_DRAG_AND_DROP
  1320. // ------- sorting support
  1321. // wxGrid doesn't support sorting on its own but it can indicate the sort
  1322. // order in the column header (currently only if native header control is
  1323. // used though)
  1324. // return the column currently displaying the sort indicator or wxNOT_FOUND
  1325. // if none
  1326. int GetSortingColumn() const { return m_sortCol; }
  1327. // return true if this column is currently used for sorting
  1328. bool IsSortingBy(int col) const { return GetSortingColumn() == col; }
  1329. // return the current sorting order (on GetSortingColumn()): true for
  1330. // ascending sort and false for descending; it doesn't make sense to call
  1331. // it if GetSortingColumn() returns wxNOT_FOUND
  1332. bool IsSortOrderAscending() const { return m_sortIsAscending; }
  1333. // set the sorting column (or unsets any existing one if wxNOT_FOUND) and
  1334. // the order in which to sort
  1335. void SetSortingColumn(int col, bool ascending = true);
  1336. // unset any existing sorting column
  1337. void UnsetSortingColumn() { SetSortingColumn(wxNOT_FOUND); }
  1338. #if WXWIN_COMPATIBILITY_2_8
  1339. // ------ For compatibility with previous wxGrid only...
  1340. //
  1341. // ************************************************
  1342. // ** Don't use these in new code because they **
  1343. // ** are liable to disappear in a future **
  1344. // ** revision **
  1345. // ************************************************
  1346. //
  1347. wxGrid( wxWindow *parent,
  1348. int x, int y, int w = wxDefaultCoord, int h = wxDefaultCoord,
  1349. long style = wxWANTS_CHARS,
  1350. const wxString& name = wxPanelNameStr )
  1351. {
  1352. Init();
  1353. Create(parent, wxID_ANY, wxPoint(x, y), wxSize(w, h), style, name);
  1354. }
  1355. void SetCellValue( const wxString& val, int row, int col )
  1356. { SetCellValue( row, col, val ); }
  1357. void UpdateDimensions()
  1358. { CalcDimensions(); }
  1359. int GetRows() const { return GetNumberRows(); }
  1360. int GetCols() const { return GetNumberCols(); }
  1361. int GetCursorRow() const { return GetGridCursorRow(); }
  1362. int GetCursorColumn() const { return GetGridCursorCol(); }
  1363. int GetScrollPosX() const { return 0; }
  1364. int GetScrollPosY() const { return 0; }
  1365. void SetScrollX( int WXUNUSED(x) ) { }
  1366. void SetScrollY( int WXUNUSED(y) ) { }
  1367. void SetColumnWidth( int col, int width )
  1368. { SetColSize( col, width ); }
  1369. int GetColumnWidth( int col ) const
  1370. { return GetColSize( col ); }
  1371. void SetRowHeight( int row, int height )
  1372. { SetRowSize( row, height ); }
  1373. // GetRowHeight() is below
  1374. int GetViewHeight() const // returned num whole rows visible
  1375. { return 0; }
  1376. int GetViewWidth() const // returned num whole cols visible
  1377. { return 0; }
  1378. void SetLabelSize( int orientation, int sz )
  1379. {
  1380. if ( orientation == wxHORIZONTAL )
  1381. SetColLabelSize( sz );
  1382. else
  1383. SetRowLabelSize( sz );
  1384. }
  1385. int GetLabelSize( int orientation ) const
  1386. {
  1387. if ( orientation == wxHORIZONTAL )
  1388. return GetColLabelSize();
  1389. else
  1390. return GetRowLabelSize();
  1391. }
  1392. void SetLabelAlignment( int orientation, int align )
  1393. {
  1394. if ( orientation == wxHORIZONTAL )
  1395. SetColLabelAlignment( align, wxALIGN_INVALID );
  1396. else
  1397. SetRowLabelAlignment( align, wxALIGN_INVALID );
  1398. }
  1399. int GetLabelAlignment( int orientation, int WXUNUSED(align) ) const
  1400. {
  1401. int h, v;
  1402. if ( orientation == wxHORIZONTAL )
  1403. {
  1404. GetColLabelAlignment( &h, &v );
  1405. return h;
  1406. }
  1407. else
  1408. {
  1409. GetRowLabelAlignment( &h, &v );
  1410. return h;
  1411. }
  1412. }
  1413. void SetLabelValue( int orientation, const wxString& val, int pos )
  1414. {
  1415. if ( orientation == wxHORIZONTAL )
  1416. SetColLabelValue( pos, val );
  1417. else
  1418. SetRowLabelValue( pos, val );
  1419. }
  1420. wxString GetLabelValue( int orientation, int pos) const
  1421. {
  1422. if ( orientation == wxHORIZONTAL )
  1423. return GetColLabelValue( pos );
  1424. else
  1425. return GetRowLabelValue( pos );
  1426. }
  1427. wxFont GetCellTextFont() const
  1428. { return m_defaultCellAttr->GetFont(); }
  1429. wxFont GetCellTextFont(int WXUNUSED(row), int WXUNUSED(col)) const
  1430. { return m_defaultCellAttr->GetFont(); }
  1431. void SetCellTextFont(const wxFont& fnt)
  1432. { SetDefaultCellFont( fnt ); }
  1433. void SetCellTextFont(const wxFont& fnt, int row, int col)
  1434. { SetCellFont( row, col, fnt ); }
  1435. void SetCellTextColour(const wxColour& val, int row, int col)
  1436. { SetCellTextColour( row, col, val ); }
  1437. void SetCellTextColour(const wxColour& col)
  1438. { SetDefaultCellTextColour( col ); }
  1439. void SetCellBackgroundColour(const wxColour& col)
  1440. { SetDefaultCellBackgroundColour( col ); }
  1441. void SetCellBackgroundColour(const wxColour& colour, int row, int col)
  1442. { SetCellBackgroundColour( row, col, colour ); }
  1443. bool GetEditable() const { return IsEditable(); }
  1444. void SetEditable( bool edit = true ) { EnableEditing( edit ); }
  1445. bool GetEditInPlace() const { return IsCellEditControlEnabled(); }
  1446. void SetEditInPlace(bool WXUNUSED(edit) = true) { }
  1447. void SetCellAlignment( int align, int row, int col)
  1448. { SetCellAlignment(row, col, align, wxALIGN_CENTER); }
  1449. void SetCellAlignment( int WXUNUSED(align) ) {}
  1450. void SetCellBitmap(wxBitmap *WXUNUSED(bitmap), int WXUNUSED(row), int WXUNUSED(col))
  1451. { }
  1452. void SetDividerPen(const wxPen& WXUNUSED(pen)) { }
  1453. wxPen& GetDividerPen() const;
  1454. void OnActivate(bool WXUNUSED(active)) {}
  1455. // ******** End of compatibility functions **********
  1456. // ------ control IDs
  1457. enum { wxGRID_CELLCTRL = 2000,
  1458. wxGRID_TOPCTRL };
  1459. // ------ control types
  1460. enum { wxGRID_TEXTCTRL = 2100,
  1461. wxGRID_CHECKBOX,
  1462. wxGRID_CHOICE,
  1463. wxGRID_COMBOBOX };
  1464. wxDEPRECATED_INLINE(bool CanDragRowSize() const, return m_canDragRowSize; )
  1465. wxDEPRECATED_INLINE(bool CanDragColSize() const, return m_canDragColSize; )
  1466. #endif // WXWIN_COMPATIBILITY_2_8
  1467. // override some base class functions
  1468. virtual bool Enable(bool enable = true);
  1469. virtual wxWindow *GetMainWindowOfCompositeControl()
  1470. { return (wxWindow*)m_gridWin; }
  1471. virtual void Fit();
  1472. // implementation only
  1473. void CancelMouseCapture();
  1474. protected:
  1475. virtual wxSize DoGetBestSize() const;
  1476. bool m_created;
  1477. wxGridWindow *m_gridWin;
  1478. wxGridCornerLabelWindow *m_cornerLabelWin;
  1479. wxGridRowLabelWindow *m_rowLabelWin;
  1480. // the real type of the column window depends on m_useNativeHeader value:
  1481. // if it is true, its dynamic type is wxHeaderCtrl, otherwise it is
  1482. // wxGridColLabelWindow, use accessors below when the real type matters
  1483. wxWindow *m_colWindow;
  1484. wxGridColLabelWindow *GetColLabelWindow() const
  1485. {
  1486. wxASSERT_MSG( !m_useNativeHeader, "no column label window" );
  1487. return reinterpret_cast<wxGridColLabelWindow *>(m_colWindow);
  1488. }
  1489. wxGridTableBase *m_table;
  1490. bool m_ownTable;
  1491. int m_numRows;
  1492. int m_numCols;
  1493. wxGridCellCoords m_currentCellCoords;
  1494. // the corners of the block being currently selected or wxGridNoCellCoords
  1495. wxGridCellCoords m_selectedBlockTopLeft;
  1496. wxGridCellCoords m_selectedBlockBottomRight;
  1497. // when selecting blocks of cells (either from the keyboard using Shift
  1498. // with cursor keys, or by dragging the mouse), the selection is anchored
  1499. // at m_currentCellCoords which defines one of the corners of the rectangle
  1500. // being selected -- and this variable defines the other corner, i.e. it's
  1501. // either m_selectedBlockTopLeft or m_selectedBlockBottomRight depending on
  1502. // which of them is not m_currentCellCoords
  1503. //
  1504. // if no block selection is in process, it is set to wxGridNoCellCoords
  1505. wxGridCellCoords m_selectedBlockCorner;
  1506. wxGridSelection *m_selection;
  1507. wxColour m_selectionBackground;
  1508. wxColour m_selectionForeground;
  1509. // NB: *never* access m_row/col arrays directly because they are created
  1510. // on demand, *always* use accessor functions instead!
  1511. // init the m_rowHeights/Bottoms arrays with default values
  1512. void InitRowHeights();
  1513. int m_defaultRowHeight;
  1514. int m_minAcceptableRowHeight;
  1515. wxArrayInt m_rowHeights;
  1516. wxArrayInt m_rowBottoms;
  1517. // init the m_colWidths/Rights arrays
  1518. void InitColWidths();
  1519. int m_defaultColWidth;
  1520. int m_minAcceptableColWidth;
  1521. wxArrayInt m_colWidths;
  1522. wxArrayInt m_colRights;
  1523. int m_sortCol;
  1524. bool m_sortIsAscending;
  1525. bool m_useNativeHeader,
  1526. m_nativeColumnLabels;
  1527. // get the col/row coords
  1528. int GetColWidth(int col) const;
  1529. int GetColLeft(int col) const;
  1530. int GetColRight(int col) const;
  1531. // this function must be public for compatibility...
  1532. public:
  1533. int GetRowHeight(int row) const;
  1534. protected:
  1535. int GetRowTop(int row) const;
  1536. int GetRowBottom(int row) const;
  1537. int m_rowLabelWidth;
  1538. int m_colLabelHeight;
  1539. // the size of the margin left to the right and bottom of the cell area
  1540. int m_extraWidth,
  1541. m_extraHeight;
  1542. wxColour m_labelBackgroundColour;
  1543. wxColour m_labelTextColour;
  1544. wxFont m_labelFont;
  1545. int m_rowLabelHorizAlign;
  1546. int m_rowLabelVertAlign;
  1547. int m_colLabelHorizAlign;
  1548. int m_colLabelVertAlign;
  1549. int m_colLabelTextOrientation;
  1550. bool m_defaultRowLabelValues;
  1551. bool m_defaultColLabelValues;
  1552. wxColour m_gridLineColour;
  1553. bool m_gridLinesEnabled;
  1554. bool m_gridLinesClipHorz,
  1555. m_gridLinesClipVert;
  1556. wxColour m_cellHighlightColour;
  1557. int m_cellHighlightPenWidth;
  1558. int m_cellHighlightROPenWidth;
  1559. // common part of AutoSizeColumn/Row() and GetBestSize()
  1560. int SetOrCalcColumnSizes(bool calcOnly, bool setAsMin = true);
  1561. int SetOrCalcRowSizes(bool calcOnly, bool setAsMin = true);
  1562. // common part of AutoSizeColumn/Row()
  1563. void AutoSizeColOrRow(int n, bool setAsMin, wxGridDirection direction);
  1564. // Calculate the minimum acceptable size for labels area
  1565. wxCoord CalcColOrRowLabelAreaMinSize(wxGridDirection direction);
  1566. // if a column has a minimal width, it will be the value for it in this
  1567. // hash table
  1568. wxLongToLongHashMap m_colMinWidths,
  1569. m_rowMinHeights;
  1570. // get the minimal width of the given column/row
  1571. int GetColMinimalWidth(int col) const;
  1572. int GetRowMinimalHeight(int col) const;
  1573. // do we have some place to store attributes in?
  1574. bool CanHaveAttributes() const;
  1575. // cell attribute cache (currently we only cache 1, may be will do
  1576. // more/better later)
  1577. struct CachedAttr
  1578. {
  1579. int row, col;
  1580. wxGridCellAttr *attr;
  1581. } m_attrCache;
  1582. // invalidates the attribute cache
  1583. void ClearAttrCache();
  1584. // adds an attribute to cache
  1585. void CacheAttr(int row, int col, wxGridCellAttr *attr) const;
  1586. // looks for an attr in cache, returns true if found
  1587. bool LookupAttr(int row, int col, wxGridCellAttr **attr) const;
  1588. // looks for the attr in cache, if not found asks the table and caches the
  1589. // result
  1590. wxGridCellAttr *GetCellAttr(int row, int col) const;
  1591. wxGridCellAttr *GetCellAttr(const wxGridCellCoords& coords ) const
  1592. { return GetCellAttr( coords.GetRow(), coords.GetCol() ); }
  1593. // the default cell attr object for cells that don't have their own
  1594. wxGridCellAttr* m_defaultCellAttr;
  1595. bool m_inOnKeyDown;
  1596. int m_batchCount;
  1597. wxGridTypeRegistry* m_typeRegistry;
  1598. enum CursorMode
  1599. {
  1600. WXGRID_CURSOR_SELECT_CELL,
  1601. WXGRID_CURSOR_RESIZE_ROW,
  1602. WXGRID_CURSOR_RESIZE_COL,
  1603. WXGRID_CURSOR_SELECT_ROW,
  1604. WXGRID_CURSOR_SELECT_COL,
  1605. WXGRID_CURSOR_MOVE_COL
  1606. };
  1607. // this method not only sets m_cursorMode but also sets the correct cursor
  1608. // for the given mode and, if captureMouse is not false releases the mouse
  1609. // if it was captured and captures it if it must be captured
  1610. //
  1611. // for this to work, you should always use it and not set m_cursorMode
  1612. // directly!
  1613. void ChangeCursorMode(CursorMode mode,
  1614. wxWindow *win = NULL,
  1615. bool captureMouse = true);
  1616. wxWindow *m_winCapture; // the window which captured the mouse
  1617. // this variable is used not for finding the correct current cursor but
  1618. // mainly for finding out what is going to happen if the mouse starts being
  1619. // dragged right now
  1620. //
  1621. // by default it is WXGRID_CURSOR_SELECT_CELL meaning that nothing else is
  1622. // going on, and it is set to one of RESIZE/SELECT/MOVE values while the
  1623. // corresponding operation will be started if the user starts dragging the
  1624. // mouse from the current position
  1625. CursorMode m_cursorMode;
  1626. //Column positions
  1627. wxArrayInt m_colAt;
  1628. bool m_canDragRowSize;
  1629. bool m_canDragColSize;
  1630. bool m_canDragColMove;
  1631. bool m_canDragGridSize;
  1632. bool m_canDragCell;
  1633. // the last position (horizontal or vertical depending on whether the user
  1634. // is resizing a column or a row) where a row or column separator line was
  1635. // dragged by the user or -1 of there is no drag operation in progress
  1636. int m_dragLastPos;
  1637. int m_dragRowOrCol;
  1638. // true if a drag operation is in progress; when this is true,
  1639. // m_startDragPos is valid, i.e. not wxDefaultPosition
  1640. bool m_isDragging;
  1641. // the position (in physical coordinates) where the user started dragging
  1642. // the mouse or wxDefaultPosition if mouse isn't being dragged
  1643. //
  1644. // notice that this can be != wxDefaultPosition while m_isDragging is still
  1645. // false because we wait until the mouse is moved some distance away before
  1646. // setting m_isDragging to true
  1647. wxPoint m_startDragPos;
  1648. bool m_waitForSlowClick;
  1649. wxGridCellCoords m_selectionStart;
  1650. wxCursor m_rowResizeCursor;
  1651. wxCursor m_colResizeCursor;
  1652. bool m_editable; // applies to whole grid
  1653. bool m_cellEditCtrlEnabled; // is in-place edit currently shown?
  1654. TabBehaviour m_tabBehaviour; // determines how the TAB key behaves
  1655. void Init(); // common part of all ctors
  1656. void Create();
  1657. void CreateColumnWindow();
  1658. void CalcDimensions();
  1659. void CalcWindowSizes();
  1660. bool Redimension( wxGridTableMessage& );
  1661. // generate the appropriate grid event and return -1 if it was vetoed, 1 if
  1662. // it was processed (but not vetoed) and 0 if it wasn't processed
  1663. int SendEvent(const wxEventType evtType,
  1664. int row, int col,
  1665. const wxMouseEvent& e);
  1666. int SendEvent(const wxEventType evtType,
  1667. const wxGridCellCoords& coords,
  1668. const wxMouseEvent& e)
  1669. { return SendEvent(evtType, coords.GetRow(), coords.GetCol(), e); }
  1670. int SendEvent(const wxEventType evtType,
  1671. int row, int col,
  1672. const wxString& s = wxString());
  1673. int SendEvent(const wxEventType evtType,
  1674. const wxGridCellCoords& coords,
  1675. const wxString& s = wxString())
  1676. { return SendEvent(evtType, coords.GetRow(), coords.GetCol(), s); }
  1677. int SendEvent(const wxEventType evtType, const wxString& s = wxString())
  1678. { return SendEvent(evtType, m_currentCellCoords, s); }
  1679. // send wxEVT_GRID_{ROW,COL}_SIZE or wxEVT_GRID_COL_AUTO_SIZE, return true
  1680. // if the event was processed, false otherwise
  1681. bool SendGridSizeEvent(wxEventType type,
  1682. int row, int col,
  1683. const wxMouseEvent& mouseEv);
  1684. void OnPaint( wxPaintEvent& );
  1685. void OnSize( wxSizeEvent& );
  1686. void OnKeyDown( wxKeyEvent& );
  1687. void OnKeyUp( wxKeyEvent& );
  1688. void OnChar( wxKeyEvent& );
  1689. void OnEraseBackground( wxEraseEvent& );
  1690. void OnHideEditor( wxCommandEvent& );
  1691. bool SetCurrentCell( const wxGridCellCoords& coords );
  1692. bool SetCurrentCell( int row, int col )
  1693. { return SetCurrentCell( wxGridCellCoords(row, col) ); }
  1694. // this function is called to extend the block being currently selected
  1695. // from mouse and keyboard event handlers
  1696. void UpdateBlockBeingSelected(int topRow, int leftCol,
  1697. int bottomRow, int rightCol);
  1698. void UpdateBlockBeingSelected(const wxGridCellCoords& topLeft,
  1699. const wxGridCellCoords& bottomRight)
  1700. { UpdateBlockBeingSelected(topLeft.GetRow(), topLeft.GetCol(),
  1701. bottomRight.GetRow(), bottomRight.GetCol()); }
  1702. // ------ functions to get/send data (see also public functions)
  1703. //
  1704. bool GetModelValues();
  1705. bool SetModelValues();
  1706. friend class WXDLLIMPEXP_FWD_ADV wxGridSelection;
  1707. friend class wxGridRowOperations;
  1708. friend class wxGridColumnOperations;
  1709. // they call our private Process{{Corner,Col,Row}Label,GridCell}MouseEvent()
  1710. friend class wxGridCornerLabelWindow;
  1711. friend class wxGridColLabelWindow;
  1712. friend class wxGridRowLabelWindow;
  1713. friend class wxGridWindow;
  1714. friend class wxGridHeaderRenderer;
  1715. friend class wxGridHeaderCtrl;
  1716. private:
  1717. // implement wxScrolledWindow method to return m_gridWin size
  1718. virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size);
  1719. // redraw the grid lines, should be called after changing their attributes
  1720. void RedrawGridLines();
  1721. // draw all grid lines in the given cell region (unlike the public
  1722. // DrawAllGridLines() which just draws all of them)
  1723. void DrawRangeGridLines(wxDC& dc, const wxRegion& reg,
  1724. const wxGridCellCoords& topLeft,
  1725. const wxGridCellCoords& bottomRight);
  1726. // draw all lines from top to bottom row and left to right column in the
  1727. // rectangle determined by (top, left)-(bottom, right) -- but notice that
  1728. // the caller must have set up the clipping correctly, this rectangle is
  1729. // only used here for optimization
  1730. void DoDrawGridLines(wxDC& dc,
  1731. int top, int left,
  1732. int bottom, int right,
  1733. int topRow, int leftCol,
  1734. int bottomRight, int rightCol);
  1735. // common part of Clip{Horz,Vert}GridLines
  1736. void DoClipGridLines(bool& var, bool clip);
  1737. // update the sorting indicator shown in the specified column (whose index
  1738. // must be valid)
  1739. //
  1740. // this will use GetSortingColumn() and IsSortOrderAscending() to determine
  1741. // the sorting indicator to effectively show
  1742. void UpdateColumnSortingIndicator(int col);
  1743. // update the grid after changing the columns order (common part of
  1744. // SetColPos() and ResetColPos())
  1745. void RefreshAfterColPosChange();
  1746. // return the position (not index) of the column at the given logical pixel
  1747. // position
  1748. //
  1749. // this always returns a valid position, even if the coordinate is out of
  1750. // bounds (in which case first/last column is returned)
  1751. int XToPos(int x) const;
  1752. // event handlers and their helpers
  1753. // --------------------------------
  1754. // process mouse drag event in WXGRID_CURSOR_SELECT_CELL mode
  1755. bool DoGridCellDrag(wxMouseEvent& event,
  1756. const wxGridCellCoords& coords,
  1757. bool isFirstDrag);
  1758. // process row/column resizing drag event
  1759. void DoGridLineDrag(wxMouseEvent& event, const wxGridOperations& oper);
  1760. // process mouse drag event in the grid window
  1761. void DoGridDragEvent(wxMouseEvent& event, const wxGridCellCoords& coords);
  1762. // process different clicks on grid cells
  1763. void DoGridCellLeftDown(wxMouseEvent& event,
  1764. const wxGridCellCoords& coords,
  1765. const wxPoint& pos);
  1766. void DoGridCellLeftDClick(wxMouseEvent& event,
  1767. const wxGridCellCoords& coords,
  1768. const wxPoint& pos);
  1769. void DoGridCellLeftUp(wxMouseEvent& event, const wxGridCellCoords& coords);
  1770. // process movement (but not dragging) event in the grid cell area
  1771. void DoGridMouseMoveEvent(wxMouseEvent& event,
  1772. const wxGridCellCoords& coords,
  1773. const wxPoint& pos);
  1774. // process mouse events in the grid window
  1775. void ProcessGridCellMouseEvent(wxMouseEvent& event);
  1776. // process mouse events in the row/column labels/corner windows
  1777. void ProcessRowLabelMouseEvent(wxMouseEvent& event);
  1778. void ProcessColLabelMouseEvent(wxMouseEvent& event);
  1779. void ProcessCornerLabelMouseEvent(wxMouseEvent& event);
  1780. void DoColHeaderClick(int col);
  1781. void DoStartResizeCol(int col);
  1782. void DoUpdateResizeCol(int x);
  1783. void DoUpdateResizeColWidth(int w);
  1784. void DoStartMoveCol(int col);
  1785. void DoEndDragResizeRow(const wxMouseEvent& event);
  1786. void DoEndDragResizeCol(const wxMouseEvent& event);
  1787. void DoEndMoveCol(int pos);
  1788. // process a TAB keypress
  1789. void DoGridProcessTab(wxKeyboardState& kbdState);
  1790. // common implementations of methods defined for both rows and columns
  1791. void DeselectLine(int line, const wxGridOperations& oper);
  1792. bool DoEndDragResizeLine(const wxGridOperations& oper);
  1793. int PosToLinePos(int pos, bool clipToMinMax,
  1794. const wxGridOperations& oper) const;
  1795. int PosToLine(int pos, bool clipToMinMax,
  1796. const wxGridOperations& oper) const;
  1797. int PosToEdgeOfLine(int pos, const wxGridOperations& oper) const;
  1798. bool DoMoveCursor(bool expandSelection,
  1799. const wxGridDirectionOperations& diroper);
  1800. bool DoMoveCursorByPage(const wxGridDirectionOperations& diroper);
  1801. bool DoMoveCursorByBlock(bool expandSelection,
  1802. const wxGridDirectionOperations& diroper);
  1803. void AdvanceToNextNonEmpty(wxGridCellCoords& coords,
  1804. const wxGridDirectionOperations& diroper);
  1805. // common part of {Insert,Delete}{Rows,Cols}
  1806. bool DoModifyLines(bool (wxGridTableBase::*funcModify)(size_t, size_t),
  1807. int pos, int num, bool updateLabels);
  1808. // Append{Rows,Cols} is a bit different because of one less parameter
  1809. bool DoAppendLines(bool (wxGridTableBase::*funcAppend)(size_t),
  1810. int num, bool updateLabels);
  1811. // common part of Set{Col,Row}Sizes
  1812. void DoSetSizes(const wxGridSizesInfo& sizeInfo,
  1813. const wxGridOperations& oper);
  1814. // common part of Disable{Row,Col}Resize and CanDrag{Row,Col}Size
  1815. void DoDisableLineResize(int line, wxGridFixedIndicesSet *& setFixed);
  1816. bool DoCanResizeLine(int line, const wxGridFixedIndicesSet *setFixed) const;
  1817. // Helper of Render(): get grid size, origin offset and fill cell arrays
  1818. void GetRenderSizes( const wxGridCellCoords& topLeft,
  1819. const wxGridCellCoords& bottomRight,
  1820. wxPoint& pointOffSet, wxSize& sizeGrid,
  1821. wxGridCellCoordsArray& renderCells,
  1822. wxArrayInt& arrayCols, wxArrayInt& arrayRows );
  1823. // Helper of Render(): set the scale to draw the cells at the right size.
  1824. void SetRenderScale( wxDC& dc, const wxPoint& pos, const wxSize& size,
  1825. const wxSize& sizeGrid );
  1826. // Helper of Render(): get render start position from passed parameter
  1827. wxPoint GetRenderPosition( wxDC& dc, const wxPoint& position );
  1828. // Helper of Render(): draws a box around the rendered area
  1829. void DoRenderBox( wxDC& dc, const int& style,
  1830. const wxPoint& pointOffSet,
  1831. const wxSize& sizeCellArea,
  1832. const wxGridCellCoords& topLeft,
  1833. const wxGridCellCoords& bottomRight );
  1834. // Implementation of public Set{Row,Col}Size() and {Hide,Show}{Row,Col}().
  1835. // They interpret their height or width parameter slightly different from
  1836. // the public methods where -1 in it means "auto fit to the label" for the
  1837. // compatibility reasons. Here it means "show a previously hidden row or
  1838. // column" while 0 means "hide it" just as in the public methods. And any
  1839. // positive values are handled naturally, i.e. they just specify the size.
  1840. void DoSetRowSize( int row, int height );
  1841. void DoSetColSize( int col, int width );
  1842. // these sets contain the indices of fixed, i.e. non-resizable
  1843. // interactively, grid rows or columns and are NULL if there are no fixed
  1844. // elements (which is the default)
  1845. wxGridFixedIndicesSet *m_setFixedRows,
  1846. *m_setFixedCols;
  1847. DECLARE_DYNAMIC_CLASS( wxGrid )
  1848. DECLARE_EVENT_TABLE()
  1849. wxDECLARE_NO_COPY_CLASS(wxGrid);
  1850. };
  1851. // ----------------------------------------------------------------------------
  1852. // wxGridUpdateLocker prevents updates to a grid during its lifetime
  1853. // ----------------------------------------------------------------------------
  1854. class WXDLLIMPEXP_ADV wxGridUpdateLocker
  1855. {
  1856. public:
  1857. // if the pointer is NULL, Create() can be called later
  1858. wxGridUpdateLocker(wxGrid *grid = NULL)
  1859. {
  1860. Init(grid);
  1861. }
  1862. // can be called if ctor was used with a NULL pointer, must not be called
  1863. // more than once
  1864. void Create(wxGrid *grid)
  1865. {
  1866. wxASSERT_MSG( !m_grid, wxT("shouldn't be called more than once") );
  1867. Init(grid);
  1868. }
  1869. ~wxGridUpdateLocker()
  1870. {
  1871. if ( m_grid )
  1872. m_grid->EndBatch();
  1873. }
  1874. private:
  1875. void Init(wxGrid *grid)
  1876. {
  1877. m_grid = grid;
  1878. if ( m_grid )
  1879. m_grid->BeginBatch();
  1880. }
  1881. wxGrid *m_grid;
  1882. wxDECLARE_NO_COPY_CLASS(wxGridUpdateLocker);
  1883. };
  1884. // ----------------------------------------------------------------------------
  1885. // Grid event class and event types
  1886. // ----------------------------------------------------------------------------
  1887. class WXDLLIMPEXP_ADV wxGridEvent : public wxNotifyEvent,
  1888. public wxKeyboardState
  1889. {
  1890. public:
  1891. wxGridEvent()
  1892. : wxNotifyEvent()
  1893. {
  1894. Init(-1, -1, -1, -1, false);
  1895. }
  1896. wxGridEvent(int id,
  1897. wxEventType type,
  1898. wxObject* obj,
  1899. int row = -1, int col = -1,
  1900. int x = -1, int y = -1,
  1901. bool sel = true,
  1902. const wxKeyboardState& kbd = wxKeyboardState())
  1903. : wxNotifyEvent(type, id),
  1904. wxKeyboardState(kbd)
  1905. {
  1906. Init(row, col, x, y, sel);
  1907. SetEventObject(obj);
  1908. }
  1909. // explicitly specifying inline allows gcc < 3.4 to
  1910. // handle the deprecation attribute even in the constructor.
  1911. wxDEPRECATED_CONSTRUCTOR(
  1912. wxGridEvent(int id,
  1913. wxEventType type,
  1914. wxObject* obj,
  1915. int row, int col,
  1916. int x, int y,
  1917. bool sel,
  1918. bool control,
  1919. bool shift = false, bool alt = false, bool meta = false));
  1920. virtual int GetRow() { return m_row; }
  1921. virtual int GetCol() { return m_col; }
  1922. wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
  1923. bool Selecting() { return m_selecting; }
  1924. virtual wxEvent *Clone() const { return new wxGridEvent(*this); }
  1925. protected:
  1926. int m_row;
  1927. int m_col;
  1928. int m_x;
  1929. int m_y;
  1930. bool m_selecting;
  1931. private:
  1932. void Init(int row, int col, int x, int y, bool sel)
  1933. {
  1934. m_row = row;
  1935. m_col = col;
  1936. m_x = x;
  1937. m_y = y;
  1938. m_selecting = sel;
  1939. }
  1940. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEvent)
  1941. };
  1942. class WXDLLIMPEXP_ADV wxGridSizeEvent : public wxNotifyEvent,
  1943. public wxKeyboardState
  1944. {
  1945. public:
  1946. wxGridSizeEvent()
  1947. : wxNotifyEvent()
  1948. {
  1949. Init(-1, -1, -1);
  1950. }
  1951. wxGridSizeEvent(int id,
  1952. wxEventType type,
  1953. wxObject* obj,
  1954. int rowOrCol = -1,
  1955. int x = -1, int y = -1,
  1956. const wxKeyboardState& kbd = wxKeyboardState())
  1957. : wxNotifyEvent(type, id),
  1958. wxKeyboardState(kbd)
  1959. {
  1960. Init(rowOrCol, x, y);
  1961. SetEventObject(obj);
  1962. }
  1963. wxDEPRECATED_CONSTRUCTOR(
  1964. wxGridSizeEvent(int id,
  1965. wxEventType type,
  1966. wxObject* obj,
  1967. int rowOrCol,
  1968. int x, int y,
  1969. bool control,
  1970. bool shift = false,
  1971. bool alt = false,
  1972. bool meta = false) );
  1973. int GetRowOrCol() { return m_rowOrCol; }
  1974. wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
  1975. virtual wxEvent *Clone() const { return new wxGridSizeEvent(*this); }
  1976. protected:
  1977. int m_rowOrCol;
  1978. int m_x;
  1979. int m_y;
  1980. private:
  1981. void Init(int rowOrCol, int x, int y)
  1982. {
  1983. m_rowOrCol = rowOrCol;
  1984. m_x = x;
  1985. m_y = y;
  1986. }
  1987. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridSizeEvent)
  1988. };
  1989. class WXDLLIMPEXP_ADV wxGridRangeSelectEvent : public wxNotifyEvent,
  1990. public wxKeyboardState
  1991. {
  1992. public:
  1993. wxGridRangeSelectEvent()
  1994. : wxNotifyEvent()
  1995. {
  1996. Init(wxGridNoCellCoords, wxGridNoCellCoords, false);
  1997. }
  1998. wxGridRangeSelectEvent(int id,
  1999. wxEventType type,
  2000. wxObject* obj,
  2001. const wxGridCellCoords& topLeft,
  2002. const wxGridCellCoords& bottomRight,
  2003. bool sel = true,
  2004. const wxKeyboardState& kbd = wxKeyboardState())
  2005. : wxNotifyEvent(type, id),
  2006. wxKeyboardState(kbd)
  2007. {
  2008. Init(topLeft, bottomRight, sel);
  2009. SetEventObject(obj);
  2010. }
  2011. wxDEPRECATED_CONSTRUCTOR(
  2012. wxGridRangeSelectEvent(int id,
  2013. wxEventType type,
  2014. wxObject* obj,
  2015. const wxGridCellCoords& topLeft,
  2016. const wxGridCellCoords& bottomRight,
  2017. bool sel,
  2018. bool control,
  2019. bool shift = false,
  2020. bool alt = false,
  2021. bool meta = false) );
  2022. wxGridCellCoords GetTopLeftCoords() { return m_topLeft; }
  2023. wxGridCellCoords GetBottomRightCoords() { return m_bottomRight; }
  2024. int GetTopRow() { return m_topLeft.GetRow(); }
  2025. int GetBottomRow() { return m_bottomRight.GetRow(); }
  2026. int GetLeftCol() { return m_topLeft.GetCol(); }
  2027. int GetRightCol() { return m_bottomRight.GetCol(); }
  2028. bool Selecting() { return m_selecting; }
  2029. virtual wxEvent *Clone() const { return new wxGridRangeSelectEvent(*this); }
  2030. protected:
  2031. void Init(const wxGridCellCoords& topLeft,
  2032. const wxGridCellCoords& bottomRight,
  2033. bool selecting)
  2034. {
  2035. m_topLeft = topLeft;
  2036. m_bottomRight = bottomRight;
  2037. m_selecting = selecting;
  2038. }
  2039. wxGridCellCoords m_topLeft;
  2040. wxGridCellCoords m_bottomRight;
  2041. bool m_selecting;
  2042. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridRangeSelectEvent)
  2043. };
  2044. class WXDLLIMPEXP_ADV wxGridEditorCreatedEvent : public wxCommandEvent
  2045. {
  2046. public:
  2047. wxGridEditorCreatedEvent()
  2048. : wxCommandEvent()
  2049. {
  2050. m_row = 0;
  2051. m_col = 0;
  2052. m_ctrl = NULL;
  2053. }
  2054. wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
  2055. int row, int col, wxControl* ctrl);
  2056. int GetRow() { return m_row; }
  2057. int GetCol() { return m_col; }
  2058. wxControl* GetControl() { return m_ctrl; }
  2059. void SetRow(int row) { m_row = row; }
  2060. void SetCol(int col) { m_col = col; }
  2061. void SetControl(wxControl* ctrl) { m_ctrl = ctrl; }
  2062. virtual wxEvent *Clone() const { return new wxGridEditorCreatedEvent(*this); }
  2063. private:
  2064. int m_row;
  2065. int m_col;
  2066. wxControl* m_ctrl;
  2067. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEditorCreatedEvent)
  2068. };
  2069. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_LEFT_CLICK, wxGridEvent );
  2070. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEvent );
  2071. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEvent );
  2072. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_RIGHT_DCLICK, wxGridEvent );
  2073. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_LEFT_CLICK, wxGridEvent );
  2074. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_RIGHT_CLICK, wxGridEvent );
  2075. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_LEFT_DCLICK, wxGridEvent );
  2076. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_RIGHT_DCLICK, wxGridEvent );
  2077. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_ROW_SIZE, wxGridSizeEvent );
  2078. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_COL_SIZE, wxGridSizeEvent );
  2079. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_COL_AUTO_SIZE, wxGridSizeEvent );
  2080. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_RANGE_SELECT, wxGridRangeSelectEvent );
  2081. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_CHANGING, wxGridEvent );
  2082. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_CHANGED, wxGridEvent );
  2083. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_SELECT_CELL, wxGridEvent );
  2084. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_EDITOR_SHOWN, wxGridEvent );
  2085. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_EDITOR_HIDDEN, wxGridEvent );
  2086. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_EDITOR_CREATED, wxGridEditorCreatedEvent );
  2087. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_BEGIN_DRAG, wxGridEvent );
  2088. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_COL_MOVE, wxGridEvent );
  2089. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_COL_SORT, wxGridEvent );
  2090. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_TABBING, wxGridEvent );
  2091. typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
  2092. typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&);
  2093. typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&);
  2094. typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction)(wxGridEditorCreatedEvent&);
  2095. #define wxGridEventHandler(func) \
  2096. wxEVENT_HANDLER_CAST(wxGridEventFunction, func)
  2097. #define wxGridSizeEventHandler(func) \
  2098. wxEVENT_HANDLER_CAST(wxGridSizeEventFunction, func)
  2099. #define wxGridRangeSelectEventHandler(func) \
  2100. wxEVENT_HANDLER_CAST(wxGridRangeSelectEventFunction, func)
  2101. #define wxGridEditorCreatedEventHandler(func) \
  2102. wxEVENT_HANDLER_CAST(wxGridEditorCreatedEventFunction, func)
  2103. #define wx__DECLARE_GRIDEVT(evt, id, fn) \
  2104. wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEventHandler(fn))
  2105. #define wx__DECLARE_GRIDSIZEEVT(evt, id, fn) \
  2106. wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridSizeEventHandler(fn))
  2107. #define wx__DECLARE_GRIDRANGESELEVT(evt, id, fn) \
  2108. wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridRangeSelectEventHandler(fn))
  2109. #define wx__DECLARE_GRIDEDITOREVT(evt, id, fn) \
  2110. wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEditorCreatedEventHandler(fn))
  2111. #define EVT_GRID_CMD_CELL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_CLICK, id, fn)
  2112. #define EVT_GRID_CMD_CELL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_CLICK, id, fn)
  2113. #define EVT_GRID_CMD_CELL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_DCLICK, id, fn)
  2114. #define EVT_GRID_CMD_CELL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_DCLICK, id, fn)
  2115. #define EVT_GRID_CMD_LABEL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_CLICK, id, fn)
  2116. #define EVT_GRID_CMD_LABEL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_CLICK, id, fn)
  2117. #define EVT_GRID_CMD_LABEL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_DCLICK, id, fn)
  2118. #define EVT_GRID_CMD_LABEL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_DCLICK, id, fn)
  2119. #define EVT_GRID_CMD_ROW_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(ROW_SIZE, id, fn)
  2120. #define EVT_GRID_CMD_COL_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(COL_SIZE, id, fn)
  2121. #define EVT_GRID_CMD_COL_AUTO_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(COL_AUTO_SIZE, id, fn)
  2122. #define EVT_GRID_CMD_COL_MOVE(id, fn) wx__DECLARE_GRIDEVT(COL_MOVE, id, fn)
  2123. #define EVT_GRID_CMD_COL_SORT(id, fn) wx__DECLARE_GRIDEVT(COL_SORT, id, fn)
  2124. #define EVT_GRID_CMD_RANGE_SELECT(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECT, id, fn)
  2125. #define EVT_GRID_CMD_CELL_CHANGING(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGING, id, fn)
  2126. #define EVT_GRID_CMD_CELL_CHANGED(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGED, id, fn)
  2127. #define EVT_GRID_CMD_SELECT_CELL(id, fn) wx__DECLARE_GRIDEVT(SELECT_CELL, id, fn)
  2128. #define EVT_GRID_CMD_EDITOR_SHOWN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_SHOWN, id, fn)
  2129. #define EVT_GRID_CMD_EDITOR_HIDDEN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_HIDDEN, id, fn)
  2130. #define EVT_GRID_CMD_EDITOR_CREATED(id, fn) wx__DECLARE_GRIDEDITOREVT(EDITOR_CREATED, id, fn)
  2131. #define EVT_GRID_CMD_CELL_BEGIN_DRAG(id, fn) wx__DECLARE_GRIDEVT(CELL_BEGIN_DRAG, id, fn)
  2132. #define EVT_GRID_CMD_TABBING(id, fn) wx__DECLARE_GRIDEVT(TABBING, id, fn)
  2133. // same as above but for any id (exists mainly for backwards compatibility but
  2134. // then it's also true that you rarely have multiple grid in the same window)
  2135. #define EVT_GRID_CELL_LEFT_CLICK(fn) EVT_GRID_CMD_CELL_LEFT_CLICK(wxID_ANY, fn)
  2136. #define EVT_GRID_CELL_RIGHT_CLICK(fn) EVT_GRID_CMD_CELL_RIGHT_CLICK(wxID_ANY, fn)
  2137. #define EVT_GRID_CELL_LEFT_DCLICK(fn) EVT_GRID_CMD_CELL_LEFT_DCLICK(wxID_ANY, fn)
  2138. #define EVT_GRID_CELL_RIGHT_DCLICK(fn) EVT_GRID_CMD_CELL_RIGHT_DCLICK(wxID_ANY, fn)
  2139. #define EVT_GRID_LABEL_LEFT_CLICK(fn) EVT_GRID_CMD_LABEL_LEFT_CLICK(wxID_ANY, fn)
  2140. #define EVT_GRID_LABEL_RIGHT_CLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_CLICK(wxID_ANY, fn)
  2141. #define EVT_GRID_LABEL_LEFT_DCLICK(fn) EVT_GRID_CMD_LABEL_LEFT_DCLICK(wxID_ANY, fn)
  2142. #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_DCLICK(wxID_ANY, fn)
  2143. #define EVT_GRID_ROW_SIZE(fn) EVT_GRID_CMD_ROW_SIZE(wxID_ANY, fn)
  2144. #define EVT_GRID_COL_SIZE(fn) EVT_GRID_CMD_COL_SIZE(wxID_ANY, fn)
  2145. #define EVT_GRID_COL_AUTO_SIZE(fn) EVT_GRID_CMD_COL_AUTO_SIZE(wxID_ANY, fn)
  2146. #define EVT_GRID_COL_MOVE(fn) EVT_GRID_CMD_COL_MOVE(wxID_ANY, fn)
  2147. #define EVT_GRID_COL_SORT(fn) EVT_GRID_CMD_COL_SORT(wxID_ANY, fn)
  2148. #define EVT_GRID_RANGE_SELECT(fn) EVT_GRID_CMD_RANGE_SELECT(wxID_ANY, fn)
  2149. #define EVT_GRID_CELL_CHANGING(fn) EVT_GRID_CMD_CELL_CHANGING(wxID_ANY, fn)
  2150. #define EVT_GRID_CELL_CHANGED(fn) EVT_GRID_CMD_CELL_CHANGED(wxID_ANY, fn)
  2151. #define EVT_GRID_SELECT_CELL(fn) EVT_GRID_CMD_SELECT_CELL(wxID_ANY, fn)
  2152. #define EVT_GRID_EDITOR_SHOWN(fn) EVT_GRID_CMD_EDITOR_SHOWN(wxID_ANY, fn)
  2153. #define EVT_GRID_EDITOR_HIDDEN(fn) EVT_GRID_CMD_EDITOR_HIDDEN(wxID_ANY, fn)
  2154. #define EVT_GRID_EDITOR_CREATED(fn) EVT_GRID_CMD_EDITOR_CREATED(wxID_ANY, fn)
  2155. #define EVT_GRID_CELL_BEGIN_DRAG(fn) EVT_GRID_CMD_CELL_BEGIN_DRAG(wxID_ANY, fn)
  2156. #define EVT_GRID_TABBING(fn) EVT_GRID_CMD_TABBING(wxID_ANY, fn)
  2157. // we used to have a single wxEVT_GRID_CELL_CHANGE event but it was split into
  2158. // wxEVT_GRID_CELL_CHANGING and CHANGED ones in wx 2.9.0, however the CHANGED
  2159. // is basically the same as the old CHANGE event so we keep the name for
  2160. // compatibility
  2161. #if WXWIN_COMPATIBILITY_2_8
  2162. #define wxEVT_GRID_CELL_CHANGE wxEVT_GRID_CELL_CHANGED
  2163. #define EVT_GRID_CMD_CELL_CHANGE EVT_GRID_CMD_CELL_CHANGED
  2164. #define EVT_GRID_CELL_CHANGE EVT_GRID_CELL_CHANGED
  2165. #endif // WXWIN_COMPATIBILITY_2_8
  2166. #if 0 // TODO: implement these ? others ?
  2167. extern const int wxEVT_GRID_CREATE_CELL;
  2168. extern const int wxEVT_GRID_CHANGE_LABELS;
  2169. extern const int wxEVT_GRID_CHANGE_SEL_LABEL;
  2170. #define EVT_GRID_CREATE_CELL(fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CREATE_CELL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
  2171. #define EVT_GRID_CHANGE_LABELS(fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_LABELS, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
  2172. #define EVT_GRID_CHANGE_SEL_LABEL(fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_SEL_LABEL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
  2173. #endif
  2174. #endif // wxUSE_GRID
  2175. #endif // _WX_GENERIC_GRID_H_