summaryrefslogtreecommitdiff
path: root/src/gui/panels/panel.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/panels/panel.c')
-rw-r--r--src/gui/panels/panel.c222
1 files changed, 222 insertions, 0 deletions
diff --git a/src/gui/panels/panel.c b/src/gui/panels/panel.c
index b101f4b..cf4423d 100644
--- a/src/gui/panels/panel.c
+++ b/src/gui/panels/panel.c
@@ -27,6 +27,7 @@
#include <ctype.h>
#include <string.h>
+#include <sys/param.h>
#include "log.h"
@@ -81,6 +82,24 @@ static void rebuild_panels_interface(const panel_node *);
+/* ---------------------- REAJUSTEMENT AUTOMATIQUE DE L'ESPACE ---------------------- */
+
+
+/* Part réservée aux parties principales (en %) */
+#define MAIN_PART_PERCENT 70
+
+
+/* Met à jour l'affichage suite à un changement hiérarchique. */
+static void auto_resize_panels(GtkWidget *, GdkRectangle *, gpointer);
+
+/* S'enquiert de la taille idéale pour un noeud. */
+static void get_panel_node_size_request(const panel_node *, GtkRequisition *);
+
+/* Impose une taille accordée à un noeud. */
+static void set_panel_node_size_request(const panel_node *, const GtkRequisition *);
+
+
+
/* Indique le type défini pour un élément destiné à un panneau. */
G_DEFINE_TYPE(GPanelItem, g_panel_item, G_TYPE_EDITOR_ITEM);
@@ -295,6 +314,8 @@ GtkWidget *init_panels2(GCallback handler, gpointer data)
result = qck_create_padded_alignment(0, 0, 0, 0);
gtk_widget_show(result);
+ g_signal_connect(result, "size-allocate", G_CALLBACK(auto_resize_panels), NULL);
+
_support = result;
_handler = handler;
_data = data;
@@ -672,3 +693,204 @@ static void rebuild_panels_interface(const panel_node *current)
}
}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* REAJUSTEMENT AUTOMATIQUE DE L'ESPACE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : current = point de départ de la réorganisation graphique. *
+* *
+* Description : Met à jour l'affichage suite à un changement hiérarchique. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void auto_resize_panels(GtkWidget *support, GdkRectangle *alloc, gpointer data)
+{
+ GtkRequisition available; /* Taille disponible */
+
+ //g_signal_handlers_disconnect_by_func(support, G_CALLBACK(auto_resize_panels), NULL);
+
+ available.width = alloc->width;
+ available.height = alloc->height;
+
+ set_panel_node_size_request(_nodes, &available);
+
+ //g_signal_connect(support, "size-allocate", G_CALLBACK(auto_resize_panels), NULL);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud à consulter. *
+* req = taille demandée par le noeud. [OUT] *
+* *
+* Description : S'enquiert de la taille idéale pour un noeud. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void get_panel_node_size_request(const panel_node *node, GtkRequisition *req)
+{
+ gint handle_size; /* Taille de la séparation */
+ GtkRequisition tmp; /* Stockage temporaire */
+
+ if (node->simple)
+ gtk_widget_size_request(node->station, req);
+
+ else
+ {
+ gtk_widget_style_get(node->paned, "handle-size", &handle_size, NULL);
+
+ if (GTK_IS_HPANED(node->paned))
+ {
+ req->width = handle_size;
+ req->height = 0;
+ }
+ else
+ {
+ req->width = 0;
+ req->height = handle_size;
+ }
+
+ get_panel_node_size_request(node->first, &tmp);
+ req->width += tmp.width;
+ req->height += tmp.height;
+
+ get_panel_node_size_request(node->second, &tmp);
+ req->width += tmp.width;
+ req->height += tmp.height;
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud à consulter. *
+* space = taille disponible pour le noeud. *
+* *
+* Description : Impose une taille accordée à un noeud. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void set_panel_node_size_request(const panel_node *node, const GtkRequisition *space)
+{
+ GtkRequisition first_req; /* Taille demandée par n°1 */
+ GtkRequisition second_req; /* Taille demandée par n°2 */
+ gint handle_size; /* Taille de la séparation */
+ gint position; /* Position de la séparation */
+ bool can_lower; /* Diminution possible ? */
+ bool can_upper; /* Augmentation possible ? */
+ GtkAllocation allocation; /* Taille allouée */
+
+ /* Pour les cas simple, GTK gère très bien... */
+ if (node->simple) return;
+
+ get_panel_node_size_request(node->first, &first_req);
+ get_panel_node_size_request(node->second, &second_req);
+
+ gtk_widget_style_get(node->paned, "handle-size", &handle_size, NULL);
+
+ /**
+ * Définitions des bornes dans chacun des cas.
+ */
+
+ /* Le premier noeud est le principal... */
+ if (is_panel_node_matching(node->first, 'M'))
+ {
+ if (GTK_IS_HPANED(node->paned))
+ position = (space->width * MAIN_PART_PERCENT) / 100;
+ else
+ position = (space->height * MAIN_PART_PERCENT) / 100;
+
+ can_lower = false;
+ can_upper = true;
+
+ }
+
+ /* Le second noeud est le principal... */
+ else if (is_panel_node_matching(node->second, 'M'))
+ {
+ if (GTK_IS_HPANED(node->paned))
+ position = space->width - (space->width * MAIN_PART_PERCENT) / 100;
+ else
+ position = space->height - (space->height * MAIN_PART_PERCENT) / 100;
+
+ can_lower = true;
+ can_upper = false;
+
+ }
+
+ /* Les éléments sont quelconques... */
+ else
+ {
+ if (GTK_IS_HPANED(node->paned))
+ position = space->width / 2;
+ else
+ position = space->height / 2;
+
+ can_lower = true;
+ can_upper = true;
+
+ }
+
+ /**
+ * Calcul des valeurs applicables et mise en application.
+ */
+
+ /* Une partie principale arrive en premier */
+ if (!can_lower && can_upper)
+ {
+ if (GTK_IS_HPANED(node->paned))
+ position = MAX(position, space->width - second_req.width - handle_size);
+ else
+ position = MAX(position, space->height - second_req.height - handle_size);
+ }
+
+ /* Une partie principale arrive en second */
+ else if (can_lower && !can_upper)
+ {
+ if (GTK_IS_HPANED(node->paned))
+ position = MIN(position, second_req.width + handle_size);
+ else
+ position = MIN(position, second_req.height + handle_size);
+ }
+
+ /* Chacun pour soit ! */
+ else
+ {
+
+
+ /* TODO */;
+
+
+
+ }
+
+ gtk_paned_set_position(GTK_PANED(node->paned), position);
+
+ gtk_widget_get_allocation(GET_PANEL_NODE_WIDGET(node->first), &allocation);
+ set_panel_node_size_request(node->first, ALLOC_2_REQ(&allocation));
+
+ gtk_widget_get_allocation(GET_PANEL_NODE_WIDGET(node->second), &allocation);
+ set_panel_node_size_request(node->second, ALLOC_2_REQ(&allocation));
+
+}