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 "SplitLayout.h" 9 10 11 // constructor 12 BSplitView::BSplitView(enum orientation orientation, float spacing) 13 : BView(NULL, 14 B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_INVALIDATE_AFTER_LAYOUT, 15 fSplitLayout = new BSplitLayout(orientation, spacing)) 16 { 17 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 18 } 19 20 // destructor 21 BSplitView::~BSplitView() 22 { 23 } 24 25 // Spacing 26 float 27 BSplitView::Spacing() const 28 { 29 return fSplitLayout->Spacing(); 30 } 31 32 // SetSpacing 33 void 34 BSplitView::SetSpacing(float spacing) 35 { 36 fSplitLayout->SetSpacing(spacing); 37 } 38 39 // Orientation 40 orientation 41 BSplitView::Orientation() const 42 { 43 return fSplitLayout->Orientation(); 44 } 45 46 // SetOrientation 47 void 48 BSplitView::SetOrientation(enum orientation orientation) 49 { 50 fSplitLayout->SetOrientation(orientation); 51 } 52 53 // SplitterSize 54 float 55 BSplitView::SplitterSize() const 56 { 57 return fSplitLayout->SplitterSize(); 58 } 59 60 // SetSplitterSize 61 void 62 BSplitView::SetSplitterSize(float size) 63 { 64 fSplitLayout->SetSplitterSize(size); 65 } 66 67 // SetCollapsible 68 void 69 BSplitView::SetCollapsible(bool collapsible) 70 { 71 fSplitLayout->SetCollapsible(collapsible); 72 } 73 74 // SetCollapsible 75 void 76 BSplitView::SetCollapsible(int32 index, bool collapsible) 77 { 78 fSplitLayout->SetCollapsible(index, collapsible); 79 } 80 81 // SetCollapsible 82 void 83 BSplitView::SetCollapsible(int32 first, int32 last, bool collapsible) 84 { 85 fSplitLayout->SetCollapsible(first, last, collapsible); 86 } 87 88 // AddChild 89 void 90 BSplitView::AddChild(BView* child, BView* sibling) 91 { 92 BView::AddChild(child, sibling); 93 } 94 95 // AddChild 96 bool 97 BSplitView::AddChild(BView* child, float weight) 98 { 99 return fSplitLayout->AddView(child, weight); 100 } 101 102 // AddChild 103 bool 104 BSplitView::AddChild(int32 index, BView* child, float weight) 105 { 106 return fSplitLayout->AddView(index, child, weight); 107 } 108 109 // AddChild 110 bool 111 BSplitView::AddChild(BLayoutItem* child) 112 { 113 return fSplitLayout->AddItem(child); 114 } 115 116 // AddChild 117 bool 118 BSplitView::AddChild(BLayoutItem* child, float weight) 119 { 120 return fSplitLayout->AddItem(child, weight); 121 } 122 123 // AddChild 124 bool 125 BSplitView::AddChild(int32 index, BLayoutItem* child, float weight) 126 { 127 return fSplitLayout->AddItem(index, child, weight); 128 } 129 130 // Draw 131 void 132 BSplitView::Draw(BRect updateRect) 133 { 134 // draw the splitters 135 int32 draggedSplitterIndex = fSplitLayout->DraggedSplitter(); 136 int32 count = fSplitLayout->CountItems(); 137 for (int32 i = 0; i < count - 1; i++) { 138 BRect frame = fSplitLayout->SplitterItemFrame(i); 139 DrawSplitter(frame, Orientation(), draggedSplitterIndex == i); 140 } 141 } 142 143 // MouseDown 144 void 145 BSplitView::MouseDown(BPoint where) 146 { 147 SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); 148 149 if (fSplitLayout->StartDraggingSplitter(where)) 150 Invalidate(); 151 } 152 153 // MouseUp 154 void 155 BSplitView::MouseUp(BPoint where) 156 { 157 if (fSplitLayout->StopDraggingSplitter()) { 158 Relayout(); 159 Invalidate(); 160 } 161 } 162 163 // MouseMoved 164 void 165 BSplitView::MouseMoved(BPoint where, uint32 transit, const BMessage* message) 166 { 167 int32 splitterIndex = fSplitLayout->DraggedSplitter(); 168 if (splitterIndex >= 0) { 169 BRect oldFrame = fSplitLayout->SplitterItemFrame(splitterIndex); 170 if (fSplitLayout->DragSplitter(where)) { 171 Invalidate(oldFrame); 172 Invalidate(fSplitLayout->SplitterItemFrame(splitterIndex)); 173 } 174 } 175 } 176 177 // SetLayout 178 void 179 BSplitView::SetLayout(BLayout* layout) 180 { 181 // not allowed 182 } 183 184 // DrawSplitter 185 void 186 BSplitView::DrawSplitter(BRect frame, enum orientation orientation, 187 bool pressed) 188 { 189 rgb_color black = { 0, 0, 0, 255 }; 190 rgb_color white = { 255, 255, 255, 255 }; 191 192 SetHighColor(pressed ? white : black); 193 194 FillRect(frame); 195 } 196