Home | History | Annotate | Download | only in gtk
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef UI_BASE_GTK_GTK_FLOATING_CONTAINER_H_
      6 #define UI_BASE_GTK_GTK_FLOATING_CONTAINER_H_
      7 
      8 #include <gdk/gdk.h>
      9 #include <gtk/gtk.h>
     10 
     11 #include "ui/base/ui_export.h"
     12 
     13 // A specialized container, which is a cross between a GtkBin and a
     14 // GtkFixed. This container dervies from GtkBin and the implementation of
     15 // gtk_container_add() is the same: only one GtkWidget can be added through
     16 // that interface. The GtkBin portion contains normal content and is given the
     17 // same allocation that this container has.
     18 //
     19 // In addition, any number of widgets can be added through the
     20 // gtk_floating_container_add_floating() method, which provides functionality
     21 // similar to a GtkFixed. Unlike a GtkFixed, coordinates are not set when you
     22 // gtk_fixed_put(). The location of the floating widgets is determined while
     23 // running the "set-floating-position" signal, which is emitted during this
     24 // container's "size-allocate" handler.
     25 //
     26 // The "set-floating-position" signal is (semi-)mandatory if you want widgets
     27 // placed anywhere other than the origin and should have the following
     28 // signature:
     29 //
     30 //   void (*set_floating_position)(GtkFloatingContainer* container,
     31 //                                 GtkAllocation* allocation,
     32 //                                 gpointer userdata);
     33 //
     34 // Your handler should, for each floating widget, set the "x" and "y" child
     35 // properties.
     36 
     37 G_BEGIN_DECLS
     38 
     39 #define GTK_TYPE_FLOATING_CONTAINER                                 \
     40     (gtk_floating_container_get_type())
     41 #define GTK_FLOATING_CONTAINER(obj)                                 \
     42     (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_FLOATING_CONTAINER, \
     43                                 GtkFloatingContainer))
     44 #define GTK_FLOATING_CONTAINER_CLASS(klass)                         \
     45     (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_FLOATING_CONTAINER,  \
     46                              GtkFloatingContainerClass))
     47 #define GTK_IS_FLOATING_CONTAINER(obj)                              \
     48     (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_FLOATING_CONTAINER))
     49 #define GTK_IS_FLOATING_CONTAINER_CLASS(klass)                      \
     50     (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_FLOATING_CONTAINER))
     51 #define GTK_FLOATING_CONTAINER_GET_CLASS(obj)                       \
     52     (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_FLOATING_CONTAINER,  \
     53                                GtkFloatingContainerClass))
     54 
     55 typedef struct _GtkFloatingContainer GtkFloatingContainer;
     56 typedef struct _GtkFloatingContainerClass GtkFloatingContainerClass;
     57 typedef struct _GtkFloatingContainerChild GtkFloatingContainerChild;
     58 
     59 struct _GtkFloatingContainer {
     60   // Parent class.
     61   GtkBin bin;
     62 
     63   // A GList of all our floating children, in GtkFloatingContainerChild
     64   // structs. Owned by the GtkFloatingContainer.
     65   GList* floating_children;
     66 };
     67 
     68 struct _GtkFloatingContainerClass {
     69   GtkBinClass parent_class;
     70 };
     71 
     72 // Internal structure used to associate a widget and its x/y child properties.
     73 struct _GtkFloatingContainerChild {
     74   GtkWidget* widget;
     75   gint x;
     76   gint y;
     77 };
     78 
     79 UI_EXPORT GType      gtk_floating_container_get_type() G_GNUC_CONST;
     80 UI_EXPORT GtkWidget* gtk_floating_container_new();
     81 UI_EXPORT void       gtk_floating_container_add_floating(
     82     GtkFloatingContainer* container,
     83     GtkWidget* widget);
     84 // Use gtk_container_remove to remove all widgets; both widgets added with
     85 // gtk_container_add() and gtk_floating_container_add_floating().
     86 
     87 G_END_DECLS
     88 
     89 #endif  // UI_BASE_GTK_GTK_FLOATING_CONTAINER_H_
     90