void OnIdle( wxIdleEvent& event );
- wxCheckBox* m_cbUseAnim;
-
protected:
wxTextCtrl* m_logWin;
wxLog* m_logOld;
// IDs for the controls and the menu commands
enum
{
- ComboControl_Compare = wxID_HIGHEST,
+ ComboCtrl_Compare = wxID_HIGHEST,
// menu items
- ComboControl_Quit = wxID_EXIT,
+ ComboCtrl_Quit = wxID_EXIT,
// it is important for the id corresponding to the "About" command to have
// this standard value as otherwise it won't be handled properly under Mac
// (where it is special and put into the "Apple" menu)
- ComboControl_About = wxID_ABOUT
+ ComboCtrl_About = wxID_ABOUT
};
// ----------------------------------------------------------------------------
// simple menu events like this the static method is much simpler.
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_TEXT(wxID_ANY,MyFrame::OnComboBoxUpdate)
+ EVT_TEXT_ENTER(wxID_ANY,MyFrame::OnComboBoxUpdate)
EVT_COMBOBOX(wxID_ANY,MyFrame::OnComboBoxUpdate)
- EVT_MENU(ComboControl_Compare, MyFrame::OnShowComparison)
- EVT_MENU(ComboControl_Quit, MyFrame::OnQuit)
- EVT_MENU(ComboControl_About, MyFrame::OnAbout)
+ EVT_MENU(ComboCtrl_Compare, MyFrame::OnShowComparison)
+ EVT_MENU(ComboCtrl_Quit, MyFrame::OnQuit)
+ EVT_MENU(ComboCtrl_About, MyFrame::OnAbout)
EVT_IDLE(MyFrame::OnIdle)
END_EVENT_TABLE()
// 'Main program' equivalent: the program execution "starts" here
bool MyApp::OnInit()
{
+ if ( !wxApp::OnInit() )
+ return false;
+
// create the main application window
- MyFrame *frame = new MyFrame(_T("wxComboCtrl and wxOwnerDrawnComboBox Sample"));
+ MyFrame *frame = new MyFrame(wxT("wxComboCtrl and wxOwnerDrawnComboBox Sample"));
// and show it (the frames, unlike simple controls, are not shown when
// created initially)
virtual void Init()
{
}
+ virtual ~TreeCtrlComboPopup()
+ {
+ if (!m_isBeingDeleted)
+ {
+ wxMessageBox("error wxTreeCtrl::Destroy() was not called");
+ }
+ SendDestroyEvent();
+ }
virtual bool Create( wxWindow* parent )
{
return wxTreeCtrl::Create(parent,1,
wxPoint(0,0),wxDefaultSize,
- wxTR_HIDE_ROOT|wxTR_HAS_BUTTONS|
- wxTR_SINGLE|wxTR_LINES_AT_ROOT|
- wxSIMPLE_BORDER);
+ wxTR_DEFAULT_STYLE | wxTR_HIDE_ROOT | wxSIMPLE_BORDER );
}
virtual void OnShow()
END_EVENT_TABLE()
// ----------------------------------------------------------------------------
-// wxComboCtrl with custom popup animation
+// wxComboCtrl with custom popup animation, using wxWindow::ShowWithEffect().
// ----------------------------------------------------------------------------
class wxComboCtrlWithCustomPopupAnim : public wxComboCtrl
{
-public:
-
+protected:
virtual bool AnimateShow( const wxRect& rect, int WXUNUSED(flags) )
{
- MyFrame* myFrame = (MyFrame*) ::wxGetTopLevelParent(this);
-
- if ( !myFrame->m_cbUseAnim->GetValue() )
- return true;
-
- int width = rect.width;
- int height = rect.height;
- wxBitmap bitmap( width, height, -1 );
- wxScreenDC dc;
- wxMemoryDC memdc( bitmap );
- memdc.Blit( 0, 0, width, height, &dc, rect.x, rect.y );
- memdc.SelectObject(wxNullBitmap);
-
- wxLongLong tStart = ::wxGetLocalTimeMillis();
- const int delay = 300;
- const int resolution = 10;
-
- int center_x = rect.x + (width/2);
- int center_y = rect.y + (height/2);
-
- double d_height = (double) height;
-
- dc.SetPen( *wxBLACK_PEN );
- dc.SetBrush( *wxTRANSPARENT_BRUSH );
- for (;;)
- {
- wxLongLong t = ::wxGetLocalTimeMillis();
- int pos = (int) (t-tStart).GetLo();
- if ( pos > delay )
- break;
-
- int w = (((pos*256)/delay)*width)/256;
-
- double ratio = ((double)w / (double)width);
- int h = (int)(d_height * ratio);
- dc.DrawRectangle( center_x - w/2, center_y - h/2, w, h );
- wxMilliSleep( resolution );
- wxYield();
- dc.DrawBitmap( bitmap, rect.x, rect.y );
-
- if ( IsPopupWindowState(Hidden) )
- return true;
- }
-
+ wxWindow* win = GetPopupWindow();
+ win->SetSize(rect);
+ win->Raise(); // This is needed
+ win->ShowWithEffect(wxSHOW_EFFECT_BLEND);
return true;
}
-
-protected:
};
// ----------------------------------------------------------------------------
// the "About" item should be in the help menu
wxMenu *helpMenu = new wxMenu;
- helpMenu->Append(ComboControl_About, _T("&About...\tF1"), _T("Show about dialog"));
+ helpMenu->Append(ComboCtrl_About, wxT("&About...\tF1"), wxT("Show about dialog"));
- fileMenu->Append(ComboControl_Compare, _T("&Compare against wxComboBox..."),
- _T("Show some wxOwnerDrawnComboBoxes side-by-side with native wxComboBoxes."));
+ fileMenu->Append(ComboCtrl_Compare, wxT("&Compare against wxComboBox..."),
+ wxT("Show some wxOwnerDrawnComboBoxes side-by-side with native wxComboBoxes."));
fileMenu->AppendSeparator();
- fileMenu->Append(ComboControl_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
+ fileMenu->Append(ComboCtrl_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
// now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar();
- menuBar->Append(fileMenu, _T("&File"));
- menuBar->Append(helpMenu, _T("&Help"));
+ menuBar->Append(fileMenu, wxT("&File"));
+ menuBar->Append(helpMenu, wxT("&Help"));
// ... and attach this menu bar to the frame
SetMenuBar(menuBar);
wxPanel* panel = new wxPanel(this);
// Prepare log window right away since it shows EVT_TEXTs
- m_logWin = new wxTextCtrl( panel, 105, wxEmptyString, wxDefaultPosition,
- wxSize(-1,125), wxTE_MULTILINE|wxFULL_REPAINT_ON_RESIZE );
- m_logWin->SetEditable(false);
- wxLogTextCtrl* logger = new wxLogTextCtrl( m_logWin );
- m_logOld = logger->SetActiveTarget( logger );
- logger->SetTimestamp( NULL );
+ m_logWin = new wxTextCtrl(panel, 105, wxEmptyString,
+ wxDefaultPosition,
+ wxSize(-1, 125),
+ wxTE_MULTILINE);
+ wxLogTextCtrl* logger = new wxLogTextCtrl(m_logWin);
+ m_logOld = logger->SetActiveTarget(logger);
+ logger->DisableTimestamp();
topSizer = new wxBoxSizer( wxVERTICAL );
//
rowSizer = new wxBoxSizer( wxHORIZONTAL );
- rowSizer->Add( new wxStaticText(panel,wxID_ANY,wxT("List View wxComboCtrl:")), 1,
- wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
- rowSizer->Add( new wxStaticText(panel,wxID_ANY,wxT("Tree Ctrl wxComboControl:")), 1,
+ rowSizer->Add( new wxStaticText(panel,
+ wxID_ANY,
+ "List View wxComboCtrl (custom animation):"),
+ 1, wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
+ rowSizer->Add( new wxStaticText(panel,wxID_ANY,wxT("Tree Ctrl wxComboCtrl:")), 1,
wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );
rowSizer = new wxBoxSizer( wxHORIZONTAL );
cc = new wxComboCtrlWithCustomPopupAnim();
+
+ // Let's set a custom style for the contained wxTextCtrl. We need to
+ // use two-step creation for it to work properly.
+ cc->SetTextCtrlStyle(wxTE_RIGHT);
+
cc->Create(panel, wxID_ANY, wxEmptyString);
// Make sure we use popup that allows focusing the listview.
colSizer = new wxBoxSizer( wxVERTICAL );
- wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox(panel,
- wxID_ANY,
- wxT("Options")),
- wxVERTICAL );
-
- m_cbUseAnim = new wxCheckBox(panel, wxID_ANY, wxT("Custom popup animation for ListView wxComboCtrl"));
- m_cbUseAnim->SetValue(true);
- sbSizer->Add( m_cbUseAnim, 0, wxALL, 3 );
-
- colSizer->Add( sbSizer, 0, wxEXPAND|wxALL, 3 );
colSizer->AddSpacer(8);
colSizer->Add( new wxStaticText(panel, wxID_ANY, wxT("Log Messages:")), 0, wxTOP|wxLEFT, 3 );
colSizer->Add( m_logWin, 1, wxEXPAND|wxALL, 3 );
return;
if ( event.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED )
+ {
wxLogDebug(wxT("EVT_COMBOBOX(id=%i,selection=%i)"),event.GetId(),event.GetSelection());
+ }
else if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED )
+ {
wxLogDebug(wxT("EVT_TEXT(id=%i,string=\"%s\")"),event.GetId(),event.GetString().c_str());
+ }
+ else if ( event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER )
+ {
+ wxLogDebug("EVT_TEXT_ENTER(id=%i,string=\"%s\")",
+ event.GetId(), event.GetString().c_str());
+ }
}
void MyFrame::OnShowComparison( wxCommandEvent& WXUNUSED(event) )
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxMessageBox(wxString::Format(
- _T("Welcome to %s!\n")
- _T("\n")
- _T("This is the wxWidgets wxComboCtrl and wxOwnerDrawnComboBox sample\n")
- _T("running under %s."),
+ wxT("Welcome to %s!\n")
+ wxT("\n")
+ wxT("This is the wxWidgets wxComboCtrl and wxOwnerDrawnComboBox sample\n")
+ wxT("running under %s."),
wxVERSION_STRING,
wxGetOsDescription().c_str()
),
- _T("About wxComboCtrl sample"),
+ wxT("About wxComboCtrl sample"),
wxOK | wxICON_INFORMATION,
this);
}