2006-05-08 19:42:45 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: combo.cpp
|
2006-05-16 18:57:40 -04:00
|
|
|
// Purpose: wxComboCtrl sample
|
2006-05-08 19:42:45 -04:00
|
|
|
// Author: Jaakko Salli
|
|
|
|
// Modified by:
|
|
|
|
// Created: Apr-30-2006
|
|
|
|
// Copyright: (c) Jaakko Salli
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// for all others, include the necessary headers (this file is usually all you
|
|
|
|
// need because it includes almost all "standard" wxWidgets headers)
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
2006-05-16 18:57:40 -04:00
|
|
|
#if !wxUSE_COMBOCTRL
|
|
|
|
#error "Please set wxUSE_COMBOCTRL to 1 and rebuild the library."
|
2006-05-08 19:42:45 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/image.h"
|
|
|
|
|
|
|
|
#include "wx/combo.h"
|
|
|
|
#include "wx/odcombo.h"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// resources
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2015-11-28 17:54:31 -05:00
|
|
|
// the application icon (under Windows it is in resources and even
|
2006-05-08 19:42:45 -04:00
|
|
|
// though we could still include the XPM here it would be unused)
|
2012-03-03 19:28:58 -05:00
|
|
|
#ifndef wxHAS_IMAGES_IN_RESOURCES
|
2006-05-08 19:42:45 -04:00
|
|
|
#include "../sample.xpm"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// private classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Define a new application type, each program should derive a class from wxApp
|
|
|
|
class MyApp : public wxApp
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// override base class virtuals
|
|
|
|
// ----------------------------
|
|
|
|
|
|
|
|
// this one is called on application startup and is a good place for the app
|
|
|
|
// initialization (doing it here and not in the ctor allows to have an error
|
|
|
|
// return: if OnInit() returns false, the application terminates)
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual bool OnInit() wxOVERRIDE;
|
2006-05-08 19:42:45 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Define a new frame type: this is going to be our main frame
|
|
|
|
class MyFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctor and dtor
|
|
|
|
MyFrame(const wxString& title);
|
|
|
|
~MyFrame();
|
|
|
|
|
|
|
|
// event handlers (these functions should _not_ be virtual)
|
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
|
|
|
|
2006-07-04 04:58:06 -04:00
|
|
|
void OnShowComparison( wxCommandEvent& event );
|
|
|
|
|
2006-05-16 18:57:40 -04:00
|
|
|
// log wxComboCtrl events
|
2006-05-08 19:42:45 -04:00
|
|
|
void OnComboBoxUpdate( wxCommandEvent& event );
|
|
|
|
|
2006-10-22 16:25:08 -04:00
|
|
|
void OnIdle( wxIdleEvent& event );
|
|
|
|
|
2006-10-25 15:48:46 -04:00
|
|
|
|
2006-05-08 19:42:45 -04:00
|
|
|
protected:
|
|
|
|
wxTextCtrl* m_logWin;
|
|
|
|
wxLog* m_logOld;
|
|
|
|
|
2006-07-04 04:58:06 -04:00
|
|
|
// Common list of items for all dialogs.
|
|
|
|
wxArrayString m_arrItems;
|
|
|
|
|
2006-05-08 19:42:45 -04:00
|
|
|
private:
|
|
|
|
// any class wishing to process wxWidgets events must use this macro
|
2014-03-30 03:07:55 -04:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2006-05-08 19:42:45 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// IDs for the controls and the menu commands
|
|
|
|
enum
|
|
|
|
{
|
2010-05-26 11:15:28 -04:00
|
|
|
ComboCtrl_Compare = wxID_HIGHEST,
|
2006-07-04 04:58:06 -04:00
|
|
|
|
2006-05-08 19:42:45 -04:00
|
|
|
// menu items
|
2010-05-26 11:15:28 -04:00
|
|
|
ComboCtrl_Quit = wxID_EXIT,
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
// 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)
|
2010-05-26 11:15:28 -04:00
|
|
|
ComboCtrl_About = wxID_ABOUT
|
2006-05-08 19:42:45 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event tables and other macros for wxWidgets
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// the event tables connect the wxWidgets events with the functions (event
|
|
|
|
// handlers) which process them. It can be also done at run-time, but for the
|
|
|
|
// simple menu events like this the static method is much simpler.
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
2006-05-08 19:42:45 -04:00
|
|
|
EVT_TEXT(wxID_ANY,MyFrame::OnComboBoxUpdate)
|
2011-04-18 05:58:27 -04:00
|
|
|
EVT_TEXT_ENTER(wxID_ANY,MyFrame::OnComboBoxUpdate)
|
2006-05-08 19:42:45 -04:00
|
|
|
EVT_COMBOBOX(wxID_ANY,MyFrame::OnComboBoxUpdate)
|
|
|
|
|
2010-05-26 11:15:28 -04:00
|
|
|
EVT_MENU(ComboCtrl_Compare, MyFrame::OnShowComparison)
|
|
|
|
EVT_MENU(ComboCtrl_Quit, MyFrame::OnQuit)
|
|
|
|
EVT_MENU(ComboCtrl_About, MyFrame::OnAbout)
|
2006-10-22 16:25:08 -04:00
|
|
|
|
|
|
|
EVT_IDLE(MyFrame::OnIdle)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
// Create a new application object: this macro will allow wxWidgets to create
|
|
|
|
// the application object during program execution (it's better than using a
|
|
|
|
// static object for many reasons) and also implements the accessor function
|
|
|
|
// wxGetApp() which will return the reference of the right type (i.e. MyApp and
|
|
|
|
// not wxApp)
|
2015-04-23 07:49:01 -04:00
|
|
|
wxIMPLEMENT_APP(MyApp);
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// the application class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// 'Main program' equivalent: the program execution "starts" here
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
2007-02-03 19:34:18 -05:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
2006-05-08 19:42:45 -04:00
|
|
|
// create the main application window
|
2009-07-23 16:30:22 -04:00
|
|
|
MyFrame *frame = new MyFrame(wxT("wxComboCtrl and wxOwnerDrawnComboBox Sample"));
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
// and show it (the frames, unlike simple controls, are not shown when
|
|
|
|
// created initially)
|
|
|
|
frame->Show(true);
|
|
|
|
|
|
|
|
// success: wxApp::OnRun() will be called which will enter the main message
|
|
|
|
// loop and the application will run. If we returned false here, the
|
|
|
|
// application would exit immediately.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-04 04:58:06 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxOwnerDrawnComboBox with custom paint list items
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxPenStyleComboBox : public wxOwnerDrawnComboBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void OnDrawItem( wxDC& dc,
|
|
|
|
const wxRect& rect,
|
|
|
|
int item,
|
2014-03-29 20:02:23 -04:00
|
|
|
int flags ) const wxOVERRIDE
|
2006-07-04 04:58:06 -04:00
|
|
|
{
|
|
|
|
if ( item == wxNOT_FOUND )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxRect r(rect);
|
|
|
|
r.Deflate(3);
|
|
|
|
r.height -= 2;
|
|
|
|
|
2012-12-01 17:34:07 -05:00
|
|
|
wxPenStyle penStyle = wxPENSTYLE_SOLID;
|
2006-07-04 04:58:06 -04:00
|
|
|
if ( item == 1 )
|
2012-12-01 17:34:07 -05:00
|
|
|
penStyle = wxPENSTYLE_TRANSPARENT;
|
2006-07-04 04:58:06 -04:00
|
|
|
else if ( item == 2 )
|
2012-12-01 17:34:07 -05:00
|
|
|
penStyle = wxPENSTYLE_DOT;
|
2006-07-04 04:58:06 -04:00
|
|
|
else if ( item == 3 )
|
2012-12-01 17:34:07 -05:00
|
|
|
penStyle = wxPENSTYLE_LONG_DASH;
|
2006-07-04 04:58:06 -04:00
|
|
|
else if ( item == 4 )
|
2012-12-01 17:34:07 -05:00
|
|
|
penStyle = wxPENSTYLE_SHORT_DASH;
|
2006-07-04 04:58:06 -04:00
|
|
|
else if ( item == 5 )
|
2012-12-01 17:34:07 -05:00
|
|
|
penStyle = wxPENSTYLE_DOT_DASH;
|
2006-07-04 04:58:06 -04:00
|
|
|
else if ( item == 6 )
|
2012-12-01 17:34:07 -05:00
|
|
|
penStyle = wxPENSTYLE_BDIAGONAL_HATCH;
|
2006-07-04 04:58:06 -04:00
|
|
|
else if ( item == 7 )
|
2012-12-01 17:34:07 -05:00
|
|
|
penStyle = wxPENSTYLE_CROSSDIAG_HATCH;
|
2006-07-04 04:58:06 -04:00
|
|
|
else if ( item == 8 )
|
2012-12-01 17:34:07 -05:00
|
|
|
penStyle = wxPENSTYLE_FDIAGONAL_HATCH;
|
2006-07-04 04:58:06 -04:00
|
|
|
else if ( item == 9 )
|
2012-12-01 17:34:07 -05:00
|
|
|
penStyle = wxPENSTYLE_CROSS_HATCH;
|
2006-07-04 04:58:06 -04:00
|
|
|
else if ( item == 10 )
|
2012-12-01 17:34:07 -05:00
|
|
|
penStyle = wxPENSTYLE_HORIZONTAL_HATCH;
|
2006-07-04 04:58:06 -04:00
|
|
|
else if ( item == 11 )
|
2012-12-01 17:34:07 -05:00
|
|
|
penStyle = wxPENSTYLE_VERTICAL_HATCH;
|
2006-07-04 04:58:06 -04:00
|
|
|
|
|
|
|
wxPen pen( dc.GetTextForeground(), 3, penStyle );
|
|
|
|
|
|
|
|
// Get text colour as pen colour
|
|
|
|
dc.SetPen( pen );
|
|
|
|
|
|
|
|
if ( !(flags & wxODCB_PAINTING_CONTROL) )
|
|
|
|
{
|
|
|
|
dc.DrawText(GetString( item ),
|
|
|
|
r.x + 3,
|
|
|
|
(r.y + 0) + ( (r.height/2) - dc.GetCharHeight() )/2
|
|
|
|
);
|
|
|
|
|
|
|
|
dc.DrawLine( r.x+5, r.y+((r.height/4)*3), r.x+r.width - 5, r.y+((r.height/4)*3) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dc.DrawLine( r.x+5, r.y+r.height/2, r.x+r.width - 5, r.y+r.height/2 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnDrawBackground( wxDC& dc, const wxRect& rect,
|
2014-03-29 20:02:23 -04:00
|
|
|
int item, int flags ) const wxOVERRIDE
|
2006-07-04 04:58:06 -04:00
|
|
|
{
|
|
|
|
|
2006-07-20 10:37:47 -04:00
|
|
|
// If item is selected or even, or we are painting the
|
|
|
|
// combo control itself, use the default rendering.
|
2006-09-19 13:16:50 -04:00
|
|
|
if ( (flags & (wxODCB_PAINTING_CONTROL|wxODCB_PAINTING_SELECTED)) ||
|
2006-07-04 04:58:06 -04:00
|
|
|
(item & 1) == 0 )
|
|
|
|
{
|
|
|
|
wxOwnerDrawnComboBox::OnDrawBackground(dc,rect,item,flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, draw every other background with different colour.
|
|
|
|
wxColour bgCol(240,240,250);
|
|
|
|
dc.SetBrush(wxBrush(bgCol));
|
|
|
|
dc.SetPen(wxPen(bgCol));
|
|
|
|
dc.DrawRectangle(rect);
|
|
|
|
}
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxCoord OnMeasureItem( size_t item ) const wxOVERRIDE
|
2006-07-04 04:58:06 -04:00
|
|
|
{
|
|
|
|
// Simply demonstrate the ability to have variable-height items
|
|
|
|
if ( item & 1 )
|
|
|
|
return 36;
|
|
|
|
else
|
|
|
|
return 24;
|
|
|
|
}
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxCoord OnMeasureItemWidth( size_t WXUNUSED(item) ) const wxOVERRIDE
|
2006-07-04 04:58:06 -04:00
|
|
|
{
|
|
|
|
return -1; // default - will be measured from text width
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-05-08 19:42:45 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxListView Custom popup interface
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include <wx/listctrl.h>
|
|
|
|
|
|
|
|
class ListViewComboPopup : public wxListView, public wxComboPopup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void Init() wxOVERRIDE
|
2006-05-09 12:18:19 -04:00
|
|
|
{
|
|
|
|
m_value = -1;
|
|
|
|
m_itemHere = -1; // hot item in list
|
|
|
|
}
|
2006-05-08 19:42:45 -04:00
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual bool Create( wxWindow* parent ) wxOVERRIDE
|
2006-05-08 19:42:45 -04:00
|
|
|
{
|
|
|
|
return wxListView::Create(parent,1,
|
|
|
|
wxPoint(0,0),wxDefaultSize,
|
|
|
|
wxLC_LIST|wxLC_SINGLE_SEL|
|
|
|
|
wxLC_SORT_ASCENDING|wxSIMPLE_BORDER);
|
|
|
|
}
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxWindow *GetControl() wxOVERRIDE { return this; }
|
2006-05-08 19:42:45 -04:00
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void SetStringValue( const wxString& s ) wxOVERRIDE
|
2006-05-08 19:42:45 -04:00
|
|
|
{
|
|
|
|
int n = wxListView::FindItem(-1,s);
|
|
|
|
if ( n >= 0 && n < GetItemCount() )
|
|
|
|
wxListView::Select(n);
|
|
|
|
}
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxString GetStringValue() const wxOVERRIDE
|
2006-05-08 19:42:45 -04:00
|
|
|
{
|
|
|
|
if ( m_value >= 0 )
|
|
|
|
return wxListView::GetItemText(m_value);
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Popup event handlers
|
|
|
|
//
|
|
|
|
|
|
|
|
// Mouse hot-tracking
|
|
|
|
void OnMouseMove(wxMouseEvent& event)
|
|
|
|
{
|
|
|
|
// Move selection to cursor if it is inside the popup
|
|
|
|
|
|
|
|
int resFlags;
|
|
|
|
int itemHere = HitTest(event.GetPosition(),resFlags);
|
|
|
|
if ( itemHere >= 0 )
|
|
|
|
{
|
|
|
|
wxListView::Select(itemHere,true);
|
|
|
|
m_itemHere = itemHere;
|
|
|
|
}
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
// On mouse left, set the value and close the popup
|
|
|
|
void OnMouseClick(wxMouseEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
m_value = m_itemHere;
|
|
|
|
// TODO: Send event
|
|
|
|
Dismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Utilies for item manipulation
|
|
|
|
//
|
|
|
|
|
|
|
|
void AddSelection( const wxString& selstr )
|
|
|
|
{
|
|
|
|
wxListView::InsertItem(GetItemCount(),selstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
int m_value; // current item index
|
|
|
|
int m_itemHere; // hot item in popup
|
|
|
|
|
|
|
|
private:
|
2014-03-30 03:07:55 -04:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2006-05-08 19:42:45 -04:00
|
|
|
};
|
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(ListViewComboPopup, wxListView)
|
2006-05-08 19:42:45 -04:00
|
|
|
EVT_MOTION(ListViewComboPopup::OnMouseMove)
|
|
|
|
// NOTE: Left down event is used instead of left up right now
|
|
|
|
// since MSW wxListCtrl doesn't seem to emit left ups
|
|
|
|
// consistently.
|
|
|
|
EVT_LEFT_DOWN(ListViewComboPopup::OnMouseClick)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxTreeCtrl Custom popup interface
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include <wx/treectrl.h>
|
|
|
|
|
|
|
|
class TreeCtrlComboPopup : public wxTreeCtrl, public wxComboPopup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void Init() wxOVERRIDE
|
2006-05-09 12:18:19 -04:00
|
|
|
{
|
|
|
|
}
|
2011-04-18 05:58:27 -04:00
|
|
|
virtual ~TreeCtrlComboPopup()
|
|
|
|
{
|
|
|
|
if (!m_isBeingDeleted)
|
|
|
|
{
|
|
|
|
wxMessageBox("error wxTreeCtrl::Destroy() was not called");
|
|
|
|
}
|
|
|
|
SendDestroyEvent();
|
|
|
|
}
|
2006-05-08 19:42:45 -04:00
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual bool Create( wxWindow* parent ) wxOVERRIDE
|
2006-05-08 19:42:45 -04:00
|
|
|
{
|
|
|
|
return wxTreeCtrl::Create(parent,1,
|
|
|
|
wxPoint(0,0),wxDefaultSize,
|
2008-04-15 05:06:11 -04:00
|
|
|
wxTR_DEFAULT_STYLE | wxTR_HIDE_ROOT | wxSIMPLE_BORDER );
|
2006-05-08 19:42:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnShow()
|
|
|
|
{
|
|
|
|
// make sure selected item is visible
|
|
|
|
if ( m_value.IsOk() )
|
|
|
|
EnsureVisible(m_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual wxSize GetAdjustedSize( int minWidth,
|
|
|
|
int WXUNUSED(prefHeight),
|
2014-03-29 20:02:23 -04:00
|
|
|
int maxHeight ) wxOVERRIDE
|
2006-05-08 19:42:45 -04:00
|
|
|
{
|
|
|
|
return wxSize(wxMax(300,minWidth),wxMin(250,maxHeight));
|
|
|
|
}
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxWindow *GetControl() wxOVERRIDE { return this; }
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
// Needed by SetStringValue
|
|
|
|
wxTreeItemId FindItemByText( wxTreeItemId parent, const wxString& text )
|
|
|
|
{
|
|
|
|
wxTreeItemIdValue cookie;
|
|
|
|
wxTreeItemId child = GetFirstChild(parent,cookie);
|
|
|
|
while ( child.IsOk() )
|
|
|
|
{
|
|
|
|
if ( GetItemText(child) == text )
|
|
|
|
{
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
if ( ItemHasChildren(child) )
|
|
|
|
{
|
|
|
|
wxTreeItemId found = FindItemByText(child,text);
|
|
|
|
if ( found.IsOk() )
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
child = GetNextChild(parent,cookie);
|
|
|
|
}
|
|
|
|
return wxTreeItemId();
|
|
|
|
}
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void SetStringValue( const wxString& s ) wxOVERRIDE
|
2006-05-08 19:42:45 -04:00
|
|
|
{
|
|
|
|
wxTreeItemId root = GetRootItem();
|
|
|
|
if ( !root.IsOk() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxTreeItemId found = FindItemByText(root,s);
|
|
|
|
if ( found.IsOk() )
|
|
|
|
{
|
|
|
|
m_value = m_itemHere = found;
|
|
|
|
wxTreeCtrl::SelectItem(found);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxString GetStringValue() const wxOVERRIDE
|
2006-05-08 19:42:45 -04:00
|
|
|
{
|
|
|
|
if ( m_value.IsOk() )
|
|
|
|
return wxTreeCtrl::GetItemText(m_value);
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Popup event handlers
|
|
|
|
//
|
|
|
|
|
|
|
|
// Mouse hot-tracking
|
|
|
|
void OnMouseMove(wxMouseEvent& event)
|
|
|
|
{
|
|
|
|
int resFlags;
|
|
|
|
wxTreeItemId itemHere = HitTest(event.GetPosition(),resFlags);
|
|
|
|
if ( itemHere.IsOk() && (resFlags & wxTREE_HITTEST_ONITEMLABEL) )
|
|
|
|
{
|
|
|
|
wxTreeCtrl::SelectItem(itemHere,true);
|
|
|
|
m_itemHere = itemHere;
|
|
|
|
}
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
// On mouse left, set the value and close the popup
|
|
|
|
void OnMouseClick(wxMouseEvent& event)
|
|
|
|
{
|
|
|
|
int resFlags;
|
|
|
|
wxTreeItemId itemHere = HitTest(event.GetPosition(),resFlags);
|
|
|
|
if ( itemHere.IsOk() && (resFlags & wxTREE_HITTEST_ONITEMLABEL) )
|
|
|
|
{
|
|
|
|
m_itemHere = itemHere;
|
|
|
|
m_value = itemHere;
|
|
|
|
Dismiss();
|
|
|
|
// TODO: Send event
|
|
|
|
}
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
wxTreeItemId m_value; // current item index
|
|
|
|
wxTreeItemId m_itemHere; // hot item in popup
|
|
|
|
|
|
|
|
private:
|
2014-03-30 03:07:55 -04:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2006-05-08 19:42:45 -04:00
|
|
|
};
|
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(TreeCtrlComboPopup, wxTreeCtrl)
|
2006-05-08 19:42:45 -04:00
|
|
|
EVT_MOTION(TreeCtrlComboPopup::OnMouseMove)
|
|
|
|
// NOTE: Left down event is used instead of left up right now
|
|
|
|
// since MSW wxTreeCtrl doesn't seem to emit left ups
|
|
|
|
// consistently.
|
|
|
|
EVT_LEFT_DOWN(TreeCtrlComboPopup::OnMouseClick)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
2006-05-08 19:42:45 -04:00
|
|
|
|
2006-10-25 15:48:46 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
2010-06-06 05:15:20 -04:00
|
|
|
// wxComboCtrl with custom popup animation, using wxWindow::ShowWithEffect().
|
2006-10-25 15:48:46 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxComboCtrlWithCustomPopupAnim : public wxComboCtrl
|
|
|
|
{
|
2010-06-06 05:15:20 -04:00
|
|
|
protected:
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual bool AnimateShow( const wxRect& rect, int WXUNUSED(flags) ) wxOVERRIDE
|
2006-10-26 16:35:57 -04:00
|
|
|
{
|
2010-06-06 05:15:20 -04:00
|
|
|
wxWindow* win = GetPopupWindow();
|
|
|
|
win->SetSize(rect);
|
|
|
|
win->Raise(); // This is needed
|
2010-06-06 08:35:03 -04:00
|
|
|
win->ShowWithEffect(wxSHOW_EFFECT_BLEND);
|
2010-06-06 05:15:20 -04:00
|
|
|
return true;
|
2006-10-25 15:48:46 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-05-08 19:42:45 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
2006-05-16 18:57:40 -04:00
|
|
|
// wxComboCtrl with entirely custom button action (opens file dialog)
|
2006-05-08 19:42:45 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2006-05-16 18:57:40 -04:00
|
|
|
class wxFileSelectorCombo : public wxComboCtrl
|
2006-05-08 19:42:45 -04:00
|
|
|
{
|
|
|
|
public:
|
2006-05-16 18:57:40 -04:00
|
|
|
wxFileSelectorCombo() : wxComboCtrl() { Init(); }
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
wxFileSelectorCombo(wxWindow *parent,
|
|
|
|
wxWindowID id = wxID_ANY,
|
|
|
|
const wxString& value = wxEmptyString,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
|
|
|
const wxString& name = wxComboBoxNameStr)
|
2006-05-16 18:57:40 -04:00
|
|
|
: wxComboCtrl()
|
2006-05-08 19:42:45 -04:00
|
|
|
{
|
|
|
|
Init();
|
|
|
|
Create(parent,id,value,
|
|
|
|
pos,size,
|
|
|
|
// Style flag wxCC_STD_BUTTON makes the button
|
|
|
|
// behave more like a standard push button.
|
|
|
|
style | wxCC_STD_BUTTON,
|
|
|
|
validator,name);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Prepare custom button bitmap (just '...' text)
|
|
|
|
wxMemoryDC dc;
|
|
|
|
wxBitmap bmp(12,16);
|
|
|
|
dc.SelectObject(bmp);
|
|
|
|
|
|
|
|
// Draw transparent background
|
|
|
|
wxColour magic(255,0,255);
|
|
|
|
wxBrush magicBrush(magic);
|
|
|
|
dc.SetBrush( magicBrush );
|
|
|
|
dc.SetPen( *wxTRANSPARENT_PEN );
|
|
|
|
dc.DrawRectangle(0,0,bmp.GetWidth(),bmp.GetHeight());
|
|
|
|
|
|
|
|
// Draw text
|
|
|
|
wxString str = wxT("...");
|
|
|
|
int w,h;
|
|
|
|
dc.GetTextExtent(str, &w, &h, 0, 0);
|
|
|
|
dc.DrawText(str, (bmp.GetWidth()-w)/2, (bmp.GetHeight()-h)/2);
|
|
|
|
|
|
|
|
dc.SelectObject( wxNullBitmap );
|
|
|
|
|
|
|
|
// Finalize transparency with a mask
|
|
|
|
wxMask *mask = new wxMask( bmp, magic );
|
|
|
|
bmp.SetMask( mask );
|
|
|
|
|
|
|
|
SetButtonBitmaps(bmp,true);
|
|
|
|
}
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void OnButtonClick() wxOVERRIDE
|
2006-05-08 19:42:45 -04:00
|
|
|
{
|
|
|
|
// Show standard wxFileDialog on button click
|
|
|
|
|
|
|
|
wxFileDialog dlg(this,
|
|
|
|
wxT("Choose File"),
|
|
|
|
wxEmptyString,
|
|
|
|
GetValue(),
|
|
|
|
wxT("All files (*.*)|*.*"),
|
2006-05-28 19:32:12 -04:00
|
|
|
wxFD_OPEN);
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
if ( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
SetValue(dlg.GetPath());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-17 03:22:22 -04:00
|
|
|
// Implement empty DoSetPopupControl to prevent assertion failure.
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void DoSetPopupControl(wxComboPopup* WXUNUSED(popup)) wxOVERRIDE
|
2006-07-17 03:22:22 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-05-08 19:42:45 -04:00
|
|
|
private:
|
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
// Initialize member variables here
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// main frame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// frame constructor
|
|
|
|
MyFrame::MyFrame(const wxString& title)
|
|
|
|
: wxFrame(NULL, wxID_ANY, title)
|
|
|
|
{
|
|
|
|
wxBoxSizer* topSizer;
|
|
|
|
wxBoxSizer* topRowSizer;
|
|
|
|
wxBoxSizer* colSizer;
|
|
|
|
wxBoxSizer* rowSizer;
|
|
|
|
|
|
|
|
// set the frame icon
|
|
|
|
SetIcon(wxICON(sample));
|
|
|
|
|
|
|
|
#if wxUSE_MENUS
|
|
|
|
// create a menu bar
|
|
|
|
wxMenu *fileMenu = new wxMenu;
|
|
|
|
|
|
|
|
// the "About" item should be in the help menu
|
|
|
|
wxMenu *helpMenu = new wxMenu;
|
2012-01-20 11:51:09 -05:00
|
|
|
helpMenu->Append(ComboCtrl_About, wxT("&About\tF1"), wxT("Show about dialog"));
|
2006-05-08 19:42:45 -04:00
|
|
|
|
2010-05-26 11:15:28 -04:00
|
|
|
fileMenu->Append(ComboCtrl_Compare, wxT("&Compare against wxComboBox..."),
|
2009-07-23 16:30:22 -04:00
|
|
|
wxT("Show some wxOwnerDrawnComboBoxes side-by-side with native wxComboBoxes."));
|
2006-07-04 04:58:06 -04:00
|
|
|
fileMenu->AppendSeparator();
|
2010-05-26 11:15:28 -04:00
|
|
|
fileMenu->Append(ComboCtrl_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
// now append the freshly created menu to the menu bar...
|
|
|
|
wxMenuBar *menuBar = new wxMenuBar();
|
2009-07-23 16:30:22 -04:00
|
|
|
menuBar->Append(fileMenu, wxT("&File"));
|
|
|
|
menuBar->Append(helpMenu, wxT("&Help"));
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
// ... and attach this menu bar to the frame
|
|
|
|
SetMenuBar(menuBar);
|
|
|
|
#endif // wxUSE_MENUS
|
|
|
|
|
|
|
|
wxPanel* panel = new wxPanel(this);
|
|
|
|
|
|
|
|
// Prepare log window right away since it shows EVT_TEXTs
|
2009-10-13 10:34:47 -04:00
|
|
|
m_logWin = new wxTextCtrl(panel, 105, wxEmptyString,
|
|
|
|
wxDefaultPosition,
|
|
|
|
wxSize(-1, 125),
|
|
|
|
wxTE_MULTILINE);
|
|
|
|
wxLogTextCtrl* logger = new wxLogTextCtrl(m_logWin);
|
|
|
|
m_logOld = logger->SetActiveTarget(logger);
|
2007-06-27 16:49:19 -04:00
|
|
|
logger->DisableTimestamp();
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
|
|
|
|
topSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
|
|
|
|
topRowSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
|
|
|
|
colSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
|
|
|
|
|
2006-05-16 18:57:40 -04:00
|
|
|
wxComboCtrl* cc;
|
2006-09-19 13:29:45 -04:00
|
|
|
wxGenericComboCtrl* gcc;
|
2006-05-08 19:42:45 -04:00
|
|
|
wxOwnerDrawnComboBox* odc;
|
|
|
|
|
|
|
|
// Create common strings array
|
2006-07-04 04:58:06 -04:00
|
|
|
m_arrItems.Add( wxT("Solid") );
|
|
|
|
m_arrItems.Add( wxT("Transparent") );
|
|
|
|
m_arrItems.Add( wxT("Dot") );
|
|
|
|
m_arrItems.Add( wxT("Long Dash") );
|
|
|
|
m_arrItems.Add( wxT("Short Dash") );
|
|
|
|
m_arrItems.Add( wxT("Dot Dash") );
|
|
|
|
m_arrItems.Add( wxT("Backward Diagonal Hatch") );
|
|
|
|
m_arrItems.Add( wxT("Cross-diagonal Hatch") );
|
|
|
|
m_arrItems.Add( wxT("Forward Diagonal Hatch") );
|
|
|
|
m_arrItems.Add( wxT("Cross Hatch") );
|
|
|
|
m_arrItems.Add( wxT("Horizontal Hatch") );
|
|
|
|
m_arrItems.Add( wxT("Vertical Hatch") );
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
|
|
|
|
//
|
2006-07-04 04:58:06 -04:00
|
|
|
// Create pen selector ODComboBox with owner-drawn items
|
2006-05-08 19:42:45 -04:00
|
|
|
//
|
2006-07-04 04:58:06 -04:00
|
|
|
rowSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
rowSizer->Add( new wxStaticText(panel,wxID_ANY,
|
|
|
|
wxT("OwnerDrawnComboBox with owner-drawn items:")), 1,
|
|
|
|
wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
|
|
|
|
colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );
|
2006-05-08 19:42:45 -04:00
|
|
|
|
2006-07-04 04:58:06 -04:00
|
|
|
rowSizer = new wxBoxSizer( wxHORIZONTAL );
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
|
2006-07-04 04:58:06 -04:00
|
|
|
// When defining derivative class for callbacks, we need
|
|
|
|
// to use two-stage creation (or redefine the common wx
|
|
|
|
// constructor).
|
|
|
|
odc = new wxPenStyleComboBox();
|
|
|
|
odc->Create(panel,wxID_ANY,wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
m_arrItems,
|
|
|
|
wxCB_READONLY //wxNO_BORDER | wxCB_READONLY
|
|
|
|
);
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
|
2006-07-04 04:58:06 -04:00
|
|
|
odc->SetSelection(0);
|
2006-05-08 19:42:45 -04:00
|
|
|
|
2006-07-04 04:58:06 -04:00
|
|
|
rowSizer->Add( odc, 1, wxALIGN_CENTER_VERTICAL|wxALL, 4 );
|
|
|
|
rowSizer->AddStretchSpacer(1);
|
|
|
|
colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2006-07-04 04:58:06 -04:00
|
|
|
// Same but with changed button position
|
2006-05-08 19:42:45 -04:00
|
|
|
//
|
2006-07-04 04:58:06 -04:00
|
|
|
rowSizer = new wxBoxSizer( wxHORIZONTAL );
|
2006-05-08 19:42:45 -04:00
|
|
|
rowSizer->Add( new wxStaticText(panel,wxID_ANY,
|
2006-07-04 04:58:06 -04:00
|
|
|
wxT("OwnerDrawnComboBox with owner-drawn items and button on the left:")), 1,
|
2006-05-08 19:42:45 -04:00
|
|
|
wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
|
|
|
|
colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );
|
|
|
|
|
2006-07-04 04:58:06 -04:00
|
|
|
rowSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
// When defining derivative class for callbacks, we need
|
|
|
|
// to use two-stage creation (or redefine the common wx
|
|
|
|
// constructor).
|
2006-06-14 14:38:47 -04:00
|
|
|
odc = new wxPenStyleComboBox();
|
|
|
|
odc->Create(panel,wxID_ANY,wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
2006-07-04 04:58:06 -04:00
|
|
|
m_arrItems,
|
2006-06-14 14:38:47 -04:00
|
|
|
wxCB_READONLY //wxNO_BORDER | wxCB_READONLY
|
|
|
|
);
|
2006-05-08 19:42:45 -04:00
|
|
|
|
2006-07-04 04:58:06 -04:00
|
|
|
|
2006-05-08 19:42:45 -04:00
|
|
|
odc->SetSelection(0);
|
2006-07-17 04:45:12 -04:00
|
|
|
|
|
|
|
// Use button size that is slightly smaller than the default.
|
|
|
|
wxSize butSize = odc->GetButtonSize();
|
|
|
|
odc->SetButtonPosition(butSize.x - 2, // button width
|
|
|
|
butSize.y - 6, // button height
|
2006-05-08 19:42:45 -04:00
|
|
|
wxLEFT, // side
|
|
|
|
2 // horizontal spacing
|
|
|
|
);
|
|
|
|
|
|
|
|
rowSizer->Add( odc, 1, wxALIGN_CENTER_VERTICAL|wxALL, 4 );
|
|
|
|
rowSizer->AddStretchSpacer(1);
|
|
|
|
colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2006-05-16 18:57:40 -04:00
|
|
|
// List View wxComboCtrl
|
2006-05-08 19:42:45 -04:00
|
|
|
//
|
|
|
|
|
2006-07-04 04:58:06 -04:00
|
|
|
rowSizer = new wxBoxSizer( wxHORIZONTAL );
|
2010-06-06 08:35:03 -04:00
|
|
|
rowSizer->Add( new wxStaticText(panel,
|
|
|
|
wxID_ANY,
|
|
|
|
"List View wxComboCtrl (custom animation):"),
|
|
|
|
1, wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
|
2010-05-26 11:15:28 -04:00
|
|
|
rowSizer->Add( new wxStaticText(panel,wxID_ANY,wxT("Tree Ctrl wxComboCtrl:")), 1,
|
2006-05-08 19:42:45 -04:00
|
|
|
wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
|
|
|
|
colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );
|
|
|
|
|
2006-07-04 04:58:06 -04:00
|
|
|
rowSizer = new wxBoxSizer( wxHORIZONTAL );
|
2006-10-25 15:48:46 -04:00
|
|
|
cc = new wxComboCtrlWithCustomPopupAnim();
|
2010-06-13 06:00:14 -04:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2006-10-25 15:48:46 -04:00
|
|
|
cc->Create(panel, wxID_ANY, wxEmptyString);
|
2006-05-08 19:42:45 -04:00
|
|
|
|
2006-10-22 16:25:08 -04:00
|
|
|
// Make sure we use popup that allows focusing the listview.
|
|
|
|
cc->UseAltPopupWindow();
|
|
|
|
|
2006-05-08 19:42:45 -04:00
|
|
|
cc->SetPopupMinWidth(300);
|
|
|
|
|
2006-05-09 12:18:19 -04:00
|
|
|
ListViewComboPopup* iface = new ListViewComboPopup();
|
2006-05-08 19:42:45 -04:00
|
|
|
cc->SetPopupControl(iface);
|
|
|
|
|
2006-07-04 04:58:06 -04:00
|
|
|
int i;
|
|
|
|
for ( i=0; i<100; i++ )
|
|
|
|
iface->AddSelection( wxString::Format(wxT("Item %02i"),i));
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
rowSizer->Add( cc, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2006-05-16 18:57:40 -04:00
|
|
|
// Tree Ctrl wxComboCtrl
|
2006-05-08 19:42:45 -04:00
|
|
|
//
|
|
|
|
|
2006-09-19 13:29:45 -04:00
|
|
|
// Note that we test that wxGenericComboCtrl works
|
|
|
|
gcc = new wxGenericComboCtrl(panel,wxID_ANY,wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize);
|
2006-05-08 19:42:45 -04:00
|
|
|
|
2006-10-22 16:25:08 -04:00
|
|
|
// Make sure we use popup that allows focusing the treectrl.
|
|
|
|
gcc->UseAltPopupWindow();
|
|
|
|
|
2006-05-08 19:42:45 -04:00
|
|
|
// Set popup interface right away, otherwise some of the calls
|
|
|
|
// below may fail
|
2006-05-09 12:18:19 -04:00
|
|
|
TreeCtrlComboPopup* tcPopup = new TreeCtrlComboPopup();
|
2006-05-08 19:42:45 -04:00
|
|
|
gcc->SetPopupControl(tcPopup);
|
|
|
|
|
|
|
|
// Add items using wxTreeCtrl methods directly
|
|
|
|
wxTreeItemId rootId = tcPopup->AddRoot(wxT("<hidden_root>"));
|
|
|
|
|
|
|
|
wxTreeItemId groupId;
|
|
|
|
|
2006-07-04 04:58:06 -04:00
|
|
|
for ( i=0; i<4; i++ )
|
|
|
|
{
|
|
|
|
groupId = tcPopup->AppendItem(rootId,
|
|
|
|
wxString::Format(wxT("Branch %02i"),i));
|
|
|
|
|
|
|
|
int n;
|
|
|
|
for ( n=0; n<25; n++ )
|
|
|
|
tcPopup->AppendItem(groupId,
|
|
|
|
wxString::Format(wxT("Subitem %02i"),(i*25)+n));
|
|
|
|
}
|
|
|
|
|
|
|
|
gcc->SetValue(wxT("Subitem 05"));
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
// Move button to left - it makes more sense for a tree ctrl
|
2006-07-17 04:45:12 -04:00
|
|
|
gcc->SetButtonPosition(-1, // button width
|
|
|
|
-1, // button height
|
2006-05-08 19:42:45 -04:00
|
|
|
wxLEFT, // side
|
|
|
|
0 // horizontal spacing
|
|
|
|
);
|
|
|
|
|
|
|
|
rowSizer->Add( gcc, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
|
|
|
|
|
|
colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );
|
|
|
|
|
|
|
|
#if wxUSE_IMAGE
|
|
|
|
wxInitAllImageHandlers();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Custom Dropbutton Bitmaps
|
|
|
|
// (second one uses blank button background)
|
|
|
|
//
|
2006-07-04 04:58:06 -04:00
|
|
|
rowSizer = new wxBoxSizer( wxHORIZONTAL );
|
2006-05-08 19:42:45 -04:00
|
|
|
rowSizer->Add( new wxStaticText(panel,wxID_ANY,
|
|
|
|
wxT("OwnerDrawnComboBox with simple dropbutton graphics:")), 1,
|
|
|
|
wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
|
|
|
|
|
|
|
|
colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );
|
|
|
|
|
2006-07-04 04:58:06 -04:00
|
|
|
rowSizer = new wxBoxSizer( wxHORIZONTAL );
|
2006-05-08 19:42:45 -04:00
|
|
|
|
|
|
|
odc = new wxOwnerDrawnComboBox(panel,wxID_ANY,wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
2006-07-04 04:58:06 -04:00
|
|
|
m_arrItems,
|
2006-05-08 19:42:45 -04:00
|
|
|
(long)0 // wxCB_SORT // wxNO_BORDER | wxCB_READONLY
|
|
|
|
);
|
|
|
|
|
|
|
|
wxOwnerDrawnComboBox* odc2;
|
|
|
|
odc2 = new wxOwnerDrawnComboBox(panel,wxID_ANY,wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
2006-07-04 04:58:06 -04:00
|
|
|
m_arrItems,
|
2006-05-08 19:42:45 -04:00
|
|
|
(long)0 // wxCB_SORT // wxNO_BORDER | wxCB_READONLY
|
|
|
|
);
|
|
|
|
|
|
|
|
// Load images from disk
|
|
|
|
wxImage imgNormal(wxT("dropbutn.png"));
|
|
|
|
wxImage imgPressed(wxT("dropbutp.png"));
|
|
|
|
wxImage imgHover(wxT("dropbuth.png"));
|
|
|
|
|
2006-10-09 05:01:55 -04:00
|
|
|
if ( imgNormal.IsOk() && imgPressed.IsOk() && imgHover.IsOk() )
|
2006-05-08 19:42:45 -04:00
|
|
|
{
|
|
|
|
wxBitmap bmpNormal(imgNormal);
|
|
|
|
wxBitmap bmpPressed(imgPressed);
|
|
|
|
wxBitmap bmpHover(imgHover);
|
|
|
|
odc->SetButtonBitmaps(bmpNormal,false,bmpPressed,bmpHover);
|
|
|
|
odc2->SetButtonBitmaps(bmpNormal,true,bmpPressed,bmpHover);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
wxLogError(wxT("Dropbutton images not found"));
|
|
|
|
|
|
|
|
//odc2->SetButtonPosition(0, // width adjustment
|
|
|
|
// 0, // height adjustment
|
|
|
|
// wxLEFT, // side
|
|
|
|
// 0 // horizontal spacing
|
|
|
|
// );
|
|
|
|
|
|
|
|
rowSizer->Add( odc, 1, wxALIGN_CENTER_VERTICAL|wxALL, 4 );
|
|
|
|
rowSizer->Add( odc2, 1, wxALIGN_CENTER_VERTICAL|wxALL, 4 );
|
|
|
|
colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2006-05-16 18:57:40 -04:00
|
|
|
// wxComboCtrl with totally custom button action (open file dialog)
|
2006-05-08 19:42:45 -04:00
|
|
|
//
|
2006-07-04 04:58:06 -04:00
|
|
|
rowSizer = new wxBoxSizer( wxHORIZONTAL );
|
2006-05-08 19:42:45 -04:00
|
|
|
rowSizer->Add( new wxStaticText(panel,wxID_ANY,
|
2006-05-16 18:57:40 -04:00
|
|
|
wxT("wxComboCtrl with custom button action:")), 1,
|
2006-05-08 19:42:45 -04:00
|
|
|
wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
|
|
|
|
|
|
|
|
|
|
|
|
colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );
|
|
|
|
|
2006-07-04 04:58:06 -04:00
|
|
|
rowSizer = new wxBoxSizer( wxHORIZONTAL );
|
2006-05-08 19:42:45 -04:00
|
|
|
wxFileSelectorCombo* fsc;
|
|
|
|
|
|
|
|
fsc = new wxFileSelectorCombo(panel,wxID_ANY,wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
(long)0
|
|
|
|
);
|
|
|
|
|
|
|
|
rowSizer->Add( fsc, 1, wxALIGN_CENTER_VERTICAL|wxALL, 4 );
|
|
|
|
colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );
|
|
|
|
|
|
|
|
|
2006-07-04 04:58:06 -04:00
|
|
|
// Make sure GetFeatures is implemented
|
|
|
|
wxComboCtrl::GetFeatures();
|
|
|
|
|
|
|
|
|
2006-05-08 19:42:45 -04:00
|
|
|
topRowSizer->Add( colSizer, 1, wxALL, 2 );
|
|
|
|
|
2006-10-25 15:48:46 -04:00
|
|
|
colSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
topRowSizer->Add( colSizer, 1, wxEXPAND|wxALL, 2 );
|
2006-05-08 19:42:45 -04:00
|
|
|
topSizer->Add( topRowSizer, 1, wxEXPAND );
|
|
|
|
|
|
|
|
panel->SetSizer( topSizer );
|
|
|
|
topSizer->SetSizeHints( panel );
|
|
|
|
|
2011-12-28 08:51:21 -05:00
|
|
|
Fit();
|
2006-05-08 19:42:45 -04:00
|
|
|
Centre();
|
|
|
|
}
|
|
|
|
|
|
|
|
// event handlers
|
|
|
|
|
|
|
|
void MyFrame::OnComboBoxUpdate( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
// Don't show messages for the log output window (it'll crash)
|
2006-07-04 04:58:06 -04:00
|
|
|
if ( !event.GetEventObject()->IsKindOf(CLASSINFO(wxComboCtrl)) )
|
2006-05-08 19:42:45 -04:00
|
|
|
return;
|
|
|
|
|
2013-04-25 06:11:03 -04:00
|
|
|
if ( event.GetEventType() == wxEVT_COMBOBOX )
|
2009-07-20 12:47:54 -04:00
|
|
|
{
|
2006-05-08 19:42:45 -04:00
|
|
|
wxLogDebug(wxT("EVT_COMBOBOX(id=%i,selection=%i)"),event.GetId(),event.GetSelection());
|
2009-07-20 12:47:54 -04:00
|
|
|
}
|
2013-04-25 06:11:03 -04:00
|
|
|
else if ( event.GetEventType() == wxEVT_TEXT )
|
2009-07-20 12:47:54 -04:00
|
|
|
{
|
2006-05-08 19:42:45 -04:00
|
|
|
wxLogDebug(wxT("EVT_TEXT(id=%i,string=\"%s\")"),event.GetId(),event.GetString().c_str());
|
2009-07-20 12:47:54 -04:00
|
|
|
}
|
2013-04-25 06:11:03 -04:00
|
|
|
else if ( event.GetEventType() == wxEVT_TEXT_ENTER )
|
2011-04-18 05:58:27 -04:00
|
|
|
{
|
|
|
|
wxLogDebug("EVT_TEXT_ENTER(id=%i,string=\"%s\")",
|
|
|
|
event.GetId(), event.GetString().c_str());
|
|
|
|
}
|
2006-05-08 19:42:45 -04:00
|
|
|
}
|
|
|
|
|
2006-07-04 04:58:06 -04:00
|
|
|
void MyFrame::OnShowComparison( wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Show some wxOwnerDrawComboBoxes for comparison
|
|
|
|
//
|
|
|
|
|
|
|
|
wxBoxSizer* colSizer;
|
|
|
|
wxBoxSizer* rowSizer;
|
|
|
|
wxStaticBoxSizer* groupSizer;
|
|
|
|
|
|
|
|
wxComboBox* cb;
|
|
|
|
wxOwnerDrawnComboBox* odc;
|
|
|
|
|
|
|
|
const int border = 4;
|
|
|
|
|
|
|
|
wxDialog* dlg = new wxDialog(this,wxID_ANY,
|
|
|
|
wxT("Compare against wxComboBox"),
|
|
|
|
wxDefaultPosition,wxDefaultSize,
|
|
|
|
wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER);
|
|
|
|
|
|
|
|
colSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
|
|
|
|
rowSizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
|
|
|
|
groupSizer = new wxStaticBoxSizer(new wxStaticBox(dlg,wxID_ANY,wxT(" wxOwnerDrawnComboBox ")),
|
|
|
|
wxVERTICAL);
|
|
|
|
|
2012-11-09 16:11:37 -05:00
|
|
|
groupSizer->Add( new wxStaticText(dlg, wxID_ANY,
|
2015-04-25 06:52:36 -04:00
|
|
|
wxT("Writable, with margins, sorted:")),
|
|
|
|
wxSizerFlags().Expand().Border(wxRIGHT, border) );
|
2006-07-04 04:58:06 -04:00
|
|
|
|
|
|
|
odc = new wxOwnerDrawnComboBox(dlg,wxID_ANY,wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
m_arrItems,
|
|
|
|
wxCB_SORT // wxNO_BORDER|wxCB_READONLY
|
|
|
|
);
|
|
|
|
|
|
|
|
odc->Append(wxT("H - Appended Item")); // test sorting in append
|
|
|
|
|
|
|
|
odc->SetValue(wxT("Dot Dash"));
|
2012-11-09 16:11:37 -05:00
|
|
|
odc->SetMargins(15, 10);
|
2015-04-25 06:52:36 -04:00
|
|
|
groupSizer->Add( odc, wxSizerFlags().Border(wxALL, border) );
|
2012-11-09 16:11:37 -05:00
|
|
|
groupSizer->AddStretchSpacer();
|
2006-07-04 04:58:06 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Readonly ODComboBox
|
2012-11-09 16:11:37 -05:00
|
|
|
groupSizer->Add( new wxStaticText(dlg, wxID_ANY,
|
2015-04-25 06:52:36 -04:00
|
|
|
wxT("Read-only, big font:")),
|
|
|
|
wxSizerFlags().Border(wxRIGHT, border) );
|
2006-07-04 04:58:06 -04:00
|
|
|
|
|
|
|
odc = new wxOwnerDrawnComboBox(dlg,wxID_ANY,wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
m_arrItems,
|
|
|
|
wxCB_SORT|wxCB_READONLY // wxNO_BORDER|wxCB_READONLY
|
|
|
|
);
|
|
|
|
|
2012-11-09 16:11:37 -05:00
|
|
|
odc->SetFont(odc->GetFont().Scale(1.5));
|
2006-07-04 04:58:06 -04:00
|
|
|
odc->SetValue(wxT("Dot Dash"));
|
|
|
|
odc->SetText(wxT("Dot Dash (Testing SetText)"));
|
|
|
|
|
2012-11-09 16:11:37 -05:00
|
|
|
groupSizer->Add( odc, 0, wxALL, border );
|
|
|
|
groupSizer->AddStretchSpacer();
|
2006-07-04 04:58:06 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Disabled ODComboBox
|
2015-04-25 06:52:36 -04:00
|
|
|
groupSizer->Add( new wxStaticText(dlg,wxID_ANY,wxT("Disabled:")),
|
|
|
|
wxSizerFlags().Border(wxRIGHT, border) );
|
2006-07-04 04:58:06 -04:00
|
|
|
|
|
|
|
odc = new wxOwnerDrawnComboBox(dlg,wxID_ANY,wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
m_arrItems,
|
|
|
|
wxCB_SORT|wxCB_READONLY // wxNO_BORDER|wxCB_READONLY
|
|
|
|
);
|
|
|
|
|
|
|
|
odc->SetValue(wxT("Dot Dash"));
|
|
|
|
odc->Enable(false);
|
|
|
|
|
2015-04-25 06:52:36 -04:00
|
|
|
groupSizer->Add( odc, wxSizerFlags(3).Expand().Border(wxALL, border) );
|
2006-07-04 04:58:06 -04:00
|
|
|
|
|
|
|
rowSizer->Add( groupSizer, 1, wxEXPAND|wxALL, border );
|
|
|
|
|
|
|
|
|
|
|
|
groupSizer = new wxStaticBoxSizer(new wxStaticBox(dlg,wxID_ANY,wxT(" wxComboBox ")),
|
|
|
|
wxVERTICAL);
|
|
|
|
|
|
|
|
//
|
|
|
|
// wxComboBox
|
|
|
|
//
|
2012-11-09 16:11:37 -05:00
|
|
|
groupSizer->Add( new wxStaticText(dlg,wxID_ANY,
|
2015-04-25 06:52:36 -04:00
|
|
|
wxT("Writable, with margins, sorted:")),
|
|
|
|
wxSizerFlags().Expand().Border(wxRIGHT, border) );
|
2006-07-04 04:58:06 -04:00
|
|
|
|
|
|
|
cb = new wxComboBox(dlg,wxID_ANY,wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
m_arrItems,
|
|
|
|
wxCB_SORT // wxNO_BORDER|wxCB_READONLY
|
|
|
|
);
|
|
|
|
|
|
|
|
cb->Append(wxT("H - Appended Item")); // test sorting in append
|
|
|
|
|
|
|
|
cb->SetValue(wxT("Dot Dash"));
|
2012-11-09 16:11:37 -05:00
|
|
|
cb->SetMargins(15, 10);
|
2015-04-25 06:52:36 -04:00
|
|
|
groupSizer->Add( cb, wxSizerFlags().Border(wxALL, border) );
|
2012-11-09 16:11:37 -05:00
|
|
|
groupSizer->AddStretchSpacer();
|
2006-07-04 04:58:06 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Readonly wxComboBox
|
2012-11-09 16:11:37 -05:00
|
|
|
groupSizer->Add( new wxStaticText(dlg, wxID_ANY,
|
2015-04-25 06:52:36 -04:00
|
|
|
wxT("Read-only, big font:")),
|
|
|
|
wxSizerFlags().Border(wxRIGHT, border) );
|
2006-07-04 04:58:06 -04:00
|
|
|
|
|
|
|
cb = new wxComboBox(dlg,wxID_ANY,wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
m_arrItems,
|
|
|
|
wxCB_SORT|wxCB_READONLY // wxNO_BORDER|wxCB_READONLY
|
|
|
|
);
|
|
|
|
|
2012-11-09 16:11:37 -05:00
|
|
|
cb->SetFont(cb->GetFont().Scale(1.5));
|
2006-07-04 04:58:06 -04:00
|
|
|
cb->SetValue(wxT("Dot Dash"));
|
|
|
|
|
2012-11-09 16:11:37 -05:00
|
|
|
groupSizer->Add( cb, 0, wxALL, border );
|
|
|
|
groupSizer->AddStretchSpacer();
|
2006-07-04 04:58:06 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Disabled wxComboBox
|
2015-04-25 06:52:36 -04:00
|
|
|
groupSizer->Add( new wxStaticText(dlg,wxID_ANY,wxT("Disabled:")),
|
|
|
|
wxSizerFlags().Border(wxRIGHT, border) );
|
2006-07-04 04:58:06 -04:00
|
|
|
|
|
|
|
cb = new wxComboBox(dlg,wxID_ANY,wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
m_arrItems,
|
|
|
|
wxCB_SORT|wxCB_READONLY // wxNO_BORDER|wxCB_READONLY
|
|
|
|
);
|
|
|
|
|
|
|
|
cb->SetValue(wxT("Dot Dash"));
|
|
|
|
cb->Enable(false);
|
|
|
|
|
2015-04-25 06:52:36 -04:00
|
|
|
groupSizer->Add( cb, wxSizerFlags(3).Expand().Border(wxALL, border) );
|
2006-07-04 04:58:06 -04:00
|
|
|
|
|
|
|
rowSizer->Add( groupSizer, 1, wxEXPAND|wxALL, border );
|
|
|
|
|
2012-11-09 16:11:37 -05:00
|
|
|
colSizer->Add( rowSizer, 1, wxEXPAND|wxALL, border );
|
2006-07-04 04:58:06 -04:00
|
|
|
|
|
|
|
dlg->SetSizer( colSizer );
|
|
|
|
colSizer->SetSizeHints( dlg );
|
|
|
|
|
|
|
|
dlg->SetSize(60,240);
|
|
|
|
dlg->Centre();
|
|
|
|
dlg->ShowModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
MyFrame::~MyFrame()
|
|
|
|
{
|
|
|
|
delete wxLog::SetActiveTarget(m_logOld);
|
|
|
|
}
|
|
|
|
|
2006-05-08 19:42:45 -04:00
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
// true is to force the frame to close
|
|
|
|
Close(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMessageBox(wxString::Format(
|
2009-07-23 16:30:22 -04:00
|
|
|
wxT("Welcome to %s!\n")
|
|
|
|
wxT("\n")
|
|
|
|
wxT("This is the wxWidgets wxComboCtrl and wxOwnerDrawnComboBox sample\n")
|
|
|
|
wxT("running under %s."),
|
2006-05-08 19:42:45 -04:00
|
|
|
wxVERSION_STRING,
|
|
|
|
wxGetOsDescription().c_str()
|
|
|
|
),
|
2009-07-23 16:30:22 -04:00
|
|
|
wxT("About wxComboCtrl sample"),
|
2006-05-08 19:42:45 -04:00
|
|
|
wxOK | wxICON_INFORMATION,
|
|
|
|
this);
|
|
|
|
}
|
2006-10-22 16:25:08 -04:00
|
|
|
|
|
|
|
void MyFrame::OnIdle(wxIdleEvent& event)
|
|
|
|
{
|
|
|
|
// This code is useful for debugging focus problems
|
|
|
|
// (which are plentiful when dealing with popup windows).
|
|
|
|
#if 0
|
|
|
|
static wxWindow* lastFocus = (wxWindow*) NULL;
|
|
|
|
|
|
|
|
wxWindow* curFocus = ::wxWindow::FindFocus();
|
|
|
|
|
|
|
|
if ( curFocus != lastFocus )
|
|
|
|
{
|
|
|
|
const wxChar* className = wxT("<none>");
|
|
|
|
if ( curFocus )
|
|
|
|
className = curFocus->GetClassInfo()->GetClassName();
|
|
|
|
lastFocus = curFocus;
|
|
|
|
wxLogDebug( wxT("FOCUSED: %s %X"),
|
|
|
|
className,
|
|
|
|
(unsigned int)curFocus);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|