]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfilechooserentry.c
Add explanation to failing test
[~andy/gtk] / gtk / gtkfilechooserentry.c
index 2a37a79d8b237df9feac6f2acbb0afe1961d323d..009d842f37c7424e060f7b67277f2509ae829323 100644 (file)
  */
 
 #include "config.h"
+
+#include "gtkfilechooserentry.h"
+
 #include <string.h>
 
 #include "gtkalignment.h"
 #include "gtkcelllayout.h"
 #include "gtkcellrenderertext.h"
 #include "gtkentry.h"
-#include "gtkfilechooserentry.h"
 #include "gtklabel.h"
 #include "gtkmain.h"
+#include "gtksizerequest.h"
 #include "gtkwindow.h"
 #include "gtkintl.h"
 
@@ -101,7 +104,7 @@ enum
 
 #define COMPLETION_FEEDBACK_TIMEOUT_MS 2000
 
-static void     gtk_file_chooser_entry_iface_init     (GtkEditableClass *iface);
+static void     gtk_file_chooser_entry_iface_init     (GtkEditableInterface *iface);
 
 static void     gtk_file_chooser_entry_finalize       (GObject          *object);
 static void     gtk_file_chooser_entry_dispose        (GObject          *object);
@@ -165,7 +168,7 @@ static void remove_completion_feedback (GtkFileChooserEntry *chooser_entry);
 static void pop_up_completion_feedback (GtkFileChooserEntry *chooser_entry,
                                        const gchar         *feedback);
 
-static GtkEditableClass *parent_editable_iface;
+static GtkEditableInterface *parent_editable_iface;
 
 G_DEFINE_TYPE_WITH_CODE (GtkFileChooserEntry, _gtk_file_chooser_entry, GTK_TYPE_ENTRY,
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
@@ -190,7 +193,7 @@ _gtk_file_chooser_entry_class_init (GtkFileChooserEntryClass *class)
 }
 
 static void
-gtk_file_chooser_entry_iface_init (GtkEditableClass *iface)
+gtk_file_chooser_entry_iface_init (GtkEditableInterface *iface)
 {
   parent_editable_iface = g_type_interface_peek_parent (iface);
 
@@ -879,24 +882,23 @@ gtk_file_chooser_entry_unmap (GtkWidget *widget)
 }
 
 static gboolean
-completion_feedback_window_expose_event_cb (GtkWidget      *widget,
-                                           GdkEventExpose *event,
-                                           gpointer        data)
+completion_feedback_window_draw_cb (GtkWidget *widget,
+                                    cairo_t   *cr,
+                                    gpointer   data)
 {
   /* Stolen from gtk_tooltip_paint_window() */
 
   GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (data);
 
-  gtk_paint_flat_box (chooser_entry->completion_feedback_window->style,
-                     chooser_entry->completion_feedback_window->window,
+  gtk_paint_flat_box (gtk_widget_get_style (chooser_entry->completion_feedback_window),
+                      cr,
                      GTK_STATE_NORMAL,
                      GTK_SHADOW_OUT,
-                     NULL,
                      chooser_entry->completion_feedback_window,
                      "tooltip",
                      0, 0,
-                     chooser_entry->completion_feedback_window->allocation.width,
-                     chooser_entry->completion_feedback_window->allocation.height);
+                      gtk_widget_get_allocated_width (widget),
+                      gtk_widget_get_allocated_height (widget));
 
   return FALSE;
 }
@@ -907,7 +909,7 @@ set_invisible_mouse_cursor (GdkWindow *window)
   GdkDisplay *display;
   GdkCursor *cursor;
 
-  display = gdk_drawable_get_display (window);
+  display = gdk_window_get_display (window);
   cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
 
   gdk_window_set_cursor (window, cursor);
@@ -923,7 +925,7 @@ completion_feedback_window_realize_cb (GtkWidget *widget,
    * GtkEntry hides the cursor when the user types.  We don't want the cursor to
    * come back if the completion feedback ends up where the mouse is.
    */
-  set_invisible_mouse_cursor (widget->window);
+  set_invisible_mouse_cursor (gtk_widget_get_window (widget));
 }
 
 static void
@@ -931,6 +933,7 @@ create_completion_feedback_window (GtkFileChooserEntry *chooser_entry)
 {
   /* Stolen from gtk_tooltip_init() */
 
+  GtkStyle *style;
   GtkWidget *alignment;
 
   chooser_entry->completion_feedback_window = gtk_window_new (GTK_WINDOW_POPUP);
@@ -941,16 +944,15 @@ create_completion_feedback_window (GtkFileChooserEntry *chooser_entry)
   gtk_widget_set_name (chooser_entry->completion_feedback_window, "gtk-tooltip");
 
   alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
+  style = gtk_widget_get_style (chooser_entry->completion_feedback_window);
   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
-                            chooser_entry->completion_feedback_window->style->ythickness,
-                            chooser_entry->completion_feedback_window->style->ythickness,
-                            chooser_entry->completion_feedback_window->style->xthickness,
-                            chooser_entry->completion_feedback_window->style->xthickness);
+                             style->ythickness, style->ythickness,
+                             style->xthickness, style->xthickness);
   gtk_container_add (GTK_CONTAINER (chooser_entry->completion_feedback_window), alignment);
   gtk_widget_show (alignment);
 
