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_CHROME_SHRINKABLE_HBOX_H_
      6 #define CHROME_BROWSER_UI_GTK_GTK_CHROME_SHRINKABLE_HBOX_H_
      7 #pragma once
      8 
      9 #include <gdk/gdk.h>
     10 #include <gtk/gtk.h>
     11 
     12 // A specialized container derived from GtkHBox, which can shrink or hide its
     13 // children one by one to fit into its width.
     14 //
     15 // Limitations of this container:
     16 // - All children should have the same pack type, otherwise they may be
     17 //   overlapped with each other.
     18 // - All children must be packed with expand == false and fill == false,
     19 //   otherwise they may be overlapped with each other.
     20 // - The visibility of a child is adjusted automatically according to the
     21 //   container's width. The child may not show or hide itself.
     22 
     23 G_BEGIN_DECLS
     24 
     25 #define GTK_TYPE_CHROME_SHRINKABLE_HBOX                                 \
     26     (gtk_chrome_shrinkable_hbox_get_type())
     27 #define GTK_CHROME_SHRINKABLE_HBOX(obj)                                 \
     28     (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_CHROME_SHRINKABLE_HBOX, \
     29                                 GtkChromeShrinkableHBox))
     30 #define GTK_CHROME_SHRINKABLE_HBOX_CLASS(klass)                         \
     31     (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_CHROME_SHRINKABLE_HBOX,  \
     32                              GtkChromeShrinkableHBoxClass))
     33 #define GTK_IS_CHROME_SHRINKABLE_HBOX(obj)                              \
     34     (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_CHROME_SHRINKABLE_HBOX))
     35 #define GTK_IS_CHROME_SHRINKABLE_HBOX_CLASS(klass)                      \
     36     (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_CHROME_SHRINKABLE_HBOX))
     37 #define GTK_CHROME_SHRINKABLE_HBOX_GET_CLASS(obj)                       \
     38     (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_CHROME_SHRINKABLE_HBOX,  \
     39                                GtkChromeShrinkableHBoxClass))
     40 
     41 typedef struct _GtkChromeShrinkableHBox GtkChromeShrinkableHBox;
     42 typedef struct _GtkChromeShrinkableHBoxClass GtkChromeShrinkableHBoxClass;
     43 
     44 struct _GtkChromeShrinkableHBox {
     45   // Parent class.
     46   GtkHBox hbox;
     47 
     48   gboolean hide_child_directly;
     49 
     50   // Private
     51   int children_width_requisition;
     52 };
     53 
     54 struct _GtkChromeShrinkableHBoxClass {
     55   GtkHBoxClass parent_class;
     56 };
     57 
     58 GType gtk_chrome_shrinkable_hbox_get_type() G_GNUC_CONST;
     59 
     60 // Creates a new shrinkable hbox.
     61 // If |hide_child_directly| is true then its child widgets will be hid directly
     62 // if they are too wide to be fit into the hbox's width. Otherwise they will be
     63 // shrunk first before being hid completely.
     64 GtkWidget* gtk_chrome_shrinkable_hbox_new(gboolean hide_child_directly,
     65                                           gboolean homogeneous,
     66                                           gint spacing);
     67 
     68 void gtk_chrome_shrinkable_hbox_set_hide_child_directly(
     69     GtkChromeShrinkableHBox* box, gboolean hide_child_directly);
     70 
     71 gboolean gtk_chrome_shrinkable_hbox_get_hide_child_directly(
     72     GtkChromeShrinkableHBox* box);
     73 
     74 void gtk_chrome_shrinkable_hbox_pack_start(GtkChromeShrinkableHBox* box,
     75                                            GtkWidget* child,
     76                                            guint padding);
     77 
     78 void gtk_chrome_shrinkable_hbox_pack_end(GtkChromeShrinkableHBox* box,
     79                                          GtkWidget* child,
     80                                          guint padding);
     81 
     82 gint gtk_chrome_shrinkable_hbox_get_visible_child_count(
     83     GtkChromeShrinkableHBox* box);
     84 
     85 G_END_DECLS
     86 
     87 #endif  // CHROME_BROWSER_UI_GTK_GTK_CHROME_SHRINKABLE_HBOX_H_
     88