mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Refactor: Extract method set_window_geometry()
This commit is contained in:
parent
1f0a69a804
commit
252b169414
@ -536,6 +536,88 @@ cleanup:
|
|||||||
g_free(page_group);
|
g_free(page_group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_window_geometry(GncMainWindow *window, GncMainWindowSaveData *data, gchar *window_group)
|
||||||
|
{
|
||||||
|
auto priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
|
||||||
|
|
||||||
|
gsize length;
|
||||||
|
GError *error = nullptr;
|
||||||
|
gint *geom = g_key_file_get_integer_list(data->key_file, window_group,
|
||||||
|
WINDOW_GEOMETRY, &length, &error);
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
g_warning("error reading group %s key %s: %s",
|
||||||
|
window_group, WINDOW_GEOMETRY, error->message);
|
||||||
|
g_error_free(error);
|
||||||
|
error = nullptr;
|
||||||
|
}
|
||||||
|
else if (length != 2)
|
||||||
|
{
|
||||||
|
g_warning("invalid number of values for group %s key %s",
|
||||||
|
window_group, WINDOW_GEOMETRY);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gtk_window_resize(GTK_WINDOW(window), geom[0], geom[1]);
|
||||||
|
DEBUG("window (%p) size %dx%d", window, geom[0], geom[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* keep the geometry for a test whether the windows position
|
||||||
|
is offscreen */
|
||||||
|
gint *pos = g_key_file_get_integer_list(data->key_file, window_group,
|
||||||
|
WINDOW_POSITION, &length, &error);
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
g_warning("error reading group %s key %s: %s",
|
||||||
|
window_group, WINDOW_POSITION, error->message);
|
||||||
|
g_error_free(error);
|
||||||
|
error = nullptr;
|
||||||
|
}
|
||||||
|
else if (length != 2)
|
||||||
|
{
|
||||||
|
g_warning("invalid number of values for group %s key %s",
|
||||||
|
window_group, WINDOW_POSITION);
|
||||||
|
}
|
||||||
|
/* Prevent restoring coordinates if this would move the window off-screen */
|
||||||
|
else if ((pos[0] + (geom ? geom[0] : 0) < 0) ||
|
||||||
|
(pos[0] > gdk_screen_width()) ||
|
||||||
|
(pos[1] + (geom ? geom[1] : 0) < 0) ||
|
||||||
|
(pos[1] > gdk_screen_height()))
|
||||||
|
{
|
||||||
|
DEBUG("position %dx%d, size%dx%d is offscreen; will not move",
|
||||||
|
pos[0], pos[1], geom ? geom[0] : 0, geom ? geom[1] : 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gtk_window_move(GTK_WINDOW(window), pos[0], pos[1]);
|
||||||
|
priv->pos[0] = pos[0];
|
||||||
|
priv->pos[1] = pos[1];
|
||||||
|
DEBUG("window (%p) position (%d,%d)", window, pos[0], pos[1]);
|
||||||
|
}
|
||||||
|
if (geom)
|
||||||
|
{
|
||||||
|
g_free(geom);
|
||||||
|
}
|
||||||
|
if (pos)
|
||||||
|
{
|
||||||
|
g_free(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean max = g_key_file_get_boolean(data->key_file, window_group,
|
||||||
|
WINDOW_MAXIMIZED, &error);
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
g_warning("error reading group %s key %s: %s",
|
||||||
|
window_group, WINDOW_MAXIMIZED, error->message);
|
||||||
|
g_error_free(error);
|
||||||
|
error = nullptr;
|
||||||
|
}
|
||||||
|
else if (max)
|
||||||
|
{
|
||||||
|
gtk_window_maximize(GTK_WINDOW(window));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Restore all the pages in a given window. This function restores
|
/** Restore all the pages in a given window. This function restores
|
||||||
* all the window specific attributes, then calls a helper function
|
* all the window specific attributes, then calls a helper function
|
||||||
@ -550,17 +632,15 @@ gnc_main_window_restore_window (GncMainWindow *window, GncMainWindowSaveData *da
|
|||||||
{
|
{
|
||||||
GncMainWindowPrivate *priv;
|
GncMainWindowPrivate *priv;
|
||||||
GAction *action;
|
GAction *action;
|
||||||
gint *pos, *geom, *order;
|
gint *order;
|
||||||
gsize length;
|
gsize length;
|
||||||
gboolean max;
|
|
||||||
gchar *window_group;
|
|
||||||
gsize page_start, page_count, i;
|
gsize page_start, page_count, i;
|
||||||
GError *error = nullptr;
|
GError *error = nullptr;
|
||||||
|
|
||||||
/* Setup */
|
/* Setup */
|
||||||
ENTER("window %p, data %p (key file %p, window %d)",
|
ENTER("window %p, data %p (key file %p, window %d)",
|
||||||
window, data, data->key_file, data->window_num);
|
window, data, data->key_file, data->window_num);
|
||||||
window_group = g_strdup_printf(WINDOW_STRING, data->window_num + 1);
|
gchar *window_group = g_strdup_printf(WINDOW_STRING, data->window_num + 1);
|
||||||
|
|
||||||
/* Deal with the uncommon case that the state file defines a window
|
/* Deal with the uncommon case that the state file defines a window
|
||||||
* but no pages. An example to get in such a situation can be found
|
* but no pages. An example to get in such a situation can be found
|
||||||
@ -619,83 +699,10 @@ gnc_main_window_restore_window (GncMainWindow *window, GncMainWindowSaveData *da
|
|||||||
window = gnc_main_window_new();
|
window = gnc_main_window_new();
|
||||||
}
|
}
|
||||||
|
|
||||||
priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
|
|
||||||
|
|
||||||
/* Get the window coordinates, etc. */
|
/* Get the window coordinates, etc. */
|
||||||
geom = g_key_file_get_integer_list(data->key_file, window_group,
|
set_window_geometry(window, data, window_group);
|
||||||
WINDOW_GEOMETRY, &length, &error);
|
|
||||||
if (error)
|
|
||||||
{
|
|
||||||
g_warning("error reading group %s key %s: %s",
|
|
||||||
window_group, WINDOW_GEOMETRY, error->message);
|
|
||||||
g_error_free(error);
|
|
||||||
error = nullptr;
|
|
||||||
}
|
|
||||||
else if (length != 2)
|
|
||||||
{
|
|
||||||
g_warning("invalid number of values for group %s key %s",
|
|
||||||
window_group, WINDOW_GEOMETRY);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gtk_window_resize(GTK_WINDOW(window), geom[0], geom[1]);
|
|
||||||
DEBUG("window (%p) size %dx%d", window, geom[0], geom[1]);
|
|
||||||
}
|
|
||||||
/* keep the geometry for a test whether the windows position
|
|
||||||
is offscreen */
|
|
||||||
|
|
||||||
pos = g_key_file_get_integer_list(data->key_file, window_group,
|
priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
|
||||||
WINDOW_POSITION, &length, &error);
|
|
||||||
if (error)
|
|
||||||
{
|
|
||||||
g_warning("error reading group %s key %s: %s",
|
|
||||||
window_group, WINDOW_POSITION, error->message);
|
|
||||||
g_error_free(error);
|
|
||||||
error = nullptr;
|
|
||||||
}
|
|
||||||
else if (length != 2)
|
|
||||||
{
|
|
||||||
g_warning("invalid number of values for group %s key %s",
|
|
||||||
window_group, WINDOW_POSITION);
|
|
||||||
}
|
|
||||||
/* Prevent restoring coordinates if this would move the window off-screen */
|
|
||||||
else if ((pos[0] + (geom ? geom[0] : 0) < 0) ||
|
|
||||||
(pos[0] > gdk_screen_width()) ||
|
|
||||||
(pos[1] + (geom ? geom[1] : 0) < 0) ||
|
|
||||||
(pos[1] > gdk_screen_height()))
|
|
||||||
{
|
|
||||||
DEBUG("position %dx%d, size%dx%d is offscreen; will not move",
|
|
||||||
pos[0], pos[1], geom ? geom[0] : 0, geom ? geom[1] : 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gtk_window_move(GTK_WINDOW(window), pos[0], pos[1]);
|
|
||||||
priv->pos[0] = pos[0];
|
|
||||||
priv->pos[1] = pos[1];
|
|
||||||
DEBUG("window (%p) position %dx%d", window, pos[0], pos[1]);
|
|
||||||
}
|
|
||||||
if (geom)
|
|
||||||
{
|
|
||||||
g_free(geom);
|
|
||||||
}
|
|
||||||
if (pos)
|
|
||||||
{
|
|
||||||
g_free(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
max = g_key_file_get_boolean(data->key_file, window_group,
|
|
||||||
WINDOW_MAXIMIZED, &error);
|
|
||||||
if (error)
|
|
||||||
{
|
|
||||||
g_warning("error reading group %s key %s: %s",
|
|
||||||
window_group, WINDOW_MAXIMIZED, error->message);
|
|
||||||
g_error_free(error);
|
|
||||||
error = nullptr;
|
|
||||||
}
|
|
||||||
else if (max)
|
|
||||||
{
|
|
||||||
gtk_window_maximize(GTK_WINDOW(window));
|
|
||||||
}
|
|
||||||
|
|
||||||
// need to add the accelerator keys
|
// need to add the accelerator keys
|
||||||
gnc_add_accelerator_keys_for_menu (GTK_WIDGET(priv->menubar), priv->accel_group);
|
gnc_add_accelerator_keys_for_menu (GTK_WIDGET(priv->menubar), priv->accel_group);
|
||||||
|
Loading…
Reference in New Issue
Block a user