Subversion Repositories filter_foundry

Rev

Rev 18 | 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-5 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. #include <controls.h>
  21. #include <controldefinitions.h>
  22. #include <dialogs.h>
  23. #include <resources.h>
  24. #include <textutils.h>
  25.  
  26. #include "str.h"
  27.  
  28. #include "ff.h"
  29.  
  30. extern PSPixelMap preview_pmap;
  31. extern PSPixelMask preview_pmask;
  32. extern Handle preview_handle;
  33. extern UIRECT preview_rect;
  34. extern int preview_w,preview_h;
  35.  
  36. extern Point preview_scroll;
  37.  
  38. CursHandle handcursor,ibeamcursor;
  39. ControlActionUPP action_UPP,indaction_UPP;
  40. DIALOGREF thedialog;
  41. ControlRef exprctls[4];
  42. int trackingitem;
  43. extern double zoomfactor;
  44.  
  45. pascal void preview_item(DialogRef dp,DialogItemIndex item);
  46. pascal void slideraction(ControlRef theControl,short partCode);
  47. pascal Boolean sliderfilter(DialogRef dialog,EventRecord *event,short *item);
  48.  
  49. void DoAbout(AboutRecordPtr prec){
  50.         PARM_T p;
  51.         char *reason;
  52.         Handle h = Get1Resource(PARM_TYPE,PARM_ID);
  53.         ModalFilterUPP filterproc_UPP = NewModalFilterUPP(aboutfilter);
  54.  
  55.         if(h){
  56.                 HLock(h);
  57.                 readPARM(*h,&p,&reason);
  58.                 ParamText(p.title,p.author,p.copyright,NULL);
  59.         }
  60.         Alert(h ? ID_ABOUTSTANDALONEDLG : ID_ABOUTDLG,filterproc_UPP);
  61.         DisposeModalFilterUPP(filterproc_UPP);
  62.         if(h)
  63.                 ReleaseResource(h);
  64. }
  65.  
  66. Boolean simplealert(char *s){
  67.         int i;
  68.  
  69.         myc2pstr(s);
  70.         ParamText((StringPtr)s,NULL,NULL,NULL);
  71.         i = StopAlert(ID_SYNTAXALERT,NULL);
  72.         myp2cstr((StringPtr)s);
  73.         return i == ok;
  74. }
  75.  
  76. pascal void preview_item(DialogRef dp,DialogItemIndex item){
  77.         GrafPtr port;
  78.         extern int recalcpreview;
  79.        
  80.         ENTERCALLBACK();
  81.  
  82.         GetPort(&port);
  83.         SetPortDialogPort(dp);
  84.  
  85.         drawpreview(dp,0,PILOCKHANDLE(preview_handle,false));
  86.         PIUNLOCKHANDLE(preview_handle);
  87.  
  88.         FrameRect(&preview_rect);
  89.        
  90.         SetPort(port);
  91.  
  92.         EXITCALLBACK();
  93. }
  94.  
  95. /*
  96.     NOTE ON CONTROL ACTION PROCS
  97.  
  98.     When using the TrackControl() call when tracking an indicator, the actionProc parameter
  99.     (type ControlActionUPP) should be replaced by a parameter of type DragGrayRgnUPP
  100.     (see Quickdraw.h).
  101.  
  102.     If, however, you are using the live feedback variants of scroll bars or sliders, you
  103.     must pass a ControlActionUPP in when tracking the indicator as well. This functionality
  104.     is available in Appearance 1.0 or later.
  105. */
  106.  
  107. pascal void slideraction(ControlRef theControl,short partCode){
  108.         int old,delta; // [] = {-10,10,-143,143};
  109.  
  110.         ENTERCALLBACK();
  111.  
  112.         if(partCode){
  113.                 if(partCode != kControlIndicatorPart){
  114.                         switch(partCode){
  115.                         case kControlUpButtonPart:   delta = -1; break;
  116.                         case kControlDownButtonPart: delta = 1; break;
  117.                         case kControlPageUpPart:     delta = -SLIDERPAGE; break;
  118.                         case kControlPageDownPart:   delta = SLIDERPAGE; break;
  119.                         }
  120.                         SetControlValue(theControl,(old = GetControlValue(theControl)) + delta);
  121.                 }
  122.                 slidermoved(thedialog,trackingitem);
  123.                 recalc_preview(gpb,thedialog);
  124.         }
  125.  
  126.         EXITCALLBACK();
  127. }
  128.  
  129. pascal Boolean sliderfilter(DialogRef dialog,EventRecord *event,short *item){  
  130.         int i;
  131.         short part;
  132.         ControlHandle c;
  133.         Point pt,origscroll,newscroll;
  134.         Boolean result = false,f;
  135.         EventRecord ev;
  136.         GrafPtr oldport;
  137.         ControlRef focus;
  138.  
  139.         ENTERCALLBACK();
  140.  
  141.         GetPort(&oldport);
  142.         SetPortDialogPort(dialog);
  143.  
  144. /* !(result = standardfilter(dialog,event,item)) && */
  145.  
  146.         if(!event->what)
  147.                 gpb->processEvent(event); // pass null events to Photoshop
  148.        
  149.         if(event->what == updateEvt && (WindowRef)event->message != GetDialogWindow(dialog)){
  150.                 // pass Photoshop update events for its windows
  151.                 gpb->processEvent(event);
  152.                 result = false;
  153.         }else if( event->what == mouseDown ){
  154.  
  155.                 pt = event->where;
  156.                 GlobalToLocal(&pt);
  157.        
  158.                 i = trackingitem = FindDialogItem(dialog,pt)+1;
  159. /*                      if( (c = FindControlUnderMouse(pt,GetDialogWindow(dialog),&part))
  160.                                         && part && HandleControlClick(c,pt,event->modifiers,action_UPP) )*/
  161.                 if( i>=FIRSTCTLITEM && i<=FIRSTCTLITEM+7
  162.                                 && (part = FindControl(pt,GetDialogWindow(dialog),&c))
  163.                                 && TrackControl(c,pt,action_UPP) ){
  164.                         *item = i;
  165.                         result = true;
  166.                 }else if(i == PREVIEWITEM){
  167.                         SetCursor(*handcursor);
  168.                         origscroll = preview_scroll;
  169.                         do{
  170.                                 f = WaitNextEvent(mUpMask,&ev,5,NULL);
  171.                                 newscroll.h = origscroll.h - zoomfactor*(ev.where.h - event->where.h);
  172.                                 newscroll.v = origscroll.v - zoomfactor*(ev.where.v - event->where.v);
  173.                                 if(!EqualPt(newscroll,preview_scroll)){
  174.                                         preview_scroll = newscroll;
  175.                                         recalc_preview(gpb,dialog);
  176.                                 }
  177.                         }while(!f);
  178.  
  179.                         *item = i;
  180.                         result = true;
  181.                 }
  182.                
  183.         }else{
  184.                 GetKeyboardFocus(GetDialogWindow(dialog),&focus);
  185.                 /* handle return keypresses */
  186.                 if( event->what == keyDown && (char)event->message == CR
  187.                                 && ( focus==exprctls[0] || focus==exprctls[1]
  188.                                   || focus==exprctls[2] || focus==exprctls[3] ) )
  189.                         result = false;
  190.                 else
  191.                         result = StdFilterProc(dialog,event,item);
  192.         }
  193.                
  194.         SetPort(oldport);
  195.  
  196.         EXITCALLBACK();
  197.  
  198.         return(result);
  199. }
  200.  
  201. Boolean maindialog(FilterRecordPtr pb){
  202.         short itemType;
  203.         Handle itemHdl;
  204.         short item;
  205.         DIALOGREF dp;
  206.         int i;
  207.         UserItemUPP preview_image_UPP = NewUserItemUPP(preview_item);
  208.         ModalFilterUPP sliderfilter_UPP = NewModalFilterUPP(sliderfilter);
  209.  
  210.         action_UPP = NewControlActionUPP(slideraction);
  211.  
  212.         dp = thedialog = GetNewDialog(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG,nil,(WindowPtr)-1);
  213.  
  214.         if(gdata->standalone)
  215.                 SetWTitle(GetDialogWindow(dp),gdata->parm.title);
  216.  
  217.         GetDialogItem(dp,PREVIEWITEM,&itemType,&itemHdl,&preview_rect);
  218.         SetDialogItem(dp,PREVIEWITEM,itemType,(Handle)preview_image_UPP,&preview_rect);
  219.         handcursor = GetCursor(ID_HANDCURSOR);
  220.         ibeamcursor = GetCursor(iBeamCursor);
  221.        
  222.         SetDialogDefaultItem(dp,ok);
  223.         SetDialogCancelItem(dp,cancel);
  224.         SetDialogTracksCursor(dp,true);
  225.        
  226.         if(!gdata->standalone)
  227.                 for(i=0;i<4;++i)
  228.                         GetDialogItemAsControl(dp,FIRSTEXPRITEM+i,&exprctls[i]);
  229.  
  230.         maindlginit(dp);
  231.         do{
  232.                 InitCursor();
  233.                 ModalDialog(sliderfilter_UPP,&item);
  234.         }while(maindlgitem(dp,item));
  235.  
  236.         DisposeDialog(dp);
  237.        
  238.         DisposeUserItemUPP(preview_image_UPP);
  239.         DisposeModalFilterUPP(sliderfilter_UPP);
  240.         DisposeControlActionUPP(action_UPP);
  241.        
  242.         return item == ok;
  243. }
  244.  
  245. Boolean builddialog(FilterRecordPtr pb){
  246.         short item;
  247.         DIALOGREF dp;
  248.  
  249.         dp = thedialog = GetNewDialog(ID_BUILDDLG,nil,(WindowPtr)-1);
  250.                
  251.         SetDialogDefaultItem(dp,ok);
  252.         SetDialogCancelItem(dp,cancel);
  253.  
  254.         builddlginit(dp);
  255.         do{
  256.                 ModalDialog(NULL,&item);
  257.         }while(builddlgitem(dp,item));
  258.  
  259.         DisposeDialog(dp);
  260.        
  261.         return item == ok;
  262. }
  263.