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 // DormantNodeWindow.cpp 33 // e.moon 2jun99 34 35 #include "DormantNodeWindow.h" 36 // DormantNodeView 37 #include "DormantNodeView.h" 38 39 #include "RouteWindow.h" 40 41 // Application Kit 42 #include <Application.h> 43 // Interface Kit 44 #include <Screen.h> 45 #include <ScrollBar.h> 46 47 __USE_CORTEX_NAMESPACE 48 49 #include <Debug.h> 50 #define D_ALLOC(x) //PRINT (x) // ctor/dtor 51 #define D_HOOK(x) //PRINT (x) // BWindow impl. 52 #define D_MESSAGE(x) //PRINT (x) // MessageReceived() 53 #define D_INTERNAL(x) //PRINT (x) // internal operations 54 55 // -------------------------------------------------------- // 56 // constants 57 // -------------------------------------------------------- // 58 59 // this should be a bit more sophisticated :) 60 const BRect DormantNodeWindow::s_initFrame(500.0, 350.0, 640.0, 480.0); 61 62 // -------------------------------------------------------- // 63 // ctor/dtor 64 // -------------------------------------------------------- // 65 66 DormantNodeWindow::DormantNodeWindow( 67 BWindow* parent) 68 : BWindow(s_initFrame, "Media add-ons", 69 B_FLOATING_WINDOW_LOOK, 70 B_FLOATING_SUBSET_WINDOW_FEEL, 71 B_WILL_ACCEPT_FIRST_CLICK|B_AVOID_FOCUS|B_ASYNCHRONOUS_CONTROLS), 72 m_parent(parent), 73 m_zoomed(false), 74 m_zooming(false) { 75 D_ALLOC(("DormantNodeWindow::DormantNodeWindow()\n")); 76 77 ASSERT(m_parent); 78 AddToSubset(m_parent); 79 80 // Create the ListView 81 BRect r = Bounds(); 82 r.right -= B_V_SCROLL_BAR_WIDTH; 83 m_listView = new DormantNodeView(r, "Dormant Node ListView", B_FOLLOW_ALL_SIDES); 84 85 // Add the vertical ScrollBar 86 r.left = r.right + 1.0; 87 r.right = r.left + B_V_SCROLL_BAR_WIDTH; 88 r.InsetBy(0.0, -1.0); 89 BScrollBar *scrollBar; 90 AddChild(scrollBar = new BScrollBar(r, "", m_listView, 0.0, 0.0, B_VERTICAL)); 91 92 // Add the ListView 93 AddChild(m_listView); 94 _constrainToScreen(); 95 } 96 97 DormantNodeWindow::~DormantNodeWindow() { 98 D_ALLOC(("DormantNodeWindow::~DormantNodeWindow()\n")); 99 100 } 101 102 // -------------------------------------------------------- // 103 // BWindow impl. 104 // -------------------------------------------------------- // 105 106 bool DormantNodeWindow::QuitRequested() { 107 D_HOOK(("DormantNodeWindow::QuitRequested()\n")); 108 109 // [e.moon 29nov99] the RouteWindow is now responsible for 110 // closing me 111 m_parent->PostMessage(RouteWindow::M_TOGGLE_DORMANT_NODE_WINDOW); 112 return false; 113 } 114 115 void DormantNodeWindow::Zoom( 116 BPoint origin, 117 float width, 118 float height) { 119 D_HOOK(("DormantNodeWindow::Zoom()\n")); 120 121 m_zooming = true; 122 123 BScreen screen(this); 124 if (!screen.Frame().Contains(Frame())) { 125 m_zoomed = false; 126 } 127 128 if (!m_zoomed) { 129 // resize to the ideal size 130 m_manualSize = Bounds(); 131 m_listView->GetPreferredSize(&width, &height); 132 ResizeTo(width + B_V_SCROLL_BAR_WIDTH, height); 133 m_zoomed = true; 134 _constrainToScreen(); 135 } 136 else { 137 // resize to the most recent manual size 138 ResizeTo(m_manualSize.Width(), m_manualSize.Height()); 139 m_zoomed = false; 140 } 141 } 142 143 // -------------------------------------------------------- // 144 // internal operations 145 // -------------------------------------------------------- // 146 147 void DormantNodeWindow::_constrainToScreen() { 148 D_INTERNAL(("DormantNodeWindow::_constrainToScreen()\n")); 149 150 BScreen screen(this); 151 BRect screenRect = screen.Frame(); 152 BRect windowRect = Frame(); 153 154 // if the window is outside the screen rect 155 // move it to the default position 156 if (!screenRect.Intersects(windowRect)) { 157 windowRect.OffsetTo(screenRect.LeftTop()); 158 MoveTo(windowRect.LeftTop()); 159 windowRect = Frame(); 160 } 161 162 // if the window is larger than the screen rect 163 // resize it to fit at each side 164 if (!screenRect.Contains(windowRect)) { 165 if (windowRect.left < screenRect.left) { 166 windowRect.left = screenRect.left + 5.0; 167 MoveTo(windowRect.LeftTop()); 168 windowRect = Frame(); 169 } 170 if (windowRect.top < screenRect.top) { 171 windowRect.top = screenRect.top + 5.0; 172 MoveTo(windowRect.LeftTop()); 173 windowRect = Frame(); 174 } 175 if (windowRect.right > screenRect.right) { 176 windowRect.right = screenRect.right - 5.0; 177 } 178 if (windowRect.bottom > screenRect.bottom) { 179 windowRect.bottom = screenRect.bottom - 5.0; 180 } 181 ResizeTo(windowRect.Width(), windowRect.Height()); 182 } 183 } 184 185 // END -- DormantNodeWindow.cpp -- 186