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 // ParameterContainerView.cpp
34 #include "ParameterContainerView.h"
37 #include <ScrollBar.h>
40 __USE_CORTEX_NAMESPACE
43 #define D_ALLOC(x) //PRINT (x)
44 #define D_HOOK(x) //PRINT (x)
45 #define D_INTERNAL(x) //PRINT (x)
47 // -------------------------------------------------------- //
49 // -------------------------------------------------------- //
51 ParameterContainerView::ParameterContainerView(
56 "ParameterContainerView",
58 B_FRAME_EVENTS
|B_WILL_DRAW
),
61 m_boundsRect(Bounds()),
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
);
73 BRect b
= wrapper
->Frame();
76 b
.Width() + B_V_SCROLL_BAR_WIDTH
,
77 b
.Height() + B_H_SCROLL_BAR_HEIGHT
);
81 hsBounds
.top
= hsBounds
.bottom
+ 1;
83 hsBounds
.bottom
= hsBounds
.top
+ B_H_SCROLL_BAR_HEIGHT
+ 1;
84 m_hScroll
= new BScrollBar(
92 vsBounds
.left
= vsBounds
.right
+ 1;
94 vsBounds
.right
= vsBounds
.right
+ B_V_SCROLL_BAR_WIDTH
+ 1;
96 m_vScroll
= new BScrollBar(
104 SetViewColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR
), B_LIGHTEN_1_TINT
));
108 ParameterContainerView::~ParameterContainerView() {
109 D_ALLOC(("ParameterContainerView::~ParameterContainerView()\n"));
113 // -------------------------------------------------------- //
114 // *** BScrollView impl
115 // -------------------------------------------------------- //
117 void ParameterContainerView::FrameResized(
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()) {
134 m_boundsRect
.left
, m_boundsRect
.bottom
, m_boundsRect
.right
, m_boundsRect
.top
+height
));
137 if(width
> m_boundsRect
.Width()) {
139 m_boundsRect
.right
, m_boundsRect
.top
, m_boundsRect
.left
+width
, m_boundsRect
.bottom
));
142 m_boundsRect
= Bounds();
146 // -------------------------------------------------------- //
147 // *** internal operations
148 // -------------------------------------------------------- //
150 void ParameterContainerView::_updateScrollBars() {
151 D_INTERNAL(("ParameterContainerView::_updateScrollBars()\n"));
153 // fetch the vertical ScrollBar
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);
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());
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);
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 --