btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / cortex / ParameterView / ParameterContainerView.cpp
blob11a4f194afbf001e5faf080751902e10ab197bc8
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 // ParameterContainerView.cpp
34 #include "ParameterContainerView.h"
36 // Interface Kit
37 #include <ScrollBar.h>
38 #include <View.h>
40 __USE_CORTEX_NAMESPACE
42 #include <Debug.h>
43 #define D_ALLOC(x) //PRINT (x)
44 #define D_HOOK(x) //PRINT (x)
45 #define D_INTERNAL(x) //PRINT (x)
47 // -------------------------------------------------------- //
48 // *** ctor/dtor
49 // -------------------------------------------------------- //
51 ParameterContainerView::ParameterContainerView(
52 BRect dataRect,
53 BView *target) :
54 BView(
55 target->Frame(),
56 "ParameterContainerView",
57 B_FOLLOW_ALL_SIDES,
58 B_FRAME_EVENTS|B_WILL_DRAW),
59 m_target(target),
60 m_dataRect(dataRect),
61 m_boundsRect(Bounds()),
62 m_hScroll(0),
63 m_vScroll(0) {
64 D_ALLOC(("ParameterContainerView::ParameterContainerView()\n"));
66 BView* wrapper = new BView(
67 m_target->Bounds(), 0, B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_FRAME_EVENTS);
68 m_target->SetResizingMode(B_FOLLOW_LEFT|B_FOLLOW_TOP);
69 m_target->MoveTo(B_ORIGIN);
70 wrapper->AddChild(m_target);
71 AddChild(wrapper);
73 BRect b = wrapper->Frame();
75 ResizeTo(
76 b.Width() + B_V_SCROLL_BAR_WIDTH,
77 b.Height() + B_H_SCROLL_BAR_HEIGHT);
79 BRect hsBounds = b;
80 hsBounds.left--;
81 hsBounds.top = hsBounds.bottom + 1;
82 hsBounds.right++;
83 hsBounds.bottom = hsBounds.top + B_H_SCROLL_BAR_HEIGHT + 1;
84 m_hScroll = new BScrollBar(
85 hsBounds,
86 "hScrollBar",
87 m_target,
88 0, 0, B_HORIZONTAL);
89 AddChild(m_hScroll);
91 BRect vsBounds = b;
92 vsBounds.left = vsBounds.right + 1;
93 vsBounds.top--;
94 vsBounds.right = vsBounds.right + B_V_SCROLL_BAR_WIDTH + 1;
95 vsBounds.bottom++;
96 m_vScroll = new BScrollBar(
97 vsBounds,
98 "vScrollBar",
99 m_target,
100 0, 0, B_VERTICAL);
101 AddChild(m_vScroll);
104 SetViewColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_1_TINT));
105 _updateScrollBars();
108 ParameterContainerView::~ParameterContainerView() {
109 D_ALLOC(("ParameterContainerView::~ParameterContainerView()\n"));
113 // -------------------------------------------------------- //
114 // *** BScrollView impl
115 // -------------------------------------------------------- //
117 void ParameterContainerView::FrameResized(
118 float width,
119 float height) {
120 D_HOOK(("ParameterContainerView::FrameResized()\n"));
122 BView::FrameResized(width, height);
123 // BRect b = ChildAt(0)->Frame();
124 // printf("param view:\n");
125 // b.PrintToStream();
126 // printf("hScroll:\n");
127 // m_target->ScrollBar(B_HORIZONTAL)->Frame().PrintToStream();
128 // printf("vScroll:\n");
129 // m_target->ScrollBar(B_VERTICAL)->Frame().PrintToStream();
130 // fprintf(stderr, "m: %.1f,%.1f c: %.1f,%.1f)\n", width, height, b.Width(),b.Height());
132 if(height > m_boundsRect.Height()) {
133 Invalidate(BRect(
134 m_boundsRect.left, m_boundsRect.bottom, m_boundsRect.right, m_boundsRect.top+height));
137 if(width > m_boundsRect.Width()) {
138 Invalidate(BRect(
139 m_boundsRect.right, m_boundsRect.top, m_boundsRect.left+width, m_boundsRect.bottom));
142 m_boundsRect = Bounds();
143 _updateScrollBars();
146 // -------------------------------------------------------- //
147 // *** internal operations
148 // -------------------------------------------------------- //
150 void ParameterContainerView::_updateScrollBars() {
151 D_INTERNAL(("ParameterContainerView::_updateScrollBars()\n"));
153 // fetch the vertical ScrollBar
154 if (m_vScroll) {
155 float height = Bounds().Height() - B_H_SCROLL_BAR_HEIGHT;
156 // Disable the ScrollBar if the window is large enough to display
157 // the entire parameter view
158 D_INTERNAL((" -> dataRect.Height() = %f scrollView.Height() = %f\n", m_dataRect.Height(), height));
159 if (height > m_dataRect.Height()) {
160 D_INTERNAL((" -> disable vertical scroll bar\n"));
161 m_vScroll->SetRange(0.0, 0.0);
162 m_vScroll->SetProportion(1.0);
164 else {
165 D_INTERNAL((" -> enable vertical scroll bar\n"));
166 m_vScroll->SetRange(m_dataRect.top, m_dataRect.bottom - height);
167 m_vScroll->SetProportion(height / m_dataRect.Height());
170 if (m_hScroll) {
171 float width = Bounds().Width() - B_V_SCROLL_BAR_WIDTH;
172 // Disable the ScrollBar if the view is large enough to display
173 // the entire data-rect
174 D_INTERNAL((" -> dataRect.Width() = %f scrollView.Width() = %f\n", m_dataRect.Width(), width));
175 if (width > m_dataRect.Width()) {
176 D_INTERNAL((" -> disable horizontal scroll bar\n"));
177 m_hScroll->SetRange(0.0, 0.0);
178 m_hScroll->SetProportion(1.0);
180 else {
181 D_INTERNAL((" -> enable horizontal scroll bar\n"));
182 m_hScroll->SetRange(m_dataRect.left, m_dataRect.right - width);
183 m_hScroll->SetProportion(width / m_dataRect.Width());
188 // END -- ParameterContainerView.cpp --