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