Subversion Repositories filter_foundry

Rev

Rev 268 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.     This file is part of a common library for Adobe(R) plugins
  3.     Copyright (C) 2002-2010 Toby Thain, toby@telegraphics.net
  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. /* Mac user interface routines */
  21.  
  22. #ifndef __x86_64__
  23.  
  24. #include <string.h>
  25. #include <stdlib.h>
  26.  
  27. #include <NumberFormatting.h>
  28. #include <controls.h>
  29. #include <controldefinitions.h>
  30.  
  31. #include "world.h"
  32. #include "ui_compat.h"
  33. #include "sprintf_tiny.h"
  34.  
  35. /*      #define DLGVARS \
  36.                 short itemType;\
  37.                 Handle itemHdl;\
  38.                 Rect itemRect;\
  39.                 Str255 itemStr;\
  40.                 long itemNum;*/
  41.  
  42. Handle get_item_handle(DIALOGREF d,int i){
  43.         short itemType;
  44.         Handle itemHdl;
  45.         Rect itemRect;
  46.  
  47.         GetDialogItem(d,i,&itemType,&itemHdl,&itemRect);
  48.         return itemHdl;
  49. }
  50.  
  51. long GetDlgItemText(DIALOGREF d,int i,char *s,long n){
  52.         Str255 itemStr;
  53.         long maxlen;
  54.  
  55.         --n;
  56.         GetDialogItemText(get_item_handle(d,i),itemStr);
  57.         maxlen = *itemStr > n ? n : *itemStr;
  58.         memcpy(s,itemStr+1,maxlen);
  59.         s[maxlen] = 0;
  60.         return maxlen;
  61. }
  62.  
  63. long SetDlgItemText(DIALOGREF d,int i,char *s){
  64.         Str255 itemStr;
  65.         long maxlen = strlen(s);
  66.  
  67.         if(maxlen>255) maxlen = 255;
  68.         memcpy(itemStr+1,s,maxlen);
  69.         *itemStr = maxlen;
  70.         SetDialogItemText(get_item_handle(d,i),itemStr);
  71.         return true;
  72. }
  73.  
  74. void SetDlgControlValue(DIALOGREF d,int i,int v){
  75.         ControlRef c;
  76.  
  77.         GetDialogItemAsControl(d,i,&c);
  78.         SetControlValue(c,v);
  79. }
  80.  
  81. int GetDlgControlValue(DIALOGREF d,int i){
  82.         ControlRef c;
  83.  
  84.         GetDialogItemAsControl(d,i,&c);
  85.         return GetControlValue(c);
  86. }
  87.  
  88. void EnableDlgControl(DIALOGREF d,int i){
  89.         ControlRef c;
  90.  
  91.         GetDialogItemAsControl(d,i,&c);
  92.         HiliteControl(c,0);
  93. }
  94. void DisableDlgControl(DIALOGREF d,int i){
  95.         ControlRef c;
  96.  
  97.         GetDialogItemAsControl(d,i,&c);
  98.         HiliteControl(c,255);
  99. }
  100. Boolean SetDlgItemInt(DIALOGREF d,int i,long v,Boolean bsigned){
  101.         Str255 s;
  102.  
  103.         NumToString(v,s);
  104.         SetDialogItemText(get_item_handle(d,i),s);
  105.         return true;
  106. }
  107. long GetDlgItemInt(DIALOGREF d,int i,Boolean *presult,Boolean bsigned){
  108.         Str255 s;
  109.         long v;
  110.  
  111.         GetDialogItemText(get_item_handle(d,i),s);
  112.         StringToNum(s,&v);
  113.         if(presult) *presult = true;
  114.         return v;
  115. }
  116.  
  117. Boolean newbitmap(BITMAPREF *pb, int depth, Rect *bounds){
  118.         OSErr e;
  119.  
  120.         if( ( *pb = (BITMAPREF)malloc(sizeof(**pb)) )
  121.                 && !(e = NewGWorld(&(*pb)->gw, depth, bounds, nil, nil, 0)) )
  122.         {
  123.                 (*pb)->pm = GetGWorldPixMap((*pb)->gw);
  124.                 return true;
  125.         }
  126.         return false;
  127. }
  128.  
  129. void disposebitmap(BITMAPREF pb){
  130.         if(pb){
  131.                 DisposeGWorld(pb->gw);
  132.                 free((char*)pb);
  133.         }
  134. }
  135.  
  136. //pascal Boolean aboutfilter(DialogRef dialog, EventRecord *event, DialogItemIndex *item){
  137. pascal Boolean aboutfilter(DialogRef dialog, EventRecord *event, short *item){
  138.         Boolean result = false;
  139.  
  140.         ENTERCALLBACK(); // not strictly needed; we don't use globals here
  141.  
  142.         if( event->what == mouseDown
  143.          || event->what == keyDown
  144.          || event->what == autoKey ){
  145.                 *item = ok;
  146.                 result = true;
  147.         }
  148.  
  149.         EXITCALLBACK();
  150.  
  151.         return(result);
  152. }
  153. pascal Boolean standardfilter(DialogRef dialog, EventRecord *event, short *item){
  154.         Boolean result = false;
  155.         char ch = event->message;
  156.  
  157.         ENTERCALLBACK(); // not strictly needed; we don't use globals here
  158.  
  159.         if( event->what == keyDown ){
  160.                 if(ch == kEnterCharCode){
  161.                         *item = ok;
  162.                         result = true;
  163.                 }else if( ch == kEscapeCharCode || (ch=='.' && (event->modifiers & cmdKey)) ){
  164.                         *item = cancel;
  165.                         result = true;
  166.                 }
  167.         }
  168.  
  169.         EXITCALLBACK();
  170.  
  171.         return(result);
  172. }
  173.  
  174. #if !TARGET_CARBON
  175. OSStatus my_InvalWindowRect(WindowRef window,const Rect *bounds){
  176.         GrafPtr port;
  177.  
  178.         GetPort(&port);
  179.         SetPort(window);
  180.         InvalRect(bounds);
  181.         SetPort(port);
  182.         return noErr;
  183. }
  184. #endif
  185.  
  186. //kControlEditTextPart,kControlEntireControl
  187. long getctltext(DIALOGREF d,int i,char *s,long n){
  188.         ControlRef c;// = (ControlRef)get_item_handle(d,i);
  189.         Size actual,len;
  190.  
  191.         if( !( GetDialogItemAsControl(d,i,&c)
  192.                         || GetControlDataSize(c,kControlEditTextPart,kControlEditTextTextTag,&actual) ) ){
  193.                 --n;
  194.                 len = n < actual ? n : actual;
  195.                 if(!GetControlData(c,kControlEditTextPart,kControlEditTextTextTag,len,s,&actual)){
  196.                         s[len] = 0;
  197.                         return len;
  198.                 }
  199.         }
  200.         dbg("getctltext failed");
  201.         return 0;
  202. }
  203.  
  204. long setctltext(DIALOGREF d,int i,char *s){
  205.         ControlRef c;// = (ControlRef)get_item_handle(d,i);
  206.  
  207.         Boolean res = !( GetDialogItemAsControl(d,i,&c)
  208.                 || SetControlData(c,kControlEditTextPart,kControlEditTextTextTag,strlen(s),s) );
  209.         if(res) Draw1Control(c);
  210.         else dbg("setctltext failed");
  211.         return res;
  212. }
  213.  
  214. long selectctltext(DIALOGREF d,int i,int start,int end){
  215.         ControlRef c;
  216.         ControlEditTextSelectionRec srec;
  217.  
  218.         srec.selStart = start;
  219.         srec.selEnd = end;
  220.  
  221.         return !( GetDialogItemAsControl(d,i,&c)
  222.                 || SetControlData(c,kControlEditTextPart,kControlEditTextSelectionTag,sizeof(srec),&srec) );
  223. }
  224. Boolean setctltextint(DIALOGREF d,int i,long v,Boolean bsigned){
  225.         ControlRef c;
  226.         Str255 s;
  227.  
  228.         NumToString(v,s);
  229.         if( !GetDialogItemAsControl(d,i,&c) )
  230.                 SetControlData(c,kControlEditTextPart,kControlEditTextTextTag,*s,s+1);
  231.         Draw1Control(c);
  232.         return true;
  233. }
  234. long getctltextint(DIALOGREF d,int i,Boolean *presult,Boolean bsigned){
  235.         ControlRef c;
  236.         Str255 s;
  237.         long num;
  238.         Size actual;
  239.  
  240.         if( !(GetDialogItemAsControl(d,i,&c)
  241.                         ||GetControlDataSize(c,kControlEditTextPart,kControlEditTextTextTag,&actual)
  242.                         ||GetControlData(c,kControlEditTextPart,kControlEditTextTextTag,actual,s+1,&actual)) ){
  243.                 *s = actual;
  244.                 StringToNum(s,&num);
  245.                 if(presult) *presult = true;
  246.                 return num;
  247.         }
  248.         if(presult) *presult = false;
  249.         return 0;
  250. }
  251.  
  252. void menuaddcstr(CTLREF c,char *s){
  253.         Str255 pstr;
  254.         MenuRef menu = GetControlPopupMenuHandle(c);
  255.  
  256.         myc2pstrcpy(pstr,s);
  257.  
  258.         /* doing it this way intentionally defeats meta-character processing in AppendMenu;
  259.            see: http://developer.apple.com/qa/tb/tb56.html */
  260.  
  261.         AppendMenu(menu,(StringPtr)"\001X"); // Pascal string literal, normally "\pX", done like this for non-Apple compilers (mingw?)
  262.         SetMenuItemText(menu,CountMenuItems(menu),pstr);
  263. }
  264.  
  265. #endif
  266.