On Apr 25, 2007, at 7:01 PM, MacArthur, Ian ((SELEX)) ((UK)) wrote:

>
>> Yes, it's a popup window that I want.  In fact I've already got it :)
>> I was hoping to improve it by allowing the user to dismiss it by
>> clicking outside it.  Which also works, except that keyboard
>> navigation
>> within it goes away.  Sigh.

I have not followed this discussion from the beginning, but it sounds  
like one o my Flmm widgets. Maybe this helps:

//
// "$Id$"
//
// Flmm_Popup_Window implementationfor the FLmm extension to FLTK.
//
// Copyright 2002-2004 by Matthias Melcher.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems to "[EMAIL PROTECTED]".
//

/** \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);
}


//
// End of "$Id:$".
//



//
// "$Id$"
//
// Flmm_Popup_Window header file for the FLmm extension to FLTK.
//
// Copyright 2002-2004 by Matthias Melcher.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems to "[EMAIL PROTECTED]".
//

#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

//
// End of "$Id$".
//

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to