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 "MediaDebug.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
22 static BLocker sLock("media theme lock");
23
24 BMediaTheme* BMediaTheme::sDefaultTheme;
25
26
~BMediaTheme()27 BMediaTheme::~BMediaTheme()
28 {
29 CALLED();
30
31 free(fName);
32 free(fInfo);
33 }
34
35
36 const char *
Name()37 BMediaTheme::Name()
38 {
39 return fName;
40 }
41
42
43 const char *
Info()44 BMediaTheme::Info()
45 {
46 return fInfo;
47 }
48
49
50 int32
ID()51 BMediaTheme::ID()
52 {
53 return fID;
54 }
55
56
57 bool
GetRef(entry_ref * ref)58 BMediaTheme::GetRef(entry_ref* ref)
59 {
60 if (!fIsAddOn || ref == NULL)
61 return false;
62
63 *ref = fAddOnRef;
64 return true;
65 }
66
67
68 BView *
ViewFor(BParameterWeb * web,const BRect * hintRect,BMediaTheme * usingTheme)69 BMediaTheme::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
89 status_t
SetPreferredTheme(BMediaTheme * defaultTheme)90 BMediaTheme::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
119 BMediaTheme *
PreferredTheme()120 BMediaTheme::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
137 BBitmap *
BackgroundBitmapFor(bg_kind bg)138 BMediaTheme::BackgroundBitmapFor(bg_kind bg)
139 {
140 UNIMPLEMENTED();
141 return NULL;
142 }
143
144
145 rgb_color
BackgroundColorFor(bg_kind bg)146 BMediaTheme::BackgroundColorFor(bg_kind bg)
147 {
148 UNIMPLEMENTED();
149 return ui_color(B_PANEL_BACKGROUND_COLOR);
150 }
151
152
153 rgb_color
ForegroundColorFor(fg_kind fg)154 BMediaTheme::ForegroundColorFor(fg_kind fg)
155 {
156 UNIMPLEMENTED();
157 rgb_color dummy = {255, 255, 255};
158
159 return dummy;
160 }
161
162
163 //! protected BMediaTheme
BMediaTheme(const char * name,const char * info,const entry_ref * ref,int32 id)164 BMediaTheme::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
182 BControl *
MakeFallbackViewFor(BParameter * parameter)183 BMediaTheme::MakeFallbackViewFor(BParameter *parameter)
184 {
185 if (parameter == NULL)
186 return NULL;
187
188 return BPrivate::DefaultMediaTheme::MakeViewFor(parameter);
189 }
190
191
192 /*
193 private unimplemented
194 BMediaTheme::BMediaTheme()
195 BMediaTheme::BMediaTheme(const BMediaTheme &clone)
196 BMediaTheme & BMediaTheme::operator=(const BMediaTheme &clone)
197 */
198
_Reserved_ControlTheme_0(void *)199 status_t BMediaTheme::_Reserved_ControlTheme_0(void *) { return B_ERROR; }
_Reserved_ControlTheme_1(void *)200 status_t BMediaTheme::_Reserved_ControlTheme_1(void *) { return B_ERROR; }
_Reserved_ControlTheme_2(void *)201 status_t BMediaTheme::_Reserved_ControlTheme_2(void *) { return B_ERROR; }
_Reserved_ControlTheme_3(void *)202 status_t BMediaTheme::_Reserved_ControlTheme_3(void *) { return B_ERROR; }
_Reserved_ControlTheme_4(void *)203 status_t BMediaTheme::_Reserved_ControlTheme_4(void *) { return B_ERROR; }
_Reserved_ControlTheme_5(void *)204 status_t BMediaTheme::_Reserved_ControlTheme_5(void *) { return B_ERROR; }
_Reserved_ControlTheme_6(void *)205 status_t BMediaTheme::_Reserved_ControlTheme_6(void *) { return B_ERROR; }
_Reserved_ControlTheme_7(void *)206 status_t BMediaTheme::_Reserved_ControlTheme_7(void *) { return B_ERROR; }
207
208