wxArt2D
canpropedit.cpp
Go to the documentation of this file.
1 /*! \file editor/src/canpropedit.cpp
2  \author Klaas Holwerda
3  \date Created 11/19/2003
4 
5  Copyright: 2003-2004 (c) Klaas Holwerda
6 
7  Licence: wxWidgets Licence
8 
9  RCS-ID: $Id: canpropedit.cpp,v 1.13 2008/10/30 23:18:09 titato Exp $
10 */
11 
12 #include "a2dprec.h"
13 
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17 
18 #ifndef WX_PRECOMP
19 #include "wx/wx.h"
20 #endif
21 
22 #include "wx/editor/canpropedit.h"
23 
24 
25 
26 class PropertyTable : public wxGridTableBase
27 {
28 public:
29  PropertyTable( a2dEditProperties* editProp ) { m_editProp = editProp; }
30 
31  virtual int GetNumberRows();
32  virtual int GetNumberCols();
33  virtual bool IsEmptyCell( int row, int col );
34  virtual wxString GetValue( int row, int col );
35  virtual void SetValue( int row, int col, const wxString& value );
36 
37  virtual wxString GetColLabelValue( int col );
38 
39  virtual wxString GetTypeName( int row, int col );
40  virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
41  virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
42 
43  virtual long GetValueAsLong( int row, int col );
44  virtual bool GetValueAsBool( int row, int col );
45  virtual double GetValueAsDouble( int row, int col );
46 
47  virtual void SetValueAsLong( int row, int col, long value );
48  virtual void SetValueAsBool( int row, int col, bool value );
49  virtual void SetValueAsDouble( int row, int col, double value );
50 
51  bool InsertRows( size_t pos, size_t numRows );
52  bool AppendRows( size_t numRows );
53  bool DeleteRows( size_t pos, size_t numRows );
54 
55 public:
56  a2dEditProperties* m_editProp;
57 };
58 
59 // ----------------------------------------------------------------------------
60 // property table data
61 // ----------------------------------------------------------------------------
62 
63 enum Columns
64 {
65  Col_Name,
66  Col_Type,
67  Col_Value,
68  Col_Max
69 };
70 
71 static const wxString PropertyTypeStrs[] =
72 {
73  _T( "string" ),
74  _T( "integer" ),
75  _T( "real" ),
76  _T( "boolean" ),
77 };
78 
79 static const wxChar* headers[Col_Max] =
80 {
81  _T( "Name" ),
82  _T( "Type" ),
83  _T( "Value" ),
84 };
85 
86 // ----------------------------------------------------------------------------
87 // PropertyTable
88 // ----------------------------------------------------------------------------
89 
90 wxString PropertyTable::GetTypeName( int row, int col )
91 {
92  switch ( col )
93  {
94  case Col_Name:
95  return wxString::Format( _T( "%s:80" ), wxGRID_VALUE_STRING );
96 
97  case Col_Type:
98  return wxString::Format( _T( "%s:string,integer,real,boolean" ), wxGRID_VALUE_CHOICE );
99 
100  case Col_Value:
101  int rowtype = m_editProp->m_propdata [row].m_type;
102  switch ( rowtype )
103  {
104  case pt_string: return wxGRID_VALUE_STRING;
105  case pt_integer: return wxGRID_VALUE_NUMBER;
106  case pt_real: return wxGRID_VALUE_FLOAT;
107  case pt_bool: return wxGRID_VALUE_BOOL;
108  }
109  }
110 
111  wxFAIL_MSG( _T( "unknown column" ) );
112 
113  return wxEmptyString;
114 }
115 
116 int PropertyTable::GetNumberRows()
117 {
118  return m_editProp->m_propdata.size();
119 }
120 
121 int PropertyTable::GetNumberCols()
122 {
123  return Col_Max;
124 }
125 
126 bool PropertyTable::IsEmptyCell( int WXUNUSED( row ), int WXUNUSED( col ) )
127 {
128  return false;
129 }
130 
131 wxString PropertyTable::GetValue( int row, int col )
132 {
133  const PropGridData& gd = m_editProp->m_propdata[row];
134 
135  switch ( col )
136  {
137  case Col_Name:
138  return gd.m_name;
139 
140  case Col_Type:
141  return PropertyTypeStrs[gd.m_type];
142 
143  case Col_Value:
144  switch ( gd.m_type )
145  {
146  case pt_string: return gd.m_val_str;
147  case pt_integer: return wxString::Format( _T( "%d" ), gd.m_val_integer );
148  case pt_real: return wxString::Format( _T( "%f" ), gd.m_val_real );
149  case pt_bool: return gd.m_val_boolean? _T( "1" ) : _T( "0" );
150  }
151  }
152 
153  return wxEmptyString;
154 }
155 
156 void PropertyTable::SetValue( int row, int col, const wxString& value )
157 {
158  PropGridData& gd = m_editProp->m_propdata[row];
159 
160  switch ( col )
161  {
162  case Col_Name:
163  gd.m_name = value;
164  break;
165 
166  case Col_Type:
167  {
168  PropertyType typeNow = gd.m_type;
169  size_t n;
170  for ( n = 0; n < WXSIZEOF( PropertyTypeStrs ); n++ )
171  {
172  if ( PropertyTypeStrs[n] == value )
173  {
174  gd.m_type = ( PropertyType )n;
175  break;
176  }
177  }
178  if ( typeNow != gd.m_type )
179  {
180  wxGrid* grid = m_editProp->m_grid;
181  switch ( gd.m_type )
182  {
183  case pt_string:
184  grid->SetCellEditor( row, Col_Value, new wxGridCellTextEditor() );
185  break;
186  case pt_integer:
187  grid->SetCellEditor( row, Col_Value, new wxGridCellNumberEditor( -1, 1 ) );
188  break;
189  case pt_real:
190  grid->SetCellEditor( row, Col_Value, new wxGridCellFloatEditor( -1, 1 ) );
191  break;
192  case pt_bool:
193  grid->SetCellEditor( row, Col_Value, new wxGridCellBoolEditor() );
194  break;
195  }
196  }
197 
198  if ( n == WXSIZEOF( PropertyTypeStrs ) )
199  {
200  wxLogWarning( _T( "Invalid type value '%s'." ),
201  value.c_str() );
202  gd.m_type = pt_string;
203  }
204  }
205  break;
206 
207  case Col_Value:
208  switch ( gd.m_type )
209  {
210  case pt_string: gd.m_val_str = value;
211  }
212  break;
213  }
214 }
215 
216 bool
217 PropertyTable::CanGetValueAs( int row,
218  int col,
219  const wxString& typeName )
220 {
221  int rowtype = m_editProp->m_propdata [row].m_type;
222 
223  if ( col == 0 )
224  {
225  if ( typeName == wxGRID_VALUE_STRING )
226  return true;
227  }
228  else if ( col == 1 )
229  {
230  if ( typeName == wxGRID_VALUE_NUMBER )
231  return true;
232  if ( typeName == wxGRID_VALUE_CHOICE )
233  return true;
234  }
235  else if ( col == 2 )
236  {
237  switch ( rowtype )
238  {
239  case pt_string: if ( typeName == wxGRID_VALUE_STRING )
240  return true;
241  break;
242  case pt_integer: if ( typeName == wxGRID_VALUE_NUMBER )
243  return true;
244  break;
245  case pt_real: if ( typeName == wxGRID_VALUE_FLOAT )
246  return true;
247  break;
248  case pt_bool: if ( typeName == wxGRID_VALUE_BOOL )
249  return true;
250  break;
251  }
252  }
253  return false;
254 }
255 
256 bool PropertyTable::CanSetValueAs( int row, int col, const wxString& typeName )
257 {
258  return CanGetValueAs( row, col, typeName );
259 }
260 
261 long PropertyTable::GetValueAsLong( int row, int col )
262 {
263  int rowtype = m_editProp->m_propdata [row].m_type;
264 
265  if ( col == 2 )
266  {
267  switch ( rowtype )
268  {
269  case pt_integer: return m_editProp->m_propdata [row].m_val_integer;
270  default:
271  wxFAIL_MSG( _T( "not a long in column value" ) );
272  return -1;
273  }
274  }
275  else
276  wxFAIL_MSG( _T( "unexpected column" ) );
277  return -1;
278 }
279 
280 bool PropertyTable::GetValueAsBool( int row, int col )
281 {
282  int rowtype = m_editProp->m_propdata [row].m_type;
283 
284  if ( col == 2 )
285  {
286  switch ( rowtype )
287  {
288  case pt_bool: return m_editProp->m_propdata [row].m_val_boolean;
289  default:
290  wxFAIL_MSG( _T( "not a bool in column value" ) );
291  return false;
292  }
293  }
294  else
295  wxFAIL_MSG( _T( "unexpected column" ) );
296  return false;
297 }
298 
299 double PropertyTable::GetValueAsDouble( int row, int col )
300 {
301  int rowtype = m_editProp->m_propdata [row].m_type;
302 
303  if ( col == 2 )
304  {
305  switch ( rowtype )
306  {
307  case pt_real: return m_editProp->m_propdata [row].m_val_real;
308  default:
309  wxFAIL_MSG( _T( "not a real in column value" ) );
310  }
311  }
312  else
313  wxFAIL_MSG( _T( "unexpected column" ) );
314  return 0.0;
315 }
316 
317 void PropertyTable::SetValueAsLong( int row, int col, long value )
318 {
319  int rowtype = m_editProp->m_propdata [row].m_type;
320 
321  if ( col == Col_Value )
322  {
323  switch ( rowtype )
324  {
325  case pt_integer: m_editProp->m_propdata [row].m_val_integer = value;
326  break;
327  default:
328  wxFAIL_MSG( _T( "unexpected column" ) );
329  }
330  }
331  else
332  wxFAIL_MSG( _T( "unexpected column" ) );
333 }
334 
335 void PropertyTable::SetValueAsBool( int row, int col, bool value )
336 {
337  int rowtype = m_editProp->m_propdata [row].m_type;
338 
339  if ( col == Col_Value )
340  {
341  switch ( rowtype )
342  {
343  case pt_bool: m_editProp->m_propdata [row].m_val_boolean = value;
344  break;
345  default:
346  wxFAIL_MSG( _T( "not a boolean in column value" ) );
347  }
348  }
349  else
350  wxFAIL_MSG( _T( "unexpected column" ) );
351 }
352 
353 void PropertyTable::SetValueAsDouble( int row, int col, double value )
354 {
355  int rowtype = m_editProp->m_propdata [row].m_type;
356 
357  if ( col == Col_Value )
358  {
359  switch ( rowtype )
360  {
361  case pt_real: m_editProp->m_propdata [row].m_val_real = value;
362  break;
363  default:
364  wxFAIL_MSG( _T( "not a real in column value" ) );
365  }
366  }
367  else
368  wxFAIL_MSG( _T( "unexpected column" ) );
369 }
370 
371 wxString PropertyTable::GetColLabelValue( int col )
372 {
373  return headers[col];
374 }
375 
376 bool PropertyTable::InsertRows( size_t pos, size_t numRows )
377 {
378  wxGrid* grid = m_editProp->m_grid;
379  size_t curNumRows = m_editProp->m_propdata.size();
380 
381  if ( pos >= curNumRows )
382  {
383  return AppendRows( numRows );
384  }
385 
386  m_editProp->m_propdata.resize( curNumRows + numRows );
387 
388  int row;
389  for ( row = curNumRows + numRows - 1; row > pos + 1; row-- )
390  {
391  m_editProp->m_propdata [row] = m_editProp->m_propdata [row - 1];
392  }
393  for ( row = pos + 1; row < pos + 1 + numRows; row++ )
394  {
395  m_editProp->m_propdata [row].m_name = wxT( "" );
396  m_editProp->m_propdata [row].m_type = pt_string;
397  m_editProp->m_propdata [row].m_val_str = wxT( "" );
398  m_editProp->m_propdata [row].m_val_integer = 0;
399  m_editProp->m_propdata [row].m_val_real = 0.0;
400  m_editProp->m_propdata [row].m_val_boolean = true;
401  m_editProp->m_propdata [row].m_prop = NULL;
402  }
403 
404  if ( GetView() )
405  {
406  wxGridTableMessage msg( this,
407  wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
408  pos,
409  numRows );
410 
411  GetView()->ProcessTableMessage( msg );
412  }
413  for ( row = pos + 1; row < pos + 1 + numRows; row++ )
414  {
415  grid->SetCellEditor( row, Col_Value, new wxGridCellTextEditor() );
416  if ( !m_editProp->m_propdata [row].m_prop )
417  grid->SetReadOnly( row, 1, false );
418 
419  }
420  return true;
421 }
422 
423 bool PropertyTable::AppendRows( size_t numRows )
424 {
425  wxGrid* grid = m_editProp->m_grid;
426  size_t curNumRows = m_editProp->m_propdata.size();
427 
428  m_editProp->m_propdata.resize( curNumRows + numRows );
429  int row;
430  for ( row = curNumRows; row < curNumRows + numRows; row++ )
431  {
432  m_editProp->m_propdata [row].m_name = wxT( "" );
433  m_editProp->m_propdata [row].m_type = pt_string;
434  m_editProp->m_propdata [row].m_val_str = wxT( "" );
435  }
436 
437  if ( GetView() )
438  {
439  wxGridTableMessage msg( this,
440  wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
441  numRows );
442 
443  GetView()->ProcessTableMessage( msg );
444  }
445  grid->SetCellEditor( curNumRows + numRows - 1, Col_Value, new wxGridCellTextEditor() );
446 
447  return true;
448 }
449 
450 bool PropertyTable::DeleteRows( size_t pos, size_t numRows )
451 {
452  size_t curNumRows = m_editProp->m_propdata.size();
453 
454  if ( pos >= curNumRows )
455  {
456  wxFAIL_MSG( wxString::Format
457  (
458  wxT( "Called PropertyTable::DeleteRows(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu rows" ),
459  ( unsigned long )pos,
460  ( unsigned long )numRows,
461  ( unsigned long )curNumRows
462  ) );
463 
464  return false;
465  }
466 
467  if ( numRows > curNumRows - pos )
468  {
469  numRows = curNumRows - pos;
470  }
471 
472  if ( numRows >= curNumRows )
473  {
474  int row;
475  for ( row = 0; row < curNumRows; row++ )
476  {
477  if ( m_editProp->m_propdata [row].m_prop )
478  m_editProp->m_propdata [row].m_prop->SetCheck( true );
479  }
480  m_editProp->m_propdata .clear();
481  }
482  else
483  {
484  PropGridDataVec::iterator iterfirst = m_editProp->m_propdata.begin();
485  PropGridDataVec::iterator iterlast = m_editProp->m_propdata.begin();
486  int row;
487  for ( row = 0; row < pos; row++ )
488  iterfirst++;
489  iterlast = iterfirst;
490  for ( row = 0; row < numRows - 1; row++ )
491  iterlast++;
492 
493  // deleted properties are checked (if already existed)
494  for ( row = pos; row < pos + numRows; row++ )
495  {
496  if ( m_editProp->m_propdata [row].m_prop )
497  m_editProp->m_propdata [row].m_prop->SetCheck( true );
498  }
499  m_editProp->m_propdata.erase( iterfirst, iterlast );
500  }
501 
502  if ( GetView() )
503  {
504  wxGridTableMessage msg( this,
505  wxGRIDTABLE_NOTIFY_ROWS_DELETED,
506  pos,
507  numRows );
508 
509  GetView()->ProcessTableMessage( msg );
510  }
511 
512  return true;
513 }
514 
515 
516 
517 
518 
519 
520 
521 
522 
523 IMPLEMENT_DYNAMIC_CLASS( a2dEditProperties, wxDialog )
524 
525 BEGIN_EVENT_TABLE( a2dEditProperties, wxDialog )
526  EVT_BUTTON( ID_ADD, a2dEditProperties::OnAddClick )
527  EVT_BUTTON( ID_CUT, a2dEditProperties::OnCutClick )\
528  EVT_BUTTON( ID_PASTE, a2dEditProperties::OnPasteClick )
529  EVT_BUTTON( ID_CANCEL, a2dEditProperties::OnCancelClick )\
530  EVT_BUTTON( ID_OKE, a2dEditProperties::OnOkeClick )
531  EVT_CLOSE( a2dEditProperties::OnCloseWindow )
532  EVT_SIZE( a2dEditProperties::OnSize )
533 END_EVENT_TABLE()
534 
535 a2dEditProperties::a2dEditProperties( )
536 {
537 }
538 
539 a2dEditProperties::a2dEditProperties( wxWindow* parent, a2dObject* propobject,
540  a2dNamedPropertyList* propertylist,
541  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
542 {
543  m_propobject = propobject;
544  m_propertylist = propertylist;
545  Create( parent, id, caption, pos, size, style );
546 }
547 
548 bool a2dEditProperties::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
549 {
550  m_grid = NULL;
551  m_add = NULL;
552  m_cut = NULL;
553  m_cancel = NULL;
554  m_oke = NULL;
555  SetExtraStyle( GetExtraStyle() | wxWS_EX_BLOCK_EVENTS );
556  wxDialog::Create( parent, id, caption, pos, size, style );
557 
558  CreateControls();
559  GetSizer()->Fit( this );
560  GetSizer()->SetSizeHints( this );
561  Centre();
562  return TRUE;
563 }
564 
566 {
567  a2dEditProperties* itemDialog1 = this;
568 
569  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer( wxVERTICAL );
570  itemDialog1->SetSizer( itemBoxSizer2 );
571 
572  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer( wxHORIZONTAL );
573  itemBoxSizer2->Add( itemBoxSizer3, 1, wxALIGN_CENTER_HORIZONTAL | wxALL | wxEXPAND, 5 );
574 
575  int row = 0;
576  a2dNamedPropertyList::const_iterator iter;
577  for( iter = m_propertylist->begin(); iter != m_propertylist->end(); ++iter )
578  {
579  const a2dNamedProperty* prop = *iter;
580  if ( prop->GetId()->IsEditable() || prop->GetId()->IsUserDefined() )
581  row++;
582  }
583 
584  m_propdata.resize( row );
585  row = 0;
586  for( iter = m_propertylist->begin(); iter != m_propertylist->end(); ++iter )
587  {
588  a2dNamedProperty* prop = *iter;
589  if ( prop->GetId()->IsEditable() || prop->GetId()->IsUserDefined() )
590  {
591  m_propdata [row].m_prop = prop;
592  m_propdata [row].m_name = prop->GetName();
593  if ( wxDynamicCast( prop, a2dStringProperty ) )
594  {
595  m_propdata [row].m_type = pt_string;
596  m_propdata [row].m_val_str = prop->GetString();
597  }
598  else if ( wxDynamicCast( prop, a2dInt32Property ) )
599  {
600  m_propdata [row].m_type = pt_integer;
601  m_propdata [row].m_val_integer = prop->GetInt32();
602  }
603  else if ( wxDynamicCast( prop, a2dDoubleProperty ) )
604  {
605  m_propdata [row].m_type = pt_real;
606  m_propdata [row].m_val_real = prop->GetDouble();
607  }
608  else if ( wxDynamicCast( prop, a2dBoolProperty ) )
609  {
610  m_propdata [row].m_type = pt_bool;
611  m_propdata [row].m_val_boolean = prop->GetBool();
612  }
613  row++;
614  }
615  }
616 
617  m_grid = new wxGrid( itemDialog1, ID_GRID, wxDefaultPosition, wxSize( 370, 150 ), wxSUNKEN_BORDER | wxHSCROLL | wxVSCROLL );
618  PropertyTable* table = new PropertyTable( this );
619  m_grid->SetDefaultColSize( 100 );
620  m_grid->SetDefaultRowSize( 25 );
621  m_grid->SetColLabelSize( 25 );
622  m_grid->SetRowLabelSize( 50 );
623  m_grid->SetTable( table, true );
624  m_grid->SetColMinimalAcceptableWidth( 50 );
625 
626  wxGridCellAttr* attrNameEditor = new wxGridCellAttr,
627  *attrTypeEditor = new wxGridCellAttr;
628 
629  attrNameEditor->SetEditor( new wxGridCellTextEditor() );
630  attrTypeEditor->SetEditor( new wxGridCellChoiceEditor( WXSIZEOF( PropertyTypeStrs ),
631  PropertyTypeStrs ) );
632  m_grid->SetColAttr( Col_Name, attrNameEditor );
633  m_grid->SetColAttr( Col_Type, attrTypeEditor );
634 
635  int j;
636  for ( j = 0; j < m_propdata.size(); j++ )
637  {
638  // if already defined property, do not allow change of type
639  int rowtype = m_propdata [j].m_type;
640  switch ( rowtype )
641  {
642  case pt_string:
643  m_grid->SetCellEditor( j, 2, new wxGridCellTextEditor() );
644  break;
645  case pt_integer:
646  m_grid->SetCellEditor( j, 2, new wxGridCellNumberEditor( -1, 1 ) );
647  break;
648  case pt_real:
649  m_grid->SetCellEditor( j, 2, new wxGridCellFloatEditor( -1, 1 ) );
650  break;
651  case pt_bool:
652  m_grid->SetCellEditor( j, 2, new wxGridCellBoolEditor() );
653  break;
654  }
655  if ( m_propdata [j].m_prop )
656  m_grid->SetReadOnly( j, 1, true );
657  }
658 
659  itemBoxSizer3->Add( m_grid, 0, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
660 
661  wxBoxSizer* itemBoxSizer5 = new wxBoxSizer( wxHORIZONTAL );
662  itemBoxSizer2->Add( itemBoxSizer5, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2 );
663 
664  m_add = new wxButton( itemDialog1, ID_ADD, _( "Add" ), wxDefaultPosition, wxDefaultSize, 0 );
665  m_add->SetDefault();
666  m_add->SetHelpText( _( "Add a row for a new property" ) );
667  if ( ShowToolTips() )
668  m_add->SetToolTip( _( "Add a row for a new property" ) );
669  itemBoxSizer5->Add( m_add, 0, wxALIGN_CENTER_VERTICAL | wxALL , 2 );
670 
671  m_cut = new wxButton( itemDialog1, ID_CUT, _( "Cut" ), wxDefaultPosition, wxDefaultSize, 0 );
672  m_cut->SetHelpText( _( "Remove property at current row" ) );
673  if ( ShowToolTips() )
674  m_cut->SetToolTip( _( "Remove property at current row" ) );
675  itemBoxSizer5->Add( m_cut, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2 );
676 
677  wxButton* itemButton8 = new wxButton( itemDialog1, ID_PASTE, _( "Paste" ), wxDefaultPosition, wxDefaultSize, 0 );
678  itemButton8->SetHelpText( _( "Paste last cut property" ) );
679  if ( ShowToolTips() )
680  itemButton8->SetToolTip( _( "Paste last cut property" ) );
681  itemBoxSizer5->Add( itemButton8, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2 );
682 
683  wxBoxSizer* itemBoxSizer9 = new wxBoxSizer( wxHORIZONTAL );
684  itemBoxSizer2->Add( itemBoxSizer9, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2 );
685 
686  m_cancel = new wxButton( itemDialog1, ID_CANCEL, _( "Cancel" ), wxDefaultPosition, wxDefaultSize, 0 );
687  m_cancel->SetHelpText( _( "End edit without applying new values and properties" ) );
688  if ( ShowToolTips() )
689  m_cancel->SetToolTip( _( "End edit without applying new values and properties" ) );
690  itemBoxSizer9->Add( m_cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2 );
691 
692  m_oke = new wxButton( itemDialog1, ID_OKE, _( "Oke" ), wxDefaultPosition, wxDefaultSize, 0 );
693  m_oke->SetHelpText( _( "End edit properties" ) );
694  if ( ShowToolTips() )
695  m_oke->SetToolTip( _( "End edit properties" ) );
696  itemBoxSizer9->Add( m_oke, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2 );
697 }
698 
700 {
701  return TRUE;
702 }
703 
704 void a2dEditProperties::OnAddClick( wxCommandEvent& event )
705 {
706  m_grid->InsertRows( m_grid->GetGridCursorRow(), 1 );
707 }
708 
709 
710 void a2dEditProperties::OnCutClick( wxCommandEvent& event )
711 {
712  m_grid->DeleteRows( m_grid->GetGridCursorRow(), 1 );
713 }
714 
715 
716 void a2dEditProperties::OnPasteClick( wxCommandEvent& event )
717 {
718  event.Skip();
719 }
720 
721 void a2dEditProperties::OnCancelClick( wxCommandEvent& event )
722 {
723  EndModal( wxID_CANCEL );
724 }
725 
726 void a2dEditProperties::OnOkeClick( wxCommandEvent& event )
727 {
728  int j;
729  for ( j = 0; j < m_propdata.size(); j++ )
730  {
731  a2dNamedProperty* prop = m_propdata [j].m_prop;
732  wxString name = m_propdata [j].m_name;
733  if ( prop )
734  {
735  if ( m_propobject->HasPropertyId( prop->GetId() ) )
736  {
737  bool check = false;
738  int rowtype = m_propdata [j].m_type;
739  switch ( rowtype )
740  {
741  case pt_string:
742  {
744  if ( sprop )
745  sprop->SetValue( m_propdata [j].m_val_str );
746  check = true;
747  break;
748  }
749  case pt_integer:
750  {
752  if ( dprop )
753  dprop->SetValue( m_propdata [j].m_val_integer );
754  check = true;
755  break;
756  }
757  case pt_real:
758  {
760  if ( dprop )
761  dprop->SetValue( m_propdata [j].m_val_real );
762  check = true;
763  break;
764  }
765  case pt_bool:
766  {
767  a2dBoolProperty* boolprop = wxDynamicCast( prop, a2dBoolProperty );
768  if ( boolprop )
769  boolprop->SetValue( m_propdata [j].m_val_boolean );
770  check = true;
771  break;
772  }
773  }
774  if ( !check )
775  {
776  wxString mes;
777  mes = wxT( "property with name: " ) + name +
778  wxT( "\nhas already bin created on this object with a different type.\n" ) +
779  wxT( "use a different name which does not conflict, or set the type to " ) +
780  PropertyTypeStrs[ rowtype ];
781  wxMessageBox( mes, _( "edit properties" ), wxICON_WARNING | wxOK );
782  }
783  else
784  {
785  // value is already set, change name now.
786  a2dPropertyId* castp = const_cast<a2dPropertyId*>( prop->GetId() );
787  castp->SetName( name );
788  }
789  }
790  else
791  wxMessageBox( _( "object is missing a property ID" ), _( "edit properties" ), wxICON_WARNING | wxOK );
792  }
793  else
794  {
795  // create a2dPropertyId of the right type, and name, unless it is already available by that name.
796  a2dPropertyId* propid = m_propobject->HasPropertyId( name );
797  int rowtype = m_propdata [j].m_type;
798  if ( propid )
799  {
800  // a property id with this name is already available, but its type must fit also.
801  bool check = false;
802  a2dNamedPropertyPtr propcreated = NULL;
803  switch ( rowtype )
804  {
805  case pt_string:
806  {
807  propcreated = propid->CreatePropertyFromString( m_propdata [j].m_val_str );
808  a2dStringProperty* prop = wxDynamicCast( propcreated.Get(), a2dStringProperty );
809  if ( prop )
810  {
811  check = true;
812  prop->SetValue( m_propdata [j].m_val_str );
813  }
814  break;
815  }
816  case pt_integer:
817  {
818  propcreated = propid->CreatePropertyFromString( wxT( "" ) );
819  a2dInt32Property* prop = wxDynamicCast( propcreated.Get(), a2dInt32Property );
820  if ( prop )
821  {
822  check = true;
823  prop->SetValue( m_propdata [j].m_val_integer );
824  }
825  break;
826  }
827  case pt_real:
828  {
829  propcreated = propid->CreatePropertyFromString( wxT( "" ) );
830  a2dDoubleProperty* prop = wxDynamicCast( propcreated.Get(), a2dDoubleProperty );
831  if ( prop )
832  {
833  check = true;
834  prop->SetValue( m_propdata [j].m_val_real );
835  }
836  break;
837  }
838  case pt_bool:
839  {
840  propcreated = propid->CreatePropertyFromString( wxT( "" ) );
841  a2dBoolProperty* prop = wxDynamicCast( propcreated.Get(), a2dBoolProperty );
842  if ( prop )
843  {
844  check = true;
845  prop->SetValue( m_propdata [j].m_val_boolean );
846  }
847  break;
848  }
849  }
850  if ( !check )
851  {
852  wxString mes;
853  mes = wxT( "property with name: " ) + name +
854  wxT( "\nhas already bin created on this object, but with a different type.\n" ) +
855  wxT( "use a different name which does not conflict, or set the type to " ) +
856  PropertyTypeStrs[ rowtype ];
857  wxMessageBox( mes, _( "edit properties" ), wxICON_WARNING | wxOK );
858  }
859  else
860  m_propertylist->push_back( propcreated );
861 
862  }
863  else
864  {
865  // we need to create a new property ID of the right type
866  a2dNamedPropertyPtr propcreated = NULL;
867  switch ( rowtype )
868  {
869  case pt_string:
870  {
871  propid = new a2dPropertyIdString( name, wxT( "" ), a2dPropertyId::flag_userDefined );
872  m_propobject->AddPropertyId( propid );
873  propcreated = propid->CreatePropertyFromString( m_propdata [j].m_val_str );
874  a2dStringProperty* prop = wxDynamicCast( propcreated.Get(), a2dStringProperty );
875  break;
876  }
877  case pt_integer:
878  {
879  propid = new a2dPropertyIdInt32( name, 0, a2dPropertyId::flag_userDefined );
880  m_propobject->AddPropertyId( propid );
881  propcreated = propid->CreatePropertyFromString( wxT( "" ) );
882  a2dInt32Property* prop = wxDynamicCast( propcreated.Get(), a2dInt32Property );
883  prop->SetValue( m_propdata [j].m_val_integer );
884  break;
885  }
886  case pt_real:
887  {
888  propid = new a2dPropertyIdDouble( name, 0, a2dPropertyId::flag_userDefined );
889  m_propobject->AddPropertyId( propid );
890  propcreated = propid->CreatePropertyFromString( wxT( "" ) );
891  a2dDoubleProperty* prop = wxDynamicCast( propcreated.Get(), a2dDoubleProperty );
892  prop->SetValue( m_propdata [j].m_val_real );
893  break;
894  }
895  case pt_bool:
896  {
897  propid = new a2dPropertyIdBool( name, 0, a2dPropertyId::flag_userDefined );
898  m_propobject->AddPropertyId( propid );
899  propcreated = propid->CreatePropertyFromString( wxT( "" ) );
900  a2dBoolProperty* prop = wxDynamicCast( propcreated.Get(), a2dBoolProperty );
901  prop->SetValue( m_propdata [j].m_val_boolean );
902  break;
903  }
904  }
905  m_propertylist->push_back( propcreated );
906  }
907  }
908  }
909 
910  EndModal( wxID_OK );
911 }
912 
913 void a2dEditProperties::OnCloseWindow( wxCloseEvent& event )
914 {
915  EndModal( wxID_CANCEL );
916 }
917 
918 void a2dEditProperties::OnSize( wxSizeEvent& event )
919 {
920  event.Skip();
921  return;
922 
923  int clientw, clienth;
924  GetClientSize( &clientw, &clienth );
925 
926  GetSizer()->SetSizeHints( this );
927  GetSizer()->Fit( this );
928  //Layout();
929 }
930 
931 
932 
933 
934 
935 
936 
937 
938 
939 
940 
941 
942 
943 
944 
945 
946 
947 
948 
949 
950 
951 
952 
953 
954 
955 const int GROUP_BUTTON_OK = wxID_HIGHEST + 5401 ;
956 const int GROUP_BUTTON_CANCEL = wxID_HIGHEST + 5402 ;
957 const int GROUP_BUTTON_SHOW = wxID_HIGHEST + 5403 ;
958 
959 BEGIN_EVENT_TABLE( a2dPropertyEditorDlg, wxDialog )
960  EVT_BUTTON ( GROUP_BUTTON_OK, a2dPropertyEditorDlg::CmOk )
961  EVT_BUTTON ( GROUP_BUTTON_CANCEL , a2dPropertyEditorDlg::CmCancel )
962  EVT_CLOSE ( a2dPropertyEditorDlg::OnCloseWindow )
963 END_EVENT_TABLE()
964 
966  wxDialog( parent, -1, _T( "Property editor" ), wxPoint( 0, 0 ), wxSize( 100, 500 ),
967  ( wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP | wxRESIZE_BORDER ), _T( "Property editor" ) )
968 {
969  m_listbox = new wxListBox( this, -1, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_NEEDED_SB | wxLB_SINGLE );
970  m_button1 = new wxButton( this, GROUP_BUTTON_OK, _T( "Ok" ), wxDefaultPosition, wxSize( 55, 20 ) );
971  m_button2 = new wxButton( this, GROUP_BUTTON_CANCEL, _T( "Cancel" ), wxDefaultPosition, wxSize( 55, 20 ) );
972 
973  m_propertylist = NULL;
974  m_listbox->Clear();
975 
976  wxBoxSizer* item0 = new wxBoxSizer( wxVERTICAL );
977 
978  wxStaticText* title = new wxStaticText( this, -1, _T( "properties" ) );
979  wxBoxSizer* item3 = new wxBoxSizer( wxHORIZONTAL );
980  item3->Add( title, 1, wxALL, 2 );
981  item0->Add( item3, 0, wxEXPAND, 2 );
982  Centre( wxBOTH );
983 
984  wxBoxSizer* item1 = new wxBoxSizer( wxHORIZONTAL );
985  item1->Add( m_listbox, 1, wxEXPAND | wxALL, 2 );
986  item0->Add( item1, 1, wxEXPAND, 2 );
987 
988  wxBoxSizer* item2 = new wxBoxSizer( wxHORIZONTAL );
989  item2->Add( m_button1, 1, wxALL, 2 );
990  item2->Add( m_button2, 1, wxALL, 2 );
991 
992  item0->Add( item2, 0, wxEXPAND, 2 );
993 
994  SetAutoLayout( true );
995  SetSizer( item0 );
996  item0->Fit( this );
997  item0->SetSizeHints( this );
998 
999  m_listbox->Clear();
1000  a2dNamedPropertyList::const_iterator iter;
1001  for( iter = propertylist->begin(); iter != propertylist->end(); ++iter )
1002  {
1003  const a2dNamedProperty* prop = *iter;
1004 
1005 
1006 
1007  m_listbox->Append( prop->GetId()->GetName() );
1008  }
1009 
1010  if ( !propertylist->empty() )
1011  m_listbox->SetSelection( 0, true );
1012 }
1013 
1015 {
1016 }
1017 
1018 void a2dPropertyEditorDlg::CmOk( wxCommandEvent& )
1019 {
1020  EndModal( wxID_OK );
1021 }
1022 
1023 void a2dPropertyEditorDlg::CmCancel( wxCommandEvent& )
1024 {
1025  EndModal( wxID_CANCEL );
1026 }
1027 
1028 void a2dPropertyEditorDlg::OnCloseWindow( wxCloseEvent& WXUNUSED( event ) )
1029 {
1030  wxCommandEvent eventc;
1031  CmCancel( eventc );
1032 }
virtual double GetDouble() const
when a2dDoubleProperty, return its value else assert
Definition: gen.cpp:1928
(In) Visible property that can be added to Docview Objects.
Definition: gen.h:1785
virtual wxString GetString() const
when a2dStringProperty, return its value else assert
Definition: gen.cpp:1922
#define wxDynamicCast(obj, className)
Define wxDynamicCast so that it will give a compiler error for unrelated types.
Definition: gen.h:75
a2dEditProperties()
Constructors.
virtual wxInt32 GetInt32() const
when a2dInt32Property, return its value else assert
Definition: gen.cpp:1958
virtual wxString GetName() const
Get the ids print and serialization name.
Definition: id.h:245
a2dPropertyIdTyped< wxString, a2dStringProperty > a2dPropertyIdString
property of this type
Definition: id.h:665
void CmCancel(wxCommandEvent &)
Close window if CANCEL-button is pressed.
Ref Counted base object.
Definition: gen.h:1045
property to hold a double type variable to be associated with a a2dObject
Definition: gen.h:2503
a2dPropertyIdTyped< wxInt32, a2dInt32Property > a2dPropertyIdInt32
property of this type
Definition: id.h:649
property to hold a bool type variable to be associated with a a2dObject
Definition: gen.h:2004
void SetName(const wxString &name)
Set the ids print and serialization name.
Definition: id.h:247
a2dPropertyIdTyped< bool, a2dBoolProperty > a2dPropertyIdBool
property of this type
Definition: id.h:655
bool Create(wxWindow *parent, wxWindowID id=SYMBOL_A2DEDITPROPERTIES_IDNAME, const wxString &caption=SYMBOL_A2DEDITPROPERTIES_TITLE, const wxPoint &pos=SYMBOL_A2DEDITPROPERTIES_POSITION, const wxSize &size=SYMBOL_A2DEDITPROPERTIES_SIZE, long style=SYMBOL_A2DEDITPROPERTIES_STYLE)
Creation.
wxString GetName() const
Get the name of the a2dPropertyId object.
Definition: gen.h:1864
list of a2dNamedProperty objects
Definition: gen.h:804
~a2dPropertyEditorDlg()
destructor.
void CmOk(wxCommandEvent &)
Close window if OK-button is pressed.
property to hold a 2 byte integer type variable to be associated with a a2dObject ...
Definition: gen.h:2401
static bool ShowToolTips()
Should we show tooltips?
bool IsUserDefined() const
true if this property is user defined
Definition: id.h:277
edit properties of a2dCanvasObject&#39;s
Definition: canpropedit.h:148
virtual bool GetBool() const
when a2dBoolProperty, return its value else assert
Definition: gen.cpp:1940
const a2dPropertyId * GetId() const
Get the a2dPropertyId object identifying this property.
Definition: gen.h:1858
property to hold a wxString type variable to be associated with a a2dObject
Definition: gen.h:2066
for edting properties in a a2dNamedPropertyList
void CreateControls()
Creates the controls and sizers.
This is the base class for all kinds of property id&#39;s for a2dObject.
Definition: id.h:154
bool IsEditable() const
true if this property is editable ( can be tested in a property editor ).
Definition: id.h:279
A property id defined by user.
Definition: id.h:207
void OnCloseWindow(wxCloseEvent &event)
Close window if EXIT -button is pressed.
virtual a2dNamedProperty * CreatePropertyFromString(const wxString &value) const
Create a new property object from a value string.
Definition: id.h:255
a2dPropertyIdTyped< double, a2dDoubleProperty > a2dPropertyIdDouble
property of this type
Definition: id.h:657
canpropedit.cpp Source File -- Sun Oct 12 2014 17:04:14 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation