On Jul 8, 2007, at 3:50 PM, Daniel Polski wrote:
>
> Hello,
> I am trying to create a menu-like window which pops up when the user
> interacts with a search field in a modal window.
You have to do some trickery with grab(). Here is some working code
(LGPL):
------- Flmm_Popup_Window.H ------
/** \class Flmm_Popup_Window
* A container for Menu Windows that are more complex than a menu
pulldown.
*
* The Popup Window behaves like a popup menu, but will vanish as
* soon as the user clicks outside of the menu area. This way, the
* Popup can contain a rather complex UI without the overhead of
* a full fledged dialog box.
*
* \todo add a 'popup()' function that will set all needed attributes
*
* \author Matthias Melcher
*/
#include "../FL/Flmm_Popup_Window.H"
Flmm_Popup_Window::Flmm_Popup_Window( int W, int H, char *L)
: Fl_Window(0, 0, W, H, L)
{
done = 0;
focus_x = focus_y = 0;
clear_border();
box(FL_UP_BOX);
set_non_modal();
}
char Flmm_Popup_Window::popup(int x, int y)
{
if (x==999999)
x = Fl::event_x_root();
if (y==999999)
y = Fl::event_y_root();
position(x-focus_x, y-focus_y);
Fl_Window::show();
Fl::grab(this);
while (visible()) {
Fl::wait();
}
Fl::release();
return 1;
}
void Flmm_Popup_Window::show() {
popup();
}
void Flmm_Popup_Window::focus(int x, int y)
{
focus_x = x;
focus_y = y;
}
void Flmm_Popup_Window::focus(Fl_Widget const* const w)
{
if (w)
focus(w->x()+w->w()/2, w->y()+w->h()/2);
}
int Flmm_Popup_Window::handle(int ev)
{
if (ev == FL_KEYBOARD && Fl::focus()) {
if (Fl::focus()->handle(ev)==1)
return 1;
if (Fl::focus()->handle(FL_SHORTCUT)==1)
return 1;
if (Fl::event_key()==FL_Escape) {
if (callback())
do_callback();
return 1;
}
} else if (ev == FL_PUSH) {
int ex = Fl::event_x(), ey = Fl::event_y();
if ( ex<0 || ey<0 || ex>w() || ey>h() ) {
hide();
if (callback())
do_callback();
return 1;
}
Fl_Window *pg = Fl::grab_;
Fl::grab_ = 0;
Fl_Window::handle(ev);
Fl::grab_ = pg;
return 1;
}
return Fl_Window::handle(ev);
}
------- Flmm_Popup_Window.H ------
#ifndef _FLMM_POPUP_WINDOW_H_
#define _FLMM_POPUP_WINDOW_H_
#include <Fl/Fl.H>
#include <Fl/Fl_Window.H>
class Flmm_Popup_Window : public Fl_Window
{
public:
Flmm_Popup_Window( int W, int H, char *L = 0L );
char popup(int x=999999, int y=999999);
void focus(int x, int y);
void focus(Fl_Widget const* const w);
protected:
int handle( int );
void show();
char done;
int focus_x, focus_y;
};
#endif
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk