Commit 43166203 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

libgimpwidgets/gimpwidgets.def made range API public.

2005-06-27  Michael Natterer  <mitch@gimp.org>

	* libgimpwidgets/gimpwidgets.def
	* libgimpwidgets/gimppageselector.[ch]: made range API public.
parent 9a3f1679
2005-06-27 Michael Natterer <mitch@gimp.org>
* libgimpwidgets/gimpwidgets.def
* libgimpwidgets/gimppageselector.[ch]: made range API public.
2005-06-27 Michael Natterer <mitch@gimp.org>
* libgimpwidgets/gimppageselector.[ch]: added "Select All/None"
......
......@@ -75,6 +75,9 @@ static gboolean gimp_page_selector_range_focus_out (GtkEntry *entry,
GimpPageSelector *selector);
static void gimp_page_selector_range_activate (GtkEntry *entry,
GimpPageSelector *selector);
static void gimp_page_selector_print_range (GString *string,
gint start,
gint end);
static guint selector_signals[LAST_SIGNAL] = { 0 };
......@@ -551,31 +554,88 @@ gimp_page_selector_get_selected_pages (GimpPageSelector *selector,
return array;
}
void
gimp_page_selector_select_range (GimpPageSelector *selector,
const gchar *range_string)
{
gchar **ranges;
/* private functions */
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
static void
gimp_page_selector_print_range (GString *string,
gint start,
gint end)
{
if (string->len != 0)
g_string_append_c (string, ',');
if (! range_string)
range_string = "";
if (start == end)
g_string_append_printf (string, "%d", start + 1);
else
g_string_append_printf (string, "%d-%d", start + 1, end + 1);
g_signal_handlers_block_by_func (selector->view,
gimp_page_selector_selection_changed,
selector);
gimp_page_selector_unselect_all (selector);
ranges = g_strsplit (range_string, ",", -1);
if (ranges)
{
gint i;
for (i = 0; ranges[i] != NULL; i++)
{
gchar *range = g_strstrip (ranges[i]);
gchar *dash;
dash = strchr (range, '-');
if (dash)
{
gint page_from;
gint page_to;
if (sscanf (range, "%i", &page_from) == 1 &&
sscanf (dash + 1, "%i", &page_to) == 1 &&
page_from <= page_to &&
page_from <= selector->n_pages)
{
gint page_no;
page_from = MAX (page_from, 1) - 1;
page_to = MIN (page_to, selector->n_pages) - 1;
for (page_no = page_from; page_no <= page_to; page_no++)
gimp_page_selector_select_page (selector, page_no);
}
}
else
{
gint page_no;
if (sscanf (range, "%i", &page_no) == 1 &&
page_no >= 1 &&
page_no <= selector->n_pages)
{
gimp_page_selector_select_page (selector, page_no - 1);
}
}
}
g_strfreev (ranges);
}
g_signal_handlers_unblock_by_func (selector->view,
gimp_page_selector_selection_changed,
selector);
gimp_page_selector_selection_changed (GTK_ICON_VIEW (selector->view),
selector);
}
static void
gimp_page_selector_selection_changed (GtkIconView *icon_view,
GimpPageSelector *selector)
gchar *
gimp_page_selector_get_selected_range (GimpPageSelector *selector)
{
gint *pages;
gint n_pages;
GString *string;
g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), NULL);
string = g_string_new ("");
pages = gimp_page_selector_get_selected_pages (selector, &n_pages);
......@@ -610,8 +670,21 @@ gimp_page_selector_selection_changed (GtkIconView *icon_view,
g_free (pages);
}
gtk_entry_set_text (GTK_ENTRY (selector->range_entry),
g_string_free (string, FALSE));
return g_string_free (string, FALSE);
}
/* private functions */
static void
gimp_page_selector_selection_changed (GtkIconView *icon_view,
GimpPageSelector *selector)
{
gchar *range;
range = gimp_page_selector_get_selected_range (selector);
gtk_entry_set_text (GTK_ENTRY (selector->range_entry), range);
g_free (range);
gtk_editable_set_position (GTK_EDITABLE (selector->range_entry), -1);
g_signal_emit (selector, selector_signals[SELECTION_CHANGED], 0);
......@@ -631,69 +704,19 @@ static void
gimp_page_selector_range_activate (GtkEntry *entry,
GimpPageSelector *selector)
{
const gchar *text;
gchar **ranges;
g_signal_handlers_block_by_func (selector->view,
gimp_page_selector_selection_changed,
selector);
gimp_page_selector_unselect_all (selector);
text = gtk_entry_get_text (entry);
ranges = g_strsplit (text, ",", -1);
if (ranges)
{
gint i;
for (i = 0; ranges[i] != NULL; i++)
{
gchar *range = g_strstrip (ranges[i]);
gchar *dash;
dash = strchr (range, '-');
if (dash)
{
gint page_from;
gint page_to;
if (sscanf (range, "%i", &page_from) == 1 &&
sscanf (dash + 1, "%i", &page_to) == 1 &&
page_from <= page_to &&
page_from <= selector->n_pages)
{
gint page_no;
page_from = MAX (page_from, 1) - 1;
page_to = MIN (page_to, selector->n_pages) - 1;
for (page_no = page_from; page_no <= page_to; page_no++)
gimp_page_selector_select_page (selector, page_no);
}
}
else
{
gint page_no;
if (sscanf (range, "%i", &page_no) == 1 &&
page_no >= 1 &&
page_no <= selector->n_pages)
{
gimp_page_selector_select_page (selector, page_no - 1);
}
}
}
g_strfreev (ranges);
}
gimp_page_selector_select_range (selector, gtk_entry_get_text (entry));
}
g_signal_handlers_unblock_by_func (selector->view,
gimp_page_selector_selection_changed,
selector);
static void
gimp_page_selector_print_range (GString *string,
gint start,
gint end)
{
if (string->len != 0)
g_string_append_c (string, ',');
gimp_page_selector_selection_changed (GTK_ICON_VIEW (selector->view),
selector);
if (start == end)
g_string_append_printf (string, "%d", start + 1);
else
g_string_append_printf (string, "%d-%d", start + 1, end + 1);
}
......@@ -96,6 +96,11 @@ gboolean gimp_page_selector_page_is_selected (GimpPageSelector *selector,
gint * gimp_page_selector_get_selected_pages (GimpPageSelector *selector,
gint *n_selected_pages);
void gimp_page_selector_select_range (GimpPageSelector *selector,
const gchar *range);
gchar * gimp_page_selector_get_selected_range (GimpPageSelector *selector);
G_END_DECLS
#endif /* __GIMP_PAGE_SELECTOR_H__ */
......@@ -170,11 +170,13 @@ EXPORTS
gimp_page_selector_get_n_pages
gimp_page_selector_get_page_thumbnail
gimp_page_selector_get_selected_pages
gimp_page_selector_get_selected_range
gimp_page_selector_get_type
gimp_page_selector_new
gimp_page_selector_page_is_selected
gimp_page_selector_select_all
gimp_page_selector_select_page
gimp_page_selector_select_range
gimp_page_selector_set_n_pages
gimp_page_selector_set_page_thumbnail
gimp_page_selector_unselect_all
......
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