Skip to content

Commit

Permalink
More Fl_Input keyboard fixes / OS X transparency for RGBA data / some…
Browse files Browse the repository at this point in the history
… utf8 reorganisation

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6765 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Matthias Melcher committed Apr 15, 2009
1 parent b214cef commit d3206f0
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 107 deletions.
4 changes: 3 additions & 1 deletion CHANGES
@@ -1,6 +1,8 @@
CHANGES IN FLTK 1.3.0

- Added improved OS X cursor control to Fl_Input (STR #2169)
- Fixed fl_draw_image to obey the alpha channel, hoping that
this has no adverse effect on existing software (OS X only)
- Added OS X cursor control to Fl_Input (STR #2169)
- Fix for multiple popups, when dragging and calling fl_alert()
and friends from the callback (STR #2159)
- Avoiding crashes for recursive common dialogs (this does not
Expand Down
5 changes: 5 additions & 0 deletions FL/Fl.H
Expand Up @@ -1014,6 +1014,11 @@ public:

};

/** \defgroup fl_unicode Unicode and UTF-8 functions
fl global Unicode and UTF-8 ahndling functions
@{ */
/** @} */

#endif // !Fl_H

//
Expand Down
6 changes: 5 additions & 1 deletion FL/Fl_Input_.H
Expand Up @@ -145,7 +145,7 @@ public:
Same as value()[n], but may be faster in plausible
implementations. No bounds checking is done.
*/
char index(int i) const {return value_[i];}
char index(int i) const {return value_[i];}
/**
Returns the number of characters in value(). This
may be greater than strlen(value()) if there are nul
Expand Down Expand Up @@ -265,6 +265,10 @@ char index(int i) const {return value_[i];}
*/
void wrap(int b) { if (b) type((uchar)(type() | FL_INPUT_WRAP));
else type((uchar)(type() & ~FL_INPUT_WRAP)); }
/**
Return the number of lines displayed on a single page.
*/
int linesPerPage();
};

#endif
Expand Down
18 changes: 17 additions & 1 deletion FL/fl_utf8.h
Expand Up @@ -30,6 +30,11 @@

/*** NOTE : all functions are LIMITED to 24 bits Unicode values !!! ***/

/**
\file fl_utf8.h
\brief header for Unicode and UTF8 chracter handling
*/

#ifndef _HAVE_FL_UTF8_HDR_
#define _HAVE_FL_UTF8_HDR_

Expand Down Expand Up @@ -78,12 +83,20 @@
extern "C" {
# endif

/** \addtogroup fl_unicode
@{
*/

int fl_unichar_to_utf8_size(Fl_Unichar);

/* F2: comes from FLTK2 */
/* OD: comes from OksiD */

/* F2: How many bytes will be used to encode this wide character as UTF8? */
/**
Return the number of bytes needed to encode the given UCS4 character in UTF8.
\param [in] ucs UCS4 encoded character
\return number of bytes required
*/
FL_EXPORT int fl_utf8bytes(unsigned ucs);

/* OD: returns the byte length of the first UTF-8 char sequence (returns -1 if not valid) */
Expand Down Expand Up @@ -222,6 +235,9 @@ FL_EXPORT void fl_make_path_for_file( const char *path );
/* OD: recursively create a path in the file system */
FL_EXPORT char fl_make_path( const char *path );


/** @} */

/*****************************************************************************/

#ifdef __cplusplus
Expand Down
103 changes: 78 additions & 25 deletions src/Fl_Input.cxx
Expand Up @@ -146,10 +146,27 @@ int Fl_Input::handle_key() {
if (Fl::event_state() & FL_CTRL) ascii = ctrl('C');
else if (Fl::event_state() & FL_SHIFT) ascii = ctrl('V');
break;
case FL_Delete: // FIXME
if (Fl::event_state() & FL_SHIFT) ascii = ctrl('X');
else ascii = ctrl('D');
break;
case FL_Delete:
#ifdef __APPLE__
if (mods==0 || mods==FL_CTRL) { // delete next char
ascii = ctrl('D');
} else if (mods==FL_ALT) { // delete next word
if (mark() != position()) return cut();
cut(position(), word_end(position()));
return 1;
} else if (mods==FL_META) { // delete to the end of the line
if (mark() != position()) return cut();
cut(position(), line_end(position()));
return 1;
} else return 1;
#else
if (mods==0) {
ascii = ctrl('D');
} else if (mods==FL_SHIFT) {
ascii = ctrl('X');
} else return 1;
#endif
break;
case FL_Left:
#ifdef __APPLE__
if (mods==0) { // char left
Expand Down Expand Up @@ -190,18 +207,31 @@ int Fl_Input::handle_key() {
} else return 1;
#endif // __APPLE__
break;
case FL_Page_Up: // FIXME
fl_font(textfont(),textsize()); //ensure current font is set to ours
repeat_num=h()/fl_height(); // number of lines to scroll
if (!repeat_num) repeat_num=1;
case FL_Page_Up:
#ifdef __APPLE__
if (mods==0) { // scroll text one page
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
repeat_num = linesPerPage();
ascii = ctrl('P');
} else if (mods==FL_ALT) { // move cursor one page
repeat_num = linesPerPage();
ascii = ctrl('P');
} else return 1;
break;
#else
repeat_num = linesPerPage();
// fall through
#endif
case FL_Up:
#ifdef __APPLE__
if (mods==0) { // line up
ascii = ctrl('P');
} else if (mods==FL_CTRL) {
return 1; // FIXME scroll text down one page
// FIXME Fl_Inut_ does not support an independent scroll value
// (heck, it doesn't even support a scrollbar - what do you expect ;-)
} else if (mods==FL_CTRL) { // scroll text down one page
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
repeat_num = linesPerPage();
ascii = ctrl('P');
} else if (mods==FL_ALT) { // line start and up
if (line_start(position())==position() && position()>0)
return shift_position(line_start(position()-1)) + NORMAL_INPUT_MOVE;
Expand All @@ -214,21 +244,37 @@ int Fl_Input::handle_key() {
#else
if (mods==0) { // line up
ascii = ctrl('P');
} else if (mods==FL_CTRL) {
return 1; // FIXME scroll text down one line
} else if (mods==FL_CTRL) { // scroll text down one line
// Fl_Input has no scroll control, so instead we move the cursor by one page
ascii = ctrl('P');
} else return 1;
#endif
break;
case FL_Page_Down: // FIXME
fl_font(textfont(),textsize());
repeat_num=h()/fl_height();
if (!repeat_num) repeat_num=1;
case FL_Page_Down:
#ifdef __APPLE__
if (mods==0) { // scroll text one page
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
repeat_num = linesPerPage();
ascii = ctrl('N');
} else if (mods==FL_ALT) { // move cursor one page
repeat_num = linesPerPage();
ascii = ctrl('N');
} else return 1;
break;
#else
repeat_num = linesPerPage();
// fall through
#endif
case FL_Down:
#ifdef __APPLE__
if (mods==0) { // line down
ascii = ctrl('N');
} else if (mods==FL_CTRL) {
return 1; // FIXME scroll text up one page
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
repeat_num = linesPerPage();
ascii = ctrl('N');
} else if (mods==FL_ALT) { // line end and down
if (line_end(position())==position() && position()<size())
return shift_position(line_end(position()+1)) + NORMAL_INPUT_MOVE;
Expand All @@ -241,15 +287,19 @@ int Fl_Input::handle_key() {
#else
if (mods==0) { // line down
ascii = ctrl('N');
} else if (mods==FL_CTRL) {
return 1; // FIXME scroll text up one line
} else if (mods==FL_CTRL) { // scroll text up one line
// Fl_Input has no scroll control, so instead we move the cursor by one page
ascii = ctrl('N');
} else return 1;
#endif
break;
case FL_Home:
#ifdef __APPLE__
if (mods==0) {
return 1; // FIXME scroll display to the top
if (mods==0) { // scroll display to the top
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
shift_position(0);
return 1;
} else return 1;
#else
if (mods==0) {
Expand All @@ -262,8 +312,11 @@ int Fl_Input::handle_key() {
break;
case FL_End:
#ifdef __APPLE__
if (mods==0) {
return 1; // FIXME scroll display to the bottom
if (mods==0) { // scroll display to the bottom
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
shift_position(size());
return 1;
} else return 1;
#else
if (mods==0) {
Expand Down
10 changes: 10 additions & 0 deletions src/Fl_Input_.cxx
Expand Up @@ -1024,6 +1024,16 @@ Fl_Input_::~Fl_Input_() {
if (bufsize) free((void*)buffer);
}

int Fl_Input_::linesPerPage() {
int n = 1;
if (input_type() == FL_MULTILINE_INPUT) {
fl_font(textfont(),textsize()); //ensure current font is set to ours
n = h()/fl_height(); // number of lines to scroll
if (n<=0) n = 1;
}
return n;
}

//
// End of "$Id$".
//
27 changes: 3 additions & 24 deletions src/Fl_Text_Buffer.cxx
Expand Up @@ -83,27 +83,6 @@ static int undocut; // number of characters deleted there
static int undoinsert; // number of characters inserted
static int undoyankcut; // length of valid contents of buffer, even if undocut=0

static int utf_len(char c)
{
if (!(c & 0x80)) return 1;
if (c & 0x40) {
if (c & 0x20) {
if (c & 0x10) {
if (c & 0x08) {
if (c & 0x04) {
return 6;
}
return 5;
}
return 4;
}
return 3;
}
return 2;
}
return 0;
}

static void undobuffersize(int n) {
if (n > undobufferlength) {
if (undobuffer) {
Expand Down Expand Up @@ -991,7 +970,7 @@ int Fl_Text_Buffer::expand_character(int pos, int indent, char *outStr) {
mTabDist, mNullSubsChar);
if (ret > 1 && (c & 0x80)) {
int i;
i = utf_len(c);
i = fl_utf8len(c);
while (i > 1) {
i--;
pos++;
Expand Down Expand Up @@ -1040,7 +1019,7 @@ int Fl_Text_Buffer::expand_character(char c, int indent, char *outStr, int tabDi
return 0;
} else if (c & 0x80) {
*outStr = c;
return utf_len(c);
return fl_utf8len(c);
}

/* Otherwise, just return the character */
Expand Down Expand Up @@ -1068,7 +1047,7 @@ int Fl_Text_Buffer::character_width(char c, int indent, int tabDist, char nullSu
else if ((c & 0x80) && !(c & 0x40))
return 0;
else if (c & 0x80) {
return utf_len(c);
return fl_utf8len(c);
}
return 1;
}
Expand Down

0 comments on commit d3206f0

Please sign in to comment.