2 * Copyright (c) 1999-2000, Eric Moon.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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
35 #include "DormantNodeWindow.h"
37 #include "DormantNodeView.h"
39 #include "RouteWindow.h"
42 #include <Application.h>
45 #include <ScrollBar.h>
47 __USE_CORTEX_NAMESPACE
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 // -------------------------------------------------------- //
57 // -------------------------------------------------------- //
59 // this should be a bit more sophisticated :)
60 const BRect
DormantNodeWindow::s_initFrame(500.0, 350.0, 640.0, 480.0);
62 // -------------------------------------------------------- //
64 // -------------------------------------------------------- //
66 DormantNodeWindow::DormantNodeWindow(
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
),
75 D_ALLOC(("DormantNodeWindow::DormantNodeWindow()\n"));
78 AddToSubset(m_parent
);
80 // Create the ListView
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
;
89 BScrollBar
*scrollBar
;
90 AddChild(scrollBar
= new BScrollBar(r
, "", m_listView
, 0.0, 0.0, B_VERTICAL
));
97 DormantNodeWindow::~DormantNodeWindow() {
98 D_ALLOC(("DormantNodeWindow::~DormantNodeWindow()\n"));
102 // -------------------------------------------------------- //
104 // -------------------------------------------------------- //
106 bool DormantNodeWindow::QuitRequested() {
107 D_HOOK(("DormantNodeWindow::QuitRequested()\n"));
109 // [e.moon 29nov99] the RouteWindow is now responsible for
111 m_parent
->PostMessage(RouteWindow::M_TOGGLE_DORMANT_NODE_WINDOW
);
115 void DormantNodeWindow::Zoom(
119 D_HOOK(("DormantNodeWindow::Zoom()\n"));
123 BScreen
screen(this);
124 if (!screen
.Frame().Contains(Frame())) {
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
);
134 _constrainToScreen();
137 // resize to the most recent manual size
138 ResizeTo(m_manualSize
.Width(), m_manualSize
.Height());
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 --