1 // InfoWindow.cpp 2 3 #include "InfoWindow.h" 4 5 // Interface Kit 6 #include <Screen.h> 7 #include <ScrollBar.h> 8 #include <View.h> 9 10 __USE_CORTEX_NAMESPACE 11 12 #include <Debug.h> 13 #define D_ALLOC(x) //PRINT (x) 14 #define D_HOOK(x) //PRINT (x) 15 #define D_INTERNAL(x) //PRINT (x) 16 #define D_MESSAGE(x) //PRINT (x) 17 18 // -------------------------------------------------------- // 19 // ctor/dtor 20 // -------------------------------------------------------- // 21 22 InfoWindow::InfoWindow( 23 BRect frame) 24 : BWindow(frame, 25 "", B_DOCUMENT_WINDOW, 0), 26 m_zoomed(false), 27 m_zooming(false) { 28 D_ALLOC(("InfoWindow::InfoWindow()\n")); 29 30 } 31 32 InfoWindow::~InfoWindow() { 33 D_ALLOC(("InfoWindow::~InfoWindow()\n")); 34 35 } 36 37 // -------------------------------------------------------- // 38 // BWindow impl 39 // -------------------------------------------------------- // 40 41 void 42 InfoWindow::FrameResized( 43 float width, 44 float height) { 45 D_HOOK(("InfoWindow::FrameResized()\n")); 46 47 if (!m_zooming) { 48 m_zoomed = false; 49 } 50 else { 51 m_zooming = false; 52 } 53 } 54 55 void 56 InfoWindow::Show() { 57 D_HOOK(("InfoWindow::Show()\n")); 58 59 _constrainToScreen(); 60 m_manualSize = Bounds().OffsetToCopy(0.0, 0.0); 61 62 BWindow::Show(); 63 } 64 65 void 66 InfoWindow::Zoom( 67 BPoint origin, 68 float width, 69 float height) { 70 D_HOOK(("InfoWindow::Zoom()\n")); 71 72 m_zooming = true; 73 74 BScreen screen(this); 75 if (!screen.Frame().Contains(Frame())) { 76 m_zoomed = false; 77 } 78 79 if (!m_zoomed) { 80 // resize to the ideal size 81 m_manualSize = Bounds(); 82 float width, height; 83 FindView("InfoView")->GetPreferredSize(&width, &height); 84 width += B_V_SCROLL_BAR_WIDTH; 85 ResizeTo(width, height); 86 _constrainToScreen(); 87 m_zoomed = true; 88 } 89 else { 90 // resize to the most recent manual size 91 ResizeTo(m_manualSize.Width(), m_manualSize.Height()); 92 m_zoomed = false; 93 } 94 } 95 96 // -------------------------------------------------------- // 97 // internal operations 98 // -------------------------------------------------------- // 99 100 void 101 InfoWindow::_constrainToScreen() { 102 D_INTERNAL(("InfoWindow::_constrainToScreen()\n")); 103 104 BScreen screen(this); 105 BRect screenRect = screen.Frame(); 106 BRect windowRect = Frame(); 107 108 // if the window is outside the screen rect 109 // move it to the default position 110 if (!screenRect.Intersects(windowRect)) { 111 windowRect.OffsetTo(screenRect.LeftTop()); 112 MoveTo(windowRect.LeftTop()); 113 windowRect = Frame(); 114 } 115 116 // if the window is larger than the screen rect 117 // resize it to fit at each side 118 if (!screenRect.Contains(windowRect)) { 119 if (windowRect.left < screenRect.left) { 120 windowRect.left = screenRect.left + 5.0; 121 MoveTo(windowRect.LeftTop()); 122 windowRect = Frame(); 123 } 124 if (windowRect.top < screenRect.top) { 125 windowRect.top = screenRect.top + 5.0; 126 MoveTo(windowRect.LeftTop()); 127 windowRect = Frame(); 128 } 129 if (windowRect.right > screenRect.right) { 130 windowRect.right = screenRect.right - 5.0; 131 } 132 if (windowRect.bottom > screenRect.bottom) { 133 windowRect.bottom = screenRect.bottom - 5.0; 134 } 135 ResizeTo(windowRect.Width(), windowRect.Height()); 136 } 137 } 138 139 // END -- InfoWindow.cpp -- 140