wxArt2D
tooldlg.cpp
1 /*! \file editor/src/tooldlg.cpp
2  \author Klaas Holwerda
3 
4  Copyright: 2000-2004 (c) Klaas Holwerda
5 
6  Licence: wxWidgets Licence
7 
8  RCS-ID: $Id: tooldlg.cpp,v 1.37 2009/10/05 20:03:12 titato Exp $
9 */
10 
11 #include "a2dprec.h"
12 
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16 
17 #ifndef WX_PRECOMP
18 #include "wx/wx.h"
19 #endif
20 
21 #include "wx/canvas/tooldlg.h"
22 
23 BEGIN_EVENT_TABLE( ToolDlg, wxMiniFrame )
24 
25  EVT_CLOSE( ToolDlg::OnCloseWindow )
26 
27 END_EVENT_TABLE()
28 
29 
30 wxBitmap* GetBitmap( const wxString& name )
31 {
32  wxImage image( 32, 32 );
33  bool loaded = false;
34  wxString file;
35  do
36  {
37 #if wxUSE_LIBPNG
38  file = a2dGlobals->GetIconPathList().FindValidPath( name + _T( ".png" ), false );
39  if ( !file.IsEmpty() && image.LoadFile( file , wxBITMAP_TYPE_PNG ) )
40  {
41  loaded = true;
42  break;
43  }
44 #endif
45  file = a2dGlobals->GetIconPathList().FindValidPath( name + _T( ".ico" ), false );
46  if ( !file.IsEmpty() && image.LoadFile( file ) )
47  {
48  loaded = true;
49  break;
50  }
51  file = a2dGlobals->GetIconPathList().FindValidPath( name + _T( ".bmp" ), false );
52  if ( !file.IsEmpty() && image.LoadFile( file , wxBITMAP_TYPE_BMP ) )
53  {
54  loaded = true;
55  break;
56  }
57  }
58  while( false );
59 
60  if ( !loaded )
61  {
62  a2dGeneralGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _( "invalid bitmap %s" ), name.c_str() );
63  }
64  return new wxBitmap( image );
65 }
66 
67 ToolDlg::ToolDlg( wxFrame* parent ):
68  wxMiniFrame( parent, -1, _T( "Tools" ), wxDefaultPosition, wxDefaultSize, wxSTAY_ON_TOP | wxDEFAULT_DIALOG_STYLE | wxDIALOG_NO_PARENT )
69 {
70  //a2dDocviewGlobals->GetDocviewCommandProcessor()->ConnectEvent( wxEVT_ACTIVATE_VIEW, this );
71 
72  //m_sizer = new wxBoxSizer( wxHORIZONTAL );
73  //m_sizer = new wxBoxSizer( wxVERTICAL );
74  m_sizer = new wxGridSizer( 2 );
75 
76  m_panel = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize, 0, _T( "panel" ) );
77  m_panel->SetSizer( m_sizer );
78 
79  Populate();
80 
81  m_panel->SetAutoLayout( true );
82  m_sizer->SetSizeHints( this );
83  m_sizer->Fit( this );
84 
85  if ( parent )
86  {
87  // align on left side of parent if given
88  wxPoint pt = parent->GetPosition();
89  wxSize dim = GetSize();
90  Move( pt.x - dim.x, pt.y );
91  }
92  else
93  {
94  Centre( wxBOTH );
95  }
96 }
97 
99 {
100  //a2dDocviewGlobals->GetDocviewCommandProcessor()->DisconnectEvent( wxEVT_ACTIVATE_VIEW, this );
101 }
102 
103 void ToolDlg::Populate()
104 {
105  wxBitmap* toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_Zoom" ) );
106  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_Zoom() );
107  delete toolbitmap;
108 
109  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_DrawPolygonL" ) );
110  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_DrawPolygonL() );
111  delete toolbitmap;
112 
113  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_DrawPolygonL_Splined" ) );
114  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_DrawPolygonL_Splined() );
115  delete toolbitmap;
116 
117  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_DrawPolylineL" ) );
118  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_DrawPolylineL() );
119  delete toolbitmap;
120 
121  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_DrawPolylineL_Splined" ) );
122  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_DrawPolylineL_Splined() );
123  delete toolbitmap;
124 
125  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_DrawRectangle" ) );
126  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_DrawRectangle() );
127  delete toolbitmap;
128 
129  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_DrawCircle" ) );
130  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_DrawCircle() );
131  delete toolbitmap;
132 
133  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_DrawEllipse" ) );
134  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_DrawEllipse() );
135  delete toolbitmap;
136 
137  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_DrawEllipticArc" ) );
138  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_DrawEllipticArc() );
139  delete toolbitmap;
140 
141  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_DrawEllipticArc_Chord" ) );
142  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_DrawEllipticArc_Chord() );
143  delete toolbitmap;
144 
145  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_DrawArc" ) );
146  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_DrawArc() );
147  delete toolbitmap;
148 
149  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_DrawArc_Chord" ) );
150  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_DrawArc_Chord() );
151  delete toolbitmap;
152 
153  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_DrawText" ) );
154  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_DrawText() );
155  delete toolbitmap;
156 
157  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_Image" ) );
158  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_Image() );
159  delete toolbitmap;
160 
161  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_Rotate" ) );
162  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_Rotate() );
163  delete toolbitmap;
164 
165  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_Drag" ) );
166  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_Drag() );
167  delete toolbitmap;
168 
169  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_Copy" ) );
170  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_Copy() );
171  delete toolbitmap;
172 
173  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_Delete" ) );
174  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_Delete() );
175  delete toolbitmap;
176 
177  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_RecursiveEdit" ) );
178  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_RecursiveEdit() );
179  delete toolbitmap;
180 
181  toolbitmap = GetBitmap( _T( "CmdMenu_PushTool_Select" ) );
182  AddCmdMenu( *toolbitmap, CmdMenu_PushTool_Select() );
183  delete toolbitmap;
184 }
185 
187 {
188  Disconnect( cmdId.GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( ToolDlg::OnCmdMenuId ) );
189  //!todo
190 }
191 
192 void ToolDlg::AddCmdMenu( wxBitmap& bitmap, const a2dMenuIdItem& cmdId )
193 {
194  Connect( cmdId.GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( ToolDlg::OnCmdMenuId ) );
195  wxBitmapButton* tool = new wxBitmapButton( m_panel, cmdId.GetId(), bitmap );
196  tool->SetToolTip( cmdId.GetHelp() );
197  m_sizer->Add( tool, 0, wxALL, 1 );
198 }
199 
200 void ToolDlg::OnCmdMenuId( wxCommandEvent& event )
201 {
202  // translate into a menu event, to be handled by command handler classes
203  wxMenuEvent eventMenu( wxEVT_COMMAND_MENU_SELECTED, event.GetId() );
204 
206  if ( !drawingPart )
207  return;
208 
209  drawingPart->GetDrawing()->GetCommandProcessor()->ProcessEvent( eventMenu );
210  if ( drawingPart->GetDisplayWindow() && !drawingPart->GetDisplayWindow()->HasFocus() )
211  drawingPart->GetDisplayWindow()->SetFocus();
212 }
213 
214 void ToolDlg::OnCloseWindow( wxCloseEvent& WXUNUSED( event ) )
215 {
216  Show( false );
217 }
218 
Display Part of a a2dDrawing, in which a2dCanvasObjects are shown.
Definition: drawer.h:470
wxString FindValidPath(const wxString &filename, bool reportError=true)
Find the first full path for which the file exists.
Definition: gen.cpp:4486
store a menu Id generated by XRCID( menuIdString ) plus a menustring and helpstring ...
Definition: comevt.h:1563
const a2dError a2dError_FileCouldNotOpen
a2dGlobal * a2dGlobals
global a2dCanvasGlobal to have easy access to global settings
Definition: artglob.cpp:34
a2dPathList & GetIconPathList()
Path for Icons and small bitmaps.
Definition: artglob.h:155
void OnCmdMenuId(wxCommandEvent &event)
Definition: tooldlg.cpp:200
void AddCmdMenu(wxBitmap &bitmap, const a2dMenuIdItem &cmdId)
add a command menu to the parent menu, and connect it to the eventhandler of the dialog ...
Definition: tooldlg.cpp:192
a2dDrawingPart * GetActiveDrawingPart()
return the currently/last active drawing part.
Definition: canglob.h:1262
~ToolDlg()
Destructor.
Definition: tooldlg.cpp:98
ToolDlg(wxFrame *parent)
Constructor.
Definition: tooldlg.cpp:67
void RemoveCmdMenu(const a2dMenuIdItem &cmdId)
remove a command menu from the parent menu.
Definition: tooldlg.cpp:186
int GetId() const
get id
Definition: comevt.h:1583
A2DGENERALDLLEXP a2dSmrtPtr< a2dGeneralGlobal > a2dGeneralGlobals
a global pointer to get to global instance of important classes.
Definition: comevt.cpp:1148
GUI to choose a tool, and execute it via the command processor.
Definition: tooldlg.h:33
a2dCommandProcessor * GetCommandProcessor() const
Returns a pointer to the command processor associated with this document.
Definition: drawing.h:549
dialog for choosing a tool
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
tooldlg.cpp Source File -- Sun Oct 12 2014 17:04:26 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation