1/////////////////////////////////////////////////////////////////////////////
2// Name:        wx/msw/choice.h
3// Purpose:     wxChoice class
4// Author:      Julian Smart
5// Modified by: Vadim Zeitlin to derive from wxChoiceBase
6// Created:     01/02/97
7// RCS-ID:      $Id: choice.h 51616 2008-02-09 15:22:15Z VZ $
8// Copyright:   (c) Julian Smart
9// Licence:     wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_CHOICE_H_
13#define _WX_CHOICE_H_
14
15// ----------------------------------------------------------------------------
16// Choice item
17// ----------------------------------------------------------------------------
18
19class WXDLLEXPORT wxChoice : public wxChoiceBase
20{
21public:
22    // ctors
23    wxChoice() { Init(); }
24    virtual ~wxChoice();
25
26    wxChoice(wxWindow *parent,
27             wxWindowID id,
28             const wxPoint& pos = wxDefaultPosition,
29             const wxSize& size = wxDefaultSize,
30             int n = 0, const wxString choices[] = NULL,
31             long style = 0,
32             const wxValidator& validator = wxDefaultValidator,
33             const wxString& name = wxChoiceNameStr)
34    {
35        Init();
36        Create(parent, id, pos, size, n, choices, style, validator, name);
37    }
38
39    wxChoice(wxWindow *parent,
40             wxWindowID id,
41             const wxPoint& pos,
42             const wxSize& size,
43             const wxArrayString& choices,
44             long style = 0,
45             const wxValidator& validator = wxDefaultValidator,
46             const wxString& name = wxChoiceNameStr)
47    {
48        Init();
49        Create(parent, id, pos, size, choices, style, validator, name);
50    }
51
52    bool Create(wxWindow *parent,
53                wxWindowID id,
54                const wxPoint& pos = wxDefaultPosition,
55                const wxSize& size = wxDefaultSize,
56                int n = 0, const wxString choices[] = NULL,
57                long style = 0,
58                const wxValidator& validator = wxDefaultValidator,
59                const wxString& name = wxChoiceNameStr);
60    bool Create(wxWindow *parent,
61                wxWindowID id,
62                const wxPoint& pos,
63                const wxSize& size,
64                const wxArrayString& choices,
65                long style = 0,
66                const wxValidator& validator = wxDefaultValidator,
67                const wxString& name = wxChoiceNameStr);
68
69    virtual void SetLabel(const wxString& label);
70
71    virtual void Delete(unsigned int n);
72    virtual void Clear();
73
74    virtual unsigned int GetCount() const;
75    virtual int GetSelection() const;
76    virtual int GetCurrentSelection() const;
77    virtual void SetSelection(int n);
78
79    virtual int FindString(const wxString& s, bool bCase = false) const;
80    virtual wxString GetString(unsigned int n) const;
81    virtual void SetString(unsigned int n, const wxString& s);
82
83    // MSW only
84    virtual bool MSWCommand(WXUINT param, WXWORD id);
85    WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
86    virtual WXHBRUSH MSWControlColor(WXHDC hDC, WXHWND hWnd);
87    virtual bool MSWShouldPreProcessMessage(WXMSG *pMsg);
88    virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
89
90protected:
91    // common part of all ctors
92    void Init() { m_lastAcceptedSelection = wxID_NONE; }
93
94    virtual int DoAppend(const wxString& item);
95    virtual int DoInsert(const wxString& item, unsigned int pos);
96    virtual void DoMoveWindow(int x, int y, int width, int height);
97    virtual void DoSetItemClientData(unsigned int n, void* clientData);
98    virtual void* DoGetItemClientData(unsigned int n) const;
99    virtual void DoSetItemClientObject(unsigned int n, wxClientData* clientData);
100    virtual wxClientData* DoGetItemClientObject(unsigned int n) const;
101
102    // MSW implementation
103    virtual wxSize DoGetBestSize() const;
104    virtual void DoGetSize(int *w, int *h) const;
105    virtual void DoSetSize(int x, int y,
106                           int width, int height,
107                           int sizeFlags = wxSIZE_AUTO);
108
109    // update the height of the drop down list to fit the number of items we
110    // have (without changing the visible height)
111    void UpdateVisibleHeight();
112
113    // create and initialize the control
114    bool CreateAndInit(wxWindow *parent, wxWindowID id,
115                       const wxPoint& pos,
116                       const wxSize& size,
117                       int n, const wxString choices[],
118                       long style,
119                       const wxValidator& validator,
120                       const wxString& name);
121
122    // free all memory we have (used by Clear() and dtor)
123    void Free();
124
125
126    // last "completed" selection, i.e. not the transient one while the user is
127    // browsing the popup list: this is only used when != wxID_NONE which is
128    // the case while the drop down is opened
129    int m_lastAcceptedSelection;
130
131
132    DECLARE_DYNAMIC_CLASS_NO_COPY(wxChoice)
133};
134
135#endif // _WX_CHOICE_H_
136