I am probably missing something here: wny not use C++ RTTI? I would just do
Code: Select all
wxTextEntry* te = dynamic_cast<wxTextEntry*>(m_pWndLastFocused);
if ( te )
te->Clear();
I have just tested it and works as expected
Code: Select all
#include <wx/wx.h>
class MyDialog : public wxDialog
{
public:
MyDialog() : wxDialog(NULL, wxID_ANY, "Test", wxDefaultPosition, wxSize(600, 600))
{
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
wxCheckBox* checkBox = new wxCheckBox(this, wxID_ANY, "CheckBox");
mainSizer->Add(checkBox, wxSizerFlags().Expand().Border());
wxTextCtrl* textCtrl = new wxTextCtrl(this, wxID_ANY, "TextCtrl");
mainSizer->Add(textCtrl, wxSizerFlags().Expand().Border());
wxRadioButton* radioButton = new wxRadioButton(this, wxID_ANY, "RadioButton");
mainSizer->Add(radioButton, wxSizerFlags().Expand().Border());
wxComboBox* comboBox = new wxComboBox(this, wxID_ANY, "ComboBox");
mainSizer->Add(comboBox, wxSizerFlags().Expand().Border());
wxButton* button = new wxButton(this, wxID_ANY, "Clear Text Entries");
mainSizer->Add(button, wxSizerFlags().Expand().Border());
Bind(wxEVT_BUTTON, &MyDialog::OnClearTextEntries, this);
m_logCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH2);
wxLog::SetActiveTarget(new wxLogTextCtrl(m_logCtrl));
wxLog::SetTimestamp("");
mainSizer->Add(m_logCtrl, wxSizerFlags().Proportion(1).Expand().DoubleBorder());
SetSizer(mainSizer);
}
private:
wxTextCtrl* m_logCtrl;
void OnClearTextEntries(wxCommandEvent&)
{
const wxWindowList& children = GetChildren();
for ( wxWindowList::Node* node = children.GetFirst(); node; node = node->GetNext() )
{
wxWindow* window = dynamic_cast<wxWindow*>(node->GetData());
wxTextEntry* te = dynamic_cast<wxTextEntry*>(window);
wxLogMessage("Window type = %s, is derived from wxTextEntry: %s",
window->GetClassInfo()->GetClassName(), te ? wxS("Yes") : wxS("No"));
if ( te && te != m_logCtrl )
{
wxLogMessage("Clearing value '%s'", te->GetValue());
te->Clear();
}
}
}
};
class MyApp : public wxApp
{
public:
bool OnInit()
{
MyDialog().ShowModal();
return false;
}
}; wxIMPLEMENT_APP(MyApp);
- textentry.png (16.55 KiB) Viewed 1105 times