wxArt2D
execdlg.cpp
Go to the documentation of this file.
1 /*! \file canvas/src/execdlg.cpp
2  \brief Document/view classes
3  \author Klaas Holwerda
4  \date Created 05/07/2003
5 
6  Copyright: 2001-2004 (C) Klaas Holwerda
7 
8  Licence: wxWidgets licence
9 
10  RCS-ID: $Id: execdlg.cpp,v 1.26 2009/09/26 19:01:06 titato Exp $
11 */
12 
13 #include "a2dprec.h"
14 
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18 
19 #ifndef WX_PRECOMP
20 #include "wx/wx.h"
21 #endif
22 
23 #include <wx/clipbrd.h>
24 
25 #include "wx/canvas/execdlg.h"
26 
27 const int CP_SEL = wxID_HIGHEST + 8801 ;
28 const int CP_ALL = wxID_HIGHEST + 8802 ;
29 
30 BEGIN_EVENT_TABLE( CopywxListBox, wxListBox )
31  EVT_RIGHT_DOWN( CopywxListBox::OnMouseRightDown )
32  EVT_MENU( CP_SEL, CopywxListBox::CopySel )
33  EVT_MENU( CP_ALL, CopywxListBox::CopyAll )
34 END_EVENT_TABLE()
35 
36 CopywxListBox::CopywxListBox( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
37  int n, const wxString choices[], long style )
38  : wxListBox ( parent, id, pos, size, n, choices, style )
39 {
40  // make a popupmenu for the right mousebutton
41  m_mousemenu = new wxMenu( _T( "Copy" ) , ( long )0 );
42  m_mousemenu->Append( CP_SEL, _T( "selected" ) );
43  m_mousemenu->Append( CP_ALL, _T( "all" ) );
44 }
45 
46 void CopywxListBox::CopySel( class wxCommandEvent& WXUNUSED( event ) )
47 {
48  if ( wxTheClipboard->Open() )
49  {
50  wxString data;
51  data = data + GetStringSelection() + _T( "\n" );
52  wxTheClipboard->SetData( new wxTextDataObject( data ) );
53  wxTheClipboard->Close();
54  }
55 }
56 
57 void CopywxListBox::CopyAll( class wxCommandEvent& WXUNUSED( event ) )
58 {
59  if ( wxTheClipboard->Open() )
60  {
61  wxString data;
62  int i;
63  for ( i = 0; i < GetCount(); i++ )
64  {
65  data = data + GetString( i ) + _T( "\n" );
66  }
67  wxTheClipboard->SetData( new wxTextDataObject( data ) );
68  wxTheClipboard->Close();
69  }
70 }
71 
72 void CopywxListBox::OnMouseRightDown( class wxMouseEvent& WXUNUSED( event ) )
73 {
74  PopupMenu( m_mousemenu, 0, 0 );
75 }
76 
77 
78 
79 /*!
80  * a2dCoordinateEntry type definition
81  */
82 
83 IMPLEMENT_DYNAMIC_CLASS( a2dCoordinateEntry, wxDialog )
84 
85 /*!
86  * a2dCoordinateEntry event table definition
87  */
88 
89 BEGIN_EVENT_TABLE( a2dCoordinateEntry, wxDialog )
90 
91  EVT_TEXT( IDentry_X, a2dCoordinateEntry::OnEntryXEnter )
92  EVT_TEXT( IDentry_Y, a2dCoordinateEntry::OnEntryYEnter )
93 
94  EVT_TEXT_ENTER( IDentry_X, a2dCoordinateEntry::OnEntryXEnter )
95 
96  EVT_TEXT_ENTER( IDentry_Y, a2dCoordinateEntry::OnEntryYEnter )
97 
98  EVT_TEXT_ENTER( IDentry_CalcCoord, a2dCoordinateEntry::OnEntryCalccoordEnter )
99 
100  EVT_RADIOBOX( IDentry_CartPolar, a2dCoordinateEntry::OnEntryCartpolarSelected )
101 
102  EVT_RADIOBOX( IDentry_AbsRel, a2dCoordinateEntry::OnEntryAbsrelSelected )
103 
104  EVT_CHECKBOX( IDentry_Snap, a2dCoordinateEntry::OnEntrySnapClick )
105 
106  EVT_BUTTON( IDentry_Hide, a2dCoordinateEntry::OnEntryHideClick )
107 
108  EVT_BUTTON( IDentry_Apply, a2dCoordinateEntry::OnEntryApplyClick )
109 
110  EVT_BUTTON( IDentry_Cancel, a2dCoordinateEntry::OnEntryCancelClick )
111 
112 END_EVENT_TABLE()
113 
114 /*!
115  * a2dCoordinateEntry constructors
116  */
117 
118 a2dCoordinateEntry::a2dCoordinateEntry( )
119 {
120 }
121 
122 a2dCoordinateEntry::a2dCoordinateEntry( wxWindow* parent, wxWindowID id, bool modal, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
123 {
124  m_modal = modal;
125  Create( parent, id, caption, pos, size, style );
126 }
127 
128 /*!
129  * a2dCoordinateEntry creator
130  */
131 
132 bool a2dCoordinateEntry::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
133 {
134  m_x = NULL;
135  m_y = NULL;
136  m_calcCoord = NULL;
137  m_cartPolar = NULL;
138  m_absRel = NULL;
139  m_snap = NULL;
140  m_hide = NULL;
141  m_apply = NULL;
142  m_cancel = NULL;
143 
144  SetExtraStyle( GetExtraStyle() | wxWS_EX_BLOCK_EVENTS );
145  wxDialog::Create( parent, id, caption, pos, size, style );
146 
147  CreateControls( style );
148  GetSizer()->Fit( this );
149  GetSizer()->SetSizeHints( this );
150  Centre();
151  return TRUE;
152 }
153 
154 /*!
155  * Control creation for a2dCoordinateEntry
156  */
157 
159 {
160  a2dCoordinateEntry* itemDialog1 = this;
161 
162  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer( wxVERTICAL );
163  itemDialog1->SetSizer( itemBoxSizer2 );
164 
165  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer( wxHORIZONTAL );
166  itemBoxSizer2->Add( itemBoxSizer3, 0, wxGROW | wxALL, 1 );
167 
168  wxStaticBox* itemStaticBoxSizer4Static = new wxStaticBox( itemDialog1, wxID_ANY, _( "Coordinates" ) );
169  wxStaticBoxSizer* itemStaticBoxSizer4 = new wxStaticBoxSizer( itemStaticBoxSizer4Static, wxVERTICAL );
170  itemBoxSizer3->Add( itemStaticBoxSizer4, 1, wxGROW | wxALL, 0 );
171 
172  wxBoxSizer* itemBoxSizer5 = new wxBoxSizer( wxHORIZONTAL );
173  itemStaticBoxSizer4->Add( itemBoxSizer5, 0, wxGROW | wxALL, 5 );
174 
175  m_xText = new wxStaticText( itemDialog1, wxID_STATIC, _( "X" ), wxDefaultPosition, wxDefaultSize, 0 );
176  itemBoxSizer5->Add( m_xText, 0, wxALL/* wxWidgets 2.9 deprecated version |wxADJUST_MINISIZE*/, 5 );
177 
178  m_x = new wxTextCtrl( itemDialog1, IDentry_X, _T( "" ), wxDefaultPosition, wxDefaultSize, 0 );
179  itemBoxSizer5->Add( m_x, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
180 
181  m_yText = new wxStaticText( itemDialog1, wxID_STATIC, _( "Y" ), wxDefaultPosition, wxDefaultSize, 0 );
182  itemBoxSizer5->Add( m_yText, 0, wxALIGN_CENTER_VERTICAL | wxALL/* wxWidgets 2.9 deprecated version |wxADJUST_MINISIZE*/, 5 );
183 
184  m_y = new wxTextCtrl( itemDialog1, IDentry_Y, _T( "" ), wxDefaultPosition, wxDefaultSize, 0 );
185  itemBoxSizer5->Add( m_y, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
186 
187  wxBoxSizer* itemBoxSizer10 = new wxBoxSizer( wxHORIZONTAL );
188  itemStaticBoxSizer4->Add( itemBoxSizer10, 0, wxGROW | wxALL, 5 );
189 
190  wxStaticText* itemStaticText11 = new wxStaticText( itemDialog1, wxID_STATIC, _( "Calc Coord" ), wxDefaultPosition, wxDefaultSize, 0 );
191  itemBoxSizer10->Add( itemStaticText11, 0, wxALIGN_CENTER_VERTICAL | wxALL/* wxWidgets 2.9 deprecated version |wxADJUST_MINISIZE*/, 5 );
192 
193  m_calcCoord = new wxTextCtrl( itemDialog1, IDentry_CalcCoord, _T( "" ), wxDefaultPosition, wxDefaultSize, 0 );
194  itemBoxSizer10->Add( m_calcCoord, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
195 
196  wxBoxSizer* itemBoxSizer13 = new wxBoxSizer( wxVERTICAL );
197  itemBoxSizer3->Add( itemBoxSizer13, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
198 
199  wxString m_cartPolarStrings[] =
200  {
201  _( "&Cart" ),
202  _( "&Polar" )
203  };
204  m_cartPolar = new wxRadioBox( itemDialog1, IDentry_CartPolar, _( "Cart-Polar" ), wxDefaultPosition, wxDefaultSize, 2, m_cartPolarStrings, 1, wxRA_SPECIFY_ROWS );
205  itemBoxSizer13->Add( m_cartPolar, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1 );
206 
207  wxString m_absRelStrings[] =
208  {
209  _( "&Abs" ),
210  _( "&Rel" )
211  };
212  m_absRel = new wxRadioBox( itemDialog1, IDentry_AbsRel, _( "Abs-Rel" ), wxDefaultPosition, wxDefaultSize, 2, m_absRelStrings, 1, wxRA_SPECIFY_ROWS );
213  itemBoxSizer13->Add( m_absRel, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1 );
214 
215  m_snap = new wxCheckBox( itemDialog1, IDentry_Snap, _( "Use Snapping" ), wxDefaultPosition, wxDefaultSize, 0 );
216  m_snap->SetValue( FALSE );
217  itemBoxSizer13->Add( m_snap, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0 );
218 
219  wxBoxSizer* itemBoxSizer17 = new wxBoxSizer( wxHORIZONTAL );
220  itemBoxSizer2->Add( itemBoxSizer17, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0 );
221 
222  if ( m_modal )
223  {
224  m_apply = new wxButton( itemDialog1, IDentry_Apply, _( "Oke" ), wxDefaultPosition, wxDefaultSize, 0 );
225  }
226  else
227  {
228  m_hide = new wxButton( itemDialog1, IDentry_Hide, _( "Hide" ), wxDefaultPosition, wxDefaultSize, 0 );
229  itemBoxSizer17->Add( m_hide, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0 );
230 
231  m_apply = new wxButton( itemDialog1, IDentry_Apply, _( "Apply" ), wxDefaultPosition, wxDefaultSize, 0 );
232  }
233  itemBoxSizer17->Add( m_apply, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0 );
234 
235  m_cancel = new wxButton( itemDialog1, IDentry_Cancel, _( "Cancel" ), wxDefaultPosition, wxDefaultSize, 0 );
236  itemBoxSizer17->Add( m_cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0 );
237 
238 }
239 
240 /*!
241  * Should we show tooltips?
242  */
243 
245 {
246  return TRUE;
247 }
248 
249 /*!
250  * Get bitmap resources
251  */
252 
253 wxBitmap a2dCoordinateEntry::GetBitmapResource( const wxString& name )
254 {
255  // Bitmap retrieval
256  return wxNullBitmap;
257 }
258 
259 /*!
260  * Get icon resources
261  */
262 
263 wxIcon a2dCoordinateEntry::GetIconResource( const wxString& name )
264 {
265  // Icon retrieval
266  return wxNullIcon;
267 }
268 
269 /*!
270  * wxEVT_COMMAND_TEXT_ENTER event handler for IDentry_TEXTCTRL
271  */
272 
273 void a2dCoordinateEntry::OnEntryXEnter( wxCommandEvent& event )
274 {
275  // Before editing this code, remove the block markers.
276  CalcCoordinate();
277 }
278 
279 /*!
280  * wxEVT_COMMAND_TEXT_ENTER event handler for IDentry_TEXTCTRL1
281  */
282 
283 void a2dCoordinateEntry::OnEntryYEnter( wxCommandEvent& event )
284 {
285  CalcCoordinate();
286 }
287 
288 /*!
289  * wxEVT_COMMAND_TEXT_ENTER event handler for IDentry_TEXTCTRL2
290  */
291 
292 void a2dCoordinateEntry::OnEntryCalccoordEnter( wxCommandEvent& event )
293 {
294  CalcCoordinate();
295 }
296 
297 /*!
298  * wxEVT_COMMAND_RADIOBOX_SELECTED event handler for IDentry_RADIOBOX
299  */
300 
301 void a2dCoordinateEntry::OnEntryCartpolarSelected( wxCommandEvent& event )
302 {
303  if ( m_cartPolar->GetSelection() == 0 )
304  {
305  m_xText->SetLabel( _T( "X" ) );
306  m_yText->SetLabel( _T( "Y" ) );
307  }
308  else
309  {
310  m_xText->SetLabel( _T( "Ang" ) );
311  m_yText->SetLabel( _T( "Radius" ) );
312  }
313  GetSizer()->Fit( this );
314  CalcCoordinate();
315 }
316 
317 /*!
318  * wxEVT_COMMAND_RADIOBOX_SELECTED event handler for IDentry_RADIOBOX1
319  */
320 
321 void a2dCoordinateEntry::OnEntryAbsrelSelected( wxCommandEvent& event )
322 {
323  CalcCoordinate();
324 }
325 
326 /*!
327  * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for IDentry_CHECKBOX
328  */
329 
330 void a2dCoordinateEntry::OnEntrySnapClick( wxCommandEvent& event )
331 {
332  CalcCoordinate();
333 }
334 
335 /*!
336  * wxEVT_COMMAND_BUTTON_CLICKED event handler for IDentry_BUTTON
337  */
338 
339 void a2dCoordinateEntry::OnEntryHideClick( wxCommandEvent& event )
340 {
341  SetReturnCode( wxID_OK );
342  Show( false );
343 }
344 
345 /*!
346  * wxEVT_COMMAND_BUTTON_CLICKED event handler for IDentry_BUTTON1
347  */
348 
349 void a2dCoordinateEntry::OnEntryApplyClick( wxCommandEvent& event )
350 {
351  if ( m_modal )
352  {
353  CalcCoordinate();
354  EndModal( wxID_OK );
355  }
356  else
357  {
358  CalcCoordinate();
359  bool polar = m_cartPolar->GetSelection() == 1;
360  bool relative = m_absRel->GetSelection() == 1;
361 
364  x( m_xcalc ).
365  y( m_ycalc ).
366  relative( relative ).
367  polar( polar ).
368  snapped( m_snap->GetValue() ) );
369 
371  if ( !drawingPart )
372  return;
373 
374  drawingPart->GetDrawing()->GetCommandProcessor()->Submit( command );
375  }
376 }
377 
378 /*!
379  * wxEVT_COMMAND_BUTTON_CLICKED event handler for IDentry_BUTTON2
380  */
381 
382 void a2dCoordinateEntry::OnEntryCancelClick( wxCommandEvent& event )
383 {
384  Show( false );
385 }
386 
388 {
389  m_xcalc = wxAtoi( m_x->GetValue() );
390  m_ycalc = wxAtoi( m_y->GetValue() );
391  bool polar = m_cartPolar->GetSelection() == 1;
392  bool relative = m_absRel->GetSelection() == 1;
393 
394  //get current position
395  double xold = a2dCanvasGlobals->GetHabitat()->GetLastXEntry();
396  double yold = a2dCanvasGlobals->GetHabitat()->GetLastYEntry();
397 
398  //get current position
399  if ( relative )
400  {
401  if ( polar )
402  {
403  double radius = m_ycalc;
404  double ang = m_xcalc;
405 
406  m_xcalc = xold + radius * cos( wxDegToRad( ang ) );
407  m_ycalc = yold + radius * sin( wxDegToRad( ang ) );
408  }
409  else
410  {
411  m_xcalc += xold;
412  m_ycalc += yold;
413  }
414  }
415  else
416  {
417  if ( polar )
418  {
419  double radius = m_ycalc;
420  double ang = m_xcalc;
421 
422  m_xcalc = radius * cos( wxDegToRad( ang ) );
423  m_ycalc = radius * sin( wxDegToRad( ang ) );
424  }
425  }
426 
427  wxString calc;
428  calc.Printf( wxT( " x = %lg, y = %lg" ), m_xcalc, m_ycalc );
429  m_calcCoord->SetValue( calc );
430 }
431 
432 
433 
434 
Display Part of a a2dDrawing, in which a2dCanvasObjects are shown.
Definition: drawer.h:470
set cursor
Definition: drawing.h:4227
void OnEntryCartpolarSelected(wxCommandEvent &event)
wxEVT_COMMAND_RADIOBOX_SELECTED event handler for IDentry_CartPolar
Definition: execdlg.cpp:301
double wxDegToRad(double deg)
conversion from degrees to radians
Definition: artglob.cpp:30
bool Create(wxWindow *parent, wxWindowID id=SYMBOL_A2DCOORDINATEENTRY_IDNAME, const wxString &caption=SYMBOL_A2DCOORDINATEENTRY_TITLE, const wxPoint &pos=SYMBOL_A2DCOORDINATEENTRY_POSITION, const wxSize &size=SYMBOL_A2DCOORDINATEENTRY_SIZE, long style=SYMBOL_A2DCOORDINATEENTRY_STYLE)
Creation.
Definition: execdlg.cpp:132
void OnEntryCancelClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for IDentry_Cancel
Definition: execdlg.cpp:382
a2dCoordinateEntry()
Constructors.
Definition: execdlg.cpp:118
a2dDrawingPart * GetActiveDrawingPart()
return the currently/last active drawing part.
Definition: canglob.h:1262
void OnEntrySnapClick(wxCommandEvent &event)
wxEVT_COMMAND_CHECKBOX_CLICKED event handler for IDentry_Snap
Definition: execdlg.cpp:330
void OnEntryApplyClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for IDentry_Apply
Definition: execdlg.cpp:349
void OnEntryHideClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for IDentry_Hide
Definition: execdlg.cpp:339
double GetLastYEntry() const
holds last mouse Y position in world coordinates, as set by tools.
Definition: canglob.h:779
void OnEntryYEnter(wxCommandEvent &event)
wxEVT_COMMAND_TEXT_ENTER event handler for IDentry_Y
Definition: execdlg.cpp:283
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
Definition: execdlg.cpp:253
double GetLastXEntry() const
holds last mouse X position in world coordinates, as set by tools.
Definition: canglob.h:777
void OnEntryXEnter(wxCommandEvent &event)
wxEVT_COMMAND_TEXT_ENTER event handler for IDentry_X
Definition: execdlg.cpp:273
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
Definition: execdlg.cpp:263
static bool ShowToolTips()
Should we show tooltips?
Definition: execdlg.cpp:244
virtual bool Submit(a2dCommand *command, bool storeIt=true)
next to the base class submit, it sets a2DocumentCommandProcessor for a2dCommand
Definition: comevt.cpp:842
a2dCommandProcessor * GetCommandProcessor() const
Returns a pointer to the command processor associated with this document.
Definition: drawing.h:549
void OnEntryCalccoordEnter(wxCommandEvent &event)
wxEVT_COMMAND_TEXT_ENTER event handler for IDentry_CalcCoord
Definition: execdlg.cpp:292
void CalcCoordinate()
based on the current setting calculate the cursor position
Definition: execdlg.cpp:387
a2dDrawing * GetDrawing() const
get drawing via top object
Definition: drawer.cpp:726
a2dCanvasGlobal * a2dCanvasGlobals
global a2dCanvasGlobal to have easy access to global settings
Definition: canglob.cpp:1234
void OnEntryAbsrelSelected(wxCommandEvent &event)
wxEVT_COMMAND_RADIOBOX_SELECTED event handler for IDentry_AbsRel
Definition: execdlg.cpp:321
void CreateControls(long style)
Creates the controls and sizers.
Definition: execdlg.cpp:158
GUI listbox with copy feature.
Definition: execdlg.h:19
A pointer class, that automatically calls SmrtPtrOwn/SmrtPtrRelease.
Definition: a2dlist.h:20
execdlg.cpp Source File -- Sun Oct 12 2014 17:04:19 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation