Commit 18bcb4e0 authored by JP Rosevear's avatar JP Rosevear Committed by JP Rosevear

Adjust if the range to be sorted has a header.

2000-06-12  JP Rosevear  <jpr@arcavia.com>

	* src/workbook.c (sort_cmd): Adjust if the range to be sorted
	has a header.

	* NEWS: Update.

	* src/ranges.h: New prototype.

	* src/ranges.c (range_has_header): New function to determine if
	a region has a header row.
parent 4dee91bd
2000-06-12 JP Rosevear <jpr@arcavia.com>
* src/workbook.c (sort_cmd): Adjust if the range to be sorted
has a header.
* NEWS: Update.
* src/ranges.h: New prototype.
* src/ranges.c (range_has_header): New function to determine if
a region has a header row.
2000-06-09 Jody Goldberg <jgoldberg@home.com>
* src/item-cursor.c (item_cursor_update) : Change sheet -> sheet-view.
......
2000-06-12 JP Rosevear <jpr@arcavia.com>
* src/workbook.c (sort_cmd): Adjust if the range to be sorted
has a header.
* NEWS: Update.
* src/ranges.h: New prototype.
* src/ranges.c (range_has_header): New function to determine if
a region has a header row.
2000-06-09 Jody Goldberg <jgoldberg@home.com>
* src/item-cursor.c (item_cursor_update) : Change sheet -> sheet-view.
......
......@@ -12,7 +12,8 @@ Jody:
* Some translation bugs.
JPR:
* Improve sorting.
* Sorting now moves styles with the elements
* Sorting now detects headers when sorting
Kenneth
* Added two perl scripts for translation help/maintainence.
......
2000-06-12 JP Rosevear <jpr@arcavia.com>
* src/workbook.c (sort_cmd): Adjust if the range to be sorted
has a header.
* NEWS: Update.
* src/ranges.h: New prototype.
* src/ranges.c (range_has_header): New function to determine if
a region has a header row.
2000-06-09 Jody Goldberg <jgoldberg@home.com>
* src/item-cursor.c (item_cursor_update) : Change sheet -> sheet-view.
......
2000-06-12 JP Rosevear <jpr@arcavia.com>
* src/workbook.c (sort_cmd): Adjust if the range to be sorted
has a header.
* NEWS: Update.
* src/ranges.h: New prototype.
* src/ranges.c (range_has_header): New function to determine if
a region has a header row.
2000-06-09 Jody Goldberg <jgoldberg@home.com>
* src/item-cursor.c (item_cursor_update) : Change sheet -> sheet-view.
......
2000-06-12 JP Rosevear <jpr@arcavia.com>
* src/workbook.c (sort_cmd): Adjust if the range to be sorted
has a header.
* NEWS: Update.
* src/ranges.h: New prototype.
* src/ranges.c (range_has_header): New function to determine if
a region has a header row.
2000-06-09 Jody Goldberg <jgoldberg@home.com>
* src/item-cursor.c (item_cursor_update) : Change sheet -> sheet-view.
......
2000-06-12 JP Rosevear <jpr@arcavia.com>
* src/workbook.c (sort_cmd): Adjust if the range to be sorted
has a header.
* NEWS: Update.
* src/ranges.h: New prototype.
* src/ranges.c (range_has_header): New function to determine if
a region has a header row.
2000-06-09 Jody Goldberg <jgoldberg@home.com>
* src/item-cursor.c (item_cursor_update) : Change sheet -> sheet-view.
......
2000-06-12 JP Rosevear <jpr@arcavia.com>
* src/workbook.c (sort_cmd): Adjust if the range to be sorted
has a header.
* NEWS: Update.
* src/ranges.h: New prototype.
* src/ranges.c (range_has_header): New function to determine if
a region has a header row.
2000-06-09 Jody Goldberg <jgoldberg@home.com>
* src/item-cursor.c (item_cursor_update) : Change sheet -> sheet-view.
......
2000-06-12 JP Rosevear <jpr@arcavia.com>
* dialog-cell-sort.c (dialog_cell_sort_ok): If the region has a
header, setup the dialog appropriately.
2000-06-11 Jon K Hellan <hellan@acm.org>
* dialog-cell-format.c (line_info[]): Add explanatory comment.
......
......@@ -606,6 +606,11 @@ dialog_cell_sort (Workbook *inwb, Sheet *sheet)
GTK_SIGNAL_FUNC (dialog_cell_sort_cols_toggled),
&sort_flow);
/* Set the header button and drop down boxes correctly */
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check),
range_has_header (sort_flow.sheet,
sort_flow.sel, TRUE));
gtk_widget_show_all (sort_flow.clause_box);
/* Run the dialog */
......
......@@ -379,6 +379,86 @@ range_name (Range const *src)
return buffer;
}
/**
* range_has_header:
* @sheet: Sheet to check
* @src: Range to check
* @top: Flag
*
* This routine takes a sheet and a range and checks for a header row
* in the range. If top is true it looks for a header row from the top
* and if false it looks for a header col from the left
*
* Return value: Whether or not the range has a header
**/
gboolean
range_has_header (const Sheet *sheet, const Range *src, gboolean top)
{
Cell *ca, *cb;
Value *valuea, *valueb;
MStyle *stylea, *styleb;
int length, i;
/* There is only one row or col */
if (top) {
if (src->end.row <= src->start.row) {
return FALSE;
}
length = src->end.col - src->start.col + 1;
} else {
if (src->end.col <= src->start.col) {
return FALSE;
}
length = src->end.row - src->start.row + 1;
}
for (i = 0; i<length; i++) {
if (top) {
ca = sheet_cell_get (sheet, src->start.col + i,
src->start.row);
cb = sheet_cell_get (sheet, src->start.col + i,
src->start.row + 1);
} else {
ca = sheet_cell_get (sheet, src->start.col,
src->start.row + i);
cb = sheet_cell_get (sheet, src->start.col + 1,
src->start.row + i);
}
if (!ca || !cb) {
continue;
}
/* Look for value differences */
valuea = ca->value;
valueb = cb->value;
if (VALUE_IS_NUMBER (valuea)) {
if (!VALUE_IS_NUMBER (valueb)) {
return TRUE;
}
} else {
if (valuea->type != valueb->type) {
return TRUE;
}
}
/* Look for style differences */
stylea = cell_get_mstyle (ca);
styleb = cell_get_mstyle (cb);
if (!mstyle_equal (stylea, styleb)) {
return TRUE;
}
mstyle_unref (stylea);
mstyle_unref (styleb);
}
return FALSE;
}
void
range_dump (Range const *src)
{
......
......@@ -97,6 +97,8 @@ gboolean range_expand (Range *range,
int d_tlx, int d_tly,
int d_brx, int d_bry);
gboolean range_has_header (const Sheet *sheet, const Range *src,
gboolean top);
const char *range_name (const Range *src);
void range_dump (const Range *src);
Range *range_copy (const Range *src);
......
......@@ -49,7 +49,6 @@ sort_data_length (const SortData *data)
return data->range->end.col - data->range->start.col + 1;
}
/* The routines to do the sorting */
static int
sort_compare_cells (const Cell *ca, const Cell *cb, SortClause *clause)
......
......@@ -1061,6 +1061,10 @@ sort_cmd (Workbook *wb, int asc)
data->num_clause = numclause;
data->clauses = clause;
data->top = TRUE;
if (range_has_header (data->sheet, data->range, TRUE)) {
data->range->start.row += 1;
}
cmd_sort (workbook_command_context_gui (wb), data);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment