Subversion Repositories filter_foundry

Rev

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