1 /* 2 * Copyright (c) 1999-2000, Eric Moon. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions, and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions, and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * 3. The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 32 // InfoWindow.cpp 33 34 #include "InfoWindow.h" 35 36 // Interface Kit 37 #include <Screen.h> 38 #include <ScrollBar.h> 39 #include <View.h> 40 41 __USE_CORTEX_NAMESPACE 42 43 #include <Debug.h> 44 #define D_ALLOC(x) //PRINT (x) 45 #define D_HOOK(x) //PRINT (x) 46 #define D_INTERNAL(x) //PRINT (x) 47 #define D_MESSAGE(x) //PRINT (x) 48 49 // -------------------------------------------------------- // 50 // ctor/dtor 51 // -------------------------------------------------------- // 52 53 InfoWindow::InfoWindow( 54 BRect frame) 55 : BWindow(frame, 56 "", B_DOCUMENT_WINDOW, 0), 57 m_zoomed(false), 58 m_zooming(false) { 59 D_ALLOC(("InfoWindow::InfoWindow()\n")); 60 61 } 62 63 InfoWindow::~InfoWindow() { 64 D_ALLOC(("InfoWindow::~InfoWindow()\n")); 65 66 } 67 68 // -------------------------------------------------------- // 69 // BWindow impl 70 // -------------------------------------------------------- // 71 72 void 73 InfoWindow::FrameResized( 74 float width, 75 float height) { 76 D_HOOK(("InfoWindow::FrameResized()\n")); 77 78 if (!m_zooming) { 79 m_zoomed = false; 80 } 81 else { 82 m_zooming = false; 83 } 84 } 85 86 void 87 InfoWindow::Show() { 88 D_HOOK(("InfoWindow::Show()\n")); 89 90 _constrainToScreen(); 91 m_manualSize = Bounds().OffsetToCopy(0.0, 0.0); 92 93 BWindow::Show(); 94 } 95 96 void 97 InfoWindow::Zoom( 98 BPoint origin, 99 float width, 100 float height) { 101 D_HOOK(("InfoWindow::Zoom()\n")); 102 103 m_zooming = true; 104 105 BScreen screen(this); 106 if (!screen.Frame().Contains(Frame())) { 107 m_zoomed = false; 108 } 109 110 if (!m_zoomed) { 111 // resize to the ideal size 112 m_manualSize = Bounds(); 113 float width, height; 114 FindView("InfoView")->GetPreferredSize(&width, &height); 115 width += B_V_SCROLL_BAR_WIDTH; 116 ResizeTo(width, height); 117 _constrainToScreen(); 118 m_zoomed = true; 119 } 120 else { 121 // resize to the most recent manual size 122 ResizeTo(m_manualSize.Width(), m_manualSize.Height()); 123 m_zoomed = false; 124 } 125 } 126 127 // -------------------------------------------------------- // 128 // internal operations 129 // -------------------------------------------------------- // 130 131 void 132 InfoWindow::_constrainToScreen() { 133 D_INTERNAL(("InfoWindow::_constrainToScreen()\n")); 134 135 BScreen screen(this); 136 BRect screenRect = screen.Frame(); 137 BRect windowRect = Frame(); 138 139 // if the window is outside the screen rect 140 // move it to the default position 141 if (!screenRect.Intersects(windowRect)) { 142 windowRect.OffsetTo(screenRect.LeftTop()); 143 MoveTo(windowRect.LeftTop()); 144 windowRect = Frame(); 145 } 146 147 // if the window is larger than the screen rect 148 // resize it to fit at each side 149 if (!screenRect.Contains(windowRect)) { 150 if (windowRect.left < screenRect.left) { 151 windowRect.left = screenRect.left + 5.0; 152 MoveTo(windowRect.LeftTop()); 153 windowRect = Frame(); 154 } 155 if (windowRect.top < screenRect.top) { 156 windowRect.top = screenRect.top + 5.0; 157 MoveTo(windowRect.LeftTop()); 158 windowRect = Frame(); 159 } 160 if (windowRect.right > screenRect.right) { 161 windowRect.right = screenRect.right - 5.0; 162 } 163 if (windowRect.bottom > screenRect.bottom) { 164 windowRect.bottom = screenRect.bottom - 5.0; 165 } 166 ResizeTo(windowRect.Width(), windowRect.Height()); 167 } 168 } 169 170 // END -- InfoWindow.cpp -- 171