]>
Commit | Line | Data |
---|---|---|
0f0a6b63 MB |
1 | /* |
2 | * Copyright (c) 2000, 2001 Red Hat, Inc. | |
3 | * Copyright (c) 2003 Robert Collins <rbtcollins@hotmail.com> | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * A copy of the GNU General Public License can be found at | |
11 | * http://www.gnu.org/ | |
12 | * | |
13 | * Written by DJ Delorie <dj@cygnus.com> | |
14 | * | |
15 | */ | |
16 | ||
17 | /* The purpose of this file is to let the user choose which packages | |
18 | to install, and which versions of the package when more than one | |
19 | version is provided. The "trust" level serves as an indication as | |
20 | to which version should be the default choice. At the moment, all | |
21 | we do is compare with previously installed packages to skip any | |
22 | that are already installed (by setting the action to ACTION_SAME). | |
23 | While the "trust" stuff is supported, it's not really implemented | |
24 | yet. We always prefer the "current" option. In the future, this | |
25 | file might have a user dialog added to let the user choose to not | |
26 | install packages, or to install packages that aren't installed by | |
27 | default. */ | |
28 | ||
0f0a6b63 MB |
29 | #include "win32.h" |
30 | #include <commctrl.h> | |
31 | #include <stdio.h> | |
2e0aaec9 | 32 | #include <stdlib.h> |
0f0a6b63 MB |
33 | #include <io.h> |
34 | #include <ctype.h> | |
35 | #include <process.h> | |
2e0aaec9 | 36 | #include <algorithm> |
0f0a6b63 | 37 | |
903087fe | 38 | #include "ini.h" |
0f0a6b63 MB |
39 | #include "dialog.h" |
40 | #include "resource.h" | |
41 | #include "state.h" | |
42 | #include "msg.h" | |
43 | #include "LogSingleton.h" | |
44 | #include "filemanip.h" | |
45 | #include "io_stream.h" | |
46 | #include "propsheet.h" | |
47 | #include "choose.h" | |
0f0a6b63 MB |
48 | |
49 | #include "package_db.h" | |
50 | #include "package_meta.h" | |
0f0a6b63 | 51 | |
0f0a6b63 MB |
52 | #include "threebar.h" |
53 | #include "Generic.h" | |
ee91d9be | 54 | #include "ControlAdjuster.h" |
82306ac2 | 55 | #include "prereq.h" |
0f0a6b63 | 56 | |
ca2b7505 CF |
57 | #include "UserSettings.h" |
58 | ||
27820085 KB |
59 | #include "Exception.h" |
60 | ||
10ac4cc7 | 61 | #include "getopt++/BoolOption.h" |
20f237b4 JT |
62 | static BoolOption UpgradeAlsoOption (false, 'g', "upgrade-also", IDS_HELPTEXT_UPGRADE_ALSO); |
63 | static BoolOption CleanOrphansOption (false, 'o', "delete-orphans", IDS_HELPTEXT_DELETE_ORPHANS); | |
64 | static BoolOption ForceCurrentOption (false, 'f', "force-current", IDS_HELPTEXT_FORCE_CURRENT); | |
65 | static BoolOption PruneInstallOption (false, 'Y', "prune-install", IDS_HELPTEXT_PRUNE_INSTALL); | |
66 | static BoolOption AllowTestOption (false, 't', "allow-test-packages", IDS_HELPTEXT_ALLOW_TEST); | |
10ac4cc7 | 67 | |
0f0a6b63 MB |
68 | extern ThreeBarProgressPage Progress; |
69 | ||
00fa5f6c CF |
70 | HWND ChooserPage::ins_dialog; |
71 | ||
ee91d9be RC |
72 | /* |
73 | Sizing information. | |
74 | */ | |
75 | static ControlAdjuster::ControlInfo ChooserControlsInfo[] = { | |
059906b3 DK |
76 | {IDC_CHOOSE_SEARCH_LABEL, CP_LEFT, CP_TOP}, |
77 | {IDC_CHOOSE_SEARCH_EDIT, CP_LEFT, CP_TOP}, | |
a8d753b6 | 78 | {IDC_CHOOSE_KEEP, CP_RIGHT, CP_TOP}, |
d78ce5e2 JT |
79 | {IDC_CHOOSE_BEST, CP_RIGHT, CP_TOP}, |
80 | {IDC_CHOOSE_SYNC, CP_RIGHT, CP_TOP}, | |
a8d753b6 | 81 | {IDC_CHOOSE_EXP, CP_RIGHT, CP_TOP}, |
6a36f6a6 | 82 | {IDC_CHOOSE_VIEW, CP_LEFT, CP_TOP}, |
6a36f6a6 | 83 | {IDC_CHOOSE_VIEWCAPTION, CP_LEFT, CP_TOP}, |
a8d753b6 | 84 | {IDC_CHOOSE_LIST, CP_STRETCH, CP_STRETCH}, |
82306ac2 | 85 | {IDC_CHOOSE_HIDE, CP_LEFT, CP_BOTTOM}, |
a8d753b6 | 86 | {0, CP_LEFT, CP_TOP} |
ee91d9be RC |
87 | }; |
88 | ||
00fa5f6c | 89 | ChooserPage::ChooserPage () : |
1c1913d1 | 90 | cmd_show_set (false), saved_geom (false), saw_geom_change (false), |
0c539f7f | 91 | timer_id (DEFAULT_TIMER_ID), activated (false) |
ee91d9be RC |
92 | { |
93 | sizeProcessor.AddControlInfo (ChooserControlsInfo); | |
ca2b7505 CF |
94 | |
95 | const char *fg_ret = | |
7411af0f | 96 | UserSettings::instance().get ("chooser_window_settings"); |
ca2b7505 CF |
97 | if (!fg_ret) |
98 | return; | |
99 | ||
100 | writer buf; | |
101 | UINT *py = buf.wpi; | |
102 | char *buf_copy = strdup (fg_ret); | |
103 | for (char *p = strtok (buf_copy, ","); p; p = strtok (NULL, ",")) | |
104 | *py++ = atoi (p); | |
105 | free (buf_copy); | |
106 | if ((py - buf.wpi) == (sizeof (buf.wpi) / sizeof (buf.wpi[0]))) | |
107 | { | |
108 | saved_geom = true; | |
109 | window_placement = buf.wp; | |
110 | } | |
111 | } | |
112 | ||
113 | ChooserPage::~ChooserPage () | |
114 | { | |
115 | if (saw_geom_change) | |
116 | { | |
117 | writer buf; | |
118 | buf.wp = window_placement; | |
119 | std::string toset; | |
120 | const char *comma = ""; | |
121 | for (unsigned i = 0; i < (sizeof (buf.wpi) / sizeof (buf.wpi[0])); i++) | |
122 | { | |
123 | char intbuf[33]; | |
124 | sprintf (intbuf, "%u", buf.wpi[i]); | |
125 | toset += comma; | |
126 | toset += intbuf; | |
127 | comma = ","; | |
128 | } | |
7411af0f | 129 | UserSettings::instance().set ("chooser_window_settings", toset); |
ca2b7505 | 130 | } |
ee91d9be RC |
131 | } |
132 | ||
ce9f6dd0 | 133 | static ListView::Header pkg_headers[] = { |
6ddcf16b JT |
134 | {IDS_COLUMN_PACKAGE, LVCFMT_LEFT, ListView::ControlType::text}, |
135 | {IDS_COLUMN_CURRENT, LVCFMT_LEFT, ListView::ControlType::text}, | |
136 | {IDS_COLUMN_NEW, LVCFMT_LEFT, ListView::ControlType::popup}, | |
137 | {IDS_COLUMN_SOURCE, LVCFMT_LEFT, ListView::ControlType::checkbox}, | |
138 | {IDS_COLUMN_CATEGORIES, LVCFMT_LEFT, ListView::ControlType::text}, | |
139 | {IDS_COLUMN_SIZE, LVCFMT_RIGHT, ListView::ControlType::text}, | |
140 | {IDS_COLUMN_DESCR, LVCFMT_LEFT, ListView::ControlType::text}, | |
ce9f6dd0 JT |
141 | {0} |
142 | }; | |
143 | ||
0f0a6b63 | 144 | void |
bc16bb7d | 145 | ChooserPage::createListview () |
0f0a6b63 | 146 | { |
67ce5bee | 147 | SetBusy (); |
ce9f6dd0 JT |
148 | |
149 | listview = new ListView(); | |
150 | listview->init(GetHWND (), IDC_CHOOSE_LIST, pkg_headers); | |
151 | ||
152 | chooser = new PickView(); | |
153 | chooser->init(PickView::views::Category, listview, this); | |
903087fe | 154 | chooser->setViewMode (!is_new_install || UpgradeAlsoOption || hasManualSelections ? |
ce9f6dd0 JT |
155 | PickView::views::PackagePending : PickView::views::Category); |
156 | ||
4f0fb3e4 | 157 | SendMessage (GetDlgItem (IDC_CHOOSE_VIEW), CB_SETCURSEL, (WPARAM)chooser->getViewMode(), 0); |
ce9f6dd0 | 158 | |
0c539f7f JT |
159 | ClearBusy (); |
160 | } | |
263157cb | 161 | |
0c539f7f JT |
162 | void |
163 | ChooserPage::initialUpdateState() | |
164 | { | |
d78ce5e2 JT |
165 | // set the initial update state |
166 | if (ForceCurrentOption) | |
167 | { | |
168 | update_mode_id = IDC_CHOOSE_SYNC; | |
d78ce5e2 JT |
169 | } |
170 | else if (hasManualSelections && !UpgradeAlsoOption) | |
171 | { | |
172 | // if packages are added or removed on the command-line and --upgrade-also | |
173 | // isn't used, we keep the current versions of everything else | |
174 | update_mode_id = IDC_CHOOSE_KEEP; | |
175 | } | |
176 | else | |
177 | { | |
178 | update_mode_id = IDC_CHOOSE_BEST; | |
d78ce5e2 | 179 | } |
b0bd1695 | 180 | changeTrust(update_mode_id, AllowTestOption, true); |
d78ce5e2 JT |
181 | |
182 | static int ta[] = { IDC_CHOOSE_KEEP, IDC_CHOOSE_BEST, IDC_CHOOSE_SYNC, 0 }; | |
183 | rbset (GetHWND (), ta, update_mode_id); | |
0f0a6b63 MB |
184 | } |
185 | ||
186 | /* TODO: review ::overrides for possible consolidation */ | |
187 | void | |
188 | ChooserPage::getParentRect (HWND parent, HWND child, RECT * r) | |
189 | { | |
190 | POINT p; | |
191 | ::GetWindowRect (child, r); | |
192 | p.x = r->left; | |
193 | p.y = r->top; | |
194 | ::ScreenToClient (parent, &p); | |
195 | r->left = p.x; | |
196 | r->top = p.y; | |
197 | p.x = r->right; | |
198 | p.y = r->bottom; | |
199 | ::ScreenToClient (parent, &p); | |
200 | r->right = p.x; | |
201 | r->bottom = p.y; | |
202 | } | |
203 | ||
00fa5f6c | 204 | void |
ca2b7505 | 205 | ChooserPage::PlaceDialog (bool doit) |
00fa5f6c | 206 | { |
7a4e611a DK |
207 | if (unattended_mode == unattended) |
208 | /* Don't jump up and down in (fully) unattended mode */; | |
ca2b7505 | 209 | else if (doit) |
00fa5f6c | 210 | { |
e305f965 | 211 | pre_chooser_placement.length = sizeof pre_chooser_placement; |
ca2b7505 CF |
212 | GetWindowPlacement (ins_dialog, &pre_chooser_placement); |
213 | if (saved_geom) | |
214 | SetWindowPlacement (ins_dialog, &window_placement); | |
215 | else | |
00fa5f6c | 216 | { |
00fa5f6c | 217 | ShowWindow (ins_dialog, SW_MAXIMIZE); |
e305f965 | 218 | window_placement.length = sizeof window_placement; |
ca2b7505 | 219 | GetWindowPlacement (ins_dialog, &window_placement); |
00fa5f6c | 220 | } |
ca2b7505 | 221 | cmd_show_set = true; |
00fa5f6c CF |
222 | } |
223 | else if (cmd_show_set) | |
224 | { | |
ca2b7505 | 225 | WINDOWPLACEMENT wp; |
e305f965 | 226 | wp.length = sizeof wp; |
ca2b7505 CF |
227 | if (GetWindowPlacement (ins_dialog, &wp) |
228 | && memcmp (&wp, &window_placement, sizeof (wp)) != 0) | |
229 | saw_geom_change = true; | |
230 | SetWindowPlacement (ins_dialog, &pre_chooser_placement); | |
231 | if (saw_geom_change) | |
232 | window_placement = wp; | |
00fa5f6c CF |
233 | cmd_show_set = false; |
234 | } | |
235 | } | |
236 | ||
0f0a6b63 MB |
237 | bool |
238 | ChooserPage::Create () | |
239 | { | |
00fa5f6c | 240 | return PropertyPage::Create (IDD_CHOOSE); |
0f0a6b63 MB |
241 | } |
242 | ||
0f0a6b63 MB |
243 | void |
244 | ChooserPage::OnInit () | |
245 | { | |
82306ac2 BD |
246 | CheckDlgButton (GetHWND (), IDC_CHOOSE_HIDE, BST_CHECKED); |
247 | ||
78edbfe4 DA |
248 | if (AllowTestOption) |
249 | CheckDlgButton (GetHWND (), IDC_CHOOSE_EXP, BST_CHECKED); | |
250 | ||
4f0fb3e4 JT |
251 | /* Populate view dropdown list with choices */ |
252 | HWND viewlist = GetDlgItem (IDC_CHOOSE_VIEW); | |
253 | SendMessage (viewlist, CB_RESETCONTENT, 0, 0); | |
254 | for (int view = (int)PickView::views::PackageFull; | |
255 | view <= (int)PickView::views::Category; | |
256 | view++) | |
257 | { | |
f7711c51 JT |
258 | std::wstring mode = LoadStringW(PickView::mode_caption((PickView::views)view)); |
259 | SendMessageW(viewlist, CB_ADDSTRING, 0, (LPARAM)mode.c_str()); | |
4f0fb3e4 JT |
260 | } |
261 | ||
24f8fc6c JT |
262 | /* Only show text appropriate to download/install mode */ |
263 | ShowWindow(GetDlgItem (IDC_CHOOSE_INST_TEXT_DOWNLOAD), | |
264 | (source == IDC_SOURCE_DOWNLOAD) ? SW_SHOW : SW_HIDE); | |
265 | ShowWindow(GetDlgItem (IDC_CHOOSE_INST_TEXT_INSTALL), | |
266 | (source != IDC_SOURCE_DOWNLOAD) ? SW_SHOW : SW_HIDE); | |
924af9d6 | 267 | |
0c539f7f | 268 | createListview (); |
0f0a6b63 | 269 | |
0c539f7f JT |
270 | AddTooltip (IDC_CHOOSE_KEEP, IDS_TRUSTKEEP_TOOLTIP); |
271 | AddTooltip (IDC_CHOOSE_BEST, IDS_TRUSTCURR_TOOLTIP); | |
272 | AddTooltip (IDC_CHOOSE_SYNC, IDS_TRUSTSYNC_TOOLTIP); | |
273 | AddTooltip (IDC_CHOOSE_EXP, IDS_TRUSTEXP_TOOLTIP); | |
274 | AddTooltip (IDC_CHOOSE_VIEW, IDS_VIEWBUTTON_TOOLTIP); | |
275 | AddTooltip (IDC_CHOOSE_HIDE, IDS_HIDEOBS_TOOLTIP); | |
276 | AddTooltip (IDC_CHOOSE_SEARCH_EDIT, IDS_SEARCH_TOOLTIP); | |
243f3cc1 | 277 | |
0c539f7f JT |
278 | /* Set focus to search edittext control. */ |
279 | PostMessage (GetHWND (), WM_NEXTDLGCTL, | |
280 | (WPARAM) GetDlgItem (IDC_CHOOSE_SEARCH_EDIT), TRUE); | |
281 | } | |
282 | ||
283 | void | |
284 | ChooserPage::applyCommandLinePackageSelection() | |
285 | { | |
286 | packagedb db; | |
a667a8b2 CV |
287 | for (packagedb::packagecollection::iterator i = db.packages.begin (); |
288 | i != db.packages.end (); ++i) | |
243f3cc1 | 289 | { |
2f6d93ed | 290 | packagemeta &pkg = *(i->second); |
bacef89a JT |
291 | packageversion wanted_version; |
292 | bool wanted = pkg.isManuallyWanted(wanted_version); | |
a667a8b2 | 293 | bool deleted = pkg.isManuallyDeleted(); |
d6e95b25 KB |
294 | bool base = pkg.categories.find ("Base") != pkg.categories.end (); |
295 | bool orphaned = pkg.categories.find ("Orphaned") != pkg.categories.end (); | |
296 | bool upgrade = wanted || (!pkg.installed && base); | |
2f6d93ed | 297 | bool install = wanted && !deleted && !pkg.installed; |
d6e95b25 KB |
298 | bool reinstall = (wanted || base) && deleted; |
299 | bool uninstall = (!(wanted || base) && (deleted || PruneInstallOption)) | |
300 | || (orphaned && CleanOrphansOption); | |
a667a8b2 | 301 | if (install) |
bacef89a | 302 | pkg.set_action (packagemeta::Install_action, UpgradeAlsoOption ? packageversion () : wanted_version, true); |
a667a8b2 | 303 | else if (reinstall) |
bacef89a | 304 | pkg.set_action (packagemeta::Reinstall_action, !wanted ? pkg.curr : wanted_version); |
a667a8b2 | 305 | else if (uninstall) |
2f6d93ed | 306 | pkg.set_action (packagemeta::Uninstall_action, packageversion ()); |
a59178eb | 307 | else if (PruneInstallOption) |
916f2b80 | 308 | pkg.set_action (packagemeta::NoChange_action, pkg.curr); |
2e6cf467 | 309 | else if (upgrade) |
bacef89a | 310 | pkg.set_action (packagemeta::Install_action, !wanted ? packageversion () : wanted_version); |
a667a8b2 | 311 | else |
916f2b80 | 312 | pkg.set_action (packagemeta::NoChange_action, pkg.installed); |
243f3cc1 | 313 | } |
0f0a6b63 MB |
314 | } |
315 | ||
316 | void | |
317 | ChooserPage::OnActivate() | |
318 | { | |
0c539f7f JT |
319 | SetBusy(); |
320 | ||
321 | packagedb db; | |
322 | db.prep(); | |
323 | ||
324 | if (!activated) | |
325 | { | |
326 | // Do things which should only happen once, but rely on packagedb being | |
327 | // ready to use, so OnInit() is too early | |
9ca5efb3 | 328 | db.noChanges(); |
0c539f7f JT |
329 | applyCommandLinePackageSelection(); |
330 | initialUpdateState(); | |
331 | ||
332 | activated = true; | |
333 | } | |
334 | ||
ce9f6dd0 JT |
335 | packagedb::categoriesType::iterator it = db.categories.find("All"); |
336 | if (it == db.categories.end ()) | |
7f85e280 JT |
337 | listview->setEmptyText(IDS_CHOOSER_EMPTY_NO_PACKAGES); |
338 | ||
ce9f6dd0 | 339 | if (source == IDC_SOURCE_DOWNLOAD) |
7f85e280 | 340 | listview->setEmptyText(IDS_CHOOSER_EMPTY_DOWNLOAD); |
ce9f6dd0 | 341 | else |
7f85e280 | 342 | listview->setEmptyText(IDS_CHOOSER_EMPTY_INSTALL); |
ce9f6dd0 JT |
343 | |
344 | chooser->build_category_tree(); | |
345 | chooser->init_headers(); | |
346 | ||
0c539f7f JT |
347 | ClearBusy(); |
348 | ||
349 | chooser->refresh(); | |
ca2b7505 | 350 | PlaceDialog (true); |
0f0a6b63 MB |
351 | } |
352 | ||
7a4e611a DK |
353 | long |
354 | ChooserPage::OnUnattended() | |
355 | { | |
356 | if (unattended_mode == unattended) | |
357 | return OnNext (); | |
358 | // Magic constant -1 (FIXME) means 'display page but stay unattended', as | |
359 | // also used for progress bars; see proppage.cc!PropertyPage::DialogProc(). | |
360 | return -1; | |
361 | } | |
362 | ||
0f0a6b63 MB |
363 | void |
364 | ChooserPage::logResults() | |
365 | { | |
157dc2b8 | 366 | Log (LOG_BABBLE) << "Chooser results..." << endLog; |
0f0a6b63 | 367 | packagedb db; |
263157cb JT |
368 | |
369 | for (packagedb::packagecollection::iterator i = db.packages.begin(); i != db.packages.end(); i++) | |
370 | { | |
371 | i->second->logSelectionStatus(); | |
372 | } | |
0f0a6b63 MB |
373 | } |
374 | ||
375 | long | |
376 | ChooserPage::OnNext () | |
377 | { | |
db165a9a | 378 | #ifdef DEBUG |
0f0a6b63 | 379 | logResults(); |
db165a9a | 380 | #endif |
0f0a6b63 | 381 | |
ca2b7505 | 382 | PlaceDialog (false); |
ad20ac46 JT |
383 | Progress.SetActivateTask (WM_APP_PREREQ_CHECK); |
384 | ||
385 | return IDD_INSTATUS; | |
0f0a6b63 MB |
386 | } |
387 | ||
388 | long | |
389 | ChooserPage::OnBack () | |
390 | { | |
6f68f70f JT |
391 | PlaceDialog (false); |
392 | ||
7cc4d95e | 393 | if (source == IDC_SOURCE_LOCALDIR) |
0f0a6b63 MB |
394 | return IDD_LOCAL_DIR; |
395 | else | |
6f68f70f | 396 | return IDD_SITE; |
0f0a6b63 MB |
397 | } |
398 | ||
399 | void | |
400 | ChooserPage::keepClicked() | |
401 | { | |
d78ce5e2 | 402 | update_mode_id = IDC_CHOOSE_KEEP; |
0f0a6b63 | 403 | packagedb db; |
9ca5efb3 | 404 | db.noChanges(); |
bb8e2353 | 405 | chooser->refresh(); |
0f0a6b63 MB |
406 | } |
407 | ||
0f0a6b63 | 408 | void |
a59178eb | 409 | ChooserPage::changeTrust(int button, bool test, bool initial) |
0f0a6b63 | 410 | { |
67ce5bee | 411 | SetBusy (); |
d78ce5e2 JT |
412 | |
413 | update_mode_id = button; | |
414 | ||
415 | SolverSolution::updateMode mode; | |
416 | switch (button) | |
417 | { | |
418 | default: | |
419 | case IDC_CHOOSE_KEEP: | |
420 | mode = SolverSolution::keep; | |
421 | break; | |
422 | ||
423 | case IDC_CHOOSE_BEST: | |
424 | mode = SolverSolution::updateBest; | |
425 | break; | |
426 | ||
427 | case IDC_CHOOSE_SYNC: | |
428 | mode = SolverSolution::updateForce; | |
429 | break; | |
430 | } | |
431 | ||
432 | packagedb db; | |
a59178eb JT |
433 | SolverTasks q; |
434 | ||
435 | // usually we want to apply the solver to an empty task list to get the list | |
436 | // of packages to upgrade (if any) | |
9ca5efb3 KB |
437 | // but initially we want a task list with any package changes caused by |
438 | // command line options | |
a59178eb | 439 | if (initial) |
9ca5efb3 KB |
440 | q.setTasks(); |
441 | ||
a59178eb | 442 | db.defaultTrust(q, mode, test); |
d78ce5e2 JT |
443 | |
444 | // configure PickView so 'test' or 'curr' version is chosen when an | |
445 | // uninstalled package is first clicked on. | |
446 | chooser->defaultTrust (test ? TRUST_TEST : TRUST_CURR); | |
447 | ||
bb8e2353 | 448 | chooser->refresh(); |
d78ce5e2 JT |
449 | |
450 | PrereqChecker::setTestPackages(test); | |
67ce5bee | 451 | ClearBusy (); |
0f0a6b63 MB |
452 | } |
453 | ||
454 | bool | |
455 | ChooserPage::OnMessageCmd (int id, HWND hwndctl, UINT code) | |
456 | { | |
4f0fb3e4 | 457 | #if DEBUG |
ce9f6dd0 | 458 | Log (LOG_BABBLE) << "ChooserPage::OnMessageCmd " << id << " " << hwndctl << " " << std::hex << code << endLog; |
4f0fb3e4 JT |
459 | #endif |
460 | ||
a7c7dea6 | 461 | if (id == IDC_CHOOSE_SEARCH_EDIT) |
059906b3 | 462 | { |
a7c7dea6 KB |
463 | HWND nextButton = ::GetDlgItem(::GetParent(GetHWND()), 0x3024 /* ID_WIZNEXT */); |
464 | char buf[16]; | |
465 | ||
466 | if ((code == EN_CHANGE) || | |
467 | ((code == EN_SETFOCUS) && GetWindowText(GetDlgItem(IDC_CHOOSE_SEARCH_EDIT), buf, 15))) | |
468 | { | |
469 | // when focus arrives at this control and it has some text in it, or | |
470 | // when we change the text in it, change the default button to one | |
471 | // which immediately applies the search filter | |
472 | // | |
473 | // (we don't do this when the focus is on this control but it's empty | |
474 | // (the initial state of the dialog) so that enter in that state moves | |
475 | // onto the next page) | |
476 | SendMessage(GetHWND (), DM_SETDEFID, (WPARAM) IDC_CHOOSE_DO_SEARCH, 0); | |
477 | SendMessage(nextButton, BM_SETSTYLE, BS_PUSHBUTTON, TRUE); | |
478 | } | |
479 | if (code == EN_CHANGE) | |
480 | { | |
481 | // apply the search filter when we stop typing | |
482 | SetTimer(GetHWND (), timer_id, SEARCH_TIMER_DELAY, (TIMERPROC) NULL); | |
483 | } | |
484 | else if (code == EN_KILLFOCUS) | |
485 | { | |
486 | // when focus leaves this control, restore the normal default button | |
487 | SendMessage(GetHWND (), DM_SETDEFID, (WPARAM) 0x3024 /* ID_WIZNEXT */, 0); | |
488 | SendMessage(nextButton, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE); | |
489 | } | |
059906b3 DK |
490 | return true; |
491 | } | |
4f0fb3e4 JT |
492 | else if (code == BN_CLICKED) |
493 | { | |
0f0a6b63 MB |
494 | switch (id) |
495 | { | |
18d74072 CV |
496 | case IDC_CHOOSE_CLEAR_SEARCH: |
497 | { | |
1c1913d1 RR |
498 | std::string value; |
499 | eset (GetHWND (), IDC_CHOOSE_SEARCH_EDIT, value); | |
0632357a | 500 | KillTimer (GetHWND (), timer_id); |
1c1913d1 RR |
501 | chooser->SetPackageFilter (value); |
502 | chooser->refresh (); | |
18d74072 CV |
503 | } |
504 | break; | |
505 | ||
a7c7dea6 KB |
506 | case IDC_CHOOSE_DO_SEARCH: |
507 | // invisible pushbutton which is the default pushbutton while typing into | |
508 | // the search textbox, so that 'enter' causes the filter to be applied | |
509 | // immediately, rather than activating the next page | |
510 | SendMessage(GetHWND (), WM_TIMER, (WPARAM) timer_id, 0); | |
511 | break; | |
512 | ||
0f0a6b63 | 513 | case IDC_CHOOSE_KEEP: |
97b50ad7 MB |
514 | if (IsButtonChecked (id)) |
515 | keepClicked(); | |
516 | break; | |
ca2b7505 | 517 | |
d78ce5e2 | 518 | case IDC_CHOOSE_BEST: |
97b50ad7 | 519 | if (IsButtonChecked (id)) |
a59178eb | 520 | changeTrust (id, IsButtonChecked(IDC_CHOOSE_EXP), false); |
97b50ad7 | 521 | break; |
ca2b7505 | 522 | |
d78ce5e2 | 523 | case IDC_CHOOSE_SYNC: |
97b50ad7 | 524 | if (IsButtonChecked (id)) |
a59178eb | 525 | changeTrust (id, IsButtonChecked(IDC_CHOOSE_EXP), false); |
d78ce5e2 JT |
526 | break; |
527 | ||
528 | case IDC_CHOOSE_EXP: | |
a59178eb | 529 | changeTrust(update_mode_id, IsButtonChecked (id), false); |
97b50ad7 MB |
530 | break; |
531 | ||
82306ac2 BD |
532 | case IDC_CHOOSE_HIDE: |
533 | chooser->setObsolete (!IsButtonChecked (id)); | |
534 | break; | |
0f0a6b63 MB |
535 | default: |
536 | // Wasn't recognized or handled. | |
537 | return false; | |
538 | } | |
539 | ||
540 | // Was handled since we never got to default above. | |
541 | return true; | |
4f0fb3e4 JT |
542 | } |
543 | else if (code == CBN_SELCHANGE) | |
544 | { | |
545 | if (id == IDC_CHOOSE_VIEW) | |
546 | { | |
547 | // switch to the selected view | |
548 | LRESULT view_mode = SendMessage (GetDlgItem (IDC_CHOOSE_VIEW), | |
549 | CB_GETCURSEL, 0, 0); | |
550 | if (view_mode != CB_ERR) | |
551 | chooser->setViewMode ((PickView::views)view_mode); | |
552 | ||
553 | return true; | |
554 | } | |
555 | } | |
556 | ||
557 | // We don't care. | |
558 | return false; | |
0f0a6b63 | 559 | } |
82306ac2 | 560 | |
ce9f6dd0 JT |
561 | bool |
562 | ChooserPage::OnNotify (NMHDR *pNmHdr, LRESULT *pResult) | |
82306ac2 | 563 | { |
ce9f6dd0 JT |
564 | #if DEBUG |
565 | Log (LOG_BABBLE) << "ChooserPage::OnNotify id:" << pNmHdr->idFrom << " hwnd:" << pNmHdr->hwndFrom << " code:" << (int)pNmHdr->code << endLog; | |
566 | #endif | |
567 | ||
568 | // offer messages to the listview | |
569 | if (listview->OnNotify(pNmHdr, pResult)) | |
570 | return true; | |
571 | ||
572 | // we don't care | |
573 | return false; | |
82306ac2 | 574 | } |
1c1913d1 RR |
575 | |
576 | INT_PTR CALLBACK | |
577 | ChooserPage::OnTimerMessage (UINT message, WPARAM wParam, LPARAM lparam) | |
578 | { | |
579 | if (wParam == timer_id) | |
580 | { | |
581 | std::string value (egetString (GetHWND (), IDC_CHOOSE_SEARCH_EDIT)); | |
582 | ||
583 | KillTimer (GetHWND (), timer_id); | |
584 | chooser->SetPackageFilter (value); | |
585 | chooser->refresh (); | |
586 | return TRUE; | |
587 | } | |
588 | ||
589 | return FALSE; | |
590 | } |