1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* The contents of this file are subject to the Netscape Public License
3
* Version 1.1 (the "License"); you may not use this file except in
4
* compliance with the License. You may obtain a copy of the License at
5
* http://www.mozilla.org/NPL/
7
* Software distributed under the License is distributed on an "AS IS" basis,
8
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
9
* for the specific language governing rights and limitations under the
12
* The Original Code is Mozilla Communicator client code, released March
15
* The Initial Developer of the Original Code is Netscape Communications
16
* Corporation. Portions created by Netscape are Copyright (C) 1999
17
* Netscape Communications Corporation. All Rights Reserved.
20
* Samir Gehani <sgehani@netscape.com>
28
#include <AppleEvents.h>
32
#include "nsEventHandler.h"
33
#include "nsAppleSingleEncoder.h"
34
#include "nsAppleSingleDecoder.h"
35
#include "MoreFilesExtras.h"
44
SetCompletionStatus(false);
46
OSErr err = NavLoad();
48
FatalError(navLoadErr);
59
nsASEApp::InitManagers(void)
62
MoreMasters(); MoreMasters(); MoreMasters();
64
InitGraf(&qd.thePort);
72
FlushEvents(everyEvent, 0);
76
#pragma mark *** Apple Event Handlers ***
80
EncodeEvent(AppleEvent *appEvent, AppleEvent *reply, SInt32 handlerRefCon)
84
Boolean result = false, isDir = false;
88
// extract FSSpec from params
89
err = AEGetParamDesc(appEvent, keyDirectObject, typeFSS, &fileDesc);
92
BlockMoveData(*fileDesc.dataHandle, ¶m, sizeof(FSSpec));
95
err = nsASEApp::GotRequiredParams(appEvent);
99
FSpGetDirectoryID(¶m, &dummy, &isDir);
101
// if folder recursively traverse and encode contents
104
nsAppleSingleEncoder encoder;
105
err = encoder.EncodeFolder(¶m);
109
// it's a file not a folder so proceed as usual
111
// check if given file has res fork (takes care of existence check)
112
if (nsAppleSingleEncoder::HasResourceFork(¶m))
115
nsAppleSingleEncoder encoder;
116
err = encoder.Encode(¶m);
123
// then set result to true
129
AEPutParamPtr(reply, keyDirectObject, typeBoolean, &result, sizeof(result));
131
// boolean takes care of failures
136
DecodeEvent(AppleEvent *appEvent, AppleEvent *reply, SInt32 handlerRefCon)
139
FSSpec param, outFile;
140
Boolean result = false, isDir = false;
144
// extract FSSpec from params
145
err = AEGetParamDesc(appEvent, keyDirectObject, typeFSS, &fileDesc);
148
BlockMoveData(*fileDesc.dataHandle, ¶m, sizeof(FSSpec));
151
err = nsASEApp::GotRequiredParams(appEvent);
155
FSpGetDirectoryID(¶m, &dummy, &isDir);
157
// if folder recursively traverse and encode contents
160
nsAppleSingleDecoder decoder;
161
err = decoder.DecodeFolder(¶m);
165
// it's a file not a folder so proceed as usual
167
// check if given file is in AS format (takes care of existence check)
168
if (nsAppleSingleDecoder::IsAppleSingleFile(¶m))
171
nsAppleSingleDecoder decoder;
172
err = decoder.Decode(¶m, &outFile);
179
// then set result to true
185
AEPutParamPtr(reply, keyDirectObject, typeBoolean, &result, sizeof(result));
187
// boolean takes care of failures
192
QuitEvent(AppleEvent *appEvent, AppleEvent *reply, SInt32 handlerRefCon)
196
nsASEApp::SetCompletionStatus(true);
204
nsASEApp::InitAEHandlers()
208
mEncodeUPP = NewAEEventHandlerProc((ProcPtr) EncodeEvent);
209
err = AEInstallEventHandler(kASEncoderEventClass, kAEEncode,
210
mEncodeUPP, 0L, false);
212
::CautionAlert(aeInitErr, nil);
214
mDecodeUPP = NewAEEventHandlerProc((ProcPtr) DecodeEvent);
215
err = AEInstallEventHandler(kASEncoderEventClass, kAEDecode,
216
mDecodeUPP, 0L, false);
218
::CautionAlert(aeInitErr, nil);
220
mQuitUPP = NewAEEventHandlerProc((ProcPtr) QuitEvent);
221
err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
222
mQuitUPP, 0L, false);
224
::CautionAlert(aeInitErr, nil);
227
nsASEApp::GotRequiredParams(AppleEvent *appEvent)
230
DescType returnedType;
233
err = AEGetAttributePtr(appEvent, keyMissedKeywordAttr, typeWildCard,
234
&returnedType, NULL, 0, &actualSize);
236
if (err == errAEDescNotFound)
238
else if (err == noErr)
239
err = errAEParamMissed;
245
nsASEApp::MakeMenus()
250
mbarHdl = ::GetNewMBar(rMenuBar);
251
::SetMenuBar(mbarHdl);
253
if ((menuHdl = ::GetMenuHandle(rMenuApple))!=nil)
255
::AppendResMenu(menuHdl, 'DRVR');
258
if ((menuHdl = GetMenuHandle(rMenuEdit))!=nil)
259
::DisableItem(menuHdl, 0);
261
::HMGetHelpMenuHandle(&menuHdl);
262
::DisableItem(menuHdl, 0);
268
nsASEApp::SetCompletionStatus(Boolean aVal)
274
nsASEApp::GetCompletionStatus()
282
nsASEApp::FatalError(short aErrID)
284
::StopAlert(aErrID, nil);
285
SetCompletionStatus(true);
293
nsEventHandler handler;
297
if (::WaitNextEvent(everyEvent, &evt, 180, NULL))
299
handler.HandleNextEvent(&evt);