summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2012-10-07 16:00:59 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2012-10-07 16:00:59 (GMT)
commitb75a1889afa207051395b0288890b5b197c87b75 (patch)
treea22e9506a9fabb7791a96c1d32bf67c0fda65a3e
parentfa83bc71888fed39bcc77ad610ffd6f6980444f8 (diff)
Tried to resize the panels when the editor is resized.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@265 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
-rw-r--r--ChangeLog11
-rw-r--r--src/gtkext/easygtk.h3
-rw-r--r--src/gui/panels/panel.c222
-rw-r--r--src/gui/panels/symbols.c4
4 files changed, 240 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index ecca861..0f1d521 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+12-10-07 Cyrille Bagard <nocbos@gmail.com>
+
+ * src/gtkext/easygtk.h:
+ Deal with GtkRequisition structures.
+
+ * src/gui/panels/panel.c:
+ Try to resize the panels when the editor is resized.
+
+ * src/gui/panels/symbols.c:
+ Store the perfect size for GTK.
+
12-09-23 Cyrille Bagard <nocbos@gmail.com>
* src/common/fnv1a.c:
diff --git a/src/gtkext/easygtk.h b/src/gtkext/easygtk.h
index 242f349..e46efee 100644
--- a/src/gtkext/easygtk.h
+++ b/src/gtkext/easygtk.h
@@ -28,6 +28,9 @@
#include <gtk/gtk.h>
+/* Conversion anonyme */
+#define ALLOC_2_REQ(a) ((GtkRequisition []){ { .width = (a)->width, .height = (a)->height }})
+
/* Met en place un aligement dont les bordures sont à ajuster. */
GtkWidget *qck_create_padded_alignment(guint, guint, guint, guint);
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));
+
+}
diff --git a/src/gui/panels/symbols.c b/src/gui/panels/symbols.c
index 6cc391f..63864d3 100644
--- a/src/gui/panels/symbols.c
+++ b/src/gui/panels/symbols.c
@@ -386,6 +386,7 @@ static void on_symbols_selection_change(GtkTreeSelection *selection, GSymbolsPan
void change_symbols_panel_current_binary(GSymbolsPanel *panel, GLoadedBinary *binary)
{
GtkToggleToolButton *button; /* Mode de représentation */
+ GtkRequisition req; /* Nouvelle taille idéale */
if (panel->binary != NULL)
g_object_unref(G_OBJECT(panel->binary));
@@ -405,6 +406,9 @@ void change_symbols_panel_current_binary(GSymbolsPanel *panel, GLoadedBinary *bi
reorganize_symbols_tree_view(NULL, G_OBJECT(G_EDITOR_ITEM(panel)->widget));
}
+ gtk_widget_size_request(GTK_WIDGET(panel->treeview), &req);
+ gtk_widget_set_size_request(GTK_WIDGET(panel->treeview), req.width, req.height);
+
}