00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "a2dprec.h"
00013
00014 #ifdef __BORLANDC__
00015 #pragma hdrstop
00016 #endif
00017
00018 #ifndef WX_PRECOMP
00019 #include "wx/wx.h"
00020 #endif
00021
00022 #include "wx/editor/canpropedit.h"
00023
00024
00025
00026 class PropertyTable : public wxGridTableBase
00027 {
00028 public:
00029 PropertyTable( a2dEditProperties* editProp ) { m_editProp = editProp; }
00030
00031 virtual int GetNumberRows();
00032 virtual int GetNumberCols();
00033 virtual bool IsEmptyCell( int row, int col );
00034 virtual wxString GetValue( int row, int col );
00035 virtual void SetValue( int row, int col, const wxString& value );
00036
00037 virtual wxString GetColLabelValue( int col );
00038
00039 virtual wxString GetTypeName( int row, int col );
00040 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
00041 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
00042
00043 virtual long GetValueAsLong( int row, int col );
00044 virtual bool GetValueAsBool( int row, int col );
00045 virtual double GetValueAsDouble( int row, int col );
00046
00047 virtual void SetValueAsLong( int row, int col, long value );
00048 virtual void SetValueAsBool( int row, int col, bool value );
00049 virtual void SetValueAsDouble( int row, int col, double value );
00050
00051 bool InsertRows( size_t pos, size_t numRows );
00052 bool AppendRows( size_t numRows );
00053 bool DeleteRows( size_t pos, size_t numRows );
00054
00055 public:
00056 a2dEditProperties* m_editProp;
00057 };
00058
00059
00060
00061
00062
00063 enum Columns
00064 {
00065 Col_Name,
00066 Col_Type,
00067 Col_Value,
00068 Col_Max
00069 };
00070
00071 static const wxString PropertyTypeStrs[] =
00072 {
00073 _T("string"),
00074 _T("integer"),
00075 _T("real"),
00076 _T("boolean"),
00077 };
00078
00079 static const wxChar *headers[Col_Max] =
00080 {
00081 _T("Name"),
00082 _T("Type"),
00083 _T("Value"),
00084 };
00085
00086
00087
00088
00089
00090 wxString PropertyTable::GetTypeName(int row, int col)
00091 {
00092 switch ( col )
00093 {
00094 case Col_Name:
00095 return wxString::Format(_T("%s:80"), wxGRID_VALUE_STRING);
00096
00097 case Col_Type:
00098 return wxString::Format(_T("%s:string,integer,real,boolean"), wxGRID_VALUE_CHOICE);
00099
00100 case Col_Value:
00101 int rowtype = m_editProp->m_propdata [row].m_type;
00102 switch ( rowtype )
00103 {
00104 case pt_string: return wxGRID_VALUE_STRING;
00105 case pt_integer: return wxGRID_VALUE_NUMBER;
00106 case pt_real: return wxGRID_VALUE_FLOAT;
00107 case pt_bool: return wxGRID_VALUE_BOOL;
00108 }
00109 }
00110
00111 wxFAIL_MSG(_T("unknown column"));
00112
00113 return wxEmptyString;
00114 }
00115
00116 int PropertyTable::GetNumberRows()
00117 {
00118 return m_editProp->m_propdata.size();
00119 }
00120
00121 int PropertyTable::GetNumberCols()
00122 {
00123 return Col_Max;
00124 }
00125
00126 bool PropertyTable::IsEmptyCell( int WXUNUSED(row), int WXUNUSED(col) )
00127 {
00128 return false;
00129 }
00130
00131 wxString PropertyTable::GetValue( int row, int col )
00132 {
00133 const PropGridData& gd = m_editProp->m_propdata[row];
00134
00135 switch ( col )
00136 {
00137 case Col_Name:
00138 return gd.m_name;
00139
00140 case Col_Type:
00141 return PropertyTypeStrs[gd.m_type];
00142
00143 case Col_Value:
00144 switch ( gd.m_type )
00145 {
00146 case pt_string: return gd.m_val_str;
00147 case pt_integer: return wxString::Format(_T("%d"), gd.m_val_integer);
00148 case pt_real: return wxString::Format(_T("%f"), gd.m_val_real);
00149 case pt_bool: return gd.m_val_boolean? _T("1") : _T("0");
00150 }
00151 }
00152
00153 return wxEmptyString;
00154 }
00155
00156 void PropertyTable::SetValue( int row, int col, const wxString& value )
00157 {
00158 PropGridData& gd = m_editProp->m_propdata[row];
00159
00160 switch ( col )
00161 {
00162 case Col_Name:
00163 gd.m_name = value;
00164 break;
00165
00166 case Col_Type:
00167 {
00168 PropertyType typeNow = gd.m_type;
00169 size_t n;
00170 for ( n = 0; n < WXSIZEOF(PropertyTypeStrs); n++ )
00171 {
00172 if ( PropertyTypeStrs[n] == value )
00173 {
00174 gd.m_type = (PropertyType)n;
00175 break;
00176 }
00177 }
00178 if ( typeNow != gd.m_type )
00179 {
00180 wxGrid* grid = m_editProp->m_grid;
00181 switch ( gd.m_type )
00182 {
00183 case pt_string:
00184 grid->SetCellEditor( row, Col_Value, new wxGridCellTextEditor() );
00185 break;
00186 case pt_integer:
00187 grid->SetCellEditor( row, Col_Value, new wxGridCellNumberEditor(-1, 1) );
00188 break;
00189 case pt_real:
00190 grid->SetCellEditor( row, Col_Value, new wxGridCellFloatEditor(-1, 1) );
00191 break;
00192 case pt_bool:
00193 grid->SetCellEditor( row, Col_Value, new wxGridCellBoolEditor() );
00194 break;
00195 }
00196 }
00197
00198 if ( n == WXSIZEOF(PropertyTypeStrs) )
00199 {
00200 wxLogWarning(_T("Invalid type value '%s'."),
00201 value.c_str());
00202 gd.m_type = pt_string;
00203 }
00204 }
00205 break;
00206
00207 case Col_Value:
00208 switch ( gd.m_type )
00209 {
00210 case pt_string: gd.m_val_str = value;
00211 }
00212 break;
00213 }
00214 }
00215
00216 bool
00217 PropertyTable::CanGetValueAs(int row,
00218 int col,
00219 const wxString& typeName)
00220 {
00221 int rowtype = m_editProp->m_propdata [row].m_type;
00222
00223 if ( col == 0 )
00224 {
00225 if ( typeName == wxGRID_VALUE_STRING )
00226 return true;
00227 }
00228 else if ( col == 1 )
00229 {
00230 if ( typeName == wxGRID_VALUE_NUMBER )
00231 return true;
00232 if ( typeName == wxGRID_VALUE_CHOICE )
00233 return true;
00234 }
00235 else if ( col == 2 )
00236 {
00237 switch ( rowtype )
00238 {
00239 case pt_string: if ( typeName == wxGRID_VALUE_STRING )
00240 return true;
00241 break;
00242 case pt_integer: if ( typeName == wxGRID_VALUE_NUMBER )
00243 return true;
00244 break;
00245 case pt_real: if ( typeName == wxGRID_VALUE_FLOAT )
00246 return true;
00247 break;
00248 case pt_bool: if ( typeName == wxGRID_VALUE_BOOL )
00249 return true;
00250 break;
00251 }
00252 }
00253 return false;
00254 }
00255
00256 bool PropertyTable::CanSetValueAs( int row, int col, const wxString& typeName )
00257 {
00258 return CanGetValueAs(row, col, typeName);
00259 }
00260
00261 long PropertyTable::GetValueAsLong( int row, int col )
00262 {
00263 int rowtype = m_editProp->m_propdata [row].m_type;
00264
00265 if ( col == 2 )
00266 {
00267 switch ( rowtype )
00268 {
00269 case pt_integer: return m_editProp->m_propdata [row].m_val_integer;
00270 default:
00271 wxFAIL_MSG(_T("not a long in column value"));
00272 return -1;
00273 }
00274 }
00275 else
00276 wxFAIL_MSG(_T("unexpected column"));
00277 return -1;
00278 }
00279
00280 bool PropertyTable::GetValueAsBool( int row, int col )
00281 {
00282 int rowtype = m_editProp->m_propdata [row].m_type;
00283
00284 if ( col == 2 )
00285 {
00286 switch ( rowtype )
00287 {
00288 case pt_bool: return m_editProp->m_propdata [row].m_val_boolean;
00289 default:
00290 wxFAIL_MSG(_T("not a bool in column value"));
00291 return false;
00292 }
00293 }
00294 else
00295 wxFAIL_MSG(_T("unexpected column"));
00296 return false;
00297 }
00298
00299 double PropertyTable::GetValueAsDouble( int row, int col )
00300 {
00301 int rowtype = m_editProp->m_propdata [row].m_type;
00302
00303 if ( col == 2 )
00304 {
00305 switch ( rowtype )
00306 {
00307 case pt_real: return m_editProp->m_propdata [row].m_val_real;
00308 default:
00309 wxFAIL_MSG(_T("not a real in column value"));
00310 }
00311 }
00312 else
00313 wxFAIL_MSG(_T("unexpected column"));
00314 return 0.0;
00315 }
00316
00317 void PropertyTable::SetValueAsLong( int row, int col, long value )
00318 {
00319 int rowtype = m_editProp->m_propdata [row].m_type;
00320
00321 if ( col == Col_Value )
00322 {
00323 switch ( rowtype )
00324 {
00325 case pt_integer: m_editProp->m_propdata [row].m_val_integer = value;
00326 break;
00327 default:
00328 wxFAIL_MSG(_T("unexpected column"));
00329 }
00330 }
00331 else
00332 wxFAIL_MSG(_T("unexpected column"));
00333 }
00334
00335 void PropertyTable::SetValueAsBool( int row, int col, bool value )
00336 {
00337 int rowtype = m_editProp->m_propdata [row].m_type;
00338
00339 if ( col == Col_Value )
00340 {
00341 switch ( rowtype )
00342 {
00343 case pt_bool: m_editProp->m_propdata [row].m_val_boolean = value;
00344 break;
00345 default:
00346 wxFAIL_MSG(_T("not a boolean in column value"));
00347 }
00348 }
00349 else
00350 wxFAIL_MSG(_T("unexpected column"));
00351 }
00352
00353 void PropertyTable::SetValueAsDouble( int row, int col, double value )
00354 {
00355 int rowtype = m_editProp->m_propdata [row].m_type;
00356
00357 if ( col == Col_Value )
00358 {
00359 switch ( rowtype )
00360 {
00361 case pt_real: m_editProp->m_propdata [row].m_val_real = value;
00362 break;
00363 default:
00364 wxFAIL_MSG(_T("not a real in column value"));
00365 }
00366 }
00367 else
00368 wxFAIL_MSG(_T("unexpected column"));
00369 }
00370
00371 wxString PropertyTable::GetColLabelValue( int col )
00372 {
00373 return headers[col];
00374 }
00375
00376 bool PropertyTable::InsertRows( size_t pos, size_t numRows )
00377 {
00378 wxGrid* grid = m_editProp->m_grid;
00379 size_t curNumRows = m_editProp->m_propdata.size();
00380
00381 if ( pos >= curNumRows )
00382 {
00383 return AppendRows( numRows );
00384 }
00385
00386 m_editProp->m_propdata.resize( curNumRows + numRows );
00387
00388 int row;
00389 for ( row = curNumRows + numRows - 1; row > pos + 1; row-- )
00390 {
00391 m_editProp->m_propdata [row] = m_editProp->m_propdata [row-1];
00392 }
00393 for ( row = pos + 1; row < pos + 1 + numRows; row++ )
00394 {
00395 m_editProp->m_propdata [row].m_name = wxT("");
00396 m_editProp->m_propdata [row].m_type = pt_string;
00397 m_editProp->m_propdata [row].m_val_str = wxT("");
00398 m_editProp->m_propdata [row].m_val_integer = 0;
00399 m_editProp->m_propdata [row].m_val_real = 0.0;
00400 m_editProp->m_propdata [row].m_val_boolean = true;
00401 m_editProp->m_propdata [row].m_prop = NULL;
00402 }
00403
00404 if ( GetView() )
00405 {
00406 wxGridTableMessage msg( this,
00407 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
00408 pos,
00409 numRows );
00410
00411 GetView()->ProcessTableMessage( msg );
00412 }
00413 for ( row = pos + 1; row < pos + 1 + numRows; row++ )
00414 {
00415 grid->SetCellEditor( row, Col_Value, new wxGridCellTextEditor() );
00416 if ( !m_editProp->m_propdata [row].m_prop )
00417 grid->SetReadOnly( row, 1, false );
00418
00419 }
00420 return true;
00421 }
00422
00423 bool PropertyTable::AppendRows( size_t numRows )
00424 {
00425 wxGrid* grid = m_editProp->m_grid;
00426 size_t curNumRows = m_editProp->m_propdata.size();
00427
00428 m_editProp->m_propdata.resize( curNumRows + numRows );
00429 int row;
00430 for ( row = curNumRows; row < curNumRows + numRows; row++ )
00431 {
00432 m_editProp->m_propdata [row].m_name = wxT("");
00433 m_editProp->m_propdata [row].m_type = pt_string;
00434 m_editProp->m_propdata [row].m_val_str = wxT("");
00435 }
00436
00437 if ( GetView() )
00438 {
00439 wxGridTableMessage msg( this,
00440 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
00441 numRows );
00442
00443 GetView()->ProcessTableMessage( msg );
00444 }
00445 grid->SetCellEditor( curNumRows + numRows - 1, Col_Value, new wxGridCellTextEditor() );
00446
00447 return true;
00448 }
00449
00450 bool PropertyTable::DeleteRows( size_t pos, size_t numRows )
00451 {
00452 size_t curNumRows = m_editProp->m_propdata.size();
00453
00454 if ( pos >= curNumRows )
00455 {
00456 wxFAIL_MSG( wxString::Format
00457 (
00458 wxT("Called PropertyTable::DeleteRows(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu rows"),
00459 (unsigned long)pos,
00460 (unsigned long)numRows,
00461 (unsigned long)curNumRows
00462 ) );
00463
00464 return false;
00465 }
00466
00467 if ( numRows > curNumRows - pos )
00468 {
00469 numRows = curNumRows - pos;
00470 }
00471
00472 if ( numRows >= curNumRows )
00473 {
00474 int row;
00475 for ( row = 0; row < curNumRows; row++ )
00476 {
00477 if ( m_editProp->m_propdata [row].m_prop )
00478 m_editProp->m_propdata [row].m_prop->SetCheck( true );
00479 }
00480 m_editProp->m_propdata .clear();
00481 }
00482 else
00483 {
00484 PropGridDataVec::iterator iterfirst = m_editProp->m_propdata.begin();
00485 PropGridDataVec::iterator iterlast = m_editProp->m_propdata.begin();
00486 int row;
00487 for ( row = 0; row < pos; row++ )
00488 iterfirst++;
00489 iterlast = iterfirst;
00490 for ( row = 0; row < numRows -1; row++ )
00491 iterlast++;
00492
00493
00494 for ( row = pos; row < pos + numRows; row++ )
00495 {
00496 if ( m_editProp->m_propdata [row].m_prop )
00497 m_editProp->m_propdata [row].m_prop->SetCheck( true );
00498 }
00499 m_editProp->m_propdata.erase( iterfirst, iterlast );
00500 }
00501
00502 if ( GetView() )
00503 {
00504 wxGridTableMessage msg( this,
00505 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
00506 pos,
00507 numRows );
00508
00509 GetView()->ProcessTableMessage( msg );
00510 }
00511
00512 return true;
00513 }
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523 IMPLEMENT_DYNAMIC_CLASS( a2dEditProperties, wxDialog )
00524
00525 BEGIN_EVENT_TABLE( a2dEditProperties, wxDialog )
00526 EVT_BUTTON( ID_ADD, a2dEditProperties::OnAddClick )
00527 EVT_BUTTON( ID_CUT, a2dEditProperties::OnCutClick )\
00528 EVT_BUTTON( ID_PASTE, a2dEditProperties::OnPasteClick )
00529 EVT_BUTTON( ID_CANCEL, a2dEditProperties::OnCancelClick )\
00530 EVT_BUTTON( ID_OKE, a2dEditProperties::OnOkeClick )
00531 EVT_CLOSE( a2dEditProperties::OnCloseWindow )
00532 EVT_SIZE( a2dEditProperties::OnSize )
00533 END_EVENT_TABLE()
00534
00535 a2dEditProperties::a2dEditProperties( )
00536 {
00537 }
00538
00539 a2dEditProperties::a2dEditProperties( wxWindow* parent, a2dObject* propobject,
00540 a2dNamedPropertyList* propertylist,
00541 wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
00542 {
00543 m_propobject = propobject;
00544 m_propertylist = propertylist;
00545 Create(parent, id, caption, pos, size, style);
00546 }
00547
00548 bool a2dEditProperties::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
00549 {
00550 m_grid = NULL;
00551 m_add = NULL;
00552 m_cut = NULL;
00553 m_cancel = NULL;
00554 m_oke = NULL;
00555 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
00556 wxDialog::Create( parent, id, caption, pos, size, style );
00557
00558 CreateControls();
00559 GetSizer()->Fit(this);
00560 GetSizer()->SetSizeHints(this);
00561 Centre();
00562 return TRUE;
00563 }
00564
00565 void a2dEditProperties::CreateControls()
00566 {
00567 a2dEditProperties* itemDialog1 = this;
00568
00569 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
00570 itemDialog1->SetSizer(itemBoxSizer2);
00571
00572 wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
00573 itemBoxSizer2->Add(itemBoxSizer3, 1, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 5);
00574
00575 int row = 0;
00576 a2dNamedPropertyList::const_iterator iter;
00577 for( iter = m_propertylist->begin(); iter != m_propertylist->end(); ++iter )
00578 {
00579 const a2dNamedProperty *prop = *iter;
00580 if ( prop->GetId()->IsEditable() || prop->GetId()->IsUserDefined() )
00581 row++;
00582 }
00583
00584 m_propdata.resize( row );
00585 row = 0;
00586 for( iter = m_propertylist->begin(); iter != m_propertylist->end(); ++iter )
00587 {
00588 a2dNamedProperty *prop = *iter;
00589 if ( prop->GetId()->IsEditable() || prop->GetId()->IsUserDefined() )
00590 {
00591 m_propdata [row].m_prop = prop;
00592 m_propdata [row].m_name = prop->GetName();
00593 if ( wxDynamicCast( prop, a2dStringProperty ) )
00594 {
00595 m_propdata [row].m_type = pt_string;
00596 m_propdata [row].m_val_str = prop->GetString();
00597 }
00598 else if ( wxDynamicCast( prop, a2dInt32Property ) )
00599 {
00600 m_propdata [row].m_type = pt_integer;
00601 m_propdata [row].m_val_integer = prop->GetInt32();
00602 }
00603 else if ( wxDynamicCast( prop, a2dDoubleProperty ) )
00604 {
00605 m_propdata [row].m_type = pt_real;
00606 m_propdata [row].m_val_real = prop->GetDouble();
00607 }
00608 else if ( wxDynamicCast( prop, a2dBoolProperty ) )
00609 {
00610 m_propdata [row].m_type = pt_bool;
00611 m_propdata [row].m_val_boolean = prop->GetBool();
00612 }
00613 row++;
00614 }
00615 }
00616
00617 m_grid = new wxGrid( itemDialog1, ID_GRID, wxDefaultPosition, wxSize(370, 150), wxSUNKEN_BORDER|wxHSCROLL|wxVSCROLL );
00618 PropertyTable* table = new PropertyTable( this );
00619 m_grid->SetDefaultColSize(100);
00620 m_grid->SetDefaultRowSize(25);
00621 m_grid->SetColLabelSize(25);
00622 m_grid->SetRowLabelSize(50);
00623 m_grid->SetTable(table, true);
00624 m_grid->SetColMinimalAcceptableWidth( 50 );
00625
00626 wxGridCellAttr *attrNameEditor = new wxGridCellAttr,
00627 *attrTypeEditor = new wxGridCellAttr;
00628
00629 attrNameEditor->SetEditor(new wxGridCellTextEditor());
00630 attrTypeEditor->SetEditor(new wxGridCellChoiceEditor(WXSIZEOF(PropertyTypeStrs),
00631 PropertyTypeStrs));
00632 m_grid->SetColAttr( Col_Name, attrNameEditor );
00633 m_grid->SetColAttr( Col_Type, attrTypeEditor );
00634
00635 int j;
00636 for ( j=0; j < m_propdata.size(); j++ )
00637 {
00638
00639 int rowtype = m_propdata [j].m_type;
00640 switch ( rowtype )
00641 {
00642 case pt_string:
00643 m_grid->SetCellEditor( j, 2, new wxGridCellTextEditor() );
00644 break;
00645 case pt_integer:
00646 m_grid->SetCellEditor( j, 2, new wxGridCellNumberEditor(-1, 1) );
00647 break;
00648 case pt_real:
00649 m_grid->SetCellEditor( j, 2, new wxGridCellFloatEditor(-1, 1) );
00650 break;
00651 case pt_bool:
00652 m_grid->SetCellEditor( j, 2, new wxGridCellBoolEditor() );
00653 break;
00654 }
00655 if ( m_propdata [j].m_prop )
00656 m_grid->SetReadOnly( j, 1, true );
00657 }
00658
00659 itemBoxSizer3->Add(m_grid, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 5);
00660
00661 wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
00662 itemBoxSizer2->Add(itemBoxSizer5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 2);
00663
00664 m_add = new wxButton( itemDialog1, ID_ADD, _("Add"), wxDefaultPosition, wxDefaultSize, 0 );
00665 m_add->SetDefault();
00666 m_add->SetHelpText(_("Add a row for a new property"));
00667 if (ShowToolTips())
00668 m_add->SetToolTip(_("Add a row for a new property"));
00669 itemBoxSizer5->Add(m_add, 0, wxALIGN_CENTER_VERTICAL|wxALL , 2);
00670
00671 m_cut = new wxButton( itemDialog1, ID_CUT, _("Cut"), wxDefaultPosition, wxDefaultSize, 0 );
00672 m_cut->SetHelpText(_("Remove property at current row"));
00673 if (ShowToolTips())
00674 m_cut->SetToolTip(_("Remove property at current row"));
00675 itemBoxSizer5->Add(m_cut, 0, wxALIGN_CENTER_VERTICAL|wxALL, 2);
00676
00677 wxButton* itemButton8 = new wxButton( itemDialog1, ID_PASTE, _("Paste"), wxDefaultPosition, wxDefaultSize, 0 );
00678 itemButton8->SetHelpText(_("Paste last cut property"));
00679 if (ShowToolTips())
00680 itemButton8->SetToolTip(_("Paste last cut property"));
00681 itemBoxSizer5->Add(itemButton8, 0, wxALIGN_CENTER_VERTICAL|wxALL, 2);
00682
00683 wxBoxSizer* itemBoxSizer9 = new wxBoxSizer(wxHORIZONTAL);
00684 itemBoxSizer2->Add(itemBoxSizer9, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 2);
00685
00686 m_cancel = new wxButton( itemDialog1, ID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
00687 m_cancel->SetHelpText(_("End edit without applying new values and properties"));
00688 if (ShowToolTips())
00689 m_cancel->SetToolTip(_("End edit without applying new values and properties"));
00690 itemBoxSizer9->Add(m_cancel, 0, wxALIGN_CENTER_VERTICAL|wxALL, 2);
00691
00692 m_oke = new wxButton( itemDialog1, ID_OKE, _("Oke"), wxDefaultPosition, wxDefaultSize, 0 );
00693 m_oke->SetHelpText(_("End edit properties"));
00694 if (ShowToolTips())
00695 m_oke->SetToolTip(_("End edit properties"));
00696 itemBoxSizer9->Add(m_oke, 0, wxALIGN_CENTER_VERTICAL|wxALL, 2);
00697 }
00698
00699 bool a2dEditProperties::ShowToolTips()
00700 {
00701 return TRUE;
00702 }
00703
00704 void a2dEditProperties::OnAddClick( wxCommandEvent& event )
00705 {
00706 m_grid->InsertRows( m_grid->GetGridCursorRow(), 1 );
00707 }
00708
00709
00710 void a2dEditProperties::OnCutClick( wxCommandEvent& event )
00711 {
00712 m_grid->DeleteRows( m_grid->GetGridCursorRow(), 1 );
00713 }
00714
00715
00716 void a2dEditProperties::OnPasteClick( wxCommandEvent& event )
00717 {
00718 event.Skip();
00719 }
00720
00721 void a2dEditProperties::OnCancelClick( wxCommandEvent& event )
00722 {
00723 EndModal(wxID_CANCEL);
00724 }
00725
00726 void a2dEditProperties::OnOkeClick( wxCommandEvent& event )
00727 {
00728 int j;
00729 for ( j=0; j < m_propdata.size(); j++ )
00730 {
00731 a2dNamedProperty *prop = m_propdata [j].m_prop;
00732 wxString name = m_propdata [j].m_name;
00733 if ( prop )
00734 {
00735 if ( m_propobject->HasPropertyId( prop->GetId() ) )
00736 {
00737 bool check = false;
00738 int rowtype = m_propdata [j].m_type;
00739 switch ( rowtype )
00740 {
00741 case pt_string:
00742 {
00743 a2dStringProperty* sprop = wxDynamicCast( prop, a2dStringProperty );
00744 if ( sprop )
00745 sprop->SetValue( m_propdata [j].m_val_str );
00746 check = true;
00747 break;
00748 }
00749 case pt_integer:
00750 {
00751 a2dInt32Property* dprop = wxDynamicCast( prop, a2dInt32Property );
00752 if ( dprop )
00753 dprop->SetValue( m_propdata [j].m_val_integer );
00754 check = true;
00755 break;
00756 }
00757 case pt_real:
00758 {
00759 a2dDoubleProperty* dprop = wxDynamicCast( prop, a2dDoubleProperty );
00760 if ( dprop )
00761 dprop->SetValue( m_propdata [j].m_val_real );
00762 check = true;
00763 break;
00764 }
00765 case pt_bool:
00766 {
00767 a2dBoolProperty* boolprop = wxDynamicCast( prop, a2dBoolProperty );
00768 if ( boolprop )
00769 boolprop->SetValue( m_propdata [j].m_val_boolean );
00770 check = true;
00771 break;
00772 }
00773 }
00774 if ( !check )
00775 {
00776 wxString mes;
00777 mes = wxT("property with name: ") + name +
00778 wxT("\nhas already bin created on this object with a different type.\n") +
00779 wxT("use a different name which does not conflict, or set the type to ") +
00780 PropertyTypeStrs[ rowtype ];
00781 wxMessageBox( mes, _("edit properties"), wxICON_WARNING | wxOK );
00782 }
00783 else
00784 {
00785 a2dPropertyId* castp = const_cast<a2dPropertyId*>( prop->GetId() );
00786 castp->SetName( name );
00787 }
00788 }
00789 else
00790 wxMessageBox( _("object is missing a property ID"), _("edit properties"), wxICON_WARNING | wxOK );
00791 }
00792 else
00793 {
00794
00795 a2dPropertyId* propid = m_propobject->HasPropertyId( name );
00796 int rowtype = m_propdata [j].m_type;
00797 if ( propid )
00798 {
00799
00800 bool check = false;
00801 a2dNamedPropertyPtr propcreated = NULL;
00802 switch ( rowtype )
00803 {
00804 case pt_string:
00805 {
00806 propcreated = propid->CreatePropertyFromString( m_propdata [j].m_val_str );
00807 a2dStringProperty* prop = wxDynamicCast( propcreated.Get(), a2dStringProperty );
00808 if ( prop )
00809 {
00810 check = true;
00811 prop->SetValue( m_propdata [j].m_val_str );
00812 }
00813 break;
00814 }
00815 case pt_integer:
00816 {
00817 propcreated = propid->CreatePropertyFromString( wxT("") );
00818 a2dInt32Property* prop = wxDynamicCast( propcreated.Get(), a2dInt32Property );
00819 if ( prop )
00820 {
00821 check = true;
00822 prop->SetValue( m_propdata [j].m_val_integer );
00823 }
00824 break;
00825 }
00826 case pt_real:
00827 {
00828 propcreated = propid->CreatePropertyFromString( wxT("") );
00829 a2dDoubleProperty* prop = wxDynamicCast( propcreated.Get(), a2dDoubleProperty );
00830 if ( prop )
00831 {
00832 check = true;
00833 prop->SetValue( m_propdata [j].m_val_real );
00834 }
00835 break;
00836 }
00837 case pt_bool:
00838 {
00839 propcreated = propid->CreatePropertyFromString( wxT("") );
00840 a2dBoolProperty* prop = wxDynamicCast( propcreated.Get(), a2dBoolProperty );
00841 if ( prop )
00842 {
00843 check = true;
00844 prop->SetValue( m_propdata [j].m_val_boolean );
00845 }
00846 break;
00847 }
00848 }
00849 if ( !check )
00850 {
00851 wxString mes;
00852 mes = wxT("property with name: ") + name +
00853 wxT("\nhas already bin created on this object, but with a different type.\n") +
00854 wxT("use a different name which does not conflict, or set the type to ") +
00855 PropertyTypeStrs[ rowtype ];
00856 wxMessageBox( mes, _("edit properties"), wxICON_WARNING | wxOK );
00857 }
00858 else
00859 m_propertylist->push_back( propcreated );
00860
00861 }
00862 else
00863 {
00864 a2dNamedPropertyPtr propcreated = NULL;
00865 switch ( rowtype )
00866 {
00867 case pt_string:
00868 {
00869 propid = new a2dPropertyIdString( name, wxT(""), a2dPropertyId::flag_userDefined );
00870 m_propobject->AddPropertyId( propid );
00871 propcreated = propid->CreatePropertyFromString( m_propdata [j].m_val_str );
00872 a2dStringProperty* prop = wxDynamicCast( propcreated.Get(), a2dStringProperty );
00873 break;
00874 }
00875 case pt_integer:
00876 {
00877 propid = new a2dPropertyIdInt32( name, 0, a2dPropertyId::flag_userDefined );
00878 m_propobject->AddPropertyId( propid );
00879 propcreated = propid->CreatePropertyFromString( wxT("") );
00880 a2dInt32Property* prop = wxDynamicCast( propcreated.Get(), a2dInt32Property );
00881 prop->SetValue( m_propdata [j].m_val_integer );
00882 break;
00883 }
00884 case pt_real:
00885 {
00886 propid = new a2dPropertyIdDouble( name, 0, a2dPropertyId::flag_userDefined );
00887 m_propobject->AddPropertyId( propid );
00888 propcreated = propid->CreatePropertyFromString( wxT("") );
00889 a2dDoubleProperty* prop = wxDynamicCast( propcreated.Get(), a2dDoubleProperty );
00890 prop->SetValue( m_propdata [j].m_val_real );
00891 break;
00892 }
00893 case pt_bool:
00894 {
00895 propid = new a2dPropertyIdBool( name, 0, a2dPropertyId::flag_userDefined );
00896 m_propobject->AddPropertyId( propid );
00897 propcreated = propid->CreatePropertyFromString( wxT("") );
00898 a2dBoolProperty* prop = wxDynamicCast( propcreated.Get(), a2dBoolProperty );
00899 prop->SetValue( m_propdata [j].m_val_boolean );
00900 break;
00901 }
00902 }
00903 m_propertylist->push_back( propcreated );
00904 }
00905 }
00906 }
00907
00908 EndModal(wxID_OK);
00909 }
00910
00911 void a2dEditProperties::OnCloseWindow( wxCloseEvent& event )
00912 {
00913 EndModal(wxID_CANCEL);
00914 }
00915
00916 void a2dEditProperties::OnSize( wxSizeEvent& event )
00917 {
00918 event.Skip();
00919 return;
00920
00921 int clientw, clienth;
00922 GetClientSize( &clientw, &clienth );
00923
00924 GetSizer()->SetSizeHints(this);
00925 GetSizer()->Fit(this);
00926
00927 }
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953 const int GROUP_BUTTON_OK = wxID_HIGHEST + 5401 ;
00954 const int GROUP_BUTTON_CANCEL = wxID_HIGHEST + 5402 ;
00955 const int GROUP_BUTTON_SHOW = wxID_HIGHEST + 5403 ;
00956
00957 BEGIN_EVENT_TABLE(a2dPropertyEditorDlg, wxDialog)
00958 EVT_BUTTON (GROUP_BUTTON_OK, a2dPropertyEditorDlg::CmOk)
00959 EVT_BUTTON (GROUP_BUTTON_CANCEL , a2dPropertyEditorDlg::CmCancel)
00960 EVT_CLOSE (a2dPropertyEditorDlg::OnCloseWindow)
00961 END_EVENT_TABLE()
00962
00963 a2dPropertyEditorDlg::a2dPropertyEditorDlg( wxFrame* parent, a2dNamedPropertyList* propertylist ):
00964 wxDialog(parent,-1, _T("Property editor"), wxPoint(0,0), wxSize(100,500),
00965 (wxDEFAULT_DIALOG_STYLE |wxSTAY_ON_TOP |wxRESIZE_BORDER), _T("Property editor"))
00966 {
00967 m_listbox = new wxListBox( this, -1, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_NEEDED_SB | wxLB_SINGLE );
00968 m_button1 = new wxButton( this, GROUP_BUTTON_OK, _T("Ok"), wxDefaultPosition, wxSize(55,20) );
00969 m_button2 = new wxButton( this, GROUP_BUTTON_CANCEL, _T("Cancel"), wxDefaultPosition, wxSize(55,20) );
00970
00971 m_propertylist = NULL;
00972 m_listbox->Clear();
00973
00974 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
00975
00976 wxStaticText* title = new wxStaticText(this,-1, _T("properties"));
00977 wxBoxSizer *item3 = new wxBoxSizer( wxHORIZONTAL );
00978 item3->Add( title, 1, wxALL, 2 );
00979 item0->Add( item3, 0, wxEXPAND, 2 );
00980 Centre(wxBOTH);
00981
00982 wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
00983 item1->Add( m_listbox, 1, wxEXPAND|wxALL, 2 );
00984 item0->Add( item1, 1, wxEXPAND, 2 );
00985
00986 wxBoxSizer *item2 = new wxBoxSizer( wxHORIZONTAL );
00987 item2->Add( m_button1, 1, wxALL, 2 );
00988 item2->Add( m_button2, 1, wxALL, 2 );
00989
00990 item0->Add( item2, 0, wxEXPAND, 2 );
00991
00992 SetAutoLayout( true );
00993 SetSizer( item0 );
00994 item0->Fit( this );
00995 item0->SetSizeHints( this );
00996
00997 m_listbox->Clear();
00998 a2dNamedPropertyList::const_iterator iter;
00999 for( iter = propertylist->begin(); iter != propertylist->end(); ++iter )
01000 {
01001 const a2dNamedProperty *prop = *iter;
01002
01003
01004
01005 m_listbox->Append(prop->GetId()->GetName());
01006 }
01007
01008 if ( !propertylist->empty() )
01009 m_listbox->SetSelection(0,true);
01010 }
01011
01012 a2dPropertyEditorDlg::~a2dPropertyEditorDlg()
01013 {
01014 }
01015
01016 void a2dPropertyEditorDlg::CmOk( wxCommandEvent& )
01017 {
01018 EndModal(wxID_OK);
01019 }
01020
01021 void a2dPropertyEditorDlg::CmCancel( wxCommandEvent& )
01022 {
01023 EndModal(wxID_CANCEL);
01024 }
01025
01026 void a2dPropertyEditorDlg::OnCloseWindow(wxCloseEvent& WXUNUSED(event) )
01027 {
01028 wxCommandEvent eventc;
01029 CmCancel( eventc );
01030 }