1 /* 2 * Copyright 2007 Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com 7 * Ryan Leavengood, leavengood@gmail.com 8 */ 9 10 11 #include "MessageWin.h" 12 13 #include <Box.h> 14 #include <Message.h> 15 #include <TextView.h> 16 #include <View.h> 17 18 /* frame will be the frame of the parent window as*/ 19 MessageWin::MessageWin(BRect parentFrame, const char *title, 20 window_look look, window_feel feel, uint32 flags, uint32 workspace) 21 : BWindow(parentFrame ,title ,look ,feel, flags, workspace) 22 { 23 fBox = new BBox(Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER); 24 fBox->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 25 fBox->SetLowColor(fBox->ViewColor()); 26 27 // Rects for the text view 28 BRect outside(fBox->Bounds()); 29 outside.InsetBy(10, 10); 30 BRect insider(outside); 31 insider.OffsetTo(B_ORIGIN); 32 33 fText = new BTextView(outside, "message", insider, B_FOLLOW_NONE, B_WILL_DRAW); 34 fText->MakeEditable(false); 35 fText->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 36 fText->SetLowColor(fText->ViewColor()); 37 38 fBox->AddChild(fText); 39 AddChild(fBox); 40 41 /* Relocate the window to the center of what its being given */ 42 ResizeTo(parentFrame.Width(), floor(parentFrame.Height() / 3)); 43 MoveBy(0, floor(parentFrame.Height() / 2 - (parentFrame.Height()/3) / 2 )); 44 45 } 46 47 48 void MessageWin::SetText(const char* str) 49 { 50 Lock(); 51 fText->SetText(str); 52 fText->Flush(); 53 Unlock(); 54 } 55 56 57 void MessageWin::MessageReceived(BMessage *message) 58 { 59 switch(message->what) 60 { 61 default: 62 BWindow::MessageReceived(message); 63 break; 64 } 65 } 66 67 68 bool MessageWin::QuitRequested() 69 { 70 return BWindow::QuitRequested(); 71 } 72 73