ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/VTBFileUtil2/ScanUtility.cxx
(Generate patch)

Comparing trunk/VTBFileUtil2/ScanUtility.cxx (file contents):
Revision 271 by douglas, 2003-08-19T22:49:34-07:00 vs.
Revision 273 by douglas, 2003-08-20T23:29:24-07:00

# Line 2 | Line 2
2   //
3   // Douglas Thrift
4   //
5 < // $Id: ScanUtility.cxx,v 1.5 2003/08/20 05:49:34 douglas Exp $
5 > // $Id: ScanUtility.cxx,v 1.6 2003/08/21 06:29:24 douglas Exp $
6  
7   #include "ScanUtility.h"
8  
# Line 27 | Line 27 | ScanUtility::ScanUtility()
27          wizard[0].lParam = number;
28          wizard[0].pszHeaderTitle = "Start";
29          wizard[0].pszHeaderSubTitle = "Change any settings before scanning.";
30 +
31 +        // select
32 +        wizard[1].dwSize = sizeof(wizard[1]);
33 +        wizard[1].dwFlags = PSP_DEFAULT | PSP_USEHICON | PSP_USETITLE |
34 +                PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
35 +        wizard[1].hInstance = gui.instance;
36 +        wizard[1].pszTemplate = MAKEINTRESOURCE(IDD_SELECT);
37 +        wizard[1].hIcon = gui.icon;
38 +        wizard[1].pszTitle = title;
39 +        wizard[1].pfnDlgProc = select;
40 +        wizard[1].lParam = number;
41 +        wizard[1].pszHeaderTitle = "Select";
42 +        wizard[1].pszHeaderSubTitle = "Choose the scanned document to save.";
43   }
44  
45   ScanUtility::~ScanUtility()
# Line 48 | Line 61 | void ScanUtility::run(void)
61          header.hwndParent = NULL;
62          header.hInstance = gui.instance;
63          header.pszIcon = MAKEINTRESOURCE(IDI_VTB_ICON);
64 <        header.nPages = 1;
64 >        header.nPages = 2;
65          header.nStartPage = 0;
66          header.ppsp = wizard;
67          header.pszbmHeader = MAKEINTRESOURCE(IDB_VTB_BMP);
# Line 80 | Line 93 | void ScanUtility::loadDirs(void)
93                          switch (type)
94                          {
95                          case REG_EXPAND_SZ:
96 <                                scanDir = data;
97 <                                scanEnv = true;
96 >                                {
97 >                                        char folder[MAX_PATH];
98 >
99 >                                        ExpandEnvironmentStrings(data, folder, MAX_PATH);
100 >
101 >                                        scanDir = folder;
102 >                                }
103                                  break;
104                          case REG_SZ:
105                                  scanDir = data;
88                                scanEnv = false;
106                                  break;
107                          default:
108                                  setScanDir();
# Line 107 | Line 124 | void ScanUtility::loadDirs(void)
124                          switch (type)
125                          {
126                          case REG_EXPAND_SZ:
127 <                                saveDir = data;
128 <                                saveEnv = true;
127 >                                {
128 >                                        char folder[MAX_PATH];
129 >
130 >                                        ExpandEnvironmentStrings(data, folder, MAX_PATH);
131 >
132 >                                        saveDir = folder;
133 >                                }
134                                  break;
135                          case REG_SZ:
136                                  saveDir = data;
115                                saveEnv = false;
137                                  break;
138                          default:
139                                  setSaveDir();
# Line 133 | Line 154 | void ScanUtility::loadDirs(void)
154          }
155  
156          if (debug) cerr << "scanDir = " << scanDir << "\n"
157 <                << "scanEnv = " << scanEnv << "\n"
137 <                << "saveDir = " << saveDir << "\n"
138 <                << "saveEnv = " << saveEnv << "\n";
157 >                << "saveDir = " << saveDir << "\n";
158   }
159  
160   void ScanUtility::saveDirs(void)
# Line 161 | Line 180 | void ScanUtility::saveDirs(void)
180                          data[0] = '\0';
181                  }
182  
183 <                if (scanDir != data || type != (scanEnv ? REG_EXPAND_SZ : REG_SZ))
183 >                if (scanDir != data || type != REG_SZ)
184                  {
185 <                        if (RegSetValueEx(key, "ScanDir", 0, scanEnv ? REG_EXPAND_SZ :
186 <                                REG_SZ, LPBYTE(scanDir.c_str()), scanDir.length() + 1) !=
185 >                        if (RegSetValueEx(key, "ScanDir", 0, REG_SZ,
186 >                                LPBYTE(scanDir.c_str()), scanDir.length() + 1) !=
187                                  ERROR_SUCCESS)
188                          {
189                                  error();
# Line 183 | Line 202 | void ScanUtility::saveDirs(void)
202                          data[0] = '\0';
203                  }
204  
205 <                if (saveDir != data || type != (saveEnv ? REG_EXPAND_SZ : REG_SZ))
205 >                if (saveDir != data || type != REG_SZ)
206                  {
207 <                        if (RegSetValueEx(key, "SaveDir", 0, saveEnv ? REG_EXPAND_SZ :
208 <                                REG_SZ, LPBYTE(saveDir.c_str()), saveDir.length() + 1) !=
207 >                        if (RegSetValueEx(key, "SaveDir", 0, REG_SZ,
208 >                                LPBYTE(saveDir.c_str()), saveDir.length() + 1) !=
209                                  ERROR_SUCCESS)
210                          {
211                                  error();
# Line 225 | Line 244 | void ScanUtility::setScanDir(HWND parent
244                          if (SHGetPathFromIDList(id, folder))
245                          {
246                                  scanDir = folder;
228                                scanEnv = false;
247                          }
248                  }
249  
# Line 255 | Line 273 | void ScanUtility::setScanDir(HWND parent
273                  }
274          }
275          while (scanDir == "");
276 +
277 +        if (debug) cerr << "scanDir = " << scanDir << "\n";
278   }
279  
280   void ScanUtility::setSaveDir(HWND parent)
# Line 281 | Line 301 | void ScanUtility::setSaveDir(HWND parent
301                          if (SHGetPathFromIDList(id, folder))
302                          {
303                                  saveDir = folder;
284                                saveEnv = false;
304                          }
305                  }
306  
# Line 311 | Line 330 | void ScanUtility::setSaveDir(HWND parent
330                  }
331          }
332          while (saveDir == "");
333 +
334 +        if (debug) cerr << "saveDir = " << saveDir << "\n";
335 + }
336 +
337 + void ScanUtility::populate(HWND parent)
338 + {
339 +        set<string> scans;
340 +
341 +        do
342 +        {
343 +                string scan = scanDir + "\\SCAN????_000." +
344 +                        IndividualClient::getExtension();
345 +                WIN32_FIND_DATA found;
346 +                HANDLE finder = FindFirstFile(scan.c_str(), &found);
347 +
348 +                if (finder != INVALID_HANDLE_VALUE)
349 +                {
350 +                        do
351 +                        {
352 +                                scans.insert(found.cFileName);
353 +                        }
354 +                        while (FindNextFile(finder, &found));
355 +
356 +                        FindClose(finder);
357 +                }
358 +
359 +                if (scans.empty())
360 +                {
361 +                        if (MessageBox(parent, "No scanned documents found.",
362 +                                programName.c_str(), MB_RETRYCANCEL | MB_ICONQUESTION) ==
363 +                                IDCANCEL) break;
364 +                }
365 +        }
366 +        while (scans.empty());
367 +
368 +        if (scans.empty())
369 +        {
370 +                PropSheet_PressButton(GetParent(parent), PSBTN_BACK);
371 +        }
372 +        else
373 +        {
374 +                SHFILEINFO info;
375 +                HIMAGELIST icons = HIMAGELIST(SHGetFileInfo((*scans.begin()).c_str(),
376 +                        0, &info, sizeof(info), SHGFI_SMALLICON | SHGFI_SYSICONINDEX));
377 +
378 +                ListView_SetImageList(GetDlgItem(parent, IDC_SELECT_SCANS), icons,
379 +                        LVSIL_SMALL);
380 +
381 +                int index = 0;
382 +
383 +                if (debug) cerr << "scans = {\n";
384 +
385 +                for (set<string>::iterator itor = scans.begin(); itor != scans.end();
386 +                        itor++)
387 +                {
388 +                        if (debug) cerr << "   " << *itor << "\n";
389 +
390 +                        char scan[MAX_PATH];
391 +
392 +                        sprintf(scan, "%s", (*itor).c_str());
393 +
394 +                        LVITEM item;
395 +
396 +                        item.mask = LVIF_IMAGE | LVIF_TEXT;
397 +                        item.iItem = index++;
398 +                        item.iSubItem = 0;
399 +                        item.state = LVIS_SELECTED;
400 +                        item.stateMask = LVIS_SELECTED;
401 +                        item.pszText = scan;
402 +                        item.iImage = info.iIcon;
403 +
404 +                        ListView_InsertItem(GetDlgItem(parent, IDC_SELECT_SCANS), &item);
405 +                }
406 +
407 +                if (debug) cerr << "}\n";
408 +        }
409   }
410  
411   int ScanUtility::browse(HWND dialog, UINT msg, LPARAM l, LPARAM d)
# Line 325 | Line 420 | int ScanUtility::browse(HWND dialog, UIN
420                  SendMessage(dialog, BFFM_SETOKTEXT, 0,
421                          LPARAM(toWide("&Select").c_str()));
422                  SendMessage(dialog, BFFM_SETEXPANDED, FALSE, CSIDL_DRIVES);
423 <                if (HIWORD(d) ? data->scanEnv : data->saveEnv)
424 <                {
330 <                        char folder[MAX_PATH];
331 <
332 <                        ExpandEnvironmentStrings(HIWORD(d) ? data->scanDir.c_str() :
333 <                                data->saveDir.c_str(), folder, MAX_PATH);
334 <                        SendMessage(dialog, BFFM_SETSELECTION, TRUE, LPARAM(folder));
335 <                }
336 <                else
337 <                {
338 <                        SendMessage(dialog, BFFM_SETSELECTION, TRUE, LPARAM(HIWORD(d) ?
339 <                                data->scanDir.c_str() : data->saveDir.c_str()));
340 <                }
423 >                SendMessage(dialog, BFFM_SETSELECTION, TRUE, LPARAM(HIWORD(d) ?
424 >                        data->scanDir.c_str() : data->saveDir.c_str()));
425                  break;
426          case BFFM_SELCHANGED:
427                  {
# Line 383 | Line 467 | INT_PTR ScanUtility::start(HWND dialog,
467  
468                          windows.insert(pair<HWND, ScanUtility*>(dialog, itor->second));
469                  }
470 +                {
471 +                        ostringstream instructions;
472 +
473 +                        instructions << "1.\tIf you need instructions, you should not be r"
474 +                                << "unning this program\n\tin Scan Utility mode.\n"
475 +                                << "2.\tOtherwise, go forth and scan.\n"
476 +                                << "3.\tThen come back and click Next.\n";
477 +
478 +                        SetDlgItemText(dialog, IDC_START_INSTRUCTIONS,
479 +                                instructions.str().c_str());
480 +                }
481                  break;
482          case WM_NOTIFY:
483                  {
484 <                        LPNMHDR nm = (LPNMHDR) l;
484 >                        LPNMHDR nm = LPNMHDR(l);
485  
486                          switch (nm->code)
487                          {
# Line 401 | Line 496 | INT_PTR ScanUtility::start(HWND dialog,
496                                          SetDlgItemText(dialog, IDC_START_SAVE_TEXT, folder);
497                                  }
498                                  break;
499 +                        case PSN_WIZNEXT:
500 +                                SetCurrentDirectory(data->scanDir.c_str());
501 +                                break;
502                          }
503                  }
504                  break;
# Line 429 | Line 527 | INT_PTR ScanUtility::start(HWND dialog,
527                  break;
528          }
529  
530 +        return FALSE;
531 + }
532 +
533 + INT_PTR ScanUtility::select(HWND dialog, UINT msg, WPARAM w, LPARAM l)
534 + {
535 +        map<HWND, ScanUtility*>::iterator itor = windows.find(dialog);
536 +        ScanUtility* data = itor->second;
537 +
538 +        switch (msg)
539 +        {
540 +        case WM_INITDIALOG:
541 +                {
542 +                        LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l);
543 +                        map<unsigned, ScanUtility*>::iterator itor =
544 +                                utilities.find(page->lParam);
545 +
546 +                        windows.insert(pair<HWND, ScanUtility*>(dialog, itor->second));
547 +                }
548 +                {
549 +                        LVCOLUMN column;
550 +
551 +                        column.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
552 +                        column.fmt = LVCFMT_IMAGE;
553 +                        column.cx = 120;
554 +                        column.pszText = "Scanned Documents";
555 +
556 +                        ListView_InsertColumn(GetDlgItem(dialog, IDC_SELECT_SCANS), 0,
557 +                                &column);
558 +                }
559 +                break;
560 +        case WM_NOTIFY:
561 +                if (w == IDC_SELECT_SCANS)
562 +                {
563 +                        switch (ListView_GetSelectedCount(GetDlgItem(dialog,
564 +                                IDC_SELECT_SCANS)))
565 +                        {
566 +                        case 1:
567 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
568 +                                        PSWIZB_NEXT);
569 +                                break;
570 +                        default:
571 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK);
572 +                                break;
573 +                        }
574 +                }
575 +                else
576 +                {
577 +                        LPNMHDR nm = LPNMHDR(l);
578 +
579 +                        switch (nm->code)
580 +                        {
581 +                        case PSN_SETACTIVE:
582 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK);
583 +                                data->populate(dialog);
584 +                                break;
585 +                        case PSN_WIZBACK:
586 +                                ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
587 +                                break;
588 +                        case PSN_WIZNEXT:
589 +                                //
590 +                                ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
591 +                                break;
592 +                        }
593 +                }
594 +                break;
595 +        case WM_COMMAND:
596 +                break;
597 +        }
598 +
599          return FALSE;
600   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines