Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
nullplugin.c File Reference
#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <gdk/gdkkeysyms.h>
#include "npapi.h"
#include "nullplugin.h"
#include "prprf.h"

Go to the source code of this file.

Defines

#define DIALOGID   "dialog"

Functions

void destroyWidget (PluginInstance *This)
static void DialogOKClicked (GtkButton *button, gpointer data)
static void DialogCancelClicked (GtkButton *button, gpointer data)
static gboolean DialogEscapePressed (GtkWidget *widget, GdkEventKey *event, gpointer data)
static GtkWidget * AddWidget (GtkWidget *widget, GtkWidget *packingbox)
static gboolean isEqual (NPMIMEType t1, NPMIMEType t2)
static MimeTypeElementisExist (MimeTypeElement **typelist, NPMIMEType type)
NPMIMEType dupMimeType (NPMIMEType type)
static gboolean addToList (MimeTypeElement **typelist, PluginInstance *This)
static gboolean delFromList (MimeTypeElement **typelist, PluginInstance *This)
static void onDestroyWidget (GtkWidget *w, gpointer data)
void makeWidget (PluginInstance *This)
static GdkWindow * getGdkWindow (PluginInstance *This)
static void createPixmap (PluginInstance *This)
static void drawPixmap (PluginInstance *This)
static void setCursor (PluginInstance *This)
static void addXtEventHandler (PluginInstance *This)
void makePixmap (PluginInstance *This)

Variables

static MimeTypeElementhead = NULL
static char * npnul320_xpm []
static GdkPixmap * nullPluginGdkPixmap = 0

Define Documentation

#define DIALOGID   "dialog"

Definition at line 67 of file nullplugin.c.


Function Documentation

static gboolean addToList ( MimeTypeElement **  typelist,
PluginInstance This 
) [static]

Definition at line 200 of file nullplugin.c.

