]>
Commit | Line | Data |
---|---|---|
97647369 RC |
1 | /* |
2 | * Copyright (c) 2002 Robert Collins. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by Robert Collins <robertc@hotmail.com> | |
13 | * | |
14 | */ | |
15 | ||
16 | #include "PickView.h" | |
17 | #include <commctrl.h> | |
18 | #include "PickPackageLine.h" | |
19 | #include "PickCategoryLine.h" | |
20 | #include "package_db.h" | |
21 | #include "package_version.h" | |
22 | #include "dialog.h" | |
23 | #include "resource.h" | |
0cf68afd | 24 | #include <algorithm> |
693916f8 RC |
25 | /* For 'source' */ |
26 | #include "state.h" | |
27 | #include "LogSingleton.h" | |
97647369 | 28 | |
6625e635 | 29 | using namespace std; |
97647369 RC |
30 | |
31 | static PickView::Header pkg_headers[] = { | |
32 | {"Current", 7, 0, 0}, | |
33 | {"New", 3, 0, 0}, | |
2fa7c5a4 | 34 | {"Bin?", 4, 0, 0}, |
97647369 | 35 | {"Src?", 4, 0, 0}, |
bfdf6ac2 | 36 | {"Categories", 10, 0, 0}, |
97647369 RC |
37 | {"Package", 7, 0, 0}, |
38 | {0, 0, 0, 0} | |
39 | }; | |
40 | ||
41 | static PickView::Header cat_headers[] = { | |
42 | {"Category", 8, 0, 0}, | |
43 | {"Current", 7, 0, 0}, | |
44 | {"New", 3, 0, 0}, | |
2fa7c5a4 | 45 | {"Bin?", 4, 0, 0}, |
97647369 RC |
46 | {"Src?", 4, 0, 0}, |
47 | {"Package", 7, 0, 0}, | |
48 | {0, 0, 0, 0} | |
49 | }; | |
50 | ||
51 | // PickView:: views | |
52 | const PickView::views PickView::views::Unknown (0); | |
53 | const PickView::views PickView::views::PackageFull (1); | |
e0aec95e MB |
54 | const PickView::views PickView::views::Package (2); |
55 | const PickView::views PickView::views::PackageKeeps (3); | |
56 | const PickView::views PickView::views::PackageSkips = PickView::views (4); | |
57 | const PickView::views PickView::views::Category (5); | |
97647369 | 58 | |
693916f8 RC |
59 | ATOM PickView::WindowClassAtom = 0; |
60 | ||
97647369 RC |
61 | // DoInsertItem - inserts an item into a header control. |
62 | // Returns the index of the new item. | |
63 | // hwndHeader - handle to the header control. | |
64 | // iInsertAfter - index of the previous item. | |
65 | // nWidth - width of the new item. | |
66 | // lpsz - address of the item string. | |
67 | static int | |
68 | DoInsertItem (HWND hwndHeader, int iInsertAfter, int nWidth, LPSTR lpsz) | |
69 | { | |
70 | HDITEM hdi; | |
71 | int index; | |
72 | ||
73 | hdi.mask = HDI_TEXT | HDI_FORMAT | HDI_WIDTH; | |
74 | hdi.pszText = lpsz; | |
75 | hdi.cxy = nWidth; | |
76 | hdi.cchTextMax = lstrlen (hdi.pszText); | |
77 | hdi.fmt = HDF_LEFT | HDF_STRING; | |
78 | ||
79 | index = SendMessage (hwndHeader, HDM_INSERTITEM, | |
80 | (WPARAM) iInsertAfter, (LPARAM) & hdi); | |
81 | ||
82 | return index; | |
83 | } | |
84 | ||
85 | ||
86 | ||
87 | void | |
88 | PickView::set_headers () | |
89 | { | |
90 | if (view_mode == views::Unknown) | |
91 | return; | |
92 | if (view_mode == views::PackageFull || | |
e0aec95e MB |
93 | view_mode == views::Package || |
94 | view_mode == views::PackageKeeps || | |
95 | view_mode == views::PackageSkips) | |
97647369 RC |
96 | { |
97 | headers = pkg_headers; | |
98 | current_col = 0; | |
99 | new_col = 1; | |
2fa7c5a4 RC |
100 | bintick_col = new_col + 1; |
101 | srctick_col = bintick_col + 1; | |
102 | cat_col = srctick_col + 1; | |
103 | pkg_col = cat_col + 1; | |
931f2755 | 104 | last_col = pkg_col; |
97647369 RC |
105 | } |
106 | else if (view_mode == views::Category) | |
107 | { | |
108 | headers = cat_headers; | |
109 | current_col = 1; | |
2fa7c5a4 RC |
110 | new_col = current_col + 1; |
111 | bintick_col = new_col + 1; | |
112 | srctick_col = bintick_col + 1; | |
97647369 | 113 | cat_col = 0; |
2fa7c5a4 RC |
114 | pkg_col = srctick_col + 1; |
115 | last_col = pkg_col; | |
97647369 RC |
116 | } |
117 | else | |
118 | return; | |
119 | while (int n = SendMessage (listheader, HDM_GETITEMCOUNT, 0, 0)) | |
120 | { | |
121 | SendMessage (listheader, HDM_DELETEITEM, n - 1, 0); | |
122 | } | |
123 | int i; | |
124 | for (i = 0; i <= last_col; i++) | |
125 | DoInsertItem (listheader, i, headers[i].width, (char *) headers[i].text); | |
126 | } | |
127 | ||
128 | void | |
3c054baf | 129 | PickView::note_width (PickView::Header *hdrs, HDC dc, String const &string, int addend, |
97647369 RC |
130 | int column) |
131 | { | |
3c054baf | 132 | if (!string.size()) |
97647369 RC |
133 | { |
134 | if (hdrs[column].width < addend) | |
135 | hdrs[column].width = addend; | |
136 | return; | |
137 | } | |
138 | SIZE s; | |
3c054baf | 139 | GetTextExtentPoint32 (dc, string.cstr_oneuse(), string.size(), &s); |
97647369 RC |
140 | if (hdrs[column].width < s.cx + addend) |
141 | hdrs[column].width = s.cx + addend; | |
142 | } | |
143 | ||
144 | void | |
145 | PickView::set_view_mode (PickView::views _mode) | |
146 | { | |
147 | view_mode = _mode; | |
148 | set_headers (); | |
149 | } | |
150 | ||
151 | const char * | |
152 | PickView::mode_caption () | |
153 | { | |
154 | return view_mode.caption (); | |
155 | } | |
156 | ||
157 | const char * | |
158 | PickView::views::caption () | |
159 | { | |
160 | switch (_value) | |
161 | { | |
162 | case 1: | |
163 | return "Full"; | |
164 | case 2: | |
165 | return "Partial"; | |
166 | case 3: | |
e0aec95e MB |
167 | return "Up To Date"; |
168 | case 4: | |
169 | return "Not Installed"; | |
170 | case 5: | |
97647369 RC |
171 | return "Category"; |
172 | default: | |
173 | return ""; | |
174 | } | |
175 | } | |
176 | ||
177 | void | |
178 | PickView::insert_pkg (packagemeta & pkg) | |
179 | { | |
180 | if (view_mode != views::Category) | |
181 | { | |
49cf3899 | 182 | PickLine & line = *new PickPackageLine (*this, pkg); |
97647369 RC |
183 | contents.insert (line); |
184 | } | |
185 | else | |
186 | { | |
405d7186 RC |
187 | for (set <String, String::caseless>::const_iterator x |
188 | = pkg.categories.begin (); x != pkg.categories.end (); ++x) | |
97647369 | 189 | { |
405d7186 RC |
190 | packagedb db; |
191 | // Special case - yuck | |
192 | if (x->casecompare ("All") == 0) | |
193 | continue; | |
194 | ||
195 | PickCategoryLine & catline = | |
0cf68afd | 196 | *new PickCategoryLine (*this,* db.categories.find (*x), 1); |
405d7186 RC |
197 | PickLine & line = *new PickPackageLine(*this, pkg); |
198 | catline.insert (line); | |
199 | contents.insert (catline); | |
97647369 RC |
200 | } |
201 | } | |
202 | } | |
203 | ||
204 | void | |
205 | PickView::insert_category (Category * cat, bool collapsed) | |
206 | { | |
0cf68afd RC |
207 | // Urk, special case |
208 | if (cat->first.casecompare ("All") == 0) | |
97647369 RC |
209 | return; |
210 | PickCategoryLine & catline = *new PickCategoryLine (*this, *cat, 1, collapsed); | |
0cf68afd RC |
211 | for (vector <packagemeta *>::iterator i = cat->second.begin (); |
212 | i != cat->second.end () ; ++i) | |
97647369 | 213 | { |
405d7186 | 214 | PickLine & line = *new PickPackageLine (*this, **i); |
97647369 RC |
215 | catline.insert (line); |
216 | } | |
217 | contents.insert (catline); | |
218 | } | |
219 | ||
220 | void | |
221 | PickView::clear_view (void) | |
222 | { | |
223 | contents.empty (); | |
224 | if (view_mode == views::Unknown) | |
225 | return; | |
226 | if (view_mode == views::PackageFull || | |
e0aec95e MB |
227 | view_mode == views::Package || |
228 | view_mode == views::PackageKeeps || | |
229 | view_mode == views::PackageSkips) | |
97647369 RC |
230 | contents.ShowLabel (false); |
231 | else if (view_mode == views::Category) | |
232 | contents.ShowLabel (); | |
233 | } | |
234 | ||
235 | PickView::views& | |
236 | PickView::views::operator++ () | |
237 | { | |
238 | ++_value; | |
239 | if (_value > Category._value) | |
240 | _value = 1; | |
241 | return *this; | |
242 | } | |
243 | ||
244 | int | |
245 | PickView::click (int row, int x) | |
246 | { | |
247 | return contents.click (0, row, x); | |
248 | } | |
249 | ||
250 | ||
251 | void | |
252 | PickView::scroll (HWND hwnd, int which, int *var, int code) | |
253 | { | |
254 | SCROLLINFO si; | |
255 | si.cbSize = sizeof (si); | |
e0aec95e | 256 | si.fMask = SIF_ALL | SIF_DISABLENOSCROLL; |
97647369 RC |
257 | GetScrollInfo (hwnd, which, &si); |
258 | ||
259 | switch (code) | |
260 | { | |
261 | case SB_THUMBTRACK: | |
262 | si.nPos = si.nTrackPos; | |
263 | break; | |
264 | case SB_THUMBPOSITION: | |
265 | break; | |
266 | case SB_BOTTOM: | |
267 | si.nPos = si.nMax; | |
268 | break; | |
269 | case SB_TOP: | |
270 | si.nPos = 0; | |
271 | break; | |
272 | case SB_LINEDOWN: | |
273 | si.nPos += row_height; | |
274 | break; | |
275 | case SB_LINEUP: | |
276 | si.nPos -= row_height; | |
277 | break; | |
278 | case SB_PAGEDOWN: | |
279 | si.nPos += si.nPage * 9 / 10; | |
280 | break; | |
281 | case SB_PAGEUP: | |
282 | si.nPos -= si.nPage * 9 / 10; | |
283 | break; | |
284 | } | |
285 | ||
286 | if ((int) si.nPos < 0) | |
287 | si.nPos = 0; | |
288 | if (si.nPos + si.nPage > (unsigned int) si.nMax) | |
289 | si.nPos = si.nMax - si.nPage; | |
290 | ||
291 | si.fMask = SIF_POS; | |
292 | SetScrollInfo (hwnd, which, &si, TRUE); | |
293 | ||
294 | int ox = scroll_ulc_x; | |
295 | int oy = scroll_ulc_y; | |
296 | *var = si.nPos; | |
297 | ||
298 | RECT cr, sr; | |
693916f8 | 299 | ::GetClientRect (hwnd, &cr); |
97647369 RC |
300 | sr = cr; |
301 | sr.top += header_height; | |
302 | UpdateWindow (hwnd); | |
303 | ScrollWindow (hwnd, ox - scroll_ulc_x, oy - scroll_ulc_y, &sr, &sr); | |
304 | /* | |
305 | sr.bottom = sr.top; | |
306 | sr.top = cr.top; | |
307 | ScrollWindow (hwnd, ox - scroll_ulc_x, 0, &sr, &sr); | |
308 | */ | |
309 | if (ox - scroll_ulc_x) | |
310 | { | |
693916f8 | 311 | ::GetClientRect (listheader, &cr); |
97647369 RC |
312 | sr = cr; |
313 | // UpdateWindow (htmp); | |
693916f8 | 314 | ::MoveWindow (listheader, -scroll_ulc_x, 0, |
97647369 RC |
315 | headers[last_col].x + |
316 | headers[last_col].width, header_height, TRUE); | |
317 | } | |
318 | UpdateWindow (hwnd); | |
319 | } | |
320 | ||
321 | void | |
322 | PickView::init_headers (HDC dc) | |
323 | { | |
324 | int i; | |
325 | ||
326 | for (i = 0; headers[i].text; i++) | |
327 | { | |
328 | headers[i].width = 0; | |
329 | headers[i].x = 0; | |
330 | } | |
331 | ||
332 | for (i = 0; headers[i].text; i++) | |
333 | note_width (headers, dc, headers[i].text, HMARGIN, i); | |
334 | /* src checkbox */ | |
2fa7c5a4 RC |
335 | note_width (headers, dc, 0, HMARGIN + 11, bintick_col); |
336 | note_width (headers, dc, 0, HMARGIN + 11, srctick_col); | |
97647369 | 337 | packagedb db; |
0cf68afd RC |
338 | for (packagedb::categoriesType::iterator n = packagedb::categories.begin(); |
339 | n != packagedb::categories.end(); ++n) | |
340 | note_width (headers, dc, String ("+ ")+n->first, HMARGIN, cat_col); | |
cfae3b8d RC |
341 | for (vector <packagemeta *>::iterator n = db.packages.begin (); |
342 | n != db.packages.end (); ++n) | |
97647369 | 343 | { |
cfae3b8d | 344 | packagemeta & pkg = **n; |
97647369 | 345 | if (pkg.installed) |
3c196821 | 346 | note_width (headers, dc, pkg.installed.Canonical_version (), |
97647369 | 347 | HMARGIN, current_col); |
3c196821 RC |
348 | for (set<packageversion>::iterator i=pkg.versions.begin(); |
349 | i != pkg.versions.end(); ++i) | |
350 | if (*i != pkg.installed) | |
97647369 | 351 | note_width (headers, dc, |
3c196821 | 352 | i->Canonical_version (), |
97647369 | 353 | NEW_COL_SIZE_SLOP + HMARGIN, new_col); |
3c054baf RC |
354 | String s = pkg.name; |
355 | if (pkg.SDesc ().size()) | |
356 | s += String (": ") + pkg.SDesc (); | |
357 | note_width (headers, dc, s, HMARGIN, pkg_col); | |
97647369 RC |
358 | } |
359 | note_width (headers, dc, "keep", NEW_COL_SIZE_SLOP + HMARGIN, new_col); | |
360 | note_width (headers, dc, "uninstall", NEW_COL_SIZE_SLOP + HMARGIN, new_col); | |
361 | ||
362 | headers[0].x = 0; | |
363 | for (i = 1; i <= last_col; i++) | |
364 | headers[i].x = headers[i - 1].x + headers[i - 1].width; | |
365 | } | |
366 | ||
367 | ||
693916f8 RC |
368 | PickView::PickView (Category &cat) : deftrust (TRUST_UNKNOWN), |
369 | contents (*this, cat, 0, false, true) | |
97647369 | 370 | { |
693916f8 | 371 | } |
97647369 | 372 | |
693916f8 RC |
373 | void |
374 | PickView::init(views _mode) | |
375 | { | |
376 | HDC dc = GetDC (GetHWND()); | |
97647369 RC |
377 | sysfont = GetStockObject (DEFAULT_GUI_FONT); |
378 | SelectObject (dc, sysfont); | |
379 | GetTextMetrics (dc, &tm); | |
380 | ||
381 | bitmap_dc = CreateCompatibleDC (dc); | |
382 | bm_spin = LoadImage (hinstance, MAKEINTRESOURCE (IDB_SPIN), IMAGE_BITMAP, 0, 0, 0); | |
383 | bm_rtarrow = LoadImage (hinstance, MAKEINTRESOURCE (IDB_RTARROW), IMAGE_BITMAP, | |
384 | 0, 0, 0); | |
385 | ||
386 | bm_checkyes = LoadImage (hinstance, MAKEINTRESOURCE (IDB_CHECK_YES), IMAGE_BITMAP, | |
387 | 0, 0, 0); | |
388 | bm_checkno = LoadImage (hinstance, MAKEINTRESOURCE (IDB_CHECK_NO), IMAGE_BITMAP, | |
389 | 0, 0, 0); | |
390 | bm_checkna = LoadImage (hinstance, MAKEINTRESOURCE (IDB_CHECK_NA), IMAGE_BITMAP, | |
391 | 0, 0, 0); | |
392 | ||
393 | row_height = (tm.tmHeight + tm.tmExternalLeading + ROW_MARGIN); | |
394 | int | |
395 | irh = | |
396 | tm. | |
397 | tmExternalLeading + | |
398 | tm. | |
399 | tmDescent + | |
400 | 11 + | |
401 | ROW_MARGIN; | |
402 | if (row_height < irh) | |
403 | row_height = irh; | |
404 | ||
405 | RECT rcParent; | |
406 | HDLAYOUT hdl; | |
407 | WINDOWPOS wp; | |
408 | ||
409 | // Ensure that the common control DLL is loaded, and then create | |
410 | // the header control. | |
411 | INITCOMMONCONTROLSEX controlinfo = | |
412 | { | |
413 | sizeof (INITCOMMONCONTROLSEX), ICC_LISTVIEW_CLASSES}; | |
414 | InitCommonControlsEx (&controlinfo); | |
415 | ||
416 | if ((listheader = CreateWindowEx (0, WC_HEADER, (LPCTSTR) NULL, | |
417 | WS_CHILD | WS_BORDER | CCS_NORESIZE | | |
418 | // | HDS_BUTTONS | |
693916f8 | 419 | HDS_HORZ, 0, 0, 0, 0, GetHWND(), |
97647369 RC |
420 | (HMENU) IDC_CHOOSE_LISTHEADER, hinstance, |
421 | (LPVOID) NULL)) == NULL) | |
422 | // FIXME: throw an exception | |
423 | exit (10); | |
424 | ||
425 | // Retrieve the bounding rectangle of the parent window's | |
426 | // client area, and then request size and position values | |
427 | // from the header control. | |
693916f8 | 428 | ::GetClientRect (GetHWND(), &rcParent); |
97647369 RC |
429 | |
430 | hdl.prc = &rcParent; | |
431 | hdl.pwpos = ℘ | |
432 | if (!SendMessage (listheader, HDM_LAYOUT, 0, (LPARAM) & hdl)) | |
433 | // FIXME: throw an exception | |
434 | exit (11); | |
435 | ||
09130e58 RC |
436 | // Set the font of the listheader, but don't redraw, because its not shown |
437 | // yet.This message does not return a value, so we are not checking it as we | |
438 | // do above. | |
439 | SendMessage (listheader, WM_SETFONT, (WPARAM) sysfont, FALSE); | |
97647369 RC |
440 | |
441 | // Set the size, position, and visibility of the header control. | |
442 | SetWindowPos (listheader, wp.hwndInsertAfter, wp.x, wp.y, | |
443 | wp.cx, wp.cy, wp.flags | SWP_SHOWWINDOW); | |
444 | ||
445 | header_height = wp.cy; | |
446 | ||
447 | view_mode = PickView::views::Package; | |
448 | set_headers (); | |
449 | init_headers (dc); | |
450 | view_mode = PickView::views::Category; | |
451 | set_headers (); | |
452 | init_headers (dc); | |
453 | ||
454 | view_mode = _mode; | |
455 | set_headers (); | |
456 | ||
457 | ReleaseDC (lv, dc); | |
458 | } | |
49cf3899 RC |
459 | |
460 | PickView::~PickView() | |
461 | { | |
462 | } | |
693916f8 RC |
463 | |
464 | bool PickView::registerWindowClass () | |
465 | { | |
466 | if (WindowClassAtom != 0) | |
467 | return true; | |
468 | ||
469 | // We're not registered yet | |
470 | WNDCLASSEX wc; | |
471 | ||
472 | wc.cbSize = sizeof (wc); | |
473 | // Some sensible style defaults | |
474 | wc.style = CS_HREDRAW | CS_VREDRAW; | |
475 | // Our default window procedure. This replaces itself | |
476 | // on the first call with the simpler Window::WindowProcReflector(). | |
477 | wc.lpfnWndProc = Window::FirstWindowProcReflector; | |
478 | // No class bytes | |
479 | wc.cbClsExtra = 0; | |
480 | // One pointer to REFLECTION_INFO in the extra window instance bytes | |
481 | wc.cbWndExtra = 4; | |
482 | // The app instance | |
483 | wc.hInstance = hinstance; //GetInstance (); | |
484 | // Use a bunch of system defaults for the GUI elements | |
485 | wc.hIcon = LoadIcon (0, IDI_APPLICATION); | |
486 | wc.hIconSm = NULL; | |
487 | wc.hCursor = LoadCursor (0, IDC_ARROW); | |
488 | wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); | |
489 | // No menu | |
490 | wc.lpszMenuName = NULL; | |
491 | // We'll get a little crazy here with the class name | |
492 | wc.lpszClassName = "listview"; | |
493 | ||
494 | // All set, try to register | |
495 | WindowClassAtom = RegisterClassEx (&wc); | |
496 | if (WindowClassAtom == 0) | |
497 | log (LOG_BABBLE) << "Failed to register listview " << GetLastError () << endLog; | |
498 | return WindowClassAtom != 0; | |
499 | } | |
500 | ||
501 | LRESULT CALLBACK | |
502 | PickView::list_vscroll (HWND hwnd, HWND hctl, UINT code, int pos) | |
503 | { | |
d2be933d | 504 | scroll (hwnd, SB_VERT, &scroll_ulc_y, code); |
693916f8 RC |
505 | return 0; |
506 | } | |
507 | ||
508 | LRESULT CALLBACK | |
509 | PickView::list_hscroll (HWND hwnd, HWND hctl, UINT code, int pos) | |
510 | { | |
d2be933d | 511 | scroll (hwnd, SB_HORZ, &scroll_ulc_x, code); |
693916f8 RC |
512 | return 0; |
513 | } | |
514 | ||
515 | LRESULT CALLBACK | |
516 | PickView::list_click (HWND hwnd, BOOL dblclk, int x, int y, UINT hitCode) | |
517 | { | |
518 | int row, refresh; | |
519 | ||
d2be933d | 520 | if (contents.itemcount () == 0) |
693916f8 RC |
521 | return 0; |
522 | ||
d2be933d | 523 | if (y < header_height) |
693916f8 | 524 | return 0; |
d2be933d RC |
525 | x += scroll_ulc_x; |
526 | y += scroll_ulc_y - header_height; | |
693916f8 | 527 | |
d2be933d | 528 | row = (y + ROW_MARGIN / 2) / row_height; |
693916f8 | 529 | |
d2be933d | 530 | if (row < 0 || row >= contents.itemcount ()) |
693916f8 RC |
531 | return 0; |
532 | ||
d2be933d | 533 | refresh = click (row, x); |
693916f8 RC |
534 | |
535 | // XXX we need a method to queryt he database to see if more | |
536 | // than just one package has changed! Until then... | |
537 | #if 0 | |
538 | if (refresh) | |
539 | { | |
540 | #endif | |
541 | RECT r; | |
542 | ::GetClientRect (lv, &r); | |
543 | SCROLLINFO si; | |
544 | memset (&si, 0, sizeof (si)); | |
545 | si.cbSize = sizeof (si); | |
546 | si.fMask = SIF_ALL | SIF_DISABLENOSCROLL; /* SIF_RANGE was giving strange behaviour */ | |
547 | si.nMin = 0; | |
548 | ||
d2be933d RC |
549 | si.nMax = contents.itemcount () * row_height; |
550 | si.nPage = r.bottom - header_height; | |
693916f8 RC |
551 | |
552 | /* if we are under the minimum display count , | |
553 | * set the offset to 0 | |
554 | */ | |
555 | if ((unsigned int) si.nMax <= si.nPage) | |
d2be933d RC |
556 | scroll_ulc_y = 0; |
557 | si.nPos = scroll_ulc_y; | |
693916f8 RC |
558 | |
559 | SetScrollInfo (lv, SB_VERT, &si, TRUE); | |
560 | ||
561 | InvalidateRect (lv, &r, TRUE); | |
562 | #if 0 | |
563 | } | |
564 | else | |
565 | { | |
566 | RECT rect; | |
567 | rect.left = | |
d2be933d | 568 | headers[new_col].x - scroll_ulc_x; |
693916f8 | 569 | rect.right = |
d2be933d | 570 | headers[src_col + 1].x - scroll_ulc_x; |
693916f8 | 571 | rect.top = |
d2be933d RC |
572 | header_height + row * row_height - |
573 | scroll_ulc_y; | |
574 | rect.bottom = rect.top + row_height; | |
693916f8 RC |
575 | InvalidateRect (hwnd, &rect, TRUE); |
576 | } | |
577 | #endif | |
578 | return 0; | |
579 | } | |
580 | ||
581 | /* | |
582 | * LRESULT CALLBACK | |
583 | * PickView::listview_proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) | |
584 | */ | |
585 | LRESULT | |
586 | PickView::WindowProc (UINT message, WPARAM wParam, LPARAM lParam) | |
587 | { | |
588 | switch (message) | |
589 | { | |
590 | case WM_HSCROLL: | |
591 | return HANDLE_WM_HSCROLL (GetHWND(), wParam, lParam, list_hscroll); | |
592 | case WM_VSCROLL: | |
593 | return HANDLE_WM_VSCROLL (GetHWND(), wParam, lParam, list_vscroll); | |
594 | case WM_LBUTTONDOWN: | |
595 | return HANDLE_WM_LBUTTONDOWN (GetHWND(), wParam, lParam, list_click); | |
596 | case WM_PAINT: | |
597 | paint (GetHWND()); | |
598 | return 0; | |
599 | case WM_NOTIFY: | |
600 | { | |
601 | // pnmh = (LPNMHDR) lParam | |
602 | LPNMHEADER phdr = (LPNMHEADER) lParam; | |
603 | switch (phdr->hdr.code) | |
604 | { | |
605 | case HDN_ITEMCHANGED: | |
d2be933d | 606 | if (phdr->hdr.hwndFrom == ListHeader ()) |
693916f8 RC |
607 | { |
608 | if (phdr->pitem && phdr->pitem->mask & HDI_WIDTH) | |
d2be933d RC |
609 | headers[phdr->iItem].width = phdr->pitem->cxy; |
610 | for (int i = 1; i <= last_col; i++) | |
611 | headers[i].x = | |
612 | headers[i - 1].x + headers[i - 1].width; | |
693916f8 RC |
613 | RECT r; |
614 | ::GetClientRect (GetHWND(), &r); | |
615 | SCROLLINFO si; | |
616 | si.cbSize = sizeof (si); | |
617 | si.fMask = SIF_ALL | SIF_DISABLENOSCROLL; | |
618 | GetScrollInfo (GetHWND(), SB_HORZ, &si); | |
619 | int oldMax = si.nMax; | |
620 | si.nMax = | |
d2be933d RC |
621 | headers[last_col].x + |
622 | headers[last_col].width; | |
693916f8 RC |
623 | if (si.nTrackPos && oldMax > si.nMax) |
624 | si.nTrackPos += si.nMax - oldMax; | |
625 | si.nPage = r.right; | |
626 | SetScrollInfo (GetHWND(), SB_HORZ, &si, TRUE); | |
627 | InvalidateRect (GetHWND(), &r, TRUE); | |
628 | if (si.nTrackPos && oldMax > si.nMax) | |
d2be933d | 629 | scroll (GetHWND(), SB_HORZ, &scroll_ulc_x, |
693916f8 RC |
630 | SB_THUMBTRACK); |
631 | } | |
632 | break; | |
633 | default: | |
634 | break; | |
635 | } | |
636 | } | |
637 | default: | |
638 | return DefWindowProc (GetHWND(), message, wParam, lParam); | |
639 | } | |
640 | } | |
641 | ||
642 | ||
643 | HWND PickView::lv; | |
693916f8 RC |
644 | |
645 | void | |
646 | PickView::paint (HWND hwnd) | |
647 | { | |
648 | HDC hdc; | |
649 | PAINTSTRUCT ps; | |
650 | int x, y; | |
651 | ||
652 | hdc = BeginPaint (hwnd, &ps); | |
653 | ||
d2be933d | 654 | SelectObject (hdc, sysfont); |
693916f8 RC |
655 | SetBkColor (hdc, GetSysColor (COLOR_WINDOW)); |
656 | SetTextColor (hdc, GetSysColor (COLOR_WINDOWTEXT)); | |
657 | ||
658 | RECT cr; | |
659 | ::GetClientRect (hwnd, &cr); | |
660 | ||
d2be933d RC |
661 | x = cr.left - scroll_ulc_x; |
662 | y = cr.top - scroll_ulc_y + header_height; | |
693916f8 | 663 | |
d2be933d | 664 | IntersectClipRect (hdc, cr.left, cr.top + header_height, cr.right, |
693916f8 RC |
665 | cr.bottom); |
666 | ||
d2be933d | 667 | contents.paint (hdc, x, y, 0, (get_view_mode () == |
693916f8 RC |
668 | PickView::views::Category) ? 0 : 1); |
669 | ||
d2be933d | 670 | if (contents.itemcount () == 0) |
693916f8 RC |
671 | { |
672 | static const char *msg = "Nothing to Install/Update"; | |
673 | if (source == IDC_SOURCE_DOWNLOAD) | |
674 | msg = "Nothing to Download"; | |
d2be933d | 675 | TextOut (hdc, HMARGIN, header_height, msg, strlen (msg)); |
693916f8 RC |
676 | } |
677 | ||
678 | EndPaint (hwnd, &ps); | |
679 | } | |
680 | ||
681 | ||
682 | bool | |
683 | PickView::Create (Window * parent, DWORD Style, RECT *r) | |
684 | { | |
685 | ||
686 | // First register the window class, if we haven't already | |
687 | if (!registerWindowClass ()) | |
688 | { | |
689 | // Registration failed | |
690 | return false; | |
691 | } | |
692 | ||
693 | // Save our parent, we'll probably need it eventually. | |
694 | setParent(parent); | |
695 | ||
696 | // Create the window instance | |
697 | CreateWindowEx ( | |
698 | // Extended Style | |
699 | WS_EX_CLIENTEDGE, | |
700 | "listview", //MAKEINTATOM(WindowClassAtom), // window class atom (name) | |
701 | "listviewwindow", // no title-bar string yet | |
702 | // Style bits | |
703 | Style, | |
704 | r ? r->left : CW_USEDEFAULT, r ? r->top : CW_USEDEFAULT, | |
705 | r? r->right - r->left + 1 : CW_USEDEFAULT, | |
706 | r? r->bottom - r->top + 1 :CW_USEDEFAULT, | |
707 | // Parent Window | |
708 | parent == NULL ? (HWND) NULL : parent->GetHWND (), | |
709 | // use class menu | |
710 | (HMENU) MAKEINTRESOURCE (IDC_CHOOSE_LIST), | |
711 | // The application instance | |
712 | GetInstance (), | |
713 | // The this ptr, which we'll use to set up the WindowProc reflection. | |
714 | reinterpret_cast<void *>((Window *)this)); | |
715 | lv = GetHWND(); | |
716 | if (GetHWND() == NULL) | |
717 | { | |
718 | log (LOG_BABBLE) << "Failed to create PickView " << GetLastError () << endLog; | |
719 | return false; | |
720 | } | |
721 | ||
722 | return true; | |
723 | } |