Ben Pfaff [Sun, 8 Jul 2012 06:44:37 +0000 (23:44 -0700)]
psppire-data-window: Delete dataset when closing window.
When the user closes the window it means that he wants to close the
underlying dataset also. Otherwise the dataset essentially leaks
(in theory it's still there in the list of datasets but in practice
that takes a DATASET ACTIVATE <name> WINDOW=FRONT command to show
it).
This also fixes a Gtk-CRITICAL and following crash in the following
scenario brought up by John Darrington:
1. Start psppire
2. File | Open and load x.sav (dataset1)
3. File | New | Data (a new data window will appear: dataset2)
4. Using the window manager close the window for dataset1
5. In dataset2: File | Open and load x.sav
I'm not 100% certain of the reason that this fixes it but I think
that there's some lingering association between the dataset and the
window that this change eliminates, by eliminating the dataset along
with the window.
The code added to psppire_data_window_dispose() in this commit
should probably go in a "finalize" function instead but there seems
to be a separate problem with references to PsppireVarSheet such
that if this new code is in "finalize" then dataset_destroy() will
call dict_clear() which will invoke the callbacks for PsppireDict
which will try to access the destroyed window. On the other hand,
with this code in "dispose" the window isn't fully destroyed yet so
while the same code path gets followed it isn't fatal.
Ben Pfaff [Sat, 7 Jul 2012 20:00:19 +0000 (13:00 -0700)]
psppire-dict: Make PsppireDict not own its "struct dictionary".
I see two places where PsppireDict are created. The first is in
psppire-data-window.c. In this case, the PsppireDataWindow is
borrowing a dictionary owned by a "struct dataset" for use in its
PsppireDict. When it destroys the PsppireDict, therefore, the
dictionary must not be destroyed because the dataset still owns it.
However, this is not what actually happens, and doing the
following:
1. Start psppire
2. File | Open and load x.sav (dataset1)
3. File | New | Data (a new data window will appear: dataset2)
4. Using the window manager close the window for dataset1
5. In dataset2: File | Open and load x.sav
or similar will cause a use-after-free error.
The second use is in text-data-import-dialog.c. This code does own
the struct dictionary, but it can simply free it itself at the same
time as the PsppireDict.
There is still some underlying issue with the above scenario,
because it still reports a GtkCritical, but valgrind no longer
reports a use-after-free error.
Ben Pfaff [Mon, 9 Jul 2012 05:12:49 +0000 (22:12 -0700)]
gui: Fix Glib-GObject-WARNING when closing the active dataset.
The DATASET CLOSE command, when it acts on the active dataset, just
removes the active dataset's name, changing it to the empty string.
(This is the documented behavior.) However, the GUI relies on
every dataset having a name, so this caused the following warning:
GLib-GObject-WARNING **: value """" of type `gchararray' is invalid
or out of range for property `id' of type `gchararray'
This commit fixes the problem by giving any unnamed dataset a name
after running syntax.
Ben Pfaff [Wed, 20 Jun 2012 05:43:24 +0000 (22:43 -0700)]
Add ENCODING subcommand to several commands.
I believe that this completes support for encodings for data input
commands such as DATA LIST and GET DATA/TYPE=TXT. Support is still
incomplete for data output commands such as PRINT, which confuse
byte offsets with character positions.
Ben Pfaff [Sat, 19 Mar 2011 23:26:55 +0000 (16:26 -0700)]
line-reader: New library for reading a file line-by-line.
This library reads a file line-by-line in an arbitrary 8-bit or wider
encoding, without requiring the file to be recoded. This will be used
in an upcoming commit.
John Darrington [Fri, 15 Jun 2012 18:29:24 +0000 (20:29 +0200)]
ext-array.c: Ensure that fseek is called before switching between read and write.
ANSI C requires that a file positioning function (eg seek) occurs before a switch
from reading to writing a stream (or vici-versa). We had not been doing this.
This had caused problems which manifested themselves on Windows operating systems,
by mysteriously failing to write the stream (and thus truncating the datafile).
This change corrects this.
Thanks to Harry Thijssen and Henry Gong for their very valuable assistance tracking
down the cause of this problem.
When CORRELATIONS was run using the WITH keyword, the wrong index
was calculated for the columns/rows - hence the program crashed.
This change fixes that.
Ben Pfaff [Wed, 9 May 2012 05:04:47 +0000 (22:04 -0700)]
i18n: Set LC_COLLATE locale category based on system locale.
LC_COLLATE controls the sort order of file names in GTK+ file
chooser dialog boxes, so we should set this locale category so as
to honor the user's preferences.
In the standard C library, only a few functions honor LC_COLLATE:
strcoll, wcscoll, strxfm, and wcsxfrm. PSPP doesn't use any of
these functions, so this commit should not affect PSPP's use of
standard library functions.
The libunistring manual only mentions collation rules in the entries
for a few functions: u8_strcoll, u16_strcoll, u32_strcoll,
u8_normcoll, u16_normcoll, u32_normcoll, u8_casecoll, u16_casecoll
u32_casecoll. PSPP doesn't use any of those functions either.
Ben Pfaff [Sun, 6 May 2012 15:06:57 +0000 (08:06 -0700)]
gui: Make lex_gtk_text_buffer_read() count bytes, not characters.
The N parameter to lex_gtk_text_buffer_read() is a count of bytes,
but the implementation treated it as characters.
Also fixes a memory leak, since gtk_text_iter_get_text()'s caller
is responsible for freeing the memory that it returns.
Reported by Alle <ajk-eis@rvhome.de>.
First investigated by John Darrington <john@darrington.wattle.id.au>.
Reviewed by John Darrington <john@darrington.wattle.id.au>.
Ben Pfaff [Sun, 6 May 2012 05:07:34 +0000 (22:07 -0700)]
lexer: Check that 'read' function in lex_source returns valid value.
A 'read' function may only read as many bytes as the size of the
buffer passed into it, but the caller didn't check, which made an
actual violation of this invariant hard to diagnose.
Ben Pfaff [Sat, 5 May 2012 04:30:49 +0000 (21:30 -0700)]
configure.ac: Link PSPPIRE explicitly against gthread.
Seems to be required on OpenSUSE.
PSPPIRE does not make explicit use of threads, but it does use
GTimer. Thus, it calls g_thread_init() because of the following
note in the documentation for GTimer:
GTimer uses a higher-quality clock when thread support is
available. Therefore, calling g_thread_init() while timers
are running may lead to unreliable results. It is best to
call g_thread_init() before starting any timers, if you are
using threads at all.
Separately, the documentation for threads in Glib says:
Calling g_thread_init() with a NULL argument is somewhat more
relaxed. You may call any other glib functions in the main
thread before g_thread_init() as long as g_thread_init() is
not called from a glib callback, or with any locks held.
However, many libraries above glib does not support late
initialization of threads, so doing this should be avoided if
possible.
Please note that since version 2.24 the GObject
initialization function g_type_init() initializes threads
(with a NULL argument), so most applications, including those
using Gtk+ will run with threads enabled. If you want a
special thread implementation, make sure you call
g_thread_init() before g_type_init() is called.
Taken together, it seems to imply that PSPPIRE should call
g_thread_init() before g_timer_new(), or the timer might be
unreliable because Glib would call it later for us. But the
documentation doesn't seem entirely clear.
John Darrington [Sat, 28 Apr 2012 10:41:05 +0000 (12:41 +0200)]
Correct erroneous g_object_unref calls
commit e89158e8abd2dae27d985e3574eb5aa1d265fc66 placed g_object_unref calls after every instance
of *_set_model - In most instances this was correct, but not all. When (for example)
gtk_tree_view_set_model (view, model) is called, it takes a ref to model, but it will then
unref it upon the next call to _set_model and/or when view is destroyed.
Unreffing the model ourself, is therefore appropriate only when we have created it ourselves.
This change fixes the few instances where this was not the case.
When "slash" is set to true, the button gets a diagonal slash drawn
across it. This is ugly, but it matches what SPSS does for cases
that are filtered out.
Ben Pfaff [Sat, 3 Mar 2012 19:25:20 +0000 (11:25 -0800)]
pspp-sheet-view: Improve look of sheet when there are few columns.
GtkTreeView always expands one or more columns so that the visible
columns fill up the entire width of the treeview. This looks funny
in a spreadsheet-like view. This commit changes PsppSheetView so
that, instead, extra space is left blanks instead of being filled
up with columns.
Ben Pfaff [Tue, 24 Apr 2012 05:43:13 +0000 (22:43 -0700)]
pspp-widget-facade: New code to measure and render some GTK+ widgets.
There are two upcoming uses for this in the tree, both related to
rendering fake buttons. First, creating, maintaining, and rendering
the column header buttons in a PsppSheetView is a huge cost when
there are hundreds or thousands of columns. Using this facade code
to "fake" buttons makes the sheet much faster. Second, this code
will be used to implement a cell renderer for GtkButton, so that
buttons can be put into PsppSheetView rows.
Ben Pfaff [Sat, 12 Nov 2011 05:50:31 +0000 (21:50 -0800)]
pspp-sheet-view: Add "special-cells" property to speed drawing many columns.
A "special cell" is a cell that is editable or activatable. When a row
that contains a special cell is selected, the cursor is drawn around a
single cell; when other rows are selected, the cursor is drawn around the
entire row.
With the default of "detect" (the only mode previously supported), whether
a given row contains a special cell is detected automatically. This is the
best choice most of the time. For sheet views that contain more than 100
columns, an explicit "yes" or "no" improves performance.
Ben Pfaff [Tue, 28 Jun 2011 05:17:57 +0000 (22:17 -0700)]
pspp-sheet-view: Support rectangular selection, column popup menus.
A "rectangular selection" is where you can click and drag to select
a rectangular group of columns and rows, like in a spreadsheet.
In this commit, rectangular selections don't interact well with
"quick-edit" mode where the first click on a cell starts editing,
because clicking in a quick-edit cell starts editing instead of
rectangular selection. The following commit will fix the problem.
This commit also adds a gtk_widget_queue_draw() call to
pspp_sheet_view_update_rubber_band() that should really
invalidate less sheet area.
Ben Pfaff [Fri, 24 Jun 2011 05:16:28 +0000 (22:16 -0700)]
pspp-sheet-view: Edit cells on the first click by default.
With GtkTreeView it takes two clicks to edit a cell. The first click
selects the row and the second click starts editing. This isn't a
great user experience for a spreadsheet, so this commit enables
single-click editing.
Ben Pfaff [Wed, 16 Nov 2011 05:05:30 +0000 (21:05 -0800)]
pspp-sheet-view: Fix rendering moving cursor left or right with keyboard.
I don't understand why this is not necessary for GtkTreeView. Without it,
the cursor doesn't get properly redrawn after a left or right arrow
keystroke moves it.
gdk_draw_line() draws lines by passing the coordinates to XDrawLine(),
which in turn casts the coordinates to "signed int" as it formats them for
the X Protocol. Thus, large coordinate values wrap around and cause odd
visual artifacts.
This fixes the problem by only calling gdk_draw_line() with coordinate
values that should actually be visible.
Ben Pfaff [Fri, 27 May 2011 05:11:42 +0000 (22:11 -0700)]
pspp-sheet-view: Improve scrolling performance.
Drawing dashed lines is very slow, at least on my computer. This commit
changes them to solid, which makes scrolling in a large sheet feel much,
much more responsive on my system.
Ben Pfaff [Sun, 22 Apr 2012 17:15:46 +0000 (10:15 -0700)]
pspp-sheet-view: Reduce time and memory cost to O(1) in number of rows.
The standard GtkTreeView uses time and memory linear in the number of
rows in the tree. When the model is set, it iterates over every row
and creates a corresponding GtkRbNode. After that, GtkTreeView uses
the GtkRbNodes for many operations on the tree.
This commit adapts GtkTreeView to avoid the need to iterate over the
entire model up front, as well as the need to maintain data for every
row. It makes the following major changes:
- The tree model must now be just a list (GTK_TREE_MODEL_LIST_ONLY);
that is, rows may not have children.
- The height of a row in the view must be fixed (as with
gtk_tree_view_set_fixed_height_mode()). Column widths must also
be fixed.
The following minor changes follow mainly as consequences of the above:
- Expander arrows, tree lines, and level indentation are no longer
supported, because these only make sense with rows that have
children.
- Separator rows are no longer supported. (They are ugly in
fixed-height mode because they occupy an entire row.)
Ben Pfaff [Wed, 25 Apr 2012 05:24:55 +0000 (22:24 -0700)]
PsppireValueEntry: Simplify 'if' condition.
The statement
if ((model != NULL) && (model != old_model))
can be simplifed to just:
if (model != NULL)
because if 'model' is nonnull then it is different from old_model,
because 'model' is a newly allocated GtkListStore.
Ben Pfaff [Wed, 25 Apr 2012 05:16:30 +0000 (22:16 -0700)]
gui: Properly manage ref counts of combo box and tree view models.
gtk_combo_box_set_model() and gtk_tree_view_set_model() add a
reference to the passed-in model, instead of transferring a
reference from the caller. A lot of the calls to these functions,
however, assumed that a reference was transferred and therefore
leaked a reference. This fixes them up.
This doesn't change PsppireValueEntry, because there's an ongoing
discussion about that.
Ben Pfaff [Wed, 25 Apr 2012 05:14:58 +0000 (22:14 -0700)]
psppire-acr: Clarify acr ownership of its list store.
PsppireAcr retains a pointer to the GtkListStore inside it but it
didn't, until now, keep a reference to it. This commit makes
PsppireAcr retain a reference, documents the interface, and updates
callers to properly maintain reference counts.
Ben Pfaff [Mon, 9 Apr 2012 03:30:14 +0000 (20:30 -0700)]
gui: New widget PsppireValueEntry for editing a "union value".
This is intended to be a convenenient way to allow the user to
view and edit a "union value" that includes the ability to see
and select values by value label.
Ben Pfaff [Thu, 7 Jul 2011 15:09:17 +0000 (08:09 -0700)]
gui: New type PsppireEmptyListStore.
PsppireEmptyListStore is an GtkTreeModel implementation that has a
client-specified number of rows and zero columns. It is a useful model for
GtkTreeView or PsppSheetView when the client can easily synthesize cell
data using a callback set with gtk_tree_view_column_set_cell_data_func().
In that situation, GtkListStore can be wasteful (because it uses a lot of
memory to store what does not need to be stored) and situation-specific
custom models require additional boilerplate.
This commit also modified the text data import dialog code to use
PsppireEmptyListStore. Future commits will add other users.
Ben Pfaff [Fri, 26 Aug 2011 03:20:52 +0000 (20:20 -0700)]
New "range-tower" data structure.
A range tower is a bitmap, implemented as an augmented binary tree.
Beyond the usual features of a bitmap, a range tower can efficiently
implement a "splice" operation that shifts ranges of bits left or right.
This feature does cost memory and time, so use a range tower only if this
feature is actually needed. Otherwise, use a range set (see range-set.h),
which can do everything that a range tower can do except the "splice"
operation.
Each operation has O(lg N) cost, where N is the number of contiguous
regions of 1-bits in the bitmap. Also, a cache reduces the second and
subsequent containment tests within a single contiguous region to O(1).
Ben Pfaff [Tue, 20 Sep 2011 04:34:13 +0000 (21:34 -0700)]
range-set: Rename "insert" function "set1", "delete" to "set0".
An upcoming commit will introduce a new "range-tower" data
structure that can actually insert and delete ranges. It
makes sense not to use different terminology for the two data
structures, so renaming these functions makes sense.
Ben Pfaff [Sat, 31 Mar 2012 22:41:39 +0000 (15:41 -0700)]
format: Fix typo in comment.
struct fmt_spec's 'd' member is not normally a number of "implied"
decimal places. It is normally the number of decimal places that
will be presented in formatted values. Thus, update the comment.
Ben Pfaff [Mon, 4 Jul 2011 21:48:57 +0000 (14:48 -0700)]
format: New functions fmt_change_width(), fmt_change_decimals().
These will be used in an upcoming commit for GUI-based format
adjustments, where we want to implement the user's request for
width or decimal places to the extent that we can, while
adjusting decimal places or width, respectively, as necessary.
John Darrington [Thu, 19 Apr 2012 19:14:54 +0000 (21:14 +0200)]
DO IF test: Correct expected outcome
Commit 27bd188495ec1a6085354b10545daba47771b517 added a test for an
error condition in DO IF, but appears to contain some cut and paste
errors. This change corrects them.