Subversion Repositories filter_foundry

Rev

Rev 114 | Rev 131 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.     This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
  3.     Copyright (C) 2003-7 Toby Thain, toby@telegraphics.com.au
  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.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */
  19.  
  20. /* Win32 user interface routines */
  21.  
  22. #include "world.h"
  23.  
  24. #include "PIAbout.h"
  25.  
  26. #include <windows.h>
  27. #include <commctrl.h>
  28.  
  29. #include "ff.h"
  30.  
  31. #include "version.h"
  32.  
  33. HWND preview_hwnd;
  34. HCURSOR hCurHandOpen;
  35. HCURSOR hCurHandGrab;
  36. HCURSOR hCurHandQuestion;
  37.  
  38. extern HANDLE hDllInstance;
  39.  
  40. void DoAbout(AboutRecordPtr pb){
  41.         char s[0x200];
  42.         int n;
  43.         PlatformData *p = (PlatformData*)pb->platformData;
  44.  
  45.         n = sprintf(s, "Filter Foundry " VERSION_STR "\n"
  46.                                    "(C) 2003-9 Toby Thain <toby@telegraphics.com.au>\n\n");
  47.         if(gdata && gdata->standalone)
  48.                 sprintf(s+n, "Standalone filter:\n%s by %s.\n%s",
  49.                         INPLACEP2CSTR(gdata->parm.title),
  50.                         INPLACEP2CSTR(gdata->parm.author),
  51.                         INPLACEP2CSTR(gdata->parm.copyright));
  52.         else
  53.                 strcat(s,
  54. "Latest version available from http://www.telegraphics.com.au/sw/\n\
  55. Please contact the author with any bug reports, suggestions or comments.\n\
  56. If you use this program and like it, please consider making a donation\n\
  57. through www.paypal.com (US$5 suggested) to the address above.");
  58.         MessageBox((HWND)p->hwnd, s, "About Filter Foundry", MB_APPLMODAL|MB_ICONINFORMATION|MB_OK);
  59. }
  60.  
  61. Boolean simplealert(char *s){
  62.         return MessageBox(NULL,s,"Filter Foundry",MB_APPLMODAL|MB_ICONERROR|MB_OK) == IDOK;
  63. }
  64.  
  65. INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
  66.  
  67. INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam){
  68.         static POINT origpos;
  69.         static Point origscroll;
  70.         static Boolean panning = false;
  71.  
  72.         int item,i;
  73.         POINT newpos;
  74.         DRAWITEMSTRUCT *pdi;
  75.         Point newscroll;
  76.         HFONT hfnt;
  77.         char s[0x100];
  78.  
  79.         extern Boolean doupdates;
  80.         extern Handle preview_handle;
  81.  
  82.         switch(wMsg){
  83.         case WM_INITDIALOG:
  84.                 gdata->hWndMainDlg = hDlg;
  85.  
  86.                 if(gdata->standalone){
  87.                         myp2cstrcpy(s,gdata->parm.title);
  88.                         SetWindowText(hDlg,s); // window title bar
  89.                 }
  90.                 centre_window(hDlg);
  91.  
  92.                 // see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/fontext_3pbo.asp
  93.                 hfnt = GetStockObject(ANSI_FIXED_FONT);
  94.  
  95.                 hCurHandOpen = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_OPEN));
  96.                 hCurHandGrab = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_GRAB));
  97.                 hCurHandQuestion = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_QUESTION));
  98.  
  99.                 preview_hwnd = GetDlgItem(hDlg, PREVIEWITEM);
  100.                 GetClientRect(preview_hwnd, &preview_rect);
  101.                 SetClassLongPtr(preview_hwnd, GCLP_HCURSOR, (LONG_PTR)hCurHandOpen);
  102.  
  103.                 SetClassLongPtr(GetDlgItem(hDlg, FIRSTICONITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandQuestion);
  104.  
  105.                 for(i = 0; i < 8; ++i){
  106.                         SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETRANGE,TRUE,MAKELONG(0,255));
  107.                         SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETTICFREQ,SLIDERPAGE,0);
  108.                         SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETPAGESIZE,0,SLIDERPAGE);
  109.                         SendDlgItemMessage(hDlg,FIRSTCTLTEXTITEM+i,     EM_SETLIMITTEXT,3,0);
  110.                 }
  111.                 for(i = 0; i < 4; ++i){
  112.                         SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        EM_SETLIMITTEXT,MAXEXPR-1,0); // we need 1 byte as NUL terminator, so our formula can be max 1023
  113.                         SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        WM_SETFONT,(WPARAM)hfnt,false);
  114.                 }
  115.  
  116.                 maindlginit(hDlg);
  117.                 break;
  118.         case WM_DESTROY:
  119.                 gdata->hWndMainDlg = 0;
  120.                 DestroyCursor(hCurHandOpen);
  121.                 DestroyCursor(hCurHandGrab);
  122.                 DestroyCursor(hCurHandQuestion);
  123.                 break;
  124.         case WM_DRAWITEM:
  125.                 pdi = (DRAWITEMSTRUCT*)lParam;
  126.                 if(pdi->itemAction == ODA_DRAWENTIRE){
  127.                         switch(pdi->CtlID){
  128.                         case PREVIEWITEM:
  129.                                 drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false));
  130.                                 PIUNLOCKHANDLE(preview_handle);
  131.                                 break;
  132.                         default:
  133.                                 return false;
  134.                         }
  135.                 }else
  136.                         return false; // we couldn't handle the message
  137.                 break;
  138.         case WM_COMMAND:
  139.                 item = LOWORD(wParam);
  140.                 switch(HIWORD(wParam)){
  141.                 case BN_CLICKED: //case STN_CLICKED:
  142.                         if(item==PREVIEWITEM && GetCursorPos(&origpos)){
  143.                                 panning = true;
  144.                                 origscroll = preview_scroll;
  145.                                 SetCursor(hCurHandGrab);
  146.                                 SetCapture(hDlg);
  147.                                 break;
  148.                         }
  149.                 case EN_CHANGE:
  150.                         if(doupdates && !maindlgitem(hDlg,item))
  151.                                 EndDialog(hDlg,item);
  152.                 }
  153.                 break;
  154. //      case WM_LBUTTONDOWN: break;
  155.         case WM_MOUSEMOVE:
  156.                 if(panning && GetCursorPos(&newpos)){
  157.                         newscroll.h = origscroll.h - zoomfactor*(newpos.x - origpos.x);
  158.                         newscroll.v = origscroll.v - zoomfactor*(newpos.y - origpos.y);
  159.                         if( newscroll.h != preview_scroll.h || newscroll.v != preview_scroll.v ){
  160.                                 preview_scroll = newscroll;
  161.                                 recalc_preview(gpb,hDlg);
  162.                         }
  163.                 }
  164.                 break;
  165.         case WM_LBUTTONUP:
  166.                 ReleaseCapture();
  167.                 panning = false;
  168.                 break;
  169.         case WM_HSCROLL:
  170.                 item = GetDlgCtrlID((HWND)lParam);
  171.                 if(doupdates && item>=FIRSTCTLITEM && item<=FIRSTCTLITEM+7)
  172.                         slidermoved(hDlg,item);
  173.                 break;
  174.         default:
  175.                 return false;
  176.         }
  177.  
  178.         return true;
  179. }
  180.  
  181. Boolean maindialog(FilterRecordPtr pb){
  182.         PlatformData *p;
  183.         WNDCLASSEX clx;
  184.  
  185.         // For the preview image, we register a class, so that we can assign a mouse cursor to this class.
  186.         clx.cbSize = sizeof(WNDCLASSEX);
  187.         GetClassInfoEx(hDllInstance, "Static", &clx);
  188.         clx.lpszClassName = "Preview";
  189.         RegisterClassEx(&clx);
  190.  
  191.         // For the caution images, we register a class, so that we can assign a mouse cursor to this class.
  192.         clx.cbSize = sizeof(WNDCLASSEX);
  193.         GetClassInfoEx(hDllInstance, "Static", &clx);
  194.         clx.lpszClassName = "CautionSign";
  195.         RegisterClassEx(&clx);
  196.  
  197.         // Now show the dialog
  198.         p = pb->platformData;
  199.         INT_PTR res = DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG),
  200.                                      (HWND)p->hwnd,maindlgproc,0) == IDOK;
  201.  
  202.         UnregisterClass("Preview", hDllInstance);
  203.         UnregisterClass("CautionSign", hDllInstance);
  204.  
  205.         return res;
  206. }
  207.  
  208.