xoblite™ / Blackbox for Windows bb5 | RC6 preview | 0.25.2.14
http://xoblite.net/
Themes.cpp File Reference
#include "Themes.h"
#include <io.h>

Classes

struct  fontListItem
 

Typedefs

typedef struct fontListItem fontListItem
 
typedef vector< fontListItem * > fontListVector
 

Functions

bool SetTheme (LPSTR themePath, bool startingUp)
 
void RegisterThemeFonts ()
 
void UnregisterThemeFonts ()
 

Variables

SettingspSettings
 
DesktoppDesktop
 
fontListVector fontList
 

Typedef Documentation

◆ fontListItem

typedef struct fontListItem fontListItem

◆ fontListVector

typedef vector<fontListItem*> fontListVector

Function Documentation

◆ SetTheme()

bool SetTheme ( LPSTR themePath,
bool startingUp )
48{
49 if (startingUp) ZeroMemory(&fontList, sizeof(fontList));
50
51 if (themePath != 0)
52 {
53 char path[MAX_LINE_LENGTH], theme[MAX_LINE_LENGTH];
54 strcpy(theme, themePath);
55 if (strchr(theme, '\"')) StrRemoveEncap(theme);
56 if (strchr(theme, '$')) ReplaceShellFolders(theme);
57 if (strchr(theme, '%')) ReplaceEnvVars(theme);
58 if (theme[strlen(theme)-1] == '\\') theme[strlen(theme)-1] = 0;
59
60 //====================
61
62 // Is the requested theme the same as the current theme? If so, just reload it... (i.e. restart operation)
63 if (!startingUp && !_stricmp(pSettings->SF_currentThemePath, theme))
64 {
65 char temp[MAX_LINE_LENGTH];
66 if (!_stricmp(pSettings->selectedTheme, "[Default]")) strcpy(temp, "Reloading the default theme...");
67 else sprintf(temp, "Reloading the \"%s\" theme...", pSettings->selectedTheme);
68 SendMessage(GetBBWnd(), BB_CONSOLEMESSAGE, (WPARAM)CONSOLE_REGULAR_MESSAGE, (LPARAM)temp);
69
74
76
77 return true;
78 }
79
80 //====================
81
82 // Otherwise, first make sure the requested theme is valid...
83 // (i.e. being either the [Default] theme, or another theme having at least a configuration xoblite.rc/blackbox.rc file)
84 bool validTheme = !_stricmp(pSettings->SF_blackboxPath, theme);
85 if (!validTheme)
86 {
87 strcpy(path, theme);
88 strcat(path, "\\xoblite.rc");
89 validTheme = FileExists(path);
90 if (!validTheme)
91 {
92 strcpy(path, theme);
93 strcat(path, "\\blackbox.rc");
94 validTheme = FileExists(path);
95 }
96 }
97
98 if (validTheme)
99 {
100 // Save settings, unload plugins etc...
101 if (!startingUp) restartBlackboxStop();
102
103 // Unload font resources for the old theme...
104 if (!startingUp) UnregisterThemeFonts();
105
106 // Set the new theme path...
107 strcpy(pSettings->SF_currentThemePath, theme);
108 pSettings->usingDefaultTheme = !_stricmp(pSettings->SF_blackboxPath, pSettings->SF_currentThemePath);
109
110 //====================
111
112 // Are we using the [Default] theme?
113 if (pSettings->usingDefaultTheme)
114 {
115 // Reset the main configuration file paths to initiate
116 // a new ConfigFileExists check for each of them...
117 strcpy(pSettings->bbrcFile, "");
118 bbrcPath();
119
120 strcpy(pSettings->xobrcFile, "");
122 strcpy(pSettings->xobrcDefaultFile, pSettings->xobrcFile);
123
124// strcpy(pSettings->pluginsFile, "");
125// plugrcPath();
126
127 if (!startingUp)
128 {
129 pSettings->writeProtection = false;
130 strcpy(pSettings->selectedTheme, "[Default]");
131 WriteString(pSettings->xobrcDefaultFile, "xoblite.selected.theme:", pSettings->selectedTheme);
132
133 // Show theme change message in the console...
134 SendMessage(GetBBWnd(), BB_CONSOLEMESSAGE, (WPARAM)CONSOLE_REGULAR_MESSAGE, (LPARAM)"Switching to the default theme...");
135 }
136 }
137
138 //====================
139
140 else // Nope, we are using any other theme than the [Default] theme...
141 {
142 // Set the new theme's configuration file paths...
143 strcpy(path, pSettings->SF_currentThemePath);
144 strcat(path, "\\xoblite.rc");
145 if (FileExists(path))
146 {
147 bbrcPath(path);
148 extensionsrcPath(path);
149 }
150 else
151 {
152 strcpy(path, pSettings->SF_currentThemePath);
153 strcat(path, "\\blackbox.rc");
154 if (FileExists(path)) bbrcPath(path);
155 strcpy(path, pSettings->SF_currentThemePath);
156 strcat(path, "\\extensions.rc");
157 if (FileExists(path)) extensionsrcPath(path);
158 }
159/*
160// strcpy(path, pSettings->SF_currentThemePath);
161// strcat(path, "\\plugins.rc");
162// strcpy(path, pSettings->pluginsFile);
163// if (FileExists(path)) plugrcPath(path);
164// else
165 strcpy(pSettings->pluginsFile, ReadString(pSettings->xobrcDefaultFile, "xoblite.pluginsFile:", "$Blackbox$\\plugins.rc"));
166 if (strchr(pSettings->pluginsFile, '\"')) StrRemoveEncap(pSettings->pluginsFile);
167 if (strchr(pSettings->pluginsFile, '$')) ReplaceShellFolders(pSettings->pluginsFile);
168 if (strchr(pSettings->pluginsFile, '%')) ReplaceEnvVars(pSettings->pluginsFile);
169
170 if (!FileExists(pSettings->pluginsFile))
171 {
172 // Reset plugin.rc file path to initiate a new ConfigFileExists check...
173 // (this allows for xoblite.rc (or bb+ext.rc) only themes using a global plugins.rc)
174// strcpy(pSettings->pluginsFile, "");
175 GetBlackboxPath(path, sizeof(path));
176 strcat(path, "\\plugins.rc");
177 plugrcPath();
178 }
179*/
180 if (!startingUp)
181 {
182 pSettings->writeProtection = false;
183 strcpy(pSettings->selectedTheme, &pSettings->SF_currentThemePath[strlen(pSettings->themesFolder)+1]);
184 WriteString(pSettings->xobrcDefaultFile, "xoblite.selected.theme:", pSettings->selectedTheme);
185
186 // Show theme change message in the console...
187 char temp[MAX_LINE_LENGTH];
188 sprintf(temp, "Switching to the \"%s\" theme...", pSettings->selectedTheme);
189 SendMessage(GetBBWnd(), BB_CONSOLEMESSAGE, (WPARAM)CONSOLE_REGULAR_MESSAGE, (LPARAM)temp);
190 }
191 }
192
193 //====================
194
195 if (!startingUp)
196 {
197 // Load font resources for the new theme...
199
200 // Finally, we load the new theme settings...
202 // ...and point out the theme change audibly as well... ;)
204
205 pSettings->Statistics.changedTheme++; // Update statistics...
206 }
207 }
208
209 //====================
210
211 else if (!startingUp)
212 {
213 // The specified theme path wasn't valid!
214 char msg[MAX_LINE_LENGTH];
215 sprintf(msg, "%s \n\ndoes not seem to be a valid theme path. \nPlease check your related configuration file. ", themePath);
216 MessageBox(GetBBWnd(), msg, "xoblite", MB_OK | MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST);
217 return false;
218 }
219 }
220
221 return false;
222}
LPCSTR bbrcPath(LPCSTR other)
Definition BBApi.cpp:863
void WriteString(LPCSTR fp, LPCSTR keyword, LPSTR value)
Definition BBApi.cpp:3156
LPCSTR extensionsrcPath(LPCSTR other)
Definition BBApi.cpp:881
bool FileExists(LPCSTR szFileName)
Definition BBApi.cpp:819
LPSTR StrRemoveEncap(LPSTR string)
Definition BBApi.cpp:406
void ReplaceEnvVars(LPSTR string)
Definition BBApi.cpp:2594
void ReplaceShellFolders(LPSTR string)
Definition BBApi.cpp:2633
Settings * pSettings
Definition Blackbox.cpp:46
HWND GetBBWnd()
Definition BBApi.cpp:128
#define BB_CONSOLEMESSAGE
Definition BBApi.h:165
#define CONSOLE_REGULAR_MESSAGE
Definition BBApi.h:297
#define MAX_LINE_LENGTH
Definition BBApi.h:64
void restartBlackboxStart()
Definition Blackbox.cpp:703
void restartBlackboxStop()
Definition Blackbox.cpp:680
void PlaySoundFX(int sound)
Definition Sounds.cpp:40
@ SFX_THEME_CHANGE
Definition Sounds.h:40
void UnregisterThemeFonts()
Definition Themes.cpp:293
void RegisterThemeFonts()
Definition Themes.cpp:229
fontListVector fontList
Definition Themes.cpp:43

