Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
nsDragService.cpp File Reference
#include "nsDragService.h"
#include "nsIObserverService.h"
#include "nsWidgetsCID.h"
#include "nsWindow.h"
#include "nsIServiceManager.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
#include "prlog.h"
#include "nsVoidArray.h"
#include "nsXPIDLString.h"
#include "nsPrimitiveHelpers.h"
#include "prtime.h"
#include "prthread.h"
#include <gtk/gtkinvisible.h>
#include <gdk/gdkx.h>
#include "nsCRT.h"

Go to the source code of this file.

Defines

#define NS_DND_TIMEOUT   500000

Functions

 NS_IMPL_QUERY_INTERFACE5 (nsDragService, nsIDragService, nsIDragService_1_8_BRANCH, nsIDragSession, nsIDragSessionGTK, nsIObserver) static void invisibleSourceDragEnd(GtkWidget *aWidget
static void invisibleSourceDragDataGet (GtkWidget *aWidget, GdkDragContext *aContext, GtkSelectionData *aSelectionData, guint aInfo, guint32 aTime, gpointer aData)
static PRUint32 CountTextUriListItems (const char *data, PRUint32 datalen)
static void GetTextUriListItem (const char *data, PRUint32 datalen, PRUint32 aItemIndex, PRUnichar **convertedText, PRInt32 *convertedTextLen)
static void CreateUriList (nsISupportsArray *items, gchar **text, gint *length)
void invisibleSourceDragEnd (GtkWidget *aWidget, GdkDragContext *aContext, gpointer aData)

Variables

static PRLogModuleInfosDragLm = NULL
static const char gMimeListType [] = "application/x-moz-internal-item-list"
static const char gMozUrlType [] = "_NETSCAPE_URL"
static const char gTextUriListType [] = "text/uri-list"
GdkDragContext * aContext
GdkDragContext gpointer aData

Define Documentation

#define NS_DND_TIMEOUT   500000

Definition at line 801 of file nsDragService.cpp.


Function Documentation

static PRUint32 CountTextUriListItems ( const char *  data,
PRUint32  datalen 
) [static]

Definition at line 249 of file nsDragService.cpp.

{
    const char *p = data;
    const char *endPtr = p + datalen;
    PRUint32 count = 0;

    while (p < endPtr) {
        // skip whitespace (if any)
        while (p < endPtr && *p != '\0' && isspace(*p))
            p++;
        // if we aren't at the end of the line ...
        if (p != endPtr && *p != '\0' && *p != '\n' && *p != '\r')
            count++;
        // skip to the end of the line
        while (p < endPtr && *p != '\0' && *p != '\n')
            p++;
        p++; // skip the actual newline as well.
    }
    return count;
}
static void CreateUriList ( nsISupportsArray items,
gchar **  text,
gint *  length 
) [static]

Definition at line 1023 of file nsDragService.cpp.

{
    PRUint32 i, count;
    GString *uriList = g_string_new(NULL);

    items->Count(&count);
    for (i = 0; i < count; i++) {
        nsCOMPtr<nsISupports> genericItem;
        items->GetElementAt(i, getter_AddRefs(genericItem));
        nsCOMPtr<nsITransferable> item;
        item = do_QueryInterface(genericItem);

        if (item) {
            PRUint32 tmpDataLen = 0;
            void    *tmpData = NULL;
            nsresult rv = 0;
            nsCOMPtr<nsISupports> data;
            rv = item->GetTransferData(kURLMime,
                                       getter_AddRefs(data),
                                       &tmpDataLen);

            if (NS_SUCCEEDED(rv)) {
                nsPrimitiveHelpers::CreateDataFromPrimitive(kURLMime,
                                                            data,
                                                            &tmpData,
                                                            tmpDataLen);
                char* plainTextData = nsnull;
                PRUnichar* castedUnicode = NS_REINTERPRET_CAST(PRUnichar*,
                                                               tmpData);
                PRInt32 plainTextLen = 0;
                nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText(
                                    castedUnicode,
                                    tmpDataLen / 2,
                                    &plainTextData,
                                    &plainTextLen);
                if (plainTextData) {
                    PRInt32 j;

                    // text/x-moz-url is of form url + "\n" + title.
                    // We just want the url.
                    for (j = 0; j < plainTextLen; j++)
                        if (plainTextData[j] == '\n' ||
                            plainTextData[j] == '\r') {
                            plainTextData[j] = '\0';
                            break;
                        }
                    g_string_append(uriList, plainTextData);
                    g_string_append(uriList, "\r\n");
                    // this wasn't allocated with glib
                    free(plainTextData);
                }
                if (tmpData) {
                    // this wasn't allocated with glib
                    free(tmpData);
                }
            }
        }
    }
    *text = uriList->str;
    *length = uriList->len + 1;
    g_string_free(uriList, FALSE); // don't free the data
}

Here is the call graph for this function:

static void GetTextUriListItem ( const char *  data,
PRUint32  datalen,
PRUint32  aItemIndex,
PRUnichar **  convertedText,
PRInt32 convertedTextLen 
) [static]

Definition at line 274 of file nsDragService.cpp.

{
    const char *p = data;
    const char *endPtr = p + datalen;
    unsigned int count = 0;

    *convertedText = nsnull;
    while (p < endPtr) {
        // skip whitespace (if any)
        while (p < endPtr && *p != '\0' && isspace(*p))
            p++;
        // if we aren't at the end of the line, we have a url
        if (p != endPtr && *p != '\0' && *p != '\n' && *p != '\r')
            count++;
        // this is the item we are after ...
        if (aItemIndex + 1 == count) {
            const char *q = p;
            while (q < endPtr && *q != '\0' && *q != '\n' && *q != '\r')
              q++;
            nsPrimitiveHelpers::ConvertPlatformPlainTextToUnicode(
                                p, q - p, convertedText, convertedTextLen);
            break;
        }
        // skip to the end of the line
        while (p < endPtr && *p != '\0' && *p != '\n')
            p++;
        p++; // skip the actual newline as well.
    }

    // didn't find the desired item, so just pass the whole lot
    if (!*convertedText) {
        nsPrimitiveHelpers::ConvertPlatformPlainTextToUnicode(
                            data, datalen, convertedText, convertedTextLen);
    }
}

Here is the call graph for this function:

void invisibleSourceDragDataGet ( GtkWidget *  aWidget,
GdkDragContext *  aContext,
GtkSelectionData *  aSelectionData,
guint  aInfo,
guint32  aTime,
gpointer  aData 
) [static]

Definition at line 1192 of file nsDragService.cpp.

{
    PR_LOG(sDragLm, PR_LOG_DEBUG, ("invisibleDragDataGet"));
    nsDragService *dragService = (nsDragService *)aData;
    dragService->SourceDataGet(aWidget, aContext,
                               aSelectionData, aInfo, aTime);
}

Here is the call graph for this function:

void invisibleSourceDragEnd ( GtkWidget *  aWidget,
GdkDragContext *  aContext,
gpointer  aData 
)

Definition at line 1207 of file nsDragService.cpp.

{
    PR_LOG(sDragLm, PR_LOG_DEBUG, ("invisibleDragEnd"));
    nsDragService *dragService = (nsDragService *)aData;
    // The drag has ended.  Release the hostages!
    dragService->SourceEndDrag();
}

Here is the call graph for this function:


Variable Documentation

GdkDragContext* aContext

Definition at line 79 of file nsDragService.cpp.

GdkDragContext gpointer aData

Definition at line 79 of file nsDragService.cpp.

const char gMimeListType[] = "application/x-moz-internal-item-list" [static]

Definition at line 64 of file nsDragService.cpp.

const char gMozUrlType[] = "_NETSCAPE_URL" [static]

Definition at line 65 of file nsDragService.cpp.

const char gTextUriListType[] = "text/uri-list" [static]

Definition at line 66 of file nsDragService.cpp.

Definition at line 62 of file nsDragService.cpp.