]>
git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_choic.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     XRC resource for wxChoice 
   4 // Author:      Bob Mitchell 
   7 // Copyright:   (c) 2000 Bob Mitchell and Verant Interactive 
   8 // Licence:     wxWindows licence 
   9 ///////////////////////////////////////////////////////////////////////////// 
  12 #pragma implementation "xh_choic.h" 
  15 // For compilers that support precompilation, includes "wx.h". 
  16 #include "wx/wxprec.h" 
  22 #include "wx/xrc/xh_choic.h" 
  23 #include "wx/choice.h" 
  26 IMPLEMENT_DYNAMIC_CLASS(wxChoiceXmlHandler
, wxXmlResourceHandler
) 
  28 wxChoiceXmlHandler::wxChoiceXmlHandler()  
  29 : wxXmlResourceHandler() , m_insideBox(FALSE
) 
  31     XRC_ADD_STYLE(wxCB_SORT
); 
  35 wxObject 
*wxChoiceXmlHandler::DoCreateResource() 
  37     if( m_class 
== wxT("wxChoice")) 
  40         long selection 
= GetLong(wxT("selection"), -1); 
  42         // need to build the list of strings from children 
  44         CreateChildrenPrivately(NULL
, GetParamNode(wxT("content"))); 
  45         wxString 
*strings 
= (wxString 
*) NULL
; 
  46         if (strList
.GetCount() > 0) 
  48             strings 
= new wxString
[strList
.GetCount()]; 
  49             int count 
= strList
.GetCount(); 
  50             for (int i 
= 0; i 
< count
; i
++) 
  51                 strings
[i
]=strList
[i
]; 
  54         XRC_MAKE_INSTANCE(control
, wxChoice
) 
  56         control
->Create(m_parentAsWindow
, 
  58                         GetPosition(), GetSize(), 
  66             control
->SetSelection(selection
); 
  72         strList
.Clear();    // dump the strings    
  79         // handle <item>Label</item> 
  82         wxString str 
= GetNodeContent(m_node
); 
  83         if (m_resource
->GetFlags() & wxXRC_USE_LOCALE
) 
  84             str 
= wxGetTranslation(str
); 
  91 bool wxChoiceXmlHandler::CanHandle(wxXmlNode 
*node
) 
  93     return (IsOfClass(node
, wxT("wxChoice")) || 
  94            (m_insideBox 
&& node
->GetName() == wxT("item")));