Greg Ercolano wrote:
>     In your final app, you would likely have a 'calendar open' button
>     the user presses, and you can use the Fl::event_x_root() and
>     Fl::event_y_root() to get the user's mouse position at the time
>     of the event, and position() your calendar window there before
>     show()ing it, so that it opens where the user's mouse is.
> [..]
>     Or, you may want to set things up so that if the user moves off
>     the calendar window, it hide()s automatically, similar to the
>     way a popup menu disappears if you move off of it. In such a case
>     you might even want to make the calendar window borderless..

        Here's a proof of that concept, I was curious.
        Seems like a good way to go:

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Group.H>
#include <stdio.h>
#include <string.h>
//
// Demonstrate a calendar popup
// 1.0 erco 4/18/07
//
class Calendar : public Fl_Double_Window {
     static void DayClick_CB(Fl_Widget*, void *o) {
         Calendar *cal = (Calendar*)o;
         cal->hide();                                    // hide when user 
clicks a day..
     }
public:
     Calendar(int X, int Y) : Fl_Double_Window(X, Y, 280, 180) {
         color(FL_WHITE);
         border(0);
         // Create fake calendar
         int bw = w()/7;
         int bh = h()/4;
         char day_str[10];
         for ( int day=0; day<28; day++ ) {
             sprintf(day_str, "%d", day+1);
             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);                     // 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));
     }
};
Calendar *G_cal = 0;
void Cal_CB(Fl_Widget*, void*) {
     G_cal->position(Fl::event_x_root()-4, Fl::event_y_root()-4);
     G_cal->show();
}
int main() {
     Fl_Double_Window win(300, 300);
       Fl_Button* b = new Fl_Button(50, 50, 100, 20, "Cal");
       b->callback(Cal_CB);
     win.end();
     win.show();
     G_cal = new Calendar(300, 300);
     return(Fl::run());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to