diff -ur fltk-1.1.7/FL/Fl_Browser_.H fltk-1.1.7.new/FL/Fl_Browser_.H --- fltk-1.1.7/FL/Fl_Browser_.H 2005-04-16 02:13:17.000000000 +0200 +++ fltk-1.1.7.new/FL/Fl_Browser_.H 2007-12-18 14:13:41.000000000 +0100 @@ -88,6 +88,7 @@ void new_list(); // completely clobber all data, as though list replaced void deleting(void *a); // get rid of any pointers to a void replacing(void *a,void *b); // change a pointers to b + void swapping(void *a,void *b); // exchange pointers a and b void inserting(void *a,void *b); // insert b near a int displayed(void *) const ; // true if this line is visible void redraw_line(void *); // minimal update, no change in size diff -ur fltk-1.1.7/FL/Fl_File_Chooser.H fltk-1.1.7.new/FL/Fl_File_Chooser.H --- fltk-1.1.7/FL/Fl_File_Chooser.H 2005-08-08 02:50:02.000000000 +0200 +++ fltk-1.1.7.new/FL/Fl_File_Chooser.H 2007-12-18 14:13:41.000000000 +0100 @@ -145,6 +145,7 @@ void preview(int e); int preview() const { return previewButton->value(); }; void rescan(); + void rescan_keep_filename(); void show(); int shown(); void textcolor(Fl_Color c); diff -ur fltk-1.1.7/FL/x.H fltk-1.1.7.new/FL/x.H --- fltk-1.1.7/FL/x.H 2005-04-16 02:13:17.000000000 +0200 +++ fltk-1.1.7.new/FL/x.H 2007-12-18 14:25:47.000000000 +0100 @@ -65,10 +65,34 @@ extern FL_EXPORT XVisualInfo *fl_visual; extern FL_EXPORT Colormap fl_colormap; +#if USE_XFT +// access to core fonts +FL_EXPORT XFontStruct* fl_xxfont(); +class Fl_XFont_On_Demand +{ +public: + Fl_XFont_On_Demand(XFontStruct* p = NULL) : ptr(p) { } + Fl_XFont_On_Demand& operator=(const Fl_XFont_On_Demand& x) + { ptr = x.ptr; return *this; } + Fl_XFont_On_Demand& operator=(XFontStruct* p) + { ptr = p; return *this; } + XFontStruct* value() { if (!ptr) { ptr = fl_xxfont(); } return ptr; } + operator XFontStruct*() { return value(); } + XFontStruct& operator*() { return *value(); } + XFontStruct* operator->() { return value(); } + bool operator==(const Fl_XFont_On_Demand& x) { return ptr == x.ptr; } + bool operator!=(const Fl_XFont_On_Demand& x) { return ptr != x.ptr; } +private: + XFontStruct* ptr; +}; +extern FL_EXPORT Fl_XFont_On_Demand fl_xfont; +#else +extern FL_EXPORT XFontStruct* fl_xfont; +#endif + // drawing functions: extern FL_EXPORT GC fl_gc; extern FL_EXPORT Window fl_window; -extern FL_EXPORT XFontStruct* fl_xfont; FL_EXPORT ulong fl_xpixel(Fl_Color i); FL_EXPORT ulong fl_xpixel(uchar r, uchar g, uchar b); FL_EXPORT void fl_clip_region(Fl_Region); diff -ur fltk-1.1.7/src/Fl_Browser_.cxx fltk-1.1.7.new/src/Fl_Browser_.cxx --- fltk-1.1.7/src/Fl_Browser_.cxx 2005-12-31 19:26:01.000000000 +0100 +++ fltk-1.1.7.new/src/Fl_Browser_.cxx 2007-12-18 14:13:41.000000000 +0100 @@ -470,6 +470,15 @@ if (a == max_width_item) {max_width_item = 0; max_width = 0;} } +void Fl_Browser_::swapping(void* a, void* b) { + redraw_line(a); + redraw_line(b); + if (a == selection_) selection_ = b; + else if (b == selection_) selection_ = a; + if (a == top_) top_ = b; + else if (b == top_) top_ = a; +} + void Fl_Browser_::inserting(void* a, void* b) { if (displayed(a)) redraw_lines(); if (a == top_) top_ = b; diff -ur fltk-1.1.7/src/Fl_Browser.cxx fltk-1.1.7.new/src/Fl_Browser.cxx --- fltk-1.1.7/src/Fl_Browser.cxx 2005-04-16 02:13:17.000000000 +0200 +++ fltk-1.1.7.new/src/Fl_Browser.cxx 2007-12-18 14:13:41.000000000 +0100 @@ -503,6 +503,7 @@ void Fl_Browser::swap(FL_BLINE *a, FL_BLINE *b) { if ( a == b || !a || !b) return; // nothing to do + swapping(a, b); FL_BLINE *aprev = a->prev; FL_BLINE *anext = a->next; FL_BLINE *bprev = b->prev; @@ -535,8 +536,6 @@ } // Disable cache -- we played around with positions cacheline = 0; - // Redraw modified lines - redraw_lines(); } void Fl_Browser::swap(int ai, int bi) { diff -ur fltk-1.1.7/src/Fl_File_Browser.cxx fltk-1.1.7.new/src/Fl_File_Browser.cxx --- fltk-1.1.7/src/Fl_File_Browser.cxx 2005-08-18 16:08:17.000000000 +0200 +++ fltk-1.1.7.new/src/Fl_File_Browser.cxx 2007-12-18 14:13:41.000000000 +0100 @@ -467,7 +467,7 @@ { sprintf(filename, "%c:/", i); - if (i < 'C') + if (i < 'C') // see also: GetDriveType and GetVolumeInformation in WIN32 add(filename, icon); else add(filename, icon); diff -ur fltk-1.1.7/src/Fl_File_Chooser2.cxx fltk-1.1.7.new/src/Fl_File_Chooser2.cxx --- fltk-1.1.7/src/Fl_File_Chooser2.cxx 2005-11-27 15:45:48.000000000 +0100 +++ fltk-1.1.7.new/src/Fl_File_Chooser2.cxx 2007-12-18 14:13:41.000000000 +0100 @@ -854,6 +854,57 @@ update_preview(); } +// +// 'Fl_File_Chooser::rescan_keep_filename()' - Rescan the current directory +// without clearing the filename, then select the file if it is in the list +// + +void +Fl_File_Chooser::rescan_keep_filename() +{ + // if no filename was set, this is likely a diretory browser + const char *fn = fileName->value(); + if (!fn || !*fn || fn[strlen(fn) - 1]=='/') { + rescan(); + return; + } + + int i; + char pathname[1024]; // New pathname for filename field + strlcpy(pathname, fn, sizeof(pathname)); + + // Build the file list... + fileList->load(directory_, sort); + + // Update the preview box... + update_preview(); + + // and select the chosen file + char found = 0; + char *slash = strrchr(pathname, '/'); + if (slash) + slash++; + else + slash = pathname; + for (i = 1; i <= fileList->size(); i ++) +#if defined(WIN32) || defined(__EMX__) + if (strcasecmp(fileList->text(i), slash) == 0) { +#else + if (strcmp(fileList->text(i), slash) == 0) { +#endif // WIN32 || __EMX__ + fileList->topline(i); + fileList->select(i); + found = 1; + break; + } + + // update OK button activity + if (found || type_ & CREATE) + okButton->activate(); + else + okButton->deactivate(); +} + // // 'Fl_File_Chooser::showChoiceCB()' - Handle show selections. @@ -889,7 +940,7 @@ if (shown()) { // Rescan the directory... - rescan(); + rescan_keep_filename(); } } diff -ur fltk-1.1.7/src/Fl_File_Chooser.cxx fltk-1.1.7.new/src/Fl_File_Chooser.cxx --- fltk-1.1.7/src/Fl_File_Chooser.cxx 2005-12-30 11:13:17.000000000 +0100 +++ fltk-1.1.7.new/src/Fl_File_Chooser.cxx 2007-12-18 14:13:41.000000000 +0100 @@ -375,7 +375,7 @@ window->show(); Fl::flush(); fl_cursor(FL_CURSOR_WAIT); -rescan(); +rescan_keep_filename(); fl_cursor(FL_CURSOR_DEFAULT); fileName->take_focus(); } diff -ur fltk-1.1.7/src/Fl_File_Chooser.fl fltk-1.1.7.new/src/Fl_File_Chooser.fl --- fltk-1.1.7/src/Fl_File_Chooser.fl 2005-12-30 11:13:17.000000000 +0100 +++ fltk-1.1.7.new/src/Fl_File_Chooser.fl 2007-12-18 14:13:41.000000000 +0100 @@ -61,7 +61,7 @@ fileList->deselect(); Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this); window->hide();} - private xywh {387 242 490 380} type Double resizable + private xywh {368 285 490 380} type Double resizable code0 {if (title) window->label(title);} code1 {\#include } code2 {\#include } @@ -138,7 +138,7 @@ if (callback_) (*callback_)(this, data_); -window->hide();} selected +window->hide();} private xywh {313 345 85 25} code0 {\#include } code1 {okButton->label(fl_ok);} @@ -160,7 +160,7 @@ } Fl_Window favWindow { label {Manage Favorites} - private xywh {437 187 355 150} type Double resizable + private xywh {421 56 355 150} type Double resizable code0 {favWindow->label(manage_favorites_label);} modal size_range {181 150 0 0} visible } { Fl_File_Browser favList { @@ -299,15 +299,18 @@ } decl {void rescan();} {public } - Function {show()} {return_type void + decl {void rescan_keep_filename();} {public + } + Function {show()} {open return_type void } { code {window->hotspot(fileList); window->show(); Fl::flush(); fl_cursor(FL_CURSOR_WAIT); -rescan(); +rescan_keep_filename(); fl_cursor(FL_CURSOR_DEFAULT); -fileName->take_focus();} {} +fileName->take_focus();} {selected + } } Function {shown()} {return_type int } { diff -ur fltk-1.1.7/src/Fl_Font.H fltk-1.1.7.new/src/Fl_Font.H --- fltk-1.1.7/src/Fl_Font.H 2005-04-16 02:13:17.000000000 +0200 +++ fltk-1.1.7.new/src/Fl_Font.H 2007-12-18 14:13:41.000000000 +0100 @@ -40,9 +40,9 @@ #include -# if USE_XFT +# if USE_XFT && !SUPPRESS_XFT typedef struct _XftFont XftFont; -# endif // USE_XFT +# endif // USE_XFT && !SUPPRESS_XFT class Fl_FontSize { public: @@ -63,7 +63,7 @@ char *q_name; int size; short ascent, descent, q_width; -# elif USE_XFT +# elif USE_XFT && !SUPPRESS_XFT XftFont* font; const char* encoding; int size; diff -ur fltk-1.1.7/src/fl_font_xft.cxx fltk-1.1.7.new/src/fl_font_xft.cxx --- fltk-1.1.7/src/fl_font_xft.cxx 2005-04-16 02:13:17.000000000 +0200 +++ fltk-1.1.7.new/src/fl_font_xft.cxx 2007-12-18 14:29:56.000000000 +0100 @@ -62,6 +62,52 @@ // are several web pages of information on how to do this. // +// kludge to pull in the Xlib code as a fallback +#define Fl_FontSize Fl_Fontsize_xlib +#define fl_fontsize fl_fontsize_xlib +#define Fl_Fontdesc Fl_Fontdesc_xlib +#define fl_fonts fl_fonts_xlib +#define built_in_table built_in_table_xlib +#define fl_font_word fl_font_word_xlib +#define fl_find_fontsize fl_find_fontsize_xlib +#define fl_encoding fl_encoding_xlib +#define fl_correct_encoding fl_correct_encoding_xlib +#define find find_xlib +#define fl_font_ fl_font__xlib +#define fl_size_ fl_size__xlib +#define fl_xfont fl_xfont_xlib +#define font_gc font_gc_xlib +#define fl_font fl_font_xlib +#define fl_height fl_height_xlib +#define fl_descent fl_descent_xlib +#define fl_width fl_width_xlib +#define fl_draw fl_draw_xlib +#define SUPPRESS_XFT 1 +#undef FL_FONT_ +#include "Fl_Font.H" +#include "fl_font_x.cxx" +#undef SUPPRESS_XFT +#undef Fl_FontSize +#undef fl_fontsize +#undef Fl_Fontdesc +#undef fl_fonts +#undef built_in_table +#undef fl_font_word +#undef fl_find_fontsize +#undef fl_encoding +#undef fl_correct_encoding +#undef find +#undef fl_font_ +#undef fl_size_ +#undef fl_xfont +#undef font_gc +#undef fl_font +#undef fl_height +#undef fl_descent +#undef fl_width +#undef fl_draw + + #include // The predefined fonts that FLTK has: @@ -90,7 +136,12 @@ int fl_font_ = 0; int fl_size_ = 0; +#if USE_XFT +Fl_XFont_On_Demand fl_xfont; +XFontStruct* fl_xxfont(); +#else XFontStruct* fl_xfont = 0; +#endif const char* fl_encoding_ = "iso8859-1"; Fl_FontSize* fl_fontsize = 0; @@ -112,7 +163,9 @@ font->first = f; } fl_fontsize = f; -#if XFT_MAJOR < 2 +#if defined(XFT_MAJOR) && XFT_MAJOR >= 2 + fl_xfont = fl_xxfont(); +#else fl_xfont = f->font->u.core.font; #endif // XFT_MAJOR < 2 } @@ -176,7 +229,6 @@ return fl_width((const char *)(&c), 1); } -#if HAVE_GL // This call is used by opengl to get a bitmapped font. XFontStruct* fl_xxfont() { # if XFT_MAJOR > 1 @@ -192,7 +244,6 @@ return xftfont->u.core.font; # endif // XFT_MAJOR > 1 } -#endif // HAVE_GL #if USE_OVERLAY // Currently Xft does not work with colormapped visuals, so this probably @@ -223,6 +274,15 @@ } void fl_draw(const char *str, int n, int x, int y) { + if ( !current_font ) { + int saved_font = fl_font_, saved_size = fl_size_; + fl_font(FL_HELVETICA, 14); + if ( !current_font ) { + fl_font_xlib(saved_font, saved_size ? saved_size : fl_size_); + fl_draw_xlib(str, n, x, y); + return; + } + } #if USE_OVERLAY XftDraw*& draw = fl_overlay ? draw_overlay : ::draw; if (fl_overlay) { diff -ur fltk-1.1.7/src/Fl_mac.cxx fltk-1.1.7.new/src/Fl_mac.cxx --- fltk-1.1.7/src/Fl_mac.cxx 2006-01-15 03:26:54.000000000 +0100 +++ fltk-1.1.7.new/src/Fl_mac.cxx 2007-12-18 14:13:41.000000000 +0100 @@ -121,7 +121,7 @@ static unsigned short macKeyLookUp[128] = { 'a', 's', 'd', 'f', 'h', 'g', 'z', 'x', - 'c', 'v', 0/*ISO extra ('#' on German keyboard)*/, 'b', 'q', 'w', 'e', 'r', + 'c', 'v', '^', 'b', 'q', 'w', 'e', 'r', 'y', 't', '1', '2', '3', '4', '6', '5', '=', '9', '7', '-', '8', '0', ']', 'o', @@ -2159,14 +2159,15 @@ Size len = 0; if (GetCurrentScrap(&scrap) == noErr && scrap != myScrap && GetScrapFlavorSize(scrap, kScrapFlavorTypeText, &len) == noErr) { - if ( len > fl_selection_buffer_length[1] ) { + if ( len >= fl_selection_buffer_length[1] ) { fl_selection_buffer_length[1] = len + 32; delete[] fl_selection_buffer[1]; - fl_selection_buffer[1] = new char[len]; + fl_selection_buffer[1] = new char[len + 32]; } + fl_selection_length[1] = len; len++; GetScrapFlavorData( scrap, kScrapFlavorTypeText, &len, fl_selection_buffer[1] ); - fl_selection_length[1] = len; + fl_selection_buffer[1][fl_selection_length[1]] = 0; // turn all \r characters into \n: for (int x = 0; x < len; x++) { if (fl_selection_buffer[1][x] == '\r') diff -ur fltk-1.1.7/src/Fl_Menu.cxx fltk-1.1.7.new/src/Fl_Menu.cxx --- fltk-1.1.7/src/Fl_Menu.cxx 2006-01-17 22:04:55.000000000 +0100 +++ fltk-1.1.7.new/src/Fl_Menu.cxx 2007-12-18 14:13:41.000000000 +0100 @@ -107,6 +107,7 @@ int titlex(int); void autoscroll(int); void position(int x, int y); + int is_inside(int x, int y); }; #define LEADING 4 // extra vertical leading @@ -458,6 +459,15 @@ return xx; } +// return 1, if the given root coordinates are inside the window +int menuwindow::is_inside(int mx, int my) { + if ( mx < x_root() || mx >= x_root() + w() || + my < y_root() || my >= y_root() + h()) { + return 0; + } + return 1; +} + //////////////////////////////////////////////////////////////// // Fl_Menu_Item::popup(...) @@ -488,9 +498,20 @@ int nummenus; int menubar; // if true p[0] is a menubar int state; + int is_inside(int mx, int my); }; static menustate* p; +// return 1 if the coordinates are inside any of the menuwindows +int menustate::is_inside(int mx, int my) { + int i; + for (i=nummenus-1; i>=0; i--) { + if (p[i]->is_inside(mx, my)) + return 1; + } + return 0; +} + static inline void setitem(const Fl_Menu_Item* i, int m, int n) { p->current_item = i; p->menu_number = m; @@ -595,14 +616,11 @@ int mx = Fl::event_x_root(); int my = Fl::event_y_root(); int item=0; int mymenu = pp.nummenus-1; - if (e == FL_PUSH && (!pp.menubar || mymenu) && - (mx < pp.p[mymenu]->x_root() || - mx >= (pp.p[mymenu]->x_root() + pp.p[mymenu]->w()) || - my < pp.p[mymenu]->y_root() || - my >= (pp.p[mymenu]->y_root() + pp.p[mymenu]->h()))) { - // Clicking outside menu cancels it... + // Clicking or dragging outside menu cancels it... + if ((!pp.menubar || mymenu) && !pp.is_inside(mx, my)) { setitem(0, -1, 0); - pp.state = DONE_STATE; + if (e==FL_PUSH) + pp.state = DONE_STATE; return 1; } for (mymenu = pp.nummenus-1; ; mymenu--) { diff -ur fltk-1.1.7/src/fl_scroll_area.cxx fltk-1.1.7.new/src/fl_scroll_area.cxx --- fltk-1.1.7/src/fl_scroll_area.cxx 2005-04-16 02:13:17.000000000 +0200 +++ fltk-1.1.7.new/src/fl_scroll_area.cxx 2007-12-18 14:13:41.000000000 +0100 @@ -32,6 +32,7 @@ #include #include #include +#include // scroll a rectangle and redraw the newly exposed portions: void fl_scroll(int X, int Y, int W, int H, int dx, int dy, diff -ur fltk-1.1.7/src/Fl_Shared_Image.cxx fltk-1.1.7.new/src/Fl_Shared_Image.cxx --- fltk-1.1.7/src/Fl_Shared_Image.cxx 2005-04-16 02:13:17.000000000 +0200 +++ fltk-1.1.7.new/src/Fl_Shared_Image.cxx 2007-12-18 14:13:41.000000000 +0100 @@ -227,7 +227,7 @@ fread(header, 1, sizeof(header), fp); fclose(fp); } else { - memset(header, 0, sizeof(header)); + return; } // Load the image as appropriate... diff -ur fltk-1.1.7/src/Fl_Window.cxx fltk-1.1.7.new/src/Fl_Window.cxx --- fltk-1.1.7/src/Fl_Window.cxx 2005-12-14 14:51:51.000000000 +0100 +++ fltk-1.1.7.new/src/Fl_Window.cxx 2007-12-18 14:13:41.000000000 +0100 @@ -36,7 +36,7 @@ #include "flstring.h" #ifdef __APPLE_QUARTZ__ -#include +#include #endif void Fl_Window::_Fl_Window() { diff -ur fltk-1.1.7/test/preferences.fl fltk-1.1.7.new/test/preferences.fl --- fltk-1.1.7/test/preferences.fl 2005-04-08 20:18:26.000000000 +0200 +++ fltk-1.1.7.new/test/preferences.fl 2007-12-18 14:13:41.000000000 +0100 @@ -69,7 +69,7 @@ } } Fl_Choice wWear { - label {Wear:} open + label {Wear:} open selected xywh {25 100 105 20} down_box BORDER_BOX align 5 } { MenuItem {} { @@ -93,15 +93,15 @@ xywh {35 120 98 60} } { Fl_Round_Button wLeft { - label {left side} selected + label {left side} xywh {35 120 95 25} type Radio down_box ROUND_DOWN_BOX } Fl_Round_Button wRight { - label {right side} selected + label {right side} xywh {35 140 95 25} type Radio down_box ROUND_DOWN_BOX } Fl_Box {} { - label {of the bed} selected + label {of the bed} xywh {38 160 95 20} } } diff -ur fltk-1.1.7/test/sudoku.cxx fltk-1.1.7.new/test/sudoku.cxx --- fltk-1.1.7/test/sudoku.cxx 2006-01-13 23:46:30.000000000 +0100 +++ fltk-1.1.7.new/test/sudoku.cxx 2007-12-18 14:13:41.000000000 +0100 @@ -547,7 +547,7 @@ break; case FL_PUSH : - if (Fl::event_inside(this)) { + if (!readonly() && Fl::event_inside(this)) { if (Fl::event_clicks()) { // 2+ clicks increments/sets value if (value()) {