00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "docviewprec.h"
00013
00014 #ifdef __BORLANDC__
00015 #pragma hdrstop
00016 #endif
00017
00018 #ifndef WX_PRECOMP
00019 #include "wx/wx.h"
00020 #include "wx/frame.h"
00021 #include "wx/menu.h"
00022 #endif
00023
00024 #if wxUSE_XRC
00025
00026 #include "wx/xrc/xh_menu.h"
00027
00028 #include "wx/general/comevt.h"
00029 #include "wx/docview/docviewref.h"
00030 #include "wx/docview/docmdiref.h"
00031 #include "wx/docview/xh_a2dmenu.h"
00032
00033 IMPLEMENT_DYNAMIC_CLASS(a2dMenuXmlHandler, wxMenuXmlHandler)
00034
00035 a2dMenuXmlHandler::a2dMenuXmlHandler() :
00036 wxMenuXmlHandler()
00037 {
00038 }
00039
00040 wxObject *a2dMenuXmlHandler::DoCreateResource()
00041 {
00042 if (m_class == wxT("a2dMenu") || m_class == wxT("wxMenu"))
00043 {
00044 wxMenu *menu = new wxMenu(GetStyle());
00045 wxString title = GetText(wxT("label"));
00046 wxString help = GetText(wxT("help"));
00047
00048 bool oldins = m_insideA2DMenu;
00049 m_insideA2DMenu = true;
00050 CreateChildren(menu, true);
00051 m_insideA2DMenu = oldins;
00052
00053 wxMenuBar *p_bar = wxDynamicCast(m_parent, wxMenuBar);
00054 if (p_bar)
00055 p_bar->Append(menu, title);
00056 else
00057 {
00058 wxMenu *p_menu = wxDynamicCast(m_parent, wxMenu);
00059 if (p_menu)
00060 {
00061 p_menu->Append(GetID(), title, menu, help);
00062 if (HasParam(wxT("enabled")))
00063 p_menu->Enable(GetID(), GetBool(wxT("enabled")));
00064 }
00065 }
00066
00067 return menu;
00068 }
00069
00070
00071
00072
00073
00074 else
00075 if (m_class == wxT("a2dMenuIdItem"))
00076 {
00077 wxMenu *p_menu = wxDynamicCast(m_parent, wxMenu);
00078
00079 int id = GetID();
00080 wxString label = GetText(wxT("label"));
00081 wxString accel = GetText(wxT("accel"), false);
00082 wxString help = GetText(wxT("help"));
00083
00084 wxString a2dCmdIdName = GetName();
00085 const a2dMenuIdItem& a2dmenu = a2dMenuIdItem::GetItemByName( a2dCmdIdName );
00086 if( &a2dmenu == &a2dMenuIdItem::sm_noCmdMenuId )
00087 {
00088 wxString error = _T("a2dMenuIdItem with id name: ") + a2dCmdIdName + _T(" not know");
00089 wxMessageBox( error, _("XRC problem"), wxICON_INFORMATION | wxOK );
00090 return NULL;
00091 }
00092 if ( label.IsEmpty() )
00093 label = a2dmenu.GetLabel();
00094 if ( help.IsEmpty() )
00095 help = a2dmenu.GetHelp();
00096
00097 wxItemKind kind = a2dmenu.GetKind();
00098
00099 wxString fullLabel = label;
00100 if (!accel.IsEmpty())
00101 fullLabel << wxT("\t") << accel;
00102
00103 id = a2dmenu.GetId();
00104 wxMenuItem *mitem = new wxMenuItem(p_menu, id, fullLabel, help, kind);
00105
00106 #if (!defined(__WXMSW__) && !defined(__WXPM__)) || wxUSE_OWNER_DRAWN
00107 if (HasParam(wxT("bitmap")))
00108 mitem->SetBitmap(GetBitmap(wxT("bitmap"), wxART_MENU));
00109 #endif
00110 if (a2dMenuBarXmlHandler::m_parentFrame)
00111 {
00112 a2dDocumentFrame *parentFrame = wxDynamicCast(a2dMenuBarXmlHandler::m_parentFrame, a2dDocumentFrame);
00113 if (parentFrame)
00114 parentFrame->AddCmdMenu( p_menu, mitem );
00115 a2dDocumentMDIChildFrame *mdiChildFrame = wxDynamicCast(a2dMenuBarXmlHandler::m_parentFrame, a2dDocumentMDIChildFrame);
00116 if (mdiChildFrame)
00117 mdiChildFrame->AddCmdMenu( p_menu, mitem );
00118 a2dDocumentMDIParentFrame *mdiParentFrame = wxDynamicCast(a2dMenuBarXmlHandler::m_parentFrame, a2dDocumentMDIParentFrame);
00119 if (mdiParentFrame)
00120 mdiParentFrame->AddCmdMenu( p_menu, mitem );
00121 }
00122
00123 mitem->Enable(GetBool(wxT("enabled"), true));
00124 if (kind == wxITEM_CHECK)
00125 mitem->Check(GetBool(wxT("checked")));
00126
00127 return NULL;
00128 }
00129 else
00130 return wxMenuXmlHandler::DoCreateResource();
00131 }
00132
00133 bool a2dMenuXmlHandler::CanHandle(wxXmlNode *node)
00134 {
00135 return IsOfClass(node, wxT("a2dMenu")) || IsOfClass(node, wxT("wxMenu")) ||
00136 (m_insideA2DMenu &&
00137 (IsOfClass(node, wxT("a2dMenuIdItem")) ||
00138 IsOfClass(node, wxT("wxMenuItem")) ||
00139 IsOfClass(node, wxT("break")) ||
00140 IsOfClass(node, wxT("separator")))
00141 );
00142 }
00143
00144
00145
00146
00147
00148
00149 IMPLEMENT_DYNAMIC_CLASS(a2dMenuBarXmlHandler, wxMenuBarXmlHandler)
00150
00151 wxFrame* a2dMenuBarXmlHandler::m_parentFrame = NULL;
00152
00153 a2dMenuBarXmlHandler::a2dMenuBarXmlHandler() : wxMenuBarXmlHandler()
00154 {
00155 }
00156
00157 wxObject *a2dMenuBarXmlHandler::DoCreateResource()
00158 {
00159 wxFrame* curFrame = m_parentFrame;
00160 wxMenuBar *menubar = NULL;
00161 if(m_parentAsWindow)
00162 {
00163 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
00164 if(parentFrame)
00165 {
00166 m_parentFrame = parentFrame;
00167 menubar = m_parentFrame->GetMenuBar();
00168 CreateChildren(menubar);
00169 }
00170 }
00171
00172 if ( !menubar )
00173 {
00174 menubar = new wxMenuBar(GetStyle());
00175 CreateChildren(menubar);
00176 if (m_parentAsWindow && m_parentFrame)
00177 {
00178 m_parentFrame->SetMenuBar(menubar);
00179 }
00180 }
00181
00182 m_parentFrame = curFrame;
00183
00184 return menubar;
00185 }
00186
00187 bool a2dMenuBarXmlHandler::CanHandle(wxXmlNode *node)
00188 {
00189 return IsOfClass(node, wxT("a2dMenuBar")) || IsOfClass(node, wxT("wxMenuBar"));
00190 }
00191
00192 #endif // wxUSE_XRC
00193
00194
00195
00196
00197
00198 #if wxUSE_XRC && wxUSE_TOOLBAR
00199
00200 #include "wx/xrc/xh_toolb.h"
00201
00202 #ifndef WX_PRECOMP
00203 #include "wx/frame.h"
00204 #include "wx/toolbar.h"
00205 #endif
00206
00207 IMPLEMENT_DYNAMIC_CLASS( a2dToolBarXmlHandler, wxToolBarXmlHandler )
00208
00209 a2dToolBarXmlHandler::a2dToolBarXmlHandler()
00210 : wxToolBarXmlHandler(), m_isInside(false), m_toolbar(NULL)
00211 {
00212 }
00213
00214 wxObject *a2dToolBarXmlHandler::DoCreateResource()
00215 {
00216 if (m_class == wxT("a2dToolCmd"))
00217 {
00218 wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: tool not within a toolbar!"));
00219
00220 int id = GetID();
00221 wxString a2dCmdIdName = GetName();
00222 const a2dMenuIdItem& a2dmenu = a2dMenuIdItem::GetItemByName( a2dCmdIdName );
00223 if( &a2dmenu == &a2dMenuIdItem::sm_noCmdMenuId )
00224 {
00225 wxString error = _T("a2dToolCmd with id name: ") + a2dCmdIdName + _T(" not know");
00226 wxMessageBox( error, _("XRC problem"), wxICON_INFORMATION | wxOK );
00227 return NULL;
00228 }
00229
00230 id = a2dmenu.GetId();
00231 wxString label = GetText(wxT("label"));
00232 wxString help = GetText(wxT("tooltip"));
00233 wxBitmap selBitmap = GetBitmap( wxT("bitmap"), wxART_TOOLBAR );
00234 if ( ! selBitmap.Ok() )
00235 selBitmap = a2dmenu.GetBitmap(false);
00236
00237 wxString error = _T("No Bitmap for a2dToolCmd found for:") + a2dCmdIdName;
00238 wxASSERT_MSG( selBitmap.Ok(), error );
00239
00240 if ( label.IsEmpty() )
00241 label = a2dmenu.GetLabel();
00242 if ( help.IsEmpty() )
00243 help = a2dmenu.GetHelp();
00244
00245
00246 if (GetPosition() != wxDefaultPosition)
00247 {
00248 m_toolbar->InsertTool( GetPosition().x, id, label,
00249 selBitmap,
00250 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR),
00251 GetBool(wxT("toggle")) ? wxITEM_CHECK : wxITEM_NORMAL,
00252 help,
00253 GetText(wxT("longhelp")));
00254 }
00255 else
00256 {
00257 wxItemKind kind = wxITEM_NORMAL;
00258 if (GetBool(wxT("radio")))
00259 kind = wxITEM_RADIO;
00260 if (GetBool(wxT("toggle")))
00261 {
00262 wxASSERT_MSG( kind == wxITEM_NORMAL,
00263 _T("can't have both toggleable and radion button at once") );
00264 kind = wxITEM_CHECK;
00265 }
00266 m_toolbar->AddTool( id,
00267 label,
00268 selBitmap,
00269 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR),
00270 kind,
00271 help,
00272 GetText(wxT("longhelp")));
00273
00274 if ( GetBool(wxT("disabled")) )
00275 m_toolbar->EnableTool(GetID(), false);
00276 }
00277
00278
00279 if (a2dToolBarXmlHandler::m_parentAsWindow)
00280 {
00281 a2dDocumentFrame *parentFrame = wxDynamicCast(a2dMenuBarXmlHandler::m_parentFrame, a2dDocumentFrame);
00282 if (parentFrame)
00283 parentFrame->ConnectCmdId( a2dmenu );
00284
00285
00286
00287
00288
00289
00290
00291
00292 }
00293
00294 return m_toolbar;
00295 }
00296 else if (m_class == wxT("a2dToolBar"))
00297 {
00298 int style = GetStyle(wxT("style"), wxNO_BORDER | wxTB_HORIZONTAL);
00299 #ifdef __WXMSW__
00300 if (!(style & wxNO_BORDER)) style |= wxNO_BORDER;
00301 #endif
00302
00303 XRC_MAKE_INSTANCE(toolbar, wxToolBar)
00304
00305 toolbar->Create(m_parentAsWindow,
00306 GetID(),
00307 GetPosition(),
00308 GetSize(),
00309 style,
00310 GetName());
00311 SetupWindow(toolbar);
00312
00313 wxSize bmpsize = GetSize(wxT("bitmapsize"));
00314 if (!(bmpsize == wxDefaultSize))
00315 toolbar->SetToolBitmapSize(bmpsize);
00316 wxSize margins = GetSize(wxT("margins"));
00317 if (!(margins == wxDefaultSize))
00318 toolbar->SetMargins(margins.x, margins.y);
00319 long packing = GetLong(wxT("packing"), -1);
00320 if (packing != -1)
00321 toolbar->SetToolPacking(packing);
00322 long separation = GetLong(wxT("separation"), -1);
00323 if (separation != -1)
00324 toolbar->SetToolSeparation(separation);
00325
00326 wxXmlNode *children_node = GetParamNode(wxT("object"));
00327 if (!children_node)
00328 children_node = GetParamNode(wxT("object_ref"));
00329
00330 if (children_node == NULL) return toolbar;
00331
00332 m_isInside = true;
00333 m_toolbar = toolbar;
00334
00335 wxXmlNode *n = children_node;
00336
00337 while (n)
00338 {
00339 if ((n->GetType() == wxXML_ELEMENT_NODE) &&
00340 (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
00341 {
00342 wxObject *created = CreateResFromNode(n, toolbar, NULL);
00343 wxControl *control = wxDynamicCast(created, wxControl);
00344 if (!IsOfClass(n, wxT("tool")) &&
00345 !IsOfClass(n, wxT("a2dToolCmd")) &&
00346 !IsOfClass(n, wxT("separator")) &&
00347 control != NULL)
00348 toolbar->AddControl(control);
00349 }
00350 n = n->GetNext();
00351 }
00352
00353 m_isInside = false;
00354 m_toolbar = NULL;
00355
00356 toolbar->Realize();
00357
00358 if (m_parentAsWindow && !GetBool(wxT("dontattachtoframe")))
00359 {
00360 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
00361 if (parentFrame)
00362 parentFrame->SetToolBar(toolbar);
00363 }
00364
00365 return toolbar;
00366 }
00367 else
00368 return a2dToolBarXmlHandler::DoCreateResource();
00369
00370 }
00371
00372 bool a2dToolBarXmlHandler::CanHandle(wxXmlNode *node)
00373 {
00374 return ((!m_isInside && IsOfClass(node, wxT("a2dToolBar"))) ||
00375 (m_isInside && IsOfClass(node, wxT("a2dToolCmd"))) ||
00376 wxToolBarXmlHandler::CanHandle(node) );
00377 }
00378
00379 #endif // wxUSE_XRC && wxUSE_TOOLBAR