1/* 2 * Copyright 2001-2006, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Marcus Overhagen 7 * Axel Dörfler, axeld@pinc-software.de 8 */ 9 10 11#include "DefaultMediaTheme.h" 12#include "debug.h" 13 14#include <MediaTheme.h> 15#include <StringView.h> 16#include <Locker.h> 17#include <Autolock.h> 18 19#include <string.h> 20 21 22static BLocker sLock("media theme lock"); 23 24BMediaTheme* BMediaTheme::sDefaultTheme; 25 26 27BMediaTheme::~BMediaTheme() 28{ 29 CALLED(); 30 31 free(fName); 32 free(fInfo); 33} 34 35 36const char * 37BMediaTheme::Name() 38{ 39 return fName; 40} 41 42 43const char * 44BMediaTheme::Info() 45{ 46 return fInfo; 47} 48 49 50int32 51BMediaTheme::ID() 52{ 53 return fID; 54} 55 56 57bool 58BMediaTheme::GetRef(entry_ref* ref) 59{ 60 if (!fIsAddOn || ref == NULL) 61 return false; 62 63 *ref = fAddOnRef; 64 return true; 65} 66 67 68BView * 69BMediaTheme::ViewFor(BParameterWeb* web, const BRect* hintRect, 70 BMediaTheme* usingTheme) 71{ 72 CALLED(); 73 74 // use default theme if none was specified 75 if (usingTheme == NULL) 76 usingTheme = PreferredTheme(); 77 78 if (usingTheme == NULL) { 79 BStringView* view = new BStringView(BRect(0, 0, 200, 30), "", 80 "No BMediaTheme available, sorry!"); 81 view->ResizeToPreferred(); 82 return view; 83 } 84 85 return usingTheme->MakeViewFor(web, hintRect); 86} 87 88 89status_t 90BMediaTheme::SetPreferredTheme(BMediaTheme* defaultTheme) 91{ 92 CALLED(); 93 94 // ToDo: this method should probably set some global settings file 95 // to make the new preferred theme available to all applications 96 97 BAutolock locker(sLock); 98 99 if (defaultTheme == NULL) { 100 // if the current preferred theme is not the default media theme, 101 // delete it, and set it back to the default 102 if (dynamic_cast<BPrivate::DefaultMediaTheme *>(sDefaultTheme) == NULL) 103 sDefaultTheme = new BPrivate::DefaultMediaTheme(); 104 105 return B_OK; 106 } 107 108 // this method takes possession of the BMediaTheme passed, even 109 // if it fails, so it has to delete it 110 if (defaultTheme != sDefaultTheme) 111 delete sDefaultTheme; 112 113 sDefaultTheme = defaultTheme; 114 115 return B_OK; 116} 117 118 119BMediaTheme * 120BMediaTheme::PreferredTheme() 121{ 122 CALLED(); 123 124 BAutolock locker(sLock); 125 126 // ToDo: should look in the global prefs file for the preferred 127 // add-on and load this from disk - in the meantime, just use 128 // the default theme 129 130 if (sDefaultTheme == NULL) 131 sDefaultTheme = new BPrivate::DefaultMediaTheme(); 132 133 return sDefaultTheme; 134} 135 136 137BBitmap * 138BMediaTheme::BackgroundBitmapFor(bg_kind bg) 139{ 140 UNIMPLEMENTED(); 141 return NULL; 142} 143 144 145rgb_color 146BMediaTheme::BackgroundColorFor(bg_kind bg) 147{ 148 UNIMPLEMENTED(); 149 return ui_color(B_PANEL_BACKGROUND_COLOR); 150} 151 152 153rgb_color 154BMediaTheme::ForegroundColorFor(fg_kind fg) 155{ 156 UNIMPLEMENTED(); 157 rgb_color dummy = {255, 255, 255}; 158 159 return dummy; 160} 161 162 163//! protected BMediaTheme 164BMediaTheme::BMediaTheme(const char* name, const char* info, 165 const entry_ref* ref, int32 id) 166 : 167 fID(id) 168{ 169 fName = strdup(name); 170 fInfo = strdup(info); 171 172 // ToDo: is there something else here, which has to be done? 173 174 if (ref) { 175 fIsAddOn = true; 176 fAddOnRef = *ref; 177 } else 178 fIsAddOn = false; 179} 180 181 182BControl * 183BMediaTheme::MakeFallbackViewFor(BParameter *parameter) 184{ 185 if (parameter == NULL) 186 return NULL; 187 188 return BPrivate::DefaultMediaTheme::MakeViewFor(parameter); 189} 190 191 192/* 193private unimplemented 194BMediaTheme::BMediaTheme() 195BMediaTheme::BMediaTheme(const BMediaTheme &clone) 196BMediaTheme & BMediaTheme::operator=(const BMediaTheme &clone) 197*/ 198 199status_t BMediaTheme::_Reserved_ControlTheme_0(void *) { return B_ERROR; } 200status_t BMediaTheme::_Reserved_ControlTheme_1(void *) { return B_ERROR; } 201status_t BMediaTheme::_Reserved_ControlTheme_2(void *) { return B_ERROR; } 202status_t BMediaTheme::_Reserved_ControlTheme_3(void *) { return B_ERROR; } 203status_t BMediaTheme::_Reserved_ControlTheme_4(void *) { return B_ERROR; } 204status_t BMediaTheme::_Reserved_ControlTheme_5(void *) { return B_ERROR; } 205status_t BMediaTheme::_Reserved_ControlTheme_6(void *) { return B_ERROR; } 206status_t BMediaTheme::_Reserved_ControlTheme_7(void *) { return B_ERROR; } 207 208