1 /**
2  * Copyright (c) 2012 ooxi/violetland
3  *     https://github.com/ooxi/violetland
4  *
5  * This software is provided 'as-is', without any express or implied warranty.
6  * In no event will the authors be held liable for any damages arising from the
7  * use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  *  1. The origin of this software must not be misrepresented; you must not
14  *     claim that you wrote the original software. If you use this software in a
15  *     product, an acknowledgment in the product documentation would be
16  *     appreciated but is not required.
17  *
18  *  2. Altered source versions must be plainly marked as such, and must not be
19  *     misrepresented as being the original software.
20  *
21  *  3. This notice may not be removed or altered from any source distribution.
22  */
23 #include <cstring>
24 #include <libintl.h>
25 
26 #include "ControlStyle.h"
27 #include "utility/Templates.h"
28 
29 using namespace violetland;
30 
31 
32 
33 
34 
35 /**
36  * @return ControlStyle represented by `serialVersionUid'
37  */
ControlStyleFromInt(int serialVersionUid)38 enum ControlStyle violetland::ControlStyleFromInt(int serialVersionUid) {
39 	#define EXPAND_CONTROL_STYLE(id, name, serialVersionUid)	\
40 		case serialVersionUid:					\
41 			return E_CONTROL_STYLE_##id;
42 
43 	switch (serialVersionUid) {
44 		#include "ControlStyles.h"
45 	}
46 	#undef EXPAND_CONTROL_STYLE
47 
48 	return E_CONTROL_STYLE_MODERN;
49 }
50 
51 
52 
53 /**
54  * @return Static \0-terminated character buffer describing the control style
55  */
ControlStyleToString(enum ControlStyle style)56 char* violetland::ControlStyleToString(enum ControlStyle style) {
57 	#define EXPAND_CONTROL_STYLE(id, name, serialVersionUid)	\
58 		case E_CONTROL_STYLE_##id:				\
59 			return gettext(name);
60 
61 	switch (style) {
62 		#include "ControlStyles.h"
63 	}
64 	#undef EXPAND_CONTROL_STYLE
65 
66 	return gettext("Modern");
67 }
68 
69 
70 
71 
72 /**
73  * @return The next available control style or the first, if no more are
74  *     available
75  */
GetNextControlStyle(enum ControlStyle style)76 enum ControlStyle violetland::GetNextControlStyle(enum ControlStyle style) {
77 	#define EXPAND_CONTROL_STYLE(id, name, serialVersionUid)	\
78 		E_CONTROL_STYLE_##id,					\
79 
80 	static enum ControlStyle styles[] = {
81 		#include "ControlStyles.h"
82 	};
83 	#undef EXPAND_CONTROL_STYLE
84 
85 	for (size_t i = 0; i < getStructSize(styles); ++i) {
86 		if (style == styles[i]) {
87 			if (i + 1 >= getStructSize(styles)) {
88 				return styles[0];
89 			} else {
90 				return styles[i + 1];
91 			}
92 		}
93 	}
94 
95 	return styles[0];
96 }
97 
98