1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
|
/////////////////////////////////////////////////////////////////////////////
// Name: wx/generic/grideditors.h
// Purpose: wxGridCellEditorEvtHandler and wxGrid editors
// Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
// Modified by: Santiago Palacios
// Created: 1/08/1999
// Copyright: (c) Michael Bedward
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GENERIC_GRID_EDITORS_H_
#define _WX_GENERIC_GRID_EDITORS_H_
#include "wx/defs.h"
#if wxUSE_GRID
#include "wx/scopedptr.h"
class wxGridCellEditorEvtHandler : public wxEvtHandler
{
public:
wxGridCellEditorEvtHandler(wxGrid* grid, wxGridCellEditor* editor)
: m_grid(grid),
m_editor(editor),
m_inSetFocus(false)
{
}
void DismissEditor();
void OnKillFocus(wxFocusEvent& event);
void OnKeyDown(wxKeyEvent& event);
void OnChar(wxKeyEvent& event);
void SetInSetFocus(bool inSetFocus) { m_inSetFocus = inSetFocus; }
private:
wxGrid *m_grid;
wxGridCellEditor *m_editor;
// Work around the fact that a focus kill event can be sent to
// a combobox within a set focus event.
bool m_inSetFocus;
wxDECLARE_EVENT_TABLE();
wxDECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler);
wxDECLARE_NO_COPY_CLASS(wxGridCellEditorEvtHandler);
};
#if wxUSE_TEXTCTRL
// the editor for string/text data
class WXDLLIMPEXP_ADV wxGridCellTextEditor : public wxGridCellEditor
{
public:
explicit wxGridCellTextEditor(size_t maxChars = 0)
: wxGridCellEditor(),
m_maxChars(maxChars)
{
}
wxGridCellTextEditor(const wxGridCellTextEditor& other);
virtual void Create(wxWindow* parent,
wxWindowID id,
wxEvtHandler* evtHandler) wxOVERRIDE;
virtual void SetSize(const wxRect& rect) wxOVERRIDE;
virtual bool IsAcceptedKey(wxKeyEvent& event) wxOVERRIDE;
virtual void BeginEdit(int row, int col, wxGrid* grid) wxOVERRIDE;
virtual bool EndEdit(int row, int col, const wxGrid* grid,
const wxString& oldval, wxString *newval) wxOVERRIDE;
virtual void ApplyEdit(int row, int col, wxGrid* grid) wxOVERRIDE;
virtual void Reset() wxOVERRIDE;
virtual void StartingKey(wxKeyEvent& event) wxOVERRIDE;
virtual void HandleReturn(wxKeyEvent& event) wxOVERRIDE;
// parameters string format is "max_width"
virtual void SetParameters(const wxString& params) wxOVERRIDE;
#if wxUSE_VALIDATORS
virtual void SetValidator(const wxValidator& validator);
#endif
virtual wxGridCellEditor *Clone() const wxOVERRIDE
{ return new wxGridCellTextEditor(*this); }
// added GetValue so we can get the value which is in the control
virtual wxString GetValue() const wxOVERRIDE;
protected:
wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
// parts of our virtual functions reused by the derived classes
void DoCreate(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler,
long style = 0);
void DoBeginEdit(const wxString& startValue);
void DoReset(const wxString& startValue);
private:
size_t m_maxChars; // max number of chars allowed
#if wxUSE_VALIDATORS
wxScopedPtr<wxValidator> m_validator;
#endif
wxString m_value;
};
// the editor for numeric (long) data
class WXDLLIMPEXP_ADV wxGridCellNumberEditor : public wxGridCellTextEditor
{
public:
// allows to specify the range - if min == max == -1, no range checking is
// done
explicit wxGridCellNumberEditor(int min = -1, int max = -1)
: wxGridCellTextEditor(),
m_min(min),
m_max(max),
m_value(0L)
{
}
wxGridCellNumberEditor(const wxGridCellNumberEditor& other)
: wxGridCellTextEditor(other),
m_min(other.m_min),
m_max(other.m_max),
m_value(other.m_value)
{
}
virtual void Create(wxWindow* parent,
wxWindowID id,
wxEvtHandler* evtHandler) wxOVERRIDE;
virtual void SetSize(const wxRect& rect) wxOVERRIDE;
virtual bool IsAcceptedKey(wxKeyEvent& event) wxOVERRIDE;
virtual void BeginEdit(int row, int col, wxGrid* grid) wxOVERRIDE;
virtual bool EndEdit(int row, int col, const wxGrid* grid,
const wxString& oldval, wxString *newval) wxOVERRIDE;
virtual void ApplyEdit(int row, int col, wxGrid* grid) wxOVERRIDE;
virtual void Reset() wxOVERRIDE;
virtual void StartingKey(wxKeyEvent& event) wxOVERRIDE;
// parameters string format is "min,max"
virtual void SetParameters(const wxString& params) wxOVERRIDE;
virtual wxGridCellEditor *Clone() const wxOVERRIDE
{ return new wxGridCellNumberEditor(*this); }
// added GetValue so we can get the value which is in the control
virtual wxString GetValue() const wxOVERRIDE;
protected:
#if wxUSE_SPINCTRL
wxSpinCtrl *Spin() const { return (wxSpinCtrl *)m_control; }
#endif
// if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
bool HasRange() const
{
#if wxUSE_SPINCTRL
return m_min != m_max;
#else
return false;
#endif
}
// string representation of our value
wxString GetString() const
{ return wxString::Format(wxT("%ld"), m_value); }
private:
int m_min,
m_max;
long m_value;
};
enum wxGridCellFloatFormat
{
// Decimal floating point (%f)
wxGRID_FLOAT_FORMAT_FIXED = 0x0010,
// Scientific notation (mantise/exponent) using e character (%e)
wxGRID_FLOAT_FORMAT_SCIENTIFIC = 0x0020,
// Use the shorter of %e or %f (%g)
wxGRID_FLOAT_FORMAT_COMPACT = 0x0040,
// To use in combination with one of the above formats (%F/%E/%G)
wxGRID_FLOAT_FORMAT_UPPER = 0x0080,
// Format used by default.
wxGRID_FLOAT_FORMAT_DEFAULT = wxGRID_FLOAT_FORMAT_FIXED,
// A mask to extract format from the combination of flags.
wxGRID_FLOAT_FORMAT_MASK = wxGRID_FLOAT_FORMAT_FIXED |
wxGRID_FLOAT_FORMAT_SCIENTIFIC |
wxGRID_FLOAT_FORMAT_COMPACT |
wxGRID_FLOAT_FORMAT_UPPER
};
// the editor for floating point numbers (double) data
class WXDLLIMPEXP_ADV wxGridCellFloatEditor : public wxGridCellTextEditor
{
public:
explicit wxGridCellFloatEditor(int width = -1,
int precision = -1,
int format = wxGRID_FLOAT_FORMAT_DEFAULT)
: wxGridCellTextEditor(),
m_width(width),
m_precision(precision),
m_value(0.0),
m_style(format)
{
}
wxGridCellFloatEditor(const wxGridCellFloatEditor& other)
: wxGridCellTextEditor(other),
m_width(other.m_width),
m_precision(other.m_precision),
m_value(other.m_value),
m_style(other.m_style),
m_format(other.m_format)
{
}
virtual void Create(wxWindow* parent,
wxWindowID id,
wxEvtHandler* evtHandler) wxOVERRIDE;
virtual bool IsAcceptedKey(wxKeyEvent& event) wxOVERRIDE;
virtual void BeginEdit(int row, int col, wxGrid* grid) wxOVERRIDE;
virtual bool EndEdit(int row, int col, const wxGrid* grid,
const wxString& oldval, wxString *newval) wxOVERRIDE;
virtual void ApplyEdit(int row, int col, wxGrid* grid) wxOVERRIDE;
virtual void Reset() wxOVERRIDE;
virtual void StartingKey(wxKeyEvent& event) wxOVERRIDE;
virtual wxGridCellEditor *Clone() const wxOVERRIDE
{ return new wxGridCellFloatEditor(*this); }
// parameters string format is "width[,precision[,format]]"
// format to choose between f|e|g|E|G (f is used by default)
virtual void SetParameters(const wxString& params) wxOVERRIDE;
protected:
// string representation of our value
wxString GetString();
private:
int m_width,
m_precision;
double m_value;
int m_style;
wxString m_format;
};
#endif // wxUSE_TEXTCTRL
#if wxUSE_CHECKBOX
// the editor for boolean data
class WXDLLIMPEXP_ADV wxGridCellBoolEditor : public wxGridCellEditor
{
public:
wxGridCellBoolEditor()
: wxGridCellEditor()
{
}
wxGridCellBoolEditor(const wxGridCellBoolEditor& other)
: wxGridCellEditor(other),
m_value(other.m_value)
{
}
virtual wxGridActivationResult
TryActivate(int row, int col, wxGrid* grid,
const wxGridActivationSource& actSource) wxOVERRIDE;
virtual void DoActivate(int row, int col, wxGrid* grid) wxOVERRIDE;
virtual void Create(wxWindow* parent,
wxWindowID id,
wxEvtHandler* evtHandler) wxOVERRIDE;
virtual void SetSize(const wxRect& rect) wxOVERRIDE;
virtual void Show(bool show, wxGridCellAttr *attr = NULL) wxOVERRIDE;
virtual bool IsAcceptedKey(wxKeyEvent& event) wxOVERRIDE;
virtual void BeginEdit(int row, int col, wxGrid* grid) wxOVERRIDE;
virtual bool EndEdit(int row, int col, const wxGrid* grid,
const wxString& oldval, wxString *newval) wxOVERRIDE;
virtual void ApplyEdit(int row, int col, wxGrid* grid) wxOVERRIDE;
virtual void Reset() wxOVERRIDE;
virtual void StartingClick() wxOVERRIDE;
virtual void StartingKey(wxKeyEvent& event) wxOVERRIDE;
virtual wxGridCellEditor *Clone() const wxOVERRIDE
{ return new wxGridCellBoolEditor(*this); }
// added GetValue so we can get the value which is in the control, see
// also UseStringValues()
virtual wxString GetValue() const wxOVERRIDE;
// set the string values returned by GetValue() for the true and false
// states, respectively
static void UseStringValues(const wxString& valueTrue = wxT("1"),
const wxString& valueFalse = wxString());
// return true if the given string is equal to the string representation of
// true value which we currently use
static bool IsTrueValue(const wxString& value);
protected:
wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
private:
// These functions modify or use m_value.
void SetValueFromGrid(int row, int col, wxGrid* grid);
void SetGridFromValue(int row, int col, wxGrid* grid) const;
wxString GetStringValue() const { return GetStringValue(m_value); }
static
wxString GetStringValue(bool value) { return ms_stringValues[value]; }
bool m_value;
static wxString ms_stringValues[2];
};
#endif // wxUSE_CHECKBOX
#if wxUSE_COMBOBOX
// the editor for string data allowing to choose from the list of strings
class WXDLLIMPEXP_ADV wxGridCellChoiceEditor : public wxGridCellEditor
{
public:
// if !allowOthers, user can't type a string not in choices array
explicit wxGridCellChoiceEditor(size_t count = 0,
const wxString choices[] = NULL,
bool allowOthers = false);
explicit wxGridCellChoiceEditor(const wxArrayString& choices,
bool allowOthers = false)
: wxGridCellEditor(),
m_choices(choices),
m_allowOthers(allowOthers)
{
}
wxGridCellChoiceEditor(const wxGridCellChoiceEditor& other)
: wxGridCellEditor(other),
m_value(other.m_value),
m_choices(other.m_choices),
m_allowOthers(other.m_allowOthers)
{
}
virtual void Create(wxWindow* parent,
wxWindowID id,
wxEvtHandler* evtHandler) wxOVERRIDE;
virtual void SetSize(const wxRect& rect) wxOVERRIDE;
virtual void BeginEdit(int row, int col, wxGrid* grid) wxOVERRIDE;
virtual bool EndEdit(int row, int col, const wxGrid* grid,
const wxString& oldval, wxString *newval) wxOVERRIDE;
virtual void ApplyEdit(int row, int col, wxGrid* grid) wxOVERRIDE;
virtual void Reset() wxOVERRIDE;
// parameters string format is "item1[,item2[...,itemN]]"
virtual void SetParameters(const wxString& params) wxOVERRIDE;
virtual wxGridCellEditor *Clone() const wxOVERRIDE
{ return new wxGridCellChoiceEditor(*this); }
// added GetValue so we can get the value which is in the control
virtual wxString GetValue() const wxOVERRIDE;
protected:
wxComboBox *Combo() const { return (wxComboBox *)m_control; }
void OnComboCloseUp(wxCommandEvent& evt);
wxString m_value;
wxArrayString m_choices;
bool m_allowOthers;
};
#endif // wxUSE_COMBOBOX
#if wxUSE_COMBOBOX
class WXDLLIMPEXP_ADV wxGridCellEnumEditor : public wxGridCellChoiceEditor
{
public:
explicit wxGridCellEnumEditor(const wxString& choices = wxString());
wxGridCellEnumEditor(const wxGridCellEnumEditor& other)
: wxGridCellChoiceEditor(other),
m_index(other.m_index)
{
}
virtual ~wxGridCellEnumEditor() {}
virtual wxGridCellEditor* Clone() const wxOVERRIDE
{ return new wxGridCellEnumEditor(*this); }
virtual void BeginEdit(int row, int col, wxGrid* grid) wxOVERRIDE;
virtual bool EndEdit(int row, int col, const wxGrid* grid,
const wxString& oldval, wxString *newval) wxOVERRIDE;
virtual void ApplyEdit(int row, int col, wxGrid* grid) wxOVERRIDE;
private:
long m_index;
};
#endif // wxUSE_COMBOBOX
class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
{
public:
wxGridCellAutoWrapStringEditor()
: wxGridCellTextEditor()
{
}
wxGridCellAutoWrapStringEditor(const wxGridCellAutoWrapStringEditor& other)
: wxGridCellTextEditor(other)
{
}
virtual void Create(wxWindow* parent,
wxWindowID id,
wxEvtHandler* evtHandler) wxOVERRIDE;
virtual wxGridCellEditor *Clone() const wxOVERRIDE
{ return new wxGridCellAutoWrapStringEditor(*this); }
};
#if wxUSE_DATEPICKCTRL
class WXDLLIMPEXP_ADV wxGridCellDateEditor : public wxGridCellEditor
{
public:
explicit wxGridCellDateEditor(const wxString& format = wxString());
wxGridCellDateEditor(const wxGridCellDateEditor& other)
: wxGridCellEditor(other),
m_value(other.m_value),
m_format(other.m_format)
{
}
virtual void SetParameters(const wxString& params) wxOVERRIDE;
virtual void Create(wxWindow* parent,
wxWindowID id,
wxEvtHandler* evtHandler) wxOVERRIDE;
virtual void SetSize(const wxRect& rect) wxOVERRIDE;
virtual void BeginEdit(int row, int col, wxGrid* grid) wxOVERRIDE;
virtual bool EndEdit(int row, int col, const wxGrid* grid,
const wxString& oldval, wxString *newval) wxOVERRIDE;
virtual void ApplyEdit(int row, int col, wxGrid* grid) wxOVERRIDE;
virtual void Reset() wxOVERRIDE;
virtual wxGridCellEditor *Clone() const wxOVERRIDE
{ return new wxGridCellDateEditor(*this); }
virtual wxString GetValue() const wxOVERRIDE;
protected:
wxDatePickerCtrl* DatePicker() const;
private:
wxDateTime m_value;
wxString m_format;
};
#endif // wxUSE_DATEPICKCTRL
#endif // wxUSE_GRID
#endif // _WX_GENERIC_GRID_EDITORS_H_
|