home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2240.zip / wxWindows-2.4.0 / contrib / src / xrc / xh_toolb.cpp < prev    next >
C/C++ Source or Header  |  2002-08-21  |  5KB  |  141 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name:        xh_toolb.cpp
  3. // Purpose:     XRC resource for wxBoxSizer
  4. // Author:      Vaclav Slavik
  5. // Created:     2000/08/11
  6. // RCS-ID:      $Id: xh_toolb.cpp,v 1.6 2002/08/20 22:28:15 VS Exp $
  7. // Copyright:   (c) 2000 Vaclav Slavik
  8. // Licence:     wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10.  
  11. #ifdef __GNUG__
  12. #pragma implementation "xh_toolb.h"
  13. #endif
  14.  
  15. // For compilers that support precompilation, includes "wx.h".
  16. #include "wx/wxprec.h"
  17.  
  18. #ifdef __BORLANDC__
  19.     #pragma hdrstop
  20. #endif
  21.  
  22. #include "wx/xrc/xh_toolb.h"
  23. #include "wx/toolbar.h"
  24. #include "wx/frame.h"
  25.  
  26. #if wxUSE_TOOLBAR
  27.  
  28. wxToolBarXmlHandler::wxToolBarXmlHandler() 
  29. : wxXmlResourceHandler(), m_isInside(FALSE), m_toolbar(NULL)
  30. {
  31.     XRC_ADD_STYLE(wxTB_FLAT);
  32.     XRC_ADD_STYLE(wxTB_DOCKABLE);
  33.     XRC_ADD_STYLE(wxTB_VERTICAL);
  34.     XRC_ADD_STYLE(wxTB_HORIZONTAL);
  35. }
  36.  
  37. wxObject *wxToolBarXmlHandler::DoCreateResource()
  38.     if (m_class == wxT("tool"))
  39.     {
  40.         wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: tool not within a toolbar!"));
  41.         m_toolbar->AddTool(GetID(),
  42.                            GetBitmap(wxT("bitmap"), wxART_TOOLBAR),
  43.                            GetBitmap(wxT("bitmap2"), wxART_TOOLBAR),
  44.                            GetBool(wxT("toggle")),
  45.                            GetPosition().x,
  46.                            GetPosition().y,
  47.                            NULL,
  48.                            GetText(wxT("tooltip")),
  49.                            GetText(wxT("longhelp")));
  50.         return m_toolbar; // must return non-NULL
  51.     }
  52.     
  53.     else if (m_class == wxT("separator"))
  54.     {
  55.         wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!"));
  56.         m_toolbar->AddSeparator();
  57.         return m_toolbar; // must return non-NULL
  58.     }
  59.     
  60.     else /*<object class="wxToolBar">*/
  61.     {
  62.         int style = GetStyle(wxT("style"), wxNO_BORDER | wxTB_HORIZONTAL);
  63. #ifdef __WXMSW__
  64.         if (!(style & wxNO_BORDER)) style |= wxNO_BORDER;
  65. #endif
  66.  
  67.         XRC_MAKE_INSTANCE(toolbar, wxToolBar)
  68.  
  69.         toolbar->Create(m_parentAsWindow,
  70.                          GetID(),
  71.                          GetPosition(),
  72.                          GetSize(),
  73.                          style,
  74.                          GetName());
  75.  
  76.         wxSize bmpsize = GetSize(wxT("bitmapsize"));
  77.         if (!(bmpsize == wxDefaultSize))
  78.             toolbar->SetToolBitmapSize(bmpsize);
  79.         wxSize margins = GetSize(wxT("margins"));
  80.         if (!(margins == wxDefaultSize))
  81.             toolbar->SetMargins(margins.x, margins.y);
  82.         long packing = GetLong(wxT("packing"), -1);
  83.         if (packing != -1)
  84.             toolbar->SetToolPacking(packing);
  85.         long separation = GetLong(wxT("separation"), -1);
  86.         if (separation != -1)
  87.             toolbar->SetToolSeparation(separation);
  88.  
  89.         wxXmlNode *children_node = GetParamNode(wxT("object"));
  90.         if (!children_node)
  91.            children_node = GetParamNode(wxT("object_ref"));
  92.  
  93.         if (children_node == NULL) return toolbar;
  94.  
  95.         m_isInside = TRUE;
  96.         m_toolbar = toolbar;
  97.  
  98.         wxXmlNode *n = children_node;
  99.  
  100.         while (n)
  101.         {
  102.             if ((n->GetType() == wxXML_ELEMENT_NODE) && 
  103.                 (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
  104.             {
  105.                 wxObject *created = CreateResFromNode(n, toolbar, NULL);
  106.                 wxControl *control = wxDynamicCast(created, wxControl);
  107.                 if (!IsOfClass(n, wxT("tool")) &&
  108.                     !IsOfClass(n, wxT("separator")) &&
  109.                     control != NULL)
  110.                     toolbar->AddControl(control);
  111.             }
  112.             n = n->GetNext();
  113.         }
  114.  
  115.         m_isInside = FALSE;
  116.         m_toolbar = NULL;
  117.  
  118.         toolbar->Realize();
  119.  
  120.         // FIXME: how can I create a toolbar without immediately setting it to the frame?
  121.         if (m_parentAsWindow)
  122.         {
  123.             wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
  124.             if (parentFrame)
  125.                 parentFrame->SetToolBar(toolbar);
  126.         }
  127.  
  128.         return toolbar;
  129.     }
  130. }
  131.  
  132. bool wxToolBarXmlHandler::CanHandle(wxXmlNode *node)
  133. {
  134.     return ((!m_isInside && IsOfClass(node, wxT("wxToolBar"))) ||
  135.             (m_isInside && IsOfClass(node, wxT("tool"))) || 
  136.             (m_isInside && IsOfClass(node, wxT("separator"))));
  137. }
  138.  
  139. #endif
  140.