diff options
| author | Michael R Sweet <michael.r.sweet@gmail.com> | 1998-11-05 16:04:53 +0000 |
|---|---|---|
| committer | Michael R Sweet <michael.r.sweet@gmail.com> | 1998-11-05 16:04:53 +0000 |
| commit | 80b1529ef4d69d9e34a48a419a018d7f4d64054b (patch) | |
| tree | 7c743dc2f7f17654f1535314f6b0e6c5eadfc21b /src | |
| parent | 60399e3945dcfe9a2bb9f00f794d9e8634dd6bd9 (diff) | |
Multiple patches from Bill:
- Double-buffered window fixes.
- Tabs fixes.
- X/WIN32 fixes.
- Fl_Input fixes.
- Support for vsnprintf and friends.
- Support for printf-style arguments in utility functions.
git-svn-id: file:///fltk/svn/fltk/trunk@52 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_Double_Window.cxx | 72 | ||||
| -rw-r--r-- | src/Fl_Input_.cxx | 6 | ||||
| -rw-r--r-- | src/Fl_Overlay_Window.cxx | 25 | ||||
| -rw-r--r-- | src/Fl_Tabs.cxx | 12 | ||||
| -rw-r--r-- | src/Fl_Window_hotspot.cxx | 31 | ||||
| -rw-r--r-- | src/Fl_abort.cxx | 11 | ||||
| -rw-r--r-- | src/Fl_win32.cxx | 123 | ||||
| -rw-r--r-- | src/Makefile | 6 | ||||
| -rw-r--r-- | src/fl_ask.cxx | 123 | ||||
| -rwxr-xr-x | src/forms_compatability.cxx | 32 |
10 files changed, 279 insertions, 162 deletions
diff --git a/src/Fl_Double_Window.cxx b/src/Fl_Double_Window.cxx index f9d3ce9f4..38e5a71e7 100644 --- a/src/Fl_Double_Window.cxx +++ b/src/Fl_Double_Window.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Double_Window.cxx,v 1.8 1998/10/21 14:20:02 mike Exp $" +// "$Id: Fl_Double_Window.cxx,v 1.9 1998/11/05 16:04:45 mike Exp $" // // Double-buffered window code for the Fast Light Tool Kit (FLTK). // @@ -56,9 +56,6 @@ static int can_xdbe() { } return use_xdbe; } -#define DAMAGE_TEST() (damage() && (use_xdbe || damage() != FL_DAMAGE_EXPOSE)) -#else -#define DAMAGE_TEST() (damage() & ~FL_DAMAGE_EXPOSE) #endif void Fl_Double_Window::show() { @@ -99,57 +96,66 @@ extern void fl_restore_clip(); #endif -// Fl_Overlay_Window relies on flush() copying the back buffer to the -// front even if damage() == 0, thus erasing the overlay inside the region: +// Fl_Overlay_Window relies on flush(1) copying the back buffer to the +// front everywhere, even if damage() == 0, thus erasing the overlay, +// and leaving the clip region set to the entire window. -void Fl_Double_Window::flush() { +void Fl_Double_Window::flush() {flush(0);} + +void Fl_Double_Window::flush(int eraseoverlay) { make_current(); // make sure fl_gc is non-zero Fl_X *i = Fl_X::i(this); if (!i->other_xid) { #if USE_XDBE if (can_xdbe()) i->other_xid = - XdbeAllocateBackBufferName(fl_display, fl_xid(this), XdbeCopied); + XdbeAllocateBackBufferName(fl_display, fl_xid(this), XdbeUndefined); else #endif i->other_xid = fl_create_offscreen(w(), h()); clear_damage(FL_DAMAGE_ALL); } +#if USE_XDBE + if (use_xdbe) { + // if this is true, copy rather than swap so back buffer is preserved: + int copy = (i->region || eraseoverlay); + if (i->backbuffer_bad) { // make sure we do a complete redraw... + if (i->region) {XDestroyRegion(i->region); i->region = 0;} + clear_damage(FL_DAMAGE_ALL); + } + if (damage()) { + fl_clip_region(i->region); i->region = 0; + fl_window = i->other_xid; + draw(); + fl_window = i->xid; + } + if (!copy) { + XdbeSwapInfo s; + s.swap_window = fl_xid(this); + s.swap_action = XdbeUndefined; + XdbeSwapBuffers(fl_display, &s, 1); + i->backbuffer_bad = 1; + return; + } + // otherwise just use normal copy from back to front: + i->backbuffer_bad = 0; // which won't destroy the back buffer... + } else +#endif + if (damage() & ~FL_DAMAGE_EXPOSE) { + fl_clip_region(i->region); i->region = 0; #ifdef WIN32 - fl_clip_region(i->region); i->region = 0; - if (DAMAGE_TEST()) { HDC _sgc = fl_gc; fl_gc = fl_makeDC(i->other_xid); fl_restore_clip(); // duplicate region into new gc draw(); DeleteDC(fl_gc); fl_gc = _sgc; - } #else // X: -#if USE_XDBE - int clipped = i->region != 0; -#endif - fl_clip_region(i->region); i->region = 0; - if (DAMAGE_TEST()) { fl_window = i->other_xid; draw(); fl_window = i->xid; - } -#if USE_XDBE - // It appears that swapbuffers ignores the clip region (it has to - // as the gc is not passed as an argument to it). This causes it - // to erase parts of the overlay that won't be redrawn, and (at least - // on XFree86) it is slower. So I don't use it unless the entire - // window is being redrawn. Sigh. - if (use_xdbe && !clipped) { - XdbeSwapInfo s; - s.swap_window = fl_xid(this); - s.swap_action = XdbeCopied; - XdbeSwapBuffers(fl_display, &s, 1); - // fl_clip_region(0); older fix for clipping problem but overlay blinked - return; - } -#endif #endif + } + if (eraseoverlay) fl_clip_region(0); // on Irix (at least) it is faster to reduce the area copied to // the current clip region: int X,Y,W,H; fl_clip_box(0,0,w(),h(),X,Y,W,H); @@ -186,5 +192,5 @@ Fl_Double_Window::~Fl_Double_Window() { } // -// End of "$Id: Fl_Double_Window.cxx,v 1.8 1998/10/21 14:20:02 mike Exp $". +// End of "$Id: Fl_Double_Window.cxx,v 1.9 1998/11/05 16:04:45 mike Exp $". // diff --git a/src/Fl_Input_.cxx b/src/Fl_Input_.cxx index 2cd0c2fa8..da1594106 100644 --- a/src/Fl_Input_.cxx +++ b/src/Fl_Input_.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Input_.cxx,v 1.4 1998/10/21 14:20:09 mike Exp $" +// "$Id: Fl_Input_.cxx,v 1.5 1998/11/05 16:04:46 mike Exp $" // // Common input widget routines for the Fast Light Tool Kit (FLTK). // @@ -544,7 +544,7 @@ int Fl_Input_::undo() { if (xlen) { undobuffersize(xlen); memcpy(undobuffer, buffer+b, xlen); - memmove(buffer+b, buffer+b+xlen, size_-xlen-b); + memmove(buffer+b, buffer+b+xlen, size_-xlen-b+1); size_ -= xlen; } @@ -725,5 +725,5 @@ Fl_Input_::~Fl_Input_() { } // -// End of "$Id: Fl_Input_.cxx,v 1.4 1998/10/21 14:20:09 mike Exp $". +// End of "$Id: Fl_Input_.cxx,v 1.5 1998/11/05 16:04:46 mike Exp $". // diff --git a/src/Fl_Overlay_Window.cxx b/src/Fl_Overlay_Window.cxx index 6b29b1c81..b25db96c5 100644 --- a/src/Fl_Overlay_Window.cxx +++ b/src/Fl_Overlay_Window.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Overlay_Window.cxx,v 1.5 1998/10/21 14:20:15 mike Exp $" +// "$Id: Fl_Overlay_Window.cxx,v 1.6 1998/11/05 16:04:47 mike Exp $" // // Overlay window code for the Fast Light Tool Kit (FLTK). // @@ -43,13 +43,9 @@ void Fl_Overlay_Window::hide() { } void Fl_Overlay_Window::flush() { - // turn off the bit set by redraw_overlay: + int erase_overlay = (damage()&FL_DAMAGE_OVERLAY); clear_damage(damage()&~FL_DAMAGE_OVERLAY); - // even if damage() == 0, flush() will erase the fake overlay by - // copying back buffer over it. It will also set the clip to the - // region made by all the expose events: - Fl_Double_Window::flush(); - // Now draw the fake overlay, if any, using the current clip: + Fl_Double_Window::flush(erase_overlay); if (overlay_ == this) draw_overlay(); } @@ -67,7 +63,11 @@ Fl_Overlay_Window::~Fl_Overlay_Window() { int Fl_Overlay_Window::can_do_overlay() {return 0;} -void Fl_Overlay_Window::redraw_overlay() {overlay_ = this; damage(FL_DAMAGE_OVERLAY);} +void Fl_Overlay_Window::redraw_overlay() { + overlay_ = this; + clear_damage(damage()|FL_DAMAGE_OVERLAY); + Fl::damage(FL_DAMAGE_CHILD); +} #else @@ -127,9 +127,10 @@ void Fl_Overlay_Window::redraw_overlay() { } } if (shown()) { - if (overlay_ == this) - damage(FL_DAMAGE_OVERLAY); - else if (!overlay_->shown()) + if (overlay_ == this) { + clear_damage(damage()|FL_DAMAGE_OVERLAY); + Fl::damage(FL_DAMAGE_CHILD); + } else if (!overlay_->shown()) overlay_->show(); else overlay_->redraw(); @@ -139,5 +140,5 @@ void Fl_Overlay_Window::redraw_overlay() { #endif // -// End of "$Id: Fl_Overlay_Window.cxx,v 1.5 1998/10/21 14:20:15 mike Exp $". +// End of "$Id: Fl_Overlay_Window.cxx,v 1.6 1998/11/05 16:04:47 mike Exp $". // diff --git a/src/Fl_Tabs.cxx b/src/Fl_Tabs.cxx index 4399d93c1..110b1b6c4 100644 --- a/src/Fl_Tabs.cxx +++ b/src/Fl_Tabs.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Tabs.cxx,v 1.4 1998/10/21 14:20:22 mike Exp $" +// "$Id: Fl_Tabs.cxx,v 1.5 1998/11/05 16:04:47 mike Exp $" // // Tab widget for the Fast Light Tool Kit (FLTK). // @@ -189,12 +189,14 @@ void Fl_Tabs::draw() { int H = tab_height(); if (damage() & FL_DAMAGE_ALL) { // redraw the entire thing: fl_clip(x(), y()+(H>=0?H:0), w(), h()-(H>=0?H:-H)); - draw_box(box(), x(), y(), w(), h(), v->color()); + draw_box(box(), x(), y(), w(), h(), v ? v->color() : color()); fl_pop_clip(); - draw_child(*v); + if (v) draw_child(*v); } else { // redraw the child - update_child(*v); + if (v) update_child(*v); } + if (!v) return; + if (damage() & (FL_DAMAGE_EXPOSE|FL_DAMAGE_ALL)) { int p[128]; int w[128]; int selected = tab_positions(p,w); @@ -257,5 +259,5 @@ Fl_Tabs::Fl_Tabs(int X,int Y,int W, int H, const char *l) : } // -// End of "$Id: Fl_Tabs.cxx,v 1.4 1998/10/21 14:20:22 mike Exp $". +// End of "$Id: Fl_Tabs.cxx,v 1.5 1998/11/05 16:04:47 mike Exp $". // diff --git a/src/Fl_Window_hotspot.cxx b/src/Fl_Window_hotspot.cxx index 9bfeade54..06a3b29d7 100644 --- a/src/Fl_Window_hotspot.cxx +++ b/src/Fl_Window_hotspot.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Window_hotspot.cxx,v 1.3 1998/10/21 14:20:28 mike Exp $" +// "$Id: Fl_Window_hotspot.cxx,v 1.4 1998/11/05 16:04:48 mike Exp $" // // Common hotspot routines for the Fast Light Tool Kit (FLTK). // @@ -26,15 +26,36 @@ #include <FL/Fl.H> #include <FL/Fl_Window.H> +#ifdef WIN32 +#include <FL/win32.H> +#endif + void Fl_Window::hotspot(int X, int Y, int offscreen) { int mx,my; Fl::get_mouse(mx,my); X = mx-X; Y = my-Y; if (!offscreen) { + if (border()) { + // ensure border is on screen: +#ifdef WIN32 + int top, left, right, bottom; + Fl_X::get_border(this, top, left, bottom); + right = left; top += bottom; +#else + const int top = 20; + const int left = 1; + const int right = 1; + const int bottom = 1; +#endif + if (X+w()+right > Fl::w()) X = Fl::w()-right-w(); + if (X-left < 0) X = left; + if (Y+h()+bottom > Fl::h()) Y = Fl::h()-bottom-h(); + if (Y-top < 0) Y = top; + } + // now insure contents are on-screen (more important than border): + if (X+w() > Fl::w()) X = Fl::w()-w(); if (X < 0) X = 0; - if (X > Fl::w()-w()) X = Fl::w()-w(); - if (Y > Fl::h()-h()) Y = Fl::h()-h(); + if (Y+h() > Fl::h()) Y = Fl::h()-h(); if (Y < 0) Y = 0; - if (border() && Y < 20) Y = 20; } position(X,Y); } @@ -50,5 +71,5 @@ void Fl_Window::hotspot(const Fl_Widget *o, int offscreen) { } // -// End of "$Id: Fl_Window_hotspot.cxx,v 1.3 1998/10/21 14:20:28 mike Exp $". +// End of "$Id: Fl_Window_hotspot.cxx,v 1.4 1998/11/05 16:04:48 mike Exp $". // diff --git a/src/Fl_abort.cxx b/src/Fl_abort.cxx index 05ae00e27..b03df4eb6 100644 --- a/src/Fl_abort.cxx +++ b/src/Fl_abort.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_abort.cxx,v 1.3 1998/10/21 14:20:29 mike Exp $" +// "$Id: Fl_abort.cxx,v 1.4 1998/11/05 16:04:49 mike Exp $" // // Warning/error message code for the Fast Light Tool Kit (FLTK). // @@ -56,12 +56,15 @@ static void error(const char *format, ...) { #else #include <windows.h> +extern "C" { +int vsnprintf(char* str, size_t size, const char* fmt, va_list ap); +} static void warning(const char *format, ...) { va_list args; char buf[1024]; va_start(args, format); - vsprintf(buf, format, args); + vnsprintf(buf, 1024, format, args); va_end(args); MessageBox(0,buf,"Warning",MB_ICONEXCLAMATION|MB_OK); } @@ -70,7 +73,7 @@ static void error(const char *format, ...) { va_list args; char buf[1024]; va_start(args, format); - vsprintf(buf, format, args); + vnsprintf(buf, 1024, format, args); va_end(args); MessageBox(0,buf,"Error",MB_ICONSTOP|MB_SYSTEMMODAL); ::exit(1); @@ -83,5 +86,5 @@ void (*Fl::error)(const char* format, ...) = ::error; void (*Fl::fatal)(const char* format, ...) = ::error; // -// End of "$Id: Fl_abort.cxx,v 1.3 1998/10/21 14:20:29 mike Exp $". +// End of "$Id: Fl_abort.cxx,v 1.4 1998/11/05 16:04:49 mike Exp $". // diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx index 02492c500..64c0d379f 100644 --- a/src/Fl_win32.cxx +++ b/src/Fl_win32.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_win32.cxx,v 1.10 1998/10/21 14:20:36 mike Exp $" +// "$Id: Fl_win32.cxx,v 1.11 1998/11/05 16:04:50 mike Exp $" // // WIN32-specific code for the Fast Light Tool Kit (FLTK). // @@ -220,9 +220,9 @@ static int ms2fltk(int vk, int extended) { for (i = 0; i < sizeof(vktab)/sizeof(*vktab); i++) { vklut[vktab[i].vk] = vktab[i].fltk; extendedlut[vktab[i].vk] = vktab[i].extended; - } - for (i = 0; i < 256; i++) if (!extendedlut[i]) extendedlut[i] = vklut[i]; } + for (i = 0; i < 256; i++) if (!extendedlut[i]) extendedlut[i] = vklut[i]; + } return extended ? extendedlut[vk] : vklut[vk]; } @@ -412,13 +412,45 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar } //////////////////////////////////////////////////////////////// +// This function gets the dimensions of the top/left borders and +// the title bar, if there is one, based on the FL_BORDER, FL_MODAL +// and FL_NONMODAL flags, and on the window's size range. +// It returns the following values: +// +// value | border | title bar +// 0 | none | no +// 1 | fix | no +// 2 | fix | yes +// 3 | size | yes + +int Fl_X::get_border(const Fl_Window* w,int &T, int &X, int &Y) { + int ret = T = X = Y = 0; + if (w->border() && !w->parent()) { + ret = 2; + if ((w->maxw != w->minw || w->maxh != w->minh) && !w->non_modal()) { + ret |= 1; + X = GetSystemMetrics(SM_CXSIZEFRAME); + Y = GetSystemMetrics(SM_CYSIZEFRAME); + } else { + X = GetSystemMetrics(SM_CXFIXEDFRAME); + Y = GetSystemMetrics(SM_CYFIXEDFRAME); + } + if (w->modal()) + ret = 1; + else T = GetSystemMetrics(SM_CYCAPTION); + } + return ret; +} + +//////////////////////////////////////////////////////////////// void Fl_Window::resize(int X,int Y,int W,int H) { + UINT flags = SWP_NOSENDCHANGING | SWP_NOZORDER; int is_a_resize = (W != w() || H != h()); int resize_from_program = (this != resize_bug_fix); if (!resize_from_program) resize_bug_fix = 0; if (X != x() || Y != y()) set_flag(FL_FORCE_POSITION); - else if (!is_a_resize) return; + else {if (!is_a_resize) return; flags |= SWP_NOMOVE;} if (is_a_resize) { Fl_Group::resize(X,Y,W,H); if (shown()) {redraw(); i->wait_for_expose = 1;} @@ -426,13 +458,14 @@ void Fl_Window::resize(int X,int Y,int W,int H) { x(X); y(Y); } if (resize_from_program && shown()) { - if (border() && !parent()) { - X -= GetSystemMetrics(SM_CXFRAME); - Y -= GetSystemMetrics(SM_CYFRAME)+GetSystemMetrics(SM_CYCAPTION); - W += 2*GetSystemMetrics(SM_CXFRAME); - H += 2*GetSystemMetrics(SM_CYFRAME)+GetSystemMetrics(SM_CYCAPTION); - } - MoveWindow(i->xid, X, Y, W, H, TRUE); + int bt, bx, by; + if (Fl_X::get_border(this, bt, bx, by)) { + X -= bx; + Y -= by+bt; + W += 2*bx; + H += 2*by+bt; + } else {flags |= SWP_NOSIZE;} + SetWindowPos(i->xid, 0, X, Y, W, H, flags); } } @@ -470,16 +503,17 @@ Fl_X* Fl_X::make(Fl_Window* w) { } HWND parent; - DWORD style; - DWORD styleEx; + DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS; + DWORD styleEx = WS_EX_LEFT; + int xp = w->x(); int yp = w->y(); int wp = w->w(); int hp = w->h(); if (w->parent()) { - style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; - styleEx = WS_EX_LEFT | WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT; + style = WS_CHILD; + styleEx = WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT; parent = fl_xid(w->window()); } else { if (!w->size_range_set) { @@ -492,24 +526,35 @@ Fl_X* Fl_X::make(Fl_Window* w) { w->size_range(w->w(), w->h(), w->w(), w->h()); } } - if (w->border()) { - style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU - | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; - styleEx = WS_EX_LEFT | WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT; - if (w->maxw != w->minw || w->maxh != w->minh) - style |= WS_THICKFRAME | WS_MAXIMIZEBOX; - if (!w->modal()) style |= WS_MINIMIZEBOX; - xp -= GetSystemMetrics(SM_CXFRAME); - yp -= GetSystemMetrics(SM_CYFRAME)+GetSystemMetrics(SM_CYCAPTION); - wp += 2*GetSystemMetrics(SM_CXFRAME); - hp += 2*GetSystemMetrics(SM_CYFRAME)+GetSystemMetrics(SM_CYCAPTION); - } else { - style = WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPED; - styleEx = WS_EX_LEFT | WS_EX_TOPMOST | WS_EX_TOOLWINDOW; + styleEx |= WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT; + int bt, bx, by; + switch (Fl_X::get_border(w, bt, bx, by)) { + // No border (user for menus) + case 0: style |= WS_POPUP; break; + + // Thin border + case 1: style |= WS_POPUP | WS_DLGFRAME; break; + + // Thin border and title bar + case 2: style |= WS_DLGFRAME | WS_CAPTION | WS_SYSMENU; + if (!w->non_modal()) style |= WS_MINIMIZEBOX; break; + + // Thick, resizable border and title bar, with maximize button + case 3: style |= WS_THICKFRAME | WS_MAXIMIZEBOX | WS_CAPTION | + WS_SYSMENU | WS_MINIMIZEBOX; } + wp += 2*bx; + hp += 2*by+bt; + if (!(w->flags() & Fl_Window::FL_FORCE_POSITION)) { xp = yp = CW_USEDEFAULT; + } else { + xp -= bx; + yp -= by+bt; } +// if (xp<0) xp = 0; +// if (yp<0) yp = 0; + parent = 0; if (w->non_modal() && !fl_disable_transient_for) { // find some other window to be "transient for": @@ -581,13 +626,13 @@ void Fl_Window::size_range_() { void Fl_X::set_minmax(LPMINMAXINFO minmax) { - int wd, hd; - if (w->border()) { - wd = 2*GetSystemMetrics(SM_CXFRAME); - hd = 2*GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION); - } else { - wd = hd = 0; - } + int td, wd, hd; + + get_border(w, td, wd, hd); + wd *= 2; + hd *= 2; + hd += td; + minmax->ptMinTrackSize.x = w->minw + wd; minmax->ptMinTrackSize.y = w->minh + hd; if (w->maxw) { @@ -642,7 +687,9 @@ void Fl_Window::show() { Fl_X::make(this); } else { // Once again, we would lose the capture if we activated the window. - ShowWindow(i->xid,fl_capture?SW_SHOWNOACTIVATE:SW_RESTORE); + if (IsIconic(i->xid)) OpenIcon(i->xid); + if (!fl_capture) BringWindowToTop(i->xid); + //ShowWindow(i->xid,fl_capture?SW_SHOWNOACTIVATE:SW_RESTORE); } } @@ -728,5 +775,5 @@ void Fl_Window::flush() { } // -// End of "$Id: Fl_win32.cxx,v 1.10 1998/10/21 14:20:36 mike Exp $". +// End of "$Id: Fl_win32.cxx,v 1.11 1998/11/05 16:04:50 mike Exp $". // diff --git a/src/Makefile b/src/Makefile index a2eb6ebff..56ad86e9b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ # -# "$Id: Makefile,v 1.5 1998/10/21 22:03:52 mike Exp $" +# "$Id: Makefile,v 1.6 1998/11/05 16:04:50 mike Exp $" # # Library makefile for the Fast Light Tool Kit (FLTK). # @@ -137,7 +137,7 @@ CPPFILES = \ glut_compatability.C \ glut_font.C -CFILES = scandir.c numericsort.c +CFILES = scandir.c numericsort.c vsnprintf.c CLEAN = @@ -182,5 +182,5 @@ install: ../lib/$(LIBNAME) @chmod -R a+r,u+w,g-w,o-w $(includedir)/FL # -# End of "$Id: Makefile,v 1.5 1998/10/21 22:03:52 mike Exp $". +# End of "$Id: Makefile,v 1.6 1998/11/05 16:04:50 mike Exp $". # diff --git a/src/fl_ask.cxx b/src/fl_ask.cxx index e26ecebb3..f2c4ecfb3 100644 --- a/src/fl_ask.cxx +++ b/src/fl_ask.cxx @@ -1,5 +1,5 @@ // -// "$Id: fl_ask.cxx,v 1.3 1998/10/21 14:20:44 mike Exp $" +// "$Id: fl_ask.cxx,v 1.4 1998/11/05 16:04:51 mike Exp $" // // Standard dialog functions for the Fast Light Tool Kit (FLTK). // @@ -39,11 +39,11 @@ #include <FL/Fl_Input.H> #include <FL/Fl_Secret_Input.H> static Fl_Window *message_form; -static Fl_Box *message[3]; +static Fl_Box *message; static Fl_Box *icon; static Fl_Button *button[3]; static Fl_Input *input; -static char *iconlabel; +static char *iconlabel = "?"; uchar fl_message_font_ = 0; uchar fl_message_size_ = FL_NORMAL_SIZE; @@ -52,11 +52,7 @@ static Fl_Window *makeform() { Fl_Window *w = message_form = new Fl_Window(410,105); // w->clear_border(); // w->box(FL_UP_BOX); - (message[0] = new Fl_Box(60, 9, 340, 20)) - ->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_WRAP); - (message[1] = new Fl_Box(60, 25, 340, 20)) - ->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_WRAP); - (message[2] = new Fl_Box(60, 41, 340, 20)) + (message = new Fl_Box(60, 25, 340, 20)) ->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_WRAP); (input = new Fl_Input(60,32,340,30))->hide(); {Fl_Box* o = icon = new Fl_Box(10, 10, 50, 50); @@ -74,28 +70,32 @@ static Fl_Window *makeform() { return w; } -// back-compatable functions: +#include <stdio.h> +#include <stdarg.h> +#include <string.h> +#if !HAVE_VSNPRINTF +extern "C" { +int vsnprintf(char* str, size_t size, const char* fmt, va_list ap); +} +#endif -int fl_show_choice( - const char *m0, - const char *m1, - const char *m2, - int, // number of buttons, ignored +static int innards(const char* fmt, va_list ap, const char *b0, const char *b1, const char *b2) { makeform(); - message[0]->label(m0); - message[1]->label(m1); - message[2]->label(m2); + char buffer[1024]; + if (!strcmp(fmt,"%s")) { + message->label(va_arg(ap, const char*)); + } else { + vsnprintf(buffer, 1024, fmt, ap); + message->label(buffer); + } Fl_Font f = (Fl_Font)fl_message_font_; if (!f) f = Fl_Input_::default_font(); - int s = fl_message_size_ + Fl_Input::default_size(); - for (int i=0; i<3; i++) { - message[i]->labelfont(f); - message[i]->labelsize(s); - } + message->labelfont(f); + message->labelsize(fl_message_size_ + Fl_Input::default_size()); if (b0) {button[0]->show();button[0]->label(b0);button[1]->position(210,70);} else {button[0]->hide(); button[1]->position(310,70);} if (b1) {button[1]->show(); button[1]->label(b1);} @@ -117,7 +117,7 @@ int fl_show_choice( } message_form->hide(); icon->label(prev_icon_label); - return r+1; + return r; } // pointers you can use to change fltk to a foreign language: @@ -126,64 +126,73 @@ const char* fl_yes= "Yes"; const char* fl_ok = "OK"; const char* fl_cancel= "Cancel"; -// back-compatable XForms functions: +// fltk functions: -void fl_show_message(const char *q1,const char *q2,const char *q3) { +void fl_message(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); iconlabel = "i"; - fl_show_choice(q1, q2, q3, 1, 0, fl_ok, 0); + innards(fmt, ap, 0, fl_ok, 0); + va_end(ap); + iconlabel = "?"; } -void fl_show_alert(const char *q1,const char *q2,const char *q3) { +void fl_alert(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); iconlabel = "!"; - fl_show_choice(q1, q2, q3, 1, 0, fl_ok, 0); -} - -int fl_show_question(const char *q1,const char *q2,const char *q3) { + innards(fmt, ap, 0, fl_ok, 0); + va_end(ap); iconlabel = "?"; - return fl_show_choice(q1, q2, q3, 2, fl_no, fl_yes, 0) - 1; } -// fltk functions: - -void fl_message(const char *question) { - fl_show_message(0, question, 0); -} - -void fl_alert(const char *question) { - fl_show_alert(0, question, 0); +int fl_ask(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + int r = innards(fmt, ap, fl_no, fl_yes, 0); + va_end(ap); + return r; } -int fl_ask(const char *question) { - return fl_show_question(0, question, 0); -} - -int fl_choice(const char *q,const char *b0,const char *b1,const char *b2) { - iconlabel = "?"; - return fl_show_choice(0,q,0,3,b0,b1,b2) - 1; +int fl_choice(const char*fmt,const char *b0,const char *b1,const char *b2,...){ + va_list ap; + va_start(ap, b2); + int r = innards(fmt, ap, b0, b1, b2); + va_end(ap); + return r; } Fl_Widget *fl_message_icon() {makeform(); return icon;} -const char *fl_input(const char *str1, const char *defstr, uchar type) { +static const char* input_innards(const char* fmt, va_list ap, + const char* defstr, uchar type) { makeform(); + message->position(60,10); input->type(type); input->show(); input->value(defstr); - iconlabel = "?"; - int r = fl_show_choice(str1,0,0,2,fl_cancel,fl_ok,0); + int r = innards(fmt, ap, fl_cancel, fl_ok, 0); input->hide(); - return r==2 ? input->value() : 0; + message->position(60,25); + return r ? input->value() : 0; } -const char *fl_input(const char *str1, const char *defstr) { - return fl_input(str1, defstr, FL_NORMAL_INPUT); +const char* fl_input(const char *fmt, const char *defstr, ...) { + va_list ap; + va_start(ap, defstr); + const char* r = input_innards(fmt, ap, defstr, FL_NORMAL_INPUT); + va_end(ap); + return r; } -char *fl_show_simple_input(const char *str1, const char *defstr) { - const char *r = fl_input(str1, defstr, FL_NORMAL_INPUT); - return (char *)(r ? r : defstr); +const char *fl_password(const char *fmt, const char *defstr, ...) { + va_list ap; + va_start(ap, defstr); + const char* r = input_innards(fmt, ap, defstr, FL_SECRET_INPUT); + va_end(ap); + return r; } // -// End of "$Id: fl_ask.cxx,v 1.3 1998/10/21 14:20:44 mike Exp $". +// End of "$Id: fl_ask.cxx,v 1.4 1998/11/05 16:04:51 mike Exp $". // diff --git a/src/forms_compatability.cxx b/src/forms_compatability.cxx index 6debc0147..651daaeaa 100755 --- a/src/forms_compatability.cxx +++ b/src/forms_compatability.cxx @@ -1,5 +1,5 @@ // -// "$Id: forms_compatability.cxx,v 1.3 1998/10/21 14:21:05 mike Exp $" +// "$Id: forms_compatability.cxx,v 1.4 1998/11/05 16:04:51 mike Exp $" // // Forms compatibility functions for the Fast Light Tool Kit (FLTK). // @@ -175,6 +175,34 @@ Fl_Button *fl_add_button(uchar t,int x,int y,int w,int h,const char *l) { return b; } +void fl_show_message(const char *q1,const char *q2,const char *q3) { + fl_message("%s\n%s\n%s", q1?q1:"", q2?q2:"", q3?q3:""); +} + +void fl_show_alert(const char *q1,const char *q2,const char *q3,int) { + fl_alert("%s\n%s\n%s", q1?q1:"", q2?q2:"", q3?q3:""); +} + +int fl_show_question(const char *q1,const char *q2,const char *q3) { + return fl_ask("%s\n%s\n%s", q1?q1:"", q2?q2:"", q3?q3:""); +} + +int fl_show_choice( + const char *q1, + const char *q2, + const char *q3, + int, // number of buttons, ignored + const char *b0, + const char *b1, + const char *b2) { + return fl_choice("%s\n%s\n%s", q1?q1:"", q2?q2:"", q3?q3:"", b0,b1,b2)+1; +} + +char *fl_show_simple_input(const char *str1, const char *defstr) { + const char *r = fl_input(str1, defstr); + return (char *)(r ? r : defstr); +} + // -// End of "$Id: forms_compatability.cxx,v 1.3 1998/10/21 14:21:05 mike Exp $". +// End of "$Id: forms_compatability.cxx,v 1.4 1998/11/05 16:04:51 mike Exp $". // |