-  g_signal_connect (chooser_entry->completion_feedback_window, "expose-event",
-                   G_CALLBACK (completion_feedback_window_expose_event_cb), chooser_entry);
+  g_signal_connect (chooser_entry->completion_feedback_window, "draw",
+                   G_CALLBACK (completion_feedback_window_draw_cb), chooser_entry);
   g_signal_connect (chooser_entry->completion_feedback_window, "realize",
                    G_CALLBACK (completion_feedback_window_realize_cb), chooser_entry);
   /* FIXME: connect to motion-notify-event, and *show* the cursor when the mouse moves */
@@ -996,13 +998,16 @@ get_entry_cursor_x (GtkFileChooserEntry *chooser_entry,
   gint layout_x, layout_y;
   gint layout_index;
   PangoRectangle strong_pos;
+  gint start_pos, end_pos;
 
   layout = gtk_entry_get_layout (GTK_ENTRY (chooser_entry));
 
   gtk_entry_get_layout_offsets (GTK_ENTRY (chooser_entry), &layout_x, &layout_y);
 
+  gtk_editable_get_selection_bounds (GTK_EDITABLE (chooser_entry), &start_pos, &end_pos);
   layout_index = gtk_entry_text_index_to_layout_index (GTK_ENTRY (chooser_entry),
-                                                      GTK_ENTRY (chooser_entry)->current_pos);
+                                                       end_pos);
+
 
   pango_layout_get_cursor_pos (layout, layout_index, &strong_pos, NULL);
 
@@ -1015,22 +1020,24 @@ show_completion_feedback_window (GtkFileChooserEntry *chooser_entry)
   /* More or less stolen from gtk_tooltip_position() */
 
   GtkRequisition feedback_req;
+  GtkWidget *widget = GTK_WIDGET (chooser_entry);
   gint entry_x, entry_y;
   gint cursor_x;
-  GtkAllocation *entry_allocation;
+  GtkAllocation entry_allocation;
   int feedback_x, feedback_y;
 
-  gtk_widget_size_request (chooser_entry->completion_feedback_window, &feedback_req);
+  gtk_widget_get_preferred_size (chooser_entry->completion_feedback_window,
+                                 &feedback_req, NULL);
 
-  gdk_window_get_origin (GTK_WIDGET (chooser_entry)->window, &entry_x, &entry_y);
-  entry_allocation = &(GTK_WIDGET (chooser_entry)->allocation);
+  gdk_window_get_origin (gtk_widget_get_window (widget), &entry_x, &entry_y);
+  gtk_widget_get_allocation (widget, &entry_allocation);
 
   get_entry_cursor_x (chooser_entry, &cursor_x);
 
   /* FIXME: fit to the screen if we bump on the screen's edge */
   /* cheap "half M-width", use height as approximation of character em-size */
-  feedback_x = entry_x + cursor_x + entry_allocation->height / 2;
-  feedback_y = entry_y + (entry_allocation->height - feedback_req.height) / 2;
+  feedback_x = entry_x + cursor_x + entry_allocation.height / 2;
+  feedback_y = entry_y + (entry_allocation.height - feedback_req.height) / 2;
 
   gtk_window_move (GTK_WINDOW (chooser_entry->completion_feedback_window), feedback_x, feedback_y);
   gtk_widget_show (chooser_entry->completion_feedback_window);
@@ -1245,7 +1252,7 @@ gtk_file_chooser_entry_key_press_event (GtkWidget *widget,
 
   /* This is a bit evil -- it makes Tab never leave the entry. It basically
    * makes it 'safe' for people to hit. */
-  if (event->keyval == GDK_Tab && !control_pressed)
+  if (event->keyval == GDK_KEY_Tab && !control_pressed)
     {
       if (chooser_entry->has_completion)
        gtk_editable_set_position (editable, gtk_entry_get_text_length (entry));
@@ -1724,7 +1731,7 @@ insert_text_callback (GtkFileChooserEntry *chooser_entry,
        *position + (colon - new_text) != 1) ||
       (new_text_length > 0 &&
        *position <= 1 &&
-       GTK_ENTRY (chooser_entry)->text_length >= 2 &&
+       gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)) >= 2 &&
        gtk_entry_get_text (GTK_ENTRY (chooser_entry))[1] == ':'))
     {
       gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
@@ -1743,7 +1750,7 @@ delete_text_callback (GtkFileChooserEntry *chooser_entry,
 {
   /* If deleting a drive letter, delete the colon, too */
   if (start_pos == 0 && end_pos == 1 &&
-      GTK_ENTRY (chooser_entry)->text_length >= 2 &&
+      gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)) >= 2 &&
       gtk_entry_get_text (GTK_ENTRY (chooser_entry))[1] == ':')
     {
       g_signal_handlers_block_by_func (chooser_entry,