1 /*****************************************************************************/ 2 // InfoWindow 3 // Written by Michael Wilber, OBOS Translation Kit Team 4 // 5 // InfoWindow.cpp 6 // 7 // BWindow class for displaying information about the currently open 8 // document 9 // 10 // 11 // Copyright (c) 2003 OpenBeOS Project 12 // 13 // Permission is hereby granted, free of charge, to any person obtaining a 14 // copy of this software and associated documentation files (the "Software"), 15 // to deal in the Software without restriction, including without limitation 16 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 // and/or sell copies of the Software, and to permit persons to whom the 18 // Software is furnished to do so, subject to the following conditions: 19 // 20 // The above copyright notice and this permission notice shall be included 21 // in all copies or substantial portions of the Software. 22 // 23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 29 // DEALINGS IN THE SOFTWARE. 30 /*****************************************************************************/ 31 32 #include "Constants.h" 33 #include "InfoWindow.h" 34 #include <Application.h> 35 #include <ScrollView.h> 36 #include <Message.h> 37 #include <String.h> 38 39 InfoWindow::InfoWindow(BRect rect, const char *name, const char *text) 40 : BWindow(rect, name, B_DOCUMENT_WINDOW, 0) 41 { 42 BRect rctframe = Bounds(); 43 rctframe.right -= B_V_SCROLL_BAR_WIDTH; 44 rctframe.bottom -= B_H_SCROLL_BAR_HEIGHT; 45 46 BRect rcttext = rctframe; 47 rcttext.OffsetTo(B_ORIGIN); 48 49 fptextView = new BTextView(rctframe, "infoview", rcttext, 50 B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_PULSE_NEEDED); 51 52 BScrollView *psv; 53 AddChild(psv = new BScrollView("infoscrollview", fptextView, 54 B_FOLLOW_ALL_SIDES, 0, true, true)); 55 fptextView->MakeEditable(false); 56 //fptextView->MakeResizable(true); 57 fptextView->SetText(text); 58 59 SetSizeLimits(100, 10000, 100, 10000); 60 61 Show(); 62 } 63 64 InfoWindow::~InfoWindow() 65 { 66 } 67 68 // 69 // TextWindow::FrameResized 70 // 71 // Adjust the size of the BTextView's text rectangle 72 // when the window is resized. 73 // 74 void 75 InfoWindow::FrameResized(float width, float height) 76 { 77 BRect rcttext = fptextView->TextRect(); 78 79 rcttext.right = rcttext.left + (width - B_V_SCROLL_BAR_WIDTH); 80 fptextView->SetTextRect(rcttext); 81 } 82 83 void 84 InfoWindow::MessageReceived(BMessage *pmsg) 85 { 86 switch (pmsg->what) { 87 case M_INFO_WINDOW_TEXT: 88 { 89 // App is telling me new info has arrived; 90 // The view text must be updated 91 BString bstr; 92 if (pmsg->FindString("text", &bstr) == B_OK) 93 fptextView->SetText(bstr.String()); 94 break; 95 } 96 97 default: 98 BWindow::MessageReceived(pmsg); 99 break; 100 } 101 } 102 103 void 104 InfoWindow::Quit() 105 { 106 // tell the app to forget about this window 107 be_app->PostMessage(M_INFO_WINDOW_QUIT); 108 BWindow::Quit(); 109 } 110