Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
nsClipboard Class Reference

Native BeOS Clipboard wrapper. More...

#include <nsClipboard.h>

Inheritance diagram for nsClipboard:
Inheritance graph
[legend]
Collaboration diagram for nsClipboard:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsClipboard ()
virtual ~nsClipboard ()
 nsClipboard ()
virtual ~nsClipboard ()
 nsClipboard ()
virtual ~nsClipboard ()
NS_DECL_ISUPPORTS
NS_DECL_NSICLIPBOARD nsresult 
Init (void)
void SelectionGetEvent (GtkWidget *aWidget, GtkSelectionData *aSelectionData, guint aTime)
void SelectionClearEvent (GtkWidget *aWidget, GdkEventSelection *aEvent)
 nsClipboard ()
virtual ~nsClipboard ()
NS_IMETHOD HasDataMatchingFlavors (nsISupportsArray *aFlavorList, PRInt32 aWhichClipboard, PRBool *_retval)
 nsClipboard ()
virtual ~nsClipboard ()
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIOBSERVER NS_IMETHOD 
HasDataMatchingFlavors (nsISupportsArray *aFlavorList, PRInt32 aWhichClipboard, PRBool *_retval)
 nsClipboard ()
virtual ~nsClipboard ()
NS_DECL_ISUPPORTS
NS_DECL_NSICLIPBOARD
NS_IMETHOD 
SetInputGroup (PRInt32 aInputGroup)
 nsClipboard ()
virtual ~nsClipboard ()
 nsClipboard ()
virtual ~nsClipboard ()
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIOBSERVER NS_IMETHOD 
HasDataMatchingFlavors (nsISupportsArray *aFlavorList, PRInt32 aWhichClipboard, PRBool *_retval)
 nsClipboard ()
virtual ~nsClipboard ()
void setData (in nsITransferable aTransferable, in nsIClipboardOwner anOwner, in long aWhichClipboard)
 Given a transferable, set the data on the native clipboard.
void getData (in nsITransferable aTransferable, in long aWhichClipboard)
 Given a transferable, get the clipboard data.
void emptyClipboard (in long aWhichClipboard)
 This empties the clipboard and notifies the clipboard owner.
boolean hasDataMatchingFlavors (in nsISupportsArray aFlavorList, in long aWhichClipboard)
 This provides a way to give correct UI feedback about, for instance, a paste should be allowed.
boolean supportsSelectionClipboard ()
 Allows clients to determine if the implementation supports the concept of a separate clipboard for selection.
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.

Static Public Member Functions

static void SetTopLevelView (BView *v)
static nsresult CreateNativeDataObject (nsITransferable *aTransferable, IDataObject **aDataObj, nsIURI *uri)
static nsresult SetupNativeDataObject (nsITransferable *aTransferable, IDataObject *aDataObj)
static nsresult GetDataFromDataObject (IDataObject *aDataObject, UINT anIndex, nsIWidget *aWindow, nsITransferable *aTransferable)
static nsresult GetNativeDataOffClipboard (nsIWidget *aWindow, UINT aIndex, UINT aFormat, void **aData, PRUint32 *aLen)
static nsresult GetNativeDataOffClipboard (IDataObject *aDataObject, UINT aIndex, UINT aFormat, void **aData, PRUint32 *aLen)
static nsresult GetGlobalData (HGLOBAL aHGBL, void **aData, PRUint32 *aLen)
static UINT GetFormat (const char *aMimeStr)
static void Shutdown ()

Public Attributes

const long kSelectionClipboard = 0
const long kGlobalClipboard = 1

Static Public Attributes

static UINT CF_HTML = ::RegisterClipboardFormat("HTML Format")

Protected Types

enum  ClipboardAction { Read, Write }

Protected Member Functions

NS_IMETHOD SetNativeClipboardData (PRInt32 aWhichClipboard)
NS_IMETHOD GetNativeClipboardData (nsITransferable *aTransferable, PRInt32 aWhichClipboard)
void Init (void)
NS_IMETHOD SetNativeClipboardData (PRInt32 aWhichClipboard)
NS_IMETHOD GetNativeClipboardData (nsITransferable *aTransferable, PRInt32 aWhichClipboard)
nsITransferableGetTransferable (PRInt32 aWhichClipboard)
NS_IMETHOD SetNativeClipboardData (PRInt32 aWhichClipboard)
NS_IMETHOD GetNativeClipboardData (nsITransferable *aTransferable, PRInt32 aWhichClipboard)
nsresult GetDataOffClipboard (ResType inMacFlavor, void **outData, PRInt32 *outDataSize)
PRBool CheckIfFlavorPresent (ResType inMacFlavor)
nsresult PutOnClipboard (ResType inFlavor, const void *inData, PRInt32 inLen)
NS_IMETHOD SetNativeClipboardData (PRInt32 aWhichClipboard)
NS_IMETHOD GetNativeClipboardData (nsITransferable *aTransferable, PRInt32 aWhichClipboard)
ULONG GetFormatID (const char *aMimeStr)
PRBool GetClipboardData (const char *aFlavour)
PRBool GetClipboardDataByID (ULONG ulFormatID, const char *aFlavor)
void SetClipboardData (const char *aFlavour)
nsresult DoClipboardAction (ClipboardAction aAction)
NS_IMETHOD SetNativeClipboardData (PRInt32 aWhichClipboard)
NS_IMETHOD GetNativeClipboardData (nsITransferable *aTransferable, PRInt32 aWhichClipboard)
nsresult GetFormat (const char *aMimeStr, char *format)
nsITransferableGetTransferable (PRInt32 aWhichClipboard)
NS_IMETHOD SetNativeClipboardData (PRInt32 aWhichClipboard)
NS_IMETHOD GetNativeClipboardData (nsITransferable *aTransferable, PRInt32 aWhichClipboard)
nsITransferableGetTransferable (PRInt32 aWhichClipboard)
NS_IMETHOD SetNativeClipboardData (PRInt32 aWhichClipboard)
NS_IMETHOD GetNativeClipboardData (nsITransferable *aTransferable, PRInt32 aWhichClipboard)
void Init (void)
nsITransferableGetTransferable (PRInt32 aWhichClipboard)
NS_IMETHOD SetNativeClipboardData (PRInt32 aWhichClipboard)

Static Protected Member Functions

static PRBool IsInternetShortcut (const nsAString &inFileName)
static PRBool FindURLFromLocalFile (IDataObject *inDataObject, UINT inIndex, void **outData, PRUint32 *outDataLen)
static PRBool FindUnicodeFromPlainText (IDataObject *inDataObject, UINT inIndex, void **outData, PRUint32 *outDataLen)
static PRBool FindPlatformHTML (IDataObject *inDataObject, UINT inIndex, void **outData, PRUint32 *outDataLen)
static void ResolveShortcut (nsILocalFile *inFileName, nsACString &outURL)
static nsEventStatus PR_CALLBACK Callback (nsGUIEvent *event)

Protected Attributes

PRBool mIgnoreEmptyNotification
nsIWidgetmWindow
nsIClipboardOwnermClipboardOwner

Static Protected Attributes

static BView * sView = 0

Private Member Functions

GdkAtom GetSelectionAtom (PRInt32 aWhichClipboard)
void AddTarget (GdkAtom aAtom, GdkAtom aSelectionAtom)
void RegisterFormat (const char *aMimeStr, GdkAtom aSelectionAtom)
PRBool DoRealConvert (GdkAtom type, GdkAtom aSelectionAtom)
PRBool DoConvert (const char *aMimeStr, GdkAtom aSelectionAtom)
PRBool GetTargets (GdkAtom aSelectionAtom)
void SelectionReceiver (GtkWidget *aWidget, GtkSelectionData *aSD)
 local method (called from nsClipboard::SelectionReceivedCB)
PRBool FindSelectionNotifyEvent ()
void SetCutBuffer ()
nsITransferableGetTransferable (PRInt32 aWhichClipboard)
void AddTarget (GdkAtom aName, GdkAtom aClipboard)
unsigned long GetFlavourTimestamp (char *type)

Static Private Member Functions

static void SelectionGetCB (GtkWidget *aWidget, GtkSelectionData *aSelectionData, guint, guint)
 This is the callback which is called when another app requests the selection.
static void SelectionClearCB (GtkWidget *aWidget, GdkEventSelection *aEvent, gpointer aData)
 Called when another app requests selection ownership.
static void SelectionRequestCB (GtkWidget *aWidget, GtkSelectionData *aSelectionData, gpointer data)
 The routine called when another app asks for the content of the selection.
static void SelectionReceivedCB (GtkWidget *aWidget, GtkSelectionData *aSelectionData, guint aTime)
 Called when the data from a paste comes in.
static void SelectionNotifyCB (GtkWidget *aWidget, GtkSelectionData *aSelectionData, gpointer aData)
 ...
static GdkAtom GetSelectionAtom (PRInt32 aWhichClipboard)
static GtkSelectionData * GetTargets (GdkAtom aWhichClipboard)

Private Attributes

nsCOMPtr< nsIClipboardOwnermSelectionOwner
nsCOMPtr< nsIClipboardOwnermGlobalOwner
nsCOMPtr< nsITransferablemSelectionTransferable
nsCOMPtr< nsITransferablemGlobalTransferable
GtkSelectionData mSelectionData
PRBool mBlocking
GtkWidget * mWidget
PRInt32 mInputGroup
nsWidgetsWidget

Static Private Attributes

static GtkWidget * sWidget = 0
static nsITransferablemTransferable = nsnull
static Window sWindow
static DisplaysDisplay

Detailed Description

Native BeOS Clipboard wrapper.

Native Xlib Clipboard wrapper.

Native Win32 Clipboard wrapper.

Native Clipboard wrapper.

Native Gtk Clipboard wrapper.

Definition at line 52 of file nsClipboard.h.


Member Enumeration Documentation

enum nsClipboard::ClipboardAction [protected]
Enumerator:
Read 
Write 

Definition at line 77 of file nsClipboard.h.

  {
    Read,
    Write
  };

Constructor & Destructor Documentation

Definition at line 67 of file nsClipboard.cpp.

                         : nsBaseClipboard()
{
#ifdef DEBUG_CLIPBOARD
  printf("  nsClipboard::nsClipboard()\n");
#endif /* DEBUG_CLIPBOARD */

  mIgnoreEmptyNotification = PR_FALSE;
  mClipboardOwner = nsnull;
  mTransferable   = nsnull;
}

Definition at line 83 of file nsClipboard.cpp.

{
#ifdef DEBUG_CLIPBOARD
  printf("  nsClipboard::~nsClipboard()\n");  
#endif /* DEBUG_CLIPBOARD */
}
virtual nsClipboard::~nsClipboard ( ) [virtual]
virtual nsClipboard::~nsClipboard ( ) [virtual]
virtual nsClipboard::~nsClipboard ( ) [virtual]
virtual nsClipboard::~nsClipboard ( ) [virtual]
virtual nsClipboard::~nsClipboard ( ) [virtual]
virtual nsClipboard::~nsClipboard ( ) [virtual]
virtual nsClipboard::~nsClipboard ( ) [virtual]
virtual nsClipboard::~nsClipboard ( ) [virtual]

Member Function Documentation

void nsClipboard::AddTarget ( GdkAtom  aName,
GdkAtom  aClipboard 
) [private]
void nsClipboard::AddTarget ( GdkAtom  aAtom,
GdkAtom  aSelectionAtom 
) [inline, private]

Definition at line 1167 of file nsClipboard.cpp.

{
  gtk_selection_add_target(sWidget, aSelectionAtom, aAtom, aAtom);
}

Here is the caller graph for this function:

nsEventStatus PR_CALLBACK nsClipboard::Callback ( nsGUIEvent event) [static, protected]

Definition at line 122 of file nsClipboard.cpp.

                                                                 {
  XEvent *ev = (XEvent *)event->nativeMsg;
  
  /* may be nsnull in the |event->message == NS_DESTROY| case... */
  if(ev == nsnull)
    return nsEventStatus_eIgnore;

  // Check the event type
  if (ev->type == SelectionRequest) {
    if (mTransferable == nsnull) {
      fprintf(stderr, "nsClipboard::Callback: null transferable\n");
      return nsEventStatus_eIgnore;
    }

    // Get the data from the Transferable

    const char *dataFlavor = kUnicodeMime;
    nsCOMPtr<nsISupports> genDataWrapper;
    nsresult rv;
    PRUint32 dataLength;
    void *data;
    data = malloc(16384);
    rv = mTransferable->GetTransferData(dataFlavor,
                                        getter_AddRefs(genDataWrapper),
                                        &dataLength);
    nsPrimitiveHelpers::CreateDataFromPrimitive(dataFlavor, genDataWrapper,
                                                &data, dataLength);
    if (NS_SUCCEEDED(rv) && data && dataLength) {
      char *plainText = nsnull;
      PRUnichar* unicodeData = NS_REINTERPRET_CAST(PRUnichar*, data);
      PRInt32 plainLen = 0;
      nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText(unicodeData,
                                                            dataLength/2,
                                                            &plainText,
                                                            &plainLen);
      if (data) {
        free(data);
        data = plainText;
        dataLength = plainLen;
      }

      // Set the window property to contain the data
      XChangeProperty(sDisplay,
                      ev->xselectionrequest.requestor,
                      ev->xselectionrequest.property, 
                      ev->xselectionrequest.target,
                      8, PropModeReplace,
                      (unsigned char *)data, dataLength);

      // Send the requestor a SelectionNotify event
      XEvent aEvent;
      aEvent.type = SelectionNotify;
      aEvent.xselection.serial = ev->xselectionrequest.serial;
      aEvent.xselection.display = ev->xselectionrequest.display;
      aEvent.xselection.requestor = ev->xselectionrequest.requestor;
      aEvent.xselection.selection = ev->xselectionrequest.selection;
      aEvent.xselection.target = ev->xselectionrequest.target;
      aEvent.xselection.property = ev->xselectionrequest.property;
      aEvent.xselection.time = CurrentTime;
      XSendEvent(sDisplay, ev->xselectionrequest.requestor, 1, 0, &aEvent);
   }
  }
  return nsEventStatus_eIgnore;
}

Here is the call graph for this function:

PRBool nsClipboard::CheckIfFlavorPresent ( ResType  inMacFlavor) [protected]

Definition at line 683 of file nsClipboard.cpp.

