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_choic.cpp < prev    next >
C/C++ Source or Header  |  2002-09-04  |  3KB  |  94 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name:        xh_choic.cpp
  3. // Purpose:     XRC resource for wxChoice
  4. // Author:      Bob Mitchell
  5. // Created:     2000/03/21
  6. // RCS-ID:      $Id: xh_choic.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_choic.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_choic.h"
  23. #include "wx/choice.h"
  24. #include "wx/intl.h"
  25.  
  26. wxChoiceXmlHandler::wxChoiceXmlHandler() 
  27. : wxXmlResourceHandler() , m_insideBox(FALSE)
  28. {
  29.     XRC_ADD_STYLE(wxCB_SORT);
  30.     AddWindowStyles();
  31. }
  32.  
  33. wxObject *wxChoiceXmlHandler::DoCreateResource()
  34.     if( m_class == wxT("wxChoice"))
  35.     {
  36.         // find the selection
  37.         long selection = GetLong(wxT("selection"), -1);
  38.  
  39.         // need to build the list of strings from children
  40.         m_insideBox = TRUE;
  41.         CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
  42.         wxString *strings = (wxString *) NULL;
  43.         if (strList.GetCount() > 0)
  44.         {
  45.             strings = new wxString[strList.GetCount()];
  46.             int count = strList.GetCount();
  47.             for (int i = 0; i < count; i++)
  48.                 strings[i]=strList[i];
  49.         }
  50.  
  51.         XRC_MAKE_INSTANCE(control, wxChoice)
  52.  
  53.         control->Create(m_parentAsWindow,
  54.                         GetID(),
  55.                         GetPosition(), GetSize(),
  56.                         strList.GetCount(),
  57.                         strings,
  58.                         GetStyle(),
  59.                         wxDefaultValidator,
  60.                         GetName());
  61.  
  62.         if (selection != -1)
  63.             control->SetSelection(selection);
  64.  
  65.         SetupWindow(control);
  66.  
  67.         if (strings != NULL)
  68.             delete[] strings;
  69.         strList.Clear();    // dump the strings   
  70.  
  71.         return control;
  72.     }
  73.     else
  74.     {
  75.         // on the inside now.
  76.         // handle <item>Label</item>
  77.         
  78.         // add to the list
  79.         wxString str = GetNodeContent(m_node);
  80.         if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
  81.             str = wxGetTranslation(str);
  82.         strList.Add(str);
  83.  
  84.         return NULL;
  85.     }
  86. }
  87.  
  88. bool wxChoiceXmlHandler::CanHandle(wxXmlNode *node)
  89. {
  90.     return (IsOfClass(node, wxT("wxChoice")) ||
  91.            (m_insideBox && node->GetName() == wxT("item")));
  92. }
  93.