[gnumeric] Introspection fixes.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Introspection fixes.
- Date: Sat, 10 Oct 2020 19:58:59 +0000 (UTC)
commit 773b1487bbf2ba06d4f3873759de99912bb48ce1
Author: Morten Welinder <terra gnome org>
Date: Sat Oct 10 15:56:12 2020 -0400
Introspection fixes.
This hides all fields of the Workbook structure from introspection, thus
making workbook_sheets visible. Consequently, python users can now loop
over sheets like this:
for s in wb.sheets():
print(s.props.name)
This commit also changes the return type of workbook_sheets to
GPtrArray* since most users don't need the copying.
plugins/html/roff.c | 9 +++---
plugins/openoffice/openoffice-write.c | 9 +++---
src/cell.c | 12 +++++++
src/cell.h | 10 +++++-
src/dialogs/dialog-sheet-resize.c | 13 ++++----
src/dialogs/dialog-zoom.c | 9 +++---
src/print-info.c | 10 ++++--
src/wbc-gtk.c | 59 -----------------------------------
src/widgets/gnm-sheet-sel.c | 18 +++++------
src/widgets/gnm-sheet-sel.h | 2 +-
src/workbook-priv.h | 2 ++
src/workbook.c | 31 +++++++-----------
src/workbook.h | 2 +-
13 files changed, 74 insertions(+), 112 deletions(-)
---
diff --git a/plugins/html/roff.c b/plugins/html/roff.c
index 70eef5b2b..5559f2b1f 100644
--- a/plugins/html/roff.c
+++ b/plugins/html/roff.c
@@ -85,7 +85,8 @@ void
roff_file_save (GOFileSaver const *fs, GOIOContext *io_context,
WorkbookView const *wb_view, GsfOutput *output)
{
- GSList *sheets, *ptr;
+ GPtrArray *sheets;
+ unsigned ui;
GnmCell *cell;
int row, col, fontsize, v_size;
Workbook *wb = wb_view_get_workbook (wb_view);
@@ -95,8 +96,8 @@ roff_file_save (GOFileSaver const *fs, GOIOContext *io_context,
gsf_output_printf (output, ".\\\" TROFF file\n");
gsf_output_printf (output, ".fo ''%%''\n");
sheets = workbook_sheets (wb);
- for (ptr = sheets ; ptr != NULL ; ptr = ptr->next) {
- Sheet *sheet = ptr->data;
+ for (ui = 0; ui < sheets->len; ui++) {
+ Sheet *sheet = g_ptr_array_index (sheets, ui);
GnmRange r = sheet_get_extent (sheet, FALSE, TRUE);
gsf_output_printf (output, "%s\n\n", sheet->name_unquoted);
@@ -188,5 +189,5 @@ roff_file_save (GOFileSaver const *fs, GOIOContext *io_context,
}
gsf_output_printf (output, ".TE\n\n");
}
- g_slist_free (sheets);
+ g_ptr_array_unref (sheets);
}
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index e2d90cfb6..7c96abbd8 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -6196,7 +6196,8 @@ odf_write_gnm_settings (GnmOOExport *state)
static void
odf_write_ooo_settings (GnmOOExport *state)
{
- GSList *l, *sheets;
+ GPtrArray *sheets;
+ unsigned ui;
gsf_xml_out_start_element (state->xml, CONFIG "config-item-set");
gsf_xml_out_add_cstr_unchecked (state->xml, CONFIG "name", OOO "view-settings");
@@ -6214,8 +6215,8 @@ odf_write_ooo_settings (GnmOOExport *state)
"Tables");
sheets = workbook_sheets (state->wb);
- for (l = sheets; l != NULL; l = l->next) {
- Sheet *sheet = l->data;
+ for (ui = 0; ui < sheets->len; ui++) {
+ Sheet *sheet = g_ptr_array_index (sheets, ui);
SheetView *sv = sheet_get_view (sheet, state->wbv);
gsf_xml_out_start_element (state->xml, CONFIG "config-item-map-entry");
gsf_xml_out_add_cstr (state->xml, CONFIG "name", sheet->name_unquoted);
@@ -6320,7 +6321,7 @@ odf_write_ooo_settings (GnmOOExport *state)
gsf_xml_out_end_element (state->xml); /* </config:config-item-map-entry> */
}
- g_slist_free (sheets);
+ g_ptr_array_unref (sheets);
gsf_xml_out_end_element (state->xml); /* </config:config-item-map-named> */
diff --git a/src/cell.c b/src/cell.c
index d8519c30f..a59e8fdc3 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -1127,3 +1127,15 @@ gnm_cell_get_type (void)
return type_cell;
}
+
+// Provide the external version of inline functions, used mainly for
+// introspection
+
+/**
+ * gnm_cell_has_expr:
+ * @cell: #GnmCell
+ *
+ * Returns: %TRUE if @cell has an expression or %FALSE if it is empty
+ * or contains a value.
+ */
+extern inline gboolean gnm_cell_has_expr (GnmCell const *cell);
diff --git a/src/cell.h b/src/cell.h
index 29f601e7c..f2b5f9838 100644
--- a/src/cell.h
+++ b/src/cell.h
@@ -33,9 +33,17 @@ GType gnm_cell_get_type (void);
/*
* GnmCell state checking
*/
+#ifdef __GI_SCANNER__
+gboolean gnm_cell_has_expr (GnmCell const *cell);
+#else
+inline gboolean
+gnm_cell_has_expr (GnmCell const *cell) {
+ return cell->base.texpr != NULL;
+}
+#endif
+
#define gnm_cell_needs_recalc(cell) ((cell)->base.flags & DEPENDENT_NEEDS_RECALC)
#define gnm_cell_expr_is_linked(cell) ((cell)->base.flags & DEPENDENT_IS_LINKED)
-#define gnm_cell_has_expr(cell) ((cell)->base.texpr != NULL)
#define gnm_cell_is_merged(cell) ((cell)->base.flags & GNM_CELL_IS_MERGED)
gboolean gnm_cell_is_empty (GnmCell const *cell);
gboolean gnm_cell_is_blank (GnmCell const *cell); /* empty, or "" */
diff --git a/src/dialogs/dialog-sheet-resize.c b/src/dialogs/dialog-sheet-resize.c
index 1a4dcf6a7..294bfc344 100644
--- a/src/dialogs/dialog-sheet-resize.c
+++ b/src/dialogs/dialog-sheet-resize.c
@@ -104,7 +104,6 @@ init_scale (GtkWidget *scale, int N, int lo, int hi)
static void
cb_ok_clicked (ResizeState *state)
{
- GSList *sheets, *l;
GSList *changed_sheets = NULL;
WorkbookControl *wbc;
Workbook *wb;
@@ -116,12 +115,14 @@ cb_ok_clicked (ResizeState *state)
(GTK_TOGGLE_BUTTON (state->all_sheets_button));
wbc = GNM_WBC (state->wbcg);
+ wb = wb_control_get_workbook (wbc);
if (all_sheets) {
- wb = wb_control_get_workbook (wbc);
- sheets = workbook_sheets (wb);
- for (l = sheets; l; l = l->next) {
- Sheet *this_sheet = l->data;
+ GPtrArray *sheets = workbook_sheets (wb);
+ unsigned ui;
+
+ for (ui = 0; ui < sheets->len; ui++) {
+ Sheet *this_sheet = g_ptr_array_index (sheets, ui);
if (this_sheet == state->sheet)
continue;
@@ -132,7 +133,7 @@ cb_ok_clicked (ResizeState *state)
changed_sheets = g_slist_prepend (changed_sheets, this_sheet);
}
- g_slist_free (sheets);
+ g_ptr_array_unref (sheets);
}
if (changed_sheets ||
diff --git a/src/dialogs/dialog-zoom.c b/src/dialogs/dialog-zoom.c
index 649c794d2..1e6f2384a 100644
--- a/src/dialogs/dialog-zoom.c
+++ b/src/dialogs/dialog-zoom.c
@@ -160,7 +160,8 @@ void
dialog_zoom (WBCGtk *wbcg, Sheet *sheet)
{
ZoomState *state;
- GSList *l, *sheets;
+ GPtrArray *sheets;
+ unsigned ui;
int i, row, cur_row;
gboolean is_custom = TRUE;
GtkRadioButton *radio;
@@ -200,9 +201,9 @@ dialog_zoom (WBCGtk *wbcg, Sheet *sheet)
sheets = workbook_sheets (wb_control_get_workbook (GNM_WBC (wbcg)));
cur_row = row = 0;
- for (l = sheets; l; l = l->next) {
+ for (ui = 0; ui < sheets->len; ui++) {
GtkTreeIter iter;
- Sheet *this_sheet = l->data;
+ Sheet *this_sheet = g_ptr_array_index (sheets, ui);
gtk_list_store_append (state->sheet_list_model, &iter);
gtk_list_store_set (state->sheet_list_model,
@@ -215,7 +216,7 @@ dialog_zoom (WBCGtk *wbcg, Sheet *sheet)
cur_row = row;
row++;
}
- g_slist_free (sheets);
+ g_ptr_array_unref (sheets);
{
GtkTreePath *path = gtk_tree_path_new_from_indices (cur_row, -1);
diff --git a/src/print-info.c b/src/print-info.c
index b7fba0081..1492be62d 100644
--- a/src/print-info.c
+++ b/src/print-info.c
@@ -892,8 +892,9 @@ cb_set_pdf_option (const char *key, const char *value,
if (strcmp (key, "object") == 0) {
GPtrArray *objects = g_object_get_data (G_OBJECT (wb), "pdf-objects");
- GSList *sheets = workbook_sheets (wb);
+ GPtrArray *sheets = workbook_sheets (wb);
gboolean object_seen = FALSE;
+ unsigned ui;
if (!objects) {
objects = g_ptr_array_new ();
@@ -902,8 +903,8 @@ cb_set_pdf_option (const char *key, const char *value,
(GDestroyNotify)g_ptr_array_unref);
}
- for (; sheets != NULL; sheets = sheets->next) {
- Sheet *sheet = sheets->data;
+ for (ui = 0; ui < sheets->len; ui++) {
+ Sheet *sheet = g_ptr_array_index (sheets, ui);
GSList *sobjects = sheet->sheet_objects;
for (; sobjects != NULL; sobjects = sobjects->next) {
SheetObject *so = sobjects->data;
@@ -915,6 +916,9 @@ cb_set_pdf_option (const char *key, const char *value,
}
}
}
+
+ g_ptr_array_unref (sheets);
+
if (!object_seen) {
*err = g_error_new (go_error_invalid (), 0,
_("There is no object with name "
diff --git a/src/wbc-gtk.c b/src/wbc-gtk.c
index d3cc16947..e330105f4 100644
--- a/src/wbc-gtk.c
+++ b/src/wbc-gtk.c
@@ -1972,65 +1972,6 @@ cb_accept_input_selected_merged (WBCGtk *wbcg)
}
}
-/* static void */
-/* cb_accept_input_sheets_collector (Sheet *sheet, GSList **n) */
-/* { */
-/* if (sheet->visibility == GNM_SHEET_VISIBILITY_VISIBLE) */
-/* (*n) = g_slist_prepend (*n, sheet); */
-/* } */
-
-/* static void */
-/* cb_accept_input_sheets (WBCGtk *wbcg) */
-/* { */
-/* GSList *sheets = workbook_sheets */
-/* (wb_control_get_workbook (GNM_WBC (wbcg))); */
-/* GSList *vis_sheets = NULL; */
-
-/* g_slist_foreach (sheets, */
-/* (GFunc) cb_accept_input_sheets_collector, */
-/* &vis_sheets); */
-
-/* wbcg_edit_multisheet_finish (wbcg, WBC_EDIT_ACCEPT, NULL, vis_sheets); */
-
-/* g_slist_free (sheets); */
-/* g_slist_free (vis_sheets); */
-/* } */
-
-/* static void */
-/* cb_accept_input_menu_sensitive_sheets_counter (Sheet *sheet, gint *n) */
-/* { */
-/* if (sheet->visibility == GNM_SHEET_VISIBILITY_VISIBLE) */
-/* (*n)++; */
-/* } */
-
-/* static gboolean */
-/* cb_accept_input_menu_sensitive_sheets (WBCGtk *wbcg) */
-/* { */
-/* GSList *sheets = workbook_sheets */
-/* (wb_control_get_workbook (GNM_WBC (wbcg))); */
-/* gint n = 0; */
-
-/* g_slist_foreach (sheets, */
-/* (GFunc) cb_accept_input_menu_sensitive_sheets_counter, */
-/* &n); */
-/* g_slist_free (sheets); */
-/* return (n > 1); */
-/* } */
-
-/* static gboolean */
-/* cb_accept_input_menu_sensitive_selected_sheets (WBCGtk *wbcg) */
-/* { */
-/* GSList *sheets = workbook_sheets */
-/* (wb_control_get_workbook (GNM_WBC (wbcg))); */
-/* gint n = 0; */
-
-/* g_slist_foreach (sheets, */
-/* (GFunc) cb_accept_input_menu_sensitive_sheets_counter, */
-/* &n); */
-/* g_slist_free (sheets); */
-/* return (n > 2); */
-/* } */
-
static gboolean
cb_accept_input_menu_sensitive_selected_cells (WBCGtk *wbcg)
{
diff --git a/src/widgets/gnm-sheet-sel.c b/src/widgets/gnm-sheet-sel.c
index fce7f62d2..cd842af9e 100644
--- a/src/widgets/gnm-sheet-sel.c
+++ b/src/widgets/gnm-sheet-sel.c
@@ -175,17 +175,17 @@ gnm_sheet_sel_new (void)
* @sheets: (element-type Sheet) (transfer none): sheets
*/
void
-gnm_sheet_sel_set_sheets (GnmSheetSel *ss, GSList *sheets)
+gnm_sheet_sel_set_sheets (GnmSheetSel *ss, GPtrArray *sheets)
{
GtkMenu *menu;
- GSList *l;
+ unsigned ui;
g_return_if_fail (GNM_IS_SHEET_SEL (ss));
menu = GTK_MENU (gtk_menu_new ());
- for (l = sheets; l; l = l->next) {
- Sheet *sheet = l->data;
+ for (ui = 0; ui < sheets->len; ui++) {
+ Sheet *sheet = g_ptr_array_index (sheets, ui);
GtkWidget *item =
gtk_check_menu_item_new_with_label
(sheet->name_unquoted);
@@ -198,8 +198,8 @@ gnm_sheet_sel_set_sheets (GnmSheetSel *ss, GSList *sheets)
gtk_widget_show_all (GTK_WIDGET (menu));
go_option_menu_set_menu (&ss->parent, GTK_WIDGET (menu));
- if (sheets)
- gnm_sheet_sel_set_sheet (ss, sheets->data);
+ if (sheets->len > 0)
+ gnm_sheet_sel_set_sheet (ss, g_ptr_array_index (sheets, 0));
}
static void
@@ -208,12 +208,10 @@ cb_wb_changed (GnmWorkbookSel *wbs,
GnmSheetSel *ss)
{
Workbook *wb = gnm_workbook_sel_get_workbook (wbs);
- GSList *sheets = wb ? workbook_sheets (wb) : NULL;
+ GPtrArray *sheets = wb ? workbook_sheets (wb) : NULL;
// FIXME: sort?
gnm_sheet_sel_set_sheets (ss, sheets);
- if (sheets)
- gnm_sheet_sel_set_sheet (ss, sheets->data);
- g_slist_free (sheets);
+ g_ptr_array_unref (sheets);
}
void
diff --git a/src/widgets/gnm-sheet-sel.h b/src/widgets/gnm-sheet-sel.h
index 7dfae9c82..a08c1e9d3 100644
--- a/src/widgets/gnm-sheet-sel.h
+++ b/src/widgets/gnm-sheet-sel.h
@@ -36,7 +36,7 @@ typedef struct GnmSheetSel_ GnmSheetSel;
GtkWidget *gnm_sheet_sel_new (void);
-void gnm_sheet_sel_set_sheets (GnmSheetSel *ss, GSList *sheets);
+void gnm_sheet_sel_set_sheets (GnmSheetSel *ss, GPtrArray *sheets);
void gnm_sheet_sel_link (GnmSheetSel *ss, GnmWorkbookSel *wbs);
diff --git a/src/workbook-priv.h b/src/workbook-priv.h
index c7347e54c..b55393bfb 100644
--- a/src/workbook-priv.h
+++ b/src/workbook-priv.h
@@ -7,6 +7,7 @@
G_BEGIN_DECLS
struct _Workbook {
+#ifndef __GI_SCANNER__
GODoc doc;
GPtrArray *wb_views;
@@ -46,6 +47,7 @@ struct _Workbook {
gboolean being_reordered;
gboolean recursive_dirty_enabled;
gboolean being_loaded;
+#endif
};
typedef struct {
diff --git a/src/workbook.c b/src/workbook.c
index 3881df205..6b4199d8f 100644
--- a/src/workbook.c
+++ b/src/workbook.c
@@ -129,8 +129,9 @@ static void
workbook_dispose (GObject *wb_object)
{
Workbook *wb = WORKBOOK (wb_object);
- GSList *sheets, *ptr;
GSList *controls = NULL;
+ GPtrArray *sheets;
+ unsigned ui;
wb->during_destruction = TRUE;
@@ -163,11 +164,13 @@ workbook_dispose (GObject *wb_object)
dependents_workbook_destroy (wb);
/* Copy the set of sheets, the list changes under us. */
- sheets = workbook_sheets (wb);
+ sheets = g_ptr_array_sized_new (wb->sheets->len);
+ memcpy (sheets->pdata, wb->sheets->pdata,
+ wb->sheets->len * sizeof (gpointer));
/* Remove all contents while all sheets still exist */
- for (ptr = sheets; ptr != NULL ; ptr = ptr->next) {
- Sheet *sheet = ptr->data;
+ for (ui = 0; ui < sheets->len; ui++) {
+ Sheet *sheet = g_ptr_array_index (sheets, ui);
GnmRange r;
sheet->being_destructed = TRUE;
@@ -181,11 +184,11 @@ workbook_dispose (GObject *wb_object)
}
/* Now remove the sheets themselves */
- for (ptr = sheets; ptr != NULL ; ptr = ptr->next) {
- Sheet *sheet = ptr->data;
+ for (ui = 0; ui < sheets->len; ui++) {
+ Sheet *sheet = g_ptr_array_index (sheets, ui);
workbook_sheet_delete (sheet);
}
- g_slist_free (sheets);
+ g_ptr_array_unref (sheets);
// Now get rid of the control refs
g_slist_free_full (controls, g_object_unref);
@@ -829,21 +832,11 @@ workbook_detach_view (WorkbookView *wbv)
*
* Returns: (element-type Sheet) (transfer container): the sheets list.
*/
-GSList *
+GPtrArray *
workbook_sheets (Workbook const *wb)
{
- GSList *list = NULL;
-
g_return_val_if_fail (GNM_IS_WORKBOOK (wb), NULL);
-
- if (wb->sheets) {
- int i = wb->sheets->len;
- while (i-- > 0)
- list = g_slist_prepend (list,
- g_ptr_array_index (wb->sheets, i));
- }
-
- return list;
+ return g_ptr_array_ref (wb->sheets);
}
int
diff --git a/src/workbook.h b/src/workbook.h
index dd65f8275..8fa683e9c 100644
--- a/src/workbook.h
+++ b/src/workbook.h
@@ -17,7 +17,7 @@ Workbook *workbook_new (void);
Workbook *workbook_new_with_sheets (int sheet_count);
/* Sheet support routines */
-GSList *workbook_sheets (Workbook const *wb);
+GPtrArray *workbook_sheets (Workbook const *wb);
int workbook_sheet_count (Workbook const *wb);
Sheet *workbook_sheet_by_index (Workbook const *wb, int i);
Sheet *workbook_sheet_by_name (Workbook const *wb, char const *sheet_name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]