示例#1
0
void ColorMenu::setParent (ColorMenuButton *pmb)
{
	parent = pmb;
	
	// Now is also a good time to put the tear-off window on screen
	// (if the app last quit that way)
	if (!fWindow)
	{
		BPoint origin;
		BRect place = Bounds();
		if (!strcmp (Name(), "fg"))
			origin = get_window_origin (numFGColorTO);
		else if (!strcmp (Name(), "bg"))
			origin = get_window_origin (numBGColorTO);
		if (origin != InvalidPoint)
		{
			place.OffsetTo (origin);
			TearDone (place, true);
		}
	}
}
示例#2
0
int
main()
{
	BApplication app("application/x-vnd.Haiku-PPMTranslator");
	BView * v = NULL;
	BRect r(0, 0, 1, 1);
	if (MakeConfig(NULL, &v, &r)) {
		BAlert * err = new BAlert("Error", 
			B_TRANSLATE("Something is wrong with the PPMTranslator!"), 
			B_TRANSLATE("OK"));
		err->Go();
		return 1;
	}
	PPMWindow *w = new PPMWindow(r);
	v->ResizeTo(r.Width(), r.Height());
	w->AddChild(v);
	BPoint o = get_window_origin();
	{
		BScreen scrn;
		BRect f = scrn.Frame();
		f.InsetBy(10,23);
		/* if not in a good place, start where the cursor is */
		if (!f.Contains(o)) {
			uint32 i;
			v->GetMouse(&o, &i, false);
			o.x -= r.Width()/2;
			o.y -= r.Height()/2;
			/* clamp location to screen */
			if (o.x < f.left) o.x = f.left;
			if (o.y < f.top) o.y = f.top;
			if (o.x > f.right) o.x = f.right;
			if (o.y > f.bottom) o.y = f.bottom;
		}
	}
	w->MoveTo(o);
	w->Show();
	app.Run();
	return 0;
}