Пример #1
0
static GdkWindow *
draw_popup_image (GtkWidget *widget, GtkTreePath *path,
                  GtkTreeViewColumn *column, GdkRegion *tr)
{
    g_assert (GTK_IS_TREE_VIEW (widget));
    g_assert (!GTK_WIDGET_NO_WINDOW (widget));

    /* We want to center the popup over the original thumbnail.  Since
    we know the original thumbnail is square, the clipbox corresponds
    to the region, so we can just get the clipbox of the thumbnail
    and take the center of that as the center of our popum image.  */
    GdkRectangle tn_rec;
    gdk_region_get_clipbox (tr, &tn_rec);

    /* Size of popup image to use, in pixels on a side.  */
    const gint popup_size = THUMB_SIZE_BIG;

    gint tree_view_x, tree_view_y;
    gdk_window_get_origin (widget->window, &tree_view_x, &tree_view_y);

    GdkWindowAttr nwa;
    nwa.event_mask = GDK_ALL_EVENTS_MASK;

    // popup must take into account any horizontal scrolling
    // that has taken place in the tree view
    GtkScrolledWindow *s =
       GTK_SCROLLED_WINDOW(get_widget_checked("scrolledwindow_in"));
    GtkAdjustment *adj = gtk_scrolled_window_get_hadjustment(s);
    gint h_adj = (gint)(.5 + gtk_adjustment_get_value(adj));

    // FIXME: when the pointer is over the popup itself,
    // maybe_clear_popup_image doesn't notice that we are still over the
    // thumbnail below and so clears things!  FIXME: I don't understand
    // why this code puts the popup image top left corner only halfway
    // down the thumbnail edge.  It looks fine this way actually, but as
    // I understand this code it should put popup top left at thumbnail
    // bottom right.
    nwa.x = tree_view_x + tn_rec.x + tn_rec.width - h_adj;
    nwa.y = tree_view_y + tn_rec.y + tn_rec.height;
    nwa.width = popup_size;
    nwa.height = popup_size;
    nwa.wclass = GDK_INPUT_OUTPUT;
    nwa.window_type = GDK_WINDOW_CHILD;
    nwa.override_redirect = TRUE;

    GdkWindow *root_window
        = gdk_screen_get_root_window (gdk_screen_get_default ());

    GdkWindow *popup_image_window
        = gdk_window_new (root_window, &nwa,
        GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR);

    /* Iterator for the data in the current row of the list.  */
    GtkTreeIter iter;
    gtk_tree_model_get_iter (GTK_TREE_MODEL (list_store), &iter, path);

    char *file, *ancillary_file, *polsarpro_aux_info;
    gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
                        COL_INPUT_FILE, &file,
                        COL_ANCILLARY_FILE, &ancillary_file,
                        COL_POLSARPRO_INFO, &polsarpro_aux_info,
                        -1);

    char *metadata_file = meta_file_name (file);
    char *data_file = data_file_name (file);
    char *lut_basename = extract_lut_name(polsarpro_aux_info);

    if (is_polsarpro(file)) {
      if(strlen(metadata_file) > 0) {
	g_free(data_file);
	data_file = (gchar*)g_malloc(sizeof(gchar)*(strlen(metadata_file)));
	sprintf(data_file, "%s", metadata_file);
      }
      else {
	g_free(metadata_file);
	metadata_file = (gchar*)g_malloc(sizeof(gchar)*(strlen(data_file) + 5));
	sprintf(metadata_file, "%s%s", data_file, ".hdr");
      }
      if (!fileExists(metadata_file)) strcpy(metadata_file, "");
    }

    GdkPixbuf *popup_image_pixbuf
      = make_input_image_thumbnail_pixbuf (metadata_file, data_file, lut_basename,
                                           THUMB_SIZE_BIG);

    if (!popup_image_pixbuf && strlen(ancillary_file) > 0)
    {
        popup_image_pixbuf = make_input_image_thumbnail_pixbuf (
          ancillary_file, ancillary_file, lut_basename, THUMB_SIZE_BIG);          
    }

    g_free(file);
    g_free(ancillary_file);
    g_free(metadata_file);
    g_free(data_file);
    g_free(polsarpro_aux_info);
    free(lut_basename);

    if (popup_image_pixbuf)
    {
        gdk_window_show (popup_image_window);

        /* Magic number understood by gdk_draw_pixbuf to mean "use pixbuf
        width".  */
        const gint use_pixbuf_width = -1;
        gdk_draw_pixbuf (GDK_DRAWABLE (popup_image_window),
            NULL,
            popup_image_pixbuf,
            0, 0, 0, 0,
            use_pixbuf_width, use_pixbuf_width,
            GDK_RGB_DITHER_NONE,
            0, 0);

        g_object_unref (popup_image_pixbuf);

        return popup_image_window;
    }
    else
    {
        return NULL;
    }
}
Пример #2
0
/* \brief Create and initialise location selector.
 * \param fname The name of the file, which contains locations data. Can be NULL.
 * \param flags Bitise or of flags indicating which columns to display.
 * \param location Newly allocated string containing location (city, country)
 * \param lat Pointer to where the latitude should be stored.
 * \param lon Pointer to where the longitude should be stored.
 * \param alt Pointer to where the altitude should be stored.
 * \param wx Newly allocated string containing the four letter weather station name.
 * \return TRUE if a location has been selected and the returned data is valid,
 *         FALSE otherwise, fx. if the user has clicked on the Cancel button.
 *
 * \note All data fields will be populated (and both strings allocated) no matter which
 *       flags have been passed by the user. The flags influence only how the tree view
 *       is displayed.
 */
