Debian Codegraph @

code/apis/SkinManager.cpp

raw
1 /*
2 Copyright (C) 2009-2010 wxLauncher Team
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include "apis/SkinManager.h"
20 #include "global/SkinDefaults.h"
21 #include <wx/filename.h>
22 #include "generated/configure_launcher.h"
23
24 #include "global/MemoryDebugging.h" // Last include for memory debugging
25
26 LAUNCHER_DEFINE_EVENT_TYPE(EVT_TC_SKIN_CHANGED);
27
28 EventHandlers SkinSystem::TCSkinChangedHandlers;
29
30 void SkinSystem::RegisterTCSkinChanged(wxEvtHandler *handler) {
31 wxASSERT(SkinSystem::IsInitialized());
32 wxASSERT_MSG(TCSkinChangedHandlers.IndexOf(handler) == wxNOT_FOUND,
33 wxString::Format(
34 _T("RegisterTCSkinChanged(): Handler at %p already registered."),
35 handler));
36 SkinSystem::TCSkinChangedHandlers.Append(handler);
37 }
38
39 void SkinSystem::UnRegisterTCSkinChanged(wxEvtHandler *handler) {
40 wxASSERT(SkinSystem::IsInitialized());
41 wxASSERT_MSG(TCSkinChangedHandlers.IndexOf(handler) != wxNOT_FOUND,
42 wxString::Format(
43 _T("UnRegisterTCSkinChanged(): Handler at %p not registered."),
44 handler));
45 SkinSystem::TCSkinChangedHandlers.DeleteObject(handler);
46 }
47
48 void SkinSystem::GenerateTCSkinChanged() {
49 wxASSERT(SkinSystem::IsInitialized());
50
51 wxCommandEvent event(EVT_TC_SKIN_CHANGED, wxID_NONE);
52
53 wxLogDebug(_T("Generating EVT_TC_SKIN_CHANGED event"));
54 for (EventHandlers::iterator
55 iter = SkinSystem::TCSkinChangedHandlers.begin(),
56 end = SkinSystem::TCSkinChangedHandlers.end();
57 iter != end; ++iter) {
58 wxEvtHandler* current = *iter;
59 current->AddPendingEvent(event);
60 wxLogDebug(_T(" Sent EVT_TC_SKIN_CHANGED event to %p"), current);
61 }
62 }
63
64
65 Skin::Skin()
66 : newsSource(NULL) {
67 }
68
69 bool Skin::SetWindowTitle(const wxString& windowTitle) {
70 if (windowTitle.IsEmpty()) {
71 wxLogWarning(_T("Provided window title is empty."));
72 return false;
73 } else {
74 this->windowTitle = windowTitle;
75 return true;
76 }
77 }
78
79 bool Skin::SetWindowIcon(const wxIcon& windowIcon) {
80 if (!windowIcon.IsOk()) {
81 wxLogWarning(_T("Provided window icon is not valid."));
82 return false;
83 } else {
84 this->windowIcon = windowIcon;
85 return true;
86 }
87 }
88
89 bool Skin::SetBanner(const wxBitmap& banner) {
90 if (!banner.IsOk()) {
91 wxLogWarning(_T("Provided banner is not valid."));
92 return false;
93 } else if (banner.GetWidth() > SkinSystem::BannerMaxWidth) {
94 wxLogWarning(_T("Provided banner is too wide (%d vs. %d pixels)."),
95 banner.GetWidth(), SkinSystem::BannerMaxWidth);
96 return false;
97 } else if (banner.GetHeight() != SkinSystem::BannerHeight) {
98 wxLogWarning(_T("Provided banner is incorrect height (%d vs. %d pixels)."),
99 banner.GetHeight(), SkinSystem::BannerHeight);
100 return false;
101 } else {
102 this->banner = banner;
103 return true;
104 }
105 }
106
107 bool Skin::SetWelcomeText(const wxString& welcomeText) {
108 if (welcomeText.IsEmpty()) {
109 wxLogWarning(_T("Provided welcome text is empty."));
110 return false;
111 } else {
112 this->welcomeText = welcomeText;
113 return true;
114 }
115 }
116
117 bool Skin::SetModImage(const wxBitmap& modImage) {
118 if (!modImage.IsOk()) {
119 wxLogWarning(_T("Provided mod image is not valid."));
120 return false;
121 } else if ((modImage.GetWidth() > SkinSystem::ModInfoDialogImageWidth) ||
122 (modImage.GetHeight() > SkinSystem::ModInfoDialogImageHeight)) {
123 wxLogDebug(_T("Provided mod image size %dx%d is larger than expected size %dx%d. Resizing."),
124 modImage.GetWidth(), modImage.GetHeight(),
125 SkinSystem::ModInfoDialogImageWidth, SkinSystem::ModInfoDialogImageHeight);
126
127 wxImage tempModImage(modImage.ConvertToImage());
128 wxImage scaledTempModImage(
129 tempModImage.Scale(
130 SkinSystem::ModListImageWidth,
131 SkinSystem::ModListImageHeight,
132 wxIMAGE_QUALITY_HIGH));
133
134 wxBitmap newModImage(scaledTempModImage);
135 wxASSERT(newModImage.GetWidth() == SkinSystem::ModListImageWidth);
136 wxASSERT(newModImage.GetHeight() == SkinSystem::ModListImageHeight);
137
138 this->modImage = wxBitmap(newModImage);
139 return true;
140 } else if ((modImage.GetWidth() < SkinSystem::ModInfoDialogImageWidth) ||
141 (modImage.GetHeight() < SkinSystem::ModInfoDialogImageHeight)) {
142 wxLogDebug(_T("Provided mod image size %dx%d is smaller than expected size %dx%d. Using as is."),
143 modImage.GetWidth(), modImage.GetHeight(),
144 SkinSystem::ModInfoDialogImageWidth, SkinSystem::ModInfoDialogImageHeight);
145 return true;
146 } else {
147 this->modImage = modImage;
148 return true;
149 }
150 }
151
152 bool Skin::SetSmallModImage(const wxBitmap& smallModImage) {
153 if (!smallModImage.IsOk()) {
154 wxLogWarning(_T("Provided small mod image is not valid."));
155 return false;
156 } else if ((smallModImage.GetWidth() != SkinSystem::ModListImageWidth) ||
157 (smallModImage.GetHeight() != SkinSystem::ModListImageHeight)) {
158 wxLogWarning(_T("Provided small mod image size %dx%d is not expected size %dx%d."),
159 smallModImage.GetWidth(), smallModImage.GetHeight(),
160 SkinSystem::ModListImageWidth, SkinSystem::ModListImageHeight);
161 return false;
162 } else {
163 this->smallModImage = smallModImage;
164 return true;
165 }
166 }
167
168 bool Skin::SetOkIcon(const wxBitmap& okIcon) {
169 if (!okIcon.IsOk()) {
170 wxLogWarning(_T("Provided ok icon is not valid."));
171 return false;
172 } else if (!CheckStatusBarIconDimensions(okIcon)) {
173 wxLogWarning(_T("Provided ok icon size is wrong."));
174 return false;
175 } else {
176 this->okIcon = okIcon;
177 return true;
178 }
179 }
180
181 bool Skin::SetWarningIcon(const wxBitmap& warningIcon) {
182 if (!warningIcon.IsOk()) {
183 wxLogWarning(_T("Provided warning icon is not valid."));
184 return false;
185 } else if (!CheckStatusBarIconDimensions(warningIcon)) {
186 wxLogWarning(_T("Provided warning icon size is wrong."));
187 return false;
188 } else {
189 this->warningIcon = warningIcon;
190 return true;
191 }
192 }
193
194 bool Skin::SetBigWarningIcon(const wxBitmap& bigWarningIcon) {
195 if (!bigWarningIcon.IsOk()) {
196 wxLogWarning(_T("Provided big warning icon is not valid."));
197 return false;
198 } else if (!CheckBigIconDimensions(bigWarningIcon)) {
199 wxLogWarning(_T("Provided big warning icon size is wrong."));
200 return false;
201 } else {
202 this->bigWarningIcon = bigWarningIcon;
203 return true;
204 }
205 }
206
207 bool Skin::SetErrorIcon(const wxBitmap& errorIcon) {
208 if (!errorIcon.IsOk()) {
209 wxLogWarning(_T("Provided error icon is not valid."));
210 return false;
211 } else if (!CheckStatusBarIconDimensions(errorIcon)) {
212 wxLogWarning(_T("Provided error icon size is wrong."));
213 return false;
214 } else {
215 this->errorIcon = errorIcon;
216 return true;
217 }
218 }
219
220 bool Skin::SetInfoIcon(const wxBitmap& infoIcon) {
221 if (!infoIcon.IsOk()) {
222 wxLogWarning(_T("Provided info icon is not valid."));
223 return false;
224 } else if (!CheckStatusBarIconDimensions(infoIcon)) {
225 wxLogWarning(_T("Provided info icon size is wrong."));
226 return false;
227 } else {
228 this->infoIcon = infoIcon;
229 return true;
230 }
231 }
232
233 bool Skin::SetBigInfoIcon(const wxBitmap& bigInfoIcon) {
234 if (!bigInfoIcon.IsOk()) {
235 wxLogWarning(_T("Provided big info icon is not valid."));
236 return false;
237 } else if (!CheckBigIconDimensions(bigInfoIcon)) {
238 wxLogWarning(_T("Provided big info icon size is wrong."));
239 return false;
240 } else {
241 this->bigInfoIcon = bigInfoIcon;
242 return true;
243 }
244 }
245
246 bool Skin::SetHelpIcon(const wxBitmap& helpIcon) {
247 if (!helpIcon.IsOk()) {
248 wxLogWarning(_T("Provided help icon is not valid."));
249 return false;
250 } else if ((helpIcon.GetWidth() != SkinSystem::HelpIconWidth) ||
251 (helpIcon.GetHeight() != SkinSystem::HelpIconHeight)) {
252 wxLogWarning(_T("Provided help icon size %dx%d is not expected size %dx%d."),
253 helpIcon.GetWidth(), helpIcon.GetHeight(),
254 SkinSystem::HelpIconWidth, SkinSystem::HelpIconHeight);
255 return false;
256 } else {
257 this->helpIcon = helpIcon;
258 return true;
259 }
260 }
261
262 bool Skin::SetBigHelpIcon(const wxBitmap& bigHelpIcon) {
263 if (!bigHelpIcon.IsOk()) {
264 wxLogWarning(_T("Provided help icon is not valid."));
265 return false;
266 } else if (!CheckBigIconDimensions(bigHelpIcon)) {
267 wxLogWarning(_T("Provided help icon size is wrong."));
268 return false;
269 } else {
270 this->bigHelpIcon = bigHelpIcon;
271 return true;
272 }
273 }
274
275 bool Skin::SetIdealIcon(const wxBitmap& idealIcon) {
276 if (!idealIcon.IsOk()) {
277 wxLogWarning(_T("Provided ideal icon is not valid."));
278 return false;
279 } else if ((idealIcon.GetWidth() != SkinSystem::IdealIconWidth) ||
280 (idealIcon.GetHeight() != SkinSystem::IdealIconHeight)) {
281 wxLogWarning(_T("Provided ideal icon size %dx%d is not expected size %dx%d."),
282 idealIcon.GetWidth(), idealIcon.GetHeight(),
283 SkinSystem::IdealIconWidth, SkinSystem::IdealIconHeight);
284 return false;
285 } else {
286 this->idealIcon = idealIcon;
287 return true;
288 }
289 }
290
291 bool Skin::SetNewsSource(const NewsSource* newsSource) {
292 if (newsSource == NULL) {
293 wxLogWarning(_T("Provided news source is NULL."));
294 return false;
295 } else {
296 this->newsSource = newsSource;
297 return true;
298 }
299 }
300
301 bool Skin::CheckStatusBarIconDimensions(const wxBitmap& icon) {
302 const bool result =
303 (icon.GetWidth() == SkinSystem::StatusBarIconWidth) &&
304 (icon.GetHeight() == SkinSystem::StatusBarIconHeight);
305 if (!result) {
306 wxLogWarning(_T("Expected status bar icon size is %dx%d but icon size is %dx%d"),
307 SkinSystem::StatusBarIconWidth, SkinSystem::StatusBarIconHeight,
308 icon.GetWidth(), icon.GetHeight());
309 }
310 return result;
311 }
312
313 bool Skin::CheckBigIconDimensions(const wxBitmap& icon) {
314 const bool result =
315 (icon.GetWidth() == SkinSystem::BigIconWidth) &&
316 (icon.GetHeight() == SkinSystem::BigIconHeight);
317 if (!result) {
318 wxLogWarning(_T("Expected big icon size is %dx%d but icon size is %dx%d"),
319 SkinSystem::BigIconWidth, SkinSystem::BigIconHeight,
320 icon.GetWidth(), icon.GetHeight());
321 }
322 return result;
323 }
324
325
326 SkinSystem* SkinSystem::skinSystem = NULL;
327
328 bool SkinSystem::Initialize() {
329 wxASSERT(!SkinSystem::IsInitialized());
330
331 SkinSystem::skinSystem = new SkinSystem();
332 return true;
333 }
334
335 void SkinSystem::DeInitialize() {
336 wxASSERT(SkinSystem::IsInitialized());
337
338 if (!SkinSystem::TCSkinChangedHandlers.IsEmpty()) {
339 wxLogDebug(_T("SkinSystem::DeInitialize(): contents of handler list:"));
340 for (EventHandlers::const_iterator
341 iter = SkinSystem::TCSkinChangedHandlers.begin(),
342 end = SkinSystem::TCSkinChangedHandlers.end();
343 iter != end; ++iter) {
344 wxLogDebug(_T(" handler at %p"), *iter);
345 }
346 SkinSystem::TCSkinChangedHandlers.Clear();
347 }
348
349 SkinSystem* temp = SkinSystem::skinSystem;
350 SkinSystem::skinSystem = NULL;
351 delete temp;
352 }
353
354 bool SkinSystem::IsInitialized() {
355 return (SkinSystem::skinSystem != NULL);
356 }
357
358 SkinSystem* SkinSystem::GetSkinSystem() {
359 wxCHECK_MSG(SkinSystem::IsInitialized(),
360 NULL,
361 _T("Attempt to get skin system when it has not been initialized."));
362
363 return SkinSystem::skinSystem;
364 }
365
366 SkinSystem::SkinSystem()
367 : TCSkin(NULL),
368 font(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)),
369 messageFont(14, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL) {
370
371 InitializeDefaultSkin();
372 }
373
374 SkinSystem::~SkinSystem() {
375 if (this->TCSkin != NULL) delete this->TCSkin;
376 }
377
378 void SkinSystem::InitializeDefaultSkin() {
379 // launcher can't function if any of the default skin is missing/invalid
380 bool success = false;
381
382 success = this->defaultSkin.SetWindowTitle(DEFAULT_SKIN_WINDOW_TITLE);
383 if (!success) {
384 wxLogFatalError(_T("Setting default window title '%s' failed"),
385 DEFAULT_SKIN_WINDOW_TITLE.c_str());
386 }
387
388 wxFileName filename(_T(RESOURCES_PATH), DEFAULT_SKIN_WINDOW_ICON);
389 success = this->defaultSkin.SetWindowIcon(
390 wxIcon(filename.GetFullPath(), wxBITMAP_TYPE_ICO));
391 if (!success) {
392 wxLogFatalError(_T("Setting default window icon '%s' failed"),
393 filename.GetFullPath().c_str());
394 }
395
396 filename = wxFileName(_T(RESOURCES_PATH), DEFAULT_SKIN_BANNER);
397 success = this->defaultSkin.SetBanner(
398 wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY));
399 if (!success) {
400 wxLogFatalError(_T("Setting default banner '%s' failed"),
401 filename.GetFullPath().c_str());
402 }
403
404 success = this->defaultSkin.SetWelcomeText(DEFAULT_SKIN_WELCOME_TEXT);
405 if (!success) {
406 wxLogFatalError(_T("Setting default welcome text '%s' failed"),
407 DEFAULT_SKIN_WELCOME_TEXT.c_str());
408 }
409
410 filename = wxFileName(_T(RESOURCES_PATH), DEFAULT_SKIN_MOD_IMAGE_255X112);
411 success = this->defaultSkin.SetModImage(
412 wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY));
413 if (!success) {
414 wxLogFatalError(_T("Setting default mod image '%s' failed"),
415 filename.GetFullPath().c_str());
416 }
417
418 filename = wxFileName(_T(RESOURCES_PATH), DEFAULT_SKIN_MOD_IMAGE_182X80);
419 success = this->defaultSkin.SetSmallModImage(
420 wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY));
421 if (!success) {
422 wxLogFatalError(_T("Setting default small mod image '%s' failed"),
423 filename.GetFullPath().c_str());
424 }
425
426 filename = wxFileName(_T(RESOURCES_PATH), DEFAULT_SKIN_ICON_OK);
427 success = this->defaultSkin.SetOkIcon(
428 wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY));
429 if (!success) {
430 wxLogFatalError(_T("Setting default ok icon '%s' failed"),
431 filename.GetFullPath().c_str());
432 }
433
434 filename = wxFileName(_T(RESOURCES_PATH), DEFAULT_SKIN_ICON_WARNING);
435 success = this->defaultSkin.SetWarningIcon(
436 wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY));
437 if (!success) {
438 wxLogFatalError(_T("Setting default warning icon '%s' failed"),
439 filename.GetFullPath().c_str());
440 }
441
442 filename = wxFileName(_T(RESOURCES_PATH), DEFAULT_SKIN_ICON_WARNING_BIG);
443 success = this->defaultSkin.SetBigWarningIcon(
444 wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY));
445 if (!success) {
446 wxLogFatalError(_T("Setting default big warning icon '%s' failed"),
447 filename.GetFullPath().c_str());
448 }
449
450 filename = wxFileName(_T(RESOURCES_PATH), DEFAULT_SKIN_ICON_ERROR);
451 success = this->defaultSkin.SetErrorIcon(
452 wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY));
453 if (!success) {
454 wxLogFatalError(_T("Setting default error icon '%s' failed"),
455 filename.GetFullPath().c_str());
456 }
457
458 filename = wxFileName(_T(RESOURCES_PATH), DEFAULT_SKIN_ICON_INFO);
459 success = this->defaultSkin.SetInfoIcon(
460 wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY));
461 if (!success) {
462 wxLogFatalError(_T("Setting default info icon '%s' failed"),
463 filename.GetFullPath().c_str());
464 }
465
466 filename = wxFileName(_T(RESOURCES_PATH), DEFAULT_SKIN_ICON_INFO_BIG);
467 success = this->defaultSkin.SetBigInfoIcon(
468 wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY));
469 if (!success) {
470 wxLogFatalError(_T("Setting default big info icon '%s' failed"),
471 filename.GetFullPath().c_str());
472 }
473
474 filename = wxFileName(_T(RESOURCES_PATH), DEFAULT_SKIN_ICON_HELP);
475 success = this->defaultSkin.SetHelpIcon(
476 wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY));
477 if (!success) {
478 wxLogFatalError(_T("Setting default help icon '%s' failed"),
479 filename.GetFullPath().c_str());
480 }
481
482 filename = wxFileName(_T(RESOURCES_PATH), DEFAULT_SKIN_ICON_HELP_BIG);
483 success = this->defaultSkin.SetBigHelpIcon(
484 wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY));
485 if (!success) {
486 wxLogFatalError(_T("Setting default big help icon '%s' failed"),
487 filename.GetFullPath().c_str());
488 }
489
490 filename = wxFileName(_T(RESOURCES_PATH), DEFAULT_SKIN_ICON_IDEAL);
491 this->defaultSkin.SetIdealIcon(
492 wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY));
493 if (!success) {
494 wxLogFatalError(_T("Setting default ideal icon '%s' failed"),
495 filename.GetFullPath().c_str());
496 }
497
498 success = this->defaultSkin.SetNewsSource(
499 NewsSource::FindSource(DEFAULT_SKIN_NEWS_SOURCE));
500 if (!success) {
501 wxLogFatalError(_T("Setting default news source '%d' failed"),
502 DEFAULT_SKIN_NEWS_SOURCE);
503 }
504 }
505
506 const wxString& SkinSystem::GetWindowTitle() const {
507 if ( this->TCSkin != NULL
508 && !this->TCSkin->GetWindowTitle().IsEmpty() ) {
509 return this->TCSkin->GetWindowTitle();
510 } else {
511 return this->defaultSkin.GetWindowTitle();
512 }
513 }
514
515 const wxIcon& SkinSystem::GetWindowIcon() const {
516 if ( this->TCSkin != NULL
517 && this->TCSkin->GetWindowIcon().IsOk() ) {
518 return this->TCSkin->GetWindowIcon();
519 } else {
520 return this->defaultSkin.GetWindowIcon();
521 }
522 }
523
524 const wxBitmap& SkinSystem::GetBanner() const {
525 if ( this->TCSkin != NULL
526 && this->TCSkin->GetBanner().IsOk() ) {
527 return this->TCSkin->GetBanner();
528 } else {
529 return this->defaultSkin.GetBanner();
530 }
531 }
532
533 const wxString& SkinSystem::GetWelcomeText() const {
534 if ( this->TCSkin != NULL
535 && !this->TCSkin->GetWelcomeText().IsEmpty() ) {
536 return this->TCSkin->GetWelcomeText();
537 } else {
538 return this->defaultSkin.GetWelcomeText();
539 }
540 }
541
542 const wxBitmap& SkinSystem::GetModImage() const {
543 if ( this->TCSkin != NULL
544 && this->TCSkin->GetModImage().IsOk() ) {
545 return this->TCSkin->GetModImage();
546 } else {
547 return this->defaultSkin.GetModImage();
548 }
549 }
550
551 const wxBitmap& SkinSystem::GetSmallModImage() const {
552 if ( this->TCSkin != NULL
553 && this->TCSkin->GetSmallModImage().IsOk() ) {
554 return this->TCSkin->GetSmallModImage();
555 } else {
556 return this->defaultSkin.GetSmallModImage();
557 }
558 }
559
560 const wxBitmap& SkinSystem::GetOkIcon() const {
561 if ( this->TCSkin != NULL
562 && this->TCSkin->GetOkIcon().IsOk() ) {
563 return this->TCSkin->GetOkIcon();
564 } else {
565 return this->defaultSkin.GetOkIcon();
566 }
567 }
568
569 const wxBitmap& SkinSystem::GetWarningIcon() const {
570 if ( this->TCSkin != NULL
571 && this->TCSkin->GetWarningIcon().IsOk() ) {
572 return this->TCSkin->GetWarningIcon();
573 } else {
574 return this->defaultSkin.GetWarningIcon();
575 }
576 }
577
578 const wxBitmap& SkinSystem::GetBigWarningIcon() const {
579 if ( this->TCSkin != NULL
580 && this->TCSkin->GetBigWarningIcon().IsOk() ) {
581 return this->TCSkin->GetBigWarningIcon();
582 } else {
583 return this->defaultSkin.GetBigWarningIcon();
584 }
585 }
586
587 const wxBitmap& SkinSystem::GetErrorIcon() const {
588 if ( this->TCSkin != NULL
589 && this->TCSkin->GetErrorIcon().IsOk() ) {
590 return this->TCSkin->GetErrorIcon();
591 } else {
592 return this->defaultSkin.GetErrorIcon();
593 }
594 }
595
596 const wxBitmap& SkinSystem::GetInfoIcon() const {
597 if ( this->TCSkin != NULL
598 && this->TCSkin->GetInfoIcon().IsOk() ) {
599 return this->TCSkin->GetInfoIcon();
600 } else {
601 return this->defaultSkin.GetInfoIcon();
602 }
603 }
604
605 const wxBitmap& SkinSystem::GetBigInfoIcon() const {
606 if ( this->TCSkin != NULL
607 && this->TCSkin->GetBigInfoIcon().IsOk() ) {
608 return this->TCSkin->GetBigInfoIcon();
609 } else {
610 return this->defaultSkin.GetBigInfoIcon();
611 }
612 }
613
614 const wxBitmap& SkinSystem::GetHelpIcon() const {
615 if ( this->TCSkin != NULL
616 && this->TCSkin->GetHelpIcon().IsOk() ) {
617 return this->TCSkin->GetHelpIcon();
618 } else {
619 return this->defaultSkin.GetHelpIcon();
620 }
621 }
622
623 const wxBitmap& SkinSystem::GetBigHelpIcon() const {
624 if ( this->TCSkin != NULL
625 && this->TCSkin->GetBigHelpIcon().IsOk() ) {
626 return this->TCSkin->GetBigHelpIcon();
627 } else {
628 return this->defaultSkin.GetBigHelpIcon();
629 }
630 }
631
632 const wxBitmap& SkinSystem::GetIdealIcon() const {
633 if ( this->TCSkin != NULL
634 && this->TCSkin->GetIdealIcon().IsOk() ) {
635 return this->TCSkin->GetIdealIcon();
636 } else {
637 return this->defaultSkin.GetIdealIcon();
638 }
639 }
640
641 const NewsSource& SkinSystem::GetNewsSource() const {
642 if ( this->TCSkin != NULL
643 && this->TCSkin->GetNewsSource() != NULL ) {
644 return *this->TCSkin->GetNewsSource();
645 } else {
646 return *this->defaultSkin.GetNewsSource();
647 }
648 }
649
650 void SkinSystem::SetTCSkin(const Skin* skin) {
651 wxCHECK_RET(skin != NULL, _T("SetTCSkin() given null Skin"));
652
653 // FIXME: Must confirm that generating the event twice isn't problematic
654 if (this->TCSkin != NULL) {
655 ResetTCSkin();
656 }
657
658 this->TCSkin = skin;
659
660 GenerateTCSkinChanged();
661 }
662
663 // Does nothing if TCSkin is NULL.
664 void SkinSystem::ResetTCSkin() {
665 if (this->TCSkin != NULL) {
666 const Skin* temp = this->TCSkin;
667 this->TCSkin = NULL;
668 delete temp;
669
670 GenerateTCSkinChanged();
671 }
672 }
673
674 /** Returns true if function is able to get a valid filename object for the
675 passed paths. Filename is returned via the param filename. */
676 bool SkinSystem::SearchFile(wxFileName& filename, wxString currentTC,
677 wxString shortmodname, wxString filepath) {
678 if (shortmodname.IsEmpty()) { // indicates that the mod is (No mod)
679 filename.Assign(
680 wxString::Format(_T("%s"), filepath.c_str()));
681 } else {
682 filename.Assign(
683 wxString::Format(_T("%s/%s"), shortmodname.c_str(), filepath.c_str()));
684 }
685
686 if ( filename.Normalize(wxPATH_NORM_ALL, currentTC, wxPATH_UNIX) ) {
687 if ( filename.IsOk() ) {
688 if ( filename.FileExists() ) {
689 return true;
690 } else {
691 wxLogDebug(_T(" File '%s' does not exist"),
692 filename.GetFullPath().c_str());
693 }
694 } else {
695 wxLogDebug(_T(" File '%s' is not valid"), filename.GetFullPath().c_str());
696 }
697 } else {
698 wxLogDebug(_T(" Unable to normalize '%s' '%s' '%s'"), currentTC.c_str(),
699 shortmodname.c_str(), filepath.c_str());
700 }
701 return false;
702 }
703
704 wxBitmap SkinSystem::MakeModListImage(const wxBitmap &orig) {
705 wxASSERT(orig.GetWidth() == SkinSystem::ModInfoDialogImageWidth);
706 wxASSERT(orig.GetHeight() == SkinSystem::ModInfoDialogImageHeight);
707
708 wxImage temp(orig.ConvertToImage());
709 wxImage scaledTemp(temp.Scale(SkinSystem::ModListImageWidth,
710 SkinSystem::ModListImageHeight,
711 wxIMAGE_QUALITY_HIGH));
712
713 wxBitmap outimg(scaledTemp);
714 wxASSERT(outimg.GetWidth() == SkinSystem::ModListImageWidth);
715 wxASSERT(outimg.GetHeight() == SkinSystem::ModListImageHeight);
716
717 return outimg;
718 }
719
720 wxBitmap SkinSystem::MakeModInfoDialogImage(const wxBitmap &orig) {
721 wxASSERT(orig.GetWidth() == SkinSystem::ModListImageWidth);
722 wxASSERT(orig.GetHeight() == SkinSystem::ModListImageHeight);
723
724 wxImage temp(orig.ConvertToImage());
725 wxImage scaledTemp(temp.Scale(SkinSystem::ModInfoDialogImageWidth,
726 SkinSystem::ModInfoDialogImageHeight,
727 wxIMAGE_QUALITY_HIGH));
728
729 wxBitmap outimg(scaledTemp);
730 wxASSERT(outimg.GetWidth() == SkinSystem::ModInfoDialogImageWidth);
731 wxASSERT(outimg.GetHeight() == SkinSystem::ModInfoDialogImageHeight);
732
733 return outimg;
734 }