[gnumeric] hlink: insist of getting the sheet when the object is created.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] hlink: insist of getting the sheet when the object is created.
- Date: Mon, 20 Jul 2020 23:33:10 +0000 (UTC)
commit b2f74828b88bbe54fa1cfd465d167929b4e09a79
Author: Morten Welinder <terra gnome org>
Date: Mon Jul 20 19:32:24 2020 -0400
hlink: insist of getting the sheet when the object is created.
src/dialogs/dialog-hyperlink.c | 8 ++---
src/hlink-impl.h | 1 -
src/hlink.c | 73 +++++++++++++++++++++++-------------------
src/hlink.h | 3 +-
src/mstyle.c | 3 +-
5 files changed, 46 insertions(+), 42 deletions(-)
---
diff --git a/src/dialogs/dialog-hyperlink.c b/src/dialogs/dialog-hyperlink.c
index 50551b70ca..1db215afc3 100644
--- a/src/dialogs/dialog-hyperlink.c
+++ b/src/dialogs/dialog-hyperlink.c
@@ -382,13 +382,13 @@ dhl_cb_ok (G_GNUC_UNUSED GtkWidget *button, HyperlinkState *state)
wb_control_sheet_focus (GNM_WBC (state->wbcg), state->sheet);
if (target) {
- gnm_hlink_set_sheet (state->link, state->sheet);
- gnm_hlink_set_target (state->link, target);
+ GnmHLink *new_link = gnm_hlink_dup_to (state->link, state->sheet);
+ gnm_hlink_set_target (new_link, target);
tip = dhl_get_tip (state, target);
- gnm_hlink_set_tip (state->link, tip);
+ gnm_hlink_set_tip (new_link, tip);
g_free (tip);
style = gnm_style_new ();
- gnm_style_set_hlink (style, g_object_ref (state->link));
+ gnm_style_set_hlink (style, new_link);
gnm_style_set_font_uline (style, UNDERLINE_SINGLE);
gnm_style_set_font_color (style, gnm_color_new_go (GO_COLOR_BLUE));
diff --git a/src/hlink-impl.h b/src/hlink-impl.h
index 49d96f0eb4..334c471543 100644
--- a/src/hlink-impl.h
+++ b/src/hlink-impl.h
@@ -16,7 +16,6 @@ typedef struct {
GObjectClass obj;
gboolean (*Activate) (GnmHLink *lnk, WBCGtk *wbcg);
- void (*set_sheet) (GnmHLink *lnk, Sheet *sheet);
void (*set_target) (GnmHLink *lnk, const char *target);
const char * (*get_target) (GnmHLink const *lnk);
} GnmHLinkClass;
diff --git a/src/hlink.c b/src/hlink.c
index 5a298313dd..75e56d0475 100644
--- a/src/hlink.c
+++ b/src/hlink.c
@@ -39,11 +39,17 @@
#include <goffice/goffice.h>
#include <gsf/gsf-impl-utils.h>
+#include <gnm-i18n.h>
#define GET_CLASS(instance) G_TYPE_INSTANCE_GET_CLASS (instance, GNM_HLINK_TYPE, GnmHLinkClass)
static GObjectClass *gnm_hlink_parent_class;
+enum {
+ PROP_0,
+ PROP_SHEET,
+};
+
/*
* WARNING WARNING WARNING
*
@@ -92,12 +98,6 @@ gnm_hlink_finalize (GObject *obj)
gnm_hlink_parent_class->finalize (obj);
}
-static void
-gnm_hlink_base_set_sheet (GnmHLink *lnk, Sheet *sheet)
-{
- lnk->sheet = sheet;
-}
-
static void
gnm_hlink_base_set_target (GnmHLink *lnk, gchar const *target)
{
@@ -112,6 +112,24 @@ gnm_hlink_base_get_target (GnmHLink const *lnk)
return lnk->target;
}
+static void
+gnm_hlink_base_set_property (GObject *object, guint property_id,
+ GValue const *value, GParamSpec *pspec)
+{
+ GnmHLink *hlink = (GnmHLink *)object;
+
+ switch (property_id) {
+ case PROP_SHEET:
+ // Construction-time only
+ hlink->sheet = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+
static void
gnm_hlink_class_init (GObjectClass *object_class)
{
@@ -120,7 +138,16 @@ gnm_hlink_class_init (GObjectClass *object_class)
gnm_hlink_parent_class = g_type_class_peek_parent (object_class);
object_class->finalize = gnm_hlink_finalize;
- hlink_class->set_sheet = gnm_hlink_base_set_sheet;
+ object_class->set_property = gnm_hlink_base_set_property;
+ g_object_class_install_property (object_class, PROP_SHEET,
+ g_param_spec_object ("sheet",
+ P_("Parent sheet"),
+ P_("The sheet in which the link lives"),
+ GNM_SHEET_TYPE,
+ GSF_PARAM_STATIC |
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
+
hlink_class->set_target = gnm_hlink_base_set_target;
hlink_class->get_target = gnm_hlink_base_get_target;
}
@@ -196,40 +223,29 @@ gnm_hlink_get_sheet (GnmHLink *lnk)
return lnk->sheet;
}
-void
-gnm_hlink_set_sheet (GnmHLink *lnk, Sheet *sheet)
-{
- g_return_if_fail (GNM_IS_HLINK (lnk));
- GET_CLASS (lnk)->set_sheet (lnk, sheet);
-}
-
GnmHLink *
gnm_hlink_new (GType typ, Sheet *sheet)
{
- GnmHLink *lnk;
-
g_return_val_if_fail (typ != 0, NULL);
g_return_val_if_fail (g_type_is_a (typ, GNM_HLINK_TYPE), NULL);
g_return_val_if_fail (!G_TYPE_IS_ABSTRACT (typ), NULL);
g_return_val_if_fail (IS_SHEET (sheet), NULL);
- lnk = g_object_new (typ, NULL);
- gnm_hlink_set_sheet (lnk, sheet);
- return lnk;
+ return g_object_new (typ, "sheet", sheet, NULL);
}
/**
- * gnm_hlink_dup:
+ * gnm_hlink_dup_to:
* @lnk: Existing link
+ * @sheet: target sheet
*
* Returns: (transfer full): A duplicate link.
*/
GnmHLink *
-gnm_hlink_dup (GnmHLink *lnk)
+gnm_hlink_dup_to (GnmHLink *lnk, Sheet *sheet)
{
- GnmHLink *new_lnk = g_object_new (G_OBJECT_TYPE (lnk), NULL);
+ GnmHLink *new_lnk = gnm_hlink_new (G_OBJECT_TYPE (lnk), sheet);
- gnm_hlink_set_sheet (new_lnk, lnk->sheet);
gnm_hlink_set_target (new_lnk, gnm_hlink_get_target (lnk));
gnm_hlink_set_tip (new_lnk, lnk->tip);
@@ -301,15 +317,6 @@ gnm_hlink_cur_wb_activate (GnmHLink *lnk, WBCGtk *wbcg)
return TRUE;
}
-static void
-gnm_hlink_cur_wb_set_sheet (GnmHLink *lnk, Sheet *sheet)
-{
- GnmHLinkCurWB *hlcwb = (GnmHLinkCurWB *)lnk;
- ((GnmHLinkClass*)gnm_hlink_cur_wb_parent_class)
- ->set_sheet (lnk, sheet);
- dependent_managed_set_sheet (&hlcwb->dep, sheet);
-}
-
static void
gnm_hlink_cur_wb_set_target (GnmHLink *lnk, const char *target)
{
@@ -339,6 +346,7 @@ gnm_hlink_cur_wb_set_target (GnmHLink *lnk, const char *target)
}
}
+ dependent_managed_set_sheet (&hlcwb->dep, lnk->sheet);
dependent_managed_set_expr (&hlcwb->dep, texpr);
if (texpr)
gnm_expr_top_unref (texpr);
@@ -394,7 +402,6 @@ gnm_hlink_cur_wb_class_init (GObjectClass *object_class)
object_class->finalize = gnm_hlink_cur_wb_finalize;
hlink_class->Activate = gnm_hlink_cur_wb_activate;
- hlink_class->set_sheet = gnm_hlink_cur_wb_set_sheet;
hlink_class->set_target = gnm_hlink_cur_wb_set_target;
hlink_class->get_target = gnm_hlink_cur_wb_get_target;
}
diff --git a/src/hlink.h b/src/hlink.h
index e4c495d9c2..9c2457625e 100644
--- a/src/hlink.h
+++ b/src/hlink.h
@@ -20,7 +20,7 @@ GnmHLink *gnm_sheet_hlink_find (Sheet const *sheet, GnmCellPos const *pos);
GType gnm_hlink_get_type (void);
GnmHLink *gnm_hlink_new (GType typ, Sheet *sheet);
-GnmHLink *gnm_hlink_dup (GnmHLink *lnk);
+GnmHLink *gnm_hlink_dup_to (GnmHLink *lnk, Sheet *sheet);
gboolean gnm_hlink_equal (GnmHLink const *a, GnmHLink const *b, gboolean relax_sheet);
@@ -33,7 +33,6 @@ const char *gnm_hlink_get_tip (GnmHLink const *lnk);
void gnm_hlink_set_tip (GnmHLink *lnk, gchar const *tip);
Sheet *gnm_hlink_get_sheet (GnmHLink *lnk);
-void gnm_hlink_set_sheet (GnmHLink *lnk, Sheet *sheet);
GType gnm_hlink_cur_wb_get_type (void);
GType gnm_hlink_url_get_type (void);
diff --git a/src/mstyle.c b/src/mstyle.c
index 572073e769..e8f9e513bb 100644
--- a/src/mstyle.c
+++ b/src/mstyle.c
@@ -991,8 +991,7 @@ gnm_style_linked_sheet_changed (GnmStyle *style)
if (elem_is_set (style, MSTYLE_HLINK) &&
style->hlink &&
gnm_hlink_get_sheet (style->hlink) != sheet) {
- GnmHLink *new_l = gnm_hlink_dup (style->hlink);
- gnm_hlink_set_sheet (new_l, sheet);
+ GnmHLink *new_l = gnm_hlink_dup_to (style->hlink, sheet);
gnm_style_set_hlink (style, new_l);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]