Author: matt
Date: 2012-07-24 12:50:22 -0700 (Tue, 24 Jul 2012)
New Revision: 9640
Log:
Fixed fltk3::strncasecmp etc.
Modified:
branches/branch-3.0/fluid/Fl_Group_Type.cxx
branches/branch-3.0/fluid/Fl_Widget_Type.cxx
branches/branch-3.0/fluid/fluid.cxx
branches/branch-3.0/include/FL/fl_utf8.h
branches/branch-3.0/include/fltk3/utf8.h
branches/branch-3.0/src/fltk3/Preferences.cxx
branches/branch-3.0/src/fltk3/utf.cxx
branches/branch-3.0/src/fltk3/utf8.cxx
branches/branch-3.0/test/utf8.cxx
Modified: branches/branch-3.0/fluid/Fl_Group_Type.cxx
===================================================================
--- branches/branch-3.0/fluid/Fl_Group_Type.cxx 2012-07-24 19:49:37 UTC (rev
9639)
+++ branches/branch-3.0/fluid/Fl_Group_Type.cxx 2012-07-24 19:50:22 UTC (rev
9640)
@@ -105,7 +105,15 @@
}
extern int force_parent;
+extern int gridx;
+
+/*
+ User must select one or more widgets.
+ A group is created. The group is large enough to contain all widgets. If ALT
+ is held down while grouping, the group is expanded by a single grid spacing.
+ All widgets are moved into the group. All coordinates are updated.
+ */
void group_cb(fltk3::Widget *, void *) {
// Find the current widget:
Fl_Type *qq = Fl_Type::current;
@@ -117,18 +125,36 @@
Fl_Widget_Type* q = (Fl_Widget_Type*)qq;
force_parent = 1;
Fl_Group_Type *n = (Fl_Group_Type*)(Fl_Group_type.make());
+ Fl_Type *t;
n->move_before(q);
- n->o->resize(q->o->x(),q->o->y(),q->o->w(),q->o->h());
- for (Fl_Type *t = Fl_Type::first; t;) {
+ fltk3::Rectangle bounds(*q->o);
+ for (t = Fl_Type::first; t;) {
+ if (t->level == n->level && t != n && t->selected && t->is_widget())
+ bounds.merge(*((Fl_Widget_Type*)t)->o);
+ t = t->next;
+ }
+ if (fltk3::event_alt()) bounds.inset(-gridx);
+ n->o->resize(bounds.x(), bounds.y(), bounds.w(), bounds.h());
+ for (t = Fl_Type::first; t;) {
if (t->level != n->level || t == n || !t->selected) {
t = t->next; continue;}
Fl_Type *nxt = t->remove();
t->add(n);
+ if (t->is_widget()) {
+ Fl_Widget_Type *w = (Fl_Widget_Type*)t;
+ w->o->move(-bounds.x(), -bounds.y());
+ }
t = nxt;
}
fix_group_size(n);
}
+
+/*
+ User must select all items in a group.
+ All items are moved outside of the group. The coordinates are fixed so that
the
+ widgets stay in the same place. At last, the group itself is removed.
+ */
void ungroup_cb(fltk3::Widget *, void *) {
// Find the group:
Fl_Type *q = Fl_Type::current;
@@ -148,6 +174,11 @@
for (n = q->next; n && n->level > q->level;) {
Fl_Type *nxt = n->remove();
n->insert(q);
+ if (n->is_widget()) {
+ Fl_Widget_Type *w = (Fl_Widget_Type*)n;
+ Fl_Widget_Type *p = (Fl_Widget_Type*)q;
+ w->o->move(p->o->x(), p->o->y());
+ }
n = nxt;
}
delete q;
Modified: branches/branch-3.0/fluid/Fl_Widget_Type.cxx
===================================================================
--- branches/branch-3.0/fluid/Fl_Widget_Type.cxx 2012-07-24 19:49:37 UTC
(rev 9639)
+++ branches/branch-3.0/fluid/Fl_Widget_Type.cxx 2012-07-24 19:50:22 UTC
(rev 9640)
@@ -26,6 +26,7 @@
//
#include <fltk3/run.h>
+#include <fltk3/utf8.h>
#include <fltk3/Group.h>
#include <fltk3/Table.h>
#include <fltk3/Input.h>
@@ -271,18 +272,32 @@
// the recursive part sorts all children, returns pointer to next:
Fl_Type *sort(Fl_Type *parent) {
- Fl_Type *f,*n=0;
+ Fl_Type *f, *n=0;
for (f = parent ? parent->next : Fl_Type::first; ; f = n) {
if (!f || (parent && f->level <= parent->level)) return f;
n = sort(f);
- if (!f->selected || (!f->is_widget() || f->is_menu_item())) continue;
- fltk3::Widget* fw = ((Fl_Widget_Type*)f)->o;
+ if (!f->selected) continue;
Fl_Type *g; // we will insert before this
- for (g = parent->next; g != f; g = g->next) {
- if (!g->selected || g->level > f->level) continue;
- fltk3::Widget* gw = ((Fl_Widget_Type*)g)->o;
- if (gw->y() > fw->y()) break;
- if (gw->y() == fw->y() && gw->x() > fw->x()) break;
+ // sort widgets by position, so we get a decent Tab navigation
+ if (f->is_widget() && !f->is_menu_item()) {
+ fltk3::Widget* fw = ((Fl_Widget_Type*)f)->o;
+ for (g = parent->next; g != f; g = g->next) {
+ if (!g->selected || g->level > f->level) continue;
+ fltk3::Widget* gw = ((Fl_Widget_Type*)g)->o;
+ if (gw->y() > fw->y()) break;
+ if (gw->y() == fw->y() && gw->x() > fw->x()) break;
+ }
+ } else if (f->is_tool()) {
+ // sort tools by name
+ Fl_Tool_Type* ft = ((Fl_Tool_Type*)f);
+ for (g = parent->next; g != f; g = g->next) {
+ if (!g->selected || g->level > f->level) continue;
+ if (fltk3::event_alt()) {
+ if (fltk3::strcasecmp(g->name(), ft->name())>0) break;
+ } else {
+ if (fltk3::strcmp(g->name(), ft->name())>0) break;
+ }
+ }
}
if (g != f) f->move_before(g);
}
Modified: branches/branch-3.0/fluid/fluid.cxx
===================================================================
--- branches/branch-3.0/fluid/fluid.cxx 2012-07-24 19:49:37 UTC (rev 9639)
+++ branches/branch-3.0/fluid/fluid.cxx 2012-07-24 19:50:22 UTC (rev 9640)
@@ -1053,7 +1053,7 @@
if (completion_button->value()) {
fltk3::message("Wrote all slected build environemtes.");
}
- // FIXME: allow for compiel-only. See below.
+ // FIXME: allow for compile-only. See below.
/*
if (compile_only) {
if (!x) {fprintf(stderr,"%s : %s\n",cname,strerror(errno)); exit(1);}
@@ -1430,9 +1430,9 @@
for (i = 0; i < max_files; i ++)
#if defined(WIN32) || defined(__APPLE__)
- if (!strcasecmp(absolute, absolute_history[i])) break;
+ if (!fltk3::strcasecmp(absolute, absolute_history[i])) break;
#else
- if (!strcmp(absolute, absolute_history[i])) break;
+ if (!fltk3::strcmp(absolute, absolute_history[i])) break;
#endif // WIN32 || __APPLE__
if (i == 0) return;
Modified: branches/branch-3.0/include/FL/fl_utf8.h
===================================================================
--- branches/branch-3.0/include/FL/fl_utf8.h 2012-07-24 19:49:37 UTC (rev
9639)
+++ branches/branch-3.0/include/FL/fl_utf8.h 2012-07-24 19:50:22 UTC (rev
9640)
@@ -126,11 +126,11 @@
}
inline int fl_utf_strncasecmp(const char *s1, const char *s2, int n) {
- return fltk3::utf_strncasecmp(s1, s2, n);
+ return fltk3::strncasecmp(s1, s2, n);
}
inline int fl_utf_strcasecmp(const char *s1, const char *s2) {
- return fltk3::utf_strcasecmp(s1, s2);
+ return fltk3::strcasecmp(s1, s2);
}
inline int fl_tolower(unsigned int ucs) {
@@ -142,11 +142,11 @@
}
inline int fl_utf_tolower(const unsigned char *str, int len, char *buf) {
- return fltk3::utf_tolower(str, len, buf);
+ return fltk3::tolower(str, len, buf);
}
inline int fl_utf_toupper(const unsigned char *str, int len, char *buf) {
- return fltk3::utf_toupper(str, len, buf);
+ return fltk3::toupper(str, len, buf);
}
inline int fl_chmod(const char* f, int mode) {
Modified: branches/branch-3.0/include/fltk3/utf8.h
===================================================================
--- branches/branch-3.0/include/fltk3/utf8.h 2012-07-24 19:49:37 UTC (rev
9639)
+++ branches/branch-3.0/include/fltk3/utf8.h 2012-07-24 19:50:22 UTC (rev
9640)
@@ -187,11 +187,17 @@
*/
/* OD: UTF8 aware strncasecmp - converts to lower case Unicode and tests */
- FLTK3_EXPORT int utf_strncasecmp(const char *s1, const char *s2, int n);
+ FLTK3_EXPORT int strncasecmp(const char *s1, const char *s2, int n);
/* OD: UTF8 aware strcasecmp - converts to Unicode and tests */
- FLTK3_EXPORT int utf_strcasecmp(const char *s1, const char *s2);
+ FLTK3_EXPORT int strcasecmp(const char *s1, const char *s2);
+ /* OD: UTF8 aware strncmp */
+ FLTK3_EXPORT int strncmp(const char *s1, const char *s2, int n);
+
+ /* OD: UTF8 aware strcmp */
+ FLTK3_EXPORT int strcmp(const char *s1, const char *s2);
+
/* OD: return the Unicode lower case value of ucs */
FLTK3_EXPORT int tolower(unsigned int ucs);
@@ -199,10 +205,10 @@
FLTK3_EXPORT int toupper(unsigned int ucs);
/* OD: converts the UTF8 string to the lower case equivalent */
- FLTK3_EXPORT int utf_tolower(const unsigned char *str, int len, char *buf);
+ FLTK3_EXPORT int tolower(const unsigned char *str, int len, char *buf);
/* OD: converts the UTF8 string to the upper case equivalent */
- FLTK3_EXPORT int utf_toupper(const unsigned char *str, int len, char *buf);
+ FLTK3_EXPORT int toupper(const unsigned char *str, int len, char *buf);
/* OD: Portable UTF8 aware chmod wrapper */
FLTK3_EXPORT int chmod(const char* f, int mode);
Modified: branches/branch-3.0/src/fltk3/Preferences.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Preferences.cxx 2012-07-24 19:49:37 UTC
(rev 9639)
+++ branches/branch-3.0/src/fltk3/Preferences.cxx 2012-07-24 19:50:22 UTC
(rev 9640)
@@ -1465,7 +1465,7 @@
// - if the node was not found, 'find' will create the required branch
fltk3::Preferences::Node *fltk3::Preferences::Node::find( const char *path ) {
int len = (int)strlen( path_ );
- if ( strncmp( path, path_, len ) == 0 ) {
+ if ( ::strncmp( path, path_, len ) == 0 ) {
if ( path[ len ] == 0 )
return this;
if ( path[ len ] == '/' ) {
Modified: branches/branch-3.0/src/fltk3/utf.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/utf.cxx 2012-07-24 19:49:37 UTC (rev
9639)
+++ branches/branch-3.0/src/fltk3/utf.cxx 2012-07-24 19:50:22 UTC (rev
9640)
@@ -112,7 +112,7 @@
(adding \e len to \e p will point at the next character).
If \p p points at an illegal UTF-8 encoding, including one that
- would go past \e end, or where a code is uses more bytes than
+ would go past \e end, or where a code uses more bytes than
necessary, then *(unsigned char*)p is translated as though it is
in the Microsoft CP1252 character set and \e len is set to 1.
Treating errors this way allows this to decode almost any
Modified: branches/branch-3.0/src/fltk3/utf8.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/utf8.cxx 2012-07-24 19:49:37 UTC (rev
9639)
+++ branches/branch-3.0/src/fltk3/utf8.cxx 2012-07-24 19:50:22 UTC (rev
9640)
@@ -186,82 +186,92 @@
return nbc;
}
-/*
- * compare only the first n bytes
- * return 0 if the strings are equal;
- * return 1 if s1 is greater than s2
- * return -1 if s1 is less than s2
- */
+
/**
UTF-8 aware strncasecmp - converts to lower case Unicode and tests.
-
- \todo Correct the incorrect logic where length of strings tested
- \todo Clarify whether n means number of bytes, or characters.
+
+ \param s1, s2 the utf8 strings to compare
+ \param n the maximum number of utf8 characters to compare
+ \return 0 if the strings are equal
+ \return >0 if s1 is greater than s2
+ \return <0 if s1 is less than s2
*/
-int fltk3::utf_strncasecmp(const char *s1, const char *s2, int n)
+int fltk3::strncasecmp(const char *s1, const char *s2, int n)
{
int i;
- int s1_l;
- int s2_l;
- char *e1, *e2; // string end pointers
-
- s1_l = 0;
- while (s1_l < n && s1[s1_l]) s1_l++;
- s2_l = 0;
- while (s2_l < n && s2[s2_l]) s2_l++;
-
- if (s1_l < s2_l) {
- return -1;
- } else if (s1_l > s2_l) {
- return 1;
- }
- e1 = (char *)&s1[s1_l]; // last char to test
- e2 = (char *)&s2[s2_l];
- for (i = 0; i < n;) {
+ for (i = 0; i < n; i++) {
int l1, l2;
unsigned int u1, u2;
- int res;
+
+ if (*s1==0 && *s2==0) return 0; // all compared equal, return 0
- // l1 = fl_utf2ucs((unsigned char*)s1 + i, n - i, &u1);
- u1 = fltk3::utf8decode(s1 + i, e1, &l1);
- // l2 = fl_utf2ucs((unsigned char*)s2 + i, n - i, &u2);
- u2 = fltk3::utf8decode(s2 + i, e2, &l2);
- if (l1 - l2 != 0) return l1 - l2;
- res = XUtf8Tolower(u1) - XUtf8Tolower(u2);
- if (res != 0) return res;
- if (l1 < 1) {
- i += 1;
- } else {
- i += l1;
- }
+ u1 = fltk3::utf8decode(s1, 0, &l1); // u1 or u2 can be NUL
+ u2 = fltk3::utf8decode(s2, 0, &l2);
+ int res = XUtf8Tolower(u1) - XUtf8Tolower(u2);
+ if (res) return res;
+ s1 += l1;
+ s2 += l2;
}
return 0;
}
-/*
- * return 0 if the strings are equal;
- * return 1 if s1 is greater than s2
- * return -1 if s1 is less than s2
- */
+
/**
UTF-8 aware strcasecmp - converts to Unicode and tests.
- \todo Correct the incorrect logic where length of strings tested
+ \return 0 if the strings are equal
+ \return 1 if s1 is greater than s2
+ \return -1 if s1 is less than s2
*/
-int fltk3::utf_strcasecmp(const char *s1, const char *s2)
+int fltk3::strcasecmp(const char *s1, const char *s2)
{
- int s1_l = (int)strlen(s1);
- int s2_l = (int)strlen(s2);
-
- if (s1_l < s2_l) {
- return -1;
- } else if (s1_l > s2_l) {
- return 1;
+ return fltk3::strncasecmp(s1, s2, 0x7fffffff);
+}
+
+
+/**
+ UTF-8 aware strncmp - converts to lower case Unicode and tests.
+
+ \param s1, s2 the utf8 strings to compare
+ \param n the maximum number of utf8 characters to compare
+ \return 0 if the strings are equal
+ \return >0 if s1 is greater than s2
+ \return <0 if s1 is less than s2
+ */
+int fltk3::strncmp(const char *s1, const char *s2, int n)
+{
+ int i;
+ for (i = 0; i < n; i++) {
+ int l1, l2;
+ unsigned int u1, u2;
+
+ if (*s1==0 && *s2==0) return 0; // all compared equal, return 0
+
+ u1 = fltk3::utf8decode(s1, 0, &l1); // u1 or u2 can be NUL
+ u2 = fltk3::utf8decode(s2, 0, &l2);
+ int res = u1 - u2;
+ if (res) return res;
+ s1 += l1;
+ s2 += l2;
}
- return fltk3::utf_strncasecmp(s1, s2, s1_l);
+ return 0;
}
+
/**
+ UTF-8 aware strcmp - converts to Unicode and tests.
+
+ \return 0 if the strings are equal
+ \return 1 if s1 is greater than s2
+ \return -1 if s1 is less than s2
+ */
+int fltk3::strcmp(const char *s1, const char *s2)
+{
+ return fltk3::strncmp(s1, s2, 0x7fffffff);
+}
+
+
+/**
return the Unicode lower case value of \p ucs
*/
int fltk3::tolower(unsigned int ucs)
@@ -281,7 +291,7 @@
converts the str string to the lower case equivalent into buf.
Warning: to be safe buf length must be at least 3 * len [for 16-bit Unicode]
*/
-int fltk3::utf_tolower(const unsigned char *str, int len, char *buf)
+int fltk3::tolower(const unsigned char *str, int len, char *buf)
{
int i;
int l = 0;
@@ -312,7 +322,7 @@
converts the str string to the upper case equivalent into buf.
Warning: to be safe buf length must be at least 3 * len [for 16-bit Unicode]
*/
-int fltk3::utf_toupper(const unsigned char *str, int len, char *buf)
+int fltk3::toupper(const unsigned char *str, int len, char *buf)
{
int i;
int l = 0;
Modified: branches/branch-3.0/test/utf8.cxx
===================================================================
--- branches/branch-3.0/test/utf8.cxx 2012-07-24 19:49:37 UTC (rev 9639)
+++ branches/branch-3.0/test/utf8.cxx 2012-07-24 19:50:22 UTC (rev 9640)
@@ -643,13 +643,13 @@
char *utf8l = (char*) malloc(strlen(utf8) * 3 + 1);
fltk3::Input i2(5, 35, 190, 25);
- l = fltk3::utf_tolower((const unsigned char*)utf8, l, utf8l);
+ l = fltk3::tolower((const unsigned char*)utf8, l, utf8l);
utf8l[l] = '\0';
i2.value(utf8l);
char *utf8u = (char*) malloc(strlen(utf8l) * 3 + 1);
fltk3::Input i3(5, 65, 190, 25);
- l = fltk3::utf_toupper((const unsigned char*)utf8l, l, utf8u);
+ l = fltk3::toupper((const unsigned char*)utf8l, l, utf8u);
utf8u[l] = '\0';
i3.value(utf8u);
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit