12 #include "docviewprec.h"
13 #include <wx/xml/xml.h>
27 #include "wx/xrc/xh_menu.h"
32 #include "wx/docview/xh_a2dmenu.h"
41 wxObject* a2dMenuXmlHandler::DoCreateResource()
43 if ( m_class == wxT(
"a2dMenu" ) || m_class == wxT(
"wxMenu" ) )
45 wxMenu* menu =
new wxMenu( GetStyle() );
46 wxString title = GetText( wxT(
"label" ) );
47 wxString help = GetText( wxT(
"help" ) );
49 bool oldins = m_insideA2DMenu;
50 m_insideA2DMenu =
true;
51 CreateChildren( menu,
true );
52 m_insideA2DMenu = oldins;
56 p_bar->Append( menu, title );
62 p_menu->Append( GetID(), title, menu, help );
63 if ( HasParam( wxT(
"enabled" ) ) )
64 p_menu->Enable( GetID(), GetBool( wxT(
"enabled" ) ) );
75 else if ( m_class == wxT(
"a2dMenuIdItem" ) )
80 wxString label = GetText( wxT(
"label" ) );
81 wxString accel = GetText( wxT(
"accel" ),
false );
82 wxString help = GetText( wxT(
"help" ) );
84 wxString a2dCmdIdName = GetName();
88 wxString error = _T(
"a2dMenuIdItem with id name: " ) + a2dCmdIdName + _T(
" not know" );
89 wxMessageBox( error, _(
"XRC problem" ), wxICON_INFORMATION | wxOK );
92 if ( label.IsEmpty() )
95 help = a2dmenu.GetHelp();
97 wxItemKind kind = a2dmenu.
GetKind();
99 wxString fullLabel = label;
100 if ( !accel.IsEmpty() )
101 fullLabel << wxT(
"\t" ) << accel;
103 id = a2dmenu.
GetId();
104 wxMenuItem* mitem =
new wxMenuItem( p_menu,
id, fullLabel, help, kind );
106 #if (!defined(__WXMSW__) && !defined(__WXPM__)) || wxUSE_OWNER_DRAWN
107 if ( HasParam( wxT(
"bitmap" ) ) )
108 mitem->SetBitmap( GetBitmap( wxT(
"bitmap" ), wxART_MENU ) );
110 if ( a2dMenuBarXmlHandler::m_parentFrame )
119 if ( mdiParentFrame )
123 mitem->Enable( GetBool( wxT(
"enabled" ),
true ) );
124 if ( kind == wxITEM_CHECK )
125 mitem->Check( GetBool( wxT(
"checked" ) ) );
130 return wxMenuXmlHandler::DoCreateResource();
133 bool a2dMenuXmlHandler::CanHandle( wxXmlNode* node )
135 return IsOfClass( node, wxT(
"a2dMenu" ) ) || IsOfClass( node, wxT(
"wxMenu" ) ) ||
137 ( IsOfClass( node, wxT(
"a2dMenuIdItem" ) ) ||
138 IsOfClass( node, wxT(
"wxMenuItem" ) ) ||
139 IsOfClass( node, wxT(
"break" ) ) ||
140 IsOfClass( node, wxT(
"separator" ) ) )
157 wxObject* a2dMenuBarXmlHandler::DoCreateResource()
159 wxFrame* curFrame = m_parentFrame;
160 wxMenuBar* menubar = NULL;
161 if( m_parentAsWindow )
166 m_parentFrame = parentFrame;
167 menubar = m_parentFrame->GetMenuBar();
168 CreateChildren( menubar );
174 menubar =
new wxMenuBar( GetStyle() );
175 CreateChildren( menubar );
176 if ( m_parentAsWindow && m_parentFrame )
178 m_parentFrame->SetMenuBar( menubar );
182 m_parentFrame = curFrame;
187 bool a2dMenuBarXmlHandler::CanHandle( wxXmlNode* node )
189 return IsOfClass( node, wxT(
"a2dMenuBar" ) ) || IsOfClass( node, wxT(
"wxMenuBar" ) );
198 #if wxUSE_XRC && wxUSE_TOOLBAR
200 #include "wx/xrc/xh_toolb.h"
203 #include "wx/frame.h"
204 #include "wx/toolbar.h"
210 : wxToolBarXmlHandler(), m_isInside( false ), m_toolbar( NULL )
214 wxObject* a2dToolBarXmlHandler::DoCreateResource()
216 if ( m_class == wxT(
"a2dToolCmd" ) )
218 wxCHECK_MSG( m_toolbar, NULL, wxT(
"Incorrect syntax of XRC resource: tool not within a toolbar!" ) );
221 wxString a2dCmdIdName = GetName();
225 wxString error = _T(
"a2dToolCmd with id name: " ) + a2dCmdIdName + _T(
" not know" );
226 wxMessageBox( error, _(
"XRC problem" ), wxICON_INFORMATION | wxOK );
230 id = a2dmenu.
GetId();
231 wxString label = GetText( wxT(
"label" ) );
232 wxString help = GetText( wxT(
"tooltip" ) );
233 wxBitmap selBitmap = GetBitmap( wxT(
"bitmap" ), wxART_TOOLBAR );
234 if ( ! selBitmap.Ok() )
235 selBitmap = a2dmenu.GetBitmap(
false );
237 wxString error = _T(
"No Bitmap for a2dToolCmd found for:" ) + a2dCmdIdName;
238 wxASSERT_MSG( selBitmap.Ok(), error );
240 if ( label.IsEmpty() )
242 if ( help.IsEmpty() )
243 help = a2dmenu.GetHelp();
246 if ( GetPosition() != wxDefaultPosition )
248 m_toolbar->InsertTool( GetPosition().x,
id, label,
250 GetBitmap( wxT(
"bitmap2" ), wxART_TOOLBAR ),
251 GetBool( wxT(
"toggle" ) ) ? wxITEM_CHECK : wxITEM_NORMAL,
253 GetText( wxT(
"longhelp" ) ) );
257 wxItemKind kind = wxITEM_NORMAL;
258 if ( GetBool( wxT(
"radio" ) ) )
260 if ( GetBool( wxT(
"toggle" ) ) )
262 wxASSERT_MSG( kind == wxITEM_NORMAL,
263 _T(
"can't have both toggleable and radion button at once" ) );
266 m_toolbar->AddTool(
id,
269 GetBitmap( wxT(
"bitmap2" ), wxART_TOOLBAR ),
272 GetText( wxT(
"longhelp" ) ) );
274 if ( GetBool( wxT(
"disabled" ) ) )
275 m_toolbar->EnableTool( GetID(),
false );
279 if ( a2dToolBarXmlHandler::m_parentAsWindow )
283 parentFrame->ConnectCmdId( a2dmenu );
296 else if ( m_class == wxT(
"a2dToolBar" ) )
298 int style = GetStyle( wxT(
"style" ), wxNO_BORDER | wxTB_HORIZONTAL );
300 if ( !( style & wxNO_BORDER ) ) style |= wxNO_BORDER;
303 XRC_MAKE_INSTANCE( toolbar, wxToolBar )
305 toolbar->Create( m_parentAsWindow,
311 SetupWindow( toolbar );
313 wxSize bmpsize = GetSize( wxT( "bitmapsize" ) );
314 if ( !( bmpsize == wxDefaultSize ) )
315 toolbar->SetToolBitmapSize( bmpsize );
316 wxSize margins = GetSize( wxT( "margins" ) );
317 if ( !( margins == wxDefaultSize ) )
318 toolbar->SetMargins( margins.x, margins.y );
319 long packing = GetLong( wxT( "packing" ), -1 );
321 toolbar->SetToolPacking( packing );
322 long separation = GetLong( wxT( "separation" ), -1 );
323 if ( separation != -1 )
324 toolbar->SetToolSeparation( separation );
326 wxXmlNode* children_node = GetParamNode( wxT( "
object" ) );
327 if ( !children_node )
328 children_node = GetParamNode( wxT( "object_ref" ) );
330 if ( children_node == NULL ) return toolbar;
335 wxXmlNode* n = children_node;
339 if ( ( n->GetType() == wxXML_ELEMENT_NODE ) &&
340 ( n->GetName() == wxT(
"object" ) || n->GetName() == wxT(
"object_ref" ) ) )
342 wxObject* created = CreateResFromNode( n, toolbar, NULL );
344 if ( !IsOfClass( n, wxT(
"tool" ) ) &&
345 !IsOfClass( n, wxT(
"a2dToolCmd" ) ) &&
346 !IsOfClass( n, wxT(
"separator" ) ) &&
348 toolbar->AddControl( control );
358 if ( m_parentAsWindow && !GetBool( wxT(
"dontattachtoframe" ) ) )
362 parentFrame->SetToolBar( toolbar );
368 return a2dToolBarXmlHandler::DoCreateResource();
372 bool a2dToolBarXmlHandler::CanHandle( wxXmlNode* node )
374 return ( ( !m_isInside && IsOfClass( node, wxT(
"a2dToolBar" ) ) ) ||
375 ( m_isInside && IsOfClass( node, wxT(
"a2dToolCmd" ) ) ) ||
376 wxToolBarXmlHandler::CanHandle( node ) );
379 #endif // wxUSE_XRC && wxUSE_TOOLBAR
The a2dDocumentMDIChildFrame class provides a default frame for displaying documents.
#define wxDynamicCast(obj, className)
Define wxDynamicCast so that it will give a compiler error for unrelated types.
Frame classes for MDI document/view applications.
void AddCmdMenu(wxMenu *parentMenu, const a2dMenuIdItem &cmdId)
add a menu to the parent menu, and connect it to the eventhandler of the frame
Docview classes for document view, window and frame.
The a2dDocumentFrame class provides a default frame for displaying documents.
void AddCmdMenu(wxMenu *parentMenu, const a2dMenuIdItem &cmdId)
add a command menu to the parent menu, and connect it to the eventhandler of the frame ...
void AddCmdMenu(wxMenu *parentMenu, const a2dMenuIdItem &cmdId)
add a command menu to the parent menu, and connect it to the eventhandler of the frame ...
command processor and intializing and event handling classes specific for wxDocview.
Use wxDocMDIParentFrame instead of wxDocMDIParentFrame.