{
  PRBool retval = PR_FALSE;

  ScrapRef scrap = nsnull;
  OSStatus err = ::GetCurrentScrap(&scrap);
  if ( scrap ) {
  
    // the OS clipboard may contain promises and require conversions. Instead
    // of calling in those promises, we can use ::GetScrapFlavorInfoList() to
    // see the list of what could be there if we asked for it. This is really
    // fast. Iterate over the list, and if we find it, we're good to go.
    UInt32 flavorCount = 0;
    ::GetScrapFlavorCount ( scrap, &flavorCount );
    nsAutoArrayPtr<ScrapFlavorInfo> flavorList(new ScrapFlavorInfo[flavorCount]);
    if ( flavorList ) {
      err = ::GetScrapFlavorInfoList ( scrap, &flavorCount, flavorList );
      if ( !err && flavorList ) {
        for ( unsigned int i = 0; i < flavorCount; ++i ) {
          if ( flavorList[i].flavorType == inMacFlavor )
            retval = PR_TRUE;
        }
      }
    }

  }
  return retval;
} // CheckIfFlavorPresent

Here is the call graph for this function:

nsresult nsClipboard::CreateNativeDataObject ( nsITransferable aTransferable,
IDataObject **  aDataObj,
nsIURI uri 
) [static]

Definition at line 138 of file nsClipboard.cpp.

{
  if (nsnull == aTransferable) {
    return NS_ERROR_FAILURE;
  }

  // Create our native DataObject that implements 
  // the OLE IDataObject interface
  nsDataObj * dataObj = new nsDataObj(uri);

  if (!dataObj) 
    return NS_ERROR_OUT_OF_MEMORY;

  dataObj->AddRef();

  // Now set it up with all the right data flavors & enums
  nsresult res = SetupNativeDataObject(aTransferable, dataObj);
  if (NS_OK == res) {
    *aDataObj = dataObj; 
  } else {
    delete dataObj;
  }
  return res;
}

Here is the call graph for this function:

Definition at line 357 of file nsClipboard.cpp.

{
  nsresult rc = NS_ERROR_FAILURE;

  if (WinOpenClipbrd(0/*hab*/)) {

    if (aAction == Write)
      WinEmptyClipbrd(0/*hab*/);

    // Get the list of formats the transferable can handle
    nsCOMPtr<nsISupportsArray> pFormats;
    if(aAction == Read)
      rc = mTransferable->FlavorsTransferableCanImport(getter_AddRefs(pFormats));
    else
      rc = mTransferable->FlavorsTransferableCanExport(getter_AddRefs(pFormats));

    if (NS_FAILED(rc))
      return NS_ERROR_FAILURE;

    PRUint32 cFormats = 0;
    pFormats->Count(&cFormats);

    for (PRUint32 i = 0; i < cFormats; i++) {

      nsCOMPtr<nsISupports> genericFlavor;
      pFormats->GetElementAt(i, getter_AddRefs(genericFlavor));
      nsCOMPtr<nsISupportsCString> currentFlavor(do_QueryInterface(genericFlavor));

      if (currentFlavor) {
        nsXPIDLCString flavorStr;
        currentFlavor->ToString(getter_Copies(flavorStr));

        if (aAction == Read) {
          if (GetClipboardData(flavorStr))
            break;
        }
        else
          SetClipboardData(flavorStr);
      }
    }
    WinCloseClipbrd(0/*hab*/);
    rc = NS_OK;
  }
  return rc;
}

Here is the call graph for this function:

PRBool nsClipboard::DoConvert ( const char *  aMimeStr,
GdkAtom  aSelectionAtom 
) [private]

Definition at line 1195 of file nsClipboard.cpp.

{
#ifdef DEBUG_CLIPBOARD
  g_print("  nsClipboard::DoConvert(%s, %s)\n", aMimeStr, gdk_atom_name(aSelectionAtom));
#endif
  /* when doing the selection_add_target, each case should have the same last parameter
     which matches the case match */
  PRBool r = PR_FALSE;

  nsCAutoString mimeStr(aMimeStr);

  if (mimeStr.Equals(kUnicodeMime)) {
    r = DoRealConvert(gdk_atom_intern("UTF8_STRING", FALSE), aSelectionAtom);
    if (r) return r;
    r = DoRealConvert(gdk_atom_intern("COMPOUND_TEXT", FALSE), aSelectionAtom);
    if (r) return r;
    r = DoRealConvert(GDK_SELECTION_TYPE_STRING, aSelectionAtom);
    if (r) return r;
  }

  GdkAtom atom = gdk_atom_intern(aMimeStr, FALSE);
  r = DoRealConvert(atom, aSelectionAtom);
  if (r) return r;

  return r;
}

Here is the call graph for this function:

PRBool nsClipboard::DoRealConvert ( GdkAtom  type,
GdkAtom  aSelectionAtom 
) [private]

Definition at line 383 of file nsClipboard.cpp.

