Пример #1
0
static WidgetInfo *
create_page_selector (void)
{
  GtkWidget *vbox;
  GtkWidget *selector;

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
  selector = gimp_page_selector_new ();
  gtk_widget_set_size_request (selector, -1, 240);
  gimp_page_selector_set_n_pages (GIMP_PAGE_SELECTOR (selector), 16);
  gimp_page_selector_select_range (GIMP_PAGE_SELECTOR (selector),
                                   "1,3,7-9,12-15");
  gtk_box_pack_start (GTK_BOX (vbox), selector, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox),
                      gtk_label_new ("Page Selector"), FALSE, FALSE, 0);

  return new_widget_info ("gimp-widget-page-selector", vbox, ASIS);
}
Пример #2
0
static gboolean
load_dialog (PopplerDocument  *doc,
             PdfSelectedPages *pages)
{
    GtkWidget  *dialog;
    GtkWidget  *vbox;
    GtkWidget  *title;
    GtkWidget  *selector;
    GtkWidget  *resolution;
    GtkWidget  *hbox;

    ThreadData  thread_data;
    GThread    *thread;

    gint        i;
    gint        n_pages;

    gdouble     width;
    gdouble     height;

    gboolean    run;

    gimp_ui_init (PLUG_IN_BINARY, FALSE);

    dialog = gimp_dialog_new (_("Import from PDF"), PLUG_IN_BINARY,
                              NULL, 0,
                              gimp_standard_help_func, LOAD_PROC,

                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                              _("_Import"),     GTK_RESPONSE_OK,

                              NULL);

    gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
            GTK_RESPONSE_OK,
            GTK_RESPONSE_CANCEL,
            -1);

    gimp_window_set_transient (GTK_WINDOW (dialog));

    vbox = gtk_vbox_new (FALSE, 12);
    gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
    gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
                        vbox, TRUE, TRUE, 0);
    gtk_widget_show (vbox);

    /* Title */
    title = gimp_prop_label_new (G_OBJECT (doc), "title");
    gtk_label_set_ellipsize (GTK_LABEL (title), PANGO_ELLIPSIZE_END);
    gtk_box_pack_start (GTK_BOX (vbox), title, FALSE, FALSE, 0);
    gtk_widget_show (title);

    /* Page Selector */
    selector = gimp_page_selector_new ();
    gtk_widget_set_size_request (selector, 380, 360);
    gtk_box_pack_start (GTK_BOX (vbox), selector, TRUE, TRUE, 0);
    gtk_widget_show (selector);

    n_pages = poppler_document_get_n_pages (doc);
    gimp_page_selector_set_n_pages (GIMP_PAGE_SELECTOR (selector), n_pages);
    gimp_page_selector_set_target (GIMP_PAGE_SELECTOR (selector),
                                   loadvals.target);

    for (i = 0; i < n_pages; i++)
    {
        PopplerPage     *page;
        gchar           *label;

        page = poppler_document_get_page (doc, i);
        g_object_get (G_OBJECT (page), "label", &label, NULL);

        gimp_page_selector_set_page_label (GIMP_PAGE_SELECTOR (selector), i,
                                           label);

        if (i == 0)
            poppler_page_get_size (page, &width, &height);

        g_object_unref (page);
        g_free (label);
    }

    g_signal_connect_swapped (selector, "activate",
                              G_CALLBACK (gtk_window_activate_default),
                              dialog);

    thread_data.document          = doc;
    thread_data.selector          = GIMP_PAGE_SELECTOR (selector);
    thread_data.stop_thumbnailing = FALSE;

    thread = g_thread_create (thumbnail_thread, &thread_data, TRUE, NULL);

    /* Resolution */

    hbox = gtk_hbox_new (FALSE, 0);
    gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
    gtk_widget_show (hbox);

    resolution = gimp_resolution_entry_new (_("_Width (pixels):"), width,
                                            _("_Height (pixels):"), height,
                                            GIMP_UNIT_POINT,
                                            _("_Resolution:"),
                                            loadvals.resolution, GIMP_UNIT_INCH);

    gtk_box_pack_start (GTK_BOX (hbox), resolution, FALSE, FALSE, 0);
    gtk_widget_show (resolution);

    g_signal_connect (resolution, "x-changed",
                      G_CALLBACK (gimp_resolution_entry_update_x_in_dpi),
                      &loadvals.resolution);

    /* Setup done; display the dialog */
    gtk_widget_show (dialog);

    /* run the dialog */
    run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);

    loadvals.target =
        gimp_page_selector_get_target (GIMP_PAGE_SELECTOR (selector));

    pages->pages =
        gimp_page_selector_get_selected_pages (GIMP_PAGE_SELECTOR (selector),
                &pages->n_pages);

    /* select all if none selected */
    if (pages->n_pages == 0)
    {
        gimp_page_selector_select_all (GIMP_PAGE_SELECTOR (selector));

        pages->pages =
            gimp_page_selector_get_selected_pages (GIMP_PAGE_SELECTOR (selector),
                    &pages->n_pages);
    }

    /* cleanup */
    thread_data.stop_thumbnailing = TRUE;
    g_thread_join (thread);

    return run;
}