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