See the test code below.
In fltk-2.0.x-r6970, file_chooser behaves insubordinate.
file_chooser(TITLE,PATTERN,NULL);
seems to be correct. But
file_chooser(TITLE,PATTERN,filename);
is not. When I load a file from a non-local directory,
the image is shown in full width and height.
When I now call file_chooser to load another file, then
- mostly but not always - the visible image shrinks.
Inserting trace code into FileChooser2.cxx I found that
in update_preview() the previewButton->value() returns 1.
Although the button has not been set.
When I now copy the file from the non-local directory to
the working directory, load this file and call file_chooser
to load another file: then the visible file does not shrink
to preview size.
file_chooser lottery.
The appended code is the 'pixmap_browser.cxx'.
winfried
-----------------------------------------------------------
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fltk/run.h>
#include <fltk/draw.h>
#include <fltk/filename.h>
#include <fltk/Widget.h>
#include <fltk/Window.h>
#include <fltk/Button.h>
#include <fltk/SharedImage.h>
#include <fltk/file_chooser.h>
#include <fltk/ask.h>
//#define CHOOSER_WITH_NAME
#define HEADER_H 45
#define WINMIN_W 210
using namespace fltk;
static Window *main_win;
static SharedImage *sim;
class Canvas: public Widget
{
void draw();
int iwidth, iheight;
public:
Canvas(int x,int y,int w,int h)
: Widget(x,y,w,h)
{
box(NO_BOX); iwidth = iheight = 0;
}
void width(int w){ iwidth = w; }
void height(int h){ iheight = h; }
};
void Canvas::draw()
{
setcolor(YELLOW);
if(sim)
{
int ww;
if((ww = iwidth) < WINMIN_W) ww = WINMIN_W;
main_win->resize(ww, HEADER_H + iheight);
resize(iwidth, iheight);
fillrect(0, 0, w(), h());
sim->draw(0, 0);
return;
}
fillrect(0, 0, w(), h());
}
static Canvas *canvas;
void newpixmap(const char *name)
{
int w, h;
sim = SharedImage::get(name);
if(sim == NULL)
{
alert("No SharedImage possible for\n%s",name);
return;
}
sim->measure(w, h);
canvas->width(w); canvas->height(h);
canvas->redraw();
}
static char name[1024];
static void file_cb(const char *n)
{
if(n[0] == '.' && n[1] == 0) return;
if( !filename_exist(n)) return;
if(filename_isdir(n)) return;
strcpy(name, n);
main_win->label(filename_name(name));
newpixmap(name);
}
static void cancel_cb(Widget *, void *)
{
exit(0);
}
static void button_cb(Widget *,void *)
{
file_chooser_callback(file_cb);
#ifdef CHOOSER_WITH_NAME
file_chooser("Image File","*.{xpm,png,jpg}", name);
#else
file_chooser("Image File","*.{xpm,png,jpg}", NULL);
#endif
file_chooser_callback(NULL);
}
int main(int argc, char **argv)
{
register_images();
main_win = new Window(400,HEADER_H+400);
main_win->label("Pixmap Browser");
main_win->begin();
{
Button *b = new Button(5,5,100,35,"Load");
b->callback(button_cb);
}
{
Button *b = new Button(105,5,100,35,"Cancel");
b->callback(cancel_cb);
}
canvas = new Canvas(0,HEADER_H,400,400);
main_win->end();
main_win->resizable(canvas);
main_win->show();
if (argv[1]) file_cb(argv[1]);
return run();
}
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs