X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/78d14f80e9a72041ede52c30d912ec5cef21b1b3..d2e66707deb10dea6f92e3e4092f8a43ef942a5d:/src/xrc/xh_radbx.cpp diff --git a/src/xrc/xh_radbx.cpp b/src/xrc/xh_radbx.cpp index 7d22430aa4..c6ee9307a6 100644 --- a/src/xrc/xh_radbx.cpp +++ b/src/xrc/xh_radbx.cpp @@ -1,16 +1,12 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: xh_radbx.cpp -// Purpose: XML resource for wxRadioBox +// Name: src/xrc/xh_radbx.cpp +// Purpose: XRC resource for wxRadioBox // Author: Bob Mitchell // Created: 2000/03/21 // RCS-ID: $Id$ // 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,134 @@ #pragma hdrstop #endif +#if wxUSE_XRC && wxUSE_RADIOBOX + #include "wx/xrc/xh_radbx.h" -#include "wx/radiobox.h" -#if wxUSE_RADIOBOX +#ifndef WX_PRECOMP + #include "wx/intl.h" + #include "wx/radiobox.h" +#endif + +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 ) + + XRC_MAKE_INSTANCE(control, wxRadioBox) + + control->Create(m_parentAsWindow, + GetID(), + GetText(wxT("label")), + GetPosition(), GetSize(), + m_labels, + GetLong(wxT("dimension"), 1), + GetStyle(), + wxDefaultValidator, + GetName()); + + if (selection != -1) + control->SetSelection(selection); + + SetupWindow(control); + + const unsigned count = m_labels.size(); + for( unsigned i = 0; i < count; i++ ) { - strings = new wxString[strList.GetCount()]; - int count = strList.GetCount(); - for( int i = 0; i < count; i++ ) - strings[i]=strList[i]; +#if wxUSE_TOOLTIPS + if ( !m_tooltips[i].empty() ) + control->SetItemToolTip(i, m_tooltips[i]); +#endif // wxUSE_TOOLTIPS +#if wxUSE_HELP + if ( m_helptextSpecified[i] ) + control->SetItemHelpText(i, m_helptexts[i]); +#endif // wxUSE_HELP + + if ( !m_isShown[i] ) + control->Show(i, false); + if ( !m_isEnabled[i] ) + control->Enable(i, false); } - wxRadioBox *control = new wxRadioBox(m_parentAsWindow, - GetID(), - GetText(wxT("label")), - GetPosition(), GetSize(), - strList.GetCount(), - strings, - GetLong( wxT("dimension"), 1 ), - GetStyle(), - wxDefaultValidator, - GetName() - ); + // forget information about the items of this radiobox, we should start + // afresh for the next one + m_labels.clear(); - if( selection != -1 ) - control->SetSelection( selection ); +#if wxUSE_TOOLTIPS + m_tooltips.clear(); +#endif // wxUSE_TOOLTIPS - SetupWindow(control); +#if wxUSE_HELP + m_helptexts.clear(); + m_helptextSpecified.clear(); +#endif // wxUSE_HELP - if( strings != NULL ) - delete [] strings; - strList.Clear(); // dump the strings + m_isShown.clear(); + m_isEnabled.clear(); return control; } - else + else // inside the radiobox element { - // on the inside now. - // handle Label + // we handle handle Label constructs here, and the item + // tag can have tooltip, helptext, enabled and hidden attributes + + wxString label = GetNodeContent(m_node); + + wxString tooltip; + m_node->GetAttribute(wxT("tooltip"), &tooltip); + + wxString helptext; + bool hasHelptext = m_node->GetAttribute(wxT("helptext"), &helptext); + + if (m_resource->GetFlags() & wxXRC_USE_LOCALE) + { + label = wxGetTranslation(label, m_resource->GetDomain()); + if ( !tooltip.empty() ) + tooltip = wxGetTranslation(tooltip, m_resource->GetDomain()); + if ( hasHelptext ) + helptext = wxGetTranslation(helptext, m_resource->GetDomain()); + } - // add to the list - strList.Add( GetNodeContent(m_node) ); + m_labels.push_back(label); +#if wxUSE_TOOLTIPS + m_tooltips.push_back(tooltip); +#endif // wxUSE_TOOLTIPS +#if wxUSE_HELP + m_helptexts.push_back(helptext); + m_helptextSpecified.push_back(hasHelptext); +#endif // wxUSE_HELP + m_isEnabled.push_back(GetBoolAttr("enabled", 1)); + m_isShown.push_back(!GetBoolAttr("hidden", 0)); 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