FLTK logo

Re: [fltk.general] Focus

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Focus "MacArthur, Ian \(SELEX\) \(UK\)" Mar 28, 2007  
 
> > Can you post a small, complete, example somewhere? Then
> > people might be able to advise you further?
> 
> Excuse me, but I really don't think there is a need for such 
> tone in your message.

Pardon?
I thought I was being constructive and helpful - perhaps you have
mis-read my intent?

> Code snippet which I've sent earlier contains all that is 
> related to this
> particular issue, in fact that's almost all that has to do 
> with GUI. 

That may be so - but it was incomplete as of itself, and could not
therefore be compiled and tested by anyone else, making it unnecessarily
difficult for us to offer you any help.
Please try and help us to help you.

Note, also, that the much longer version you posted is similarly
afflicted: It does not compile.
Yes, the omissions you have made are probably trivial to fix, but it
simply places an obstacle in the way of those who would offer help,
making it less likely that someone will jump in and sort your problems
for you.

Anyway. I couldn't build your example, but the Michael Sephton example
does build, so I have tweaked that do what I think you want - I have
used a number of different techniques to cover the issues with
hiding/exposing the browser window when the main window is max/minimised
- either by sub classing the handle method of the main window, or via
timeouts. 
One or other of these techniques should work for you.
This example also works around the focus passing issue in a pragmatic
(albeit not very pretty) way.
It works correctly.
Hope this is of some help to you:

----------------- 
#include <fltk/run.h>
#include <fltk/Window.h>
#include <fltk/Input.h>
#include <fltk/Button.h>
#include <fltk/events.h>

using namespace fltk;

Input *in;
Window *ext_win=0;
Input *ext_in;
Button *hide_button;

class MainWindow : public Window {
	public:
	int sub_shown;
	
	MainWindow(int X, int Y, int W, int H, const char *L=0) : 
	    Window(X,Y,W,H,L){sub_shown = 0;};

	private:
	int handle(int ev) {
		int res = fltk::Window::handle(ev);
		if(ev == HIDE) {
			if (ext_win) ext_win->hide();
		}
		return res;
	}
};

MainWindow *win;

void hide_cb(Widget *w,void *d){
	ext_win->hide();
	win->sub_shown = 0;
}

void cb_grab_focus(void*)
{
	in->take_focus();
}

void in_cb(Widget *w,void *d){
	ext_in->value(in->value());
	if(!ext_win->visible())
	{
		ext_win->show();
		win->sub_shown = 1;
		fltk::add_timeout(0.05, cb_grab_focus);
	}
}//in_cb

void timer_hide_child(void*)
{
//	int v1 = win->visible();
	int i1 = win->iconic();
	int v2 = ext_win->visible();
	int i2 = ext_win->iconic();
	
	if(i1 && !i2)
		ext_win->hide();
	else if ((!i1) && win->sub_shown) {
		if(!v2) ext_win->show();
	}
	fltk::repeat_timeout(0.4, timer_hide_child);
}

int main(void) {
	win = new MainWindow(100,300,120,120,"window");
	win->begin();
		in = new Input(10,10,100,30);
		in->callback(in_cb,0);
		in->when(WHEN_CHANGED);
	win->end();
	win->box(UP_BOX);
	win->show();

	ext_win = new Window(230,300,320,70,"extended window");
	ext_win->begin();
		ext_in = new Input(10,10,300,30);
		hide_button = new Button(10,50,45,15,"Hide");
		hide_button->callback(hide_cb);
	ext_win->end();
	ext_win->box(UP_BOX);
	ext_win->clear_border();
	ext_win->hide();
	fltk::add_timeout(0.3, timer_hide_child);

	return run();
}
// --- End ---

With any luck, that might give you some clues as to how to get what you
want from your program. Good luck with your code.
And your attitude.
Way to go.



SELEX Sensors and Airborne Systems Limited
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales.  Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************


Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.