BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / cortex / DormantNodeView / DormantNodeWindow.cpp
blob52f3aed55df8613e2dc7400a0167b56118588dfd
1 /*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
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.
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.
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.
32 // DormantNodeWindow.cpp
33 // e.moon 2jun99
35 #include "DormantNodeWindow.h"
36 // DormantNodeView
37 #include "DormantNodeView.h"
39 #include "RouteWindow.h"
41 // Application Kit
42 #include <Application.h>
43 // Interface Kit
44 #include <Screen.h>
45 #include <ScrollBar.h>
47 __USE_CORTEX_NAMESPACE
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
55 // -------------------------------------------------------- //
56 // constants
57 // -------------------------------------------------------- //
59 // this should be a bit more sophisticated :)
60 const BRect DormantNodeWindow::s_initFrame(500.0, 350.0, 640.0, 480.0);
62 // -------------------------------------------------------- //
63 // ctor/dtor
64 // -------------------------------------------------------- //
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"));
77 ASSERT(m_parent);
78 AddToSubset(m_parent);
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);
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));
92 // Add the ListView
93 AddChild(m_listView);
94 _constrainToScreen();
97 DormantNodeWindow::~DormantNodeWindow() {
98 D_ALLOC(("DormantNodeWindow::~DormantNodeWindow()\n"));
102 // -------------------------------------------------------- //
103 // BWindow impl.
104 // -------------------------------------------------------- //
106 bool DormantNodeWindow::QuitRequested() {
107 D_HOOK(("DormantNodeWindow::QuitRequested()\n"));
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;
115 void DormantNodeWindow::Zoom(
116 BPoint origin,
117 float width,
118 float height) {
119 D_HOOK(("DormantNodeWindow::Zoom()\n"));
121 m_zooming = true;
123 BScreen screen(this);
124 if (!screen.Frame().Contains(Frame())) {
125 m_zoomed = false;
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();
136 else {
137 // resize to the most recent manual size
138 ResizeTo(m_manualSize.Width(), m_manualSize.Height());
139 m_zoomed = false;
143 // -------------------------------------------------------- //
144 // internal operations
145 // -------------------------------------------------------- //
147 void DormantNodeWindow::_constrainToScreen() {
148 D_INTERNAL(("DormantNodeWindow::_constrainToScreen()\n"));
150 BScreen screen(this);
151 BRect screenRect = screen.Frame();
152 BRect windowRect = Frame();
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();
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();
170 if (windowRect.top < screenRect.top) {
171 windowRect.top = screenRect.top + 5.0;
172 MoveTo(windowRect.LeftTop());
173 windowRect = Frame();
175 if (windowRect.right > screenRect.right) {
176 windowRect.right = screenRect.right - 5.0;
178 if (windowRect.bottom > screenRect.bottom) {
179 windowRect.bottom = screenRect.bottom - 5.0;
181 ResizeTo(windowRect.Width(), windowRect.Height());
185 // END -- DormantNodeWindow.cpp --