{
    if (This && This->type && !isExist(typelist, This->type))
    {
        MimeTypeElement *ele;
        if ((ele = (MimeTypeElement *) NPN_MemAlloc(sizeof(MimeTypeElement))))
        {
            ele->pinst = This;
            ele->next = *typelist;
            *typelist = ele;
            return(TRUE);
        }
    }
    return(FALSE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static GtkWidget* AddWidget ( GtkWidget *  widget,
GtkWidget *  packingbox 
) [static]

Definition at line 160 of file nullplugin.c.

{
    gtk_box_pack_start(GTK_BOX(packingbox), widget, TRUE, TRUE, 2);
    return widget;
}

Here is the caller graph for this function:

static void addXtEventHandler ( PluginInstance This) [static]

Definition at line 484 of file nullplugin.c.

{
#ifdef MOZ_X11
     Display *dpy = (Display*) This->display;
     Window xwin = (Window) This->window;
     Widget xt_w = XtWindowToWidget(dpy, xwin);
     if (xt_w)
     {
         long event_mask = ExposureMask | ButtonReleaseMask | ButtonPressMask;
         XSelectInput(dpy, xwin, event_mask);
         XtAddEventHandler(xt_w, event_mask, False, (XtEventHandler)xt_event_handler, This);
     }
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void createPixmap ( PluginInstance This) [static]

Definition at line 392 of file nullplugin.c.

{
    int err = 0;

    if (nullPluginGdkPixmap == 0)
    { 
       GtkStyle *style;
       GdkBitmap *mask;
       GdkWindow *gdk_window = getGdkWindow(This);
       if (gdk_window)
       {
           GtkWidget *widget;
#ifndef MOZ_WIDGET_GTK2
           widget = (GtkWidget *)gdk_window->user_data;
#else
           gpointer user_data = NULL;
           gdk_window_get_user_data( gdk_window, &user_data);
           widget = GTK_WIDGET(user_data);
#endif
           style = gtk_widget_get_style(widget);
           nullPluginGdkPixmap = gdk_pixmap_create_from_xpm_d(gdk_window , &mask,
                                             &style->bg[GTK_STATE_NORMAL], npnul320_xpm);
#ifdef MOZ_X11
          /* Pixmap is created on original X session but used by new session */
          XSync(GDK_DISPLAY(), False);
#endif
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean delFromList ( MimeTypeElement **  typelist,
PluginInstance This 
) [static]

Definition at line 217 of file nullplugin.c.

{
    if (typelist && This)
    {
        MimeTypeElement *ele_prev;
        MimeTypeElement *ele = *typelist;
        while (ele)
        {
            if (isEqual(ele->pinst->type, This->type))
            {
                if (*typelist == ele)
                {
                    *typelist = ele->next;
                } else {
                    ele_prev->next = ele->next;
                }
                NPN_MemFree(ele);
                return(TRUE);
            }
            ele_prev = ele;
            ele = ele->next;
        }
    }
    return(FALSE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 74 of file nullplugin.c.

{
    if (This && This->dialogBox)
    {
      gtk_widget_destroy (GTK_WIDGET(This->dialogBox));
    }
}

Here is the caller graph for this function:

static void DialogCancelClicked ( GtkButton *  button,
gpointer  data 
) [static]

Definition at line 139 of file nullplugin.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean DialogEscapePressed ( GtkWidget *  widget,
GdkEventKey *  event,
gpointer  data 
) [static]

Definition at line 146 of file nullplugin.c.

{
    if (event->keyval == GDK_Escape)
    {
        gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event");
        gtk_object_destroy (GTK_OBJECT (widget));
        return TRUE;
    }

    return FALSE;
}

Here is the caller graph for this function:

static void DialogOKClicked ( GtkButton *  button,
gpointer  data 
) [static]

Definition at line 84 of file nullplugin.c.

{
    PluginInstance* This = (PluginInstance*) data;
    GtkWidget* dialogWindow = gtk_object_get_data(GTK_OBJECT(button), DIALOGID);
    char *url;

    gtk_object_remove_data(GTK_OBJECT(button), DIALOGID);

    if (This->pluginsFileUrl != NULL)
    {
        /* Get the JavaScript command string */
        static const char buf[] = 
          "javascript:netscape.softupdate.Trigger.StartSoftwareUpdate(\"%s\")";

        url = NPN_MemAlloc(strlen(This->pluginsFileUrl) + (sizeof(buf) - 2));
        if (url != NULL)
        {
            /* Insert the file URL into the JavaScript command */
            sprintf(url, buf, This->pluginsFileUrl);
            NPN_GetURL(This->instance, url, TARGET);
            NPN_MemFree(url);
        }
    }
    else
    {
        /* If necessary, get the default plug-ins page resource */
        char* address = This->pluginsPageUrl;
        if (address == NULL || *address == 0)
        {
            address = PLUGINSPAGE_URL;
        }

        url = NPN_MemAlloc(strlen(address) + 1 + strlen(This->type)+1);
        if (url != NULL)
        {
            NPN_PushPopupsEnabledState(This->instance, TRUE);
                /* Append the MIME type to the URL */
            sprintf(url, "%s?%s", address, This->type);
            if (strcmp (This->type, JVM_MINETYPE) == 0) 
            {
                NPN_GetURL(This->instance, JVM_SMARTUPDATE_URL , TARGET);
            }
            else 
            {
                NPN_GetURL(This->instance, url, TARGET);
            }
            NPN_MemFree(url);
            NPN_PopPopupsEnabledState(This->instance);
        }
    }
    destroyWidget(This);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void drawPixmap ( PluginInstance This) [static]

Definition at line 423 of file nullplugin.c.

{
    if (nullPluginGdkPixmap)
    {
        int pixmap_with, pixmap_height, dest_x, dest_y;
        gdk_window_get_size((GdkWindow *)nullPluginGdkPixmap, &pixmap_with, &pixmap_height);
        dest_x = This->width/2 - pixmap_with/2;
        dest_y = This->height/2 - pixmap_height/2;
        if (dest_x >= 0 && dest_y >= 0)
        {
#ifdef MOZ_X11
            GC gc;
            gc = XCreateGC(This->display, This->window, 0, NULL);
            XCopyArea(This->display, GDK_WINDOW_XWINDOW(nullPluginGdkPixmap) , This->window, gc,
                0, 0, pixmap_with, pixmap_height, dest_x, dest_y);
            XFreeGC(This->display, gc);
#endif
        }
    }
}

Here is the caller graph for this function:

Definition at line 191 of file nullplugin.c.

{
    NPMIMEType mimetype = NPN_MemAlloc(strlen(type)+1);
    if (mimetype)
        strcpy(mimetype, type);
    return(mimetype);
}

Here is the caller graph for this function:

static GdkWindow* getGdkWindow ( PluginInstance This) [static]

Definition at line 370 of file nullplugin.c.

{
#ifdef MOZ_X11
    GdkWindow *gdk_window;
    Window xwin = (Window) This->window;
    Widget xt_w = XtWindowToWidget(This->display, xwin);

    if (xt_w) {
      xt_w = XtParent(xt_w);
      if (xt_w) {
         xwin = XtWindow(xt_w);
         /* xwin = xt_w->core.window; */
      }
    }
    gdk_window = gdk_window_lookup(xwin);
    return gdk_window;
#else
    return NULL;
#endif
}

Here is the caller graph for this function:

static gboolean isEqual ( NPMIMEType  t1,
NPMIMEType  t2 
) [static]

Definition at line 171 of file nullplugin.c.

{
    return (t1 && t2) ? (strcmp(t1, t2) == 0) : FALSE; 
}

Here is the caller graph for this function:

static MimeTypeElement* isExist ( MimeTypeElement **  typelist,
NPMIMEType  type 
) [static]

Definition at line 177 of file nullplugin.c.

{
    MimeTypeElement *ele;

    ele = *typelist;
    while (ele != NULL) {
        if (isEqual(ele->pinst->type, type))
            return ele;
        ele = ele->next;
    }
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 501 of file nullplugin.c.

{
    createPixmap(This);
    drawPixmap(This);
    setCursor(This);
    addXtEventHandler(This);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 256 of file nullplugin.c.

{
    GtkWidget *dialogWindow;
    GtkWidget *dialogMessage;
    GtkWidget *okButton;
    GtkWidget *cancelButton;
    char message[1024];
    MimeTypeElement *ele;

    if (!This) return;

    /* need to check whether we already pop up a dialog box for previous
       minetype in the same web page. It's require otherwise there will
       be 2 dialog boxes pop if there are 2 plugin in the same web page
    */
    if ((ele = isExist(&head, This->type)))
    {
        if (ele->pinst && ele->pinst->dialogBox)
        {
            GtkWidget *top_window = gtk_widget_get_toplevel(ele->pinst->dialogBox);
            if (top_window && GTK_WIDGET_VISIBLE(top_window))
            {   /* this will raise the toplevel window */
                gdk_window_show(top_window->window);
            }
        }
        return;
    }

    dialogWindow = gtk_dialog_new();
    This->dialogBox = dialogWindow;
    This->exists = TRUE;
    This->dialogBox = dialogWindow;
    addToList(&head, This);
    gtk_window_set_title(GTK_WINDOW(dialogWindow), PLUGIN_NAME);
    gtk_window_set_position(GTK_WINDOW(dialogWindow), GTK_WIN_POS_CENTER);
    gtk_window_set_modal(GTK_WINDOW(dialogWindow), FALSE);
    gtk_container_set_border_width(GTK_CONTAINER(dialogWindow), 20);
    gtk_window_set_policy(GTK_WINDOW(dialogWindow), FALSE, FALSE, TRUE);

    PR_snprintf(message, sizeof(message) - 1, MESSAGE, This->type);
    dialogMessage = AddWidget(gtk_label_new (message), 
                   GTK_DIALOG(dialogWindow)->vbox);

    okButton= AddWidget(gtk_button_new_with_label (OK_BUTTON), 
                   GTK_DIALOG(dialogWindow)->action_area);
    gtk_object_set_data(GTK_OBJECT(okButton), DIALOGID, dialogWindow);

    GTK_WIDGET_SET_FLAGS (okButton, GTK_CAN_DEFAULT);
    gtk_widget_grab_default(okButton);

    cancelButton= AddWidget(gtk_button_new_with_label (CANCEL_BUTTON), 
                   GTK_DIALOG(dialogWindow)->action_area);

    gtk_signal_connect (GTK_OBJECT(okButton),  "clicked",
                        GTK_SIGNAL_FUNC(DialogOKClicked), This);

    gtk_signal_connect (GTK_OBJECT(cancelButton),  "clicked",
                        GTK_SIGNAL_FUNC(DialogCancelClicked), This);

    gtk_signal_connect(GTK_OBJECT(dialogWindow), "key_press_event",
                        GTK_SIGNAL_FUNC (DialogEscapePressed), NULL);

    /* hookup to when the dialog is destroyed */
    gtk_signal_connect(GTK_OBJECT(dialogWindow), "destroy",
                        GTK_SIGNAL_FUNC(onDestroyWidget), This);

    gtk_widget_show_all(dialogWindow);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void onDestroyWidget ( GtkWidget *  w,
gpointer  data 
) [static]

Definition at line 244 of file nullplugin.c.

{
    PluginInstance* This = (PluginInstance*) data;
    if (This && This->dialogBox && This->dialogBox == w)
    {
        This->dialogBox = 0;
        delFromList(&head, This);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void setCursor ( PluginInstance This) [static]

Definition at line 445 of file nullplugin.c.

{
#ifdef MOZ_X11
    static Cursor nullPluginCursor = 0;
    if (!nullPluginCursor)
    {
        nullPluginCursor = XCreateFontCursor(This->display, XC_hand2);
    }
    if (nullPluginCursor)
    {
        XDefineCursor(This->display, This->window, nullPluginCursor);
    }
#endif
}

Here is the caller graph for this function:


Variable Documentation

MimeTypeElement* head = NULL [static]

Definition at line 70 of file nullplugin.c.

char* npnul320_xpm[] [static]

Definition at line 326 of file nullplugin.c.

GdkPixmap* nullPluginGdkPixmap = 0 [static]

Definition at line 368 of file nullplugin.c.