1 /* 2 * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 #include <SplitView.h> 7 8 #include <stdio.h> 9 10 #include <ControlLook.h> 11 #include <Cursor.h> 12 13 #include "SplitLayout.h" 14 15 16 BSplitView::BSplitView(enum orientation orientation, float spacing) 17 : 18 BView(NULL, 19 B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_INVALIDATE_AFTER_LAYOUT, 20 fSplitLayout = new BSplitLayout(orientation, spacing)) 21 { 22 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 23 } 24 25 26 BSplitView::~BSplitView() 27 { 28 } 29 30 31 void 32 BSplitView::SetInsets(float left, float top, float right, float bottom) 33 { 34 fSplitLayout->SetInsets(left, top, right, bottom); 35 } 36 37 38 void 39 BSplitView::GetInsets(float* left, float* top, float* right, 40 float* bottom) const 41 { 42 fSplitLayout->GetInsets(left, top, right, bottom); 43 } 44 45 46 float 47 BSplitView::Spacing() const 48 { 49 return fSplitLayout->Spacing(); 50 } 51 52 53 void 54 BSplitView::SetSpacing(float spacing) 55 { 56 fSplitLayout->SetSpacing(spacing); 57 } 58 59 60 orientation 61 BSplitView::Orientation() const 62 { 63 return fSplitLayout->Orientation(); 64 } 65 66 67 void 68 BSplitView::SetOrientation(enum orientation orientation) 69 { 70 fSplitLayout->SetOrientation(orientation); 71 } 72 73 74 float 75 BSplitView::SplitterSize() const 76 { 77 return fSplitLayout->SplitterSize(); 78 } 79 80 81 void 82 BSplitView::SetSplitterSize(float size) 83 { 84 fSplitLayout->SetSplitterSize(size); 85 } 86 87 88 void 89 BSplitView::SetCollapsible(bool collapsible) 90 { 91 fSplitLayout->SetCollapsible(collapsible); 92 } 93 94 95 void 96 BSplitView::SetCollapsible(int32 index, bool collapsible) 97 { 98 fSplitLayout->SetCollapsible(index, collapsible); 99 } 100 101 102 void 103 BSplitView::SetCollapsible(int32 first, int32 last, bool collapsible) 104 { 105 fSplitLayout->SetCollapsible(first, last, collapsible); 106 } 107 108 109 void 110 BSplitView::AddChild(BView* child, BView* sibling) 111 { 112 BView::AddChild(child, sibling); 113 } 114 115 116 bool 117 BSplitView::AddChild(BView* child, float weight) 118 { 119 return fSplitLayout->AddView(child, weight); 120 } 121 122 123 bool 124 BSplitView::AddChild(int32 index, BView* child, float weight) 125 { 126 return fSplitLayout->AddView(index, child, weight); 127 } 128 129 130 bool 131 BSplitView::AddChild(BLayoutItem* child) 132 { 133 return fSplitLayout->AddItem(child); 134 } 135 136 137 bool 138 BSplitView::AddChild(BLayoutItem* child, float weight) 139 { 140 return fSplitLayout->AddItem(child, weight); 141 } 142 143 144 bool 145 BSplitView::AddChild(int32 index, BLayoutItem* child, float weight) 146 { 147 return fSplitLayout->AddItem(index, child, weight); 148 } 149 150 151 void 152 BSplitView::Draw(BRect updateRect) 153 { 154 // draw the splitters 155 int32 draggedSplitterIndex = fSplitLayout->DraggedSplitter(); 156 int32 count = fSplitLayout->CountItems(); 157 for (int32 i = 0; i < count - 1; i++) { 158 BRect frame = fSplitLayout->SplitterItemFrame(i); 159 DrawSplitter(frame, updateRect, Orientation(), 160 draggedSplitterIndex == i); 161 } 162 } 163 164 165 void 166 BSplitView::MouseDown(BPoint where) 167 { 168 SetMouseEventMask(B_POINTER_EVENTS, 169 B_LOCK_WINDOW_FOCUS | B_SUSPEND_VIEW_FOCUS); 170 171 if (fSplitLayout->StartDraggingSplitter(where)) 172 Invalidate(); 173 } 174 175 176 void 177 BSplitView::MouseUp(BPoint where) 178 { 179 if (fSplitLayout->StopDraggingSplitter()) { 180 Relayout(); 181 Invalidate(); 182 } 183 } 184 185 186 void 187 BSplitView::MouseMoved(BPoint where, uint32 transit, const BMessage* message) 188 { 189 BCursor cursor(B_CURSOR_ID_SYSTEM_DEFAULT); 190 191 int32 splitterIndex = fSplitLayout->DraggedSplitter(); 192 193 if (splitterIndex >= 0 || fSplitLayout->IsAboveSplitter(where)) { 194 if (Orientation() == B_VERTICAL) 195 cursor = BCursor(B_CURSOR_ID_RESIZE_NORTH_SOUTH); 196 else 197 cursor = BCursor(B_CURSOR_ID_RESIZE_EAST_WEST); 198 } 199 200 if (splitterIndex >= 0) { 201 BRect oldFrame = fSplitLayout->SplitterItemFrame(splitterIndex); 202 if (fSplitLayout->DragSplitter(where)) { 203 Invalidate(oldFrame); 204 Invalidate(fSplitLayout->SplitterItemFrame(splitterIndex)); 205 } 206 } 207 208 SetViewCursor(&cursor, true); 209 } 210 211 212 void 213 BSplitView::SetLayout(BLayout* layout) 214 { 215 // not allowed 216 } 217 218 219 void 220 BSplitView::DrawSplitter(BRect frame, const BRect& updateRect, 221 enum orientation orientation, bool pressed) 222 { 223 _DrawDefaultSplitter(this, frame, updateRect, orientation, pressed); 224 } 225 226 227 void 228 BSplitView::_DrawDefaultSplitter(BView* view, BRect frame, 229 const BRect& updateRect, enum orientation orientation, bool pressed) 230 { 231 uint32 flags = pressed ? BControlLook::B_ACTIVATED : 0; 232 be_control_look->DrawSplitter(view, frame, updateRect, view->ViewColor(), 233 orientation, flags, 0); 234 } 235