1 /* 2 Open Tracker License 3 4 Terms and Conditions 5 6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 8 Permission is hereby granted, free of charge, to any person obtaining a copy of 9 this software and associated documentation files (the "Software"), to deal in 10 the Software without restriction, including without limitation the rights to 11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12 of the Software, and to permit persons to whom the Software is furnished to do 13 so, subject to the following conditions: 14 15 The above copyright notice and this permission notice applies to all licensees 16 and shall be included in all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 25 Except as contained in this notice, the name of Be Incorporated shall not be 26 used in advertising or otherwise to promote the sale, use or other dealings in 27 this Software without prior written authorization from Be Incorporated. 28 29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 30 of Be Incorporated in the United States and other countries. Other brand product 31 names are registered trademarks or trademarks of their respective holders. 32 All rights reserved. 33 */ 34 35 36 #include "SettingsViews.h" 37 #include "TrackerSettings.h" 38 #include "TrackerSettingsWindow.h" 39 40 #include <CheckBox.h> 41 42 43 const BPoint kSettingsWindowOffset(30, 30); 44 const float kSettingsWindowsWidth = 370; 45 const float kSettingsWindowsHeight = 270; 46 47 const uint32 kSettingsViewChanged = 'Svch'; 48 const uint32 kDefaultsButtonPressed = 'Apbp'; 49 const uint32 kRevertButtonPressed = 'Rebp'; 50 51 52 TrackerSettingsWindow::TrackerSettingsWindow() 53 : BWindow(BRect(kSettingsWindowOffset.x, kSettingsWindowOffset.y, 54 kSettingsWindowOffset.x + kSettingsWindowsWidth, 55 kSettingsWindowOffset.y + kSettingsWindowsHeight), 56 "Tracker Settings", B_TITLED_WINDOW, B_NOT_MINIMIZABLE | B_NOT_RESIZABLE 57 | B_NO_WORKSPACE_ACTIVATION | B_NOT_ANCHORED_ON_ACTIVATE 58 | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) 59 { 60 BView *backgroundView = new BView(Bounds(), "Background", B_FOLLOW_ALL_SIDES, 0); 61 62 backgroundView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 63 AddChild(backgroundView); 64 65 const float kBorderDistance = 12; 66 const float kListViewWidth = 90; 67 const float kListViewHeight = kSettingsWindowsHeight - 2 * kBorderDistance; 68 const float kBoxWidth = kSettingsWindowsWidth - kListViewWidth - 3 * (kBorderDistance - 1); 69 const float kBoxHeight = kListViewHeight - 30; 70 71 BRect listViewRect(kBorderDistance, kBorderDistance, kBorderDistance + kListViewWidth, 72 kBorderDistance + kListViewHeight); 73 74 BBox *borderBox = new BBox(listViewRect.InsetByCopy(-2, -2)); 75 76 backgroundView->AddChild(borderBox); 77 78 listViewRect.OffsetTo(2, 2); 79 listViewRect.right -= 1; 80 81 fSettingsTypeListView = new BListView(listViewRect, "List View"); 82 83 borderBox->AddChild(fSettingsTypeListView); 84 85 fSettingsContainerBox = new BBox(BRect(kBorderDistance + kListViewWidth + kBorderDistance, 86 kBorderDistance, kBorderDistance + kListViewWidth + kBorderDistance + kBoxWidth, 87 kBorderDistance + kBoxHeight)); 88 89 backgroundView->AddChild(fSettingsContainerBox); 90 91 const float kButtonTop = fSettingsContainerBox->Frame().bottom + kBorderDistance; 92 const float kDefaultsButtonLeft = fSettingsContainerBox->Frame().left; 93 const float kButtonWidth = 45; 94 const float kButtonHeight = 20; 95 96 fDefaultsButton = new BButton(BRect(kDefaultsButtonLeft, kButtonTop, 97 kDefaultsButtonLeft + kButtonWidth, kButtonTop + kButtonHeight), 98 "Defaults", "Defaults", new BMessage(kDefaultsButtonPressed)); 99 100 backgroundView->AddChild(fDefaultsButton); 101 102 fDefaultsButton->ResizeToPreferred(); 103 fDefaultsButton->SetEnabled(true); 104 105 fRevertButton = new BButton(BRect(fDefaultsButton->Frame().right + kBorderDistance, 106 kButtonTop, fDefaultsButton->Frame().right + kBorderDistance + kButtonWidth, kButtonTop 107 + kButtonHeight), "Revert", "Revert", new BMessage(kRevertButtonPressed)); 108 109 fRevertButton->SetEnabled(false); 110 fRevertButton->ResizeToPreferred(); 111 backgroundView->AddChild(fRevertButton); 112 113 BRect SettingsViewSize = fSettingsContainerBox->Bounds().InsetByCopy(5, 5); 114 115 SettingsViewSize.top += 10; 116 117 fSettingsTypeListView->AddItem(new SettingsItem("Desktop", 118 new DesktopSettingsView(SettingsViewSize))); 119 fSettingsTypeListView->AddItem(new SettingsItem("Windows", 120 new WindowsSettingsView(SettingsViewSize))); 121 fSettingsTypeListView->AddItem(new SettingsItem("File Panel", 122 new FilePanelSettingsView(SettingsViewSize))); 123 fSettingsTypeListView->AddItem(new SettingsItem("Time Format", 124 new TimeFormatSettingsView(SettingsViewSize))); 125 fSettingsTypeListView->AddItem(new SettingsItem("Trash", 126 new TrashSettingsView(SettingsViewSize))); 127 fSettingsTypeListView->AddItem(new SettingsItem("Volume Icons", 128 new SpaceBarSettingsView(SettingsViewSize))); 129 130 fSettingsTypeListView->SetSelectionMessage(new BMessage(kSettingsViewChanged)); 131 132 fSettingsTypeListView->Select(0); 133 } 134 135 136 bool 137 TrackerSettingsWindow::QuitRequested() 138 { 139 bool isHidden = false; 140 141 if (Lock()) { 142 isHidden = IsHidden(); 143 Unlock(); 144 } else 145 return true; 146 147 if (isHidden) 148 return true; 149 150 Hide(); 151 152 return false; 153 } 154 155 156 void 157 TrackerSettingsWindow::MessageReceived(BMessage *message) 158 { 159 switch (message->what) { 160 case kSettingsContentsModified: 161 HandleChangedContents(); 162 break; 163 164 case kDefaultsButtonPressed: 165 HandlePressedDefaultsButton(); 166 break; 167 168 case kRevertButtonPressed: 169 HandlePressedRevertButton(); 170 break; 171 172 case kSettingsViewChanged: 173 HandleChangedSettingsView(); 174 break; 175 176 default: 177 _inherited::MessageReceived(message); 178 } 179 } 180 181 182 void 183 TrackerSettingsWindow::Show() 184 { 185 if (Lock()) { 186 int32 itemCount = fSettingsTypeListView->CountItems(); 187 188 for (int32 i = 0; i < itemCount; i++) { 189 ViewAt(i)->RecordRevertSettings(); 190 ViewAt(i)->ShowCurrentSettings(); 191 } 192 193 fSettingsTypeListView->Invalidate(); 194 195 Unlock(); 196 } 197 _inherited::Show(); 198 } 199 200 201 SettingsView * 202 TrackerSettingsWindow::ViewAt(int32 i) 203 { 204 if (!Lock()) 205 return NULL; 206 207 SettingsItem *item = dynamic_cast<SettingsItem*>(fSettingsTypeListView->ItemAt(i)); 208 209 Unlock(); 210 211 return item->View(); 212 } 213 214 215 void 216 TrackerSettingsWindow::HandleChangedContents() 217 { 218 int32 itemCount = fSettingsTypeListView->CountItems(); 219 220 bool revertable = false; 221 222 for (int32 i = 0; i < itemCount; i++) { 223 revertable |= ViewAt(i)->IsRevertable(); 224 } 225 226 fSettingsTypeListView->Invalidate(); 227 fRevertButton->SetEnabled(revertable); 228 229 TrackerSettings().SaveSettings(false); 230 } 231 232 233 void 234 TrackerSettingsWindow::HandlePressedDefaultsButton() 235 { 236 int32 itemCount = fSettingsTypeListView->CountItems(); 237 238 for (int32 i = 0; i < itemCount; i++) 239 ViewAt(i)->SetDefaults(); 240 241 HandleChangedContents(); 242 } 243 244 245 void 246 TrackerSettingsWindow::HandlePressedRevertButton() 247 { 248 int32 itemCount = fSettingsTypeListView->CountItems(); 249 250 for (int32 i = 0; i < itemCount; i++) { 251 if (ViewAt(i)->IsRevertable()) 252 ViewAt(i)->Revert(); 253 } 254 255 HandleChangedContents(); 256 } 257 258 259 void 260 TrackerSettingsWindow::HandleChangedSettingsView() 261 { 262 int32 currentSelection = fSettingsTypeListView->CurrentSelection(); 263 if (currentSelection < 0) 264 return; 265 266 BView *oldView = fSettingsContainerBox->ChildAt(0); 267 268 if (oldView) 269 oldView->RemoveSelf(); 270 271 SettingsItem *selectedItem = 272 dynamic_cast<SettingsItem*>(fSettingsTypeListView->ItemAt(currentSelection)); 273 274 if (selectedItem) { 275 fSettingsContainerBox->SetLabel(selectedItem->Text()); 276 selectedItem->View()->SetViewColor(fSettingsContainerBox->ViewColor()); 277 fSettingsContainerBox->AddChild(selectedItem->View()); 278 } 279 } 280 281 282 // #pragma mark - 283 284 285 SettingsItem::SettingsItem(const char *label, SettingsView *view) 286 : BStringItem(label), 287 fSettingsView(view) 288 { 289 } 290 291 292 void 293 SettingsItem::DrawItem(BView *owner, BRect rect, bool drawEverything) 294 { 295 const rgb_color kModifiedColor = {0, 0, 255, 0}; 296 const rgb_color kBlack = {0, 0, 0, 0}; 297 const rgb_color kSelectedColor = {140, 140, 140, 0}; 298 299 if (fSettingsView) { 300 bool isRevertable = fSettingsView->IsRevertable(); 301 bool isSelected = IsSelected(); 302 303 if (isSelected || drawEverything) { 304 rgb_color color; 305 if (isSelected) 306 color = kSelectedColor; 307 else 308 color = owner->ViewColor(); 309 310 owner->SetHighColor(color); 311 owner->SetLowColor(color); 312 owner->FillRect(rect); 313 } 314 315 if (isRevertable) 316 owner->SetHighColor(kModifiedColor); 317 else 318 owner->SetHighColor(kBlack); 319 320 owner->MovePenTo(rect.left + 4, rect.bottom - 2); 321 322 owner->DrawString(Text()); 323 324 owner->SetHighColor(kBlack); 325 owner->SetLowColor(owner->ViewColor()); 326 } 327 } 328 329 330 SettingsView * 331 SettingsItem::View() 332 { 333 return fSettingsView; 334 } 335