From 6f4acbfe0a7c2dc5e4bc507bd78b75dbff3bea3b Mon Sep 17 00:00:00 2001 From: Andrzej Date: Wed, 18 Jan 2012 12:56:11 +0900 Subject: [PATCH] Changing orientation in vertical panels. Removed expansion behavior in wide panels. --- panel-plugin/datetime.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++- panel-plugin/datetime.h | 1 + 2 files changed, 61 insertions(+), 1 deletions(-) diff --git a/panel-plugin/datetime.c b/panel-plugin/datetime.c index 30ee04a..4eef2d8 100644 --- a/panel-plugin/datetime.c +++ b/panel-plugin/datetime.c @@ -512,6 +512,45 @@ static int datetime_set_size(XfcePanelPlugin *plugin, return TRUE; } +static void datetime_update_orientation(t_datetime *datetime, GtkOrientation orientation) +{ + if (orientation == GTK_ORIENTATION_VERTICAL) + { + gtk_label_set_angle(GTK_LABEL(datetime->time_label), 0); + gtk_label_set_angle(GTK_LABEL(datetime->date_label), 0); + gtk_box_reorder_child(GTK_BOX(datetime->vbox), datetime->time_label, 1); + gtk_box_reorder_child(GTK_BOX(datetime->vbox), datetime->date_label, 0); + } + else + { + gtk_label_set_angle(GTK_LABEL(datetime->time_label), 270); + gtk_label_set_angle(GTK_LABEL(datetime->date_label), 270); + gtk_box_reorder_child(GTK_BOX(datetime->vbox), datetime->time_label, 0); + gtk_box_reorder_child(GTK_BOX(datetime->vbox), datetime->date_label, 1); + } + + gtk_orientable_set_orientation (GTK_ORIENTABLE (datetime->vbox), orientation); + gtk_orientable_set_orientation (GTK_ORIENTABLE (datetime->outer_vbox), orientation); +} + +/* + * Function only called by the signal handler. + */ +#if LIBXFCE4PANEL_CHECK_VERSION (4,9,0) +static void datetime_set_mode(XfcePanelPlugin *plugin, + XfcePanelPluginMode mode, + t_datetime *datetime) +{ + GtkOrientation orientation; + + orientation = + (mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL) ? + GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL; + + datetime_update_orientation(datetime, orientation); +} +#endif + /* * Read the settings from the config file */ @@ -595,10 +634,16 @@ static void datetime_create_widget(t_datetime * datetime) datetime->button = xfce_create_panel_toggle_button(); gtk_widget_show(datetime->button); + /* create outer vertical box */ + datetime->outer_vbox = gtk_vbox_new(TRUE, 0); + gtk_widget_show(datetime->outer_vbox); + gtk_container_add(GTK_CONTAINER(datetime->button), datetime->outer_vbox); + /* create vertical box */ datetime->vbox = gtk_vbox_new(TRUE, 0); gtk_widget_show(datetime->vbox); - gtk_container_add(GTK_CONTAINER(datetime->button), datetime->vbox); + gtk_box_pack_start(GTK_BOX(datetime->outer_vbox), + datetime->vbox, TRUE, FALSE, 0); /* create time and date lines */ datetime->time_label = gtk_label_new(""); @@ -679,6 +724,16 @@ static void datetime_construct(XfcePanelPlugin *plugin) /* create datetime plugin */ t_datetime * datetime = datetime_new(plugin); +#if LIBXFCE4PANEL_CHECK_VERSION (4,9,0) + GtkOrientation orientation; + + orientation = + (xfce_panel_plugin_get_mode(plugin) == XFCE_PANEL_PLUGIN_MODE_VERTICAL) ? + GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL; + + datetime_update_orientation(datetime, orientation); +#endif + /* add plugin to panel */ gtk_container_add(GTK_CONTAINER(plugin), datetime->button); xfce_panel_plugin_add_action_widget(plugin, datetime->button); @@ -690,6 +745,10 @@ static void datetime_construct(XfcePanelPlugin *plugin) G_CALLBACK(datetime_free), datetime); g_signal_connect(plugin, "size-changed", G_CALLBACK (datetime_set_size), datetime); +#if LIBXFCE4PANEL_CHECK_VERSION (4,9,0) + g_signal_connect(plugin, "mode-changed", + G_CALLBACK(datetime_set_mode), datetime); +#endif g_signal_connect(plugin, "configure-plugin", G_CALLBACK (datetime_properties_dialog), datetime); xfce_panel_plugin_menu_show_configure(plugin); diff --git a/panel-plugin/datetime.h b/panel-plugin/datetime.h index 57de4b9..09ed7a5 100644 --- a/panel-plugin/datetime.h +++ b/panel-plugin/datetime.h @@ -43,6 +43,7 @@ typedef enum typedef struct { XfcePanelPlugin * plugin; GtkWidget *button; + GtkWidget *outer_vbox; GtkWidget *vbox; GtkWidget *date_label; GtkWidget *time_label; -- 1.7.1