app: remove the entire dockable tab auto-sizing code

It was totally broken and could never work like this in GTK+ 3.x, and
if it can be reimplemented it should be started from scratch.
This commit is contained in:
Michael Natterer 2018-05-26 16:28:58 +02:00
parent abdd69640d
commit baaa2cd7ca
9 changed files with 111 additions and 586 deletions

View File

@ -112,9 +112,7 @@ static const GimpRadioActionEntry dockable_tab_style_actions[] =
TAB_STYLE ("icon-name",
NC_("tab-style", "I_con & Text"), GIMP_TAB_STYLE_ICON_NAME),
TAB_STYLE ("preview-name",
NC_("tab-style", "St_atus & Text"), GIMP_TAB_STYLE_PREVIEW_NAME),
TAB_STYLE ("automatic",
NC_("tab-style", "Automatic"), GIMP_TAB_STYLE_AUTOMATIC)
NC_("tab-style", "St_atus & Text"), GIMP_TAB_STYLE_PREVIEW_NAME)
};
#undef VIEW_SIZE
@ -179,7 +177,7 @@ dockable_actions_setup (GimpActionGroup *group)
dockable_tab_style_actions,
G_N_ELEMENTS (dockable_tab_style_actions),
NULL,
GIMP_TAB_STYLE_AUTOMATIC,
GIMP_TAB_STYLE_PREVIEW,
G_CALLBACK (dockable_tab_style_cmd_callback));
gimp_action_group_add_radio_actions (group, "dockable-action",
@ -342,8 +340,6 @@ dockable_actions_update (GimpActionGroup *group,
SET_ACTIVE ("dockable-tab-style-icon-name", TRUE);
else if (tab_style == GIMP_TAB_STYLE_PREVIEW_NAME)
SET_ACTIVE ("dockable-tab-style-preview-name", TRUE);
else if (tab_style == GIMP_TAB_STYLE_AUTOMATIC)
SET_ACTIVE ("dockable-tab-style-automatic", TRUE);
docked_iface = GIMP_DOCKED_GET_INTERFACE (docked);
SET_SENSITIVE ("dockable-tab-style-preview",

View File

@ -111,7 +111,7 @@ new_dockable_not_in_new_window (gconstpointer data)
gimp_test_run_mainloop_until_idle ();
/* Count dialogs after we created the dockable */
dialogs = gimp_dialog_factory_get_open_dialogs (factory);
dialogs = gimp_dialog_factory_get_open_dialogs (factory);
dialogs_after = g_list_length (dialogs);
for (iter = dialogs; iter; iter = g_list_next (iter))
{

View File

@ -185,7 +185,7 @@ automatic_tab_style (gconstpointer data)
*/
g_assert_cmpint (GIMP_TAB_STYLE_ICON_BLURB,
==,
gimp_dockable_get_actual_tab_style (dockable));
gimp_dockable_get_tab_style (dockable));
/* Add some dockables to the channel dockable dockbook */
ui_manager =
@ -203,7 +203,7 @@ automatic_tab_style (gconstpointer data)
*/
g_assert_cmpint (GIMP_TAB_STYLE_ICON,
==,
gimp_dockable_get_actual_tab_style (dockable));
gimp_dockable_get_tab_style (dockable));
/* Close the two dockables we added */
gimp_ui_manager_activate_action (ui_manager,
@ -217,7 +217,7 @@ automatic_tab_style (gconstpointer data)
/* We should now be back on icon-blurb */
g_assert_cmpint (GIMP_TAB_STYLE_ICON_BLURB,
==,
gimp_dockable_get_actual_tab_style (dockable));
gimp_dockable_get_tab_style (dockable));
}
static void

View File

@ -62,7 +62,6 @@ struct _GimpDockablePrivate
gchar *icon_name;
gchar *help_id;
GimpTabStyle tab_style;
GimpTabStyle actual_tab_style;
gboolean locked;
GimpDockbook *dockbook;
@ -183,10 +182,9 @@ gimp_dockable_init (GimpDockable *dockable)
GIMP_TYPE_DOCKABLE,
GimpDockablePrivate);
dockable->p->tab_style = GIMP_TAB_STYLE_AUTOMATIC;
dockable->p->actual_tab_style = GIMP_TAB_STYLE_UNDEFINED;
dockable->p->drag_x = GIMP_DOCKABLE_DRAG_OFFSET;
dockable->p->drag_y = GIMP_DOCKABLE_DRAG_OFFSET;
dockable->p->tab_style = GIMP_TAB_STYLE_PREVIEW;
dockable->p->drag_x = GIMP_DOCKABLE_DRAG_OFFSET;
dockable->p->drag_y = GIMP_DOCKABLE_DRAG_OFFSET;
gtk_drag_dest_set (GTK_WIDGET (dockable),
0,
@ -528,11 +526,6 @@ gimp_dockable_new_tab_widget_internal (GimpDockable *dockable,
gtk_box_pack_start (GTK_BOX (tab_widget), label, FALSE, FALSE, 0);
gtk_widget_show (label);
break;
case GIMP_TAB_STYLE_UNDEFINED:
case GIMP_TAB_STYLE_AUTOMATIC:
g_warning ("Tab style error, unexpected code path taken, fix!");
break;
}
return tab_widget;
@ -595,22 +588,6 @@ gimp_dockable_get_tab_style (GimpDockable *dockable)
return dockable->p->tab_style;
}
/**
* gimp_dockable_get_actual_tab_style:
* @dockable:
*
* Get actual tab style, i.e. never "automatic". This state should
* actually be hold on a per-dockbook basis, but at this point that
* feels like over-engineering...
**/
GimpTabStyle
gimp_dockable_get_actual_tab_style (GimpDockable *dockable)
{
g_return_val_if_fail (GIMP_IS_DOCKABLE (dockable), -1);
return dockable->p->actual_tab_style;
}
const gchar *
gimp_dockable_get_name (GimpDockable *dockable)
{
@ -722,39 +699,6 @@ gimp_dockable_set_tab_style (GimpDockable *dockable,
g_return_if_fail (GIMP_IS_DOCKABLE (dockable));
dockable->p->tab_style = gimp_dockable_convert_tab_style (dockable, tab_style);
if (tab_style == GIMP_TAB_STYLE_AUTOMATIC)
gimp_dockable_set_actual_tab_style (dockable, GIMP_TAB_STYLE_UNDEFINED);
else
gimp_dockable_set_actual_tab_style (dockable, tab_style);
if (dockable->p->dockbook)
gimp_dockbook_update_auto_tab_style (dockable->p->dockbook);
}
/**
* gimp_dockable_set_actual_tab_style:
* @dockable:
* @tab_style:
*
* Sets actual tab style, meant for those that decides what
* "automatic" tab style means.
*
* Returns: %TRUE if changed, %FALSE otherwise.
**/
gboolean
gimp_dockable_set_actual_tab_style (GimpDockable *dockable,
GimpTabStyle tab_style)
{
GimpTabStyle new_tab_style = gimp_dockable_convert_tab_style (dockable, tab_style);
GimpTabStyle old_tab_style = dockable->p->actual_tab_style;
g_return_val_if_fail (GIMP_IS_DOCKABLE (dockable), FALSE);
g_return_val_if_fail (tab_style != GIMP_TAB_STYLE_AUTOMATIC, FALSE);
dockable->p->actual_tab_style = new_tab_style;
return new_tab_style != old_tab_style;
}
GtkWidget *

View File

@ -88,9 +88,6 @@ gboolean gimp_dockable_is_locked (GimpDockable *dockable);
void gimp_dockable_set_tab_style (GimpDockable *dockable,
GimpTabStyle tab_style);
gboolean gimp_dockable_set_actual_tab_style (GimpDockable *dockable,
GimpTabStyle tab_style);
GimpTabStyle gimp_dockable_get_actual_tab_style (GimpDockable *dockable);
GtkWidget * gimp_dockable_create_tab_widget (GimpDockable *dockable,
GimpContext *context,
GimpTabStyle tab_style,

View File

@ -58,7 +58,6 @@
#define DEFAULT_TAB_ICON_SIZE GTK_ICON_SIZE_BUTTON
#define DND_WIDGET_ICON_SIZE GTK_ICON_SIZE_BUTTON
#define MENU_WIDGET_ICON_SIZE GTK_ICON_SIZE_MENU
#define MENU_WIDGET_SPACING 4
#define TAB_HOVER_TIMEOUT 500
#define GIMP_DOCKABLE_DETACH_REF_KEY "gimp-dockable-detach-ref"
@ -72,15 +71,6 @@ enum
LAST_SIGNAL
};
/* List of candidates for the automatic style, starting with the
* biggest first
*/
static const GimpTabStyle gimp_tab_style_candidates[] =
{
GIMP_TAB_STYLE_PREVIEW_BLURB,
GIMP_TAB_STYLE_PREVIEW_NAME,
GIMP_TAB_STYLE_PREVIEW
};
struct _GimpDockbookPrivate
{
@ -92,97 +82,71 @@ struct _GimpDockbookPrivate
GimpPanedBox *drag_handler;
/* Cache for "what actual tab style for automatic styles can we use
* for a given dockbook width
*/
gint min_width_for_style[G_N_ELEMENTS (gimp_tab_style_candidates)];
/* We need a list separate from the GtkContainer children list,
* because we need to do calculations for all dockables before we
* can add a dockable as a child, namely automatic tab style
* calculations
*/
GList *dockables;
GtkWidget *menu_button;
};
static void gimp_dockbook_dispose (GObject *object);
static void gimp_dockbook_finalize (GObject *object);
static void gimp_dockbook_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gimp_dockbook_style_updated (GtkWidget *widget);
static void gimp_dockbook_drag_leave (GtkWidget *widget,
GdkDragContext *context,
guint time);
static gboolean gimp_dockbook_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time);
static gboolean gimp_dockbook_drag_drop (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time);
static gboolean gimp_dockbook_popup_menu (GtkWidget *widget);
static gboolean gimp_dockbook_menu_button_press (GimpDockbook *dockbook,
GdkEventButton *bevent,
GtkWidget *button);
static gboolean gimp_dockbook_show_menu (GimpDockbook *dockbook);
static void gimp_dockbook_menu_end (GimpDockable *dockable);
static void gimp_dockbook_dockable_added (GimpDockbook *dockbook,
GimpDockable *dockable);
static void gimp_dockbook_dockable_removed (GimpDockbook *dockbook,
GimpDockable *dockable);
static void gimp_dockbook_recreate_tab_widgets (GimpDockbook *dockbook,
gboolean only_auto);
static void gimp_dockbook_tab_drag_source_setup (GtkWidget *widget,
GimpDockable *dockable);
static void gimp_dockbook_tab_drag_begin (GtkWidget *widget,
GdkDragContext *context,
GimpDockable *dockable);
static void gimp_dockbook_tab_drag_end (GtkWidget *widget,
GdkDragContext *context,
GimpDockable *dockable);
static void gimp_dockbook_tab_drag_leave (GtkWidget *widget,
GdkDragContext *context,
guint time,
GimpDockable *dockable);
static gboolean gimp_dockbook_tab_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time,
GimpDockable *dockable);
static gboolean gimp_dockbook_tab_drag_drop (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time);
static GimpTabStyle gimp_dockbook_tab_style_to_preferred (GimpTabStyle tab_style,
GimpDockable *dockable);
static void gimp_dockbook_refresh_tab_layout_lut (GimpDockbook *dockbook);
static void gimp_dockbook_update_automatic_tab_style (GimpDockbook *dockbook);
static GtkWidget * gimp_dockable_create_event_box_tab_widget (GimpDockable *dockable,
GimpContext *context,
GimpTabStyle tab_style,
GtkIconSize size);
static GtkIconSize gimp_dockbook_get_tab_icon_size (GimpDockbook *dockbook);
static void gimp_dockbook_add_tab_timeout (GimpDockbook *dockbook,
GimpDockable *dockable);
static void gimp_dockbook_remove_tab_timeout (GimpDockbook *dockbook);
static gboolean gimp_dockbook_tab_timeout (GimpDockbook *dockbook);
static void gimp_dockbook_tab_locked_notify (GimpDockable *dockable,
GParamSpec *pspec,
GimpDockbook *dockbook);
static void gimp_dockbook_help_func (const gchar *help_id,
gpointer help_data);
static const gchar *gimp_dockbook_get_tab_style_name (GimpTabStyle tab_style);
static void gimp_dockbook_dispose (GObject *object);
static void gimp_dockbook_finalize (GObject *object);
static void gimp_dockbook_config_size_changed (GimpGuiConfig *config,
GimpDockbook *dockbook);
static void gimp_dockbook_drag_leave (GtkWidget *widget,
GdkDragContext *context,
guint time);
static gboolean gimp_dockbook_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time);
static gboolean gimp_dockbook_drag_drop (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time);
static gboolean gimp_dockbook_popup_menu (GtkWidget *widget);
static gboolean gimp_dockbook_menu_button_press (GimpDockbook *dockbook,
GdkEventButton *bevent,
GtkWidget *button);
static gboolean gimp_dockbook_show_menu (GimpDockbook *dockbook);
static void gimp_dockbook_menu_end (GimpDockable *dockable);
static void gimp_dockbook_dockable_added (GimpDockbook *dockbook,
GimpDockable *dockable);
static void gimp_dockbook_dockable_removed (GimpDockbook *dockbook,
GimpDockable *dockable);
static void gimp_dockbook_tab_drag_source_setup (GtkWidget *widget,
GimpDockable *dockable);
static void gimp_dockbook_tab_drag_begin (GtkWidget *widget,
GdkDragContext *context,
GimpDockable *dockable);
static void gimp_dockbook_tab_drag_end (GtkWidget *widget,
GdkDragContext *context,
GimpDockable *dockable);
static void gimp_dockbook_tab_drag_leave (GtkWidget *widget,
GdkDragContext *context,
guint time,
GimpDockable *dockable);
static gboolean gimp_dockbook_tab_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time,
GimpDockable *dockable);
static gboolean gimp_dockbook_tab_drag_drop (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time);
static GtkIconSize gimp_dockbook_get_tab_icon_size (GimpDockbook *dockbook);
static void gimp_dockbook_add_tab_timeout (GimpDockbook *dockbook,
GimpDockable *dockable);
static void gimp_dockbook_remove_tab_timeout (GimpDockbook *dockbook);
static gboolean gimp_dockbook_tab_timeout (GimpDockbook *dockbook);
static void gimp_dockbook_tab_locked_notify (GimpDockable *dockable,
GParamSpec *pspec,
GimpDockbook *dockbook);
static void gimp_dockbook_help_func (const gchar *help_id,
gpointer help_data);
G_DEFINE_TYPE (GimpDockbook, gimp_dockbook, GTK_TYPE_NOTEBOOK)
@ -233,8 +197,6 @@ gimp_dockbook_class_init (GimpDockbookClass *klass)
object_class->dispose = gimp_dockbook_dispose;
object_class->finalize = gimp_dockbook_finalize;
widget_class->size_allocate = gimp_dockbook_size_allocate;
widget_class->style_updated = gimp_dockbook_style_updated;
widget_class->drag_leave = gimp_dockbook_drag_leave;
widget_class->drag_motion = gimp_dockbook_drag_motion;
widget_class->drag_drop = gimp_dockbook_drag_drop;
@ -258,7 +220,7 @@ static void
gimp_dockbook_init (GimpDockbook *dockbook)
{
GtkNotebook *notebook = GTK_NOTEBOOK (dockbook);
GtkWidget *image = NULL;
GtkWidget *image;
dockbook->p = G_TYPE_INSTANCE_GET_PRIVATE (dockbook,
GIMP_TYPE_DOCKBOOK,
@ -305,12 +267,16 @@ static void
gimp_dockbook_dispose (GObject *object)
{
GimpDockbook *dockbook = GIMP_DOCKBOOK (object);
GList *children;
GList *list;
gimp_dockbook_remove_tab_timeout (dockbook);
while (dockbook->p->dockables)
children = gtk_container_get_children (GTK_CONTAINER (object));
for (list = children; list; list = g_list_next (list))
{
GimpDockable *dockable = dockbook->p->dockables->data;
GimpDockable *dockable = list->data;
g_object_ref (dockable);
gimp_dockbook_remove (dockbook, dockable);
@ -318,6 +284,8 @@ gimp_dockbook_dispose (GObject *object)
g_object_unref (dockable);
}
g_list_free (children);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
@ -328,47 +296,9 @@ gimp_dockbook_finalize (GObject *object)
g_clear_object (&dockbook->p->ui_manager);
if (dockbook->p->dock)
{
g_signal_handlers_disconnect_by_func (gimp_dock_get_context (dockbook->p->dock)->gimp->config,
gimp_dockbook_config_size_changed,
dockbook);
dockbook->p->dock = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_dockbook_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GimpDockbook *dockbook = GIMP_DOCKBOOK (widget);
/* Update tab styles, also recreates if changed */
gimp_dockbook_update_automatic_tab_style (dockbook);
GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
}
static void
gimp_dockbook_style_updated (GtkWidget *widget)
{
GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
/* Don't attempt to construct widgets that require a GimpContext if
* we are detached from a top-level, we're either on our way to
* destruction, in which case we don't care, or we will be given a
* new parent, in which case the widget style will be reset again
* anyway, i.e. this function will be called again
*/
if (! gtk_widget_is_toplevel (gtk_widget_get_toplevel (widget)))
return;
gimp_dockbook_recreate_tab_widgets (GIMP_DOCKBOOK (widget),
FALSE /*only_auto*/);
}
static void
gimp_dockbook_drag_leave (GtkWidget *widget,
GdkDragContext *context,
@ -454,14 +384,14 @@ gimp_dockbook_menu_button_press (GimpDockbook *dockbook,
static gboolean
gimp_dockbook_show_menu (GimpDockbook *dockbook)
{
GimpUIManager *dockbook_ui_manager = NULL;
GimpUIManager *dialog_ui_manager = NULL;
const gchar *dialog_ui_path = NULL;
gpointer dialog_popup_data = FALSE;
GtkWidget *parent_menu_widget = NULL;
GtkAction *parent_menu_action = NULL;
GimpDockable *dockable = NULL;
gint page_num = -1;
GimpUIManager *dockbook_ui_manager;
GimpUIManager *dialog_ui_manager;
const gchar *dialog_ui_path;
gpointer dialog_popup_data;
GtkWidget *parent_menu_widget;
GtkAction *parent_menu_action;
GimpDockable *dockable;
gint page_num;
dockbook_ui_manager = gimp_dockbook_get_ui_manager (dockbook);
@ -616,243 +546,6 @@ gimp_dockbook_dockable_removed (GimpDockbook *dockbook,
{
}
/**
* gimp_dockbook_get_dockable_tab_width:
* @dockable:
* @tab_style:
*
* Returns: Width of tab when the dockable is using the specified tab
* style.
**/
static gint
gimp_dockbook_get_dockable_tab_width (GimpDockbook *dockbook,
GimpDockable *dockable,
GimpTabStyle tab_style)
{
GtkRequisition dockable_request;
GtkWidget *tab_widget;
tab_widget =
gimp_dockable_create_event_box_tab_widget (dockable,
gimp_dock_get_context (dockbook->p->dock),
tab_style,
gimp_dockbook_get_tab_icon_size (dockbook));
/* So font-scale is applied. We can't apply styles without having a
* GdkScreen :(
*/
gimp_dock_temp_add (dockbook->p->dock, tab_widget);
gtk_widget_get_preferred_size (tab_widget, &dockable_request, NULL);
/* Also destroys the widget */
gimp_dock_temp_remove (dockbook->p->dock, tab_widget);
return dockable_request.width;
}
/**
* gimp_dockbook_tab_style_to_preferred:
* @tab_style:
* @dockable:
*
* The list of tab styles to try in automatic mode only consists of
* preview styles. For some dockables, like the tool options dockable,
* we rather want to use the icon tab styles for the automatic
* mode. This function is used to convert tab styles for such
* dockables.
*
* Returns: An icon tab style if the dockable prefers icon tab styles
* in automatic mode.
**/
static GimpTabStyle
gimp_dockbook_tab_style_to_preferred (GimpTabStyle tab_style,
GimpDockable *dockable)
{
GimpDocked *docked = GIMP_DOCKED (gtk_bin_get_child (GTK_BIN (dockable)));
if (gimp_docked_get_prefer_icon (docked))
tab_style = gimp_preview_tab_style_to_icon (tab_style);
return tab_style;
}
/**
* gimp_dockbook_refresh_tab_layout_lut:
* @dockbook:
*
* For each given set of tab widgets, there is a fixed mapping between
* the width of the dockbook and the actual tab style to use for auto
* tab widgets. This function refreshes that look-up table.
**/
static void
gimp_dockbook_refresh_tab_layout_lut (GimpDockbook *dockbook)
{
GList *auto_dockables = NULL;
GList *iter = NULL;
gint fixed_tab_style_space = 0;
int i = 0;
/* Calculate space taken by dockables with fixed tab styles */
fixed_tab_style_space = 0;
for (iter = dockbook->p->dockables; iter; iter = g_list_next (iter))
{
GimpDockable *dockable = GIMP_DOCKABLE (iter->data);
GimpTabStyle tab_style = gimp_dockable_get_tab_style (dockable);
if (tab_style == GIMP_TAB_STYLE_AUTOMATIC)
auto_dockables = g_list_prepend (auto_dockables, dockable);
else
fixed_tab_style_space +=
gimp_dockbook_get_dockable_tab_width (dockbook,
dockable,
tab_style);
}
/* Calculate space taken with auto tab style for all candidates */
for (i = 0; i < G_N_ELEMENTS (gimp_tab_style_candidates); i++)
{
gint size_with_candidate = 0;
GimpTabStyle candidate = gimp_tab_style_candidates[i];
for (iter = auto_dockables; iter; iter = g_list_next (iter))
{
GimpDockable *dockable = GIMP_DOCKABLE (iter->data);
GimpTabStyle style_to_use;
style_to_use = gimp_dockbook_tab_style_to_preferred (candidate,
dockable);
size_with_candidate +=
gimp_dockbook_get_dockable_tab_width (dockbook,
dockable,
style_to_use);
}
dockbook->p->min_width_for_style[i] =
fixed_tab_style_space + size_with_candidate;
GIMP_LOG (AUTO_TAB_STYLE, "Total tab space taken for auto tab style %s = %d",
gimp_dockbook_get_tab_style_name (candidate),
dockbook->p->min_width_for_style[i]);
}
g_list_free (auto_dockables);
}
/**
* gimp_dockbook_update_automatic_tab_style:
* @dockbook:
*
* Based on widget allocation, sets actual tab style for dockables
* with automatic tab styles. Takes care of recreating tab widgets if
* necessary.
**/
static void
gimp_dockbook_update_automatic_tab_style (GimpDockbook *dockbook)
{
GtkWidget *widget = GTK_WIDGET (dockbook);
gboolean changed = FALSE;
GList *iter = NULL;
GtkAllocation dockbook_allocation = { 0, };
GtkAllocation button_allocation = { 0, };
GimpTabStyle tab_style = 0;
int i = 0;
gint available_space = 0;
guint tab_hborder = 0;
gint xthickness = 0;
gint tab_curvature = 0;
gint focus_width = 0;
gint tab_overlap = 0;
gint tab_padding = 0;
gint border_loss = 0;
gint action_widget_size = 0;
xthickness = gtk_widget_get_style (widget)->xthickness;
#if 0
g_object_get (widget,
"tab-hborder", &tab_hborder,
NULL);
#endif
gtk_widget_style_get (widget,
"tab-curvature", &tab_curvature,
"focus-line-width", &focus_width,
"tab-overlap", &tab_overlap,
NULL);
gtk_widget_get_allocation (dockbook->p->menu_button,
&button_allocation);
/* Calculate available space. Based on code in GTK+ internal
* functions gtk_notebook_size_request() and
* gtk_notebook_pages_allocate()
*/
gtk_widget_get_allocation (widget, &dockbook_allocation);
/* Border on both sides */
border_loss = gtk_container_get_border_width (GTK_CONTAINER (dockbook)) * 2;
/* Space taken by action widget */
action_widget_size = button_allocation.width + xthickness;
/* Space taken by the tabs but not the tab widgets themselves */
tab_padding = gtk_notebook_get_n_pages (GTK_NOTEBOOK (dockbook)) *
(2 * (xthickness + tab_curvature + focus_width + tab_hborder) -
tab_overlap);
available_space = dockbook_allocation.width
- border_loss
- action_widget_size
- tab_padding
- tab_overlap;
GIMP_LOG (AUTO_TAB_STYLE, "\n"
" available_space = %d where\n"
" dockbook_allocation.width = %d\n"
" border_loss = %d\n"
" action_widget_size = %d\n"
" tab_padding = %d\n"
" tab_overlap = %d\n",
available_space,
dockbook_allocation.width,
border_loss,
action_widget_size,
tab_padding,
tab_overlap);
/* Try all candidates, if we don't get any hit we still end up on
* the smallest style (which we always fall back to if we don't get
* a better match)
*/
for (i = 0; i < G_N_ELEMENTS (gimp_tab_style_candidates); i++)
{
tab_style = gimp_tab_style_candidates[i];
if (available_space > dockbook->p->min_width_for_style[i])
{
GIMP_LOG (AUTO_TAB_STYLE, "Choosing tab style %s",
gimp_dockbook_get_tab_style_name (tab_style));
break;
}
}
for (iter = dockbook->p->dockables; iter; iter = g_list_next (iter))
{
GimpDockable *dockable = GIMP_DOCKABLE (iter->data);
GimpTabStyle actual_tab_style = tab_style;
if (gimp_dockable_get_tab_style (dockable) != GIMP_TAB_STYLE_AUTOMATIC)
continue;
actual_tab_style = gimp_dockbook_tab_style_to_preferred (tab_style,
dockable);
if (gimp_dockable_set_actual_tab_style (dockable, actual_tab_style))
changed = TRUE;
}
if (changed)
gimp_dockbook_recreate_tab_widgets (dockbook,
TRUE /*only_auto*/);
}
GtkWidget *
gimp_dockbook_new (GimpMenuFactory *menu_factory)
{
@ -887,16 +580,7 @@ gimp_dockbook_set_dock (GimpDockbook *dockbook,
g_return_if_fail (GIMP_IS_DOCKBOOK (dockbook));
g_return_if_fail (dock == NULL || GIMP_IS_DOCK (dock));
if (dockbook->p->dock && gimp_dock_get_context (dockbook->p->dock))
g_signal_handlers_disconnect_by_func (gimp_dock_get_context (dockbook->p->dock)->gimp->config,
G_CALLBACK (gimp_dockbook_config_size_changed),
dockbook);
dockbook->p->dock = dock;
if (dock)
g_signal_connect (gimp_dock_get_context (dockbook->p->dock)->gimp->config,
"size-changed",
G_CALLBACK (gimp_dockbook_config_size_changed),
dockbook);
}
GimpUIManager *
@ -922,31 +606,21 @@ gimp_dockbook_add (GimpDockbook *dockbook,
GIMP_LOG (DND, "Adding GimpDockable %p to GimpDockbook %p", dockable, dockbook);
/* Add to internal list before doing automatic tab style
* calculations
*/
dockbook->p->dockables = g_list_insert (dockbook->p->dockables,
dockable,
position);
gimp_dockbook_update_auto_tab_style (dockbook);
/* Create the new tab widget, it will get the correct tab style now */
tab_widget = gimp_dockbook_create_tab_widget (dockbook, dockable);
g_return_if_fail (GTK_IS_WIDGET (tab_widget));
gimp_dockable_set_drag_handler (dockable, dockbook->p->drag_handler);
/* For the notebook right-click menu, always use the icon style */
menu_widget =
gimp_dockable_create_tab_widget (dockable,
gimp_dock_get_context (dockbook->p->dock),
GIMP_TAB_STYLE_ICON_BLURB,
MENU_WIDGET_ICON_SIZE);
GTK_ICON_SIZE_MENU);
g_return_if_fail (GTK_IS_WIDGET (menu_widget));
gimp_dockable_set_drag_handler (dockable, dockbook->p->drag_handler);
if (position == -1)
{
gtk_notebook_append_page_menu (GTK_NOTEBOOK (dockbook),
@ -1047,8 +721,6 @@ gimp_dockbook_remove (GimpDockbook *dockbook,
gimp_dockable_set_context (dockable, NULL);
gtk_container_remove (GTK_CONTAINER (dockbook), GTK_WIDGET (dockable));
dockbook->p->dockables = g_list_remove (dockbook->p->dockables,
dockable);
g_signal_emit (dockbook, dockbook_signals[DOCKABLE_REMOVED], 0, dockable);
@ -1058,9 +730,7 @@ gimp_dockbook_remove (GimpDockbook *dockbook,
{
GList *children = gtk_container_get_children (GTK_CONTAINER (dockbook));
if (children)
gimp_dockbook_update_auto_tab_style (dockbook);
else
if (! children)
gimp_dock_remove_book (dockbook->p->dock, dockbook);
g_list_free (children);
@ -1079,11 +749,9 @@ gimp_dockbook_update_with_context (GimpDockbook *dockbook,
GimpContext *context)
{
GList *children = gtk_container_get_children (GTK_CONTAINER (dockbook));
GList *iter = NULL;
GList *iter;
for (iter = children;
iter;
iter = g_list_next (iter))
for (iter = children; iter; iter = g_list_next (iter))
{
GimpDockable *dockable = GIMP_DOCKABLE (iter->data);
@ -1102,10 +770,23 @@ gimp_dockbook_create_tab_widget (GimpDockbook *dockbook,
GtkAction *action = NULL;
tab_widget =
gimp_dockable_create_event_box_tab_widget (dockable,
gimp_dock_get_context (dockbook->p->dock),
gimp_dockable_get_actual_tab_style (dockable),
gimp_dockbook_get_tab_icon_size (dockbook));
gimp_dockable_create_tab_widget (dockable,
gimp_dock_get_context (dockbook->p->dock),
gimp_dockable_get_tab_style (dockable),
gimp_dockbook_get_tab_icon_size (dockbook));
if (! GIMP_IS_VIEW (tab_widget))
{
GtkWidget *event_box;
event_box = gtk_event_box_new ();
gtk_event_box_set_visible_window (GTK_EVENT_BOX (event_box), FALSE);
gtk_event_box_set_above_child (GTK_EVENT_BOX (event_box), TRUE);
gtk_container_add (GTK_CONTAINER (event_box), tab_widget);
gtk_widget_show (tab_widget);
tab_widget = event_box;
}
/* EEK */
dock_window = gimp_dock_window_from_dock (dockbook->p->dock);
@ -1192,23 +873,6 @@ gimp_dockbook_create_tab_widget (GimpDockbook *dockbook,
return tab_widget;
}
/**
* gimp_dockbook_update_auto_tab_style:
* @dockbook:
*
* Refresh the table that we use to map dockbook width to actual auto
* tab style, then update auto tabs (also recreate tab widgets if
* necessary).
**/
void
gimp_dockbook_update_auto_tab_style (GimpDockbook *dockbook)
{
g_return_if_fail (GIMP_IS_DOCKBOOK (dockbook));
gimp_dockbook_refresh_tab_layout_lut (dockbook);
gimp_dockbook_update_automatic_tab_style (dockbook);
}
gboolean
gimp_dockbook_drop_dockable (GimpDockbook *dockbook,
GtkWidget *drag_source)
@ -1280,6 +944,7 @@ gimp_dockbook_drag_source_to_dockable (GtkWidget *drag_source)
else
dockable = g_object_get_data (G_OBJECT (drag_source),
"gimp-dockable");
if (dockable)
g_object_set_data (G_OBJECT (dockable),
"gimp-dock-drag-widget", NULL);
@ -1289,32 +954,6 @@ gimp_dockbook_drag_source_to_dockable (GtkWidget *drag_source)
/* tab DND source side */
static void
gimp_dockbook_recreate_tab_widgets (GimpDockbook *dockbook,
gboolean only_auto)
{
GList *dockables = gtk_container_get_children (GTK_CONTAINER (dockbook));
GList *iter = NULL;
for (iter = dockables; iter; iter = g_list_next (iter))
{
GimpDockable *dockable = GIMP_DOCKABLE (iter->data);
GtkWidget *tab_widget;
if (only_auto &&
! (gimp_dockable_get_tab_style (dockable) == GIMP_TAB_STYLE_AUTOMATIC))
continue;
tab_widget = gimp_dockbook_create_tab_widget (dockbook, dockable);
gtk_notebook_set_tab_label (GTK_NOTEBOOK (dockbook),
GTK_WIDGET (dockable),
tab_widget);
}
g_list_free (dockables);
}
static void
gimp_dockbook_tab_drag_source_setup (GtkWidget *widget,
GimpDockable *dockable)
@ -1548,36 +1187,6 @@ gimp_dockbook_tab_drag_drop (GtkWidget *widget,
return TRUE;
}
static GtkWidget *
gimp_dockable_create_event_box_tab_widget (GimpDockable *dockable,
GimpContext *context,
GimpTabStyle tab_style,
GtkIconSize size)
{
GtkWidget *tab_widget;
tab_widget =
gimp_dockable_create_tab_widget (dockable,
context,
tab_style,
size);
if (! GIMP_IS_VIEW (tab_widget))
{
GtkWidget *event_box;
event_box = gtk_event_box_new ();
gtk_event_box_set_visible_window (GTK_EVENT_BOX (event_box), FALSE);
gtk_event_box_set_above_child (GTK_EVENT_BOX (event_box), TRUE);
gtk_container_add (GTK_CONTAINER (event_box), tab_widget);
gtk_widget_show (tab_widget);
tab_widget = event_box;
}
return tab_widget;
}
static GtkIconSize
gimp_dockbook_get_tab_icon_size (GimpDockbook *dockbook)
{
@ -1682,17 +1291,3 @@ gimp_dockbook_help_func (const gchar *help_id,
else
gimp_standard_help_func (GIMP_HELP_DOCK, NULL);
}
static const gchar *
gimp_dockbook_get_tab_style_name (GimpTabStyle tab_style)
{
return g_enum_get_value (g_type_class_peek (GIMP_TYPE_TAB_STYLE),
tab_style)->value_name;
}
static void
gimp_dockbook_config_size_changed (GimpGuiConfig *config,
GimpDockbook *dockbook)
{
gimp_dockbook_recreate_tab_widgets (dockbook, TRUE);
}

View File

@ -77,7 +77,6 @@ void gimp_dockbook_update_with_context (GimpDockbook *dockbo
GimpContext *context);
GtkWidget * gimp_dockbook_create_tab_widget (GimpDockbook *dockbook,
GimpDockable *dockable);
void gimp_dockbook_update_auto_tab_style (GimpDockbook *dockbook);
gboolean gimp_dockbook_drop_dockable (GimpDockbook *dockbook,
GtkWidget *drag_source);
void gimp_dockbook_set_drag_handler (GimpDockbook *dockbook,

View File

@ -242,8 +242,6 @@ gimp_tab_style_get_type (void)
{ GIMP_TAB_STYLE_ICON_BLURB, "GIMP_TAB_STYLE_ICON_BLURB", "icon-blurb" },
{ GIMP_TAB_STYLE_PREVIEW_NAME, "GIMP_TAB_STYLE_PREVIEW_NAME", "preview-name" },
{ GIMP_TAB_STYLE_PREVIEW_BLURB, "GIMP_TAB_STYLE_PREVIEW_BLURB", "preview-blurb" },
{ GIMP_TAB_STYLE_UNDEFINED, "GIMP_TAB_STYLE_UNDEFINED", "undefined" },
{ GIMP_TAB_STYLE_AUTOMATIC, "GIMP_TAB_STYLE_AUTOMATIC", "automatic" },
{ 0, NULL, NULL }
};
@ -257,8 +255,6 @@ gimp_tab_style_get_type (void)
{ GIMP_TAB_STYLE_ICON_BLURB, NC_("tab-style", "Icon & desc"), NULL },
{ GIMP_TAB_STYLE_PREVIEW_NAME, NC_("tab-style", "Status & text"), NULL },
{ GIMP_TAB_STYLE_PREVIEW_BLURB, NC_("tab-style", "Status & desc"), NULL },
{ GIMP_TAB_STYLE_UNDEFINED, NC_("tab-style", "Undefined"), NULL },
{ GIMP_TAB_STYLE_AUTOMATIC, NC_("tab-style", "Automatic"), NULL },
{ 0, NULL, NULL }
};

View File

@ -122,9 +122,7 @@ typedef enum
GIMP_TAB_STYLE_ICON_NAME, /*< desc="Icon & text" >*/
GIMP_TAB_STYLE_ICON_BLURB, /*< desc="Icon & desc" >*/
GIMP_TAB_STYLE_PREVIEW_NAME, /*< desc="Status & text" >*/
GIMP_TAB_STYLE_PREVIEW_BLURB, /*< desc="Status & desc" >*/
GIMP_TAB_STYLE_UNDEFINED, /*< desc="Undefined" >*/
GIMP_TAB_STYLE_AUTOMATIC /*< desc="Automatic" >*/
GIMP_TAB_STYLE_PREVIEW_BLURB /*< desc="Status & desc" >*/
} GimpTabStyle;