Andreas Schömann schrieb:
> My program has several windows open at the same time. After a while some
> of these windows are covered by windows from other applications I work
> with, e.g. web browser.
>
> Now my question is: How can I bring _all_ windows of my application on
> top again by just clicking _one_ of the windows?
I have developped two classes that implement most of the behaviour I need:
1. All windows of an application shall come to the top by just clicking
one window.
2. Minimizing the main window shall minimize all other windows too.
3. Restoring the main window (from minimized state) shall restore all
other windows too.
Both classes are derived from Fl_Window. JoinedVisibilityWindow
implements 1. JoinedMinimizeWindow implements 2. and 3. A
JoinedMinimizeWindow is also a JointVisibilityWindow hence derived from it.
All this works good. However, there is one major problem: Clicking the
_border_ of a window does not bring all joined windows to the top as I
want it. Clicking the border of a window does not produce a FL_PUSH
event but a FL_FOCUS event. Trying to utilize FL_FOCUS produces only
nonsense!? Please try.
Question: How can I reliably react on clicking the border of a window?
Another thing I don't understand: calling hide() from within
handle(FL_HIDE) results in an endless loop: hide()->handle()->hide()...
!? Look JoinedMinimizeWindow::handle.
Andreas
#include <iostream>
#include <pair>
#include <list>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
class JoinedVisibilityWindow : public Fl_Window
{
protected:
struct Window
{
Fl_Window * pointer;
bool joined;
Window(Fl_Window * p, bool j)
: pointer(p),
joined(j)
{}
};
typedef std::list<Window> Windows;
static Windows windows_;
public:
JoinedVisibilityWindow(int x, int y, int w, int h, const char * l = 0)
: Fl_Window(x, y, w, h, l)
{
windows_.push_back(Window(this, false));
}
JoinedVisibilityWindow(int w, int h, const char * l = 0)
: Fl_Window(w, h, l)
{
windows_.push_back(Window(this, false));
}
int handle(int e)
{
std::cout << "JoinedVisibility::event " << e << std::endl;
switch(e)
{
// clicking the border of a window does not produce a FL_PUSH event
// but a FL_FOCUS event. Simply catching FL_FOCUS and showing all
// Joined windows produces only nonsense!?
// case FL_FOCUS:
case FL_PUSH:
{
Windows::const_iterator window;
for(window = windows_.begin(); window != windows_.end(); ++window)
{
std::cout << "JoinedVisibility::push: " << window->pointer << ", " <<
window->joined << std::endl;
if(window->joined)
window->pointer->show();
}
break;
}
case FL_SHOW:
{
Windows::iterator window;
for(window = windows_.begin(); window != windows_.end(); ++window)
{
std::cout << "JoinedVisibility::show: " << window->pointer << ", " <<
window->joined << std::endl;
if(window->pointer == this)
window->joined = true;
}
break;
}
case FL_HIDE:
{
Windows::iterator window;
for(window = windows_.begin(); window != windows_.end(); ++window)
if(window->pointer == this)
window->joined = false;
break;
}
}
return Fl_Window::handle(e);
}
};
JoinedVisibilityWindow::Windows JoinedVisibilityWindow::windows_;
class JoinedMinimizeWindow : public JoinedVisibilityWindow
{
public:
JoinedMinimizeWindow(int x, int y, int w, int h, const char * l = 0)
: JoinedVisibilityWindow(x, y, w, h, l)
{}
JoinedMinimizeWindow(int w, int h, const char * l = 0)
: JoinedVisibilityWindow(w, h, l)
{}
int handle(int e)
{
std::cout << "JoinedMinimize::event " << e << std::endl;
switch(e)
{
case FL_SHOW:
{
Windows::iterator window;
for(window = windows_.begin(); window != windows_.end(); ++window)
{
if(window->joined)
{
std::cout << "JoinedMinimize::show: " << window->pointer << ", " <<
window->joined << std::endl;
window->pointer->show();
}
}
break;
}
case FL_HIDE:
{
Windows::iterator window;
for(window = windows_.begin(); window != windows_.end(); ++window)
{
// test for visibility, otherwise all windows will be
destroyed due to
// an hide()->handle()->hide()... endless loop (calling
hide() twice
// on a window destroys it!?)
if(window->pointer->visible())
{
std::cout << "JoinedMinimize::hide: " << window->pointer << ", " <<
window->joined << std::endl;
window->pointer->hide();
window->joined = true;
}
}
return 1;
}
}
return JoinedVisibilityWindow::handle(e);
}
};
int main(int argc,char **argv)
{
JoinedMinimizeWindow a(200, 200, "min 1");
a.end();
a.show();
JoinedVisibilityWindow b(200, 200, "vis 1");
b.end();
b.show();
JoinedVisibilityWindow c(200, 200, "vis 2");
c.end();
c.show();
Fl::run();
return (0);
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk