Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » TopWindow&PopUp, TrayIcon » Windows that cant leave Mainwindow
Re: Windows that cant leave Mainwindow [message #30472 is a reply to message #30469] Mon, 03 January 2011 13:31 Go to previous messageGo to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Jens!
Welcome to the U++ Wink

Jschn88 wrote on Mon, 03 January 2011 11:33


The subwindows should only be moved arround in the mainwindow and are not allowed to leave it.

If I understand right, you want something like this:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;

class RestrictedTopWindow:public TopWindow{
	TopWindow* parent;
	typedef RestrictedTopWindow CLASSNAME;
public:
	RestrictedTopWindow(TopWindow* parent):parent(parent){
		SetTimeCallback(-50,THISBACK(CheckPos));
	}
	void CheckPos(){
		Rect allowed=parent->GetRect();
		Rect r=GetRect();
		if(!r.Contains(allowed)){
			SetRect(minmax(r.left,allowed.left,allowed.right-r.GetWidth()),
			        minmax(r.top,allowed.top,allowed.bottom-r.GetHeight()),
			        r.GetWidth(),r.GetHeight());
		}
	}
};

class App :public TopWindow {
	typedef App CLASSNAME;
public:
	RestrictedTopWindow rtw;
	App():rtw(this){
		Title("MainWindow");
	}
	void LeftUp(Point p,dword){
		rtw.SetRect(p.x,p.y,200,100);
		rtw.Title("Child window").Sizeable().Run();	
	}
};

GUI_APP_MAIN{
	App().Sizeable().Run();
}
This code is of course oversimplified and probably not very clever anyway, but it might give you some ideas to start with. The basic idea is that you derive your custom class from TopWindow (or some TopWindow-derived class) which checks periodically if its location is correct and reposition itself if necessary. Checking every 100ms is fine enough to go unnoticed for human eye Smile

I didn't find any better way to do it, but that doesn't mean that there is none Smile I think there is no callback or virtual method that is called upon repositioning of window, so unless I missed something this is out of scope. But there might a nicer way how to achieve what you want using Docking windows (have a look in bazaar and search here on the forum).

Best regards,
Honza

EDIT: Fixed an error in the code

[Updated on: Mon, 03 January 2011 14:43]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: [FEATURE] Setting TopWindow to urgent/flashing state
Next Topic: How to get top and left position of top window
Goto Forum:
  


Current Time: Mon May 13 19:36:33 CEST 2024

Total time taken to generate the page: 0.02006 seconds