xh_odcombo.cpp

Go to the documentation of this file.
00001 
00002 // Name:        src/xrc/xh_odcombo.cpp
00003 // Purpose:     XRC resource for wxRadioBox
00004 // Author:      Alex Bligh - Based on src/xrc/xh_combo.cpp
00005 // Created:     2006/06/19
00006 // RCS-ID:      $Id: xh_odcombo.cpp,v 1.2 2006/06/20 17:02:26 ABX Exp $
00007 // Copyright:   (c) 2006 Alex Bligh
00008 // Licence:     wxWindows licence
00010 
00011 #include <wx/wx.h>
00012 
00013 #include "xh_odcombo.h"
00014 // Only compile stuff if this is not already in WX
00015 #if wxXTRA_XH_ODCOMBO
00016 #include "odcombo.h"
00017 
00018 IMPLEMENT_DYNAMIC_CLASS(wxOwnerDrawnComboBoxXmlHandler, wxXmlResourceHandler)
00019 
00020 wxOwnerDrawnComboBoxXmlHandler::wxOwnerDrawnComboBoxXmlHandler()
00021                      :wxXmlResourceHandler()
00022                      ,m_insideBox(false)
00023 {
00024     XRC_ADD_STYLE(wxCB_SIMPLE);
00025     XRC_ADD_STYLE(wxCB_SORT);
00026     XRC_ADD_STYLE(wxCB_READONLY);
00027     XRC_ADD_STYLE(wxCB_DROPDOWN);
00028     XRC_ADD_STYLE(wxODCB_STD_CONTROL_PAINT);
00029     XRC_ADD_STYLE(wxODCB_DCLICK_CYCLES);
00030     XRC_ADD_STYLE(wxTE_PROCESS_ENTER);
00031     AddWindowStyles();
00032 }
00033 
00034 wxObject *wxOwnerDrawnComboBoxXmlHandler::DoCreateResource()
00035 {
00036     if( m_class == wxT("wxOwnerDrawnComboBox"))
00037     {
00038         // find the selection
00039         long selection = GetLong( wxT("selection"), -1 );
00040 
00041         // need to build the list of strings from children
00042         m_insideBox = true;
00043         CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
00044         wxString *strings = (wxString *) NULL;
00045         if (strList.GetCount() > 0)
00046         {
00047             strings = new wxString[strList.GetCount()];
00048             int count = strList.GetCount();
00049             for (int i = 0; i < count; i++)
00050                 strings[i]=strList[i];
00051         }
00052 
00053         XRC_MAKE_INSTANCE(control, wxOwnerDrawnComboBox)
00054 
00055         control->Create(m_parentAsWindow,
00056                         GetID(),
00057                         GetText(wxT("value")),
00058                         GetPosition(), GetSize(),
00059                         strList.GetCount(),
00060                         strings,
00061                         GetStyle(),
00062                         wxDefaultValidator,
00063                         GetName());
00064 
00065         wxSize ButtonSize=GetSize(wxT("buttonsize"));
00066 
00067         if (ButtonSize != wxDefaultSize)
00068         control->SetButtonPosition(ButtonSize.GetWidth(), ButtonSize.GetHeight());
00069 
00070         if (selection != -1)
00071             control->SetSelection(selection);
00072 
00073         SetupWindow(control);
00074 
00075         if (strings != NULL)
00076             delete[] strings;
00077         strList.Clear();    // dump the strings
00078 
00079         return control;
00080     }
00081     else
00082     {
00083         // on the inside now.
00084         // handle <item>Label</item>
00085 
00086         // add to the list
00087         wxString str = GetNodeContent(m_node);
00088         if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
00089             str = wxGetTranslation(str);
00090         strList.Add(str);
00091 
00092         return NULL;
00093     }
00094 }
00095 
00096 bool wxOwnerDrawnComboBoxXmlHandler::CanHandle(wxXmlNode *node)
00097 {
00098 #if wxABI_VERSION >= 20700
00099 
00100     return (IsOfClass(node, wxT("wxOwnerDrawnComboBox")) ||
00101            (m_insideBox && node->GetName() == wxT("item")));
00102 
00103 #else
00104 
00105 //  Avoid GCC bug - this fails on certain GCC 3.3 and 3.4 builds for an unknown reason
00106 //  it is believed to be related to the fact IsOfClass is inline, and node->GetPropVal
00107 //  gets passed an invalid "this" pointer. On 2.7, the function is out of line, so the
00108 //  above should work fine. This code is left in here so this file can easily be used
00109 //  in a version backported to 2.6. All we are doing here is expanding the macro
00110 
00111     bool fOurClass = node->GetPropVal(wxT("class"), wxEmptyString) == wxT("wxOwnerDrawnComboBox");
00112     return (fOurClass ||
00113           (m_insideBox && node->GetName() == wxT("item")));
00114 #endif
00115 }
00116 
00117 #endif // wxUSE_XRC && wxUSE_ODCOMBOBOX

Generated on Sat Nov 10 03:49:02 2007 for Camelot by  doxygen 1.4.4