/* This file is part of icobundle Copyright (C) 2003-7 Toby Thain, toby@telegraphics.com.au This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include // paramtext #include // kHighLevelEvent #include #include // StripAddress #include #include // SysBeep #include #include #include #include #include #include #include #include #include // OpenDeskAcc #include #include "ae.h" #include "dlg.h" #include "misc-mac.h" #include "qd.h" #include "wind.h" #include "choosefile.h" #include "bundle.h" #include "str.h" #include "carbonstuff.h" #define DBG dbg_alert enum{APPLE_MENU=1,FILE_MENU}; enum{QUIT_ITEM=1}; Boolean run; StandardFileReply sfreply; Str255 origname; AE_HANDLER(my_open_doc); //RoutineDescriptor ae_quit_rd = BUILD_ROUTINE_DESCRIPTOR(uppAEEventHandlerProcInfo, handle_quit_app); struct AE_handler handlers[]={ {kCoreEventClass,kAEOpenApplication,&handle_open_app}, {kCoreEventClass,kAEOpenDocuments,my_open_doc}, // {kCoreEventClass,kAEPrintDocuments,handle_print_doc}, {kCoreEventClass,kAEQuitApplication,&handle_quit_app}, 0 }; OSErr open_app(void){ run = false; return noErr; } int iconcount; FSSpec *iconfiles; NavReplyRecord navreply; AE_HANDLER(my_open_doc){ AEDescList docList; long i,n; AEKeyword theAEKeyword; DescType typeCode; FSSpec *fss; Size actualSize; OSErr e; FILEREF outfile; if(!(e = AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,&docList))){ if( !(e = got_required_params(theAppleEvent)) && !(e = AECountItems(&docList,&n)) && (iconfiles = (FSSpec*) NewPtr(n*sizeof(FSSpec))) ){ for( fss=iconfiles,iconcount=0,i=1 ; i<=n ; ++i ) if( !(e = AEGetNthPtr(&docList,i,typeFSS,&theAEKeyword, &typeCode,(Ptr)fss,sizeof(FSSpec),&actualSize)) ){ //DebugStr(fss->name); ++iconcount; ++fss; } } AEDisposeDesc(&docList); } if(!e && iconcount && putfile("\pBundle icons into file:","\picons.ico",'ICO ','8BIM',&navreply,&sfreply,"ICO",NULL,0) ){ FSpCreate(&sfreply.sfFile,'8BIM','ICO ',sfreply.sfScript); if(!(e = FSpOpenDF(&sfreply.sfFile,fsWrPerm,&outfile))){ SetEOF(outfile,0); bundle(iconcount,outfile); FSClose(outfile); completesave(&navreply); } } run = false; return e; } FILEREF opennth(int i){ FILEREF r; return FSpOpenDF(&iconfiles[i-1],fsRdPerm,&r) ? 0 : r; } void bad(char *msg){ Str255 s; myc2pstrcpy(s,msg); ParamText(s,0,0,0); CautionAlert(256,0); } void note(char *msg){ Str255 s; myc2pstrcpy(s,msg); ParamText(s,0,0,0); NoteAlert(256,0); } /* OSErr open_doc(FSSpec *fss){ } OSErr print_doc(FSSpec *fss){ } */ OSErr quit_app(void){ run = false; return noErr; } static void do_menu(long r){ short i = r; Str255 s; switch(r>>16){ case APPLE_MENU: #if !TARGET_CARBON GetMenuItemText(GetMenuHandle(APPLE_MENU), i, s); OpenDeskAcc(s); #endif break; case FILE_MENU: switch(i){ case QUIT_ITEM: quit_app(); break; } break; } HiliteMenu(0); } static OSErr maineventloop(){ EventRecord e; WindowPtr w; Boolean f; BitMap sb; for(run = true; run;){ if(f = WaitNextEvent(everyEvent, &e, -1, 0)) switch(e.what){ case mouseDown: switch(FindWindow(e.where, &w)){ case inMenuBar: do_menu(MenuSelect(e.where)); break; // inSysWindow = 2, case inContent: if(w != FrontWindow()) SelectWindow(w); break; case inDrag: GetQDGlobalsScreenBits(&sb); DragWindow(w, e.where, &sb.bounds); break; // inGrow = 5, case inGoAway: if(TrackGoAway(w, e.where)) quit_app(); break; // inZoomIn = 7, // inZoomOut = 8 } break; case keyDown: if(e.modifiers & cmdKey) do_menu(MenuKey(e.message)); break; case updateEvt: SetPortWindowPort(w); BeginUpdate(w); EndUpdate(w); break; case kHighLevelEvent: AEProcessAppleEvent(&e); } //if(!e.what) // ; /* null event */ } return noErr; } void main(){ init_toolbox(); init_AE(handlers); SetMenuBar(GetNewMBar(128)); #if !TARGET_CARBON AppendResMenu(GetMenuHandle(APPLE_MENU), 'DRVR'); #endif DrawMenuBar(); maineventloop(); }