home *** CD-ROM | disk | FTP | other *** search
/ swCHIP 1991 January / swCHIP_95-1.bin / utility / gsview13 / src / gvwdlg.c < prev    next >
C/C++ Source or Header  |  1995-12-09  |  21KB  |  704 lines

  1. /* Copyright (C) 1993, 1994, Russell Lang.  All rights reserved.
  2.   
  3.   This file is part of GSview.
  4.   
  5.   This program is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the GSview Free Public Licence 
  9.   (the "Licence") for full details.
  10.   
  11.   Every copy of GSview must include a copy of the Licence, normally in a 
  12.   plain ASCII text file named LICENCE.  The Licence grants you the right 
  13.   to copy, modify and redistribute GSview, but only under certain conditions 
  14.   described in the Licence.  Among other things, the Licence requires that 
  15.   the copyright notice and this notice be preserved on all copies.
  16. */
  17.  
  18. /* gvwdlg.c */
  19. /* Dialog boxes for Windows GSview */
  20. #include "gvwin.h"
  21.  
  22. BOOL
  23. get_filename(char *filename, BOOL save, int filter, int title, int help)
  24. {
  25. LPSTR old_lpstrFile;
  26. LPCSTR old_lpstrTitle;
  27. char szTitle[MAXSTR];
  28. BOOL flag;
  29. LPCSTR old_lpstrFilter;
  30. char szFilter[256];        /* filter for OFN */
  31. int i;
  32. char cReplace;
  33.     if (help)
  34.         LoadString(phInstance, help, szHelpTopic, sizeof(szHelpTopic));
  35.     old_lpstrTitle = ofn.lpstrTitle;
  36.     if (title) {
  37.         LoadString(phInstance, title, szTitle, sizeof(szTitle));
  38.         ofn.lpstrTitle = (LPCSTR)szTitle;
  39.     }
  40.     old_lpstrFile = ofn.lpstrFile;
  41.     if (filename != (LPSTR)NULL)
  42.         ofn.lpstrFile = filename;
  43.     /* Get filter types */
  44.     old_lpstrFilter = ofn.lpstrFilter;
  45.     ofn.nFilterIndex = 0;
  46.     if (LoadString(phInstance, IDS_FILTER_BASE+filter, szFilter, sizeof(szFilter)-1)) {
  47.         cReplace = szFilter[strlen(szFilter)-1];
  48.         for (i=0; szFilter[i] != '\0'; i++)
  49.             if (szFilter[i] == cReplace)
  50.             szFilter[i] = '\0';
  51.         ofn.lpstrFilter = szFilter;
  52.         ofn.nFilterIndex = 0;
  53.     }
  54.     /* call the common dialog box */
  55.     if (save)
  56.         flag = GetSaveFileName(&ofn);
  57.     else
  58.         flag = GetOpenFileName(&ofn);
  59.     ofn.lpstrTitle = old_lpstrTitle;
  60.     ofn.lpstrFile = old_lpstrFile;
  61.     ofn.lpstrFilter = old_lpstrFilter;
  62.     ofn.nFilterIndex = 0;
  63.     if ( save && flag && 
  64.             (psfile.name[0]!='\0') && (lstrcmp(filename, psfile.name) == 0) ) {
  65.         gserror(IDS_NOTDFNAME, NULL, MB_ICONEXCLAMATION, SOUND_ERROR);
  66.         flag = FALSE;
  67.     }
  68. #if defined(__WIN32__)
  69.     /* GetOpenFileName() should change current directory */
  70.     /* Deal with broken Win32 that doesn't do this */
  71.     if (flag) {
  72.         char *p;
  73.         char temp[MAXSTR];
  74.         strcpy(temp, filename);
  75.         p = strrchr(temp, '\\');
  76.         if (p == NULL) {
  77.         if (strlen(temp) > 2) {
  78.             if (isalpha(temp[0]) && (temp[1]==':')) {
  79.             temp[2] = '\0';
  80.             _chdir(temp);
  81.             }
  82.         }
  83.         }
  84.         else {
  85.         *p = '\0';
  86.         _chdir(temp);
  87.         }
  88.     }
  89. #endif
  90.     return flag;
  91. }
  92.  
  93. /* Input Dialog Box structures */
  94. LPSTR input_prop = "input_prop";
  95. struct input_param {
  96.     LPSTR prompt;
  97.     LPSTR answer;
  98. };
  99.  
  100.  
  101. /* input string dialog box */
  102. BOOL CALLBACK _export
  103. InputDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  104. {
  105.     switch(message) {
  106.         case WM_INITDIALOG:
  107.         {
  108.           HLOCAL hlocal;
  109.           LPSTR *panswer;
  110.           struct input_param *pparam = (struct input_param *)lParam;
  111.           SetDlgItemText(hDlg, ID_PROMPT, pparam->prompt);
  112.           SetDlgItemText(hDlg, ID_ANSWER, pparam->answer);
  113.           /* save address of answer string in property list */
  114.           hlocal = LocalAlloc(LHND, sizeof(pparam->answer));
  115.           panswer = (LPSTR *)LocalLock(hlocal);
  116.           if (panswer != (LPSTR *)NULL) {
  117.             *panswer = pparam->answer;
  118.         LocalUnlock(hlocal);
  119.             SetProp(hDlg, input_prop, (HANDLE)hlocal);
  120.           }
  121.         }
  122.             return( TRUE);
  123.         case WM_COMMAND:
  124.             switch(LOWORD(wParam)) {
  125.         case ID_HELP:
  126.             SendMessage(hwndimg, help_message, 0, 0L);
  127.             return(FALSE);
  128.                 case ID_ANSWER:
  129.                     return(TRUE);
  130.         case IDOK:
  131.             {
  132.               HLOCAL hlocal = (HLOCAL)GetProp(hDlg, input_prop); 
  133.               LPSTR *panswer;
  134.                   panswer = (LPSTR *)LocalLock(hlocal);
  135.                   if (panswer != (LPSTR *)NULL) {
  136.                 GetDlgItemText(hDlg, ID_ANSWER, *panswer, MAXSTR);
  137.             LocalUnlock(hlocal);
  138.               }
  139.               LocalFree(hlocal);
  140.               RemoveProp(hDlg, input_prop);
  141.             }
  142.                     EndDialog(hDlg, TRUE);
  143.                     return(TRUE);
  144.                 case IDCANCEL:
  145.             {
  146.               HLOCAL hlocal = (HLOCAL)GetProp(hDlg, input_prop); 
  147.               LocalFree(hlocal);
  148.               RemoveProp(hDlg, input_prop);
  149.             }
  150.                     EndDialog(hDlg, FALSE);
  151.                     return(TRUE);
  152.                 default:
  153.                     return(FALSE);
  154.             }
  155.         default:
  156.             return(FALSE);
  157.     }
  158. }
  159.  
  160. BOOL
  161. get_string(char *prompt, char *answer)
  162. {
  163. struct input_param param;
  164. BOOL flag;
  165. #ifndef __WIN32__
  166. DLGPROC lpProcInput;
  167. #endif
  168.     param.answer = answer;
  169.     param.prompt = prompt;
  170. #ifdef __WIN32__
  171.     flag = DialogBoxParam( phInstance, "InputDlgBox", hwndimg, InputDlgProc, (LPARAM)¶m);
  172. #else
  173.     lpProcInput = (DLGPROC)MakeProcInstance((FARPROC)InputDlgProc, phInstance);
  174.     flag = DialogBoxParam( phInstance, "InputDlgBox", hwndimg, lpProcInput, (LPARAM)¶m);
  175.     FreeProcInstance((FARPROC)lpProcInput);
  176. #endif
  177.     return flag;
  178. }
  179.  
  180.  
  181. /* copyright dialog box */
  182. BOOL CALLBACK _export
  183. AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  184. {
  185.     switch(message) {
  186.         case WM_INITDIALOG:
  187.             SetDlgItemText(hDlg, ABOUT_VERSION, GSVIEW_VERSION);
  188.             return( TRUE);
  189.     case WM_LBUTTONDBLCLK:
  190.         {DWORD dwUnit = GetDialogBaseUnits();
  191.         RECT rect; POINT pt;
  192.         pt.x = LOWORD(lParam); pt.y = HIWORD(lParam);
  193.         /* this is for 8pt dialog fonts */
  194.         rect.left   =   8 * LOWORD(dwUnit) / 5;
  195.         rect.top    = 146 * HIWORD(dwUnit) / 10;
  196.         rect.right  = 240 * LOWORD(dwUnit) / 5 + rect.left;
  197.         rect.bottom =  10 * HIWORD(dwUnit) / 10 + rect.top;
  198. #ifdef NOTUSED
  199.         /* this is for 10pt dialog fonts */
  200.         rect.left   =   8 * LOWORD(dwUnit) / 4;
  201.         rect.top    = 146 * HIWORD(dwUnit) / 8;
  202.         rect.right  = 240 * LOWORD(dwUnit) / 4 + rect.left;
  203.         rect.bottom =   8 * HIWORD(dwUnit) / 8 + rect.top;
  204. #endif
  205.  
  206.         if (PtInRect(&rect,pt)) {
  207.         BITMAP bm;
  208.         HBITMAP hbitmap_old;
  209.         HBITMAP hbitmap = LoadBitmap(phInstance,"gsview_bitmap");
  210.         HDC hdc = GetDC(hDlg);
  211.         HDC hdcsrc = CreateCompatibleDC(hdc);
  212.         hbitmap_old = SelectObject(hdcsrc,hbitmap);
  213.         GetObject(hbitmap, sizeof(BITMAP),&bm);
  214.         BitBlt(hdc, rect.right-bm.bmWidth,rect.bottom-bm.bmHeight,
  215.            bm.bmWidth,bm.bmHeight,hdcsrc,0,0,SRCCOPY);
  216.         SelectObject(hdcsrc,hbitmap_old);
  217.         DeleteObject(hbitmap);
  218.         DeleteDC(hdcsrc);
  219.         ReleaseDC(hDlg,hdc);
  220.         }
  221.         }
  222.         return FALSE;
  223.         case WM_COMMAND:
  224.             switch(LOWORD(wParam)) {
  225.                 case IDOK:
  226.                     EndDialog(hDlg, TRUE);
  227.                     return(TRUE);
  228.                 default:
  229.                     return(FALSE);
  230.             }
  231.         default:
  232.             return(FALSE);
  233.     }
  234. }
  235.  
  236. void
  237. show_about()
  238. {
  239. #ifdef __WIN32__
  240.     DialogBoxParam( phInstance, "AboutDlgBox", hwndimg, AboutDlgProc, (LPARAM)NULL);
  241. #else
  242.     DLGPROC lpProcAbout;
  243.     lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)AboutDlgProc, phInstance);
  244.     DialogBoxParam( phInstance, "AboutDlgBox", hwndimg, lpProcAbout, (LPARAM)NULL);
  245.     FreeProcInstance((FARPROC)lpProcAbout);
  246. #endif
  247. }
  248.  
  249. /* information about document dialog box */
  250. BOOL CALLBACK _export
  251. InfoDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  252. {
  253.     switch(message) {
  254.         case WM_INITDIALOG:
  255.         info_init(hDlg);
  256.             return( TRUE);
  257.     case WM_COMMAND:
  258.             switch(LOWORD(wParam)) {
  259.                 case IDOK:
  260.                     EndDialog(hDlg, TRUE);
  261.                     return(TRUE);
  262.                 case IDCANCEL:
  263.                     EndDialog(hDlg, FALSE);
  264.                     return(TRUE);
  265.                 default:
  266.                     return(FALSE);
  267.             }
  268.         default:
  269.             return(FALSE);
  270.     }
  271. }
  272.  
  273. /* show info about ps file */
  274. void
  275. show_info()
  276. {
  277. #ifdef __WIN32__
  278.     DialogBoxParam( phInstance, "InfoDlgBox", hwndimg, InfoDlgProc, (LPARAM)NULL);
  279. #else
  280.     DLGPROC lpProcInfo;
  281.     lpProcInfo = (DLGPROC)MakeProcInstance((FARPROC)InfoDlgProc, phInstance);
  282.     DialogBoxParam( phInstance, "InfoDlgBox", hwndimg, lpProcInfo, (LPARAM)NULL);
  283.     FreeProcInstance((FARPROC)lpProcInfo);
  284. #endif
  285. }
  286.  
  287.  
  288.  
  289. #define MAX_SYSTEM_SOUND 16
  290. char *system_sounds;
  291. char *sound_entry[MAX_SYSTEM_SOUND];
  292. char szNone[32];
  293. char szSpeaker[32];
  294. int system_num;
  295. BOOL CALLBACK _export SoundDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam);
  296.  
  297. int
  298. load_sounds(void)
  299. {
  300.     char *p;
  301.     int j;
  302.  
  303.     /* add our two sounds */
  304.     sound_entry[0] = "";
  305.     sound_entry[1] = BEEP;
  306.     LoadString(phInstance, IDS_NONE, szNone, sizeof(szNone));
  307.     LoadString(phInstance, IDS_SPKR, szSpeaker, sizeof(szSpeaker));
  308.     /* get list of system sounds */
  309.     system_sounds = malloc(PROFILE_SIZE);
  310.     if (system_sounds != (char *)NULL) {
  311.         GetProfileString("sounds", NULL, "", system_sounds, PROFILE_SIZE);
  312.     }
  313.     p = system_sounds;
  314.     for (j=2; p!=(char *)NULL && j<MAX_SYSTEM_SOUND && strlen(p)!=0; j++) {
  315.         /* Windows NT uses "Enable=1" in the sounds section */
  316.         /* We need to prevent this from appearing in the list of sounds */
  317.         if (strcmp(p, "Enable") == 0)
  318.         j--;
  319.         else
  320.             sound_entry[j] = p;    
  321.         p += strlen(p) + 1;
  322.     }
  323.     system_num = j;
  324.     return system_num;
  325. }
  326.  
  327. char *
  328. get_sound_entry(int index)
  329. {
  330.     return (sound_entry[index]);
  331. }
  332.  
  333. char *
  334. get_sound_name(int index)
  335. {
  336. static char buf[64];
  337. char *p;
  338.     if (index==0)
  339.         return szNone;
  340.     if (index==1)
  341.         return szSpeaker;
  342.         GetProfileString("sounds", sound_entry[index], ",", buf, sizeof(buf));
  343.         p = strchr(buf,',');
  344.         if (p != (char *)NULL)
  345.         return p+1;
  346.     return (char *)NULL;
  347. }
  348.  
  349. int 
  350. find_sound_name(char *entry)
  351. {
  352. int i;
  353.     for (i=0; i<system_num; i++) {
  354.         if (strcmp(entry, sound_entry[i])==0)
  355.             return i;
  356.     }
  357.     return -1;    /* no find */
  358. }
  359.  
  360. void
  361. add_sounds(HWND hDlg)
  362. {
  363. int ifile;
  364. char *p;
  365.     for (ifile=system_num-1; ifile>=0; ifile--) {
  366.         p = get_sound_name(ifile);
  367.         if (p != (char *)NULL)
  368.             SendDlgItemMessage(hDlg, SOUND_FILE, LB_INSERTSTRING, 0,
  369.                 (LPARAM)(LPSTR)p);
  370.     }
  371. }
  372.  
  373. void
  374. free_sounds(void)
  375. {
  376.     if (system_sounds != (char *)NULL)
  377.         free(system_sounds);
  378. }
  379.  
  380. void
  381. change_sounds(void)
  382. {
  383. #ifdef __WIN32__
  384.     LoadString(phInstance, IDS_TOPICSOUND, szHelpTopic, sizeof(szHelpTopic));
  385.     DialogBoxParam( phInstance, "SoundDlgBox", hwndimg, SoundDlgProc, (LPARAM)NULL);
  386. #else
  387.     DLGPROC lpProcSound;
  388.     LoadString(phInstance, IDS_TOPICSOUND, szHelpTopic, sizeof(szHelpTopic));
  389.     lpProcSound = (DLGPROC)MakeProcInstance((FARPROC)SoundDlgProc, phInstance);
  390.     DialogBoxParam( phInstance, "SoundDlgBox", hwndimg, lpProcSound, (LPARAM)NULL);
  391.     FreeProcInstance((FARPROC)lpProcSound);
  392. #endif
  393. }
  394.  
  395. BOOL CALLBACK _export
  396. SoundDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam)
  397. {
  398.     char buf[MAXSTR];
  399.     int ievent, ifile;
  400.     static struct sound_s dsound[NUMSOUND];    /* copy of sound[] */
  401.     WORD notify_message;
  402.     char *szWaveFilter = "*.wav";
  403.     static char szPath[MAXSTR];
  404.     static int file_start;
  405.     char *p;
  406.  
  407.     switch (wmsg) {
  408.         case WM_INITDIALOG:
  409.         file_start = load_sounds();
  410.         for (ievent=0; ievent<NUMSOUND; ievent++) {
  411.             strcpy(dsound[ievent].file, sound[ievent].file);
  412.             LoadString(phInstance, sound[ievent].title, buf, sizeof(buf));
  413.             SendDlgItemMessage(hDlg, SOUND_EVENT, LB_ADDSTRING, 0, 
  414.             (LPARAM)((LPSTR)buf));
  415.         }
  416.         ievent = 0;
  417.         SendDlgItemMessage(hDlg, SOUND_EVENT, LB_SETCURSEL, ievent, 0L);
  418.         /* force update of SOUND_FILE */
  419.         SendDlgNotification(hDlg, SOUND_EVENT, LBN_SELCHANGE);
  420.         return TRUE;
  421.         case WM_COMMAND:
  422.         notify_message = GetNotification(wParam,lParam);
  423.         switch (LOWORD(wParam)) {
  424.             case ID_HELP:
  425.                 SendMessage(hwndimg, help_message, 0, 0L);
  426.                 return(FALSE);
  427.             case SOUND_EVENT:
  428.             if (notify_message != LBN_SELCHANGE) {
  429.                 return FALSE;
  430.             }
  431.             ievent = (int)SendDlgItemMessage(hDlg, SOUND_EVENT, LB_GETCURSEL, 0, 0L);
  432.             if (ievent == LB_ERR) {
  433.                 EnableWindow(GetDlgItem(hDlg, SOUND_TEST), FALSE);
  434.                 return FALSE;
  435.             }
  436.             ifile = find_sound_name(dsound[ievent].file);
  437.             if (ifile >= 0) {
  438.                 strcpy(buf, get_sound_name(ifile));
  439.                 szPath[0] = '\0';
  440.                 EnableWindow(GetDlgItem(hDlg, SOUND_TEST), ifile!=0);
  441.             }
  442.             else {
  443.                 /* must be WAVE file */
  444.                 strcpy(szPath, dsound[ievent].file);
  445.                 p = strrchr(szPath, '\\');
  446.                 if (p != (char *)NULL) {
  447.                     strcpy(buf,++p);
  448.                     *p = '\0';
  449.                 }
  450.                 else {
  451.                     strcpy(buf, szPath);
  452.                 }
  453.                 EnableWindow(GetDlgItem(hDlg, SOUND_TEST), TRUE);
  454.             }
  455.             strcat(szPath, szWaveFilter);
  456.             DlgDirList(hDlg, szPath, SOUND_FILE, SOUND_PATH, DDL_DRIVES | DDL_DIRECTORY);
  457.             add_sounds(hDlg);
  458.             SendDlgItemMessage(hDlg, SOUND_FILE, LB_SELECTSTRING, file_start, (LPARAM)(LPSTR)buf);
  459.             return FALSE;
  460.             case SOUND_FILE:
  461.             if (notify_message == LBN_SELCHANGE) {
  462.                 ifile = (int)SendDlgItemMessage(hDlg, SOUND_FILE, LB_GETCURSEL, 0, 0L);
  463.                 SendDlgItemMessage(hDlg, SOUND_FILE, LB_GETTEXT, ifile, (LPARAM)(LPSTR)buf);
  464.                 ievent = (int)SendDlgItemMessage(hDlg, SOUND_EVENT, LB_GETCURSEL, 0, 0L);
  465.                 if (ifile >= file_start) {
  466.                 if (buf[0] == '[') { /* selected a directory */
  467.                     EnableWindow(GetDlgItem(hDlg, SOUND_TEST), FALSE);
  468.                     }
  469.                 else { /* selected a WAVE file */
  470.                             int i = GetDlgItemText(hDlg, SOUND_PATH, dsound[ievent].file, MAXSTR);
  471.                         if (dsound[ievent].file[i-1] != '\\')
  472.                             dsound[ievent].file[i++] = '\\';
  473.                             DlgDirSelectEx(hDlg, dsound[ievent].file + i, sizeof(dsound[ievent].file), SOUND_FILE);
  474.                     EnableWindow(GetDlgItem(hDlg, SOUND_TEST), TRUE);
  475.                 }
  476.                 }
  477.                 else {
  478.                 EnableWindow(GetDlgItem(hDlg, SOUND_TEST), ifile!=0);
  479.                 strcpy(dsound[ievent].file,get_sound_entry(ifile));
  480.                 }
  481.             }
  482.             if (notify_message == LBN_DBLCLK) {
  483.                 ifile = (int)SendDlgItemMessage(hDlg, SOUND_FILE, LB_GETCURSEL, 0, 0L);
  484.                 SendDlgItemMessage(hDlg, SOUND_FILE, LB_GETTEXT, ifile, (LPARAM)(LPSTR)buf);
  485.                 if (buf[0] == '[') {
  486.                         DlgDirSelectEx(hDlg, szPath, sizeof(szPath), SOUND_FILE);
  487.                     lstrcat(szPath, szWaveFilter);
  488.                         DlgDirList(hDlg, szPath, SOUND_FILE, SOUND_PATH, DDL_DRIVES | DDL_DIRECTORY);
  489.                 add_sounds(hDlg);
  490.                 }
  491.                 else {
  492.                 SendDlgNotification(hDlg, SOUND_TEST, BN_CLICKED);
  493.                 }
  494.             }
  495.             return FALSE;
  496.             case SOUND_TEST:
  497.             ievent = (int)SendDlgItemMessage(hDlg, SOUND_EVENT, LB_GETCURSEL, 0, 0L);
  498.             if (strlen(dsound[ievent].file)==0)
  499.                 return FALSE;
  500.             if (!is_win31 || (strcmp(dsound[ievent].file,BEEP)==0)) {
  501.                 MessageBeep(-1);
  502.                 return FALSE;
  503.             }
  504.             if (is_win31) {
  505.                 if (lpfnSndPlaySound != (FPSPS)NULL) 
  506.                         lpfnSndPlaySound(dsound[ievent].file, SND_SYNC);
  507.                 else
  508.                     MessageBeep(-1);
  509.                 return FALSE;
  510.             }
  511.             return FALSE;
  512.             case IDOK:
  513.             for (ievent=0; ievent<NUMSOUND; ievent++)
  514.                 strcpy(sound[ievent].file, dsound[ievent].file);
  515.             free_sounds();
  516.             EndDialog(hDlg, TRUE);
  517.             return TRUE;
  518.             case IDCANCEL:
  519.             free_sounds();
  520.             EndDialog(hDlg, FALSE);
  521.             return TRUE;
  522.         }
  523.         break;
  524.     }
  525.     return FALSE;
  526. }
  527.  
  528.  
  529. BOOL CALLBACK _export
  530. PageDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam)
  531. {
  532.     char buf[40];
  533.     int i;
  534.     WORD notify_message;
  535.     switch (wmsg) {
  536.         case WM_INITDIALOG:
  537.         if (page_list.multiple)
  538.             LoadString(phInstance, IDS_SELECTPAGES, buf, sizeof(buf));
  539.         else
  540.             LoadString(phInstance, IDS_SELECTPAGE, buf, sizeof(buf));
  541.         SetWindowText(hDlg, buf);
  542.         for (i=0; i<doc->numpages; i++) {
  543.             SendDlgItemMessage(hDlg, PAGE_LIST, LB_ADDSTRING, 0, 
  544.             (LPARAM)((LPSTR)doc->pages[map_page(i)].label));
  545.         }
  546.         SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETSEL, TRUE, MAKELPARAM(page_list.current,0));
  547.         SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETCURSEL, page_list.current, 0L);
  548.         if (!page_list.multiple) {
  549.             EnableWindow(GetDlgItem(hDlg, PAGE_ALL), FALSE);
  550.             EnableWindow(GetDlgItem(hDlg, PAGE_ODD), FALSE);
  551.             EnableWindow(GetDlgItem(hDlg, PAGE_EVEN), FALSE);
  552.         }
  553.         return TRUE;
  554.         case WM_COMMAND:
  555.         notify_message = GetNotification(wParam,lParam);
  556.         switch (LOWORD(wParam)) {
  557.             case PAGE_LIST:
  558.             if (notify_message == LBN_DBLCLK)
  559.                 PostMessage(hDlg, WM_COMMAND, IDOK, 0L);
  560.             return FALSE;
  561.             case PAGE_ALL:
  562.             SendDlgItemMessage(hDlg, PAGE_LIST, LB_SELITEMRANGE, TRUE, 
  563.                 MAKELPARAM(0,doc->numpages-1));
  564.             return FALSE;
  565.             case PAGE_ODD:
  566.             for (i=(int)SendDlgItemMessage(hDlg, PAGE_LIST, LB_GETCOUNT, 0, 0L)-1; i>=0; i--)
  567.                 SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETSEL, !(i&1), MAKELPARAM(i,0));
  568.             return FALSE;
  569.             case PAGE_EVEN:
  570.             for (i=(int)SendDlgItemMessage(hDlg, PAGE_LIST, LB_GETCOUNT, 0, 0L); i>=0; i--)
  571.                 SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETSEL, (i&1), MAKELPARAM(i,0));
  572.             SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETTOPINDEX, 0, 0L);
  573.             return FALSE;
  574.             case IDOK:
  575.             i = (int)SendDlgItemMessage(hDlg, PAGE_LIST, LB_GETCURSEL, 0, 0L);
  576.             page_list.current = (i == LB_ERR) ? -1 : i;
  577.             for (i=0; i<doc->numpages; i++) {
  578.               page_list.select[i] =
  579.                 (int)SendDlgItemMessage(hDlg, PAGE_LIST, LB_GETSEL, i, 0L);
  580.             }
  581.             EndDialog(hDlg, TRUE);
  582.             return TRUE;
  583.             case IDCANCEL:
  584.             EndDialog(hDlg, FALSE);
  585.             return TRUE;
  586.         }
  587.         break;
  588.     }
  589.     return FALSE;
  590. }
  591.  
  592. /* Get page number from dialog box and store in ppage */
  593. BOOL
  594. get_page(int *ppage, BOOL multiple)
  595. {
  596. #ifndef __WIN32__
  597. DLGPROC lpProcPage;
  598. #endif
  599. BOOL flag;
  600.     if (doc == (PSDOC *)NULL)
  601.         return FALSE;
  602.     if (doc->numpages == 0) {
  603.         gserror(IDS_NOPAGE, NULL, MB_ICONEXCLAMATION, SOUND_NONUMBER);
  604.         return FALSE;
  605.     }
  606.     page_list.current = *ppage - 1;
  607.     page_list.multiple = multiple;
  608.     if (page_list.select == (BOOL *)NULL)
  609.         return FALSE;
  610.     memset(page_list.select, 0, doc->numpages * sizeof(BOOL) );
  611. #ifdef __WIN32__
  612.     flag = DialogBoxParam( phInstance, "PageDlgBox", hwndimg, PageDlgProc, (LPARAM)NULL);
  613. #else
  614.     lpProcPage = (DLGPROC)MakeProcInstance((FARPROC)PageDlgProc, phInstance);
  615.     flag = DialogBoxParam( phInstance, "PageDlgBox", hwndimg, lpProcPage, (LPARAM)NULL);
  616.     FreeProcInstance((FARPROC)lpProcPage);
  617. #endif
  618.     if (flag && (page_list.current >= 0))
  619.         *ppage = page_list.current + 1;
  620.     return flag;
  621. }
  622.  
  623. BOOL CALLBACK _export
  624. BoundingBoxDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  625. {
  626. static int bboxindex;
  627. float x, y;
  628. char buf[MAXSTR];
  629.     switch(message) {
  630.     case WM_INITDIALOG:
  631.         bboxindex = 0;
  632.         LoadString(phInstance, IDS_BBPROMPT, buf, sizeof(buf));
  633.         SetDlgItemText(hDlg, BB_PROMPT, buf);
  634.         return TRUE;
  635.     case WM_COMMAND:
  636.         switch(LOWORD(wParam)) {
  637.         case BB_CLICK:
  638.             if (!get_cursorpos(&x, &y)) {
  639.             DestroyWindow(hDlg);
  640.             hDlgModeless = 0;
  641.             }
  642.             switch(bboxindex) {
  643.             case 0:
  644.                 bbox.llx = x;
  645.                 break;
  646.             case 1:
  647.                 bbox.lly = y;
  648.                 break;
  649.             case 2:
  650.                 bbox.urx = x;
  651.                 break;
  652.             case 3:
  653.                 bbox.ury = y;
  654.                 bbox.valid = TRUE;
  655.                 break;
  656.             }
  657.             bboxindex++;
  658.             if (bboxindex <= 3) {
  659.                     LoadString(phInstance, IDS_BBPROMPT+bboxindex, buf, sizeof(buf));
  660.                     SetDlgItemText(hDlg, BB_PROMPT, buf);
  661.             return FALSE;
  662.             }
  663.         case IDCANCEL:
  664.             DestroyWindow(hDlg);
  665.             hDlgModeless = 0;
  666.             return TRUE;
  667.         }
  668.     case WM_CLOSE:
  669.         DestroyWindow(hDlg);
  670.         hDlgModeless = 0;
  671.         return TRUE;
  672.     }
  673.     return FALSE;
  674. }
  675.  
  676. BOOL
  677. get_bbox(void)
  678. {
  679. #ifndef __WIN32__
  680. DLGPROC lpfnBoundingBoxProc;
  681. #endif
  682.     bbox.valid = FALSE;
  683.     bbox.llx = bbox.lly = bbox.urx = bbox.ury = 0;
  684.     if (!display.page) {
  685.         gserror(IDS_EPSNOBBOX, NULL, MB_ICONEXCLAMATION, SOUND_ERROR);
  686.         return FALSE;
  687.     }
  688. #ifdef __WIN32__
  689.     hDlgModeless = CreateDialogParam(phInstance, "BoundingBoxDlgBox", hwndimg, BoundingBoxDlgProc, (LPARAM)NULL);
  690. #else
  691.     lpfnBoundingBoxProc = (DLGPROC)MakeProcInstance((FARPROC)BoundingBoxDlgProc, phInstance);
  692.     hDlgModeless = CreateDialogParam(phInstance, "BoundingBoxDlgBox", hwndimg, lpfnBoundingBoxProc, (LPARAM)NULL);
  693. #endif
  694.     while (hDlgModeless) {
  695.         do_message();    /* wait for bounding box to be obtained */
  696.     }
  697. #ifndef __WIN32__
  698.     FreeProcInstance((FARPROC)lpfnBoundingBoxProc);
  699. #endif
  700.     return bbox.valid;
  701. }
  702.  
  703.  
  704.