X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b5d6954b87d910969226ffade9714db7429211f3..7bd236e6da74203ba429941d3f9643291494b420:/src/xrc/xh_radbx.cpp diff --git a/src/xrc/xh_radbx.cpp b/src/xrc/xh_radbx.cpp index 17beaac5f9..83be9a2d29 100644 --- a/src/xrc/xh_radbx.cpp +++ b/src/xrc/xh_radbx.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: xh_radbx.cpp +// Name: src/xrc/xh_radbx.cpp // Purpose: XRC resource for wxRadioBox // Author: Bob Mitchell // Created: 2000/03/21 @@ -7,10 +7,6 @@ // Copyright: (c) 2000 Bob Mitchell and Verant Interactive // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "xh_radbx.h" -#endif // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -19,84 +15,113 @@ #pragma hdrstop #endif +#if wxUSE_XRC && wxUSE_RADIOBOX + #include "wx/xrc/xh_radbx.h" + +#ifndef WX_PRECOMP + #include "wx/intl.h" +#endif + #include "wx/radiobox.h" -#if wxUSE_RADIOBOX +IMPLEMENT_DYNAMIC_CLASS(wxRadioBoxXmlHandler, wxXmlResourceHandler) -wxRadioBoxXmlHandler::wxRadioBoxXmlHandler() -: wxXmlResourceHandler() , m_insideBox(FALSE) +wxRadioBoxXmlHandler::wxRadioBoxXmlHandler() +: wxXmlResourceHandler(), m_insideBox(false) { - ADD_STYLE(wxRA_SPECIFY_COLS); - ADD_STYLE(wxRA_HORIZONTAL); - ADD_STYLE(wxRA_SPECIFY_ROWS); - ADD_STYLE(wxRA_VERTICAL); + XRC_ADD_STYLE(wxRA_SPECIFY_COLS); + XRC_ADD_STYLE(wxRA_HORIZONTAL); + XRC_ADD_STYLE(wxRA_SPECIFY_ROWS); + XRC_ADD_STYLE(wxRA_VERTICAL); AddWindowStyles(); } wxObject *wxRadioBoxXmlHandler::DoCreateResource() -{ - if( m_class == wxT("wxRadioBox")) +{ + if ( m_class == wxT("wxRadioBox")) { // find the selection long selection = GetLong( wxT("selection"), -1 ); // need to build the list of strings from children - m_insideBox = TRUE; + m_insideBox = true; CreateChildrenPrivately( NULL, GetParamNode(wxT("content"))); - wxString *strings = (wxString *) NULL; - if( strList.GetCount() > 0 ) + + wxString *strings; + if ( !labels.empty() ) { - strings = new wxString[strList.GetCount()]; - int count = strList.GetCount(); - for( int i = 0; i < count; i++ ) - strings[i]=strList[i]; + strings = new wxString[labels.size()]; + const unsigned count = labels.size(); + for( unsigned i = 0; i < count; i++ ) + strings[i] = labels[i]; } + else + { + strings = NULL; + } + + XRC_MAKE_INSTANCE(control, wxRadioBox) + control->Create(m_parentAsWindow, + GetID(), + GetText(wxT("label")), + GetPosition(), GetSize(), + labels.size(), + strings, + GetLong(wxT("dimension"), 1), + GetStyle(), + wxDefaultValidator, + GetName()); - wxRadioBox *control = new wxRadioBox(m_parentAsWindow, - GetID(), - GetText(wxT("label")), - GetPosition(), GetSize(), - strList.GetCount(), - strings, - GetLong( wxT("dimension"), 1 ), - GetStyle(), - wxDefaultValidator, - GetName() - ); + delete[] strings; - if( selection != -1 ) - control->SetSelection( selection ); + if (selection != -1) + control->SetSelection(selection); SetupWindow(control); - if( strings != NULL ) - delete [] strings; - strList.Clear(); // dump the strings +#if wxUSE_TOOLTIPS + const unsigned count = labels.size(); + for( unsigned i = 0; i < count; i++ ) + { + if ( !tooltips[i].empty() ) + control->SetItemToolTip(i, tooltips[i]); + } +#endif // wxUSE_TOOLTIPS + + labels.clear(); // dump the strings + tooltips.clear(); // dump the tooltips return control; } - else + else // inside the radiobox element { - // on the inside now. - // handle Label + // we handle Label constructs here + + wxString str = GetNodeContent(m_node); + wxString tooltip; + m_node->GetPropVal(wxT("tooltip"), &tooltip); + + if (m_resource->GetFlags() & wxXRC_USE_LOCALE) + { + str = wxGetTranslation(str); + if ( !tooltip.empty() ) + tooltip = wxGetTranslation(tooltip); + } - // add to the list - strList.Add( GetNodeContent(m_node) ); + labels.push_back(str); + tooltips.push_back(tooltip); return NULL; } } - - bool wxRadioBoxXmlHandler::CanHandle(wxXmlNode *node) { return (IsOfClass(node, wxT("wxRadioBox")) || - (m_insideBox && node->GetName() == wxT("item")) - ); + (m_insideBox && node->GetName() == wxT("item"))); } -#endif +#endif // wxUSE_XRC && wxUSE_RADIOBOX