* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
#include "gtksettings.h"
#include "gtksizerequest.h"
#include "gtkwindow.h"
+#include "gtkcontainerprivate.h"
#include "gtkintl.h"
#include "gtkprivate.h"
#include "gtktypebuiltins.h"
-#define BORDER_SPACING 0
-#define DEFAULT_IPADDING 1
-
/* Properties */
enum {
PROP_0,
widget_class->draw = gtk_menu_bar_draw;
widget_class->hierarchy_changed = gtk_menu_bar_hierarchy_changed;
+ gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_MENU_BAR);
+
menu_shell_class->submenu_placement = GTK_TOP_BOTTOM;
menu_shell_class->get_popup_delay = gtk_menu_bar_get_popup_delay;
menu_shell_class->move_current = gtk_menu_bar_move_current;
GTK_SHADOW_OUT,
GTK_PARAM_READABLE));
+ /**
+ * GtkMenuBar:internal-padding:
+ *
+ * Amount of border space between the menubar shadow and the menu items
+ *
+ * Deprecated: 3.8: use the standard padding CSS property (through objects
+ * like #GtkStyleContext and #GtkCssProvider); the value of this style
+ * property is ignored.
+ */
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("internal-padding",
P_("Internal padding"),
P_("Amount of border space between the menubar shadow and the menu items"),
0,
G_MAXINT,
- DEFAULT_IPADDING,
- GTK_PARAM_READABLE));
+ 0,
+ GTK_PARAM_READABLE |
+ G_PARAM_DEPRECATED));
g_type_class_add_private (gobject_class, sizeof (GtkMenuBarPrivate));
}
GtkMenuShell *menu_shell;
GtkWidget *child;
GList *children;
- gint ipadding;
guint border_width;
gboolean use_toggle_size, use_maximize;
gint child_minimum, child_natural;
+ GtkStyleContext *context;
+ GtkBorder border;
+ GtkStateFlags flags;
*minimum = 0;
*natural = 0;
}
}
- gtk_widget_style_get (widget, "internal-padding", &ipadding, NULL);
- border_width = gtk_container_get_border_width (GTK_CONTAINER (menu_bar));
- *minimum += (border_width + ipadding + BORDER_SPACING) * 2;
- *natural += (border_width + ipadding + BORDER_SPACING) * 2;
+ context = gtk_widget_get_style_context (widget);
+ flags = gtk_widget_get_state_flags (widget);
+ gtk_style_context_get_padding (context, flags, &border);
- if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
- GtkStyleContext *context;
- GtkBorder *border;
+ *minimum += border.left + border.right;
+ *natural += border.left + border.right;
+ }
+ else
+ {
+ *minimum += border.top + border.bottom;
+ *natural += border.top + border.bottom;
+ }
- context = gtk_widget_get_style_context (widget);
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (menu_bar));
+ *minimum += border_width * 2;
+ *natural += border_width * 2;
- gtk_style_context_get (context, 0,
- "border-width", &border,
- NULL);
+ if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
+ {
+ gtk_style_context_get_border (context, flags, &border);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
- *minimum += border->left + border->right;
- *natural += border->left + border->right;
+ *minimum += border.left + border.right;
+ *natural += border.left + border.right;
}
else
{
- *minimum += border->top + border->bottom;
- *natural += border->top + border->bottom;
+ *minimum += border.top + border.bottom;
+ *natural += border.top + border.bottom;
}
- gtk_border_free (border);
}
}
GtkWidget *child;
GList *children;
GtkAllocation remaining_space;
- gint ipadding;
guint border_width;
GArray *requested_sizes;
gint toggle_size;
if (menu_shell->priv->children)
{
- gtk_widget_style_get (widget, "internal-padding", &ipadding, NULL);
-
+ GtkStyleContext *context;
+ GtkStateFlags flags;
+ GtkBorder border;
+
+ context = gtk_widget_get_style_context (widget);
+ flags = gtk_widget_get_state_flags (widget);
+ gtk_style_context_get_padding (context, flags, &border);
+
border_width = gtk_container_get_border_width (GTK_CONTAINER (menu_bar));
- remaining_space.x = (border_width +
- ipadding +
- BORDER_SPACING);
- remaining_space.y = (border_width +
- ipadding +
- BORDER_SPACING);
+
+ remaining_space.x = (border_width + border.left);
+ remaining_space.y = (border_width + border.top);
remaining_space.width = allocation->width -
- 2 * (border_width + ipadding + BORDER_SPACING);
+ 2 * (border_width) - border.left - border.right;
remaining_space.height = allocation->height -
- 2 * (border_width + ipadding + BORDER_SPACING);
-
+ 2 * (border_width) - border.top - border.bottom;
+
if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
{
- GtkStyleContext *context;
- GtkBorder *border;
+ gtk_style_context_get_border (context, flags, &border);
- context = gtk_widget_get_style_context (widget);
- gtk_style_context_get (context, 0,
- "border-width", &border,
- NULL);
-
- remaining_space.x += border->left;
- remaining_space.y += border->top;
- remaining_space.width -= border->left + border->right;
- remaining_space.height -= border->top + border->bottom;
-
- gtk_border_free (border);
+ remaining_space.x += border.left;
+ remaining_space.y += border.top;
+ remaining_space.width -= border.left + border.right;
+ remaining_space.height -= border.top + border.bottom;
}
requested_sizes = g_array_new (FALSE, FALSE, sizeof (GtkRequestedSize));
remaining_space.width -= request->minimum_size;
if (i + 1 == requested_sizes->len && GTK_IS_MENU_ITEM (request->data) &&
- gtk_menu_item_get_right_justified (request->data))
+ GTK_MENU_ITEM (request->data)->priv->right_justify)
ltr = !ltr;
if (ltr)
remaining_space.height -= request->minimum_size;
if (i + 1 == requested_sizes->len && GTK_IS_MENU_ITEM (request->data) &&
- gtk_menu_item_get_right_justified (request->data))
+ GTK_MENU_ITEM (request->data)->priv->right_justify)
ttb = !ttb;
if (ttb)
cairo_t *cr)
{
GtkStyleContext *context;
- GtkStateFlags state;
int border;
border = gtk_container_get_border_width (GTK_CONTAINER (widget));
context = gtk_widget_get_style_context (widget);
- state = gtk_widget_get_state_flags (widget);
- gtk_style_context_set_state (context, state);
+ gtk_render_background (context, cr,
+ border, border,
+ gtk_widget_get_allocated_width (widget) - border * 2,
+ gtk_widget_get_allocated_height (widget) - border * 2);
if (get_shadow_type (GTK_MENU_BAR (widget)) != GTK_SHADOW_NONE)
- gtk_render_background (context, cr,
- border, border,
- gtk_widget_get_allocated_width (widget) - border * 2,
- gtk_widget_get_allocated_height (widget) - border * 2);
-
- gtk_render_frame (context, cr,
- border, border,
- gtk_widget_get_allocated_width (widget) - border * 2,
- gtk_widget_get_allocated_height (widget) - border * 2);
+ gtk_render_frame (context, cr,
+ border, border,
+ gtk_widget_get_allocated_width (widget) - border * 2,
+ gtk_widget_get_allocated_height (widget) - border * 2);
GTK_WIDGET_CLASS (gtk_menu_bar_parent_class)->draw (widget, cr);
g_object_notify (G_OBJECT (menubar), "child-pack-direction");
}
}
+
+/**
+ * gtk_menu_bar_new_from_model:
+ * @model: a #GMenuModel
+ *
+ * Creates a new #GtkMenuBar and populates it with menu items
+ * and submenus according to @model.
+ *
+ * The created menu items are connected to actions found in the
+ * #GtkApplicationWindow to which the menu bar belongs - typically
+ * by means of being contained within the #GtkApplicationWindows
+ * widget hierarchy.
+ *
+ * Returns: a new #GtkMenuBar
+ *
+ * Since: 3.4
+ */
+GtkWidget *
+gtk_menu_bar_new_from_model (GMenuModel *model)
+{
+ GtkWidget *menubar;
+
+ g_return_val_if_fail (G_IS_MENU_MODEL (model), NULL);
+
+ menubar = gtk_menu_bar_new ();
+ gtk_menu_shell_bind_model (GTK_MENU_SHELL (menubar), model, NULL, FALSE);
+
+ return menubar;
+}