home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2233.zip / wxOS2-2_3_3.zip / wxWindows-2.3.3 / contrib / src / xrc / xh_chckl.cpp < prev    next >
C/C++ Source or Header  |  2002-09-04  |  3KB  |  109 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name:        xh_chckl.cpp
  3. // Purpose:     XRC resource for wxCheckList
  4. // Author:      Bob Mitchell
  5. // Created:     2000/03/21
  6. // RCS-ID:      $Id: xh_chckl.cpp,v 1.6 2002/09/01 17:11:38 VS Exp $
  7. // Copyright:   (c) 2000 Bob Mitchell and Verant Interactive
  8. // Licence:     wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10.  
  11. #ifdef __GNUG__
  12. #pragma implementation "xh_chckl.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_chckl.h"
  23. #include "wx/checklst.h"
  24. #include "wx/intl.h"
  25.  
  26. wxCheckListXmlHandler::wxCheckListXmlHandler() 
  27. : wxXmlResourceHandler(), m_insideBox(FALSE)
  28. {
  29.     // no styles
  30.     AddWindowStyles();
  31. }
  32.  
  33. wxObject *wxCheckListXmlHandler::DoCreateResource()
  34.     if (m_class == wxT("wxCheckList"))
  35.     {
  36.         // need to build the list of strings from children
  37.         m_insideBox = TRUE;
  38.         CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
  39.         wxString *strings = (wxString *) NULL;
  40.         if (strList.GetCount() > 0)
  41.         {
  42.             strings = new wxString[strList.GetCount()];
  43.             int count = strList.GetCount();
  44.             for(int i = 0; i < count; i++)
  45.                 strings[i] = strList[i];
  46.         }
  47.  
  48.         XRC_MAKE_INSTANCE(control, wxCheckListBox)
  49.  
  50.         control->Create(m_parentAsWindow,
  51.                         GetID(),
  52.                         GetPosition(), GetSize(),
  53.                         strList.GetCount(),
  54.                         strings,
  55.                         GetStyle(),
  56.                         wxDefaultValidator,
  57.                         GetName());
  58.  
  59.         // step through children myself (again.)
  60.         wxXmlNode *n = GetParamNode(wxT("content"));
  61.         if (n) n = n->GetChildren();
  62.         int i = 0;
  63.         while (n)
  64.         {
  65.             if (n->GetType() != wxXML_ELEMENT_NODE ||
  66.                 n->GetName() != wxT("item"))
  67.                { n = n->GetNext(); continue; }
  68.  
  69.             // checking boolean is a bit ugly here (see GetBool() )
  70.             wxString v = n->GetPropVal(wxT("checked"), wxEmptyString);
  71.             v.MakeLower();
  72.             if (v && v == wxT("1"))
  73.                 control->Check( i, TRUE );
  74.  
  75.             i++;        
  76.             n = n->GetNext();
  77.         }
  78.         
  79.         SetupWindow(control);
  80.  
  81.         if (strings != NULL)
  82.             delete[] strings;
  83.         strList.Clear();    // dump the strings   
  84.  
  85.         return control;
  86.     }
  87.     else
  88.     {
  89.         // on the inside now.
  90.         // handle <item checked="boolean">Label</item>
  91.  
  92.         // add to the list
  93.         wxString str = GetNodeContent(m_node);
  94.         if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
  95.             str = wxGetTranslation(str);
  96.         strList.Add(str);
  97.         return NULL;
  98.     }
  99. }
  100.  
  101. bool wxCheckListXmlHandler::CanHandle(wxXmlNode *node)
  102. {
  103.     return (IsOfClass(node, wxT("wxCheckList")) ||
  104.            (m_insideBox && node->GetName() == wxT("item")));
  105. }
  106.  
  107.  
  108.