wxArt2D
orderdlg.cpp
Go to the documentation of this file.
1 /*! \file editor/src/orderdlg.cpp
2  \author Klaas Holwerda
3 
4  Copyright: 2000-2004 (c) Klaas Holwerda
5 
6  Licence: wxWidgets Licence
7 
8  RCS-ID: $Id: orderdlg.cpp,v 1.8 2009/10/01 19:22:35 titato Exp $
9 */
10 
11 #include "a2dprec.h"
12 
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16 
17 #ifdef __GNUG__
18 #pragma implementation
19 #endif
20 
21 #include "wx/canvas/canmod.h"
22 #include "wx/editor/candocproc.h"
23 #include "wx/canvas/layerinf.h"
24 #include "wx/canvas/canorderdlg.h"
25 
26 #include "wx/editor/orderdlg.h"
27 
28 const int ORDER_LIST_SELECT = wxID_HIGHEST + 5108 ;
29 
30 const int ORDER_BUTTON_OK = wxID_HIGHEST + 5101 ;
31 const int ORDER_BUTTON_CANCEL = wxID_HIGHEST + 5102 ;
32 
33 const int ORDER_BUTTON_UP = wxID_HIGHEST + 5103 ;
34 
35 const int ORDER_BUTTON_DOWN = wxID_HIGHEST + 5104 ;
36 
37 const int ORDER_BUTTON_SHOW = wxID_HIGHEST + 5106 ;
38 
39 const int ORDER_UPDATE_DIALOG = wxID_HIGHEST + 5107 ;
40 
41 
42 BEGIN_EVENT_TABLE( a2dLayerOrderDialog, wxDialog )
43 
44  EVT_CHANGED_DOCUMENT( a2dLayerOrderDialog::OnChangedDocument )
45 
46  EVT_BUTTON ( ORDER_BUTTON_OK, a2dLayerOrderDialog::CmOk )
47 
48  EVT_BUTTON ( ORDER_BUTTON_CANCEL, a2dLayerOrderDialog::CmCancel )
49 
50  EVT_BUTTON ( ORDER_BUTTON_UP, a2dLayerOrderDialog::CmUp )
51 
52  EVT_BUTTON ( ORDER_BUTTON_DOWN, a2dLayerOrderDialog::CmDown )
53 
54  EVT_BUTTON ( ORDER_BUTTON_SHOW, a2dLayerOrderDialog::CmShow )
55 
56  EVT_LISTBOX ( ORDER_LIST_SELECT, a2dLayerOrderDialog::CmListBox )
57 
58  EVT_CLOSE ( a2dLayerOrderDialog::OnCloseWindow )
59 
60  EVT_ACTIVATE_VIEW( a2dLayerOrderDialog::OnActivateView )
61 
62 END_EVENT_TABLE()
63 
64 
65 a2dLayerOrderDialog::a2dLayerOrderDialog( wxWindow* parent, a2dLayers* layersetup, const wxString& title, long style, const wxString& name ):
66  wxDialog( parent, ORDER_UPDATE_DIALOG, title, wxPoint( 0, 0 ), wxSize( 200, 500 ), style, name )
67 {
68  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_ACTIVATE_VIEW, this );
69  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_CHANGED_DOCUMENT, this );
70  a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( a2dEVT_COM_EVENT, this );
71 
72  a2dLayerOrderDialog* itemDialog1 = this;
73 
74  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer( wxHORIZONTAL );
75  itemDialog1->SetSizer( itemBoxSizer2 );
76 
77  wxString* m_listboxStrings = NULL;
78  m_listbox = new a2dDragListBox( itemDialog1, ORDER_LIST_SELECT, wxDefaultPosition, wxSize( 100, 500 ), 0, m_listboxStrings, wxLB_SINGLE | wxLB_NEEDED_SB );
79  m_listbox->SetHelpText( _( "Select a layer and press up or down button" ) );
80  m_listbox->SetToolTip( _( "Select a layer and press up or down button" ) );
81  itemBoxSizer2->Add( m_listbox, 1, wxGROW | wxALL, 0 );
82 
83  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer( wxVERTICAL );
84  itemBoxSizer2->Add( itemBoxSizer4, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0 );
85 
86  m_buttonOK = new wxButton( itemDialog1, ORDER_BUTTON_OK, _( "Hide" ), wxDefaultPosition, wxSize( 55, 22 ), 0 );
87  itemBoxSizer4->Add( m_buttonOK, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0 );
88 
89  m_buttonCANCEL = new wxButton( itemDialog1, ORDER_BUTTON_CANCEL, _( "Cancel" ), wxDefaultPosition, wxSize( 55, 22 ), 0 );
90  itemBoxSizer4->Add( m_buttonCANCEL, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0 );
91 
92  itemBoxSizer4->Add( 5, 5, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5 );
93 
94  m_buttonUP = new wxButton( itemDialog1, ORDER_BUTTON_UP, _( "Up" ), wxDefaultPosition, wxSize( 55, 22 ), 0 );
95  itemBoxSizer4->Add( m_buttonUP, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0 );
96 
97  m_buttonDOWN = new wxButton( itemDialog1, ORDER_BUTTON_DOWN, _( "Down" ), wxDefaultPosition, wxSize( 55, 22 ), 0 );
98  itemBoxSizer4->Add( m_buttonDOWN, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0 );
99 
100  m_buttonSHOW = new wxButton( itemDialog1, ORDER_BUTTON_SHOW, _( "Apply" ), wxDefaultPosition, wxSize( 55, 22 ), 0 );
101  itemBoxSizer4->Add( m_buttonSHOW, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0 );
102 
103  GetSizer()->Fit( this );
104  GetSizer()->SetSizeHints( this );
105  Centre();
106 
107  Init( layersetup );
108 }
109 
111 {
112  a2dDocviewGlobals->GetDocviewCommandProcessor()->DisconnectEvent( wxEVT_ACTIVATE_VIEW, this );
113  a2dDocviewGlobals->GetDocviewCommandProcessor()->DisconnectEvent( wxEVT_CHANGED_DOCUMENT, this );
114  a2dDocviewGlobals->GetDocviewCommandProcessor()->DisconnectEvent( a2dEVT_COM_EVENT, this );
115 }
116 
118 {
119  if ( !layersetup )
120  return;
121 
122  m_layersetup = layersetup;
123 
124  m_listbox->Clear();
125 
126  int j;
127  for ( j = 0; j < wxMAXLAYER; j++ )
128  {
129  a2dLayerInfo* layerinfo = m_layersetup->GetOrderIndex()[ j ];
130  if ( layerinfo != wxNullLayerInfo )
131  {
132  wxChar _buf[60];
133  // insert the layer in the listbox
134  wxSnprintf( _buf, sizeof( _buf ), wxT( "%04d %s" ), j, layerinfo->GetName().c_str() );
135  m_listbox->Append( _buf ); //AddString(buf);
136  }
137  else
138  {
139  wxChar _buf[60];
140  // insert the layer in the listbox
141  wxSnprintf( _buf, sizeof( _buf ), wxT( "%04d ND %s" ), j, layerinfo->GetName().c_str() );
142  m_listbox->Append( _buf ); //AddString(buf);
143  }
144 
145  }
146 }
147 
148 void a2dLayerOrderDialog::OnActivateView( a2dViewEvent& viewevent )
149 {
150  a2dCanvasView* view = wxDynamicCast( viewevent.GetEventObject(), a2dCanvasView );
151  if ( view && view->GetDrawingPart()->GetShowObject() && view->GetDrawingPart()->GetShowObject()->GetRoot() )
152  {
153  view->GetDrawingPart()->GetShowObject()->GetRoot()->SetAvailable();
154  Init( view->GetDrawingPart()->GetShowObject()->GetRoot()->GetLayerSetup() );
155  }
156 }
157 
158 void a2dLayerOrderDialog::OnChangedDocument( a2dCommandEvent& event )
159 {
160 /*
161  a2dCanvasDocument* doc = ( a2dCanvasDocument* ) event.GetDocument();
162  if ( doc && doc->GetLayerSetup() != m_layersetup )
163  {
164  doc->GetLayerSetup()->SetAvailable( doc );
165  Init( doc->GetLayerSetup() );
166  }
167 */
168 }
169 
171 {
172  wxString layernr;
173  for ( int i = 0; i < wxMAXLAYER; i++ )
174  {
175  layernr = m_listbox->GetString( i ).Left( 4 );
176  a2dLayerInfo* layerinfo = m_layersetup->GetLayerIndex()[ wxAtoi( layernr ) ];
177  if ( layerinfo != wxNullLayerInfo )
178  {
179  layerinfo->SetOrder( i * 10 );
180  }
181  }
182  m_layersetup->SetPending( true );
183 
184  SetEvtHandlerEnabled( false );
185  a2dComEvent changedlayers( m_layersetup->GetRoot(), m_layersetup, a2dCanvasDocument::sig_layersetupChanged );
186  ProcessEvent( changedlayers );
187  SetEvtHandlerEnabled( true );
188 }
189 
190 void a2dLayerOrderDialog::CmOk( wxCommandEvent& )
191 {
192  int selection = m_listbox->GetSelection();
193  m_listbox->SetSelection( selection, FALSE );
194 
195  StoreOrder();
196  Show( FALSE );
197 }
198 
199 void a2dLayerOrderDialog::CmShow( wxCommandEvent& )
200 {
201  int selection = m_listbox->GetSelection();
202  m_listbox->SetSelection( selection, FALSE );
203 
204  StoreOrder();
205 }
206 
207 void a2dLayerOrderDialog::OnCloseWindow( wxCloseEvent& event )
208 {
209  wxCommandEvent a = wxCommandEvent();
210  CmCancel( a );
211 }
212 
213 void a2dLayerOrderDialog::CmCancel( wxCommandEvent& )
214 {
215  Show( FALSE );
216 
217  m_listbox->Clear();
218 
219  // old values reread
220  //Init();
221 }
222 
223 void a2dLayerOrderDialog::CmUp( wxCommandEvent& )
224 {
225  int selection = m_listbox->GetSelection();
226  if ( selection == -1 )
227  ( void )wxMessageBox( _T( "You must select a layer first" ), _T( "a2dLayerOrderDialog" ), wxICON_INFORMATION | wxOK );
228  else
229  {
230  if ( selection != 0 )
231  {
232  if ( selection == wxMAXLAYER - 1 ) m_buttonDOWN->Enable( TRUE );
233 
234  wxString selected = m_listbox->GetString( m_listbox->GetSelection() - 1 );
235 
236  m_listbox->SetString( selection - 1, m_listbox->GetString( selection ) );
237  m_listbox->SetString( selection, selected );
238  m_listbox->Show( TRUE );
239 
240  // to keep the original selection selected
241  m_listbox->SetSelection( selection, FALSE );
242  m_listbox->SetSelection( selection - 1, TRUE );
243  if ( selection == 1 )
244  m_buttonUP->Enable( FALSE );
245  }
246  else
247  {
248  ( void )wxMessageBox( _T( "layer is allready at the highest possible order" ), _T( "a2dLayerOrderDialog" ), wxICON_INFORMATION | wxOK );
249  }
250  }
251 }
252 
253 void a2dLayerOrderDialog::CmDown( wxCommandEvent& )
254 {
255  int selection = m_listbox->GetSelection();
256 
257  if ( selection == -1 )
258  ( void )wxMessageBox( _T( "You must select a layer first" ), _T( "a2dLayerOrderDialog" ), wxICON_INFORMATION | wxOK );
259  else
260  {
261  if ( selection != wxMAXLAYER - 1 )
262  {
263  if ( selection == 0 ) m_buttonUP->Enable( TRUE );
264 
265  wxString selected = m_listbox->GetString( m_listbox->GetSelection() + 1 );
266 
267  m_listbox->SetString( selection + 1, m_listbox->GetString( selection ) );
268  m_listbox->SetString( selection, selected );
269  m_listbox->Show( TRUE );
270 
271  // to keep the original selection selected
272  m_listbox->SetSelection( selection, FALSE );
273  m_listbox->SetSelection( selection + 1, TRUE );
274 
275  if ( selection == wxMAXLAYER - 2 ) m_buttonDOWN->Enable( FALSE );
276  }
277  else
278  {
279  ( void )wxMessageBox( _T( "layer is allready at the lowest possible order" ), _T( "a2dLayerOrderDialog" ), wxICON_INFORMATION | wxOK );
280  }
281  }
282 }
283 
284 void a2dLayerOrderDialog::CmListBox( wxCommandEvent& )
285 {
286  int selection = m_listbox->GetSelection();
287  m_buttonUP->Enable( selection != 0 );
288  m_buttonDOWN->Enable( selection != wxMAXLAYER - 1 );
289 
290  a2dCanvasGlobals->GetHabitat()->SetLayer( selection, true );
291 }
292 
293 void a2dLayerOrderDialog::OnComEvent( a2dComEvent& event )
294 {
295  if ( GetEvtHandlerEnabled() )
296  {
297  if ( event.GetId() == a2dDrawingPart::sig_changedLayers )
298  {
299  a2dDrawing* doc = wxDynamicCast( event.GetEventObject(), a2dDrawing );
300  if ( doc && doc == m_layersetup->GetRoot() )
301  Init( doc->GetLayerSetup() );
302  }
303  else if ( event.GetId() == a2dDrawing::sig_layersetupChanged )
304  {
305  a2dDrawing* doc = wxDynamicCast( event.GetEventObject(), a2dDrawing );
306  if ( doc && doc == m_layersetup->GetRoot() )
307  Init( doc->GetLayerSetup() );
308  }
309  else if ( event.GetId() == a2dLayerInfo::sig_changedLayerInfo )
310  {
311  a2dDrawing* obj = wxDynamicCast( event.GetEventObject(), a2dDrawing );
312  if ( m_layersetup->GetRoot() == obj->GetRootObject()->GetRoot() )
313  Init( m_layersetup );
314  }
315 
316  }
317 }
318 
#define wxDynamicCast(obj, className)
Define wxDynamicCast so that it will give a compiler error for unrelated types.
Definition: gen.h:75
#define EVT_CHANGED_DOCUMENT(func)
event sent to a2dDocumentCommandProcessor when the current document has changed in the a2dDocumentCom...
Definition: doccom.h:179
void SetLayer(wxUint16 layer, bool setStyleOfLayer=false)
Definition: canglob.cpp:1076
#define EVT_ACTIVATE_VIEW(func)
event sent to view and document manager
Definition: docviewref.h:999
View on a a2dCanvasDocument.
Definition: candoc.h:212
a2dCanvasObject * GetRootObject() const
get the root object, which holds the objects in the document
Definition: drawing.h:521
void CmUp(wxCommandEvent &)
Move selected layer to a heigher layersetting if UP-button is pressed.
Definition: orderdlg.cpp:223
a2dDrawing * GetRoot() const
get a2dCanvasDocument of the object.
Definition: canobj.h:952
void ConnectEvent(wxEventType type, wxEvtHandler *eventSink)
Definition: gen.cpp:876
see a2dCommandEvent
Definition: doccom.h:79
a2dView event, to report events in the a2dView class
Definition: docviewref.h:424
std::vector< a2dLayerInfoPtr > & GetLayerIndex()
return array index on Layer
Definition: layerinf.cpp:555
void CmOk(wxCommandEvent &)
Close window if OK-button is pressed.
Definition: orderdlg.cpp:190
void CmListBox(wxCommandEvent &)
Definition: orderdlg.cpp:284
a2dLayers * GetLayerSetup()
Get the layersettings for the canvas.
Definition: drawing.h:506
static const a2dSignal sig_layersetupChanged
layer info changed id sent around when m_layersetup is changed.
Definition: drawing.h:771
void StoreOrder()
store current order to layer setup
Definition: orderdlg.cpp:170
void OnCloseWindow(wxCloseEvent &event)
Close window if EXIT-button is pressed.
Definition: orderdlg.cpp:207
void CmDown(wxCommandEvent &)
Move selected layer to a lower layersetting if the DOWN-button is pressed.
Definition: orderdlg.cpp:253
static const a2dSignal sig_layersetupChanged
layer info changed id sent around when m_layersetup is changed.
Definition: candoc.h:757
virtual wxString GetName() const
Get name for layer.
Definition: layerinf.cpp:248
layer settings for a a2dCanvasDocument Holds layers settings classes
void CmShow(wxCommandEvent &)
Show new layerorder if the SHOW-button is pressed.
Definition: orderdlg.cpp:199
GUI listbox with copy feature.
Definition: canorderdlg.h:29
void SetPending(bool pending)
next to base sets m_indexed false
Definition: layerinf.cpp:545
a2dCanvasObject * GetShowObject() const
return pointer of then currently shown object on the drawer.
Definition: drawer.h:680
static const a2dSignal sig_changedLayerInfo
when one layer its a2dLayerInfo has changed ( e.g. visible or order of rendering ) ...
Definition: layerinf.h:322
contains the layer properties for one layer,
Definition: layerinf.h:41
holds the central a2dCentralCanvasCommandProcessor which is
static const a2dSignal sig_changedLayers
when more layers changed ( rerendering view is needed).
Definition: drawer.h:1505
void CmCancel(wxCommandEvent &)
Close window if CANCEL-button is pressed.
Definition: orderdlg.cpp:213
a2dDocviewGlobal * a2dDocviewGlobals
a global pointer to get to global instance of important classes.
Definition: doccom.cpp:2348
void Init(a2dLayers *layersetup)
initialize with this layer setup
Definition: orderdlg.cpp:117
void SetOrder(wxUint16 order)
set drawing order for layer
Definition: layerinf.cpp:371
Definition of class for dialog to specify the layerorder.
see a2dComEvent
Definition: gen.h:371
a2dDocumentCommandProcessor * GetDocviewCommandProcessor() const
Gets a2dDocumentCommandProcessor pointer.
Definition: doccom.h:1034
std::vector< a2dLayerInfoPtr > & GetOrderIndex()
return array index on Order
Definition: layerinf.cpp:562
a2dCanvasGlobal * a2dCanvasGlobals
global a2dCanvasGlobal to have easy access to global settings
Definition: canglob.cpp:1234
all headers of the canvas module
bool DisconnectEvent(wxEventType type, wxEvtHandler *eventSink)
Definition: gen.cpp:902
~a2dLayerOrderDialog()
destructor.
Definition: orderdlg.cpp:110
Contain one drawing as hierarchical tree of a2dCanvasObject&#39;s.
Definition: drawing.h:434
orderdlg.cpp Source File -- Sun Oct 12 2014 17:04:22 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation