[snip: paul davis' gtk embedding example]

well, looking at your code, i am not really sure if this is what you
mean, but the attached code shows how to embed an existing X11 window
inside a fltk window (run it, find out the XId of any existing window
(with xwininfo), and enter it in the text input. it does not matter if
the existing window is gtk, qt, motif, fltk or plain X. however there
are some problems, if you move the parent window: motif menus are opened
at the position where the window was first embedded, and for fltk menus
even the menubar buttons itself. if anybody has a suggestion on how to
solve this...

maarten

g++ embed.cxx -lfltk

#include <FL/Fl_Window.H>
#include <FL/Fl_Input.H>
#include <FL/Fl.H>
#include <FL/x.H>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

class Fl_Embed_Window:public Fl_Window
{
public:
	Window xid_;
	Fl_Embed_Window(int ix,int iy,Window xid):Fl_Window(ix,iy,0,0)
	{
		xid_ = xid;
	}
	
	void show(void)
	{
		XWindowAttributes attribs;
 		XGetWindowAttributes(fl_display, xid_, &attribs);
		if (shown()) {
			Fl_Window::show();
			return;
		}
		Fl_X::set_xid(this, xid_);
		size(attribs.width,attribs.height);
		XReparentWindow (fl_display, xid_, fl_xid(window()), 0, 0);
	}
};

void embed(Fl_Widget* widget,void* ptr)
{
	Fl_Input* input = (Fl_Input*) widget;
	Fl_Window* window = widget->window();
	Fl_Window* embedded;
	char tmp[256];
	int xid;
	strncpy(tmp,input->value(),255);
	
	sscanf(tmp,"%x",&xid);

	window->add(embedded = new Fl_Embed_Window(0,0,xid));
	embedded->show(); // cause the reparent
}

main()
{
	Fl_Window window(400,400);
	Fl_Input input(0,380,400,20);
	input.when(FL_WHEN_ENTER_KEY);
	input.callback(embed);
	window.end();
	window.resizable(window);
	window.show();
	Fl::run();
}

Reply via email to