{
#ifdef DEBUG_CLIPBOARD
  g_print("    nsClipboard::DoRealConvert(%li)\n    {\n", type);
#endif

  // Set a flag saying that we're blocking waiting for the callback:
  mBlocking = PR_TRUE;

  //
  // ask X what kind of data we can get
  //
#ifdef DEBUG_CLIPBOARD
  g_print("     Doing real conversion of atom type '%s'\n", gdk_atom_name(type));
#endif
  gtk_selection_convert(sWidget,
                        aSelectionAtom,
                        type,
                        GDK_CURRENT_TIME);


  /* because Gtk is smart, it checks in gtk_selection_convert to see if
     the widget we are converting owns the selection, and if it does it
     doesn't bother going to X, so it will be done and mBlocking will be
     set to FALSE by this point, so only poll X if we have to.  (pav)
  */
  if (mBlocking) {
    // Now we need to wait until the callback comes in ...
    // i is in case we get a runaway (yuck).
#ifdef DEBUG_CLIPBOARD
    g_print("      Waiting for the callback... mBlocking = %d\n", mBlocking);
#endif /* DEBUG_CLIPBOARD */

    if (!FindSelectionNotifyEvent())
      return PR_FALSE;

#ifdef DEBUG_CLIPBOARD
    g_print("    }\n");
#endif
  }

  if (mSelectionData.length > 0)
    return PR_TRUE;

  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIClipboard::emptyClipboard ( in long  aWhichClipboard) [inherited]

This empties the clipboard and notifies the clipboard owner.

This empties the "logical" clipboard. It does not clear the native clipboard.

Parameters:
aWhichClipboardSpecifies the clipboard to which this operation applies.
Returns:
NS_OK if successful.
PRBool nsClipboard::FindPlatformHTML ( IDataObject *  inDataObject,
UINT  inIndex,
void **  outData,
PRUint32 outDataLen 
) [static, protected]

Definition at line 701 of file nsClipboard.cpp.

{
  PRBool dataFound = PR_FALSE;

  if ( outData && *outData ) {
    // CF_HTML is UTF8, not unicode. We also can't rely on it being null-terminated
    // so we have to check the CF_HTML header for the correct length. The length we return
    // is the bytecount from the beginning of the data to the end, without
    // the null termination. Because it's UTF8, we're guaranteed the header is ascii (yay!).
    float vers = 0.0;
    PRUint32 startOfData = 0;
    sscanf((char*)*outData, "Version:%f\nStartHTML:%d\nEndHTML:%d", &vers, &startOfData, outDataLen);
    NS_ASSERTION(startOfData && *outDataLen, "Couldn't parse CF_HTML description header");
 
    if ( *outDataLen )
      dataFound = PR_TRUE;
  }

  return dataFound;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1362 of file nsClipboard.cpp.

{
  Display *xDisplay = GDK_DISPLAY();
  checkEventContext context;
  context.cbWidget = nsnull;
  context.selAtom = gdk_atom_intern("GDK_SELECTION", FALSE);

  // Send X events which are relevant to the ongoing selection retrieval
  // to the clipboard widget.  Wait until either the operation completes, or
  // we hit our timeout.  All other X events remain queued.

  int select_result;

#ifdef POLL_WITH_XCONNECTIONNUMBER
  struct pollfd fds[1];
  fds[0].fd = XConnectionNumber(xDisplay);
  fds[0].events = POLLIN;
#else
  int cnumber = ConnectionNumber(xDisplay);
  fd_set select_set;
  FD_ZERO(&select_set);
  FD_SET(cnumber, &select_set);
  ++cnumber;
  struct timeval tv;
#endif

  do {
    XEvent xevent;

    while (XCheckIfEvent(xDisplay, &xevent, checkEventProc,
                         (XPointer) &context)) {

      if (xevent.xany.type == SelectionNotify)
        DispatchSelectionNotifyEvent(context.cbWidget, &xevent);
      else
        DispatchPropertyNotifyEvent(context.cbWidget, &xevent);

      if (!mBlocking)
        return PR_TRUE;
    }

#ifdef POLL_WITH_XCONNECTIONNUMBER
    select_result = poll(fds, 1, kClipboardTimeout / 1000);
#else
    tv.tv_sec = 0;
    tv.tv_usec = kClipboardTimeout;
    select_result = select(cnumber, &select_set, nsnull, nsnull, &tv);
#endif
  } while (select_result == 1);

#ifdef DEBUG_CLIPBOARD
  printf("exceeded clipboard timeout\n");
#endif
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsClipboard::FindUnicodeFromPlainText ( IDataObject *  inDataObject,
UINT  inIndex,
void **  outData,
PRUint32 outDataLen 
) [static, protected]

Definition at line 730 of file nsClipboard.cpp.

{
  PRBool dataFound = PR_FALSE;

  // we are looking for text/unicode and we failed to find it on the clipboard first,
  // try again with text/plain. If that is present, convert it to unicode.
  nsresult loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, GetFormat(kTextMime), outData, outDataLen);
  if ( NS_SUCCEEDED(loadResult) && *outData ) {
    const char* castedText = NS_REINTERPRET_CAST(char*, *outData);          
    PRUnichar* convertedText = nsnull;
    PRInt32 convertedTextLen = 0;
    nsPrimitiveHelpers::ConvertPlatformPlainTextToUnicode ( castedText, *outDataLen, 
                                                              &convertedText, &convertedTextLen );
    if ( convertedText ) {
      // out with the old, in with the new 
      nsMemory::Free(*outData);
      *outData = convertedText;
      *outDataLen = convertedTextLen * sizeof(PRUnichar);
      dataFound = PR_TRUE;
    }
  } // if plain text data on clipboard

  return dataFound;

} // FindUnicodeFromPlainText

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsClipboard::FindURLFromLocalFile ( IDataObject *  inDataObject,
UINT  inIndex,
void **  outData,
PRUint32 outDataLen 
) [static, protected]

Definition at line 766 of file nsClipboard.cpp.

{
  PRBool dataFound = PR_FALSE;

  nsresult loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, GetFormat(kFileMime), outData, outDataLen);
  if ( NS_SUCCEEDED(loadResult) && *outData ) {
    // we have a file path in |data|. Is it an internet shortcut or a normal file?
    const nsDependentString filepath(NS_STATIC_CAST(PRUnichar*, *outData));
    nsCOMPtr<nsILocalFile> file;
    nsresult rv = NS_NewLocalFile(filepath, PR_TRUE, getter_AddRefs(file));
    if (NS_FAILED(rv))
      return dataFound;

    if ( IsInternetShortcut(filepath) ) {
      nsCAutoString url;
      ResolveShortcut( file, url );
      if ( !url.IsEmpty() ) {
        // convert it to unicode and pass it out
        nsMemory::Free(*outData);
        *outData = UTF8ToNewUnicode(url);
        *outDataLen = nsCRT::strlen(NS_STATIC_CAST(PRUnichar*, *outData)) * sizeof(PRUnichar);

        dataFound = PR_TRUE;
      }
    }
    else {
      // we have a normal file, use some Necko objects to get our file path
      nsCAutoString urlSpec;
      NS_GetURLSpecFromFile(file, urlSpec);

      // convert it to unicode and pass it out
      nsMemory::Free(*outData);
      *outData = UTF8ToNewUnicode(urlSpec);
      *outDataLen = nsCRT::strlen(NS_STATIC_CAST(PRUnichar*, *outData)) * sizeof(PRUnichar);
      dataFound = PR_TRUE;
    } // else regular file
  }

  return dataFound;
} // FindURLFromLocalFile

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsClipboard::GetClipboardData ( const char *  aFlavour) [protected]

Definition at line 113 of file nsClipboard.cpp.

{
  ULONG ulFormatID = GetFormatID( aFlavor );
  
  PRBool found = GetClipboardDataByID( ulFormatID, aFlavor );

  if (!found) 
  {
    if (!strcmp( aFlavor, kUnicodeMime ))
    {
      found = GetClipboardDataByID( CF_TEXT, aFlavor );
    }
    else if (strstr( aFlavor, "image/" ))
    {
      found = GetClipboardDataByID( CF_BITMAP, aFlavor );
    }
  }

  return found;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsClipboard::GetClipboardDataByID ( ULONG  ulFormatID,
const char *  aFlavor 
) [protected]

Definition at line 134 of file nsClipboard.cpp.

{
  PVOID pDataMem;
  PRUint32 NumOfBytes;
  PRBool TempBufAllocated = PR_FALSE;

  PVOID pClipboardData = NS_REINTERPRET_CAST(PVOID, WinQueryClipbrdData( 0, ulFormatID ));

  if (!pClipboardData) 
    return PR_FALSE;

  if (strstr( aFlavor, "text/" ))  // All text/.. flavors are null-terminated
  {
    pDataMem = pClipboardData;

    if (ulFormatID == CF_TEXT)     // CF_TEXT is one byte character set
    {
      PRUint32 NumOfChars = strlen( NS_STATIC_CAST (char*, pDataMem) );
      NumOfBytes = NumOfChars;

      if (!strcmp( aFlavor, kUnicodeMime ))  // Asked for unicode, but only plain text available.  Convert it!
      {
        nsAutoChar16Buffer buffer;
        PRInt32 bufLength;
        MultiByteToWideChar(0, NS_STATIC_CAST(char*, pDataMem), NumOfChars,
                            buffer, bufLength);
        pDataMem = ToNewUnicode(nsDependentString(buffer.get()));
        TempBufAllocated = PR_TRUE;
        NumOfBytes = bufLength * sizeof(UniChar);
      }

    }
    else                           // All other text/.. flavors are in unicode
    {
      PRUint32 NumOfChars = UniStrlen( NS_STATIC_CAST(UniChar*, pDataMem) );
      NumOfBytes = NumOfChars * sizeof(UniChar);
      PVOID pTempBuf = nsMemory::Alloc(NumOfBytes);
      memcpy(pTempBuf, pDataMem, NumOfBytes);
      pDataMem = pTempBuf;
      TempBufAllocated = PR_TRUE;
    }

    // DOM wants LF only, so convert from CRLF
    nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks( aFlavor, &pDataMem,   // pDataMem could be reallocated !!
                                                        NS_REINTERPRET_CAST(PRInt32*, &NumOfBytes) );  // yuck

  }
  else                             // Assume rest of flavors are binary data
  {
    if (ulFormatID == CF_BITMAP)
    {
      if (!strcmp( aFlavor, kJPEGImageMime ))
      {
        // OS2TODO  Convert bitmap to jpg
#ifdef DEBUG
        printf( "nsClipboard:: No JPG found on clipboard; need to convert BMP\n");
#endif
      }
      else if (!strcmp( aFlavor, kGIFImageMime ))
      {
        // OS2TODO  Convert bitmap to gif
#ifdef DEBUG
        printf( "nsClipboard:: No GIF found on clipboard; need to convert BMP\n");
#endif
      }
      else if (!strcmp( aFlavor, kPNGImageMime ))
      {
        // OS2TODO  Convert bitmap to png
#ifdef DEBUG
        printf( "nsClipboard:: No PNG found on clipboard; need to convert BMP\n");
#endif
      }
    }
    else
    {
      pDataMem = NS_STATIC_CAST(PBYTE, pClipboardData) + sizeof(PRUint32);
      NumOfBytes = *(NS_STATIC_CAST(PRUint32*, pClipboardData));
    }
  }

  nsCOMPtr<nsISupports> genericDataWrapper;
  nsPrimitiveHelpers::CreatePrimitiveForData( aFlavor, pDataMem, NumOfBytes, getter_AddRefs(genericDataWrapper) );
  nsresult errCode = mTransferable->SetTransferData( aFlavor, genericDataWrapper, NumOfBytes );
#ifdef DEBUG
  if (errCode != NS_OK)
    printf( "nsClipboard:: Error setting data into transferable\n" );
#endif

  if (TempBufAllocated)
    nsMemory::Free(pDataMem);

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIClipboard::getData ( in nsITransferable  aTransferable,
in long  aWhichClipboard 
) [inherited]

Given a transferable, get the clipboard data.

Parameters:
aTransferableThe transferable
aWhichClipboardSpecifies the clipboard to which this operation applies.
Returns:
NS_Ok if no errors
nsresult nsClipboard::GetDataFromDataObject ( IDataObject *  aDataObject,
UINT  anIndex,
nsIWidget aWindow,
nsITransferable aTransferable 
) [static]

Definition at line 583 of file nsClipboard.cpp.

{
  // make sure we have a good transferable
  if ( !aTransferable )
    return NS_ERROR_INVALID_ARG;

  nsresult res = NS_ERROR_FAILURE;

  // get flavor list that includes all flavors that can be written (including ones 
  // obtained through conversion)
  nsCOMPtr<nsISupportsArray> flavorList;
  res = aTransferable->FlavorsTransferableCanImport ( getter_AddRefs(flavorList) );
  if ( NS_FAILED(res) )
    return NS_ERROR_FAILURE;

  // Walk through flavors and see which flavor is on the clipboard them on the native clipboard,
  PRUint32 i;
  PRUint32 cnt;
  flavorList->Count(&cnt);
  for (i=0;i<cnt;i++) {
    nsCOMPtr<nsISupports> genericFlavor;
    flavorList->GetElementAt ( i, getter_AddRefs(genericFlavor) );
    nsCOMPtr<nsISupportsCString> currentFlavor ( do_QueryInterface(genericFlavor) );
    if ( currentFlavor ) {
      nsXPIDLCString flavorStr;
      currentFlavor->ToString(getter_Copies(flavorStr));
      UINT format = GetFormat(flavorStr);

      // Try to get the data using the desired flavor. This might fail, but all is
      // not lost.
      void* data = nsnull;
      PRUint32 dataLen = 0;
      PRBool dataFound = PR_FALSE;
      if (nsnull != aDataObject) {
        if ( NS_SUCCEEDED(GetNativeDataOffClipboard(aDataObject, anIndex, format, &data, &dataLen)) )
          dataFound = PR_TRUE;
      } 
      else if (nsnull != aWindow) {
        if ( NS_SUCCEEDED(GetNativeDataOffClipboard(aWindow, anIndex, format, &data, &dataLen)) )
          dataFound = PR_TRUE;
      }

      // This is our second chance to try to find some data, having not found it
      // when directly asking for the flavor. Let's try digging around in other
      // flavors to help satisfy our craving for data.
      if ( !dataFound ) {
        if ( strcmp(flavorStr, kUnicodeMime) == 0 )
          dataFound = FindUnicodeFromPlainText ( aDataObject, anIndex, &data, &dataLen );
        else if ( strcmp(flavorStr, kURLMime) == 0 )
          dataFound = FindURLFromLocalFile ( aDataObject, anIndex, &data, &dataLen );
      } // if we try one last ditch effort to find our data

      // Hopefully by this point we've found it and can go about our business
      if ( dataFound ) {
        nsCOMPtr<nsISupports> genericDataWrapper;
        if ( strcmp(flavorStr, kFileMime) == 0 ) {
          // we have a file path in |data|. Create an nsLocalFile object.
          nsDependentString filepath(NS_REINTERPRET_CAST(PRUnichar*, data));
          nsCOMPtr<nsILocalFile> file;
          if ( NS_SUCCEEDED(NS_NewLocalFile(filepath, PR_FALSE, getter_AddRefs(file))) )
            genericDataWrapper = do_QueryInterface(file);
          nsMemory::Free(data);
        }
        else if ( strcmp(flavorStr, kNativeHTMLMime) == 0) {
          // the editor folks want CF_HTML exactly as it's on the clipboard, no conversions,
          // no fancy stuff. Pull it off the clipboard, stuff it into a wrapper and hand
          // it back to them.
          if ( FindPlatformHTML(aDataObject, anIndex, &data, &dataLen) )
            nsPrimitiveHelpers::CreatePrimitiveForData ( flavorStr, data, dataLen, getter_AddRefs(genericDataWrapper) );
          else
          {
            nsMemory::Free(data);
            continue;     // something wrong with this flavor, keep looking for other data
          }
          nsMemory::Free(data);
        }
        else if ( strcmp(flavorStr, kJPEGImageMime) == 0) {
          nsIInputStream * imageStream = NS_REINTERPRET_CAST(nsIInputStream*, data);
          genericDataWrapper = do_QueryInterface(imageStream);
          NS_IF_RELEASE(imageStream);
        }
        else {
          // we probably have some form of text. The DOM only wants LF, so convert from Win32 line 
          // endings to DOM line endings.
          PRInt32 signedLen = NS_STATIC_CAST(PRInt32, dataLen);
          nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks ( flavorStr, &data, &signedLen );
          dataLen = signedLen;

          nsPrimitiveHelpers::CreatePrimitiveForData ( flavorStr, data, dataLen, getter_AddRefs(genericDataWrapper) );
          nsMemory::Free(data);
        }
        
        NS_ASSERTION ( genericDataWrapper, "About to put null data into the transferable" );
        aTransferable->SetTransferData(flavorStr, genericDataWrapper, dataLen);
        res = NS_OK;

        // we found one, get out of the loop
        break;
      }

    }
  } // foreach flavor

  return res;

}

Here is the call graph for this function:

nsresult nsClipboard::GetDataOffClipboard ( ResType  inMacFlavor,
void **  outData,
PRInt32 outDataSize 
) [protected]

Definition at line 546 of file nsClipboard.cpp.

{
  if ( !outData || !inMacFlavor )
    return NS_ERROR_FAILURE;

  // set up default results.
  *outData = nsnull;
  if ( outDataSize )
      *outDataSize = 0;


  ScrapRef scrap;
  long dataSize;
  OSStatus err;

  err = ::GetCurrentScrap(&scrap);
  if (err != noErr) return NS_ERROR_FAILURE;
  err = ::GetScrapFlavorSize(scrap, inMacFlavor, &dataSize);
  if (err != noErr) return NS_ERROR_FAILURE;
  if (dataSize > 0) {
    char* dataBuff = (char*) nsMemory::Alloc(dataSize);
    if ( !dataBuff )
      return NS_ERROR_OUT_OF_MEMORY;
      
    // ::GetScrapFlavorData can be very expensive when a conversion
    // is required (say the OS does the conversion from TEXT to utxt). Be
    // sure to only call this when pasting. We no longer use it in 
    // CheckIfFlavorPresent() for this very reason.
    err = ::GetScrapFlavorData(scrap, inMacFlavor, &dataSize, dataBuff);
    NS_ASSERTION(err == noErr, "nsClipboard:: Error getting data off clipboard");
    if ( err ) {
      nsMemory::Free(dataBuff);
      return NS_ERROR_FAILURE;
    }

    if ((inMacFlavor & kPrivateFlavorMask) == kPrivateFlavorTag) {
      // Byte-swap private flavors if running translated
      nsCOMPtr<nsIMacUtils> macUtils =
       do_GetService("@mozilla.org/xpcom/mac-utils;1");
      PRBool isTranslated;
      if (macUtils &&
          NS_SUCCEEDED(macUtils->GetIsTranslated(&isTranslated)) &&
          isTranslated) {
        char* swappedData = (char*) nsMemory::Alloc(dataSize);
        if (!swappedData) {
          nsMemory::Free(dataBuff);
          return NS_ERROR_OUT_OF_MEMORY;
        }

        swab(dataBuff, swappedData, dataSize);
        nsMemory::Free(dataBuff);
        dataBuff = swappedData;
      }
    }

    // put it into the transferable
    if ( outDataSize )
      *outDataSize = dataSize;
    *outData = dataBuff;
  }
  return NS_OK;
  
} // GetDataOffClipboard

Here is the call graph for this function:

unsigned long nsClipboard::GetFlavourTimestamp ( char *  type) [private]

Definition at line 581 of file nsClipboard.cpp.

{
       char fname[512];
       extern struct _Ph_ctrl *_Ph_;

  strcpy( fname, "/var/clipboard/" );
  if( access( fname, X_OK ) != 0 )
              return 0;

       struct stat buf;
       if( fstat( _Ph_->fd, &buf ) != 0 )
              return 0;

  if(gethostname(&fname[strlen(fname)],PATH_MAX-40)!=0)
    strcpy(&fname[strlen(fname)],"localhost");

  sprintf( &fname[strlen(fname)], "/%08x/%d.%s",buf.st_uid, mInputGroup, type );
       struct stat st;
       if( stat( fname, &st ) != 0 )
              return 0;

       return st.st_mtime;
}

Here is the call graph for this function:

nsresult nsClipboard::GetFormat ( const char *  aMimeStr,
char *  format 
) [protected]

Definition at line 551 of file nsClipboard.cpp.

{
       nsDependentCString mimeStr(aMimeStr);
       int ret = NS_OK;

       if( mimeStr.Equals(kUnicodeMime) || mimeStr.Equals(kTextMime) )
       strcpy( format, Ph_CLIPBOARD_TYPE_TEXT );
       else if( mimeStr.Equals(kHTMLMime) )
       strcpy( format, Ph_CLIPBOARD_TYPE_HTML );
       else if (mimeStr.Equals("moz/bookmarkclipboarditem"))
       strcpy( format, Ph_CLIPBOARD_TYPE_MOZ_BOOKMARK );
       else ret = NS_ERROR_FAILURE;
       return ret;
}

Here is the caller graph for this function:

UINT nsClipboard::GetFormat ( const char *  aMimeStr) [static]

Definition at line 108 of file nsClipboard.cpp.

{
  UINT format;

  if (strcmp(aMimeStr, kTextMime) == 0)
    format = CF_TEXT;
  else if (strcmp(aMimeStr, kUnicodeMime) == 0)
    format = CF_UNICODETEXT;
#ifndef WINCE
  else if (strcmp(aMimeStr, kJPEGImageMime) == 0)
    format = CF_DIB;
  else if (strcmp(aMimeStr, kFileMime) == 0 || 
           strcmp(aMimeStr, kFilePromiseMime) == 0)
    format = CF_HDROP;
#endif
  else if (strcmp(aMimeStr, kURLMime) == 0 || 
           strcmp(aMimeStr, kURLDataMime) == 0 || 
           strcmp(aMimeStr, kURLDescriptionMime) == 0 || 
           strcmp(aMimeStr, kURLPrivateMime) == 0 || 
           strcmp(aMimeStr, kFilePromiseURLMime) == 0)
    format = CF_UNICODETEXT;
  else if (strcmp(aMimeStr, kNativeHTMLMime) == 0)
    format = CF_HTML;
  else
    format = ::RegisterClipboardFormat(aMimeStr);

  return format;
}

Here is the call graph for this function:

ULONG nsClipboard::GetFormatID ( const char *  aMimeStr) [protected]

Definition at line 404 of file nsClipboard.cpp.

{
  if (strcmp(aMimeStr, kTextMime) == 0)
    return CF_TEXT;

  return RegisterClipboardFormat(aMimeStr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsClipboard::GetGlobalData ( HGLOBAL  aHGBL,
void **  aData,
PRUint32 aLen 
) [static]

Definition at line 297 of file nsClipboard.cpp.

{
  // Allocate a new memory buffer and copy the data from global memory.
  // Recall that win98 allocates to nearest DWORD boundary. As a safety
  // precaution, allocate an extra 2 bytes (but don't report them!) and
  // null them out to ensure that all of our strlen calls will succeed.
  nsresult  result = NS_ERROR_FAILURE;
  if (aHGBL != NULL) {
    LPSTR lpStr = (LPSTR) GlobalLock(aHGBL);
    DWORD allocSize = GlobalSize(aHGBL);
    char* data = NS_STATIC_CAST(char*, nsMemory::Alloc(allocSize + sizeof(PRUnichar)));
    if ( data ) {    
      memcpy ( data, lpStr, allocSize );
      data[allocSize] = data[allocSize + 1] = '\0';     // null terminate for safety

      GlobalUnlock(aHGBL);
      *aData = data;
      *aLen = allocSize;

      result = NS_OK;
    }
  } 
  else {
    // We really shouldn't ever get here
    // but just in case
    *aData = nsnull;
    *aLen  = 0;
    LPVOID lpMsgBuf;

    FormatMessage( 
        FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
        NULL,
        GetLastError(),
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
        (LPTSTR) &lpMsgBuf,
        0,
        NULL 
    );

    // Display the string.
    MessageBox( NULL, (const char *)lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION );

    // Free the buffer.
    LocalFree( lpMsgBuf );    
  }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsClipboard::GetNativeClipboardData ( nsITransferable aTransferable,
PRInt32  aWhichClipboard 
) [protected, virtual]

Implements nsBaseClipboard.

Definition at line 245 of file nsClipboard.cpp.

{
#ifdef DEBUG_CLIPBOARD
  printf("  nsClipboard::GetNativeClipboardData()\n");
#endif /* DEBUG_CLIPBOARD */

  // make sure we have a good transferable
  if (nsnull == aTransferable) {
    printf("  GetNativeClipboardData: Transferable is null!\n");
    return NS_ERROR_FAILURE;
  }

  // get flavor list
  nsresult rv;
  nsCOMPtr<nsISupportsArray> flavorList;
  rv = aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList));
  if (NS_FAILED(rv))
    return NS_ERROR_FAILURE;

  // get native clipboard data
  if (!be_clipboard->Lock())
    return NS_ERROR_FAILURE;

  BMessage *msg = be_clipboard->Data();
  if (!msg)
    return NS_ERROR_FAILURE;  
#ifdef DEBUG_CLIPBOARD
  msg->PrintToStream();
#endif /* DEBUG_CLIPBOARD */

  PRUint32 cnt;
  flavorList->Count(&cnt);
  for (PRUint32 i = 0; i < cnt; i++) {
    nsCOMPtr<nsISupports> genericFlavor;
    flavorList->GetElementAt(i, getter_AddRefs(genericFlavor));
    nsCOMPtr<nsISupportsCString> currentFlavor(do_QueryInterface(genericFlavor));
    if (currentFlavor) {
      nsXPIDLCString flavorStr;
      currentFlavor->ToString(getter_Copies(flavorStr));

#ifdef DEBUG_CLIPBOARD
      printf("nsClipboard: %d/%d = %s\n", i, cnt, (const char *)flavorStr);
#endif /* DEBUG_CLIPBOARD */
      const void *data;
      ssize_t size;
      if (0 == strncmp(flavorStr, "text/", 5)) {
        // [Be] text/ * => [NS] text/ *
        status_t rc;
        if (0 == strcmp(flavorStr, kUnicodeMime))
          rc = msg->FindData(kTextMime, B_MIME_TYPE, &data, &size);
        else
          rc = msg->FindData(flavorStr, B_MIME_TYPE, &data, &size);
        if (rc != B_OK || !data || !size) {
#ifdef DEBUG_CLIPBOARD
          printf("nsClipboard: not found in BMessage\n");
#endif /* DEBUG_CLIPBOARD */
        } else {
          NS_ConvertUTF8toUTF16 ucs2Str((const char *)data, (PRUint32)size);
          nsCOMPtr<nsISupports> genericDataWrapper;
          nsPrimitiveHelpers::CreatePrimitiveForData(flavorStr, (void *)ucs2Str.get(), ucs2Str.Length() * 2, getter_AddRefs(genericDataWrapper));
          rv = aTransferable->SetTransferData(flavorStr, genericDataWrapper, ucs2Str.Length() * 2);
        }
      } else {
        // [Be] * / * => [NS] * / *
        if (B_OK != msg->FindData(flavorStr, B_MIME_TYPE, &data, &size)) {
#ifdef DEBUG_CLIPBOARD
          printf("nsClipboard: not found in BMessage\n");
#endif /* DEBUG_CLIPBOARD */
        } else {
          nsCOMPtr<nsISupports> genericDataWrapper;
          nsPrimitiveHelpers::CreatePrimitiveForData(flavorStr, (void *)data, (PRUint32)size, getter_AddRefs(genericDataWrapper));
          rv = aTransferable->SetTransferData(flavorStr, genericDataWrapper, size);
        }
      }
#ifdef DEBUG_CLIPBOARD
      if (NS_FAILED(rv))
        printf("nsClipboard: Error SetTransferData\n");
#endif /* DEBUG_CLIPBOARD */
    } else {
      rv = NS_ERROR_FAILURE;
#ifdef DEBUG_CLIPBOARD
      printf("nsClipboard: Error gerring flavor");
#endif /* DEBUG_CLIPBOARD */
    }
    if (rv != NS_OK)
      break;
  } /* for */

  be_clipboard->Unlock();

  return rv;
}

Here is the call graph for this function:

NS_IMETHOD nsClipboard::GetNativeClipboardData ( nsITransferable aTransferable,
PRInt32  aWhichClipboard 
) [protected, virtual]

Implements nsBaseClipboard.

NS_IMETHOD nsClipboard::GetNativeClipboardData ( nsITransferable aTransferable,
PRInt32  aWhichClipboard 
) [protected, virtual]

Implements nsBaseClipboard.

NS_IMETHOD nsClipboard::GetNativeClipboardData ( nsITransferable aTransferable,
PRInt32  aWhichClipboard 
) [protected, virtual]

Implements nsBaseClipboard.

NS_IMETHOD nsClipboard::GetNativeClipboardData ( nsITransferable aTransferable,
PRInt32  aWhichClipboard 
) [protected, virtual]

Implements nsBaseClipboard.

NS_IMETHOD nsClipboard::GetNativeClipboardData ( nsITransferable aTransferable,
PRInt32  aWhichClipboard 
) [protected, virtual]

Implements nsBaseClipboard.

NS_IMETHOD nsClipboard::GetNativeClipboardData ( nsITransferable aTransferable,
PRInt32  aWhichClipboard 
) [protected, virtual]

Implements nsBaseClipboard.

nsresult nsClipboard::GetNativeDataOffClipboard ( nsIWidget aWindow,
UINT  aIndex,
UINT  aFormat,
void **  aData,
PRUint32 aLen 
) [static]

Definition at line 347 of file nsClipboard.cpp.

{
  HGLOBAL   hglb; 
  nsresult  result = NS_ERROR_FAILURE;

  HWND nativeWin = nsnull;//(HWND)aWindow->GetNativeData(NS_NATIVE_WINDOW);
  if (::OpenClipboard(nativeWin)) { 
    hglb = ::GetClipboardData(aFormat); 
    result = GetGlobalData(hglb, aData, aLen);
    ::CloseClipboard();
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsClipboard::GetNativeDataOffClipboard ( IDataObject *  aDataObject,
UINT  aIndex,
UINT  aFormat,
void **  aData,
PRUint32 aLen 
) [static]

Definition at line 420 of file nsClipboard.cpp.

{
  nsresult result = NS_ERROR_FAILURE;
  *aData = nsnull;
  *aLen = 0;

  if ( !aDataObject )
    return result;

  UINT    format = aFormat;
  HRESULT hres   = S_FALSE;

  // XXX at the moment we only support global memory transfers
  // It is here where we will add support for native images 
  // and IStream
  FORMATETC fe;
  STGMEDIUM stm;
  hres = FillSTGMedium(aDataObject, format, &fe, &stm, TYMED_HGLOBAL);

  // Currently this is only handling TYMED_HGLOBAL data
  // For Text, Dibs, Files, and generic data (like HTML)
  if (S_OK == hres) {
    static CLIPFORMAT fileDescriptorFlavorA = ::RegisterClipboardFormat( CFSTR_FILEDESCRIPTORA ); 
    static CLIPFORMAT fileDescriptorFlavorW = ::RegisterClipboardFormat( CFSTR_FILEDESCRIPTORW ); 
#ifndef WINCE
    static CLIPFORMAT fileFlavor = ::RegisterClipboardFormat( CFSTR_FILECONTENTS ); 
#endif
    switch (stm.tymed) {
     case TYMED_HGLOBAL: 
        {
          switch (fe.cfFormat) {
            case CF_TEXT:
              {
                // Get the data out of the global data handle. The size we return
                // should not include the null because the other platforms don't
                // use nulls, so just return the length we get back from strlen(),
                // since we know CF_TEXT is null terminated. Recall that GetGlobalData() 
                // returns the size of the allocated buffer, not the size of the data 
                // (on 98, these are not the same) so we can't use that.
                PRUint32 allocLen = 0;
                if ( NS_SUCCEEDED(GetGlobalData(stm.hGlobal, aData, &allocLen)) ) {
                  *aLen = strlen ( NS_REINTERPRET_CAST(char*, *aData) );
                  result = NS_OK;
                }
              } break;

            case CF_UNICODETEXT:
              {
                // Get the data out of the global data handle. The size we return
                // should not include the null because the other platforms don't
                // use nulls, so just return the length we get back from strlen(),
                // since we know CF_UNICODETEXT is null terminated. Recall that GetGlobalData() 
                // returns the size of the allocated buffer, not the size of the data 
                // (on 98, these are not the same) so we can't use that.
                PRUint32 allocLen = 0;
                if ( NS_SUCCEEDED(GetGlobalData(stm.hGlobal, aData, &allocLen)) ) {
                  *aLen = nsCRT::strlen(NS_REINTERPRET_CAST(PRUnichar*, *aData)) * 2;
                  result = NS_OK;
                }
              } break;

#ifndef WINCE
            case CF_DIB :
              {
                PRUint32 allocLen = 0;
                unsigned char * clipboardData;
                nsresult rv = GetGlobalData(stm.hGlobal, (void **) &clipboardData, &allocLen);
                if (NS_SUCCEEDED(rv))
                {
                  nsImageFromClipboard converter;
                  nsIInputStream * inputStream;
                  converter.GetEncodedImageStream (clipboardData,  &inputStream );   // addrefs for us, don't release
                  if ( inputStream ) {
                    *aData = inputStream;
                    *aLen = sizeof(nsIInputStream*);
                    result = NS_OK;
                  }
                }
              } break;

            case CF_HDROP : 
              {
                // in the case of a file drop, multiple files are stashed within a
                // single data object. In order to match mozilla's D&D apis, we
                // just pull out the file at the requested index, pretending as
                // if there really are multiple drag items.
                HDROP dropFiles = (HDROP) GlobalLock(stm.hGlobal);

                UINT numFiles = nsToolkit::mDragQueryFile(dropFiles, 0xFFFFFFFF, NULL, 0);
                NS_ASSERTION ( numFiles > 0, "File drop flavor, but no files...hmmmm" );
                NS_ASSERTION ( aIndex < numFiles, "Asked for a file index out of range of list" );
                if (numFiles > 0) {
                  UINT fileNameLen = nsToolkit::mDragQueryFile(dropFiles, aIndex, nsnull, 0);
                  PRUnichar* buffer = NS_REINTERPRET_CAST(PRUnichar*, nsMemory::Alloc((fileNameLen + 1) * sizeof(PRUnichar)));
                  if ( buffer ) {
                    nsToolkit::mDragQueryFile(dropFiles, aIndex, buffer, fileNameLen + 1);
                    *aData = buffer;
                    *aLen = fileNameLen * sizeof(PRUnichar);
                    result = NS_OK;
                  }
                  else
                    result = NS_ERROR_OUT_OF_MEMORY;
                }
                GlobalUnlock (stm.hGlobal) ;

              } break;

#endif
            default: {
#ifndef WINCE
              if ( fe.cfFormat == fileDescriptorFlavorA || fe.cfFormat == fileDescriptorFlavorW || fe.cfFormat == fileFlavor ) {
                NS_WARNING ( "Mozilla doesn't yet understand how to read this type of file flavor" );
              } 
              else
#endif
              {
                // Get the data out of the global data handle. The size we return
                // should not include the null because the other platforms don't
                // use nulls, so just return the length we get back from strlen(),
                // since we know CF_UNICODETEXT is null terminated. Recall that GetGlobalData() 
                // returns the size of the allocated buffer, not the size of the data 
                // (on 98, these are not the same) so we can't use that.
                //
                // NOTE: we are assuming that anything that falls into this default case
                //        is unicode. As we start to get more kinds of binary data, this
                //        may become an incorrect assumption. Stay tuned.
                PRUint32 allocLen = 0;
                if ( NS_SUCCEEDED(GetGlobalData(stm.hGlobal, aData, &allocLen)) ) {
                  if ( fe.cfFormat == CF_HTML ) {
                    // CF_HTML is actually UTF8, not unicode, so disregard the assumption
                    // above. We have to check the header for the actual length, and we'll
                    // do that in FindPlatformHTML(). For now, return the allocLen. This
                    // case is mostly to ensure we don't try to call strlen on the buffer.
                    *aLen = allocLen;
                  }
                  else
                    *aLen = nsCRT::strlen(NS_REINTERPRET_CAST(PRUnichar*, *aData)) * sizeof(PRUnichar);
                  result = NS_OK;
                }
              }
            } break;
          } // switch
        } break;

      case TYMED_GDI: 
        {
#ifdef DEBUG
          printf("*********************** TYMED_GDI\n");
#endif
        } break;

      default:
        break;
    } //switch
    
    ReleaseStgMedium(&stm);
  }

  return result;
}

Here is the call graph for this function:

static GdkAtom nsClipboard::GetSelectionAtom ( PRInt32  aWhichClipboard) [static, private]
GdkAtom nsClipboard::GetSelectionAtom ( PRInt32  aWhichClipboard) [inline, private]

Definition at line 1138 of file nsClipboard.cpp.

{
  switch (aWhichClipboard)
  {
  case kGlobalClipboard:
    return GDK_SELECTION_CLIPBOARD;
  case kSelectionClipboard:
  default:
    return GDK_SELECTION_PRIMARY;
  }
}

Here is the caller graph for this function:

static GtkSelectionData* nsClipboard::GetTargets ( GdkAtom  aWhichClipboard) [static, private]
GtkSelectionData * nsClipboard::GetTargets ( GdkAtom  aSelectionAtom) [private]

Definition at line 1222 of file nsClipboard.cpp.

{
#ifdef DEBUG_CLIPBOARD
  g_print("    nsClipboard::GetTargets(%d)\n    {\n", aSelectionAtom);
#endif

  // Set a flag saying that we're blocking waiting for the callback:
  mBlocking = PR_TRUE;

  //
  // ask X what kind of data we can get
  //
  static GdkAtom targetsAtom = gdk_atom_intern("TARGETS", PR_FALSE);

  gtk_selection_convert(sWidget,
                        aSelectionAtom,
                        targetsAtom,
                        GDK_CURRENT_TIME);

  /* see comment in DoRealConvert for why we check for mBlocking here */
  if (mBlocking) {
    // Now we need to wait until the callback comes in ...
#ifdef DEBUG_CLIPBOARD
    g_print("      Waiting for the callback... mBlocking = %d\n", mBlocking);
#endif /* DEBUG_CLIPBOARD */

    if (!FindSelectionNotifyEvent())
      return PR_FALSE;

  }

#ifdef DEBUG_CLIPBOARD
  g_print("    }\n");
#endif

  if (mSelectionData.length <= 0)
    return PR_FALSE;

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsITransferable* nsClipboard::GetTransferable ( PRInt32  aWhichClipboard) [protected]
nsITransferable* nsClipboard::GetTransferable ( PRInt32  aWhichClipboard) [private]
nsITransferable* nsClipboard::GetTransferable ( PRInt32  aWhichClipboard) [inline, protected]
nsITransferable * nsClipboard::GetTransferable ( PRInt32  aWhichClipboard) [inline, protected]

Definition at line 1151 of file nsClipboard.cpp.

{
  nsITransferable *transferable = nsnull;
  switch (aWhichClipboard)
  {
  case kGlobalClipboard:
    transferable = mGlobalTransferable;
    break;
  case kSelectionClipboard:
    transferable = mSelectionTransferable;
    break;
  }
  return transferable;
}

Here is the caller graph for this function:

nsITransferable* nsClipboard::GetTransferable ( PRInt32  aWhichClipboard) [inline, protected]
NS_IMETHODIMP nsClipboard::HasDataMatchingFlavors ( nsISupportsArray aFlavorList,
PRInt32  aWhichClipboard,
PRBool _retval 
)

Definition at line 756 of file nsClipboard.cpp.

{
  // XXX this doesn't work right.  need to fix it.
  
  // Note to implementor...(from pink the clipboard bitch).
  //
  // If a client asks for unicode, first check if unicode is present. If not, then 
  // check for plain text. If it's there, say "yes" as we will do the conversion
  // in GetNativeClipboardData(). From this point on, no client will
  // ever ask for text/plain explicitly. If they do, you must ASSERT!
#ifdef DEBUG_CLIPBOARD
  g_print("  nsClipboard::HasDataMatchingFlavors()\n  {\n");
#endif


  GetTargets(GetSelectionAtom(aWhichClipboard));

  guchar *data = mSelectionData.data;
  PRInt32 dataLength = mSelectionData.length;
  int position = 0;
  gchar *str;


  *outResult = PR_FALSE;
  PRUint32 length;
  aFlavorList->Count(&length);
  for ( PRUint32 i = 0; i < length; ++i ) {
    nsCOMPtr<nsISupports> genericFlavor;
    aFlavorList->GetElementAt ( i, getter_AddRefs(genericFlavor) );
    nsCOMPtr<nsISupportsCString> flavorWrapper ( do_QueryInterface(genericFlavor) );
    if ( flavorWrapper ) {
      nsCAutoString flavorStr;
      nsXPIDLCString myStr;
      flavorWrapper->ToString(getter_Copies(myStr));
      flavorStr = nsCAutoString(myStr);

      position = 0;
      while (position < dataLength) {
        str = gdk_atom_name(*(GdkAtom*)(data+position));
        position += sizeof(GdkAtom);
        nsCAutoString atomName(str);
        g_free(str);
        
        if (flavorStr.Equals(kUnicodeMime)) {
          if (atomName.Equals("COMPOUND_TEXT") ||
              atomName.Equals("UTF8_STRING") ||
              atomName.Equals("STRING")) {
#ifdef DEBUG_CLIPBOARD
            g_print("    Selection owner has matching type: %s\n", atomName.mBuffer);
#endif
            *outResult = PR_TRUE;
            break;
          }
        }
        if (flavorStr.Equals(atomName)) {
#ifdef DEBUG_CLIPBOARD
          g_print("    Selection owner has matching type: %s\n", atomName.mBuffer);
#endif
          *outResult = PR_TRUE;
          break;
        }
      }
    }
  }
#ifdef DEBUG_CLIPBOARD
  g_print("    returning %i\n  }\n", *outResult);
#endif

  nsMemory::Free(mSelectionData.data);
  mSelectionData.data = nsnull;
  mSelectionData.length = 0;

  return NS_OK;

}

Here is the call graph for this function:

NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSIOBSERVER NS_IMETHOD nsClipboard::HasDataMatchingFlavors ( nsISupportsArray aFlavorList,
PRInt32  aWhichClipboard,
PRBool _retval 
)
NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSIOBSERVER NS_IMETHOD nsClipboard::HasDataMatchingFlavors ( nsISupportsArray aFlavorList,
PRInt32  aWhichClipboard,
PRBool _retval 
)
boolean nsIClipboard::hasDataMatchingFlavors ( in nsISupportsArray  aFlavorList,
in long  aWhichClipboard 
) [inherited]

This provides a way to give correct UI feedback about, for instance, a paste should be allowed.

It does NOT actually retreive the data and should be a very inexpensive call. All it does is check if there is data on the clipboard matching any of the flavors in the given list.

- nsISupportsCString's in a nsISupportsArray (for JavaScript).

Parameters:
aWhichClipboardSpecifies the clipboard to which this operation applies. - if data is present matching one of
Returns:
NS_OK if successful.
NS_DECL_ISUPPORTS NS_DECL_NSICLIPBOARD nsresult nsClipboard::Init ( void  )
void nsClipboard::Init ( void  ) [protected]

Definition at line 192 of file nsClipboard.cpp.

{
#ifdef DEBUG_CLIPBOARD
  g_print("nsClipboard::Init\n");
#endif

  GDK_SELECTION_CLIPBOARD = gdk_atom_intern("CLIPBOARD", FALSE);

  // create invisible widget to use for the clipboard
  sWidget = gtk_invisible_new();

  // add the clipboard pointer to the widget so we can get it.
  gtk_object_set_data(GTK_OBJECT(sWidget), "cb", this);

  // Handle selection requests if we called gtk_selection_add_target:
  gtk_signal_connect(GTK_OBJECT(sWidget), "selection_get",
                     GTK_SIGNAL_FUNC(nsClipboard::SelectionGetCB),
                     nsnull);

  // When someone else takes the selection away:
  gtk_signal_connect(GTK_OBJECT(sWidget), "selection_clear_event",
                     GTK_SIGNAL_FUNC(nsClipboard::SelectionClearCB),
                     nsnull);

  // Set up the paste handler:
  gtk_signal_connect(GTK_OBJECT(sWidget), "selection_received",
                     GTK_SIGNAL_FUNC(nsClipboard::SelectionReceivedCB),
                     nsnull);
}

Here is the call graph for this function:

void nsClipboard::Init ( void  ) [protected]
PRBool nsClipboard::IsInternetShortcut ( const nsAString &  inFileName) [static, protected]

Definition at line 834 of file nsClipboard.cpp.

{
  return StringEndsWith(inFileName, NS_LITERAL_STRING(".url"), nsCaseInsensitiveStringComparator());
} // IsInternetShortcut

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIObserver::observe ( in nsISupports  aSubject,
in string  aTopic,
in wstring  aData 
) [inherited]

Observe will be called when there is a notification for the topic |aTopic|.

This assumes that the object implementing this interface has been registered with an observer service such as the nsIObserverService.

If you expect multiple topics/subjects, the impl is responsible for filtering.

You should not modify, add, remove, or enumerate notifications in the implemention of observe.

Parameters:
aSubject: Notification specific interface pointer.
aTopic: The notification topic or subject.
aData: Notification specific wide string. subject event.
nsresult nsClipboard::PutOnClipboard ( ResType  inFlavor,
const void inData,
PRInt32  inLen 
) [protected]

Definition at line 331 of file nsClipboard.cpp.

{
  nsresult errCode = NS_OK;

  void* data = (void*) inData;
  if ((inFlavor & kPrivateFlavorMask) == kPrivateFlavorTag) {
    // Byte-swap private flavors if running translated
    nsCOMPtr<nsIMacUtils> macUtils =
     do_GetService("@mozilla.org/xpcom/mac-utils;1");
    PRBool isTranslated;
    if (macUtils &&
        NS_SUCCEEDED(macUtils->GetIsTranslated(&isTranslated)) &&
        isTranslated) {
      data = nsMemory::Alloc(inLen);
      if (!data)
        return NS_ERROR_OUT_OF_MEMORY;

      swab(inData, data, inLen);
    }
  }
  
  ScrapRef scrap;
  ::GetCurrentScrap(&scrap);
  ::PutScrapFlavor( scrap, inFlavor, kScrapFlavorMaskNone, inLen, data );

  if (data != inData)
    nsMemory::Free(data);

  return errCode;
  
} // PutOnClipboard

Here is the call graph for this function:

void nsClipboard::RegisterFormat ( const char *  aMimeStr,
GdkAtom  aSelectionAtom 
) [private]

Definition at line 1172 of file nsClipboard.cpp.

{
#ifdef DEBUG_CLIPBOARD
  g_print("  nsClipboard::RegisterFormat(%s)\n", aMimeStr);
#endif
  nsCAutoString mimeStr(aMimeStr);

  GdkAtom atom = gdk_atom_intern(aMimeStr, FALSE);

  // for Text and Unicode we want to add some extra types to the X clipboard
  if (mimeStr.Equals(kUnicodeMime)) {
    // we will do the conversions to and from unicode internally
    // anyone asking for TEXT will get COMPOUND_TEXT
    AddTarget(gdk_atom_intern("TEXT", FALSE), aSelectionAtom); 
    AddTarget(gdk_atom_intern("COMPOUND_TEXT", FALSE), aSelectionAtom);
    AddTarget(gdk_atom_intern("UTF8_STRING", FALSE), aSelectionAtom);
    AddTarget(GDK_SELECTION_TYPE_STRING, aSelectionAtom);
  }

  AddTarget(atom, aSelectionAtom);
}

Here is the call graph for this function:

void nsClipboard::ResolveShortcut ( nsILocalFile inFileName,
nsACString &  outURL 
) [static, protected]

Definition at line 812 of file nsClipboard.cpp.

{
  nsCOMPtr<nsIFileProtocolHandler> fph;
  nsresult rv = NS_GetFileProtocolHandler(getter_AddRefs(fph));
  if (NS_FAILED(rv))
    return;

  nsCOMPtr<nsIURI> uri;
  rv = fph->ReadURLFile(aFile, getter_AddRefs(uri));
  if (NS_FAILED(rv))
    return;

  uri->GetSpec(outURL);
} // ResolveShortcut

Here is the call graph for this function:

Here is the caller graph for this function:

void nsClipboard::SelectionClearCB ( GtkWidget *  aWidget,
GdkEventSelection *  aEvent,
gpointer  aData 
) [static, private]

Called when another app requests selection ownership.

Parameters:
aWidgetthe widget
aEventthe GdkEvent for the selection
aDatavalue passed in from the callback init

Definition at line 1066 of file nsClipboard.cpp.

{
#ifdef DEBUG_CLIPBOARD
  g_print("  nsClipboard::SelectionClearCB\n");
#endif /* DEBUG_CLIPBOARD */

  if (!aWidget) {
    NS_ASSERTION(PR_FALSE, "Null widget passed to SelectionClearCB)\n");
    return;
  }

  if (!aEvent) {
    NS_ASSERTION(PR_FALSE, "Null event passed to SelectionClearCB)\n");
    return;
  }

  nsClipboard *cb = (nsClipboard *)gtk_object_get_data(GTK_OBJECT(aWidget),
                                                       "cb");

  if (aEvent->selection == GDK_SELECTION_PRIMARY) {
#ifdef DEBUG_CLIPBOARD
    g_print("clearing PRIMARY clipboard\n");
#endif
    cb->EmptyClipboard(kSelectionClipboard);
  } else if (aEvent->selection == GDK_SELECTION_CLIPBOARD) {
#ifdef DEBUG_CLIPBOARD
    g_print("clearing CLIPBOARD clipboard\n");
#endif
    cb->EmptyClipboard(kGlobalClipboard);
  }
}

Here is the caller graph for this function:

void nsClipboard::SelectionClearEvent ( GtkWidget *  aWidget,
GdkEventSelection *  aEvent 
)

Definition at line 564 of file nsClipboard.cpp.

{
    PRInt32 whichClipboard;

    // which clipboard?
    if (aEvent->selection == GDK_SELECTION_PRIMARY)
        whichClipboard = kSelectionClipboard;
    else if (aEvent->selection == GDK_SELECTION_CLIPBOARD)
        whichClipboard = kGlobalClipboard;
    else
        return; // THAT AINT NO CLIPBOARD I EVER HEARD OF

    EmptyClipboard(whichClipboard);
}

Here is the caller graph for this function:

void nsClipboard::SelectionGetCB ( GtkWidget *  widget,
GtkSelectionData *  aSelectionData,
guint  aInfo,
guint  aTime 
) [static, private]

This is the callback which is called when another app requests the selection.

Parameters:
widgetThe widget
aSelectionDataSelection data
infoValue passed in from the callback init
timeTime when the selection request came in
widgetThe widget
aSelectionDataSelection data
thetype being asked for
timeTime when the selection request came in

Definition at line 843 of file nsClipboard.cpp.

{
#ifdef DEBUG_CLIPBOARD
  g_print("nsClipboard::SelectionGetCB\n"); 
#endif
  nsClipboard *cb = (nsClipboard *)gtk_object_get_data(GTK_OBJECT(widget),
                                                       "cb");

  void     *clipboardData;
  PRUint32 dataLength;
  nsresult rv;

  PRInt32 whichClipboard = -1;

  if (aSelectionData->selection == GDK_SELECTION_PRIMARY)
    whichClipboard = kSelectionClipboard;
  else if (aSelectionData->selection == GDK_SELECTION_CLIPBOARD)
    whichClipboard = kGlobalClipboard;

#ifdef DEBUG_CLIPBOARD
  g_print("  whichClipboard = %d\n", whichClipboard);
#endif
  nsCOMPtr<nsITransferable> transferable(cb->GetTransferable(whichClipboard));

  // Make sure we have a transferable:
  if (!transferable) {
#ifdef DEBUG_CLIPBOARD
    g_print("Clipboard has no transferable!\n");
#endif
    return;
  }
#ifdef DEBUG_CLIPBOARD
  g_print("  aInfo == %s\n  transferable == %p\n", gdk_atom_name(aInfo), transferable.get());
  g_print("  aSD->type == %s\n  aSD->target == %s\n", gdk_atom_name(aSelectionData->type),
          gdk_atom_name(aSelectionData->target));
#endif
  const char *dataFlavor = nsnull;
  char *tstr = gdk_atom_name(aInfo);
  nsCAutoString type(tstr);
  g_free(tstr);

  if (type.Equals("STRING") ||
      type.Equals("UTF8_STRING") ||
      type.Equals("COMPOUND_TEXT") ||
      type.Equals("TEXT"))
  {
    dataFlavor = kUnicodeMime;
  } else {
    dataFlavor = type.get();
  }

  // Get data out of transferable.
  nsCOMPtr<nsISupports> genericDataWrapper;
  rv = transferable->GetTransferData(dataFlavor,
                                     getter_AddRefs(genericDataWrapper),
                                     &dataLength);
  nsPrimitiveHelpers::CreateDataFromPrimitive ( dataFlavor, genericDataWrapper, &clipboardData, dataLength );
  if (NS_SUCCEEDED(rv) && clipboardData && dataLength > 0) {
    size_t size = 1;
    // find the number of bytes in the data for the below thing
    //    size_t size = sizeof((void*)((unsigned char)clipboardData[0]));
    //    g_print("************  *****************      ******************* %i\n", size);
    

#ifdef DEBUG_CLIPBOARD
    printf("got data from transferable\n");
    printf("clipboardData is %s\n", clipboardData);
    printf("length is %d\n", dataLength);
#endif

    if (type.Equals("STRING")) {
      // if someone was asking for text/plain, lookup unicode instead so we can convert it.
      char* plainTextData = nsnull;
      PRUnichar* castedUnicode = NS_REINTERPRET_CAST(PRUnichar*, clipboardData);
      PRInt32 plainTextLen = 0;
      nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText (castedUnicode, dataLength / 2,
                                                             &plainTextData, &plainTextLen);
      if (clipboardData) {
        nsMemory::Free(NS_REINTERPRET_CAST(char*, clipboardData));
        clipboardData = plainTextData;
        dataLength = plainTextLen;
      }
    } else if (type.Equals("UTF8_STRING")) {
      if (clipboardData) {
        PRUnichar* castedUnicode = NS_REINTERPRET_CAST(PRUnichar*, clipboardData);
        char *utf8String =
            ToNewUTF8String(nsDependentString(castedUnicode, dataLength/2));
        nsMemory::Free(NS_REINTERPRET_CAST(char*, clipboardData));
        clipboardData = utf8String;
        dataLength = strlen(utf8String);
      }
    } else if (type.Equals(kHTMLMime)) {
      if (clipboardData) {
        /*
         * "text/html" can be encoded UCS2. It is recommended that
         * documents transmitted as UCS2 always begin with a ZERO-WIDTH
         * NON-BREAKING SPACE character (hexadecimal FEFF, also called
         * Byte Order Mark (BOM)). Adding BOM can help other app to
         * detect mozilla use UCS2 encoding when copy-paste.
         */

        char *buffer = NS_STATIC_CAST(char *,
                         nsMemory::Alloc((dataLength + 2) * sizeof(char)));
        if (buffer) {
          PRUnichar prefix = 0xFEFF;
          memcpy(buffer, &prefix, 2);
          memcpy(buffer + 2, clipboardData, dataLength);
          nsMemory::Free(NS_REINTERPRET_CAST(char*, clipboardData));
          clipboardData = NS_REINTERPRET_CAST(char*, buffer);
          dataLength = dataLength + 2;
        }
      }
    } else if (type.Equals("COMPOUND_TEXT") || type.Equals("TEXT")) {
      if (type.Equals("TEXT")) {
        // if we get a request for  TEXT, return COMPOUND_TEXT
        aInfo = gdk_atom_intern("COMPOUND_TEXT", FALSE);
      }
      char *platformText;
      PRInt32 platformLen;
      // Get the appropriate unicode encoder. We're guaranteed that this won't change
      // through the life of the app so we can cache it.

      nsCOMPtr<nsIUnicodeEncoder> encoder;
      // get the charset
      nsCAutoString platformCharset;
      nsCOMPtr <nsIPlatformCharset> platformCharsetService = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
      if (NS_SUCCEEDED(rv))
        rv = platformCharsetService->GetCharset(kPlatformCharsetSel_Menu, platformCharset);
      if (NS_FAILED(rv))
        platformCharset.AssignLiteral("ISO-8859-1");
      
      // get the encoder
      nsCOMPtr<nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
      rv = ccm->GetUnicodeEncoderRaw(platformCharset.get(), getter_AddRefs(encoder));
      NS_ASSERTION(NS_SUCCEEDED(rv), "GetUnicodeEncoderRaw failed");
      if (NS_FAILED(rv)) {
        nsMemory::Free(NS_REINTERPRET_CAST(char*, clipboardData));
        return;
      }

      encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, '?');

      // Estimate out length and allocate the buffer based on a worst-case estimate, then do
      // the conversion.
      PRUnichar *castedData = NS_REINTERPRET_CAST(PRUnichar*, clipboardData);
      encoder->GetMaxLength(castedData, dataLength/2, &platformLen);
      if ( platformLen ) {
        platformText = NS_REINTERPRET_CAST(char*, nsMemory::Alloc(platformLen + sizeof(char)));
        if ( platformText ) {
          PRInt32 len = (PRInt32)dataLength/2;
          rv = encoder->Convert(castedData, &len, platformText, &platformLen);
          (platformText)[platformLen] = '\0';  // null terminate. Convert() doesn't do it for us
        }
 } // if valid length

      if (platformLen > 0) {
        int status = 0;
        XTextProperty prop;

#ifdef DEBUG_CLIPBOARD
        g_print("\nConverted text from unicode to platform locale\n");
        g_print("platformText is %s\n", platformText);
        g_print("platformLen is %d\n", platformLen);
#endif

        status = XmbTextListToTextProperty(GDK_DISPLAY(), &platformText, 1, XCompoundTextStyle,
                                           &prop);

        if (status == Success) {
#ifdef DEBUG_CLIPBOARD
          g_print("\nXmbTextListToTextProperty succeeded\n  text is %s\n  length is %d\n", prop.value,
                  prop.nitems);
#endif
          nsMemory::Free(platformText);
          platformText = (char *)prop.value;
          platformLen = prop.nitems;
        }
      }

#ifdef DEBUG_CLIPBOARD
      g_print("\nFinished trying to convert to platform charset\n");
#endif

      if (clipboardData) {
        nsMemory::Free(NS_REINTERPRET_CAST(char*, clipboardData));
        clipboardData = platformText;
        dataLength = platformLen;
      }
    }
#ifdef DEBUG_CLIPBOARD
    g_print("\nPutting data on clipboard:\n");
    g_print("  clipboardData is %s\n", clipboardData);
    g_print("  length is %d\n", dataLength);
#endif
    if (clipboardData && dataLength > 0)
      gtk_selection_data_set(aSelectionData,
                             aInfo, size*8,
                             NS_REINTERPRET_CAST(unsigned char *, clipboardData),
                             dataLength);
    else
      gtk_selection_data_set(aSelectionData,
                             gdk_atom_intern("NULL", FALSE), 8,
                             nsnull, 0);
    nsMemory::Free ( NS_REINTERPRET_CAST(char*, clipboardData) );
  }
#ifdef DEBUG_pavlov
  else
    printf("Transferable didn't support data flavor %s (type = %d)\n",
           dataFlavor ? dataFlavor : "None", aInfo);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsClipboard::SelectionGetEvent ( GtkWidget *  aWidget,
GtkSelectionData *  aSelectionData,
guint  aTime 
)

Definition at line 457 of file nsClipboard.cpp.

{
    // Someone has asked us to hand them something.  The first thing
    // that we want to do is see if that something includes text.  If
    // it does, try to give it text/unicode after converting it to
    // utf-8.

    PRInt32 whichClipboard;

    // which clipboard?
    if (aSelectionData->selection == GDK_SELECTION_PRIMARY)
        whichClipboard = kSelectionClipboard;
    else if (aSelectionData->selection == GDK_SELECTION_CLIPBOARD)
        whichClipboard = kGlobalClipboard;
    else
        return; // THAT AINT NO CLIPBOARD I EVER HEARD OF

    nsCOMPtr<nsITransferable> trans = GetTransferable(whichClipboard);
    
    nsresult rv;
    nsCOMPtr<nsISupports> item;
    PRUint32 len;

    // Check to see if the selection data includes any of the string
    // types that we support.
    if (aSelectionData->target == gdk_atom_intern ("STRING", FALSE) ||
        aSelectionData->target == gdk_atom_intern ("TEXT", FALSE) ||
        aSelectionData->target == gdk_atom_intern ("COMPOUND_TEXT", FALSE) ||
        aSelectionData->target == gdk_atom_intern ("UTF8_STRING", FALSE)) {
        // Try to convert our internal type into a text string.  Get
        // the transferable for this clipboard and try to get the
        // text/unicode type for it.
        rv = trans->GetTransferData("text/unicode", getter_AddRefs(item),
                                    &len);
        if (!item || NS_FAILED(rv))
            return;
        
        nsCOMPtr<nsISupportsString> wideString;
        wideString = do_QueryInterface(item);
        if (!wideString)
            return;

        nsAutoString ucs2string;
        wideString->GetData(ucs2string);
        char *utf8string = ToNewUTF8String(ucs2string);
        if (!utf8string)
            return;
        
        gtk_selection_data_set_text (aSelectionData, utf8string,
                                     strlen(utf8string));

        nsMemory::Free(utf8string);
        return;
    }

    // Try to match up the selection data target to something our
    // transferable provides.
    gchar *target_name = gdk_atom_name(aSelectionData->target);
    if (!target_name)
        return;

    rv = trans->GetTransferData(target_name, getter_AddRefs(item), &len);
    // nothing found?
    if (!item || NS_FAILED(rv)) {
        g_free(target_name);
        return;
    }

    void *primitive_data = nsnull;
    nsPrimitiveHelpers::CreateDataFromPrimitive(target_name, item,
                                                &primitive_data, len);

    if (primitive_data) {
        // Check to see if the selection data is text/html
        if (aSelectionData->target == gdk_atom_intern (kHTMLMime, FALSE)) {
            /*
             * "text/html" can be encoded UCS2. It is recommended that
             * documents transmitted as UCS2 always begin with a ZERO-WIDTH
             * NON-BREAKING SPACE character (hexadecimal FEFF, also called
             * Byte Order Mark (BOM)). Adding BOM can help other app to
             * detect mozilla use UCS2 encoding when copy-paste.
             */
            guchar *buffer = (guchar *)
                    nsMemory::Alloc((len * sizeof(guchar)) + sizeof(PRUnichar));
            if (!buffer)
                return;
            PRUnichar prefix = 0xFEFF;
            memcpy(buffer, &prefix, sizeof(prefix));
            memcpy(buffer + sizeof(prefix), primitive_data, len);
            nsMemory::Free((guchar *)primitive_data);
            primitive_data = (guchar *)buffer;
            len += sizeof(prefix);
        }
  
        gtk_selection_data_set(aSelectionData, aSelectionData->target,
                               8, /* 8 bits in a unit */
                               (const guchar *)primitive_data, len);
        nsMemory::Free(primitive_data);
    }

    g_free(target_name);
                           
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsClipboard::SelectionNotifyCB ( GtkWidget *  aWidget,
GtkSelectionData *  aSelectionData,
gpointer  aData 
) [static, private]

...

Parameters:
aWidgetthe widget
aSelectionDatagtk selection stuff
aDatavalue passed in from the callback init

Definition at line 1126 of file nsClipboard.cpp.

{
#ifdef DEBUG_CLIPBOARD
  g_print("  nsClipboard::SelectionNotifyCB\n");
#endif /* DEBUG_CLIPBOARD */
}
void nsClipboard::SelectionReceivedCB ( GtkWidget *  aWidget,
GtkSelectionData *  aSelectionData,
guint  aTime 
) [static, private]

Called when the data from a paste comes in.

Called when the data from a paste comes in (recieved from gdk_selection_convert)

Parameters:
aWidgetthe widget
aSelectionDatagtk selection stuff
aTimetime the selection was requested

Definition at line 519 of file nsClipboard.cpp.

{
#ifdef DEBUG_CLIPBOARD
  g_print("      nsClipboard::SelectionReceivedCB\n      {\n");
#endif /* DEBUG_CLIPBOARD */
  nsClipboard *cb =(nsClipboard *)gtk_object_get_data(GTK_OBJECT(aWidget),
                                                      "cb");
  if (!cb)
  {
#ifdef DEBUG_CLIPBOARD
    g_print("no clipboard found.. this is bad.\n");
#endif
    return;
  }
  cb->SelectionReceiver(aWidget, aSelectionData);
#ifdef DEBUG_CLIPBOARD
  g_print("      }\n");
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsClipboard::SelectionReceiver ( GtkWidget *  aWidget,
GtkSelectionData *  aSD 
) [private]

local method (called from nsClipboard::SelectionReceivedCB)

Parameters:
aWidgetthe widget
aSelectionDatagtk selection stuff

Definition at line 549 of file nsClipboard.cpp.

{
  mBlocking = PR_FALSE;

  if (aSD->length <= 0)
  {
#ifdef DEBUG_CLIPBOARD
    g_print("        Error retrieving selection: length was %d\n", aSD->length);
#endif
    mSelectionData.length = aSD->length;
    return;
  }

  char *str = gdk_atom_name(aSD->type);
  nsCAutoString type(str);
  g_free(str);

#ifdef DEBUG_CLIPBOARD
  g_print("        Type is %s\n", type.mBuffer);

  if (type.Equals("ATOM")) {
    g_print("        Asked for TARGETS\n");
  }
#endif

  if (type.Equals("COMPOUND_TEXT")) {
#ifdef DEBUG_CLIPBOARD
    g_print("        Copying mSelectionData pointer -- \n");
#endif
    mSelectionData = *aSD;

    char *data = (char*)aSD->data;
    PRInt32 len = (PRInt32)aSD->length;

    int status = 0;
    XTextProperty prop;

#ifdef DEBUG_CLIPBOARD
    g_print("        Converted text from COMPOUND_TEXT to platform locale\n");
    g_print("        data is %s\n", data);
    g_print("        len is %d\n", len);
#endif

    prop.value = (unsigned char *)data;
    prop.nitems = len;
    prop.encoding = XInternAtom(GDK_DISPLAY(), "COMPOUND_TEXT", FALSE);
    prop.format = 8;

    char **tmpData;
    int foo;
    status = XmbTextPropertyToTextList(GDK_DISPLAY(), &prop, &tmpData, &foo);

#ifdef DEBUG_CLIPBOARD
    if (foo > 1)
      printf("Got multiple strings from XmbTextPropertyToTextList.. don't know how to handle this yet\n");
#endif

    PRInt32 numberOfBytes = 0;

    if (status == XNoMemory || status == XLocaleNotSupported ||
        status == XConverterNotFound) {
#ifdef DEBUG_CLIPBOARD
      g_print("\n         XmbTextListToTextProperty failed.  returned %d\n", status);
      g_print("          text is \"%s\"\n", tmpData[0]);
#endif
      numberOfBytes = strlen(NS_REINTERPRET_CAST(const char *, data));
    } else {
      if (foo > 0 && tmpData[0] != 0 && (*tmpData[0]) != 0) {
        data = tmpData[0];
      }
      numberOfBytes = strlen(NS_REINTERPRET_CAST(const char *, data));
#ifdef DEBUG_CLIPBOARD
      g_print("\n        XmbTextListToTextProperty succeeded\n");
      g_print("          text is \"%s\"\n", data);
      g_print("          numberOfBytes is %d\n", numberOfBytes);
#endif
    }

    nsresult rv;
    PRInt32 outUnicodeLen;
    PRUnichar *unicodeData = nsnull;

#ifdef DEBUG_CLIPBOARD
    g_print("        Converting from current locale to unicode\n");
#endif

    nsCOMPtr<nsIUnicodeDecoder> decoder;
    // get the charset
    nsCAutoString platformCharset;
    nsCOMPtr <nsIPlatformCharset> platformCharsetService = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
    if (NS_SUCCEEDED(rv))
      rv = platformCharsetService->GetCharset(kPlatformCharsetSel_Menu, platformCharset);
    if (NS_FAILED(rv))
      platformCharset.AssignLiteral("ISO-8859-1");
      
    // get the decoder
    nsCOMPtr<nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
    rv = ccm->GetUnicodeDecoderRaw(platformCharset.get(),
                                   getter_AddRefs(decoder));
    NS_ASSERTION(NS_SUCCEEDED(rv), "GetUnicodeEncoderRaw failed");
    if (NS_FAILED(rv)) {
      if (tmpData) XFreeStringList(tmpData);
      return;
    }
      
    // Estimate out length and allocate the buffer based on a worst-case estimate, then do
    // the conversion. 
    decoder->GetMaxLength(data, numberOfBytes, &outUnicodeLen);   // |outUnicodeLen| is number of chars
    if (outUnicodeLen) {
      unicodeData = NS_REINTERPRET_CAST(PRUnichar*, nsMemory::Alloc((outUnicodeLen + 1) * sizeof(PRUnichar)));
      if ( unicodeData ) {
        PRInt32 numberTmp = numberOfBytes;
        rv = decoder->Convert(data, &numberTmp, unicodeData, &outUnicodeLen);
#ifdef DEBUG_CLIPBOARD
        if (numberTmp != numberOfBytes)
          printf("didn't consume all the bytes\n");
#endif

        (unicodeData)[outUnicodeLen] = '\0';    // null terminate. Convert() doesn't do it for us
      }
    } // if valid length


    mSelectionData.data = NS_REINTERPRET_CAST(guchar*,unicodeData);
    mSelectionData.length = outUnicodeLen * 2;
    if (tmpData) XFreeStringList(tmpData);
  }
  else if (type.Equals("UTF8_STRING")) {
    mSelectionData = *aSD;

    nsresult rv;
    PRInt32 outUnicodeLen;
    PRUnichar *unicodeData = nsnull;

    char *data = (char*)aSD->data;
    PRInt32 numberOfBytes = (PRInt32)aSD->length;

#ifdef DEBUG_CLIPBOARD
    printf("UTF8_STRING is %s\nlength is %i\n", aSD->data, aSD->length);
#endif

    // get the decoder
    nsCOMPtr<nsIUnicodeDecoder> decoder;
    nsCOMPtr<nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
    rv = ccm->GetUnicodeDecoderRaw("UTF-8", getter_AddRefs(decoder));

    g_return_if_fail(NS_SUCCEEDED(rv));

    decoder->GetMaxLength(data, numberOfBytes, &outUnicodeLen);   // |outUnicodeLen| is number of chars
    if (outUnicodeLen) {
      unicodeData = NS_REINTERPRET_CAST(PRUnichar*, nsMemory::Alloc((outUnicodeLen + 1) * sizeof(PRUnichar)));
      if ( unicodeData ) {
        PRInt32 numberTmp = numberOfBytes;
        rv = decoder->Convert(data, &numberTmp, unicodeData, &outUnicodeLen);
#ifdef DEBUG_CLIPBOARD
        if (numberTmp != numberOfBytes)
          printf("didn't consume all the bytes\n");
#endif

        (unicodeData)[outUnicodeLen] = '\0';    // null terminate. Convert() doesn't do it for us
      }
    } // if valid length


    mSelectionData.data = NS_REINTERPRET_CAST(guchar*,unicodeData);
    mSelectionData.length = outUnicodeLen * 2;
    mSelectionData.type = gdk_atom_intern(kUnicodeMime, FALSE);

  } else if (type.Equals("STRING")) {
#ifdef DEBUG_CLIPBOARD
    g_print("        Copying mSelectionData pointer -- \n");
    g_print("         Data = %s\n         Length = %i\n", aSD->data, aSD->length);
#endif
    mSelectionData = *aSD;

    // convert our plain text to unicode
    const char* castedText = NS_REINTERPRET_CAST(char*, mSelectionData.data);          
    PRUnichar* convertedText = nsnull;
    PRInt32 convertedTextLen = 0;
    nsPrimitiveHelpers::ConvertPlatformPlainTextToUnicode (castedText, mSelectionData.length, 
                                                           &convertedText, &convertedTextLen);
    if (convertedText) {
      // out with the old, in with the new 
      mSelectionData.data = NS_REINTERPRET_CAST(guchar*, convertedText);
      mSelectionData.length = convertedTextLen * 2;
    }
  } else if (type.Equals(kHTMLMime)) {
    mSelectionData = *aSD;
    PRUnichar* htmlBody= nsnull;
    PRInt32 htmlBodyLen = 0;
    ConvertHTMLtoUCS2((char*)aSD->data, aSD->length, &htmlBody, htmlBodyLen);
    if (htmlBodyLen) {
      mSelectionData.data = NS_REINTERPRET_CAST(guchar*, htmlBody);
      mSelectionData.length = htmlBodyLen * 2;
    }
  } else {
    mSelectionData = *aSD;
    mSelectionData.data = g_new(guchar, aSD->length + 1);
    memcpy(mSelectionData.data,
           aSD->data,
           aSD->length);
    mSelectionData.length = aSD->length;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsClipboard::SelectionRequestCB ( GtkWidget *  aWidget,
GtkSelectionData *  aSelectionData,
gpointer  aData 
) [static, private]

The routine called when another app asks for the content of the selection.

Parameters:
aWidgetthe widget
aSelectionDatagtk selection stuff
aDatavalue passed in from the callback init

Definition at line 1109 of file nsClipboard.cpp.

{
#ifdef DEBUG_CLIPBOARD
  g_print("  nsClipboard::SelectionRequestCB\n");
#endif /* DEBUG_CLIPBOARD */
}
void nsClipboard::SetClipboardData ( const char *  aFlavour) [protected]

Definition at line 230 of file nsClipboard.cpp.

{
  void *pMozData = nsnull;
  PRUint32 NumOfBytes = 0;

  // Get the data from the transferable
  nsCOMPtr<nsISupports> genericDataWrapper;
  nsresult errCode = mTransferable->GetTransferData( aFlavor, getter_AddRefs(genericDataWrapper), &NumOfBytes );
#ifdef DEBUG
  if (NS_FAILED(errCode)) printf( "nsClipboard:: Error getting data from transferable\n" );
#endif
  if (NumOfBytes == 0) return;
  nsPrimitiveHelpers::CreateDataFromPrimitive( aFlavor, genericDataWrapper, &pMozData, NumOfBytes );

  /* If creating the data failed, just return */
  if (!pMozData) {
    return;
  }

  ULONG ulFormatID = GetFormatID( aFlavor );

  if (strstr( aFlavor, "text/" ))  // All text/.. flavors are null-terminated
  {
    if (ulFormatID == CF_TEXT)     // CF_TEXT is one byte character set
    {
      char* pByteMem = nsnull;

      if (DosAllocSharedMem( NS_REINTERPRET_CAST(PPVOID, &pByteMem), nsnull, NumOfBytes + sizeof(char), 
                             PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE ) == NO_ERROR)
      {
        memcpy( pByteMem, pMozData, NumOfBytes );       // Copy text string
        pByteMem[NumOfBytes] = '\0';                    // Append terminator

        // Don't copy text larger than 64K to the clipboard
        if (strlen(pByteMem) <= 0xFFFF) {
          WinSetClipbrdData( 0, NS_REINTERPRET_CAST(ULONG, pByteMem), ulFormatID, CFI_POINTER );
        } else {
          WinAlarm(HWND_DESKTOP, WA_ERROR);
        }
      }
    }
    else                           // All other text/.. flavors are in unicode
    {
      UniChar* pUnicodeMem = nsnull;
      PRUint32 NumOfChars = NumOfBytes / sizeof(UniChar);
   
      if (DosAllocSharedMem( NS_REINTERPRET_CAST(PPVOID, &pUnicodeMem), nsnull, NumOfBytes + sizeof(UniChar), 
                             PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE ) == NO_ERROR) 
      {
        memcpy( pUnicodeMem, pMozData, NumOfBytes );    // Copy text string
        pUnicodeMem[NumOfChars] = L'\0';                // Append terminator

        WinSetClipbrdData( 0, NS_REINTERPRET_CAST(ULONG, pUnicodeMem), ulFormatID, CFI_POINTER );
      }

      // If the flavor is unicode, we also put it on the clipboard as CF_TEXT
      // after conversion to locale charset.

      if (!strcmp( aFlavor, kUnicodeMime ))
      {
        char* pByteMem = nsnull;

        if (DosAllocSharedMem(NS_REINTERPRET_CAST(PPVOID, &pByteMem), nsnull,
                              NumOfBytes + 1, 
                              PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE ) == NO_ERROR) 
        {
          PRUnichar* uchtemp = (PRUnichar*)pMozData;
          for (PRUint32 i=0;i<NumOfChars;i++) {
            switch (uchtemp[i]) {
              case 0x2018:
              case 0x2019:
                uchtemp[i] = 0x0027;
                break;
              case 0x201C:
              case 0x201D:
                uchtemp[i] = 0x0022;
                break;
              case 0x2014:
                uchtemp[i] = 0x002D;
                break;
            }
          }

          nsAutoCharBuffer buffer;
          PRInt32 bufLength;
          WideCharToMultiByte(0, NS_STATIC_CAST(PRUnichar*, pMozData),
                              NumOfBytes, buffer, bufLength);
          memcpy(pByteMem, buffer.get(), NumOfBytes);
          // Don't copy text larger than 64K to the clipboard
          if (strlen(pByteMem) <= 0xFFFF) {
            WinSetClipbrdData(0, NS_REINTERPRET_CAST(ULONG, pByteMem), CF_TEXT,
                              CFI_POINTER);
          } else {
            WinAlarm(HWND_DESKTOP, WA_ERROR);
          }
        }
      }
    }
  }
  else                             // Assume rest of flavors are binary data
  {
    PBYTE pBinaryMem = nsnull;

    if (DosAllocSharedMem( NS_REINTERPRET_CAST(PPVOID, &pBinaryMem), nsnull, NumOfBytes + sizeof(PRUint32), 
                           PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE ) == NO_ERROR) 
    {
      *(NS_REINTERPRET_CAST(PRUint32*, pBinaryMem)) = NumOfBytes;          // First DWORD contains data length
      memcpy( pBinaryMem + sizeof(PRUint32), pMozData, NumOfBytes );  // Copy binary data

      WinSetClipbrdData( 0, NS_REINTERPRET_CAST(ULONG, pBinaryMem), ulFormatID, CFI_POINTER );
    }

    // If the flavor is image, we also put it on clipboard as CF_BITMAP
    // after conversion to OS2 bitmap

    if (strstr (aFlavor, "image/"))
    {
      //  XXX OS2TODO  Convert jpg, gif, png to bitmap
#ifdef DEBUG
      printf( "nsClipboard:: Putting image on clipboard; should also convert to BMP\n" );
#endif
    }
  }
  nsMemory::Free(pMozData);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1263 of file nsClipboard.cpp.

{
#ifdef USE_CUTBUFFERS
  void *clipboardData;
  PRUint32 dataLength;
  nsresult rv;

  nsCOMPtr<nsITransferable> transferable(GetTransferable(kGlobalClipboard));

  // Make sure we have a transferable:
  if (!transferable) {
#ifdef DEBUG_CLIPBOARD
    g_print("Clipboard has no transferable!\n");
#endif
    return;
  }

  nsCOMPtr<nsISupports> genericDataWrapper;
  rv = transferable->GetTransferData(kUnicodeMime, getter_AddRefs(genericDataWrapper), &dataLength);
  nsPrimitiveHelpers::CreateDataFromPrimitive(kUnicodeMime, genericDataWrapper, &clipboardData, dataLength);
  if (NS_SUCCEEDED(rv) && clipboardData && dataLength > 0) {
    char* plainTextData = nsnull;
    PRUnichar* castedUnicode = NS_REINTERPRET_CAST(PRUnichar*, clipboardData);
    PRInt32 plainTextLen = 0;
    nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText (castedUnicode, dataLength / 2,
                                                           &plainTextData, &plainTextLen);
    if (clipboardData) {
      nsMemory::Free(NS_REINTERPRET_CAST(char*, clipboardData));
      clipboardData = plainTextData;
      dataLength = plainTextLen;
    }
  }

  XRotateBuffers(GDK_DISPLAY(), 1);
  XStoreBytes(GDK_DISPLAY(), (const char *) clipboardData, nsCRT::strlen((const char *)clipboardData));
#endif
}

Here is the call graph for this function:

void nsIClipboard::setData ( in nsITransferable  aTransferable,
in nsIClipboardOwner  anOwner,
in long  aWhichClipboard 
) [inherited]

Given a transferable, set the data on the native clipboard.

Parameters:
aTransferableThe transferable
anOwnerThe owner of the transferable
aWhichClipboardSpecifies the clipboard to which this operation applies.
Returns:
NS_Ok if no errors
NS_DECL_ISUPPORTS NS_DECL_NSICLIPBOARD NS_IMETHOD nsClipboard::SetInputGroup ( PRInt32  aInputGroup) [inline]

Definition at line 72 of file nsClipboard.h.

  {
    mInputGroup = aInputGroup;
    return NS_OK;
  }

Here is the caller graph for this function:

NS_IMETHODIMP nsClipboard::SetNativeClipboardData ( PRInt32  aWhichClipboard) [protected, virtual]

Implements nsBaseClipboard.

Definition at line 116 of file nsClipboard.cpp.

{
  mIgnoreEmptyNotification = PR_TRUE;

#ifdef DEBUG_CLIPBOARD
  printf("  nsClipboard::SetNativeClipboardData()\n");
#endif /* DEBUG_CLIPBOARD */

  // make sure we have a good transferable
  if (nsnull == mTransferable) {
#ifdef DEBUG_CLIPBOARD
    printf("  SetNativeClipboardData: no transferable!\n");
#endif /* DEBUG_CLIPBOARD */
    return NS_ERROR_FAILURE;
  }

  // lock the native clipboard
  if (!be_clipboard->Lock())
    return NS_ERROR_FAILURE;

  // clear the native clipboard
  nsresult rv = NS_OK;
  if (B_OK == be_clipboard->Clear()) {
    // set data to the native clipboard
    if (BMessage *msg = be_clipboard->Data()) {
      // Get the transferable list of data flavors
      nsCOMPtr<nsISupportsArray> dfList;
      mTransferable->FlavorsTransferableCanExport(getter_AddRefs(dfList));

      // Walk through flavors that contain data and register them
      // into the BMessage as supported flavors
      PRUint32 i;
      PRUint32 cnt;
      dfList->Count(&cnt);
      for (i = 0; i < cnt && rv == NS_OK; i++) {
        nsCOMPtr<nsISupports> genericFlavor;
        dfList->GetElementAt(i, getter_AddRefs(genericFlavor));
        nsCOMPtr<nsISupportsCString> currentFlavor (do_QueryInterface(genericFlavor));
        if (currentFlavor) {
          nsXPIDLCString flavorStr;
          currentFlavor->ToString(getter_Copies(flavorStr));

#ifdef DEBUG_CLIPBOARD
          printf("nsClipboard: %d/%d = %s\n", i, cnt, (const char *)flavorStr);
#endif /* DEBUG_CLIPBOARD */
          if (0 == strncmp(flavorStr, "text/", 5)) {
            // [NS] text/ * => [Be] text/ *
            void *data = nsnull;
            PRUint32 dataSize = 0;
            nsCOMPtr<nsISupports> genericDataWrapper;
            rv = mTransferable->GetTransferData(flavorStr, getter_AddRefs(genericDataWrapper), &dataSize);
            nsPrimitiveHelpers::CreateDataFromPrimitive(flavorStr, genericDataWrapper, &data, dataSize);
#ifdef DEBUG_CLIPBOARD
            if (NS_FAILED(rv))
              printf("nsClipboard: Error getting data from transferable\n");
#endif /* DEBUG_CLIPBOARD */
            if (dataSize && data != nsnull) {
              NS_ConvertUCS2toUTF8 cv((const PRUnichar *)data, (PRUint32)dataSize / 2);
              const char *utf8Str = cv.get();
              uint32 utf8Len = strlen(utf8Str);
#ifdef DEBUG_CLIPBOARD
              if (0 == strcmp(flavorStr, kUnicodeMime))
                printf(" => [%s]%s\n", kTextMime, utf8Str);
              else
                printf(" => [%s]%s\n", (const char *)flavorStr, utf8Str);
#endif /* DEBUG_CLIPBOARD */
              status_t rc;
              if (0 == strcmp(flavorStr, kUnicodeMime)) {
                // [NS] text/unicode => [Be] text/plain
                rc = msg->AddData(kTextMime, B_MIME_TYPE, (void *)utf8Str, utf8Len);
              } else {
                // [NS] text/ * => [Be] text/ *
                rc = msg->AddData((const char *)flavorStr, B_MIME_TYPE, (void *)utf8Str, utf8Len);
              }
              if (rc != B_OK)
                rv = NS_ERROR_FAILURE;
            } else {
#ifdef DEBUG_CLIPBOARD
              printf("nsClipboard: Error null data from transferable\n");
#endif /* DEBUG_CLIPBOARD */
                // not fatal. force to continue...
                rv = NS_OK;
            }
          } else {
            // [NS] * / * => [Be] * / *
            void *data = nsnull;
            PRUint32 dataSize = 0;
            nsCOMPtr<nsISupports> genericDataWrapper;
            rv = mTransferable->GetTransferData(flavorStr, getter_AddRefs(genericDataWrapper), &dataSize);
            nsPrimitiveHelpers::CreateDataFromPrimitive(flavorStr, genericDataWrapper, &data, dataSize);
#ifdef DEBUG_CLIPBOARD
            if (NS_FAILED(rv))
              printf("nsClipboard: Error getting data from transferable\n");
#endif /* DEBUG_CLIPBOARD */
            if (dataSize && data != nsnull) {
#ifdef DEBUG_CLIPBOARD
              printf("[%s](binary)\n", (const char *)flavorStr);
#endif /* DEBUG_CLIPBOARD */
              if (B_OK != msg->AddData((const char *)flavorStr, B_MIME_TYPE, data, dataSize))
                rv = NS_ERROR_FAILURE;
            }
          }
        } else {
#ifdef DEBUG_CLIPBOARD
          printf("nsClipboard: Error getting flavor\n");
#endif /* DEBUG_CLIPBOARD */
          rv = NS_ERROR_FAILURE;
        }
      } /* for */
    } else {
      rv = NS_ERROR_FAILURE;
    }
  } else {
    rv = NS_ERROR_FAILURE;
  }
  if (B_OK != be_clipboard->Commit())
    rv = NS_ERROR_FAILURE;
  be_clipboard->Unlock();

  mIgnoreEmptyNotification = PR_FALSE;

  return rv;
}

Here is the call graph for this function:

NS_IMETHOD nsClipboard::SetNativeClipboardData ( PRInt32  aWhichClipboard) [protected, virtual]

Implements nsBaseClipboard.

NS_IMETHOD nsClipboard::SetNativeClipboardData ( PRInt32  aWhichClipboard) [protected, virtual]

Implements nsBaseClipboard.

NS_IMETHOD nsClipboard::SetNativeClipboardData ( PRInt32  aWhichClipboard) [protected, virtual]

Implements nsBaseClipboard.

NS_IMETHOD nsClipboard::SetNativeClipboardData ( PRInt32  aWhichClipboard) [protected, virtual]

Implements nsBaseClipboard.

NS_IMETHOD nsClipboard::SetNativeClipboardData ( PRInt32  aWhichClipboard) [protected, virtual]

Implements nsBaseClipboard.

NS_IMETHOD nsClipboard::SetNativeClipboardData ( PRInt32  aWhichClipboard) [protected, virtual]

Implements nsBaseClipboard.

NS_IMETHOD nsClipboard::SetNativeClipboardData ( PRInt32  aWhichClipboard) [protected, virtual]

Implements nsBaseClipboard.

void nsClipboard::SetTopLevelView ( BView *  v) [static]

Definition at line 90 of file nsClipboard.cpp.

{
  // Don't set up any more event handlers if we're being called twice
  // for the same toplevel widget
  if (sView == v)
    return;

  if (sView != 0 && sView->Window() != 0)
    return;

  if(v == 0 || v->Window() == 0)
  {
#ifdef DEBUG_CLIPBOARD
    printf("  nsClipboard::SetTopLevelView: widget passed in is null or has no window!\n");
#endif /* DEBUG_CLIPBOARD */
    return;
  }

#ifdef DEBUG_CLIPBOARD
  printf("  nsClipboard::SetTopLevelView\n");
#endif /* DEBUG_CLIPBOARD */
}
nsresult nsClipboard::SetupNativeDataObject ( nsITransferable aTransferable,
IDataObject *  aDataObj 
) [static]

Definition at line 164 of file nsClipboard.cpp.

{
  if (nsnull == aTransferable || nsnull == aDataObj) {
    return NS_ERROR_FAILURE;
  }

  nsDataObj * dObj = NS_STATIC_CAST(nsDataObj *, aDataObj);

  // Now give the Transferable to the DataObject 
  // for getting the data out of it
  dObj->SetTransferable(aTransferable);

  // Get the transferable list of data flavors
  nsCOMPtr<nsISupportsArray> dfList;
  aTransferable->FlavorsTransferableCanExport(getter_AddRefs(dfList));

  // Walk through flavors that contain data and register them
  // into the DataObj as supported flavors
  PRUint32 i;
  PRUint32 cnt;
  dfList->Count(&cnt);
  for (i=0;i<cnt;i++) {
    nsCOMPtr<nsISupports> genericFlavor;
    dfList->GetElementAt ( i, getter_AddRefs(genericFlavor) );
    nsCOMPtr<nsISupportsCString> currentFlavor ( do_QueryInterface(genericFlavor) );
    if ( currentFlavor ) {
      nsXPIDLCString flavorStr;
      currentFlavor->ToString(getter_Copies(flavorStr));
      UINT format = GetFormat(flavorStr);

      // Now tell the native IDataObject about both our mime type and 
      // the native data format
      FORMATETC fe;
      SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
      dObj->AddDataFlavor(flavorStr, &fe);
      
      // Do various things internal to the implementation, like map one
      // flavor to another or add additional flavors based on what's required
      // for the win32 impl.
      if ( strcmp(flavorStr, kUnicodeMime) == 0 ) {
        // if we find text/unicode, also advertise text/plain (which we will convert
        // on our own in nsDataObj::GetText().
        FORMATETC textFE;
        SET_FORMATETC(textFE, CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
        dObj->AddDataFlavor(kTextMime, &textFE);
      }
      else if ( strcmp(flavorStr, kHTMLMime) == 0 ) {      
        // if we find text/html, also advertise win32's html flavor (which we will convert
        // on our own in nsDataObj::GetText().
        FORMATETC htmlFE;
        SET_FORMATETC(htmlFE, CF_HTML, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
        dObj->AddDataFlavor(kHTMLMime, &htmlFE);     
      }
      else if ( strcmp(flavorStr, kURLMime) == 0 ) {
        // if we're a url, in addition to also being text, we need to register
        // the "file" flavors so that the win32 shell knows to create an internet
        // shortcut when it sees one of these beasts.
        FORMATETC shortcutFE;
        SET_FORMATETC(shortcutFE, ::RegisterClipboardFormat(CFSTR_FILEDESCRIPTORA), 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL)
        dObj->AddDataFlavor(kURLMime, &shortcutFE);      
        SET_FORMATETC(shortcutFE, ::RegisterClipboardFormat(CFSTR_FILEDESCRIPTORW), 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL)
        dObj->AddDataFlavor(kURLMime, &shortcutFE);      
#ifndef WINCE
        SET_FORMATETC(shortcutFE, ::RegisterClipboardFormat(CFSTR_FILECONTENTS), 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL)
        dObj->AddDataFlavor(kURLMime, &shortcutFE);  
#endif
        SET_FORMATETC(shortcutFE, ::RegisterClipboardFormat(CFSTR_INETURLA), 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL)
        dObj->AddDataFlavor(kURLMime, &shortcutFE);      
        SET_FORMATETC(shortcutFE, ::RegisterClipboardFormat(CFSTR_INETURLW), 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL)
        dObj->AddDataFlavor(kURLMime, &shortcutFE);      
      }
      else if ( strcmp(flavorStr, kPNGImageMime) == 0 || strcmp(flavorStr, kJPEGImageMime) == 0 ||
                  strcmp(flavorStr, kGIFImageMime) == 0 || strcmp(flavorStr, kNativeImageMime) == 0  ) {
        // if we're an image, register the native bitmap flavor
        FORMATETC imageFE;
        SET_FORMATETC(imageFE, CF_DIB, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL)
        dObj->AddDataFlavor(flavorStr, &imageFE);      
      }
#ifndef WINCE
      else if ( strcmp(flavorStr, kFilePromiseMime) == 0 ) {
         // if we're a file promise flavor, also register the 
         // CFSTR_PREFERREDDROPEFFECT format.  The data object
         // returns a value of DROPEFFECTS_MOVE to the drop target
         // when it asks for the value of this format.  This causes
         // the file to be moved from the temporary location instead
         // of being copied.  The right thing to do here is to call
         // SetData() on the data object and set the value of this format
         // to DROPEFFECTS_MOVE on this particular data object.  But,
         // since all the other clipboard formats follow the model of setting
         // data on the data object only when the drop object calls GetData(),
         // I am leaving this format's value hard coded in the data object.
         // We can change this if other consumers of this format get added to this
         // codebase and they need different values.
        FORMATETC shortcutFE;
        SET_FORMATETC(shortcutFE, ::RegisterClipboardFormat(CFSTR_PREFERREDDROPEFFECT), 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL)
        dObj->AddDataFlavor(kFilePromiseMime, &shortcutFE);
      }
#endif
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 95 of file nsClipboard.cpp.

Here is the caller graph for this function:

Allows clients to determine if the implementation supports the concept of a separate clipboard for selection.

- true if

Returns:
NS_OK if successful.

Member Data Documentation

UINT nsClipboard::CF_HTML = ::RegisterClipboardFormat("HTML Format") [static]

Definition at line 87 of file nsClipboard.h.

Definition at line 51 of file nsIClipboard.idl.

Definition at line 50 of file nsIClipboard.idl.

Definition at line 101 of file nsClipboard.h.

Definition at line 72 of file nsBaseClipboard.h.

Definition at line 94 of file nsClipboard.h.

Definition at line 96 of file nsClipboard.h.

Reimplemented from nsBaseClipboard.

Definition at line 66 of file nsClipboard.h.

Definition at line 99 of file nsClipboard.h.

GtkSelectionData nsClipboard::mSelectionData [private]

Definition at line 100 of file nsClipboard.h.

Definition at line 93 of file nsClipboard.h.

Definition at line 95 of file nsClipboard.h.

Reimplemented from nsBaseClipboard.

Definition at line 84 of file nsClipboard.h.

GtkWidget* nsClipboard::mWidget [private]

Definition at line 80 of file nsClipboard.h.

Definition at line 99 of file nsClipboard.h.

Display * nsClipboard::sDisplay [static, private]

Definition at line 97 of file nsClipboard.h.

BView * nsClipboard::sView = 0 [static, protected]

Definition at line 68 of file nsClipboard.h.

Definition at line 96 of file nsClipboard.h.

GtkWidget * nsClipboard::sWidget = 0 [static, private]

Definition at line 104 of file nsClipboard.h.

Window nsClipboard::sWindow [static, private]

Definition at line 95 of file nsClipboard.h.


The documentation for this class was generated from the following files: