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