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