◆ RegisterThemeFonts()

void RegisterThemeFonts ( )
230{
231 if (fontList.size() > 0) UnregisterThemeFonts(); // Safeguard
232 if (pSettings->disableThemeFonts) return;
233
234 char fontsFolder[MAX_PATH];
235 strcpy(fontsFolder, pSettings->SF_currentThemePath);
236 strcat(fontsFolder, "\\fonts");
237 if (!FolderExists(fontsFolder))
238 {
239 strcpy(fontsFolder, pSettings->SF_blackboxPath);
240 strcat(fontsFolder, "\\fonts");
241 }
242
243 if (FolderExists(fontsFolder))
244 {
245 char searchPattern[MAX_PATH];
246 strcpy(searchPattern, fontsFolder);
247 strcat(searchPattern, "\\*");
248
249 _finddata_t found;
250 long handle = _findfirst(searchPattern, &found);
251 if (handle != -1)
252 {
253 char fontFile[MAX_PATH];
254
255 do
256 {
257 // Skip hidden files and any subfolders... (nb. we only register fonts in the main /fonts folder for a theme!)
258 if (strcmp(found.name, ".") == 0 || strcmp(found.name, "..") == 0 || (found.attrib & _A_HIDDEN)) continue;
259 if (found.attrib & _A_SUBDIR) continue;
260
261 // Have we found a valid font file?
262 if (IsInString(found.name, ".ttf") || IsInString(found.name, ".otf") || IsInString(found.name, ".fon"))
263 {
264 // Add the font resource, marked as private to our process, to the system...
265 sprintf(fontFile, "%s\\%s", fontsFolder, found.name);
266 if (AddFontResourceEx(fontFile, FR_PRIVATE, 0) > 0)
267 {
268 fontListItem* addedFont = new fontListItem;
269 strcpy(addedFont->fontFile, fontFile);
270 fontList.push_back(addedFont);
271 }
272 }
273 }
274 while (_findnext(handle, &found) == 0);
275 }
276
277 _findclose(handle);
278
279 if (fontList.size() > 0)
280 {
281 PostMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
282
283 char msg[255];
284 if (fontList.size() > 1) sprintf(msg, "Adding theme fonts -> %d fonts registered.", fontList.size());
285 else sprintf(msg, "Adding theme fonts -> %d font registered.", fontList.size());
286 SendMessage(GetBBWnd(), BB_CONSOLEMESSAGE, (WPARAM)CONSOLE_REGULAR_MESSAGE, (LPARAM)msg);
287 }
288 }
289}
bool FolderExists(LPCSTR szFolderPath)
Definition BBApi.cpp:842
bool IsInString(LPCSTR inputString, LPCSTR searchString)
Definition BBApi.cpp:2519
Definition Themes.cpp:38
char fontFile[MAX_PATH]
Definition Themes.cpp:39

◆ UnregisterThemeFonts()

void UnregisterThemeFonts ( )
294{
295 if (fontList.empty()) return;
296
297 int fontsUnregistered = fontList.size();
298
299 for (int i=0; i<(int)fontList.size(); i++)
300 {
301 RemoveFontResourceEx(fontList[i]->fontFile, FR_PRIVATE, 0);
302 delete fontList[i];
303 }
304 fontList.clear();
305// ZeroMemory(&fontList, sizeof(fontList));
306
307 PostMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
308/*
309 if (pSettings->debugLogging)
310 {
311 char msg[255];
312 if (fontsUnregistered > 1) sprintf(msg, "Removing theme fonts -> %d fonts unregistered.", fontsUnregistered);
313 else sprintf(msg, "Removing theme fonts -> %d font unregistered.", fontsUnregistered);
314 SendMessage(GetBBWnd(), BB_CONSOLEMESSAGE, (WPARAM)CONSOLE_REGULAR_MESSAGE, (LPARAM)msg);
315 }
316*/
317}

Variable Documentation

◆ pSettings

Settings* pSettings
extern

◆ pDesktop

Desktop* pDesktop
extern

◆ fontList

fontListVector fontList