Back to index

lightning-sunbird  0.9+nobinonly
nsEventHandler.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code, released
00016  * March 31, 1998.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Samir Gehani <sgehani@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039  
00040  
00041 #ifndef _NS_EVENTHANDLER_H_
00042        #include "nsEventHandler.h"
00043 #endif
00044 
00045 #include <LowMem.h>
00046 #include <ToolUtils.h>
00047 
00048 
00049 #include "nsASEApp.h"
00050 #include "nsFileSelector.h"
00051 #include "nsAppleSingleEncoder.h"
00052 #include "nsAppleSingleDecoder.h"
00053 
00054 nsEventHandler::nsEventHandler()
00055 {
00056 
00057 }
00058 
00059 nsEventHandler::~nsEventHandler()
00060 {
00061 
00062 }
00063 
00064 OSErr 
00065 nsEventHandler::HandleNextEvent(EventRecord *aEvt) 
00066 { 
00067        OSErr err = noErr;
00068               
00069        mCurrEvent = aEvt;
00070        
00071        switch(aEvt->what)
00072        {
00073               case kHighLevelEvent:
00074                      err = AEProcessAppleEvent(aEvt);
00075                      if (err != errAEEventNotHandled)
00076                             break;
00077                             
00078               case mouseDown:
00079                      err = HandleMouseDown();
00080                      break;
00081                      
00082               case mouseUp:
00083                      break;
00084 
00085               case autoKey:
00086               case keyDown:
00087                      err = HandleKeyDown();
00088                      break;
00089                      
00090               case updateEvt:
00091                      err = HandleUpdateEvt();
00092                      break;
00093                      
00094               case activateEvt:
00095                      err = HandleActivateEvt();
00096                      break;
00097                      
00098               case osEvt:
00099                      err = HandleOSEvt();
00100                      break;
00101               
00102               case nullEvent:
00103                      break;
00104                      
00105               default:
00106                      break;
00107        }
00108        
00109        return err;
00110 }
00111 
00112 OSErr 
00113 nsEventHandler::HandleMouseDown() 
00114 { 
00115        OSErr                       err = noErr;
00116        WindowPtr                   currWindow;
00117        SInt16                      cntlPartCode;
00118        SInt32                      menuChoice;
00119        
00120        cntlPartCode = FindWindow(mCurrEvent->where, &currWindow);
00121        switch (cntlPartCode)
00122        {
00123               case inMenuBar:
00124                      menuChoice = MenuSelect(mCurrEvent->where);
00125                      HandleMenuChoice(menuChoice);
00126                      ::InvalMenuBar();
00127                      break;
00128                      
00129               default:
00130                      break;
00131        }
00132        
00133        return err;
00134 }
00135 
00136 OSErr 
00137 nsEventHandler::HandleKeyDown() 
00138 { 
00139        OSErr  err = noErr;
00140        SInt8  charCode;
00141        SInt32 menuChoice = 0;
00142        
00143        charCode = mCurrEvent->message & charCodeMask;
00144        if ((mCurrEvent->modifiers & cmdKey) != 0)
00145        {
00146               switch (charCode)
00147               {
00148                      case 'E':
00149                      case 'e':
00150                             menuChoice = rMenuFile;
00151                             menuChoice <<= 16;
00152                             menuChoice |= rMenuItemASEncode;
00153                             break;
00154                             
00155                      case 'D':
00156                      case 'd':
00157                             menuChoice = rMenuFile;
00158                             menuChoice <<= 16;
00159                             menuChoice |= rMenuItemASDecode;
00160                             break;
00161                             
00162                      case 'F':
00163                      case 'f':
00164                             menuChoice = rMenuFile;
00165                             menuChoice <<= 16;
00166                             menuChoice |= rMenuItemASEncodeFolder;
00167                             break;
00168                             
00169                      case 'O':
00170                      case 'o':
00171                             menuChoice = rMenuFile;
00172                             menuChoice <<= 16;
00173                             menuChoice |= rMenuItemASDecodeFolder;
00174                             break;
00175                             
00176                      case 'Q':
00177                      case 'q':
00178                             menuChoice = rMenuFile;
00179                             menuChoice <<= 16;
00180                             menuChoice |= rMenuItemQuit;
00181                             break;
00182                             
00183                      default:
00184                             menuChoice = 0;
00185                             break;
00186               }      
00187               err = HandleMenuChoice(menuChoice);
00188        }
00189        
00190        return err;
00191 }
00192 
00193 OSErr 
00194 nsEventHandler::HandleUpdateEvt() 
00195 { 
00196        return noErr;
00197 }
00198 
00199 OSErr 
00200 nsEventHandler::HandleActivateEvt() 
00201 { 
00202        return noErr;
00203 }
00204 
00205 OSErr 
00206 nsEventHandler::HandleOSEvt() 
00207 { 
00208        ::HiliteMenu(0);
00209        
00210        return noErr;
00211 }
00212 
00213 OSErr 
00214 nsEventHandler::HandleInContent() 
00215 { 
00216        return noErr;
00217 }
00218 
00219 OSErr
00220 nsEventHandler::HandleMenuChoice(SInt32 aChoice)
00221 {
00222        OSErr                       err = noErr;
00223        long                        menuID = HiWord(aChoice);
00224        long                        menuItem = LoWord(aChoice);
00225        FSSpec                      file, outFile;
00226        nsFileSelector              selector;
00227        
00228        switch (menuID)
00229        {
00230               case rMenuFile:
00231                      switch (menuItem)
00232                      {
00233                             case rMenuItemASEncode:                   /* AS Encode... */
00234                                    err = selector.SelectFile(&file);
00235                                    if (err == noErr)
00236                                    {
00237                                           if (nsAppleSingleEncoder::HasResourceFork(&file))
00238                                           {
00239                                                  nsAppleSingleEncoder encoder;
00240                                                  err = encoder.Encode(&file);
00241                                           }
00242                                    }
00243                                    break;
00244                             
00245                             case rMenuItemASDecode:                   /* AS Decode... */
00246                                    err = selector.SelectFile(&file);
00247                                    if (err == noErr)
00248                                    {
00249                                           if (nsAppleSingleDecoder::IsAppleSingleFile(&file))
00250                                           {
00251                                                  nsAppleSingleDecoder decoder;
00252                                                  err = decoder.Decode(&file, &outFile);
00253                                           }
00254                                    }
00255                                    break;
00256                                    
00257                             case rMenuItemASEncodeFolder:      /* AS Encode Folder... */
00258                                    err = selector.SelectFolder(&file);
00259                                    if (err == noErr)
00260                                    {
00261                                           nsAppleSingleEncoder encoder;
00262                                           err = encoder.EncodeFolder(&file);
00263                                    }
00264                                    break;
00265                                    
00266                             case rMenuItemASDecodeFolder:      /* AS Decode Folder... */
00267                                    err = selector.SelectFolder(&file);
00268                                    if (err == noErr)
00269                                    {
00270                                           nsAppleSingleDecoder decoder;
00271                                           err = decoder.DecodeFolder(&file);
00272                                    }
00273                                    break;
00274                                    
00275                             case rMenuItemQuit:                       /* Quit */
00276                                    nsASEApp::SetCompletionStatus(true);
00277                                    break;
00278                      }
00279                      break;
00280               
00281               case rMenuApple:
00282                      if (menuItem == rMenuItemAbout)
00283                             ::Alert(rAboutBox, nil);
00284                      break;
00285                      
00286               default:
00287                      break;
00288        }
00289        
00290        return err;
00291 }