1c284bb0fSMatt Madia /*
2c284bb0fSMatt Madia * Copyright (c) 1999-2000, Eric Moon.
3c284bb0fSMatt Madia * All rights reserved.
4c284bb0fSMatt Madia *
5c284bb0fSMatt Madia * Redistribution and use in source and binary forms, with or without
6c284bb0fSMatt Madia * modification, are permitted provided that the following conditions
7c284bb0fSMatt Madia * are met:
8c284bb0fSMatt Madia *
9c284bb0fSMatt Madia * 1. Redistributions of source code must retain the above copyright
10c284bb0fSMatt Madia * notice, this list of conditions, and the following disclaimer.
11c284bb0fSMatt Madia *
12c284bb0fSMatt Madia * 2. Redistributions in binary form must reproduce the above copyright
13c284bb0fSMatt Madia * notice, this list of conditions, and the following disclaimer in the
14c284bb0fSMatt Madia * documentation and/or other materials provided with the distribution.
15c284bb0fSMatt Madia *
16c284bb0fSMatt Madia * 3. The name of the author may not be used to endorse or promote products
17c284bb0fSMatt Madia * derived from this software without specific prior written permission.
18c284bb0fSMatt Madia *
19c284bb0fSMatt Madia * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20c284bb0fSMatt Madia * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21c284bb0fSMatt Madia * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22c284bb0fSMatt Madia * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23c284bb0fSMatt Madia * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24c284bb0fSMatt Madia * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25c284bb0fSMatt Madia * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26c284bb0fSMatt Madia * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27c284bb0fSMatt Madia * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28c284bb0fSMatt Madia * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29c284bb0fSMatt Madia */
30c284bb0fSMatt Madia
31c284bb0fSMatt Madia
32a0795c6fSMarcus Overhagen // DormantNodeWindow.cpp
33a0795c6fSMarcus Overhagen // e.moon 2jun99
34a0795c6fSMarcus Overhagen
35a0795c6fSMarcus Overhagen #include "DormantNodeWindow.h"
36a0795c6fSMarcus Overhagen // DormantNodeView
37a0795c6fSMarcus Overhagen #include "DormantNodeView.h"
38a0795c6fSMarcus Overhagen
39a0795c6fSMarcus Overhagen #include "RouteWindow.h"
40a0795c6fSMarcus Overhagen
41a0795c6fSMarcus Overhagen // Application Kit
42a0795c6fSMarcus Overhagen #include <Application.h>
432cba2d56SDancsó Róbert // Locale Kit
442cba2d56SDancsó Róbert #undef B_CATALOG
452cba2d56SDancsó Róbert #define B_CATALOG (&sCatalog)
462cba2d56SDancsó Róbert #include <Catalog.h>
47a0795c6fSMarcus Overhagen // Interface Kit
48a0795c6fSMarcus Overhagen #include <Screen.h>
49a0795c6fSMarcus Overhagen #include <ScrollBar.h>
50a0795c6fSMarcus Overhagen
512cba2d56SDancsó Róbert #undef B_TRANSLATION_CONTEXT
522cba2d56SDancsó Róbert #define B_TRANSLATION_CONTEXT "CortexDormantNodeWindow"
532cba2d56SDancsó Róbert
54a0795c6fSMarcus Overhagen __USE_CORTEX_NAMESPACE
55a0795c6fSMarcus Overhagen
56a0795c6fSMarcus Overhagen #include <Debug.h>
57a0795c6fSMarcus Overhagen #define D_ALLOC(x) //PRINT (x) // ctor/dtor
58a0795c6fSMarcus Overhagen #define D_HOOK(x) //PRINT (x) // BWindow impl.
59a0795c6fSMarcus Overhagen #define D_MESSAGE(x) //PRINT (x) // MessageReceived()
60a0795c6fSMarcus Overhagen #define D_INTERNAL(x) //PRINT (x) // internal operations
61a0795c6fSMarcus Overhagen
62*bf6a2a2bSNiels Sascha Reedijk static BCatalog sCatalog("x-vnd.Cortex.DormantNodeView");
632cba2d56SDancsó Róbert
64a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
65a0795c6fSMarcus Overhagen // constants
66a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
67a0795c6fSMarcus Overhagen
68a0795c6fSMarcus Overhagen // this should be a bit more sophisticated :)
69a0795c6fSMarcus Overhagen const BRect DormantNodeWindow::s_initFrame(500.0, 350.0, 640.0, 480.0);
70a0795c6fSMarcus Overhagen
71a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
72a0795c6fSMarcus Overhagen // ctor/dtor
73a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
74a0795c6fSMarcus Overhagen
DormantNodeWindow(BWindow * parent)75a0795c6fSMarcus Overhagen DormantNodeWindow::DormantNodeWindow(
76a0795c6fSMarcus Overhagen BWindow* parent)
772cba2d56SDancsó Róbert : BWindow(s_initFrame,
782cba2d56SDancsó Róbert B_TRANSLATE("Media add-ons"),
79a0795c6fSMarcus Overhagen B_FLOATING_WINDOW_LOOK,
80a0795c6fSMarcus Overhagen B_FLOATING_SUBSET_WINDOW_FEEL,
81a0795c6fSMarcus Overhagen B_WILL_ACCEPT_FIRST_CLICK|B_AVOID_FOCUS|B_ASYNCHRONOUS_CONTROLS),
82a0795c6fSMarcus Overhagen m_parent(parent),
83a0795c6fSMarcus Overhagen m_zoomed(false),
84a0795c6fSMarcus Overhagen m_zooming(false) {
85a0795c6fSMarcus Overhagen D_ALLOC(("DormantNodeWindow::DormantNodeWindow()\n"));
86a0795c6fSMarcus Overhagen
87a0795c6fSMarcus Overhagen ASSERT(m_parent);
88a0795c6fSMarcus Overhagen AddToSubset(m_parent);
89a0795c6fSMarcus Overhagen
90a0795c6fSMarcus Overhagen // Create the ListView
91a0795c6fSMarcus Overhagen BRect r = Bounds();
92a0795c6fSMarcus Overhagen r.right -= B_V_SCROLL_BAR_WIDTH;
93a0795c6fSMarcus Overhagen m_listView = new DormantNodeView(r, "Dormant Node ListView", B_FOLLOW_ALL_SIDES);
94a0795c6fSMarcus Overhagen
95a0795c6fSMarcus Overhagen // Add the vertical ScrollBar
96a0795c6fSMarcus Overhagen r.left = r.right + 1.0;
97a0795c6fSMarcus Overhagen r.right = r.left + B_V_SCROLL_BAR_WIDTH;
98a0795c6fSMarcus Overhagen r.InsetBy(0.0, -1.0);
99f30ba677SMurai Takashi AddChild(new BScrollBar(r, "", m_listView, 0.0, 0.0, B_VERTICAL));
100a0795c6fSMarcus Overhagen
101a0795c6fSMarcus Overhagen // Add the ListView
102a0795c6fSMarcus Overhagen AddChild(m_listView);
103a0795c6fSMarcus Overhagen _constrainToScreen();
104a0795c6fSMarcus Overhagen }
105a0795c6fSMarcus Overhagen
~DormantNodeWindow()106a0795c6fSMarcus Overhagen DormantNodeWindow::~DormantNodeWindow() {
107a0795c6fSMarcus Overhagen D_ALLOC(("DormantNodeWindow::~DormantNodeWindow()\n"));
108a0795c6fSMarcus Overhagen
109a0795c6fSMarcus Overhagen }
110a0795c6fSMarcus Overhagen
111a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
112a0795c6fSMarcus Overhagen // BWindow impl.
113a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
114a0795c6fSMarcus Overhagen
QuitRequested()115a0795c6fSMarcus Overhagen bool DormantNodeWindow::QuitRequested() {
116a0795c6fSMarcus Overhagen D_HOOK(("DormantNodeWindow::QuitRequested()\n"));
117a0795c6fSMarcus Overhagen
118a0795c6fSMarcus Overhagen // [e.moon 29nov99] the RouteWindow is now responsible for
119a0795c6fSMarcus Overhagen // closing me
120a0795c6fSMarcus Overhagen m_parent->PostMessage(RouteWindow::M_TOGGLE_DORMANT_NODE_WINDOW);
121a0795c6fSMarcus Overhagen return false;
122a0795c6fSMarcus Overhagen }
123a0795c6fSMarcus Overhagen
Zoom(BPoint origin,float width,float height)124a0795c6fSMarcus Overhagen void DormantNodeWindow::Zoom(
125a0795c6fSMarcus Overhagen BPoint origin,
126a0795c6fSMarcus Overhagen float width,
127a0795c6fSMarcus Overhagen float height) {
128a0795c6fSMarcus Overhagen D_HOOK(("DormantNodeWindow::Zoom()\n"));
129a0795c6fSMarcus Overhagen
130a0795c6fSMarcus Overhagen m_zooming = true;
131a0795c6fSMarcus Overhagen
132a0795c6fSMarcus Overhagen BScreen screen(this);
133a0795c6fSMarcus Overhagen if (!screen.Frame().Contains(Frame())) {
134a0795c6fSMarcus Overhagen m_zoomed = false;
135a0795c6fSMarcus Overhagen }
136a0795c6fSMarcus Overhagen
137a0795c6fSMarcus Overhagen if (!m_zoomed) {
138a0795c6fSMarcus Overhagen // resize to the ideal size
139a0795c6fSMarcus Overhagen m_manualSize = Bounds();
140a0795c6fSMarcus Overhagen m_listView->GetPreferredSize(&width, &height);
141a0795c6fSMarcus Overhagen ResizeTo(width + B_V_SCROLL_BAR_WIDTH, height);
142a0795c6fSMarcus Overhagen m_zoomed = true;
143a0795c6fSMarcus Overhagen _constrainToScreen();
144a0795c6fSMarcus Overhagen }
145a0795c6fSMarcus Overhagen else {
146a0795c6fSMarcus Overhagen // resize to the most recent manual size
147a0795c6fSMarcus Overhagen ResizeTo(m_manualSize.Width(), m_manualSize.Height());
148a0795c6fSMarcus Overhagen m_zoomed = false;
149a0795c6fSMarcus Overhagen }
150a0795c6fSMarcus Overhagen }
151a0795c6fSMarcus Overhagen
152a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
153a0795c6fSMarcus Overhagen // internal operations
154a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
155a0795c6fSMarcus Overhagen
_constrainToScreen()156a0795c6fSMarcus Overhagen void DormantNodeWindow::_constrainToScreen() {
157a0795c6fSMarcus Overhagen D_INTERNAL(("DormantNodeWindow::_constrainToScreen()\n"));
158a0795c6fSMarcus Overhagen
159a0795c6fSMarcus Overhagen BScreen screen(this);
160a0795c6fSMarcus Overhagen BRect screenRect = screen.Frame();
161a0795c6fSMarcus Overhagen BRect windowRect = Frame();
162a0795c6fSMarcus Overhagen
163a0795c6fSMarcus Overhagen // if the window is outside the screen rect
164a0795c6fSMarcus Overhagen // move it to the default position
165a0795c6fSMarcus Overhagen if (!screenRect.Intersects(windowRect)) {
166a0795c6fSMarcus Overhagen windowRect.OffsetTo(screenRect.LeftTop());
167a0795c6fSMarcus Overhagen MoveTo(windowRect.LeftTop());
168a0795c6fSMarcus Overhagen windowRect = Frame();
169a0795c6fSMarcus Overhagen }
170a0795c6fSMarcus Overhagen
171a0795c6fSMarcus Overhagen // if the window is larger than the screen rect
172a0795c6fSMarcus Overhagen // resize it to fit at each side
173a0795c6fSMarcus Overhagen if (!screenRect.Contains(windowRect)) {
174a0795c6fSMarcus Overhagen if (windowRect.left < screenRect.left) {
175a0795c6fSMarcus Overhagen windowRect.left = screenRect.left + 5.0;
176a0795c6fSMarcus Overhagen MoveTo(windowRect.LeftTop());
177a0795c6fSMarcus Overhagen windowRect = Frame();
178a0795c6fSMarcus Overhagen }
179a0795c6fSMarcus Overhagen if (windowRect.top < screenRect.top) {
180a0795c6fSMarcus Overhagen windowRect.top = screenRect.top + 5.0;
181a0795c6fSMarcus Overhagen MoveTo(windowRect.LeftTop());
182a0795c6fSMarcus Overhagen windowRect = Frame();
183a0795c6fSMarcus Overhagen }
184a0795c6fSMarcus Overhagen if (windowRect.right > screenRect.right) {
185a0795c6fSMarcus Overhagen windowRect.right = screenRect.right - 5.0;
186a0795c6fSMarcus Overhagen }
187a0795c6fSMarcus Overhagen if (windowRect.bottom > screenRect.bottom) {
188a0795c6fSMarcus Overhagen windowRect.bottom = screenRect.bottom - 5.0;
189a0795c6fSMarcus Overhagen }
190a0795c6fSMarcus Overhagen ResizeTo(windowRect.Width(), windowRect.Height());
191a0795c6fSMarcus Overhagen }
192a0795c6fSMarcus Overhagen }
193a0795c6fSMarcus Overhagen
194a0795c6fSMarcus Overhagen // END -- DormantNodeWindow.cpp --
195