[tepl] InfoBar: private function for the set_size_request() safety net
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] InfoBar: private function for the set_size_request() safety net
- Date: Fri, 23 Jun 2017 15:13:51 +0000 (UTC)
commit 64bd4f38775b0635652868221f2c9179c06eb479
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Jun 23 17:01:48 2017 +0200
InfoBar: private function for the set_size_request() safety net
tepl_tab_add_info_bar() takes a GtkInfoBar param, to be more re-usable
in case someone doesn't like TeplInfoBar. So keep the safety net in
tepl_tab_add_info_bar().
Add the safety net in tepl_info_bar_init(), because a TeplInfoBar can be
added to another container than TeplTab.
So create the private function _tepl_info_bar_set_size_request() to have
the code in common.
tepl/tepl-info-bar.c | 29 +++++++++++++++++++++++++++++
tepl/tepl-info-bar.h | 5 ++++-
tepl/tepl-tab.c | 23 ++---------------------
3 files changed, 35 insertions(+), 22 deletions(-)
---
diff --git a/tepl/tepl-info-bar.c b/tepl/tepl-info-bar.c
index 0f660d8..cc732f4 100644
--- a/tepl/tepl-info-bar.c
+++ b/tepl/tepl-info-bar.c
@@ -83,6 +83,8 @@ tepl_info_bar_init (TeplInfoBar *info_bar)
priv = tepl_info_bar_get_instance_private (info_bar);
+ _tepl_info_bar_set_size_request (GTK_INFO_BAR (info_bar));
+
/* Change the buttons orientation to be vertical.
* With a small window, if 3 or more buttons are shown horizontally,
* there is a ridiculous amount of space for the text. And it can get
@@ -408,3 +410,30 @@ tepl_info_bar_create_label (void)
return label;
}
+
+void
+_tepl_info_bar_set_size_request (GtkInfoBar *info_bar)
+{
+ gint min_width;
+ gint min_height;
+
+ g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
+
+ gtk_widget_get_size_request (GTK_WIDGET (info_bar), &min_width, &min_height);
+
+ /* If min_width != -1, gtk_widget_set_size_request() has already been
+ * called, so don't change the value.
+ */
+ if (min_width == -1)
+ {
+ /* Safety net to avoid in most cases the GtkWindow height to
+ * grow.
+ *
+ * The gtk_label_set_width_chars() call in
+ * tepl_info_bar_create_label() fixes the problem at the root,
+ * but we cannot enforce all GtkLabel of @info_bar to be created
+ * with tepl_info_bar_create_label(), so a safety net is better.
+ */
+ gtk_widget_set_size_request (GTK_WIDGET (info_bar), 300, min_height);
+ }
+}
diff --git a/tepl/tepl-info-bar.h b/tepl/tepl-info-bar.h
index c11e886..ce44d93 100644
--- a/tepl/tepl-info-bar.h
+++ b/tepl/tepl-info-bar.h
@@ -1,7 +1,7 @@
/*
* This file is part of Tepl, a text editor library.
*
- * Copyright 2016 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright 2016, 2017 - Sébastien Wilmet <swilmet gnome org>
*
* Tepl is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
@@ -61,6 +61,9 @@ void tepl_info_bar_add_close_button (TeplInfoBar
*info_bar);
GtkLabel * tepl_info_bar_create_label (void);
+G_GNUC_INTERNAL
+void _tepl_info_bar_set_size_request (GtkInfoBar *info_bar);
+
G_END_DECLS
#endif /* TEPL_INFO_BAR_H */
diff --git a/tepl/tepl-tab.c b/tepl/tepl-tab.c
index 5a3a363..373d8dd 100644
--- a/tepl/tepl-tab.c
+++ b/tepl/tepl-tab.c
@@ -20,6 +20,7 @@
#include "tepl-tab.h"
#include "tepl-view.h"
#include "tepl-buffer.h"
+#include "tepl-info-bar.h"
/**
* SECTION:tab
@@ -316,30 +317,10 @@ void
tepl_tab_add_info_bar (TeplTab *tab,
GtkInfoBar *info_bar)
{
- gint min_width;
- gint min_height;
-
g_return_if_fail (TEPL_IS_TAB (tab));
g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
- gtk_widget_get_size_request (GTK_WIDGET (info_bar), &min_width, &min_height);
-
- /* If min_width != -1, gtk_widget_set_size_request() has already been
- * called, so don't change the value.
- */
- if (min_width == -1)
- {
- /* Safety net to avoid in most cases the GtkWindow height to
- * grow.
- *
- * The gtk_label_set_width_chars() call in
- * tepl_info_bar_create_label() fixes the problem at the root,
- * but we cannot enforce all GtkLabel of @info_bar to have been
- * created with tepl_info_bar_create_label(), so a safety net is
- * better.
- */
- gtk_widget_set_size_request (GTK_WIDGET (info_bar), 300, min_height);
- }
+ _tepl_info_bar_set_size_request (info_bar);
TEPL_TAB_GET_CLASS (tab)->pack_info_bar (tab, info_bar);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]