Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 1 | /* |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 2 | * Listbox controls |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright 1996 Alexandre Julliard |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 21 | #include <string.h> |
David Luyer | ee517e8 | 1999-02-28 12:27:56 +0000 | [diff] [blame] | 22 | #include <stdlib.h> |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 23 | #include <stdio.h> |
| 24 | #include "windef.h" |
| 25 | #include "wingdi.h" |
Alex Korobka | 311d329 | 1999-01-01 18:40:02 +0000 | [diff] [blame] | 26 | #include "wine/winuser16.h" |
Nick Holloway | b9ce4fd | 1999-09-11 16:29:00 +0000 | [diff] [blame] | 27 | #include "wine/winbase16.h" |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 28 | #include "wine/unicode.h" |
Alex Korobka | 311d329 | 1999-01-01 18:40:02 +0000 | [diff] [blame] | 29 | #include "winuser.h" |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 30 | #include "winerror.h" |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 31 | #include "spy.h" |
Alexandre Julliard | a41b2cf | 2001-01-15 20:12:55 +0000 | [diff] [blame] | 32 | #include "user.h" |
Alexandre Julliard | 91222da | 2000-12-10 23:01:33 +0000 | [diff] [blame] | 33 | #include "controls.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 34 | #include "wine/debug.h" |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 35 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 36 | WINE_DEFAULT_DEBUG_CHANNEL(listbox); |
| 37 | WINE_DECLARE_DEBUG_CHANNEL(combo); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 38 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 39 | /* Unimplemented yet: |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 40 | * - LBS_USETABSTOPS |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 41 | * - Locale handling |
Andreas Mohr | 85ba879 | 2001-01-06 00:34:14 +0000 | [diff] [blame] | 42 | * |
| 43 | * Probably needs improvement: |
| 44 | * - LBS_NOSEL |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 45 | */ |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 46 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 47 | /* Items array granularity */ |
| 48 | #define LB_ARRAY_GRANULARITY 16 |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 49 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 50 | /* Scrolling timeout in ms */ |
| 51 | #define LB_SCROLL_TIMEOUT 50 |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 52 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 53 | /* Listbox system timer id */ |
| 54 | #define LB_TIMER_ID 2 |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 55 | |
Gerard Patel | 41b07fb | 2000-06-15 00:07:20 +0000 | [diff] [blame] | 56 | /* flag listbox changed while setredraw false - internal style */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 57 | #define LBS_DISPLAYCHANGED 0x80000000 |
Gerard Patel | 41b07fb | 2000-06-15 00:07:20 +0000 | [diff] [blame] | 58 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 59 | /* Item structure */ |
| 60 | typedef struct |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 61 | { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 62 | LPWSTR str; /* Item text */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 63 | BOOL selected; /* Is item selected? */ |
| 64 | UINT height; /* Item height (only for OWNERDRAWVARIABLE) */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 65 | DWORD data; /* User data */ |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 66 | } LB_ITEMDATA; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 67 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 68 | /* Listbox structure */ |
| 69 | typedef struct |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 70 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 71 | HWND owner; /* Owner window to send notifications to */ |
| 72 | UINT style; /* Window style */ |
| 73 | INT width; /* Window width */ |
| 74 | INT height; /* Window height */ |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 75 | LB_ITEMDATA *items; /* Array of items */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 76 | INT nb_items; /* Number of items */ |
| 77 | INT top_item; /* Top visible item */ |
| 78 | INT selected_item; /* Selected item */ |
| 79 | INT focus_item; /* Item that has the focus */ |
| 80 | INT anchor_item; /* Anchor item for extended selection */ |
| 81 | INT item_height; /* Default item height */ |
| 82 | INT page_size; /* Items per listbox page */ |
| 83 | INT column_width; /* Column width for multi-column listboxes */ |
| 84 | INT horz_extent; /* Horizontal extent (0 if no hscroll) */ |
| 85 | INT horz_pos; /* Horizontal position */ |
| 86 | INT nb_tabs; /* Number of tabs in array */ |
| 87 | INT *tabs; /* Array of tabs */ |
| 88 | BOOL caret_on; /* Is caret on? */ |
Luc Tourangeau | 5ee117b | 1999-04-04 12:48:21 +0000 | [diff] [blame] | 89 | BOOL captured; /* Is mouse captured? */ |
Alexandre Julliard | ab2f43f | 2000-05-26 22:28:34 +0000 | [diff] [blame] | 90 | BOOL in_focus; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 91 | HFONT font; /* Current font */ |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 92 | LCID locale; /* Current locale for string comparisons */ |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 93 | LPHEADCOMBO lphc; /* ComboLBox */ |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 94 | } LB_DESCR; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 95 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 96 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 97 | #define IS_OWNERDRAW(descr) \ |
| 98 | ((descr)->style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 99 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 100 | #define HAS_STRINGS(descr) \ |
| 101 | (!IS_OWNERDRAW(descr) || ((descr)->style & LBS_HASSTRINGS)) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 102 | |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 103 | |
| 104 | #define IS_MULTISELECT(descr) \ |
| 105 | ((descr)->style & LBS_MULTIPLESEL || ((descr)->style & LBS_EXTENDEDSEL)) |
| 106 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 107 | #define SEND_NOTIFICATION(hwnd,descr,code) \ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 108 | (SendMessageW( (descr)->owner, WM_COMMAND, \ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 109 | MAKEWPARAM( GetWindowLongA((hwnd),GWL_ID), (code)), (hwnd) )) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 110 | |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 111 | #define ISWIN31 (LOWORD(GetVersion()) == 0x0a03) |
| 112 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 113 | /* Current timer status */ |
| 114 | typedef enum |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 115 | { |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 116 | LB_TIMER_NONE, |
| 117 | LB_TIMER_UP, |
| 118 | LB_TIMER_LEFT, |
| 119 | LB_TIMER_DOWN, |
| 120 | LB_TIMER_RIGHT |
| 121 | } TIMER_DIRECTION; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 122 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 123 | static TIMER_DIRECTION LISTBOX_Timer = LB_TIMER_NONE; |
| 124 | |
Alexandre Julliard | 91222da | 2000-12-10 23:01:33 +0000 | [diff] [blame] | 125 | static LRESULT WINAPI ComboLBWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 126 | static LRESULT WINAPI ComboLBWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ); |
Alexandre Julliard | 91222da | 2000-12-10 23:01:33 +0000 | [diff] [blame] | 127 | static LRESULT WINAPI ListBoxWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 128 | static LRESULT WINAPI ListBoxWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ); |
Alexandre Julliard | 91222da | 2000-12-10 23:01:33 +0000 | [diff] [blame] | 129 | |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 130 | static LRESULT LISTBOX_GetItemRect( LB_DESCR *descr, INT index, RECT *rect ); |
Alexandre Julliard | 91222da | 2000-12-10 23:01:33 +0000 | [diff] [blame] | 131 | |
| 132 | /********************************************************************* |
| 133 | * listbox class descriptor |
| 134 | */ |
| 135 | const struct builtin_class_descr LISTBOX_builtin_class = |
| 136 | { |
| 137 | "ListBox", /* name */ |
| 138 | CS_GLOBALCLASS | CS_DBLCLKS /*| CS_PARENTDC*/, /* style */ |
| 139 | ListBoxWndProcA, /* procA */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 140 | ListBoxWndProcW, /* procW */ |
Alexandre Julliard | 91222da | 2000-12-10 23:01:33 +0000 | [diff] [blame] | 141 | sizeof(LB_DESCR *), /* extra */ |
| 142 | IDC_ARROWA, /* cursor */ |
| 143 | 0 /* brush */ |
| 144 | }; |
| 145 | |
| 146 | |
| 147 | /********************************************************************* |
| 148 | * combolbox class descriptor |
| 149 | */ |
| 150 | const struct builtin_class_descr COMBOLBOX_builtin_class = |
| 151 | { |
| 152 | "ComboLBox", /* name */ |
| 153 | CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS, /* style */ |
| 154 | ComboLBWndProcA, /* procA */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 155 | ComboLBWndProcW, /* procW */ |
Alexandre Julliard | 91222da | 2000-12-10 23:01:33 +0000 | [diff] [blame] | 156 | sizeof(LB_DESCR *), /* extra */ |
| 157 | IDC_ARROWA, /* cursor */ |
| 158 | 0 /* brush */ |
| 159 | }; |
| 160 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 161 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 162 | /* check whether app is a Win 3.1 app */ |
| 163 | inline static BOOL is_old_app( HWND hwnd ) |
| 164 | { |
| 165 | return (GetExpWinVer16( GetWindowLongA(hwnd,GWL_HINSTANCE) ) & 0xFF00 ) == 0x0300; |
| 166 | } |
| 167 | |
| 168 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 169 | /*********************************************************************** |
| 170 | * LISTBOX_Dump |
| 171 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 172 | void LISTBOX_Dump( HWND hwnd ) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 173 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 174 | INT i; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 175 | LB_ITEMDATA *item; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 176 | LB_DESCR *descr = (LB_DESCR *)GetWindowLongA( hwnd, 0 ); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 177 | |
Alexandre Julliard | 9fe7a25 | 1999-05-14 08:17:14 +0000 | [diff] [blame] | 178 | TRACE( "Listbox:\n" ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 179 | TRACE( "hwnd=%04x descr=%08x items=%d top=%d\n", |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 180 | hwnd, (UINT)descr, descr->nb_items, |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 181 | descr->top_item ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 182 | for (i = 0, item = descr->items; i < descr->nb_items; i++, item++) |
| 183 | { |
Alexandre Julliard | 9fe7a25 | 1999-05-14 08:17:14 +0000 | [diff] [blame] | 184 | TRACE( "%4d: %-40s %d %08lx %3d\n", |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 185 | i, debugstr_w(item->str), item->selected, item->data, item->height ); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 186 | } |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 190 | /*********************************************************************** |
| 191 | * LISTBOX_GetCurrentPageSize |
| 192 | * |
| 193 | * Return the current page size |
| 194 | */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 195 | static INT LISTBOX_GetCurrentPageSize( LB_DESCR *descr ) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 196 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 197 | INT i, height; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 198 | if (!(descr->style & LBS_OWNERDRAWVARIABLE)) return descr->page_size; |
| 199 | for (i = descr->top_item, height = 0; i < descr->nb_items; i++) |
| 200 | { |
| 201 | if ((height += descr->items[i].height) > descr->height) break; |
| 202 | } |
| 203 | if (i == descr->top_item) return 1; |
| 204 | else return i - descr->top_item; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 208 | /*********************************************************************** |
| 209 | * LISTBOX_GetMaxTopIndex |
| 210 | * |
| 211 | * Return the maximum possible index for the top of the listbox. |
| 212 | */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 213 | static INT LISTBOX_GetMaxTopIndex( LB_DESCR *descr ) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 214 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 215 | INT max, page; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 216 | |
| 217 | if (descr->style & LBS_OWNERDRAWVARIABLE) |
| 218 | { |
| 219 | page = descr->height; |
| 220 | for (max = descr->nb_items - 1; max >= 0; max--) |
| 221 | if ((page -= descr->items[max].height) < 0) break; |
| 222 | if (max < descr->nb_items - 1) max++; |
| 223 | } |
| 224 | else if (descr->style & LBS_MULTICOLUMN) |
| 225 | { |
| 226 | if ((page = descr->width / descr->column_width) < 1) page = 1; |
| 227 | max = (descr->nb_items + descr->page_size - 1) / descr->page_size; |
| 228 | max = (max - page) * descr->page_size; |
| 229 | } |
| 230 | else |
| 231 | { |
| 232 | max = descr->nb_items - descr->page_size; |
| 233 | } |
| 234 | if (max < 0) max = 0; |
| 235 | return max; |
| 236 | } |
| 237 | |
| 238 | |
| 239 | /*********************************************************************** |
| 240 | * LISTBOX_UpdateScroll |
| 241 | * |
| 242 | * Update the scrollbars. Should be called whenever the content |
| 243 | * of the listbox changes. |
| 244 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 245 | static void LISTBOX_UpdateScroll( HWND hwnd, LB_DESCR *descr ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 246 | { |
| 247 | SCROLLINFO info; |
| 248 | |
Yuxi Zhang | f94c3c5 | 2000-02-26 19:13:12 +0000 | [diff] [blame] | 249 | /* Check the listbox scroll bar flags individually before we call |
| 250 | SetScrollInfo otherwise when the listbox style is WS_HSCROLL and |
| 251 | no WS_VSCROLL, we end up with an uninitialized, visible horizontal |
| 252 | scroll bar when we do not need one. |
| 253 | if (!(descr->style & WS_VSCROLL)) return; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 254 | */ |
Yuxi Zhang | f94c3c5 | 2000-02-26 19:13:12 +0000 | [diff] [blame] | 255 | |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame^] | 256 | /* It is important that we check descr->style, and not wnd->dwStyle, |
| 257 | for WS_VSCROLL, as the former is exactly the one passed in |
| 258 | argument to CreateWindow. |
| 259 | In Windows (and from now on in Wine :) a listbox created |
| 260 | with such a style (no WS_SCROLL) does not update |
| 261 | the scrollbar with listbox-related data, thus letting |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 262 | the programmer use it for his/her own purposes. */ |
| 263 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 264 | if (descr->style & LBS_NOREDRAW) return; |
| 265 | info.cbSize = sizeof(info); |
| 266 | |
| 267 | if (descr->style & LBS_MULTICOLUMN) |
| 268 | { |
| 269 | info.nMin = 0; |
| 270 | info.nMax = (descr->nb_items - 1) / descr->page_size; |
| 271 | info.nPos = descr->top_item / descr->page_size; |
| 272 | info.nPage = descr->width / descr->column_width; |
| 273 | if (info.nPage < 1) info.nPage = 1; |
| 274 | info.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; |
| 275 | if (descr->style & LBS_DISABLENOSCROLL) |
| 276 | info.fMask |= SIF_DISABLENOSCROLL; |
Yuxi Zhang | f94c3c5 | 2000-02-26 19:13:12 +0000 | [diff] [blame] | 277 | if (descr->style & WS_HSCROLL) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 278 | SetScrollInfo( hwnd, SB_HORZ, &info, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 279 | info.nMax = 0; |
| 280 | info.fMask = SIF_RANGE; |
Yuxi Zhang | f94c3c5 | 2000-02-26 19:13:12 +0000 | [diff] [blame] | 281 | if (descr->style & WS_VSCROLL) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 282 | SetScrollInfo( hwnd, SB_VERT, &info, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 283 | } |
| 284 | else |
| 285 | { |
| 286 | info.nMin = 0; |
| 287 | info.nMax = descr->nb_items - 1; |
| 288 | info.nPos = descr->top_item; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 289 | info.nPage = LISTBOX_GetCurrentPageSize( descr ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 290 | info.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; |
| 291 | if (descr->style & LBS_DISABLENOSCROLL) |
| 292 | info.fMask |= SIF_DISABLENOSCROLL; |
Yuxi Zhang | f94c3c5 | 2000-02-26 19:13:12 +0000 | [diff] [blame] | 293 | if (descr->style & WS_VSCROLL) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 294 | SetScrollInfo( hwnd, SB_VERT, &info, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 295 | |
| 296 | if (descr->horz_extent) |
| 297 | { |
| 298 | info.nMin = 0; |
| 299 | info.nMax = descr->horz_extent - 1; |
| 300 | info.nPos = descr->horz_pos; |
| 301 | info.nPage = descr->width; |
| 302 | info.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; |
| 303 | if (descr->style & LBS_DISABLENOSCROLL) |
| 304 | info.fMask |= SIF_DISABLENOSCROLL; |
Yuxi Zhang | f94c3c5 | 2000-02-26 19:13:12 +0000 | [diff] [blame] | 305 | if (descr->style & WS_HSCROLL) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 306 | SetScrollInfo( hwnd, SB_HORZ, &info, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | |
| 312 | /*********************************************************************** |
| 313 | * LISTBOX_SetTopItem |
| 314 | * |
| 315 | * Set the top item of the listbox, scrolling up or down if necessary. |
| 316 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 317 | static LRESULT LISTBOX_SetTopItem( HWND hwnd, LB_DESCR *descr, INT index, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 318 | BOOL scroll ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 319 | { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 320 | INT max = LISTBOX_GetMaxTopIndex( descr ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 321 | if (index > max) index = max; |
| 322 | if (index < 0) index = 0; |
| 323 | if (descr->style & LBS_MULTICOLUMN) index -= index % descr->page_size; |
| 324 | if (descr->top_item == index) return LB_OKAY; |
| 325 | if (descr->style & LBS_MULTICOLUMN) |
| 326 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 327 | INT diff = (descr->top_item - index) / descr->page_size * descr->column_width; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 328 | if (scroll && (abs(diff) < descr->width)) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 329 | ScrollWindowEx( hwnd, diff, 0, NULL, NULL, 0, NULL, |
NF Stevens | 762f18d | 1999-01-24 19:02:16 +0000 | [diff] [blame] | 330 | SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN ); |
| 331 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 332 | else |
| 333 | scroll = FALSE; |
| 334 | } |
| 335 | else if (scroll) |
| 336 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 337 | INT diff; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 338 | if (descr->style & LBS_OWNERDRAWVARIABLE) |
| 339 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 340 | INT i; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 341 | diff = 0; |
| 342 | if (index > descr->top_item) |
| 343 | { |
| 344 | for (i = index - 1; i >= descr->top_item; i--) |
| 345 | diff -= descr->items[i].height; |
| 346 | } |
| 347 | else |
| 348 | { |
| 349 | for (i = index; i < descr->top_item; i++) |
| 350 | diff += descr->items[i].height; |
| 351 | } |
| 352 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 353 | else |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 354 | diff = (descr->top_item - index) * descr->item_height; |
| 355 | |
| 356 | if (abs(diff) < descr->height) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 357 | ScrollWindowEx( hwnd, 0, diff, NULL, NULL, 0, NULL, |
NF Stevens | 762f18d | 1999-01-24 19:02:16 +0000 | [diff] [blame] | 358 | SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 359 | else |
| 360 | scroll = FALSE; |
| 361 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 362 | if (!scroll) InvalidateRect( hwnd, NULL, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 363 | descr->top_item = index; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 364 | LISTBOX_UpdateScroll( hwnd, descr ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 365 | return LB_OKAY; |
| 366 | } |
| 367 | |
| 368 | |
| 369 | /*********************************************************************** |
| 370 | * LISTBOX_UpdatePage |
| 371 | * |
| 372 | * Update the page size. Should be called when the size of |
| 373 | * the client area or the item height changes. |
| 374 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 375 | static void LISTBOX_UpdatePage( HWND hwnd, LB_DESCR *descr ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 376 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 377 | INT page_size; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 378 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 379 | if ((descr->item_height == 0) || (page_size = descr->height / descr->item_height) < 1) |
Paul Quinn | 7572207 | 1999-05-22 18:45:06 +0000 | [diff] [blame] | 380 | page_size = 1; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 381 | if (page_size == descr->page_size) return; |
| 382 | descr->page_size = page_size; |
| 383 | if (descr->style & LBS_MULTICOLUMN) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 384 | InvalidateRect( hwnd, NULL, TRUE ); |
| 385 | LISTBOX_SetTopItem( hwnd, descr, descr->top_item, FALSE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | |
| 389 | /*********************************************************************** |
| 390 | * LISTBOX_UpdateSize |
| 391 | * |
| 392 | * Update the size of the listbox. Should be called when the size of |
| 393 | * the client area changes. |
| 394 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 395 | static void LISTBOX_UpdateSize( HWND hwnd, LB_DESCR *descr ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 396 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 397 | RECT rect; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 398 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 399 | GetClientRect( hwnd, &rect ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 400 | descr->width = rect.right - rect.left; |
| 401 | descr->height = rect.bottom - rect.top; |
Alexandre Julliard | 72bdd5b | 2000-06-07 03:17:35 +0000 | [diff] [blame] | 402 | if (!(descr->style & LBS_NOINTEGRALHEIGHT) && !(descr->style & LBS_OWNERDRAWVARIABLE)) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 403 | { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 404 | INT remaining; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 405 | RECT rect; |
Mike McCormack | 5ae1c39 | 2000-09-09 19:39:24 +0000 | [diff] [blame] | 406 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 407 | GetWindowRect( hwnd, &rect ); |
Mike McCormack | 5ae1c39 | 2000-09-09 19:39:24 +0000 | [diff] [blame] | 408 | if(descr->item_height != 0) |
| 409 | remaining = descr->height % descr->item_height; |
| 410 | else |
| 411 | remaining = 0; |
Gerard Patel | cef1253 | 2000-08-01 20:48:40 +0000 | [diff] [blame] | 412 | if ((descr->height > descr->item_height) && remaining) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 413 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 414 | if (is_old_app(hwnd)) |
Gerard Patel | cef1253 | 2000-08-01 20:48:40 +0000 | [diff] [blame] | 415 | { /* give a margin for error to 16 bits programs - if we need |
| 416 | less than the height of the nonclient area, round to the |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 417 | *next* number of items */ |
| 418 | int ncheight = rect.bottom - rect.top - descr->height; |
Gerard Patel | cef1253 | 2000-08-01 20:48:40 +0000 | [diff] [blame] | 419 | if ((descr->item_height - remaining) <= ncheight) |
| 420 | remaining = remaining - descr->item_height; |
| 421 | } |
Alexandre Julliard | 9fe7a25 | 1999-05-14 08:17:14 +0000 | [diff] [blame] | 422 | TRACE("[%04x]: changing height %d -> %d\n", |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 423 | hwnd, descr->height, descr->height - remaining ); |
| 424 | SetWindowPos( hwnd, 0, 0, 0, rect.right - rect.left, |
| 425 | rect.bottom - rect.top - remaining, |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 426 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 427 | return; |
| 428 | } |
| 429 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 430 | TRACE("[%04x]: new size = %d,%d\n", hwnd, descr->width, descr->height ); |
| 431 | LISTBOX_UpdatePage( hwnd, descr ); |
| 432 | LISTBOX_UpdateScroll( hwnd, descr ); |
Louis Philippe Gagnon | 956c847 | 2000-12-13 21:26:45 +0000 | [diff] [blame] | 433 | |
| 434 | /* Invalidate the focused item so it will be repainted correctly */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 435 | if (LISTBOX_GetItemRect( descr, descr->focus_item, &rect ) == 1) |
Louis Philippe Gagnon | 956c847 | 2000-12-13 21:26:45 +0000 | [diff] [blame] | 436 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 437 | InvalidateRect( hwnd, &rect, FALSE ); |
Louis Philippe Gagnon | 956c847 | 2000-12-13 21:26:45 +0000 | [diff] [blame] | 438 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | |
| 442 | /*********************************************************************** |
| 443 | * LISTBOX_GetItemRect |
| 444 | * |
| 445 | * Get the rectangle enclosing an item, in listbox client coordinates. |
| 446 | * Return 1 if the rectangle is (partially) visible, 0 if hidden, -1 on error. |
| 447 | */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 448 | static LRESULT LISTBOX_GetItemRect( LB_DESCR *descr, INT index, RECT *rect ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 449 | { |
| 450 | /* Index <= 0 is legal even on empty listboxes */ |
| 451 | if (index && (index >= descr->nb_items)) return -1; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 452 | SetRect( rect, 0, 0, descr->width, descr->height ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 453 | if (descr->style & LBS_MULTICOLUMN) |
| 454 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 455 | INT col = (index / descr->page_size) - |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 456 | (descr->top_item / descr->page_size); |
| 457 | rect->left += col * descr->column_width; |
| 458 | rect->right = rect->left + descr->column_width; |
| 459 | rect->top += (index % descr->page_size) * descr->item_height; |
| 460 | rect->bottom = rect->top + descr->item_height; |
| 461 | } |
| 462 | else if (descr->style & LBS_OWNERDRAWVARIABLE) |
| 463 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 464 | INT i; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 465 | rect->right += descr->horz_pos; |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 466 | if ((index >= 0) && (index < descr->nb_items)) |
| 467 | { |
| 468 | if (index < descr->top_item) |
| 469 | { |
| 470 | for (i = descr->top_item-1; i >= index; i--) |
| 471 | rect->top -= descr->items[i].height; |
| 472 | } |
| 473 | else |
| 474 | { |
| 475 | for (i = descr->top_item; i < index; i++) |
| 476 | rect->top += descr->items[i].height; |
| 477 | } |
| 478 | rect->bottom = rect->top + descr->items[index].height; |
| 479 | |
| 480 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 481 | } |
| 482 | else |
| 483 | { |
| 484 | rect->top += (index - descr->top_item) * descr->item_height; |
| 485 | rect->bottom = rect->top + descr->item_height; |
| 486 | rect->right += descr->horz_pos; |
| 487 | } |
| 488 | |
| 489 | return ((rect->left < descr->width) && (rect->right > 0) && |
| 490 | (rect->top < descr->height) && (rect->bottom > 0)); |
| 491 | } |
| 492 | |
| 493 | |
| 494 | /*********************************************************************** |
| 495 | * LISTBOX_GetItemFromPoint |
| 496 | * |
| 497 | * Return the item nearest from point (x,y) (in client coordinates). |
| 498 | */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 499 | static INT LISTBOX_GetItemFromPoint( LB_DESCR *descr, INT x, INT y ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 500 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 501 | INT index = descr->top_item; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 502 | |
| 503 | if (!descr->nb_items) return -1; /* No items */ |
| 504 | if (descr->style & LBS_OWNERDRAWVARIABLE) |
| 505 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 506 | INT pos = 0; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 507 | if (y >= 0) |
| 508 | { |
| 509 | while (index < descr->nb_items) |
| 510 | { |
| 511 | if ((pos += descr->items[index].height) > y) break; |
| 512 | index++; |
| 513 | } |
| 514 | } |
| 515 | else |
| 516 | { |
| 517 | while (index > 0) |
| 518 | { |
| 519 | index--; |
| 520 | if ((pos -= descr->items[index].height) <= y) break; |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | else if (descr->style & LBS_MULTICOLUMN) |
| 525 | { |
| 526 | if (y >= descr->item_height * descr->page_size) return -1; |
| 527 | if (y >= 0) index += y / descr->item_height; |
| 528 | if (x >= 0) index += (x / descr->column_width) * descr->page_size; |
| 529 | else index -= (((x + 1) / descr->column_width) - 1) * descr->page_size; |
| 530 | } |
| 531 | else |
| 532 | { |
| 533 | index += (y / descr->item_height); |
| 534 | } |
| 535 | if (index < 0) return 0; |
| 536 | if (index >= descr->nb_items) return -1; |
| 537 | return index; |
| 538 | } |
| 539 | |
| 540 | |
| 541 | /*********************************************************************** |
| 542 | * LISTBOX_PaintItem |
| 543 | * |
| 544 | * Paint an item. |
| 545 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 546 | static void LISTBOX_PaintItem( HWND hwnd, LB_DESCR *descr, HDC hdc, |
Gerard Patel | 8caa407 | 2000-09-24 19:29:18 +0000 | [diff] [blame] | 547 | const RECT *rect, INT index, UINT action, BOOL ignoreFocus ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 548 | { |
| 549 | LB_ITEMDATA *item = NULL; |
| 550 | if (index < descr->nb_items) item = &descr->items[index]; |
| 551 | |
| 552 | if (IS_OWNERDRAW(descr)) |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 553 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 554 | DRAWITEMSTRUCT dis; |
Gerard Patel | 9788ba6 | 2000-07-16 15:39:37 +0000 | [diff] [blame] | 555 | RECT r; |
| 556 | HRGN hrgn; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 557 | UINT id = GetWindowLongA( hwnd, GWL_ID ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 558 | |
Marcus Meissner | 9ad9017 | 1999-01-20 14:08:00 +0000 | [diff] [blame] | 559 | if (!item) |
| 560 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 561 | if (action == ODA_FOCUS) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 562 | DrawFocusRect( hdc, rect ); |
Marcus Meissner | 9ad9017 | 1999-01-20 14:08:00 +0000 | [diff] [blame] | 563 | else |
Alexandre Julliard | 9fe7a25 | 1999-05-14 08:17:14 +0000 | [diff] [blame] | 564 | FIXME("called with an out of bounds index %d(%d) in owner draw, Not good.\n",index,descr->nb_items); |
Marcus Meissner | 9ad9017 | 1999-01-20 14:08:00 +0000 | [diff] [blame] | 565 | return; |
| 566 | } |
Gerard Patel | 9788ba6 | 2000-07-16 15:39:37 +0000 | [diff] [blame] | 567 | |
| 568 | /* some programs mess with the clipping region when |
| 569 | drawing the item, *and* restore the previous region |
| 570 | after they are done, so a region has better to exist |
| 571 | else everything ends clipped */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 572 | GetClientRect(hwnd, &r); |
Gerard Patel | 9788ba6 | 2000-07-16 15:39:37 +0000 | [diff] [blame] | 573 | hrgn = CreateRectRgnIndirect(&r); |
| 574 | SelectClipRgn( hdc, hrgn); |
| 575 | DeleteObject( hrgn ); |
| 576 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 577 | dis.CtlType = ODT_LISTBOX; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 578 | dis.CtlID = id; |
| 579 | dis.hwndItem = hwnd; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 580 | dis.itemAction = action; |
| 581 | dis.hDC = hdc; |
| 582 | dis.itemID = index; |
| 583 | dis.itemState = 0; |
| 584 | if (item && item->selected) dis.itemState |= ODS_SELECTED; |
Gerard Patel | 8caa407 | 2000-09-24 19:29:18 +0000 | [diff] [blame] | 585 | if (!ignoreFocus && (descr->focus_item == index) && |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 586 | (descr->caret_on) && |
Alexandre Julliard | ab2f43f | 2000-05-26 22:28:34 +0000 | [diff] [blame] | 587 | (descr->in_focus)) dis.itemState |= ODS_FOCUS; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 588 | if (!IsWindowEnabled(hwnd)) dis.itemState |= ODS_DISABLED; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 589 | dis.itemData = item ? item->data : 0; |
| 590 | dis.rcItem = *rect; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 591 | TRACE("[%04x]: drawitem %d (%s) action=%02x state=%02x rect=%d,%d-%d,%d\n", |
| 592 | hwnd, index, item ? debugstr_w(item->str) : "", action, |
| 593 | dis.itemState, rect->left, rect->top, rect->right, rect->bottom ); |
| 594 | SendMessageW(descr->owner, WM_DRAWITEM, id, (LPARAM)&dis); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 595 | } |
| 596 | else |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 597 | { |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 598 | COLORREF oldText = 0, oldBk = 0; |
| 599 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 600 | if (action == ODA_FOCUS) |
| 601 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 602 | DrawFocusRect( hdc, rect ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 603 | return; |
| 604 | } |
| 605 | if (item && item->selected) |
| 606 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 607 | oldBk = SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) ); |
| 608 | oldText = SetTextColor( hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 609 | } |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 610 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 611 | TRACE("[%04x]: painting %d (%s) action=%02x rect=%d,%d-%d,%d\n", |
| 612 | hwnd, index, item ? debugstr_w(item->str) : "", action, |
| 613 | rect->left, rect->top, rect->right, rect->bottom ); |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 614 | if (!item) |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 615 | ExtTextOutW( hdc, rect->left + 1, rect->top, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 616 | ETO_OPAQUE | ETO_CLIPPED, rect, NULL, 0, NULL ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 617 | else if (!(descr->style & LBS_USETABSTOPS)) |
| 618 | ExtTextOutW( hdc, rect->left + 1, rect->top, |
| 619 | ETO_OPAQUE | ETO_CLIPPED, rect, item->str, |
| 620 | strlenW(item->str), NULL ); |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 621 | else |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 622 | { |
| 623 | /* Output empty string to paint background in the full width. */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 624 | ExtTextOutW( hdc, rect->left + 1, rect->top, |
| 625 | ETO_OPAQUE | ETO_CLIPPED, rect, NULL, 0, NULL ); |
| 626 | TabbedTextOutW( hdc, rect->left + 1 , rect->top, |
| 627 | item->str, strlenW(item->str), |
| 628 | descr->nb_tabs, descr->tabs, 0); |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 629 | } |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 630 | if (item && item->selected) |
| 631 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 632 | SetBkColor( hdc, oldBk ); |
| 633 | SetTextColor( hdc, oldText ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 634 | } |
Gerard Patel | 8caa407 | 2000-09-24 19:29:18 +0000 | [diff] [blame] | 635 | if (!ignoreFocus && (descr->focus_item == index) && |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 636 | (descr->caret_on) && |
Alexandre Julliard | ab2f43f | 2000-05-26 22:28:34 +0000 | [diff] [blame] | 637 | (descr->in_focus)) DrawFocusRect( hdc, rect ); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 638 | } |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 641 | |
| 642 | /*********************************************************************** |
| 643 | * LISTBOX_SetRedraw |
| 644 | * |
| 645 | * Change the redraw flag. |
| 646 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 647 | static void LISTBOX_SetRedraw( HWND hwnd, LB_DESCR *descr, BOOL on ) |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 648 | { |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 649 | if (on) |
| 650 | { |
| 651 | if (!(descr->style & LBS_NOREDRAW)) return; |
| 652 | descr->style &= ~LBS_NOREDRAW; |
Gerard Patel | 41b07fb | 2000-06-15 00:07:20 +0000 | [diff] [blame] | 653 | if (descr->style & LBS_DISPLAYCHANGED) |
| 654 | { /* page was changed while setredraw false, refresh automatically */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 655 | InvalidateRect(hwnd, NULL, TRUE); |
Gerard Patel | 41b07fb | 2000-06-15 00:07:20 +0000 | [diff] [blame] | 656 | if ((descr->top_item + descr->page_size) > descr->nb_items) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 657 | { /* reset top of page if less than number of items/page */ |
Gerard Patel | 41b07fb | 2000-06-15 00:07:20 +0000 | [diff] [blame] | 658 | descr->top_item = descr->nb_items - descr->page_size; |
| 659 | if (descr->top_item < 0) descr->top_item = 0; |
| 660 | } |
| 661 | descr->style &= ~LBS_DISPLAYCHANGED; |
| 662 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 663 | LISTBOX_UpdateScroll( hwnd, descr ); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 664 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 665 | else descr->style |= LBS_NOREDRAW; |
| 666 | } |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 667 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 668 | |
| 669 | /*********************************************************************** |
| 670 | * LISTBOX_RepaintItem |
| 671 | * |
| 672 | * Repaint a single item synchronously. |
| 673 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 674 | static void LISTBOX_RepaintItem( HWND hwnd, LB_DESCR *descr, INT index, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 675 | UINT action ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 676 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 677 | HDC hdc; |
| 678 | RECT rect; |
| 679 | HFONT oldFont = 0; |
| 680 | HBRUSH hbrush, oldBrush = 0; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 681 | |
Francois Boisvert | 428d298 | 1999-05-08 09:33:53 +0000 | [diff] [blame] | 682 | /* Do not repaint the item if the item is not visible */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 683 | if (!IsWindowVisible(hwnd)) return; |
Gerard Patel | 41b07fb | 2000-06-15 00:07:20 +0000 | [diff] [blame] | 684 | if (descr->style & LBS_NOREDRAW) |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 685 | { |
Gerard Patel | 41b07fb | 2000-06-15 00:07:20 +0000 | [diff] [blame] | 686 | descr->style |= LBS_DISPLAYCHANGED; |
| 687 | return; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 688 | } |
| 689 | if (LISTBOX_GetItemRect( descr, index, &rect ) != 1) return; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 690 | if (!(hdc = GetDCEx( hwnd, 0, DCX_CACHE ))) return; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 691 | if (descr->font) oldFont = SelectObject( hdc, descr->font ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 692 | hbrush = SendMessageW( descr->owner, WM_CTLCOLORLISTBOX, |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 693 | hdc, (LPARAM)hwnd ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 694 | if (hbrush) oldBrush = SelectObject( hdc, hbrush ); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 695 | if (!IsWindowEnabled(hwnd)) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 696 | SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) ); |
| 697 | SetWindowOrgEx( hdc, descr->horz_pos, 0, NULL ); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 698 | LISTBOX_PaintItem( hwnd, descr, hdc, &rect, index, action, FALSE ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 699 | if (oldFont) SelectObject( hdc, oldFont ); |
| 700 | if (oldBrush) SelectObject( hdc, oldBrush ); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 701 | ReleaseDC( hwnd, hdc ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | |
| 705 | /*********************************************************************** |
| 706 | * LISTBOX_InitStorage |
| 707 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 708 | static LRESULT LISTBOX_InitStorage( HWND hwnd, LB_DESCR *descr, INT nb_items ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 709 | { |
| 710 | LB_ITEMDATA *item; |
| 711 | |
| 712 | nb_items += LB_ARRAY_GRANULARITY - 1; |
| 713 | nb_items -= (nb_items % LB_ARRAY_GRANULARITY); |
| 714 | if (descr->items) |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 715 | nb_items += HeapSize( GetProcessHeap(), 0, descr->items ) / sizeof(*item); |
| 716 | if (!(item = HeapReAlloc( GetProcessHeap(), 0, descr->items, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 717 | nb_items * sizeof(LB_ITEMDATA) ))) |
| 718 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 719 | SEND_NOTIFICATION( hwnd, descr, LBN_ERRSPACE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 720 | return LB_ERRSPACE; |
| 721 | } |
| 722 | descr->items = item; |
| 723 | return LB_OKAY; |
| 724 | } |
| 725 | |
| 726 | |
| 727 | /*********************************************************************** |
| 728 | * LISTBOX_SetTabStops |
| 729 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 730 | static BOOL LISTBOX_SetTabStops( HWND hwnd, LB_DESCR *descr, INT count, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 731 | LPINT tabs, BOOL short_ints ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 732 | { |
| 733 | if (!(descr->style & LBS_USETABSTOPS)) return TRUE; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 734 | if (descr->tabs) HeapFree( GetProcessHeap(), 0, descr->tabs ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 735 | if (!(descr->nb_tabs = count)) |
| 736 | { |
| 737 | descr->tabs = NULL; |
| 738 | return TRUE; |
| 739 | } |
| 740 | /* FIXME: count = 1 */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 741 | if (!(descr->tabs = (INT *)HeapAlloc( GetProcessHeap(), 0, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 742 | descr->nb_tabs * sizeof(INT) ))) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 743 | return FALSE; |
| 744 | if (short_ints) |
| 745 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 746 | INT i; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 747 | LPINT16 p = (LPINT16)tabs; |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 748 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 749 | TRACE("[%04x]: settabstops ", hwnd ); |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 750 | for (i = 0; i < descr->nb_tabs; i++) { |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 751 | descr->tabs[i] = *p++<<1; /* FIXME */ |
Alexandre Julliard | 15de615 | 1999-08-04 12:22:42 +0000 | [diff] [blame] | 752 | if (TRACE_ON(listbox)) DPRINTF("%hd ", descr->tabs[i]); |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 753 | } |
Alexandre Julliard | 15de615 | 1999-08-04 12:22:42 +0000 | [diff] [blame] | 754 | if (TRACE_ON(listbox)) DPRINTF("\n"); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 755 | } |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 756 | else memcpy( descr->tabs, tabs, descr->nb_tabs * sizeof(INT) ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 757 | /* FIXME: repaint the window? */ |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 758 | return TRUE; |
| 759 | } |
| 760 | |
| 761 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 762 | /*********************************************************************** |
| 763 | * LISTBOX_GetText |
| 764 | */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 765 | static LRESULT LISTBOX_GetText( LB_DESCR *descr, INT index, LPARAM lParam, BOOL unicode ) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 766 | { |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 767 | if ((index < 0) || (index >= descr->nb_items)) return LB_ERR; |
| 768 | if (HAS_STRINGS(descr)) |
| 769 | { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 770 | if (!lParam) |
| 771 | return strlenW(descr->items[index].str); |
| 772 | |
Dmitry Timoshkov | e8ffcaa | 2001-04-16 19:32:19 +0000 | [diff] [blame] | 773 | TRACE("index %d (0x%04x) %s\n", index, index, debugstr_w(descr->items[index].str)); |
| 774 | |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 775 | if(unicode) |
| 776 | { |
| 777 | LPWSTR buffer = (LPWSTR)lParam; |
| 778 | strcpyW( buffer, descr->items[index].str ); |
| 779 | return strlenW(buffer); |
| 780 | } |
| 781 | else |
| 782 | { |
| 783 | LPSTR buffer = (LPSTR)lParam; |
Gerard Patel | db8fb6f | 2001-01-10 23:54:46 +0000 | [diff] [blame] | 784 | return WideCharToMultiByte(CP_ACP, 0, descr->items[index].str, -1, buffer, 0x7FFFFFFF, NULL, NULL) - 1; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 785 | } |
Marcus Meissner | 4f7dc46 | 1998-11-22 15:43:34 +0000 | [diff] [blame] | 786 | } else { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 787 | if (lParam) |
| 788 | *((LPDWORD)lParam)=*(LPDWORD)(&descr->items[index].data); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 789 | return sizeof(DWORD); |
| 790 | } |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 794 | /*********************************************************************** |
| 795 | * LISTBOX_FindStringPos |
| 796 | * |
| 797 | * Find the nearest string located before a given string in sort order. |
| 798 | * If 'exact' is TRUE, return an error if we don't get an exact match. |
| 799 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 800 | static INT LISTBOX_FindStringPos( HWND hwnd, LB_DESCR *descr, LPCWSTR str, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 801 | BOOL exact ) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 802 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 803 | INT index, min, max, res = -1; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 804 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 805 | if (!(descr->style & LBS_SORT)) return -1; /* Add it at the end */ |
| 806 | min = 0; |
| 807 | max = descr->nb_items; |
| 808 | while (min != max) |
| 809 | { |
| 810 | index = (min + max) / 2; |
| 811 | if (HAS_STRINGS(descr)) |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 812 | res = lstrcmpiW( descr->items[index].str, str ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 813 | else |
| 814 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 815 | COMPAREITEMSTRUCT cis; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 816 | UINT id = GetWindowLongA( hwnd, GWL_ID ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 817 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 818 | cis.CtlType = ODT_LISTBOX; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 819 | cis.CtlID = id; |
| 820 | cis.hwndItem = hwnd; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 821 | cis.itemID1 = index; |
| 822 | cis.itemData1 = descr->items[index].data; |
| 823 | cis.itemID2 = -1; |
| 824 | cis.itemData2 = (DWORD)str; |
| 825 | cis.dwLocaleId = descr->locale; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 826 | res = SendMessageW( descr->owner, WM_COMPAREITEM, id, (LPARAM)&cis ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 827 | } |
| 828 | if (!res) return index; |
| 829 | if (res > 0) max = index; |
| 830 | else min = index + 1; |
| 831 | } |
| 832 | return exact ? -1 : max; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 836 | /*********************************************************************** |
| 837 | * LISTBOX_FindFileStrPos |
| 838 | * |
| 839 | * Find the nearest string located before a given string in directory |
| 840 | * sort order (i.e. first files, then directories, then drives). |
| 841 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 842 | static INT LISTBOX_FindFileStrPos( HWND hwnd, LB_DESCR *descr, LPCWSTR str ) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 843 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 844 | INT min, max, res = -1; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 845 | |
| 846 | if (!HAS_STRINGS(descr)) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 847 | return LISTBOX_FindStringPos( hwnd, descr, str, FALSE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 848 | min = 0; |
| 849 | max = descr->nb_items; |
| 850 | while (min != max) |
| 851 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 852 | INT index = (min + max) / 2; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 853 | LPCWSTR p = descr->items[index].str; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 854 | if (*p == '[') /* drive or directory */ |
| 855 | { |
| 856 | if (*str != '[') res = -1; |
| 857 | else if (p[1] == '-') /* drive */ |
| 858 | { |
| 859 | if (str[1] == '-') res = str[2] - p[2]; |
| 860 | else res = -1; |
| 861 | } |
| 862 | else /* directory */ |
| 863 | { |
| 864 | if (str[1] == '-') res = 1; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 865 | else res = lstrcmpiW( str, p ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | else /* filename */ |
| 869 | { |
| 870 | if (*str == '[') res = 1; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 871 | else res = lstrcmpiW( str, p ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 872 | } |
| 873 | if (!res) return index; |
| 874 | if (res < 0) max = index; |
| 875 | else min = index + 1; |
| 876 | } |
| 877 | return max; |
| 878 | } |
| 879 | |
| 880 | |
| 881 | /*********************************************************************** |
| 882 | * LISTBOX_FindString |
| 883 | * |
| 884 | * Find the item beginning with a given string. |
| 885 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 886 | static INT LISTBOX_FindString( HWND hwnd, LB_DESCR *descr, INT start, |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 887 | LPCWSTR str, BOOL exact ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 888 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 889 | INT i; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 890 | LB_ITEMDATA *item; |
| 891 | |
| 892 | if (start >= descr->nb_items) start = -1; |
| 893 | item = descr->items + start + 1; |
| 894 | if (HAS_STRINGS(descr)) |
| 895 | { |
Rein Klazes | d35c834 | 1999-08-21 13:04:58 +0000 | [diff] [blame] | 896 | if (!str || ! str[0] ) return LB_ERR; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 897 | if (exact) |
| 898 | { |
| 899 | for (i = start + 1; i < descr->nb_items; i++, item++) |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 900 | if (!lstrcmpiW( str, item->str )) return i; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 901 | for (i = 0, item = descr->items; i <= start; i++, item++) |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 902 | if (!lstrcmpiW( str, item->str )) return i; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 903 | } |
| 904 | else |
| 905 | { |
| 906 | /* Special case for drives and directories: ignore prefix */ |
| 907 | #define CHECK_DRIVE(item) \ |
| 908 | if ((item)->str[0] == '[') \ |
| 909 | { \ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 910 | if (!strncmpiW( str, (item)->str+1, len )) return i; \ |
| 911 | if (((item)->str[1] == '-') && !strncmpiW(str, (item)->str+2, len)) \ |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 912 | return i; \ |
| 913 | } |
| 914 | |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 915 | INT len = strlenW(str); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 916 | for (i = start + 1; i < descr->nb_items; i++, item++) |
| 917 | { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 918 | if (!strncmpiW( str, item->str, len )) return i; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 919 | CHECK_DRIVE(item); |
| 920 | } |
| 921 | for (i = 0, item = descr->items; i <= start; i++, item++) |
| 922 | { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 923 | if (!strncmpiW( str, item->str, len )) return i; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 924 | CHECK_DRIVE(item); |
| 925 | } |
| 926 | #undef CHECK_DRIVE |
| 927 | } |
| 928 | } |
| 929 | else |
| 930 | { |
| 931 | if (exact && (descr->style & LBS_SORT)) |
| 932 | /* If sorted, use a WM_COMPAREITEM binary search */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 933 | return LISTBOX_FindStringPos( hwnd, descr, str, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 934 | |
| 935 | /* Otherwise use a linear search */ |
| 936 | for (i = start + 1; i < descr->nb_items; i++, item++) |
| 937 | if (item->data == (DWORD)str) return i; |
| 938 | for (i = 0, item = descr->items; i <= start; i++, item++) |
| 939 | if (item->data == (DWORD)str) return i; |
| 940 | } |
| 941 | return LB_ERR; |
| 942 | } |
| 943 | |
| 944 | |
| 945 | /*********************************************************************** |
| 946 | * LISTBOX_GetSelCount |
| 947 | */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 948 | static LRESULT LISTBOX_GetSelCount( LB_DESCR *descr ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 949 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 950 | INT i, count; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 951 | LB_ITEMDATA *item = descr->items; |
| 952 | |
| 953 | if (!(descr->style & LBS_MULTIPLESEL)) return LB_ERR; |
| 954 | for (i = count = 0; i < descr->nb_items; i++, item++) |
| 955 | if (item->selected) count++; |
| 956 | return count; |
| 957 | } |
| 958 | |
| 959 | |
| 960 | /*********************************************************************** |
| 961 | * LISTBOX_GetSelItems16 |
| 962 | */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 963 | static LRESULT LISTBOX_GetSelItems16( LB_DESCR *descr, INT16 max, LPINT16 array ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 964 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 965 | INT i, count; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 966 | LB_ITEMDATA *item = descr->items; |
| 967 | |
| 968 | if (!(descr->style & LBS_MULTIPLESEL)) return LB_ERR; |
| 969 | for (i = count = 0; (i < descr->nb_items) && (count < max); i++, item++) |
| 970 | if (item->selected) array[count++] = (INT16)i; |
| 971 | return count; |
| 972 | } |
| 973 | |
| 974 | |
| 975 | /*********************************************************************** |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 976 | * LISTBOX_GetSelItems |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 977 | */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 978 | static LRESULT LISTBOX_GetSelItems( LB_DESCR *descr, INT max, LPINT array ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 979 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 980 | INT i, count; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 981 | LB_ITEMDATA *item = descr->items; |
| 982 | |
| 983 | if (!(descr->style & LBS_MULTIPLESEL)) return LB_ERR; |
| 984 | for (i = count = 0; (i < descr->nb_items) && (count < max); i++, item++) |
| 985 | if (item->selected) array[count++] = i; |
| 986 | return count; |
| 987 | } |
| 988 | |
| 989 | |
| 990 | /*********************************************************************** |
| 991 | * LISTBOX_Paint |
| 992 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 993 | static LRESULT LISTBOX_Paint( HWND hwnd, LB_DESCR *descr, HDC hdc ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 994 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 995 | INT i, col_pos = descr->page_size - 1; |
| 996 | RECT rect; |
Alexandre Julliard | 72bdd5b | 2000-06-07 03:17:35 +0000 | [diff] [blame] | 997 | RECT focusRect = {-1, -1, -1, -1}; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 998 | HFONT oldFont = 0; |
| 999 | HBRUSH hbrush, oldBrush = 0; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1000 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1001 | if (descr->style & LBS_NOREDRAW) return 0; |
Serge Ivanov | 07917e4 | 2000-06-07 03:46:57 +0000 | [diff] [blame] | 1002 | |
| 1003 | SetRect( &rect, 0, 0, descr->width, descr->height ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1004 | if (descr->style & LBS_MULTICOLUMN) |
| 1005 | rect.right = rect.left + descr->column_width; |
| 1006 | else if (descr->horz_pos) |
| 1007 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1008 | SetWindowOrgEx( hdc, descr->horz_pos, 0, NULL ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1009 | rect.right += descr->horz_pos; |
| 1010 | } |
| 1011 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1012 | if (descr->font) oldFont = SelectObject( hdc, descr->font ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1013 | hbrush = SendMessageW( descr->owner, WM_CTLCOLORLISTBOX, |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1014 | hdc, (LPARAM)hwnd ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1015 | if (hbrush) oldBrush = SelectObject( hdc, hbrush ); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1016 | if (!IsWindowEnabled(hwnd)) SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1017 | |
| 1018 | if (!descr->nb_items && (descr->focus_item != -1) && descr->caret_on && |
Alexandre Julliard | ab2f43f | 2000-05-26 22:28:34 +0000 | [diff] [blame] | 1019 | (descr->in_focus)) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1020 | { |
| 1021 | /* Special case for empty listbox: paint focus rect */ |
| 1022 | rect.bottom = rect.top + descr->item_height; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1023 | LISTBOX_PaintItem( hwnd, descr, hdc, &rect, descr->focus_item, |
Gerard Patel | 8caa407 | 2000-09-24 19:29:18 +0000 | [diff] [blame] | 1024 | ODA_FOCUS, FALSE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1025 | rect.top = rect.bottom; |
| 1026 | } |
| 1027 | |
Alexandre Julliard | 72bdd5b | 2000-06-07 03:17:35 +0000 | [diff] [blame] | 1028 | /* Paint all the item, regarding the selection |
| 1029 | Focus state will be painted after */ |
Alexandre Julliard | 72bdd5b | 2000-06-07 03:17:35 +0000 | [diff] [blame] | 1030 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1031 | for (i = descr->top_item; i < descr->nb_items; i++) |
| 1032 | { |
| 1033 | if (!(descr->style & LBS_OWNERDRAWVARIABLE)) |
| 1034 | rect.bottom = rect.top + descr->item_height; |
| 1035 | else |
| 1036 | rect.bottom = rect.top + descr->items[i].height; |
| 1037 | |
Gerard Patel | 8caa407 | 2000-09-24 19:29:18 +0000 | [diff] [blame] | 1038 | if (i == descr->focus_item) |
Alexandre Julliard | 72bdd5b | 2000-06-07 03:17:35 +0000 | [diff] [blame] | 1039 | { |
| 1040 | /* keep the focus rect, to paint the focus item after */ |
| 1041 | focusRect.left = rect.left; |
| 1042 | focusRect.right = rect.right; |
| 1043 | focusRect.top = rect.top; |
| 1044 | focusRect.bottom = rect.bottom; |
| 1045 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1046 | LISTBOX_PaintItem( hwnd, descr, hdc, &rect, i, ODA_DRAWENTIRE, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1047 | rect.top = rect.bottom; |
| 1048 | |
| 1049 | if ((descr->style & LBS_MULTICOLUMN) && !col_pos) |
| 1050 | { |
| 1051 | if (!IS_OWNERDRAW(descr)) |
| 1052 | { |
| 1053 | /* Clear the bottom of the column */ |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1054 | if (rect.top < descr->height) |
| 1055 | { |
| 1056 | rect.bottom = descr->height; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1057 | ExtTextOutW( hdc, 0, 0, ETO_OPAQUE | ETO_CLIPPED, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1058 | &rect, NULL, 0, NULL ); |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | /* Go to the next column */ |
| 1063 | rect.left += descr->column_width; |
| 1064 | rect.right += descr->column_width; |
| 1065 | rect.top = 0; |
| 1066 | col_pos = descr->page_size - 1; |
| 1067 | } |
| 1068 | else |
| 1069 | { |
| 1070 | col_pos--; |
| 1071 | if (rect.top >= descr->height) break; |
| 1072 | } |
| 1073 | } |
| 1074 | |
Alexandre Julliard | 72bdd5b | 2000-06-07 03:17:35 +0000 | [diff] [blame] | 1075 | /* Paint the focus item now */ |
Serge Ivanov | 07917e4 | 2000-06-07 03:46:57 +0000 | [diff] [blame] | 1076 | if (focusRect.top != focusRect.bottom && descr->caret_on) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1077 | LISTBOX_PaintItem( hwnd, descr, hdc, &focusRect, descr->focus_item, ODA_FOCUS, FALSE ); |
Alexandre Julliard | 72bdd5b | 2000-06-07 03:17:35 +0000 | [diff] [blame] | 1078 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1079 | if (!IS_OWNERDRAW(descr)) |
| 1080 | { |
| 1081 | /* Clear the remainder of the client area */ |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1082 | if (rect.top < descr->height) |
| 1083 | { |
| 1084 | rect.bottom = descr->height; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1085 | ExtTextOutW( hdc, 0, 0, ETO_OPAQUE | ETO_CLIPPED, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1086 | &rect, NULL, 0, NULL ); |
| 1087 | } |
| 1088 | if (rect.right < descr->width) |
| 1089 | { |
| 1090 | rect.left = rect.right; |
| 1091 | rect.right = descr->width; |
| 1092 | rect.top = 0; |
| 1093 | rect.bottom = descr->height; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1094 | ExtTextOutW( hdc, 0, 0, ETO_OPAQUE | ETO_CLIPPED, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1095 | &rect, NULL, 0, NULL ); |
| 1096 | } |
| 1097 | } |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1098 | if (oldFont) SelectObject( hdc, oldFont ); |
| 1099 | if (oldBrush) SelectObject( hdc, oldBrush ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1100 | return 0; |
| 1101 | } |
| 1102 | |
| 1103 | |
| 1104 | /*********************************************************************** |
| 1105 | * LISTBOX_InvalidateItems |
| 1106 | * |
| 1107 | * Invalidate all items from a given item. If the specified item is not |
| 1108 | * visible, nothing happens. |
| 1109 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1110 | static void LISTBOX_InvalidateItems( HWND hwnd, LB_DESCR *descr, INT index ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1111 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1112 | RECT rect; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1113 | |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1114 | if (LISTBOX_GetItemRect( descr, index, &rect ) == 1) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1115 | { |
Gerard Patel | 41b07fb | 2000-06-15 00:07:20 +0000 | [diff] [blame] | 1116 | if (descr->style & LBS_NOREDRAW) |
| 1117 | { |
| 1118 | descr->style |= LBS_DISPLAYCHANGED; |
| 1119 | return; |
| 1120 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1121 | rect.bottom = descr->height; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1122 | InvalidateRect( hwnd, &rect, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1123 | if (descr->style & LBS_MULTICOLUMN) |
| 1124 | { |
| 1125 | /* Repaint the other columns */ |
| 1126 | rect.left = rect.right; |
| 1127 | rect.right = descr->width; |
| 1128 | rect.top = 0; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1129 | InvalidateRect( hwnd, &rect, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1130 | } |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | |
| 1135 | /*********************************************************************** |
| 1136 | * LISTBOX_GetItemHeight |
| 1137 | */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1138 | static LRESULT LISTBOX_GetItemHeight( LB_DESCR *descr, INT index ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1139 | { |
| 1140 | if (descr->style & LBS_OWNERDRAWVARIABLE) |
| 1141 | { |
| 1142 | if ((index < 0) || (index >= descr->nb_items)) return LB_ERR; |
| 1143 | return descr->items[index].height; |
| 1144 | } |
| 1145 | else return descr->item_height; |
| 1146 | } |
| 1147 | |
| 1148 | |
| 1149 | /*********************************************************************** |
| 1150 | * LISTBOX_SetItemHeight |
| 1151 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1152 | static LRESULT LISTBOX_SetItemHeight( HWND hwnd, LB_DESCR *descr, INT index, |
Alexandre Julliard | c72a9aa | 2002-01-31 21:05:05 +0000 | [diff] [blame] | 1153 | INT height, BOOL repaint ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1154 | { |
| 1155 | if (!height) height = 1; |
| 1156 | |
| 1157 | if (descr->style & LBS_OWNERDRAWVARIABLE) |
| 1158 | { |
| 1159 | if ((index < 0) || (index >= descr->nb_items)) return LB_ERR; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1160 | TRACE("[%04x]: item %d height = %d\n", hwnd, index, height ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1161 | descr->items[index].height = height; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1162 | LISTBOX_UpdateScroll( hwnd, descr ); |
Alexandre Julliard | c72a9aa | 2002-01-31 21:05:05 +0000 | [diff] [blame] | 1163 | if (repaint) |
| 1164 | LISTBOX_InvalidateItems( hwnd, descr, index ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1165 | } |
| 1166 | else if (height != descr->item_height) |
| 1167 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1168 | TRACE("[%04x]: new height = %d\n", hwnd, height ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1169 | descr->item_height = height; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1170 | LISTBOX_UpdatePage( hwnd, descr ); |
| 1171 | LISTBOX_UpdateScroll( hwnd, descr ); |
Alexandre Julliard | c72a9aa | 2002-01-31 21:05:05 +0000 | [diff] [blame] | 1172 | if (repaint) |
| 1173 | InvalidateRect( hwnd, 0, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1174 | } |
| 1175 | return LB_OKAY; |
| 1176 | } |
| 1177 | |
| 1178 | |
| 1179 | /*********************************************************************** |
| 1180 | * LISTBOX_SetHorizontalPos |
| 1181 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1182 | static void LISTBOX_SetHorizontalPos( HWND hwnd, LB_DESCR *descr, INT pos ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1183 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1184 | INT diff; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1185 | |
| 1186 | if (pos > descr->horz_extent - descr->width) |
| 1187 | pos = descr->horz_extent - descr->width; |
| 1188 | if (pos < 0) pos = 0; |
| 1189 | if (!(diff = descr->horz_pos - pos)) return; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1190 | TRACE("[%04x]: new horz pos = %d\n", hwnd, pos ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1191 | descr->horz_pos = pos; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1192 | LISTBOX_UpdateScroll( hwnd, descr ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1193 | if (abs(diff) < descr->width) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1194 | ScrollWindowEx( hwnd, diff, 0, NULL, NULL, 0, NULL, |
NF Stevens | 762f18d | 1999-01-24 19:02:16 +0000 | [diff] [blame] | 1195 | SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1196 | else |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1197 | InvalidateRect( hwnd, NULL, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | |
| 1201 | /*********************************************************************** |
| 1202 | * LISTBOX_SetHorizontalExtent |
| 1203 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1204 | static LRESULT LISTBOX_SetHorizontalExtent( HWND hwnd, LB_DESCR *descr, |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1205 | INT extent ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1206 | { |
| 1207 | if (!descr->horz_extent || (descr->style & LBS_MULTICOLUMN)) |
| 1208 | return LB_OKAY; |
| 1209 | if (extent <= 0) extent = 1; |
| 1210 | if (extent == descr->horz_extent) return LB_OKAY; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1211 | TRACE("[%04x]: new horz extent = %d\n", hwnd, extent ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1212 | descr->horz_extent = extent; |
| 1213 | if (descr->horz_pos > extent - descr->width) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1214 | LISTBOX_SetHorizontalPos( hwnd, descr, extent - descr->width ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1215 | else |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1216 | LISTBOX_UpdateScroll( hwnd, descr ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1217 | return LB_OKAY; |
| 1218 | } |
| 1219 | |
| 1220 | |
| 1221 | /*********************************************************************** |
| 1222 | * LISTBOX_SetColumnWidth |
| 1223 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1224 | static LRESULT LISTBOX_SetColumnWidth( HWND hwnd, LB_DESCR *descr, INT width) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1225 | { |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1226 | if (width == descr->column_width) return LB_OKAY; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1227 | TRACE("[%04x]: new column width = %d\n", hwnd, width ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1228 | descr->column_width = width; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1229 | LISTBOX_UpdatePage( hwnd, descr ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1230 | return LB_OKAY; |
| 1231 | } |
| 1232 | |
| 1233 | |
| 1234 | /*********************************************************************** |
| 1235 | * LISTBOX_SetFont |
| 1236 | * |
| 1237 | * Returns the item height. |
| 1238 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1239 | static INT LISTBOX_SetFont( HWND hwnd, LB_DESCR *descr, HFONT font ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1240 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1241 | HDC hdc; |
| 1242 | HFONT oldFont = 0; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1243 | TEXTMETRICW tm; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1244 | |
| 1245 | descr->font = font; |
| 1246 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1247 | if (!(hdc = GetDCEx( hwnd, 0, DCX_CACHE ))) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1248 | { |
Alexandre Julliard | 9fe7a25 | 1999-05-14 08:17:14 +0000 | [diff] [blame] | 1249 | ERR("unable to get DC.\n" ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1250 | return 16; |
| 1251 | } |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1252 | if (font) oldFont = SelectObject( hdc, font ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1253 | GetTextMetricsW( hdc, &tm ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1254 | if (oldFont) SelectObject( hdc, oldFont ); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1255 | ReleaseDC( hwnd, hdc ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1256 | if (!IS_OWNERDRAW(descr)) |
Alexandre Julliard | c72a9aa | 2002-01-31 21:05:05 +0000 | [diff] [blame] | 1257 | LISTBOX_SetItemHeight( hwnd, descr, 0, tm.tmHeight, FALSE ); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1258 | return tm.tmHeight ; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | |
| 1262 | /*********************************************************************** |
| 1263 | * LISTBOX_MakeItemVisible |
| 1264 | * |
| 1265 | * Make sure that a given item is partially or fully visible. |
| 1266 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1267 | static void LISTBOX_MakeItemVisible( HWND hwnd, LB_DESCR *descr, INT index, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1268 | BOOL fully ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1269 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1270 | INT top; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1271 | |
| 1272 | if (index <= descr->top_item) top = index; |
| 1273 | else if (descr->style & LBS_MULTICOLUMN) |
| 1274 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1275 | INT cols = descr->width; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1276 | if (!fully) cols += descr->column_width - 1; |
| 1277 | if (cols >= descr->column_width) cols /= descr->column_width; |
| 1278 | else cols = 1; |
| 1279 | if (index < descr->top_item + (descr->page_size * cols)) return; |
| 1280 | top = index - descr->page_size * (cols - 1); |
| 1281 | } |
| 1282 | else if (descr->style & LBS_OWNERDRAWVARIABLE) |
| 1283 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1284 | INT height = fully ? descr->items[index].height : 1; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1285 | for (top = index; top > descr->top_item; top--) |
| 1286 | if ((height += descr->items[top-1].height) > descr->height) break; |
| 1287 | } |
| 1288 | else |
| 1289 | { |
| 1290 | if (index < descr->top_item + descr->page_size) return; |
| 1291 | if (!fully && (index == descr->top_item + descr->page_size) && |
| 1292 | (descr->height > (descr->page_size * descr->item_height))) return; |
| 1293 | top = index - descr->page_size + 1; |
| 1294 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1295 | LISTBOX_SetTopItem( hwnd, descr, top, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1296 | } |
| 1297 | |
Gerard Patel | 2ffbb31 | 2000-07-09 12:18:14 +0000 | [diff] [blame] | 1298 | /*********************************************************************** |
| 1299 | * LISTBOX_SetCaretIndex |
| 1300 | * |
| 1301 | * NOTES |
| 1302 | * index must be between 0 and descr->nb_items-1, or LB_ERR is returned. |
| 1303 | * |
| 1304 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1305 | static LRESULT LISTBOX_SetCaretIndex( HWND hwnd, LB_DESCR *descr, INT index, |
Gerard Patel | 2ffbb31 | 2000-07-09 12:18:14 +0000 | [diff] [blame] | 1306 | BOOL fully_visible ) |
| 1307 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1308 | INT oldfocus = descr->focus_item; |
Gerard Patel | 2ffbb31 | 2000-07-09 12:18:14 +0000 | [diff] [blame] | 1309 | |
Andreas Mohr | 85ba879 | 2001-01-06 00:34:14 +0000 | [diff] [blame] | 1310 | if (descr->style & LBS_NOSEL) return LB_ERR; |
Gerard Patel | 2ffbb31 | 2000-07-09 12:18:14 +0000 | [diff] [blame] | 1311 | if ((index < 0) || (index >= descr->nb_items)) return LB_ERR; |
| 1312 | if (index == oldfocus) return LB_OKAY; |
| 1313 | descr->focus_item = index; |
| 1314 | if ((oldfocus != -1) && descr->caret_on && (descr->in_focus)) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1315 | LISTBOX_RepaintItem( hwnd, descr, oldfocus, ODA_FOCUS ); |
Gerard Patel | 2ffbb31 | 2000-07-09 12:18:14 +0000 | [diff] [blame] | 1316 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1317 | LISTBOX_MakeItemVisible( hwnd, descr, index, fully_visible ); |
Gerard Patel | 2ffbb31 | 2000-07-09 12:18:14 +0000 | [diff] [blame] | 1318 | if (descr->caret_on && (descr->in_focus)) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1319 | LISTBOX_RepaintItem( hwnd, descr, index, ODA_FOCUS ); |
Gerard Patel | 2ffbb31 | 2000-07-09 12:18:14 +0000 | [diff] [blame] | 1320 | |
| 1321 | return LB_OKAY; |
| 1322 | } |
| 1323 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1324 | |
| 1325 | /*********************************************************************** |
| 1326 | * LISTBOX_SelectItemRange |
| 1327 | * |
| 1328 | * Select a range of items. Should only be used on a MULTIPLESEL listbox. |
| 1329 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1330 | static LRESULT LISTBOX_SelectItemRange( HWND hwnd, LB_DESCR *descr, INT first, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1331 | INT last, BOOL on ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1332 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1333 | INT i; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1334 | |
| 1335 | /* A few sanity checks */ |
| 1336 | |
Andreas Mohr | 85ba879 | 2001-01-06 00:34:14 +0000 | [diff] [blame] | 1337 | if (descr->style & LBS_NOSEL) return LB_ERR; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 1338 | if ((last == -1) && (descr->nb_items == 0)) return LB_OKAY; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1339 | if (!(descr->style & LBS_MULTIPLESEL)) return LB_ERR; |
| 1340 | if (last == -1) last = descr->nb_items - 1; |
| 1341 | if ((first < 0) || (first >= descr->nb_items)) return LB_ERR; |
| 1342 | if ((last < 0) || (last >= descr->nb_items)) return LB_ERR; |
| 1343 | /* selected_item reflects last selected/unselected item on multiple sel */ |
| 1344 | descr->selected_item = last; |
| 1345 | |
| 1346 | if (on) /* Turn selection on */ |
| 1347 | { |
| 1348 | for (i = first; i <= last; i++) |
| 1349 | { |
| 1350 | if (descr->items[i].selected) continue; |
| 1351 | descr->items[i].selected = TRUE; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1352 | LISTBOX_RepaintItem( hwnd, descr, i, ODA_SELECT ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1353 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1354 | LISTBOX_SetCaretIndex( hwnd, descr, last, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1355 | } |
| 1356 | else /* Turn selection off */ |
| 1357 | { |
| 1358 | for (i = first; i <= last; i++) |
| 1359 | { |
| 1360 | if (!descr->items[i].selected) continue; |
| 1361 | descr->items[i].selected = FALSE; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1362 | LISTBOX_RepaintItem( hwnd, descr, i, ODA_SELECT ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1363 | } |
| 1364 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1365 | return LB_OKAY; |
| 1366 | } |
| 1367 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1368 | /*********************************************************************** |
| 1369 | * LISTBOX_SetSelection |
| 1370 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1371 | static LRESULT LISTBOX_SetSelection( HWND hwnd, LB_DESCR *descr, INT index, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1372 | BOOL on, BOOL send_notify ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1373 | { |
Dmitry Timoshkov | e0f493e | 1999-11-28 19:44:33 +0000 | [diff] [blame] | 1374 | TRACE( "index=%d notify=%s\n", index, send_notify ? "YES" : "NO" ); |
| 1375 | |
Andreas Mohr | 85ba879 | 2001-01-06 00:34:14 +0000 | [diff] [blame] | 1376 | if (descr->style & LBS_NOSEL) return LB_ERR; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1377 | if ((index < -1) || (index >= descr->nb_items)) return LB_ERR; |
| 1378 | if (descr->style & LBS_MULTIPLESEL) |
| 1379 | { |
| 1380 | if (index == -1) /* Select all items */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1381 | return LISTBOX_SelectItemRange( hwnd, descr, 0, -1, on ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1382 | else /* Only one item */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1383 | return LISTBOX_SelectItemRange( hwnd, descr, index, index, on ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1384 | } |
| 1385 | else |
| 1386 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1387 | INT oldsel = descr->selected_item; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1388 | if (index == oldsel) return LB_OKAY; |
| 1389 | if (oldsel != -1) descr->items[oldsel].selected = FALSE; |
| 1390 | if (index != -1) descr->items[index].selected = TRUE; |
| 1391 | descr->selected_item = index; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1392 | if (oldsel != -1) LISTBOX_RepaintItem( hwnd, descr, oldsel, ODA_SELECT ); |
| 1393 | if (index != -1) LISTBOX_RepaintItem( hwnd, descr, index, ODA_SELECT ); |
| 1394 | if (send_notify && descr->nb_items) SEND_NOTIFICATION( hwnd, descr, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1395 | (index != -1) ? LBN_SELCHANGE : LBN_SELCANCEL ); |
Alex Korobka | 311d329 | 1999-01-01 18:40:02 +0000 | [diff] [blame] | 1396 | else |
| 1397 | if( descr->lphc ) /* set selection change flag for parent combo */ |
| 1398 | descr->lphc->wState |= CBF_SELCHANGE; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1399 | } |
| 1400 | return LB_OKAY; |
| 1401 | } |
| 1402 | |
| 1403 | |
| 1404 | /*********************************************************************** |
| 1405 | * LISTBOX_MoveCaret |
| 1406 | * |
| 1407 | * Change the caret position and extend the selection to the new caret. |
| 1408 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1409 | static void LISTBOX_MoveCaret( HWND hwnd, LB_DESCR *descr, INT index, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1410 | BOOL fully_visible ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1411 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1412 | INT oldfocus = descr->focus_item; |
Alexandre Julliard | 72bdd5b | 2000-06-07 03:17:35 +0000 | [diff] [blame] | 1413 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1414 | if ((index < 0) || (index >= descr->nb_items)) |
Alexandre Julliard | 72bdd5b | 2000-06-07 03:17:35 +0000 | [diff] [blame] | 1415 | return; |
| 1416 | |
| 1417 | /* Important, repaint needs to be done in this order if |
| 1418 | you want to mimic Windows behavior: |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame^] | 1419 | 1. Remove the focus and paint the item |
Alexandre Julliard | 72bdd5b | 2000-06-07 03:17:35 +0000 | [diff] [blame] | 1420 | 2. Remove the selection and paint the item(s) |
| 1421 | 3. Set the selection and repaint the item(s) |
| 1422 | 4. Set the focus to 'index' and repaint the item */ |
| 1423 | |
| 1424 | /* 1. remove the focus and repaint the item */ |
| 1425 | descr->focus_item = -1; |
| 1426 | if ((oldfocus != -1) && descr->caret_on && (descr->in_focus)) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1427 | LISTBOX_RepaintItem( hwnd, descr, oldfocus, ODA_FOCUS ); |
Alexandre Julliard | 72bdd5b | 2000-06-07 03:17:35 +0000 | [diff] [blame] | 1428 | |
| 1429 | /* 2. then turn off the previous selection */ |
| 1430 | /* 3. repaint the new selected item */ |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1431 | if (descr->style & LBS_EXTENDEDSEL) |
| 1432 | { |
| 1433 | if (descr->anchor_item != -1) |
| 1434 | { |
Alexandre Julliard | 72bdd5b | 2000-06-07 03:17:35 +0000 | [diff] [blame] | 1435 | INT first = min( index, descr->anchor_item ); |
| 1436 | INT last = max( index, descr->anchor_item ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1437 | if (first > 0) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1438 | LISTBOX_SelectItemRange( hwnd, descr, 0, first - 1, FALSE ); |
| 1439 | LISTBOX_SelectItemRange( hwnd, descr, last + 1, -1, FALSE ); |
| 1440 | LISTBOX_SelectItemRange( hwnd, descr, first, last, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1441 | } |
| 1442 | } |
Francis Beaudet | 6ec3eaf | 1999-06-12 10:51:19 +0000 | [diff] [blame] | 1443 | else if (!(descr->style & LBS_MULTIPLESEL)) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1444 | { |
| 1445 | /* Set selection to new caret item */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1446 | LISTBOX_SetSelection( hwnd, descr, index, TRUE, FALSE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1447 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1448 | |
Alexandre Julliard | 72bdd5b | 2000-06-07 03:17:35 +0000 | [diff] [blame] | 1449 | /* 4. repaint the new item with the focus */ |
| 1450 | descr->focus_item = index; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1451 | LISTBOX_MakeItemVisible( hwnd, descr, index, fully_visible ); |
Alexandre Julliard | 72bdd5b | 2000-06-07 03:17:35 +0000 | [diff] [blame] | 1452 | if (descr->caret_on && (descr->in_focus)) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1453 | LISTBOX_RepaintItem( hwnd, descr, index, ODA_FOCUS ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | |
| 1457 | /*********************************************************************** |
| 1458 | * LISTBOX_InsertItem |
| 1459 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1460 | static LRESULT LISTBOX_InsertItem( HWND hwnd, LB_DESCR *descr, INT index, |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1461 | LPWSTR str, DWORD data ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1462 | { |
| 1463 | LB_ITEMDATA *item; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1464 | INT max_items; |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 1465 | INT oldfocus = descr->focus_item; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1466 | |
| 1467 | if (index == -1) index = descr->nb_items; |
| 1468 | else if ((index < 0) || (index > descr->nb_items)) return LB_ERR; |
| 1469 | if (!descr->items) max_items = 0; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1470 | else max_items = HeapSize( GetProcessHeap(), 0, descr->items ) / sizeof(*item); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1471 | if (descr->nb_items == max_items) |
| 1472 | { |
| 1473 | /* We need to grow the array */ |
| 1474 | max_items += LB_ARRAY_GRANULARITY; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1475 | if (!(item = HeapReAlloc( GetProcessHeap(), 0, descr->items, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1476 | max_items * sizeof(LB_ITEMDATA) ))) |
| 1477 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1478 | SEND_NOTIFICATION( hwnd, descr, LBN_ERRSPACE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1479 | return LB_ERRSPACE; |
| 1480 | } |
| 1481 | descr->items = item; |
| 1482 | } |
| 1483 | |
| 1484 | /* Insert the item structure */ |
| 1485 | |
| 1486 | item = &descr->items[index]; |
| 1487 | if (index < descr->nb_items) |
| 1488 | RtlMoveMemory( item + 1, item, |
| 1489 | (descr->nb_items - index) * sizeof(LB_ITEMDATA) ); |
| 1490 | item->str = str; |
| 1491 | item->data = data; |
| 1492 | item->height = 0; |
| 1493 | item->selected = FALSE; |
| 1494 | descr->nb_items++; |
| 1495 | |
| 1496 | /* Get item height */ |
| 1497 | |
| 1498 | if (descr->style & LBS_OWNERDRAWVARIABLE) |
| 1499 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1500 | MEASUREITEMSTRUCT mis; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1501 | UINT id = GetWindowLongA( hwnd, GWL_ID ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 1502 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1503 | mis.CtlType = ODT_LISTBOX; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1504 | mis.CtlID = id; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1505 | mis.itemID = index; |
| 1506 | mis.itemData = descr->items[index].data; |
| 1507 | mis.itemHeight = descr->item_height; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1508 | SendMessageW( descr->owner, WM_MEASUREITEM, id, (LPARAM)&mis ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1509 | item->height = mis.itemHeight ? mis.itemHeight : 1; |
Alexandre Julliard | 9fe7a25 | 1999-05-14 08:17:14 +0000 | [diff] [blame] | 1510 | TRACE("[%04x]: measure item %d (%s) = %d\n", |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1511 | hwnd, index, str ? debugstr_w(str) : "", item->height ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | /* Repaint the items */ |
| 1515 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1516 | LISTBOX_UpdateScroll( hwnd, descr ); |
| 1517 | LISTBOX_InvalidateItems( hwnd, descr, index ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1518 | |
| 1519 | /* Move selection and focused item */ |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1520 | /* If listbox was empty, set focus to the first item */ |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 1521 | if (descr->nb_items == 1) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1522 | LISTBOX_SetCaretIndex( hwnd, descr, 0, FALSE ); |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 1523 | /* single select don't change selection index in win31 */ |
| 1524 | else if ((ISWIN31) && !(IS_MULTISELECT(descr))) |
| 1525 | { |
| 1526 | descr->selected_item++; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1527 | LISTBOX_SetSelection( hwnd, descr, descr->selected_item-1, TRUE, FALSE ); |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 1528 | } |
| 1529 | else |
| 1530 | { |
| 1531 | if (index <= descr->selected_item) |
| 1532 | { |
| 1533 | descr->selected_item++; |
| 1534 | descr->focus_item = oldfocus; /* focus not changed */ |
| 1535 | } |
| 1536 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1537 | return LB_OKAY; |
| 1538 | } |
| 1539 | |
| 1540 | |
| 1541 | /*********************************************************************** |
| 1542 | * LISTBOX_InsertString |
| 1543 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1544 | static LRESULT LISTBOX_InsertString( HWND hwnd, LB_DESCR *descr, INT index, |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1545 | LPCWSTR str ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1546 | { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1547 | LPWSTR new_str = NULL; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1548 | DWORD data = 0; |
| 1549 | LRESULT ret; |
| 1550 | |
| 1551 | if (HAS_STRINGS(descr)) |
| 1552 | { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1553 | static const WCHAR empty_stringW[] = { 0 }; |
| 1554 | if (!str) str = empty_stringW; |
| 1555 | if (!(new_str = HeapAlloc( GetProcessHeap(), 0, (strlenW(str) + 1) * sizeof(WCHAR) ))) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1556 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1557 | SEND_NOTIFICATION( hwnd, descr, LBN_ERRSPACE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1558 | return LB_ERRSPACE; |
| 1559 | } |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1560 | strcpyW(new_str, str); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1561 | } |
| 1562 | else data = (DWORD)str; |
| 1563 | |
| 1564 | if (index == -1) index = descr->nb_items; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1565 | if ((ret = LISTBOX_InsertItem( hwnd, descr, index, new_str, data )) != 0) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1566 | { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1567 | if (new_str) HeapFree( GetProcessHeap(), 0, new_str ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1568 | return ret; |
| 1569 | } |
| 1570 | |
Francois Gouget | ee285b7 | 2001-05-11 20:03:40 +0000 | [diff] [blame] | 1571 | TRACE("[%04x]: added item %d %s\n", |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1572 | hwnd, index, HAS_STRINGS(descr) ? debugstr_w(new_str) : "" ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1573 | return index; |
| 1574 | } |
| 1575 | |
| 1576 | |
| 1577 | /*********************************************************************** |
| 1578 | * LISTBOX_DeleteItem |
| 1579 | * |
| 1580 | * Delete the content of an item. 'index' must be a valid index. |
| 1581 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1582 | static void LISTBOX_DeleteItem( HWND hwnd, LB_DESCR *descr, INT index ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1583 | { |
| 1584 | /* Note: Win 3.1 only sends DELETEITEM on owner-draw items, |
| 1585 | * while Win95 sends it for all items with user data. |
| 1586 | * It's probably better to send it too often than not |
| 1587 | * often enough, so this is what we do here. |
| 1588 | */ |
| 1589 | if (IS_OWNERDRAW(descr) || descr->items[index].data) |
| 1590 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1591 | DELETEITEMSTRUCT dis; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1592 | UINT id = GetWindowLongA( hwnd, GWL_ID ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 1593 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1594 | dis.CtlType = ODT_LISTBOX; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1595 | dis.CtlID = id; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1596 | dis.itemID = index; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1597 | dis.hwndItem = hwnd; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1598 | dis.itemData = descr->items[index].data; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1599 | SendMessageW( descr->owner, WM_DELETEITEM, id, (LPARAM)&dis ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1600 | } |
| 1601 | if (HAS_STRINGS(descr) && descr->items[index].str) |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1602 | HeapFree( GetProcessHeap(), 0, descr->items[index].str ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | |
| 1606 | /*********************************************************************** |
| 1607 | * LISTBOX_RemoveItem |
| 1608 | * |
| 1609 | * Remove an item from the listbox and delete its content. |
| 1610 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1611 | static LRESULT LISTBOX_RemoveItem( HWND hwnd, LB_DESCR *descr, INT index ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1612 | { |
| 1613 | LB_ITEMDATA *item; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1614 | INT max_items; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1615 | |
Aric Stewart | fe9a0f0 | 2001-01-04 19:27:03 +0000 | [diff] [blame] | 1616 | if ((index == -1) && (descr->nb_items > 0)) index = descr->nb_items - 1; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1617 | else if ((index < 0) || (index >= descr->nb_items)) return LB_ERR; |
Yuxi Zhang | f94c3c5 | 2000-02-26 19:13:12 +0000 | [diff] [blame] | 1618 | |
| 1619 | /* We need to invalidate the original rect instead of the updated one. */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1620 | LISTBOX_InvalidateItems( hwnd, descr, index ); |
Yuxi Zhang | f94c3c5 | 2000-02-26 19:13:12 +0000 | [diff] [blame] | 1621 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1622 | LISTBOX_DeleteItem( hwnd, descr, index ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1623 | |
| 1624 | /* Remove the item */ |
| 1625 | |
| 1626 | item = &descr->items[index]; |
| 1627 | if (index < descr->nb_items-1) |
| 1628 | RtlMoveMemory( item, item + 1, |
| 1629 | (descr->nb_items - index - 1) * sizeof(LB_ITEMDATA) ); |
| 1630 | descr->nb_items--; |
| 1631 | if (descr->anchor_item == descr->nb_items) descr->anchor_item--; |
| 1632 | |
| 1633 | /* Shrink the item array if possible */ |
| 1634 | |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1635 | max_items = HeapSize( GetProcessHeap(), 0, descr->items ) / sizeof(LB_ITEMDATA); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1636 | if (descr->nb_items < max_items - 2*LB_ARRAY_GRANULARITY) |
| 1637 | { |
| 1638 | max_items -= LB_ARRAY_GRANULARITY; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1639 | item = HeapReAlloc( GetProcessHeap(), 0, descr->items, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1640 | max_items * sizeof(LB_ITEMDATA) ); |
| 1641 | if (item) descr->items = item; |
| 1642 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1643 | /* Repaint the items */ |
| 1644 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1645 | LISTBOX_UpdateScroll( hwnd, descr ); |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 1646 | /* if we removed the scrollbar, reset the top of the list |
| 1647 | (correct for owner-drawn ???) */ |
| 1648 | if (descr->nb_items == descr->page_size) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1649 | LISTBOX_SetTopItem( hwnd, descr, 0, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1650 | |
| 1651 | /* Move selection and focused item */ |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 1652 | if (!IS_MULTISELECT(descr)) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1653 | { |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 1654 | if (index == descr->selected_item) |
| 1655 | descr->selected_item = -1; |
| 1656 | else if (index < descr->selected_item) |
| 1657 | { |
| 1658 | descr->selected_item--; |
| 1659 | if (ISWIN31) /* win 31 do not change the selected item number */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1660 | LISTBOX_SetSelection( hwnd, descr, descr->selected_item + 1, TRUE, FALSE); |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 1661 | } |
| 1662 | } |
Yuxi Zhang | f94c3c5 | 2000-02-26 19:13:12 +0000 | [diff] [blame] | 1663 | |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 1664 | if (descr->focus_item >= descr->nb_items) |
| 1665 | { |
| 1666 | descr->focus_item = descr->nb_items - 1; |
| 1667 | if (descr->focus_item < 0) descr->focus_item = 0; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1668 | } |
| 1669 | return LB_OKAY; |
| 1670 | } |
| 1671 | |
| 1672 | |
| 1673 | /*********************************************************************** |
| 1674 | * LISTBOX_ResetContent |
| 1675 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1676 | static void LISTBOX_ResetContent( HWND hwnd, LB_DESCR *descr ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1677 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1678 | INT i; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1679 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1680 | for (i = 0; i < descr->nb_items; i++) LISTBOX_DeleteItem( hwnd, descr, i ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1681 | if (descr->items) HeapFree( GetProcessHeap(), 0, descr->items ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1682 | descr->nb_items = 0; |
| 1683 | descr->top_item = 0; |
| 1684 | descr->selected_item = -1; |
| 1685 | descr->focus_item = 0; |
| 1686 | descr->anchor_item = -1; |
| 1687 | descr->items = NULL; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | |
| 1691 | /*********************************************************************** |
| 1692 | * LISTBOX_SetCount |
| 1693 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1694 | static LRESULT LISTBOX_SetCount( HWND hwnd, LB_DESCR *descr, INT count ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1695 | { |
| 1696 | LRESULT ret; |
| 1697 | |
| 1698 | if (HAS_STRINGS(descr)) return LB_ERR; |
| 1699 | /* FIXME: this is far from optimal... */ |
| 1700 | if (count > descr->nb_items) |
| 1701 | { |
| 1702 | while (count > descr->nb_items) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1703 | if ((ret = LISTBOX_InsertString( hwnd, descr, -1, 0 )) < 0) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1704 | return ret; |
| 1705 | } |
| 1706 | else if (count < descr->nb_items) |
| 1707 | { |
| 1708 | while (count < descr->nb_items) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1709 | if ((ret = LISTBOX_RemoveItem( hwnd, descr, -1 )) < 0) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1710 | return ret; |
| 1711 | } |
| 1712 | return LB_OKAY; |
| 1713 | } |
| 1714 | |
| 1715 | |
| 1716 | /*********************************************************************** |
| 1717 | * LISTBOX_Directory |
| 1718 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1719 | static LRESULT LISTBOX_Directory( HWND hwnd, LB_DESCR *descr, UINT attrib, |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1720 | LPCWSTR filespec, BOOL long_names ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1721 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1722 | HANDLE handle; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1723 | LRESULT ret = LB_OKAY; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1724 | WIN32_FIND_DATAW entry; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1725 | int pos; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1726 | |
Ove Kaaven | 2c691b3 | 2000-11-25 03:06:03 +0000 | [diff] [blame] | 1727 | /* don't scan directory if we just want drives exclusively */ |
| 1728 | if (attrib != (DDL_DRIVES | DDL_EXCLUSIVE)) { |
| 1729 | /* scan directory */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1730 | if ((handle = FindFirstFileW(filespec, &entry)) == INVALID_HANDLE_VALUE) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1731 | { |
Ove Kaaven | 2c691b3 | 2000-11-25 03:06:03 +0000 | [diff] [blame] | 1732 | if (GetLastError() != ERROR_NO_MORE_FILES) return LB_ERR; |
| 1733 | } |
| 1734 | else |
| 1735 | { |
| 1736 | do |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1737 | { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1738 | WCHAR buffer[270]; |
Ove Kaaven | 2c691b3 | 2000-11-25 03:06:03 +0000 | [diff] [blame] | 1739 | if (entry.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
| 1740 | { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1741 | static const WCHAR bracketW[] = { ']',0 }; |
| 1742 | static const WCHAR dotW[] = { '.',0 }; |
Ove Kaaven | 2c691b3 | 2000-11-25 03:06:03 +0000 | [diff] [blame] | 1743 | if (!(attrib & DDL_DIRECTORY) || |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1744 | !strcmpW( entry.cAlternateFileName, dotW )) continue; |
| 1745 | buffer[0] = '['; |
| 1746 | if (long_names) strcpyW( buffer + 1, entry.cFileName ); |
| 1747 | else strcpyW( buffer + 1, entry.cAlternateFileName ); |
| 1748 | strcatW(buffer, bracketW); |
Ove Kaaven | 2c691b3 | 2000-11-25 03:06:03 +0000 | [diff] [blame] | 1749 | } |
| 1750 | else /* not a directory */ |
| 1751 | { |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1752 | #define ATTRIBS (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | \ |
| 1753 | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE) |
| 1754 | |
Ove Kaaven | 2c691b3 | 2000-11-25 03:06:03 +0000 | [diff] [blame] | 1755 | if ((attrib & DDL_EXCLUSIVE) && |
| 1756 | ((attrib & ATTRIBS) != (entry.dwFileAttributes & ATTRIBS))) |
| 1757 | continue; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1758 | #undef ATTRIBS |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1759 | if (long_names) strcpyW( buffer, entry.cFileName ); |
| 1760 | else strcpyW( buffer, entry.cAlternateFileName ); |
Ove Kaaven | 2c691b3 | 2000-11-25 03:06:03 +0000 | [diff] [blame] | 1761 | } |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1762 | if (!long_names) CharLowerW( buffer ); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1763 | pos = LISTBOX_FindFileStrPos( hwnd, descr, buffer ); |
| 1764 | if ((ret = LISTBOX_InsertString( hwnd, descr, pos, buffer )) < 0) |
Ove Kaaven | 2c691b3 | 2000-11-25 03:06:03 +0000 | [diff] [blame] | 1765 | break; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1766 | } while (FindNextFileW( handle, &entry )); |
Ove Kaaven | 2c691b3 | 2000-11-25 03:06:03 +0000 | [diff] [blame] | 1767 | FindClose( handle ); |
| 1768 | } |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1769 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1770 | |
Ove Kaaven | 2c691b3 | 2000-11-25 03:06:03 +0000 | [diff] [blame] | 1771 | /* scan drives */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1772 | if ((ret >= 0) && (attrib & DDL_DRIVES)) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1773 | { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1774 | WCHAR buffer[] = {'[','-','a','-',']',0}; |
| 1775 | WCHAR root[] = {'A',':','\\',0}; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1776 | int drive; |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 1777 | for (drive = 0; drive < 26; drive++, buffer[2]++, root[0]++) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1778 | { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1779 | if (GetDriveTypeW(root) <= DRIVE_NO_ROOT_DIR) continue; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1780 | if ((ret = LISTBOX_InsertString( hwnd, descr, -1, buffer )) < 0) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1781 | break; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1782 | } |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1783 | } |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1784 | return ret; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1788 | /*********************************************************************** |
| 1789 | * LISTBOX_HandleVScroll |
| 1790 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1791 | static LRESULT LISTBOX_HandleVScroll( HWND hwnd, LB_DESCR *descr, WPARAM wParam ) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1792 | { |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1793 | SCROLLINFO info; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1794 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1795 | if (descr->style & LBS_MULTICOLUMN) return 0; |
| 1796 | switch(LOWORD(wParam)) |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 1797 | { |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1798 | case SB_LINEUP: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1799 | LISTBOX_SetTopItem( hwnd, descr, descr->top_item - 1, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1800 | break; |
| 1801 | case SB_LINEDOWN: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1802 | LISTBOX_SetTopItem( hwnd, descr, descr->top_item + 1, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1803 | break; |
| 1804 | case SB_PAGEUP: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1805 | LISTBOX_SetTopItem( hwnd, descr, descr->top_item - |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1806 | LISTBOX_GetCurrentPageSize( descr ), TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1807 | break; |
| 1808 | case SB_PAGEDOWN: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1809 | LISTBOX_SetTopItem( hwnd, descr, descr->top_item + |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1810 | LISTBOX_GetCurrentPageSize( descr ), TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1811 | break; |
| 1812 | case SB_THUMBPOSITION: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1813 | LISTBOX_SetTopItem( hwnd, descr, HIWORD(wParam), TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1814 | break; |
| 1815 | case SB_THUMBTRACK: |
| 1816 | info.cbSize = sizeof(info); |
| 1817 | info.fMask = SIF_TRACKPOS; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1818 | GetScrollInfo( hwnd, SB_VERT, &info ); |
| 1819 | LISTBOX_SetTopItem( hwnd, descr, info.nTrackPos, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1820 | break; |
| 1821 | case SB_TOP: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1822 | LISTBOX_SetTopItem( hwnd, descr, 0, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1823 | break; |
| 1824 | case SB_BOTTOM: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1825 | LISTBOX_SetTopItem( hwnd, descr, descr->nb_items, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1826 | break; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 1827 | } |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1828 | return 0; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1831 | |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1832 | /*********************************************************************** |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1833 | * LISTBOX_HandleHScroll |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1834 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1835 | static LRESULT LISTBOX_HandleHScroll( HWND hwnd, LB_DESCR *descr, WPARAM wParam ) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1836 | { |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1837 | SCROLLINFO info; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1838 | INT page; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1839 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1840 | if (descr->style & LBS_MULTICOLUMN) |
| 1841 | { |
| 1842 | switch(LOWORD(wParam)) |
| 1843 | { |
| 1844 | case SB_LINELEFT: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1845 | LISTBOX_SetTopItem( hwnd, descr, descr->top_item-descr->page_size, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1846 | TRUE ); |
| 1847 | break; |
| 1848 | case SB_LINERIGHT: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1849 | LISTBOX_SetTopItem( hwnd, descr, descr->top_item+descr->page_size, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1850 | TRUE ); |
| 1851 | break; |
| 1852 | case SB_PAGELEFT: |
| 1853 | page = descr->width / descr->column_width; |
| 1854 | if (page < 1) page = 1; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1855 | LISTBOX_SetTopItem( hwnd, descr, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1856 | descr->top_item - page * descr->page_size, TRUE ); |
| 1857 | break; |
| 1858 | case SB_PAGERIGHT: |
| 1859 | page = descr->width / descr->column_width; |
| 1860 | if (page < 1) page = 1; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1861 | LISTBOX_SetTopItem( hwnd, descr, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1862 | descr->top_item + page * descr->page_size, TRUE ); |
| 1863 | break; |
| 1864 | case SB_THUMBPOSITION: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1865 | LISTBOX_SetTopItem( hwnd, descr, HIWORD(wParam)*descr->page_size, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1866 | TRUE ); |
| 1867 | break; |
| 1868 | case SB_THUMBTRACK: |
| 1869 | info.cbSize = sizeof(info); |
| 1870 | info.fMask = SIF_TRACKPOS; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1871 | GetScrollInfo( hwnd, SB_VERT, &info ); |
| 1872 | LISTBOX_SetTopItem( hwnd, descr, info.nTrackPos*descr->page_size, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1873 | TRUE ); |
| 1874 | break; |
| 1875 | case SB_LEFT: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1876 | LISTBOX_SetTopItem( hwnd, descr, 0, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1877 | break; |
| 1878 | case SB_RIGHT: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1879 | LISTBOX_SetTopItem( hwnd, descr, descr->nb_items, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1880 | break; |
| 1881 | } |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1882 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1883 | else if (descr->horz_extent) |
| 1884 | { |
| 1885 | switch(LOWORD(wParam)) |
| 1886 | { |
| 1887 | case SB_LINELEFT: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1888 | LISTBOX_SetHorizontalPos( hwnd, descr, descr->horz_pos - 1 ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1889 | break; |
| 1890 | case SB_LINERIGHT: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1891 | LISTBOX_SetHorizontalPos( hwnd, descr, descr->horz_pos + 1 ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1892 | break; |
| 1893 | case SB_PAGELEFT: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1894 | LISTBOX_SetHorizontalPos( hwnd, descr, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1895 | descr->horz_pos - descr->width ); |
| 1896 | break; |
| 1897 | case SB_PAGERIGHT: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1898 | LISTBOX_SetHorizontalPos( hwnd, descr, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1899 | descr->horz_pos + descr->width ); |
| 1900 | break; |
| 1901 | case SB_THUMBPOSITION: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1902 | LISTBOX_SetHorizontalPos( hwnd, descr, HIWORD(wParam) ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1903 | break; |
| 1904 | case SB_THUMBTRACK: |
| 1905 | info.cbSize = sizeof(info); |
| 1906 | info.fMask = SIF_TRACKPOS; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1907 | GetScrollInfo( hwnd, SB_HORZ, &info ); |
| 1908 | LISTBOX_SetHorizontalPos( hwnd, descr, info.nTrackPos ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1909 | break; |
| 1910 | case SB_LEFT: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1911 | LISTBOX_SetHorizontalPos( hwnd, descr, 0 ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1912 | break; |
| 1913 | case SB_RIGHT: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1914 | LISTBOX_SetHorizontalPos( hwnd, descr, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1915 | descr->horz_extent - descr->width ); |
| 1916 | break; |
| 1917 | } |
| 1918 | } |
| 1919 | return 0; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 1920 | } |
| 1921 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1922 | static LRESULT LISTBOX_HandleMouseWheel(HWND hwnd, LB_DESCR *descr, WPARAM wParam ) |
Stephane Lussier | 4bdf4af | 2000-04-18 11:56:33 +0000 | [diff] [blame] | 1923 | { |
| 1924 | short gcWheelDelta = 0; |
| 1925 | UINT pulScrollLines = 3; |
| 1926 | |
| 1927 | SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0); |
| 1928 | |
| 1929 | gcWheelDelta -= (short) HIWORD(wParam); |
| 1930 | |
| 1931 | if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines) |
| 1932 | { |
| 1933 | int cLineScroll = (int) min((UINT) descr->page_size, pulScrollLines); |
| 1934 | cLineScroll *= (gcWheelDelta / WHEEL_DELTA); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1935 | LISTBOX_SetTopItem( hwnd, descr, descr->top_item + cLineScroll, TRUE ); |
Stephane Lussier | 4bdf4af | 2000-04-18 11:56:33 +0000 | [diff] [blame] | 1936 | } |
| 1937 | return 0; |
| 1938 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1939 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 1940 | /*********************************************************************** |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1941 | * LISTBOX_HandleLButtonDown |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 1942 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1943 | static LRESULT LISTBOX_HandleLButtonDown( HWND hwnd, LB_DESCR *descr, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1944 | WPARAM wParam, INT x, INT y ) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 1945 | { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1946 | INT index = LISTBOX_GetItemFromPoint( descr, x, y ); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1947 | TRACE("[%04x]: lbuttondown %d,%d item %d\n", hwnd, x, y, index ); |
Alexandre Julliard | ab2f43f | 2000-05-26 22:28:34 +0000 | [diff] [blame] | 1948 | if (!descr->caret_on && (descr->in_focus)) return 0; |
Jason Mawdsley | 50523d1 | 2000-06-11 20:34:07 +0000 | [diff] [blame] | 1949 | |
| 1950 | if (!descr->in_focus) |
| 1951 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1952 | if( !descr->lphc ) SetFocus( hwnd ); |
| 1953 | else SetFocus( (descr->lphc->hWndEdit) ? descr->lphc->hWndEdit : descr->lphc->self ); |
Jason Mawdsley | 50523d1 | 2000-06-11 20:34:07 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
Ulrich Czekalla | 7c55bc0 | 2000-12-15 22:58:25 +0000 | [diff] [blame] | 1956 | if (index == -1) return 0; |
Andreas Mohr | 2b5d9c6 | 2000-08-29 03:52:16 +0000 | [diff] [blame] | 1957 | |
Ulrich Czekalla | 7c55bc0 | 2000-12-15 22:58:25 +0000 | [diff] [blame] | 1958 | if (descr->style & LBS_EXTENDEDSEL) |
| 1959 | { |
| 1960 | /* we should perhaps make sure that all items are deselected |
| 1961 | FIXME: needed for !LBS_EXTENDEDSEL, too ? |
| 1962 | if (!(wParam & (MK_SHIFT|MK_CONTROL))) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1963 | LISTBOX_SetSelection( hwnd, descr, -1, FALSE, FALSE); |
Ulrich Czekalla | 7c55bc0 | 2000-12-15 22:58:25 +0000 | [diff] [blame] | 1964 | */ |
| 1965 | |
| 1966 | if (!(wParam & MK_SHIFT)) descr->anchor_item = index; |
| 1967 | if (wParam & MK_CONTROL) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1968 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1969 | LISTBOX_SetCaretIndex( hwnd, descr, index, FALSE ); |
| 1970 | LISTBOX_SetSelection( hwnd, descr, index, |
Ulrich Czekalla | 7c55bc0 | 2000-12-15 22:58:25 +0000 | [diff] [blame] | 1971 | !descr->items[index].selected, |
| 1972 | (descr->style & LBS_NOTIFY) != 0); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1973 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1974 | else LISTBOX_MoveCaret( hwnd, descr, index, FALSE ); |
Ulrich Czekalla | 7c55bc0 | 2000-12-15 22:58:25 +0000 | [diff] [blame] | 1975 | } |
| 1976 | else |
| 1977 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1978 | LISTBOX_MoveCaret( hwnd, descr, index, FALSE ); |
| 1979 | LISTBOX_SetSelection( hwnd, descr, index, |
Ulrich Czekalla | 7c55bc0 | 2000-12-15 22:58:25 +0000 | [diff] [blame] | 1980 | (!(descr->style & LBS_MULTIPLESEL) || |
| 1981 | !descr->items[index].selected), |
| 1982 | (descr->style & LBS_NOTIFY) != 0 ); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1983 | } |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 1984 | |
Luc Tourangeau | 5ee117b | 1999-04-04 12:48:21 +0000 | [diff] [blame] | 1985 | descr->captured = TRUE; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1986 | SetCapture( hwnd ); |
Ulrich Czekalla | 7c55bc0 | 2000-12-15 22:58:25 +0000 | [diff] [blame] | 1987 | |
| 1988 | if (!descr->lphc) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1989 | { |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 1990 | if (descr->style & LBS_NOTIFY ) |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 1991 | SendMessageW( descr->owner, WM_LBTRACKPOINT, index, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1992 | MAKELPARAM( x, y ) ); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1993 | if (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_DRAGDETECT) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1994 | { |
Patrik Stridvall | 0f8bc5b | 1999-04-22 16:27:50 +0000 | [diff] [blame] | 1995 | POINT pt; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1996 | |
Patrik Stridvall | 0f8bc5b | 1999-04-22 16:27:50 +0000 | [diff] [blame] | 1997 | pt.x = x; |
| 1998 | pt.y = y; |
| 1999 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2000 | if (DragDetect( hwnd, pt )) |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2001 | SendMessageW( descr->owner, WM_BEGINDRAG, 0, 0 ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2002 | } |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 2003 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2004 | return 0; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2005 | } |
| 2006 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2007 | |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 2008 | /************************************************************************* |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2009 | * LISTBOX_HandleLButtonDownCombo [Internal] |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 2010 | * |
| 2011 | * Process LButtonDown message for the ComboListBox |
| 2012 | * |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2013 | nn * PARAMS |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 2014 | * pWnd [I] The windows internal structure |
| 2015 | * pDescr [I] The ListBox internal structure |
| 2016 | * wParam [I] Key Flag (WM_LBUTTONDOWN doc for more info) |
| 2017 | * x [I] X Mouse Coordinate |
| 2018 | * y [I] Y Mouse Coordinate |
| 2019 | * |
| 2020 | * RETURNS |
| 2021 | * 0 since we are processing the WM_LBUTTONDOWN Message |
| 2022 | * |
| 2023 | * NOTES |
| 2024 | * This function is only to be used when a ListBox is a ComboListBox |
| 2025 | */ |
| 2026 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2027 | static LRESULT LISTBOX_HandleLButtonDownCombo( HWND hwnd, LB_DESCR *pDescr, |
Alexandre Julliard | 7f90a8c | 2000-05-23 04:18:12 +0000 | [diff] [blame] | 2028 | UINT msg, WPARAM wParam, INT x, INT y) |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 2029 | { |
| 2030 | RECT clientRect, screenRect; |
| 2031 | POINT mousePos; |
| 2032 | |
| 2033 | mousePos.x = x; |
| 2034 | mousePos.y = y; |
| 2035 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2036 | GetClientRect(hwnd, &clientRect); |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 2037 | |
| 2038 | if(PtInRect(&clientRect, mousePos)) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2039 | { |
Alexandre Julliard | 7f90a8c | 2000-05-23 04:18:12 +0000 | [diff] [blame] | 2040 | /* MousePos is in client, resume normal processing */ |
| 2041 | if (msg == WM_LBUTTONDOWN) |
Serge Ivanov | 07917e4 | 2000-06-07 03:46:57 +0000 | [diff] [blame] | 2042 | { |
| 2043 | pDescr->lphc->droppedIndex = pDescr->nb_items ? pDescr->selected_item : -1; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2044 | return LISTBOX_HandleLButtonDown( hwnd, pDescr, wParam, x, y); |
Serge Ivanov | 07917e4 | 2000-06-07 03:46:57 +0000 | [diff] [blame] | 2045 | } |
Alexandre Julliard | 7f90a8c | 2000-05-23 04:18:12 +0000 | [diff] [blame] | 2046 | else if (pDescr->style & LBS_NOTIFY) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2047 | SEND_NOTIFICATION( hwnd, pDescr, LBN_DBLCLK ); |
Alexandre Julliard | 7f90a8c | 2000-05-23 04:18:12 +0000 | [diff] [blame] | 2048 | return 0; |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 2049 | } |
| 2050 | else |
| 2051 | { |
| 2052 | POINT screenMousePos; |
| 2053 | HWND hWndOldCapture; |
| 2054 | |
| 2055 | /* Check the Non-Client Area */ |
| 2056 | screenMousePos = mousePos; |
| 2057 | hWndOldCapture = GetCapture(); |
| 2058 | ReleaseCapture(); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2059 | GetWindowRect(hwnd, &screenRect); |
| 2060 | ClientToScreen(hwnd, &screenMousePos); |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 2061 | |
| 2062 | if(!PtInRect(&screenRect, screenMousePos)) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2063 | { |
| 2064 | LISTBOX_SetCaretIndex( hwnd, pDescr, pDescr->lphc->droppedIndex, FALSE ); |
| 2065 | LISTBOX_SetSelection( hwnd, pDescr, pDescr->lphc->droppedIndex, FALSE, FALSE ); |
Serge Ivanov | 07917e4 | 2000-06-07 03:46:57 +0000 | [diff] [blame] | 2066 | COMBO_FlipListbox( pDescr->lphc, FALSE, FALSE ); |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 2067 | return 0; |
| 2068 | } |
| 2069 | else |
| 2070 | { |
| 2071 | /* Check to see the NC is a scrollbar */ |
| 2072 | INT nHitTestType=0; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2073 | LONG style = GetWindowLongA( hwnd, GWL_STYLE ); |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 2074 | /* Check Vertical scroll bar */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2075 | if (style & WS_VSCROLL) |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 2076 | { |
| 2077 | clientRect.right += GetSystemMetrics(SM_CXVSCROLL); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2078 | if (PtInRect( &clientRect, mousePos )) |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 2079 | { |
| 2080 | nHitTestType = HTVSCROLL; |
| 2081 | } |
| 2082 | } |
| 2083 | /* Check horizontal scroll bar */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2084 | if (style & WS_HSCROLL) |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 2085 | { |
| 2086 | clientRect.bottom += GetSystemMetrics(SM_CYHSCROLL); |
| 2087 | if (PtInRect( &clientRect, mousePos )) |
| 2088 | { |
| 2089 | nHitTestType = HTHSCROLL; |
| 2090 | } |
| 2091 | } |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame^] | 2092 | /* Windows sends this message when a scrollbar is clicked |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 2093 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2094 | |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 2095 | if(nHitTestType != 0) |
| 2096 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2097 | SendMessageW(hwnd, WM_NCLBUTTONDOWN, nHitTestType, |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 2098 | MAKELONG(screenMousePos.x, screenMousePos.y)); |
| 2099 | } |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame^] | 2100 | /* Resume the Capture after scrolling is complete |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 2101 | */ |
| 2102 | if(hWndOldCapture != 0) |
| 2103 | { |
| 2104 | SetCapture(hWndOldCapture); |
| 2105 | } |
| 2106 | } |
| 2107 | } |
| 2108 | return 0; |
| 2109 | } |
| 2110 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2111 | /*********************************************************************** |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 2112 | * LISTBOX_HandleLButtonUp |
| 2113 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2114 | static LRESULT LISTBOX_HandleLButtonUp( HWND hwnd, LB_DESCR *descr ) |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 2115 | { |
| 2116 | if (LISTBOX_Timer != LB_TIMER_NONE) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2117 | KillSystemTimer( hwnd, LB_TIMER_ID ); |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 2118 | LISTBOX_Timer = LB_TIMER_NONE; |
Luc Tourangeau | 5ee117b | 1999-04-04 12:48:21 +0000 | [diff] [blame] | 2119 | if (descr->captured) |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 2120 | { |
Luc Tourangeau | 5ee117b | 1999-04-04 12:48:21 +0000 | [diff] [blame] | 2121 | descr->captured = FALSE; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2122 | if (GetCapture() == hwnd) ReleaseCapture(); |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 2123 | if ((descr->style & LBS_NOTIFY) && descr->nb_items) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2124 | SEND_NOTIFICATION( hwnd, descr, LBN_SELCHANGE ); |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 2125 | } |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 2126 | return 0; |
| 2127 | } |
| 2128 | |
| 2129 | |
| 2130 | /*********************************************************************** |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2131 | * LISTBOX_HandleTimer |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 2132 | * |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2133 | * Handle scrolling upon a timer event. |
| 2134 | * Return TRUE if scrolling should continue. |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2135 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2136 | static LRESULT LISTBOX_HandleTimer( HWND hwnd, LB_DESCR *descr, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2137 | INT index, TIMER_DIRECTION dir ) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2138 | { |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2139 | switch(dir) |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 2140 | { |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2141 | case LB_TIMER_UP: |
| 2142 | if (descr->top_item) index = descr->top_item - 1; |
| 2143 | else index = 0; |
| 2144 | break; |
| 2145 | case LB_TIMER_LEFT: |
| 2146 | if (descr->top_item) index -= descr->page_size; |
| 2147 | break; |
| 2148 | case LB_TIMER_DOWN: |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2149 | index = descr->top_item + LISTBOX_GetCurrentPageSize( descr ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 2150 | if (index == descr->focus_item) index++; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2151 | if (index >= descr->nb_items) index = descr->nb_items - 1; |
| 2152 | break; |
| 2153 | case LB_TIMER_RIGHT: |
| 2154 | if (index + descr->page_size < descr->nb_items) |
| 2155 | index += descr->page_size; |
| 2156 | break; |
| 2157 | case LB_TIMER_NONE: |
| 2158 | break; |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 2159 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2160 | if (index == descr->focus_item) return FALSE; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2161 | LISTBOX_MoveCaret( hwnd, descr, index, FALSE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2162 | return TRUE; |
| 2163 | } |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 2164 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2165 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2166 | /*********************************************************************** |
| 2167 | * LISTBOX_HandleSystemTimer |
| 2168 | * |
| 2169 | * WM_SYSTIMER handler. |
| 2170 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2171 | static LRESULT LISTBOX_HandleSystemTimer( HWND hwnd, LB_DESCR *descr ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2172 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2173 | if (!LISTBOX_HandleTimer( hwnd, descr, descr->focus_item, LISTBOX_Timer )) |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 2174 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2175 | KillSystemTimer( hwnd, LB_TIMER_ID ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2176 | LISTBOX_Timer = LB_TIMER_NONE; |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 2177 | } |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 2178 | return 0; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2179 | } |
| 2180 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2181 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2182 | /*********************************************************************** |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2183 | * LISTBOX_HandleMouseMove |
| 2184 | * |
| 2185 | * WM_MOUSEMOVE handler. |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2186 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2187 | static void LISTBOX_HandleMouseMove( HWND hwnd, LB_DESCR *descr, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2188 | INT x, INT y ) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2189 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2190 | INT index; |
Serge Ivanov | 07917e4 | 2000-06-07 03:46:57 +0000 | [diff] [blame] | 2191 | TIMER_DIRECTION dir = LB_TIMER_NONE; |
Alexandre Julliard | 7d654eb | 1996-02-25 11:36:22 +0000 | [diff] [blame] | 2192 | |
Luc Tourangeau | 5ee117b | 1999-04-04 12:48:21 +0000 | [diff] [blame] | 2193 | if (!descr->captured) return; |
| 2194 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2195 | if (descr->style & LBS_MULTICOLUMN) |
Alexandre Julliard | 7d654eb | 1996-02-25 11:36:22 +0000 | [diff] [blame] | 2196 | { |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2197 | if (y < 0) y = 0; |
| 2198 | else if (y >= descr->item_height * descr->page_size) |
| 2199 | y = descr->item_height * descr->page_size - 1; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2200 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2201 | if (x < 0) |
| 2202 | { |
| 2203 | dir = LB_TIMER_LEFT; |
| 2204 | x = 0; |
| 2205 | } |
| 2206 | else if (x >= descr->width) |
| 2207 | { |
| 2208 | dir = LB_TIMER_RIGHT; |
| 2209 | x = descr->width - 1; |
| 2210 | } |
Alexandre Julliard | 7d654eb | 1996-02-25 11:36:22 +0000 | [diff] [blame] | 2211 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2212 | else |
| 2213 | { |
| 2214 | if (y < 0) dir = LB_TIMER_UP; /* above */ |
| 2215 | else if (y >= descr->height) dir = LB_TIMER_DOWN; /* below */ |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2216 | } |
| 2217 | |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2218 | index = LISTBOX_GetItemFromPoint( descr, x, y ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2219 | if (index == -1) index = descr->focus_item; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2220 | if (!LISTBOX_HandleTimer( hwnd, descr, index, dir )) dir = LB_TIMER_NONE; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2221 | |
| 2222 | /* Start/stop the system timer */ |
| 2223 | |
| 2224 | if (dir != LB_TIMER_NONE) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2225 | SetSystemTimer( hwnd, LB_TIMER_ID, LB_SCROLL_TIMEOUT, NULL); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2226 | else if (LISTBOX_Timer != LB_TIMER_NONE) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2227 | KillSystemTimer( hwnd, LB_TIMER_ID ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2228 | LISTBOX_Timer = dir; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2229 | } |
| 2230 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2231 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2232 | /*********************************************************************** |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2233 | * LISTBOX_HandleKeyDown |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2234 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2235 | static LRESULT LISTBOX_HandleKeyDown( HWND hwnd, LB_DESCR *descr, WPARAM wParam ) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2236 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2237 | INT caret = -1; |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 2238 | BOOL bForceSelection = TRUE; /* select item pointed to by focus_item */ |
| 2239 | if ((IS_MULTISELECT(descr)) || (descr->selected_item == descr->focus_item)) |
| 2240 | bForceSelection = FALSE; /* only for single select list */ |
| 2241 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2242 | if (descr->style & LBS_WANTKEYBOARDINPUT) |
| 2243 | { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2244 | caret = SendMessageW( descr->owner, WM_VKEYTOITEM, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2245 | MAKEWPARAM(LOWORD(wParam), descr->focus_item), |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2246 | hwnd ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2247 | if (caret == -2) return 0; |
| 2248 | } |
| 2249 | if (caret == -1) switch(wParam) |
| 2250 | { |
| 2251 | case VK_LEFT: |
| 2252 | if (descr->style & LBS_MULTICOLUMN) |
| 2253 | { |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 2254 | bForceSelection = FALSE; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2255 | if (descr->focus_item >= descr->page_size) |
| 2256 | caret = descr->focus_item - descr->page_size; |
| 2257 | break; |
| 2258 | } |
| 2259 | /* fall through */ |
| 2260 | case VK_UP: |
| 2261 | caret = descr->focus_item - 1; |
| 2262 | if (caret < 0) caret = 0; |
| 2263 | break; |
| 2264 | case VK_RIGHT: |
| 2265 | if (descr->style & LBS_MULTICOLUMN) |
| 2266 | { |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 2267 | bForceSelection = FALSE; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2268 | if (descr->focus_item + descr->page_size < descr->nb_items) |
| 2269 | caret = descr->focus_item + descr->page_size; |
| 2270 | break; |
| 2271 | } |
| 2272 | /* fall through */ |
| 2273 | case VK_DOWN: |
| 2274 | caret = descr->focus_item + 1; |
| 2275 | if (caret >= descr->nb_items) caret = descr->nb_items - 1; |
| 2276 | break; |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 2277 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2278 | case VK_PRIOR: |
| 2279 | if (descr->style & LBS_MULTICOLUMN) |
| 2280 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2281 | INT page = descr->width / descr->column_width; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2282 | if (page < 1) page = 1; |
| 2283 | caret = descr->focus_item - (page * descr->page_size) + 1; |
| 2284 | } |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2285 | else caret = descr->focus_item-LISTBOX_GetCurrentPageSize(descr) + 1; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2286 | if (caret < 0) caret = 0; |
| 2287 | break; |
| 2288 | case VK_NEXT: |
| 2289 | if (descr->style & LBS_MULTICOLUMN) |
| 2290 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2291 | INT page = descr->width / descr->column_width; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2292 | if (page < 1) page = 1; |
| 2293 | caret = descr->focus_item + (page * descr->page_size) - 1; |
| 2294 | } |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2295 | else caret = descr->focus_item + LISTBOX_GetCurrentPageSize(descr) - 1; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2296 | if (caret >= descr->nb_items) caret = descr->nb_items - 1; |
| 2297 | break; |
| 2298 | case VK_HOME: |
| 2299 | caret = 0; |
| 2300 | break; |
| 2301 | case VK_END: |
| 2302 | caret = descr->nb_items - 1; |
| 2303 | break; |
| 2304 | case VK_SPACE: |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 2305 | if (descr->style & LBS_EXTENDEDSEL) caret = descr->focus_item; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2306 | else if (descr->style & LBS_MULTIPLESEL) |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 2307 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2308 | LISTBOX_SetSelection( hwnd, descr, descr->focus_item, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2309 | !descr->items[descr->focus_item].selected, |
| 2310 | (descr->style & LBS_NOTIFY) != 0 ); |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 2311 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2312 | break; |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 2313 | default: |
| 2314 | bForceSelection = FALSE; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2315 | } |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 2316 | if (bForceSelection) /* focused item is used instead of key */ |
| 2317 | caret = descr->focus_item; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2318 | if (caret >= 0) |
| 2319 | { |
| 2320 | if ((descr->style & LBS_EXTENDEDSEL) && |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2321 | !(GetKeyState( VK_SHIFT ) & 0x8000)) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2322 | descr->anchor_item = caret; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2323 | LISTBOX_MoveCaret( hwnd, descr, caret, TRUE ); |
| 2324 | LISTBOX_SetSelection( hwnd, descr, caret, TRUE, FALSE); |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 2325 | if (descr->style & LBS_NOTIFY) |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2326 | { |
Dmitry Timoshkov | 6df245d | 2001-04-09 18:30:25 +0000 | [diff] [blame] | 2327 | if( descr->lphc ) |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2328 | { |
| 2329 | /* make sure that combo parent doesn't hide us */ |
| 2330 | descr->lphc->wState |= CBF_NOROLLUP; |
| 2331 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2332 | if (descr->nb_items) SEND_NOTIFICATION( hwnd, descr, LBN_SELCHANGE ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2333 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2334 | } |
| 2335 | return 0; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2336 | } |
| 2337 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2338 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2339 | /*********************************************************************** |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2340 | * LISTBOX_HandleChar |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2341 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2342 | static LRESULT LISTBOX_HandleChar( HWND hwnd, LB_DESCR *descr, WCHAR charW ) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2343 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2344 | INT caret = -1; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2345 | WCHAR str[2]; |
| 2346 | |
| 2347 | str[0] = charW; |
Patrik Stridvall | 0f8bc5b | 1999-04-22 16:27:50 +0000 | [diff] [blame] | 2348 | str[1] = '\0'; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2349 | |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 2350 | if (descr->style & LBS_WANTKEYBOARDINPUT) |
| 2351 | { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2352 | caret = SendMessageW( descr->owner, WM_CHARTOITEM, |
| 2353 | MAKEWPARAM(charW, descr->focus_item), |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2354 | hwnd ); |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 2355 | if (caret == -2) return 0; |
| 2356 | } |
| 2357 | if (caret == -1) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2358 | caret = LISTBOX_FindString( hwnd, descr, descr->focus_item, str, FALSE); |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 2359 | if (caret != -1) |
| 2360 | { |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 2361 | if ((!IS_MULTISELECT(descr)) && descr->selected_item == -1) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2362 | LISTBOX_SetSelection( hwnd, descr, caret, TRUE, FALSE); |
| 2363 | LISTBOX_MoveCaret( hwnd, descr, caret, TRUE ); |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 2364 | if ((descr->style & LBS_NOTIFY) && descr->nb_items) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2365 | SEND_NOTIFICATION( hwnd, descr, LBN_SELCHANGE ); |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 2366 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2367 | return 0; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2368 | } |
| 2369 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2370 | |
| 2371 | /*********************************************************************** |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2372 | * LISTBOX_Create |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2373 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2374 | static BOOL LISTBOX_Create( HWND hwnd, LPHEADCOMBO lphc ) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2375 | { |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2376 | LB_DESCR *descr; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2377 | MEASUREITEMSTRUCT mis; |
| 2378 | RECT rect; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2379 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2380 | if (!(descr = HeapAlloc( GetProcessHeap(), 0, sizeof(*descr) ))) |
| 2381 | return FALSE; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2382 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2383 | GetClientRect( hwnd, &rect ); |
| 2384 | descr->owner = GetParent( hwnd ); |
| 2385 | descr->style = GetWindowLongA( hwnd, GWL_STYLE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2386 | descr->width = rect.right - rect.left; |
| 2387 | descr->height = rect.bottom - rect.top; |
| 2388 | descr->items = NULL; |
| 2389 | descr->nb_items = 0; |
| 2390 | descr->top_item = 0; |
| 2391 | descr->selected_item = -1; |
| 2392 | descr->focus_item = 0; |
| 2393 | descr->anchor_item = -1; |
| 2394 | descr->item_height = 1; |
| 2395 | descr->page_size = 1; |
| 2396 | descr->column_width = 150; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2397 | descr->horz_extent = (descr->style & WS_HSCROLL) ? 1 : 0; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2398 | descr->horz_pos = 0; |
| 2399 | descr->nb_tabs = 0; |
| 2400 | descr->tabs = NULL; |
Serge Ivanov | 07917e4 | 2000-06-07 03:46:57 +0000 | [diff] [blame] | 2401 | descr->caret_on = lphc ? FALSE : TRUE; |
Andreas Mohr | 85ba879 | 2001-01-06 00:34:14 +0000 | [diff] [blame] | 2402 | if (descr->style & LBS_NOSEL) descr->caret_on = FALSE; |
Alexandre Julliard | ab2f43f | 2000-05-26 22:28:34 +0000 | [diff] [blame] | 2403 | descr->in_focus = FALSE; |
Luc Tourangeau | 5ee117b | 1999-04-04 12:48:21 +0000 | [diff] [blame] | 2404 | descr->captured = FALSE; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2405 | descr->font = 0; |
| 2406 | descr->locale = 0; /* FIXME */ |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2407 | descr->lphc = lphc; |
| 2408 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2409 | if (is_old_app(hwnd) && ( descr->style & ( WS_VSCROLL | WS_HSCROLL ) ) ) |
Nick Holloway | b9ce4fd | 1999-09-11 16:29:00 +0000 | [diff] [blame] | 2410 | { |
| 2411 | /* Win95 document "List Box Differences" from MSDN: |
| 2412 | If a list box in a version 3.x application has either the |
| 2413 | WS_HSCROLL or WS_VSCROLL style, the list box receives both |
| 2414 | horizontal and vertical scroll bars. |
| 2415 | */ |
| 2416 | descr->style |= WS_VSCROLL | WS_HSCROLL; |
| 2417 | } |
| 2418 | |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2419 | if( lphc ) |
| 2420 | { |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 2421 | TRACE_(combo)("[%04x]: resetting owner %04x -> %04x\n", |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2422 | hwnd, descr->owner, lphc->self ); |
| 2423 | descr->owner = lphc->self; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2424 | } |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 2425 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2426 | SetWindowLongA( hwnd, 0, (LONG)descr ); |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2427 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 2428 | /* if (wnd->dwExStyle & WS_EX_NOPARENTNOTIFY) descr->style &= ~LBS_NOTIFY; |
| 2429 | */ |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2430 | if (descr->style & LBS_EXTENDEDSEL) descr->style |= LBS_MULTIPLESEL; |
| 2431 | if (descr->style & LBS_MULTICOLUMN) descr->style &= ~LBS_OWNERDRAWVARIABLE; |
| 2432 | if (descr->style & LBS_OWNERDRAWVARIABLE) descr->style |= LBS_NOINTEGRALHEIGHT; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2433 | descr->item_height = LISTBOX_SetFont( hwnd, descr, 0 ); |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2434 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2435 | if (descr->style & LBS_OWNERDRAWFIXED) |
| 2436 | { |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2437 | if( descr->lphc && (descr->lphc->dwStyle & CBS_DROPDOWN)) |
| 2438 | { |
| 2439 | /* WinWord gets VERY unhappy if we send WM_MEASUREITEM from here */ |
Francis Beaudet | f585c61 | 1999-04-02 10:37:42 +0000 | [diff] [blame] | 2440 | descr->item_height = lphc->fixedOwnerDrawHeight; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2441 | } |
| 2442 | else |
| 2443 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2444 | UINT id = GetWindowLongA( hwnd, GWL_ID ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2445 | mis.CtlType = ODT_LISTBOX; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2446 | mis.CtlID = id; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2447 | mis.itemID = -1; |
| 2448 | mis.itemWidth = 0; |
| 2449 | mis.itemData = 0; |
| 2450 | mis.itemHeight = descr->item_height; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2451 | SendMessageW( descr->owner, WM_MEASUREITEM, id, (LPARAM)&mis ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2452 | descr->item_height = mis.itemHeight ? mis.itemHeight : 1; |
| 2453 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2454 | } |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2455 | |
Andreas Mohr | 85ba879 | 2001-01-06 00:34:14 +0000 | [diff] [blame] | 2456 | TRACE("owner: %04x, style: %08x, width: %d, height: %d\n", descr->owner, descr->style, descr->width, descr->height); |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2457 | return TRUE; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2458 | } |
| 2459 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2460 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2461 | /*********************************************************************** |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2462 | * LISTBOX_Destroy |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2463 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2464 | static BOOL LISTBOX_Destroy( HWND hwnd, LB_DESCR *descr ) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 2465 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2466 | LISTBOX_ResetContent( hwnd, descr ); |
| 2467 | SetWindowLongA( hwnd, 0, 0 ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2468 | HeapFree( GetProcessHeap(), 0, descr ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 2469 | return TRUE; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2470 | } |
| 2471 | |
| 2472 | |
| 2473 | /*********************************************************************** |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2474 | * ListBoxWndProc_common |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2475 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2476 | static LRESULT WINAPI ListBoxWndProc_common( HWND hwnd, UINT msg, |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2477 | WPARAM wParam, LPARAM lParam, BOOL unicode ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2478 | { |
| 2479 | LRESULT ret; |
| 2480 | LB_DESCR *descr; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2481 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2482 | if (!(descr = (LB_DESCR *)GetWindowLongA( hwnd, 0 ))) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2483 | { |
Bill Medland | e79f076 | 2001-07-17 00:55:23 +0000 | [diff] [blame] | 2484 | if (msg == WM_CREATE) |
| 2485 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2486 | if (!LISTBOX_Create( hwnd, NULL )) |
Bill Medland | e79f076 | 2001-07-17 00:55:23 +0000 | [diff] [blame] | 2487 | return -1; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2488 | TRACE("creating wnd=%04x descr=%lx\n", hwnd, GetWindowLongA( hwnd, 0 ) ); |
Bill Medland | e79f076 | 2001-07-17 00:55:23 +0000 | [diff] [blame] | 2489 | return 0; |
| 2490 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2491 | /* Ignore all other messages before we get a WM_CREATE */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2492 | return unicode ? DefWindowProcW( hwnd, msg, wParam, lParam ) : |
| 2493 | DefWindowProcA( hwnd, msg, wParam, lParam ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2494 | } |
| 2495 | |
Alexandre Julliard | 9fe7a25 | 1999-05-14 08:17:14 +0000 | [diff] [blame] | 2496 | TRACE("[%04x]: msg %s wp %08x lp %08lx\n", |
Guy L. Albertelli | db9b549 | 2001-09-07 18:38:57 +0000 | [diff] [blame] | 2497 | hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2498 | switch(msg) |
| 2499 | { |
| 2500 | case LB_RESETCONTENT16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2501 | case LB_RESETCONTENT: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2502 | LISTBOX_ResetContent( hwnd, descr ); |
| 2503 | LISTBOX_UpdateScroll( hwnd, descr ); |
| 2504 | InvalidateRect( hwnd, NULL, TRUE ); |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2505 | return 0; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2506 | |
| 2507 | case LB_ADDSTRING16: |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 2508 | if (HAS_STRINGS(descr)) lParam = (LPARAM)MapSL(lParam); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2509 | /* fall through */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2510 | case LB_ADDSTRING: |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2511 | { |
| 2512 | INT ret; |
| 2513 | LPWSTR textW; |
| 2514 | if(unicode || !HAS_STRINGS(descr)) |
| 2515 | textW = (LPWSTR)lParam; |
| 2516 | else |
| 2517 | { |
| 2518 | LPSTR textA = (LPSTR)lParam; |
| 2519 | INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0); |
| 2520 | if((textW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR)))) |
| 2521 | MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW); |
| 2522 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2523 | wParam = LISTBOX_FindStringPos( hwnd, descr, textW, FALSE ); |
| 2524 | ret = LISTBOX_InsertString( hwnd, descr, wParam, textW ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2525 | if (!unicode && HAS_STRINGS(descr)) |
| 2526 | HeapFree(GetProcessHeap(), 0, textW); |
| 2527 | return ret; |
| 2528 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2529 | |
| 2530 | case LB_INSERTSTRING16: |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 2531 | if (HAS_STRINGS(descr)) lParam = (LPARAM)MapSL(lParam); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2532 | wParam = (INT)(INT16)wParam; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2533 | /* fall through */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2534 | case LB_INSERTSTRING: |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2535 | { |
| 2536 | INT ret; |
| 2537 | LPWSTR textW; |
| 2538 | if(unicode || !HAS_STRINGS(descr)) |
| 2539 | textW = (LPWSTR)lParam; |
| 2540 | else |
| 2541 | { |
| 2542 | LPSTR textA = (LPSTR)lParam; |
| 2543 | INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0); |
| 2544 | if((textW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR)))) |
| 2545 | MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW); |
| 2546 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2547 | ret = LISTBOX_InsertString( hwnd, descr, wParam, textW ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2548 | if(!unicode && HAS_STRINGS(descr)) |
| 2549 | HeapFree(GetProcessHeap(), 0, textW); |
| 2550 | return ret; |
| 2551 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2552 | |
| 2553 | case LB_ADDFILE16: |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 2554 | if (HAS_STRINGS(descr)) lParam = (LPARAM)MapSL(lParam); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2555 | /* fall through */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2556 | case LB_ADDFILE: |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2557 | { |
| 2558 | INT ret; |
| 2559 | LPWSTR textW; |
| 2560 | if(unicode || !HAS_STRINGS(descr)) |
| 2561 | textW = (LPWSTR)lParam; |
| 2562 | else |
| 2563 | { |
| 2564 | LPSTR textA = (LPSTR)lParam; |
| 2565 | INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0); |
| 2566 | if((textW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR)))) |
| 2567 | MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW); |
| 2568 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2569 | wParam = LISTBOX_FindFileStrPos( hwnd, descr, textW ); |
| 2570 | ret = LISTBOX_InsertString( hwnd, descr, wParam, textW ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2571 | if(!unicode && HAS_STRINGS(descr)) |
| 2572 | HeapFree(GetProcessHeap(), 0, textW); |
| 2573 | return ret; |
| 2574 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2575 | |
| 2576 | case LB_DELETESTRING16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2577 | case LB_DELETESTRING: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2578 | if (LISTBOX_RemoveItem( hwnd, descr, wParam) != LB_ERR) |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 2579 | return descr->nb_items; |
| 2580 | else |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2581 | return LB_ERR; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2582 | |
| 2583 | case LB_GETITEMDATA16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2584 | case LB_GETITEMDATA: |
| 2585 | if (((INT)wParam < 0) || ((INT)wParam >= descr->nb_items)) |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2586 | return LB_ERR; |
| 2587 | return descr->items[wParam].data; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2588 | |
| 2589 | case LB_SETITEMDATA16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2590 | case LB_SETITEMDATA: |
| 2591 | if (((INT)wParam < 0) || ((INT)wParam >= descr->nb_items)) |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2592 | return LB_ERR; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2593 | descr->items[wParam].data = (DWORD)lParam; |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2594 | return LB_OKAY; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2595 | |
| 2596 | case LB_GETCOUNT16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2597 | case LB_GETCOUNT: |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2598 | return descr->nb_items; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2599 | |
| 2600 | case LB_GETTEXT16: |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 2601 | lParam = (LPARAM)MapSL(lParam); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2602 | /* fall through */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2603 | case LB_GETTEXT: |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2604 | return LISTBOX_GetText( descr, wParam, lParam, unicode ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2605 | |
| 2606 | case LB_GETTEXTLEN16: |
| 2607 | /* fall through */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2608 | case LB_GETTEXTLEN: |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2609 | if ((INT)wParam >= descr->nb_items || (INT)wParam < 0) |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2610 | return LB_ERR; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2611 | return (HAS_STRINGS(descr) ? strlenW(descr->items[wParam].str) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2612 | : sizeof(DWORD)); |
| 2613 | |
| 2614 | case LB_GETCURSEL16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2615 | case LB_GETCURSEL: |
Francis Beaudet | 8730e45 | 1999-03-25 13:22:02 +0000 | [diff] [blame] | 2616 | if (descr->nb_items==0) |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2617 | return LB_ERR; |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 2618 | if (!IS_MULTISELECT(descr)) |
| 2619 | return descr->selected_item; |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2620 | /* else */ |
| 2621 | if (descr->selected_item!=-1) |
| 2622 | return descr->selected_item; |
| 2623 | /* else */ |
| 2624 | return descr->focus_item; |
Lawson Whitney | 613092a | 1999-03-22 14:46:43 +0000 | [diff] [blame] | 2625 | /* otherwise, if the user tries to move the selection with the */ |
| 2626 | /* arrow keys, we will give the application something to choke on */ |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2627 | case LB_GETTOPINDEX16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2628 | case LB_GETTOPINDEX: |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2629 | return descr->top_item; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2630 | |
| 2631 | case LB_GETITEMHEIGHT16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2632 | case LB_GETITEMHEIGHT: |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2633 | return LISTBOX_GetItemHeight( descr, wParam ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2634 | |
| 2635 | case LB_SETITEMHEIGHT16: |
| 2636 | lParam = LOWORD(lParam); |
| 2637 | /* fall through */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2638 | case LB_SETITEMHEIGHT: |
Alexandre Julliard | c72a9aa | 2002-01-31 21:05:05 +0000 | [diff] [blame] | 2639 | return LISTBOX_SetItemHeight( hwnd, descr, wParam, lParam, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2640 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2641 | case LB_ITEMFROMPOINT: |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2642 | { |
Patrik Stridvall | 0f8bc5b | 1999-04-22 16:27:50 +0000 | [diff] [blame] | 2643 | POINT pt; |
| 2644 | RECT rect; |
| 2645 | |
| 2646 | pt.x = LOWORD(lParam); |
| 2647 | pt.y = HIWORD(lParam); |
| 2648 | rect.left = 0; |
| 2649 | rect.top = 0; |
| 2650 | rect.right = descr->width; |
| 2651 | rect.bottom = descr->height; |
| 2652 | |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2653 | return MAKELONG( LISTBOX_GetItemFromPoint(descr, pt.x, pt.y), |
Gerard Patel | 777508a | 1999-05-08 12:35:17 +0000 | [diff] [blame] | 2654 | !PtInRect( &rect, pt ) ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2655 | } |
| 2656 | |
| 2657 | case LB_SETCARETINDEX16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2658 | case LB_SETCARETINDEX: |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 2659 | if ((!IS_MULTISELECT(descr)) && (descr->selected_item != -1)) return LB_ERR; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2660 | if (LISTBOX_SetCaretIndex( hwnd, descr, wParam, !lParam ) == LB_ERR) |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 2661 | return LB_ERR; |
| 2662 | else if (ISWIN31) |
| 2663 | return wParam; |
| 2664 | else |
| 2665 | return LB_OKAY; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2666 | |
| 2667 | case LB_GETCARETINDEX16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2668 | case LB_GETCARETINDEX: |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2669 | return descr->focus_item; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2670 | |
| 2671 | case LB_SETTOPINDEX16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2672 | case LB_SETTOPINDEX: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2673 | return LISTBOX_SetTopItem( hwnd, descr, wParam, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2674 | |
| 2675 | case LB_SETCOLUMNWIDTH16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2676 | case LB_SETCOLUMNWIDTH: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2677 | return LISTBOX_SetColumnWidth( hwnd, descr, wParam ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2678 | |
| 2679 | case LB_GETITEMRECT16: |
| 2680 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2681 | RECT rect; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2682 | ret = LISTBOX_GetItemRect( descr, (INT16)wParam, &rect ); |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 2683 | CONV_RECT32TO16( &rect, MapSL(lParam) ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2684 | } |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2685 | return ret; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2686 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2687 | case LB_GETITEMRECT: |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2688 | return LISTBOX_GetItemRect( descr, wParam, (RECT *)lParam ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2689 | |
| 2690 | case LB_FINDSTRING16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2691 | wParam = (INT)(INT16)wParam; |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 2692 | if (HAS_STRINGS(descr)) lParam = (LPARAM)MapSL(lParam); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2693 | /* fall through */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2694 | case LB_FINDSTRING: |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2695 | { |
| 2696 | INT ret; |
| 2697 | LPWSTR textW; |
| 2698 | if(unicode || !HAS_STRINGS(descr)) |
| 2699 | textW = (LPWSTR)lParam; |
| 2700 | else |
| 2701 | { |
| 2702 | LPSTR textA = (LPSTR)lParam; |
| 2703 | INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0); |
| 2704 | if((textW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR)))) |
| 2705 | MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW); |
| 2706 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2707 | ret = LISTBOX_FindString( hwnd, descr, wParam, textW, FALSE ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2708 | if(!unicode && HAS_STRINGS(descr)) |
| 2709 | HeapFree(GetProcessHeap(), 0, textW); |
| 2710 | return ret; |
| 2711 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2712 | |
| 2713 | case LB_FINDSTRINGEXACT16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2714 | wParam = (INT)(INT16)wParam; |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 2715 | if (HAS_STRINGS(descr)) lParam = (LPARAM)MapSL(lParam); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2716 | /* fall through */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2717 | case LB_FINDSTRINGEXACT: |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2718 | { |
| 2719 | INT ret; |
| 2720 | LPWSTR textW; |
| 2721 | if(unicode || !HAS_STRINGS(descr)) |
| 2722 | textW = (LPWSTR)lParam; |
| 2723 | else |
| 2724 | { |
| 2725 | LPSTR textA = (LPSTR)lParam; |
| 2726 | INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0); |
| 2727 | if((textW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR)))) |
| 2728 | MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW); |
| 2729 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2730 | ret = LISTBOX_FindString( hwnd, descr, wParam, textW, TRUE ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2731 | if(!unicode && HAS_STRINGS(descr)) |
| 2732 | HeapFree(GetProcessHeap(), 0, textW); |
| 2733 | return ret; |
| 2734 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2735 | |
| 2736 | case LB_SELECTSTRING16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2737 | wParam = (INT)(INT16)wParam; |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 2738 | if (HAS_STRINGS(descr)) lParam = (LPARAM)MapSL(lParam); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2739 | /* fall through */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2740 | case LB_SELECTSTRING: |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2741 | { |
| 2742 | INT index; |
| 2743 | LPWSTR textW; |
Dmitry Timoshkov | e8ffcaa | 2001-04-16 19:32:19 +0000 | [diff] [blame] | 2744 | |
| 2745 | if(HAS_STRINGS(descr)) |
| 2746 | TRACE("LB_SELECTSTRING: %s\n", unicode ? debugstr_w((LPWSTR)lParam) : |
| 2747 | debugstr_a((LPSTR)lParam)); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2748 | if(unicode || !HAS_STRINGS(descr)) |
| 2749 | textW = (LPWSTR)lParam; |
| 2750 | else |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2751 | { |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2752 | LPSTR textA = (LPSTR)lParam; |
| 2753 | INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0); |
| 2754 | if((textW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR)))) |
| 2755 | MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2756 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2757 | index = LISTBOX_FindString( hwnd, descr, wParam, textW, FALSE ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2758 | if(!unicode && HAS_STRINGS(descr)) |
| 2759 | HeapFree(GetProcessHeap(), 0, textW); |
| 2760 | if (index != LB_ERR) |
Dmitry Timoshkov | e8ffcaa | 2001-04-16 19:32:19 +0000 | [diff] [blame] | 2761 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2762 | LISTBOX_SetCaretIndex( hwnd, descr, index, TRUE ); |
| 2763 | LISTBOX_SetSelection( hwnd, descr, index, TRUE, FALSE ); |
Dmitry Timoshkov | e8ffcaa | 2001-04-16 19:32:19 +0000 | [diff] [blame] | 2764 | } |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2765 | return index; |
| 2766 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2767 | |
| 2768 | case LB_GETSEL16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2769 | wParam = (INT)(INT16)wParam; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2770 | /* fall through */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2771 | case LB_GETSEL: |
| 2772 | if (((INT)wParam < 0) || ((INT)wParam >= descr->nb_items)) |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2773 | return LB_ERR; |
| 2774 | return descr->items[wParam].selected; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2775 | |
| 2776 | case LB_SETSEL16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2777 | lParam = (INT)(INT16)lParam; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2778 | /* fall through */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2779 | case LB_SETSEL: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2780 | return LISTBOX_SetSelection( hwnd, descr, lParam, wParam, FALSE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2781 | |
| 2782 | case LB_SETCURSEL16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2783 | wParam = (INT)(INT16)wParam; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2784 | /* fall through */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2785 | case LB_SETCURSEL: |
Gerard Patel | c9a6d50 | 1999-07-25 13:03:17 +0000 | [diff] [blame] | 2786 | if (IS_MULTISELECT(descr)) return LB_ERR; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2787 | LISTBOX_SetCaretIndex( hwnd, descr, wParam, TRUE ); |
| 2788 | return LISTBOX_SetSelection( hwnd, descr, wParam, TRUE, FALSE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2789 | |
| 2790 | case LB_GETSELCOUNT16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2791 | case LB_GETSELCOUNT: |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2792 | return LISTBOX_GetSelCount( descr ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2793 | |
| 2794 | case LB_GETSELITEMS16: |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2795 | return LISTBOX_GetSelItems16( descr, wParam, (LPINT16)MapSL(lParam) ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2796 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2797 | case LB_GETSELITEMS: |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2798 | return LISTBOX_GetSelItems( descr, wParam, (LPINT)lParam ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2799 | |
| 2800 | case LB_SELITEMRANGE16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2801 | case LB_SELITEMRANGE: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2802 | if (LOWORD(lParam) <= HIWORD(lParam)) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2803 | return LISTBOX_SelectItemRange( hwnd, descr, LOWORD(lParam), |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2804 | HIWORD(lParam), wParam ); |
| 2805 | else |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2806 | return LISTBOX_SelectItemRange( hwnd, descr, HIWORD(lParam), |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2807 | LOWORD(lParam), wParam ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2808 | |
| 2809 | case LB_SELITEMRANGEEX16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2810 | case LB_SELITEMRANGEEX: |
| 2811 | if ((INT)lParam >= (INT)wParam) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2812 | return LISTBOX_SelectItemRange( hwnd, descr, wParam, lParam, TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2813 | else |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2814 | return LISTBOX_SelectItemRange( hwnd, descr, lParam, wParam, FALSE); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2815 | |
| 2816 | case LB_GETHORIZONTALEXTENT16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2817 | case LB_GETHORIZONTALEXTENT: |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2818 | return descr->horz_extent; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2819 | |
| 2820 | case LB_SETHORIZONTALEXTENT16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2821 | case LB_SETHORIZONTALEXTENT: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2822 | return LISTBOX_SetHorizontalExtent( hwnd, descr, wParam ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2823 | |
| 2824 | case LB_GETANCHORINDEX16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2825 | case LB_GETANCHORINDEX: |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2826 | return descr->anchor_item; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2827 | |
| 2828 | case LB_SETANCHORINDEX16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2829 | wParam = (INT)(INT16)wParam; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2830 | /* fall through */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2831 | case LB_SETANCHORINDEX: |
| 2832 | if (((INT)wParam < -1) || ((INT)wParam >= descr->nb_items)) |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2833 | return LB_ERR; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2834 | descr->anchor_item = (INT)wParam; |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2835 | return LB_OKAY; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2836 | |
| 2837 | case LB_DIR16: |
Ove Kaaven | 2c691b3 | 2000-11-25 03:06:03 +0000 | [diff] [blame] | 2838 | /* according to Win16 docs, DDL_DRIVES should make DDL_EXCLUSIVE |
| 2839 | * be set automatically (this is different in Win32) */ |
| 2840 | if (wParam & DDL_DRIVES) wParam |= DDL_EXCLUSIVE; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2841 | lParam = (LPARAM)MapSL(lParam); |
| 2842 | /* fall through */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2843 | case LB_DIR: |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2844 | { |
| 2845 | INT ret; |
| 2846 | LPWSTR textW; |
| 2847 | if(unicode) |
| 2848 | textW = (LPWSTR)lParam; |
| 2849 | else |
| 2850 | { |
| 2851 | LPSTR textA = (LPSTR)lParam; |
| 2852 | INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0); |
| 2853 | if((textW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR)))) |
| 2854 | MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW); |
| 2855 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2856 | ret = LISTBOX_Directory( hwnd, descr, wParam, textW, msg == LB_DIR ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2857 | if(!unicode) |
| 2858 | HeapFree(GetProcessHeap(), 0, textW); |
| 2859 | return ret; |
| 2860 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2861 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2862 | case LB_GETLOCALE: |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2863 | return descr->locale; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2864 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2865 | case LB_SETLOCALE: |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2866 | descr->locale = (LCID)wParam; /* FIXME: should check for valid lcid */ |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2867 | return LB_OKAY; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2868 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2869 | case LB_INITSTORAGE: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2870 | return LISTBOX_InitStorage( hwnd, descr, wParam ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2871 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2872 | case LB_SETCOUNT: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2873 | return LISTBOX_SetCount( hwnd, descr, (INT)wParam ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2874 | |
| 2875 | case LB_SETTABSTOPS16: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2876 | return LISTBOX_SetTabStops( hwnd, descr, (INT)(INT16)wParam, MapSL(lParam), TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2877 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2878 | case LB_SETTABSTOPS: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2879 | return LISTBOX_SetTabStops( hwnd, descr, wParam, (LPINT)lParam, FALSE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2880 | |
| 2881 | case LB_CARETON16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2882 | case LB_CARETON: |
Francois Boisvert | 6b1b41c | 1999-03-14 17:25:32 +0000 | [diff] [blame] | 2883 | if (descr->caret_on) |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2884 | return LB_OKAY; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2885 | descr->caret_on = TRUE; |
Alexandre Julliard | ab2f43f | 2000-05-26 22:28:34 +0000 | [diff] [blame] | 2886 | if ((descr->focus_item != -1) && (descr->in_focus)) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2887 | LISTBOX_RepaintItem( hwnd, descr, descr->focus_item, ODA_FOCUS ); |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2888 | return LB_OKAY; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2889 | |
| 2890 | case LB_CARETOFF16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2891 | case LB_CARETOFF: |
Francois Boisvert | 6b1b41c | 1999-03-14 17:25:32 +0000 | [diff] [blame] | 2892 | if (!descr->caret_on) |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2893 | return LB_OKAY; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2894 | descr->caret_on = FALSE; |
Alexandre Julliard | ab2f43f | 2000-05-26 22:28:34 +0000 | [diff] [blame] | 2895 | if ((descr->focus_item != -1) && (descr->in_focus)) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2896 | LISTBOX_RepaintItem( hwnd, descr, descr->focus_item, ODA_FOCUS ); |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2897 | return LB_OKAY; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2898 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2899 | case WM_DESTROY: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2900 | return LISTBOX_Destroy( hwnd, descr ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2901 | |
| 2902 | case WM_ENABLE: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2903 | InvalidateRect( hwnd, NULL, TRUE ); |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2904 | return 0; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2905 | |
| 2906 | case WM_SETREDRAW: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2907 | LISTBOX_SetRedraw( hwnd, descr, wParam != 0 ); |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2908 | return 0; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2909 | |
| 2910 | case WM_GETDLGCODE: |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2911 | return DLGC_WANTARROWS | DLGC_WANTCHARS; |
| 2912 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2913 | case WM_PAINT: |
| 2914 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2915 | PAINTSTRUCT ps; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2916 | HDC hdc = ( wParam ) ? ((HDC)wParam) : BeginPaint( hwnd, &ps ); |
| 2917 | ret = LISTBOX_Paint( hwnd, descr, hdc ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2918 | if( !wParam ) EndPaint( hwnd, &ps ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2919 | } |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2920 | return ret; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2921 | case WM_SIZE: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2922 | LISTBOX_UpdateSize( hwnd, descr ); |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2923 | return 0; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2924 | case WM_GETFONT: |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2925 | return descr->font; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2926 | case WM_SETFONT: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2927 | LISTBOX_SetFont( hwnd, descr, (HFONT)wParam ); |
| 2928 | if (lParam) InvalidateRect( hwnd, 0, TRUE ); |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2929 | return 0; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2930 | case WM_SETFOCUS: |
Alexandre Julliard | ab2f43f | 2000-05-26 22:28:34 +0000 | [diff] [blame] | 2931 | descr->in_focus = TRUE; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2932 | descr->caret_on = TRUE; |
| 2933 | if (descr->focus_item != -1) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2934 | LISTBOX_RepaintItem( hwnd, descr, descr->focus_item, ODA_FOCUS ); |
| 2935 | SEND_NOTIFICATION( hwnd, descr, LBN_SETFOCUS ); |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2936 | return 0; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2937 | case WM_KILLFOCUS: |
Alexandre Julliard | ab2f43f | 2000-05-26 22:28:34 +0000 | [diff] [blame] | 2938 | descr->in_focus = FALSE; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2939 | if ((descr->focus_item != -1) && descr->caret_on) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2940 | LISTBOX_RepaintItem( hwnd, descr, descr->focus_item, ODA_FOCUS ); |
| 2941 | SEND_NOTIFICATION( hwnd, descr, LBN_KILLFOCUS ); |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2942 | return 0; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2943 | case WM_HSCROLL: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2944 | return LISTBOX_HandleHScroll( hwnd, descr, wParam ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2945 | case WM_VSCROLL: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2946 | return LISTBOX_HandleVScroll( hwnd, descr, wParam ); |
Stephane Lussier | 4bdf4af | 2000-04-18 11:56:33 +0000 | [diff] [blame] | 2947 | case WM_MOUSEWHEEL: |
| 2948 | if (wParam & (MK_SHIFT | MK_CONTROL)) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2949 | return DefWindowProcW( hwnd, msg, wParam, lParam ); |
| 2950 | return LISTBOX_HandleMouseWheel( hwnd, descr, wParam ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2951 | case WM_LBUTTONDOWN: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2952 | return LISTBOX_HandleLButtonDown( hwnd, descr, wParam, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2953 | (INT16)LOWORD(lParam), |
| 2954 | (INT16)HIWORD(lParam) ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2955 | case WM_LBUTTONDBLCLK: |
| 2956 | if (descr->style & LBS_NOTIFY) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2957 | SEND_NOTIFICATION( hwnd, descr, LBN_DBLCLK ); |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2958 | return 0; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2959 | case WM_MOUSEMOVE: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 2960 | if (GetCapture() == hwnd) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2961 | LISTBOX_HandleMouseMove( hwnd, descr, (INT16)LOWORD(lParam), |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2962 | (INT16)HIWORD(lParam) ); |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2963 | return 0; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2964 | case WM_LBUTTONUP: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2965 | return LISTBOX_HandleLButtonUp( hwnd, descr ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2966 | case WM_KEYDOWN: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2967 | return LISTBOX_HandleKeyDown( hwnd, descr, wParam ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2968 | case WM_CHAR: |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2969 | { |
| 2970 | WCHAR charW; |
| 2971 | if(unicode) |
| 2972 | charW = (WCHAR)wParam; |
| 2973 | else |
| 2974 | { |
| 2975 | CHAR charA = (CHAR)wParam; |
| 2976 | MultiByteToWideChar(CP_ACP, 0, &charA, 1, &charW, 1); |
| 2977 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2978 | return LISTBOX_HandleChar( hwnd, descr, charW ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2979 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2980 | case WM_SYSTIMER: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2981 | return LISTBOX_HandleSystemTimer( hwnd, descr ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2982 | case WM_ERASEBKGND: |
Gerard Patel | 41b07fb | 2000-06-15 00:07:20 +0000 | [diff] [blame] | 2983 | if ((IS_OWNERDRAW(descr)) && !(descr->style & LBS_DISPLAYCHANGED)) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2984 | { |
Luc Tourangeau | 8914799 | 1999-04-18 09:23:56 +0000 | [diff] [blame] | 2985 | RECT rect; |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2986 | HBRUSH hbrush = SendMessageW( descr->owner, WM_CTLCOLORLISTBOX, |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 2987 | wParam, (LPARAM)hwnd ); |
Dmitry Timoshkov | 52ece0e | 2001-02-26 22:31:55 +0000 | [diff] [blame] | 2988 | TRACE("hbrush = %04x\n", hbrush); |
| 2989 | if(!hbrush) |
| 2990 | hbrush = GetSysColorBrush(COLOR_WINDOW); |
| 2991 | if(hbrush) |
| 2992 | { |
| 2993 | GetClientRect(hwnd, &rect); |
| 2994 | FillRect((HDC)wParam, &rect, hbrush); |
| 2995 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2996 | } |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 2997 | return 1; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 2998 | case WM_DROPFILES: |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 2999 | if( !descr->lphc ) |
| 3000 | return unicode ? SendMessageW( descr->owner, msg, wParam, lParam ) : |
| 3001 | SendMessageA( descr->owner, msg, wParam, lParam ); |
| 3002 | break; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 3003 | |
| 3004 | case WM_DROPOBJECT: |
| 3005 | case WM_QUERYDROPOBJECT: |
| 3006 | case WM_DRAGSELECT: |
| 3007 | case WM_DRAGMOVE: |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3008 | if( !descr->lphc ) |
| 3009 | { |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 3010 | LPDRAGINFO16 dragInfo = MapSL( lParam ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 3011 | dragInfo->l = LISTBOX_GetItemFromPoint( descr, dragInfo->pt.x, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 3012 | dragInfo->pt.y ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 3013 | return SendMessage16( descr->owner, msg, wParam, lParam ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3014 | } |
| 3015 | break; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 3016 | |
| 3017 | default: |
| 3018 | if ((msg >= WM_USER) && (msg < 0xc000)) |
Alexandre Julliard | 9fe7a25 | 1999-05-14 08:17:14 +0000 | [diff] [blame] | 3019 | WARN("[%04x]: unknown msg %04x wp %08x lp %08lx\n", |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 3020 | hwnd, msg, wParam, lParam ); |
| 3021 | return unicode ? DefWindowProcW( hwnd, msg, wParam, lParam ) : |
| 3022 | DefWindowProcA( hwnd, msg, wParam, lParam ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 3023 | } |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 3024 | return 0; |
| 3025 | } |
| 3026 | |
| 3027 | /*********************************************************************** |
Alexandre Julliard | 91222da | 2000-12-10 23:01:33 +0000 | [diff] [blame] | 3028 | * ListBoxWndProcA |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 3029 | * |
| 3030 | * This is just a wrapper for the real wndproc, it only does window locking |
| 3031 | * and unlocking. |
| 3032 | */ |
Alexandre Julliard | 91222da | 2000-12-10 23:01:33 +0000 | [diff] [blame] | 3033 | static LRESULT WINAPI ListBoxWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 3034 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 3035 | if (!IsWindow(hwnd)) return 0; |
| 3036 | return ListBoxWndProc_common( hwnd, msg, wParam, lParam, FALSE ); |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 3037 | } |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3038 | |
| 3039 | /*********************************************************************** |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 3040 | * ListBoxWndProcW |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3041 | */ |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 3042 | static LRESULT WINAPI ListBoxWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3043 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 3044 | if (!IsWindow(hwnd)) return 0; |
| 3045 | return ListBoxWndProc_common( hwnd, msg, wParam, lParam, TRUE ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3046 | } |
| 3047 | |
| 3048 | /*********************************************************************** |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 3049 | * ComboLBWndProc_common |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3050 | * |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 3051 | * The real combo listbox wndproc |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3052 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 3053 | static LRESULT WINAPI ComboLBWndProc_common( HWND hwnd, UINT msg, |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 3054 | WPARAM wParam, LPARAM lParam, BOOL unicode ) |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3055 | { |
| 3056 | LRESULT lRet = 0; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 3057 | LB_DESCR *descr = (LB_DESCR *)GetWindowLongA( hwnd, 0 ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3058 | |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3059 | TRACE_(combo)("[%04x]: msg %s wp %08x lp %08lx\n", |
Guy L. Albertelli | db9b549 | 2001-09-07 18:38:57 +0000 | [diff] [blame] | 3060 | hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam ); |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3061 | |
| 3062 | if( descr || msg == WM_CREATE ) |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3063 | { |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3064 | LPHEADCOMBO lphc = (descr) ? descr->lphc : NULL; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3065 | |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3066 | switch( msg ) |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3067 | { |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3068 | case WM_CREATE: |
| 3069 | { |
| 3070 | CREATESTRUCTA *lpcs = (CREATESTRUCTA *)lParam; |
| 3071 | TRACE_(combo)("\tpassed parent handle = %p\n",lpcs->lpCreateParams); |
| 3072 | lphc = (LPHEADCOMBO)(lpcs->lpCreateParams); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 3073 | return LISTBOX_Create( hwnd, lphc ); |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3074 | } |
| 3075 | case WM_MOUSEMOVE: |
| 3076 | if ( (TWEAK_WineLook > WIN31_LOOK) && |
| 3077 | (CB_GETTYPE(lphc) != CBS_SIMPLE) ) |
| 3078 | { |
| 3079 | POINT mousePos; |
| 3080 | BOOL captured; |
| 3081 | RECT clientRect; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3082 | |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3083 | mousePos.x = (INT16)LOWORD(lParam); |
| 3084 | mousePos.y = (INT16)HIWORD(lParam); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3085 | |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3086 | /* |
| 3087 | * If we are in a dropdown combobox, we simulate that |
| 3088 | * the mouse is captured to show the tracking of the item. |
| 3089 | */ |
| 3090 | GetClientRect(hwnd, &clientRect); |
Francis Beaudet | 6ec3eaf | 1999-06-12 10:51:19 +0000 | [diff] [blame] | 3091 | |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3092 | if (PtInRect( &clientRect, mousePos )) |
| 3093 | { |
| 3094 | captured = descr->captured; |
| 3095 | descr->captured = TRUE; |
Francis Beaudet | 6ec3eaf | 1999-06-12 10:51:19 +0000 | [diff] [blame] | 3096 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 3097 | LISTBOX_HandleMouseMove( hwnd, descr, |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3098 | mousePos.x, mousePos.y); |
Francis Beaudet | 6ec3eaf | 1999-06-12 10:51:19 +0000 | [diff] [blame] | 3099 | |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3100 | descr->captured = captured; |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 3101 | |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3102 | } |
| 3103 | else |
| 3104 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 3105 | LISTBOX_HandleMouseMove( hwnd, descr, |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3106 | mousePos.x, mousePos.y); |
| 3107 | } |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 3108 | |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3109 | return 0; |
Francis Beaudet | 6ec3eaf | 1999-06-12 10:51:19 +0000 | [diff] [blame] | 3110 | |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3111 | } |
| 3112 | else |
| 3113 | { |
| 3114 | /* |
| 3115 | * If we are in Win3.1 look, go with the default behavior. |
| 3116 | */ |
| 3117 | return unicode ? ListBoxWndProcW( hwnd, msg, wParam, lParam ) : |
| 3118 | ListBoxWndProcA( hwnd, msg, wParam, lParam ); |
| 3119 | } |
| 3120 | case WM_LBUTTONUP: |
| 3121 | if (TWEAK_WineLook > WIN31_LOOK) |
| 3122 | { |
| 3123 | POINT mousePos; |
| 3124 | RECT clientRect; |
Pierre Mageau | 25c62cc | 1999-09-11 16:26:03 +0000 | [diff] [blame] | 3125 | |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3126 | /* |
| 3127 | * If the mouse button "up" is not in the listbox, |
| 3128 | * we make sure there is no selection by re-selecting the |
| 3129 | * item that was selected when the listbox was made visible. |
| 3130 | */ |
| 3131 | mousePos.x = (INT16)LOWORD(lParam); |
| 3132 | mousePos.y = (INT16)HIWORD(lParam); |
Francis Beaudet | 6ec3eaf | 1999-06-12 10:51:19 +0000 | [diff] [blame] | 3133 | |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3134 | GetClientRect(hwnd, &clientRect); |
Francis Beaudet | 6ec3eaf | 1999-06-12 10:51:19 +0000 | [diff] [blame] | 3135 | |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3136 | /* |
| 3137 | * When the user clicks outside the combobox and the focus |
| 3138 | * is lost, the owning combobox will send a fake buttonup with |
| 3139 | * 0xFFFFFFF as the mouse location, we must also revert the |
| 3140 | * selection to the original selection. |
| 3141 | */ |
| 3142 | if ( (lParam == (LPARAM)-1) || |
| 3143 | (!PtInRect( &clientRect, mousePos )) ) |
| 3144 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 3145 | LISTBOX_MoveCaret( hwnd, descr, lphc->droppedIndex, FALSE ); |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3146 | } |
| 3147 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 3148 | return LISTBOX_HandleLButtonUp( hwnd, descr ); |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3149 | case WM_LBUTTONDBLCLK: |
| 3150 | case WM_LBUTTONDOWN: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 3151 | return LISTBOX_HandleLButtonDownCombo(hwnd, descr, msg, wParam, |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3152 | (INT16)LOWORD(lParam), |
| 3153 | (INT16)HIWORD(lParam) ); |
| 3154 | case WM_NCACTIVATE: |
| 3155 | return FALSE; |
| 3156 | case WM_KEYDOWN: |
| 3157 | if( CB_GETTYPE(lphc) != CBS_SIMPLE ) |
| 3158 | { |
| 3159 | /* for some reason(?) Windows makes it possible to |
| 3160 | * show/hide ComboLBox by sending it WM_KEYDOWNs */ |
Francis Beaudet | 6ec3eaf | 1999-06-12 10:51:19 +0000 | [diff] [blame] | 3161 | |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3162 | if( (!(lphc->wState & CBF_EUI) && wParam == VK_F4) || |
| 3163 | ( (lphc->wState & CBF_EUI) && !(lphc->wState & CBF_DROPPED) |
| 3164 | && (wParam == VK_DOWN || wParam == VK_UP)) ) |
| 3165 | { |
| 3166 | COMBO_FlipListbox( lphc, FALSE, FALSE ); |
| 3167 | return 0; |
| 3168 | } |
| 3169 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 3170 | return LISTBOX_HandleKeyDown( hwnd, descr, wParam ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3171 | |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3172 | case LB_SETCURSEL16: |
| 3173 | case LB_SETCURSEL: |
| 3174 | lRet = unicode ? ListBoxWndProcW( hwnd, msg, wParam, lParam ) : |
| 3175 | ListBoxWndProcA( hwnd, msg, wParam, lParam ); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 3176 | lRet =(lRet == LB_ERR) ? lRet : descr->selected_item; |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3177 | return lRet; |
| 3178 | case WM_NCDESTROY: |
| 3179 | if( CB_GETTYPE(lphc) != CBS_SIMPLE ) |
| 3180 | lphc->hWndLBox = 0; |
| 3181 | /* fall through */ |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3182 | |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3183 | default: |
| 3184 | return unicode ? ListBoxWndProcW( hwnd, msg, wParam, lParam ) : |
| 3185 | ListBoxWndProcA( hwnd, msg, wParam, lParam ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3186 | } |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3187 | } |
Jukka Heinonen | 186a79c | 2001-07-24 01:16:16 +0000 | [diff] [blame] | 3188 | lRet = unicode ? DefWindowProcW( hwnd, msg, wParam, lParam ) : |
| 3189 | DefWindowProcA( hwnd, msg, wParam, lParam ); |
| 3190 | |
| 3191 | TRACE_(combo)("\t default on msg [%04x]\n", (UINT16)msg ); |
| 3192 | |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3193 | return lRet; |
| 3194 | } |
| 3195 | |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 3196 | /*********************************************************************** |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 3197 | * ComboLBWndProcA |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 3198 | * |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame^] | 3199 | * NOTE: in Windows, winproc address of the ComboLBox is the same |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 3200 | * as that of the Listbox. |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 3201 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 3202 | LRESULT WINAPI ComboLBWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 3203 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 3204 | if (!IsWindow(hwnd)) return 0; |
| 3205 | return ComboLBWndProc_common( hwnd, msg, wParam, lParam, FALSE ); |
Dmitry Timoshkov | 7462099 | 2001-01-09 21:51:04 +0000 | [diff] [blame] | 3206 | } |
| 3207 | |
| 3208 | /*********************************************************************** |
| 3209 | * ComboLBWndProcW |
| 3210 | */ |
| 3211 | LRESULT WINAPI ComboLBWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) |
| 3212 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 3213 | if (!IsWindow(hwnd)) return 0; |
| 3214 | return ComboLBWndProc_common( hwnd, msg, wParam, lParam, TRUE ); |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 3215 | } |