1
/////////////////////////////////////////////////////////////////////////////
3
// Purpose: base class for a control like a combobox
4
// Author: John Labenski
7
// Copyright: (c) John Labenski
8
// Licence: wxWidgets licence
9
/////////////////////////////////////////////////////////////////////////////
13
YOU MUST USE A wxWIDGETS RELEASE NEWER THAN 1/29/05 - AFTER POPUPWINDOW FIX
15
DropDownBase is a class that has a DropDownPopup as a child. It works like a
16
wxComboBox in that there is a button to the right that you use to drop down
17
a window. You can put whatever you want in the DropDownPopup by calling
18
GetPopupWindow()->SetChild(win) in your DoShowPopup function.
19
Additionally, you'll want to put a window to the left of the dropdown button.
21
You need to subclass this to make a new control.
23
You need to override these function in DropDownBase
24
DoGetBestSize() let wxWidgets know how big this control wants to be
25
DoGetBestDropHeight(max) - max is the # pixels to bottom of screen, you probably want
26
it smaller so return that height, return -1 if you don't want the popup shown.
27
DoShowPopup() - this is called from ShowPopup after creating the m_popupWin.
28
Create your child window with the popup as the parent and call
29
GetPopupWindow()->SetChild(win). Make sure you call
30
DropDownBase::DoShowPopup() to have the popup window shown.
33
#ifndef _WX_DROPDOWNBASE_H_
34
#define _WX_DROPDOWNBASE_H_
36
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
37
#pragma interface "dropdown.h"
40
#include "wx/popupwin.h"
41
#include "wx/things/thingdef.h"
43
class WXDLLEXPORT wxTimer;
44
class WXDLLEXPORT wxTimerEvent;
45
class WXDLLEXPORT wxCustomButton;
46
class WXDLLIMPEXP_THINGS DropDownPopup;
48
#define DROPDOWN_DROP_WIDTH 14 // these are the default sizes
49
#define DROPDOWN_DROP_HEIGHT 22
51
//-----------------------------------------------------------------------------
52
// DropDownBase generic combobox type widget that drops down a DropDownPopup
53
//-----------------------------------------------------------------------------
55
class WXDLLIMPEXP_THINGS DropDownBase : public wxControl
59
DropDownBase() : wxControl() { Init(); }
61
DropDownBase( wxWindow *parent, wxWindowID id = wxID_ANY,
62
const wxPoint& pos = wxDefaultPosition,
63
const wxSize& size = wxDefaultSize,
65
const wxValidator& val = wxDefaultValidator,
66
const wxString& name = wxT("DropDownBase"))
70
Create(parent, id, pos, size, style, val, name);
73
virtual ~DropDownBase();
75
bool Create(wxWindow* parent,
76
wxWindowID id = wxID_ANY,
77
const wxPoint& pos = wxDefaultPosition,
78
const wxSize& size = wxDefaultSize,
80
const wxValidator& val = wxDefaultValidator,
81
const wxString& name = wxT("DropDownBase"));
83
virtual bool ShowPopup();
84
virtual void HidePopup();
88
void OnDropButton( wxCommandEvent &event );
89
wxCustomButton* GetDropDownButton() { return m_dropdownButton; }
90
// Get the popup window, NULL when not shown
91
DropDownPopup* GetPopupWindow() { return m_popupWin; }
94
virtual void DoSetSize(int x, int y, int width, int height,
95
int sizeFlags = wxSIZE_AUTO);
97
void OnSize( wxSizeEvent& event );
98
virtual wxSize DoGetBestSize() const;
100
virtual bool DoShowPopup();
102
// override to set the height of the dropdown box
103
// input max_height is height from bottom of ctrl to bottom of screen
104
// return < 1 to not have the popup displayed
105
virtual int DoGetBestDropHeight(int max_height) { return max_height; }
107
wxCustomButton *m_dropdownButton;
108
DropDownPopup *m_popupWin;
112
DECLARE_DYNAMIC_CLASS(DropDownBase)
113
DECLARE_EVENT_TABLE()
116
//-----------------------------------------------------------------------------
117
// DropDownPopup generic popup window, call SetChild
118
//-----------------------------------------------------------------------------
120
class WXDLLIMPEXP_THINGS DropDownPopup : public wxPopupTransientWindow
123
DropDownPopup() : wxPopupTransientWindow() { Init(); }
124
DropDownPopup(DropDownBase *parent, int style = wxBORDER_NONE) : wxPopupTransientWindow()
127
Create(parent, style);
129
virtual ~DropDownPopup();
131
bool Create(DropDownBase *parent, int style = wxBORDER_NONE);
133
virtual void Popup(wxWindow *focus = NULL);
134
virtual void Dismiss();
135
virtual bool ProcessLeftDown(wxMouseEvent& event);
137
virtual void SetChild(wxWindow *child);
138
virtual wxWindow *GetChild() const { return m_childWin; }
143
// start/stop timer shat pushes and pops handler when the mouse goes over
144
// the scrollbars (if any) of the child window
147
void PushPopupHandler(wxWindow* child);
148
void PopPopupHandler(wxWindow* child);
150
void OnMouse( wxMouseEvent& event );
151
void OnKeyDown( wxKeyEvent &event );
152
void OnTimer( wxTimerEvent& event );
153
void OnIdle( wxIdleEvent& event );
155
wxPoint m_mouse; // last/current mouse position
156
wxWindow *m_childWin; // store our own child pointer
157
DropDownBase *m_owner;
158
wxTimer *m_timer; // timer for tracking mouse position
159
bool m_popped_handler; // state of the event handler
163
DECLARE_DYNAMIC_CLASS(DropDownPopup)
164
DECLARE_EVENT_TABLE()
167
#endif // _WX_DROPDOWNBASE_H_