vfs: check userland buffers before reading them.
[haiku.git] / src / apps / cortex / InfoView / InfoWindow.cpp
blob082d61dd1b2e9f08eb1fba643563d6cfe2092210
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 // InfoWindow.cpp
34 #include "InfoWindow.h"
36 // Interface Kit
37 #include <Screen.h>
38 #include <ScrollBar.h>
39 #include <View.h>
41 __USE_CORTEX_NAMESPACE
43 #include <Debug.h>
44 #define D_ALLOC(x) //PRINT (x)
45 #define D_HOOK(x) //PRINT (x)
46 #define D_INTERNAL(x) //PRINT (x)
47 #define D_MESSAGE(x) //PRINT (x)
49 // -------------------------------------------------------- //
50 // ctor/dtor
51 // -------------------------------------------------------- //
53 InfoWindow::InfoWindow(
54 BRect frame)
55 : BWindow(frame,
56 "", B_DOCUMENT_WINDOW, 0),
57 m_zoomed(false),
58 m_zooming(false) {
59 D_ALLOC(("InfoWindow::InfoWindow()\n"));
63 InfoWindow::~InfoWindow() {
64 D_ALLOC(("InfoWindow::~InfoWindow()\n"));
68 // -------------------------------------------------------- //
69 // BWindow impl
70 // -------------------------------------------------------- //
72 void
73 InfoWindow::FrameResized(
74 float width,
75 float height) {
76 D_HOOK(("InfoWindow::FrameResized()\n"));
78 if (!m_zooming) {
79 m_zoomed = false;
81 else {
82 m_zooming = false;
86 void
87 InfoWindow::Show() {
88 D_HOOK(("InfoWindow::Show()\n"));
90 _constrainToScreen();
91 m_manualSize = Bounds().OffsetToCopy(0.0, 0.0);
93 BWindow::Show();
96 void
97 InfoWindow::Zoom(
98 BPoint origin,
99 float width,
100 float height) {
101 D_HOOK(("InfoWindow::Zoom()\n"));
103 m_zooming = true;
105 BScreen screen(this);
106 if (!screen.Frame().Contains(Frame())) {
107 m_zoomed = false;
110 if (!m_zoomed) {
111 // resize to the ideal size
112 m_manualSize = Bounds();
113 float width, height;
114 FindView("InfoView")->GetPreferredSize(&width, &height);
115 width += B_V_SCROLL_BAR_WIDTH;
116 ResizeTo(width, height);
117 _constrainToScreen();
118 m_zoomed = true;
120 else {
121 // resize to the most recent manual size
122 ResizeTo(m_manualSize.Width(), m_manualSize.Height());
123 m_zoomed = false;
127 // -------------------------------------------------------- //
128 // internal operations
129 // -------------------------------------------------------- //
131 void
132 InfoWindow::_constrainToScreen() {
133 D_INTERNAL(("InfoWindow::_constrainToScreen()\n"));
135 BScreen screen(this);
136 BRect screenRect = screen.Frame();
137 BRect windowRect = Frame();
139 // if the window is outside the screen rect
140 // move it to the default position
141 if (!screenRect.Intersects(windowRect)) {
142 windowRect.OffsetTo(screenRect.LeftTop());
143 MoveTo(windowRect.LeftTop());
144 windowRect = Frame();
147 // if the window is larger than the screen rect
148 // resize it to fit at each side
149 if (!screenRect.Contains(windowRect)) {
150 if (windowRect.left < screenRect.left) {
151 windowRect.left = screenRect.left + 5.0;
152 MoveTo(windowRect.LeftTop());
153 windowRect = Frame();
155 if (windowRect.top < screenRect.top) {
156 windowRect.top = screenRect.top + 5.0;
157 MoveTo(windowRect.LeftTop());
158 windowRect = Frame();
160 if (windowRect.right > screenRect.right) {
161 windowRect.right = screenRect.right - 5.0;
163 if (windowRect.bottom > screenRect.bottom) {
164 windowRect.bottom = screenRect.bottom - 5.0;
166 ResizeTo(windowRect.Width(), windowRect.Height());
170 // END -- InfoWindow.cpp --