File: SmartComboBox.h

package info (click to toggle)
gcvs 1.0final-17
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 12,248 kB
  • ctags: 10,629
  • sloc: ansic: 71,711; cpp: 39,785; sh: 18,434; makefile: 1,917; yacc: 1,299; tcl: 1,283; perl: 910; lex: 249; csh: 185; lisp: 7
file content (163 lines) | stat: -rw-r--r-- 5,187 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 1, or (at your option)
** any later version.

** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.

** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

/*
 * Author : Jerzy Kaczorowski <kaczoroj@hotmail.com> --- December 2001
 */

#if !defined(AFX_SMARTCOMBOBOX_H__E3F8DAE6_C2EF_49CE_AE52_3AE54F5A629C__INCLUDED_)
#define AFX_SMARTCOMBOBOX_H__E3F8DAE6_C2EF_49CE_AE52_3AE54F5A629C__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// SmartComboBox.h : header file
//

//forward declaration
class CMString;

/*! \class USmartCombo SmartComboBox.h "common/SmartComboBox.h"
 *  \brief This is an abstract class for Smart Combo Box (CSmartComboBox).
 *
 * Use as a base class to derive the Smart Combo Box for different plaftorms.
 * 
 * \note To set the desired features support by Smart Combo Box objects you
 *  can use the combinations of values enumerated under USmartCombo::Feature
 */

class USmartCombo
{
public:
	// Construction / Destruction
	USmartCombo(int feature);
	virtual ~USmartCombo();

private:
	int m_feature;
	CMString* m_pstrItems;

public:
	//! Feature enum
	/*! Enum to specify the desired features for your Smart Combo Box object */
	enum Feature{
		None =			0x00,	/*!< No features, just standard Combo Box. */
		AutoDropWidth =	0x01,	/*!< Automatically adjust the width of the droplist to fit the long items. */
		RemoveItems =	0x02,	/*!< Allows to remove items from combo boxes containing previous values. */
		ReadOnly =		0x04,	/*!< Make the edit portion of combo box read-only (while still allowing to change the selection it prevents from typing those and copy it's values). */
		//
		DefaultFeature = AutoDropWidth | RemoveItems  /*!< Default combination of features passed to the Smart Combo Box constructor. */
	};

public:
	// Get / Set methods
	void SetFeature(int feature);
	bool HasFeature(int feature) const;

	void SetItems(CMString* pstrItems);
	CMString* GetItems();

	// Overrides
	virtual int CalcDroppedWidth();
	virtual void SetReadOnly(bool readOnly = true);
	virtual bool RemoveItem(const char* strItem);
};

#ifdef WIN32

/*! 
 * Private window message to set the features. 
 * See CSmartComboBox::OnSetFeature for more details.
 */
#define WM_SMCB_SETFEATURE	WM_USER	+ 1

/*! 
 * Private window message to set the droplist items collection. 
 * See CSmartComboBox::OnSetItems for more details.
 */
#define WM_SMCB_SETITEMS	WM_USER	+ 2

/*! 
 * Private window message to set the read-only feature. 
 * See CSmartComboBox::OnSetFeature for more details.
 */
#define WM_SMCB_SETREADONLY	WM_USER	+ 3

/////////////////////////////////////////////////////////////////////////////
// CSmartComboBox window

/*! \class CSmartComboBox SmartComboBox.h "common/SmartComboBox.h"
 *  \brief This is a Smart Combo Box class(CSmartComboBox).
 *
 * Use that class as a replacement for CComboBox. Set the desired features 
 * using the constructor or CSmartComboBox::SetFeature method. To use the Del
 * key feature when the droplist is dropped down you need to also call CSmartComboBox::SetItems
 * method to setup apropriate persistent collection (CMString object). 
 * The CSmartComboBox::SetReadOnlymethod can be used to make an edit portion of the combo
 * readonly or to reverse that feature. For use with the UWidget the messages to set apropriate 
 * features and data members are provided (#WM_SMCB_SETFEATURE, #WM_SMCB_SETITEMS and #WM_SMCB_SETREADONLY).
 */

class CSmartComboBox : public CComboBox, public USmartCombo
{
// Construction
public:
	CSmartComboBox(int feature = USmartCombo::DefaultFeature);

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CSmartComboBox)
	public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	protected:
	virtual void PreSubclassWindow();
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CSmartComboBox();

	// Generated message map functions
protected:
	//{{AFX_MSG(CSmartComboBox)
	afx_msg void OnDropdown();
	//}}AFX_MSG
	afx_msg LRESULT OnSetFeature(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnSetItems(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnSetReadOnly(WPARAM wParam, LPARAM lParam);

	DECLARE_MESSAGE_MAP()
private:
	virtual int CalcDroppedWidth();
	BOOL DelKeyTest(MSG* pMsg);

public:
	virtual void SetReadOnly(bool readOnly = true);
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif /* WIN32 */

#endif // !defined(AFX_SMARTCOMBOBOX_H__E3F8DAE6_C2EF_49CE_AE52_3AE54F5A629C__INCLUDED_)