Back to index

lightning-sunbird  0.9+nobinonly
CWebBrowserCMAttachment.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is the Mozilla browser.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications, Inc.
00020  * Portions created by the Initial Developer are Copyright (C) 1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Conrad Carlen <ccarlen@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * 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 #include "CWebBrowserCMAttachment.h"
00041 
00042 
00043 //*****************************************************************************
00044 //  CWebBrowserChrome
00045 //
00046 //  This override is needed because LCMAttachment intercepts mouse clicks, tracks
00047 //  the click, and handles it if the click is on a context menu. We don't want so
00048 //  complete a solution. In our case, mozilla handles the click, determines that
00049 //  it's a context menu click and then calls nsIContextMenuListener::OnShowContextMenu.
00050 //  This override allows DoContextMenuClick to be called after the click.
00051 //
00052 //*****************************************************************************
00053 
00054 CWebBrowserCMAttachment::CWebBrowserCMAttachment()
00055 {
00056 }
00057 
00058 CWebBrowserCMAttachment::CWebBrowserCMAttachment(LCommander*    inTarget,
00059                                                     PaneIDT           inTargetPaneID)
00060        : LCMAttachment(inTarget, inTargetPaneID)
00061 {
00062 }
00063 
00064 CWebBrowserCMAttachment::CWebBrowserCMAttachment(LStream*      inStream)
00065        : LCMAttachment(inStream)
00066 {
00067 }
00068 
00069 CWebBrowserCMAttachment::~CWebBrowserCMAttachment()
00070 {
00071 }
00072 
00073 
00074 void CWebBrowserCMAttachment::ExecuteSelf(MessageT      inMessage,
00075                                              void*             ioParam)
00076 {
00077        SetExecuteHost(true);
00078        
00079               // Ensure the CMM is installed and initialized. If not, just
00080               // return quietly.
00081        if (not mCMMInitialized) {
00082               return;
00083        }
00084 
00085               // Dispatch to the various messages we handle.
00086               
00087        if (inMessage == msg_AdjustCursor) {
00088        
00089                      // Only display the cursor if the control key is depressed
00090               if (((static_cast<EventRecord*>(ioParam))->modifiers & controlKey) != 0) {
00091               
00092                             //+++ This needs to be updated to use kThemeContextualMenuArrowCursor,
00093                             //+++ but UCursor needs to be updated to be Theme-savvy first.
00094                      UCursor::SetTheCursor(mCMMCursorID);
00095                      SetExecuteHost(false);
00096               }
00097               
00098        } else if (inMessage == msg_Event) {
00099        
00100        } else if (inMessage == msg_Click) {
00101 
00102                      // It's a click, but is it a CMM click?
00103               if (::IsShowContextualMenuClick(
00104                             &(static_cast<SMouseDownEvent*>(ioParam))->macEvent)) {
00105 
00106                      // It is; let's handle it. However, first we must switch the
00107                      // target to our object, and update the port.
00108                      
00109                      LCommander*   target = FindCommandTarget();
00110                      if ((target != nil) && LCommander::SwitchTarget(target)) {
00111                             LPane* ownerAsPane = dynamic_cast<LPane*>(mOwnerHost);                       
00112                             if (ownerAsPane != nil) {
00113                                    ownerAsPane->UpdatePort();
00114                             }
00115                      }
00116               }
00117        }
00118 }
00119 
00120 
00121 void CWebBrowserCMAttachment::SetCommandList(SInt16 mcmdResID)
00122 {
00123     Handle mcmdRes = ::GetResource(ResType_MenuCommands, mcmdResID);
00124     ThrowIfResFail_(mcmdRes);
00125     ::DetachResource(mcmdRes);  // LHandleStream takes ownership and uses DisposeHandle()
00126     LHandleStream inStream(mcmdRes);
00127     
00128     mCommandList.RemoveItemsAt(mCommandList.GetCount(), LArray::index_First);
00129     
00130        UInt16 numCommands;
00131        inStream >> numCommands;
00132        
00133        for (SInt16 i = 1; i <= numCommands; i++) {
00134               CommandT theCommand;
00135               inStream >> theCommand;
00136               mCommandList.AddItem(theCommand);
00137        }
00138 }
00139 
00140 
00141 void CWebBrowserCMAttachment::DoContextMenuClick(const EventRecord&   inMacEvent)
00142 {
00143     DoCMMClick(inMacEvent);
00144 }
00145