Back to index

lightning-sunbird  0.9+nobinonly
nsBaseClipboard.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; 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.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * 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 #include "nsBaseClipboard.h"
00039 
00040 #include "nsIClipboardOwner.h"
00041 #include "nsString.h"
00042 
00043 #include "nsIWidget.h"
00044 #include "nsIComponentManager.h"
00045 #include "nsCOMPtr.h"
00046 #include "nsXPCOM.h"
00047 #include "nsISupportsPrimitives.h"
00048 
00049 
00050 NS_IMPL_ADDREF(nsBaseClipboard)
00051 NS_IMPL_RELEASE(nsBaseClipboard)
00052 NS_IMPL_QUERY_INTERFACE1(nsBaseClipboard, nsIClipboard)
00053 
00054 
00055 //-------------------------------------------------------------------------
00056 //
00057 // nsBaseClipboard constructor
00058 //
00059 //-------------------------------------------------------------------------
00060 nsBaseClipboard::nsBaseClipboard()
00061 {
00062   mClipboardOwner          = nsnull;
00063   mTransferable            = nsnull;
00064   mIgnoreEmptyNotification = PR_FALSE;
00065 
00066 }
00067 
00068 //-------------------------------------------------------------------------
00069 //
00070 // nsBaseClipboard destructor
00071 //
00072 //-------------------------------------------------------------------------
00073 nsBaseClipboard::~nsBaseClipboard()
00074 {
00075   EmptyClipboard(kSelectionClipboard);
00076   EmptyClipboard(kGlobalClipboard);
00077 }
00078 
00079 
00084 NS_IMETHODIMP nsBaseClipboard::SetData(nsITransferable * aTransferable, nsIClipboardOwner * anOwner,
00085                                         PRInt32 aWhichClipboard)
00086 {
00087   NS_ASSERTION ( aTransferable, "clipboard given a null transferable" );
00088 
00089   if (aTransferable == mTransferable && anOwner == mClipboardOwner)
00090     return NS_OK;
00091   PRBool selectClipPresent;
00092   SupportsSelectionClipboard(&selectClipPresent);
00093   if ( !selectClipPresent && aWhichClipboard != kGlobalClipboard )
00094     return NS_ERROR_FAILURE;
00095 
00096   EmptyClipboard(aWhichClipboard);
00097 
00098   mClipboardOwner = anOwner;
00099   if ( anOwner )
00100     NS_ADDREF(mClipboardOwner);
00101 
00102   mTransferable = aTransferable;
00103   
00104   nsresult rv = NS_ERROR_FAILURE;
00105 
00106   if ( mTransferable ) {
00107     NS_ADDREF(mTransferable);
00108     rv = SetNativeClipboardData(aWhichClipboard);
00109   }
00110   
00111   return rv;
00112 }
00113 
00118 NS_IMETHODIMP nsBaseClipboard::GetData(nsITransferable * aTransferable, PRInt32 aWhichClipboard)
00119 {
00120   NS_ASSERTION ( aTransferable, "clipboard given a null transferable" );
00121   
00122   PRBool selectClipPresent;
00123   SupportsSelectionClipboard(&selectClipPresent);
00124   if ( !selectClipPresent && aWhichClipboard != kGlobalClipboard )
00125     return NS_ERROR_FAILURE;
00126 
00127   if ( aTransferable )
00128     return GetNativeClipboardData(aTransferable, aWhichClipboard);
00129 
00130   return NS_ERROR_FAILURE;
00131 }
00132 
00133 
00138 NS_IMETHODIMP nsBaseClipboard::EmptyClipboard(PRInt32 aWhichClipboard)
00139 {
00140   PRBool selectClipPresent;
00141   SupportsSelectionClipboard(&selectClipPresent);
00142   if ( !selectClipPresent && aWhichClipboard != kGlobalClipboard )
00143     return NS_ERROR_FAILURE;
00144 
00145   if (mIgnoreEmptyNotification)
00146     return NS_OK;
00147 
00148   if ( mClipboardOwner ) {
00149     mClipboardOwner->LosingOwnership(mTransferable);
00150     NS_RELEASE(mClipboardOwner);
00151   }
00152 
00153   NS_IF_RELEASE(mTransferable);
00154 
00155   return NS_OK;
00156 }
00157 
00158 
00163 NS_IMETHODIMP
00164 nsBaseClipboard :: HasDataMatchingFlavors ( nsISupportsArray* aFlavorList, PRInt32 aWhichClipboard, PRBool * outResult ) 
00165 {
00166   *outResult = PR_TRUE;  // say we always do.
00167   return NS_OK;
00168 }
00169 
00170 
00171 NS_IMETHODIMP
00172 nsBaseClipboard :: SupportsSelectionClipboard ( PRBool *_retval )
00173 {
00174   *_retval = PR_FALSE;   // we don't support the selection clipboard by default.
00175   return NS_OK;
00176 }