Back to index

lightning-sunbird  0.9+nobinonly
MRJFrame.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1998
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either of the GNU General Public License Version 2 or later (the "GPL"),
00025  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 /*
00038        MRJFrame.cpp
00039        
00040        Encapsulates a JManager frame.
00041        
00042        by Patrick C. Beard.
00043  */
00044 
00045 #include "MRJFrame.h"
00046 #include "LocalPort.h"
00047 #include "nsplugindefs.h"
00048 
00049 MRJFrame::MRJFrame(JMFrameRef frameRef)
00050        :      mFrameRef(frameRef), mActive(false), mFocused(false)
00051 {
00052 }
00053 
00054 MRJFrame::~MRJFrame()
00055 {
00056 }
00057 
00058 /* Stub implementations. */
00059 void MRJFrame::setSize(const Rect* newSize) {}
00060 void MRJFrame::invalRect(const Rect* invalidRect) {}
00061 void MRJFrame::showHide(Boolean visible) {}
00062 void MRJFrame::setTitle(const StringPtr title) {}
00063 void MRJFrame::checkUpdate() {}
00064 void MRJFrame::reorder(ReorderRequest request) {}
00065 void MRJFrame::setResizeable(Boolean resizeable) {}
00066 
00067 Boolean MRJFrame::handleEvent(const EventRecord* event)
00068 {
00069        Boolean eventHandled = true;
00070 
00071        switch (event->what) {
00072        case nsPluginEventType_AdjustCursorEvent:
00073               idle(event->modifiers);
00074               break;
00075        
00076        case ::mouseDown:
00077               click(event);
00078               break;
00079        
00080        case keyDown:
00081        case autoKey:
00082               keyPress(event->message, event->modifiers);
00083               break;
00084        
00085        case keyUp:
00086               keyRelease(event->message, event->modifiers);
00087               break;
00088 
00089        case updateEvt:
00090               update();
00091               break;
00092        
00093        case activateEvt:
00094               activate((event->modifiers & activeFlag) != 0);
00095               break;
00096 
00097 #if 0
00098        case osEvt:
00099               resume((event->message & resumeFlag) != 0);
00100               eventHandled = false;
00101               break;
00102 #endif
00103        
00104        default:
00105               eventHandled = false;
00106               break;
00107        }
00108               
00109        return eventHandled;
00110 }
00111 
00112 void MRJFrame::idle(SInt16 modifiers)
00113 {
00114        LocalPort port(getPort());
00115        port.Enter();
00116        
00117        Point pt;
00118        ::GetMouse(&pt);
00119        ::JMFrameMouseOver(mFrameRef, pt, modifiers);
00120        
00121        port.Exit();
00122 }
00123 
00124 void MRJFrame::update()
00125 {
00126        GrafPtr framePort = getPort();
00127        if (framePort != NULL)
00128               ::JMFrameUpdate(mFrameRef, framePort->clipRgn);
00129 }
00130 
00131 void MRJFrame::activate(Boolean active)
00132 {
00133        if (mActive != active) {
00134               mActive = active;
00135               ::JMFrameActivate(mFrameRef, active);
00136        }
00137 }
00138 
00139 void MRJFrame::focusEvent(Boolean gotFocus)
00140 {
00141        if (&::JMFrameFocus != NULL) {
00142               if (gotFocus != mFocused) {
00143                      if (gotFocus) {
00144                             // HACK, until focus really works.
00145                             if (mActive != gotFocus) {
00146                                    mActive = gotFocus;
00147                                    ::JMFrameActivate(mFrameRef, gotFocus);
00148                             }
00149                      }
00150                      mFocused = gotFocus;
00151                      ::JMFrameFocus(mFrameRef, gotFocus);
00152               }
00153        } else {
00154               if (mActive != gotFocus) {
00155                      mActive = gotFocus;
00156                      ::JMFrameActivate(mFrameRef, gotFocus);
00157               }
00158        }
00159 }
00160 
00161 void MRJFrame::resume(Boolean inFront)
00162 {
00163        ::JMFrameResume(mFrameRef, inFront);
00164 }
00165 
00166 void MRJFrame::click(const EventRecord* event)
00167 {
00168        // make the frame's port current, and move its origin to (0, 0).
00169        // this is needed to transform the mouse click location to frame coordinates.
00170        LocalPort port(getPort());
00171        port.Enter();
00172 
00173        Point localWhere = event->where;
00174        ::GlobalToLocal(&localWhere);
00175        click(event, localWhere);
00176        
00177        // restore the plugin port's origin, and restore the current port.
00178        port.Exit();
00179 }
00180 
00181 void MRJFrame::click(const EventRecord* event, Point localWhere)
00182 {
00183        if (&::JMFrameClickWithEventRecord != NULL)
00184               ::JMFrameClickWithEventRecord(mFrameRef, localWhere, event);
00185        else
00186               ::JMFrameClick(mFrameRef, localWhere, event->modifiers);
00187 }
00188 
00189 void MRJFrame::keyPress(UInt32 message, SInt16 modifiers)
00190 {
00191        ::JMFrameKey(mFrameRef, message & charCodeMask, (message & keyCodeMask) >> 8, modifiers);
00192 }
00193 
00194 void MRJFrame::keyRelease(UInt32 message, SInt16 modifiers)
00195 {
00196        ::JMFrameKeyRelease(mFrameRef, message & charCodeMask, (message & keyCodeMask) >> 8, modifiers);
00197 }
00198 
00199 void MRJFrame::menuSelected(UInt32 message, SInt16 modifiers)
00200 {
00201        MenuHandle menu = ::GetMenuHandle(short(message >> 16));
00202        if (menu != NULL) {
00203               short item = short(message);
00204               if (&::JMMenuSelectedWithModifiers != NULL)
00205                      ::JMMenuSelectedWithModifiers(::JMGetFrameContext(mFrameRef), menu, item, modifiers);
00206               else
00207                      ::JMMenuSelected(::JMGetFrameContext(mFrameRef), menu, item);
00208        }
00209 }
00210 
00211 void MRJFrame::print(GrafPtr printingPort, Point frameOrigin)
00212 {
00213 #if 0
00214        // this doesn't work, as Apple hasn't implemented it yet.
00215        OSStatus status = JMDrawFrameInPort(mFrameRef, printingPort, frameOrigin, printingPort->clipRgn, false);
00216        if (status != noErr) {
00217               ::MoveTo(10, 12);
00218               ::TextFont(0);
00219               ::TextSize(12);
00220               ::DrawString("\pMRJPlugin:  printing failed.");
00221        }
00222 #endif
00223 }