| 1 | /////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: generic/grid.cpp |
| 3 | // Purpose: wxGrid and related classes |
| 4 | // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn) |
| 5 | // Modified by: Robin Dunn, Vadim Zeitlin |
| 6 | // Created: 1/08/1999 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) Michael Bedward (mbedward@ozemail.com.au) |
| 9 | // Licence: wxWindows licence |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | // ============================================================================ |
| 13 | // declarations |
| 14 | // ============================================================================ |
| 15 | |
| 16 | // ---------------------------------------------------------------------------- |
| 17 | // headers |
| 18 | // ---------------------------------------------------------------------------- |
| 19 | |
| 20 | // For compilers that support precompilatixon, includes "wx/wx.h". |
| 21 | #include "wx/wxprec.h" |
| 22 | |
| 23 | #include "wx/defs.h" |
| 24 | |
| 25 | #ifdef __BORLANDC__ |
| 26 | #pragma hdrstop |
| 27 | #endif |
| 28 | |
| 29 | #if wxUSE_GRID |
| 30 | |
| 31 | #ifndef WX_PRECOMP |
| 32 | #include "wx/utils.h" |
| 33 | #include "wx/dcclient.h" |
| 34 | #include "wx/settings.h" |
| 35 | #include "wx/log.h" |
| 36 | #include "wx/textctrl.h" |
| 37 | #include "wx/checkbox.h" |
| 38 | #include "wx/combobox.h" |
| 39 | #include "wx/valtext.h" |
| 40 | #include "wx/intl.h" |
| 41 | #include "wx/math.h" |
| 42 | #endif |
| 43 | |
| 44 | #include "wx/textfile.h" |
| 45 | #include "wx/spinctrl.h" |
| 46 | #include "wx/tokenzr.h" |
| 47 | #include "wx/renderer.h" |
| 48 | |
| 49 | #include "wx/grid.h" |
| 50 | #include "wx/generic/gridsel.h" |
| 51 | |
| 52 | #if defined(__WXMOTIF__) |
| 53 | #define WXUNUSED_MOTIF(identifier) WXUNUSED(identifier) |
| 54 | #else |
| 55 | #define WXUNUSED_MOTIF(identifier) identifier |
| 56 | #endif |
| 57 | |
| 58 | #if defined(__WXGTK__) |
| 59 | #define WXUNUSED_GTK(identifier) WXUNUSED(identifier) |
| 60 | #else |
| 61 | #define WXUNUSED_GTK(identifier) identifier |
| 62 | #endif |
| 63 | |
| 64 | // Required for wxIs... functions |
| 65 | #include <ctype.h> |
| 66 | |
| 67 | // ---------------------------------------------------------------------------- |
| 68 | // array classes |
| 69 | // ---------------------------------------------------------------------------- |
| 70 | |
| 71 | WX_DEFINE_ARRAY_WITH_DECL_PTR(wxGridCellAttr *, wxArrayAttrs, |
| 72 | class WXDLLIMPEXP_ADV); |
| 73 | |
| 74 | struct wxGridCellWithAttr |
| 75 | { |
| 76 | wxGridCellWithAttr(int row, int col, wxGridCellAttr *attr_) |
| 77 | : coords(row, col), attr(attr_) |
| 78 | { |
| 79 | } |
| 80 | |
| 81 | ~wxGridCellWithAttr() |
| 82 | { |
| 83 | attr->DecRef(); |
| 84 | } |
| 85 | |
| 86 | wxGridCellCoords coords; |
| 87 | wxGridCellAttr *attr; |
| 88 | |
| 89 | // Cannot do this: |
| 90 | // DECLARE_NO_COPY_CLASS(wxGridCellWithAttr) |
| 91 | // without rewriting the macros, which require a public copy constructor. |
| 92 | }; |
| 93 | |
| 94 | WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellWithAttr, wxGridCellWithAttrArray, |
| 95 | class WXDLLIMPEXP_ADV); |
| 96 | |
| 97 | #include "wx/arrimpl.cpp" |
| 98 | |
| 99 | WX_DEFINE_OBJARRAY(wxGridCellCoordsArray) |
| 100 | WX_DEFINE_OBJARRAY(wxGridCellWithAttrArray) |
| 101 | |
| 102 | // ---------------------------------------------------------------------------- |
| 103 | // events |
| 104 | // ---------------------------------------------------------------------------- |
| 105 | |
| 106 | DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_CLICK) |
| 107 | DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_CLICK) |
| 108 | DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_DCLICK) |
| 109 | DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_DCLICK) |
| 110 | DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_BEGIN_DRAG) |
| 111 | DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_CLICK) |
| 112 | DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_CLICK) |
| 113 | DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_DCLICK) |
| 114 | DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_DCLICK) |
| 115 | DEFINE_EVENT_TYPE(wxEVT_GRID_ROW_SIZE) |
| 116 | DEFINE_EVENT_TYPE(wxEVT_GRID_COL_SIZE) |
| 117 | DEFINE_EVENT_TYPE(wxEVT_GRID_RANGE_SELECT) |
| 118 | DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_CHANGE) |
| 119 | DEFINE_EVENT_TYPE(wxEVT_GRID_SELECT_CELL) |
| 120 | DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_SHOWN) |
| 121 | DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_HIDDEN) |
| 122 | DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_CREATED) |
| 123 | |
| 124 | // ---------------------------------------------------------------------------- |
| 125 | // private classes |
| 126 | // ---------------------------------------------------------------------------- |
| 127 | |
| 128 | class WXDLLIMPEXP_ADV wxGridRowLabelWindow : public wxWindow |
| 129 | { |
| 130 | public: |
| 131 | wxGridRowLabelWindow() { m_owner = (wxGrid *)NULL; } |
| 132 | wxGridRowLabelWindow( wxGrid *parent, wxWindowID id, |
| 133 | const wxPoint &pos, const wxSize &size ); |
| 134 | |
| 135 | private: |
| 136 | wxGrid *m_owner; |
| 137 | |
| 138 | void OnPaint( wxPaintEvent& event ); |
| 139 | void OnMouseEvent( wxMouseEvent& event ); |
| 140 | void OnMouseWheel( wxMouseEvent& event ); |
| 141 | void OnKeyDown( wxKeyEvent& event ); |
| 142 | void OnKeyUp( wxKeyEvent& ); |
| 143 | void OnChar( wxKeyEvent& ); |
| 144 | |
| 145 | DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow) |
| 146 | DECLARE_EVENT_TABLE() |
| 147 | DECLARE_NO_COPY_CLASS(wxGridRowLabelWindow) |
| 148 | }; |
| 149 | |
| 150 | |
| 151 | class WXDLLIMPEXP_ADV wxGridColLabelWindow : public wxWindow |
| 152 | { |
| 153 | public: |
| 154 | wxGridColLabelWindow() { m_owner = (wxGrid *)NULL; } |
| 155 | wxGridColLabelWindow( wxGrid *parent, wxWindowID id, |
| 156 | const wxPoint &pos, const wxSize &size ); |
| 157 | |
| 158 | private: |
| 159 | wxGrid *m_owner; |
| 160 | |
| 161 | void OnPaint( wxPaintEvent &event ); |
| 162 | void OnMouseEvent( wxMouseEvent& event ); |
| 163 | void OnMouseWheel( wxMouseEvent& event ); |
| 164 | void OnKeyDown( wxKeyEvent& event ); |
| 165 | void OnKeyUp( wxKeyEvent& ); |
| 166 | void OnChar( wxKeyEvent& ); |
| 167 | |
| 168 | DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow) |
| 169 | DECLARE_EVENT_TABLE() |
| 170 | DECLARE_NO_COPY_CLASS(wxGridColLabelWindow) |
| 171 | }; |
| 172 | |
| 173 | |
| 174 | class WXDLLIMPEXP_ADV wxGridCornerLabelWindow : public wxWindow |
| 175 | { |
| 176 | public: |
| 177 | wxGridCornerLabelWindow() { m_owner = (wxGrid *)NULL; } |
| 178 | wxGridCornerLabelWindow( wxGrid *parent, wxWindowID id, |
| 179 | const wxPoint &pos, const wxSize &size ); |
| 180 | |
| 181 | private: |
| 182 | wxGrid *m_owner; |
| 183 | |
| 184 | void OnMouseEvent( wxMouseEvent& event ); |
| 185 | void OnMouseWheel( wxMouseEvent& event ); |
| 186 | void OnKeyDown( wxKeyEvent& event ); |
| 187 | void OnKeyUp( wxKeyEvent& ); |
| 188 | void OnChar( wxKeyEvent& ); |
| 189 | void OnPaint( wxPaintEvent& event ); |
| 190 | |
| 191 | DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow) |
| 192 | DECLARE_EVENT_TABLE() |
| 193 | DECLARE_NO_COPY_CLASS(wxGridCornerLabelWindow) |
| 194 | }; |
| 195 | |
| 196 | class WXDLLIMPEXP_ADV wxGridWindow : public wxWindow |
| 197 | { |
| 198 | public: |
| 199 | wxGridWindow() |
| 200 | { |
| 201 | m_owner = (wxGrid *)NULL; |
| 202 | m_rowLabelWin = (wxGridRowLabelWindow *)NULL; |
| 203 | m_colLabelWin = (wxGridColLabelWindow *)NULL; |
| 204 | } |
| 205 | |
| 206 | wxGridWindow( wxGrid *parent, |
| 207 | wxGridRowLabelWindow *rowLblWin, |
| 208 | wxGridColLabelWindow *colLblWin, |
| 209 | wxWindowID id, const wxPoint &pos, const wxSize &size ); |
| 210 | ~wxGridWindow() {} |
| 211 | |
| 212 | void ScrollWindow( int dx, int dy, const wxRect *rect ); |
| 213 | |
| 214 | wxGrid* GetOwner() { return m_owner; } |
| 215 | |
| 216 | private: |
| 217 | wxGrid *m_owner; |
| 218 | wxGridRowLabelWindow *m_rowLabelWin; |
| 219 | wxGridColLabelWindow *m_colLabelWin; |
| 220 | |
| 221 | void OnPaint( wxPaintEvent &event ); |
| 222 | void OnMouseWheel( wxMouseEvent& event ); |
| 223 | void OnMouseEvent( wxMouseEvent& event ); |
| 224 | void OnKeyDown( wxKeyEvent& ); |
| 225 | void OnKeyUp( wxKeyEvent& ); |
| 226 | void OnChar( wxKeyEvent& ); |
| 227 | void OnEraseBackground( wxEraseEvent& ); |
| 228 | void OnFocus( wxFocusEvent& ); |
| 229 | |
| 230 | DECLARE_DYNAMIC_CLASS(wxGridWindow) |
| 231 | DECLARE_EVENT_TABLE() |
| 232 | DECLARE_NO_COPY_CLASS(wxGridWindow) |
| 233 | }; |
| 234 | |
| 235 | |
| 236 | class wxGridCellEditorEvtHandler : public wxEvtHandler |
| 237 | { |
| 238 | public: |
| 239 | wxGridCellEditorEvtHandler(wxGrid* grid, wxGridCellEditor* editor) |
| 240 | : m_grid(grid), |
| 241 | m_editor(editor), |
| 242 | m_inSetFocus(false) |
| 243 | { |
| 244 | } |
| 245 | |
| 246 | void OnKillFocus(wxFocusEvent& event); |
| 247 | void OnKeyDown(wxKeyEvent& event); |
| 248 | void OnChar(wxKeyEvent& event); |
| 249 | |
| 250 | void SetInSetFocus(bool inSetFocus) { m_inSetFocus = inSetFocus; } |
| 251 | |
| 252 | private: |
| 253 | wxGrid* m_grid; |
| 254 | wxGridCellEditor* m_editor; |
| 255 | |
| 256 | // Work around the fact that a focus kill event can be sent to |
| 257 | // a combobox within a set focus event. |
| 258 | bool m_inSetFocus; |
| 259 | |
| 260 | DECLARE_EVENT_TABLE() |
| 261 | DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler) |
| 262 | DECLARE_NO_COPY_CLASS(wxGridCellEditorEvtHandler) |
| 263 | }; |
| 264 | |
| 265 | |
| 266 | IMPLEMENT_ABSTRACT_CLASS(wxGridCellEditorEvtHandler, wxEvtHandler) |
| 267 | |
| 268 | BEGIN_EVENT_TABLE( wxGridCellEditorEvtHandler, wxEvtHandler ) |
| 269 | EVT_KILL_FOCUS( wxGridCellEditorEvtHandler::OnKillFocus ) |
| 270 | EVT_KEY_DOWN( wxGridCellEditorEvtHandler::OnKeyDown ) |
| 271 | EVT_CHAR( wxGridCellEditorEvtHandler::OnChar ) |
| 272 | END_EVENT_TABLE() |
| 273 | |
| 274 | |
| 275 | |
| 276 | // ---------------------------------------------------------------------------- |
| 277 | // the internal data representation used by wxGridCellAttrProvider |
| 278 | // ---------------------------------------------------------------------------- |
| 279 | |
| 280 | // this class stores attributes set for cells |
| 281 | class WXDLLIMPEXP_ADV wxGridCellAttrData |
| 282 | { |
| 283 | public: |
| 284 | void SetAttr(wxGridCellAttr *attr, int row, int col); |
| 285 | wxGridCellAttr *GetAttr(int row, int col) const; |
| 286 | void UpdateAttrRows( size_t pos, int numRows ); |
| 287 | void UpdateAttrCols( size_t pos, int numCols ); |
| 288 | |
| 289 | private: |
| 290 | // searches for the attr for given cell, returns wxNOT_FOUND if not found |
| 291 | int FindIndex(int row, int col) const; |
| 292 | |
| 293 | wxGridCellWithAttrArray m_attrs; |
| 294 | }; |
| 295 | |
| 296 | // this class stores attributes set for rows or columns |
| 297 | class WXDLLIMPEXP_ADV wxGridRowOrColAttrData |
| 298 | { |
| 299 | public: |
| 300 | // empty ctor to suppress warnings |
| 301 | wxGridRowOrColAttrData() { } |
| 302 | ~wxGridRowOrColAttrData(); |
| 303 | |
| 304 | void SetAttr(wxGridCellAttr *attr, int rowOrCol); |
| 305 | wxGridCellAttr *GetAttr(int rowOrCol) const; |
| 306 | void UpdateAttrRowsOrCols( size_t pos, int numRowsOrCols ); |
| 307 | |
| 308 | private: |
| 309 | wxArrayInt m_rowsOrCols; |
| 310 | wxArrayAttrs m_attrs; |
| 311 | }; |
| 312 | |
| 313 | // NB: this is just a wrapper around 3 objects: one which stores cell |
| 314 | // attributes, and 2 others for row/col ones |
| 315 | class WXDLLIMPEXP_ADV wxGridCellAttrProviderData |
| 316 | { |
| 317 | public: |
| 318 | wxGridCellAttrData m_cellAttrs; |
| 319 | wxGridRowOrColAttrData m_rowAttrs, |
| 320 | m_colAttrs; |
| 321 | }; |
| 322 | |
| 323 | |
| 324 | // ---------------------------------------------------------------------------- |
| 325 | // data structures used for the data type registry |
| 326 | // ---------------------------------------------------------------------------- |
| 327 | |
| 328 | struct wxGridDataTypeInfo |
| 329 | { |
| 330 | wxGridDataTypeInfo(const wxString& typeName, |
| 331 | wxGridCellRenderer* renderer, |
| 332 | wxGridCellEditor* editor) |
| 333 | : m_typeName(typeName), m_renderer(renderer), m_editor(editor) |
| 334 | { } |
| 335 | |
| 336 | ~wxGridDataTypeInfo() |
| 337 | { |
| 338 | wxSafeDecRef(m_renderer); |
| 339 | wxSafeDecRef(m_editor); |
| 340 | } |
| 341 | |
| 342 | wxString m_typeName; |
| 343 | wxGridCellRenderer* m_renderer; |
| 344 | wxGridCellEditor* m_editor; |
| 345 | |
| 346 | DECLARE_NO_COPY_CLASS(wxGridDataTypeInfo) |
| 347 | }; |
| 348 | |
| 349 | |
| 350 | WX_DEFINE_ARRAY_WITH_DECL_PTR(wxGridDataTypeInfo*, wxGridDataTypeInfoArray, |
| 351 | class WXDLLIMPEXP_ADV); |
| 352 | |
| 353 | |
| 354 | class WXDLLIMPEXP_ADV wxGridTypeRegistry |
| 355 | { |
| 356 | public: |
| 357 | wxGridTypeRegistry() {} |
| 358 | ~wxGridTypeRegistry(); |
| 359 | |
| 360 | void RegisterDataType(const wxString& typeName, |
| 361 | wxGridCellRenderer* renderer, |
| 362 | wxGridCellEditor* editor); |
| 363 | |
| 364 | // find one of already registered data types |
| 365 | int FindRegisteredDataType(const wxString& typeName); |
| 366 | |
| 367 | // try to FindRegisteredDataType(), if this fails and typeName is one of |
| 368 | // standard typenames, register it and return its index |
| 369 | int FindDataType(const wxString& typeName); |
| 370 | |
| 371 | // try to FindDataType(), if it fails see if it is not one of already |
| 372 | // registered data types with some params in which case clone the |
| 373 | // registered data type and set params for it |
| 374 | int FindOrCloneDataType(const wxString& typeName); |
| 375 | |
| 376 | wxGridCellRenderer* GetRenderer(int index); |
| 377 | wxGridCellEditor* GetEditor(int index); |
| 378 | |
| 379 | private: |
| 380 | wxGridDataTypeInfoArray m_typeinfo; |
| 381 | }; |
| 382 | |
| 383 | // ---------------------------------------------------------------------------- |
| 384 | // conditional compilation |
| 385 | // ---------------------------------------------------------------------------- |
| 386 | |
| 387 | #ifndef WXGRID_DRAW_LINES |
| 388 | #define WXGRID_DRAW_LINES 1 |
| 389 | #endif |
| 390 | |
| 391 | // ---------------------------------------------------------------------------- |
| 392 | // globals |
| 393 | // ---------------------------------------------------------------------------- |
| 394 | |
| 395 | //#define DEBUG_ATTR_CACHE |
| 396 | #ifdef DEBUG_ATTR_CACHE |
| 397 | static size_t gs_nAttrCacheHits = 0; |
| 398 | static size_t gs_nAttrCacheMisses = 0; |
| 399 | #endif // DEBUG_ATTR_CACHE |
| 400 | |
| 401 | // ---------------------------------------------------------------------------- |
| 402 | // constants |
| 403 | // ---------------------------------------------------------------------------- |
| 404 | |
| 405 | wxGridCellCoords wxGridNoCellCoords( -1, -1 ); |
| 406 | wxRect wxGridNoCellRect( -1, -1, -1, -1 ); |
| 407 | |
| 408 | // scroll line size |
| 409 | // TODO: this doesn't work at all, grid cells have different sizes and approx |
| 410 | // calculations don't work as because of the size mismatch scrollbars |
| 411 | // sometimes fail to be shown when they should be or vice versa |
| 412 | // |
| 413 | // The scroll bars may be a little flakey once in a while, but that is |
| 414 | // surely much less horrible than having scroll lines of only 1!!! |
| 415 | // -- Robin |
| 416 | // |
| 417 | // Well, it's still seriously broken so it might be better but needs |
| 418 | // fixing anyhow |
| 419 | // -- Vadim |
| 420 | static const size_t GRID_SCROLL_LINE_X = 15; // 1; |
| 421 | static const size_t GRID_SCROLL_LINE_Y = GRID_SCROLL_LINE_X; |
| 422 | |
| 423 | // the size of hash tables used a bit everywhere (the max number of elements |
| 424 | // in these hash tables is the number of rows/columns) |
| 425 | static const int GRID_HASH_SIZE = 100; |
| 426 | |
| 427 | #if 0 |
| 428 | // ---------------------------------------------------------------------------- |
| 429 | // private functions |
| 430 | // ---------------------------------------------------------------------------- |
| 431 | |
| 432 | static inline int GetScrollX(int x) |
| 433 | { |
| 434 | return (x + GRID_SCROLL_LINE_X - 1) / GRID_SCROLL_LINE_X; |
| 435 | } |
| 436 | |
| 437 | static inline int GetScrollY(int y) |
| 438 | { |
| 439 | return (y + GRID_SCROLL_LINE_Y - 1) / GRID_SCROLL_LINE_Y; |
| 440 | } |
| 441 | #endif |
| 442 | |
| 443 | // ============================================================================ |
| 444 | // implementation |
| 445 | // ============================================================================ |
| 446 | |
| 447 | // ---------------------------------------------------------------------------- |
| 448 | // wxGridCellEditor |
| 449 | // ---------------------------------------------------------------------------- |
| 450 | |
| 451 | wxGridCellEditor::wxGridCellEditor() |
| 452 | { |
| 453 | m_control = NULL; |
| 454 | m_attr = NULL; |
| 455 | } |
| 456 | |
| 457 | |
| 458 | wxGridCellEditor::~wxGridCellEditor() |
| 459 | { |
| 460 | Destroy(); |
| 461 | } |
| 462 | |
| 463 | void wxGridCellEditor::Create(wxWindow* WXUNUSED(parent), |
| 464 | wxWindowID WXUNUSED(id), |
| 465 | wxEvtHandler* evtHandler) |
| 466 | { |
| 467 | if ( evtHandler ) |
| 468 | m_control->PushEventHandler(evtHandler); |
| 469 | } |
| 470 | |
| 471 | void wxGridCellEditor::PaintBackground(const wxRect& rectCell, |
| 472 | wxGridCellAttr *attr) |
| 473 | { |
| 474 | // erase the background because we might not fill the cell |
| 475 | wxClientDC dc(m_control->GetParent()); |
| 476 | wxGridWindow* gridWindow = wxDynamicCast(m_control->GetParent(), wxGridWindow); |
| 477 | if (gridWindow) |
| 478 | gridWindow->GetOwner()->PrepareDC(dc); |
| 479 | |
| 480 | dc.SetPen(*wxTRANSPARENT_PEN); |
| 481 | dc.SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID)); |
| 482 | dc.DrawRectangle(rectCell); |
| 483 | |
| 484 | // redraw the control we just painted over |
| 485 | m_control->Refresh(); |
| 486 | } |
| 487 | |
| 488 | void wxGridCellEditor::Destroy() |
| 489 | { |
| 490 | if (m_control) |
| 491 | { |
| 492 | m_control->PopEventHandler(true /* delete it*/); |
| 493 | |
| 494 | m_control->Destroy(); |
| 495 | m_control = NULL; |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | void wxGridCellEditor::Show(bool show, wxGridCellAttr *attr) |
| 500 | { |
| 501 | wxASSERT_MSG(m_control, |
| 502 | wxT("The wxGridCellEditor must be Created first!")); |
| 503 | m_control->Show(show); |
| 504 | |
| 505 | if ( show ) |
| 506 | { |
| 507 | // set the colours/fonts if we have any |
| 508 | if ( attr ) |
| 509 | { |
| 510 | m_colFgOld = m_control->GetForegroundColour(); |
| 511 | m_control->SetForegroundColour(attr->GetTextColour()); |
| 512 | |
| 513 | m_colBgOld = m_control->GetBackgroundColour(); |
| 514 | m_control->SetBackgroundColour(attr->GetBackgroundColour()); |
| 515 | |
| 516 | // Workaround for GTK+1 font setting problem on some platforms |
| 517 | #if !defined(__WXGTK__) || defined(__WXGTK20__) |
| 518 | m_fontOld = m_control->GetFont(); |
| 519 | m_control->SetFont(attr->GetFont()); |
| 520 | #endif |
| 521 | // can't do anything more in the base class version, the other |
| 522 | // attributes may only be used by the derived classes |
| 523 | } |
| 524 | } |
| 525 | else |
| 526 | { |
| 527 | // restore the standard colours fonts |
| 528 | if ( m_colFgOld.Ok() ) |
| 529 | { |
| 530 | m_control->SetForegroundColour(m_colFgOld); |
| 531 | m_colFgOld = wxNullColour; |
| 532 | } |
| 533 | |
| 534 | if ( m_colBgOld.Ok() ) |
| 535 | { |
| 536 | m_control->SetBackgroundColour(m_colBgOld); |
| 537 | m_colBgOld = wxNullColour; |
| 538 | } |
| 539 | // Workaround for GTK+1 font setting problem on some platforms |
| 540 | #if !defined(__WXGTK__) || defined(__WXGTK20__) |
| 541 | if ( m_fontOld.Ok() ) |
| 542 | { |
| 543 | m_control->SetFont(m_fontOld); |
| 544 | m_fontOld = wxNullFont; |
| 545 | } |
| 546 | #endif |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | void wxGridCellEditor::SetSize(const wxRect& rect) |
| 551 | { |
| 552 | wxASSERT_MSG(m_control, |
| 553 | wxT("The wxGridCellEditor must be Created first!")); |
| 554 | m_control->SetSize(rect, wxSIZE_ALLOW_MINUS_ONE); |
| 555 | } |
| 556 | |
| 557 | void wxGridCellEditor::HandleReturn(wxKeyEvent& event) |
| 558 | { |
| 559 | event.Skip(); |
| 560 | } |
| 561 | |
| 562 | bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event) |
| 563 | { |
| 564 | bool ctrl = event.ControlDown(); |
| 565 | bool alt = event.AltDown(); |
| 566 | #ifdef __WXMAC__ |
| 567 | // On the Mac the Alt key is more like shift and is used for entry of |
| 568 | // valid characters, so check for Ctrl and Meta instead. |
| 569 | alt = event.MetaDown(); |
| 570 | #endif |
| 571 | |
| 572 | // Assume it's not a valid char if ctrl or alt is down, but if both are |
| 573 | // down then it may be because of an AltGr key combination, so let them |
| 574 | // through in that case. |
| 575 | if ((ctrl || alt) && !(ctrl && alt)) |
| 576 | return false; |
| 577 | |
| 578 | #if wxUSE_UNICODE |
| 579 | int key = event.GetUnicodeKey(); |
| 580 | bool keyOk = true; |
| 581 | |
| 582 | // if the unicode key code is not really a unicode character (it may |
| 583 | // be a function key or etc., the platforms appear to always give us a |
| 584 | // small value in this case) then fallback to the ascii key code but |
| 585 | // don't do anything for function keys or etc. |
| 586 | if (key <= 127) |
| 587 | { |
| 588 | key = event.GetKeyCode(); |
| 589 | keyOk = (key <= 127); |
| 590 | } |
| 591 | return keyOk; |
| 592 | #else // !wxUSE_UNICODE |
| 593 | int key = event.GetKeyCode(); |
| 594 | if (key <= 255) |
| 595 | return true; |
| 596 | return false; |
| 597 | #endif // wxUSE_UNICODE/!wxUSE_UNICODE |
| 598 | } |
| 599 | |
| 600 | void wxGridCellEditor::StartingKey(wxKeyEvent& event) |
| 601 | { |
| 602 | event.Skip(); |
| 603 | } |
| 604 | |
| 605 | void wxGridCellEditor::StartingClick() |
| 606 | { |
| 607 | } |
| 608 | |
| 609 | #if wxUSE_TEXTCTRL |
| 610 | |
| 611 | // ---------------------------------------------------------------------------- |
| 612 | // wxGridCellTextEditor |
| 613 | // ---------------------------------------------------------------------------- |
| 614 | |
| 615 | wxGridCellTextEditor::wxGridCellTextEditor() |
| 616 | { |
| 617 | m_maxChars = 0; |
| 618 | } |
| 619 | |
| 620 | void wxGridCellTextEditor::Create(wxWindow* parent, |
| 621 | wxWindowID id, |
| 622 | wxEvtHandler* evtHandler) |
| 623 | { |
| 624 | m_control = new wxTextCtrl(parent, id, wxEmptyString, |
| 625 | wxDefaultPosition, wxDefaultSize |
| 626 | #if defined(__WXMSW__) |
| 627 | , wxTE_PROCESS_TAB | wxTE_AUTO_SCROLL |
| 628 | #endif |
| 629 | ); |
| 630 | |
| 631 | // set max length allowed in the textctrl, if the parameter was set |
| 632 | if (m_maxChars != 0) |
| 633 | { |
| 634 | ((wxTextCtrl*)m_control)->SetMaxLength(m_maxChars); |
| 635 | } |
| 636 | |
| 637 | wxGridCellEditor::Create(parent, id, evtHandler); |
| 638 | } |
| 639 | |
| 640 | void wxGridCellTextEditor::PaintBackground(const wxRect& WXUNUSED(rectCell), |
| 641 | wxGridCellAttr * WXUNUSED(attr)) |
| 642 | { |
| 643 | // as we fill the entire client area, don't do anything here to minimize |
| 644 | // flicker |
| 645 | } |
| 646 | |
| 647 | void wxGridCellTextEditor::SetSize(const wxRect& rectOrig) |
| 648 | { |
| 649 | wxRect rect(rectOrig); |
| 650 | |
| 651 | // Make the edit control large enough to allow for internal |
| 652 | // margins |
| 653 | // |
| 654 | // TODO: remove this if the text ctrl sizing is improved esp. for |
| 655 | // unix |
| 656 | // |
| 657 | #if defined(__WXGTK__) |
| 658 | if (rect.x != 0) |
| 659 | { |
| 660 | rect.x += 1; |
| 661 | rect.y += 1; |
| 662 | rect.width -= 1; |
| 663 | rect.height -= 1; |
| 664 | } |
| 665 | #else // !GTK |
| 666 | int extra_x = ( rect.x > 2 )? 2 : 1; |
| 667 | |
| 668 | // MB: treat MSW separately here otherwise the caret doesn't show |
| 669 | // when the editor is in the first row. |
| 670 | #if defined(__WXMSW__) |
| 671 | int extra_y = 2; |
| 672 | #else |
| 673 | int extra_y = ( rect.y > 2 )? 2 : 1; |
| 674 | #endif // MSW |
| 675 | |
| 676 | #if defined(__WXMOTIF__) |
| 677 | extra_x *= 2; |
| 678 | extra_y *= 2; |
| 679 | #endif |
| 680 | rect.SetLeft( wxMax(0, rect.x - extra_x) ); |
| 681 | rect.SetTop( wxMax(0, rect.y - extra_y) ); |
| 682 | rect.SetRight( rect.GetRight() + 2*extra_x ); |
| 683 | rect.SetBottom( rect.GetBottom() + 2*extra_y ); |
| 684 | #endif // GTK/!GTK |
| 685 | |
| 686 | wxGridCellEditor::SetSize(rect); |
| 687 | } |
| 688 | |
| 689 | void wxGridCellTextEditor::BeginEdit(int row, int col, wxGrid* grid) |
| 690 | { |
| 691 | wxASSERT_MSG(m_control, |
| 692 | wxT("The wxGridCellEditor must be Created first!")); |
| 693 | |
| 694 | m_startValue = grid->GetTable()->GetValue(row, col); |
| 695 | |
| 696 | DoBeginEdit(m_startValue); |
| 697 | } |
| 698 | |
| 699 | void wxGridCellTextEditor::DoBeginEdit(const wxString& startValue) |
| 700 | { |
| 701 | Text()->SetValue(startValue); |
| 702 | Text()->SetInsertionPointEnd(); |
| 703 | Text()->SetSelection(-1,-1); |
| 704 | Text()->SetFocus(); |
| 705 | } |
| 706 | |
| 707 | bool wxGridCellTextEditor::EndEdit(int row, int col, |
| 708 | wxGrid* grid) |
| 709 | { |
| 710 | wxASSERT_MSG(m_control, |
| 711 | wxT("The wxGridCellEditor must be Created first!")); |
| 712 | |
| 713 | bool changed = false; |
| 714 | wxString value = Text()->GetValue(); |
| 715 | if (value != m_startValue) |
| 716 | changed = true; |
| 717 | |
| 718 | if (changed) |
| 719 | grid->GetTable()->SetValue(row, col, value); |
| 720 | |
| 721 | m_startValue = wxEmptyString; |
| 722 | // No point in setting the text of the hidden control |
| 723 | //Text()->SetValue(m_startValue); |
| 724 | |
| 725 | return changed; |
| 726 | } |
| 727 | |
| 728 | |
| 729 | void wxGridCellTextEditor::Reset() |
| 730 | { |
| 731 | wxASSERT_MSG(m_control, |
| 732 | wxT("The wxGridCellEditor must be Created first!")); |
| 733 | |
| 734 | DoReset(m_startValue); |
| 735 | } |
| 736 | |
| 737 | void wxGridCellTextEditor::DoReset(const wxString& startValue) |
| 738 | { |
| 739 | Text()->SetValue(startValue); |
| 740 | Text()->SetInsertionPointEnd(); |
| 741 | } |
| 742 | |
| 743 | bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent& event) |
| 744 | { |
| 745 | return wxGridCellEditor::IsAcceptedKey(event); |
| 746 | } |
| 747 | |
| 748 | void wxGridCellTextEditor::StartingKey(wxKeyEvent& event) |
| 749 | { |
| 750 | // Since this is now happening in the EVT_CHAR event EmulateKeyPress is no |
| 751 | // longer an appropriate way to get the character into the text control. |
| 752 | // Do it ourselves instead. We know that if we get this far that we have |
| 753 | // a valid character, so not a whole lot of testing needs to be done. |
| 754 | |
| 755 | wxTextCtrl* tc = Text(); |
| 756 | wxChar ch; |
| 757 | long pos; |
| 758 | |
| 759 | #if wxUSE_UNICODE |
| 760 | ch = event.GetUnicodeKey(); |
| 761 | if (ch <= 127) |
| 762 | ch = (wxChar)event.GetKeyCode(); |
| 763 | #else |
| 764 | ch = (wxChar)event.GetKeyCode(); |
| 765 | #endif |
| 766 | switch (ch) |
| 767 | { |
| 768 | case WXK_DELETE: |
| 769 | // delete the character at the cursor |
| 770 | pos = tc->GetInsertionPoint(); |
| 771 | if (pos < tc->GetLastPosition()) |
| 772 | tc->Remove(pos, pos+1); |
| 773 | break; |
| 774 | |
| 775 | case WXK_BACK: |
| 776 | // delete the character before the cursor |
| 777 | pos = tc->GetInsertionPoint(); |
| 778 | if (pos > 0) |
| 779 | tc->Remove(pos-1, pos); |
| 780 | break; |
| 781 | |
| 782 | default: |
| 783 | tc->WriteText(ch); |
| 784 | break; |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | void wxGridCellTextEditor::HandleReturn( wxKeyEvent& |
| 789 | WXUNUSED_GTK(WXUNUSED_MOTIF(event)) ) |
| 790 | { |
| 791 | #if defined(__WXMOTIF__) || defined(__WXGTK__) |
| 792 | // wxMotif needs a little extra help... |
| 793 | size_t pos = (size_t)( Text()->GetInsertionPoint() ); |
| 794 | wxString s( Text()->GetValue() ); |
| 795 | s = s.Left(pos) + wxT("\n") + s.Mid(pos); |
| 796 | Text()->SetValue(s); |
| 797 | Text()->SetInsertionPoint( pos ); |
| 798 | #else |
| 799 | // the other ports can handle a Return key press |
| 800 | // |
| 801 | event.Skip(); |
| 802 | #endif |
| 803 | } |
| 804 | |
| 805 | void wxGridCellTextEditor::SetParameters(const wxString& params) |
| 806 | { |
| 807 | if ( !params ) |
| 808 | { |
| 809 | // reset to default |
| 810 | m_maxChars = 0; |
| 811 | } |
| 812 | else |
| 813 | { |
| 814 | long tmp; |
| 815 | if ( !params.ToLong(&tmp) ) |
| 816 | { |
| 817 | wxLogDebug(_T("Invalid wxGridCellTextEditor parameter string '%s' ignored"), params.c_str()); |
| 818 | } |
| 819 | else |
| 820 | { |
| 821 | m_maxChars = (size_t)tmp; |
| 822 | } |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | // return the value in the text control |
| 827 | wxString wxGridCellTextEditor::GetValue() const |
| 828 | { |
| 829 | return Text()->GetValue(); |
| 830 | } |
| 831 | |
| 832 | // ---------------------------------------------------------------------------- |
| 833 | // wxGridCellNumberEditor |
| 834 | // ---------------------------------------------------------------------------- |
| 835 | |
| 836 | wxGridCellNumberEditor::wxGridCellNumberEditor(int min, int max) |
| 837 | { |
| 838 | m_min = min; |
| 839 | m_max = max; |
| 840 | } |
| 841 | |
| 842 | void wxGridCellNumberEditor::Create(wxWindow* parent, |
| 843 | wxWindowID id, |
| 844 | wxEvtHandler* evtHandler) |
| 845 | { |
| 846 | #if wxUSE_SPINCTRL |
| 847 | if ( HasRange() ) |
| 848 | { |
| 849 | // create a spin ctrl |
| 850 | m_control = new wxSpinCtrl(parent, wxID_ANY, wxEmptyString, |
| 851 | wxDefaultPosition, wxDefaultSize, |
| 852 | wxSP_ARROW_KEYS, |
| 853 | m_min, m_max); |
| 854 | |
| 855 | wxGridCellEditor::Create(parent, id, evtHandler); |
| 856 | } |
| 857 | else |
| 858 | #endif |
| 859 | { |
| 860 | // just a text control |
| 861 | wxGridCellTextEditor::Create(parent, id, evtHandler); |
| 862 | |
| 863 | #if wxUSE_VALIDATORS |
| 864 | Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); |
| 865 | #endif // wxUSE_VALIDATORS |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | void wxGridCellNumberEditor::BeginEdit(int row, int col, wxGrid* grid) |
| 870 | { |
| 871 | // first get the value |
| 872 | wxGridTableBase *table = grid->GetTable(); |
| 873 | if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) ) |
| 874 | { |
| 875 | m_valueOld = table->GetValueAsLong(row, col); |
| 876 | } |
| 877 | else |
| 878 | { |
| 879 | m_valueOld = 0; |
| 880 | wxString sValue = table->GetValue(row, col); |
| 881 | if (! sValue.ToLong(&m_valueOld) && ! sValue.empty()) |
| 882 | { |
| 883 | wxFAIL_MSG( _T("this cell doesn't have numeric value") ); |
| 884 | return; |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | #if wxUSE_SPINCTRL |
| 889 | if ( HasRange() ) |
| 890 | { |
| 891 | Spin()->SetValue((int)m_valueOld); |
| 892 | Spin()->SetFocus(); |
| 893 | } |
| 894 | else |
| 895 | #endif |
| 896 | { |
| 897 | DoBeginEdit(GetString()); |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | bool wxGridCellNumberEditor::EndEdit(int row, int col, |
| 902 | wxGrid* grid) |
| 903 | { |
| 904 | bool changed; |
| 905 | long value = 0; |
| 906 | wxString text; |
| 907 | |
| 908 | #if wxUSE_SPINCTRL |
| 909 | if ( HasRange() ) |
| 910 | { |
| 911 | value = Spin()->GetValue(); |
| 912 | changed = value != m_valueOld; |
| 913 | if (changed) |
| 914 | text = wxString::Format(wxT("%ld"), value); |
| 915 | } |
| 916 | else |
| 917 | #endif |
| 918 | { |
| 919 | text = Text()->GetValue(); |
| 920 | changed = (text.empty() || text.ToLong(&value)) && (value != m_valueOld); |
| 921 | } |
| 922 | |
| 923 | if ( changed ) |
| 924 | { |
| 925 | if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_NUMBER)) |
| 926 | grid->GetTable()->SetValueAsLong(row, col, value); |
| 927 | else |
| 928 | grid->GetTable()->SetValue(row, col, text); |
| 929 | } |
| 930 | |
| 931 | return changed; |
| 932 | } |
| 933 | |
| 934 | void wxGridCellNumberEditor::Reset() |
| 935 | { |
| 936 | #if wxUSE_SPINCTRL |
| 937 | if ( HasRange() ) |
| 938 | { |
| 939 | Spin()->SetValue((int)m_valueOld); |
| 940 | } |
| 941 | else |
| 942 | #endif |
| 943 | { |
| 944 | DoReset(GetString()); |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | bool wxGridCellNumberEditor::IsAcceptedKey(wxKeyEvent& event) |
| 949 | { |
| 950 | if ( wxGridCellEditor::IsAcceptedKey(event) ) |
| 951 | { |
| 952 | int keycode = event.GetKeyCode(); |
| 953 | if ( (keycode < 128) && |
| 954 | (wxIsdigit(keycode) || keycode == '+' || keycode == '-')) |
| 955 | { |
| 956 | return true; |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | return false; |
| 961 | } |
| 962 | |
| 963 | void wxGridCellNumberEditor::StartingKey(wxKeyEvent& event) |
| 964 | { |
| 965 | int keycode = event.GetKeyCode(); |
| 966 | if ( !HasRange() ) |
| 967 | { |
| 968 | if ( wxIsdigit(keycode) || keycode == '+' || keycode == '-') |
| 969 | { |
| 970 | wxGridCellTextEditor::StartingKey(event); |
| 971 | |
| 972 | // skip Skip() below |
| 973 | return; |
| 974 | } |
| 975 | } |
| 976 | #if wxUSE_SPINCTRL |
| 977 | else |
| 978 | { |
| 979 | if ( wxIsdigit(keycode) ) |
| 980 | { |
| 981 | wxSpinCtrl* spin = (wxSpinCtrl*)m_control; |
| 982 | spin->SetValue(keycode - '0'); |
| 983 | spin->SetSelection(1,1); |
| 984 | return; |
| 985 | } |
| 986 | } |
| 987 | #endif |
| 988 | event.Skip(); |
| 989 | } |
| 990 | |
| 991 | void wxGridCellNumberEditor::SetParameters(const wxString& params) |
| 992 | { |
| 993 | if ( !params ) |
| 994 | { |
| 995 | // reset to default |
| 996 | m_min = |
| 997 | m_max = -1; |
| 998 | } |
| 999 | else |
| 1000 | { |
| 1001 | long tmp; |
| 1002 | if ( params.BeforeFirst(_T(',')).ToLong(&tmp) ) |
| 1003 | { |
| 1004 | m_min = (int)tmp; |
| 1005 | |
| 1006 | if ( params.AfterFirst(_T(',')).ToLong(&tmp) ) |
| 1007 | { |
| 1008 | m_max = (int)tmp; |
| 1009 | |
| 1010 | // skip the error message below |
| 1011 | return; |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | wxLogDebug(_T("Invalid wxGridCellNumberEditor parameter string '%s' ignored"), params.c_str()); |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | // return the value in the spin control if it is there (the text control otherwise) |
| 1020 | wxString wxGridCellNumberEditor::GetValue() const |
| 1021 | { |
| 1022 | wxString s; |
| 1023 | |
| 1024 | #if wxUSE_SPINCTRL |
| 1025 | if ( HasRange() ) |
| 1026 | { |
| 1027 | long value = Spin()->GetValue(); |
| 1028 | s.Printf(wxT("%ld"), value); |
| 1029 | } |
| 1030 | else |
| 1031 | #endif |
| 1032 | { |
| 1033 | s = Text()->GetValue(); |
| 1034 | } |
| 1035 | |
| 1036 | return s; |
| 1037 | } |
| 1038 | |
| 1039 | // ---------------------------------------------------------------------------- |
| 1040 | // wxGridCellFloatEditor |
| 1041 | // ---------------------------------------------------------------------------- |
| 1042 | |
| 1043 | wxGridCellFloatEditor::wxGridCellFloatEditor(int width, int precision) |
| 1044 | { |
| 1045 | m_width = width; |
| 1046 | m_precision = precision; |
| 1047 | } |
| 1048 | |
| 1049 | void wxGridCellFloatEditor::Create(wxWindow* parent, |
| 1050 | wxWindowID id, |
| 1051 | wxEvtHandler* evtHandler) |
| 1052 | { |
| 1053 | wxGridCellTextEditor::Create(parent, id, evtHandler); |
| 1054 | |
| 1055 | #if wxUSE_VALIDATORS |
| 1056 | Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); |
| 1057 | #endif // wxUSE_VALIDATORS |
| 1058 | } |
| 1059 | |
| 1060 | void wxGridCellFloatEditor::BeginEdit(int row, int col, wxGrid* grid) |
| 1061 | { |
| 1062 | // first get the value |
| 1063 | wxGridTableBase *table = grid->GetTable(); |
| 1064 | if ( table->CanGetValueAs(row, col, wxGRID_VALUE_FLOAT) ) |
| 1065 | { |
| 1066 | m_valueOld = table->GetValueAsDouble(row, col); |
| 1067 | } |
| 1068 | else |
| 1069 | { |
| 1070 | m_valueOld = 0.0; |
| 1071 | wxString sValue = table->GetValue(row, col); |
| 1072 | if (! sValue.ToDouble(&m_valueOld) && ! sValue.empty()) |
| 1073 | { |
| 1074 | wxFAIL_MSG( _T("this cell doesn't have float value") ); |
| 1075 | return; |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | DoBeginEdit(GetString()); |
| 1080 | } |
| 1081 | |
| 1082 | bool wxGridCellFloatEditor::EndEdit(int row, int col, |
| 1083 | wxGrid* grid) |
| 1084 | { |
| 1085 | double value = 0.0; |
| 1086 | wxString text(Text()->GetValue()); |
| 1087 | |
| 1088 | if ( (text.empty() || text.ToDouble(&value)) && |
| 1089 | !wxIsSameDouble(value, m_valueOld) ) |
| 1090 | { |
| 1091 | if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_FLOAT)) |
| 1092 | grid->GetTable()->SetValueAsDouble(row, col, value); |
| 1093 | else |
| 1094 | grid->GetTable()->SetValue(row, col, text); |
| 1095 | |
| 1096 | return true; |
| 1097 | } |
| 1098 | return false; |
| 1099 | } |
| 1100 | |
| 1101 | void wxGridCellFloatEditor::Reset() |
| 1102 | { |
| 1103 | DoReset(GetString()); |
| 1104 | } |
| 1105 | |
| 1106 | void wxGridCellFloatEditor::StartingKey(wxKeyEvent& event) |
| 1107 | { |
| 1108 | int keycode = event.GetKeyCode(); |
| 1109 | char tmpbuf[2]; |
| 1110 | tmpbuf[0] = (char) keycode; |
| 1111 | tmpbuf[1] = '\0'; |
| 1112 | wxString strbuf(tmpbuf, *wxConvCurrent); |
| 1113 | #if wxUSE_INTL |
| 1114 | bool is_decimal_point = ( strbuf == |
| 1115 | wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER) ); |
| 1116 | #else |
| 1117 | bool is_decimal_point = ( strbuf == _T(".") ); |
| 1118 | #endif |
| 1119 | if ( wxIsdigit(keycode) || keycode == '+' || keycode == '-' |
| 1120 | || is_decimal_point ) |
| 1121 | { |
| 1122 | wxGridCellTextEditor::StartingKey(event); |
| 1123 | |
| 1124 | // skip Skip() below |
| 1125 | return; |
| 1126 | } |
| 1127 | |
| 1128 | event.Skip(); |
| 1129 | } |
| 1130 | |
| 1131 | void wxGridCellFloatEditor::SetParameters(const wxString& params) |
| 1132 | { |
| 1133 | if ( !params ) |
| 1134 | { |
| 1135 | // reset to default |
| 1136 | m_width = |
| 1137 | m_precision = -1; |
| 1138 | } |
| 1139 | else |
| 1140 | { |
| 1141 | long tmp; |
| 1142 | if ( params.BeforeFirst(_T(',')).ToLong(&tmp) ) |
| 1143 | { |
| 1144 | m_width = (int)tmp; |
| 1145 | |
| 1146 | if ( params.AfterFirst(_T(',')).ToLong(&tmp) ) |
| 1147 | { |
| 1148 | m_precision = (int)tmp; |
| 1149 | |
| 1150 | // skip the error message below |
| 1151 | return; |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | wxLogDebug(_T("Invalid wxGridCellFloatEditor parameter string '%s' ignored"), params.c_str()); |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | wxString wxGridCellFloatEditor::GetString() const |
| 1160 | { |
| 1161 | wxString fmt; |
| 1162 | if ( m_width == -1 ) |
| 1163 | { |
| 1164 | // default width/precision |
| 1165 | fmt = _T("%f"); |
| 1166 | } |
| 1167 | else if ( m_precision == -1 ) |
| 1168 | { |
| 1169 | // default precision |
| 1170 | fmt.Printf(_T("%%%d.f"), m_width); |
| 1171 | } |
| 1172 | else |
| 1173 | { |
| 1174 | fmt.Printf(_T("%%%d.%df"), m_width, m_precision); |
| 1175 | } |
| 1176 | |
| 1177 | return wxString::Format(fmt, m_valueOld); |
| 1178 | } |
| 1179 | |
| 1180 | bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event) |
| 1181 | { |
| 1182 | if ( wxGridCellEditor::IsAcceptedKey(event) ) |
| 1183 | { |
| 1184 | int keycode = event.GetKeyCode(); |
| 1185 | printf("%d\n", keycode); |
| 1186 | // accept digits, 'e' as in '1e+6', also '-', '+', and '.' |
| 1187 | char tmpbuf[2]; |
| 1188 | tmpbuf[0] = (char) keycode; |
| 1189 | tmpbuf[1] = '\0'; |
| 1190 | wxString strbuf(tmpbuf, *wxConvCurrent); |
| 1191 | #if wxUSE_INTL |
| 1192 | bool is_decimal_point = |
| 1193 | ( strbuf == wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, |
| 1194 | wxLOCALE_CAT_NUMBER) ); |
| 1195 | #else |
| 1196 | bool is_decimal_point = ( strbuf == _T(".") ); |
| 1197 | #endif |
| 1198 | if ( (keycode < 128) && |
| 1199 | (wxIsdigit(keycode) || tolower(keycode) == 'e' || |
| 1200 | is_decimal_point || keycode == '+' || keycode == '-') ) |
| 1201 | return true; |
| 1202 | } |
| 1203 | |
| 1204 | return false; |
| 1205 | } |
| 1206 | |
| 1207 | #endif // wxUSE_TEXTCTRL |
| 1208 | |
| 1209 | #if wxUSE_CHECKBOX |
| 1210 | |
| 1211 | // ---------------------------------------------------------------------------- |
| 1212 | // wxGridCellBoolEditor |
| 1213 | // ---------------------------------------------------------------------------- |
| 1214 | |
| 1215 | void wxGridCellBoolEditor::Create(wxWindow* parent, |
| 1216 | wxWindowID id, |
| 1217 | wxEvtHandler* evtHandler) |
| 1218 | { |
| 1219 | m_control = new wxCheckBox(parent, id, wxEmptyString, |
| 1220 | wxDefaultPosition, wxDefaultSize, |
| 1221 | wxNO_BORDER); |
| 1222 | |
| 1223 | wxGridCellEditor::Create(parent, id, evtHandler); |
| 1224 | } |
| 1225 | |
| 1226 | void wxGridCellBoolEditor::SetSize(const wxRect& r) |
| 1227 | { |
| 1228 | bool resize = false; |
| 1229 | wxSize size = m_control->GetSize(); |
| 1230 | wxCoord minSize = wxMin(r.width, r.height); |
| 1231 | |
| 1232 | // check if the checkbox is not too big/small for this cell |
| 1233 | wxSize sizeBest = m_control->GetBestSize(); |
| 1234 | if ( !(size == sizeBest) ) |
| 1235 | { |
| 1236 | // reset to default size if it had been made smaller |
| 1237 | size = sizeBest; |
| 1238 | |
| 1239 | resize = true; |
| 1240 | } |
| 1241 | |
| 1242 | if ( size.x >= minSize || size.y >= minSize ) |
| 1243 | { |
| 1244 | // leave 1 pixel margin |
| 1245 | size.x = size.y = minSize - 2; |
| 1246 | |
| 1247 | resize = true; |
| 1248 | } |
| 1249 | |
| 1250 | if ( resize ) |
| 1251 | { |
| 1252 | m_control->SetSize(size); |
| 1253 | } |
| 1254 | |
| 1255 | // position it in the centre of the rectangle (TODO: support alignment?) |
| 1256 | |
| 1257 | #if defined(__WXGTK__) || defined (__WXMOTIF__) |
| 1258 | // the checkbox without label still has some space to the right in wxGTK, |
| 1259 | // so shift it to the right |
| 1260 | size.x -= 8; |
| 1261 | #elif defined(__WXMSW__) |
| 1262 | // here too, but in other way |
| 1263 | size.x += 1; |
| 1264 | size.y -= 2; |
| 1265 | #endif |
| 1266 | |
| 1267 | int hAlign = wxALIGN_CENTRE; |
| 1268 | int vAlign = wxALIGN_CENTRE; |
| 1269 | if (GetCellAttr()) |
| 1270 | GetCellAttr()->GetAlignment(& hAlign, & vAlign); |
| 1271 | |
| 1272 | int x = 0, y = 0; |
| 1273 | if (hAlign == wxALIGN_LEFT) |
| 1274 | { |
| 1275 | x = r.x + 2; |
| 1276 | #ifdef __WXMSW__ |
| 1277 | x += 2; |
| 1278 | #endif |
| 1279 | y = r.y + r.height/2 - size.y/2; |
| 1280 | } |
| 1281 | else if (hAlign == wxALIGN_RIGHT) |
| 1282 | { |
| 1283 | x = r.x + r.width - size.x - 2; |
| 1284 | y = r.y + r.height/2 - size.y/2; |
| 1285 | } |
| 1286 | else if (hAlign == wxALIGN_CENTRE) |
| 1287 | { |
| 1288 | x = r.x + r.width/2 - size.x/2; |
| 1289 | y = r.y + r.height/2 - size.y/2; |
| 1290 | } |
| 1291 | |
| 1292 | m_control->Move(x, y); |
| 1293 | } |
| 1294 | |
| 1295 | void wxGridCellBoolEditor::Show(bool show, wxGridCellAttr *attr) |
| 1296 | { |
| 1297 | m_control->Show(show); |
| 1298 | |
| 1299 | if ( show ) |
| 1300 | { |
| 1301 | wxColour colBg = attr ? attr->GetBackgroundColour() : *wxLIGHT_GREY; |
| 1302 | CBox()->SetBackgroundColour(colBg); |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid) |
| 1307 | { |
| 1308 | wxASSERT_MSG(m_control, |
| 1309 | wxT("The wxGridCellEditor must be Created first!")); |
| 1310 | |
| 1311 | if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL)) |
| 1312 | m_startValue = grid->GetTable()->GetValueAsBool(row, col); |
| 1313 | else |
| 1314 | { |
| 1315 | wxString cellval( grid->GetTable()->GetValue(row, col) ); |
| 1316 | m_startValue = !( !cellval || (cellval == wxT("0")) ); |
| 1317 | } |
| 1318 | CBox()->SetValue(m_startValue); |
| 1319 | CBox()->SetFocus(); |
| 1320 | } |
| 1321 | |
| 1322 | bool wxGridCellBoolEditor::EndEdit(int row, int col, |
| 1323 | wxGrid* grid) |
| 1324 | { |
| 1325 | wxASSERT_MSG(m_control, |
| 1326 | wxT("The wxGridCellEditor must be Created first!")); |
| 1327 | |
| 1328 | bool changed = false; |
| 1329 | bool value = CBox()->GetValue(); |
| 1330 | if ( value != m_startValue ) |
| 1331 | changed = true; |
| 1332 | |
| 1333 | if ( changed ) |
| 1334 | { |
| 1335 | if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL)) |
| 1336 | grid->GetTable()->SetValueAsBool(row, col, value); |
| 1337 | else |
| 1338 | grid->GetTable()->SetValue(row, col, value ? _T("1") : wxEmptyString); |
| 1339 | } |
| 1340 | |
| 1341 | return changed; |
| 1342 | } |
| 1343 | |
| 1344 | void wxGridCellBoolEditor::Reset() |
| 1345 | { |
| 1346 | wxASSERT_MSG(m_control, |
| 1347 | wxT("The wxGridCellEditor must be Created first!")); |
| 1348 | |
| 1349 | CBox()->SetValue(m_startValue); |
| 1350 | } |
| 1351 | |
| 1352 | void wxGridCellBoolEditor::StartingClick() |
| 1353 | { |
| 1354 | CBox()->SetValue(!CBox()->GetValue()); |
| 1355 | } |
| 1356 | |
| 1357 | bool wxGridCellBoolEditor::IsAcceptedKey(wxKeyEvent& event) |
| 1358 | { |
| 1359 | if ( wxGridCellEditor::IsAcceptedKey(event) ) |
| 1360 | { |
| 1361 | int keycode = event.GetKeyCode(); |
| 1362 | switch ( keycode ) |
| 1363 | { |
| 1364 | case WXK_SPACE: |
| 1365 | case '+': |
| 1366 | case '-': |
| 1367 | return true; |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | return false; |
| 1372 | } |
| 1373 | |
| 1374 | void wxGridCellBoolEditor::StartingKey(wxKeyEvent& event) |
| 1375 | { |
| 1376 | int keycode = event.GetKeyCode(); |
| 1377 | switch ( keycode ) |
| 1378 | { |
| 1379 | case WXK_SPACE: |
| 1380 | CBox()->SetValue(!CBox()->GetValue()); |
| 1381 | break; |
| 1382 | |
| 1383 | case '+': |
| 1384 | CBox()->SetValue(true); |
| 1385 | break; |
| 1386 | |
| 1387 | case '-': |
| 1388 | CBox()->SetValue(false); |
| 1389 | break; |
| 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | |
| 1394 | // return the value as "1" for true and the empty string for false |
| 1395 | wxString wxGridCellBoolEditor::GetValue() const |
| 1396 | { |
| 1397 | bool bSet = CBox()->GetValue(); |
| 1398 | return bSet ? _T("1") : wxEmptyString; |
| 1399 | } |
| 1400 | |
| 1401 | #endif // wxUSE_CHECKBOX |
| 1402 | |
| 1403 | #if wxUSE_COMBOBOX |
| 1404 | |
| 1405 | // ---------------------------------------------------------------------------- |
| 1406 | // wxGridCellChoiceEditor |
| 1407 | // ---------------------------------------------------------------------------- |
| 1408 | |
| 1409 | wxGridCellChoiceEditor::wxGridCellChoiceEditor(const wxArrayString& choices, |
| 1410 | bool allowOthers) |
| 1411 | : m_choices(choices), |
| 1412 | m_allowOthers(allowOthers) { } |
| 1413 | |
| 1414 | wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count, |
| 1415 | const wxString choices[], |
| 1416 | bool allowOthers) |
| 1417 | : m_allowOthers(allowOthers) |
| 1418 | { |
| 1419 | if ( count ) |
| 1420 | { |
| 1421 | m_choices.Alloc(count); |
| 1422 | for ( size_t n = 0; n < count; n++ ) |
| 1423 | { |
| 1424 | m_choices.Add(choices[n]); |
| 1425 | } |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | wxGridCellEditor *wxGridCellChoiceEditor::Clone() const |
| 1430 | { |
| 1431 | wxGridCellChoiceEditor *editor = new wxGridCellChoiceEditor; |
| 1432 | editor->m_allowOthers = m_allowOthers; |
| 1433 | editor->m_choices = m_choices; |
| 1434 | |
| 1435 | return editor; |
| 1436 | } |
| 1437 | |
| 1438 | void wxGridCellChoiceEditor::Create(wxWindow* parent, |
| 1439 | wxWindowID id, |
| 1440 | wxEvtHandler* evtHandler) |
| 1441 | { |
| 1442 | m_control = new wxComboBox(parent, id, wxEmptyString, |
| 1443 | wxDefaultPosition, wxDefaultSize, |
| 1444 | m_choices, |
| 1445 | m_allowOthers ? 0 : wxCB_READONLY); |
| 1446 | |
| 1447 | wxGridCellEditor::Create(parent, id, evtHandler); |
| 1448 | } |
| 1449 | |
| 1450 | void wxGridCellChoiceEditor::PaintBackground(const wxRect& rectCell, |
| 1451 | wxGridCellAttr * attr) |
| 1452 | { |
| 1453 | // as we fill the entire client area, don't do anything here to minimize |
| 1454 | // flicker |
| 1455 | |
| 1456 | // TODO: It doesn't actually fill the client area since the height of a |
| 1457 | // combo always defaults to the standard... Until someone has time to |
| 1458 | // figure out the right rectangle to paint, just do it the normal way... |
| 1459 | wxGridCellEditor::PaintBackground(rectCell, attr); |
| 1460 | } |
| 1461 | |
| 1462 | void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid) |
| 1463 | { |
| 1464 | wxASSERT_MSG(m_control, |
| 1465 | wxT("The wxGridCellEditor must be Created first!")); |
| 1466 | |
| 1467 | wxGridCellEditorEvtHandler* evtHandler = NULL; |
| 1468 | if (m_control) |
| 1469 | evtHandler = wxDynamicCast(m_control->GetEventHandler(), wxGridCellEditorEvtHandler); |
| 1470 | |
| 1471 | // Don't immediately end if we get a kill focus event within BeginEdit |
| 1472 | if (evtHandler) |
| 1473 | evtHandler->SetInSetFocus(true); |
| 1474 | |
| 1475 | m_startValue = grid->GetTable()->GetValue(row, col); |
| 1476 | |
| 1477 | if (m_allowOthers) |
| 1478 | Combo()->SetValue(m_startValue); |
| 1479 | else |
| 1480 | { |
| 1481 | // find the right position, or default to the first if not found |
| 1482 | int pos = Combo()->FindString(m_startValue); |
| 1483 | if (pos == wxNOT_FOUND) |
| 1484 | pos = 0; |
| 1485 | Combo()->SetSelection(pos); |
| 1486 | } |
| 1487 | Combo()->SetInsertionPointEnd(); |
| 1488 | Combo()->SetFocus(); |
| 1489 | |
| 1490 | if (evtHandler) |
| 1491 | { |
| 1492 | // When dropping down the menu, a kill focus event |
| 1493 | // happens after this point, so we can't reset the flag yet. |
| 1494 | #if !defined(__WXGTK20__) |
| 1495 | evtHandler->SetInSetFocus(false); |
| 1496 | #endif |
| 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | bool wxGridCellChoiceEditor::EndEdit(int row, int col, |
| 1501 | wxGrid* grid) |
| 1502 | { |
| 1503 | wxString value = Combo()->GetValue(); |
| 1504 | if ( value == m_startValue ) |
| 1505 | return false; |
| 1506 | |
| 1507 | grid->GetTable()->SetValue(row, col, value); |
| 1508 | |
| 1509 | return true; |
| 1510 | } |
| 1511 | |
| 1512 | void wxGridCellChoiceEditor::Reset() |
| 1513 | { |
| 1514 | Combo()->SetValue(m_startValue); |
| 1515 | Combo()->SetInsertionPointEnd(); |
| 1516 | } |
| 1517 | |
| 1518 | void wxGridCellChoiceEditor::SetParameters(const wxString& params) |
| 1519 | { |
| 1520 | if ( !params ) |
| 1521 | { |
| 1522 | // what can we do? |
| 1523 | return; |
| 1524 | } |
| 1525 | |
| 1526 | m_choices.Empty(); |
| 1527 | |
| 1528 | wxStringTokenizer tk(params, _T(',')); |
| 1529 | while ( tk.HasMoreTokens() ) |
| 1530 | { |
| 1531 | m_choices.Add(tk.GetNextToken()); |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | // return the value in the text control |
| 1536 | wxString wxGridCellChoiceEditor::GetValue() const |
| 1537 | { |
| 1538 | return Combo()->GetValue(); |
| 1539 | } |
| 1540 | |
| 1541 | #endif // wxUSE_COMBOBOX |
| 1542 | |
| 1543 | // ---------------------------------------------------------------------------- |
| 1544 | // wxGridCellEditorEvtHandler |
| 1545 | // ---------------------------------------------------------------------------- |
| 1546 | |
| 1547 | void wxGridCellEditorEvtHandler::OnKillFocus(wxFocusEvent& event) |
| 1548 | { |
| 1549 | // Don't disable the cell if we're just starting to edit it |
| 1550 | if (m_inSetFocus) |
| 1551 | return; |
| 1552 | |
| 1553 | // accept changes |
| 1554 | m_grid->DisableCellEditControl(); |
| 1555 | |
| 1556 | event.Skip(); |
| 1557 | } |
| 1558 | |
| 1559 | void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event) |
| 1560 | { |
| 1561 | switch ( event.GetKeyCode() ) |
| 1562 | { |
| 1563 | case WXK_ESCAPE: |
| 1564 | m_editor->Reset(); |
| 1565 | m_grid->DisableCellEditControl(); |
| 1566 | break; |
| 1567 | |
| 1568 | case WXK_TAB: |
| 1569 | m_grid->GetEventHandler()->ProcessEvent( event ); |
| 1570 | break; |
| 1571 | |
| 1572 | case WXK_RETURN: |
| 1573 | case WXK_NUMPAD_ENTER: |
| 1574 | if (!m_grid->GetEventHandler()->ProcessEvent(event)) |
| 1575 | m_editor->HandleReturn(event); |
| 1576 | break; |
| 1577 | |
| 1578 | default: |
| 1579 | event.Skip(); |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent& event) |
| 1584 | { |
| 1585 | switch ( event.GetKeyCode() ) |
| 1586 | { |
| 1587 | case WXK_ESCAPE: |
| 1588 | case WXK_TAB: |
| 1589 | case WXK_RETURN: |
| 1590 | case WXK_NUMPAD_ENTER: |
| 1591 | break; |
| 1592 | |
| 1593 | default: |
| 1594 | event.Skip(); |
| 1595 | } |
| 1596 | } |
| 1597 | |
| 1598 | // ---------------------------------------------------------------------------- |
| 1599 | // wxGridCellWorker is an (almost) empty common base class for |
| 1600 | // wxGridCellRenderer and wxGridCellEditor managing ref counting |
| 1601 | // ---------------------------------------------------------------------------- |
| 1602 | |
| 1603 | void wxGridCellWorker::SetParameters(const wxString& WXUNUSED(params)) |
| 1604 | { |
| 1605 | // nothing to do |
| 1606 | } |
| 1607 | |
| 1608 | wxGridCellWorker::~wxGridCellWorker() |
| 1609 | { |
| 1610 | } |
| 1611 | |
| 1612 | // ============================================================================ |
| 1613 | // renderer classes |
| 1614 | // ============================================================================ |
| 1615 | |
| 1616 | // ---------------------------------------------------------------------------- |
| 1617 | // wxGridCellRenderer |
| 1618 | // ---------------------------------------------------------------------------- |
| 1619 | |
| 1620 | void wxGridCellRenderer::Draw(wxGrid& grid, |
| 1621 | wxGridCellAttr& attr, |
| 1622 | wxDC& dc, |
| 1623 | const wxRect& rect, |
| 1624 | int WXUNUSED(row), int WXUNUSED(col), |
| 1625 | bool isSelected) |
| 1626 | { |
| 1627 | dc.SetBackgroundMode( wxSOLID ); |
| 1628 | |
| 1629 | // grey out fields if the grid is disabled |
| 1630 | if ( grid.IsEnabled() ) |
| 1631 | { |
| 1632 | if ( isSelected ) |
| 1633 | { |
| 1634 | dc.SetBrush( wxBrush(grid.GetSelectionBackground(), wxSOLID) ); |
| 1635 | } |
| 1636 | else |
| 1637 | { |
| 1638 | dc.SetBrush( wxBrush(attr.GetBackgroundColour(), wxSOLID) ); |
| 1639 | } |
| 1640 | } |
| 1641 | else |
| 1642 | { |
| 1643 | dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE), wxSOLID)); |
| 1644 | } |
| 1645 | |
| 1646 | dc.SetPen( *wxTRANSPARENT_PEN ); |
| 1647 | dc.DrawRectangle(rect); |
| 1648 | } |
| 1649 | |
| 1650 | // ---------------------------------------------------------------------------- |
| 1651 | // wxGridCellStringRenderer |
| 1652 | // ---------------------------------------------------------------------------- |
| 1653 | |
| 1654 | void wxGridCellStringRenderer::SetTextColoursAndFont(const wxGrid& grid, |
| 1655 | const wxGridCellAttr& attr, |
| 1656 | wxDC& dc, |
| 1657 | bool isSelected) |
| 1658 | { |
| 1659 | dc.SetBackgroundMode( wxTRANSPARENT ); |
| 1660 | |
| 1661 | // TODO some special colours for attr.IsReadOnly() case? |
| 1662 | |
| 1663 | // different coloured text when the grid is disabled |
| 1664 | if ( grid.IsEnabled() ) |
| 1665 | { |
| 1666 | if ( isSelected ) |
| 1667 | { |
| 1668 | dc.SetTextBackground( grid.GetSelectionBackground() ); |
| 1669 | dc.SetTextForeground( grid.GetSelectionForeground() ); |
| 1670 | } |
| 1671 | else |
| 1672 | { |
| 1673 | dc.SetTextBackground( attr.GetBackgroundColour() ); |
| 1674 | dc.SetTextForeground( attr.GetTextColour() ); |
| 1675 | } |
| 1676 | } |
| 1677 | else |
| 1678 | { |
| 1679 | dc.SetTextBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); |
| 1680 | dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT)); |
| 1681 | } |
| 1682 | |
| 1683 | dc.SetFont( attr.GetFont() ); |
| 1684 | } |
| 1685 | |
| 1686 | wxSize wxGridCellStringRenderer::DoGetBestSize(const wxGridCellAttr& attr, |
| 1687 | wxDC& dc, |
| 1688 | const wxString& text) |
| 1689 | { |
| 1690 | wxCoord x = 0, y = 0, max_x = 0; |
| 1691 | dc.SetFont(attr.GetFont()); |
| 1692 | wxStringTokenizer tk(text, _T('\n')); |
| 1693 | while ( tk.HasMoreTokens() ) |
| 1694 | { |
| 1695 | dc.GetTextExtent(tk.GetNextToken(), &x, &y); |
| 1696 | max_x = wxMax(max_x, x); |
| 1697 | } |
| 1698 | |
| 1699 | y *= 1 + text.Freq(wxT('\n')); // multiply by the number of lines. |
| 1700 | |
| 1701 | return wxSize(max_x, y); |
| 1702 | } |
| 1703 | |
| 1704 | wxSize wxGridCellStringRenderer::GetBestSize(wxGrid& grid, |
| 1705 | wxGridCellAttr& attr, |
| 1706 | wxDC& dc, |
| 1707 | int row, int col) |
| 1708 | { |
| 1709 | return DoGetBestSize(attr, dc, grid.GetCellValue(row, col)); |
| 1710 | } |
| 1711 | |
| 1712 | void wxGridCellStringRenderer::Draw(wxGrid& grid, |
| 1713 | wxGridCellAttr& attr, |
| 1714 | wxDC& dc, |
| 1715 | const wxRect& rectCell, |
| 1716 | int row, int col, |
| 1717 | bool isSelected) |
| 1718 | { |
| 1719 | wxRect rect = rectCell; |
| 1720 | rect.Inflate(-1); |
| 1721 | |
| 1722 | // erase only this cells background, overflow cells should have been erased |
| 1723 | wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected); |
| 1724 | |
| 1725 | int hAlign, vAlign; |
| 1726 | attr.GetAlignment(&hAlign, &vAlign); |
| 1727 | |
| 1728 | int overflowCols = 0; |
| 1729 | |
| 1730 | if (attr.GetOverflow()) |
| 1731 | { |
| 1732 | int cols = grid.GetNumberCols(); |
| 1733 | int best_width = GetBestSize(grid,attr,dc,row,col).GetWidth(); |
| 1734 | int cell_rows, cell_cols; |
| 1735 | attr.GetSize( &cell_rows, &cell_cols ); // shouldn't get here if <=0 |
| 1736 | if ((best_width > rectCell.width) && (col < cols) && grid.GetTable()) |
| 1737 | { |
| 1738 | int i, c_cols, c_rows; |
| 1739 | for (i = col+cell_cols; i < cols; i++) |
| 1740 | { |
| 1741 | bool is_empty = true; |
| 1742 | for (int j=row; j<row+cell_rows; j++) |
| 1743 | { |
| 1744 | // check w/ anchor cell for multicell block |
| 1745 | grid.GetCellSize(j, i, &c_rows, &c_cols); |
| 1746 | if (c_rows > 0) c_rows = 0; |
| 1747 | if (!grid.GetTable()->IsEmptyCell(j+c_rows, i)) |
| 1748 | { |
| 1749 | is_empty = false; |
| 1750 | break; |
| 1751 | } |
| 1752 | } |
| 1753 | if (is_empty) |
| 1754 | rect.width += grid.GetColSize(i); |
| 1755 | else |
| 1756 | { |
| 1757 | i--; |
| 1758 | break; |
| 1759 | } |
| 1760 | if (rect.width >= best_width) |
| 1761 | break; |
| 1762 | } |
| 1763 | overflowCols = i - col - cell_cols + 1; |
| 1764 | if (overflowCols >= cols) |
| 1765 | overflowCols = cols - 1; |
| 1766 | } |
| 1767 | |
| 1768 | if (overflowCols > 0) // redraw overflow cells w/ proper hilight |
| 1769 | { |
| 1770 | hAlign = wxALIGN_LEFT; // if oveflowed then it's left aligned |
| 1771 | wxRect clip = rect; |
| 1772 | clip.x += rectCell.width; |
| 1773 | // draw each overflow cell individually |
| 1774 | int col_end = col+cell_cols+overflowCols; |
| 1775 | if (col_end >= grid.GetNumberCols()) |
| 1776 | col_end = grid.GetNumberCols() - 1; |
| 1777 | for (int i = col+cell_cols; i <= col_end; i++) |
| 1778 | { |
| 1779 | clip.width = grid.GetColSize(i) - 1; |
| 1780 | dc.DestroyClippingRegion(); |
| 1781 | dc.SetClippingRegion(clip); |
| 1782 | |
| 1783 | SetTextColoursAndFont(grid, attr, dc, |
| 1784 | grid.IsInSelection(row,i)); |
| 1785 | |
| 1786 | grid.DrawTextRectangle(dc, grid.GetCellValue(row, col), |
| 1787 | rect, hAlign, vAlign); |
| 1788 | clip.x += grid.GetColSize(i) - 1; |
| 1789 | } |
| 1790 | |
| 1791 | rect = rectCell; |
| 1792 | rect.Inflate(-1); |
| 1793 | rect.width++; |
| 1794 | dc.DestroyClippingRegion(); |
| 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | // now we only have to draw the text |
| 1799 | SetTextColoursAndFont(grid, attr, dc, isSelected); |
| 1800 | |
| 1801 | grid.DrawTextRectangle(dc, grid.GetCellValue(row, col), |
| 1802 | rect, hAlign, vAlign); |
| 1803 | } |
| 1804 | |
| 1805 | // ---------------------------------------------------------------------------- |
| 1806 | // wxGridCellNumberRenderer |
| 1807 | // ---------------------------------------------------------------------------- |
| 1808 | |
| 1809 | wxString wxGridCellNumberRenderer::GetString(const wxGrid& grid, int row, int col) |
| 1810 | { |
| 1811 | wxGridTableBase *table = grid.GetTable(); |
| 1812 | wxString text; |
| 1813 | if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) ) |
| 1814 | { |
| 1815 | text.Printf(_T("%ld"), table->GetValueAsLong(row, col)); |
| 1816 | } |
| 1817 | else |
| 1818 | { |
| 1819 | text = table->GetValue(row, col); |
| 1820 | } |
| 1821 | |
| 1822 | return text; |
| 1823 | } |
| 1824 | |
| 1825 | void wxGridCellNumberRenderer::Draw(wxGrid& grid, |
| 1826 | wxGridCellAttr& attr, |
| 1827 | wxDC& dc, |
| 1828 | const wxRect& rectCell, |
| 1829 | int row, int col, |
| 1830 | bool isSelected) |
| 1831 | { |
| 1832 | wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected); |
| 1833 | |
| 1834 | SetTextColoursAndFont(grid, attr, dc, isSelected); |
| 1835 | |
| 1836 | // draw the text right aligned by default |
| 1837 | int hAlign, vAlign; |
| 1838 | attr.GetAlignment(&hAlign, &vAlign); |
| 1839 | hAlign = wxALIGN_RIGHT; |
| 1840 | |
| 1841 | wxRect rect = rectCell; |
| 1842 | rect.Inflate(-1); |
| 1843 | |
| 1844 | grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, hAlign, vAlign); |
| 1845 | } |
| 1846 | |
| 1847 | wxSize wxGridCellNumberRenderer::GetBestSize(wxGrid& grid, |
| 1848 | wxGridCellAttr& attr, |
| 1849 | wxDC& dc, |
| 1850 | int row, int col) |
| 1851 | { |
| 1852 | return DoGetBestSize(attr, dc, GetString(grid, row, col)); |
| 1853 | } |
| 1854 | |
| 1855 | // ---------------------------------------------------------------------------- |
| 1856 | // wxGridCellFloatRenderer |
| 1857 | // ---------------------------------------------------------------------------- |
| 1858 | |
| 1859 | wxGridCellFloatRenderer::wxGridCellFloatRenderer(int width, int precision) |
| 1860 | { |
| 1861 | SetWidth(width); |
| 1862 | SetPrecision(precision); |
| 1863 | } |
| 1864 | |
| 1865 | wxGridCellRenderer *wxGridCellFloatRenderer::Clone() const |
| 1866 | { |
| 1867 | wxGridCellFloatRenderer *renderer = new wxGridCellFloatRenderer; |
| 1868 | renderer->m_width = m_width; |
| 1869 | renderer->m_precision = m_precision; |
| 1870 | renderer->m_format = m_format; |
| 1871 | |
| 1872 | return renderer; |
| 1873 | } |
| 1874 | |
| 1875 | wxString wxGridCellFloatRenderer::GetString(const wxGrid& grid, int row, int col) |
| 1876 | { |
| 1877 | wxGridTableBase *table = grid.GetTable(); |
| 1878 | |
| 1879 | bool hasDouble; |
| 1880 | double val; |
| 1881 | wxString text; |
| 1882 | if ( table->CanGetValueAs(row, col, wxGRID_VALUE_FLOAT) ) |
| 1883 | { |
| 1884 | val = table->GetValueAsDouble(row, col); |
| 1885 | hasDouble = true; |
| 1886 | } |
| 1887 | else |
| 1888 | { |
| 1889 | text = table->GetValue(row, col); |
| 1890 | hasDouble = text.ToDouble(&val); |
| 1891 | } |
| 1892 | |
| 1893 | if ( hasDouble ) |
| 1894 | { |
| 1895 | if ( !m_format ) |
| 1896 | { |
| 1897 | if ( m_width == -1 ) |
| 1898 | { |
| 1899 | if ( m_precision == -1 ) |
| 1900 | { |
| 1901 | // default width/precision |
| 1902 | m_format = _T("%f"); |
| 1903 | } |
| 1904 | else |
| 1905 | { |
| 1906 | m_format.Printf(_T("%%.%df"), m_precision); |
| 1907 | } |
| 1908 | } |
| 1909 | else if ( m_precision == -1 ) |
| 1910 | { |
| 1911 | // default precision |
| 1912 | m_format.Printf(_T("%%%d.f"), m_width); |
| 1913 | } |
| 1914 | else |
| 1915 | { |
| 1916 | m_format.Printf(_T("%%%d.%df"), m_width, m_precision); |
| 1917 | } |
| 1918 | } |
| 1919 | |
| 1920 | text.Printf(m_format, val); |
| 1921 | |
| 1922 | } |
| 1923 | //else: text already contains the string |
| 1924 | |
| 1925 | return text; |
| 1926 | } |
| 1927 | |
| 1928 | void wxGridCellFloatRenderer::Draw(wxGrid& grid, |
| 1929 | wxGridCellAttr& attr, |
| 1930 | wxDC& dc, |
| 1931 | const wxRect& rectCell, |
| 1932 | int row, int col, |
| 1933 | bool isSelected) |
| 1934 | { |
| 1935 | wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected); |
| 1936 | |
| 1937 | SetTextColoursAndFont(grid, attr, dc, isSelected); |
| 1938 | |
| 1939 | // draw the text right aligned by default |
| 1940 | int hAlign, vAlign; |
| 1941 | attr.GetAlignment(&hAlign, &vAlign); |
| 1942 | hAlign = wxALIGN_RIGHT; |
| 1943 | |
| 1944 | wxRect rect = rectCell; |
| 1945 | rect.Inflate(-1); |
| 1946 | |
| 1947 | grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, hAlign, vAlign); |
| 1948 | } |
| 1949 | |
| 1950 | wxSize wxGridCellFloatRenderer::GetBestSize(wxGrid& grid, |
| 1951 | wxGridCellAttr& attr, |
| 1952 | wxDC& dc, |
| 1953 | int row, int col) |
| 1954 | { |
| 1955 | return DoGetBestSize(attr, dc, GetString(grid, row, col)); |
| 1956 | } |
| 1957 | |
| 1958 | void wxGridCellFloatRenderer::SetParameters(const wxString& params) |
| 1959 | { |
| 1960 | if ( !params ) |
| 1961 | { |
| 1962 | // reset to defaults |
| 1963 | SetWidth(-1); |
| 1964 | SetPrecision(-1); |
| 1965 | } |
| 1966 | else |
| 1967 | { |
| 1968 | wxString tmp = params.BeforeFirst(_T(',')); |
| 1969 | if ( !tmp.empty() ) |
| 1970 | { |
| 1971 | long width; |
| 1972 | if ( tmp.ToLong(&width) ) |
| 1973 | { |
| 1974 | SetWidth((int)width); |
| 1975 | } |
| 1976 | else |
| 1977 | { |
| 1978 | wxLogDebug(_T("Invalid wxGridCellFloatRenderer width parameter string '%s ignored"), params.c_str()); |
| 1979 | } |
| 1980 | } |
| 1981 | tmp = params.AfterFirst(_T(',')); |
| 1982 | if ( !tmp.empty() ) |
| 1983 | { |
| 1984 | long precision; |
| 1985 | if ( tmp.ToLong(&precision) ) |
| 1986 | { |
| 1987 | SetPrecision((int)precision); |
| 1988 | } |
| 1989 | else |
| 1990 | { |
| 1991 | wxLogDebug(_T("Invalid wxGridCellFloatRenderer precision parameter string '%s ignored"), params.c_str()); |
| 1992 | } |
| 1993 | } |
| 1994 | } |
| 1995 | } |
| 1996 | |
| 1997 | |
| 1998 | // ---------------------------------------------------------------------------- |
| 1999 | // wxGridCellBoolRenderer |
| 2000 | // ---------------------------------------------------------------------------- |
| 2001 | |
| 2002 | wxSize wxGridCellBoolRenderer::ms_sizeCheckMark; |
| 2003 | |
| 2004 | // FIXME these checkbox size calculations are really ugly... |
| 2005 | |
| 2006 | // between checkmark and box |
| 2007 | static const wxCoord wxGRID_CHECKMARK_MARGIN = 2; |
| 2008 | |
| 2009 | wxSize wxGridCellBoolRenderer::GetBestSize(wxGrid& grid, |
| 2010 | wxGridCellAttr& WXUNUSED(attr), |
| 2011 | wxDC& WXUNUSED(dc), |
| 2012 | int WXUNUSED(row), |
| 2013 | int WXUNUSED(col)) |
| 2014 | { |
| 2015 | // compute it only once (no locks for MT safeness in GUI thread...) |
| 2016 | if ( !ms_sizeCheckMark.x ) |
| 2017 | { |
| 2018 | // get checkbox size |
| 2019 | wxCheckBox *checkbox = new wxCheckBox(&grid, wxID_ANY, wxEmptyString); |
| 2020 | wxSize size = checkbox->GetBestSize(); |
| 2021 | wxCoord checkSize = size.y + 2*wxGRID_CHECKMARK_MARGIN; |
| 2022 | |
| 2023 | // FIXME wxGTK::wxCheckBox::GetBestSize() gives "wrong" result |
| 2024 | #if defined(__WXGTK__) || defined(__WXMOTIF__) |
| 2025 | checkSize -= size.y / 2; |
| 2026 | #endif |
| 2027 | |
| 2028 | delete checkbox; |
| 2029 | |
| 2030 | ms_sizeCheckMark.x = ms_sizeCheckMark.y = checkSize; |
| 2031 | } |
| 2032 | |
| 2033 | return ms_sizeCheckMark; |
| 2034 | } |
| 2035 | |
| 2036 | void wxGridCellBoolRenderer::Draw(wxGrid& grid, |
| 2037 | wxGridCellAttr& attr, |
| 2038 | wxDC& dc, |
| 2039 | const wxRect& rect, |
| 2040 | int row, int col, |
| 2041 | bool isSelected) |
| 2042 | { |
| 2043 | wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected); |
| 2044 | |
| 2045 | // draw a check mark in the centre (ignoring alignment - TODO) |
| 2046 | wxSize size = GetBestSize(grid, attr, dc, row, col); |
| 2047 | |
| 2048 | // don't draw outside the cell |
| 2049 | wxCoord minSize = wxMin(rect.width, rect.height); |
| 2050 | if ( size.x >= minSize || size.y >= minSize ) |
| 2051 | { |
| 2052 | // and even leave (at least) 1 pixel margin |
| 2053 | size.x = size.y = minSize - 2; |
| 2054 | } |
| 2055 | |
| 2056 | // draw a border around checkmark |
| 2057 | int vAlign, hAlign; |
| 2058 | attr.GetAlignment(& hAlign, &vAlign); |
| 2059 | |
| 2060 | wxRect rectBorder; |
| 2061 | if (hAlign == wxALIGN_CENTRE) |
| 2062 | { |
| 2063 | rectBorder.x = rect.x + rect.width/2 - size.x/2; |
| 2064 | rectBorder.y = rect.y + rect.height/2 - size.y/2; |
| 2065 | rectBorder.width = size.x; |
| 2066 | rectBorder.height = size.y; |
| 2067 | } |
| 2068 | else if (hAlign == wxALIGN_LEFT) |
| 2069 | { |
| 2070 | rectBorder.x = rect.x + 2; |
| 2071 | rectBorder.y = rect.y + rect.height/2 - size.y/2; |
| 2072 | rectBorder.width = size.x; |
| 2073 | rectBorder.height = size.y; |
| 2074 | } |
| 2075 | else if (hAlign == wxALIGN_RIGHT) |
| 2076 | { |
| 2077 | rectBorder.x = rect.x + rect.width - size.x - 2; |
| 2078 | rectBorder.y = rect.y + rect.height/2 - size.y/2; |
| 2079 | rectBorder.width = size.x; |
| 2080 | rectBorder.height = size.y; |
| 2081 | } |
| 2082 | |
| 2083 | bool value; |
| 2084 | if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) ) |
| 2085 | value = grid.GetTable()->GetValueAsBool(row, col); |
| 2086 | else |
| 2087 | { |
| 2088 | wxString cellval( grid.GetTable()->GetValue(row, col) ); |
| 2089 | value = !( !cellval || (cellval == wxT("0")) ); |
| 2090 | } |
| 2091 | |
| 2092 | if ( value ) |
| 2093 | { |
| 2094 | wxRect rectMark = rectBorder; |
| 2095 | #ifdef __WXMSW__ |
| 2096 | // MSW DrawCheckMark() is weird (and should probably be changed...) |
| 2097 | rectMark.Inflate(-wxGRID_CHECKMARK_MARGIN/2); |
| 2098 | rectMark.x++; |
| 2099 | rectMark.y++; |
| 2100 | #else // !MSW |
| 2101 | rectMark.Inflate(-wxGRID_CHECKMARK_MARGIN); |
| 2102 | #endif // MSW/!MSW |
| 2103 | |
| 2104 | dc.SetTextForeground(attr.GetTextColour()); |
| 2105 | dc.DrawCheckMark(rectMark); |
| 2106 | } |
| 2107 | |
| 2108 | dc.SetBrush(*wxTRANSPARENT_BRUSH); |
| 2109 | dc.SetPen(wxPen(attr.GetTextColour(), 1, wxSOLID)); |
| 2110 | dc.DrawRectangle(rectBorder); |
| 2111 | } |
| 2112 | |
| 2113 | // ---------------------------------------------------------------------------- |
| 2114 | // wxGridCellAttr |
| 2115 | // ---------------------------------------------------------------------------- |
| 2116 | |
| 2117 | void wxGridCellAttr::Init(wxGridCellAttr *attrDefault) |
| 2118 | { |
| 2119 | m_nRef = 1; |
| 2120 | |
| 2121 | m_isReadOnly = Unset; |
| 2122 | |
| 2123 | m_renderer = NULL; |
| 2124 | m_editor = NULL; |
| 2125 | |
| 2126 | m_attrkind = wxGridCellAttr::Cell; |
| 2127 | |
| 2128 | m_sizeRows = m_sizeCols = 1; |
| 2129 | m_overflow = UnsetOverflow; |
| 2130 | |
| 2131 | SetDefAttr(attrDefault); |
| 2132 | } |
| 2133 | |
| 2134 | wxGridCellAttr *wxGridCellAttr::Clone() const |
| 2135 | { |
| 2136 | wxGridCellAttr *attr = new wxGridCellAttr(m_defGridAttr); |
| 2137 | |
| 2138 | if ( HasTextColour() ) |
| 2139 | attr->SetTextColour(GetTextColour()); |
| 2140 | if ( HasBackgroundColour() ) |
| 2141 | attr->SetBackgroundColour(GetBackgroundColour()); |
| 2142 | if ( HasFont() ) |
| 2143 | attr->SetFont(GetFont()); |
| 2144 | if ( HasAlignment() ) |
| 2145 | attr->SetAlignment(m_hAlign, m_vAlign); |
| 2146 | |
| 2147 | attr->SetSize( m_sizeRows, m_sizeCols ); |
| 2148 | |
| 2149 | if ( m_renderer ) |
| 2150 | { |
| 2151 | attr->SetRenderer(m_renderer); |
| 2152 | m_renderer->IncRef(); |
| 2153 | } |
| 2154 | if ( m_editor ) |
| 2155 | { |
| 2156 | attr->SetEditor(m_editor); |
| 2157 | m_editor->IncRef(); |
| 2158 | } |
| 2159 | |
| 2160 | if ( IsReadOnly() ) |
| 2161 | attr->SetReadOnly(); |
| 2162 | |
| 2163 | attr->SetKind( m_attrkind ); |
| 2164 | |
| 2165 | return attr; |
| 2166 | } |
| 2167 | |
| 2168 | void wxGridCellAttr::MergeWith(wxGridCellAttr *mergefrom) |
| 2169 | { |
| 2170 | if ( !HasTextColour() && mergefrom->HasTextColour() ) |
| 2171 | SetTextColour(mergefrom->GetTextColour()); |
| 2172 | if ( !HasBackgroundColour() && mergefrom->HasBackgroundColour() ) |
| 2173 | SetBackgroundColour(mergefrom->GetBackgroundColour()); |
| 2174 | if ( !HasFont() && mergefrom->HasFont() ) |
| 2175 | SetFont(mergefrom->GetFont()); |
| 2176 | if ( !HasAlignment() && mergefrom->HasAlignment() ) |
| 2177 | { |
| 2178 | int hAlign, vAlign; |
| 2179 | mergefrom->GetAlignment( &hAlign, &vAlign); |
| 2180 | SetAlignment(hAlign, vAlign); |
| 2181 | } |
| 2182 | if ( !HasSize() && mergefrom->HasSize() ) |
| 2183 | mergefrom->GetSize( &m_sizeRows, &m_sizeCols ); |
| 2184 | |
| 2185 | // Directly access member functions as GetRender/Editor don't just return |
| 2186 | // m_renderer/m_editor |
| 2187 | // |
| 2188 | // Maybe add support for merge of Render and Editor? |
| 2189 | if (!HasRenderer() && mergefrom->HasRenderer() ) |
| 2190 | { |
| 2191 | m_renderer = mergefrom->m_renderer; |
| 2192 | m_renderer->IncRef(); |
| 2193 | } |
| 2194 | if ( !HasEditor() && mergefrom->HasEditor() ) |
| 2195 | { |
| 2196 | m_editor = mergefrom->m_editor; |
| 2197 | m_editor->IncRef(); |
| 2198 | } |
| 2199 | if ( !HasReadWriteMode() && mergefrom->HasReadWriteMode() ) |
| 2200 | SetReadOnly(mergefrom->IsReadOnly()); |
| 2201 | |
| 2202 | if (!HasOverflowMode() && mergefrom->HasOverflowMode() ) |
| 2203 | SetOverflow(mergefrom->GetOverflow()); |
| 2204 | |
| 2205 | SetDefAttr(mergefrom->m_defGridAttr); |
| 2206 | } |
| 2207 | |
| 2208 | void wxGridCellAttr::SetSize(int num_rows, int num_cols) |
| 2209 | { |
| 2210 | // The size of a cell is normally 1,1 |
| 2211 | |
| 2212 | // If this cell is larger (2,2) then this is the top left cell |
| 2213 | // the other cells that will be covered (lower right cells) must be |
| 2214 | // set to negative or zero values such that |
| 2215 | // row + num_rows of the covered cell points to the larger cell (this cell) |
| 2216 | // same goes for the col + num_cols. |
| 2217 | |
| 2218 | // Size of 0,0 is NOT valid, neither is <=0 and any positive value |
| 2219 | |
| 2220 | wxASSERT_MSG( (!((num_rows>0)&&(num_cols<=0)) || |
| 2221 | !((num_rows<=0)&&(num_cols>0)) || |
| 2222 | !((num_rows==0)&&(num_cols==0))), |
| 2223 | wxT("wxGridCellAttr::SetSize only takes two postive values or negative/zero values")); |
| 2224 | |
| 2225 | m_sizeRows = num_rows; |
| 2226 | m_sizeCols = num_cols; |
| 2227 | } |
| 2228 | |
| 2229 | const wxColour& wxGridCellAttr::GetTextColour() const |
| 2230 | { |
| 2231 | if (HasTextColour()) |
| 2232 | { |
| 2233 | return m_colText; |
| 2234 | } |
| 2235 | else if (m_defGridAttr && m_defGridAttr != this) |
| 2236 | { |
| 2237 | return m_defGridAttr->GetTextColour(); |
| 2238 | } |
| 2239 | else |
| 2240 | { |
| 2241 | wxFAIL_MSG(wxT("Missing default cell attribute")); |
| 2242 | return wxNullColour; |
| 2243 | } |
| 2244 | } |
| 2245 | |
| 2246 | |
| 2247 | const wxColour& wxGridCellAttr::GetBackgroundColour() const |
| 2248 | { |
| 2249 | if (HasBackgroundColour()) |
| 2250 | return m_colBack; |
| 2251 | else if (m_defGridAttr && m_defGridAttr != this) |
| 2252 | return m_defGridAttr->GetBackgroundColour(); |
| 2253 | else |
| 2254 | { |
| 2255 | wxFAIL_MSG(wxT("Missing default cell attribute")); |
| 2256 | return wxNullColour; |
| 2257 | } |
| 2258 | } |
| 2259 | |
| 2260 | |
| 2261 | const wxFont& wxGridCellAttr::GetFont() const |
| 2262 | { |
| 2263 | if (HasFont()) |
| 2264 | return m_font; |
| 2265 | else if (m_defGridAttr && m_defGridAttr != this) |
| 2266 | return m_defGridAttr->GetFont(); |
| 2267 | else |
| 2268 | { |
| 2269 | wxFAIL_MSG(wxT("Missing default cell attribute")); |
| 2270 | return wxNullFont; |
| 2271 | } |
| 2272 | } |
| 2273 | |
| 2274 | |
| 2275 | void wxGridCellAttr::GetAlignment(int *hAlign, int *vAlign) const |
| 2276 | { |
| 2277 | if (HasAlignment()) |
| 2278 | { |
| 2279 | if ( hAlign ) |
| 2280 | *hAlign = m_hAlign; |
| 2281 | if ( vAlign ) |
| 2282 | *vAlign = m_vAlign; |
| 2283 | } |
| 2284 | else if (m_defGridAttr && m_defGridAttr != this) |
| 2285 | m_defGridAttr->GetAlignment(hAlign, vAlign); |
| 2286 | else |
| 2287 | { |
| 2288 | wxFAIL_MSG(wxT("Missing default cell attribute")); |
| 2289 | } |
| 2290 | } |
| 2291 | |
| 2292 | void wxGridCellAttr::GetSize( int *num_rows, int *num_cols ) const |
| 2293 | { |
| 2294 | if ( num_rows ) |
| 2295 | *num_rows = m_sizeRows; |
| 2296 | if ( num_cols ) |
| 2297 | *num_cols = m_sizeCols; |
| 2298 | } |
| 2299 | |
| 2300 | // GetRenderer and GetEditor use a slightly different decision path about |
| 2301 | // which attribute to use. If a non-default attr object has one then it is |
| 2302 | // used, otherwise the default editor or renderer is fetched from the grid and |
| 2303 | // used. It should be the default for the data type of the cell. If it is |
| 2304 | // NULL (because the table has a type that the grid does not have in its |
| 2305 | // registry,) then the grid's default editor or renderer is used. |
| 2306 | |
| 2307 | wxGridCellRenderer* wxGridCellAttr::GetRenderer(wxGrid* grid, int row, int col) const |
| 2308 | { |
| 2309 | wxGridCellRenderer *renderer; |
| 2310 | |
| 2311 | if ( m_renderer && this != m_defGridAttr ) |
| 2312 | { |
| 2313 | // use the cells renderer if it has one |
| 2314 | renderer = m_renderer; |
| 2315 | renderer->IncRef(); |
| 2316 | } |
| 2317 | else // no non default cell renderer |
| 2318 | { |
| 2319 | // get default renderer for the data type |
| 2320 | if ( grid ) |
| 2321 | { |
| 2322 | // GetDefaultRendererForCell() will do IncRef() for us |
| 2323 | renderer = grid->GetDefaultRendererForCell(row, col); |
| 2324 | } |
| 2325 | else |
| 2326 | { |
| 2327 | renderer = NULL; |
| 2328 | } |
| 2329 | |
| 2330 | if ( !renderer ) |
| 2331 | { |
| 2332 | if (m_defGridAttr && this != m_defGridAttr ) |
| 2333 | { |
| 2334 | // if we still don't have one then use the grid default |
| 2335 | // (no need for IncRef() here neither) |
| 2336 | renderer = m_defGridAttr->GetRenderer(NULL, 0, 0); |
| 2337 | } |
| 2338 | else // default grid attr |
| 2339 | { |
| 2340 | // use m_renderer which we had decided not to use initially |
| 2341 | renderer = m_renderer; |
| 2342 | if ( renderer ) |
| 2343 | renderer->IncRef(); |
| 2344 | } |
| 2345 | } |
| 2346 | } |
| 2347 | |
| 2348 | // we're supposed to always find something |
| 2349 | wxASSERT_MSG(renderer, wxT("Missing default cell renderer")); |
| 2350 | |
| 2351 | return renderer; |
| 2352 | } |
| 2353 | |
| 2354 | // same as above, except for s/renderer/editor/g |
| 2355 | wxGridCellEditor* wxGridCellAttr::GetEditor(wxGrid* grid, int row, int col) const |
| 2356 | { |
| 2357 | wxGridCellEditor *editor; |
| 2358 | |
| 2359 | if ( m_editor && this != m_defGridAttr ) |
| 2360 | { |
| 2361 | // use the cells editor if it has one |
| 2362 | editor = m_editor; |
| 2363 | editor->IncRef(); |
| 2364 | } |
| 2365 | else // no non default cell editor |
| 2366 | { |
| 2367 | // get default editor for the data type |
| 2368 | if ( grid ) |
| 2369 | { |
| 2370 | // GetDefaultEditorForCell() will do IncRef() for us |
| 2371 | editor = grid->GetDefaultEditorForCell(row, col); |
| 2372 | } |
| 2373 | else |
| 2374 | { |
| 2375 | editor = NULL; |
| 2376 | } |
| 2377 | |
| 2378 | if ( !editor ) |
| 2379 | { |
| 2380 | if ( m_defGridAttr && this != m_defGridAttr ) |
| 2381 | { |
| 2382 | // if we still don't have one then use the grid default |
| 2383 | // (no need for IncRef() here neither) |
| 2384 | editor = m_defGridAttr->GetEditor(NULL, 0, 0); |
| 2385 | } |
| 2386 | else // default grid attr |
| 2387 | { |
| 2388 | // use m_editor which we had decided not to use initially |
| 2389 | editor = m_editor; |
| 2390 | if ( editor ) |
| 2391 | editor->IncRef(); |
| 2392 | } |
| 2393 | } |
| 2394 | } |
| 2395 | |
| 2396 | // we're supposed to always find something |
| 2397 | wxASSERT_MSG(editor, wxT("Missing default cell editor")); |
| 2398 | |
| 2399 | return editor; |
| 2400 | } |
| 2401 | |
| 2402 | // ---------------------------------------------------------------------------- |
| 2403 | // wxGridCellAttrData |
| 2404 | // ---------------------------------------------------------------------------- |
| 2405 | |
| 2406 | void wxGridCellAttrData::SetAttr(wxGridCellAttr *attr, int row, int col) |
| 2407 | { |
| 2408 | int n = FindIndex(row, col); |
| 2409 | if ( n == wxNOT_FOUND ) |
| 2410 | { |
| 2411 | // add the attribute |
| 2412 | m_attrs.Add(new wxGridCellWithAttr(row, col, attr)); |
| 2413 | } |
| 2414 | else |
| 2415 | { |
| 2416 | // free the old attribute |
| 2417 | m_attrs[(size_t)n].attr->DecRef(); |
| 2418 | |
| 2419 | if ( attr ) |
| 2420 | { |
| 2421 | // change the attribute |
| 2422 | m_attrs[(size_t)n].attr = attr; |
| 2423 | } |
| 2424 | else |
| 2425 | { |
| 2426 | // remove this attribute |
| 2427 | m_attrs.RemoveAt((size_t)n); |
| 2428 | } |
| 2429 | } |
| 2430 | } |
| 2431 | |
| 2432 | wxGridCellAttr *wxGridCellAttrData::GetAttr(int row, int col) const |
| 2433 | { |
| 2434 | wxGridCellAttr *attr = (wxGridCellAttr *)NULL; |
| 2435 | |
| 2436 | int n = FindIndex(row, col); |
| 2437 | if ( n != wxNOT_FOUND ) |
| 2438 | { |
| 2439 | attr = m_attrs[(size_t)n].attr; |
| 2440 | attr->IncRef(); |
| 2441 | } |
| 2442 | |
| 2443 | return attr; |
| 2444 | } |
| 2445 | |
| 2446 | void wxGridCellAttrData::UpdateAttrRows( size_t pos, int numRows ) |
| 2447 | { |
| 2448 | size_t count = m_attrs.GetCount(); |
| 2449 | for ( size_t n = 0; n < count; n++ ) |
| 2450 | { |
| 2451 | wxGridCellCoords& coords = m_attrs[n].coords; |
| 2452 | wxCoord row = coords.GetRow(); |
| 2453 | if ((size_t)row >= pos) |
| 2454 | { |
| 2455 | if (numRows > 0) |
| 2456 | { |
| 2457 | // If rows inserted, include row counter where necessary |
| 2458 | coords.SetRow(row + numRows); |
| 2459 | } |
| 2460 | else if (numRows < 0) |
| 2461 | { |
| 2462 | // If rows deleted ... |
| 2463 | if ((size_t)row >= pos - numRows) |
| 2464 | { |
| 2465 | // ...either decrement row counter (if row still exists)... |
| 2466 | coords.SetRow(row + numRows); |
| 2467 | } |
| 2468 | else |
| 2469 | { |
| 2470 | // ...or remove the attribute |
| 2471 | // No need to DecRef the attribute itself since this is |
| 2472 | // done be wxGridCellWithAttr's destructor! |
| 2473 | m_attrs.RemoveAt(n); |
| 2474 | n--; |
| 2475 | count--; |
| 2476 | } |
| 2477 | } |
| 2478 | } |
| 2479 | } |
| 2480 | } |
| 2481 | |
| 2482 | void wxGridCellAttrData::UpdateAttrCols( size_t pos, int numCols ) |
| 2483 | { |
| 2484 | size_t count = m_attrs.GetCount(); |
| 2485 | for ( size_t n = 0; n < count; n++ ) |
| 2486 | { |
| 2487 | wxGridCellCoords& coords = m_attrs[n].coords; |
| 2488 | wxCoord col = coords.GetCol(); |
| 2489 | if ( (size_t)col >= pos ) |
| 2490 | { |
| 2491 | if ( numCols > 0 ) |
| 2492 | { |
| 2493 | // If rows inserted, include row counter where necessary |
| 2494 | coords.SetCol(col + numCols); |
| 2495 | } |
| 2496 | else if (numCols < 0) |
| 2497 | { |
| 2498 | // If rows deleted ... |
| 2499 | if ((size_t)col >= pos - numCols) |
| 2500 | { |
| 2501 | // ...either decrement row counter (if row still exists)... |
| 2502 | coords.SetCol(col + numCols); |
| 2503 | } |
| 2504 | else |
| 2505 | { |
| 2506 | // ...or remove the attribute |
| 2507 | // No need to DecRef the attribute itself since this is |
| 2508 | // done be wxGridCellWithAttr's destructor! |
| 2509 | m_attrs.RemoveAt(n); |
| 2510 | n--; count--; |
| 2511 | } |
| 2512 | } |
| 2513 | } |
| 2514 | } |
| 2515 | } |
| 2516 | |
| 2517 | int wxGridCellAttrData::FindIndex(int row, int col) const |
| 2518 | { |
| 2519 | size_t count = m_attrs.GetCount(); |
| 2520 | for ( size_t n = 0; n < count; n++ ) |
| 2521 | { |
| 2522 | const wxGridCellCoords& coords = m_attrs[n].coords; |
| 2523 | if ( (coords.GetRow() == row) && (coords.GetCol() == col) ) |
| 2524 | { |
| 2525 | return n; |
| 2526 | } |
| 2527 | } |
| 2528 | |
| 2529 | return wxNOT_FOUND; |
| 2530 | } |
| 2531 | |
| 2532 | // ---------------------------------------------------------------------------- |
| 2533 | // wxGridRowOrColAttrData |
| 2534 | // ---------------------------------------------------------------------------- |
| 2535 | |
| 2536 | wxGridRowOrColAttrData::~wxGridRowOrColAttrData() |
| 2537 | { |
| 2538 | size_t count = m_attrs.Count(); |
| 2539 | for ( size_t n = 0; n < count; n++ ) |
| 2540 | { |
| 2541 | m_attrs[n]->DecRef(); |
| 2542 | } |
| 2543 | } |
| 2544 | |
| 2545 | wxGridCellAttr *wxGridRowOrColAttrData::GetAttr(int rowOrCol) const |
| 2546 | { |
| 2547 | wxGridCellAttr *attr = (wxGridCellAttr *)NULL; |
| 2548 | |
| 2549 | int n = m_rowsOrCols.Index(rowOrCol); |
| 2550 | if ( n != wxNOT_FOUND ) |
| 2551 | { |
| 2552 | attr = m_attrs[(size_t)n]; |
| 2553 | attr->IncRef(); |
| 2554 | } |
| 2555 | |
| 2556 | return attr; |
| 2557 | } |
| 2558 | |
| 2559 | void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr *attr, int rowOrCol) |
| 2560 | { |
| 2561 | int i = m_rowsOrCols.Index(rowOrCol); |
| 2562 | if ( i == wxNOT_FOUND ) |
| 2563 | { |
| 2564 | // add the attribute |
| 2565 | m_rowsOrCols.Add(rowOrCol); |
| 2566 | m_attrs.Add(attr); |
| 2567 | } |
| 2568 | else |
| 2569 | { |
| 2570 | size_t n = (size_t)i; |
| 2571 | if ( attr ) |
| 2572 | { |
| 2573 | // change the attribute |
| 2574 | m_attrs[n]->DecRef(); |
| 2575 | m_attrs[n] = attr; |
| 2576 | } |
| 2577 | else |
| 2578 | { |
| 2579 | // remove this attribute |
| 2580 | m_attrs[n]->DecRef(); |
| 2581 | m_rowsOrCols.RemoveAt(n); |
| 2582 | m_attrs.RemoveAt(n); |
| 2583 | } |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | void wxGridRowOrColAttrData::UpdateAttrRowsOrCols( size_t pos, int numRowsOrCols ) |
| 2588 | { |
| 2589 | size_t count = m_attrs.GetCount(); |
| 2590 | for ( size_t n = 0; n < count; n++ ) |
| 2591 | { |
| 2592 | int & rowOrCol = m_rowsOrCols[n]; |
| 2593 | if ( (size_t)rowOrCol >= pos ) |
| 2594 | { |
| 2595 | if ( numRowsOrCols > 0 ) |
| 2596 | { |
| 2597 | // If rows inserted, include row counter where necessary |
| 2598 | rowOrCol += numRowsOrCols; |
| 2599 | } |
| 2600 | else if ( numRowsOrCols < 0) |
| 2601 | { |
| 2602 | // If rows deleted, either decrement row counter (if row still exists) |
| 2603 | if ((size_t)rowOrCol >= pos - numRowsOrCols) |
| 2604 | rowOrCol += numRowsOrCols; |
| 2605 | else |
| 2606 | { |
| 2607 | m_rowsOrCols.RemoveAt(n); |
| 2608 | m_attrs[n]->DecRef(); |
| 2609 | m_attrs.RemoveAt(n); |
| 2610 | n--; |
| 2611 | count--; |
| 2612 | } |
| 2613 | } |
| 2614 | } |
| 2615 | } |
| 2616 | } |
| 2617 | |
| 2618 | // ---------------------------------------------------------------------------- |
| 2619 | // wxGridCellAttrProvider |
| 2620 | // ---------------------------------------------------------------------------- |
| 2621 | |
| 2622 | wxGridCellAttrProvider::wxGridCellAttrProvider() |
| 2623 | { |
| 2624 | m_data = (wxGridCellAttrProviderData *)NULL; |
| 2625 | } |
| 2626 | |
| 2627 | wxGridCellAttrProvider::~wxGridCellAttrProvider() |
| 2628 | { |
| 2629 | delete m_data; |
| 2630 | } |
| 2631 | |
| 2632 | void wxGridCellAttrProvider::InitData() |
| 2633 | { |
| 2634 | m_data = new wxGridCellAttrProviderData; |
| 2635 | } |
| 2636 | |
| 2637 | wxGridCellAttr *wxGridCellAttrProvider::GetAttr(int row, int col, |
| 2638 | wxGridCellAttr::wxAttrKind kind ) const |
| 2639 | { |
| 2640 | wxGridCellAttr *attr = (wxGridCellAttr *)NULL; |
| 2641 | if ( m_data ) |
| 2642 | { |
| 2643 | switch (kind) |
| 2644 | { |
| 2645 | case (wxGridCellAttr::Any): |
| 2646 | // Get cached merge attributes. |
| 2647 | // Currently not used as no cache implemented as not mutable |
| 2648 | // attr = m_data->m_mergeAttr.GetAttr(row, col); |
| 2649 | if (!attr) |
| 2650 | { |
| 2651 | // Basically implement old version. |
| 2652 | // Also check merge cache, so we don't have to re-merge every time.. |
| 2653 | wxGridCellAttr *attrcell = m_data->m_cellAttrs.GetAttr(row, col); |
| 2654 | wxGridCellAttr *attrrow = m_data->m_rowAttrs.GetAttr(row); |
| 2655 | wxGridCellAttr *attrcol = m_data->m_colAttrs.GetAttr(col); |
| 2656 | |
| 2657 | if ((attrcell != attrrow) && (attrrow != attrcol) && (attrcell != attrcol)) |
| 2658 | { |
| 2659 | // Two or more are non NULL |
| 2660 | attr = new wxGridCellAttr; |
| 2661 | attr->SetKind(wxGridCellAttr::Merged); |
| 2662 | |
| 2663 | // Order is important.. |
| 2664 | if (attrcell) |
| 2665 | { |
| 2666 | attr->MergeWith(attrcell); |
| 2667 | attrcell->DecRef(); |
| 2668 | } |
| 2669 | if (attrcol) |
| 2670 | { |
| 2671 | attr->MergeWith(attrcol); |
| 2672 | attrcol->DecRef(); |
| 2673 | } |
| 2674 | if (attrrow) |
| 2675 | { |
| 2676 | attr->MergeWith(attrrow); |
| 2677 | attrrow->DecRef(); |
| 2678 | } |
| 2679 | |
| 2680 | // store merge attr if cache implemented |
| 2681 | //attr->IncRef(); |
| 2682 | //m_data->m_mergeAttr.SetAttr(attr, row, col); |
| 2683 | } |
| 2684 | else |
| 2685 | { |
| 2686 | // one or none is non null return it or null. |
| 2687 | if (attrrow) |
| 2688 | attr = attrrow; |
| 2689 | if (attrcol) |
| 2690 | { |
| 2691 | if (attr) |
| 2692 | attr->DecRef(); |
| 2693 | attr = attrcol; |
| 2694 | } |
| 2695 | if (attrcell) |
| 2696 | { |
| 2697 | if (attr) |
| 2698 | attr->DecRef(); |
| 2699 | attr = attrcell; |
| 2700 | } |
| 2701 | } |
| 2702 | } |
| 2703 | break; |
| 2704 | |
| 2705 | case (wxGridCellAttr::Cell): |
| 2706 | attr = m_data->m_cellAttrs.GetAttr(row, col); |
| 2707 | break; |
| 2708 | |
| 2709 | case (wxGridCellAttr::Col): |
| 2710 | attr = m_data->m_colAttrs.GetAttr(col); |
| 2711 | break; |
| 2712 | |
| 2713 | case (wxGridCellAttr::Row): |
| 2714 | attr = m_data->m_rowAttrs.GetAttr(row); |
| 2715 | break; |
| 2716 | |
| 2717 | default: |
| 2718 | // unused as yet... |
| 2719 | // (wxGridCellAttr::Default): |
| 2720 | // (wxGridCellAttr::Merged): |
| 2721 | break; |
| 2722 | } |
| 2723 | } |
| 2724 | return attr; |
| 2725 | } |
| 2726 | |
| 2727 | void wxGridCellAttrProvider::SetAttr(wxGridCellAttr *attr, |
| 2728 | int row, int col) |
| 2729 | { |
| 2730 | if ( !m_data ) |
| 2731 | InitData(); |
| 2732 | |
| 2733 | m_data->m_cellAttrs.SetAttr(attr, row, col); |
| 2734 | } |
| 2735 | |
| 2736 | void wxGridCellAttrProvider::SetRowAttr(wxGridCellAttr *attr, int row) |
| 2737 | { |
| 2738 | if ( !m_data ) |
| 2739 | InitData(); |
| 2740 | |
| 2741 | m_data->m_rowAttrs.SetAttr(attr, row); |
| 2742 | } |
| 2743 | |
| 2744 | void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr *attr, int col) |
| 2745 | { |
| 2746 | if ( !m_data ) |
| 2747 | InitData(); |
| 2748 | |
| 2749 | m_data->m_colAttrs.SetAttr(attr, col); |
| 2750 | } |
| 2751 | |
| 2752 | void wxGridCellAttrProvider::UpdateAttrRows( size_t pos, int numRows ) |
| 2753 | { |
| 2754 | if ( m_data ) |
| 2755 | { |
| 2756 | m_data->m_cellAttrs.UpdateAttrRows( pos, numRows ); |
| 2757 | |
| 2758 | m_data->m_rowAttrs.UpdateAttrRowsOrCols( pos, numRows ); |
| 2759 | } |
| 2760 | } |
| 2761 | |
| 2762 | void wxGridCellAttrProvider::UpdateAttrCols( size_t pos, int numCols ) |
| 2763 | { |
| 2764 | if ( m_data ) |
| 2765 | { |
| 2766 | m_data->m_cellAttrs.UpdateAttrCols( pos, numCols ); |
| 2767 | |
| 2768 | m_data->m_colAttrs.UpdateAttrRowsOrCols( pos, numCols ); |
| 2769 | } |
| 2770 | } |
| 2771 | |
| 2772 | // ---------------------------------------------------------------------------- |
| 2773 | // wxGridTypeRegistry |
| 2774 | // ---------------------------------------------------------------------------- |
| 2775 | |
| 2776 | wxGridTypeRegistry::~wxGridTypeRegistry() |
| 2777 | { |
| 2778 | size_t count = m_typeinfo.Count(); |
| 2779 | for ( size_t i = 0; i < count; i++ ) |
| 2780 | delete m_typeinfo[i]; |
| 2781 | } |
| 2782 | |
| 2783 | |
| 2784 | void wxGridTypeRegistry::RegisterDataType(const wxString& typeName, |
| 2785 | wxGridCellRenderer* renderer, |
| 2786 | wxGridCellEditor* editor) |
| 2787 | { |
| 2788 | wxGridDataTypeInfo* info = new wxGridDataTypeInfo(typeName, renderer, editor); |
| 2789 | |
| 2790 | // is it already registered? |
| 2791 | int loc = FindRegisteredDataType(typeName); |
| 2792 | if ( loc != wxNOT_FOUND ) |
| 2793 | { |
| 2794 | delete m_typeinfo[loc]; |
| 2795 | m_typeinfo[loc] = info; |
| 2796 | } |
| 2797 | else |
| 2798 | { |
| 2799 | m_typeinfo.Add(info); |
| 2800 | } |
| 2801 | } |
| 2802 | |
| 2803 | int wxGridTypeRegistry::FindRegisteredDataType(const wxString& typeName) |
| 2804 | { |
| 2805 | size_t count = m_typeinfo.GetCount(); |
| 2806 | for ( size_t i = 0; i < count; i++ ) |
| 2807 | { |
| 2808 | if ( typeName == m_typeinfo[i]->m_typeName ) |
| 2809 | { |
| 2810 | return i; |
| 2811 | } |
| 2812 | } |
| 2813 | |
| 2814 | return wxNOT_FOUND; |
| 2815 | } |
| 2816 | |
| 2817 | int wxGridTypeRegistry::FindDataType(const wxString& typeName) |
| 2818 | { |
| 2819 | int index = FindRegisteredDataType(typeName); |
| 2820 | if ( index == wxNOT_FOUND ) |
| 2821 | { |
| 2822 | // check whether this is one of the standard ones, in which case |
| 2823 | // register it "on the fly" |
| 2824 | #if wxUSE_TEXTCTRL |
| 2825 | if ( typeName == wxGRID_VALUE_STRING ) |
| 2826 | { |
| 2827 | RegisterDataType(wxGRID_VALUE_STRING, |
| 2828 | new wxGridCellStringRenderer, |
| 2829 | new wxGridCellTextEditor); |
| 2830 | } |
| 2831 | else |
| 2832 | #endif // wxUSE_TEXTCTRL |
| 2833 | #if wxUSE_CHECKBOX |
| 2834 | if ( typeName == wxGRID_VALUE_BOOL ) |
| 2835 | { |
| 2836 | RegisterDataType(wxGRID_VALUE_BOOL, |
| 2837 | new wxGridCellBoolRenderer, |
| 2838 | new wxGridCellBoolEditor); |
| 2839 | } |
| 2840 | else |
| 2841 | #endif // wxUSE_CHECKBOX |
| 2842 | #if wxUSE_TEXTCTRL |
| 2843 | if ( typeName == wxGRID_VALUE_NUMBER ) |
| 2844 | { |
| 2845 | RegisterDataType(wxGRID_VALUE_NUMBER, |
| 2846 | new wxGridCellNumberRenderer, |
| 2847 | new wxGridCellNumberEditor); |
| 2848 | } |
| 2849 | else if ( typeName == wxGRID_VALUE_FLOAT ) |
| 2850 | { |
| 2851 | RegisterDataType(wxGRID_VALUE_FLOAT, |
| 2852 | new wxGridCellFloatRenderer, |
| 2853 | new wxGridCellFloatEditor); |
| 2854 | } |
| 2855 | else |
| 2856 | #endif // wxUSE_TEXTCTRL |
| 2857 | #if wxUSE_COMBOBOX |
| 2858 | if ( typeName == wxGRID_VALUE_CHOICE ) |
| 2859 | { |
| 2860 | RegisterDataType(wxGRID_VALUE_CHOICE, |
| 2861 | new wxGridCellStringRenderer, |
| 2862 | new wxGridCellChoiceEditor); |
| 2863 | } |
| 2864 | else |
| 2865 | #endif // wxUSE_COMBOBOX |
| 2866 | { |
| 2867 | return wxNOT_FOUND; |
| 2868 | } |
| 2869 | |
| 2870 | // we get here only if just added the entry for this type, so return |
| 2871 | // the last index |
| 2872 | index = m_typeinfo.GetCount() - 1; |
| 2873 | } |
| 2874 | |
| 2875 | return index; |
| 2876 | } |
| 2877 | |
| 2878 | int wxGridTypeRegistry::FindOrCloneDataType(const wxString& typeName) |
| 2879 | { |
| 2880 | int index = FindDataType(typeName); |
| 2881 | if ( index == wxNOT_FOUND ) |
| 2882 | { |
| 2883 | // the first part of the typename is the "real" type, anything after ':' |
| 2884 | // are the parameters for the renderer |
| 2885 | index = FindDataType(typeName.BeforeFirst(_T(':'))); |
| 2886 | if ( index == wxNOT_FOUND ) |
| 2887 | { |
| 2888 | return wxNOT_FOUND; |
| 2889 | } |
| 2890 | |
| 2891 | wxGridCellRenderer *renderer = GetRenderer(index); |
| 2892 | wxGridCellRenderer *rendererOld = renderer; |
| 2893 | renderer = renderer->Clone(); |
| 2894 | rendererOld->DecRef(); |
| 2895 | |
| 2896 | wxGridCellEditor *editor = GetEditor(index); |
| 2897 | wxGridCellEditor *editorOld = editor; |
| 2898 | editor = editor->Clone(); |
| 2899 | editorOld->DecRef(); |
| 2900 | |
| 2901 | // do it even if there are no parameters to reset them to defaults |
| 2902 | wxString params = typeName.AfterFirst(_T(':')); |
| 2903 | renderer->SetParameters(params); |
| 2904 | editor->SetParameters(params); |
| 2905 | |
| 2906 | // register the new typename |
| 2907 | RegisterDataType(typeName, renderer, editor); |
| 2908 | |
| 2909 | // we just registered it, it's the last one |
| 2910 | index = m_typeinfo.GetCount() - 1; |
| 2911 | } |
| 2912 | |
| 2913 | return index; |
| 2914 | } |
| 2915 | |
| 2916 | wxGridCellRenderer* wxGridTypeRegistry::GetRenderer(int index) |
| 2917 | { |
| 2918 | wxGridCellRenderer* renderer = m_typeinfo[index]->m_renderer; |
| 2919 | if (renderer) |
| 2920 | renderer->IncRef(); |
| 2921 | return renderer; |
| 2922 | } |
| 2923 | |
| 2924 | wxGridCellEditor* wxGridTypeRegistry::GetEditor(int index) |
| 2925 | { |
| 2926 | wxGridCellEditor* editor = m_typeinfo[index]->m_editor; |
| 2927 | if (editor) |
| 2928 | editor->IncRef(); |
| 2929 | return editor; |
| 2930 | } |
| 2931 | |
| 2932 | // ---------------------------------------------------------------------------- |
| 2933 | // wxGridTableBase |
| 2934 | // ---------------------------------------------------------------------------- |
| 2935 | |
| 2936 | IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase, wxObject ) |
| 2937 | |
| 2938 | |
| 2939 | wxGridTableBase::wxGridTableBase() |
| 2940 | { |
| 2941 | m_view = (wxGrid *) NULL; |
| 2942 | m_attrProvider = (wxGridCellAttrProvider *) NULL; |
| 2943 | } |
| 2944 | |
| 2945 | wxGridTableBase::~wxGridTableBase() |
| 2946 | { |
| 2947 | delete m_attrProvider; |
| 2948 | } |
| 2949 | |
| 2950 | void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider *attrProvider) |
| 2951 | { |
| 2952 | delete m_attrProvider; |
| 2953 | m_attrProvider = attrProvider; |
| 2954 | } |
| 2955 | |
| 2956 | bool wxGridTableBase::CanHaveAttributes() |
| 2957 | { |
| 2958 | if ( ! GetAttrProvider() ) |
| 2959 | { |
| 2960 | // use the default attr provider by default |
| 2961 | SetAttrProvider(new wxGridCellAttrProvider); |
| 2962 | } |
| 2963 | return true; |
| 2964 | } |
| 2965 | |
| 2966 | wxGridCellAttr *wxGridTableBase::GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind) |
| 2967 | { |
| 2968 | if ( m_attrProvider ) |
| 2969 | return m_attrProvider->GetAttr(row, col, kind); |
| 2970 | else |
| 2971 | return (wxGridCellAttr *)NULL; |
| 2972 | } |
| 2973 | |
| 2974 | |
| 2975 | void wxGridTableBase::SetAttr(wxGridCellAttr* attr, int row, int col) |
| 2976 | { |
| 2977 | if ( m_attrProvider ) |
| 2978 | { |
| 2979 | attr->SetKind(wxGridCellAttr::Cell); |
| 2980 | m_attrProvider->SetAttr(attr, row, col); |
| 2981 | } |
| 2982 | else |
| 2983 | { |
| 2984 | // as we take ownership of the pointer and don't store it, we must |
| 2985 | // free it now |
| 2986 | wxSafeDecRef(attr); |
| 2987 | } |
| 2988 | } |
| 2989 | |
| 2990 | void wxGridTableBase::SetRowAttr(wxGridCellAttr *attr, int row) |
| 2991 | { |
| 2992 | if ( m_attrProvider ) |
| 2993 | { |
| 2994 | attr->SetKind(wxGridCellAttr::Row); |
| 2995 | m_attrProvider->SetRowAttr(attr, row); |
| 2996 | } |
| 2997 | else |
| 2998 | { |
| 2999 | // as we take ownership of the pointer and don't store it, we must |
| 3000 | // free it now |
| 3001 | wxSafeDecRef(attr); |
| 3002 | } |
| 3003 | } |
| 3004 | |
| 3005 | void wxGridTableBase::SetColAttr(wxGridCellAttr *attr, int col) |
| 3006 | { |
| 3007 | if ( m_attrProvider ) |
| 3008 | { |
| 3009 | attr->SetKind(wxGridCellAttr::Col); |
| 3010 | m_attrProvider->SetColAttr(attr, col); |
| 3011 | } |
| 3012 | else |
| 3013 | { |
| 3014 | // as we take ownership of the pointer and don't store it, we must |
| 3015 | // free it now |
| 3016 | wxSafeDecRef(attr); |
| 3017 | } |
| 3018 | } |
| 3019 | |
| 3020 | bool wxGridTableBase::InsertRows( size_t WXUNUSED(pos), |
| 3021 | size_t WXUNUSED(numRows) ) |
| 3022 | { |
| 3023 | wxFAIL_MSG( wxT("Called grid table class function InsertRows\nbut your derived table class does not override this function") ); |
| 3024 | |
| 3025 | return false; |
| 3026 | } |
| 3027 | |
| 3028 | bool wxGridTableBase::AppendRows( size_t WXUNUSED(numRows) ) |
| 3029 | { |
| 3030 | wxFAIL_MSG( wxT("Called grid table class function AppendRows\nbut your derived table class does not override this function")); |
| 3031 | |
| 3032 | return false; |
| 3033 | } |
| 3034 | |
| 3035 | bool wxGridTableBase::DeleteRows( size_t WXUNUSED(pos), |
| 3036 | size_t WXUNUSED(numRows) ) |
| 3037 | { |
| 3038 | wxFAIL_MSG( wxT("Called grid table class function DeleteRows\nbut your derived table class does not override this function")); |
| 3039 | |
| 3040 | return false; |
| 3041 | } |
| 3042 | |
| 3043 | bool wxGridTableBase::InsertCols( size_t WXUNUSED(pos), |
| 3044 | size_t WXUNUSED(numCols) ) |
| 3045 | { |
| 3046 | wxFAIL_MSG( wxT("Called grid table class function InsertCols\nbut your derived table class does not override this function")); |
| 3047 | |
| 3048 | return false; |
| 3049 | } |
| 3050 | |
| 3051 | bool wxGridTableBase::AppendCols( size_t WXUNUSED(numCols) ) |
| 3052 | { |
| 3053 | wxFAIL_MSG(wxT("Called grid table class function AppendCols\nbut your derived table class does not override this function")); |
| 3054 | |
| 3055 | return false; |
| 3056 | } |
| 3057 | |
| 3058 | bool wxGridTableBase::DeleteCols( size_t WXUNUSED(pos), |
| 3059 | size_t WXUNUSED(numCols) ) |
| 3060 | { |
| 3061 | wxFAIL_MSG( wxT("Called grid table class function DeleteCols\nbut your derived table class does not override this function")); |
| 3062 | |
| 3063 | return false; |
| 3064 | } |
| 3065 | |
| 3066 | wxString wxGridTableBase::GetRowLabelValue( int row ) |
| 3067 | { |
| 3068 | wxString s; |
| 3069 | s << row + 1; // RD: Starting the rows at zero confuses users, no matter |
| 3070 | // how much it makes sense to us geeks. |
| 3071 | return s; |
| 3072 | } |
| 3073 | |
| 3074 | wxString wxGridTableBase::GetColLabelValue( int col ) |
| 3075 | { |
| 3076 | // default col labels are: |
| 3077 | // cols 0 to 25 : A-Z |
| 3078 | // cols 26 to 675 : AA-ZZ |
| 3079 | // etc. |
| 3080 | |
| 3081 | wxString s; |
| 3082 | unsigned int i, n; |
| 3083 | for ( n = 1; ; n++ ) |
| 3084 | { |
| 3085 | s += (wxChar) (_T('A') + (wxChar)( col%26 )); |
| 3086 | col = col/26 - 1; |
| 3087 | if ( col < 0 ) |
| 3088 | break; |
| 3089 | } |
| 3090 | |
| 3091 | // reverse the string... |
| 3092 | wxString s2; |
| 3093 | for ( i = 0; i < n; i++ ) |
| 3094 | { |
| 3095 | s2 += s[n-i-1]; |
| 3096 | } |
| 3097 | |
| 3098 | return s2; |
| 3099 | } |
| 3100 | |
| 3101 | wxString wxGridTableBase::GetTypeName( int WXUNUSED(row), int WXUNUSED(col) ) |
| 3102 | { |
| 3103 | return wxGRID_VALUE_STRING; |
| 3104 | } |
| 3105 | |
| 3106 | bool wxGridTableBase::CanGetValueAs( int WXUNUSED(row), int WXUNUSED(col), |
| 3107 | const wxString& typeName ) |
| 3108 | { |
| 3109 | return typeName == wxGRID_VALUE_STRING; |
| 3110 | } |
| 3111 | |
| 3112 | bool wxGridTableBase::CanSetValueAs( int row, int col, const wxString& typeName ) |
| 3113 | { |
| 3114 | return CanGetValueAs(row, col, typeName); |
| 3115 | } |
| 3116 | |
| 3117 | long wxGridTableBase::GetValueAsLong( int WXUNUSED(row), int WXUNUSED(col) ) |
| 3118 | { |
| 3119 | return 0; |
| 3120 | } |
| 3121 | |
| 3122 | double wxGridTableBase::GetValueAsDouble( int WXUNUSED(row), int WXUNUSED(col) ) |
| 3123 | { |
| 3124 | return 0.0; |
| 3125 | } |
| 3126 | |
| 3127 | bool wxGridTableBase::GetValueAsBool( int WXUNUSED(row), int WXUNUSED(col) ) |
| 3128 | { |
| 3129 | return false; |
| 3130 | } |
| 3131 | |
| 3132 | void wxGridTableBase::SetValueAsLong( int WXUNUSED(row), int WXUNUSED(col), |
| 3133 | long WXUNUSED(value) ) |
| 3134 | { |
| 3135 | } |
| 3136 | |
| 3137 | void wxGridTableBase::SetValueAsDouble( int WXUNUSED(row), int WXUNUSED(col), |
| 3138 | double WXUNUSED(value) ) |
| 3139 | { |
| 3140 | } |
| 3141 | |
| 3142 | void wxGridTableBase::SetValueAsBool( int WXUNUSED(row), int WXUNUSED(col), |
| 3143 | bool WXUNUSED(value) ) |
| 3144 | { |
| 3145 | } |
| 3146 | |
| 3147 | |
| 3148 | void* wxGridTableBase::GetValueAsCustom( int WXUNUSED(row), int WXUNUSED(col), |
| 3149 | const wxString& WXUNUSED(typeName) ) |
| 3150 | { |
| 3151 | return NULL; |
| 3152 | } |
| 3153 | |
| 3154 | void wxGridTableBase::SetValueAsCustom( int WXUNUSED(row), int WXUNUSED(col), |
| 3155 | const wxString& WXUNUSED(typeName), |
| 3156 | void* WXUNUSED(value) ) |
| 3157 | { |
| 3158 | } |
| 3159 | |
| 3160 | ////////////////////////////////////////////////////////////////////// |
| 3161 | // |
| 3162 | // Message class for the grid table to send requests and notifications |
| 3163 | // to the grid view |
| 3164 | // |
| 3165 | |
| 3166 | wxGridTableMessage::wxGridTableMessage() |
| 3167 | { |
| 3168 | m_table = (wxGridTableBase *) NULL; |
| 3169 | m_id = -1; |
| 3170 | m_comInt1 = -1; |
| 3171 | m_comInt2 = -1; |
| 3172 | } |
| 3173 | |
| 3174 | wxGridTableMessage::wxGridTableMessage( wxGridTableBase *table, int id, |
| 3175 | int commandInt1, int commandInt2 ) |
| 3176 | { |
| 3177 | m_table = table; |
| 3178 | m_id = id; |
| 3179 | m_comInt1 = commandInt1; |
| 3180 | m_comInt2 = commandInt2; |
| 3181 | } |
| 3182 | |
| 3183 | |
| 3184 | |
| 3185 | ////////////////////////////////////////////////////////////////////// |
| 3186 | // |
| 3187 | // A basic grid table for string data. An object of this class will |
| 3188 | // created by wxGrid if you don't specify an alternative table class. |
| 3189 | // |
| 3190 | |
| 3191 | WX_DEFINE_OBJARRAY(wxGridStringArray) |
| 3192 | |
| 3193 | IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable, wxGridTableBase ) |
| 3194 | |
| 3195 | wxGridStringTable::wxGridStringTable() |
| 3196 | : wxGridTableBase() |
| 3197 | { |
| 3198 | } |
| 3199 | |
| 3200 | wxGridStringTable::wxGridStringTable( int numRows, int numCols ) |
| 3201 | : wxGridTableBase() |
| 3202 | { |
| 3203 | m_data.Alloc( numRows ); |
| 3204 | |
| 3205 | wxArrayString sa; |
| 3206 | sa.Alloc( numCols ); |
| 3207 | sa.Add( wxEmptyString, numCols ); |
| 3208 | |
| 3209 | m_data.Add( sa, numRows ); |
| 3210 | } |
| 3211 | |
| 3212 | wxGridStringTable::~wxGridStringTable() |
| 3213 | { |
| 3214 | } |
| 3215 | |
| 3216 | int wxGridStringTable::GetNumberRows() |
| 3217 | { |
| 3218 | return m_data.GetCount(); |
| 3219 | } |
| 3220 | |
| 3221 | int wxGridStringTable::GetNumberCols() |
| 3222 | { |
| 3223 | if ( m_data.GetCount() > 0 ) |
| 3224 | return m_data[0].GetCount(); |
| 3225 | else |
| 3226 | return 0; |
| 3227 | } |
| 3228 | |
| 3229 | wxString wxGridStringTable::GetValue( int row, int col ) |
| 3230 | { |
| 3231 | wxCHECK_MSG( (row < GetNumberRows()) && (col < GetNumberCols()), |
| 3232 | wxEmptyString, |
| 3233 | _T("invalid row or column index in wxGridStringTable") ); |
| 3234 | |
| 3235 | return m_data[row][col]; |
| 3236 | } |
| 3237 | |
| 3238 | void wxGridStringTable::SetValue( int row, int col, const wxString& value ) |
| 3239 | { |
| 3240 | wxCHECK_RET( (row < GetNumberRows()) && (col < GetNumberCols()), |
| 3241 | _T("invalid row or column index in wxGridStringTable") ); |
| 3242 | |
| 3243 | m_data[row][col] = value; |
| 3244 | } |
| 3245 | |
| 3246 | bool wxGridStringTable::IsEmptyCell( int row, int col ) |
| 3247 | { |
| 3248 | wxCHECK_MSG( (row < GetNumberRows()) && (col < GetNumberCols()), |
| 3249 | true, |
| 3250 | _T("invalid row or column index in wxGridStringTable") ); |
| 3251 | |
| 3252 | return (m_data[row][col] == wxEmptyString); |
| 3253 | } |
| 3254 | |
| 3255 | void wxGridStringTable::Clear() |
| 3256 | { |
| 3257 | int row, col; |
| 3258 | int numRows, numCols; |
| 3259 | |
| 3260 | numRows = m_data.GetCount(); |
| 3261 | if ( numRows > 0 ) |
| 3262 | { |
| 3263 | numCols = m_data[0].GetCount(); |
| 3264 | |
| 3265 | for ( row = 0; row < numRows; row++ ) |
| 3266 | { |
| 3267 | for ( col = 0; col < numCols; col++ ) |
| 3268 | { |
| 3269 | m_data[row][col] = wxEmptyString; |
| 3270 | } |
| 3271 | } |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | |
| 3276 | bool wxGridStringTable::InsertRows( size_t pos, size_t numRows ) |
| 3277 | { |
| 3278 | size_t curNumRows = m_data.GetCount(); |
| 3279 | size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : |
| 3280 | ( GetView() ? GetView()->GetNumberCols() : 0 ) ); |
| 3281 | |
| 3282 | if ( pos >= curNumRows ) |
| 3283 | { |
| 3284 | return AppendRows( numRows ); |
| 3285 | } |
| 3286 | |
| 3287 | wxArrayString sa; |
| 3288 | sa.Alloc( curNumCols ); |
| 3289 | sa.Add( wxEmptyString, curNumCols ); |
| 3290 | m_data.Insert( sa, pos, numRows ); |
| 3291 | if ( GetView() ) |
| 3292 | { |
| 3293 | wxGridTableMessage msg( this, |
| 3294 | wxGRIDTABLE_NOTIFY_ROWS_INSERTED, |
| 3295 | pos, |
| 3296 | numRows ); |
| 3297 | |
| 3298 | GetView()->ProcessTableMessage( msg ); |
| 3299 | } |
| 3300 | |
| 3301 | return true; |
| 3302 | } |
| 3303 | |
| 3304 | bool wxGridStringTable::AppendRows( size_t numRows ) |
| 3305 | { |
| 3306 | size_t curNumRows = m_data.GetCount(); |
| 3307 | size_t curNumCols = ( curNumRows > 0 |
| 3308 | ? m_data[0].GetCount() |
| 3309 | : ( GetView() ? GetView()->GetNumberCols() : 0 ) ); |
| 3310 | |
| 3311 | wxArrayString sa; |
| 3312 | if ( curNumCols > 0 ) |
| 3313 | { |
| 3314 | sa.Alloc( curNumCols ); |
| 3315 | sa.Add( wxEmptyString, curNumCols ); |
| 3316 | } |
| 3317 | |
| 3318 | m_data.Add( sa, numRows ); |
| 3319 | |
| 3320 | if ( GetView() ) |
| 3321 | { |
| 3322 | wxGridTableMessage msg( this, |
| 3323 | wxGRIDTABLE_NOTIFY_ROWS_APPENDED, |
| 3324 | numRows ); |
| 3325 | |
| 3326 | GetView()->ProcessTableMessage( msg ); |
| 3327 | } |
| 3328 | |
| 3329 | return true; |
| 3330 | } |
| 3331 | |
| 3332 | bool wxGridStringTable::DeleteRows( size_t pos, size_t numRows ) |
| 3333 | { |
| 3334 | size_t curNumRows = m_data.GetCount(); |
| 3335 | |
| 3336 | if ( pos >= curNumRows ) |
| 3337 | { |
| 3338 | wxFAIL_MSG( wxString::Format |
| 3339 | ( |
| 3340 | wxT("Called wxGridStringTable::DeleteRows(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu rows"), |
| 3341 | (unsigned long)pos, |
| 3342 | (unsigned long)numRows, |
| 3343 | (unsigned long)curNumRows |
| 3344 | ) ); |
| 3345 | |
| 3346 | return false; |
| 3347 | } |
| 3348 | |
| 3349 | if ( numRows > curNumRows - pos ) |
| 3350 | { |
| 3351 | numRows = curNumRows - pos; |
| 3352 | } |
| 3353 | |
| 3354 | if ( numRows >= curNumRows ) |
| 3355 | { |
| 3356 | m_data.Clear(); |
| 3357 | } |
| 3358 | else |
| 3359 | { |
| 3360 | m_data.RemoveAt( pos, numRows ); |
| 3361 | } |
| 3362 | |
| 3363 | if ( GetView() ) |
| 3364 | { |
| 3365 | wxGridTableMessage msg( this, |
| 3366 | wxGRIDTABLE_NOTIFY_ROWS_DELETED, |
| 3367 | pos, |
| 3368 | numRows ); |
| 3369 | |
| 3370 | GetView()->ProcessTableMessage( msg ); |
| 3371 | } |
| 3372 | |
| 3373 | return true; |
| 3374 | } |
| 3375 | |
| 3376 | bool wxGridStringTable::InsertCols( size_t pos, size_t numCols ) |
| 3377 | { |
| 3378 | size_t row, col; |
| 3379 | |
| 3380 | size_t curNumRows = m_data.GetCount(); |
| 3381 | size_t curNumCols = ( curNumRows > 0 |
| 3382 | ? m_data[0].GetCount() |
| 3383 | : ( GetView() ? GetView()->GetNumberCols() : 0 ) ); |
| 3384 | |
| 3385 | if ( pos >= curNumCols ) |
| 3386 | { |
| 3387 | return AppendCols( numCols ); |
| 3388 | } |
| 3389 | |
| 3390 | for ( row = 0; row < curNumRows; row++ ) |
| 3391 | { |
| 3392 | for ( col = pos; col < pos + numCols; col++ ) |
| 3393 | { |
| 3394 | m_data[row].Insert( wxEmptyString, col ); |
| 3395 | } |
| 3396 | } |
| 3397 | |
| 3398 | if ( GetView() ) |
| 3399 | { |
| 3400 | wxGridTableMessage msg( this, |
| 3401 | wxGRIDTABLE_NOTIFY_COLS_INSERTED, |
| 3402 | pos, |
| 3403 | numCols ); |
| 3404 | |
| 3405 | GetView()->ProcessTableMessage( msg ); |
| 3406 | } |
| 3407 | |
| 3408 | return true; |
| 3409 | } |
| 3410 | |
| 3411 | bool wxGridStringTable::AppendCols( size_t numCols ) |
| 3412 | { |
| 3413 | size_t row; |
| 3414 | |
| 3415 | size_t curNumRows = m_data.GetCount(); |
| 3416 | #if 0 |
| 3417 | if ( !curNumRows ) |
| 3418 | { |
| 3419 | // TODO: something better than this ? |
| 3420 | // |
| 3421 | wxFAIL_MSG( wxT("Unable to append cols to a grid table with no rows.\nCall AppendRows() first") ); |
| 3422 | return false; |
| 3423 | } |
| 3424 | #endif |
| 3425 | |
| 3426 | for ( row = 0; row < curNumRows; row++ ) |
| 3427 | { |
| 3428 | m_data[row].Add( wxEmptyString, numCols ); |
| 3429 | } |
| 3430 | |
| 3431 | if ( GetView() ) |
| 3432 | { |
| 3433 | wxGridTableMessage msg( this, |
| 3434 | wxGRIDTABLE_NOTIFY_COLS_APPENDED, |
| 3435 | numCols ); |
| 3436 | |
| 3437 | GetView()->ProcessTableMessage( msg ); |
| 3438 | } |
| 3439 | |
| 3440 | return true; |
| 3441 | } |
| 3442 | |
| 3443 | bool wxGridStringTable::DeleteCols( size_t pos, size_t numCols ) |
| 3444 | { |
| 3445 | size_t row; |
| 3446 | |
| 3447 | size_t curNumRows = m_data.GetCount(); |
| 3448 | size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : |
| 3449 | ( GetView() ? GetView()->GetNumberCols() : 0 ) ); |
| 3450 | |
| 3451 | if ( pos >= curNumCols ) |
| 3452 | { |
| 3453 | wxFAIL_MSG( wxString::Format |
| 3454 | ( |
| 3455 | wxT("Called wxGridStringTable::DeleteCols(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu cols"), |
| 3456 | (unsigned long)pos, |
| 3457 | (unsigned long)numCols, |
| 3458 | (unsigned long)curNumCols |
| 3459 | ) ); |
| 3460 | return false; |
| 3461 | } |
| 3462 | |
| 3463 | if ( numCols > curNumCols - pos ) |
| 3464 | { |
| 3465 | numCols = curNumCols - pos; |
| 3466 | } |
| 3467 | |
| 3468 | for ( row = 0; row < curNumRows; row++ ) |
| 3469 | { |
| 3470 | if ( numCols >= curNumCols ) |
| 3471 | { |
| 3472 | m_data[row].Clear(); |
| 3473 | } |
| 3474 | else |
| 3475 | { |
| 3476 | m_data[row].RemoveAt( pos, numCols ); |
| 3477 | } |
| 3478 | } |
| 3479 | |
| 3480 | if ( GetView() ) |
| 3481 | { |
| 3482 | wxGridTableMessage msg( this, |
| 3483 | wxGRIDTABLE_NOTIFY_COLS_DELETED, |
| 3484 | pos, |
| 3485 | numCols ); |
| 3486 | |
| 3487 | GetView()->ProcessTableMessage( msg ); |
| 3488 | } |
| 3489 | |
| 3490 | return true; |
| 3491 | } |
| 3492 | |
| 3493 | wxString wxGridStringTable::GetRowLabelValue( int row ) |
| 3494 | { |
| 3495 | if ( row > (int)(m_rowLabels.GetCount()) - 1 ) |
| 3496 | { |
| 3497 | // using default label |
| 3498 | // |
| 3499 | return wxGridTableBase::GetRowLabelValue( row ); |
| 3500 | } |
| 3501 | else |
| 3502 | { |
| 3503 | return m_rowLabels[ row ]; |
| 3504 | } |
| 3505 | } |
| 3506 | |
| 3507 | wxString wxGridStringTable::GetColLabelValue( int col ) |
| 3508 | { |
| 3509 | if ( col > (int)(m_colLabels.GetCount()) - 1 ) |
| 3510 | { |
| 3511 | // using default label |
| 3512 | // |
| 3513 | return wxGridTableBase::GetColLabelValue( col ); |
| 3514 | } |
| 3515 | else |
| 3516 | { |
| 3517 | return m_colLabels[ col ]; |
| 3518 | } |
| 3519 | } |
| 3520 | |
| 3521 | void wxGridStringTable::SetRowLabelValue( int row, const wxString& value ) |
| 3522 | { |
| 3523 | if ( row > (int)(m_rowLabels.GetCount()) - 1 ) |
| 3524 | { |
| 3525 | int n = m_rowLabels.GetCount(); |
| 3526 | int i; |
| 3527 | for ( i = n; i <= row; i++ ) |
| 3528 | { |
| 3529 | m_rowLabels.Add( wxGridTableBase::GetRowLabelValue(i) ); |
| 3530 | } |
| 3531 | } |
| 3532 | |
| 3533 | m_rowLabels[row] = value; |
| 3534 | } |
| 3535 | |
| 3536 | void wxGridStringTable::SetColLabelValue( int col, const wxString& value ) |
| 3537 | { |
| 3538 | if ( col > (int)(m_colLabels.GetCount()) - 1 ) |
| 3539 | { |
| 3540 | int n = m_colLabels.GetCount(); |
| 3541 | int i; |
| 3542 | for ( i = n; i <= col; i++ ) |
| 3543 | { |
| 3544 | m_colLabels.Add( wxGridTableBase::GetColLabelValue(i) ); |
| 3545 | } |
| 3546 | } |
| 3547 | |
| 3548 | m_colLabels[col] = value; |
| 3549 | } |
| 3550 | |
| 3551 | |
| 3552 | ////////////////////////////////////////////////////////////////////// |
| 3553 | ////////////////////////////////////////////////////////////////////// |
| 3554 | |
| 3555 | IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow, wxWindow ) |
| 3556 | |
| 3557 | BEGIN_EVENT_TABLE( wxGridRowLabelWindow, wxWindow ) |
| 3558 | EVT_PAINT( wxGridRowLabelWindow::OnPaint ) |
| 3559 | EVT_MOUSEWHEEL( wxGridRowLabelWindow::OnMouseWheel) |
| 3560 | EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent ) |
| 3561 | EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown ) |
| 3562 | EVT_KEY_UP( wxGridRowLabelWindow::OnKeyUp ) |
| 3563 | EVT_CHAR ( wxGridRowLabelWindow::OnChar ) |
| 3564 | END_EVENT_TABLE() |
| 3565 | |
| 3566 | wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid *parent, |
| 3567 | wxWindowID id, |
| 3568 | const wxPoint &pos, const wxSize &size ) |
| 3569 | : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE|wxFULL_REPAINT_ON_RESIZE ) |
| 3570 | { |
| 3571 | m_owner = parent; |
| 3572 | } |
| 3573 | |
| 3574 | void wxGridRowLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) ) |
| 3575 | { |
| 3576 | wxPaintDC dc(this); |
| 3577 | |
| 3578 | // NO - don't do this because it will set both the x and y origin |
| 3579 | // coords to match the parent scrolled window and we just want to |
| 3580 | // set the y coord - MB |
| 3581 | // |
| 3582 | // m_owner->PrepareDC( dc ); |
| 3583 | |
| 3584 | int x, y; |
| 3585 | m_owner->CalcUnscrolledPosition( 0, 0, &x, &y ); |
| 3586 | dc.SetDeviceOrigin( 0, -y ); |
| 3587 | |
| 3588 | wxArrayInt rows = m_owner->CalcRowLabelsExposed( GetUpdateRegion() ); |
| 3589 | m_owner->DrawRowLabels( dc , rows ); |
| 3590 | } |
| 3591 | |
| 3592 | void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent& event ) |
| 3593 | { |
| 3594 | m_owner->ProcessRowLabelMouseEvent( event ); |
| 3595 | } |
| 3596 | |
| 3597 | void wxGridRowLabelWindow::OnMouseWheel( wxMouseEvent& event ) |
| 3598 | { |
| 3599 | m_owner->GetEventHandler()->ProcessEvent(event); |
| 3600 | } |
| 3601 | |
| 3602 | // This seems to be required for wxMotif otherwise the mouse |
| 3603 | // cursor must be in the cell edit control to get key events |
| 3604 | // |
| 3605 | void wxGridRowLabelWindow::OnKeyDown( wxKeyEvent& event ) |
| 3606 | { |
| 3607 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
| 3608 | } |
| 3609 | |
| 3610 | void wxGridRowLabelWindow::OnKeyUp( wxKeyEvent& event ) |
| 3611 | { |
| 3612 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
| 3613 | } |
| 3614 | |
| 3615 | void wxGridRowLabelWindow::OnChar( wxKeyEvent& event ) |
| 3616 | { |
| 3617 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
| 3618 | } |
| 3619 | |
| 3620 | |
| 3621 | ////////////////////////////////////////////////////////////////////// |
| 3622 | |
| 3623 | IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow, wxWindow ) |
| 3624 | |
| 3625 | BEGIN_EVENT_TABLE( wxGridColLabelWindow, wxWindow ) |
| 3626 | EVT_PAINT( wxGridColLabelWindow::OnPaint ) |
| 3627 | EVT_MOUSEWHEEL( wxGridColLabelWindow::OnMouseWheel) |
| 3628 | EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent ) |
| 3629 | EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown ) |
| 3630 | EVT_KEY_UP( wxGridColLabelWindow::OnKeyUp ) |
| 3631 | EVT_CHAR ( wxGridColLabelWindow::OnChar ) |
| 3632 | END_EVENT_TABLE() |
| 3633 | |
| 3634 | wxGridColLabelWindow::wxGridColLabelWindow( wxGrid *parent, |
| 3635 | wxWindowID id, |
| 3636 | const wxPoint &pos, const wxSize &size ) |
| 3637 | : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE|wxFULL_REPAINT_ON_RESIZE ) |
| 3638 | { |
| 3639 | m_owner = parent; |
| 3640 | } |
| 3641 | |
| 3642 | void wxGridColLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) ) |
| 3643 | { |
| 3644 | wxPaintDC dc(this); |
| 3645 | |
| 3646 | // NO - don't do this because it will set both the x and y origin |
| 3647 | // coords to match the parent scrolled window and we just want to |
| 3648 | // set the x coord - MB |
| 3649 | // |
| 3650 | // m_owner->PrepareDC( dc ); |
| 3651 | |
| 3652 | int x, y; |
| 3653 | m_owner->CalcUnscrolledPosition( 0, 0, &x, &y ); |
| 3654 | dc.SetDeviceOrigin( -x, 0 ); |
| 3655 | |
| 3656 | wxArrayInt cols = m_owner->CalcColLabelsExposed( GetUpdateRegion() ); |
| 3657 | m_owner->DrawColLabels( dc , cols ); |
| 3658 | } |
| 3659 | |
| 3660 | void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent& event ) |
| 3661 | { |
| 3662 | m_owner->ProcessColLabelMouseEvent( event ); |
| 3663 | } |
| 3664 | |
| 3665 | void wxGridColLabelWindow::OnMouseWheel( wxMouseEvent& event ) |
| 3666 | { |
| 3667 | m_owner->GetEventHandler()->ProcessEvent(event); |
| 3668 | } |
| 3669 | |
| 3670 | // This seems to be required for wxMotif otherwise the mouse |
| 3671 | // cursor must be in the cell edit control to get key events |
| 3672 | // |
| 3673 | void wxGridColLabelWindow::OnKeyDown( wxKeyEvent& event ) |
| 3674 | { |
| 3675 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) |
| 3676 | event.Skip(); |
| 3677 | } |
| 3678 | |
| 3679 | void wxGridColLabelWindow::OnKeyUp( wxKeyEvent& event ) |
| 3680 | { |
| 3681 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) |
| 3682 | event.Skip(); |
| 3683 | } |
| 3684 | |
| 3685 | void wxGridColLabelWindow::OnChar( wxKeyEvent& event ) |
| 3686 | { |
| 3687 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) |
| 3688 | event.Skip(); |
| 3689 | } |
| 3690 | |
| 3691 | |
| 3692 | ////////////////////////////////////////////////////////////////////// |
| 3693 | |
| 3694 | IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow, wxWindow ) |
| 3695 | |
| 3696 | BEGIN_EVENT_TABLE( wxGridCornerLabelWindow, wxWindow ) |
| 3697 | EVT_MOUSEWHEEL( wxGridCornerLabelWindow::OnMouseWheel) |
| 3698 | EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent ) |
| 3699 | EVT_PAINT( wxGridCornerLabelWindow::OnPaint) |
| 3700 | EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown ) |
| 3701 | EVT_KEY_UP( wxGridCornerLabelWindow::OnKeyUp ) |
| 3702 | EVT_CHAR ( wxGridCornerLabelWindow::OnChar ) |
| 3703 | END_EVENT_TABLE() |
| 3704 | |
| 3705 | wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid *parent, |
| 3706 | wxWindowID id, |
| 3707 | const wxPoint &pos, const wxSize &size ) |
| 3708 | : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE|wxFULL_REPAINT_ON_RESIZE ) |
| 3709 | { |
| 3710 | m_owner = parent; |
| 3711 | } |
| 3712 | |
| 3713 | void wxGridCornerLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) ) |
| 3714 | { |
| 3715 | wxPaintDC dc(this); |
| 3716 | |
| 3717 | int client_height = 0; |
| 3718 | int client_width = 0; |
| 3719 | GetClientSize( &client_width, &client_height ); |
| 3720 | |
| 3721 | // VZ: any reason for this ifdef? (FIXME) |
| 3722 | #ifdef __WXGTK__ |
| 3723 | wxRect rect; |
| 3724 | rect.SetX( 1 ); |
| 3725 | rect.SetY( 1 ); |
| 3726 | rect.SetWidth( client_width - 2 ); |
| 3727 | rect.SetHeight( client_height - 2 ); |
| 3728 | |
| 3729 | wxRendererNative::Get().DrawHeaderButton( this, dc, rect, 0 ); |
| 3730 | #else // !__WXGTK__ |
| 3731 | dc.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW),1, wxSOLID) ); |
| 3732 | dc.DrawLine( client_width-1, client_height-1, client_width-1, 0 ); |
| 3733 | dc.DrawLine( client_width-1, client_height-1, 0, client_height-1 ); |
| 3734 | dc.DrawLine( 0, 0, client_width, 0 ); |
| 3735 | dc.DrawLine( 0, 0, 0, client_height ); |
| 3736 | |
| 3737 | dc.SetPen( *wxWHITE_PEN ); |
| 3738 | dc.DrawLine( 1, 1, client_width-1, 1 ); |
| 3739 | dc.DrawLine( 1, 1, 1, client_height-1 ); |
| 3740 | #endif // __WXGTK__/!__WXGTK__ |
| 3741 | } |
| 3742 | |
| 3743 | void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent& event ) |
| 3744 | { |
| 3745 | m_owner->ProcessCornerLabelMouseEvent( event ); |
| 3746 | } |
| 3747 | |
| 3748 | void wxGridCornerLabelWindow::OnMouseWheel( wxMouseEvent& event ) |
| 3749 | { |
| 3750 | m_owner->GetEventHandler()->ProcessEvent(event); |
| 3751 | } |
| 3752 | |
| 3753 | // This seems to be required for wxMotif otherwise the mouse |
| 3754 | // cursor must be in the cell edit control to get key events |
| 3755 | // |
| 3756 | void wxGridCornerLabelWindow::OnKeyDown( wxKeyEvent& event ) |
| 3757 | { |
| 3758 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
| 3759 | } |
| 3760 | |
| 3761 | void wxGridCornerLabelWindow::OnKeyUp( wxKeyEvent& event ) |
| 3762 | { |
| 3763 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
| 3764 | } |
| 3765 | |
| 3766 | void wxGridCornerLabelWindow::OnChar( wxKeyEvent& event ) |
| 3767 | { |
| 3768 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
| 3769 | } |
| 3770 | |
| 3771 | |
| 3772 | ////////////////////////////////////////////////////////////////////// |
| 3773 | |
| 3774 | IMPLEMENT_DYNAMIC_CLASS( wxGridWindow, wxWindow ) |
| 3775 | |
| 3776 | BEGIN_EVENT_TABLE( wxGridWindow, wxWindow ) |
| 3777 | EVT_PAINT( wxGridWindow::OnPaint ) |
| 3778 | EVT_MOUSEWHEEL( wxGridWindow::OnMouseWheel) |
| 3779 | EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent ) |
| 3780 | EVT_KEY_DOWN( wxGridWindow::OnKeyDown ) |
| 3781 | EVT_KEY_UP( wxGridWindow::OnKeyUp ) |
| 3782 | EVT_CHAR ( wxGridWindow::OnChar ) |
| 3783 | EVT_SET_FOCUS( wxGridWindow::OnFocus ) |
| 3784 | EVT_KILL_FOCUS( wxGridWindow::OnFocus ) |
| 3785 | EVT_ERASE_BACKGROUND( wxGridWindow::OnEraseBackground ) |
| 3786 | END_EVENT_TABLE() |
| 3787 | |
| 3788 | wxGridWindow::wxGridWindow( wxGrid *parent, |
| 3789 | wxGridRowLabelWindow *rowLblWin, |
| 3790 | wxGridColLabelWindow *colLblWin, |
| 3791 | wxWindowID id, |
| 3792 | const wxPoint &pos, |
| 3793 | const wxSize &size ) |
| 3794 | : wxWindow( parent, id, pos, size, wxWANTS_CHARS | wxBORDER_NONE | wxCLIP_CHILDREN|wxFULL_REPAINT_ON_RESIZE, |
| 3795 | wxT("grid window") ) |
| 3796 | { |
| 3797 | m_owner = parent; |
| 3798 | m_rowLabelWin = rowLblWin; |
| 3799 | m_colLabelWin = colLblWin; |
| 3800 | } |
| 3801 | |
| 3802 | void wxGridWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) |
| 3803 | { |
| 3804 | wxPaintDC dc( this ); |
| 3805 | m_owner->PrepareDC( dc ); |
| 3806 | wxRegion reg = GetUpdateRegion(); |
| 3807 | wxGridCellCoordsArray DirtyCells = m_owner->CalcCellsExposed( reg ); |
| 3808 | m_owner->DrawGridCellArea( dc , DirtyCells); |
| 3809 | #if WXGRID_DRAW_LINES |
| 3810 | m_owner->DrawAllGridLines( dc, reg ); |
| 3811 | #endif |
| 3812 | m_owner->DrawGridSpace( dc ); |
| 3813 | m_owner->DrawHighlight( dc , DirtyCells ); |
| 3814 | } |
| 3815 | |
| 3816 | void wxGridWindow::ScrollWindow( int dx, int dy, const wxRect *rect ) |
| 3817 | { |
| 3818 | wxWindow::ScrollWindow( dx, dy, rect ); |
| 3819 | m_rowLabelWin->ScrollWindow( 0, dy, rect ); |
| 3820 | m_colLabelWin->ScrollWindow( dx, 0, rect ); |
| 3821 | } |
| 3822 | |
| 3823 | void wxGridWindow::OnMouseEvent( wxMouseEvent& event ) |
| 3824 | { |
| 3825 | if (event.ButtonDown(wxMOUSE_BTN_LEFT) && FindFocus() != this) |
| 3826 | SetFocus(); |
| 3827 | |
| 3828 | m_owner->ProcessGridCellMouseEvent( event ); |
| 3829 | } |
| 3830 | |
| 3831 | void wxGridWindow::OnMouseWheel( wxMouseEvent& event ) |
| 3832 | { |
| 3833 | m_owner->GetEventHandler()->ProcessEvent(event); |
| 3834 | } |
| 3835 | |
| 3836 | // This seems to be required for wxMotif/wxGTK otherwise the mouse |
| 3837 | // cursor must be in the cell edit control to get key events |
| 3838 | // |
| 3839 | void wxGridWindow::OnKeyDown( wxKeyEvent& event ) |
| 3840 | { |
| 3841 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) |
| 3842 | event.Skip(); |
| 3843 | } |
| 3844 | |
| 3845 | void wxGridWindow::OnKeyUp( wxKeyEvent& event ) |
| 3846 | { |
| 3847 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) |
| 3848 | event.Skip(); |
| 3849 | } |
| 3850 | |
| 3851 | void wxGridWindow::OnChar( wxKeyEvent& event ) |
| 3852 | { |
| 3853 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) |
| 3854 | event.Skip(); |
| 3855 | } |
| 3856 | |
| 3857 | void wxGridWindow::OnEraseBackground( wxEraseEvent& WXUNUSED(event) ) |
| 3858 | { |
| 3859 | } |
| 3860 | |
| 3861 | void wxGridWindow::OnFocus(wxFocusEvent& event) |
| 3862 | { |
| 3863 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) |
| 3864 | event.Skip(); |
| 3865 | } |
| 3866 | |
| 3867 | ////////////////////////////////////////////////////////////////////// |
| 3868 | |
| 3869 | // Internal Helper function for computing row or column from some |
| 3870 | // (unscrolled) coordinate value, using either |
| 3871 | // m_defaultRowHeight/m_defaultColWidth or binary search on array |
| 3872 | // of m_rowBottoms/m_ColRights to speed up the search! |
| 3873 | |
| 3874 | // Internal helper macros for simpler use of that function |
| 3875 | |
| 3876 | static int CoordToRowOrCol(int coord, int defaultDist, int minDist, |
| 3877 | const wxArrayInt& BorderArray, int nMax, |
| 3878 | bool clipToMinMax); |
| 3879 | |
| 3880 | #define internalXToCol(x) CoordToRowOrCol(x, m_defaultColWidth, \ |
| 3881 | m_minAcceptableColWidth, \ |
| 3882 | m_colRights, m_numCols, true) |
| 3883 | #define internalYToRow(y) CoordToRowOrCol(y, m_defaultRowHeight, \ |
| 3884 | m_minAcceptableRowHeight, \ |
| 3885 | m_rowBottoms, m_numRows, true) |
| 3886 | ///////////////////////////////////////////////////////////////////// |
| 3887 | |
| 3888 | #if wxUSE_EXTENDED_RTTI |
| 3889 | WX_DEFINE_FLAGS( wxGridStyle ) |
| 3890 | |
| 3891 | wxBEGIN_FLAGS( wxGridStyle ) |
| 3892 | // new style border flags, we put them first to |
| 3893 | // use them for streaming out |
| 3894 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
| 3895 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) |
| 3896 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) |
| 3897 | wxFLAGS_MEMBER(wxBORDER_RAISED) |
| 3898 | wxFLAGS_MEMBER(wxBORDER_STATIC) |
| 3899 | wxFLAGS_MEMBER(wxBORDER_NONE) |
| 3900 | |
| 3901 | // old style border flags |
| 3902 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
| 3903 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) |
| 3904 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) |
| 3905 | wxFLAGS_MEMBER(wxRAISED_BORDER) |
| 3906 | wxFLAGS_MEMBER(wxSTATIC_BORDER) |
| 3907 | wxFLAGS_MEMBER(wxBORDER) |
| 3908 | |
| 3909 | // standard window styles |
| 3910 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
| 3911 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) |
| 3912 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) |
| 3913 | wxFLAGS_MEMBER(wxWANTS_CHARS) |
| 3914 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
| 3915 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
| 3916 | wxFLAGS_MEMBER(wxVSCROLL) |
| 3917 | wxFLAGS_MEMBER(wxHSCROLL) |
| 3918 | |
| 3919 | wxEND_FLAGS( wxGridStyle ) |
| 3920 | |
| 3921 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxGrid, wxScrolledWindow,"wx/grid.h") |
| 3922 | |
| 3923 | wxBEGIN_PROPERTIES_TABLE(wxGrid) |
| 3924 | wxHIDE_PROPERTY( Children ) |
| 3925 | wxPROPERTY_FLAGS( WindowStyle , wxGridStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
| 3926 | wxEND_PROPERTIES_TABLE() |
| 3927 | |
| 3928 | wxBEGIN_HANDLERS_TABLE(wxGrid) |
| 3929 | wxEND_HANDLERS_TABLE() |
| 3930 | |
| 3931 | wxCONSTRUCTOR_5( wxGrid , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
| 3932 | |
| 3933 | /* |
| 3934 |