gboolean
loc_tree_create (const gchar *fname,
                     guint    flags,
                     gchar  **loc,
                     gfloat  *lat,
                     gfloat  *lon,
                     guint   *alt,
                     gchar  **wx)
{
     GtkCellRenderer     *renderer;  /* tree view cell renderer */
     GtkTreeViewColumn   *column;    /* tree view column used to add columns */
     GtkTreeModel        *model;     /* tree model */
     GtkWidget           *view;      /* tree view widget */
     GtkTreeSelection    *selection; /* used to set selection checking func */
     GtkWidget           *swin;      /* scrolled window widget */
     GtkWidget           *dialog;    /* the dialog widget */
     gint                 response;  /* response ID returned by gtk_dialog_run */
     gchar               *ffname;

     /* return false if specified file does not exist */
     //     g_return_val_if_fail (g_file_test (fname, G_FILE_TEST_IS_REGULAR), FALSE);

     if (!fname) {
          ffname = data_file_name ("locations.dat");
     }
     else {
          ffname = g_strdup (fname);
     }

     view = gtk_tree_view_new ();
    gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE);

     /* Create columns.
        Note that there are several ways to create and add the individual
        columns, especially there are tree_view_insert_col functions, which
        do not require explicit creation of columns. I have chosen to
        explicitly ceate the columns in order to be able to hide them
        according to the flags parameter.
     */

     /* --- Column #1 --- */
     renderer = gtk_cell_renderer_text_new ();
     column = gtk_tree_view_column_new_with_attributes (_("Location"),
                                                                    renderer,
                                                                    "text", TREE_COL_NAM,
                                                                    NULL);
     gtk_tree_view_insert_column (GTK_TREE_VIEW (view),
                                         column,
                                         -1);
     if (!(flags & TREE_COL_FLAG_NAME)) {
          gtk_tree_view_column_set_visible (column, FALSE);
     }

     /* --- Column #2 --- */
     renderer = gtk_cell_renderer_text_new ();
     column = gtk_tree_view_column_new_with_attributes (_("Lat"),
                                                                    renderer,
                                                                    "text", TREE_COL_LAT,
                                                                    NULL);
     gtk_tree_view_column_set_alignment (column, 0.5);
     gtk_tree_view_column_set_cell_data_func (column,
                                                        renderer,
                                                        loc_tree_float_cell_data_function,
                                                        GUINT_TO_POINTER (TREE_COL_LAT),
                                                        NULL);
     gtk_tree_view_insert_column (GTK_TREE_VIEW (view),
                                         column,
                                         -1);
     if (!(flags & TREE_COL_FLAG_LAT)) {
          gtk_tree_view_column_set_visible (column, FALSE);
     }
                             

     /* --- Column #3 --- */
     renderer = gtk_cell_renderer_text_new ();
     column = gtk_tree_view_column_new_with_attributes (_("Lon"),
                                                                    renderer,
                                                                    "text", TREE_COL_LON,
                                                                    NULL);
     gtk_tree_view_column_set_alignment (column, 0.5);
     gtk_tree_view_column_set_cell_data_func (column,
                                                        renderer,
                                                        loc_tree_float_cell_data_function,
                                                        GUINT_TO_POINTER (TREE_COL_LON),
                                                        NULL);
     gtk_tree_view_insert_column (GTK_TREE_VIEW (view),
                                         column,
                                         -1);
     if (!(flags & TREE_COL_FLAG_LON)) {
          gtk_tree_view_column_set_visible (column, FALSE);
     }


     /* --- Column #4 --- */
     renderer = gtk_cell_renderer_text_new ();
     column = gtk_tree_view_column_new_with_attributes (_("Alt"),
                                                                    renderer,
                                                                    "text", TREE_COL_ALT,
                                                                    NULL);
     gtk_tree_view_column_set_alignment (column, 0.5);
     gtk_tree_view_column_set_cell_data_func (column,
                                                        renderer,
                                                        loc_tree_int_cell_data_function,
                                                        GUINT_TO_POINTER (TREE_COL_ALT),
                                                        NULL);
     gtk_tree_view_insert_column (GTK_TREE_VIEW (view),
                                         column,
                                         -1);
     if (!(flags & TREE_COL_FLAG_ALT)) {
          gtk_tree_view_column_set_visible (column, FALSE);
     }

     /* --- Column #5 --- */
     renderer = gtk_cell_renderer_text_new ();
     column = gtk_tree_view_column_new_with_attributes (_("WX"),
                                                                    renderer,
                                                                    "text", TREE_COL_WX,
                                                                    NULL);
     gtk_tree_view_insert_column (GTK_TREE_VIEW (view),
                                         column,
                                         -1);
     if (!(flags & TREE_COL_FLAG_WX)) {
          gtk_tree_view_column_set_visible (column, FALSE);
     }

     /* Invisible column holding 0 or 1 indicating whether a row can be selected
        or not. We use this to prevent the user from selecting regions or
        countries, since they are not valid locations.
     */
     renderer = gtk_cell_renderer_text_new ();
     column = gtk_tree_view_column_new_with_attributes (_("X"),
                                                                    renderer,
                                                                    "text", TREE_COL_SELECT,
                                                                    NULL);
     gtk_tree_view_insert_column (GTK_TREE_VIEW (view),
                                         column,
                                         -1);
     gtk_tree_view_column_set_visible (column, FALSE);
     

     /* create model and finalise treeview */
     model = loc_tree_create_and_fill_model (ffname);

     /* we are done with it */
     g_free (ffname);

     gtk_tree_view_set_model (GTK_TREE_VIEW (view), model);

     /* The tree view has acquired its own reference to the
      *  model, so we can drop ours. That way the model will
      *  be freed automatically when the tree view is destroyed */
     g_object_unref (model);

     /* make sure rows are checked when they are selected */
     /* ... but first create the dialog window .... */

     /* scrolled window */
     swin = gtk_scrolled_window_new (NULL, NULL);
     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
                                             GTK_POLICY_NEVER,
                                             GTK_POLICY_AUTOMATIC);
     gtk_container_add (GTK_CONTAINER (swin), view);

     /**** CRASH (because treeview float data func) *****/
     gtk_widget_show_all (swin);

     /* dialog window */
     dialog = gtk_dialog_new_with_buttons (_("Select Location"),
                                                    NULL,
                                                    GTK_DIALOG_MODAL,
                                                    GTK_STOCK_CANCEL,
                                                    GTK_RESPONSE_REJECT,
                                                    GTK_STOCK_OK,
                                                    GTK_RESPONSE_ACCEPT,
                                                    NULL);

     gtk_window_set_default_size (GTK_WINDOW (dialog), 450, 400);

     /* OK button disabled by default until a valid selection is made */
     gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
                                                GTK_RESPONSE_ACCEPT,
                                                FALSE);
     gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area(GTK_DIALOG(dialog))), swin, TRUE, TRUE, 0);

     /* connect selection checker for the tree-view;
        we have waited so far, because we want to pass the dialog as
        parameter
     */
     selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
     gtk_tree_selection_set_select_function (selection,
                                                       loc_tree_check_selection_cb,
                                                       dialog, NULL);

     response = gtk_dialog_run (GTK_DIALOG (dialog));
     switch (response) {

     case GTK_RESPONSE_ACCEPT:
          loc_tree_get_selection (view, loc, lat, lon, alt, wx);
          gtk_widget_destroy (dialog);

          /* send debug message */
          sat_log_log (SAT_LOG_LEVEL_INFO,
                          _("%s: Selected %s"),
                          __FUNCTION__, *loc);

          return TRUE;
          break;

     default:
          gtk_widget_destroy (dialog);

          /* send debug message */
          sat_log_log (SAT_LOG_LEVEL_INFO,
                          _("%s: No location selected"),
                          __FUNCTION__);

          return FALSE;

          break;
     }

     /*** FIXME: Never reached code; should be removed */
     gtk_widget_destroy (dialog);

     return FALSE;
}