2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
#ifndef AWT_LIST_H
|
|
27 |
#define AWT_LIST_H
|
|
28 |
|
|
29 |
#include "awt_Component.h"
|
|
30 |
|
|
31 |
#include "sun_awt_windows_WListPeer.h"
|
|
32 |
|
|
33 |
|
|
34 |
/************************************************************************
|
|
35 |
* AwtList class
|
|
36 |
*/
|
|
37 |
|
|
38 |
class AwtList : public AwtComponent {
|
|
39 |
public:
|
|
40 |
AwtList();
|
|
41 |
virtual ~AwtList();
|
|
42 |
|
|
43 |
virtual LPCTSTR GetClassName();
|
|
44 |
|
|
45 |
static AwtList* Create(jobject peer, jobject parent);
|
|
46 |
|
|
47 |
virtual BOOL NeedDblClick() { return TRUE; }
|
|
48 |
|
|
49 |
INLINE void Select(int pos) {
|
|
50 |
if (isMultiSelect) {
|
|
51 |
SendListMessage(LB_SETSEL, TRUE, pos);
|
|
52 |
}
|
|
53 |
else {
|
|
54 |
SendListMessage(LB_SETCURSEL, pos);
|
|
55 |
}
|
|
56 |
}
|
|
57 |
INLINE void Deselect(int pos) {
|
|
58 |
if (isMultiSelect) {
|
|
59 |
SendListMessage(LB_SETSEL, FALSE, pos);
|
|
60 |
}
|
|
61 |
else {
|
|
62 |
SendListMessage(LB_SETCURSEL, (WPARAM)-1);
|
|
63 |
}
|
|
64 |
}
|
|
65 |
INLINE UINT GetCount() {
|
|
66 |
LRESULT index = SendListMessage(LB_GETCOUNT);
|
|
67 |
DASSERT(index != LB_ERR);
|
|
68 |
return static_cast<UINT>(index);
|
|
69 |
}
|
|
70 |
|
|
71 |
INLINE void InsertString(WPARAM index, LPTSTR str) {
|
|
72 |
VERIFY(SendListMessage(LB_INSERTSTRING, index, (LPARAM)str) != LB_ERR);
|
|
73 |
}
|
|
74 |
INLINE BOOL IsItemSelected(UINT index) {
|
|
75 |
LRESULT ret = SendListMessage(LB_GETSEL, index);
|
|
76 |
DASSERT(ret != LB_ERR);
|
|
77 |
return (ret > 0);
|
|
78 |
}
|
|
79 |
INLINE BOOL InvalidateList(CONST RECT* lpRect, BOOL bErase) {
|
|
80 |
DASSERT(GetListHandle());
|
|
81 |
return InvalidateRect(GetListHandle(), lpRect, bErase);
|
|
82 |
}
|
|
83 |
|
|
84 |
// Adjust the horizontal scrollbar as necessary
|
|
85 |
void AdjustHorizontalScrollbar();
|
|
86 |
void UpdateMaxItemWidth();
|
|
87 |
|
|
88 |
INLINE long GetMaxWidth() {
|
|
89 |
return m_nMaxWidth;
|
|
90 |
}
|
|
91 |
|
|
92 |
INLINE void CheckMaxWidth(long nWidth) {
|
|
93 |
if (nWidth > m_nMaxWidth) {
|
|
94 |
m_nMaxWidth = nWidth;
|
|
95 |
AdjustHorizontalScrollbar();
|
|
96 |
}
|
|
97 |
}
|
|
98 |
|
|
99 |
// Netscape : Change the font on the list and redraw the
|
|
100 |
// items nicely.
|
|
101 |
virtual void SetFont(AwtFont *pFont);
|
|
102 |
|
|
103 |
/* Set whether a list accepts single or multiple selections. */
|
|
104 |
void SetMultiSelect(BOOL ms);
|
|
105 |
|
|
106 |
/*for multifont list */
|
|
107 |
jobject PreferredItemSize(JNIEnv *envx);
|
|
108 |
|
|
109 |
/*
|
|
110 |
* Windows message handler functions
|
|
111 |
*/
|
|
112 |
MsgRouting WmNcHitTest(UINT x, UINT y, LRESULT& retVal);
|
|
113 |
MsgRouting WmMouseDown(UINT flags, int x, int y, int button);
|
|
114 |
MsgRouting WmMouseUp(UINT flags, int x, int y, int button);
|
|
115 |
MsgRouting WmNotify(UINT notifyCode);
|
|
116 |
|
|
117 |
/* for multifont list */
|
|
118 |
MsgRouting OwnerDrawItem(UINT ctrlId, DRAWITEMSTRUCT& drawInfo);
|
|
119 |
MsgRouting OwnerMeasureItem(UINT ctrlId, MEASUREITEMSTRUCT& measureInfo);
|
|
120 |
|
|
121 |
//for horizontal scrollbar
|
|
122 |
MsgRouting WmSize(UINT type, int w, int h);
|
|
123 |
|
|
124 |
MsgRouting WmCtlColor(HDC hDC, HWND hCtrl, UINT ctlColor,
|
|
125 |
HBRUSH& retBrush);
|
|
126 |
|
|
127 |
MsgRouting HandleEvent(MSG *msg, BOOL synthetic);
|
|
128 |
|
|
129 |
MsgRouting WmPrint(HDC hDC, LPARAM flags);
|
|
130 |
|
|
131 |
virtual void SetDragCapture(UINT flags);
|
|
132 |
virtual void ReleaseDragCapture(UINT flags);
|
|
133 |
void Reshape(int x, int y, int w, int h);
|
|
134 |
|
|
135 |
INLINE LRESULT SendListMessage(UINT msg, WPARAM wParam=0, LPARAM lParam=0)
|
|
136 |
{
|
|
137 |
DASSERT(GetListHandle() != NULL);
|
|
138 |
return ::SendMessage(GetListHandle(), msg, wParam, lParam);
|
|
139 |
}
|
|
140 |
INLINE virtual LONG GetStyle() {
|
|
141 |
DASSERT(GetListHandle());
|
|
142 |
return ::GetWindowLong(GetListHandle(), GWL_STYLE);
|
|
143 |
}
|
|
144 |
INLINE virtual void SetStyle(LONG style) {
|
|
145 |
DASSERT(GetListHandle());
|
|
146 |
// SetWindowLong() error handling as recommended by Win32 API doc.
|
|
147 |
::SetLastError(0);
|
|
148 |
LONG ret = ::SetWindowLong(GetListHandle(), GWL_STYLE, style);
|
|
149 |
DASSERT(ret != 0 || ::GetLastError() == 0);
|
|
150 |
}
|
|
151 |
INLINE virtual LONG GetStyleEx() {
|
|
152 |
DASSERT(GetListHandle());
|
|
153 |
return ::GetWindowLong(GetListHandle(), GWL_EXSTYLE);
|
|
154 |
}
|
|
155 |
INLINE virtual void SetStyleEx(LONG style) {
|
|
156 |
DASSERT(GetListHandle());
|
|
157 |
// SetWindowLong() error handling as recommended by Win32 API doc.
|
|
158 |
::SetLastError(0);
|
|
159 |
LONG ret = ::SetWindowLong(GetListHandle(), GWL_EXSTYLE, style);
|
|
160 |
DASSERT(ret != 0 || ::GetLastError() == 0);
|
|
161 |
}
|
|
162 |
|
|
163 |
INLINE HWND GetDBCSEditHandle() { return GetListHandle(); }
|
|
164 |
|
|
165 |
virtual BOOL InheritsNativeMouseWheelBehavior();
|
|
166 |
|
2464
|
167 |
virtual BOOL IsFocusingMouseMessage(MSG *pMsg);
|
|
168 |
|
2
|
169 |
// some methods called on Toolkit thread
|
|
170 |
static jint _GetMaxWidth(void *param);
|
|
171 |
static void _UpdateMaxItemWidth(void *param);
|
|
172 |
static void _AddItems(void *param);
|
|
173 |
static void _DelItems(void *param);
|
|
174 |
static void _Select(void *param);
|
|
175 |
static void _Deselect(void *param);
|
|
176 |
static void _MakeVisible(void *param);
|
|
177 |
static void _SetMultipleSelections(void *param);
|
|
178 |
static jboolean _IsSelected(void *param);
|
|
179 |
|
|
180 |
protected:
|
|
181 |
INLINE HWND GetListHandle() { return GetHWnd(); }
|
|
182 |
|
|
183 |
static BOOL IsListOwnerMessage(UINT message) {
|
|
184 |
switch (message) {
|
|
185 |
case WM_DRAWITEM:
|
|
186 |
case WM_MEASUREITEM:
|
|
187 |
case WM_COMMAND:
|
|
188 |
#if defined(WIN32)
|
|
189 |
case WM_CTLCOLORLISTBOX:
|
|
190 |
#else
|
|
191 |
case WM_CTLCOLOR:
|
|
192 |
#endif
|
|
193 |
return TRUE;
|
|
194 |
}
|
|
195 |
return FALSE;
|
|
196 |
}
|
|
197 |
|
|
198 |
static BOOL IsAwtMessage(UINT message) {
|
|
199 |
return (message >= WM_APP);
|
|
200 |
}
|
|
201 |
|
|
202 |
private:
|
|
203 |
BOOL isMultiSelect;
|
|
204 |
BOOL isWrapperPrint;
|
|
205 |
|
|
206 |
// The width of the longest item in the listbox
|
|
207 |
long m_nMaxWidth;
|
|
208 |
};
|
|
209 |
|
|
210 |
#endif /* AWT_LIST_H */
|