summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Fl.cxx78
-rw-r--r--src/Fl_BMP_Image.cxx6
-rw-r--r--src/Fl_Browser.cxx13
-rw-r--r--src/Fl_Button.cxx22
-rw-r--r--src/Fl_Color_Chooser.cxx29
-rw-r--r--src/Fl_File_Chooser2.cxx5
-rw-r--r--src/Fl_Group.cxx27
-rw-r--r--src/Fl_Help_View.cxx6
-rw-r--r--src/Fl_Input.cxx58
-rw-r--r--src/Fl_Input_.cxx6
-rw-r--r--src/Fl_JPEG_Image.cxx7
-rw-r--r--src/Fl_Menu.cxx12
-rw-r--r--src/Fl_Menu_add.cxx54
-rw-r--r--src/Fl_PNM_Image.cxx6
-rw-r--r--src/Fl_PostScript.cxx46
-rw-r--r--src/Fl_Preferences.cxx24
-rw-r--r--src/Fl_Scroll.cxx10
-rw-r--r--src/Fl_Shared_Image.cxx6
-rw-r--r--src/Fl_Table.cxx62
-rw-r--r--src/Fl_Tabs.cxx36
-rw-r--r--src/Fl_Text_Buffer.cxx1704
-rw-r--r--src/Fl_Text_Display.cxx3197
-rw-r--r--src/Fl_Text_Editor.cxx8
-rw-r--r--src/Fl_Tile.cxx12
-rw-r--r--src/Fl_Tree.cxx7
-rw-r--r--src/Fl_XPM_Image.cxx6
-rw-r--r--src/Fl_arg.cxx227
-rw-r--r--src/Fl_cocoa.mm322
-rw-r--r--src/Fl_compose.cxx71
-rw-r--r--src/Fl_lock.cxx14
-rw-r--r--src/Fl_x.cxx22
-rw-r--r--src/filename_absolute.cxx5
-rw-r--r--src/fl_boxtype.cxx20
-rw-r--r--src/fl_color.cxx23
-rw-r--r--src/fl_draw.cxx11
-rw-r--r--src/fl_draw_pixmap.cxx6
-rw-r--r--src/fl_font_xft.cxx27
-rw-r--r--src/fl_plastic.cxx64
-rw-r--r--src/fl_rect.cxx12
-rw-r--r--src/fl_set_fonts_xft.cxx6
-rw-r--r--src/fl_utf8.cxx6
-rw-r--r--src/forms_compatability.cxx6
-rw-r--r--src/gl_draw.cxx8
-rw-r--r--src/print_panel.cxx6
-rw-r--r--src/ps_image.cxx10
45 files changed, 2667 insertions, 3646 deletions
diff --git a/src/Fl.cxx b/src/Fl.cxx
index fbc4167..66813b9 100644
--- a/src/Fl.cxx
+++ b/src/Fl.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl.cxx 7706 2010-09-27 14:57:53Z AlbrechtS $"
+// "$Id: Fl.cxx 7789 2010-10-31 22:39:40Z matt $"
//
// Main event handling code for the Fast Light Tool Kit (FLTK).
//
@@ -85,6 +85,10 @@ int Fl::e_length;
int Fl::visible_focus_ = 1,
Fl::dnd_text_ops_ = 1;
+unsigned char Fl::options_[] = { 0, 0 };
+unsigned char Fl::options_read_ = 0;
+
+
Fl_Window *fl_xfocus; // which window X thinks has focus
Fl_Window *fl_xmousewin;// which window X thinks has FL_ENTER
Fl_Window *Fl::grab_; // most recent Fl::grab()
@@ -986,7 +990,7 @@ int Fl::handle(int e, Fl_Window* window)
switch (e) {
case FL_CLOSE:
- if (grab() || modal() && window != modal()) return 0;
+ if ( grab() || (modal() && window != modal()) ) return 0;
wi->do_callback();
return 1;
@@ -1414,16 +1418,36 @@ void Fl_Widget::redraw_label() {
W += 5; // Add a little to the size of the label to cover overflow
H += 5;
- if (align() & FL_ALIGN_BOTTOM) {
- window()->damage(FL_DAMAGE_EXPOSE, x(), y() + h(), w(), H);
- } else if (align() & FL_ALIGN_TOP) {
- window()->damage(FL_DAMAGE_EXPOSE, x(), y() - H, w(), H);
- } else if (align() & FL_ALIGN_LEFT) {
- window()->damage(FL_DAMAGE_EXPOSE, x() - W, y(), W, h());
- } else if (align() & FL_ALIGN_RIGHT) {
- window()->damage(FL_DAMAGE_EXPOSE, x() + w(), y(), W, h());
- } else {
- window()->damage(FL_DAMAGE_ALL);
+ // FIXME:
+ // This assumes the measure() returns the correct outline, which it does
+ // not in all possible cases of alignment combinedwith image and symbols.
+ switch (align() & 0x0f) {
+ case FL_ALIGN_TOP_LEFT:
+ window()->damage(FL_DAMAGE_EXPOSE, x(), y()-H, W, H); break;
+ case FL_ALIGN_TOP:
+ window()->damage(FL_DAMAGE_EXPOSE, x()+(w()-W)/2, y()-H, W, H); break;
+ case FL_ALIGN_TOP_RIGHT:
+ window()->damage(FL_DAMAGE_EXPOSE, x()+w()-W, y()-H, W, H); break;
+ case FL_ALIGN_LEFT_TOP:
+ window()->damage(FL_DAMAGE_EXPOSE, x()-W, y(), W, H); break;
+ case FL_ALIGN_RIGHT_TOP:
+ window()->damage(FL_DAMAGE_EXPOSE, x()+w(), y(), W, H); break;
+ case FL_ALIGN_LEFT:
+ window()->damage(FL_DAMAGE_EXPOSE, x()-W, y()+(h()-H)/2, W, H); break;
+ case FL_ALIGN_RIGHT:
+ window()->damage(FL_DAMAGE_EXPOSE, x()+w(), y()+(h()-H)/2, W, H); break;
+ case FL_ALIGN_LEFT_BOTTOM:
+ window()->damage(FL_DAMAGE_EXPOSE, x()-W, y()+h()-H, W, H); break;
+ case FL_ALIGN_RIGHT_BOTTOM:
+ window()->damage(FL_DAMAGE_EXPOSE, x()+w(), y()+h()-H, W, H); break;
+ case FL_ALIGN_BOTTOM_LEFT:
+ window()->damage(FL_DAMAGE_EXPOSE, x(), y()+h(), W, H); break;
+ case FL_ALIGN_BOTTOM:
+ window()->damage(FL_DAMAGE_EXPOSE, x()+(w()-W)/2, y()+h(), W, H); break;
+ case FL_ALIGN_BOTTOM_RIGHT:
+ window()->damage(FL_DAMAGE_EXPOSE, x()+w()-W, y()+h(), W, H); break;
+ default:
+ window()->damage(FL_DAMAGE_ALL); break;
}
} else {
// The label is inside the widget, so just redraw the widget itself...
@@ -1714,6 +1738,33 @@ void Fl::clear_widget_pointer(Fl_Widget const *w)
}
}
+
+bool Fl::option(Fl_Option o)
+{
+ if (!options_read_) {
+ int tmp;
+ { // first, read the system wide preferences
+ Fl_Preferences prefs(Fl_Preferences::SYSTEM, "fltk.org", "fltk");
+ Fl_Preferences opt(prefs, "options");
+ prefs.get("ArrowFocus", tmp, 0); options_[OPTION_ARROW_FOCUS] = tmp;
+ prefs.get("NativeFilechooser", tmp, 0); options_[OPTION_NATIVE_FILECHOOSER] = tmp;
+ }
+ { // next, check the user preferences
+ Fl_Preferences prefs(Fl_Preferences::USER, "fltk.org", "fltk");
+ Fl_Preferences opt(prefs, "options");
+ prefs.get("ArrowFocus", tmp, 0); options_[OPTION_ARROW_FOCUS] = tmp;
+ prefs.get("NativeFilechooser", tmp, 0); options_[OPTION_NATIVE_FILECHOOSER] = tmp;
+ }
+ { // now, if the developer has registered this app, we could as for per-application preferences
+ }
+ options_read_ = 1;
+ }
+ if (o<0 || o>=OPTION_LAST)
+ return false;
+ return (bool)options_[o];
+}
+
+
// Helper class Fl_Widget_Tracker
/**
@@ -1733,6 +1784,7 @@ Fl_Widget_Tracker::~Fl_Widget_Tracker() {
Fl::release_widget_pointer(wp_); // remove pointer from watch list
}
+
//
-// End of "$Id: Fl.cxx 7706 2010-09-27 14:57:53Z AlbrechtS $".
+// End of "$Id: Fl.cxx 7789 2010-10-31 22:39:40Z matt $".
//
diff --git a/src/Fl_BMP_Image.cxx b/src/Fl_BMP_Image.cxx
index 1ba63f7..14bb542 100644
--- a/src/Fl_BMP_Image.cxx
+++ b/src/Fl_BMP_Image.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_BMP_Image.cxx 6616 2009-01-01 21:28:26Z matt $"
+// "$Id: Fl_BMP_Image.cxx 7767 2010-10-28 21:47:01Z matt $"
//
// Fl_BMP_Image routines.
//
@@ -177,7 +177,7 @@ Fl_BMP_Image::Fl_BMP_Image(const char *bmp) // I - File to read
for (repcount = 0; repcount < colors_used; repcount ++) {
// Read BGR color...
- fread(colormap[repcount], 1, 3, fp);
+ if (fread(colormap[repcount], 1, 3, fp)==0) { /* ignore */ }
// Skip pad byte for new BMP files...
if (info_size > 12) getc(fp);
@@ -490,5 +490,5 @@ read_long(FILE *fp) { // I - File to read from
//
-// End of "$Id: Fl_BMP_Image.cxx 6616 2009-01-01 21:28:26Z matt $".
+// End of "$Id: Fl_BMP_Image.cxx 7767 2010-10-28 21:47:01Z matt $".
//
diff --git a/src/Fl_Browser.cxx b/src/Fl_Browser.cxx
index 0db0092..71eb4b3 100644
--- a/src/Fl_Browser.cxx
+++ b/src/Fl_Browser.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Browser.cxx 6895 2009-09-21 06:35:08Z greg.ercolano $"
+// "$Id: Fl_Browser.cxx 7765 2010-10-28 18:02:20Z matt $"
//
// Browser widget for the Fast Light Tool Kit (FLTK).
//
@@ -375,6 +375,7 @@ int Fl_Browser::item_height(void *item) const {
if (hh > hmax) hmax = hh;
} else {
const int* i = column_widths();
+ long int dummy;
// do each column separately as they may all set different fonts:
for (char* str = l->txt; str && *str; str++) {
Fl_Font font = textfont(); // default font
@@ -389,7 +390,7 @@ int Fl_Browser::item_height(void *item) const {
case 'i': font = (Fl_Font)(font|FL_ITALIC); break;
case 'f': case 't': font = FL_COURIER; break;
case 'B':
- case 'C': strtol(str, &str, 10); break;// skip a color number
+ case 'C': dummy = strtol(str, &str, 10); break;// skip a color number
case 'F': font = (Fl_Font)strtol(str,&str,10); break;
case 'S': tsize = strtol(str,&str,10); break;
case 0: case '@': str--;
@@ -442,6 +443,7 @@ int Fl_Browser::item_width(void *item) const {
int done = 0;
while (*str == format_char_ && str[1] && str[1] != format_char_) {
+ long int dummy;
str ++;
switch (*str++) {
case 'l': case 'L': tsize = 24; break;
@@ -451,7 +453,7 @@ int Fl_Browser::item_width(void *item) const {
case 'i': font = (Fl_Font)(font|FL_ITALIC); break;
case 'f': case 't': font = FL_COURIER; break;
case 'B':
- case 'C': strtol(str, &str, 10); break;// skip a color number
+ case 'C': dummy = strtol(str, &str, 10); break;// skip a color number
case 'F': font = (Fl_Font)strtol(str, &str, 10); break;
case 'S': tsize = strtol(str, &str, 10); break;
case '.':
@@ -536,6 +538,7 @@ void Fl_Browser::item_draw(void* item, int X, int Y, int W, int H) const {
//#warning FIXME This maybe needs to be more UTF8 aware now...?
//#endif /*__GNUC__*/
while (*str == format_char() && *++str && *str != format_char()) {
+ long int dummy;
switch (*str++) {
case 'l': case 'L': tsize = 24; break;
case 'm': case 'M': tsize = 18; break;
@@ -549,7 +552,7 @@ void Fl_Browser::item_draw(void* item, int X, int Y, int W, int H) const {
if (!(l->flags & SELECTED)) {
fl_color((Fl_Color)strtol(str, &str, 10));
fl_rectf(X, Y, w1, H);
- } else strtol(str, &str, 10);
+ } else dummy = strtol(str, &str, 10);
break;
case 'C':
lcol = (Fl_Color)strtol(str, &str, 10);
@@ -912,5 +915,5 @@ void Fl_Browser::remove_icon(int line) {
}
//
-// End of "$Id: Fl_Browser.cxx 6895 2009-09-21 06:35:08Z greg.ercolano $".
+// End of "$Id: Fl_Browser.cxx 7765 2010-10-28 18:02:20Z matt $".
//
diff --git a/src/Fl_Button.cxx b/src/Fl_Button.cxx
index 391f931..d52271c 100644
--- a/src/Fl_Button.cxx
+++ b/src/Fl_Button.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Button.cxx 7476 2010-04-09 22:18:05Z matt $"
+// "$Id: Fl_Button.cxx 7774 2010-10-30 16:50:44Z matt $"
//
// Button widget for the Fast Light Tool Kit (FLTK).
//
@@ -128,22 +128,9 @@ int Fl_Button::handle(int event) {
return 1;
case FL_SHORTCUT:
if (!(shortcut() ?
- Fl::test_shortcut(shortcut()) : test_shortcut())) return 0;
-
+ Fl::test_shortcut(shortcut()) : test_shortcut())) return 0;
if (Fl::visible_focus() && handle(FL_FOCUS)) Fl::focus(this);
-
- if (type() == FL_RADIO_BUTTON && !value_) {
- setonly();
- set_changed();
- if (when() & (FL_WHEN_CHANGED|FL_WHEN_RELEASE) )
- do_callback();
- } else if (type() == FL_TOGGLE_BUTTON) {
- value(!value());
- set_changed();
- if (when() & (FL_WHEN_CHANGED|FL_WHEN_RELEASE))
- do_callback();
- } else if (when() & FL_WHEN_RELEASE) do_callback();
- return 1;
+ goto triggered_by_keyboard;
case FL_FOCUS : /* FALLTHROUGH */
case FL_UNFOCUS :
if (Fl::visible_focus()) {
@@ -161,6 +148,7 @@ int Fl_Button::handle(int event) {
if (Fl::focus() == this && Fl::event_key() == ' ' &&
!(Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT | FL_META))) {
set_changed();
+ triggered_by_keyboard:
Fl_Widget_Tracker wp(this);
if (type() == FL_RADIO_BUTTON && !value_) {
setonly();
@@ -193,5 +181,5 @@ Fl_Button::Fl_Button(int X, int Y, int W, int H, const char *L)
}
//
-// End of "$Id: Fl_Button.cxx 7476 2010-04-09 22:18:05Z matt $".
+// End of "$Id: Fl_Button.cxx 7774 2010-10-30 16:50:44Z matt $".
//
diff --git a/src/Fl_Color_Chooser.cxx b/src/Fl_Color_Chooser.cxx
index eb88f8d..c207ab7 100644
--- a/src/Fl_Color_Chooser.cxx
+++ b/src/Fl_Color_Chooser.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Color_Chooser.cxx 7347 2010-03-27 16:35:14Z AlbrechtS $"
+// "$Id: Fl_Color_Chooser.cxx 7790 2010-11-01 00:29:08Z greg.ercolano $"
//
// Color chooser for the Fast Light Tool Kit (FLTK).
//
@@ -455,6 +455,13 @@ void Fl_Color_Chooser::mode_cb(Fl_Widget* o, void*) {
c->set_valuators();
}
+void Fl_Color_Chooser::mode(int newMode)
+{
+ choice.value(newMode);
+ choice.do_callback();
+}
+
+
////////////////////////////////////////////////////////////////
/**
@@ -555,13 +562,14 @@ static void cc_cancel_cb (Fl_Widget *o, void *p) {
\brief Pops up a window to let the user pick an arbitrary RGB color.
\image html fl_color_chooser.jpg
\image latex fl_color_chooser.eps "fl_color_chooser" width=8cm
- \param[in] name title label for the window
- \param[in,out] r, g, b color components in the range 0.0 to 1.0.
+ \param[in] name Title label for the window
+ \param[in,out] r, g, b Color components in the range 0.0 to 1.0.
+ \param[in] cmode Optional mode for color chooser. See mode(int). Default -1 if none (rgb mode).
\retval 1 if user confirms the selection
\retval 0 if user cancels the dialog
\relates Fl_Color_Chooser
*/
-int fl_color_chooser(const char* name, double& r, double& g, double& b) {
+int fl_color_chooser(const char* name, double& r, double& g, double& b, int cmode) {
int ret = 0;
Fl_Window window(215,200,name);
window.callback(cc_cancel_cb,&ret);
@@ -578,6 +586,7 @@ int fl_color_chooser(const char* name, double& r, double& g, double& b) {
window.resizable(chooser);
chooser.rgb(r,g,b);
chooser.callback(chooser_cb, &ok_color);
+ if (cmode!=-1) chooser.mode(cmode);
window.end();
window.set_modal();
window.hotspot(window);
@@ -595,17 +604,18 @@ int fl_color_chooser(const char* name, double& r, double& g, double& b) {
\brief Pops up a window to let the user pick an arbitrary RGB color.
\image html fl_color_chooser.jpg
\image latex fl_color_chooser.eps "fl_color_chooser" width=8cm
- \param[in] name title label for the window
- \param[in,out] r, g, b color components in the range 0 to 255.
+ \param[in] name Title label for the window
+ \param[in,out] r, g, b Color components in the range 0 to 255.
+ \param[in] cmode Optional mode for color chooser. See mode(int). Default -1 if none (rgb mode).
\retval 1 if user confirms the selection
\retval 0 if user cancels the dialog
\relates Fl_Color_Chooser
*/
-int fl_color_chooser(const char* name, uchar& r, uchar& g, uchar& b) {
+int fl_color_chooser(const char* name, uchar& r, uchar& g, uchar& b, int cmode) {
double dr = r/255.0;
double dg = g/255.0;
double db = b/255.0;
- if (fl_color_chooser(name,dr,dg,db)) {
+ if (fl_color_chooser(name,dr,dg,db,cmode)) {
r = uchar(255*dr+.5);
g = uchar(255*dg+.5);
b = uchar(255*db+.5);
@@ -613,7 +623,8 @@ int fl_color_chooser(const char* name, uchar& r, uchar& g, uchar& b) {
}
return 0;
}
+
/** @} */
//
-// End of "$Id: Fl_Color_Chooser.cxx 7347 2010-03-27 16:35:14Z AlbrechtS $".
+// End of "$Id: Fl_Color_Chooser.cxx 7790 2010-11-01 00:29:08Z greg.ercolano $".
//
diff --git a/src/Fl_File_Chooser2.cxx b/src/Fl_File_Chooser2.cxx
index fda39ef..ebd8fd0 100644
--- a/src/Fl_File_Chooser2.cxx
+++ b/src/Fl_File_Chooser2.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_File_Chooser2.cxx 7672 2010-07-10 09:44:45Z matt $"
+// "$Id: Fl_File_Chooser2.cxx 7783 2010-10-30 21:52:38Z matt $"
//
// More Fl_File_Chooser routines.
//
@@ -727,6 +727,7 @@ Fl_File_Chooser::fileListCB()
{
// Hide the window - picked the file...
window->hide();
+ if (callback_) (*callback_)(this, data_);
}
}
else
@@ -1650,5 +1651,5 @@ unquote_pathname(char *dst, // O - Destination string
//
-// End of "$Id: Fl_File_Chooser2.cxx 7672 2010-07-10 09:44:45Z matt $".
+// End of "$Id: Fl_File_Chooser2.cxx 7783 2010-10-30 21:52:38Z matt $".
//
diff --git a/src/Fl_Group.cxx b/src/Fl_Group.cxx
index fc9d7fa..57e0d3c 100644
--- a/src/Fl_Group.cxx
+++ b/src/Fl_Group.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Group.cxx 7718 2010-10-12 08:12:44Z AlbrechtS $"
+// "$Id: Fl_Group.cxx 7782 2010-10-30 21:32:15Z matt $"
//
// Group widget for the Fast Light Tool Kit (FLTK).
//
@@ -133,7 +133,6 @@ static int navkey() {
break;
case FL_Tab:
if (!Fl::event_state(FL_SHIFT)) return FL_Right;
- case 0xfe20: // XK_ISO_Left_Tab
return FL_Left;
case FL_Right:
return FL_Right;
@@ -790,42 +789,48 @@ void Fl_Group::draw_outside_label(const Fl_Widget& widget) const {
int Y = widget.y();
int W = widget.w();
int H = widget.h();
+ int wx, wy;
+ if (const_cast<Fl_Group*>(this)->as_window()) {
+ wx = wy = 0;
+ } else {
+ wx = x(); wy = y();
+ }
if ( (a & 0x0f) == FL_ALIGN_LEFT_TOP ) {
a = (a &~0x0f ) | FL_ALIGN_TOP_RIGHT;
- X = x();
+ X = wx;
W = widget.x()-X-3;
} else if ( (a & 0x0f) == FL_ALIGN_LEFT_BOTTOM ) {
a = (a &~0x0f ) | FL_ALIGN_BOTTOM_RIGHT;
- X = x();
+ X = wx;
W = widget.x()-X-3;
} else if ( (a & 0x0f) == FL_ALIGN_RIGHT_TOP ) {
a = (a &~0x0f ) | FL_ALIGN_TOP_LEFT;
X = X+W+3;
- W = x()+this->w()-X;
+ W = wx+this->w()-X;
} else if ( (a & 0x0f) == FL_ALIGN_RIGHT_BOTTOM ) {
a = (a &~0x0f ) | FL_ALIGN_BOTTOM_LEFT;
X = X+W+3;
- W = x()+this->w()-X;
+ W = wx+this->w()-X;
} else if (a & FL_ALIGN_TOP) {
a ^= (FL_ALIGN_BOTTOM|FL_ALIGN_TOP);
- Y = y();
+ Y = wy;
H = widget.y()-Y;
} else if (a & FL_ALIGN_BOTTOM) {
a ^= (FL_ALIGN_BOTTOM|FL_ALIGN_TOP);
Y = Y+H;
- H = y()+h()-Y;
+ H = wy+h()-Y;
} else if (a & FL_ALIGN_LEFT) {
a ^= (FL_ALIGN_LEFT|FL_ALIGN_RIGHT);
- X = x();
+ X = wx;
W = widget.x()-X-3;
} else if (a & FL_ALIGN_RIGHT) {
a ^= (FL_ALIGN_LEFT|FL_ALIGN_RIGHT);
X = X+W+3;
- W = x()+this->w()-X;
+ W = wx+this->w()-X;
}
widget.draw_label(X,Y,W,H,(Fl_Align)a);
}
//
-// End of "$Id: Fl_Group.cxx 7718 2010-10-12 08:12:44Z AlbrechtS $".
+// End of "$Id: Fl_Group.cxx 7782 2010-10-30 21:32:15Z matt $".
//
diff --git a/src/Fl_Help_View.cxx b/src/Fl_Help_View.cxx
index 04d4cae..e1fb13f 100644
--- a/src/Fl_Help_View.cxx
+++ b/src/Fl_Help_View.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Help_View.cxx 6776 2009-04-22 09:02:13Z greg.ercolano $"
+// "$Id: Fl_Help_View.cxx 7765 2010-10-28 18:02:20Z matt $"
//
// Fl_Help_View widget routines.
//
@@ -3201,7 +3201,7 @@ Fl_Help_View::load(const char *f)// I - Filename to load (may also have target)
rewind(fp);
value_ = (const char *)calloc(len + 1, 1);
- fread((void *)value_, 1, len, fp);
+ if (fread((void *)value_, 1, len, fp)==0) { /* use default 0 */ }
fclose(fp);
}
else
@@ -3515,5 +3515,5 @@ hscrollbar_callback(Fl_Widget *s, void *)
//
-// End of "$Id: Fl_Help_View.cxx 6776 2009-04-22 09:02:13Z greg.ercolano $".
+// End of "$Id: Fl_Help_View.cxx 7765 2010-10-28 18:02:20Z matt $".
//
diff --git a/src/Fl_Input.cxx b/src/Fl_Input.cxx
index aeb0969..809d504 100644
--- a/src/Fl_Input.cxx
+++ b/src/Fl_Input.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Input.cxx 6968 2009-12-13 14:44:30Z matt $"
+// "$Id: Fl_Input.cxx 7789 2010-10-31 22:39:40Z matt $"
//
// Input widget for the Fast Light Tool Kit (FLTK).
//
@@ -123,12 +123,12 @@ int Fl_Input::handle_key() {
// find the insert position
int ip = position()<mark() ? position() : mark();
// This is complex to allow "0xff12" hex to be typed:
- if (!ip && (ascii == '+' || ascii == '-')
+ if ( (!ip && (ascii == '+' || ascii == '-'))
|| (ascii >= '0' && ascii <= '9')
|| (ip==1 && index(0)=='0' && (ascii=='x' || ascii == 'X'))
- || (ip>1 && index(0)=='0' && (index(1)=='x'||index(1)=='X')
- && (ascii>='A'&& ascii<='F' || ascii>='a'&& ascii<='f'))
- || input_type()==FL_FLOAT_INPUT && ascii && strchr(legal_fp_chars, ascii))
+ || (ip>1 && index(0)=='0' && (index(1)=='x'||index(1)=='X')
+ && ((ascii>='A'&& ascii<='F') || (ascii>='a'&& ascii<='f')))
+ || (input_type()==FL_FLOAT_INPUT && ascii && strchr(legal_fp_chars, ascii)))
{
if (readonly()) fl_beep();
else replace(position(), mark(), &ascii, 1);
@@ -382,7 +382,8 @@ int Fl_Input::handle_key() {
case ctrl('A'): // go to the beginning of the current line
return shift_position(line_start(position())) + NORMAL_INPUT_MOVE;
case ctrl('B'): // go one character backward
- return shift_position(position()-1) + NORMAL_INPUT_MOVE;
+ i = shift_position(position()-1) + NORMAL_INPUT_MOVE;
+ return Fl::option(Fl::OPTION_ARROW_FOCUS) ? i : 1;
case ctrl('C'): // copy
return copy(1);
case ctrl('D'): // cut the next character
@@ -396,7 +397,8 @@ int Fl_Input::handle_key() {
case ctrl('E'): // go to the end of the line
return shift_position(line_end(position())) + NORMAL_INPUT_MOVE;
case ctrl('F'): // go to the next character
- return shift_position(position()+1) + NORMAL_INPUT_MOVE;
+ i = shift_position(position()+1) + NORMAL_INPUT_MOVE;
+ return Fl::option(Fl::OPTION_ARROW_FOCUS) ? i : 1;
case ctrl('H'): // cut the previous character
if (readonly()) {
fl_beep();
@@ -417,7 +419,10 @@ int Fl_Input::handle_key() {
return copy_cuts();
case ctrl('N'): // go down one line
i = position();
- if (line_end(i) >= size()) return NORMAL_INPUT_MOVE;
+ if (line_end(i) >= size()) {
+ if (input_type()==FL_MULTILINE_INPUT && !Fl::option(Fl::OPTION_ARROW_FOCUS)) return 1;
+ return NORMAL_INPUT_MOVE;
+ }
while (repeat_num--) {
i = line_end(i);
if (i >= size()) break;
@@ -427,7 +432,10 @@ int Fl_Input::handle_key() {
return 1;
case ctrl('P'): // go up one line
i = position();
- if (!line_start(i)) return NORMAL_INPUT_MOVE;
+ if (!line_start(i)) {
+ if (input_type()==FL_MULTILINE_INPUT && !Fl::option(Fl::OPTION_ARROW_FOCUS)) return 1;
+ return NORMAL_INPUT_MOVE;
+ }
while(repeat_num--) {
i = line_start(i);
if (!i) break;
@@ -475,6 +483,7 @@ int Fl_Input::handle_key() {
// insert a few selected control characters literally:
if (input_type() != FL_FLOAT_INPUT && input_type() != FL_INT_INPUT)
return replace(position(), mark(), &ascii, 1);
+ break;
}
return 0;
@@ -499,7 +508,6 @@ int Fl_Input::handle(int event) {
up_down_position(line_start(size()));
break;
case FL_Tab:
- case 0xfe20: // XK_ISO_Left_Tab
position(size(),0);
break;
default:
@@ -521,23 +529,23 @@ int Fl_Input::handle(int event) {
window()->cursor(FL_CURSOR_NONE);
return handle_key();
}
+ //NOTREACHED
case FL_PUSH:
if (Fl::dnd_text_ops()) {
int oldpos = position(), oldmark = mark();
Fl_Boxtype b = box();
- Fl_Input_::handle_mouse(
- x()+Fl::box_dx(b), y()+Fl::box_dy(b),
+ Fl_Input_::handle_mouse(x()+Fl::box_dx(b), y()+Fl::box_dy(b),
w()-Fl::box_dw(b), h()-Fl::box_dh(b), 0);
newpos = position();
position( oldpos, oldmark );
if (Fl::focus()==this && !Fl::event_state(FL_SHIFT) && input_type()!=FL_SECRET_INPUT &&
- (newpos >= mark() && newpos < position() ||
- newpos >= position() && newpos < mark())) {
- // user clicked in the selection, may be trying to drag
- drag_start = newpos;
- return 1;
- }
+ ( (newpos >= mark() && newpos < position()) ||
+ (newpos >= position() && newpos < mark()) ) ) {
+ // user clicked in the selection, may be trying to drag
+ drag_start = newpos;
+ return 1;
+ }
drag_start = -1;
}
@@ -602,12 +610,11 @@ int Fl_Input::handle(int event) {
return 0;
}
#endif
- {
- Fl_Boxtype b = box();
- Fl_Input_::handle_mouse(
- x()+Fl::box_dx(b), y()+Fl::box_dy(b),
- w()-Fl::box_dw(b), h()-Fl::box_dh(b), 0);
- }
+ {
+ Fl_Boxtype b = box();
+ Fl_Input_::handle_mouse(x()+Fl::box_dx(b), y()+Fl::box_dy(b),
+ w()-Fl::box_dw(b), h()-Fl::box_dh(b), 0);
+ }
return 1;
case FL_DND_LEAVE:
@@ -636,7 +643,6 @@ int Fl_Input::handle(int event) {
}
return 1;
*/
-
}
Fl_Boxtype b = box();
return Fl_Input_::handletext(event,
@@ -653,5 +659,5 @@ Fl_Input::Fl_Input(int X, int Y, int W, int H, const char *l)
}
//
-// End of "$Id: Fl_Input.cxx 6968 2009-12-13 14:44:30Z matt $".
+// End of "$Id: Fl_Input.cxx 7789 2010-10-31 22:39:40Z matt $".
//
diff --git a/src/Fl_Input_.cxx b/src/Fl_Input_.cxx
index 6a94ad1..cda67b0 100644
--- a/src/Fl_Input_.cxx
+++ b/src/Fl_Input_.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Input_.cxx 7672 2010-07-10 09:44:45Z matt $"
+// "$Id: Fl_Input_.cxx 7765 2010-10-28 18:02:20Z matt $"
//
// Common input widget routines for the Fast Light Tool Kit (FLTK).
//
@@ -844,7 +844,7 @@ int Fl_Input_::replace(int b, int e, const char* text, int ilen) {
*/
int Fl_Input_::undo() {
was_up_down = 0;
- if (undowidget != this || !undocut && !undoinsert) return 0;
+ if ( undowidget != this || (!undocut && !undoinsert) ) return 0;
int ilen = undocut;
int xlen = undoinsert;
@@ -1254,5 +1254,5 @@ unsigned int Fl_Input_::index(int i) const
}
//
-// End of "$Id: Fl_Input_.cxx 7672 2010-07-10 09:44:45Z matt $".
+// End of "$Id: Fl_Input_.cxx 7765 2010-10-28 18:02:20Z matt $".
//
diff --git a/src/Fl_JPEG_Image.cxx b/src/Fl_JPEG_Image.cxx
index 2b5b0cb..8473990 100644
--- a/src/Fl_JPEG_Image.cxx
+++ b/src/Fl_JPEG_Image.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_JPEG_Image.cxx 7092 2010-02-18 11:38:42Z matt $"
+// "$Id: Fl_JPEG_Image.cxx 7780 2010-10-30 20:01:16Z matt $"
//
// Fl_JPEG_Image routines.
//
@@ -205,7 +205,7 @@ Fl_JPEG_Image::Fl_JPEG_Image(const char *filename) // I - File to load
// JOCTET * next_output_byte; /* => next byte to write in buffer */
// size_t free_in_buffer; /* # of byte spaces remaining in buffer */
-
+#ifdef HAVE_LIBJPEG
typedef struct {
struct jpeg_source_mgr pub;
const unsigned char *data, *s;
@@ -261,6 +261,7 @@ static void jpeg_mem_src(j_decompress_ptr cinfo, const unsigned char *data)
src->data = data;
src->s = data;
}
+#endif // HAVE_LIBJPEG
/**
@@ -364,5 +365,5 @@ Fl_JPEG_Image::Fl_JPEG_Image(const char *name, const unsigned char *data)
}
//
-// End of "$Id: Fl_JPEG_Image.cxx 7092 2010-02-18 11:38:42Z matt $".
+// End of "$Id: Fl_JPEG_Image.cxx 7780 2010-10-30 20:01:16Z matt $".
//
diff --git a/src/Fl_Menu.cxx b/src/Fl_Menu.cxx
index d8a7c12..f30eeaf 100644
--- a/src/Fl_Menu.cxx
+++ b/src/Fl_Menu.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Menu.cxx 7151 2010-02-26 13:28:36Z matt $"
+// "$Id: Fl_Menu.cxx 7779 2010-10-30 19:56:20Z matt $"
//
// Menu code for the Fast Light Tool Kit (FLTK).
//
@@ -660,7 +660,6 @@ int menuwindow::early_hide_handle(int e) {
case FL_KEYBOARD:
switch (Fl::event_key()) {
case FL_BackSpace:
- case 0xFE20: // backtab
BACKTAB:
if (!backward(pp.menu_number)) {pp.item_number = -1;backward(pp.menu_number);}
return 1;
@@ -686,7 +685,7 @@ int menuwindow::early_hide_handle(int e) {
}
return 1;
case FL_Right:
- if (pp.menubar && (pp.menu_number<=0 || pp.menu_number==1 && pp.nummenus==2))
+ if (pp.menubar && (pp.menu_number<=0 || (pp.menu_number==1 && pp.nummenus==2)))
forward(0);
else if (pp.menu_number < pp.nummenus-1) forward(pp.menu_number+1);
return 1;
@@ -774,8 +773,9 @@ int menuwindow::early_hide_handle(int e) {
case FL_RELEASE:
// Mouse must either be held down/dragged some, or this must be
// the second click (not the one that popped up the menu):
- if (!Fl::event_is_click() || pp.state == PUSH_STATE ||
- pp.menubar && pp.current_item && !pp.current_item->submenu() // button
+ if ( !Fl::event_is_click()
+ || pp.state == PUSH_STATE
+ || (pp.menubar && pp.current_item && !pp.current_item->submenu()) // button
) {
#if 0 // makes the check/radio items leave the menu up
const Fl_Menu_Item* m = pp.current_item;
@@ -1032,5 +1032,5 @@ const Fl_Menu_Item* Fl_Menu_Item::test_shortcut() const {
}
//
-// End of "$Id: Fl_Menu.cxx 7151 2010-02-26 13:28:36Z matt $".
+// End of "$Id: Fl_Menu.cxx 7779 2010-10-30 19:56:20Z matt $".
//
diff --git a/src/Fl_Menu_add.cxx b/src/Fl_Menu_add.cxx
index c36eb29..9f34c9a 100644
--- a/src/Fl_Menu_add.cxx
+++ b/src/Fl_Menu_add.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Menu_add.cxx 7519 2010-04-16 19:50:40Z greg.ercolano $"
+// "$Id: Fl_Menu_add.cxx 7789 2010-10-31 22:39:40Z matt $"
//
// Menu utilities for the Fast Light Tool Kit (FLTK).
//
@@ -51,6 +51,8 @@ extern Fl_Menu_* fl_menu_array_owner; // in Fl_Menu_.cxx
// above pointers to detect if the array belongs to an Fl_Menu_
// widget, and if so it reallocates as necessary.
+
+
// Insert a single Fl_Menu_Item into an array of size at offset n,
// if this is local_array it will be reallocated if needed.
static Fl_Menu_Item* array_insert(
@@ -81,6 +83,8 @@ static Fl_Menu_Item* array_insert(
return array;
}
+
+
// Comparison that does not care about deleted '&' signs:
static int compare(const char* a, const char* b) {
for (;;) {
@@ -97,6 +101,8 @@ static int compare(const char* a, const char* b) {
}
}
+
+
/** Adds an item. The text is split at '/' characters to automatically
produce submenus (actually a totally unnecessary feature as you can
now add submenu titles directly by setting SUBMENU in the flags):
@@ -111,15 +117,26 @@ int Fl_Menu_Item::add(
return(insert(-1,mytext,sc,cb,data,myflags)); // -1: append
}
-/** Inserts an item at position \p index.
-
- If \p index is -1, the item is added the same way as Fl_Menu_Item::add().
- If 'mytext' contains any un-escaped front slashes (/), it's assumed
- a menu pathname is being specified, and the value of \p index
- will be ignored.
- In all other aspects, the behavior of insert() is the same as add().
+/**
+ Inserts an item at position \p index.
+
+ If \p index is -1, the item is added the same way as Fl_Menu_Item::add().
+
+ If 'mytext' contains any un-escaped front slashes (/), it's assumed
+ a menu pathname is being specified, and the value of \p index
+ will be ignored.
+
+ In all other aspects, the behavior of insert() is the same as add().
+
+ \param index insert new items here
+ \param mytext new label string, details see above
+ \param sc keyboard shortcut for new item
+ \param cb callback function for new item
+ \param data user data for new item
+ \param myflags menu flags as described in FL_Menu_Item
+ \returns the index into the menu() array, where the entry was added
*/
int Fl_Menu_Item::insert(
int index,
@@ -199,6 +216,8 @@ int Fl_Menu_Item::insert(
return m-array;
}
+
+
/**
Adds a new menu item.
@@ -307,6 +326,8 @@ int Fl_Menu_::add(const char *label,int shortcut,Fl_Callback *callback,void *use
return(insert(-1,label,shortcut,callback,userdata,flags)); // -1: append
}
+
+
/**
Inserts a new menu item at the specified \p index position.
@@ -387,6 +408,8 @@ int Fl_Menu_::insert(
return r;
}
+
+
/**
This is a Forms (and SGI GL library) compatible add function, it
adds many menu items, with '|' separating the menu items, and tab
@@ -399,6 +422,9 @@ int Fl_Menu_::insert(
same special characters as described for the long version of add().
No items must be added to a menu during a callback to the same menu.
+
+ \param str string containing multiple menu labels as described above
+ \returns the index into the menu() array, where the entry was added
*/
int Fl_Menu_::add(const char *str) {
char buf[1024];
@@ -417,10 +443,15 @@ int Fl_Menu_::add(const char *str) {
return r;
}
+
+
/**
Changes the text of item \p i. This is the only way to get
slash into an add()'ed menu item. If the menu array was directly set
with menu(x) then copy() is done to make a private array.
+
+ \param i index into menu array
+ \param str new label for menu item at index i
*/
void Fl_Menu_::replace(int i, const char *str) {
if (i<0 || i>=size()) return;
@@ -431,11 +462,16 @@ void Fl_Menu_::replace(int i, const char *str) {
}
menu_[i].text = str;
}
+
+
+
/**
Deletes item \p i from the menu. If the menu array was directly
set with menu(x) then copy() is done to make a private array.
No items must be removed from a menu during a callback to the same menu.
+
+ \param i index into menu array
*/
void Fl_Menu_::remove(int i) {
int n = size();
@@ -454,5 +490,5 @@ void Fl_Menu_::remove(int i) {
}
//
-// End of "$Id: Fl_Menu_add.cxx 7519 2010-04-16 19:50:40Z greg.ercolano $".
+// End of "$Id: Fl_Menu_add.cxx 7789 2010-10-31 22:39:40Z matt $".
//
diff --git a/src/Fl_PNM_Image.cxx b/src/Fl_PNM_Image.cxx
index c1e446d..3e50431 100644
--- a/src/Fl_PNM_Image.cxx
+++ b/src/Fl_PNM_Image.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_PNM_Image.cxx 6616 2009-01-01 21:28:26Z matt $"
+// "$Id: Fl_PNM_Image.cxx 7767 2010-10-28 21:47:01Z matt $"
//
// Fl_PNM_Image routines.
//
@@ -166,7 +166,7 @@ Fl_PNM_Image::Fl_PNM_Image(const char *name) // I - File to read
case 5 :
case 6 :
if (maxval < 256) {
- fread(ptr, w(), d(), fp);
+ if (fread(ptr, w(), d(), fp)) { /* ignored */ }
} else {
for (x = d() * w(); x > 0; x --) {
val = (uchar)getc(fp);
@@ -193,5 +193,5 @@ Fl_PNM_Image::Fl_PNM_Image(const char *name) // I - File to read
//
-// End of "$Id: Fl_PNM_Image.cxx 6616 2009-01-01 21:28:26Z matt $".
+// End of "$Id: Fl_PNM_Image.cxx 7767 2010-10-28 21:47:01Z matt $".
//
diff --git a/src/Fl_PostScript.cxx b/src/Fl_PostScript.cxx
index 68e698e..e86645a 100644
--- a/src/Fl_PostScript.cxx
+++ b/src/Fl_PostScript.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_PostScript.cxx 7697 2010-09-04 15:01:07Z manolo $"
+// "$Id: Fl_PostScript.cxx 7788 2010-10-31 20:47:50Z matt $"
//
// PostScript device support for the Fast Light Tool Kit (FLTK).
//
@@ -699,7 +699,7 @@ void Fl_PostScript_Graphics_Driver::page(double pw, double ph, int media) {
}
}
fprintf(output, "GS\nCS\n");
-};
+}
void Fl_PostScript_Graphics_Driver::page(int format){
@@ -712,7 +712,7 @@ void Fl_PostScript_Graphics_Driver::page(int format){
ph_=Fl_PostScript_Graphics_Driver::page_formats[format & 0xFF].height;
}
page(pw_,ph_,format & 0xFF00);//,orientation only;
-};
+}
void Fl_PostScript_Graphics_Driver::rect(int x, int y, int w, int h) {
// Commented code does not work, i can't find the bug ;-(
@@ -758,7 +758,7 @@ void Fl_PostScript_Graphics_Driver::xyline(int x, int y, int x1, int y2, int x3)
fprintf(output,"%i %i LT\n", x3 , y2);
fprintf(output, "ELP\n");
fprintf(output, "GR\n");
-};
+}
void Fl_PostScript_Graphics_Driver::xyline(int x, int y, int x1, int y2){
@@ -770,7 +770,7 @@ void Fl_PostScript_Graphics_Driver::xyline(int x, int y, int x1, int y2){
fprintf(output, "%i %i LT\n", x1 , y2 );
fprintf(output, "ELP\n");
fprintf(output, "GR\n");
-};
+}
void Fl_PostScript_Graphics_Driver::xyline(int x, int y, int x1){
fprintf(output, "GS\n");
@@ -780,7 +780,7 @@ void Fl_PostScript_Graphics_Driver::xyline(int x, int y, int x1){
fprintf(output, "ELP\n");
fprintf(output, "GR\n");
-};
+}
void Fl_PostScript_Graphics_Driver::yxline(int x, int y, int y1, int x2, int y3){
fprintf(output, "GS\n");
@@ -792,7 +792,7 @@ void Fl_PostScript_Graphics_Driver::yxline(int x, int y, int y1, int x2, int y3)
fprintf(output , "%i %i LT\n", x2 , y3);
fprintf(output, "ELP\n");
fprintf(output, "GR\n");
-};
+}
void Fl_PostScript_Graphics_Driver::yxline(int x, int y, int y1, int x2){
fprintf(output, "GS\n");
@@ -802,7 +802,7 @@ void Fl_PostScript_Graphics_Driver::yxline(int x, int y, int y1, int x2){
fprintf(output, "%i %i LT\n", x2 , y1);
fprintf(output, "ELP\n");
fprintf(output, "GR\n");
-};
+}
void Fl_PostScript_Graphics_Driver::yxline(int x, int y, int y1){
fprintf(output, "GS\n");
@@ -811,7 +811,7 @@ void Fl_PostScript_Graphics_Driver::yxline(int x, int y, int y1){
fprintf(output, "%i %i LT\n", x , y1);
fprintf(output, "ELP\n");
fprintf(output, "GR\n");
-};
+}
void Fl_PostScript_Graphics_Driver::loop(int x0, int y0, int x1, int y1, int x2, int y2) {
fprintf(output, "GS\n");
@@ -936,7 +936,7 @@ void Fl_PostScript_Graphics_Driver::line_style(int style, int width, char* dashe
}
}
fprintf(output, "] 0 setdash\n");
-};
+}
static const char *_fontNames[] = {
"Helvetica2B",
@@ -964,7 +964,7 @@ void Fl_PostScript_Graphics_Driver::font(int f, int s) {
fprintf(output,"%i FS\n", s);
Fl_Display_Device::display_device()->driver()->font(f,s); // Use display fonts for font measurement
font_ = f; size_ = s;
-};
+}
void Fl_PostScript_Graphics_Driver::color(Fl_Color c) {
Fl::get_color(c, cr_, cg_, cb_);
@@ -1146,7 +1146,7 @@ void Fl_PostScript_Graphics_Driver::begin_points(){
fprintf(output, "BP\n");
gap_=1;
shape_=POINTS;
-};
+}
void Fl_PostScript_Graphics_Driver::begin_line(){
fprintf(output, "GS\n");
@@ -1154,7 +1154,7 @@ void Fl_PostScript_Graphics_Driver::begin_line(){
fprintf(output, "BP\n");
gap_=1;
shape_=LINE;
-};
+}
void Fl_PostScript_Graphics_Driver::begin_loop(){
fprintf(output, "GS\n");
@@ -1162,7 +1162,7 @@ void Fl_PostScript_Graphics_Driver::begin_loop(){
fprintf(output, "BP\n");
gap_=1;
shape_=LOOP;
-};
+}
void Fl_PostScript_Graphics_Driver::begin_polygon(){
fprintf(output, "GS\n");
@@ -1170,7 +1170,7 @@ void Fl_PostScript_Graphics_Driver::begin_polygon(){
fprintf(output, "BP\n");
gap_=1;
shape_=POLYGON;
-};
+}
void Fl_PostScript_Graphics_Driver::vertex(double x, double y){
if(shape_==POINTS){
@@ -1183,7 +1183,7 @@ void Fl_PostScript_Graphics_Driver::vertex(double x, double y){
gap_=0;
}else
fprintf(output, "%g %g LT\n", x , y);
-};
+}
void Fl_PostScript_Graphics_Driver::curve(double x, double y, double x1, double y1, double x2, double y2, double x3, double y3){
if(shape_==NONE) return;
@@ -1194,7 +1194,7 @@ void Fl_PostScript_Graphics_Driver::curve(double x, double y, double x1, double
gap_=0;
fprintf(output, "%g %g %g %g %g %g curveto \n", x1 , y1 , x2 , y2 , x3 , y3);
-};
+}
void Fl_PostScript_Graphics_Driver::circle(double x, double y, double r){
@@ -1210,7 +1210,7 @@ void Fl_PostScript_Graphics_Driver::circle(double x, double y, double r){
fprintf(output, "%g %g %g 0 360 arc\n", x , y , r);
-};
+}
void Fl_PostScript_Graphics_Driver::arc(double x, double y, double r, double start, double a){
if(shape_==NONE) return;
@@ -1220,7 +1220,7 @@ void Fl_PostScript_Graphics_Driver::arc(double x, double y, double r, double sta
else
fprintf(output, "%g %g %g %g %g arcn\n", x , y , r , -start, -a);
-};
+}
void Fl_PostScript_Graphics_Driver::arc(int x, int y, int w, int h, double a1, double a2) {
fprintf(output, "GS\n");
@@ -1293,7 +1293,7 @@ void Fl_PostScript_Graphics_Driver::transformed_vertex(double x, double y){
}else
fprintf(output, "%g %g LT\n", x , y);
concat();
-};
+}
///////////////////////////// Clipping /////////////////////////////////////////////
@@ -1366,7 +1366,7 @@ int Fl_PostScript_Graphics_Driver::clip_box(int x, int y, int w, int h, int &X,
return 1;
}
return ret;
-};
+}
int Fl_PostScript_Graphics_Driver::not_clipped(int x, int y, int w, int h){
if(!clip_) return 1;
@@ -1375,7 +1375,7 @@ int Fl_PostScript_Graphics_Driver::not_clipped(int x, int y, int w, int h){
clip_box(x, y, w, h, X, Y, W, H);
if(W) return 1;
return 0;
-};
+}
void Fl_PostScript_File_Device::margins(int *left, int *top, int *right, int *bottom) // to implement
@@ -1556,5 +1556,5 @@ int Fl_Printer::start_job(int pages, int *firstpage, int *lastpage) {
#endif // FL_DOXYGEN
//
-// End of "$Id: Fl_PostScript.cxx 7697 2010-09-04 15:01:07Z manolo $".
+// End of "$Id: Fl_PostScript.cxx 7788 2010-10-31 20:47:50Z matt $".
//
diff --git a/src/Fl_Preferences.cxx b/src/Fl_Preferences.cxx
index 4419983..e7bb59e 100644
--- a/src/Fl_Preferences.cxx
+++ b/src/Fl_Preferences.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Preferences.cxx 7707 2010-09-30 09:00:56Z ianmacarthur $"
+// "$Id: Fl_Preferences.cxx 7783 2010-10-30 21:52:38Z matt $"
//
// Preferences methods for the Fast Light Tool Kit (FLTK).
//
@@ -28,7 +28,6 @@
#include <FL/Fl.H>
#include <FL/Fl_Preferences.H>
#include <FL/Fl_Plugin.H>
-#include <FL/Fl_Tree.H>
#include <FL/filename.H>
#include <stdio.h>
@@ -162,9 +161,7 @@ const char *Fl_Preferences::newUUID()
b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15]);
}
#else
-# if defined(__GNUC__)
-# warning Unix implementation of Fl_Preferences::newUUID() incomplete!
-# endif /*__GNUC__*/
+ // warning Unix implementation of Fl_Preferences::newUUID() incomplete!
// #include <uuid/uuid.h>
// void uuid_generate(uuid_t out);
unsigned char b[16];
@@ -692,8 +689,13 @@ static char *decodeText( const char *src )
const char *s = src;
for ( ; *s; s++, len++ )
{
- if ( *s == '\\' )
- if ( isdigit( s[1] ) ) s+=3; else s+=1;
+ if ( *s == '\\' ) {
+ if ( isdigit( s[1] ) ) {
+ s+=3;
+ } else {
+ s+=1;
+ }
+ }
}
char *dst = (char*)malloc( len+1 ), *d = dst;
for ( s = src; *s; s++ )
@@ -1267,9 +1269,9 @@ int Fl_Preferences::RootNode::read()
if ( !f )
return -1;
- fgets( buf, 1024, f );
- fgets( buf, 1024, f );
- fgets( buf, 1024, f );
+ if (fgets( buf, 1024, f )==0) { /* ignore */ }
+ if (fgets( buf, 1024, f )==0) { /* ignore */ }
+ if (fgets( buf, 1024, f )==0) { /* ignore */ }
Node *nd = prefs_->node;
for (;;)
{
@@ -1968,5 +1970,5 @@ int Fl_Plugin_Manager::loadAll(const char *filepath, const char *pattern)
//
-// End of "$Id: Fl_Preferences.cxx 7707 2010-09-30 09:00:56Z ianmacarthur $".
+// End of "$Id: Fl_Preferences.cxx 7783 2010-10-30 21:52:38Z matt $".
//
diff --git a/src/Fl_Scroll.cxx b/src/Fl_Scroll.cxx
index 0057ead..87a4d10 100644
--- a/src/Fl_Scroll.cxx
+++ b/src/Fl_Scroll.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Scroll.cxx 7718 2010-10-12 08:12:44Z AlbrechtS $"
+// "$Id: Fl_Scroll.cxx 7765 2010-10-28 18:02:20Z matt $"
//
// Scroll widget for the Fast Light Tool Kit (FLTK).
//
@@ -348,9 +348,9 @@ void Fl_Scroll::resize(int X, int Y, int W, int H) {
o->position(o->x()+dx, o->y()+dy);
}
if (dw==0 && dh==0) {
- char pad = (scrollbar.visible() && hscrollbar.visible());
- char al = (scrollbar.align()&FL_ALIGN_LEFT!=0);
- char at = (scrollbar.align()&FL_ALIGN_TOP!=0);
+ char pad = ( scrollbar.visible() && hscrollbar.visible() );
+ char al = ( (scrollbar.align() & FL_ALIGN_LEFT) != 0 );
+ char at = ( (scrollbar.align() & FL_ALIGN_TOP) !=0 );
scrollbar.position(al?X:X+W-scrollbar.w(), (at&&pad)?Y+hscrollbar.h():Y);
hscrollbar.position((al&&pad)?X+scrollbar.w():X, at?Y:Y+H-hscrollbar.h());
} else {
@@ -416,5 +416,5 @@ int Fl_Scroll::handle(int event) {
}
//
-// End of "$Id: Fl_Scroll.cxx 7718 2010-10-12 08:12:44Z AlbrechtS $".
+// End of "$Id: Fl_Scroll.cxx 7765 2010-10-28 18:02:20Z matt $".
//
diff --git a/src/Fl_Shared_Image.cxx b/src/Fl_Shared_Image.cxx
index b32c572..512e9ff 100644
--- a/src/Fl_Shared_Image.cxx
+++ b/src/Fl_Shared_Image.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Shared_Image.cxx 6616 2009-01-01 21:28:26Z matt $"
+// "$Id: Fl_Shared_Image.cxx 7765 2010-10-28 18:02:20Z matt $"
//
// Shared image code for the Fast Light Tool Kit (FLTK).
//
@@ -228,7 +228,7 @@ void Fl_Shared_Image::reload() {
if (!name_) return;
if ((fp = fl_fopen(name_, "rb")) != NULL) {
- fread(header, 1, sizeof(header), fp);
+ if (fread(header, 1, sizeof(header), fp)==0) { /* ignore */ }
fclose(fp);
} else {
return;
@@ -459,5 +459,5 @@ void Fl_Shared_Image::remove_handler(Fl_Shared_Handler f) {
//
-// End of "$Id: Fl_Shared_Image.cxx 6616 2009-01-01 21:28:26Z matt $".
+// End of "$Id: Fl_Shared_Image.cxx 7765 2010-10-28 18:02:20Z matt $".
//
diff --git a/src/Fl_Table.cxx b/src/Fl_Table.cxx
index 8f743d1..cbed85a 100644
--- a/src/Fl_Table.cxx
+++ b/src/Fl_Table.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Table.cxx 7117 2010-02-20 21:14:47Z matt $"
+// "$Id: Fl_Table.cxx 7751 2010-10-26 11:30:58Z greg.ercolano $"
//
// Fl_Table -- A table widget
//
@@ -990,6 +990,13 @@ int Fl_Table::handle(int event) {
case FL_Down:
ret = move_cursor(1, 0);
break;
+ case FL_Tab:
+ if ( Fl::event_state() & FL_SHIFT ) {
+ ret = move_cursor(0, -1); // shift-tab -> left
+ } else {
+ ret = move_cursor(0, 1); // tab -> right
+ }
+ break;
}
if (ret && Fl::focus() != this) {
do_callback(CONTEXT_TABLE, -1, -1);
@@ -1034,6 +1041,10 @@ void Fl_Table::_redraw_cell(TableContext context, int r, int c) {
draw_cell(context, r, c, X, Y, W, H); // call users' function to draw it
}
+/**
+ See if the cell at row \p r and column \p c is selected.
+ \returns 1 if the cell is selected, 0 if not.
+ */
int Fl_Table::is_selected(int r, int c) {
int s_left, s_right, s_top, s_bottom;
@@ -1057,29 +1068,48 @@ int Fl_Table::is_selected(int r, int c) {
return 0;
}
-void Fl_Table::get_selection(int& s_top, int& s_left, int& s_bottom, int& s_right) {
+/**
+ Gets the region of cells selected (highlighted).
+
+ \param[in] row_top Returns the top row of selection area
+ \param[in] col_left Returns the left column of selection area
+ \param[in] row_bot Returns the bottom row of selection area
+ \param[in] col_right Returns the right column of selection area
+*/
+void Fl_Table::get_selection(int& row_top, int& col_left, int& row_bot, int& col_right) {
if (select_col > current_col) {
- s_left = current_col;
- s_right = select_col;
+ col_left = current_col;
+ col_right = select_col;
} else {
- s_right = current_col;
- s_left = select_col;
+ col_right = current_col;
+ col_left = select_col;
}
if (select_row > current_row) {
- s_top = current_row;
- s_bottom = select_row;
+ row_top = current_row;
+ row_bot = select_row;
} else {
- s_bottom = current_row;
- s_top = select_row;
+ row_bot = current_row;
+ row_top = select_row;
}
}
-void Fl_Table::set_selection(int s_top, int s_left, int s_bottom, int s_right) {
+/**
+ Sets the region of cells to be selected (highlighted).
+
+ So for instance, set_selection(0,0,0,0) selects the top/left cell in the table.
+ And set_selection(0,0,1,1) selects the four cells in rows 0 and 1, column 0 and 1.
+
+ \param[in] row_top Top row of selection area
+ \param[in] col_left Left column of selection area
+ \param[in] row_bot Bottom row of selection area
+ \param[in] col_right Right column of selection area
+*/
+void Fl_Table::set_selection(int row_top, int col_left, int row_bot, int col_right) {
damage_zone(current_row, current_col, select_row, select_col);
- current_col = s_left;
- current_row = s_top;
- select_col = s_right;
- select_row = s_bottom;
+ current_col = col_left;
+ current_row = row_top;
+ select_col = col_right;
+ select_row = row_bot;
damage_zone(current_row, current_col, select_row, select_col);
}
@@ -1220,5 +1250,5 @@ void Fl_Table::draw() {
}
//
-// End of "$Id: Fl_Table.cxx 7117 2010-02-20 21:14:47Z matt $".
+// End of "$Id: Fl_Table.cxx 7751 2010-10-26 11:30:58Z greg.ercolano $".
//
diff --git a/src/Fl_Tabs.cxx b/src/Fl_Tabs.cxx
index bb5e54b..cca76dc 100644
--- a/src/Fl_Tabs.cxx
+++ b/src/Fl_Tabs.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Tabs.cxx 7162 2010-02-26 21:10:46Z matt $"
+// "$Id: Fl_Tabs.cxx 7777 2010-10-30 19:28:17Z matt $"
//
// Tab widget for the Fast Light Tool Kit (FLTK).
//
@@ -117,12 +117,20 @@ Fl_Widget *Fl_Tabs::which(int event_x, int event_y) {
if (event_y > y()+H || event_y < y()) return 0;
}
if (event_x < x()) return 0;
- int p[128], wp[128];
+ Fl_Widget *ret = 0L;
+ int nc = children();
+ int *p = (int*)malloc((nc+1)*sizeof(int));
+ int *wp = (int*)malloc((nc+1)*sizeof(int));
tab_positions(p, wp);
for (int i=0; i<children(); i++) {
- if (event_x < x()+p[i+1]) return child(i);
+ if (event_x < x()+p[i+1]) {
+ ret = child(i);
+ break;
+ }
}
- return 0;
+ free(p);
+ free(wp);
+ return ret;
}
void Fl_Tabs::redraw_tabs()
@@ -246,7 +254,7 @@ int Fl_Tabs::handle(int event) {
int Fl_Tabs::push(Fl_Widget *o) {
if (push_ == o) return 0;
- if (push_ && !push_->visible() || o && !o->visible())
+ if ( (push_ && !push_->visible()) || (o && !o->visible()) )
redraw_tabs();
push_ = o;
return 1;
@@ -318,7 +326,9 @@ void Fl_Tabs::draw() {
if (v) update_child(*v);
}
if (damage() & (FL_DAMAGE_SCROLL|FL_DAMAGE_ALL)) {
- int p[128]; int wp[128];
+ int nc = children();
+ int *p = (int*)malloc((nc+1)*sizeof(int));
+ int *wp = (int*)malloc((nc+1)*sizeof(int));
int selected = tab_positions(p,wp);
int i;
Fl_Widget*const* a = array();
@@ -330,6 +340,8 @@ void Fl_Tabs::draw() {
i = selected;
draw_tab(x()+p[i], x()+p[i+1], wp[i], H, a[i], SELECTED);
}
+ free(p);
+ free(wp);
}
}
@@ -405,13 +417,17 @@ void Fl_Tabs::draw_tab(int x1, int x2, int W, int H, Fl_Widget* o, int what) {
Creates a new Fl_Tabs widget using the given position, size,
and label string. The default boxtype is FL_THIN_UP_BOX.
- <P>Use add(Fl_Widget
- *) to add each child, which are usually
+ Use add(Fl_Widget*) to add each child, which are usually
Fl_Group widgets. The children should be sized to stay
away from the top or bottom edge of the Fl_Tabs widget,
which is where the tabs will be drawn.
- <P>The destructor <I>also deletes all the children</I>. This
+ All children of Fl_Tab should have the same size and exactly fit on top of
+ each other. They should only leave space above or below where that tabs will
+ go, but not on the sides. If the first child of Fl_Tab is set to
+ "resizable()", the riders will not resize when the tabs are resized.
+
+ The destructor <I>also deletes all the children</I>. This
allows a whole tree to be deleted at once, without having to
keep a pointer to all the children in the user code. A kludge
has been done so the Fl_Tabs and all of its children
@@ -426,5 +442,5 @@ Fl_Tabs::Fl_Tabs(int X,int Y,int W, int H, const char *l) :
}
//
-// End of "$Id: Fl_Tabs.cxx 7162 2010-02-26 21:10:46Z matt $".
+// End of "$Id: Fl_Tabs.cxx 7777 2010-10-30 19:28:17Z matt $".
//
diff --git a/src/Fl_Text_Buffer.cxx b/src/Fl_Text_Buffer.cxx
index 6e244a0..f3949d1 100644
--- a/src/Fl_Text_Buffer.cxx
+++ b/src/Fl_Text_Buffer.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Text_Buffer.cxx 7672 2010-07-10 09:44:45Z matt $"
+// "$Id: Fl_Text_Buffer.cxx 7794 2010-11-04 21:53:56Z matt $"
//
// Copyright 2001-2009 by Bill Spitzak and others.
// Original code Copyright Mark Edel. Permission to distribute under
@@ -33,97 +33,47 @@
#include <FL/Fl.H>
#include <FL/Fl_Text_Buffer.H>
+
/*
This file is based on a port of NEdit to FLTK many years ago. NEdit at that
point was already stretched beyond the task it was designed for which explains
- why the source code is sometimes pretty convoluted. It still is a nice widget
- for FLTK.
+ why the source code is sometimes pretty convoluted. It still is a very useful
+ widget for FLTK, and we are thankful that the nedit team allowed us to
+ integrate their code.
With the introduction of Unicode and UTF-8, Fl_Text_... has to go into a whole
new generation of code. Originally designed for monspaced fonts only, many
features make les sense in the multibyte and multiwdth world of UTF-8.
- Columns are a good example. There is simply no such thing.
-
- Rectangular selections pose a real problem.
-
- Using multiple spaces to emulate tab stops will no longer work.
+ Columns are a good example. There is simply no such thing. The new Fl_Text_...
+ widget converts columns to pixels by multiplying them with the average
+ character width for a given font
- And constantly recalculating character widths is just much too expensive.
+ Rectangular selections were rearely used (if at all) and make little sense when
+ using variable width fonts. They have been removed.
- But nevertheless, we will get ths widget rolling again ;-)
+ Using multiple spaces to emulate tab stops has been replaced by pixel counting
+ routines. They are slower, but give the expected result for proportional fonts.
+ And constantly recalculating character widths is just much too expensive. Lines
+ of text are now subdivided into blocks of text which are measured at once
+ instead of individual characters.
*/
-/*
- \todo unicode check
- */
-static void insertColInLine(const char *line, char *insLine, int column,
- int insWidth, int tabDist, int useTabs,
- char *outStr, int *outLen,
- int *endOffset);
-
-/*
- \todo unicode check
- */
-static void deleteRectFromLine(const char *line, int rectStart,
- int rectEnd, int tabDist, int useTabs,
- char *outStr,
- int *outLen, int *endOffset);
-
-/*
- \todo unicode check
- */
-static void overlayRectInLine(const char *line, char *insLine,
- int rectStart, int rectEnd, int tabDist,
- int useTabs, char *outStr,
- int *outLen, int *endOffset);
-
-/*
- \todo unicode check
- */
-static void addPadding(char *string, int startIndent, int toIndent,
- int tabDist, int useTabs, int *charsAdded);
-
-/*
- \todo unicode check
- */
-static char *copyLine(const char *text, int *lineLen);
-
-/*
- unicode tested
- */
-static int countLines(const char *string);
-
-/*
- \todo unicode check
- */
-static int textWidth(const char *text, int tabDist);
-
-/*
- \todo unicode check
- */
-static char *realignTabs(const char *text, int origIndent, int newIndent,
- int tabDist, int useTabs, int *newLength);
-
-/*
- \todo unicode check
- */
-static char *expandTabs(const char *text, int startIndent, int tabDist, int *newLen);
+#ifndef min
/*
- \todo unicode check
+ Unicode safe.
*/
-static char *unexpandTabs(char *text, int startIndent, int tabDist, int *newLen);
-
-#ifndef min
-
static int max(int i1, int i2)
{
return i1 >= i2 ? i1 : i2;
}
+/*
+ Unicode safe.
+ */
static int min(int i1, int i2)
{
return i1 <= i2 ? i1 : i2;
@@ -131,12 +81,6 @@ static int min(int i1, int i2)
#endif
-static const char *ControlCodeTable[32] = {
- "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel",
- "bs", "ht", "nl", "vt", "np", "cr", "so", "si",
- "dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb",
- "can", "em", "sub", "esc", "fs", "gs", "rs", "us"
-};
static char *undobuffer;
static int undobufferlength;
@@ -146,6 +90,10 @@ 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
+/*
+ Resize the undo buffer to match at least the requested size.
+ Unicode safe.
+ */
static void undobuffersize(int n)
{
if (n > undobufferlength) {
@@ -162,7 +110,10 @@ static void undobuffersize(int n)
}
-// unicode ok
+/*
+ Initialize all variables.
+ Unicode safe.
+ */
Fl_Text_Buffer::Fl_Text_Buffer(int requestedSize, int preferredGapSize)
{
mLength = 0;
@@ -171,16 +122,12 @@ Fl_Text_Buffer::Fl_Text_Buffer(int requestedSize, int preferredGapSize)
mGapStart = 0;
mGapEnd = mPreferredGapSize;
mTabDist = 8;
- mUseTabs = 1;
mPrimary.mSelected = 0;
- mPrimary.mRectangular = 0;
mPrimary.mStart = mPrimary.mEnd = 0;
mSecondary.mSelected = 0;
mSecondary.mStart = mSecondary.mEnd = 0;
- mSecondary.mRectangular = 0;
mHighlight.mSelected = 0;
mHighlight.mStart = mHighlight.mEnd = 0;
- mHighlight.mRectangular = 0;
mModifyProcs = NULL;
mCbArgs = NULL;
mNModifyProcs = 0;
@@ -189,17 +136,13 @@ Fl_Text_Buffer::Fl_Text_Buffer(int requestedSize, int preferredGapSize)
mPredeleteCbArgs = NULL;
mCursorPosHint = 0;
mCanUndo = 1;
-#ifdef PURIFY
- {
- int i;
- for (i = mGapStart; i < mGapEnd; i++)
- mBuf[i] = '.';
}
-#endif
-}
-// unicode ok
+/*
+ Free all resources.
+ Unicode safe.
+ */
Fl_Text_Buffer::~Fl_Text_Buffer()
{
free(mBuf);
@@ -214,19 +157,24 @@ Fl_Text_Buffer::~Fl_Text_Buffer()
}
-// This function copies verbose whatever is in front and after the gap into a
-// single buffer.
-// - unicode ok
+/*
+ This function copies verbose whatever is in front and after the gap into a
+ single buffer.
+ Unicode safe.
+ */
char *Fl_Text_Buffer::text() const {
char *t = (char *) malloc(mLength + 1);
memcpy(t, mBuf, mGapStart);
- memcpy(&t[mGapStart], &mBuf[mGapEnd], mLength - mGapStart);
+ memcpy(t+mGapStart, mBuf+mGapEnd, mLength - mGapStart);
t[mLength] = '\0';
return t;
}
-// unicode ok, functions called have not been verified yet
+/*
+ Set the text buffer to a new string.
+ Unicode safe.
+ */
void Fl_Text_Buffer::text(const char *t)
{
call_predelete_callbacks(0, length());
@@ -243,13 +191,6 @@ void Fl_Text_Buffer::text(const char *t)
mGapStart = insertedLength;
mGapEnd = mGapStart + mPreferredGapSize;
memcpy(mBuf, t, insertedLength);
-#ifdef PURIFY
- {
- int i;
- for (i = mGapStart; i < mGapEnd; i++)
- mBuf[i] = '.';
- }
-#endif
/* Zero all of the existing selections */
update_selections(0, deletedLength, 0);
@@ -260,8 +201,10 @@ void Fl_Text_Buffer::text(const char *t)
}
-// Creates a new buffer and copies verbose from around the gap.
-// - unicode ok
+/*
+ Creates a range of text to a new buffer and copies verbose from around the gap.
+ Unicode safe.
+ */
char *Fl_Text_Buffer::text_range(int start, int end) const {
char *s = NULL;
@@ -285,22 +228,23 @@ char *Fl_Text_Buffer::text_range(int start, int end) const {
/* Copy the text from the buffer to the returned string */
if (end <= mGapStart) {
- memcpy(s, &mBuf[start], copiedLength);
+ memcpy(s, mBuf + start, copiedLength);
} else if (start >= mGapStart) {
- memcpy(s, &mBuf[start + (mGapEnd - mGapStart)], copiedLength);
+ memcpy(s, mBuf + start + (mGapEnd - mGapStart), copiedLength);
} else {
int part1Length = mGapStart - start;
- memcpy(s, &mBuf[start], part1Length);
- memcpy(&s[part1Length], &mBuf[mGapEnd], copiedLength - part1Length);
+ memcpy(s, mBuf + start, part1Length);
+ memcpy(s + part1Length, mBuf + mGapEnd, copiedLength - part1Length);
}
s[copiedLength] = '\0';
return s;
}
-
-// TODO: we will need the same signature function to get bytes (style buffer)
-// unicode ok
-unsigned int Fl_Text_Buffer::character(int pos) const {
+/*
+ Return a UCS-4 character at the given index.
+ Unicode safe. Pos must be at a character boundary.
+ */
+unsigned int Fl_Text_Buffer::char_at(int pos) const {
if (pos < 0 || pos >= mLength)
return '\0';
const char *src = address(pos);
@@ -308,9 +252,28 @@ unsigned int Fl_Text_Buffer::character(int pos) const {
}
-// unicode ok, dependents not tested
+/*
+ Return the raw byte at the given index.
+ This function ignores all unicode encoding.
+ */
+char Fl_Text_Buffer::byte_at(int pos) const {
+ if (pos < 0 || pos >= mLength)
+ return '\0';
+ const char *src = address(pos);
+ return *src;
+}
+
+
+/*
+ Insert some text at the given index.
+ Unicode safe. Pos must be at a character boundary.
+*/
void Fl_Text_Buffer::insert(int pos, const char *text)
{
+ /* check if there is actually any text */
+ if (!text || !*text)
+ return;
+
/* if pos is not contiguous to existing text, make it */
if (pos > mLength)
pos = mLength;
@@ -327,7 +290,10 @@ void Fl_Text_Buffer::insert(int pos, const char *text)
}
-// unicode ok, dependents not tested
+/*
+ Replace a range of text with new text.
+ Unicode safe. Start and end must be at a character boundary.
+*/
void Fl_Text_Buffer::replace(int start, int end, const char *text)
{
// Range check...
@@ -348,7 +314,10 @@ void Fl_Text_Buffer::replace(int start, int end, const char *text)
}
-// unicode ok, dependents not tested
+/*
+ Remove a range of text.
+ Unicode safe. Start and End must be at a character boundary.
+*/
void Fl_Text_Buffer::remove(int start, int end)
{
/* Make sure the arguments make sense */
@@ -378,6 +347,11 @@ void Fl_Text_Buffer::remove(int start, int end)
free((void *) deletedText);
}
+
+/*
+ Copy a range of text from another text buffer.
+ Unicode safe. FromDtart, fromEnd, and toPos must be at a character boundary.
+ */
void Fl_Text_Buffer::copy(Fl_Text_Buffer * fromBuf, int fromStart,
int fromEnd, int toPos)
{
@@ -398,8 +372,7 @@ void Fl_Text_Buffer::copy(Fl_Text_Buffer * fromBuf, int fromStart,
memcpy(&mBuf[toPos], &fromBuf->mBuf[fromStart], copiedLength);
} else if (fromStart >= fromBuf->mGapStart) {
memcpy(&mBuf[toPos],
- &fromBuf->mBuf[fromStart +
- (fromBuf->mGapEnd - fromBuf->mGapStart)],
+ &fromBuf->mBuf[fromStart + (fromBuf->mGapEnd - fromBuf->mGapStart)],
copiedLength);
} else {
int part1Length = fromBuf->mGapStart - fromStart;
@@ -412,6 +385,12 @@ void Fl_Text_Buffer::copy(Fl_Text_Buffer * fromBuf, int fromStart,
update_selections(toPos, 0, copiedLength);
}
+
+/*
+ Take the previous changes and undo them. Return the previous
+ cursor position in cursorPos. Returns 1 if the undo was applied.
+ Unicode safe. CursorPos will be at a character boundary.
+ */
int Fl_Text_Buffer::undo(int *cursorPos)
{
if (undowidget != this || !undocut && !undoinsert && !mCanUndo)
@@ -450,181 +429,27 @@ int Fl_Text_Buffer::undo(int *cursorPos)
}
-// unicode ok
+/*
+ Set a flag is undo function will work.
+ Unicode safe.
+ */
void Fl_Text_Buffer::canUndo(char flag)
{
mCanUndo = flag;
+ // disabeling undo also clears the last undo operation!
+ if (!mCanUndo && undowidget==this)
+ undowidget = 0;
}
-void Fl_Text_Buffer::insert_column(int column, int startPos,
- const char *text, int *charsInserted,
- int *charsDeleted)
-{
- int nLines = countLines(text);
- int lineStartPos = line_start(startPos);
- int nDeleted = line_end(skip_lines(startPos, nLines)) - lineStartPos;
- call_predelete_callbacks(lineStartPos, nDeleted);
- const char *deletedText =
- text_range(lineStartPos, lineStartPos + nDeleted);
- int insertDeleted, nInserted;
- insert_column_(column, lineStartPos, text, &insertDeleted, &nInserted,
- &mCursorPosHint);
- if (nDeleted != insertDeleted)
- Fl::error
- ("Fl_Text_Buffer::insert_column(): internal consistency check ins1 failed");
- call_modify_callbacks(lineStartPos, nDeleted, nInserted, 0, deletedText);
- free((void *) deletedText);
- if (charsInserted != NULL)
- *charsInserted = nInserted;
- if (charsDeleted != NULL)
- *charsDeleted = nDeleted;
-}
-
-void Fl_Text_Buffer::overlay_rectangular(int startPos, int rectStart,
- int rectEnd, const char *text,
- int *charsInserted,
- int *charsDeleted)
-{
-
- int nLines = countLines(text);
- int lineStartPos = line_start(startPos);
- int nDeleted = line_end(skip_lines(startPos, nLines)) - lineStartPos;
- call_predelete_callbacks(lineStartPos, nDeleted);
- const char *deletedText =
- text_range(lineStartPos, lineStartPos + nDeleted);
- int insertDeleted, nInserted;
- overlay_rectangular_(lineStartPos, rectStart, rectEnd, text,
- &insertDeleted, &nInserted, &mCursorPosHint);
- if (nDeleted != insertDeleted)
- Fl::error
- ("Fl_Text_Buffer::overlay_rectangle(): internal consistency check ovly1 failed");
- call_modify_callbacks(lineStartPos, nDeleted, nInserted, 0, deletedText);
- free((void *) deletedText);
- if (charsInserted != NULL)
- *charsInserted = nInserted;
- if (charsDeleted != NULL)
- *charsDeleted = nDeleted;
-}
-
-void Fl_Text_Buffer::replace_rectangular(int start, int end, int rectStart,
- int rectEnd, const char *text)
-{
- char *insText = (char *) "";
- int linesPadded = 0;
-
- /* Make sure start and end refer to complete lines, since the
- columnar delete and insert operations will replace whole lines */
- start = line_start(start);
- end = line_end(end);
-
- call_predelete_callbacks(start, end - start);
-
- /* If more lines will be deleted than inserted, pad the inserted text
- with newlines to make it as long as the number of deleted lines. This
- will indent all of the text to the right of the rectangle to the same
- column. If more lines will be inserted than deleted, insert extra
- lines in the buffer at the end of the rectangle to make room for the
- additional lines in "text" */
- int nInsertedLines = countLines(text);
- int nDeletedLines = count_lines(start, end);
- if (nInsertedLines < nDeletedLines) {
- int insLen = strlen(text);
- insText = (char *) malloc(insLen + nDeletedLines - nInsertedLines + 1);
- strcpy(insText, text);
- char *insPtr = insText + insLen;
- for (int i = 0; i < nDeletedLines - nInsertedLines; i++)
- *insPtr++ = '\n';
- *insPtr = '\0';
- } else if (nDeletedLines < nInsertedLines) {
- linesPadded = nInsertedLines - nDeletedLines;
- for (int i = 0; i < linesPadded; i++)
- insert_(end, "\n");
- }
-
- /* else nDeletedLines == nInsertedLines; */
- /* Save a copy of the text which will be modified for the modify CBs */
- const char *deletedText = text_range(start, end);
-
- /* Delete then insert */
- int insertDeleted, insertInserted, deleteInserted, hint;
- remove_rectangular_(start, end, rectStart, rectEnd, &deleteInserted,
- &hint);
- insert_column_(rectStart, start, insText, &insertDeleted,
- &insertInserted, &mCursorPosHint);
-
- /* Figure out how many chars were inserted and call modify callbacks */
- if (insertDeleted != deleteInserted + linesPadded)
- Fl::error
- ("Fl_Text_Buffer::replace_rectangular(): internal consistency check repl1 failed");
- call_modify_callbacks(start, end - start, insertInserted, 0,
- deletedText);
- free((void *) deletedText);
- if (nInsertedLines < nDeletedLines)
- free((void *) insText);
-}
-
-void Fl_Text_Buffer::remove_rectangular(int start, int end, int rectStart,
- int rectEnd)
-{
-
- start = line_start(start);
- end = line_end(end);
- call_predelete_callbacks(start, end - start);
- const char *deletedText = text_range(start, end);
- int nInserted;
- remove_rectangular_(start, end, rectStart, rectEnd, &nInserted,
- &mCursorPosHint);
- call_modify_callbacks(start, end - start, nInserted, 0, deletedText);
- free((void *) deletedText);
-}
-
-void Fl_Text_Buffer::clear_rectangular(int start, int end, int rectStart,
- int rectEnd)
-{
- int nLines = count_lines(start, end);
- char *newlineString = (char *) malloc(nLines + 1);
- int i;
- for (i = 0; i < nLines; i++)
- newlineString[i] = '\n';
- newlineString[i] = '\0';
- overlay_rectangular(start, rectStart, rectEnd, newlineString,
- NULL, NULL);
- free((void *) newlineString);
-}
-
-char *Fl_Text_Buffer::text_in_rectangle(int start, int end,
- int rectStart,
- int rectEnd) const {
- start = line_start(start);
- end = line_end(end);
- char *textOut = (char *) malloc((end - start) + 1);
- int lineStart = start;
- char *outPtr = textOut;
- int selLeft, selRight;
- while (lineStart <= end)
- {
- rectangular_selection_boundaries(lineStart, rectStart, rectEnd,
- &selLeft, &selRight);
- const char *textIn = text_range(selLeft, selRight);
- int len = selRight - selLeft;
- memcpy(outPtr, textIn, len);
- free((void *) textIn);
- outPtr += len;
- lineStart = line_end(selRight) + 1;
- *outPtr++ = '\n';
- } if (outPtr != textOut)
- outPtr--; /* don't leave trailing newline */
- *outPtr = '\0';
-
- /* If necessary, realign the tabs in the selection as if the text were
- positioned at the left margin */
- int len;
- char *retabbedStr = realignTabs(textOut, rectStart, 0, mTabDist,
- mUseTabs, &len);
- free((void *) textOut);
- return retabbedStr;
-}
+/*
+ Change the tab width. This will cause a couple of callbacks and a complete
+ redisplay.
+ Matt: I am not entirely sure why we need to trigger callbacks because
+ tabs are only a graphical hint, not changing any text at all, but I leave
+ this in here for back compatibility.
+ Unicode safe.
+ */
void Fl_Text_Buffer::tab_distance(int tabDist)
{
/* First call the pre-delete callbacks with the previous tab setting
@@ -641,6 +466,11 @@ void Fl_Text_Buffer::tab_distance(int tabDist)
free((void *) deletedText);
}
+
+/*
+ Select a range of text.
+ Unicode safe. Start and End must be at a character boundary.
+ */
void Fl_Text_Buffer::select(int start, int end)
{
Fl_Text_Selection oldSelection = mPrimary;
@@ -649,6 +479,11 @@ void Fl_Text_Buffer::select(int start, int end)
redisplay_selection(&oldSelection, &mPrimary);
}
+
+/*
+ Clear the primary selection.
+ Unicode safe.
+ */
void Fl_Text_Buffer::unselect()
{
Fl_Text_Selection oldSelection = mPrimary;
@@ -657,42 +492,51 @@ void Fl_Text_Buffer::unselect()
redisplay_selection(&oldSelection, &mPrimary);
}
-void Fl_Text_Buffer::select_rectangular(int start, int end, int rectStart,
- int rectEnd)
-{
- Fl_Text_Selection oldSelection = mPrimary;
- mPrimary.set_rectangular(start, end, rectStart, rectEnd);
- redisplay_selection(&oldSelection, &mPrimary);
-}
-
+/*
+ Return the primary selection range.
+ Unicode safe.
+ */
int Fl_Text_Buffer::selection_position(int *start, int *end)
{
return mPrimary.position(start, end);
}
-int Fl_Text_Buffer::selection_position(int *start, int *end,
- int *isRect, int *rectStart,
- int *rectEnd)
-{
- return mPrimary.position(start, end, isRect, rectStart, rectEnd);
-}
+/*
+ Return a copy of the selected text.
+ Unicode safe.
+ */
char *Fl_Text_Buffer::selection_text()
{
return selection_text_(&mPrimary);
}
+
+/*
+ Remove the selected text.
+ Unicode safe.
+ */
void Fl_Text_Buffer::remove_selection()
{
remove_selection_(&mPrimary);
}
+
+/*
+ Replace the selected text.
+ Unicode safe.
+ */
void Fl_Text_Buffer::replace_selection(const char *text)
{
replace_selection_(&mPrimary, text);
}
+
+/*
+ Select text.
+ Unicode safe. Start and End must be at a character boundary.
+ */
void Fl_Text_Buffer::secondary_select(int start, int end)
{
Fl_Text_Selection oldSelection = mSecondary;
@@ -701,6 +545,11 @@ void Fl_Text_Buffer::secondary_select(int start, int end)
redisplay_selection(&oldSelection, &mSecondary);
}
+
+/*
+ Deselect text.
+ Unicode safe.
+ */
void Fl_Text_Buffer::secondary_unselect()
{
Fl_Text_Selection oldSelection = mSecondary;
@@ -709,44 +558,51 @@ void Fl_Text_Buffer::secondary_unselect()
redisplay_selection(&oldSelection, &mSecondary);
}
-void Fl_Text_Buffer::secondary_select_rectangular(int start, int end,
- int rectStart,
- int rectEnd)
-{
- Fl_Text_Selection oldSelection = mSecondary;
- mSecondary.set_rectangular(start, end, rectStart, rectEnd);
- redisplay_selection(&oldSelection, &mSecondary);
-}
-
+/*
+ Return the selected range.
+ Unicode safe.
+ */
int Fl_Text_Buffer::secondary_selection_position(int *start, int *end)
{
return mSecondary.position(start, end);
}
-int Fl_Text_Buffer::secondary_selection_position(int *start, int *end,
- int *isRect,
- int *rectStart,
- int *rectEnd)
-{
- return mSecondary.position(start, end, isRect, rectStart, rectEnd);
-}
+/*
+ Return a copy of the text in this selection.
+ Unicode safe.
+ */
char *Fl_Text_Buffer::secondary_selection_text()
{
return selection_text_(&mSecondary);
}
+
+/*
+ Remove the selected text.
+ Unicode safe.
+ */
void Fl_Text_Buffer::remove_secondary_selection()
{
remove_selection_(&mSecondary);
}
+
+/*
+ Replace selected text.
+ Unicode safe.
+ */
void Fl_Text_Buffer::replace_secondary_selection(const char *text)
{
replace_selection_(&mSecondary, text);
}
+
+/*
+ Highlight a range of text.
+ Unicode safe. Start and End must be at a character boundary.
+ */
void Fl_Text_Buffer::highlight(int start, int end)
{
Fl_Text_Selection oldSelection = mHighlight;
@@ -755,6 +611,11 @@ void Fl_Text_Buffer::highlight(int start, int end)
redisplay_selection(&oldSelection, &mHighlight);
}
+
+/*
+ Remove text highlighting.
+ Unicode safe.
+ */
void Fl_Text_Buffer::unhighlight()
{
Fl_Text_Selection oldSelection = mHighlight;
@@ -763,32 +624,31 @@ void Fl_Text_Buffer::unhighlight()
redisplay_selection(&oldSelection, &mHighlight);
}
-void Fl_Text_Buffer::highlight_rectangular(int start, int end,
- int rectStart, int rectEnd)
-{
- Fl_Text_Selection oldSelection = mHighlight;
- mHighlight.set_rectangular(start, end, rectStart, rectEnd);
- redisplay_selection(&oldSelection, &mHighlight);
-}
-
+/*
+ Return position of highlight.
+ Unicode safe.
+ */
int Fl_Text_Buffer::highlight_position(int *start, int *end)
{
return mHighlight.position(start, end);
}
-int Fl_Text_Buffer::highlight_position(int *start, int *end,
- int *isRect, int *rectStart,
- int *rectEnd)
-{
- return mHighlight.position(start, end, isRect, rectStart, rectEnd);
-}
+/*
+ Return a copy of highlighted text.
+ Unicode safe.
+ */
char *Fl_Text_Buffer::highlight_text()
{
return selection_text_(&mHighlight);
}
+
+/*
+ Add a callback that is called whenever text is modified.
+ Unicode safe.
+ */
void Fl_Text_Buffer::add_modify_callback(Fl_Text_Modify_Cb bufModifiedCB,
void *cbArg)
{
@@ -810,8 +670,13 @@ void Fl_Text_Buffer::add_modify_callback(Fl_Text_Modify_Cb bufModifiedCB,
mCbArgs = newCBArgs;
}
-void Fl_Text_Buffer::
-remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void *cbArg)
+
+/*
+ Remove a callback.
+ Unicode safe.
+ */
+void Fl_Text_Buffer::remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB,
+ void *cbArg)
{
int i, toRemove = -1;
@@ -857,8 +722,13 @@ remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void *cbArg)
mCbArgs = newCBArgs;
}
-void Fl_Text_Buffer::
-add_predelete_callback(Fl_Text_Predelete_Cb bufPreDeleteCB, void *cbArg)
+
+/*
+ Add a callback that is called before deleting text.
+ Unicode safe.
+ */
+void Fl_Text_Buffer::add_predelete_callback(Fl_Text_Predelete_Cb bufPreDeleteCB,
+ void *cbArg)
{
Fl_Text_Predelete_Cb *newPreDeleteProcs =
new Fl_Text_Predelete_Cb[mNPredeleteProcs + 1];
@@ -878,8 +748,12 @@ add_predelete_callback(Fl_Text_Predelete_Cb bufPreDeleteCB, void *cbArg)
mPredeleteCbArgs = newCBArgs;
}
-void Fl_Text_Buffer::
-remove_predelete_callback(Fl_Text_Predelete_Cb bufPreDeleteCB, void *cbArg)
+
+/*
+ Remove a callback.
+ Unicode safe.
+ */
+void Fl_Text_Buffer::remove_predelete_callback(Fl_Text_Predelete_Cb bufPreDeleteCB, void *cbArg)
{
int i, toRemove = -1;
/* find the matching callback to remove */
@@ -926,156 +800,99 @@ remove_predelete_callback(Fl_Text_Predelete_Cb bufPreDeleteCB, void *cbArg)
mPredeleteCbArgs = newCBArgs;
}
+
+/*
+ Return a copy of the line that contains a given index.
+ Unicode safe. Pos must be at a character boundary.
+ */
char *Fl_Text_Buffer::line_text(int pos) const {
return text_range(line_start(pos), line_end(pos));
}
-int Fl_Text_Buffer::line_start(int pos) const {
+
+/*
+ Find the beginning of the line.
+ NOT UNICODE SAFE.
+ */
+int Fl_Text_Buffer::line_start(int pos) const
+{
+ // FIXME: this currently works for unicode, but will be very inefficent when findchar_backward is fixed.
if (!findchar_backward(pos, '\n', &pos))
return 0;
return pos + 1;
}
+
+/*
+ Find the end of the line.
+ NOT UNICODE SAFE.
+ */
int Fl_Text_Buffer::line_end(int pos) const {
+ // FIXME: this currently works for unicode, but will be very inefficent when findchar_forward is fixed.
if (!findchar_forward(pos, '\n', &pos))
pos = mLength;
return pos;
}
+
+/*
+ Find the beginning of a word.
+ NOT UNICODE SAFE.
+ */
int Fl_Text_Buffer::word_start(int pos) const {
// FIXME: character is ucs-4
- while (pos && (isalnum(character(pos)) || character(pos) == '_')) {
+ while (pos && (isalnum(char_at(pos)) || char_at(pos) == '_')) {
pos--;
}
// FIXME: character is ucs-4
- if (!(isalnum(character(pos)) || character(pos) == '_'))
+ if (!(isalnum(char_at(pos)) || char_at(pos) == '_'))
pos++;
return pos;
}
+
+/*
+ Find the end of a word.
+ NOT UNICODE SAFE.
+ */
int Fl_Text_Buffer::word_end(int pos) const {
// FIXME: character is ucs-4
- while (pos < length() && (isalnum(character(pos)) || character(pos) == '_'))
+ while (pos < length() && (isalnum(char_at(pos)) || char_at(pos) == '_'))
{
pos++;
} return pos;
}
-// Expand from the byte representation into some readable text.
-// Under unicode, this is not really needed because all characters should
-// be prinatble one way or the other. But since we use this to (badly) simulate
-// tabs, we can leave this here anyway.
-// - unicode ok
-int Fl_Text_Buffer::expand_character(int pos, int indent, char *outStr) const {
- const char *src = address(pos);
- return expand_character(src, indent, outStr, mTabDist);
-}
-
-
-// static function and counterpart to "character_width"
-// - unicode ok
-// FIXME: harmonise with new character_width(char*...) version
-//
-int Fl_Text_Buffer::expand_character(const char *src, int indent, char *outStr, int tabDist)
-{
- char c = *src;
- /* Convert tabs to spaces */
- if (c == '\t') {
- int nSpaces = tabDist - (indent % tabDist);
- for (int i = 0; i < nSpaces; i++)
- outStr[i] = ' ';
- return nSpaces;
- }
-
- /* Convert control codes to readable character sequences */
- if (((unsigned char) c) <= 31) {
- sprintf(outStr, "<%s>", ControlCodeTable[(unsigned char) c]);
- return strlen(outStr);
- } else if (c == 127) {
- sprintf(outStr, "<del>");
- return 5;
- } else if ((c & 0x80) && !(c & 0x40)) {
-#ifdef DEBUG
- fprintf(stderr, "%s:%d - Error in UTF-8 encoding!\n", __FILE__, __LINE__);
-#endif
- *outStr = c;
- return 1;
- } else if (c & 0x80) {
- int i, n = fl_utf8len(c);
- for (i=0; i<n; i++) *outStr++ = *src++;
- return n;
- }
-
- /* Otherwise, just return the character */
- *outStr = c;
- return 1;
-}
-
-
-// This function takes a character and optionally converts it into a little
-// string which will replace the character on screen. This function returns
-// the number of bytes in the replacement string, but *not* the number of
-// bytes in the original character!
-// - unicode ok
-int Fl_Text_Buffer::character_width(const char *src, int indent, int tabDist)
-{
- char c = *src;
- if ((c & 0x80) && (c & 0x40)) { // first byte of UTF-8 sequence
- int len = fl_utf8len(c);
- int ret = 0;
- unsigned int ucs = fl_utf8decode(src, src+len, &ret);
- int width = fl_wcwidth_(ucs); // FIXME
- // fprintf(stderr, "mk_wcwidth(%x) -> %d (%d, %d, %s)\n", ucs, width, len, ret, src);
- return width;
- }
- if ((c & 0x80) && !(c & 0x40)) { // other byte of UTF-8 sequence
- return 0;
- }
- return character_width(c, indent, tabDist);
-}
-
-// FIXME: merge the following with the char* version above.
-// but the question then is: how to reorganise expand_character()?
-//
-int Fl_Text_Buffer::character_width(const char c, int indent, int tabDist)
-{
- /* Note, this code must parallel that in Fl_Text_Buffer::ExpandCharacter */
- if (c == '\t') {
- return tabDist - (indent % tabDist);
- } else if (((unsigned char) c) <= 31) {
- return strlen(ControlCodeTable[(unsigned char) c]) + 2;
- } else if (c == 127) {
- return 5;
- } else if ((c & 0x80) && !(c & 0x40)) {
-#ifdef DEBUG
- fprintf(stderr, "%s:%d - Error in UTF-8 encoding!\n", __FILE__, __LINE__);
-#endif
- return 1;
- } else if (c & 0x80) {
- // return fl_utf8len(c);
- return 1;
- }
- return 1;
-}
-
+/*
+ Matt: I am not sure why we need this function. Does it still make sense in
+ the world of proportional characters?
+ */
int Fl_Text_Buffer::count_displayed_characters(int lineStartPos,
int targetPos) const
{
+ // TODO: is this function still needed? If it is, put this functionality in handle_vline?
int charCount = 0;
- char expandedChar[FL_TEXT_MAX_EXP_CHAR_LEN];
int pos = lineStartPos;
- while (pos < targetPos)
- charCount += expand_character(pos++, charCount, expandedChar);
+ while (pos < targetPos) {
+ int len = fl_utf8len(*address(pos));
+ charCount += 1;
+ pos += len;
+ }
return charCount;
}
+/*
+ Matt: I am not sure why we need this function. Does it still make sense in
+ the world of proportional characters?
+ */
// All values are number of bytes.
-// - unicode ok
+// - unicode ok?
int Fl_Text_Buffer::skip_displayed_characters(int lineStartPos, int nChars)
{
+ // FIXME: is this function still needed?
int pos = lineStartPos;
for (int charCount = 0; charCount < nChars && pos < mLength;) {
@@ -1083,12 +900,17 @@ int Fl_Text_Buffer::skip_displayed_characters(int lineStartPos, int nChars)
char c = *src;
if (c == '\n')
return pos;
- charCount += character_width(src, charCount, mTabDist);
+ charCount++;
pos += fl_utf8len(c);
}
return pos;
}
+
+/*
+ Count the number of newline characters between start and end.
+ Unicode safe. StartPos and endPos must be at a character boundary.
+ */
int Fl_Text_Buffer::count_lines(int startPos, int endPos) const {
int gapLen = mGapEnd - mGapStart;
int lineCount = 0;
@@ -1100,7 +922,8 @@ int Fl_Text_Buffer::count_lines(int startPos, int endPos) const {
return lineCount;
if (mBuf[pos++] == '\n')
lineCount++;
- } while (pos < mLength) {
+ }
+ while (pos < mLength) {
if (pos == endPos)
return lineCount;
if (mBuf[pos++ + gapLen] == '\n')
@@ -1109,6 +932,11 @@ int Fl_Text_Buffer::count_lines(int startPos, int endPos) const {
return lineCount;
}
+
+/*
+ Skip to the first character, n lines ahead.
+ Unicode safe. StartPos must be at a character boundary.
+ */
int Fl_Text_Buffer::skip_lines(int startPos, int nLines)
{
if (nLines == 0)
@@ -1134,6 +962,11 @@ int Fl_Text_Buffer::skip_lines(int startPos, int nLines)
return pos;
}
+
+/*
+ Skip to the first character, n lines back.
+ Unicode safe. StartPos must be at a character boundary.
+ */
int Fl_Text_Buffer::rewind_lines(int startPos, int nLines)
{
int pos = startPos - 1;
@@ -1159,10 +992,15 @@ int Fl_Text_Buffer::rewind_lines(int startPos, int nLines)
return 0;
}
+
+/*
+ Find a matching string in the buffer.
+ NOT TESTED FOR UNICODE.
+ */
int Fl_Text_Buffer::search_forward(int startPos, const char *searchString,
- int *foundPos,
- int matchCase) const
+ int *foundPos, int matchCase) const
{
+ // FIXME: Unicode?
if (!searchString)
return 0;
int bp;
@@ -1176,17 +1014,22 @@ int Fl_Text_Buffer::search_forward(int startPos, const char *searchString,
return 1;
}
// FIXME: character is ucs-4
- } while ((matchCase ? character(bp++) == *sp++ :
- toupper(character(bp++)) == toupper(*sp++))
+ } while ((matchCase ? char_at(bp++) == (unsigned int)*sp++ :
+ toupper(char_at(bp++)) == toupper(*sp++))
&& bp < length());
startPos++;
}
return 0;
}
+
+/*
+ Find a matching string in the buffer.
+ NOT TESTED FOR UNICODE.
+ */
int Fl_Text_Buffer::search_backward(int startPos, const char *searchString,
- int *foundPos,
- int matchCase) const {
+ int *foundPos, int matchCase) const {
+ // FIXME: Unicode?
if (!searchString)
return 0;
int bp;
@@ -1201,17 +1044,22 @@ int Fl_Text_Buffer::search_backward(int startPos, const char *searchString,
return 1;
}
// FIXME: character is ucs-4
- } while ((matchCase ? character(bp--) == *sp-- :
- toupper(character(bp--)) == toupper(*sp--))
+ } while ((matchCase ? char_at(bp--) == (unsigned int)*sp-- :
+ toupper(char_at(bp--)) == toupper(*sp--))
&& bp >= 0);
startPos--;
}
return 0;
}
-int Fl_Text_Buffer::findchars_forward(int startPos,
- const char *searchChars,
+
+/*
+ Find a matching string in the buffer.
+ NOT TESTED FOR UNICODE.
+ */
+int Fl_Text_Buffer::findchars_forward(int startPos, const char *searchChars,
int *foundPos) const {
+ // FIXME: unicode?
int gapLen = mGapEnd - mGapStart;
const char *c;
@@ -1238,9 +1086,14 @@ int Fl_Text_Buffer::findchars_forward(int startPos,
return 0;
}
-int Fl_Text_Buffer::findchars_backward(int startPos,
- const char *searchChars,
+
+/*
+ Find a matching string in the buffer.
+ NOT TESTED FOR UNICODE.
+ */
+int Fl_Text_Buffer::findchars_backward(int startPos, const char *searchChars,
int *foundPos) const {
+ // FIXME: Unicode
int gapLen = mGapEnd - mGapStart;
const char *c;
@@ -1272,8 +1125,16 @@ int Fl_Text_Buffer::findchars_backward(int startPos,
return 0;
}
+
+/*
+ Insert a string into the buffer.
+ Unicode safe. Pos must be at a character boundary. Text must be a correct utf8 string.
+ */
int Fl_Text_Buffer::insert_(int pos, const char *text)
{
+ if (!text || !*text)
+ return 0;
+
int insertedLength = strlen(text);
/* Prepare the buffer to receive the new text. If the new text fits in
@@ -1307,6 +1168,11 @@ int Fl_Text_Buffer::insert_(int pos, const char *text)
return insertedLength;
}
+
+/*
+ Remove a string from the buffer.
+ Unicode safe. Start and end must be at a character boundary.
+ */
void Fl_Text_Buffer::remove_(int start, int end)
{
/* if the gap is not contiguous to the area to remove, move it there */
@@ -1354,458 +1220,23 @@ void Fl_Text_Buffer::remove_(int start, int end)
update_selections(start, end - start, 0);
}
-void Fl_Text_Buffer::insert_column_(int column, int startPos,
- const char *insText, int *nDeleted,
- int *nInserted, int *endPos)
-{
- if (column < 0)
- column = 0;
-
- /* Allocate a buffer for the replacement string large enough to hold
- possibly expanded tabs in both the inserted text and the replaced
- area, as well as per line: 1) an additional 2*FL_TEXT_MAX_EXP_CHAR_LEN
- characters for padding where tabs and control characters cross the
- column of the selection, 2) up to "column" additional spaces per
- line for padding out to the position of "column", 3) padding up
- to the width of the inserted text if that must be padded to align
- the text beyond the inserted column. (Space for additional
- newlines if the inserted text extends beyond the end of the buffer
- is counted with the length of insText) */
- int start = line_start(startPos);
- int nLines = countLines(insText) + 1;
- int insWidth = textWidth(insText, mTabDist); // this function probably returns a useless value
- int end = line_end(skip_lines(start, nLines - 1));
- int expReplLen, expInsLen, len, endOffset;
- const char *replText = text_range(start, end);
- char *expText = expandTabs(replText, 0, mTabDist, &expReplLen);
- free((void *) replText);
- free((void *) expText);
- expText = expandTabs(insText, 0, mTabDist, &expInsLen);
- free((void *) expText);
- char *outStr = (char *) malloc(expReplLen + expInsLen +
- nLines * (column + insWidth +
- FL_TEXT_MAX_EXP_CHAR_LEN) + 1);
-
- /* Loop over all lines in the buffer between start and end removing the
- text between rectStart and rectEnd and padding appropriately. Trim
- trailing space from line (whitespace at the ends of lines otherwise
- tends to multiply, since additional padding is added to maintain it */
- char *outPtr = outStr, *insLine;
- const char *insPtr = insText, *line;
- for (int lineStart = start, lineEnd;;) {
- lineEnd = line_end(lineStart);
- line = text_range(lineStart, lineEnd);
- insLine = copyLine(insPtr, &len);
- insPtr += len;
- insertColInLine(line, insLine, column, insWidth, mTabDist,
- mUseTabs, outPtr, &len, &endOffset);
- free((void *) line);
- free((void *) insLine);
- for (const char *c = outPtr + len - 1; c > outPtr && isspace(*c); c--)
- len--;
- outPtr += len;
- *outPtr++ = '\n';
- lineStart = lineEnd < mLength ? lineEnd + 1 : mLength;
- if (*insPtr == '\0')
- break;
- insPtr++;
- }
- if (outPtr != outStr)
- outPtr--; /* trim back off extra newline */
- *outPtr = '\0';
- /* replace the text between start and end with the new stuff */
- remove_(start, end);
- insert_(start, outStr);
- *nInserted = outPtr - outStr;
- *nDeleted = end - start;
- *endPos = start + (outPtr - outStr) - len + endOffset;
- free((void *) outStr);
-}
-
-void Fl_Text_Buffer::remove_rectangular_(int start, int end, int rectStart,
- int rectEnd, int *replaceLen,
- int *endPos)
-{
- /* allocate a buffer for the replacement string large enough to hold
- possibly expanded tabs as well as an additional FL_TEXT_MAX_EXP_CHAR_LEN * 2
- characters per line for padding where tabs and control characters cross
- the edges of the selection */
- start = line_start(start);
- end = line_end(end);
- int nLines = count_lines(start, end) + 1;
- const char *s = text_range(start, end);
- int len;
- char *expText = expandTabs(s, 0, mTabDist, &len);
- free((void *) s);
- free((void *) expText);
- char *outStr =
- (char *) malloc(len + nLines * FL_TEXT_MAX_EXP_CHAR_LEN * 2 + 1);
-
- /* loop over all lines in the buffer between start and end removing
- the text between rectStart and rectEnd and padding appropriately */
- int endOffset = 0;
- char *outPtr = outStr;
- const char *line;
- for (int lineStart = start, lineEnd;
- lineStart <= mLength && lineStart <= end;) {
- lineEnd = line_end(lineStart);
- line = text_range(lineStart, lineEnd);
- deleteRectFromLine(line, rectStart, rectEnd, mTabDist,
- mUseTabs, outPtr, &len, &endOffset);
- free((void *) line);
- outPtr += len;
- *outPtr++ = '\n';
- lineStart = lineEnd + 1;
- }
- if (outPtr != outStr)
- outPtr--; /* trim back off extra newline */
- *outPtr = '\0';
-
- /* replace the text between start and end with the newly created string */
- remove_(start, end);
- insert_(start, outStr);
- *replaceLen = outPtr - outStr;
- *endPos = start + (outPtr - outStr) - len + endOffset;
- free((void *) outStr);
-}
-
-void Fl_Text_Buffer::overlay_rectangular_(int startPos, int rectStart,
- int rectEnd, const char *insText,
- int *nDeleted, int *nInserted,
- int *endPos)
-{
-
- /* Allocate a buffer for the replacement string large enough to hold
- possibly expanded tabs in the inserted text, as well as per line: 1)
- an additional 2*FL_TEXT_MAX_EXP_CHAR_LEN characters for padding where tabs
- and control characters cross the column of the selection, 2) up to
- "column" additional spaces per line for padding out to the position
- of "column", 3) padding up to the width of the inserted text if that
- must be padded to align the text beyond the inserted column. (Space
- for additional newlines if the inserted text extends beyond the end
- of the buffer is counted with the length of insText) */
- int start = line_start(startPos);
- int nLines = countLines(insText) + 1;
- int end = line_end(skip_lines(start, nLines - 1)), expInsLen;
- char *expText = expandTabs(insText, 0, mTabDist, &expInsLen);
- free((void *) expText);
- char *outStr = (char *) malloc(end - start + expInsLen +
- nLines * (rectEnd +
- FL_TEXT_MAX_EXP_CHAR_LEN) + 1);
-
- /* Loop over all lines in the buffer between start and end overlaying the
- text between rectStart and rectEnd and padding appropriately. Trim
- trailing space from line (whitespace at the ends of lines otherwise
- tends to multiply, since additional padding is added to maintain it */
- int len, endOffset;
- char *outPtr = outStr, *insLine;
- const char *insPtr = insText, *line;
- for (int lineStart = start, lineEnd;;) {
- lineEnd = line_end(lineStart);
- line = text_range(lineStart, lineEnd);
- insLine = copyLine(insPtr, &len);
- insPtr += len;
- overlayRectInLine(line, insLine, rectStart, rectEnd, mTabDist,
- mUseTabs, outPtr, &len, &endOffset);
- free((void *) line);
- free((void *) insLine);
- for (const char *c = outPtr + len - 1; c > outPtr && isspace(*c); c--)
- len--;
- outPtr += len;
- *outPtr++ = '\n';
- lineStart = lineEnd < mLength ? lineEnd + 1 : mLength;
- if (*insPtr == '\0')
- break;
- insPtr++;
- }
- if (outPtr != outStr)
- outPtr--; /* trim back off extra newline */
- *outPtr = '\0';
-
- /* replace the text between start and end with the new stuff */
- remove_(start, end);
- insert_(start, outStr);
- *nInserted = outPtr - outStr;
- *nDeleted = end - start;
- *endPos = start + (outPtr - outStr) - len + endOffset;
- free((void *) outStr);
-}
-
/*
- Inserts characters from single-line string \p insLine in single-line string
- \p line at \p column, leaving \p insWidth space before continuing line.
- \p outLen returns the number of characters written to \p outStr, \p endOffset
- returns the number of characters from the beginning of the string to
- the right edge of the inserted text (as a hint for routines which need
- to position the cursor).
+ simple setter.
+ Unicode safe. Start and end must be at a character boundary.
*/
-static void insertColInLine(const char *line, char *insLine, int column,
- int insWidth, int tabDist, int useTabs,
- char *outStr, int *outLen,
- int *endOffset)
-{
- /* copy the line up to "column" */
- char *outPtr = outStr;
- int indent = 0, len;
- const char *linePtr;
-
- for (linePtr = line; *linePtr != '\0'; linePtr++) {
- len = Fl_Text_Buffer::character_width(linePtr, indent, tabDist);
- if (indent + len > column)
- break;
- indent += len;
- *outPtr++ = *linePtr;
- }
-
- /* If "column" falls in the middle of a character, and the character is a
- tab, leave it off and leave the indent short and it will get padded
- later. If it's a control character, insert it and adjust indent
- accordingly. */
- int postColIndent;
- if (indent < column && *linePtr != '\0') {
- postColIndent = indent + len;
- if (*linePtr == '\t')
- linePtr++;
- else {
- *outPtr++ = *linePtr++;
- indent += len;
- }
- } else
- postColIndent = indent;
-
- /* If there's no text after the column and no text to insert, that's all */
- if (*insLine == '\0' && *linePtr == '\0') {
- *outLen = *endOffset = outPtr - outStr;
- return;
- }
-
- /* pad out to column if text is too short */
- if (indent < column) {
- addPadding(outPtr, indent, column, tabDist, useTabs, &len);
- outPtr += len;
- indent = column;
- }
-
- /* Copy the text from "insLine" (if any), recalculating the tabs as if
- the inserted string began at column 0 to its new column destination */
- if (*insLine != '\0') {
- char *retabbedStr = realignTabs(insLine, 0, indent, tabDist, useTabs,
- &len);
- for (const char *c = retabbedStr; *c != '\0'; c++) {
- *outPtr++ = *c;
- len = Fl_Text_Buffer::character_width(c, indent, tabDist);
- indent += len;
- }
- free((void *) retabbedStr);
- }
-
- /* If the original line did not extend past "column", that's all */
- if (*linePtr == '\0') {
- *outLen = *endOffset = outPtr - outStr;
- return;
- }
-
- /* Pad out to column + width of inserted text + (additional original
- offset due to non-breaking character at column) */
- int toIndent = column + insWidth + postColIndent - column;
- addPadding(outPtr, indent, toIndent, tabDist, useTabs, &len);
- outPtr += len;
- indent = toIndent;
-
- /* realign tabs for text beyond "column" and write it out */
- char *retabbedStr = realignTabs(linePtr, postColIndent, indent, tabDist,
- useTabs, &len);
- strcpy(outPtr, retabbedStr);
- free((void *) retabbedStr);
- *endOffset = outPtr - outStr;
- *outLen = (outPtr - outStr) + len;
-}
-
-/**
- Removes characters in single-line string \p line between displayed positions
- \p rectStart and \p rectEnd, and write the result to \p outStr, which is
- assumed to be large enough to hold the returned string. Note that in
- certain cases, it is possible for the string to get longer due to
- expansion of tabs. \p endOffset returns the number of characters from
- the beginning of the string to the point where the characters were
- deleted (as a hint for routines which need to position the cursor).
- */
-static void deleteRectFromLine(const char *line, int rectStart,
- int rectEnd, int tabDist, int useTabs,
- char *outStr,
- int *outLen, int *endOffset)
-{
-
- /* copy the line up to rectStart */
- char *outPtr = outStr;
- int indent = 0, len;
- const char *c;
- for (c = line; *c != '\0'; c++) {
- if (indent > rectStart)
- break;
- len = Fl_Text_Buffer::character_width(c, indent, tabDist);
- if (indent + len > rectStart && (indent == rectStart || *c == '\t'))
- break;
- indent += len;
- *outPtr++ = *c;
- }
- int preRectIndent = indent;
-
- /* skip the characters between rectStart and rectEnd */
- for (; *c != '\0' && indent < rectEnd; c++)
- indent += Fl_Text_Buffer::character_width(c, indent, tabDist);
- int postRectIndent = indent;
-
- /* If the line ended before rectEnd, there's nothing more to do */
- if (*c == '\0') {
- *outPtr = '\0';
- *outLen = *endOffset = outPtr - outStr;
- return;
- }
-
- /* fill in any space left by removed tabs or control characters
- which straddled the boundaries */
- indent = max(rectStart + postRectIndent - rectEnd, preRectIndent);
- addPadding(outPtr, preRectIndent, indent, tabDist, useTabs, &len);
- outPtr += len;
-
- /* Copy the rest of the line. If the indentation has changed, preserve
- the position of non-whitespace characters by converting tabs to
- spaces, then back to tabs with the correct offset */
- char *retabbedStr =
- realignTabs(c, postRectIndent, indent, tabDist, useTabs, &len);
- strcpy(outPtr, retabbedStr);
- free((void *) retabbedStr);
- *endOffset = outPtr - outStr;
- *outLen = (outPtr - outStr) + len;
-}
-
-/**
- Overlay characters from single-line string \p insLine on single-line string
- \p line between displayed character offsets \p rectStart and \p rectEnd.
- \p outLen returns the number of characters written to \p outStr, \p endOffset
- returns the number of characters from the beginning of the string to
- the right edge of the inserted text (as a hint for routines which need
- to position the cursor).
- */
-static void overlayRectInLine(const char *line, char *insLine,
- int rectStart, int rectEnd, int tabDist,
- int useTabs, char *outStr,
- int *outLen, int *endOffset)
-{
- /* copy the line up to "rectStart" */
- char *outPtr = outStr;
- int inIndent = 0, outIndent = 0, len;
- const char *linePtr = line;
-
- for (; *linePtr != '\0'; linePtr++) {
- len = Fl_Text_Buffer::character_width(linePtr, inIndent, tabDist);
- if (inIndent + len > rectStart)
- break;
- inIndent += len;
- outIndent += len;
- *outPtr++ = *linePtr;
- }
-
- /* If "rectStart" falls in the middle of a character, and the character
- is a tab, leave it off and leave the outIndent short and it will get
- padded later. If it's a control character, insert it and adjust
- outIndent accordingly. */
- if (inIndent < rectStart && *linePtr != '\0') {
- if (*linePtr == '\t') {
- linePtr++;
- inIndent += len;
- } else {
- *outPtr++ = *linePtr++;
- outIndent += len;
- inIndent += len;
- }
- }
-
- /* skip the characters between rectStart and rectEnd */
- int postRectIndent = rectEnd;
- for (; *linePtr != '\0'; linePtr++) {
- inIndent += Fl_Text_Buffer::character_width(linePtr, inIndent, tabDist);
- if (inIndent >= rectEnd) {
- linePtr++;
- postRectIndent = inIndent;
- break;
- }
- }
-
- /* If there's no text after rectStart and no text to insert, that's all */
- if (*insLine == '\0' && *linePtr == '\0') {
- *outLen = *endOffset = outPtr - outStr;
- return;
- }
-
- /* pad out to rectStart if text is too short */
- if (outIndent < rectStart) {
- addPadding(outPtr, outIndent, rectStart, tabDist, useTabs, &len);
- outPtr += len;
- }
- outIndent = rectStart;
-
- /* Copy the text from "insLine" (if any), recalculating the tabs as if
- the inserted string began at column 0 to its new column destination */
- if (*insLine != '\0') {
- char *retabbedStr =
- realignTabs(insLine, 0, rectStart, tabDist, useTabs, &len);
- for (const char *c = retabbedStr; *c != '\0'; c++) {
- *outPtr++ = *c;
- len = Fl_Text_Buffer::character_width(c, outIndent, tabDist);
- outIndent += len;
- }
- free((void *) retabbedStr);
- }
-
- /* If the original line did not extend past "rectStart", that's all */
- if (*linePtr == '\0') {
- *outLen = *endOffset = outPtr - outStr;
- return;
- }
-
- /* Pad out to rectEnd + (additional original offset
- due to non-breaking character at right boundary) */
- addPadding(outPtr, outIndent, postRectIndent, tabDist, useTabs, &len);
- outPtr += len;
- outIndent = postRectIndent;
-
- /* copy the text beyond "rectEnd" */
- strcpy(outPtr, linePtr);
- *endOffset = outPtr - outStr;
- *outLen = (outPtr - outStr) + strlen(linePtr);
-}
-
-
-// simple setter
-// Unicode safe
void Fl_Text_Selection::set(int startpos, int endpos)
{
mSelected = startpos != endpos;
- mRectangular = 0;
mStart = min(startpos, endpos);
mEnd = max(startpos, endpos);
}
-// simple setter
-// Unicode safe
-void Fl_Text_Selection::set_rectangular(int startpos, int endpos,
- int rectStart, int rectEnd)
-{
- mSelected = rectStart < rectEnd;
- mRectangular = 1;
- mStart = startpos;
- mEnd = endpos;
- mRectStart = rectStart;
- mRectEnd = rectEnd;
-}
-
-
-// simple getter
-// Unicode safe
+/*
+ simple getter.
+ Unicode safe. Start and end will be at a character boundary.
+ */
int Fl_Text_Selection::position(int *startpos, int *endpos) const {
if (!mSelected)
return 0;
@@ -1816,83 +1247,65 @@ int Fl_Text_Selection::position(int *startpos, int *endpos) const {
}
-// simple getter
-// Unicode safe
-int Fl_Text_Selection::position(int *startpos, int *endpos,
- int *isRect, int *rectStart,
- int *rectEnd) const {
- if (!mSelected)
- return 0;
- *isRect = mRectangular;
- *startpos = mStart;
- *endpos = mEnd;
- if (mRectangular)
- {
- *rectStart = mRectStart;
- *rectEnd = mRectEnd;
- }
- return 1;
+/*
+ Return if a position is inside the eselected area.
+ Unicode safe. Pos must be at a character boundary.
+ */
+int Fl_Text_Selection::includes(int pos) const {
+ return (selected() && pos >= start() && pos < end() );
}
-// unicode safe
-int Fl_Text_Selection::includes(int pos, int lineStartPos, int dispIndex) const {
- return (selected()
- && ( (!rectangular() && pos >= start() && pos < end())
- || (rectangular() && pos >= start() && lineStartPos <= end()
- && dispIndex >= rect_start() && dispIndex < rect_end()
- )
- )
- );
-}
-
+/*
+ Return a duplicate of the selected text, or an empty string.
+ Unicode safe.
+ */
char *Fl_Text_Buffer::selection_text_(Fl_Text_Selection * sel) const {
- int start, end, isRect, rectStart, rectEnd;
+ int start, end;
/* If there's no selection, return an allocated empty string */
- if (!sel->position(&start, &end, &isRect, &rectStart, &rectEnd))
+ if (!sel->position(&start, &end))
{
char *s = (char *) malloc(1);
*s = '\0';
return s;
}
- /* If the selection is not rectangular, return the selected range */
- if (isRect)
- return text_in_rectangle(start, end, rectStart, rectEnd);
- else
+ /* Return the selected range */
return text_range(start, end);
}
+
+/*
+ Remove the selected text.
+ Unicode safe.
+ */
void Fl_Text_Buffer::remove_selection_(Fl_Text_Selection * sel)
{
- int start, end, isRect, rectStart, rectEnd;
+ int start, end;
- if (!sel->position(&start, &end, &isRect, &rectStart, &rectEnd))
+ if (!sel->position(&start, &end))
return;
- if (isRect)
- remove_rectangular(start, end, rectStart, rectEnd);
- else {
remove(start, end);
//undoyankcut = undocut;
}
-}
+/*
+ Replace selection with text.
+ Unicode safe.
+ */
void Fl_Text_Buffer::replace_selection_(Fl_Text_Selection * sel,
const char *text)
{
Fl_Text_Selection oldSelection = *sel;
/* If there's no selection, return */
- int start, end, isRect, rectStart, rectEnd;
- if (!sel->position(&start, &end, &isRect, &rectStart, &rectEnd))
+ int start, end;
+ if (!sel->position(&start, &end))
return;
/* Do the appropriate type of replace */
- if (isRect)
- replace_rectangular(start, end, rectStart, rectEnd, text);
- else
replace(start, end, text);
/* Unselect (happens automatically in BufReplace, but BufReplaceRect
@@ -1901,43 +1314,35 @@ void Fl_Text_Buffer::replace_selection_(Fl_Text_Selection * sel,
redisplay_selection(&oldSelection, sel);
}
-static void addPadding(char *string, int startIndent, int toIndent,
- int tabDist, int useTabs, int *charsAdded)
-{
- int indent = startIndent, len;
- char *outPtr = string;
-
- if (useTabs) {
- while (indent < toIndent) {
- //static char t = '\t';
- len = Fl_Text_Buffer::character_width("\t", indent, tabDist);
- if (len > 1 && indent + len <= toIndent) {
- *outPtr++ = '\t';
- indent += len;
- } else {
- *outPtr++ = ' ';
- indent++;
- }
- }
- } else {
- while (indent < toIndent) {
- *outPtr++ = ' ';
- indent++;
- }
- }
- *charsAdded = outPtr - string;
-}
-
+
+/*
+ Call all callbacks.
+ Unicode safe.
+ */
void Fl_Text_Buffer::call_modify_callbacks(int pos, int nDeleted,
int nInserted, int nRestyled,
const char *deletedText) const {
for (int i = 0; i < mNModifyProcs; i++)
(*mModifyProcs[i]) (pos, nInserted, nDeleted, nRestyled,
deletedText, mCbArgs[i]);
-} void Fl_Text_Buffer::call_predelete_callbacks(int pos, int nDeleted) const {
+}
+
+
+/*
+ Call all callbacks.
+ Unicode safe.
+ */
+void Fl_Text_Buffer::call_predelete_callbacks(int pos, int nDeleted) const {
for (int i = 0; i < mNPredeleteProcs; i++)
(*mPredeleteProcs[i]) (pos, nDeleted, mPredeleteCbArgs[i]);
-} void Fl_Text_Buffer::redisplay_selection(Fl_Text_Selection *
+}
+
+
+/*
+ Redisplay a new selected area.
+ Unicode safe.
+ */
+void Fl_Text_Buffer::redisplay_selection(Fl_Text_Selection *
oldSelection,
Fl_Text_Selection *
newSelection) const
@@ -1952,10 +1357,6 @@ void Fl_Text_Buffer::call_modify_callbacks(int pos, int nDeleted,
newStart = newSelection->mStart;
oldEnd = oldSelection->mEnd;
newEnd = newSelection->mEnd;
- if (oldSelection->mRectangular)
- oldEnd++;
- if (newSelection->mRectangular)
- newEnd++;
/* If the old or new selection is unselected, just redisplay the
single area that is (was) selected and return */
@@ -1971,20 +1372,6 @@ void Fl_Text_Buffer::call_modify_callbacks(int pos, int nDeleted,
return;
}
- /* If the selection changed from normal to rectangular or visa versa, or
- if a rectangular selection changed boundaries, redisplay everything */
- if ((oldSelection->mRectangular && !newSelection->mRectangular) ||
- (!oldSelection->mRectangular && newSelection->mRectangular) ||
- (oldSelection->mRectangular && ((oldSelection->mRectStart !=
- newSelection->mRectStart)
- || (oldSelection->mRectEnd !=
- newSelection->mRectEnd)))) {
- call_modify_callbacks(min(oldStart, newStart), 0, 0,
- max(oldEnd, newEnd) - min(oldStart,
- newStart), NULL);
- return;
- }
-
/* If the selections are non-contiguous, do two separate updates
and return */
if (oldEnd < newStart || newEnd < oldStart) {
@@ -2006,6 +1393,11 @@ void Fl_Text_Buffer::call_modify_callbacks(int pos, int nDeleted,
call_modify_callbacks(ch2Start, 0, 0, ch2End - ch2Start, NULL);
}
+
+/*
+ Move the gap around without changing buffer content.
+ Unicode safe. Pos must be at a character boundary.
+ */
void Fl_Text_Buffer::move_gap(int pos)
{
int gapLen = mGapEnd - mGapStart;
@@ -2018,6 +1410,11 @@ void Fl_Text_Buffer::move_gap(int pos)
mGapStart += pos - mGapStart;
}
+
+/*
+ Create a larger gap.
+ Unicode safe. Start must be at a character boundary.
+ */
void Fl_Text_Buffer::reallocate_with_gap(int newGapStart, int newGapLen)
{
char *newBuf = (char *) malloc(mLength + newGapLen);
@@ -2040,15 +1437,13 @@ void Fl_Text_Buffer::reallocate_with_gap(int newGapStart, int newGapLen)
mBuf = newBuf;
mGapStart = newGapStart;
mGapEnd = newGapEnd;
-#ifdef PURIFY
- {
- int i;
- for (i = mGapStart; i < mGapEnd; i++)
- mBuf[i] = '.';
}
-#endif
-}
+
+/*
+ Update selection range if characers were inserted.
+ Unicode safe. Pos must be at a character boundary.
+ */
void Fl_Text_Buffer::update_selections(int pos, int nDeleted,
int nInserted)
{
@@ -2061,6 +1456,7 @@ void Fl_Text_Buffer::update_selections(int pos, int nDeleted,
// unicode safe, assuming the arguments are on character boundaries
void Fl_Text_Selection::update(int pos, int nDeleted, int nInserted)
{
+ // FIXME: check if this is safe when seletion crosses selction boundaries
if (!mSelected || pos > mEnd)
return;
if (pos + nDeleted <= mStart) {
@@ -2080,283 +1476,69 @@ void Fl_Text_Selection::update(int pos, int nDeleted, int nInserted)
}
}
-int Fl_Text_Buffer::findchar_forward(int startPos, char searchChar,
- int *foundPos) const {
- if (startPos < 0 || startPos >= mLength)
+
+/*
+ Find a UCS-4 character.
+ Unicode safe. StartPos must be at a charcter boundary, searchChar is UCS-4 encoded.
+ */
+int Fl_Text_Buffer::findchar_forward(int startPos, unsigned searchChar,
+ int *foundPos) const
+ {
+ if (startPos >= mLength)
{
*foundPos = mLength;
return 0;
}
- int pos = startPos;
- while (pos < mGapStart) {
- if (mBuf[pos] == searchChar) {
- *foundPos = pos;
- return 1;
- }
- pos++;
- }
+ if (startPos<0)
+ startPos = 0;
+
+ // TODO: for performance reasons, we can re-insert the ASCII search here which is about three times as fast if searchChar is <128
- for (int gapLen = mGapEnd - mGapStart; pos < mLength; pos++) {
- if (mBuf[pos + gapLen] == searchChar) {
- *foundPos = pos;
+ for ( ; startPos<mLength; startPos = next_char(startPos)) {
+ if (searchChar == char_at(startPos)) {
+ *foundPos = startPos;
return 1;
}
}
+
*foundPos = mLength;
return 0;
}
-int Fl_Text_Buffer::findchar_backward(int startPos, char searchChar,
- int *foundPos) const {
- if (startPos <= 0 || startPos > mLength)
- {
+/*
+ Find a UCS-4 character.
+ Unicode safe. StartPos must be at a charcter boundary, searchChar is UCS-4 encoded.
+ */
+int Fl_Text_Buffer::findchar_backward(int startPos, unsigned searchChar,
+ int *foundPos) const {
+ if (startPos <= 0) {
*foundPos = 0;
return 0;
}
- int pos = startPos - 1;
- for (int gapLen = mGapEnd - mGapStart; pos >= mGapStart; pos--) {
- if (mBuf[pos + gapLen] == searchChar) {
- *foundPos = pos;
- return 1;
- }
- }
+ if (startPos > mLength)
+ startPos = mLength;
- for (; pos >= 0; pos--) {
- if (mBuf[pos] == searchChar) {
- *foundPos = pos;
+ // TODO: for performance reasons, we can re-insert the ASCII search here which is about three times as fast if searchChar is <128
+
+ for (startPos = prev_char(startPos); startPos>=0; startPos = prev_char(startPos)) {
+ if (searchChar == char_at(startPos)) {
+ *foundPos = startPos;
return 1;
}
}
+
*foundPos = 0;
return 0;
}
-/*
- Copies from \p text to end up to but not including newline (or end of \p text)
- and return the copy as the function value, and the length of the line in
- \p lineLen
- */
-static char *copyLine(const char *text, int *lineLen)
-{
- int len = 0;
-
- for (const char *c = text; *c != '\0' && *c != '\n'; c++)
- len++;
- char *outStr = (char *) malloc(len + 1);
- strlcpy(outStr, text, len + 1);
- *lineLen = len;
- return outStr;
-}
-
-/*
- Counts the number of newlines in a null-terminated text string.
- Unicode tested.
- */
-static int countLines(const char *string)
-{
- int lineCount = 0;
-
- for (const char *c = string; *c != '\0'; c++)
- if (*c == '\n')
- lineCount++;
- return lineCount;
-}
-
-/*
- Measures the width in displayed characters of string \p text
- */
-static int textWidth(const char *text, int tabDist)
-{
- int width = 0, maxWidth = 0;
-
- // HUH? Why is "c" incremented? Shouldn't "text" be incrmented?
- // FIXME: increment is wrong!
- for (const char *c = text; *c != '\0'; c++) {
- if (*c == '\n') {
- if (width > maxWidth)
- maxWidth = width;
- width = 0;
- } else
- width += Fl_Text_Buffer::character_width(c, width, tabDist);
- }
- if (width > maxWidth)
- return width;
- return maxWidth;
-}
-
-void Fl_Text_Buffer::rectangular_selection_boundaries(int lineStartPos,
- int rectStart,
- int rectEnd,
- int *selStart,
- int *selEnd) const
-{
- int pos, width, indent = 0;
- char c;
- /* find the start of the selection */
- for (pos = lineStartPos; pos < mLength; pos++)
- {
- // FIXME: character is ucs-4
- c = character(pos);
- if (c == '\n')
- break;
- width =
- Fl_Text_Buffer::character_width(&c, indent, mTabDist); // FIXME: c is not unicode
- if (indent + width > rectStart) {
- if (indent != rectStart && c != '\t') {
- pos++;
- indent += width;
- }
- break;
- }
- indent += width;
- }
- *selStart = pos;
-
- /* find the end */
- for (; pos < mLength; pos++) {
- // FIXME: character is ucs-4
- c = character(pos);
- if (c == '\n')
- break;
- width =
- Fl_Text_Buffer::character_width(&c, indent, mTabDist); // FIXME: c is not unicode
- indent += width;
- if (indent > rectEnd) {
- if (indent - width != rectEnd && c != '\t')
- pos++;
- break;
- }
- }
- *selEnd = pos;
-}
-
/*
- Adjust the space and tab characters from string \p text so that non-white
- characters remain stationary when the text is shifted from starting at
- \p origIndent to starting at \p newIndent. Returns an allocated string
- which must be freed by the caller with XtFree.
+ Insert text from a file.
+ Unicode safe. Inout must be correct utf8!
*/
-static char *realignTabs(const char *text, int origIndent, int newIndent,
- int tabDist, int useTabs, int *newLength)
-{
- /* If the tabs settings are the same, retain original tabs */
- int len;
- char *outStr;
- if (origIndent % tabDist == newIndent % tabDist) {
- len = strlen(text);
- outStr = (char *) malloc(len + 1);
- strcpy(outStr, text);
- *newLength = len;
- return outStr;
- }
-
- /* If the tab settings are not the same, brutally convert tabs to
- spaces, then back to tabs in the new position */
- char *expStr = expandTabs(text, origIndent, tabDist, &len);
- if (!useTabs) {
- *newLength = len;
- return expStr;
- }
- outStr =
- unexpandTabs(expStr, newIndent, tabDist, newLength);
- free((void *) expStr);
- return outStr;
-}
-
-/*
- Expand tabs to spaces for a block of text. The additional parameter
- \p startIndent if nonzero, indicates that the text is a rectangular selection
- beginning at column \p startIndent
- */
-static char *expandTabs(const char *text, int startIndent, int tabDist, int *newLen)
-{
- /* rehearse the expansion to figure out length for output string */
- int indent = startIndent, len, outLen = 0;
- const char *c;
- for (c = text; *c != '\0'; c++) {
- if (*c == '\t') {
- len =
- Fl_Text_Buffer::character_width(c, indent, tabDist);
- outLen += len;
- indent += len;
- } else if (*c == '\n') {
- indent = startIndent;
- outLen++;
- } else {
- // FIXME: character_width does not return number of bytes for UTF-8!
- indent +=
- Fl_Text_Buffer::character_width(c, indent, tabDist);
- outLen++;
- }
- }
-
- /* do the expansion */
- char *outStr = (char *) malloc(outLen + 1);
- char *outPtr = outStr;
- indent = startIndent;
- for (c = text; *c != '\0'; c++) {
- if (*c == '\t') {
- len =
- Fl_Text_Buffer::expand_character(c, indent, outPtr, tabDist);
- outPtr += len;
- indent += len;
- } else if (*c == '\n') {
- indent = startIndent;
- *outPtr++ = *c;
- } else {
- // FIXME: character_width does not return number of bytes for UTF-8!
- indent +=
- Fl_Text_Buffer::character_width(c, indent, tabDist);
- *outPtr++ = *c;
- }
- }
- outStr[outLen] = '\0';
- *newLen = outLen;
- return outStr;
-}
-
-/*
- Convert sequences of spaces into tabs. The threshold for conversion is
- when 3 or more spaces can be converted into a single tab, this avoids
- converting double spaces after a period withing a block of text.
- */
-static char *unexpandTabs(char *text, int startIndent, int tabDist, int *newLen)
-{
- char expandedChar[FL_TEXT_MAX_EXP_CHAR_LEN];
- char *outStr = (char *) malloc(strlen(text) + 1);
- char *outPtr = outStr;
- int indent = startIndent, len;
-
- for (const char *c = text; *c != '\0';) {
- if (*c == ' ') {
- static char tab = '\t';
- len =
- Fl_Text_Buffer::expand_character(&tab, indent, expandedChar, tabDist);
- if (len >= 3 && !strncmp(c, expandedChar, len)) {
- c += len;
- *outPtr++ = '\t';
- indent += len;
- } else {
- *outPtr++ = *c++;
- indent++;
- }
- } else if (*c == '\n') {
- indent = startIndent;
- *outPtr++ = *c++;
- } else {
- *outPtr++ = *c++;
- indent++;
- }
- }
- *outPtr = '\0';
- *newLen = outPtr - outStr;
- return outStr;
-}
-
int Fl_Text_Buffer::insertfile(const char *file, int pos, int buflen)
{
FILE *fp;
@@ -2374,6 +1556,11 @@ int Fl_Text_Buffer::insertfile(const char *file, int pos, int buflen)
return e;
}
+
+/*
+ Write text to file,
+ Unicode safe.
+ */
int Fl_Text_Buffer::outputfile(const char *file, int start, int end,
int buflen)
{
@@ -2394,6 +1581,39 @@ int Fl_Text_Buffer::outputfile(const char *file, int start, int end,
}
+/*
+ Return the previous character position.
+ Uncode safe.
+ */
+int Fl_Text_Buffer::prev_char(int pos) const
+{
+ if (pos<=0)
+ return 0;
+
+ char c;
+ do {
+ pos--;
+ if (pos==0)
+ return 0;
+ c = byte_at(pos);
+ } while ( (c&0xc0) == 0x80);
+
+ return pos;
+}
+
+/*
+ Return the next character position.
+ Uncode safe.
+ */
+int Fl_Text_Buffer::next_char(int pos) const
+{
+ int n = fl_utf8len(byte_at(pos));
+ pos += n;
+ if (pos>=mLength)
+ return mLength;
+ return pos;
+}
+
//
-// End of "$Id: Fl_Text_Buffer.cxx 7672 2010-07-10 09:44:45Z matt $".
+// End of "$Id: Fl_Text_Buffer.cxx 7794 2010-11-04 21:53:56Z matt $".
//
diff --git a/src/Fl_Text_Display.cxx b/src/Fl_Text_Display.cxx
index c6b5a81..56e221c 100644
--- a/src/Fl_Text_Display.cxx
+++ b/src/Fl_Text_Display.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Text_Display.cxx 7527 2010-04-18 14:33:33Z engelsman $"
+// "$Id: Fl_Text_Display.cxx 7794 2010-11-04 21:53:56Z matt $"
//
// Copyright 2001-2009 by Bill Spitzak and others.
// Original code Copyright Mark Edel. Permission to distribute under
@@ -25,6 +25,8 @@
// http://www.fltk.org/str.php
//
+// TODO: check all functions for UTF-8/UCS-4 compatibility!
+
#include <stdio.h>
#include <stdlib.h>
#include <FL/fl_utf8.h>
@@ -49,7 +51,7 @@
#define NO_HINT -1
/* Masks for text drawing methods. These are or'd together to form an
- integer which describes what drawing calls to use to draw a string */
+ integer which describes what drawing calls to use to draw a string */
#define FILL_MASK 0x0100
#define SECONDARY_MASK 0x0200
#define PRIMARY_MASK 0x0400
@@ -59,8 +61,8 @@
#define STYLE_LOOKUP_MASK 0xff
/* Maximum displayable line length (how many characters will fit across the
- widest window). This amount of memory is temporarily allocated from the
- stack in the draw_vline() method for drawing strings */
+ widest window). This amount of memory is temporarily allocated from the
+ stack in the draw_vline() method for drawing strings */
#define MAX_DISP_LINE_LEN 1000
static int max( int i1, int i2 );
@@ -68,7 +70,7 @@ static int min( int i1, int i2 );
static int countlines( const char *string );
/* The variables below are used in a timer event to allow smooth
- scrolling of the text area when the pointer has left the area. */
+ scrolling of the text area when the pointer has left the area. */
static int scroll_direction = 0;
static int scroll_amount = 0;
static int scroll_y = 0;
@@ -79,39 +81,39 @@ static int scroll_x = 0;
/** Creates a new text display widget.*/
Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l)
- : Fl_Group(X, Y, W, H, l) {
+: Fl_Group(X, Y, W, H, l) {
int i;
-
+
mMaxsize = 0;
damage_range1_start = damage_range1_end = -1;
damage_range2_start = damage_range2_end = -1;
dragPos = dragType = dragging = 0;
display_insert_position_hint = 0;
shortcut_ = 0;
-
+
color(FL_BACKGROUND2_COLOR, FL_SELECTION_COLOR);
box(FL_DOWN_FRAME);
textsize(FL_NORMAL_SIZE);
textcolor(FL_FOREGROUND_COLOR);
textfont(FL_HELVETICA);
set_flag(SHORTCUT_LABEL);
-
+
text_area.x = 0;
text_area.y = 0;
text_area.w = 0;
text_area.h = 0;
-
+
mVScrollBar = new Fl_Scrollbar(0,0,1,1);
mVScrollBar->callback((Fl_Callback*)v_scrollbar_cb, this);
mHScrollBar = new Fl_Scrollbar(0,0,1,1);
mHScrollBar->callback((Fl_Callback*)h_scrollbar_cb, this);
mHScrollBar->type(FL_HORIZONTAL);
-
+
end();
-
+
scrollbar_width(Fl::scrollbar_size());
scrollbar_align(FL_ALIGN_BOTTOM_RIGHT);
-
+
mCursorOn = 0;
mCursorPos = 0;
mCursorOldY = -100;
@@ -126,10 +128,9 @@ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l)
mAbsTopLineNum = 1;
mNeedAbsTopLineNum = 0;
mHorizOffset = mHorizOffsetHint = 0;
-
+
mCursor_color = FL_FOREGROUND_COLOR;
-
- mFixedFontWidth = -1;
+
mStyleBuffer = 0;
mStyleTable = 0;
mNStyles = 0;
@@ -141,21 +142,23 @@ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l)
mSuppressResync = 0;
mNLinesDeleted = 0;
mModifyingTabDistance = 0;
-
+
mUnfinishedStyle = 0;
mUnfinishedHighlightCB = 0;
mHighlightCBArg = 0;
-
+
mLineNumLeft = mLineNumWidth = 0;
mContinuousWrap = 0;
mWrapMargin = 0;
mSuppressResync = mNLinesDeleted = mModifyingTabDistance = 0;
}
-/** Free a text display and release its associated memory. Note, the text
- BUFFER that the text display displays is a separate entity and is not
- freed, nor are the style buffer or style table.
-*/
+/**
+ Free a text display and release its associated memory.
+
+ Note, the text BUFFER that the text display displays is a separate
+ entity and is not freed, nor are the style buffer or style table.
+ */
Fl_Text_Display::~Fl_Text_Display() {
if (scroll_direction) {
Fl::remove_timeout(scroll_timer_cb, this);
@@ -168,60 +171,64 @@ Fl_Text_Display::~Fl_Text_Display() {
if (mLineStarts) delete[] mLineStarts;
}
+
/**
- Attach a text buffer to display, replacing the current buffer (if any)
-*/
+ Attach a text buffer to display, replacing the current buffer (if any)
+ \param buf attach this text buffer
+ */
void Fl_Text_Display::buffer( Fl_Text_Buffer *buf ) {
/* If the text display is already displaying a buffer, clear it off
- of the display and remove our callback from it */
+ of the display and remove our callback from it */
if ( buf == mBuffer) return;
if ( mBuffer != 0 ) {
buffer_modified_cb( 0, 0, mBuffer->length(), 0, 0, this );
- mNBufferLines = 0;
+ mNBufferLines = 0;
mBuffer->remove_modify_callback( buffer_modified_cb, this );
mBuffer->remove_predelete_callback( buffer_predelete_cb, this );
}
-
+
/* Add the buffer to the display, and attach a callback to the buffer for
- receiving modification information when the buffer contents change */
+ receiving modification information when the buffer contents change */
mBuffer = buf;
if (mBuffer) {
mBuffer->add_modify_callback( buffer_modified_cb, this );
mBuffer->add_predelete_callback( buffer_predelete_cb, this );
-
+
/* Update the display */
buffer_modified_cb( 0, buf->length(), 0, 0, 0, this );
}
-
+
/* Resize the widget to update the screen... */
resize(x(), y(), w(), h());
}
/**
- Attach (or remove) highlight information in text display and redisplay.
- Highlighting information consists of a style buffer which parallels the
- normal text buffer, but codes font and color information for the display;
- a style table which translates style buffer codes (indexed by buffer
- character - 'A') into fonts and colors; and a callback mechanism for
- as-needed highlighting, triggered by a style buffer entry of
- "unfinishedStyle". Style buffer can trigger additional redisplay during
- a normal buffer modification if the buffer contains a primary Fl_Text_Selection
- (see extendRangeForStyleMods for more information on this protocol).
-
- Style buffers, tables and their associated memory are managed by the caller.
-*/
+ Attach (or remove) highlight information in text display and redisplay.
+ Highlighting information consists of a style buffer which parallels the
+ normal text buffer, but codes font and color information for the display;
+ a style table which translates style buffer codes (indexed by buffer
+ character - 'A') into fonts and colors; and a callback mechanism for
+ as-needed highlighting, triggered by a style buffer entry of
+ "unfinishedStyle". Style buffer can trigger additional redisplay during
+ a normal buffer modification if the buffer contains a primary Fl_Text_Selection
+ (see extendRangeForStyleMods for more information on this protocol).
+
+ Style buffers, tables and their associated memory are managed by the caller.
+
+ Styles are ranged from 65 ('A') to 126.
+ */
void Fl_Text_Display::highlight_data(Fl_Text_Buffer *styleBuffer,
- const Style_Table_Entry *styleTable,
- int nStyles, char unfinishedStyle,
- Unfinished_Style_Cb unfinishedHighlightCB,
- void *cbArg ) {
+ const Style_Table_Entry *styleTable,
+ int nStyles, char unfinishedStyle,
+ Unfinished_Style_Cb unfinishedHighlightCB,
+ void *cbArg ) {
mStyleBuffer = styleBuffer;
mStyleTable = styleTable;
mNStyles = nStyles;
mUnfinishedStyle = unfinishedStyle;
mUnfinishedHighlightCB = unfinishedHighlightCB;
mHighlightCBArg = cbArg;
-
+
mStyleBuffer->canUndo(0);
damage(FL_DAMAGE_EXPOSE);
}
@@ -234,8 +241,8 @@ int Fl_Text_Display::longest_vline() const {
}
/**
- Change the size of the displayed text area
-*/
+ Change the size of the displayed text area
+ */
void Fl_Text_Display::resize(int X, int Y, int W, int H) {
#ifdef DEBUG
printf("Fl_Text_Display::resize(X=%d, Y=%d, W=%d, H=%d)\n", X, Y, W, H);
@@ -251,44 +258,44 @@ void Fl_Text_Display::resize(int X, int Y, int W, int H) {
Y += Fl::box_dy(box());
W -= Fl::box_dw(box());
H -= Fl::box_dh(box());
-
+
text_area.x = X+LEFT_MARGIN;
text_area.y = Y+TOP_MARGIN;
text_area.w = W-LEFT_MARGIN-RIGHT_MARGIN;
text_area.h = H-TOP_MARGIN-BOTTOM_MARGIN;
int i;
-
+
/* Find the new maximum font height for this text display */
for (i = 0, mMaxsize = fl_height(textfont(), textsize()); i < mNStyles; i++)
mMaxsize = max(mMaxsize, fl_height(mStyleTable[i].font, mStyleTable[i].size));
-
+
// did we have scrollbars initially?
unsigned int hscrollbarvisible = mHScrollBar->visible();
unsigned int vscrollbarvisible = mVScrollBar->visible();
-
+
// try without scrollbars first
mVScrollBar->clear_visible();
mHScrollBar->clear_visible();
-
+
for (int again = 1; again;) {
- again = 0;
+ again = 0;
/* In continuous wrap mode, a change in width affects the total number of
- lines in the buffer, and can leave the top line number incorrect, and
- the top character no longer pointing at a valid line start */
+ lines in the buffer, and can leave the top line number incorrect, and
+ the top character no longer pointing at a valid line start */
if (mContinuousWrap && !mWrapMargin && W!=oldWidth) {
int oldFirstChar = mFirstChar;
mNBufferLines = count_lines(0, buffer()->length(), true);
mFirstChar = line_start(mFirstChar);
mTopLineNum = count_lines(0, mFirstChar, true)+1;
absolute_top_line_number(oldFirstChar);
-
+
#ifdef DEBUG
printf(" mNBufferLines=%d\n", mNBufferLines);
#endif // DEBUG
}
-
+
/* reallocate and update the line starts array, which may have changed
- size and / or contents. */
+ size and / or contents. */
int nvlines = (text_area.h + mMaxsize - 1) / mMaxsize;
if (nvlines < 1) nvlines = 1;
if (mNVisibleLines != nvlines) {
@@ -296,10 +303,10 @@ void Fl_Text_Display::resize(int X, int Y, int W, int H) {
if (mLineStarts) delete[] mLineStarts;
mLineStarts = new int [mNVisibleLines];
}
-
+
calc_line_starts(0, mNVisibleLines);
calc_last_char();
-
+
// figure the scrollbars
if (scrollbar_width()) {
/* Decide if the vertical scroll bar needs to be visible */
@@ -319,28 +326,28 @@ void Fl_Text_Display::resize(int X, int Y, int W, int H) {
scrollbar_width(), text_area.h+TOP_MARGIN+BOTTOM_MARGIN);
}
}
-
+
/*
- Decide if the horizontal scroll bar needs to be visible. If there
- is a vertical scrollbar, a horizontal is always created too. This
- is because the alternatives are unatractive:
- * Dynamically creating a horizontal scrollbar based on the currently
- visible lines is what the original nedit does, but it always wastes
- space for the scrollbar even when it's not used. Since the FLTK
- widget dynamically allocates the space for the scrollbar and
- rearranges the widget to make room for it, this would create a very
- visually displeasing "bounce" effect when the vertical scrollbar is
- dragged. Trust me, I tried it and it looks really bad.
- * The other alternative would be to keep track of what the longest
- line in the entire buffer is and base the scrollbar on that. I
- didn't do this because I didn't see any easy way to do that using
- the nedit code and this could involve a lengthy calculation for
- large buffers. If an efficient and non-costly way of doing this
- can be found, this might be a way to go.
- */
+ Decide if the horizontal scroll bar needs to be visible. If there
+ is a vertical scrollbar, a horizontal is always created too. This
+ is because the alternatives are unatractive:
+ * Dynamically creating a horizontal scrollbar based on the currently
+ visible lines is what the original nedit does, but it always wastes
+ space for the scrollbar even when it's not used. Since the FLTK
+ widget dynamically allocates the space for the scrollbar and
+ rearranges the widget to make room for it, this would create a very
+ visually displeasing "bounce" effect when the vertical scrollbar is
+ dragged. Trust me, I tried it and it looks really bad.
+ * The other alternative would be to keep track of what the longest
+ line in the entire buffer is and base the scrollbar on that. I
+ didn't do this because I didn't see any easy way to do that using
+ the nedit code and this could involve a lengthy calculation for
+ large buffers. If an efficient and non-costly way of doing this
+ can be found, this might be a way to go.
+ */
/* WAS: Suggestion: Try turning the horizontal scrollbar on when
- you first see a line that is too wide in the window, but then
- don't turn it off (ie mix both of your solutions). */
+ you first see a line that is too wide in the window, but then
+ don't turn it off (ie mix both of your solutions). */
if (scrollbar_align() & (FL_ALIGN_TOP|FL_ALIGN_BOTTOM) &&
(mVScrollBar->visible() || longest_vline() > text_area.w))
{
@@ -362,63 +369,63 @@ void Fl_Text_Display::resize(int X, int Y, int W, int H) {
}
}
}
-
+
// user request to change viewport
if (mTopLineNumHint != mTopLineNum || mHorizOffsetHint != mHorizOffset)
scroll_(mTopLineNumHint, mHorizOffsetHint);
-
+
// everything will fit in the viewport
if (mNBufferLines < mNVisibleLines || mBuffer == NULL || mBuffer->length() == 0)
scroll_(1, mHorizOffset);
/* if empty lines become visible, there may be an opportunity to
- display more text by scrolling down */
+ display more text by scrolling down */
else while (mLineStarts[mNVisibleLines-2] == -1)
scroll_(mTopLineNum-1, mHorizOffset);
-
+
// user request to display insert position
if (display_insert_position_hint)
display_insert();
-
+
// in case horizontal offset is now greater than longest line
int maxhoffset = max(0, longest_vline()-text_area.w);
if (mHorizOffset > maxhoffset)
scroll_(mTopLineNumHint, maxhoffset);
-
+
mTopLineNumHint = mTopLineNum;
mHorizOffsetHint = mHorizOffset;
display_insert_position_hint = 0;
-
+
if (mContinuousWrap ||
hscrollbarvisible != mHScrollBar->visible() ||
vscrollbarvisible != mVScrollBar->visible())
redraw();
-
+
update_v_scrollbar();
update_h_scrollbar();
}
/**
- Refresh a rectangle of the text display. left and top are in coordinates of
- the text drawing window
-*/
+ Refresh a rectangle of the text display. left and top are in coordinates of
+ the text drawing window
+ */
void Fl_Text_Display::draw_text( int left, int top, int width, int height ) {
int fontHeight, firstLine, lastLine, line;
-
+
/* find the line number range of the display */
fontHeight = mMaxsize ? mMaxsize : textsize_;
firstLine = ( top - text_area.y - fontHeight + 1 ) / fontHeight;
lastLine = ( top + height - text_area.y ) / fontHeight + 1;
-
+
fl_push_clip( left, top, width, height );
-
+
/* draw the lines */
for ( line = firstLine; line <= lastLine; line++ )
draw_vline( line, left, left + width, 0, INT_MAX );
-
- /* draw the line numbers if exposed area includes them */
- if (mLineNumWidth != 0 && left <= mLineNumLeft + mLineNumWidth)
- draw_line_numbers(false);
-
+
+ /* draw the line numbers if exposed area includes them */
+ if (mLineNumWidth != 0 && left <= mLineNumLeft + mLineNumWidth)
+ draw_line_numbers(false);
+
fl_pop_clip();
}
@@ -427,7 +434,7 @@ void Fl_Text_Display::redisplay_range(int startpos, int endpos) {
int ok = 0;
while (!ok && startpos > 0) {
// FIXME: character is ucs-4
- char c = buffer()->character( startpos );
+ char c = buffer()->char_at( startpos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
} else {
@@ -436,7 +443,7 @@ void Fl_Text_Display::redisplay_range(int startpos, int endpos) {
}
while (!ok && endpos < buffer()->length()) {
// FIXME: character is ucs-4
- char c = buffer()->character( endpos );
+ char c = buffer()->char_at( endpos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
} else {
@@ -460,25 +467,25 @@ void Fl_Text_Display::redisplay_range(int startpos, int endpos) {
damage(FL_DAMAGE_SCROLL);
}
/**
- Refresh all of the text between buffer positions "start" and "end"
- not including the character at the position "end".
- If end points beyond the end of the buffer, refresh the whole display
- after pos, including blank lines which are not technically part of
- any range of characters.
-*/
+ Refresh all of the text between buffer positions "start" and "end"
+ not including the character at the position "end".
+ If end points beyond the end of the buffer, refresh the whole display
+ after pos, including blank lines which are not technically part of
+ any range of characters.
+ */
void Fl_Text_Display::draw_range(int startpos, int endpos) {
int i, startLine, lastLine, startIndex, endIndex;
-
+
/* If the range is outside of the displayed text, just return */
if ( endpos < mFirstChar || ( startpos > mLastChar &&
- !empty_vlines() ) ) return;
-
+ !empty_vlines() ) ) return;
+
/* Clean up the starting and ending values */
if ( startpos < 0 ) startpos = 0;
if ( startpos > mBuffer->length() ) startpos = mBuffer->length();
if ( endpos < 0 ) endpos = 0;
if ( endpos > mBuffer->length() ) endpos = mBuffer->length();
-
+
/* Get the starting and ending lines */
if ( startpos < mFirstChar )
startpos = mFirstChar;
@@ -492,31 +499,31 @@ void Fl_Text_Display::draw_range(int startpos, int endpos) {
lastLine = mNVisibleLines - 1;
}
}
-
+
/* Get the starting and ending positions within the lines */
startIndex = mLineStarts[ startLine ] == -1 ? 0 :
- startpos - mLineStarts[ startLine ];
+ startpos - mLineStarts[ startLine ];
if ( endpos >= mLastChar )
endIndex = INT_MAX;
else if ( mLineStarts[ lastLine ] == -1 )
endIndex = 0;
else
endIndex = endpos - mLineStarts[ lastLine ];
-
+
/* If the starting and ending lines are the same, redisplay the single
- line between "start" and "end" */
+ line between "start" and "end" */
if ( startLine == lastLine ) {
draw_vline( startLine, 0, INT_MAX, startIndex, endIndex );
return;
}
-
+
/* Redisplay the first line from "start" */
draw_vline( startLine, 0, INT_MAX, startIndex, INT_MAX );
-
+
/* Redisplay the lines in between at their full width */
for ( i = startLine + 1; i < lastLine; i++ )
draw_vline( i, 0, INT_MAX, 0, INT_MAX );
-
+
/* Redisplay the last line to "end" */
draw_vline( lastLine, 0, INT_MAX, 0, endIndex );
}
@@ -528,18 +535,19 @@ void Fl_Text_Display::insert_position( int newPos ) {
return;
if ( newPos < 0 ) newPos = 0;
if ( newPos > mBuffer->length() ) newPos = mBuffer->length();
-
+
/* cursor movement cancels vertical cursor motion column */
mCursorPreferredCol = -1;
-
+
/* erase the cursor at it's previous position */
redisplay_range(mCursorPos - 1, mCursorPos + 1); // FIXME utf8
-
+
mCursorPos = newPos;
-
+
/* draw cursor at its new position */
redisplay_range(mCursorPos - 1, mCursorPos + 1); // FIXME utf8
}
+
/** Shows the text cursor */
void Fl_Text_Display::show_cursor(int b) {
mCursorOn = b;
@@ -547,48 +555,40 @@ void Fl_Text_Display::show_cursor(int b) {
}
/**
- Sets the text cursor style to one of the following:
-
- <UL>
-
- <LI>Fl_Text_Display::NORMAL_CURSOR - Shows an I beam.
-
- <LI>Fl_Text_Display::CARET_CURSOR - Shows a caret under the text.
-
- <LI>Fl_Text_Display::DIM_CURSOR - Shows a dimmed I beam.
-
- <LI>Fl_Text_Display::BLOCK_CURSOR - Shows an unfilled box around the current
- character.
-
- <LI>Fl_Text_Display::HEAVY_CURSOR - Shows a thick I beam.
-
- </UL>
-*/
+ Sets the text cursor style to one of the following:
+
+ \li Fl_Text_Display::NORMAL_CURSOR - Shows an I beam.
+ \li Fl_Text_Display::CARET_CURSOR - Shows a caret under the text.
+ \li Fl_Text_Display::DIM_CURSOR - Shows a dimmed I beam.
+ \li Fl_Text_Display::BLOCK_CURSOR - Shows an unfilled box around the current
+ character.
+ \li Fl_Text_Display::HEAVY_CURSOR - Shows a thick I beam.
+ */
void Fl_Text_Display::cursor_style(int style) {
mCursorStyle = style;
if (mCursorOn) show_cursor();
}
/**
- If <i>mode</i> is not zero, this call enables automatic word wrapping at column <i>pos</i>.
- Word-wrapping does not change the text buffer itself, only the way that the text is displayed.
-*/
+ If <i>mode</i> is not zero, this call enables automatic word wrapping at column <i>pos</i>.
+ Word-wrapping does not change the text buffer itself, only the way that the text is displayed.
+ */
void Fl_Text_Display::wrap_mode(int wrap, int wrapMargin) {
mWrapMargin = wrapMargin;
mContinuousWrap = wrap;
-
+
if (buffer()) {
/* wrapping can change the total number of lines, re-count */
mNBufferLines = count_lines(0, buffer()->length(), true);
-
+
/* changing wrap margins or changing from wrapped mode to non-wrapped
- can leave the character at the top no longer at a line start, and/or
- change the line number */
+ can leave the character at the top no longer at a line start, and/or
+ change the line number */
mFirstChar = line_start(mFirstChar);
mTopLineNum = count_lines(0, mFirstChar, true) + 1;
-
+
reset_absolute_top_line_number();
-
+
/* update the line starts array */
calc_line_starts(0, mNVisibleLines);
calc_last_char();
@@ -599,19 +599,19 @@ void Fl_Text_Display::wrap_mode(int wrap, int wrapMargin) {
mTopLineNum = 1;
mAbsTopLineNum = 0;
}
-
+
resize(x(), y(), w(), h());
}
/**
- Inserts "text" at the current cursor location. This has the same
- effect as inserting the text into the buffer using BufInsert and
- then moving the insert position after the newly inserted text, except
- that it's optimized to do less redrawing.
-*/
+ Inserts "text" at the current cursor location. This has the same
+ effect as inserting the text into the buffer using BufInsert and
+ then moving the insert position after the newly inserted text, except
+ that it's optimized to do less redrawing.
+ */
void Fl_Text_Display::insert(const char* text) {
int pos = mCursorPos;
-
+
mCursorToHint = pos + strlen( text );
mBuffer->insert( pos, text );
mCursorToHint = NO_HINT;
@@ -626,26 +626,25 @@ void Fl_Text_Display::overstrike(const char* text) {
int i, p, endPos, indent, startIndent, endIndent;
const char *c;
char ch, *paddedText = NULL;
-
+
/* determine how many displayed character positions are covered */
startIndent = mBuffer->count_displayed_characters( lineStart, startPos );
indent = startIndent;
for ( c = text; *c != '\0'; c++ )
- indent += Fl_Text_Buffer::character_width( c, indent, buf->tab_distance() );
+ indent++;
endIndent = indent;
-
+
/* find which characters to remove, and if necessary generate additional
- padding to make up for removed control characters at the end */
+ padding to make up for removed control characters at the end */
indent = startIndent;
for ( p = startPos; ; p++ ) {
if ( p == buf->length() )
break;
// FIXME: character is ucs-4
- ch = buf->character( p );
+ ch = buf->char_at( p );
if ( ch == '\n' )
break;
- const char *s = buf->address(p);
- indent += Fl_Text_Buffer::character_width(s, indent, buf->tab_distance() ); // FIXME: not unicode
+ indent++;
if ( indent == endIndent ) {
p++;
break;
@@ -662,7 +661,7 @@ void Fl_Text_Display::overstrike(const char* text) {
}
}
endPos = p;
-
+
mCursorToHint = startPos + textLen;
buf->replace( startPos, endPos, paddedText == NULL ? text : paddedText );
mCursorToHint = NO_HINT;
@@ -671,204 +670,157 @@ void Fl_Text_Display::overstrike(const char* text) {
}
/**
- Translate a buffer text position to the XY location where the top left
- of the cursor would be positioned to point to that character. Returns
- 0 if the position is not displayed because it is VERTICALLY out
- of view. If the position is horizontally out of view, returns the
- X coordinate where the position would be if it were visible.
-*/
+ Translate a buffer text position to the XY location where the top left
+ of the cursor would be positioned to point to that character. Returns
+ 0 if the position is not displayed because it is VERTICALLY out
+ of view. If the position is horizontally out of view, returns the
+ X coordinate where the position would be if it were visible.
+ */
int Fl_Text_Display::position_to_xy( int pos, int* X, int* Y ) const {
- int charIndex, lineStartPos, fontHeight, lineLen;
- int visLineNum, charLen, outIndex, xStep, charStyle;
- char expandedChar[ FL_TEXT_MAX_EXP_CHAR_LEN ];
- const char *lineStr;
-
-// printf("position_to_xy(pos=%d, X=%p, Y=%p)\n", pos, X, Y);
-
+ int lineStartPos, fontHeight, lineLen;
+ int visLineNum;
+
/* If position is not displayed, return false */
if (pos < mFirstChar || (pos > mLastChar && !empty_vlines())) {
-// printf(" returning 0\n"
-// " mFirstChar=%d, mLastChar=%d, empty_vlines()=0\n",
-// mFirstChar, mLastChar);
return 0;
}
-
+
/* Calculate Y coordinate */
if (!position_to_line(pos, &visLineNum)) {
-// puts(" returning 0\n"
-// " position_to_line()=0");
return 0;
}
-
if (visLineNum < 0 || visLineNum > mNBufferLines) {
-// printf(" returning 0\n"
-// " visLineNum=%d, mNBufferLines=%d\n",
-// visLineNum, mNBufferLines);
return 0;
}
-
+
fontHeight = mMaxsize;
*Y = text_area.y + visLineNum * fontHeight;
-
+
/* Get the text, length, and buffer position of the line. If the position
- is beyond the end of the buffer and should be at the first position on
- the first empty line, don't try to get or scan the text */
+ is beyond the end of the buffer and should be at the first position on
+ the first empty line, don't try to get or scan the text */
lineStartPos = mLineStarts[visLineNum];
if ( lineStartPos == -1 ) {
*X = text_area.x - mHorizOffset;
return 1;
}
lineLen = vline_length( visLineNum );
- lineStr = mBuffer->text_range( lineStartPos, lineStartPos + lineLen );
-
- /* Step through character positions from the beginning of the line
- to "pos" to calculate the X coordinate */
- xStep = text_area.x - mHorizOffset;
- outIndex = 0;
- for (charIndex = 0;
- charIndex < lineLen && charIndex < pos - lineStartPos;
- charIndex += fl_utf8len(lineStr[charIndex]) )
- {
- charLen = Fl_Text_Buffer::expand_character( lineStr+charIndex, outIndex, expandedChar,
- mBuffer->tab_distance());
- charStyle = position_style( lineStartPos, lineLen, charIndex,
- outIndex );
- xStep += string_width( expandedChar, charLen, charStyle );
- outIndex += charLen;
- }
- *X = xStep;
- free((char *)lineStr);
+ *X = text_area.x + handle_vline(GET_WIDTH, lineStartPos, pos-lineStartPos, 0, 0, 0, 0, 0, 0) - mHorizOffset;
return 1;
}
/**
- Find the line number of position "pos". Note: this only works for
- displayed lines. If the line is not displayed, the function returns
- 0 (without the mLineStarts array it could turn in to very long
- calculation involving scanning large amounts of text in the buffer).
- If continuous wrap mode is on, returns the absolute line number (as opposed
- to the wrapped line number which is used for scrolling).
-*/
+ Find the line number of position "pos". Note: this only works for
+ displayed lines. If the line is not displayed, the function returns
+ 0 (without the mLineStarts array it could turn in to very long
+ calculation involving scanning large amounts of text in the buffer).
+ If continuous wrap mode is on, returns the absolute line number (as opposed
+ to the wrapped line number which is used for scrolling).
+ */
int Fl_Text_Display::position_to_linecol( int pos, int* lineNum, int* column ) const {
int retVal;
-
- /* In continuous wrap mode, the absolute (non-wrapped) line count is
- maintained separately, as needed. Only return it if we're actually
- keeping track of it and pos is in the displayed text */
- if (mContinuousWrap) {
- if (!maintaining_absolute_top_line_number() ||
- pos < mFirstChar || pos > mLastChar)
- return 0;
- *lineNum = mAbsTopLineNum + buffer()->count_lines(mFirstChar, pos);
- *column
- = buffer()->count_displayed_characters(buffer()->line_start(pos), pos);
- return 1;
- }
-
+
+ /* In continuous wrap mode, the absolute (non-wrapped) line count is
+ maintained separately, as needed. Only return it if we're actually
+ keeping track of it and pos is in the displayed text */
+ if (mContinuousWrap) {
+ if (!maintaining_absolute_top_line_number() ||
+ pos < mFirstChar || pos > mLastChar)
+ return 0;
+ *lineNum = mAbsTopLineNum + buffer()->count_lines(mFirstChar, pos);
+ *column = buffer()->count_displayed_characters(buffer()->line_start(pos), pos);
+ return 1;
+ }
+
retVal = position_to_line( pos, lineNum );
if ( retVal ) {
- *column = mBuffer->count_displayed_characters(
- mLineStarts[ *lineNum ], pos );
+ *column = mBuffer->count_displayed_characters( mLineStarts[ *lineNum ], pos );
*lineNum += mTopLineNum;
}
return retVal;
}
/**
- Return 1 if position (X, Y) is inside of the primary Fl_Text_Selection
-*/
+ Return 1 if position (X, Y) is inside of the primary Fl_Text_Selection
+ */
int Fl_Text_Display::in_selection( int X, int Y ) const {
- int row, column, pos = xy_to_position( X, Y, CHARACTER_POS );
+ int pos = xy_to_position( X, Y, CHARACTER_POS );
Fl_Text_Buffer *buf = mBuffer;
- int ok = 0;
- while (!ok) {
- // FIXME: character is ucs-4
- char c = buffer()->character( pos );
- if (!((c & 0x80) && !(c & 0x40))) {
- ok = 1;
- } else {
- pos++;
- }
- }
-
- xy_to_rowcol( X, Y, &row, &column, CHARACTER_POS );
- if (range_touches_selection(buf->primary_selection(), mFirstChar, mLastChar))
- column = wrapped_column(row, column);
- return buf->primary_selection()->includes(pos, buf->line_start( pos ), column);
+ return buf->primary_selection()->includes(pos);
}
/**
- Correct a column number based on an unconstrained position (as returned by
- TextDXYToUnconstrainedPosition) to be relative to the last actual newline
- in the buffer before the row and column position given, rather than the
- last line start created by line wrapping. This is an adapter
- for rectangular selections and code written before continuous wrap mode,
- which thinks that the unconstrained column is the number of characters
- from the last newline. Obviously this is time consuming, because it
- invloves character re-counting.
-*/
+ Correct a column number based on an unconstrained position (as returned by
+ TextDXYToUnconstrainedPosition) to be relative to the last actual newline
+ in the buffer before the row and column position given, rather than the
+ last line start created by line wrapping. This is an adapter
+ for rectangular selections and code written before continuous wrap mode,
+ which thinks that the unconstrained column is the number of characters
+ from the last newline. Obviously this is time consuming, because it
+ invloves character re-counting.
+ */
int Fl_Text_Display::wrapped_column(int row, int column) const {
- int lineStart, dispLineStart;
-
- if (!mContinuousWrap || row < 0 || row > mNVisibleLines)
- return column;
- dispLineStart = mLineStarts[row];
- if (dispLineStart == -1)
- return column;
- lineStart = buffer()->line_start(dispLineStart);
- return column
- + buffer()->count_displayed_characters(lineStart, dispLineStart);
+ int lineStart, dispLineStart;
+
+ if (!mContinuousWrap || row < 0 || row > mNVisibleLines)
+ return column;
+ dispLineStart = mLineStarts[row];
+ if (dispLineStart == -1)
+ return column;
+ lineStart = buffer()->line_start(dispLineStart);
+ return column
+ + buffer()->count_displayed_characters(lineStart, dispLineStart);
}
/**
- Correct a row number from an unconstrained position (as returned by
- TextDXYToUnconstrainedPosition) to a straight number of newlines from the
- top line of the display. Because rectangular selections are based on
- newlines, rather than display wrapping, and anywhere a rectangular selection
- needs a row, it needs it in terms of un-wrapped lines.
-*/
+ Correct a row number from an unconstrained position (as returned by
+ TextDXYToUnconstrainedPosition) to a straight number of newlines from the
+ top line of the display. Because rectangular selections are based on
+ newlines, rather than display wrapping, and anywhere a rectangular selection
+ needs a row, it needs it in terms of un-wrapped lines.
+ */
int Fl_Text_Display::wrapped_row(int row) const{
- if (!mContinuousWrap || row < 0 || row > mNVisibleLines)
- return row;
- return buffer()->count_lines(mFirstChar, mLineStarts[row]);
+ if (!mContinuousWrap || row < 0 || row > mNVisibleLines)
+ return row;
+ return buffer()->count_lines(mFirstChar, mLineStarts[row]);
}
/**
- Scroll the display to bring insertion cursor into view.
-**
- Note: it would be nice to be able to do this without counting lines twice
- (scroll_() counts them too) and/or to count from the most efficient
- starting point, but the efficiency of this routine is not as important to
- the overall performance of the text display.
-*/
+ Scroll the display to bring insertion cursor into view.
+ **
+ Note: it would be nice to be able to do this without counting lines twice
+ (scroll_() counts them too) and/or to count from the most efficient
+ starting point, but the efficiency of this routine is not as important to
+ the overall performance of the text display.
+ */
void Fl_Text_Display::display_insert() {
int hOffset, topLine, X, Y;
hOffset = mHorizOffset;
topLine = mTopLineNum;
-
-// FIXME: I don't understand this well enough to know if it is correct
-// it is different than nedit 5.3
+
+ // FIXME: I don't understand this well enough to know if it is correct
+ // it is different than nedit 5.3
if (insert_position() < mFirstChar) {
topLine -= count_lines(insert_position(), mFirstChar, false);
} else if (mLineStarts[mNVisibleLines-2] != -1) {
int lastChar = line_end(mLineStarts[mNVisibleLines-2],true);
if (insert_position() >= lastChar)
topLine
- += count_lines(lastChar - (wrap_uses_character(mLastChar) ? 0 : 1),
- insert_position(), false);
+ += count_lines(lastChar - (wrap_uses_character(mLastChar) ? 0 : 1),
+ insert_position(), false);
}
-
+
/* Find the new setting for horizontal offset (this is a bit ungraceful).
- If the line is visible, just use PositionToXY to get the position
- to scroll to, otherwise, do the vertical scrolling first, then the
- horizontal */
+ If the line is visible, just use PositionToXY to get the position
+ to scroll to, otherwise, do the vertical scrolling first, then the
+ horizontal */
if (!position_to_xy( mCursorPos, &X, &Y )) {
scroll_(topLine, hOffset);
if (!position_to_xy( mCursorPos, &X, &Y )) {
- #ifdef DEBUG
+#ifdef DEBUG
printf ("*** display_insert/position_to_xy # GIVE UP !\n"); fflush(stdout);
- #endif // DEBUG
+#endif // DEBUG
return; /* Give up, it's not worth it (but why does it fail?) */
}
}
@@ -876,7 +828,7 @@ void Fl_Text_Display::display_insert() {
hOffset += X-(text_area.x + text_area.w);
else if (X < text_area.x)
hOffset += X-text_area.x;
-
+
/* Do the scroll */
if (topLine != mTopLineNum || hOffset != mHorizOffset)
scroll_(topLine, hOffset);
@@ -889,43 +841,41 @@ void Fl_Text_Display::show_insert_position() {
}
/*
- Cursor movement functions
-*/
-/** Moves the current insert position right one character.*/
+ Cursor movement functions
+ */
+
+/**
+ Moves the current insert position right one character.
+ \return 1 if the cursor moved, 0 if the end of the text was reached
+ */
int Fl_Text_Display::move_right() {
- int ok = 0;
- while (!ok) {
if ( mCursorPos >= mBuffer->length() )
return 0;
- insert_position( mCursorPos + 1 );
- int pos = insert_position();
- // FIXME: character is ucs-4
- char c = buffer()->character( pos );
- if (!((c & 0x80) && !(c & 0x40))) ok = 1;
- }
+ int p = insert_position();
+ int q = buffer()->next_char(p);
+ insert_position(q);
return 1;
}
-/** Moves the current insert position left one character.*/
+
+/**
+ Moves the current insert position left one character.
+ \return 1 if the cursor moved, 0 if the beginning of the text was reached
+ */
int Fl_Text_Display::move_left() {
- int ok = 0;
- while (!ok) {
if ( mCursorPos <= 0 )
return 0;
- insert_position( mCursorPos - 1 );
- int pos = insert_position();
- // FIXME: character is ucs-4
- char c = buffer()->character( pos );
- if (!((c & 0x80) && !(c & 0x40))) ok = 1;
- }
+ int p = insert_position();
+ int q = buffer()->prev_char(p);
+ insert_position(q);
return 1;
}
/** Moves the current insert position up one line.*/
int Fl_Text_Display::move_up() {
int lineStartPos, column, prevLineStartPos, newPos, visLineNum;
-
+
/* Find the position of the start of the line. Use the line starts array
- if possible */
+ if possible */
if ( position_to_line( mCursorPos, &visLineNum ) )
lineStartPos = mLineStarts[ visLineNum ];
else {
@@ -934,11 +884,11 @@ int Fl_Text_Display::move_up() {
}
if ( lineStartPos == 0 )
return 0;
-
+
/* Decide what column to move to, if there's a preferred column use that */
column = mCursorPreferredCol >= 0 ? mCursorPreferredCol :
- mBuffer->count_displayed_characters( lineStartPos, mCursorPos );
-
+ mBuffer->count_displayed_characters( lineStartPos, mCursorPos );
+
/* count forward from the start of the previous line to reach the column */
if ( visLineNum != -1 && visLineNum != 0 )
prevLineStartPos = mLineStarts[ visLineNum - 1 ];
@@ -946,23 +896,23 @@ int Fl_Text_Display::move_up() {
prevLineStartPos = rewind_lines( lineStartPos, 1 );
newPos = mBuffer->skip_displayed_characters( prevLineStartPos, column );
if (mContinuousWrap)
- newPos = min(newPos, line_end(prevLineStartPos, true));
-
+ newPos = min(newPos, line_end(prevLineStartPos, true));
+
/* move the cursor */
insert_position( newPos );
-
- int ok = 0;
+
+ int ok = 0;
while (!ok) {
int pos = insert_position();
// FIXME: character is ucs-4
- char c = buffer()->character( pos );
+ char c = buffer()->char_at( pos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
} else {
insert_position( mCursorPos + 1 );
}
}
-
+
/* if a preferred column wasn't aleady established, establish it */
mCursorPreferredCol = column;
return 1;
@@ -971,7 +921,7 @@ int Fl_Text_Display::move_up() {
/** Moves the current insert position down one line.*/
int Fl_Text_Display::move_down() {
int lineStartPos, column, nextLineStartPos, newPos, visLineNum;
-
+
if ( mCursorPos == mBuffer->length() )
return 0;
if ( position_to_line( mCursorPos, &visLineNum ) )
@@ -981,18 +931,18 @@ int Fl_Text_Display::move_down() {
visLineNum = -1;
}
column = mCursorPreferredCol >= 0 ? mCursorPreferredCol :
- mBuffer->count_displayed_characters( lineStartPos, mCursorPos );
+ mBuffer->count_displayed_characters( lineStartPos, mCursorPos );
nextLineStartPos = skip_lines( lineStartPos, 1, true );
newPos = mBuffer->skip_displayed_characters( nextLineStartPos, column );
- if (mContinuousWrap)
- newPos = min(newPos, line_end(nextLineStartPos, true));
-
+ if (mContinuousWrap)
+ newPos = min(newPos, line_end(nextLineStartPos, true));
+
insert_position( newPos );
int ok = 0;
while (!ok) {
int pos = insert_position();
// FIXME: character is ucs-4
- char c = buffer()->character( pos );
+ char c = buffer()->char_at( pos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
} else {
@@ -1004,134 +954,134 @@ int Fl_Text_Display::move_down() {
}
/**
- Same as BufCountLines, but takes in to account wrapping if wrapping is
- turned on. If the caller knows that startPos is at a line start, it
- can pass "startPosIsLineStart" as True to make the call more efficient
- by avoiding the additional step of scanning back to the last newline.
-*/
+ Same as BufCountLines, but takes in to account wrapping if wrapping is
+ turned on. If the caller knows that startPos is at a line start, it
+ can pass "startPosIsLineStart" as True to make the call more efficient
+ by avoiding the additional step of scanning back to the last newline.
+ */
int Fl_Text_Display::count_lines(int startPos, int endPos,
- bool startPosIsLineStart) const {
- int retLines, retPos, retLineStart, retLineEnd;
-
+ bool startPosIsLineStart) const {
+ int retLines, retPos, retLineStart, retLineEnd;
+
#ifdef DEBUG
- printf("Fl_Text_Display::count_lines(startPos=%d, endPos=%d, startPosIsLineStart=%d\n",
- startPos, endPos, startPosIsLineStart);
+ printf("Fl_Text_Display::count_lines(startPos=%d, endPos=%d, startPosIsLineStart=%d\n",
+ startPos, endPos, startPosIsLineStart);
#endif // DEBUG
-
- /* If we're not wrapping use simple (and more efficient) BufCountLines */
- if (!mContinuousWrap)
- return buffer()->count_lines(startPos, endPos);
-
- wrapped_line_counter(buffer(), startPos, endPos, INT_MAX,
- startPosIsLineStart, 0, &retPos, &retLines, &retLineStart,
- &retLineEnd);
-
+
+ /* If we're not wrapping use simple (and more efficient) BufCountLines */
+ if (!mContinuousWrap)
+ return buffer()->count_lines(startPos, endPos);
+
+ wrapped_line_counter(buffer(), startPos, endPos, INT_MAX,
+ startPosIsLineStart, 0, &retPos, &retLines, &retLineStart,
+ &retLineEnd);
+
#ifdef DEBUG
- printf(" # after WLC: retPos=%d, retLines=%d, retLineStart=%d, retLineEnd=%d\n",
- retPos, retLines, retLineStart, retLineEnd);
+ printf(" # after WLC: retPos=%d, retLines=%d, retLineStart=%d, retLineEnd=%d\n",
+ retPos, retLines, retLineStart, retLineEnd);
#endif // DEBUG
-
- return retLines;
+
+ return retLines;
}
/**
- Same as BufCountForwardNLines, but takes in to account line breaks when
- wrapping is turned on. If the caller knows that startPos is at a line start,
- it can pass "startPosIsLineStart" as True to make the call more efficient
- by avoiding the additional step of scanning back to the last newline.
-*/
+ Same as BufCountForwardNLines, but takes in to account line breaks when
+ wrapping is turned on. If the caller knows that startPos is at a line start,
+ it can pass "startPosIsLineStart" as True to make the call more efficient
+ by avoiding the additional step of scanning back to the last newline.
+ */
int Fl_Text_Display::skip_lines(int startPos, int nLines,
- bool startPosIsLineStart) {
- int retLines, retPos, retLineStart, retLineEnd;
-
- /* if we're not wrapping use more efficient BufCountForwardNLines */
- if (!mContinuousWrap)
- return buffer()->skip_lines(startPos, nLines);
-
- /* wrappedLineCounter can't handle the 0 lines case */
- if (nLines == 0)
- return startPos;
-
- /* use the common line counting routine to count forward */
- wrapped_line_counter(buffer(), startPos, buffer()->length(),
- nLines, startPosIsLineStart, 0, &retPos, &retLines, &retLineStart,
- &retLineEnd);
- return retPos;
+ bool startPosIsLineStart) {
+ int retLines, retPos, retLineStart, retLineEnd;
+
+ /* if we're not wrapping use more efficient BufCountForwardNLines */
+ if (!mContinuousWrap)
+ return buffer()->skip_lines(startPos, nLines);
+
+ /* wrappedLineCounter can't handle the 0 lines case */
+ if (nLines == 0)
+ return startPos;
+
+ /* use the common line counting routine to count forward */
+ wrapped_line_counter(buffer(), startPos, buffer()->length(),
+ nLines, startPosIsLineStart, 0, &retPos, &retLines, &retLineStart,
+ &retLineEnd);
+ return retPos;
}
/**
- Same as BufEndOfLine, but takes in to account line breaks when wrapping
- is turned on. If the caller knows that startPos is at a line start, it
- can pass "startPosIsLineStart" as True to make the call more efficient
- by avoiding the additional step of scanning back to the last newline.
-**
- Note that the definition of the end of a line is less clear when continuous
- wrap is on. With continuous wrap off, it's just a pointer to the newline
- that ends the line. When it's on, it's the character beyond the last
- DISPLAYABLE character on the line, where a whitespace character which has
- been "converted" to a newline for wrapping is not considered displayable.
- Also note that, a line can be wrapped at a non-whitespace character if the
- line had no whitespace. In this case, this routine returns a pointer to
- the start of the next line. This is also consistent with the model used by
- visLineLength.
-*/
+ Same as BufEndOfLine, but takes in to account line breaks when wrapping
+ is turned on. If the caller knows that startPos is at a line start, it
+ can pass "startPosIsLineStart" as True to make the call more efficient
+ by avoiding the additional step of scanning back to the last newline.
+ **
+ Note that the definition of the end of a line is less clear when continuous
+ wrap is on. With continuous wrap off, it's just a pointer to the newline
+ that ends the line. When it's on, it's the character beyond the last
+ DISPLAYABLE character on the line, where a whitespace character which has
+ been "converted" to a newline for wrapping is not considered displayable.
+ Also note that, a line can be wrapped at a non-whitespace character if the
+ line had no whitespace. In this case, this routine returns a pointer to
+ the start of the next line. This is also consistent with the model used by
+ visLineLength.
+ */
int Fl_Text_Display::line_end(int pos, bool startPosIsLineStart) const {
- int retLines, retPos, retLineStart, retLineEnd;
-
- /* If we're not wrapping use more efficien BufEndOfLine */
- if (!mContinuousWrap)
- return buffer()->line_end(pos);
-
- if (pos == buffer()->length())
- return pos;
- wrapped_line_counter(buffer(), pos, buffer()->length(), 1,
- startPosIsLineStart, 0, &retPos, &retLines, &retLineStart,
- &retLineEnd);
- return retLineEnd;
+ int retLines, retPos, retLineStart, retLineEnd;
+
+ /* If we're not wrapping use more efficien BufEndOfLine */
+ if (!mContinuousWrap)
+ return buffer()->line_end(pos);
+
+ if (pos == buffer()->length())
+ return pos;
+ wrapped_line_counter(buffer(), pos, buffer()->length(), 1,
+ startPosIsLineStart, 0, &retPos, &retLines, &retLineStart,
+ &retLineEnd);
+ return retLineEnd;
}
/**
- Same as BufStartOfLine, but returns the character after last wrap point
- rather than the last newline.
-*/
+ Same as BufStartOfLine, but returns the character after last wrap point
+ rather than the last newline.
+ */
int Fl_Text_Display::line_start(int pos) const {
- int retLines, retPos, retLineStart, retLineEnd;
-
- /* If we're not wrapping, use the more efficient BufStartOfLine */
- if (!mContinuousWrap)
- return buffer()->line_start(pos);
-
- wrapped_line_counter(buffer(), buffer()->line_start(pos), pos, INT_MAX, true, 0,
- &retPos, &retLines, &retLineStart, &retLineEnd);
- return retLineStart;
+ int retLines, retPos, retLineStart, retLineEnd;
+
+ /* If we're not wrapping, use the more efficient BufStartOfLine */
+ if (!mContinuousWrap)
+ return buffer()->line_start(pos);
+
+ wrapped_line_counter(buffer(), buffer()->line_start(pos), pos, INT_MAX, true, 0,
+ &retPos, &retLines, &retLineStart, &retLineEnd);
+ return retLineStart;
}
/**
- Same as BufCountBackwardNLines, but takes in to account line breaks when
- wrapping is turned on.
-*/
+ Same as BufCountBackwardNLines, but takes in to account line breaks when
+ wrapping is turned on.
+ */
int Fl_Text_Display::rewind_lines(int startPos, int nLines) {
- Fl_Text_Buffer *buf = buffer();
- int pos, lineStart, retLines, retPos, retLineStart, retLineEnd;
-
- /* If we're not wrapping, use the more efficient BufCountBackwardNLines */
- if (!mContinuousWrap)
- return buf->rewind_lines(startPos, nLines);
-
- pos = startPos;
- for (;;) {
- lineStart = buf->line_start(pos);
- wrapped_line_counter(buf, lineStart, pos, INT_MAX,
- true, 0, &retPos, &retLines, &retLineStart, &retLineEnd, false);
- if (retLines > nLines)
- return skip_lines(lineStart, retLines-nLines,
- true);
- nLines -= retLines;
- pos = lineStart - 1;
- if (pos < 0)
- return 0;
- nLines -= 1;
- }
+ Fl_Text_Buffer *buf = buffer();
+ int pos, lineStart, retLines, retPos, retLineStart, retLineEnd;
+
+ /* If we're not wrapping, use the more efficient BufCountBackwardNLines */
+ if (!mContinuousWrap)
+ return buf->rewind_lines(startPos, nLines);
+
+ pos = startPos;
+ for (;;) {
+ lineStart = buf->line_start(pos);
+ wrapped_line_counter(buf, lineStart, pos, INT_MAX,
+ true, 0, &retPos, &retLines, &retLineStart, &retLineEnd, false);
+ if (retLines > nLines)
+ return skip_lines(lineStart, retLines-nLines,
+ true);
+ nLines -= retLines;
+ pos = lineStart - 1;
+ if (pos < 0)
+ return 0;
+ nLines -= 1;
+ }
}
static inline int fl_isseparator(int c) {
@@ -1142,14 +1092,14 @@ static inline int fl_isseparator(int c) {
void Fl_Text_Display::next_word() {
int pos = insert_position();
// FIXME: character is ucs-4
- while (pos < buffer()->length() && !fl_isseparator(buffer()->character(pos))) {
+ while (pos < buffer()->length() && !fl_isseparator(buffer()->char_at(pos))) {
pos++;
}
// FIXME: character is ucs-4
- while (pos < buffer()->length() && fl_isseparator(buffer()->character(pos))) {
+ while (pos < buffer()->length() && fl_isseparator(buffer()->char_at(pos))) {
pos++;
}
-
+
insert_position( pos );
}
@@ -1159,94 +1109,93 @@ void Fl_Text_Display::previous_word() {
if (pos==0) return;
pos--;
// FIXME: character is ucs-4
- while (pos && fl_isseparator(buffer()->character(pos))) {
+ while (pos && fl_isseparator(buffer()->char_at(pos))) {
pos--;
}
// FIXME: character is ucs-4
- while (pos && !fl_isseparator(buffer()->character(pos))) {
+ while (pos && !fl_isseparator(buffer()->char_at(pos))) {
pos--;
}
// FIXME: character is ucs-4
- if (fl_isseparator(buffer()->character(pos))) pos++;
-
+ if (fl_isseparator(buffer()->char_at(pos))) pos++;
+
insert_position( pos );
}
/**
- Callback attached to the text buffer to receive delete information before
- the modifications are actually made.
-*/
+ Callback attached to the text buffer to receive delete information before
+ the modifications are actually made.
+ */
void Fl_Text_Display::buffer_predelete_cb(int pos, int nDeleted, void *cbArg) {
- Fl_Text_Display *textD = (Fl_Text_Display *)cbArg;
- if (textD->mContinuousWrap &&
- (textD->mFixedFontWidth == -1 || textD->mModifyingTabDistance))
- /* Note: we must perform this measurement, even if there is not a
- single character deleted; the number of "deleted" lines is the
- number of visual lines spanned by the real line in which the
- modification takes place.
- Also, a modification of the tab distance requires the same
- kind of calculations in advance, even if the font width is "fixed",
- because when the width of the tab characters changes, the layout
- of the text may be completely different. */
- textD->measure_deleted_lines(pos, nDeleted);
- else
- textD->mSuppressResync = 0; /* Probably not needed, but just in case */
+ Fl_Text_Display *textD = (Fl_Text_Display *)cbArg;
+ if (textD->mContinuousWrap)
+ /* Note: we must perform this measurement, even if there is not a
+ single character deleted; the number of "deleted" lines is the
+ number of visual lines spanned by the real line in which the
+ modification takes place.
+ Also, a modification of the tab distance requires the same
+ kind of calculations in advance, even if the font width is "fixed",
+ because when the width of the tab characters changes, the layout
+ of the text may be completely different. */
+ textD->measure_deleted_lines(pos, nDeleted);
+ else
+ textD->mSuppressResync = 0; /* Probably not needed, but just in case */
}
/**
- Callback attached to the text buffer to receive modification information
-*/
+ Callback attached to the text buffer to receive modification information
+ */
void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted,
- int nRestyled, const char *deletedText, void *cbArg ) {
+ int nRestyled, const char *deletedText, void *cbArg ) {
int linesInserted, linesDeleted, startDispPos, endDispPos;
Fl_Text_Display *textD = ( Fl_Text_Display * ) cbArg;
Fl_Text_Buffer *buf = textD->mBuffer;
int oldFirstChar = textD->mFirstChar;
int scrolled, origCursorPos = textD->mCursorPos;
int wrapModStart, wrapModEnd;
-
+
/* buffer modification cancels vertical cursor motion column */
if ( nInserted != 0 || nDeleted != 0 )
textD->mCursorPreferredCol = -1;
-
- /* Count the number of lines inserted and deleted, and in the case
- of continuous wrap mode, how much has changed */
+
+ /* Count the number of lines inserted and deleted, and in the case
+ of continuous wrap mode, how much has changed */
+ if (textD->mContinuousWrap) {
+ textD->find_wrap_range(deletedText, pos, nInserted, nDeleted,
+ &wrapModStart, &wrapModEnd, &linesInserted, &linesDeleted);
+ } else {
+ linesInserted = nInserted == 0 ? 0 :
+ buf->count_lines( pos, pos + nInserted );
+ linesDeleted = nDeleted == 0 ? 0 : countlines( deletedText );
+ }
+
+ /* Update the line starts and mTopLineNum */
+ if ( nInserted != 0 || nDeleted != 0 ) {
if (textD->mContinuousWrap) {
- textD->find_wrap_range(deletedText, pos, nInserted, nDeleted,
- &wrapModStart, &wrapModEnd, &linesInserted, &linesDeleted);
+ textD->update_line_starts( wrapModStart, wrapModEnd-wrapModStart,
+ nDeleted + pos-wrapModStart + (wrapModEnd-(pos+nInserted)),
+ linesInserted, linesDeleted, &scrolled );
} else {
- linesInserted = nInserted == 0 ? 0 :
- buf->count_lines( pos, pos + nInserted );
- linesDeleted = nDeleted == 0 ? 0 : countlines( deletedText );
+ textD->update_line_starts( pos, nInserted, nDeleted, linesInserted,
+ linesDeleted, &scrolled );
}
-
- /* Update the line starts and mTopLineNum */
- if ( nInserted != 0 || nDeleted != 0 ) {
- if (textD->mContinuousWrap) {
- textD->update_line_starts( wrapModStart, wrapModEnd-wrapModStart,
- nDeleted + pos-wrapModStart + (wrapModEnd-(pos+nInserted)),
- linesInserted, linesDeleted, &scrolled );
- } else {
- textD->update_line_starts( pos, nInserted, nDeleted, linesInserted,
- linesDeleted, &scrolled );
- }
} else
scrolled = 0;
-
- /* If we're counting non-wrapped lines as well, maintain the absolute
- (non-wrapped) line number of the text displayed */
- if (textD->maintaining_absolute_top_line_number() &&
- (nInserted != 0 || nDeleted != 0)) {
- if (pos + nDeleted < oldFirstChar)
- textD->mAbsTopLineNum += buf->count_lines(pos, pos + nInserted) -
- countlines(deletedText);
- else if (pos < oldFirstChar)
- textD->reset_absolute_top_line_number();
- }
-
+
+ /* If we're counting non-wrapped lines as well, maintain the absolute
+ (non-wrapped) line number of the text displayed */
+ if (textD->maintaining_absolute_top_line_number() &&
+ (nInserted != 0 || nDeleted != 0)) {
+ if (pos + nDeleted < oldFirstChar)
+ textD->mAbsTopLineNum += buf->count_lines(pos, pos + nInserted) -
+ countlines(deletedText);
+ else if (pos < oldFirstChar)
+ textD->reset_absolute_top_line_number();
+ }
+
/* Update the line count for the whole buffer */
textD->mNBufferLines += linesInserted - linesDeleted;
-
+
/* Update the cursor position */
if ( textD->mCursorToHint != NO_HINT ) {
textD->mCursorPos = textD->mCursorToHint;
@@ -1257,13 +1206,13 @@ void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted,
else
textD->mCursorPos += nInserted - nDeleted;
}
-
+
// refigure scrollbars & stuff
textD->resize(textD->x(), textD->y(), textD->w(), textD->h());
-
+
// don't need to do anything else if not visible?
if (!textD->visible_r()) return;
-
+
/* If the changes caused scrolling, re-paint everything and we're done. */
if ( scrolled ) {
textD->damage(FL_DAMAGE_EXPOSE);
@@ -1271,12 +1220,12 @@ void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted,
textD->mStyleBuffer->primary_selection()->selected(0);
return;
}
-
+
/* If the changes didn't cause scrolling, decide the range of characters
- that need to be re-painted. Also if the cursor position moved, be
- sure that the redisplay range covers the old cursor position so the
- old cursor gets erased, and erase the bits of the cursor which extend
- beyond the left and right edges of the text. */
+ that need to be re-painted. Also if the cursor position moved, be
+ sure that the redisplay range covers the old cursor position so the
+ old cursor gets erased, and erase the bits of the cursor which extend
+ beyond the left and right edges of the text. */
startDispPos = textD->mContinuousWrap ? wrapModStart : pos;
if ( origCursorPos == startDispPos && textD->mCursorPos != startDispPos )
startDispPos = min( startDispPos, origCursorPos - 1 );
@@ -1285,99 +1234,99 @@ void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted,
endDispPos = pos + nRestyled;
else {
endDispPos = textD->mContinuousWrap ? wrapModEnd :
- buf->line_end( pos + nInserted ) + 1;
+ buf->line_end( pos + nInserted ) + 1;
// CET - FIXME if ( origCursorPos >= startDispPos &&
// ( origCursorPos <= endDispPos || endDispPos == buf->length() ) )
}
-
- if (linesInserted > 1) textD->draw_line_numbers(false);
+
+ if (linesInserted > 1) textD->draw_line_numbers(false);
} else {
endDispPos = textD->mLastChar + 1;
// CET - FIXME if ( origCursorPos >= pos )
- /* If more than one line is inserted/deleted, a line break may have
- been inserted or removed in between, and the line numbers may
- have changed. If only one line is altered, line numbers cannot
- be affected (the insertion or removal of a line break always
- results in at least two lines being redrawn). */
- textD->draw_line_numbers(false);
+ /* If more than one line is inserted/deleted, a line break may have
+ been inserted or removed in between, and the line numbers may
+ have changed. If only one line is altered, line numbers cannot
+ be affected (the insertion or removal of a line break always
+ results in at least two lines being redrawn). */
+ textD->draw_line_numbers(false);
}
-
+
/* If there is a style buffer, check if the modification caused additional
- changes that need to be redisplayed. (Redisplaying separately would
- cause double-redraw on almost every modification involving styled
- text). Extend the redraw range to incorporate style changes */
+ changes that need to be redisplayed. (Redisplaying separately would
+ cause double-redraw on almost every modification involving styled
+ text). Extend the redraw range to incorporate style changes */
if ( textD->mStyleBuffer )
textD->extend_range_for_styles( &startDispPos, &endDispPos );
-
+
/* Redisplay computed range */
textD->redisplay_range( startDispPos, endDispPos ); // FIXME utf8
}
/**
- In continuous wrap mode, internal line numbers are calculated after
- wrapping. A separate non-wrapped line count is maintained when line
- numbering is turned on. There is some performance cost to maintaining this
- line count, so normally absolute line numbers are not tracked if line
- numbering is off. This routine allows callers to specify that they still
- want this line count maintained (for use via TextDPosToLineAndCol).
- More specifically, this allows the line number reported in the statistics
- line to be calibrated in absolute lines, rather than post-wrapped lines.
-*/
+ In continuous wrap mode, internal line numbers are calculated after
+ wrapping. A separate non-wrapped line count is maintained when line
+ numbering is turned on. There is some performance cost to maintaining this
+ line count, so normally absolute line numbers are not tracked if line
+ numbering is off. This routine allows callers to specify that they still
+ want this line count maintained (for use via TextDPosToLineAndCol).
+ More specifically, this allows the line number reported in the statistics
+ line to be calibrated in absolute lines, rather than post-wrapped lines.
+ */
void Fl_Text_Display::maintain_absolute_top_line_number(int state) {
- mNeedAbsTopLineNum = state;
- reset_absolute_top_line_number();
+ mNeedAbsTopLineNum = state;
+ reset_absolute_top_line_number();
}
/**
- Returns the absolute (non-wrapped) line number of the first line displayed.
- Returns 0 if the absolute top line number is not being maintained.
-*/
+ Returns the absolute (non-wrapped) line number of the first line displayed.
+ Returns 0 if the absolute top line number is not being maintained.
+ */
int Fl_Text_Display::get_absolute_top_line_number() const {
- if (!mContinuousWrap)
- return mTopLineNum;
- if (maintaining_absolute_top_line_number())
- return mAbsTopLineNum;
- return 0;
+ if (!mContinuousWrap)
+ return mTopLineNum;
+ if (maintaining_absolute_top_line_number())
+ return mAbsTopLineNum;
+ return 0;
}
/**
- Re-calculate absolute top line number for a change in scroll position.
-*/
+ Re-calculate absolute top line number for a change in scroll position.
+ */
void Fl_Text_Display::absolute_top_line_number(int oldFirstChar) {
- if (maintaining_absolute_top_line_number()) {
- if (mFirstChar < oldFirstChar)
- mAbsTopLineNum -= buffer()->count_lines(mFirstChar, oldFirstChar);
- else
- mAbsTopLineNum += buffer()->count_lines(oldFirstChar, mFirstChar);
- }
+ if (maintaining_absolute_top_line_number()) {
+ if (mFirstChar < oldFirstChar)
+ mAbsTopLineNum -= buffer()->count_lines(mFirstChar, oldFirstChar);
+ else
+ mAbsTopLineNum += buffer()->count_lines(oldFirstChar, mFirstChar);
+ }
}
/**
- Return true if a separate absolute top line number is being maintained
- (for displaying line numbers or showing in the statistics line).
-*/
+ Return true if a separate absolute top line number is being maintained
+ (for displaying line numbers or showing in the statistics line).
+ */
int Fl_Text_Display::maintaining_absolute_top_line_number() const {
- return mContinuousWrap &&
- (mLineNumWidth != 0 || mNeedAbsTopLineNum);
+ return mContinuousWrap &&
+ (mLineNumWidth != 0 || mNeedAbsTopLineNum);
}
/**
- Count lines from the beginning of the buffer to reestablish the
- absolute (non-wrapped) top line number. If mode is not continuous wrap,
- or the number is not being maintained, does nothing.
-*/
+ Count lines from the beginning of the buffer to reestablish the
+ absolute (non-wrapped) top line number. If mode is not continuous wrap,
+ or the number is not being maintained, does nothing.
+ */
void Fl_Text_Display::reset_absolute_top_line_number() {
- mAbsTopLineNum = 1;
- absolute_top_line_number(0);
+ mAbsTopLineNum = 1;
+ absolute_top_line_number(0);
}
/**
- Find the line number of position "pos" relative to the first line of
- displayed text. Returns 0 if the line is not displayed.
-*/
+ Find the line number of position "pos" relative to the first line of
+ displayed text. Returns 0 if the line is not displayed.
+ */
int Fl_Text_Display::position_to_line( int pos, int *lineNum ) const {
int i;
-
+
*lineNum = 0;
if ( pos < mFirstChar ) return 0;
if ( pos > mLastChar ) {
@@ -1395,7 +1344,7 @@ int Fl_Text_Display::position_to_line( int pos, int *lineNum ) const {
}
return 0;
}
-
+
for ( i = mNVisibleLines - 1; i >= 0; i-- ) {
if ( mLineStarts[ i ] != -1 && pos >= mLineStarts[ i ] ) {
*lineNum = i;
@@ -1405,231 +1354,196 @@ int Fl_Text_Display::position_to_line( int pos, int *lineNum ) const {
return 0; /* probably never be reached */
}
+// We use a single function that handles all line layout, measuring, and drawing
+// - draw a text range
+// - return the width of a text range in pixels
+// - return the index of a char that is at a pixel position
+//
+// - we need to handle hidden hyphens and tabs here!
+// - we handle all styles and selections
+//
+// needs:
+// mode: draw, find width, find index
+// index of first character
+// size of string in bytes
+// x and y drawing position
+// width and height of drawing rectangle
+//
+// returns:
+// width of drawing in pixels
+// index of last character that fits into the box
+//
+// enum { DRAW_LINE, FIND_INDEX, GET_WIDTH };
+//
+//
+int Fl_Text_Display::handle_vline(
+ int mode,
+ int lineStartPos, int lineLen, int leftChar, int rightChar,
+ int Y, int bottomClip,
+ int leftClip, int rightClip) const
+{
+ // FIXME: we need to allow two modes for FIND_INDEX: one on the edge of the
+ // FIXME: character for selection, and one on the character center for cursors.
+ int i, X, startX, startIndex, style, charStyle;
+ char *lineStr;
+
+ if ( lineStartPos == -1 ) {
+ lineStr = NULL;
+ } else {
+ lineStr = mBuffer->text_range( lineStartPos, lineStartPos + lineLen );
+ }
+
+ if (mode==GET_WIDTH)
+ X = 0;
+ else
+ X = text_area.x - mHorizOffset;
+
+ startX = X;
+ startIndex = 0;
+ if (!lineStr) {
+ // just clear the background
+ if (mode==DRAW_LINE) {
+ style = position_style(lineStartPos, lineLen, -1);
+ draw_string( style|BG_ONLY_MASK, text_area.x, Y, text_area.x+text_area.w, lineStr, lineLen );
+ }
+ if (mode==FIND_INDEX)
+ return lineStartPos;
+ return 0;
+ }
+
+ // draw the line
+ style = position_style(lineStartPos, lineLen, 0);
+ for (i=0; i<lineLen; ) {
+ int len = fl_utf8len(lineStr[i]);
+ charStyle = position_style(lineStartPos, lineLen, i);
+ // FIXME: if the character is a tab, we need to do the correct indenting
+ // FIXME: if the character is an optional hyphen, we need to ignore it unless we wrap the text
+ if (charStyle!=style) {
+ // draw a segment whenever the style changes
+ int w = string_width( lineStr+startIndex, i-startIndex, style );
+ if (mode==DRAW_LINE)
+ draw_string( style, startX, Y, startX+w, lineStr+startIndex, i-startIndex );
+ if (mode==FIND_INDEX && startX+w>rightClip) {
+ // find x pos inside block
+ int di = find_x(lineStr+startIndex, i-startIndex, style, rightClip-startX);
+ free(lineStr);
+ return lineStartPos + startIndex + di;
+ }
+ style = charStyle;
+ startX += w;
+ startIndex = i;
+ }
+ if (len==-1) {
+ // FIXME: what happened? Is there an illegal charater, or an illegal index?
+ len = 1;
+ }
+ i += len;
+ }
+ int w = string_width( lineStr+startIndex, i-startIndex, style );
+ if (mode==DRAW_LINE)
+ draw_string( style, startX, Y, startX+w, lineStr+startIndex, i-startIndex );
+ if (mode==FIND_INDEX) {
+ // find x pos inside block
+ int di = find_x(lineStr+startIndex, i-startIndex, style, rightClip-startX);
+ free(lineStr);
+ return lineStartPos + startIndex + di;
+ }
+ if (mode==GET_WIDTH) {
+ free(lineStr);
+ return startX+w;
+ }
+
+ // clear the rest of the line
+ startX += w;
+ style = position_style(lineStartPos, lineLen, i);
+ if (mode==DRAW_LINE)
+ draw_string( style|BG_ONLY_MASK, startX, Y, text_area.x+text_area.w, lineStr, lineLen );
+
+ free(lineStr);
+ return lineStartPos + lineLen;
+}
+
+int Fl_Text_Display::find_x(const char *s, int len, int style, int x) const {
+ // FIXME: use binary search which is much quicker!
+ int i = 0;
+ while (i<len) {
+ int cl = fl_utf8len(s[i]);
+ int w = string_width(s, i+cl, style);
+ if (w>x)
+ return i;
+ i += cl;
+ }
+ return len;
+}
+
+
/**
- Draw the text on a single line represented by "visLineNum" (the
- number of lines down from the top of the display), limited by
- "leftClip" and "rightClip" window coordinates and "leftCharIndex" and
- "rightCharIndex" character positions (not including the character at
- position "rightCharIndex").
-*/
+ Draw the text on a single line represented by "visLineNum" (the
+ number of lines down from the top of the display), limited by
+ "leftClip" and "rightClip" window coordinates and "leftCharIndex" and
+ "rightCharIndex" character positions (not including the character at
+ position "rightCharIndex").
+ */
void Fl_Text_Display::draw_vline(int visLineNum, int leftClip, int rightClip,
int leftCharIndex, int rightCharIndex) {
- Fl_Text_Buffer * buf = mBuffer;
- int i, X, Y, startX, charIndex, lineStartPos, lineLen, fontHeight;
- int stdCharWidth, charWidth, startIndex, charStyle, style;
- int charLen, outStartIndex, outIndex;
- int dispIndexOffset;
- char expandedChar[ FL_TEXT_MAX_EXP_CHAR_LEN ], outStr[ MAX_DISP_LINE_LEN ];
- char *outPtr;
- const char *lineStr;
-
-// printf("draw_vline(visLineNum=%d, leftClip=%d, rightClip=%d, leftCharIndex=%d, rightCharIndex=%d)\n",
-// visLineNum, leftClip, rightClip, leftCharIndex, rightCharIndex);
-// printf("nNVisibleLines=%d\n", mNVisibleLines);
-
+ int Y, lineStartPos, lineLen, fontHeight;
+ int stdCharWidth;
+
+ // printf("draw_vline(visLineNum=%d, leftClip=%d, rightClip=%d, leftCharIndex=%d, rightCharIndex=%d)\n",
+ // visLineNum, leftClip, rightClip, leftCharIndex, rightCharIndex);
+ // printf("nNVisibleLines=%d\n", mNVisibleLines);
+
/* If line is not displayed, skip it */
if ( visLineNum < 0 || visLineNum >= mNVisibleLines )
return;
-
+
/* Calculate Y coordinate of the string to draw */
fontHeight = mMaxsize;
Y = text_area.y + visLineNum * fontHeight;
-
+
/* Get the text, length, and buffer position of the line to display */
lineStartPos = mLineStarts[ visLineNum ];
-// printf("lineStartPos=%d\n", lineStartPos);
+ // printf("lineStartPos=%d\n", lineStartPos);
if ( lineStartPos == -1 ) {
lineLen = 0;
- lineStr = NULL;
} else {
lineLen = vline_length( visLineNum );
- lineStr = buf->text_range( lineStartPos, lineStartPos + lineLen );
}
-
+
/* Space beyond the end of the line is still counted in units of characters
- of a standardized character width (this is done mostly because style
- changes based on character position can still occur in this region due
- to rectangular Fl_Text_Selections). stdCharWidth must be non-zero to
- prevent a potential infinite loop if X does not advance */
+ of a standardized character width (this is done mostly because style
+ changes based on character position can still occur in this region due
+ to rectangular Fl_Text_Selections). stdCharWidth must be non-zero to
+ prevent a potential infinite loop if X does not advance */
stdCharWidth = TMPFONTWIDTH; //mFontStruct->max_bounds.width;
if ( stdCharWidth <= 0 ) {
Fl::error("Fl_Text_Display::draw_vline(): bad font measurement");
- if (lineStr) free((void *)lineStr);
return;
}
-
+
/* Shrink the clipping range to the active display area */
leftClip = max( text_area.x, leftClip );
rightClip = min( rightClip, text_area.x + text_area.w );
-
- /* Rectangular Fl_Text_Selections are based on "real" line starts (after
- a newline or start of buffer). Calculate the difference between the
- last newline position and the line start we're using. Since scanning
- back to find a newline is expensive, only do so if there's actually a
- rectangular Fl_Text_Selection which needs it */
- if (mContinuousWrap && (range_touches_selection(buf->primary_selection(),
- lineStartPos, lineStartPos + lineLen) || range_touches_selection(
- buf->secondary_selection(), lineStartPos, lineStartPos + lineLen) ||
- range_touches_selection(buf->highlight_selection(), lineStartPos,
- lineStartPos + lineLen))) {
- dispIndexOffset = buf->count_displayed_characters(
- buf->line_start(lineStartPos), lineStartPos);
- } else
- dispIndexOffset = 0;
-
- /* Step through character positions from the beginning of the line (even if
- that's off the left edge of the displayed area) to find the first
- character position that's not clipped, and the X coordinate for drawing
- that character */
- X = text_area.x - mHorizOffset;
- outIndex = 0;
- for ( charIndex = 0; ; charIndex += lineStr ? fl_utf8len(lineStr[charIndex]) : 1 ) {
- charLen = charIndex >= lineLen ? 1 :
- Fl_Text_Buffer::expand_character( lineStr+charIndex, outIndex,
- expandedChar, buf->tab_distance());
- style = position_style( lineStartPos, lineLen, charIndex,
- outIndex + dispIndexOffset );
- charWidth = charIndex >= lineLen ? stdCharWidth :
- string_width( expandedChar, charLen, style );
- if ( X + charWidth >= leftClip && charIndex >= leftCharIndex ) {
- startIndex = charIndex;
- outStartIndex = outIndex;
- startX = X;
- break;
- }
- X += charWidth;
- outIndex += charLen;
- }
-
- /* Scan character positions from the beginning of the clipping range, and
- draw parts whenever the style changes (also note if the cursor is on
- this line, and where it should be drawn to take advantage of the x
- position which we've gone to so much trouble to calculate) */
- /* since characters between style may overlap, we draw the full
- background first */
- int sX = startX;
- outPtr = outStr;
- outIndex = outStartIndex;
- X = startX;
- for (charIndex = startIndex;
- charIndex < rightCharIndex;
- charIndex += lineStr ? fl_utf8len(lineStr[charIndex]) : 1 )
- {
- charLen = charIndex >= lineLen ? 1 :
- Fl_Text_Buffer::expand_character( lineStr+charIndex, outIndex, expandedChar,
- buf->tab_distance());
- charStyle = position_style( lineStartPos, lineLen, charIndex,
- outIndex + dispIndexOffset );
- for ( i = 0; i < charLen; i++ ) { // FIXME: this rips apart the utf-8 sequneces
- if ( i != 0 && charIndex < lineLen && lineStr[ charIndex ] == '\t' )
- charStyle = position_style( lineStartPos, lineLen,
- charIndex, outIndex + dispIndexOffset );
- if ( charStyle != style ) {
- draw_string( style|BG_ONLY_MASK, sX, Y, X, outStr, outPtr - outStr );
- outPtr = outStr;
- sX = X;
- style = charStyle;
- }
- if ( charIndex < lineLen ) {
- *outPtr = expandedChar[ i ];
- int l = 1;
- if (*outPtr & 0x80) {
- l = fl_utf8len(*outPtr);
- if (l<=0) l = 1;
- }
- charWidth = string_width( &expandedChar[ i ], l, charStyle );
- } else
- charWidth = stdCharWidth;
- outPtr++;
- X += charWidth;
- outIndex++;
- }
- if ( outPtr - outStr + FL_TEXT_MAX_EXP_CHAR_LEN >= MAX_DISP_LINE_LEN || X >= rightClip )
- break;
- }
- draw_string( style|BG_ONLY_MASK, sX, Y, X, outStr, outPtr - outStr );
-
- /* now draw the text over the previously erased background */
- outPtr = outStr;
- outIndex = outStartIndex;
- X = startX;
- for (charIndex = startIndex;
- charIndex < rightCharIndex;
- charIndex += lineStr ? fl_utf8len(lineStr[charIndex]) : 0)
- {
- charLen = charIndex >= lineLen ? 1 :
- Fl_Text_Buffer::expand_character( lineStr+charIndex, outIndex, expandedChar,
- buf->tab_distance());
- charStyle = position_style( lineStartPos, lineLen, charIndex,
- outIndex + dispIndexOffset );
- for ( i = 0; i < charLen; i++ ) { // FIXME: this rips apart the utf-8 sequneces
- if ( i != 0 && charIndex < lineLen && lineStr[ charIndex ] == '\t' )
- charStyle = position_style( lineStartPos, lineLen,
- charIndex, outIndex + dispIndexOffset );
- if ( charStyle != style ) {
- draw_string( style|TEXT_ONLY_MASK, startX, Y, X, outStr, outPtr - outStr );
- outPtr = outStr;
- startX = X;
- style = charStyle;
- }
- if ( charIndex < lineLen ) {
- *outPtr = expandedChar[ i ];
- int l = 1;
- if (*outPtr & 0x80) {
- l = fl_utf8len(*outPtr);
- if (l<=0) l = 1;
- }
- charWidth = string_width( &expandedChar[ i ], l, charStyle );
- } else
- charWidth = stdCharWidth;
- outPtr++;
- X += charWidth;
- outIndex++;
- }
- if ( outPtr - outStr + FL_TEXT_MAX_EXP_CHAR_LEN >= MAX_DISP_LINE_LEN || X >= rightClip )
- break;
- }
-
- /* Draw the remaining style segment */
- draw_string( style|TEXT_ONLY_MASK, startX, Y, X, outStr, outPtr - outStr );
-
- /* Draw the cursor if part of it appeared on the redisplayed part of
- this line. Also check for the cases which are not caught as the
- line is scanned above: when the cursor appears at the very end
- of the redisplayed section. */
- /* CET - FIXME
- if ( mCursorOn )
- {
- if ( hasCursor )
- draw_cursor( cursorX, Y );
- else if ( charIndex < lineLen && ( lineStartPos + charIndex + 1 == cursorPos )
- && X == rightClip )
- {
- if ( cursorPos >= buf->length() )
- draw_cursor( X - 1, Y );
- else
- {
- draw_cursor( X - 1, Y );
- }
- }
- }
- */
- if ( lineStr != NULL )
- free((void *)lineStr);
+
+ handle_vline(DRAW_LINE,
+ lineStartPos, lineLen, leftCharIndex, rightCharIndex,
+ Y, Y+fontHeight, leftClip, rightClip);
+ return;
}
/**
- Draw a string or blank area according to parameter "style", using the
- appropriate colors and drawing method for that style, with top left
- corner at X, y. If style says to draw text, use "string" as source of
- characters, and draw "nChars", if style is FILL, erase
- rectangle where text would have drawn from X to toX and from Y to
- the maximum Y extent of the current font(s).
-*/
-void Fl_Text_Display::draw_string( int style, int X, int Y, int toX,
- const char *string, int nChars ) {
+ Draw a string or blank area according to parameter "style", using the
+ appropriate colors and drawing method for that style, with top left
+ corner at X, y. If style says to draw text, use "string" as source of
+ characters, and draw "nChars", if style is FILL, erase
+ rectangle where text would have drawn from X to toX and from Y to
+ the maximum Y extent of the current font(s).
+ */
+void Fl_Text_Display::draw_string(int style,
+ int X, int Y, int toX,
+ const char *string, int nChars) const {
const Style_Table_Entry * styleRec;
-
+
/* Draw blank area rather than text, if that was the request */
if ( style & FILL_MASK ) {
if (style & TEXT_ONLY_MASK) return;
@@ -1637,24 +1551,24 @@ void Fl_Text_Display::draw_string( int style, int X, int Y, int toX,
return;
}
/* Set font, color, and gc depending on style. For normal text, GCs
- for normal drawing, or drawing within a Fl_Text_Selection or highlight are
- pre-allocated and pre-configured. For syntax highlighting, GCs are
- configured here, on the fly. */
-
+ for normal drawing, or drawing within a Fl_Text_Selection or highlight are
+ pre-allocated and pre-configured. For syntax highlighting, GCs are
+ configured here, on the fly. */
+
Fl_Font font = textfont();
int fsize = textsize();
Fl_Color foreground;
Fl_Color background;
-
+
if ( style & STYLE_LOOKUP_MASK ) {
int si = (style & STYLE_LOOKUP_MASK) - 'A';
if (si < 0) si = 0;
else if (si >= mNStyles) si = mNStyles - 1;
-
+
styleRec = mStyleTable + si;
font = styleRec->font;
fsize = styleRec->size;
-
+
if (style & PRIMARY_MASK) {
if (Fl::focus() == this) background = selection_color();
else background = fl_color_average(color(), selection_color(), 0.4f);
@@ -1675,7 +1589,7 @@ void Fl_Text_Display::draw_string( int style, int X, int Y, int toX,
foreground = textcolor();
background = color();
}
-
+
if (!(style & TEXT_ONLY_MASK)) {
fl_color( background );
fl_rectf( X, Y, toX - X, mMaxsize );
@@ -1685,37 +1599,38 @@ void Fl_Text_Display::draw_string( int style, int X, int Y, int toX,
fl_font( font, fsize );
fl_draw( string, nChars, X, Y + mMaxsize - fl_descent());
}
-
+
// CET - FIXME
/* If any space around the character remains unfilled (due to use of
- different sized fonts for highlighting), fill in above or below
- to erase previously drawn characters */
+ different sized fonts for highlighting), fill in above or below
+ to erase previously drawn characters */
/*
- if (fs->ascent < mAscent)
- clear_rect( style, X, Y, toX - X, mAscent - fs->ascent);
- if (fs->descent < mDescent)
- clear_rect( style, X, Y + mAscent + fs->descent, toX - x,
- mDescent - fs->descent);
- */
+ if (fs->ascent < mAscent)
+ clear_rect( style, X, Y, toX - X, mAscent - fs->ascent);
+ if (fs->descent < mDescent)
+ clear_rect( style, X, Y + mAscent + fs->descent, toX - x,
+ mDescent - fs->descent);
+ */
/* Underline if style is secondary Fl_Text_Selection */
-
+
/*
- if (style & SECONDARY_MASK)
- XDrawLine(XtDisplay(mW), XtWindow(mW), gc, x,
- y + mAscent, toX - 1, Y + fs->ascent);
- */
+ if (style & SECONDARY_MASK)
+ XDrawLine(XtDisplay(mW), XtWindow(mW), gc, x,
+ y + mAscent, toX - 1, Y + fs->ascent);
+ */
}
/**
- Clear a rectangle with the appropriate background color for "style"
-*/
-void Fl_Text_Display::clear_rect( int style, int X, int Y,
- int width, int height ) {
+ Clear a rectangle with the appropriate background color for "style"
+ */
+void Fl_Text_Display::clear_rect(int style,
+ int X, int Y,
+ int width, int height) const {
/* A width of zero means "clear to end of window" to XClearArea */
if ( width == 0 )
return;
-
+
if (style & PRIMARY_MASK) {
if (Fl::focus()==this) {
fl_color(selection_color());
@@ -1736,14 +1651,14 @@ void Fl_Text_Display::clear_rect( int style, int X, int Y,
/**
- Draw a cursor with top center at X, y.
-*/
+ Draw a cursor with top center at X, y.
+ */
void Fl_Text_Display::draw_cursor( int X, int Y ) {
typedef struct {
int x1, y1, x2, y2;
}
Segment;
-
+
Segment segs[ 5 ];
int left, right, cursorWidth, midY;
// int fontWidth = mFontStruct->min_bounds.width, nSegs = 0;
@@ -1751,17 +1666,17 @@ void Fl_Text_Display::draw_cursor( int X, int Y ) {
int nSegs = 0;
int fontHeight = mMaxsize;
int bot = Y + fontHeight - 1;
-
+
if ( X < text_area.x - 1 || X > text_area.x + text_area.w )
return;
-
+
/* For cursors other than the block, make them around 2/3 of a character
- width, rounded to an even number of pixels so that X will draw an
- odd number centered on the stem at x. */
+ width, rounded to an even number of pixels so that X will draw an
+ odd number centered on the stem at x. */
cursorWidth = 4; //(fontWidth/3) * 2;
left = X - cursorWidth / 2;
right = left + cursorWidth;
-
+
/* Create segments and draw cursor */
if ( mCursorStyle == CARET_CURSOR ) {
midY = bot - fontHeight / 5;
@@ -1797,72 +1712,70 @@ void Fl_Text_Display::draw_cursor( int X, int Y ) {
nSegs = 4;
}
fl_color( mCursor_color );
-
+
for ( int k = 0; k < nSegs; k++ ) {
fl_line( segs[ k ].x1, segs[ k ].y1, segs[ k ].x2, segs[ k ].y2 );
}
}
/**
- Determine the drawing method to use to draw a specific character from "buf".
- "lineStartPos" gives the character index where the line begins, "lineIndex",
- the number of characters past the beginning of the line, and "dispIndex",
- the number of displayed characters past the beginning of the line. Passing
- lineStartPos of -1 returns the drawing style for "no text".
-**
- Why not just: position_style(pos)? Because style applies to blank areas
- of the window beyond the text boundaries, and because this routine must also
- decide whether a position is inside of a rectangular Fl_Text_Selection, and do
- so efficiently, without re-counting character positions from the start of the
- line.
-**
- Note that style is a somewhat incorrect name, drawing method would
- be more appropriate.
-*/
-int Fl_Text_Display::position_style( int lineStartPos,
- int lineLen, int lineIndex, int dispIndex ) const {
+ Determine the drawing method to use to draw a specific character from "buf".
+ "lineStartPos" gives the character index where the line begins, "lineIndex",
+ the number of characters past the beginning of the line, and "dispIndex",
+ the number of displayed characters past the beginning of the line. Passing
+ lineStartPos of -1 returns the drawing style for "no text".
+ **
+ Why not just: position_style(pos)? Because style applies to blank areas
+ of the window beyond the text boundaries, and because this routine must also
+ decide whether a position is inside of a rectangular Fl_Text_Selection, and do
+ so efficiently, without re-counting character positions from the start of the
+ line.
+ **
+ Note that style is a somewhat incorrect name, drawing method would
+ be more appropriate.
+ */
+int Fl_Text_Display::position_style( int lineStartPos, int lineLen, int lineIndex) const
+{
Fl_Text_Buffer * buf = mBuffer;
Fl_Text_Buffer *styleBuf = mStyleBuffer;
int pos, style = 0;
-
+
if ( lineStartPos == -1 || buf == NULL )
return FILL_MASK;
-
+
pos = lineStartPos + min( lineIndex, lineLen );
-
+
if ( lineIndex >= lineLen )
style = FILL_MASK;
else if ( styleBuf != NULL ) {
- // FIXME: character is ucs-4
- style = ( unsigned char ) styleBuf->character( pos );
+ style = ( unsigned char ) styleBuf->byte_at( pos );
if (style == mUnfinishedStyle && mUnfinishedHighlightCB) {
- /* encountered "unfinished" style, trigger parsing */
- (mUnfinishedHighlightCB)( pos, mHighlightCBArg);
- // FIXME: character is ucs-4
- style = (unsigned char) styleBuf->character( pos);
+ /* encountered "unfinished" style, trigger parsing */
+ (mUnfinishedHighlightCB)( pos, mHighlightCBArg);
+ style = (unsigned char) styleBuf->byte_at( pos);
}
}
- if (buf->primary_selection()->includes(pos, lineStartPos, dispIndex))
+ if (buf->primary_selection()->includes(pos))
style |= PRIMARY_MASK;
- if (buf->highlight_selection()->includes(pos, lineStartPos, dispIndex))
+ if (buf->highlight_selection()->includes(pos))
style |= HIGHLIGHT_MASK;
- if (buf->secondary_selection()->includes(pos, lineStartPos, dispIndex))
+ if (buf->secondary_selection()->includes(pos))
style |= SECONDARY_MASK;
return style;
}
/**
- Find the width of a string in the font of a particular style
-*/
+ Find the width of a string in the font of a particular style
+ */
int Fl_Text_Display::string_width( const char *string, int length, int style ) const {
Fl_Font font;
int fsize;
-
+
if ( style & STYLE_LOOKUP_MASK ) {
int si = (style & STYLE_LOOKUP_MASK) - 'A';
if (si < 0) si = 0;
else if (si >= mNStyles) si = mNStyles - 1;
-
+
font = mStyleTable[si].font;
fsize = mStyleTable[si].size;
} else {
@@ -1870,23 +1783,21 @@ int Fl_Text_Display::string_width( const char *string, int length, int style ) c
fsize = textsize();
}
fl_font( font, fsize );
-
+
return ( int ) ( fl_width( string, length ) );
}
/**
- Translate window coordinates to the nearest (insert cursor or character
- cell) text position. The parameter posType specifies how to interpret the
- position: CURSOR_POS means translate the coordinates to the nearest cursor
- position, and CHARACTER_POS means return the position of the character
- closest to (X, Y).
-*/
+ Translate window coordinates to the nearest (insert cursor or character
+ cell) text position. The parameter posType specifies how to interpret the
+ position: CURSOR_POS means translate the coordinates to the nearest cursor
+ position, and CHARACTER_POS means return the position of the character
+ closest to (X, Y).
+ */
int Fl_Text_Display::xy_to_position( int X, int Y, int posType ) const {
- int charIndex, lineStart, lineLen, fontHeight;
- int charWidth, charLen, charStyle, visLineNum, xStep, outIndex;
- char expandedChar[ FL_TEXT_MAX_EXP_CHAR_LEN ];
- const char *lineStr;
-
+ int lineStart, lineLen, fontHeight;
+ int visLineNum;
+
/* Find the visible line number corresponding to the Y coordinate */
fontHeight = mMaxsize;
visLineNum = ( Y - text_area.y ) / fontHeight;
@@ -1894,73 +1805,52 @@ int Fl_Text_Display::xy_to_position( int X, int Y, int posType ) const {
return mFirstChar;
if ( visLineNum >= mNVisibleLines )
visLineNum = mNVisibleLines - 1;
-
+
/* Find the position at the start of the line */
lineStart = mLineStarts[ visLineNum ];
-
+
/* If the line start was empty, return the last position in the buffer */
if ( lineStart == -1 )
return mBuffer->length();
-
+
/* Get the line text and its length */
lineLen = vline_length( visLineNum );
- lineStr = mBuffer->text_range( lineStart, lineStart + lineLen );
-
- /* Step through character positions from the beginning of the line
- to find the character position corresponding to the X coordinate */
- xStep = text_area.x - mHorizOffset;
- outIndex = 0;
- for (charIndex = 0;
- charIndex < lineLen;
- charIndex += fl_utf8len(lineStr[charIndex]) )
- {
- charLen = Fl_Text_Buffer::expand_character( lineStr+charIndex, outIndex, expandedChar,
- mBuffer->tab_distance());
- charStyle = position_style( lineStart, lineLen, charIndex, outIndex );
- charWidth = string_width( expandedChar, charLen, charStyle );
- if ( X < xStep + ( posType == CURSOR_POS ? charWidth / 2 : charWidth ) ) {
- free((char *)lineStr);
- return lineStart + charIndex;
- }
- xStep += charWidth;
- outIndex += charLen;
- }
-
- /* If the X position was beyond the end of the line, return the position
- of the newline at the end of the line */
- free((char *)lineStr);
- return lineStart + lineLen;
+
+ return handle_vline(FIND_INDEX,
+ lineStart, lineLen, 0, 0,
+ 0, 0,
+ text_area.x, X);
}
/**
- Translate window coordinates to the nearest row and column number for
- positioning the cursor. This, of course, makes no sense when the font is
- proportional, since there are no absolute columns. The parameter posType
- specifies how to interpret the position: CURSOR_POS means translate the
- coordinates to the nearest position between characters, and CHARACTER_POS
- means translate the position to the nearest character cell.
-*/
+ Translate window coordinates to the nearest row and column number for
+ positioning the cursor. This, of course, makes no sense when the font is
+ proportional, since there are no absolute columns. The parameter posType
+ specifies how to interpret the position: CURSOR_POS means translate the
+ coordinates to the nearest position between characters, and CHARACTER_POS
+ means translate the position to the nearest character cell.
+ */
void Fl_Text_Display::xy_to_rowcol( int X, int Y, int *row,
- int *column, int posType ) const {
+ int *column, int posType ) const {
int fontHeight = mMaxsize;
int fontWidth = TMPFONTWIDTH; //mFontStruct->max_bounds.width;
-
+
/* Find the visible line number corresponding to the Y coordinate */
*row = ( Y - text_area.y ) / fontHeight;
if ( *row < 0 ) * row = 0;
if ( *row >= mNVisibleLines ) * row = mNVisibleLines - 1;
*column = ( ( X - text_area.x ) + mHorizOffset +
- ( posType == CURSOR_POS ? fontWidth / 2 : 0 ) ) / fontWidth;
+ ( posType == CURSOR_POS ? fontWidth / 2 : 0 ) ) / fontWidth;
if ( *column < 0 ) * column = 0;
}
/**
- Offset the line starts array, mTopLineNum, mFirstChar and lastChar, for a new
- vertical scroll position given by newTopLineNum. If any currently displayed
- lines will still be visible, salvage the line starts values, otherwise,
- count lines from the nearest known line start (start or end of buffer, or
- the closest value in the mLineStarts array)
-*/
+ Offset the line starts array, mTopLineNum, mFirstChar and lastChar, for a new
+ vertical scroll position given by newTopLineNum. If any currently displayed
+ lines will still be visible, salvage the line starts values, otherwise,
+ count lines from the nearest known line start (start or end of buffer, or
+ the closest value in the mLineStarts array)
+ */
void Fl_Text_Display::offset_line_starts( int newTopLineNum ) {
int oldTopLineNum = mTopLineNum;
int oldFirstChar = mFirstChar;
@@ -1969,14 +1859,14 @@ void Fl_Text_Display::offset_line_starts( int newTopLineNum ) {
int *lineStarts = mLineStarts;
int i, lastLineNum;
Fl_Text_Buffer *buf = mBuffer;
-
+
/* If there was no offset, nothing needs to be changed */
if ( lineDelta == 0 )
return;
-
+
/* Find the new value for mFirstChar by counting lines from the nearest
- known line start (start or end of buffer, or the closest value in the
- lineStarts array) */
+ known line start (start or end of buffer, or the closest value in the
+ lineStarts array) */
lastLineNum = oldTopLineNum + nVisLines - 1;
if ( newTopLineNum < oldTopLineNum && newTopLineNum < -lineDelta ) {
mFirstChar = skip_lines( 0, newTopLineNum - 1, true );
@@ -1986,11 +1876,11 @@ void Fl_Text_Display::offset_line_starts( int newTopLineNum ) {
mFirstChar = lineStarts[ newTopLineNum - oldTopLineNum ];
} else if ( newTopLineNum - lastLineNum < mNBufferLines - newTopLineNum ) {
mFirstChar = skip_lines( lineStarts[ nVisLines - 1 ],
- newTopLineNum - lastLineNum, true );
+ newTopLineNum - lastLineNum, true );
} else {
mFirstChar = rewind_lines( buf->length(), mNBufferLines - newTopLineNum + 1 );
}
-
+
/* Fill in the line starts array */
if ( lineDelta < 0 && -lineDelta < nVisLines ) {
for ( i = nVisLines - 1; i >= -lineDelta; i-- )
@@ -2002,32 +1892,32 @@ void Fl_Text_Display::offset_line_starts( int newTopLineNum ) {
calc_line_starts( nVisLines - lineDelta, nVisLines - 1 );
} else
calc_line_starts( 0, nVisLines );
-
+
/* Set lastChar and mTopLineNum */
calc_last_char();
mTopLineNum = newTopLineNum;
-
- /* If we're numbering lines or being asked to maintain an absolute line
- number, re-calculate the absolute line number */
- absolute_top_line_number(oldFirstChar);
+
+ /* If we're numbering lines or being asked to maintain an absolute line
+ number, re-calculate the absolute line number */
+ absolute_top_line_number(oldFirstChar);
}
/**
- Update the line starts array, mTopLineNum, mFirstChar and lastChar for text
- display "textD" after a modification to the text buffer, given by the
- position where the change began "pos", and the nmubers of characters
- and lines inserted and deleted.
-*/
+ Update the line starts array, mTopLineNum, mFirstChar and lastChar for text
+ display "textD" after a modification to the text buffer, given by the
+ position where the change began "pos", and the nmubers of characters
+ and lines inserted and deleted.
+ */
void Fl_Text_Display::update_line_starts( int pos, int charsInserted,
- int charsDeleted, int linesInserted, int linesDeleted, int *scrolled ) {
+ int charsDeleted, int linesInserted, int linesDeleted, int *scrolled ) {
int * lineStarts = mLineStarts;
int i, lineOfPos, lineOfEnd, nVisLines = mNVisibleLines;
int charDelta = charsInserted - charsDeleted;
int lineDelta = linesInserted - linesDeleted;
-
+
/* If all of the changes were before the displayed text, the display
- doesn't change, just update the top line num and offset the line
- start entries and first and last characters */
+ doesn't change, just update the top line num and offset the line
+ start entries and first and last characters */
if ( pos + charsDeleted < mFirstChar ) {
mTopLineNum += lineDelta;
for ( i = 0; i < nVisLines && lineStarts[i] != -1; i++ )
@@ -2037,16 +1927,16 @@ void Fl_Text_Display::update_line_starts( int pos, int charsInserted,
*scrolled = 0;
return;
}
-
+
/* The change began before the beginning of the displayed text, but
- part or all of the displayed text was deleted */
+ part or all of the displayed text was deleted */
if ( pos < mFirstChar ) {
/* If some text remains in the window, anchor on that */
if ( position_to_line( pos + charsDeleted, &lineOfEnd ) &&
- ++lineOfEnd < nVisLines && lineStarts[ lineOfEnd ] != -1 ) {
+ ++lineOfEnd < nVisLines && lineStarts[ lineOfEnd ] != -1 ) {
mTopLineNum = max( 1, mTopLineNum + lineDelta );
mFirstChar = rewind_lines(
- lineStarts[ lineOfEnd ] + charDelta, lineOfEnd );
+ lineStarts[ lineOfEnd ] + charDelta, lineOfEnd );
/* Otherwise anchor on original line number and recount everything */
} else {
if ( mTopLineNum > mNBufferLines + lineDelta ) {
@@ -2061,12 +1951,12 @@ void Fl_Text_Display::update_line_starts( int pos, int charsInserted,
*scrolled = 1;
return;
}
-
+
/* If the change was in the middle of the displayed text (it usually is),
- salvage as much of the line starts array as possible by moving and
- offsetting the entries after the changed area, and re-counting the
- added lines or the lines beyond the salvaged part of the line starts
- array */
+ salvage as much of the line starts array as possible by moving and
+ offsetting the entries after the changed area, and re-counting the
+ added lines or the lines beyond the salvaged part of the line starts
+ array */
if ( pos <= mLastChar ) {
/* find line on which the change began */
position_to_line( pos, &lineOfPos );
@@ -2077,11 +1967,11 @@ void Fl_Text_Display::update_line_starts( int pos, int charsInserted,
} else if ( lineDelta > 0 ) {
for ( i = nVisLines - 1; i >= lineOfPos + lineDelta + 1; i-- )
lineStarts[ i ] = lineStarts[ i - lineDelta ] +
- ( lineStarts[ i - lineDelta ] == -1 ? 0 : charDelta );
+ ( lineStarts[ i - lineDelta ] == -1 ? 0 : charDelta );
} else /* (lineDelta < 0) */ {
for ( i = max( 0, lineOfPos + 1 ); i < nVisLines + lineDelta; i++ )
lineStarts[ i ] = lineStarts[ i - lineDelta ] +
- ( lineStarts[ i - lineDelta ] == -1 ? 0 : charDelta );
+ ( lineStarts[ i - lineDelta ] == -1 ? 0 : charDelta );
}
/* fill in the missing line starts */
if ( linesInserted >= 0 )
@@ -2093,9 +1983,9 @@ void Fl_Text_Display::update_line_starts( int pos, int charsInserted,
*scrolled = 0;
return;
}
-
+
/* Change was past the end of the displayed text, but displayable by virtue
- of being an insert at the end of the buffer into visible blank lines */
+ of being an insert at the end of the buffer into visible blank lines */
if ( empty_vlines() ) {
position_to_line( pos, &lineOfPos );
calc_line_starts( lineOfPos, lineOfPos + linesInserted );
@@ -2103,24 +1993,24 @@ void Fl_Text_Display::update_line_starts( int pos, int charsInserted,
*scrolled = 0;
return;
}
-
+
/* Change was beyond the end of the buffer and not visible, do nothing */
*scrolled = 0;
}
/**
- Scan through the text in the "textD"'s buffer and recalculate the line
- starts array values beginning at index "startLine" and continuing through
- (including) "endLine". It assumes that the line starts entry preceding
- "startLine" (or mFirstChar if startLine is 0) is good, and re-counts
- newlines to fill in the requested entries. Out of range values for
- "startLine" and "endLine" are acceptable.
-*/
+ Scan through the text in the "textD"'s buffer and recalculate the line
+ starts array values beginning at index "startLine" and continuing through
+ (including) "endLine". It assumes that the line starts entry preceding
+ "startLine" (or mFirstChar if startLine is 0) is good, and re-counts
+ newlines to fill in the requested entries. Out of range values for
+ "startLine" and "endLine" are acceptable.
+ */
void Fl_Text_Display::calc_line_starts( int startLine, int endLine ) {
int startPos, bufLen = mBuffer->length();
int line, lineEnd, nextLineStart, nVis = mNVisibleLines;
int *lineStarts = mLineStarts;
-
+
/* Clean up (possibly) messy input parameters */
if ( endLine < 0 ) endLine = 0;
if ( endLine >= nVis ) endLine = nVis - 1;
@@ -2128,34 +2018,34 @@ void Fl_Text_Display::calc_line_starts( int startLine, int endLine ) {
if ( startLine >= nVis ) startLine = nVis - 1;
if ( startLine > endLine )
return;
-
+
/* Find the last known good line number -> position mapping */
if ( startLine == 0 ) {
lineStarts[ 0 ] = mFirstChar;
startLine = 1;
}
startPos = lineStarts[ startLine - 1 ];
-
+
/* If the starting position is already past the end of the text,
- fill in -1's (means no text on line) and return */
+ fill in -1's (means no text on line) and return */
if ( startPos == -1 ) {
for ( line = startLine; line <= endLine; line++ )
lineStarts[ line ] = -1;
return;
}
-
+
/* Loop searching for ends of lines and storing the positions of the
- start of the next line in lineStarts */
+ start of the next line in lineStarts */
for ( line = startLine; line <= endLine; line++ ) {
find_line_end(startPos, true, &lineEnd, &nextLineStart);
startPos = nextLineStart;
if ( startPos >= bufLen ) {
/* If the buffer ends with a newline or line break, put
- buf->length() in the next line start position (instead of
- a -1 which is the normal marker for an empty line) to
- indicate that the cursor may safely be displayed there */
+ buf->length() in the next line start position (instead of
+ a -1 which is the normal marker for an empty line) to
+ indicate that the cursor may safely be displayed there */
if ( line == 0 || ( lineStarts[ line - 1 ] != bufLen &&
- lineEnd != nextLineStart ) ) {
+ lineEnd != nextLineStart ) ) {
lineStarts[ line ] = bufLen;
line++;
}
@@ -2163,16 +2053,16 @@ void Fl_Text_Display::calc_line_starts( int startLine, int endLine ) {
}
lineStarts[ line ] = startPos;
}
-
+
/* Set any entries beyond the end of the text to -1 */
for ( ; line <= endLine; line++ )
lineStarts[ line ] = -1;
}
/**
- Given a Fl_Text_Display with a complete, up-to-date lineStarts array, update
- the lastChar entry to point to the last buffer position displayed.
-*/
+ Given a Fl_Text_Display with a complete, up-to-date lineStarts array, update
+ the lastChar entry to point to the last buffer position displayed.
+ */
void Fl_Text_Display::calc_last_char() {
int i;
for (i = mNVisibleLines - 1; i >= 0 && mLineStarts[i] == -1; i--) ;
@@ -2191,58 +2081,58 @@ void Fl_Text_Display::scroll_(int topLineNum, int horizOffset) {
if (topLineNum > mNBufferLines + 3 - mNVisibleLines)
topLineNum = mNBufferLines + 3 - mNVisibleLines;
if (topLineNum < 1) topLineNum = 1;
-
+
if (horizOffset > longest_vline() - text_area.w)
horizOffset = longest_vline() - text_area.w;
if (horizOffset < 0) horizOffset = 0;
-
+
/* Do nothing if scroll position hasn't actually changed or there's no
- window to draw in yet */
+ window to draw in yet */
if (mHorizOffset == horizOffset && mTopLineNum == topLineNum)
return;
-
+
/* If the vertical scroll position has changed, update the line
- starts array and related counters in the text display */
+ starts array and related counters in the text display */
offset_line_starts(topLineNum);
-
+
/* Just setting mHorizOffset is enough information for redisplay */
mHorizOffset = horizOffset;
-
+
// redraw all text
damage(FL_DAMAGE_EXPOSE);
}
/**
- Update the minimum, maximum, slider size, page increment, and value
- for vertical scroll bar.
-*/
+ Update the minimum, maximum, slider size, page increment, and value
+ for vertical scroll bar.
+ */
void Fl_Text_Display::update_v_scrollbar() {
/* The Vert. scroll bar value and slider size directly represent the top
- line number, and the number of visible lines respectively. The scroll
- bar maximum value is chosen to generally represent the size of the whole
- buffer, with minor adjustments to keep the scroll bar widget happy */
+ line number, and the number of visible lines respectively. The scroll
+ bar maximum value is chosen to generally represent the size of the whole
+ buffer, with minor adjustments to keep the scroll bar widget happy */
#ifdef DEBUG
printf("Fl_Text_Display::update_v_scrollbar():\n"
" mTopLineNum=%d, mNVisibleLines=%d, mNBufferLines=%d\n",
mTopLineNum, mNVisibleLines, mNBufferLines);
#endif // DEBUG
-
+
mVScrollBar->value(mTopLineNum, mNVisibleLines, 1, mNBufferLines+2);
mVScrollBar->linesize(3);
}
/**
- Update the minimum, maximum, slider size, page increment, and value
- for the horizontal scroll bar.
-*/
+ Update the minimum, maximum, slider size, page increment, and value
+ for the horizontal scroll bar.
+ */
void Fl_Text_Display::update_h_scrollbar() {
int sliderMax = max(longest_vline(), text_area.w + mHorizOffset);
mHScrollBar->value( mHorizOffset, text_area.w, 0, sliderMax );
}
/**
- Callbacks for drag or valueChanged on scroll bars
-*/
+ Callbacks for drag or valueChanged on scroll bars
+ */
void Fl_Text_Display::v_scrollbar_cb(Fl_Scrollbar* b, Fl_Text_Display* textD) {
if (b->value() == textD->mTopLineNum) return;
textD->scroll(b->value(), textD->mHorizOffset);
@@ -2254,62 +2144,62 @@ void Fl_Text_Display::h_scrollbar_cb(Fl_Scrollbar* b, Fl_Text_Display* textD) {
}
/**
- Refresh the line number area. If clearAll is False, writes only over
- the character cell areas. Setting clearAll to True will clear out any
- stray marks outside of the character cell area, which might have been
- left from before a resize or font change.
-*/
+ Refresh the line number area. If clearAll is False, writes only over
+ the character cell areas. Setting clearAll to True will clear out any
+ stray marks outside of the character cell area, which might have been
+ left from before a resize or font change.
+ */
void Fl_Text_Display::draw_line_numbers(bool /*clearAll*/) {
#if 0
- // FIXME: don't want this yet, so will leave for another time
-
- int y, line, visLine, nCols, lineStart;
- char lineNumString[12];
- int lineHeight = mMaxsize ? mMaxsize : textsize_;
- int charWidth = TMPFONTWIDTH; //mFontStruct->max_bounds.width;
-
- /* Don't draw if mLineNumWidth == 0 (line numbers are hidden), or widget is
- not yet realized */
- if (mLineNumWidth == 0 || visible_r())
- return;
-
- /* GC is allocated on demand, since not everyone will use line numbering */
- if (textD->lineNumGC == NULL) {
- XGCValues values;
- values.foreground = textD->lineNumFGPixel;
- values.background = textD->bgPixel;
- values.font = textD->fontStruct->fid;
- textD->lineNumGC = XtGetGC(textD->w,
- GCFont| GCForeground | GCBackground, &values);
- }
-
- /* Erase the previous contents of the line number area, if requested */
- if (clearAll)
- XClearArea(XtDisplay(textD->w), XtWindow(textD->w), textD->lineNumLeft,
- textD->top, textD->lineNumWidth, textD->height, False);
-
- /* Draw the line numbers, aligned to the text */
- nCols = min(11, textD->lineNumWidth / charWidth);
- y = textD->top;
- line = getAbsTopLineNum(textD);
- for (visLine=0; visLine < textD->nVisibleLines; visLine++) {
- lineStart = textD->lineStarts[visLine];
- if (lineStart != -1 && (lineStart==0 ||
- BufGetCharacter(textD->buffer, lineStart-1)=='\n')) {
- sprintf(lineNumString, "%*d", nCols, line);
- XDrawImageString(XtDisplay(textD->w), XtWindow(textD->w),
- textD->lineNumGC, textD->lineNumLeft, y + textD->ascent,
- lineNumString, strlen(lineNumString));
- line++;
- } else {
- XClearArea(XtDisplay(textD->w), XtWindow(textD->w),
- textD->lineNumLeft, y, textD->lineNumWidth,
- textD->ascent + textD->descent, False);
- if (visLine == 0)
- line++;
- }
- y += lineHeight;
+ // FIXME: don't want this yet, so will leave for another time
+
+ int y, line, visLine, nCols, lineStart;
+ char lineNumString[12];
+ int lineHeight = mMaxsize ? mMaxsize : textsize_;
+ int charWidth = TMPFONTWIDTH; //mFontStruct->max_bounds.width;
+
+ /* Don't draw if mLineNumWidth == 0 (line numbers are hidden), or widget is
+ not yet realized */
+ if (mLineNumWidth == 0 || visible_r())
+ return;
+
+ /* GC is allocated on demand, since not everyone will use line numbering */
+ if (textD->lineNumGC == NULL) {
+ XGCValues values;
+ values.foreground = textD->lineNumFGPixel;
+ values.background = textD->bgPixel;
+ values.font = textD->fontStruct->fid;
+ textD->lineNumGC = XtGetGC(textD->w,
+ GCFont| GCForeground | GCBackground, &values);
+ }
+
+ /* Erase the previous contents of the line number area, if requested */
+ if (clearAll)
+ XClearArea(XtDisplay(textD->w), XtWindow(textD->w), textD->lineNumLeft,
+ textD->top, textD->lineNumWidth, textD->height, False);
+
+ /* Draw the line numbers, aligned to the text */
+ nCols = min(11, textD->lineNumWidth / charWidth);
+ y = textD->top;
+ line = getAbsTopLineNum(textD);
+ for (visLine=0; visLine < textD->nVisibleLines; visLine++) {
+ lineStart = textD->lineStarts[visLine];
+ if (lineStart != -1 && (lineStart==0 ||
+ BufGetCharacter(textD->buffer, lineStart-1)=='\n')) {
+ sprintf(lineNumString, "%*d", nCols, line);
+ XDrawImageString(XtDisplay(textD->w), XtWindow(textD->w),
+ textD->lineNumGC, textD->lineNumLeft, y + textD->ascent,
+ lineNumString, strlen(lineNumString));
+ line++;
+ } else {
+ XClearArea(XtDisplay(textD->w), XtWindow(textD->w),
+ textD->lineNumLeft, y, textD->lineNumWidth,
+ textD->ascent + textD->descent, False);
+ if (visLine == 0)
+ line++;
}
+ y += lineHeight;
+ }
#endif
}
@@ -2322,80 +2212,49 @@ static int min( int i1, int i2 ) {
}
/**
- Count the number of newlines in a null-terminated text string;
-*/
+ Count the number of newlines in a null-terminated text string;
+ */
static int countlines( const char *string ) {
const char * c;
int lineCount = 0;
-
+
if (!string) return 0;
-
+
for ( c = string; *c != '\0'; c++ )
if ( *c == '\n' ) lineCount++;
return lineCount;
}
/**
- Return the width in pixels of the displayed line pointed to by "visLineNum"
-*/
+ Return the width in pixels of the displayed line pointed to by "visLineNum"
+ */
int Fl_Text_Display::measure_vline( int visLineNum ) const {
- int i, width = 0, len, style, lineLen = vline_length( visLineNum );
- int charCount = 0, lineStartPos = mLineStarts[ visLineNum ];
- char expandedChar[ FL_TEXT_MAX_EXP_CHAR_LEN ];
-
+ // FIXME: the horizontal scroll bar is still messed up. Clicking the right container is not possible.
+ int lineLen = vline_length( visLineNum );
+ int lineStartPos = mLineStarts[ visLineNum ];
if (lineStartPos < 0 || lineLen == 0) return 0;
- if ( mStyleBuffer == NULL ) {
- for ( i = 0; i < lineLen; i++ ) {
- len = mBuffer->expand_character( lineStartPos + i,
- charCount, expandedChar );
-
- fl_font( textfont(), textsize() );
-
- width += ( int ) fl_width( expandedChar, len );
-
- charCount += len;
- }
- } else {
- for ( i = 0; i < lineLen; i++ ) {
- len = mBuffer->expand_character( lineStartPos + i,
- charCount, expandedChar );
- // FIXME: character is ucs-4
- style = ( unsigned char ) mStyleBuffer->character(
- lineStartPos + i ) - 'A';
-
- if (style < 0) style = 0;
- else if (style >= mNStyles) style = mNStyles - 1;
-
- fl_font( mStyleTable[ style ].font, mStyleTable[ style ].size );
-
- width += ( int ) fl_width( expandedChar, len );
-
- charCount += len;
- }
- }
- return width;
+ return handle_vline(GET_WIDTH, lineStartPos, lineLen, 0, 0, 0, 0, 0, 0);
}
/**
- Return true if there are lines visible with no corresponding buffer text
-*/
+ Return true if there are lines visible with no corresponding buffer text
+ */
int Fl_Text_Display::empty_vlines() const {
- return mNVisibleLines > 0 &&
- mLineStarts[ mNVisibleLines - 1 ] == -1;
+ return (mNVisibleLines > 0) && (mLineStarts[ mNVisibleLines - 1 ] == -1);
}
/**
- Return the length of a line (number of displayable characters) by examining
- entries in the line starts array rather than by scanning for newlines
-*/
+ Return the length of a line (number of displayable characters) by examining
+ entries in the line starts array rather than by scanning for newlines
+ */
int Fl_Text_Display::vline_length( int visLineNum ) const {
int nextLineStart, lineStartPos;
-
+
if (visLineNum < 0 || visLineNum >= mNVisibleLines)
return (0);
-
+
lineStartPos = mLineStarts[ visLineNum ];
-
+
if ( lineStartPos == -1 )
return 0;
if ( visLineNum + 1 >= mNVisibleLines )
@@ -2409,502 +2268,480 @@ int Fl_Text_Display::vline_length( int visLineNum ) const {
}
/**
- When continuous wrap is on, and the user inserts or deletes characters,
- wrapping can happen before and beyond the changed position. This routine
- finds the extent of the changes, and counts the deleted and inserted lines
- over that range. It also attempts to minimize the size of the range to
- what has to be counted and re-displayed, so the results can be useful
- both for delimiting where the line starts need to be recalculated, and
- for deciding what part of the text to redisplay.
-*/
+ When continuous wrap is on, and the user inserts or deletes characters,
+ wrapping can happen before and beyond the changed position. This routine
+ finds the extent of the changes, and counts the deleted and inserted lines
+ over that range. It also attempts to minimize the size of the range to
+ what has to be counted and re-displayed, so the results can be useful
+ both for delimiting where the line starts need to be recalculated, and
+ for deciding what part of the text to redisplay.
+ */
void Fl_Text_Display::find_wrap_range(const char *deletedText, int pos,
- int nInserted, int nDeleted, int *modRangeStart, int *modRangeEnd,
- int *linesInserted, int *linesDeleted) {
- int length, retPos, retLines, retLineStart, retLineEnd;
- Fl_Text_Buffer *deletedTextBuf, *buf = buffer();
- int nVisLines = mNVisibleLines;
- int *lineStarts = mLineStarts;
- int countFrom, countTo, lineStart, adjLineStart, i;
- int visLineNum = 0, nLines = 0;
+ int nInserted, int nDeleted, int *modRangeStart, int *modRangeEnd,
+ int *linesInserted, int *linesDeleted) {
+ int length, retPos, retLines, retLineStart, retLineEnd;
+ Fl_Text_Buffer *deletedTextBuf, *buf = buffer();
+ int nVisLines = mNVisibleLines;
+ int *lineStarts = mLineStarts;
+ int countFrom, countTo, lineStart, adjLineStart, i;
+ int visLineNum = 0, nLines = 0;
+
+ /*
+ ** Determine where to begin searching: either the previous newline, or
+ ** if possible, limit to the start of the (original) previous displayed
+ ** line, using information from the existing line starts array
+ */
+ if (pos >= mFirstChar && pos <= mLastChar) {
+ for (i=nVisLines-1; i>0; i--)
+ if (lineStarts[i] != -1 && pos >= lineStarts[i])
+ break;
+ if (i > 0) {
+ countFrom = lineStarts[i-1];
+ visLineNum = i-1;
+ } else
+ countFrom = buf->line_start(pos);
+ } else
+ countFrom = buf->line_start(pos);
+
+
+ /*
+ ** Move forward through the (new) text one line at a time, counting
+ ** displayed lines, and looking for either a real newline, or for the
+ ** line starts to re-sync with the original line starts array
+ */
+ lineStart = countFrom;
+ *modRangeStart = countFrom;
+ for (;;) {
- /*
- ** Determine where to begin searching: either the previous newline, or
- ** if possible, limit to the start of the (original) previous displayed
- ** line, using information from the existing line starts array
- */
- if (pos >= mFirstChar && pos <= mLastChar) {
- for (i=nVisLines-1; i>0; i--)
- if (lineStarts[i] != -1 && pos >= lineStarts[i])
- break;
- if (i > 0) {
- countFrom = lineStarts[i-1];
- visLineNum = i-1;
- } else
- countFrom = buf->line_start(pos);
+ /* advance to the next line. If the line ended in a real newline
+ or the end of the buffer, that's far enough */
+ wrapped_line_counter(buf, lineStart, buf->length(), 1, true, 0,
+ &retPos, &retLines, &retLineStart, &retLineEnd);
+ if (retPos >= buf->length()) {
+ countTo = buf->length();
+ *modRangeEnd = countTo;
+ if (retPos != retLineEnd)
+ nLines++;
+ break;
} else
- countFrom = buf->line_start(pos);
-
+ lineStart = retPos;
+ nLines++;
+ if (lineStart > pos + nInserted &&
+ // FIXME: character is ucs-4
+ buf->char_at(lineStart-1) == '\n') {
+ countTo = lineStart;
+ *modRangeEnd = lineStart;
+ break;
+ }
- /*
- ** Move forward through the (new) text one line at a time, counting
- ** displayed lines, and looking for either a real newline, or for the
- ** line starts to re-sync with the original line starts array
- */
- lineStart = countFrom;
- *modRangeStart = countFrom;
- for (;;) {
-
- /* advance to the next line. If the line ended in a real newline
- or the end of the buffer, that's far enough */
- wrapped_line_counter(buf, lineStart, buf->length(), 1, true, 0,
- &retPos, &retLines, &retLineStart, &retLineEnd);
- if (retPos >= buf->length()) {
- countTo = buf->length();
- *modRangeEnd = countTo;
- if (retPos != retLineEnd)
- nLines++;
- break;
- } else
- lineStart = retPos;
- nLines++;
- if (lineStart > pos + nInserted &&
- // FIXME: character is ucs-4
- buf->character(lineStart-1) == '\n') {
- countTo = lineStart;
- *modRangeEnd = lineStart;
- break;
- }
-
- /* Don't try to resync in continuous wrap mode with non-fixed font
- sizes; it would result in a chicken-and-egg dependency between
- the calculations for the inserted and the deleted lines.
- If we're in that mode, the number of deleted lines is calculated in
- advance, without resynchronization, so we shouldn't resynchronize
- for the inserted lines either. */
- if (mSuppressResync)
- continue;
-
- /* check for synchronization with the original line starts array
- before pos, if so, the modified range can begin later */
- if (lineStart <= pos) {
- while (visLineNum<nVisLines && lineStarts[visLineNum] < lineStart)
- visLineNum++;
- if (visLineNum < nVisLines && lineStarts[visLineNum] == lineStart) {
- countFrom = lineStart;
- nLines = 0;
- if (visLineNum+1 < nVisLines && lineStarts[visLineNum+1] != -1)
- *modRangeStart = min(pos, lineStarts[visLineNum+1]-1);
- else
- *modRangeStart = countFrom;
- } else
- *modRangeStart = min(*modRangeStart, lineStart-1);
- }
-
- /* check for synchronization with the original line starts array
- after pos, if so, the modified range can end early */
- else if (lineStart > pos + nInserted) {
- adjLineStart = lineStart - nInserted + nDeleted;
- while (visLineNum<nVisLines && lineStarts[visLineNum]<adjLineStart)
- visLineNum++;
- if (visLineNum < nVisLines && lineStarts[visLineNum] != -1 &&
- lineStarts[visLineNum] == adjLineStart) {
- countTo = line_end(lineStart, true);
- *modRangeEnd = lineStart;
- break;
- }
- }
+ /* Don't try to resync in continuous wrap mode with non-fixed font
+ sizes; it would result in a chicken-and-egg dependency between
+ the calculations for the inserted and the deleted lines.
+ If we're in that mode, the number of deleted lines is calculated in
+ advance, without resynchronization, so we shouldn't resynchronize
+ for the inserted lines either. */
+ if (mSuppressResync)
+ continue;
+
+ /* check for synchronization with the original line starts array
+ before pos, if so, the modified range can begin later */
+ if (lineStart <= pos) {
+ while (visLineNum<nVisLines && lineStarts[visLineNum] < lineStart)
+ visLineNum++;
+ if (visLineNum < nVisLines && lineStarts[visLineNum] == lineStart) {
+ countFrom = lineStart;
+ nLines = 0;
+ if (visLineNum+1 < nVisLines && lineStarts[visLineNum+1] != -1)
+ *modRangeStart = min(pos, lineStarts[visLineNum+1]-1);
+ else
+ *modRangeStart = countFrom;
+ } else
+ *modRangeStart = min(*modRangeStart, lineStart-1);
}
- *linesInserted = nLines;
-
-
- /* Count deleted lines between countFrom and countTo as the text existed
- before the modification (that is, as if the text between pos and
- pos+nInserted were replaced by "deletedText"). This extra context is
- necessary because wrapping can occur outside of the modified region
- as a result of adding or deleting text in the region. This is done by
- creating a textBuffer containing the deleted text and the necessary
- additional context, and calling the wrappedLineCounter on it.
-
- NOTE: This must not be done in continuous wrap mode when the font
- width is not fixed. In that case, the calculation would try
- to access style information that is no longer available (deleted
- text), or out of date (updated highlighting), possibly leading
- to completely wrong calculations and/or even crashes eventually.
- (This is not theoretical; it really happened.)
-
- In that case, the calculation of the number of deleted lines
- has happened before the buffer was modified (only in that case,
- because resynchronization of the line starts is impossible
- in that case, which makes the whole calculation less efficient).
- */
- if (mSuppressResync) {
- *linesDeleted = mNLinesDeleted;
- mSuppressResync = 0;
- return;
+
+ /* check for synchronization with the original line starts array
+ after pos, if so, the modified range can end early */
+ else if (lineStart > pos + nInserted) {
+ adjLineStart = lineStart - nInserted + nDeleted;
+ while (visLineNum<nVisLines && lineStarts[visLineNum]<adjLineStart)
+ visLineNum++;
+ if (visLineNum < nVisLines && lineStarts[visLineNum] != -1 &&
+ lineStarts[visLineNum] == adjLineStart) {
+ countTo = line_end(lineStart, true);
+ *modRangeEnd = lineStart;
+ break;
+ }
}
-
- length = (pos-countFrom) + nDeleted +(countTo-(pos+nInserted));
- deletedTextBuf = new Fl_Text_Buffer(length);
- deletedTextBuf->copy(buffer(), countFrom, pos, 0);
- if (nDeleted != 0)
- deletedTextBuf->insert(pos-countFrom, deletedText);
- deletedTextBuf->copy(buffer(),
- pos+nInserted, countTo, pos-countFrom+nDeleted);
- /* Note that we need to take into account an offset for the style buffer:
- the deletedTextBuf can be out of sync with the style buffer. */
- wrapped_line_counter(deletedTextBuf, 0, length, INT_MAX, true,
- countFrom, &retPos, &retLines, &retLineStart, &retLineEnd, false);
- delete deletedTextBuf;
- *linesDeleted = retLines;
+ }
+ *linesInserted = nLines;
+
+
+ /* Count deleted lines between countFrom and countTo as the text existed
+ before the modification (that is, as if the text between pos and
+ pos+nInserted were replaced by "deletedText"). This extra context is
+ necessary because wrapping can occur outside of the modified region
+ as a result of adding or deleting text in the region. This is done by
+ creating a textBuffer containing the deleted text and the necessary
+ additional context, and calling the wrappedLineCounter on it.
+
+ NOTE: This must not be done in continuous wrap mode when the font
+ width is not fixed. In that case, the calculation would try
+ to access style information that is no longer available (deleted
+ text), or out of date (updated highlighting), possibly leading
+ to completely wrong calculations and/or even crashes eventually.
+ (This is not theoretical; it really happened.)
+
+ In that case, the calculation of the number of deleted lines
+ has happened before the buffer was modified (only in that case,
+ because resynchronization of the line starts is impossible
+ in that case, which makes the whole calculation less efficient).
+ */
+ if (mSuppressResync) {
+ *linesDeleted = mNLinesDeleted;
mSuppressResync = 0;
+ return;
+ }
+
+ length = (pos-countFrom) + nDeleted +(countTo-(pos+nInserted));
+ deletedTextBuf = new Fl_Text_Buffer(length);
+ deletedTextBuf->copy(buffer(), countFrom, pos, 0);
+ if (nDeleted != 0)
+ deletedTextBuf->insert(pos-countFrom, deletedText);
+ deletedTextBuf->copy(buffer(),
+ pos+nInserted, countTo, pos-countFrom+nDeleted);
+ /* Note that we need to take into account an offset for the style buffer:
+ the deletedTextBuf can be out of sync with the style buffer. */
+ wrapped_line_counter(deletedTextBuf, 0, length, INT_MAX, true,
+ countFrom, &retPos, &retLines, &retLineStart, &retLineEnd, false);
+ delete deletedTextBuf;
+ *linesDeleted = retLines;
+ mSuppressResync = 0;
}
/**
- This is a stripped-down version of the findWrapRange() function above,
- intended to be used to calculate the number of "deleted" lines during
- a buffer modification. It is called _before_ the modification takes place.
-
- This function should only be called in continuous wrap mode with a
- non-fixed font width. In that case, it is impossible to calculate
- the number of deleted lines, because the necessary style information
- is no longer available _after_ the modification. In other cases, we
- can still perform the calculation afterwards (possibly even more
- efficiently).
-*/
+ This is a stripped-down version of the findWrapRange() function above,
+ intended to be used to calculate the number of "deleted" lines during
+ a buffer modification. It is called _before_ the modification takes place.
+
+ This function should only be called in continuous wrap mode with a
+ non-fixed font width. In that case, it is impossible to calculate
+ the number of deleted lines, because the necessary style information
+ is no longer available _after_ the modification. In other cases, we
+ can still perform the calculation afterwards (possibly even more
+ efficiently).
+ */
void Fl_Text_Display::measure_deleted_lines(int pos, int nDeleted) {
- int retPos, retLines, retLineStart, retLineEnd;
- Fl_Text_Buffer *buf = buffer();
- int nVisLines = mNVisibleLines;
- int *lineStarts = mLineStarts;
- int countFrom, lineStart;
- int visLineNum = 0, nLines = 0, i;
- /*
- ** Determine where to begin searching: either the previous newline, or
- ** if possible, limit to the start of the (original) previous displayed
- ** line, using information from the existing line starts array
- */
- if (pos >= mFirstChar && pos <= mLastChar) {
- for (i=nVisLines-1; i>0; i--)
- if (lineStarts[i] != -1 && pos >= lineStarts[i])
- break;
- if (i > 0) {
- countFrom = lineStarts[i-1];
- visLineNum = i-1;
- } else
- countFrom = buf->line_start(pos);
+ int retPos, retLines, retLineStart, retLineEnd;
+ Fl_Text_Buffer *buf = buffer();
+ int nVisLines = mNVisibleLines;
+ int *lineStarts = mLineStarts;
+ int countFrom, lineStart;
+ int visLineNum = 0, nLines = 0, i;
+ /*
+ ** Determine where to begin searching: either the previous newline, or
+ ** if possible, limit to the start of the (original) previous displayed
+ ** line, using information from the existing line starts array
+ */
+ if (pos >= mFirstChar && pos <= mLastChar) {
+ for (i=nVisLines-1; i>0; i--)
+ if (lineStarts[i] != -1 && pos >= lineStarts[i])
+ break;
+ if (i > 0) {
+ countFrom = lineStarts[i-1];
+ visLineNum = i-1;
} else
- countFrom = buf->line_start(pos);
-
- /*
- ** Move forward through the (new) text one line at a time, counting
- ** displayed lines, and looking for either a real newline, or for the
- ** line starts to re-sync with the original line starts array
- */
- lineStart = countFrom;
- for (;;) {
- /* advance to the next line. If the line ended in a real newline
- or the end of the buffer, that's far enough */
- wrapped_line_counter(buf, lineStart, buf->length(), 1, true, 0,
- &retPos, &retLines, &retLineStart, &retLineEnd);
- if (retPos >= buf->length()) {
- if (retPos != retLineEnd)
- nLines++;
- break;
- } else
- lineStart = retPos;
- nLines++;
- if (lineStart > pos + nDeleted &&
- // FIXME: character is ucs-4
- buf->character(lineStart-1) == '\n') {
- break;
- }
-
- /* Unlike in the findWrapRange() function above, we don't try to
- resync with the line starts, because we don't know the length
- of the inserted text yet, nor the updated style information.
-
- Because of that, we also shouldn't resync with the line starts
- after the modification either, because we must perform the
- calculations for the deleted and inserted lines in the same way.
-
- This can result in some unnecessary recalculation and redrawing
- overhead, and therefore we should only use this two-phase mode
- of calculation when it's really needed (continuous wrap + variable
- font width). */
+ countFrom = buf->line_start(pos);
+ } else
+ countFrom = buf->line_start(pos);
+
+ /*
+ ** Move forward through the (new) text one line at a time, counting
+ ** displayed lines, and looking for either a real newline, or for the
+ ** line starts to re-sync with the original line starts array
+ */
+ lineStart = countFrom;
+ for (;;) {
+ /* advance to the next line. If the line ended in a real newline
+ or the end of the buffer, that's far enough */
+ wrapped_line_counter(buf, lineStart, buf->length(), 1, true, 0,
+ &retPos, &retLines, &retLineStart, &retLineEnd);
+ if (retPos >= buf->length()) {
+ if (retPos != retLineEnd)
+ nLines++;
+ break;
+ } else
+ lineStart = retPos;
+ nLines++;
+ if (lineStart > pos + nDeleted &&
+ // FIXME: character is ucs-4
+ buf->char_at(lineStart-1) == '\n') {
+ break;
}
- mNLinesDeleted = nLines;
- mSuppressResync = 1;
+
+ /* Unlike in the findWrapRange() function above, we don't try to
+ resync with the line starts, because we don't know the length
+ of the inserted text yet, nor the updated style information.
+
+ Because of that, we also shouldn't resync with the line starts
+ after the modification either, because we must perform the
+ calculations for the deleted and inserted lines in the same way.
+
+ This can result in some unnecessary recalculation and redrawing
+ overhead, and therefore we should only use this two-phase mode
+ of calculation when it's really needed (continuous wrap + variable
+ font width). */
+ }
+ mNLinesDeleted = nLines;
+ mSuppressResync = 1;
}
/**
- Count forward from startPos to either maxPos or maxLines (whichever is
- reached first), and return all relevant positions and line count.
- The provided textBuffer may differ from the actual text buffer of the
- widget. In that case it must be a (partial) copy of the actual text buffer
- and the styleBufOffset argument must indicate the starting position of the
- copy, to take into account the correct style information.
-**
- Returned values:
-**
- retPos: Position where counting ended. When counting lines, the
- position returned is the start of the line "maxLines"
- lines beyond "startPos".
- retLines: Number of line breaks counted
- retLineStart: Start of the line where counting ended
- retLineEnd: End position of the last line traversed
-*/
+ Count forward from startPos to either maxPos or maxLines (whichever is
+ reached first), and return all relevant positions and line count.
+ The provided textBuffer may differ from the actual text buffer of the
+ widget. In that case it must be a (partial) copy of the actual text buffer
+ and the styleBufOffset argument must indicate the starting position of the
+ copy, to take into account the correct style information.
+ **
+ Returned values:
+ **
+ retPos: Position where counting ended. When counting lines, the
+ position returned is the start of the line "maxLines"
+ lines beyond "startPos".
+ retLines: Number of line breaks counted
+ retLineStart: Start of the line where counting ended
+ retLineEnd: End position of the last line traversed
+ */
void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
- int maxPos, int maxLines, bool startPosIsLineStart, int styleBufOffset,
- int *retPos, int *retLines, int *retLineStart, int *retLineEnd,
- bool countLastLineMissingNewLine) const {
- int lineStart, newLineStart = 0, b, p, colNum, wrapMargin;
- int maxWidth, i, foundBreak, width;
- bool countPixels;
- int nLines = 0, tabDist = buffer()->tab_distance();
- unsigned char c;
+ int maxPos, int maxLines, bool startPosIsLineStart, int styleBufOffset,
+ int *retPos, int *retLines, int *retLineStart, int *retLineEnd,
+ bool countLastLineMissingNewLine) const {
+ int lineStart, newLineStart = 0, b, p, colNum, wrapMargin;
+ int maxWidth, i, foundBreak, width;
+ bool countPixels;
+ int nLines = 0;
+ unsigned char c;
+
+ /* If the font is fixed, or there's a wrap margin set, it's more efficient
+ to measure in columns, than to count pixels. Determine if we can count
+ in columns (countPixels == False) or must count pixels (countPixels ==
+ True), and set the wrap target for either pixels or columns */
+ if (mWrapMargin != 0) {
+ // FIXME: the warp margin is actually a pixel boundary, so we have to measure nevertheless!
+ countPixels = false;
+ wrapMargin = mWrapMargin;
+ maxWidth = INT_MAX;
+ } else {
+ countPixels = true;
+ wrapMargin = INT_MAX;
+ maxWidth = text_area.w;
+ }
+
+ /* Find the start of the line if the start pos is not marked as a
+ line start. */
+ if (startPosIsLineStart)
+ lineStart = startPos;
+ else
+ lineStart = line_start(startPos);
+
+ /*
+ ** Loop until position exceeds maxPos or line count exceeds maxLines.
+ ** (actually, continues beyond maxPos to end of line containing maxPos,
+ ** in case later characters cause a word wrap back before maxPos)
+ */
+ colNum = 0;
+ width = 0;
+ for (p=lineStart; p<buf->length(); p++) {
+ // FIXME: character is ucs-4
+ c = (unsigned char)buf->char_at(p);
- /* If the font is fixed, or there's a wrap margin set, it's more efficient
- to measure in columns, than to count pixels. Determine if we can count
- in columns (countPixels == False) or must count pixels (countPixels ==
- True), and set the wrap target for either pixels or columns */
- if (mFixedFontWidth != -1 || mWrapMargin != 0) {
- countPixels = false;
- wrapMargin = mWrapMargin ? mWrapMargin : text_area.w / (mFixedFontWidth + 1);
- maxWidth = INT_MAX;
+ /* If the character was a newline, count the line and start over,
+ otherwise, add it to the width and column counts */
+ if (c == '\n') {
+ if (p >= maxPos) {
+ *retPos = maxPos;
+ *retLines = nLines;
+ *retLineStart = lineStart;
+ *retLineEnd = maxPos;
+ return;
+ }
+ nLines++;
+ if (nLines >= maxLines) {
+ *retPos = p + 1;
+ *retLines = nLines;
+ *retLineStart = p + 1;
+ *retLineEnd = p;
+ return;
+ }
+ lineStart = p + 1;
+ colNum = 0;
+ width = 0;
} else {
- countPixels = true;
- wrapMargin = INT_MAX;
- maxWidth = text_area.w;
+ const char *s = buf->address(p);
+ colNum++;
+ if (countPixels)
+ width += measure_proportional_character(s, colNum, p+styleBufOffset);
}
- /* Find the start of the line if the start pos is not marked as a
- line start. */
- if (startPosIsLineStart)
- lineStart = startPos;
- else
- lineStart = line_start(startPos);
-
- /*
- ** Loop until position exceeds maxPos or line count exceeds maxLines.
- ** (actually, contines beyond maxPos to end of line containing maxPos,
- ** in case later characters cause a word wrap back before maxPos)
- */
- colNum = 0;
- width = 0;
- for (p=lineStart; p<buf->length(); p++) {
- // FIXME: character is ucs-4
- c = (unsigned char)buf->character(p);
-
- /* If the character was a newline, count the line and start over,
- otherwise, add it to the width and column counts */
- if (c == '\n') {
- if (p >= maxPos) {
- *retPos = maxPos;
- *retLines = nLines;
- *retLineStart = lineStart;
- *retLineEnd = maxPos;
- return;
- }
- nLines++;
- if (nLines >= maxLines) {
- *retPos = p + 1;
- *retLines = nLines;
- *retLineStart = p + 1;
- *retLineEnd = p;
- return;
- }
- lineStart = p + 1;
- colNum = 0;
- width = 0;
- } else {
- const char *s = buf->address(p);
- colNum += Fl_Text_Buffer::character_width(s, colNum, tabDist); // FIXME: unicode
- if (countPixels)
- width += measure_proportional_character(s, colNum, p+styleBufOffset);
- }
-
- /* If character exceeded wrap margin, find the break point
- and wrap there */
- if (colNum > wrapMargin || width > maxWidth) {
- foundBreak = false;
- for (b=p; b>=lineStart; b--) {
- // FIXME: character is ucs-4
- c = (unsigned char)buf->character(b);
- if (c == '\t' || c == ' ') {
- newLineStart = b + 1;
- if (countPixels) {
- colNum = 0;
- width = 0;
- for (i=b+1; i<p+1; i++) {
- width += measure_proportional_character(
- // FIXME: character is ucs-4
- buf->address(i), colNum,
- i+styleBufOffset);
- colNum++;
- }
- } else
- colNum = buf->count_displayed_characters(b+1, p+1);
- foundBreak = true;
- break;
- }
- }
- if (!foundBreak) { /* no whitespace, just break at margin */
- newLineStart = max(p, lineStart+1);
- const char *s = buf->address(b);
- colNum = Fl_Text_Buffer::character_width(s, colNum, tabDist); // FIXME: unicode
- if (countPixels)
- width = measure_proportional_character(s, colNum, p+styleBufOffset);
- }
- if (p >= maxPos) {
- *retPos = maxPos;
- *retLines = maxPos < newLineStart ? nLines : nLines + 1;
- *retLineStart = maxPos < newLineStart ? lineStart :
- newLineStart;
- *retLineEnd = maxPos;
- return;
- }
- nLines++;
- if (nLines >= maxLines) {
- *retPos = foundBreak ? b + 1 : max(p, lineStart+1);
- *retLines = nLines;
- *retLineStart = lineStart;
- *retLineEnd = foundBreak ? b : p;
- return;
- }
- lineStart = newLineStart;
- }
+ /* If character exceeded wrap margin, find the break point
+ and wrap there */
+ if (colNum > wrapMargin || width > maxWidth) {
+ foundBreak = false;
+ for (b=p; b>=lineStart; b--) {
+ // FIXME: character is ucs-4
+ c = (unsigned char)buf->char_at(b);
+ if (c == '\t' || c == ' ') {
+ newLineStart = b + 1;
+ if (countPixels) {
+ colNum = 0;
+ width = 0;
+ for (i=b+1; i<p+1; i++) {
+ width += measure_proportional_character(
+ // FIXME: character is ucs-4
+ buf->address(i), colNum,
+ i+styleBufOffset);
+ colNum++;
+ }
+ } else
+ colNum = buf->count_displayed_characters(b+1, p+1);
+ foundBreak = true;
+ break;
+ }
+ }
+ if (!foundBreak) { /* no whitespace, just break at margin */
+ newLineStart = max(p, lineStart+1);
+ const char *s = buf->address(b);
+ colNum++;
+ if (countPixels)
+ width = measure_proportional_character(s, colNum, p+styleBufOffset);
+ }
+ if (p >= maxPos) {
+ *retPos = maxPos;
+ *retLines = maxPos < newLineStart ? nLines : nLines + 1;
+ *retLineStart = maxPos < newLineStart ? lineStart :
+ newLineStart;
+ *retLineEnd = maxPos;
+ return;
+ }
+ nLines++;
+ if (nLines >= maxLines) {
+ *retPos = foundBreak ? b + 1 : max(p, lineStart+1);
+ *retLines = nLines;
+ *retLineStart = lineStart;
+ *retLineEnd = foundBreak ? b : p;
+ return;
+ }
+ lineStart = newLineStart;
}
-
- /* reached end of buffer before reaching pos or line target */
- *retPos = buf->length();
- *retLines = nLines;
- if (countLastLineMissingNewLine && colNum > 0)
- ++(*retLines);
- *retLineStart = lineStart;
- *retLineEnd = buf->length();
+ }
+
+ /* reached end of buffer before reaching pos or line target */
+ *retPos = buf->length();
+ *retLines = nLines;
+ if (countLastLineMissingNewLine && colNum > 0)
+ ++(*retLines);
+ *retLineStart = lineStart;
+ *retLineEnd = buf->length();
}
/**
- Measure the width in pixels of the first character of string "s" at a
- particular column "colNum" and buffer position "pos". This is for measuring
- characters in proportional or mixed-width highlighting fonts.
-**
- A note about proportional and mixed-width fonts: the mixed width and
- proportional font code in nedit does not get much use in general editing,
- because nedit doesn't allow per-language-mode fonts, and editing programs
- in a proportional font is usually a bad idea, so very few users would
- choose a proportional font as a default. There are still probably mixed-
- width syntax highlighting cases where things don't redraw properly for
- insertion/deletion, though static display and wrapping and resizing
- should now be solid because they are now used for online help display.
-*/
-
+ Measure the width in pixels of the first character of string "s" at a
+ particular column "colNum" and buffer position "pos". This is for measuring
+ characters in proportional or mixed-width highlighting fonts.
+ **
+ A note about proportional and mixed-width fonts: the mixed width and
+ proportional font code in nedit does not get much use in general editing,
+ because nedit doesn't allow per-language-mode fonts, and editing programs
+ in a proportional font is usually a bad idea, so very few users would
+ choose a proportional font as a default. There are still probably mixed-
+ width syntax highlighting cases where things don't redraw properly for
+ insertion/deletion, though static display and wrapping and resizing
+ should now be solid because they are now used for online help display.
+ */
int Fl_Text_Display::measure_proportional_character(const char *s, int colNum, int pos) const {
- int charLen, style;
- char expChar[ FL_TEXT_MAX_EXP_CHAR_LEN ];
- Fl_Text_Buffer *styleBuf = mStyleBuffer;
-
- charLen = Fl_Text_Buffer::expand_character(s, colNum, expChar, buffer()->tab_distance()); // FIXME: unicode
- if (styleBuf == 0) {
- style = 0;
- } else {
- // FIXME: character is ucs-4
- style = (unsigned char)styleBuf->character(pos);
- if (style == mUnfinishedStyle && mUnfinishedHighlightCB) {
- /* encountered "unfinished" style, trigger parsing */
- (mUnfinishedHighlightCB)(pos, mHighlightCBArg);
- // FIXME: character is ucs-4
- style = (unsigned char)styleBuf->character(pos);
- }
- }
- return string_width(expChar, charLen, style);
+ int charLen = fl_utf8len(*s), style = 0;
+ if (mStyleBuffer) {
+ const char *b = mStyleBuffer->address(pos);
+ style = *b;
+ }
+ return string_width(s, charLen, style);
}
/**
- Finds both the end of the current line and the start of the next line. Why?
- In continuous wrap mode, if you need to know both, figuring out one from the
- other can be expensive or error prone. The problem comes when there's a
- trailing space or tab just before the end of the buffer. To translate an
- end of line value to or from the next lines start value, you need to know
- whether the trailing space or tab is being used as a line break or just a
- normal character, and to find that out would otherwise require counting all
- the way back to the beginning of the line.
-*/
+ Finds both the end of the current line and the start of the next line. Why?
+ In continuous wrap mode, if you need to know both, figuring out one from the
+ other can be expensive or error prone. The problem comes when there's a
+ trailing space or tab just before the end of the buffer. To translate an
+ end of line value to or from the next lines start value, you need to know
+ whether the trailing space or tab is being used as a line break or just a
+ normal character, and to find that out would otherwise require counting all
+ the way back to the beginning of the line.
+ */
void Fl_Text_Display::find_line_end(int startPos, bool startPosIsLineStart,
- int *lineEnd, int *nextLineStart) const {
- int retLines, retLineStart;
-
- /* if we're not wrapping use more efficient BufEndOfLine */
- if (!mContinuousWrap) {
- *lineEnd = buffer()->line_end(startPos);
- *nextLineStart = min(buffer()->length(), *lineEnd + 1);
- return;
- }
-
- /* use the wrapped line counter routine to count forward one line */
- wrapped_line_counter(buffer(), startPos, buffer()->length(),
- 1, startPosIsLineStart, 0, nextLineStart, &retLines,
- &retLineStart, lineEnd);
+ int *lineEnd, int *nextLineStart) const {
+ int retLines, retLineStart;
+
+ /* if we're not wrapping use more efficient BufEndOfLine */
+ if (!mContinuousWrap) {
+ *lineEnd = buffer()->line_end(startPos);
+ *nextLineStart = min(buffer()->length(), *lineEnd + 1);
return;
+ }
+
+ /* use the wrapped line counter routine to count forward one line */
+ wrapped_line_counter(buffer(), startPos, buffer()->length(),
+ 1, startPosIsLineStart, 0, nextLineStart, &retLines,
+ &retLineStart, lineEnd);
+ return;
}
/**
- Line breaks in continuous wrap mode usually happen at newlines or
- whitespace. This line-terminating character is not included in line
- width measurements and has a special status as a non-visible character.
- However, lines with no whitespace are wrapped without the benefit of a
- line terminating character, and this distinction causes endless trouble
- with all of the text display code which was originally written without
- continuous wrap mode and always expects to wrap at a newline character.
-**
- Given the position of the end of the line, as returned by TextDEndOfLine
- or BufEndOfLine, this returns true if there is a line terminating
- character, and false if there's not. On the last character in the
- buffer, this function can't tell for certain whether a trailing space was
- used as a wrap point, and just guesses that it wasn't. So if an exact
- accounting is necessary, don't use this function.
-*/
+ Line breaks in continuous wrap mode usually happen at newlines or
+ whitespace. This line-terminating character is not included in line
+ width measurements and has a special status as a non-visible character.
+ However, lines with no whitespace are wrapped without the benefit of a
+ line terminating character, and this distinction causes endless trouble
+ with all of the text display code which was originally written without
+ continuous wrap mode and always expects to wrap at a newline character.
+ **
+ Given the position of the end of the line, as returned by TextDEndOfLine
+ or BufEndOfLine, this returns true if there is a line terminating
+ character, and false if there's not. On the last character in the
+ buffer, this function can't tell for certain whether a trailing space was
+ used as a wrap point, and just guesses that it wasn't. So if an exact
+ accounting is necessary, don't use this function.
+ */
int Fl_Text_Display::wrap_uses_character(int lineEndPos) const {
- char c;
-
- if (!mContinuousWrap || lineEndPos == buffer()->length())
- return 1;
-
+ char c;
+
+ if (!mContinuousWrap || lineEndPos == buffer()->length())
+ return 1;
+
// FIXME: character is ucs-4
- c = buffer()->character(lineEndPos);
- return c == '\n' || ((c == '\t' || c == ' ') &&
- lineEndPos + 1 != buffer()->length());
+ c = buffer()->char_at(lineEndPos);
+ return c == '\n' || ((c == '\t' || c == ' ') &&
+ lineEndPos + 1 != buffer()->length());
}
/**
- Return true if the selection "sel" is rectangular, and touches a
- buffer position withing "rangeStart" to "rangeEnd"
-*/
-int Fl_Text_Display::range_touches_selection(const Fl_Text_Selection *sel,
- int rangeStart, int rangeEnd) const {
- return sel->selected() && sel->rectangular() && sel->end() >= rangeStart &&
- sel->start() <= rangeEnd;
-}
-
-/**
- Extend the range of a redraw request (from *start to *end) with additional
- redraw requests resulting from changes to the attached style buffer (which
- contains auxiliary information for coloring or styling text).
-*/
+ Extend the range of a redraw request (from *start to *end) with additional
+ redraw requests resulting from changes to the attached style buffer (which
+ contains auxiliary information for coloring or styling text).
+ */
void Fl_Text_Display::extend_range_for_styles( int *startpos, int *endpos ) {
Fl_Text_Selection * sel = mStyleBuffer->primary_selection();
int extended = 0;
-
+
/* The peculiar protocol used here is that modifications to the style
- buffer are marked by selecting them with the buffer's primary Fl_Text_Selection.
- The style buffer is usually modified in response to a modify callback on
- the text buffer BEFORE Fl_Text_Display.c's modify callback, so that it can keep
- the style buffer in step with the text buffer. The style-update
- callback can't just call for a redraw, because Fl_Text_Display hasn't processed
- the original text changes yet. Anyhow, to minimize redrawing and to
- avoid the complexity of scheduling redraws later, this simple protocol
- tells the text display's buffer modify callback to extend it's redraw
- range to show the text color/and font changes as well. */
+ buffer are marked by selecting them with the buffer's primary Fl_Text_Selection.
+ The style buffer is usually modified in response to a modify callback on
+ the text buffer BEFORE Fl_Text_Display.c's modify callback, so that it can keep
+ the style buffer in step with the text buffer. The style-update
+ callback can't just call for a redraw, because Fl_Text_Display hasn't processed
+ the original text changes yet. Anyhow, to minimize redrawing and to
+ avoid the complexity of scheduling redraws later, this simple protocol
+ tells the text display's buffer modify callback to extend it's redraw
+ range to show the text color/and font changes as well. */
if ( sel->selected() ) {
if ( sel->start() < *startpos ) {
*startpos = sel->start();
@@ -2915,11 +2752,11 @@ void Fl_Text_Display::extend_range_for_styles( int *startpos, int *endpos ) {
extended = 1;
}
}
-
+
/* If the Fl_Text_Selection was extended due to a style change, and some of the
- fonts don't match in spacing, extend redraw area to end of line to
- redraw characters exposed by possible font size changes */
- if ( mFixedFontWidth == -1 && extended )
+ fonts don't match in spacing, extend redraw area to end of line to
+ redraw characters exposed by possible font size changes */
+ if ( extended )
*endpos = mBuffer->line_end( *endpos ) + 1;
}
@@ -2927,49 +2764,49 @@ void Fl_Text_Display::extend_range_for_styles( int *startpos, int *endpos ) {
void Fl_Text_Display::draw(void) {
// don't even try if there is no associated text buffer!
if (!buffer()) { draw_box(); return; }
-
+
fl_push_clip(x(),y(),w(),h()); // prevent drawing outside widget area
-
+
// draw the non-text, non-scrollbar areas.
if (damage() & FL_DAMAGE_ALL) {
-// printf("drawing all (box = %d)\n", box());
+ // printf("drawing all (box = %d)\n", box());
// draw the box()
int W = w(), H = h();
draw_box(box(), x(), y(), W, H, color());
-
+
if (mHScrollBar->visible())
W -= scrollbar_width();
if (mVScrollBar->visible())
H -= scrollbar_width();
-
+
// left margin
fl_rectf(text_area.x-LEFT_MARGIN, text_area.y-TOP_MARGIN,
LEFT_MARGIN, text_area.h+TOP_MARGIN+BOTTOM_MARGIN,
color());
-
+
// right margin
fl_rectf(text_area.x+text_area.w, text_area.y-TOP_MARGIN,
RIGHT_MARGIN, text_area.h+TOP_MARGIN+BOTTOM_MARGIN,
color());
-
+
// top margin
fl_rectf(text_area.x, text_area.y-TOP_MARGIN,
text_area.w, TOP_MARGIN, color());
-
+
// bottom margin
fl_rectf(text_area.x, text_area.y+text_area.h,
text_area.w, BOTTOM_MARGIN, color());
-
+
// draw that little box in the corner of the scrollbars
if (mVScrollBar->visible() && mHScrollBar->visible())
fl_rectf(mVScrollBar->x(), mHScrollBar->y(),
mVScrollBar->w(), mHScrollBar->h(),
FL_GRAY);
-
+
// blank the previous cursor protrusions
}
else if (damage() & (FL_DAMAGE_SCROLL | FL_DAMAGE_EXPOSE)) {
-// printf("blanking previous cursor extrusions at Y: %d\n", mCursorOldY);
+ // printf("blanking previous cursor extrusions at Y: %d\n", mCursorOldY);
// CET - FIXME - save old cursor position instead and just draw side needed?
fl_push_clip(text_area.x-LEFT_MARGIN,
text_area.y,
@@ -2981,7 +2818,7 @@ void Fl_Text_Display::draw(void) {
RIGHT_MARGIN, mMaxsize, color());
fl_pop_clip();
}
-
+
// draw the scrollbars
if (damage() & (FL_DAMAGE_ALL | FL_DAMAGE_CHILD)) {
mVScrollBar->damage(FL_DAMAGE_ALL);
@@ -2989,7 +2826,7 @@ void Fl_Text_Display::draw(void) {
}
update_child(*mVScrollBar);
update_child(*mHScrollBar);
-
+
// draw all of the text
if (damage() & (FL_DAMAGE_ALL | FL_DAMAGE_EXPOSE)) {
//printf("drawing all text\n");
@@ -3018,7 +2855,7 @@ void Fl_Text_Display::draw(void) {
damage_range2_start = damage_range2_end = -1;
fl_pop_clip();
}
-
+
// draw the text cursor
if (damage() & (FL_DAMAGE_ALL | FL_DAMAGE_SCROLL | FL_DAMAGE_EXPOSE)
&& !buffer()->primary_selection()->selected() &&
@@ -3027,10 +2864,10 @@ void Fl_Text_Display::draw(void) {
text_area.y,
text_area.w+LEFT_MARGIN+RIGHT_MARGIN,
text_area.h);
-
+
int X, Y;
if (position_to_xy(mCursorPos, &X, &Y)) draw_cursor(X, Y);
-// else puts("position_to_xy() failed - unable to draw cursor!");
+ // else puts("position_to_xy() failed - unable to draw cursor!");
//printf("drew cursor at pos: %d (%d,%d)\n", mCursorPos, X, Y);
mCursorOldY = Y;
fl_pop_clip();
@@ -3077,24 +2914,24 @@ void Fl_Text_Display::scroll_timer_cb(void *user_data) {
Fl_Text_Display *w = (Fl_Text_Display*)user_data;
int pos;
switch (scroll_direction) {
- case 1: // mouse is to the right, scroll left
- w->scroll(w->mTopLineNum, w->mHorizOffset + scroll_amount);
- pos = w->xy_to_position(w->text_area.x + w->text_area.w, scroll_y, CURSOR_POS);
- break;
- case 2: // mouse is to the left, scroll right
- w->scroll(w->mTopLineNum, w->mHorizOffset + scroll_amount);
- pos = w->xy_to_position(w->text_area.x, scroll_y, CURSOR_POS);
- break;
- case 3: // mouse is above, scroll down
- w->scroll(w->mTopLineNum + scroll_amount, w->mHorizOffset);
- pos = w->xy_to_position(scroll_x, w->text_area.y, CURSOR_POS);
- break;
- case 4: // mouse is below, scroll up
- w->scroll(w->mTopLineNum + scroll_amount, w->mHorizOffset);
- pos = w->xy_to_position(scroll_x, w->text_area.y + w->text_area.h, CURSOR_POS);
- break;
- default:
- return;
+ case 1: // mouse is to the right, scroll left
+ w->scroll(w->mTopLineNum, w->mHorizOffset + scroll_amount);
+ pos = w->xy_to_position(w->text_area.x + w->text_area.w, scroll_y, CURSOR_POS);
+ break;
+ case 2: // mouse is to the left, scroll right
+ w->scroll(w->mTopLineNum, w->mHorizOffset + scroll_amount);
+ pos = w->xy_to_position(w->text_area.x, scroll_y, CURSOR_POS);
+ break;
+ case 3: // mouse is above, scroll down
+ w->scroll(w->mTopLineNum + scroll_amount, w->mHorizOffset);
+ pos = w->xy_to_position(scroll_x, w->text_area.y, CURSOR_POS);
+ break;
+ case 4: // mouse is below, scroll up
+ w->scroll(w->mTopLineNum + scroll_amount, w->mHorizOffset);
+ pos = w->xy_to_position(scroll_x, w->text_area.y + w->text_area.h, CURSOR_POS);
+ break;
+ default:
+ return;
}
fl_text_drag_me(pos, w);
Fl::repeat_timeout(.1, scroll_timer_cb, user_data);
@@ -3110,7 +2947,7 @@ int Fl_Text_Display::handle(int event) {
event != FL_KEYBOARD && event != FL_KEYUP) {
return Fl_Group::handle(event);
}
-
+
switch (event) {
case FL_ENTER:
case FL_MOVE:
@@ -3122,137 +2959,137 @@ int Fl_Text_Display::handle(int event) {
} else {
return 0;
}
-
+
case FL_LEAVE:
case FL_HIDE:
if (active_r() && window()) {
window()->cursor(FL_CURSOR_DEFAULT);
-
+
return 1;
} else {
return 0;
}
-
+
case FL_PUSH: {
- if (active_r() && window()) {
- if (Fl::event_inside(text_area.x, text_area.y, text_area.w,
- text_area.h)) window()->cursor(FL_CURSOR_INSERT);
- else window()->cursor(FL_CURSOR_DEFAULT);
- }
-
- if (Fl::focus() != this) {
- Fl::focus(this);
- handle(FL_FOCUS);
- }
- if (Fl_Group::handle(event)) return 1;
- if (Fl::event_state()&FL_SHIFT) return handle(FL_DRAG);
- dragging = 1;
- int pos = xy_to_position(Fl::event_x(), Fl::event_y(), CURSOR_POS);
+ if (active_r() && window()) {
+ if (Fl::event_inside(text_area.x, text_area.y, text_area.w,
+ text_area.h)) window()->cursor(FL_CURSOR_INSERT);
+ else window()->cursor(FL_CURSOR_DEFAULT);
+ }
+
+ if (Fl::focus() != this) {
+ Fl::focus(this);
+ handle(FL_FOCUS);
+ }
+ if (Fl_Group::handle(event)) return 1;
+ if (Fl::event_state()&FL_SHIFT) return handle(FL_DRAG);
+ dragging = 1;
+ int pos = xy_to_position(Fl::event_x(), Fl::event_y(), CURSOR_POS);
+ int ok = 0;
+ while (!ok) {
+ // FIXME: character is ucs-4
+ char c = buffer()->char_at( pos );
+ if (!((c & 0x80) && !(c & 0x40))) {
+ ok = 1;
+ } else {
+ pos++;
+ }
+ }
+ dragType = Fl::event_clicks();
+ dragPos = pos;
+ if (dragType == DRAG_CHAR)
+ buffer()->unselect();
+ else if (dragType == DRAG_WORD)
+ buffer()->select(word_start(pos), word_end(pos));
+ else if (dragType == DRAG_LINE)
+ buffer()->select(buffer()->line_start(pos), buffer()->line_end(pos)+1);
+
+ if (buffer()->primary_selection()->selected())
+ insert_position(buffer()->primary_selection()->end());
+ else
+ insert_position(pos);
+ show_insert_position();
+ return 1;
+ }
+
+ case FL_DRAG: {
+ if (dragType < 0) return 1;
+ int X = Fl::event_x(), Y = Fl::event_y(), pos = 0;
+ // if we leave the text_area, we start a timer event
+ // that will take care of scrolling and selecting
+ if (Y < text_area.y) {
+ scroll_x = X;
+ scroll_amount = (Y - text_area.y) / 5 - 1;
+ if (!scroll_direction) {
+ Fl::add_timeout(.01, scroll_timer_cb, this);
+ }
+ scroll_direction = 3;
+ } else if (Y >= text_area.y+text_area.h) {
+ scroll_x = X;
+ scroll_amount = (Y - text_area.y - text_area.h) / 5 + 1;
+ if (!scroll_direction) {
+ Fl::add_timeout(.01, scroll_timer_cb, this);
+ }
+ scroll_direction = 4;
+ } else if (X < text_area.x) {
+ scroll_y = Y;
+ scroll_amount = (X - text_area.x) / 2 - 1;
+ if (!scroll_direction) {
+ Fl::add_timeout(.01, scroll_timer_cb, this);
+ }
+ scroll_direction = 2;
+ } else if (X >= text_area.x+text_area.w) {
+ scroll_y = Y;
+ scroll_amount = (X - text_area.x - text_area.w) / 2 + 1;
+ if (!scroll_direction) {
+ Fl::add_timeout(.01, scroll_timer_cb, this);
+ }
+ scroll_direction = 1;
+ } else {
+ if (scroll_direction) {
+ Fl::remove_timeout(scroll_timer_cb, this);
+ scroll_direction = 0;
+ }
+ pos = xy_to_position(X, Y, CURSOR_POS);
int ok = 0;
while (!ok) {
// FIXME: character is ucs-4
- char c = buffer()->character( pos );
+ char c = buffer()->char_at( pos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
} else {
pos++;
}
}
- dragType = Fl::event_clicks();
- dragPos = pos;
- if (dragType == DRAG_CHAR)
- buffer()->unselect();
- else if (dragType == DRAG_WORD)
- buffer()->select(word_start(pos), word_end(pos));
- else if (dragType == DRAG_LINE)
- buffer()->select(buffer()->line_start(pos), buffer()->line_end(pos)+1);
-
- if (buffer()->primary_selection()->selected())
- insert_position(buffer()->primary_selection()->end());
- else
- insert_position(pos);
- show_insert_position();
- return 1;
}
-
- case FL_DRAG: {
- if (dragType < 0) return 1;
- int X = Fl::event_x(), Y = Fl::event_y(), pos = 0;
- // if we leave the text_area, we start a timer event
- // that will take care of scrolling and selecting
- if (Y < text_area.y) {
- scroll_x = X;
- scroll_amount = (Y - text_area.y) / 5 - 1;
- if (!scroll_direction) {
- Fl::add_timeout(.01, scroll_timer_cb, this);
- }
- scroll_direction = 3;
- } else if (Y >= text_area.y+text_area.h) {
- scroll_x = X;
- scroll_amount = (Y - text_area.y - text_area.h) / 5 + 1;
- if (!scroll_direction) {
- Fl::add_timeout(.01, scroll_timer_cb, this);
- }
- scroll_direction = 4;
- } else if (X < text_area.x) {
- scroll_y = Y;
- scroll_amount = (X - text_area.x) / 2 - 1;
- if (!scroll_direction) {
- Fl::add_timeout(.01, scroll_timer_cb, this);
- }
- scroll_direction = 2;
- } else if (X >= text_area.x+text_area.w) {
- scroll_y = Y;
- scroll_amount = (X - text_area.x - text_area.w) / 2 + 1;
- if (!scroll_direction) {
- Fl::add_timeout(.01, scroll_timer_cb, this);
- }
- scroll_direction = 1;
- } else {
- if (scroll_direction) {
- Fl::remove_timeout(scroll_timer_cb, this);
- scroll_direction = 0;
- }
- pos = xy_to_position(X, Y, CURSOR_POS);
- int ok = 0;
- while (!ok) {
- // FIXME: character is ucs-4
- char c = buffer()->character( pos );
- if (!((c & 0x80) && !(c & 0x40))) {
- ok = 1;
- } else {
- pos++;
- }
- }
- }
- fl_text_drag_me(pos, this);
- return 1;
- }
-
+ fl_text_drag_me(pos, this);
+ return 1;
+ }
+
case FL_RELEASE: {
- dragging = 0;
- if (scroll_direction) {
- Fl::remove_timeout(scroll_timer_cb, this);
- scroll_direction = 0;
- }
-
- // convert from WORD or LINE selection to CHAR
- if (insert_position() >= dragPos)
- dragPos = buffer()->primary_selection()->start();
- else
- dragPos = buffer()->primary_selection()->end();
- dragType = DRAG_CHAR;
-
- const char* copy = buffer()->selection_text();
- if (*copy) Fl::copy(copy, strlen(copy), 0);
- free((void*)copy);
- return 1;
+ dragging = 0;
+ if (scroll_direction) {
+ Fl::remove_timeout(scroll_timer_cb, this);
+ scroll_direction = 0;
}
-
+
+ // convert from WORD or LINE selection to CHAR
+ if (insert_position() >= dragPos)
+ dragPos = buffer()->primary_selection()->start();
+ else
+ dragPos = buffer()->primary_selection()->end();
+ dragType = DRAG_CHAR;
+
+ const char* copy = buffer()->selection_text();
+ if (*copy) Fl::copy(copy, strlen(copy), 0);
+ free((void*)copy);
+ return 1;
+ }
+
case FL_MOUSEWHEEL:
if (Fl::event_dy()) return mVScrollBar->handle(event);
else return mHScrollBar->handle(event);
-
+
case FL_UNFOCUS:
if (active_r() && window()) window()->cursor(FL_CURSOR_DEFAULT);
case FL_FOCUS:
@@ -3272,28 +3109,28 @@ int Fl_Text_Display::handle(int event) {
redisplay_range(start, end);
}
return 1;
-
+
case FL_KEYBOARD:
// Copy?
if ((Fl::event_state()&(FL_CTRL|FL_COMMAND)) && Fl::event_key()=='c') {
- if (!buffer()->selected()) return 1;
- const char *copy = buffer()->selection_text();
- if (*copy) Fl::copy(copy, strlen(copy), 1);
- free((void*)copy);
- return 1;
+ if (!buffer()->selected()) return 1;
+ const char *copy = buffer()->selection_text();
+ if (*copy) Fl::copy(copy, strlen(copy), 1);
+ free((void*)copy);
+ return 1;
}
-
+
// Select all ?
if ((Fl::event_state()&(FL_CTRL|FL_COMMAND)) && Fl::event_key()=='a') {
- buffer()->select(0,buffer()->length());
- return 1;
+ buffer()->select(0,buffer()->length());
+ return 1;
}
-
+
if (mVScrollBar->handle(event)) return 1;
if (mHScrollBar->handle(event)) return 1;
-
+
break;
-
+
case FL_SHORTCUT:
if (!(shortcut() ? Fl::test_shortcut(shortcut()) : test_shortcut()))
return 0;
@@ -3304,11 +3141,11 @@ int Fl_Text_Display::handle(int event) {
break;
}
-
+
return 0;
}
//
-// End of "$Id: Fl_Text_Display.cxx 7527 2010-04-18 14:33:33Z engelsman $".
+// End of "$Id: Fl_Text_Display.cxx 7794 2010-11-04 21:53:56Z matt $".
//
diff --git a/src/Fl_Text_Editor.cxx b/src/Fl_Text_Editor.cxx
index a670fb7..f025d00 100644
--- a/src/Fl_Text_Editor.cxx
+++ b/src/Fl_Text_Editor.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Text_Editor.cxx 7462 2010-04-06 23:00:56Z matt $"
+// "$Id: Fl_Text_Editor.cxx 7792 2010-11-03 22:01:43Z matt $"
//
// Copyright 2001-2009 by Bill Spitzak and others.
// Original code Copyright Mark Edel. Permission to distribute under
@@ -255,7 +255,7 @@ int Fl_Text_Editor::kf_backspace(int, Fl_Text_Editor* e) {
if (!e->buffer()->selected() && e->move_left()) {
int l = 1;
// FIXME: character is ucs-4
- char c = e->buffer()->character(e->insert_position());
+ char c = e->buffer()->char_at(e->insert_position());
if (c & 0x80 && c & 0x40) {
l = fl_utf8len(c);
}
@@ -451,7 +451,7 @@ int Fl_Text_Editor::kf_delete(int, Fl_Text_Editor* e) {
if (!e->buffer()->selected()) {
int l = 1;
// FIXME: character is ucs-4
- char c = e->buffer()->character(e->insert_position());
+ char c = e->buffer()->char_at(e->insert_position());
if (c & 0x80 && c & 0x40) {
l = fl_utf8len(c);
}
@@ -616,5 +616,5 @@ int Fl_Text_Editor::handle(int event) {
}
//
-// End of "$Id: Fl_Text_Editor.cxx 7462 2010-04-06 23:00:56Z matt $".
+// End of "$Id: Fl_Text_Editor.cxx 7792 2010-11-03 22:01:43Z matt $".
//
diff --git a/src/Fl_Tile.cxx b/src/Fl_Tile.cxx
index 762ea7d..a597531 100644
--- a/src/Fl_Tile.cxx
+++ b/src/Fl_Tile.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Tile.cxx 6616 2009-01-01 21:28:26Z matt $"
+// "$Id: Fl_Tile.cxx 7765 2010-10-28 18:02:20Z matt $"
//
// Tile widget for the Fast Light Tool Kit (FLTK).
//
@@ -52,17 +52,17 @@ void Fl_Tile::position(int oix, int oiy, int newx, int newy) {
int R = X+o->w();
if (oix) {
int t = p[0];
- if (t == oix || t>oix && X<newx || t<oix && X>newx) X = newx;
+ if (t == oix || (t>oix && X<newx) || (t<oix && X>newx) ) X = newx;
t = p[1];
- if (t == oix || t>oix && R<newx || t<oix && R>newx) R = newx;
+ if (t == oix || (t>oix && R<newx) || (t<oix && R>newx) ) R = newx;
}
int Y = o->y();
int B = Y+o->h();
if (oiy) {
int t = p[2];
- if (t == oiy || t>oiy && Y<newy || t<oiy && Y>newy) Y = newy;
+ if (t == oiy || (t>oiy && Y<newy) || (t<oiy && Y>newy) ) Y = newy;
t = p[3];
- if (t == oiy || t>oiy && B<newy || t<oiy && B>newy) B = newy;
+ if (t == oiy || (t>oiy && B<newy) || (t<oiy && B>newy) ) B = newy;
}
o->damage_resize(X,Y,R-X,B-Y);
}
@@ -210,5 +210,5 @@ int Fl_Tile::handle(int event) {
}
//
-// End of "$Id: Fl_Tile.cxx 6616 2009-01-01 21:28:26Z matt $".
+// End of "$Id: Fl_Tile.cxx 7765 2010-10-28 18:02:20Z matt $".
//
diff --git a/src/Fl_Tree.cxx b/src/Fl_Tree.cxx
index 57f7992..fa4318d 100644
--- a/src/Fl_Tree.cxx
+++ b/src/Fl_Tree.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Tree.cxx 7722 2010-10-12 15:46:30Z greg.ercolano $"
+// "$Id: Fl_Tree.cxx 7779 2010-10-30 19:56:20Z matt $"
//
#include <stdio.h>
@@ -488,8 +488,7 @@ int Fl_Tree::handle(int e) {
break;
}
case FL_Left: // received focus via LEFT or UP?
- case FL_Up:
- case 0xfe20: { // XK_ISO_Left_Tab
+ case FL_Up: { // XK_ISO_Left_Tab
set_item_focus(next_visible_item(0, FL_Up));
break;
}
@@ -894,5 +893,5 @@ void Fl_Tree::load(Fl_Preferences &prefs)
}
//
-// End of "$Id: Fl_Tree.cxx 7722 2010-10-12 15:46:30Z greg.ercolano $".
+// End of "$Id: Fl_Tree.cxx 7779 2010-10-30 19:56:20Z matt $".
//
diff --git a/src/Fl_XPM_Image.cxx b/src/Fl_XPM_Image.cxx
index 2d7326a..a94f60c 100644
--- a/src/Fl_XPM_Image.cxx
+++ b/src/Fl_XPM_Image.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_XPM_Image.cxx 6616 2009-01-01 21:28:26Z matt $"
+// "$Id: Fl_XPM_Image.cxx 7765 2010-10-28 18:02:20Z matt $"
//
// Fl_XPM_Image routines.
//
@@ -77,7 +77,7 @@ Fl_XPM_Image::Fl_XPM_Image(const char *name) : Fl_Pixmap((char *const*)0) {
if (*q == '\\') switch (*++q) {
case '\r':
case '\n':
- fgets(q,(buffer+MAXSIZE+20)-q,f); break;
+ if (!fgets(q,(buffer+MAXSIZE+20)-q,f)) { /* no problem if we hit EOF */ } break;
case 0:
break;
case 'x': {
@@ -132,5 +132,5 @@ Fl_XPM_Image::Fl_XPM_Image(const char *name) : Fl_Pixmap((char *const*)0) {
//
-// End of "$Id: Fl_XPM_Image.cxx 6616 2009-01-01 21:28:26Z matt $".
+// End of "$Id: Fl_XPM_Image.cxx 7765 2010-10-28 18:02:20Z matt $".
//
diff --git a/src/Fl_arg.cxx b/src/Fl_arg.cxx
index 1a9c36e..e042169 100644
--- a/src/Fl_arg.cxx
+++ b/src/Fl_arg.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_arg.cxx 7334 2010-03-25 14:37:46Z AlbrechtS $"
+// "$Id: Fl_arg.cxx 7731 2010-10-24 12:53:53Z engelsman $"
//
// Optional argument initialization code for the Fast Light Tool Kit (FLTK).
//
@@ -68,11 +68,73 @@ extern const char *fl_bg;
extern const char *fl_bg2;
/**
- Consume a single switch from argv, starting at word i.
+ Parse a single switch from \p argv, starting at word \p i.
Returns the number of words eaten (1 or 2, or 0 if it is not
- recognized) and adds the same value to i. You can use this
- function if you prefer to control the incrementing through the
- arguments yourself.
+ recognized) and adds the same value to \p i.
+
+ This is the default argument handler used internally by Fl::args(...),
+ but you can use this function if you prefer to step through the
+ standard FLTK switches yourself.
+
+ All standard FLTK switches except -bg2 may be abbreviated to just
+ one letter and case is ignored:
+
+ \li -bg color or -background color
+ <br>
+ Sets the background color using Fl::background().
+
+ \li -bg2 color or -background2 color
+ <br>
+ Sets the secondary background color using Fl::background2().
+
+ \li -display host:n.n
+ <br>
+ Sets the X display to use; this option is silently
+ ignored under WIN32 and MacOS.
+
+ \li -dnd and -nodnd
+ <br>
+ Enables or disables drag and drop text operations
+ using Fl::dnd_text_ops().
+
+ \li -fg color or -foreground color
+ <br>
+ Sets the foreground color using Fl::foreground().
+
+ \li -geometry WxH+X+Y
+ <br>
+ Sets the initial window position and size according
+ to the standard X geometry string.
+
+ \li -iconic
+ <br>
+ Iconifies the window using Fl_Window::iconize().
+
+ \li -kbd and -nokbd
+ <br>
+ Enables or disables visible keyboard focus for
+ non-text widgets using Fl::visible_focus().
+
+ \li -name string
+ <br>
+ Sets the window class using Fl_Window::xclass().
+
+ \li -scheme string
+ <br>
+ Sets the widget scheme using Fl::scheme().
+
+ \li -title string
+ <br>
+ Sets the window title using Fl_Window::label().
+
+ \li -tooltips and -notooltips
+ <br>
+ Enables or disables tooltips using Fl_Tooltip::enable().
+
+
+ If your program requires other switches in addition to the standard
+ FLTK options, you will need to pass your own argument handler to
+ Fl::args(int,char**,int&,Fl_Args_Handler) explicitly.
*/
int Fl::arg(int argc, char **argv, int &i) {
arg_called = 1;
@@ -167,114 +229,59 @@ int Fl::arg(int argc, char **argv, int &i) {
}
-/**
- Consume all switches from argv. Returns number of words eaten
- Returns zero on error. 'i' will either point at first word that
- does not start with '-', at the error word, or after a '--', or at
- argc. If your program does not take any word arguments you can
- report an error if i < argc.
-
- <P>FLTK provides an <I>entirely optional</I> command-line switch parser.
- You don't have to call it if you don't like them! Everything it can do
- can be done with other calls to FLTK.
-
- <P>To use the switch parser, call Fl::args(...) near the start
- of your program. This does <I>not</I> open the display, instead
- switches that need the display open are stashed into static variables.
- Then you <I>must</I> display your first window by calling
- window-&gt;show(argc,argv), which will do anything stored in the
- static variables.
-
- <P>callback lets you define your own switches. It is called
- with the same argc and argv, and with i the
- index of each word. The callback should return zero if the switch is
- unrecognized, and not change i. It should return non-zero if
- the switch is recognized, and add at least 1 to i (it can add
- more to consume words after the switch). This function is called
- <i>before</i> any other tests, so <i>you can override any FLTK
- switch</i> (this is why FLTK can use very short switches instead of
+/**
+ Parse command line switches using the \p cb argument handler.
+
+ Returns 0 on error, or the number of words processed.
+
+ FLTK provides this as an <i>entirely optional</i> command line
+ switch parser. You don't have to call it if you don't want to.
+ Everything it can do can be done with other calls to FLTK.
+
+ To use the switch parser, call Fl::args(...) near the start
+ of your program. This does \b not open the display, instead
+ switches that need the display open are stashed into static
+ variables. Then you \b must display your first window by calling
+ <tt>window->show(argc,argv)</tt>, which will do anything stored
+ in the static variables.
+
+ Providing an argument handler callback \p cb lets you define
+ your own switches. It is called with the same \p argc and \p argv,
+ and with \p i set to the index of the switch to be processed.
+ The \p cb handler should return zero if the switch is unrecognized,
+ and not change \p i. It should return non-zero to indicate the
+ number of words processed if the switch is recognized, i.e. 1 for
+ just the switch, and more than 1 for the switch plus associated
+ parameters. \p i should be incremented by the same amount.
+
+ The \p cb handler is called \b before any other tests, so
+ <i>you can also override any standard FLTK switch</i>
+ (this is why FLTK can use very short switches instead of
the long ones all other toolkits force you to use).
-
- <P>On return i is set to the index of the first non-switch.
+ See Fl::arg() for descriptions of the standard switches.
+
+ On return \p i is set to the index of the first non-switch.
This is either:
- <UL>
- <LI>The first word that does not start with '-'. </LI>
- <LI>The word '-' (used by many programs to name stdin as a file) </LI>
- <LI>The first unrecognized switch (return value is 0). </LI>
- <LI>argc</LI>
- </UL>
+ \li The first word that does not start with '-'.
+ \li The word '-' (used by many programs to name stdin as a file)
+ \li The first unrecognized switch (return value is 0).
+ \li \p argc
- <P>The return value is i unless an unrecognized switch is found,
- in which case it is zero. If your program takes no arguments other
+ The return value is \p i unless an unrecognized switch is found,
+ in which case it is zero. If your program takes no arguments other
than switches you should produce an error if the return value is less
- than argc.
-
- <P>All switches except -bg2 may be abbreviated one letter and case is ignored:
-
- <UL>
-
- <LI>-bg color or -background color
-
- <P>Sets the background color using Fl::background().</LI>
-
- <LI>-bg2 color or -background2 color
+ than \p argc.
- <P>Sets the secondary background color using Fl::background2().</LI>
- <LI>-display host:n.n
-
- <P>Sets the X display to use; this option is silently
- ignored under WIN32 and MacOS.</LI>
-
- <LI>-dnd and -nodnd
-
- <P>Enables or disables drag and drop text operations
- using Fl::dnd_text_ops().</LI>
-
- <LI>-fg color or -foreground color
-
- <P>Sets the foreground color using Fl::foreground().</LI>
-
- <LI>-geometry WxH+X+Y
-
- <P>Sets the initial window position and size according
- to the standard X geometry string.</LI>
-
- <LI>-iconic
-
- <P>Iconifies the window using Fl_Window::iconize().</LI>
-
- <LI>-kbd and -nokbd
-
- <P>Enables or disables visible keyboard focus for
- non-text widgets using Fl::visible_focus().</LI>
-
- <LI>-name string
-
- <P>Sets the window class using Fl_Window::xclass().</LI>
-
- <LI>-scheme string
-
- <P>Sets the widget scheme using Fl::scheme().</LI>
-
- <LI>-title string
-
- <P>Sets the window title using Fl_Window::label().</LI>
-
- <LI>-tooltips and -notooltips
-
- <P>Enables or disables tooltips using Fl_Tooltip::enable().</LI>
-
- </UL>
+ A usage string is displayed if Fl::args() detects an invalid argument
+ on the command-line. You can change the message by setting the
+ Fl::help pointer.
- <P>The second form of Fl::args() is useful if your program does
- not have command line switches of its own. It parses all the switches,
- and if any are not recognized it calls Fl::abort(Fl::help).
+ A very simple command line parser can be found in <tt>examples/howto-parse-args.cxx</tt>
- <P>A usage string is displayed if Fl::args() detects an invalid
- argument on the command-line. You can change the message by setting the
- Fl::help pointer.
+ The simpler Fl::args(int argc, char **argv) form is useful if your program
+ does not have command line switches of its own.
*/
int Fl::args(int argc, char** argv, int& i, Fl_Args_Handler cb) {
@@ -387,7 +394,15 @@ static const char * const helpmsg =
" -to[oltips]";
const char * const Fl::help = helpmsg+13;
-/** See Fl::args(int argc, char **argv, int& i, int (*cb)(int,char**,int&)) */
+
+/**
+ Parse all command line switches matching standard FLTK options only.
+
+ It parses all the switches, and if any are not recognized it calls
+ Fl::abort(Fl::help), i.e. unlike the long form, an unrecognized
+ switch generates an error message and causes the program to exit.
+
+ */
void Fl::args(int argc, char **argv) {
int i; if (Fl::args(argc,argv,i) < argc) Fl::error(helpmsg);
}
@@ -531,5 +546,5 @@ int XParseGeometry(const char* string, int* x, int* y,
#endif // ifdef WIN32
//
-// End of "$Id: Fl_arg.cxx 7334 2010-03-25 14:37:46Z AlbrechtS $".
+// End of "$Id: Fl_arg.cxx 7731 2010-10-24 12:53:53Z engelsman $".
//
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index ec45131..d9a97f5 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -875,141 +875,33 @@ static void cocoaMouseHandler(NSEvent *theEvent)
}
-/*
- * keycode_function for post-10.5 systems, allows more sophisticated decoding of keys
- */
-/*
- static int keycodeToUnicode(
- char * uniChars, int maxChars,
- EventKind eKind,
- UInt32 keycode, UInt32 modifiers,
- UInt32 * deadKeyStatePtr,
- unsigned char, // not used in this function
- unsigned short) // not used in this function
- {
- // first get the keyboard mapping in a post 10.2 way
-
- Ptr resource;
- TextEncoding encoding;
- static TextEncoding lastEncoding = kTextEncodingMacRoman;
- int len = 0;
- KeyboardLayoutRef currentLayout = NULL;
- static KeyboardLayoutRef lastLayout = NULL;
- SInt32 currentLayoutId = 0;
- static SInt32 lastLayoutId;
- int hasLayoutChanged = false;
- static Ptr uchr = NULL;
- static Ptr KCHR = NULL;
- // ScriptCode currentKeyScript;
-
- KLGetCurrentKeyboardLayout(&currentLayout);
- if (currentLayout) {
- KLGetKeyboardLayoutProperty(currentLayout, kKLIdentifier, (const void**)&currentLayoutId);
- if ( (lastLayout != currentLayout) || (lastLayoutId != currentLayoutId) ) {
- lastLayout = currentLayout;
- lastLayoutId = currentLayoutId;
- uchr = NULL;
- KCHR = NULL;
- if ((KLGetKeyboardLayoutProperty(currentLayout, kKLuchrData, (const void**)&uchr) == noErr) && (uchr != NULL)) {
- // done
- } else if ((KLGetKeyboardLayoutProperty(currentLayout, kKLKCHRData, (const void**)&KCHR) == noErr) && (KCHR != NULL)) {
- // done
- }
- // FIXME No Layout property found. Now we have a problem.
- }
- }
- if (hasLayoutChanged) {
- // deadKeyStateUp = deadKeyStateDown = 0;
- if (KCHR != NULL) {
- // FIXME this must not happen
- } else if (uchr == NULL) {
- KCHR = (Ptr) GetScriptManagerVariable(smKCHRCache);
- }
- }
- if (uchr != NULL) {
- // this is what I expect
- resource = uchr;
- } else {
- resource = KCHR;
- encoding = lastEncoding;
- // this is actually not supported by the following code and will likely crash
- }
-
- // now apply that keyboard mapping to our keycode
-
- int action;
- //OptionBits options = 0;
- // not used yet: OptionBits options = kUCKeyTranslateNoDeadKeysMask;
- unsigned long keyboardType;
- keycode &= 0xFF;
- modifiers = (modifiers >> 8) & 0xFF;
- keyboardType = LMGetKbdType();
- OSStatus status;
- UniCharCount actuallength;
- UniChar utext[10];
-
- switch(eKind) {
- case kEventRawKeyDown: action = kUCKeyActionDown; break;
- case kEventRawKeyUp: action = kUCKeyActionUp; break;
- case kEventRawKeyRepeat: action = kUCKeyActionAutoKey; break;
- default: return 0;
- }
-
- UInt32 deadKeyState = *deadKeyStatePtr;
- if ((action==kUCKeyActionUp)&&(*deadKeyStatePtr)) {
- deadKeyStatePtr = &deadKeyState;
- }
-
- status = UCKeyTranslate((const UCKeyboardLayout *) uchr,
- keycode, action, modifiers, keyboardType,
- 0, deadKeyStatePtr,
- 10, &actuallength, utext);
-
- if (noErr != status) {
- fprintf(stderr,"UCKeyTranslate failed: %d\n", (int) status);
- actuallength = 0;
- }
-
- // convert the list of unicode chars into utf8
- // FIXME no bounds check (see maxchars)
- unsigned i;
- for (i=0; i<actuallength; ++i) {
- len += fl_utf8encode(utext[i], uniChars+len);
- }
- uniChars[len] = 0;
- return len;
- }
- */
-
-/*
- * keycode_function for pre-10.5 systems, this is the "historic" fltk Mac key handling
- */
-static int keycode_wrap_old(char * buffer,
- int, EventKind, UInt32, // not used in this function
- UInt32, UInt32 *, // not used in this function
- unsigned char key,
- unsigned short sym)
-{
- if ( (sym >= FL_KP && sym <= FL_KP_Last) || !(sym & 0xff00) ||
- sym == FL_Tab || sym == FL_Enter) {
- buffer[0] = key;
- return 1;
- } else {
+static void calc_e_text(CFStringRef s, char *buffer, size_t len, unsigned sym)
+{
+ int i, no_text_key = false;
+ static unsigned notext[] = { // keys that don't emit text
+ FL_BackSpace, FL_Print, FL_Scroll_Lock, FL_Pause,
+ FL_Insert, FL_Home, FL_Page_Up, FL_Delete, FL_End, FL_Page_Down,
+ FL_Left, FL_Up, FL_Right, FL_Down,
+ FL_Menu, FL_Num_Lock, FL_Help
+ };
+ int count = sizeof(notext)/sizeof(int);
+
+ if (sym > FL_F && sym <= FL_F_Last) no_text_key = true;
+ else for (i=0; i < count; i++) {
+ if(notext[i] == sym) {
+ no_text_key = true;
+ break;
+ }
+ }
+
+ if ( no_text_key) {
buffer[0] = 0;
- return 0;
+ } else {
+ CFStringGetCString(s, buffer, len, kCFStringEncodingUTF8);
}
-} /* keycode_wrap_old */
-
-/*
- * Stub pointer to select appropriate keycode_function per operating system version. This function pointer
- * is initialised in fl_open_display, based on the runtime identification of the host OS version. This is
- * intended to allow us to utilise 10.5 services dynamically to improve Unicode handling, whilst still
- * allowing code to run satisfactorily on older systems.
- */
-static int (*keycode_function)(char*, int, EventKind, UInt32, UInt32, UInt32*, unsigned char, unsigned short) = keycode_wrap_old;
+}
-// EXPERIMENTAL!
// this gets called by CJK character palette input
OSStatus carbonTextHandler( EventHandlerCallRef nextHandler, EventRef event, void *unused )
{
@@ -1018,20 +910,16 @@ OSStatus carbonTextHandler( EventHandlerCallRef nextHandler, EventRef event, voi
if (keywindow == nil || ![keywindow isMemberOfClass:[FLWindow class]]) return eventNotHandledErr;
// under 10.5 this gets called only after character palette inputs
// but under 10.6 this gets also called by interpretKeyEvents
- // during character composition when we don't want to run it
+ // during keyboard input when we don't want to run it
if ([[NSApp currentEvent] type] != NSSystemDefined) return eventNotHandledErr;
Fl_Window *window = [(FLWindow*)keywindow getFl_Window];
fl_lock_function();
- // int kind = GetEventKind(event);
- unsigned short buf[200];
- ByteCount size;
+ UniChar ucs[20];
GetEventParameter( event, kEventParamTextInputSendText, typeUnicodeText,
- NULL, 100, &size, &buf );
- // printf("TextEvent: %02x %02x %02x %02x\n", buf[0], buf[1], buf[2], buf[3]);
- // FIXME: oversimplified!
- unsigned ucs = buf[0];
- char utf8buf[20];
- int len = fl_utf8encode(ucs, utf8buf);
+ NULL, 20, NULL, ucs );
+ char utf8buf[5];
+ int len = fl_utf8encode(ucs[0], utf8buf);
+ utf8buf[len]=0;
Fl::e_length = len;
Fl::e_text = utf8buf;
@@ -1047,44 +935,6 @@ OSStatus carbonTextHandler( EventHandlerCallRef nextHandler, EventRef event, voi
return noErr;
}
-static void processCompositionSequence(CFStringRef s, Fl_Window *window)
-// composed character sequences are sent here
-// they contain 2 unichars, the first comes from the deadkey and can be non ascii (e.g., diaeresis),
-// the second is the character to be modified (e.g., e to be accented)
-{
- // unicodes: non-ascii unicode chars produced by deadkeys
- // asciis: corresponding ascii chars expected by Fl::compose()
- // diaeresis acute-accent circumflex tilde ring-above
- static UniChar unicodes[] = {0xA8, 0xB4, 0x2C6, 0x2DC, 0x2DA };
- static char asciis[] = { ':', '\'', '^', '~', '*' };
- if (CFStringGetLength(s) == 0) return;
- char text[10];
- char buffer[10];
- UniChar unis[2];
- CFStringGetCharacters(s, CFRangeMake(0, 2), unis);
- for(unsigned int i = 0; i < sizeof(asciis)/sizeof(char); i++) {
- if (unis[0] == unicodes[i]) {
- // replace the non-ascii unicode by the corresponding ascii value
- unis[0] = (UniChar)asciis[i];
- break;
- }
- }
- CFStringRef smod = CFStringCreateWithCharacters(kCFAllocatorDefault, unis, 2);
- CFStringGetCString(smod, buffer, sizeof(buffer), kCFStringEncodingUTF8);
- CFRelease(smod);
- Fl::e_keysym = 0;
- Fl::e_state = 0;
- Fl::e_length = 1;
- Fl::e_text = text;
- Fl::e_text[0] = buffer[0];
- Fl::handle(FL_KEYBOARD, window);
- Fl::e_keysym = 0;
- Fl::e_state = 0;
- Fl::e_length = 1;
- Fl::e_text[0] = buffer[1];
- Fl::handle(FL_KEYBOARD, window);
-}
-
/*
* handle cocoa keyboard events
@@ -1098,124 +948,62 @@ OSStatus cocoaKeyboardHandler(NSEvent *theEvent)
NSUInteger mods;
fl_lock_function();
-
- int kind = 0;
-
- // get the modifiers for any of the events
+
+ // get the modifiers
mods = [theEvent modifierFlags];
-
- // get the key code only for key events
+ // get the key code
UInt32 keyCode = 0, maskedKeyCode = 0;
- unichar key = 0;
- unsigned char keychar = 0;
unsigned short sym = 0;
keyCode = [theEvent keyCode];
NSString *s = [theEvent characters];
static BOOL compose = NO;
- static NSText *edit;
- static int countevents;
- static CFMutableStringRef sequence; // will contain the two characters of the composition sequence
+ // send keydown events to an object of type NSText that handles character composition sequences
+ NSText *edit = [[theEvent window] fieldEditor:YES forObject:nil];
+ if([theEvent type] == NSKeyDown) [edit interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
+
if ( (mods & NSShiftKeyMask) && (mods & NSCommandKeyMask) ) {
s = [s uppercaseString]; // US keyboards return lowercase letter in s if cmd-shift-key is hit
}
- if (compose) { // we are in a composition sequence
- // the only benefit of sending events to the NSText object edit is that the deadkey becomes visible
- // at its keyUp event; without this, the deadkey remains invisible
- if ([s length] == 0) { // occurs if 2 deadkeys are typed successively by error
- compose = NO;
- [edit setString:@""];
- CFRelease(sequence);
- fl_unlock_function();
- return noErr;
- }
- [edit interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
- countevents++;
- UniChar deadkey;
- CFStringGetCharacters((CFStringRef)s, CFRangeMake(0, 1), &deadkey);
- CFStringAppendCharacters(sequence, &deadkey, 1);// done for keyUp of deadkey and keyDown of next key
- if (countevents >= 3) { // end of composition sequence
- processCompositionSequence( sequence, window );
- CFRelease(sequence);
- [edit setString:@""]; // clear the content of the edit object
- compose=NO; // character composition is now complete
- }
- fl_unlock_function();
- return noErr;
- }
- if ([s length] == 0) { // this is a dead key that must be combined with the next key to be pressed
- while (window->parent()) window = window->window();
- Fl::e_keysym = FL_Control_R; // first simulate pressing of the compose key (FL_Control_R)
- Fl::e_text = (char*)"";
- Fl::e_length = 0;
- Fl::handle(FL_KEYBOARD, window);
+ if ([s length] == 0) { // this is a dead key that must be combined with the next key to be pressed
compose=YES;
- // then send remaining events to an object of type NSText that helps handle character composition sequences
- edit = [[theEvent window] fieldEditor:YES forObject:nil];
- [edit interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
- countevents = 1;
- sequence = CFStringCreateMutable(NULL, 2);
fl_unlock_function();
return noErr;
- } else {
- char buff[10];
- CFStringGetCString((CFStringRef)s, buff, sizeof(buff), kCFStringEncodingUnicode);
- key = *(unichar*)buff;
- keychar = buff[0];
}
// extended keyboards can also send sequences on key-up to generate Kanji etc. codes.
// Some observed prefixes are 0x81 to 0x83, followed by an 8 bit keycode.
// In this mode, there seem to be no key-down codes
// printf("%08x %08x %08x\n", keyCode, mods, key);
maskedKeyCode = keyCode & 0x7f;
- /* output a human readable event identifier for debugging
- * const char *ev = "";
- * switch (kind) {
- * case kEventRawKeyDown: ev = "kEventRawKeyDown"; break;
- * case kEventRawKeyRepeat: ev = "kEventRawKeyRepeat"; break;
- * case kEventRawKeyUp: ev = "kEventRawKeyUp"; break;
- * case kEventRawKeyModifiersChanged: ev = "kEventRawKeyModifiersChanged"; break;
- * default: ev = "unknown"; break;
- * }
- * printf("%08x %08x %08x '%c' %s \n", mods, keyCode, key, key, ev);
- */
switch([theEvent type]) {
case NSKeyDown:
sendEvent = FL_KEYBOARD;
+ if(compose) Fl::compose_state = 1;
// fall through
case NSKeyUp: {
+ if(compose) sendEvent = FL_KEYBOARD;
if ( !sendEvent ) {
sendEvent = FL_KEYUP;
Fl::e_state &= 0xbfffffff; // clear the deadkey flag
}
- mods_to_e_state( mods ); // we process modifier keys at the same time
- // if the user pressed alt/option, event_key should have the keycap,
- // but event_text should generate the international symbol
+ mods_to_e_state( mods ); // process modifier keys
sym = macKeyLookUp[maskedKeyCode];
- if ( isalpha(key) )
- sym = tolower(key);
- else if ( Fl::e_state&FL_CTRL && key<32 && sym<0xff00)
- sym = key+96;
- else if ( Fl::e_state&FL_ALT && sym<0xff00) { // find the keycap of this key
+ if (sym < 0xff00) { // a "simple" key
+ // find the result of this key without modifier
NSString *sim = [theEvent charactersIgnoringModifiers];
UniChar one;
CFStringGetCharacters((CFStringRef)sim, CFRangeMake(0, 1), &one);
sym = one;
- // charactersIgnoringModifiers does'nt ignore shift, remove it when it's on
+ // charactersIgnoringModifiers doesn't ignore shift, remove it when it's on
if(sym >= 'A' && sym <= 'Z') sym += 32;
}
Fl::e_keysym = Fl::e_original_keysym = sym;
// Handle FL_KP_Enter on regular keyboards and on Powerbooks
- if ( maskedKeyCode==0x4c || maskedKeyCode==0x34) key=0x0d;
- static UInt32 deadKeyState = 0; // must be cleared when losing focus
- int l = (*keycode_function)(buffer, 31, kind, keyCode, mods, &deadKeyState, keychar, sym);
- if (l > 0) {
- CFStringGetCString((CFStringRef)s, buffer, sizeof(buffer), kCFStringEncodingUTF8);
- }
+ if ( maskedKeyCode==0x4c || maskedKeyCode==0x34) s = @"\r";
+ calc_e_text((CFStringRef)s, buffer, sizeof(buffer), sym);
Fl::e_length = strlen(buffer);
Fl::e_text = buffer;
- buffer[Fl::e_length] = 0; // just in case...
- }
+ }
break;
default:
fl_unlock_function();
@@ -1223,6 +1011,10 @@ OSStatus cocoaKeyboardHandler(NSEvent *theEvent)
}
while (window->parent()) window = window->window();
if (sendEvent && Fl::handle(sendEvent,window)) {
+ if ([theEvent type] == NSKeyDown) {
+ [edit setString:@""];
+ if (compose) compose = NO;
+ }
fl_unlock_function();
return noErr; // return noErr if FLTK handled the event
} else {
@@ -1232,7 +1024,6 @@ OSStatus cocoaKeyboardHandler(NSEvent *theEvent)
}
-
/*
* Open callback function to call...
*/
@@ -1557,18 +1348,7 @@ void fl_open_display() {
CFRelease(execUrl);
}
-
- keycode_function = keycode_wrap_old; // under Cocoa we always use this one
- /* // imm: keycode handler stub setting - use Gestalt to determine the running system version,
- * // then set the keycode_function pointer accordingly
- * if (MACsystemVersion >= 0x1050) { // 10.5.0 or later
- * keycode_function = keycodeToUnicode;
- * }
- * else {
- * keycode_function = keycode_wrap_old; // pre-10.5 mechanism
- * }
- */
-
+
if ( !bundle )
{
// Earlier versions of this code tried to use weak linking, however it
diff --git a/src/Fl_compose.cxx b/src/Fl_compose.cxx
index dce2d11..28d04e0 100644
--- a/src/Fl_compose.cxx
+++ b/src/Fl_compose.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_compose.cxx 7351 2010-03-29 10:35:00Z matt $"
+// "$Id: Fl_compose.cxx 7765 2010-10-28 18:02:20Z matt $"
//
// Character compose processing for the Fast Light Tool Kit (FLTK).
//
@@ -37,14 +37,7 @@
//#define OLD_DEAD_KEY_CODE
-#ifdef __APPLE__
-
-static const char* const compose_pairs =
-" ! % # $ y=| & : c a <<~ - r _ * +-2 3 ' u p . , 1 o >>141234? "//00A0 ...
-"`A'A^A~A:A*AAE,C`E'E^E:E`I'I^I:I-D~N`O'O^O~O:Ox O/`U'U^U:U'YTHss" //00C0 ...
-"`a'a^a~a:a*aae,c`e'e^e:e`i'i^i:i-d~n`o'o^o~o:o-:o/`u'u^u:u'yth:y";//00E0 ...
-
-#else
+#ifndef __APPLE__
static const char* const compose_pairs =
"=E _'f _\"..+ ++^ %%^S< OE ^Z ^''^^\"\"^-*- --~ TM^s> oe ^z:Y"
@@ -85,6 +78,26 @@ static char dead_keys[] = {
int Fl::compose_state = 0;
#endif
+#ifdef __APPLE__
+// under Mac OS X character composition is handled by the OS
+int Fl::compose(int& del) {
+ if(Fl::e_length == 0 || Fl::e_keysym == FL_Enter || Fl::e_keysym == FL_KP_Enter ||
+ Fl::e_keysym == FL_Tab || Fl::e_keysym == FL_Escape || Fl::e_state&FL_META || Fl::e_state&FL_CTRL) {
+ del = 0;
+ return 0;
+ }
+ if(Fl::compose_state) {
+ del = 1;
+ Fl::compose_state = 0;
+ }
+ else {
+ del = 0;
+ }
+ return 1;
+}
+
+#else
+
/** Any text editing widget should call this for each FL_KEYBOARD event.
Use of this function is very simple.
@@ -114,11 +127,7 @@ int Fl::compose(int& del) {
//
// OSX users sometimes need to hold down ALT for keys, so we only check
// for META on OSX...
-#ifdef __APPLE__
- if ((e_state & FL_META) && !(ascii & 128)) return 0;
-#else
if ((e_state & (FL_ALT|FL_META)) && !(ascii & 128)) return 0;
-#endif // __APPLE__
if (compose_state == 1) { // after the compose key
if ( // do not get distracted by any modifier keys
@@ -134,15 +143,9 @@ int Fl::compose(int& del) {
) return 0;
if (ascii == ' ') { // space turns into nbsp
-#ifdef __APPLE__
- int len = fl_utf8encode(0xCA, e_text);
- e_text[len] = '\0';
- e_length = len;
- #else
int len = fl_utf8encode(0xA0, e_text);
e_text[len] = '\0';
e_length = len;
-#endif
compose_state = 0;
return 1;
} else if (ascii < ' ' || ascii == 127) {
@@ -171,22 +174,9 @@ int Fl::compose(int& del) {
} else if (compose_state) { // second character of compose
char c1 = char(compose_state); // retrieve first character
-#ifdef __APPLE__
- if ( (c1==0x60 && ascii==0xab) || (c1==0x27 && ascii==0x60)) {
- del = 1;
- compose_state = '^';
- e_text[0] = 0xf6;
- return 1;
- }
- if (ascii==' ') {
- del = 0;
- compose_state = 0;
- return 0;
- }
-#endif
// now search for the pair in either order:
for (const char *p = compose_pairs; *p; p += 2) {
- if (p[0] == ascii && p[1] == c1 || p[1] == ascii && p[0] == c1) {
+ if ( (p[0] == ascii && p[1] == c1) || (p[1] == ascii && p[0] == c1)) {
int len = fl_utf8encode((p-compose_pairs)/2+0xA0, e_text);
e_text[len] = '\0';
e_length = len;
@@ -206,16 +196,7 @@ int Fl::compose(int& del) {
return 1;
}
-#ifdef WIN32
-#elif (defined __APPLE__)
- if (e_state & 0x40000000) {
- if (ascii<0x80)
- compose_state = ascii;
- else
- compose_state = compose_pairs[(ascii-0x80)*2];
- return 1;
- }
-#else
+#ifndef WIN32
// See if they typed a dead key. This gets it into the same state as
// typing prefix+accent:
if (i >= 0xfe50 && i <= 0xfe5b) {
@@ -246,5 +227,9 @@ int Fl::compose(int& del) {
return 0;
}
+#endif // __APPLE__
+//
+// End of "$Id: Fl_compose.cxx 7765 2010-10-28 18:02:20Z matt $"
+//
diff --git a/src/Fl_lock.cxx b/src/Fl_lock.cxx
index 1d2b617..16672a4 100644
--- a/src/Fl_lock.cxx
+++ b/src/Fl_lock.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_lock.cxx 6787 2009-05-14 20:16:09Z engelsman $"
+// "$Id: Fl_lock.cxx 7765 2010-10-28 18:02:20Z matt $"
//
// Multi-threading support code for the Fast Light Tool Kit (FLTK).
//
@@ -304,7 +304,7 @@ static void unlock_function_rec() {
# endif // PTHREAD_MUTEX_RECURSIVE
void Fl::awake(void* msg) {
- write(thread_filedes[1], &msg, sizeof(void*));
+ if (write(thread_filedes[1], &msg, sizeof(void*))==0) { /* ignore */ }
}
static void* thread_message_;
@@ -315,7 +315,9 @@ void* Fl::thread_message() {
}
static void thread_awake_cb(int fd, void*) {
- read(fd, &thread_message_, sizeof(void*));
+ if (read(fd, &thread_message_, sizeof(void*))==0) {
+ /* This should never happen */
+ }
Fl_Awake_Handler func;
void *data;
while (Fl::get_awake_handler_(func, data)==0) {
@@ -331,7 +333,9 @@ void Fl::lock() {
if (!thread_filedes[1]) {
// Initialize thread communication pipe to let threads awake FLTK
// from Fl::wait()
- pipe(thread_filedes);
+ if (pipe(thread_filedes)==-1) {
+ /* this should not happen */
+ }
// Make the write side of the pipe non-blocking to avoid deadlock
// conditions (STR #1537)
@@ -395,5 +399,5 @@ void Fl::awake(void*) {
#endif // WIN32
//
-// End of "$Id: Fl_lock.cxx 6787 2009-05-14 20:16:09Z engelsman $".
+// End of "$Id: Fl_lock.cxx 7765 2010-10-28 18:02:20Z matt $".
//
diff --git a/src/Fl_x.cxx b/src/Fl_x.cxx
index 4e9cebc..843b978 100644
--- a/src/Fl_x.cxx
+++ b/src/Fl_x.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_x.cxx 7659 2010-07-01 13:21:32Z manolo $"
+// "$Id: Fl_x.cxx 7779 2010-10-30 19:56:20Z matt $"
//
// X specific code for the Fast Light Tool Kit (FLTK).
//
@@ -350,19 +350,19 @@ void fl_new_ic()
#if USE_XFT
#if defined(__GNUC__)
-#warning XFT support here
+// FIXME: warning XFT support here
#endif /*__GNUC__*/
if (!fs) {
fnt = NULL;//fl_get_font_xfld(0, 14);
- if (!fnt) {fnt = "-misc-fixed-*";must_free_fnt=false;}
+ if (!fnt) {fnt = (char*)"-misc-fixed-*";must_free_fnt=false;}
fs = XCreateFontSet(fl_display, fnt, &missing_list,
&missing_count, &def_string);
}
#else
if (!fs) {
fnt = fl_get_font_xfld(0, 14);
- if (!fnt) {fnt = "-misc-fixed-*";must_free_fnt=false;}
+ if (!fnt) {fnt = (char*)"-misc-fixed-*";must_free_fnt=false;}
fs = XCreateFontSet(fl_display, fnt, &missing_list,
&missing_count, &def_string);
}
@@ -465,16 +465,16 @@ void fl_set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win)
#if USE_XFT
#if defined(__GNUC__)
-#warning XFT support here
+// FIXME: warning XFT support here
#endif /*__GNUC__*/
fnt = NULL; // fl_get_font_xfld(font, size);
- if (!fnt) {fnt = "-misc-fixed-*";must_free_fnt=false;}
+ if (!fnt) {fnt = (char*)"-misc-fixed-*";must_free_fnt=false;}
fs = XCreateFontSet(fl_display, fnt, &missing_list,
&missing_count, &def_string);
#else
fnt = fl_get_font_xfld(font, size);
- if (!fnt) {fnt = "-misc-fixed-*";must_free_fnt=false;}
+ if (!fnt) {fnt = (char*)"-misc-fixed-*";must_free_fnt=false;}
fs = XCreateFontSet(fl_display, fnt, &missing_list,
&missing_count, &def_string);
#endif
@@ -1254,6 +1254,10 @@ int fl_handle(const XEvent& thisevent)
Fl::e_original_keysym = (int)keysym;
}
Fl::e_keysym = int(keysym);
+
+ // replace XK_ISO_Left_Tab (Shift-TAB) with FL_Tab (modifier flags are set correctly by X11)
+ if (Fl::e_keysym == 0xfe20) Fl::e_keysym = FL_Tab;
+
set_event_xy();
Fl::e_is_click = 0;
break;}
@@ -1725,7 +1729,7 @@ void Fl_Window::label(const char *name,const char *iname) {
// contents are restored to the area, but this assumes the area
// is cleared to background color. So this is disabled in this version.
// Fl_Window *fl_boxcheat;
-static inline int can_boxcheat(uchar b) {return (b==1 || (b&2) && b<=15);}
+static inline int can_boxcheat(uchar b) {return (b==1 || ((b&2) && b<=15));}
void Fl_Window::show() {
image(Fl::scheme_bg_);
@@ -1829,5 +1833,5 @@ void preparePrintFront(void)
#endif
//
-// End of "$Id: Fl_x.cxx 7659 2010-07-01 13:21:32Z manolo $".
+// End of "$Id: Fl_x.cxx 7779 2010-10-30 19:56:20Z matt $".
//
diff --git a/src/filename_absolute.cxx b/src/filename_absolute.cxx
index 35a5fc7..2b4c4c3 100644
--- a/src/filename_absolute.cxx
+++ b/src/filename_absolute.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: filename_absolute.cxx 6986 2010-01-01 18:30:49Z greg.ercolano $"
+// "$Id: filename_absolute.cxx 7778 2010-10-30 19:46:05Z matt $"
//
// Filename expansion routines for the Fast Light Tool Kit (FLTK).
//
@@ -210,6 +210,7 @@ fl_filename_relative(char *to, // O - Relative filename
if (isdirsep(*slash)) slash ++;
// do the same for the current dir
+ if (isdirsep(*newslash)) newslash --;
if (*newslash != '\0')
while (!isdirsep(*newslash) && newslash > cwd) newslash --;
@@ -232,5 +233,5 @@ fl_filename_relative(char *to, // O - Relative filename
//
-// End of "$Id: filename_absolute.cxx 6986 2010-01-01 18:30:49Z greg.ercolano $".
+// End of "$Id: filename_absolute.cxx 7778 2010-10-30 19:46:05Z matt $".
//
diff --git a/src/fl_boxtype.cxx b/src/fl_boxtype.cxx
index 6a1b761..e3c37a7 100644
--- a/src/fl_boxtype.cxx
+++ b/src/fl_boxtype.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: fl_boxtype.cxx 7469 2010-04-07 23:17:33Z matt $"
+// "$Id: fl_boxtype.cxx 7765 2010-10-28 18:02:20Z matt $"
//
// Box drawing code for the Fast Light Tool Kit (FLTK).
//
@@ -81,19 +81,19 @@ void fl_frame(const char* s, int x, int y, int w, int h) {
uchar *g = fl_gray_ramp();
if (h > 0 && w > 0) for (;*s;) {
// draw top line:
- fl_color(g[*s++]);
+ fl_color(g[(int)*s++]);
fl_xyline(x, y, x+w-1);
y++; if (--h <= 0) break;
// draw left line:
- fl_color(g[*s++]);
+ fl_color(g[(int)*s++]);
fl_yxline(x, y+h-1, y);
x++; if (--w <= 0) break;
// draw bottom line:
- fl_color(g[*s++]);
+ fl_color(g[(int)*s++]);
fl_xyline(x, y+h-1, x+w-1);
if (--h <= 0) break;
// draw right line:
- fl_color(g[*s++]);
+ fl_color(g[(int)*s++]);
fl_yxline(x+w-1, y+h-1, y);
if (--w <= 0) break;
}
@@ -115,19 +115,19 @@ void fl_frame2(const char* s, int x, int y, int w, int h) {
uchar *g = fl_gray_ramp();
if (h > 0 && w > 0) for (;*s;) {
// draw bottom line:
- fl_color(g[*s++]);
+ fl_color(g[(int)*s++]);
fl_xyline(x, y+h-1, x+w-1);
if (--h <= 0) break;
// draw right line:
- fl_color(g[*s++]);
+ fl_color(g[(int)*s++]);
fl_yxline(x+w-1, y+h-1, y);
if (--w <= 0) break;
// draw top line:
- fl_color(g[*s++]);
+ fl_color(g[(int)*s++]);
fl_xyline(x, y, x+w-1);
y++; if (--h <= 0) break;
// draw left line:
- fl_color(g[*s++]);
+ fl_color(g[(int)*s++]);
fl_yxline(x, y+h-1, y);
x++; if (--w <= 0) break;
}
@@ -425,5 +425,5 @@ void Fl_Widget::draw_box(Fl_Boxtype t, int X, int Y, int W, int H, Fl_Color c) c
}
//
-// End of "$Id: fl_boxtype.cxx 7469 2010-04-07 23:17:33Z matt $".
+// End of "$Id: fl_boxtype.cxx 7765 2010-10-28 18:02:20Z matt $".
//
diff --git a/src/fl_color.cxx b/src/fl_color.cxx
index 5946976..c55c61d 100644
--- a/src/fl_color.cxx
+++ b/src/fl_color.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: fl_color.cxx 7617 2010-05-27 17:20:18Z manolo $"
+// "$Id: fl_color.cxx 7770 2010-10-29 22:14:59Z engelsman $"
//
// Color functions for the Fast Light Tool Kit (FLTK).
//
@@ -202,7 +202,7 @@ static inline uchar realcolor(uchar color, uchar mask) {
}
return result;
# else
- return (color&mask) | (~mask)&(mask>>1);
+ return (color&mask) | ( (~mask)&(mask>>1) );
# endif
}
@@ -361,14 +361,12 @@ void Fl::set_color(Fl_Color i, unsigned c) {
#endif // end of X-specific code
/**
- Returns the RGB value(s) for the given FLTK color index. The
- first form returns the RGB values packed in a 32-bit unsigned
+ Returns the RGB value(s) for the given FLTK color index.
+
+ This form returns the RGB values packed in a 32-bit unsigned
integer with the red value in the upper 8 bits, the green value
in the next 8 bits, and the blue value in bits 8-15. The lower
8 bits will always be 0.
-
- The second form returns the red, green, and blue values
- separately in referenced variables.
*/
unsigned Fl::get_color(Fl_Color i) {
if (i & 0xffffff00) return (i);
@@ -383,7 +381,14 @@ void Fl::set_color(Fl_Color i, uchar red, uchar green, uchar blue) {
Fl::set_color((Fl_Color)(i & 255),
((unsigned)red<<24)+((unsigned)green<<16)+((unsigned)blue<<8));
}
-/** See unsigned get_color(Fl_Color c) */
+/**
+ Returns the RGB value(s) for the given FLTK color index.
+
+ This form returns the red, green, and blue values
+ separately in referenced variables.
+
+ See also unsigned get_color(Fl_Color c)
+ */
void Fl::get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue) {
unsigned c;
@@ -465,5 +470,5 @@ Fl_Color fl_contrast(Fl_Color fg, Fl_Color bg) {
@}
*/
//
-// End of "$Id: fl_color.cxx 7617 2010-05-27 17:20:18Z manolo $".
+// End of "$Id: fl_color.cxx 7770 2010-10-29 22:14:59Z engelsman $".
//
diff --git a/src/fl_draw.cxx b/src/fl_draw.cxx
index 129a744..4885420 100644
--- a/src/fl_draw.cxx
+++ b/src/fl_draw.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: fl_draw.cxx 7502 2010-04-14 13:21:10Z manolo $"
+// "$Id: fl_draw.cxx 7782 2010-10-30 21:32:15Z matt $"
//
// Label drawing code for the Fast Light Tool Kit (FLTK).
//
@@ -193,7 +193,7 @@ void fl_draw(
char buf[MAXBUF];
int buflen;
char symbol[2][255], *symptr;
- int symwidth[2], symoffset, symtotal;
+ int symwidth[2], symoffset, symtotal, imgtotal;
// count how many lines and put the last one into the buffer:
int lines;
@@ -226,13 +226,14 @@ void fl_draw(
}
symtotal = symwidth[0] + symwidth[1];
+ imgtotal = (img && (align&FL_ALIGN_IMAGE_NEXT_TO_TEXT)) ? img->w() : 0;
int strw = 0;
int strh;
if (str) {
for (p = str, lines=0; p;) {
- e = fl_expand_text(p, buf, MAXBUF, w - symtotal, buflen, width,
+ e = fl_expand_text(p, buf, MAXBUF, w - symtotal - imgtotal, buflen, width,
align&FL_ALIGN_WRAP, draw_symbols);
if (strw<width) strw = (int)width;
lines++;
@@ -299,7 +300,7 @@ void fl_draw(
if (str) {
int desc = fl_descent();
for (p=str; ; ypos += height) {
- if (lines>1) e = fl_expand_text(p, buf, MAXBUF, w - symtotal, buflen,
+ if (lines>1) e = fl_expand_text(p, buf, MAXBUF, w - symtotal - imgtotal, buflen,
width, align&FL_ALIGN_WRAP, draw_symbols);
else e = "";
@@ -482,5 +483,5 @@ int fl_height(int font, int size) {
}
//
-// End of "$Id: fl_draw.cxx 7502 2010-04-14 13:21:10Z manolo $".
+// End of "$Id: fl_draw.cxx 7782 2010-10-30 21:32:15Z matt $".
//
diff --git a/src/fl_draw_pixmap.cxx b/src/fl_draw_pixmap.cxx
index c9debb5..25e1645 100644
--- a/src/fl_draw_pixmap.cxx
+++ b/src/fl_draw_pixmap.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: fl_draw_pixmap.cxx 7659 2010-07-01 13:21:32Z manolo $"
+// "$Id: fl_draw_pixmap.cxx 7765 2010-10-28 18:02:20Z matt $"
//
// Pixmap drawing code for the Fast Light Tool Kit (FLTK).
//
@@ -63,7 +63,7 @@ int fl_measure_pixmap(/*const*/ char* const* data, int &w, int &h) {
int fl_measure_pixmap(const char * const *cdata, int &w, int &h) {
int i = sscanf(cdata[0],"%d%d%d%d",&w,&h,&ncolors,&chars_per_pixel);
if (i<4 || w<=0 || h<=0 ||
- chars_per_pixel!=1 && chars_per_pixel!=2) return w=0;
+ (chars_per_pixel!=1 && chars_per_pixel!=2) ) return w=0;
return 1;
}
@@ -425,5 +425,5 @@ int fl_draw_pixmap(const char*const* cdata, int x, int y, Fl_Color bg) {
}
//
-// End of "$Id: fl_draw_pixmap.cxx 7659 2010-07-01 13:21:32Z manolo $".
+// End of "$Id: fl_draw_pixmap.cxx 7765 2010-10-28 18:02:20Z matt $".
//
diff --git a/src/fl_font_xft.cxx b/src/fl_font_xft.cxx
index 2b5d214..5d6af73 100644
--- a/src/fl_font_xft.cxx
+++ b/src/fl_font_xft.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: fl_font_xft.cxx 7652 2010-06-21 15:49:45Z manolo $"
+// "$Id: fl_font_xft.cxx 7773 2010-10-30 16:32:04Z matt $"
//
// Xft font code for the Fast Light Tool Kit (FLTK).
//
@@ -69,6 +69,7 @@
// The predefined fonts that FLTK has:
static Fl_Fontdesc built_in_table[] = {
+#if 1
{" sans"},
{"Bsans"},
{"Isans"},
@@ -84,7 +85,25 @@ static Fl_Fontdesc built_in_table[] = {
{" symbol"},
{" screen"},
{"Bscreen"},
-{" dingbats"},
+{" zapf dingbats"},
+#else
+{" helvetica"},
+{"Bhelvetica"},
+{"Ihelvetica"},
+{"Phelvetica"},
+{" courier"},
+{"Bcourier"},
+{"Icourier"},
+{"Pcourier"},
+{" times"},
+{"Btimes"},
+{"Itimes"},
+{"Ptimes"},
+{" symbol"},
+{" lucidatypewriter"},
+{"Blucidatypewriter"},
+{" zapf dingbats"},
+#endif
};
Fl_Fontdesc* fl_fonts = built_in_table;
@@ -587,7 +606,7 @@ static void fl_drawUCS4(const FcChar32 *str, int n, int x, int y) {
void Fl_Graphics_Driver::rtl_draw(const char* c, int n, int x, int y) {
#if defined(__GNUC__)
-#warning Need to improve this XFT right to left draw function
+// FIXME: warning Need to improve this XFT right to left draw function
#endif /*__GNUC__*/
// This actually draws LtoR, but aligned to R edge with the glyph order reversed...
@@ -624,5 +643,5 @@ void Fl_Graphics_Driver::rtl_draw(const char* c, int n, int x, int y) {
#endif
//
-// End of "$Id: fl_font_xft.cxx 7652 2010-06-21 15:49:45Z manolo $"
+// End of "$Id: fl_font_xft.cxx 7773 2010-10-30 16:32:04Z matt $"
//
diff --git a/src/fl_plastic.cxx b/src/fl_plastic.cxx
index d8d4c4b..dc66ec8 100644
--- a/src/fl_plastic.cxx
+++ b/src/fl_plastic.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: fl_plastic.cxx 6616 2009-01-01 21:28:26Z matt $"
+// "$Id: fl_plastic.cxx 7765 2010-10-28 18:02:20Z matt $"
//
// "Plastic" drawing routines for the Fast Light Tool Kit (FLTK).
//
@@ -87,13 +87,13 @@ static void frame_rect(int x, int y, int w, int h, const char *c, Fl_Color bc) {
{
// Draw lines around the perimeter of the button, 4 colors per
// circuit.
- fl_color(shade_color(g[*c++], bc));
+ fl_color(shade_color(g[(int)*c++], bc));
fl_line(x, y + h + b, x + w - 1, y + h + b, x + w + b - 1, y + h);
- fl_color(shade_color(g[*c++], bc));
+ fl_color(shade_color(g[(int)*c++], bc));
fl_line(x + w + b - 1, y + h, x + w + b - 1, y, x + w - 1, y - b);
- fl_color(shade_color(g[*c++], bc));
+ fl_color(shade_color(g[(int)*c++], bc));
fl_line(x + w - 1, y - b, x, y - b, x - b, y);
- fl_color(shade_color(g[*c++], bc));
+ fl_color(shade_color(g[(int)*c++], bc));
fl_line(x - b, y, x - b, y + h, x, y + h + b);
}
}
@@ -106,45 +106,45 @@ static void frame_round(int x, int y, int w, int h, const char *c, Fl_Color bc)
if (w==h) {
for (; b > 1; b --, x ++, y ++, w -= 2, h -= 2)
{
- fl_color(shade_color(g[*c++], bc));
+ fl_color(shade_color(g[(int)*c++], bc));
fl_arc(x, y, w, h, 45.0, 135.0);
- fl_color(shade_color(g[*c++], bc));
+ fl_color(shade_color(g[(int)*c++], bc));
fl_arc(x, y, w, h, 315.0, 405.0);
- fl_color(shade_color(g[*c++], bc));
+ fl_color(shade_color(g[(int)*c++], bc));
fl_arc(x, y, w, h, 225.0, 315.0);
- fl_color(shade_color(g[*c++], bc));
+ fl_color(shade_color(g[(int)*c++], bc));
fl_arc(x, y, w, h, 135.0, 225.0);
}
} else if (w>h) {
int d = h/2;
for (; b > 1; d--, b --, x ++, y ++, w -= 2, h -= 2)
{
- fl_color(shade_color(g[*c++], bc));
+ fl_color(shade_color(g[(int)*c++], bc));
fl_arc(x, y, h, h, 90.0, 135.0);
fl_xyline(x+d, y, x+w-d);
fl_arc(x+w-h, y, h, h, 45.0, 90.0);
- fl_color(shade_color(g[*c++], bc));
+ fl_color(shade_color(g[(int)*c++], bc));
fl_arc(x+w-h, y, h, h, 315.0, 405.0);
- fl_color(shade_color(g[*c++], bc));
+ fl_color(shade_color(g[(int)*c++], bc));
fl_arc(x+w-h, y, h, h, 270.0, 315.0);
fl_xyline(x+d, y+h-1, x+w-d);
fl_arc(x, y, h, h, 225.0, 270.0);
- fl_color(shade_color(g[*c++], bc));
+ fl_color(shade_color(g[(int)*c++], bc));
fl_arc(x, y, h, h, 135.0, 225.0);
}
} else if (w<h) {
int d = w/2;
for (; b > 1; d--, b --, x ++, y ++, w -= 2, h -= 2)
{
- fl_color(shade_color(g[*c++], bc));
+ fl_color(shade_color(g[(int)*c++], bc));
fl_arc(x, y, w, w, 45.0, 135.0);
- fl_color(shade_color(g[*c++], bc));
+ fl_color(shade_color(g[(int)*c++], bc));
fl_arc(x, y, w, w, 0.0, 45.0);
fl_yxline(x+w-1, y+d, y+h-d);
fl_arc(x, y+h-w, w, w, 315.0, 360.0);
- fl_color(shade_color(g[*c++], bc));
+ fl_color(shade_color(g[(int)*c++], bc));
fl_arc(x, y+h-w, w, w, 225.0, 315.0);
- fl_color(shade_color(g[*c++], bc));
+ fl_color(shade_color(g[(int)*c++], bc));
fl_arc(x, y+h-w, w, w, 180.0, 225.0);
fl_yxline(x, y+d, y+h-d);
fl_arc(x, y, w, w, 135.0, 180.0);
@@ -166,7 +166,7 @@ static void shade_rect(int x, int y, int w, int h, const char *c, Fl_Color bc) {
for (i = 0, j = 0; j < chalf; i ++, j += cstep) {
// Draw the top line and points...
- fl_color(shade_color(g[c[i]], bc));
+ fl_color(shade_color(g[(int)c[i]], bc));
fl_xyline(x + 1, y + i, x + w - 2);
fl_color(shade_color(g[c[i] - 2], bc));
@@ -174,7 +174,7 @@ static void shade_rect(int x, int y, int w, int h, const char *c, Fl_Color bc) {
fl_point(x + w - 1, y + i + 1);
// Draw the bottom line and points...
- fl_color(shade_color(g[c[clen - i]], bc));
+ fl_color(shade_color(g[(int)c[clen - i]], bc));
fl_xyline(x + 1, y + h - i, x + w - 2);
fl_color(shade_color(g[c[clen - i] - 2], bc));
@@ -185,7 +185,7 @@ static void shade_rect(int x, int y, int w, int h, const char *c, Fl_Color bc) {
// Draw the interior and sides...
i = chalf / cstep;
- fl_color(shade_color(g[c[chalf]], bc));
+ fl_color(shade_color(g[(int)c[chalf]], bc));
fl_rectf(x + 1, y + i, w - 2, h - 2 * i + 1);
fl_color(shade_color(g[c[chalf] - 2], bc));
@@ -197,7 +197,7 @@ static void shade_rect(int x, int y, int w, int h, const char *c, Fl_Color bc) {
for (i = 0, j = 0; j < chalf; i ++, j += cstep) {
// Draw the left line and points...
- fl_color(shade_color(g[c[i]], bc));
+ fl_color(shade_color(g[(int)c[i]], bc));
fl_yxline(x + i, y + 1, y + h - 1);
fl_color(shade_color(g[c[i] - 2], bc));
@@ -205,7 +205,7 @@ static void shade_rect(int x, int y, int w, int h, const char *c, Fl_Color bc) {
fl_point(x + i + 1, y + h);
// Draw the right line and points...
- fl_color(shade_color(g[c[clen - i]], bc));
+ fl_color(shade_color(g[(int)c[clen - i]], bc));
fl_yxline(x + w - 1 - i, y + 1, y + h - 1);
fl_color(shade_color(g[c[clen - i] - 2], bc));
@@ -216,7 +216,7 @@ static void shade_rect(int x, int y, int w, int h, const char *c, Fl_Color bc) {
// Draw the interior, top, and bottom...
i = chalf / cstep;
- fl_color(shade_color(g[c[chalf]], bc));
+ fl_color(shade_color(g[(int)c[chalf]], bc));
fl_rectf(x + i, y + 1, w - 2 * i, h - 1);
fl_color(shade_color(g[c[chalf] - 2], bc));
@@ -236,20 +236,20 @@ static void shade_round(int x, int y, int w, int h, const char *c, Fl_Color bc)
const int na = 8;
for (i=0; i<chalf; i++, d--, x++, y++, w-=2, h-=2)
{
- fl_color(shade_color(g[c[i]], bc));
+ fl_color(shade_color(g[(int)c[i]], bc));
fl_pie(x, y, h, h, 90.0, 135.0+i*na);
fl_xyline(x+d, y, x+w-d);
fl_pie(x+w-h, y, h, h, 45.0+i*na, 90.0);
- fl_color(shade_color(g[c[i] - 2], bc));
+ fl_color(shade_color(g[(int)c[i] - 2], bc));
fl_pie(x+w-h, y, h, h, 315.0+i*na, 405.0+i*na);
- fl_color(shade_color(g[c[clen - i]], bc));
+ fl_color(shade_color(g[(int)c[clen - i]], bc));
fl_pie(x+w-h, y, h, h, 270.0, 315.0+i*na);
fl_xyline(x+d, y+h-1, x+w-d);
fl_pie(x, y, h, h, 225.0+i*na, 270.0);
- fl_color(shade_color(g[c[clen - i] - 2], bc));
+ fl_color(shade_color(g[c[(int)clen - i] - 2], bc));
fl_pie(x, y, h, h, 135.0+i*na, 225.0+i*na);
}
- fl_color(shade_color(g[c[chalf]], bc));
+ fl_color(shade_color(g[(int)c[chalf]], bc));
fl_rectf(x+d, y, w-h+1, h+1);
fl_pie(x, y, h, h, 90.0, 270.0);
fl_pie(x+w-h, y, h, h, 270.0, 90.0);
@@ -258,20 +258,20 @@ static void shade_round(int x, int y, int w, int h, const char *c, Fl_Color bc)
const int na = 8;
for (i=0; i<chalf; i++, d--, x++, y++, w-=2, h-=2)
{
- fl_color(shade_color(g[c[i]], bc));
+ fl_color(shade_color(g[(int)c[i]], bc));
fl_pie(x, y, w, w, 45.0+i*na, 135.0+i*na);
fl_color(shade_color(g[c[i] - 2], bc));
fl_pie(x, y, w, w, 0.0, 45.0+i*na);
fl_yxline(x+w-1, y+d, y+h-d);
fl_pie(x, y+h-w, w, w, 315.0+i*na, 360.0);
- fl_color(shade_color(g[c[clen - i]], bc));
+ fl_color(shade_color(g[(int)c[clen - i]], bc));
fl_pie(x, y+h-w, w, w, 225.0+i*na, 315.0+i*na);
fl_color(shade_color(g[c[clen - i] - 2], bc));
fl_pie(x, y+h-w, w, w, 180.0, 225.0+i*na);
fl_yxline(x, y+d, y+h-d);
fl_pie(x, y, w, w, 135.0+i*na, 180.0);
}
- fl_color(shade_color(g[c[chalf]], bc));
+ fl_color(shade_color(g[(int)c[chalf]], bc));
fl_rectf(x, y+d, w+1, h-w+1);
fl_pie(x, y, w, w, 0.0, 180.0);
fl_pie(x, y+h-w, w, w, 180.0, 360.0);
@@ -377,5 +377,5 @@ Fl_Boxtype fl_define_FL_PLASTIC_UP_BOX() {
//
-// End of "$Id: fl_plastic.cxx 6616 2009-01-01 21:28:26Z matt $".
+// End of "$Id: fl_plastic.cxx 7765 2010-10-28 18:02:20Z matt $".
//
diff --git a/src/fl_rect.cxx b/src/fl_rect.cxx
index 3a9b470..e6ab1c0 100644
--- a/src/fl_rect.cxx
+++ b/src/fl_rect.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: fl_rect.cxx 7617 2010-05-27 17:20:18Z manolo $"
+// "$Id: fl_rect.cxx 7768 2010-10-28 23:08:06Z greg.ercolano $"
//
// Rectangle drawing routines for the Fast Light Tool Kit (FLTK).
//
@@ -597,10 +597,10 @@ int Fl_Graphics_Driver::clip_box(int x, int y, int w, int h, int& X, int& Y, int
else u = CGRectUnion(u, test);
}
}
- X = u.origin.x;
- Y = u.origin.y;
- W = u.size.width + 1;
- H = u.size.height + 1;
+ X = int(u.origin.x);
+ Y = int(u.origin.y);
+ W = int(u.size.width + 1);
+ H = int(u.size.height + 1);
if(CGRectIsEmpty(u)) W = H = 0;
return ! CGRectEqualToRect(arg, u);
#else
@@ -609,5 +609,5 @@ int Fl_Graphics_Driver::clip_box(int x, int y, int w, int h, int& X, int& Y, int
}
//
-// End of "$Id: fl_rect.cxx 7617 2010-05-27 17:20:18Z manolo $".
+// End of "$Id: fl_rect.cxx 7768 2010-10-28 23:08:06Z greg.ercolano $".
//
diff --git a/src/fl_set_fonts_xft.cxx b/src/fl_set_fonts_xft.cxx
index 65237d6..60aa1f0 100644
--- a/src/fl_set_fonts_xft.cxx
+++ b/src/fl_set_fonts_xft.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: fl_set_fonts_xft.cxx 6833 2009-07-23 22:51:56Z AlbrechtS $"
+// "$Id: fl_set_fonts_xft.cxx 7765 2010-10-28 18:02:20Z matt $"
//
// More font utilities for the Fast Light Tool Kit (FLTK).
//
@@ -116,7 +116,7 @@ static void make_raw_name(char *raw, char *pretty)
char *nm2 = strchr(pretty, ',');
if(nm2) *nm2 = 0; // terminate name after first entry
raw[0] = ' '; raw[1] = 0; // Default start of "raw name" text
- strncat(raw, pretty, LOCAL_RAW_NAME_MAX);
+ strncat(raw, pretty, LOCAL_RAW_NAME_MAX-1);
#endif
// At this point, the name is "marked" as regular...
if (style)
@@ -380,5 +380,5 @@ int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) {
}
//
-// End of "$Id: fl_set_fonts_xft.cxx 6833 2009-07-23 22:51:56Z AlbrechtS $".
+// End of "$Id: fl_set_fonts_xft.cxx 7765 2010-10-28 18:02:20Z matt $".
//
diff --git a/src/fl_utf8.cxx b/src/fl_utf8.cxx
index 8621c1f..473bbec 100644
--- a/src/fl_utf8.cxx
+++ b/src/fl_utf8.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: fl_utf8.cxx 6943 2009-11-18 12:43:21Z AlbrechtS $"
+// "$Id: fl_utf8.cxx 7788 2010-10-31 20:47:50Z matt $"
//
// Unicode to UTF-8 conversion functions.
//
@@ -60,7 +60,7 @@ extern "C" {
extern "C" {
int XUtf8Tolower(int ucs);
unsigned short XUtf8IsNonSpacing(unsigned int ucs);
-};
+}
#else // X-windows platform
@@ -823,5 +823,5 @@ void fl_make_path_for_file( const char *path )
/** @} */
//
-// End of "$Id: fl_utf8.cxx 6943 2009-11-18 12:43:21Z AlbrechtS $".
+// End of "$Id: fl_utf8.cxx 7788 2010-10-31 20:47:50Z matt $".
//
diff --git a/src/forms_compatability.cxx b/src/forms_compatability.cxx
index 9c3942c..4d08424 100644
--- a/src/forms_compatability.cxx
+++ b/src/forms_compatability.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: forms_compatability.cxx 7334 2010-03-25 14:37:46Z AlbrechtS $"
+// "$Id: forms_compatability.cxx 7767 2010-10-28 21:47:01Z matt $"
//
// Forms compatibility functions for the Fast Light Tool Kit (FLTK).
//
@@ -204,10 +204,10 @@ int fl_show_choice(
}
char *fl_show_simple_input(const char *str1, const char *defstr) {
- const char *r = fl_input(str1, defstr);
+ const char *r = fl_input("%s", defstr, str1);
return (char *)(r ? r : defstr);
}
//
-// End of "$Id: forms_compatability.cxx 7334 2010-03-25 14:37:46Z AlbrechtS $".
+// End of "$Id: forms_compatability.cxx 7767 2010-10-28 21:47:01Z matt $".
//
diff --git a/src/gl_draw.cxx b/src/gl_draw.cxx
index 06fa273..6abc97b 100644
--- a/src/gl_draw.cxx
+++ b/src/gl_draw.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: gl_draw.cxx 7500 2010-04-14 09:29:08Z manolo $"
+// "$Id: gl_draw.cxx 7767 2010-10-28 21:47:01Z matt $"
//
// OpenGL drawing support routines for the Fast Light Tool Kit (FLTK).
//
@@ -84,8 +84,8 @@ void gl_font(int fontid, int size) {
#else // Fltk-1.1.8 style GL font selection
#if defined (USE_X11) // X-windows options follow, either XFT or "plain" X
-# warning Ideally, for XFT, we really need a glXUseXftFont implementation here...
-# warning GL font selection is basically wrong here
+// FIXME: warning Ideally, for XFT, we really need a glXUseXftFont implementation here...
+// FIXME: warning GL font selection is basically wrong here
/* OksiD had a fairly sophisticated scheme for storing multiple X fonts in a XUtf8FontStruct,
* then sorting through them at draw time (for normal X rendering) to find which one can
* render the current glyph... But for now, just use the first font in the list for GL...
@@ -563,5 +563,5 @@ void gl_texture_pile_height(int max)
#endif // HAVE_GL
//
-// End of "$Id: gl_draw.cxx 7500 2010-04-14 09:29:08Z manolo $".
+// End of "$Id: gl_draw.cxx 7767 2010-10-28 21:47:01Z matt $".
//
diff --git a/src/print_panel.cxx b/src/print_panel.cxx
index d9d8781..ee2e424 100644
--- a/src/print_panel.cxx
+++ b/src/print_panel.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: print_panel.cxx 7480 2010-04-11 18:42:35Z AlbrechtS $"
+// "$Id: print_panel.cxx 7765 2010-10-28 18:02:20Z matt $"
//
// Print panel for the Fast Light Tool Kit (FLTK).
//
@@ -574,7 +574,7 @@ void print_update_status() {
if (print_choice->value()) {
snprintf(command, sizeof(command), "lpstat -p '%s'", printer);
if ((lpstat = popen(command, "r")) != NULL) {
- fgets(status, sizeof(status), lpstat);
+ if (fgets(status, sizeof(status), lpstat)==0) { /* ignore */ }
pclose(lpstat);
} else strcpy(status, "printer status unavailable");
} else status[0] = '\0';
@@ -594,5 +594,5 @@ void print_update_status() {
}
//
-// End of "$Id: print_panel.cxx 7480 2010-04-11 18:42:35Z AlbrechtS $".
+// End of "$Id: print_panel.cxx 7765 2010-10-28 18:02:20Z matt $".
//
diff --git a/src/ps_image.cxx b/src/ps_image.cxx
index eb1c878..b186d3e 100644
--- a/src/ps_image.cxx
+++ b/src/ps_image.cxx
@@ -260,7 +260,7 @@ void Fl_PostScript_Graphics_Driver::draw_scaled_image(const uchar *data, double
fprintf(output," >\nrestore\n" );
-};
+}
void Fl_PostScript_Graphics_Driver::draw_scaled_image(Fl_Draw_Image_Cb call, void *data, double x, double y, double w, double h, int iw, int ih, int D) {
@@ -405,7 +405,7 @@ void Fl_PostScript_Graphics_Driver::draw_scaled_image_mono(const uchar *data, do
fprintf(output," >\nrestore\n" );
-};
+}
@@ -472,7 +472,7 @@ void Fl_PostScript_Graphics_Driver::draw(Fl_Pixmap * pxm,int XP, int YP, int WP,
delete[] mask;
mask=0;
fl_mask_bitmap=0;
-};
+}
void Fl_PostScript_Graphics_Driver::draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy){
const uchar * di = rgb->array;
@@ -486,7 +486,7 @@ void Fl_PostScript_Graphics_Driver::draw(Fl_RGB_Image * rgb,int XP, int YP, int
pop_clip();
delete[]mask;
mask=0;
-};
+}
void Fl_PostScript_Graphics_Driver::draw(Fl_Bitmap * bitmap,int XP, int YP, int WP, int HP, int cx, int cy){
const uchar * di = bitmap->array;
@@ -523,7 +523,7 @@ void Fl_PostScript_Graphics_Driver::draw(Fl_Bitmap * bitmap,int XP, int YP, int
}
fprintf(output,">\n");
pop_clip();
-};
+}
#endif // FL_DOXYGEN