Greg Ercolano wrote:
> "This widget produces an actual window. This can either be a main window,
> [..] or a "subwindow" inside a window. This is controlled by whether or not
> the window has a parent()."
>
> That last line seems to imply that maybe all that's needed is to put:
>
> parent(0);
>
> ..to the top of Calendar's ctor.
This seemed to work; test case below.
I added some stuff to pass the user-picked calendar button back to
Fl_Input, just to make it more of a 'working' example.
Might need a cleanup pass; it's Friday and I'm getting lazy..
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Group.H>
#include <string>
#include <sstream>
//
// Demonstrate a calendar popup
// 1.1 erco 4/20/07
//
class Calendar : public Fl_Double_Window {
std::string date;
static void DayClick_CB(Fl_Widget *w, void *o) {
Calendar *cal = (Calendar*)o;
cal->hide(); // hide when user
clicks a day..
cal->date = w->label();
cal->do_callback();
}
public:
Calendar(int X, int Y) : Fl_Double_Window(X, Y, 280, 180) {
parent(0);
color(FL_WHITE);
border(0);
// Create fake calendar
int bw = w()/7;
int bh = h()/4;
for ( int day=0; day<28; day++ ) {
std::ostringstream day_str;
day_str << (day+1); // (avoiding sprintf())
Fl_Button *b = new Fl_Button((day % 7) * bw, (day / 7) * bh, bw,
bh);
b->callback(DayClick_CB, (void*)this); // when user clicks a
day
b->copy_label(day_str.str().c_str()); // day label
b->box(FL_BORDER_BOX);
b->color(FL_WHITE);
b->align(FL_ALIGN_INSIDE|FL_ALIGN_LEFT|FL_ALIGN_TOP);
}
end();
}
int handle(int e) {
if ( e == FL_LEAVE ) hide(); // hide if mouse
leaves window
return(Fl_Double_Window::handle(e));
}
const char *GetDate() {
return(date.c_str());
}
};
class DateInput : public Fl_Group {
static Calendar *cal_;
Fl_Button *but;
Fl_Input *in;
static void Button_CB(Fl_Widget*, void *o) {
DateInput *di = (DateInput*)o;
di->cal_->position(Fl::event_x_root()-4, Fl::event_y_root()-4);
di->cal_->show();
}
static void SetInput_CB(Fl_Widget*, void *o) {
DateInput *di = (DateInput*)o;
di->in->value(cal_->GetDate());
}
public:
DateInput(int X, int Y, int W, int H) : Fl_Group(X, Y, W, H) {
box(FL_BORDER_BOX);
but = new Fl_Button(50, 50, 100, 20, "Cal");
but->callback(Button_CB, (void*)this);
in = new Fl_Input(50, 80, 100, 20, "Day:");
if ( cal_ == 0 ) {
cal_ = new Calendar(X,Y);
cal_->callback(SetInput_CB, (void*)this);
}
end();
}
};
Calendar *DateInput::cal_ = 0; // initialize static
int main() {
Fl_Double_Window win(300, 300);
DateInput *di = new DateInput(10,40,300-20,300-40);
di->end();
Fl_Button *but = new Fl_Button(50,10,100,20,"Test"); // verify
Fl_Window is still 'current'
win.end();
win.show();
return(Fl::run());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk