00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "a2dprec.h"
00012
00013 #ifdef __BORLANDC__
00014 #pragma hdrstop
00015 #endif
00016
00017 #ifdef __GNUG__
00018 #pragma implementation
00019 #endif
00020
00021 #include "wx/canvas/canmod.h"
00022 #include "wx/editor/doccancom.h"
00023 #include "wx/canvas/layerinf.h"
00024
00025 #include "wx/editor/orderdlg.h"
00026
00027 const int ORDER_LIST_SELECT = wxID_HIGHEST + 5108 ;
00028
00029 BEGIN_EVENT_TABLE(a2dDragListBox, wxListBox)
00030 EVT_LISTBOX( ORDER_LIST_SELECT, a2dDragListBox::CmListBox )
00031 EVT_LEFT_DOWN(a2dDragListBox::OnMouseLeftDown)
00032 EVT_LEFT_UP(a2dDragListBox::OnMouseLeftUp)
00033 END_EVENT_TABLE()
00034
00035 a2dDragListBox::a2dDragListBox(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size,
00036 int n,const wxString choices[],long style)
00037 :wxListBox (parent,id,pos,size,n,choices,style)
00038 {
00039 m_selection = 0;
00040 }
00041
00042 void a2dDragListBox::OnMouseLeftDown(class wxMouseEvent& event )
00043 {
00044 wxPoint point = wxPoint( event.m_x, event.m_y );
00045 m_selection = HitTest( point );
00046
00047 event.Skip();
00048 }
00049
00050 void a2dDragListBox::OnMouseLeftUp(class wxMouseEvent& event )
00051 {
00052 int pasteLoc = GetSelection();
00053 if ( m_selection != -1 && m_selection != pasteLoc )
00054 {
00055 if ( m_selection < pasteLoc )
00056 {
00057 int row;
00058 for ( row = m_selection; row < pasteLoc; row++ )
00059 {
00060 wxString selectLocStr = GetString( row );
00061 wxString copyLocStr = GetString( row + 1 );
00062
00063 SetString( row, copyLocStr );
00064 SetString( row + 1, selectLocStr );
00065 }
00066
00067 }
00068 else
00069 {
00070 int row;
00071 for ( row = m_selection; row > pasteLoc; row-- )
00072 {
00073 wxString selectLocStr = GetString( row );
00074 wxString copyLocStr = GetString( row - 1 );
00075
00076 SetString( row, copyLocStr );
00077 SetString( row - 1, selectLocStr );
00078 }
00079
00080 }
00081 }
00082 event.Skip();
00083 }
00084
00085 void a2dDragListBox::CmListBox( wxCommandEvent& selevent )
00086 {
00087 m_selection = GetSelection();
00088 selevent.Skip();
00089 }
00090
00091
00092 const int ORDER_BUTTON_OK = wxID_HIGHEST + 5101 ;
00093 const int ORDER_BUTTON_CANCEL = wxID_HIGHEST + 5102 ;
00094
00095 const int ORDER_BUTTON_UP = wxID_HIGHEST + 5103 ;
00096
00097 const int ORDER_BUTTON_DOWN = wxID_HIGHEST + 5104 ;
00098
00099 const int ORDER_BUTTON_SHOW = wxID_HIGHEST + 5106 ;
00100
00101 const int ORDER_UPDATE_DIALOG = wxID_HIGHEST + 5107 ;
00102
00103
00104 BEGIN_EVENT_TABLE(a2dLayerOrderDialog, wxDialog)
00105
00106 EVT_CHANGED_DOCUMENT( a2dLayerOrderDialog::OnChangedDocument )
00107
00108 EVT_BUTTON (ORDER_BUTTON_OK, a2dLayerOrderDialog::CmOk)
00109
00110 EVT_BUTTON (ORDER_BUTTON_CANCEL, a2dLayerOrderDialog::CmCancel)
00111
00112 EVT_BUTTON (ORDER_BUTTON_UP, a2dLayerOrderDialog::CmUp)
00113
00114 EVT_BUTTON (ORDER_BUTTON_DOWN, a2dLayerOrderDialog::CmDown)
00115
00116 EVT_BUTTON (ORDER_BUTTON_SHOW, a2dLayerOrderDialog::CmShow)
00117
00118 EVT_LISTBOX (ORDER_LIST_SELECT, a2dLayerOrderDialog::CmListBox)
00119
00120 EVT_CLOSE (a2dLayerOrderDialog::OnCloseWindow)
00121
00122 END_EVENT_TABLE()
00123
00124
00125 a2dLayerOrderDialog::a2dLayerOrderDialog( wxWindow* parent, a2dLayers* layersetup, const wxString& title, long style, const wxString& name ):
00126 wxDialog(parent,ORDER_UPDATE_DIALOG,title,wxPoint(0,0),wxSize(200,500),style,name)
00127 {
00128 a2dDocviewGlobals->GetEventDistributer()->Register( this );
00129
00130 a2dLayerOrderDialog* itemDialog1 = this;
00131
00132 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
00133 itemDialog1->SetSizer(itemBoxSizer2);
00134
00135 wxString* m_listboxStrings = NULL;
00136 m_listbox = new a2dDragListBox( itemDialog1, ORDER_LIST_SELECT, wxDefaultPosition, wxSize(100,500), 0, m_listboxStrings, wxLB_SINGLE|wxLB_NEEDED_SB );
00137 m_listbox->SetHelpText(_("Select a layer and press up or down button"));
00138 m_listbox->SetToolTip(_("Select a layer and press up or down button"));
00139 itemBoxSizer2->Add(m_listbox, 1, wxGROW|wxALL, 0);
00140
00141 wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
00142 itemBoxSizer2->Add(itemBoxSizer4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
00143
00144 m_buttonOK = new wxButton( itemDialog1, ORDER_BUTTON_OK, _("Hide"), wxDefaultPosition, wxSize(55, 22), 0 );
00145 itemBoxSizer4->Add(m_buttonOK, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
00146
00147 m_buttonCANCEL = new wxButton( itemDialog1, ORDER_BUTTON_CANCEL, _("Cancel"), wxDefaultPosition, wxSize(55, 22), 0 );
00148 itemBoxSizer4->Add(m_buttonCANCEL, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
00149
00150 itemBoxSizer4->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
00151
00152 m_buttonUP = new wxButton( itemDialog1, ORDER_BUTTON_UP, _("Up"), wxDefaultPosition, wxSize(55, 22), 0 );
00153 itemBoxSizer4->Add(m_buttonUP, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
00154
00155 m_buttonDOWN = new wxButton( itemDialog1, ORDER_BUTTON_DOWN, _("Down"), wxDefaultPosition, wxSize(55, 22), 0 );
00156 itemBoxSizer4->Add(m_buttonDOWN, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
00157
00158 m_buttonSHOW = new wxButton( itemDialog1, ORDER_BUTTON_SHOW, _("Apply"), wxDefaultPosition, wxSize(55, 22), 0 );
00159 itemBoxSizer4->Add(m_buttonSHOW, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
00160
00161 GetSizer()->Fit(this);
00162 GetSizer()->SetSizeHints(this);
00163 Centre();
00164
00165 Init( layersetup );
00166 }
00167
00168 a2dLayerOrderDialog::~a2dLayerOrderDialog()
00169 {
00170 a2dDocviewGlobals->GetEventDistributer()->Unregister( this );
00171 }
00172
00173 void a2dLayerOrderDialog::Init( a2dLayers* layersetup )
00174 {
00175 if ( !layersetup )
00176 return;
00177
00178 m_layersetup = layersetup;
00179
00180 m_listbox->Clear();
00181
00182 int j;
00183 for ( j=0; j < wxMAXLAYER; j++ )
00184 {
00185 a2dLayerInfo* layerinfo = m_layersetup->GetOrderIndex()[ j ];
00186 if ( layerinfo != wxNullLayerInfo )
00187 {
00188 wxChar _buf[60];
00189
00190 wxSnprintf(_buf, sizeof(_buf), wxT("%04d %s"), j, layerinfo->GetName().c_str() );
00191 m_listbox->Append(_buf);
00192 }
00193 else
00194 {
00195 wxChar _buf[60];
00196
00197 wxSnprintf(_buf, sizeof(_buf), wxT("%04d ND %s"), j, layerinfo->GetName().c_str() );
00198 m_listbox->Append(_buf);
00199 }
00200
00201 }
00202 }
00203
00204 void a2dLayerOrderDialog::OnChangedDocument( a2dCommandEvent& event )
00205 {
00206 a2dCanvasDocument* doc = (a2dCanvasDocument*) event.GetDocument();
00207 if ( doc && doc->GetLayerSetup() != m_layersetup )
00208 {
00209 doc->GetLayerSetup()->SetAvailable( doc );
00210 Init( doc->GetLayerSetup() );
00211 }
00212 }
00213
00214 void a2dLayerOrderDialog::StoreOrder()
00215 {
00216 wxString layernr;
00217 for (int i = 0; i < wxMAXLAYER; i++)
00218 {
00219 layernr = m_listbox->GetString(i).Left(4);
00220 a2dLayerInfo* layerinfo = m_layersetup->GetLayerIndex()[ wxAtoi(layernr) ];
00221 if ( layerinfo != wxNullLayerInfo )
00222 {
00223 layerinfo->SetOrder( i*10 );
00224 }
00225 }
00226 m_layersetup->SetPending( true );
00227
00228 SetEvtHandlerEnabled( false );
00229 a2dComEvent changedlayers( m_layersetup->GetCanvasDocument(), m_layersetup, &a2dCanvasDocument::sm_layersetupChanged );
00230 a2dDocviewGlobals->GetEventDistributer()->ProcessEvent( changedlayers );
00231 SetEvtHandlerEnabled( true );
00232 }
00233
00234 void a2dLayerOrderDialog::CmOk(wxCommandEvent&)
00235 {
00236 int selection = m_listbox->GetSelection();
00237 m_listbox->SetSelection(selection, FALSE);
00238
00239 StoreOrder();
00240 Show(FALSE);
00241 }
00242
00243 void a2dLayerOrderDialog::CmShow(wxCommandEvent&)
00244 {
00245 int selection = m_listbox->GetSelection();
00246 m_listbox->SetSelection(selection, FALSE);
00247
00248 StoreOrder();
00249 }
00250
00251 void a2dLayerOrderDialog::OnCloseWindow(wxCloseEvent& event)
00252 {
00253 wxCommandEvent a = wxCommandEvent();
00254 CmCancel(a);
00255 }
00256
00257 void a2dLayerOrderDialog::CmCancel(wxCommandEvent&)
00258 {
00259 Show(FALSE);
00260
00261 m_listbox->Clear();
00262
00263
00264
00265 }
00266
00267 void a2dLayerOrderDialog::CmUp(wxCommandEvent&)
00268 {
00269 int selection = m_listbox->GetSelection();
00270 if (selection == -1)
00271 (void)wxMessageBox( _T("You must select a layer first"),_T("a2dLayerOrderDialog"), wxICON_INFORMATION | wxOK );
00272 else
00273 {
00274 if ( selection != 0 )
00275 {
00276 if (selection == wxMAXLAYER-1 ) m_buttonDOWN->Enable(TRUE);
00277
00278 wxString selected = m_listbox->GetString(m_listbox->GetSelection()-1);
00279
00280 m_listbox->SetString(selection-1,m_listbox->GetString(selection));
00281 m_listbox->SetString(selection,selected);
00282 m_listbox->Show(TRUE);
00283
00284
00285 m_listbox->SetSelection(selection, FALSE);
00286 m_listbox->SetSelection(selection-1, TRUE);
00287 if (selection == 1)
00288 m_buttonUP->Enable(FALSE);
00289 }
00290 else
00291 {
00292 (void)wxMessageBox( _T("layer is allready at the highest possible order"),_T("a2dLayerOrderDialog"), wxICON_INFORMATION | wxOK );
00293 }
00294 }
00295 }
00296
00297 void a2dLayerOrderDialog::CmDown(wxCommandEvent&)
00298 {
00299 int selection = m_listbox->GetSelection();
00300
00301 if (selection == -1)
00302 (void)wxMessageBox( _T("You must select a layer first"),_T("a2dLayerOrderDialog"), wxICON_INFORMATION | wxOK );
00303 else
00304 {
00305 if (selection != wxMAXLAYER-1 )
00306 {
00307 if (selection == 0) m_buttonUP->Enable(TRUE);
00308
00309 wxString selected = m_listbox->GetString(m_listbox->GetSelection()+1);
00310
00311 m_listbox->SetString(selection+1,m_listbox->GetString(selection));
00312 m_listbox->SetString(selection,selected);
00313 m_listbox->Show(TRUE);
00314
00315
00316 m_listbox->SetSelection(selection, FALSE);
00317 m_listbox->SetSelection(selection+1, TRUE);
00318
00319 if (selection == wxMAXLAYER-2 ) m_buttonDOWN->Enable(FALSE);
00320 }
00321 else
00322 {
00323 (void)wxMessageBox( _T("layer is allready at the lowest possible order"),_T("a2dLayerOrderDialog"), wxICON_INFORMATION | wxOK );
00324 }
00325 }
00326 }
00327
00328 void a2dLayerOrderDialog::CmListBox(wxCommandEvent&)
00329 {
00330 int selection = m_listbox->GetSelection();
00331 m_buttonUP->Enable(selection != 0);
00332 m_buttonDOWN->Enable(selection != wxMAXLAYER-1 );
00333
00334 a2dGetCmdh()->Submit( new a2dCommand_SetLayer( selection, true ) );
00335
00336 }
00337
00338 void a2dLayerOrderDialog::OnComEvent( a2dComEvent& event )
00339 {
00340 if ( GetEvtHandlerEnabled() )
00341 {
00342 if ( event.GetEventComId() == &a2dCanvasView::sm_changedLayers )
00343 {
00344 a2dCanvasDocument* doc = wxDynamicCast( event.GetEventObject(), a2dCanvasDocument );
00345 if ( doc && doc == m_layersetup->GetCanvasDocument() )
00346 Init( doc->GetLayerSetup() );
00347 }
00348 else if ( event.GetEventComId() == &a2dCanvasDocument::sm_layersetupChanged )
00349 {
00350 a2dCanvasDocument* doc = wxDynamicCast( event.GetEventObject(), a2dCanvasDocument );
00351 if ( doc && doc == m_layersetup->GetCanvasDocument() )
00352 Init( doc->GetLayerSetup() );
00353 }
00354 else if ( event.GetEventComId() == &a2dLayerInfo::sm_changedLayer )
00355 {
00356 a2dCanvasObject* obj = wxDynamicCast( event.GetEventObject(), a2dCanvasObject );
00357 if ( m_layersetup->GetCanvasDocument() == obj->GetCanvasDocument() )
00358 Init( m_layersetup );
00359 }
00360
00361 }
00362 }
00363
00364
00365
00366
00367
00368 BEGIN_EVENT_TABLE(a2dLayerDialog, wxDialog)
00369
00370 EVT_CHANGED_DOCUMENT( a2dLayerDialog::OnChangedDocument )
00371
00372 EVT_BUTTON (ORDER_BUTTON_OK, a2dLayerDialog::CmOk)
00373
00374 EVT_BUTTON (ORDER_BUTTON_CANCEL, a2dLayerDialog::CmCancel)
00375
00376 EVT_LISTBOX (ORDER_LIST_SELECT, a2dLayerDialog::CmListBox)
00377
00378 EVT_CLOSE (a2dLayerDialog::OnCloseWindow)
00379
00380 END_EVENT_TABLE()
00381
00382
00383 a2dLayerDialog::a2dLayerDialog( wxWindow* parent, a2dLayers* layersetup, bool onOrder, bool modal, const wxString& title, const wxString& name ):
00384 wxDialog(parent,ORDER_UPDATE_DIALOG,title,wxPoint(0,0),wxSize(200,500), wxDEFAULT_DIALOG_STYLE, name )
00385 {
00386 a2dDocviewGlobals->GetEventDistributer()->Register( this );
00387
00388 a2dLayerDialog* itemDialog1 = this;
00389
00390 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
00391 itemDialog1->SetSizer(itemBoxSizer2);
00392
00393 wxString* m_listboxStrings = NULL;
00394 m_listbox = new wxListBox( itemDialog1, ORDER_LIST_SELECT, wxDefaultPosition, wxSize(100,500), 0, m_listboxStrings, wxLB_SINGLE|wxLB_NEEDED_SB );
00395 m_listbox->SetHelpText(_("Select a layer and press up or down button"));
00396 m_listbox->SetToolTip(_("Select a layer and press up or down button"));
00397 itemBoxSizer2->Add(m_listbox, 1, wxGROW|wxALL, 0);
00398
00399 wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
00400 itemBoxSizer2->Add(itemBoxSizer4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
00401
00402 m_modal = modal;
00403 if ( m_modal )
00404 m_buttonOK = new wxButton( itemDialog1, ORDER_BUTTON_OK, _("Oke"), wxDefaultPosition, wxSize(55, 22), 0 );
00405 else
00406 m_buttonOK = new wxButton( itemDialog1, ORDER_BUTTON_OK, _("Hide"), wxDefaultPosition, wxSize(55, 22), 0 );
00407 itemBoxSizer4->Add(m_buttonOK, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
00408
00409 m_buttonCANCEL = new wxButton( itemDialog1, ORDER_BUTTON_CANCEL, _("Cancel"), wxDefaultPosition, wxSize(55, 22), 0 );
00410 itemBoxSizer4->Add(m_buttonCANCEL, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
00411
00412 itemBoxSizer4->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
00413
00414 GetSizer()->Fit(this);
00415 GetSizer()->SetSizeHints(this);
00416 Centre();
00417
00418 m_layerselected = 0;
00419 m_onOrder = onOrder;
00420 Init( layersetup );
00421 }
00422
00423 a2dLayerDialog::~a2dLayerDialog()
00424 {
00425 a2dDocviewGlobals->GetEventDistributer()->Unregister( this );
00426 }
00427
00428 void a2dLayerDialog::Init( a2dLayers* layersetup )
00429 {
00430 if ( !layersetup )
00431 return;
00432
00433 m_layersetup = layersetup;
00434
00435 m_listbox->Clear();
00436
00437 int j;
00438 for ( j=0; j < wxMAXLAYER; j++ )
00439 {
00440 a2dLayerInfo* layerinfo;
00441 if ( m_onOrder )
00442 layerinfo = m_layersetup->GetOrderIndex()[ j ];
00443 else
00444 layerinfo = m_layersetup->GetLayerIndex()[ j ];
00445
00446 if ( layerinfo != wxNullLayerInfo )
00447 {
00448 wxChar _buf[60];
00449
00450 wxSnprintf(_buf, sizeof(_buf), wxT("%04d %s"), j, layerinfo->GetName().c_str() );
00451 m_listbox->Append(_buf);
00452 }
00453 }
00454 }
00455
00456 void a2dLayerDialog::OnChangedDocument( a2dCommandEvent& event )
00457 {
00458 a2dCanvasDocument* doc = (a2dCanvasDocument*) event.GetDocument();
00459 if ( doc && doc->GetLayerSetup() != m_layersetup )
00460 {
00461 doc->GetLayerSetup()->SetAvailable( doc );
00462 Init( doc->GetLayerSetup() );
00463 }
00464 }
00465
00466 void a2dLayerDialog::CmOk(wxCommandEvent&)
00467 {
00468 if ( IsModal() )
00469 EndModal(wxID_OK);
00470 else
00471 {
00472 SetReturnCode(wxID_OK);
00473 Show(false);
00474 }
00475 }
00476
00477 void a2dLayerDialog::OnCloseWindow(wxCloseEvent& event)
00478 {
00479 if ( IsModal() )
00480 EndModal(wxID_CANCEL);
00481 else
00482 {
00483 SetReturnCode(wxID_CANCEL);
00484 Show(false);
00485 }
00486 }
00487
00488 void a2dLayerDialog::CmCancel(wxCommandEvent&)
00489 {
00490 if ( IsModal() )
00491 EndModal(wxID_CANCEL);
00492 else
00493 {
00494 SetReturnCode(wxID_CANCEL);
00495 Show(false);
00496 }
00497 }
00498
00499 void a2dLayerDialog::CmListBox(wxCommandEvent&)
00500 {
00501 m_layerselected = m_listbox->GetSelection();
00502 if ( !IsModal() )
00503 {
00504 if ( !a2dGetCmdhEditor() )
00505 return;
00506 a2dGetCmdhEditor()->Submit( new a2dCommand_SetLayer( GetSelectedLayer(), false ) );
00507 }
00508 }
00509
00510 void a2dLayerDialog::OnComEvent( a2dComEvent& event )
00511 {
00512 if ( GetEvtHandlerEnabled() )
00513 {
00514 if ( event.GetEventComId() == &a2dCanvasView::sm_changedLayers )
00515 {
00516 a2dCanvasDocument* doc = wxDynamicCast( event.GetEventObject(), a2dCanvasDocument );
00517 if ( doc && doc == m_layersetup->GetCanvasDocument() )
00518 Init( doc->GetLayerSetup() );
00519 }
00520 else if ( event.GetEventComId() == &a2dCanvasDocument::sm_layersetupChanged )
00521 {
00522 a2dCanvasDocument* doc = wxDynamicCast( event.GetEventObject(), a2dCanvasDocument );
00523 if ( doc && doc == m_layersetup->GetCanvasDocument() )
00524 Init( doc->GetLayerSetup() );
00525 }
00526 else if ( event.GetEventComId() == &a2dLayerInfo::sm_changedLayer )
00527 {
00528 a2dCanvasObject* obj = wxDynamicCast( event.GetEventObject(), a2dCanvasObject );
00529 if ( m_layersetup->GetCanvasDocument() == obj->GetCanvasDocument() )
00530 Init( m_layersetup );
00531 }
00532
00533 }
00534 }