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