tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / kits / interface / SplitView.cpp
blob6a174d5db635210c0738f24a4d065ff699ef50b3
1 /*
2 * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
6 #include <SplitView.h>
8 #include <stdio.h>
10 #include <Archivable.h>
11 #include <ControlLook.h>
12 #include <Cursor.h>
14 #include "SplitLayout.h"
17 BSplitView::BSplitView(orientation orientation, float spacing)
19 BView(NULL,
20 B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_INVALIDATE_AFTER_LAYOUT,
21 fSplitLayout = new BSplitLayout(orientation, spacing))
23 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
27 BSplitView::BSplitView(BMessage* from)
29 BView(BUnarchiver::PrepareArchive(from)),
30 fSplitLayout(NULL)
32 BUnarchiver(from).Finish();
36 BSplitView::~BSplitView()
41 void
42 BSplitView::SetInsets(float left, float top, float right, float bottom)
44 left = BControlLook::ComposeSpacing(left);
45 top = BControlLook::ComposeSpacing(top);
46 right = BControlLook::ComposeSpacing(right);
47 bottom = BControlLook::ComposeSpacing(bottom);
49 fSplitLayout->SetInsets(left, top, right, bottom);
53 void
54 BSplitView::SetInsets(float horizontal, float vertical)
56 horizontal = BControlLook::ComposeSpacing(horizontal);
57 vertical = BControlLook::ComposeSpacing(vertical);
58 fSplitLayout->SetInsets(horizontal, vertical, horizontal, vertical);
62 void
63 BSplitView::SetInsets(float insets)
65 insets = BControlLook::ComposeSpacing(insets);
66 fSplitLayout->SetInsets(insets, insets, insets, insets);
70 void
71 BSplitView::GetInsets(float* left, float* top, float* right,
72 float* bottom) const
74 fSplitLayout->GetInsets(left, top, right, bottom);
78 float
79 BSplitView::Spacing() const
81 return fSplitLayout->Spacing();
85 void
86 BSplitView::SetSpacing(float spacing)
88 fSplitLayout->SetSpacing(spacing);
92 orientation
93 BSplitView::Orientation() const
95 return fSplitLayout->Orientation();
99 void
100 BSplitView::SetOrientation(orientation orientation)
102 fSplitLayout->SetOrientation(orientation);
106 float
107 BSplitView::SplitterSize() const
109 return fSplitLayout->SplitterSize();
113 void
114 BSplitView::SetSplitterSize(float size)
116 fSplitLayout->SetSplitterSize(size);
120 int32
121 BSplitView::CountItems() const
123 return fSplitLayout->CountItems();
127 float
128 BSplitView::ItemWeight(int32 index) const
130 return fSplitLayout->ItemWeight(index);
134 float
135 BSplitView::ItemWeight(BLayoutItem* item) const
137 return fSplitLayout->ItemWeight(item);
141 void
142 BSplitView::SetItemWeight(int32 index, float weight, bool invalidateLayout)
144 fSplitLayout->SetItemWeight(index, weight, invalidateLayout);
148 void
149 BSplitView::SetItemWeight(BLayoutItem* item, float weight)
151 fSplitLayout->SetItemWeight(item, weight);
155 bool
156 BSplitView::IsCollapsible(int32 index) const
158 return fSplitLayout->IsCollapsible(index);
162 void
163 BSplitView::SetCollapsible(bool collapsible)
165 fSplitLayout->SetCollapsible(collapsible);
169 void
170 BSplitView::SetCollapsible(int32 index, bool collapsible)
172 fSplitLayout->SetCollapsible(index, collapsible);
176 void
177 BSplitView::SetCollapsible(int32 first, int32 last, bool collapsible)
179 fSplitLayout->SetCollapsible(first, last, collapsible);
183 bool
184 BSplitView::IsItemCollapsed(int32 index) const
186 return fSplitLayout->IsItemCollapsed(index);
190 void
191 BSplitView::SetItemCollapsed(int32 index, bool collapsed)
193 fSplitLayout->SetItemCollapsed(index, collapsed);
197 void
198 BSplitView::AddChild(BView* child, BView* sibling)
200 BView::AddChild(child, sibling);
204 bool
205 BSplitView::AddChild(BView* child, float weight)
207 return fSplitLayout->AddView(child, weight);
211 bool
212 BSplitView::AddChild(int32 index, BView* child, float weight)
214 return fSplitLayout->AddView(index, child, weight);
218 bool
219 BSplitView::AddChild(BLayoutItem* child)
221 return fSplitLayout->AddItem(child);
225 bool
226 BSplitView::AddChild(BLayoutItem* child, float weight)
228 return fSplitLayout->AddItem(child, weight);
232 bool
233 BSplitView::AddChild(int32 index, BLayoutItem* child, float weight)
235 return fSplitLayout->AddItem(index, child, weight);
239 void
240 BSplitView::Draw(BRect updateRect)
242 // draw the splitters
243 int32 draggedSplitterIndex = fSplitLayout->DraggedSplitter();
244 int32 count = fSplitLayout->CountItems();
245 for (int32 i = 0; i < count - 1; i++) {
246 BRect frame = fSplitLayout->SplitterItemFrame(i);
247 DrawSplitter(frame, updateRect, Orientation(),
248 draggedSplitterIndex == i);
253 void
254 BSplitView::DrawAfterChildren(BRect r)
256 return BView::DrawAfterChildren(r);
260 void
261 BSplitView::MouseDown(BPoint where)
263 SetMouseEventMask(B_POINTER_EVENTS,
264 B_LOCK_WINDOW_FOCUS | B_SUSPEND_VIEW_FOCUS);
266 if (fSplitLayout->StartDraggingSplitter(where))
267 Invalidate();
271 void
272 BSplitView::MouseUp(BPoint where)
274 if (fSplitLayout->StopDraggingSplitter()) {
275 Relayout();
276 Invalidate();
281 void
282 BSplitView::MouseMoved(BPoint where, uint32 transit, const BMessage* message)
284 BCursor cursor(B_CURSOR_ID_SYSTEM_DEFAULT);
286 int32 splitterIndex = fSplitLayout->DraggedSplitter();
288 if (splitterIndex >= 0 || fSplitLayout->IsAboveSplitter(where)) {
289 if (Orientation() == B_VERTICAL)
290 cursor = BCursor(B_CURSOR_ID_RESIZE_NORTH_SOUTH);
291 else
292 cursor = BCursor(B_CURSOR_ID_RESIZE_EAST_WEST);
295 if (splitterIndex >= 0) {
296 BRect oldFrame = fSplitLayout->SplitterItemFrame(splitterIndex);
297 if (fSplitLayout->DragSplitter(where)) {
298 Invalidate(oldFrame);
299 Invalidate(fSplitLayout->SplitterItemFrame(splitterIndex));
303 SetViewCursor(&cursor, true);
307 void
308 BSplitView::MessageReceived(BMessage* message)
310 return BView::MessageReceived(message);
314 void
315 BSplitView::SetLayout(BLayout* layout)
317 // not allowed
321 status_t
322 BSplitView::Archive(BMessage* into, bool deep) const
324 return BView::Archive(into, deep);
328 status_t
329 BSplitView::AllArchived(BMessage* archive) const
331 return BView::AllArchived(archive);
335 status_t
336 BSplitView::AllUnarchived(const BMessage* from)
338 status_t err = BView::AllUnarchived(from);
339 if (err == B_OK) {
340 fSplitLayout = dynamic_cast<BSplitLayout*>(GetLayout());
341 if (!fSplitLayout && GetLayout())
342 return B_BAD_TYPE;
343 else if (!fSplitLayout)
344 return B_ERROR;
346 return err;
350 BArchivable*
351 BSplitView::Instantiate(BMessage* from)
353 if (validate_instantiation(from, "BSplitView"))
354 return new BSplitView(from);
355 return NULL;
359 void
360 BSplitView::DrawSplitter(BRect frame, const BRect& updateRect,
361 orientation orientation, bool pressed)
363 _DrawDefaultSplitter(this, frame, updateRect, orientation, pressed);
367 void
368 BSplitView::_DrawDefaultSplitter(BView* view, BRect frame,
369 const BRect& updateRect, orientation orientation, bool pressed)
371 uint32 flags = pressed ? BControlLook::B_ACTIVATED : 0;
372 be_control_look->DrawSplitter(view, frame, updateRect, view->ViewColor(),
373 orientation, flags, 0);
377 status_t
378 BSplitView::Perform(perform_code d, void* arg)
380 return BView::Perform(d, arg);
384 void BSplitView::_ReservedSplitView1() {}
385 void BSplitView::_ReservedSplitView2() {}
386 void BSplitView::_ReservedSplitView3() {}
387 void BSplitView::_ReservedSplitView4() {}
388 void BSplitView::_ReservedSplitView5() {}
389 void BSplitView::_ReservedSplitView6() {}
390 void BSplitView::_ReservedSplitView7() {}
391 void BSplitView::_ReservedSplitView8() {}
392 void BSplitView::_ReservedSplitView9() {}
393 void BSplitView::_ReservedSplitView10() {}