xref: /haiku/src/preferences/joysticks/MessageWin.cpp (revision d9b872d03c844b09c79e9647f668eef70b84fee6)
144d1fa37SRyan Leavengood /*
244d1fa37SRyan Leavengood  * Copyright 2007 Haiku.
344d1fa37SRyan Leavengood  * Distributed under the terms of the MIT License.
444d1fa37SRyan Leavengood  *
544d1fa37SRyan Leavengood  * Authors:
644d1fa37SRyan Leavengood  *		Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
744d1fa37SRyan Leavengood  *		Ryan Leavengood, leavengood@gmail.com
844d1fa37SRyan Leavengood  */
944d1fa37SRyan Leavengood 
1044d1fa37SRyan Leavengood 
1144d1fa37SRyan Leavengood #include "MessageWin.h"
1244d1fa37SRyan Leavengood 
1344d1fa37SRyan Leavengood #include <Box.h>
1444d1fa37SRyan Leavengood #include <Message.h>
1544d1fa37SRyan Leavengood #include <TextView.h>
1644d1fa37SRyan Leavengood #include <View.h>
1744d1fa37SRyan Leavengood 
1844d1fa37SRyan Leavengood /* frame will be the frame of the parent window as*/
MessageWin(BRect parentFrame,const char * title,window_look look,window_feel feel,uint32 flags,uint32 workspace)1944d1fa37SRyan Leavengood MessageWin::MessageWin(BRect parentFrame, const char *title,
2044d1fa37SRyan Leavengood 	window_look look, window_feel feel, uint32 flags, uint32 workspace)
2144d1fa37SRyan Leavengood 	: BWindow(parentFrame ,title ,look ,feel, flags, workspace)
2244d1fa37SRyan Leavengood {
2344d1fa37SRyan Leavengood 	fBox = new BBox(Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER);
24*f0650dc9Slooncraz 	fBox->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
2544d1fa37SRyan Leavengood 	fBox->SetLowColor(fBox->ViewColor());
2644d1fa37SRyan Leavengood 
2744d1fa37SRyan Leavengood 	// Rects for the text view
2844d1fa37SRyan Leavengood 	BRect outside(fBox->Bounds());
2944d1fa37SRyan Leavengood 	outside.InsetBy(10, 10);
3044d1fa37SRyan Leavengood 	BRect insider(outside);
3144d1fa37SRyan Leavengood 	insider.OffsetTo(B_ORIGIN);
3244d1fa37SRyan Leavengood 
3344d1fa37SRyan Leavengood 	fText = new BTextView(outside, "message", insider, B_FOLLOW_NONE, B_WILL_DRAW);
3444d1fa37SRyan Leavengood 	fText->MakeEditable(false);
35*f0650dc9Slooncraz 	fText->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
3644d1fa37SRyan Leavengood 	fText->SetLowColor(fText->ViewColor());
3744d1fa37SRyan Leavengood 
3844d1fa37SRyan Leavengood 	fBox->AddChild(fText);
3944d1fa37SRyan Leavengood  	AddChild(fBox);
4044d1fa37SRyan Leavengood 
4144d1fa37SRyan Leavengood  	/* Relocate the window to the center of what its being given */
4244d1fa37SRyan Leavengood   	ResizeTo(parentFrame.Width(), floor(parentFrame.Height() / 3));
4344d1fa37SRyan Leavengood  	MoveBy(0, floor(parentFrame.Height() / 2 - (parentFrame.Height()/3) / 2 ));
4444d1fa37SRyan Leavengood 
4544d1fa37SRyan Leavengood }
4644d1fa37SRyan Leavengood 
4744d1fa37SRyan Leavengood 
SetText(const char * str)4844d1fa37SRyan Leavengood void MessageWin::SetText(const char* str)
4944d1fa37SRyan Leavengood {
5044d1fa37SRyan Leavengood 	Lock();
5144d1fa37SRyan Leavengood 	fText->SetText(str);
5244d1fa37SRyan Leavengood 	fText->Flush();
5344d1fa37SRyan Leavengood 	Unlock();
5444d1fa37SRyan Leavengood }
5544d1fa37SRyan Leavengood 
5644d1fa37SRyan Leavengood 
MessageReceived(BMessage * message)5744d1fa37SRyan Leavengood void MessageWin::MessageReceived(BMessage *message)
5844d1fa37SRyan Leavengood {
5944d1fa37SRyan Leavengood 	switch(message->what)
6044d1fa37SRyan Leavengood 	{
6144d1fa37SRyan Leavengood 		default:
6244d1fa37SRyan Leavengood 			BWindow::MessageReceived(message);
6344d1fa37SRyan Leavengood 			break;
6444d1fa37SRyan Leavengood 	}
6544d1fa37SRyan Leavengood }
6644d1fa37SRyan Leavengood 
6744d1fa37SRyan Leavengood 
QuitRequested()6844d1fa37SRyan Leavengood bool MessageWin::QuitRequested()
6944d1fa37SRyan Leavengood {
7044d1fa37SRyan Leavengood 	return BWindow::QuitRequested();
7144d1fa37SRyan Leavengood }
7244d1fa37SRyan Leavengood 
73