OWLNext
7.0
Borland's Object Windows Library for the modern age
Toggle main menu visibility
Loading...
Searching...
No Matches
codepages.h
Go to the documentation of this file.
1
//
2
/// \file codepages.h
3
/// Utilities for accessing and setting code page information
4
//
5
// Part of OWLNext - the next generation Object Windows Library
6
// Copyright (c) 2014 by Joe Slater
7
//
8
// For more information, including license details, see
9
// http://owlnext.sourceforge.net
10
//
11
12
#if !defined(OWL_CODEPAGES_H)
13
#define OWL_CODEPAGES_H
14
15
#include <
owl/private/defs.h
>
16
#if defined(BI_HAS_PRAGMA_ONCE)
17
# pragma once
18
#endif
19
20
#include <
owl/defs.h
>
21
#include <mbctype.h>
22
#include <vector>
23
24
#if defined(__WINCE__)
25
#define OWL_SET_OEMCP_(idCodePage) static_cast<bool>(::SetOEMCP(static_cast<UINT>(idCodePage)))
26
#define OWL_SET_ANSICP_(idCodePage) static_cast<bool>(::SetACP(static_cast<UINT>(idCodePage)))
27
#else
28
#define OWL_SET_OEMCP_(idCodePage) false
29
#define OWL_SET_ANSICP_(idCodePage) false
30
#endif
31
32
namespace
owl
33
{
34
35
//
36
/// Encapsulates Windows code page functionality.
37
//
38
/// TCodePages is a static class and instantiation is not allowed.
39
//
40
/// The code page list does not get loaded until accessed using `GetCodePageList`
41
/// or `GetIndex`. Loading is performed only once and is persistent until the
42
/// application terminates.
43
//
44
/// The following sample code illustrates loading the code page list in a TComboBox
45
/// control, retrieving the current code page identifier, initializing the selection of
46
/// the control to the currently selected code page identifier, and changing the
47
/// current code page to the user selection.
48
//
49
/// \code
50
/// TComboBox* cbox = new TComboBox(/*...*/);
51
/// // ...
52
/// for (auto &cp : TCodePages::GetCodePageList())
53
/// cbox->AddString(cp.Name);
54
/// auto iCur = TCodePages::GetIndex(TCodePages::GetAnsiCodePageId());
55
/// if (iCur != -1) cbox->SetSelIndex(iCur);
56
/// // ...
57
/// auto iSel = cbox->GetSelIndex();
58
/// if (iSel != -1) TCodePages::SetAnsiCodePageId(TCodePages::GetCodePageList().at(iSel).CodePageId);
59
/// \endcode
60
//
61
class
TCodePages
62
{
63
64
public
:
65
//
66
/// Define the code page, code page object, and container types.
67
//
68
using
TCodePageId
=
uint
;
69
using
TCodePage
=
struct
{
TCodePageId
CodePageId;
bool
Installed;
tstring
Name; };
70
using
TCodePageList
= std::vector<TCodePage>;
71
72
//
73
/// \name Code Page List Operations
74
/// @{
75
76
static
auto
GetCodePageList
() ->
const
TCodePageList
&;
77
static
auto
GetIndex
(
TCodePageId
idCodePage) -> int;
78
79
/// @}
80
81
//
82
/// \name Code Page WINAPI Wrapper Operations
83
/// @{
84
85
//
86
/// Retrieves the current OEM code page identifier.
87
//
88
/// Wrapper function for the Windows API `GetOEMCP`.
89
//
90
/// \return current OEM code page identifier.
91
//
92
/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/dd318114.aspx
93
//
94
static
auto
GetOemCodePageId
() ->
TCodePageId
95
{
return
static_cast<
TCodePageId
>
(::GetOEMCP()); }
96
97
//
98
/// Sets the current OEM code page identifier.
99
//
100
/// Wrapper function for the Windows API `SetOEMCP`.
101
//
102
/// @param[in] idCodePage is the code page identifier to set.
103
//
104
/// \note Avaiable for WINCE only.
105
//
106
/// \return true if successful.
107
//
108
/// \sa http://msdn.microsoft.com/en-us/library/gg155426.aspx
109
//
110
static
auto
SetOemCodePageId
(
TCodePageId
idCodePage) ->
bool
111
{
return
OWL_SET_OEMCP_
(idCodePage); }
112
113
//
114
/// Retrieves the current ANSI code page identifier.
115
//
116
/// Wrapper function for the Windows API `GetACP`.
117
//
118
/// \return current ANSI code page identifier.
119
//
120
/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/dd318070.aspx
121
//
122
static
auto
GetAnsiCodePageId
() ->
TCodePageId
123
{
return
static_cast<
TCodePageId
>
(::GetACP()); }
124
125
//
126
/// Sets the current ANSI code page identifier.
127
//
128
/// Wrapper function for the Windows API `SetACP`.
129
//
130
/// @param[in] idCodePage is the code page identifier to set.
131
//
132
/// \note Avaiable for WINCE only.
133
//
134
/// \return true if successful.
135
//
136
/// \sa http://msdn.microsoft.com/en-us/library/gg155975.aspx
137
//
138
static
auto
SetAnsiCodePageId
(
TCodePageId
idCodePage) ->
bool
139
{
return
OWL_SET_ANSICP_
(idCodePage); }
140
141
//
142
/// Retieves a CPINFOEX structure.
143
//
144
/// Wrapper function for the Windows API `GetCPInfoEx`.
145
//
146
/// @param[in] idCodePage is the code page identifier to use.
147
//
148
/// \return the CPINFOEX structure.
149
//
150
/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/dd318081.aspx
151
/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/dd317781.aspx
152
//
153
static
auto
GetCodePageInfoEx
(
TCodePageId
idCodePage) -> CPINFOEX
154
{
155
CPINFOEX cpInfoEx = { 0 };
156
::GetCPInfoEx(idCodePage, 0, &cpInfoEx);
157
return
cpInfoEx;
158
}
159
160
//
161
/// Retieves a CPINFO structure.
162
//
163
/// Wrapper function for the Windows API `GetCPInfo`.
164
//
165
/// @param[in] idCodePage is the code page identifier to use.
166
//
167
/// \return the CPINFO structure.
168
//
169
/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/dd318078.aspx
170
/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/dd317780.aspx
171
//
172
static
auto
GetCodePageInfo
(
TCodePageId
idCodePage) -> CPINFO
173
{
174
CPINFO cpInfo = { 0 };
175
::GetCPInfo(idCodePage, &cpInfo);
176
return
cpInfo;
177
}
178
179
//
180
/// Retieves the multi-byte code page identifier.
181
//
182
/// Wrapper function for the Windows API `_getmbcp`.
183
//
184
/// \return the multi-byte code page identifier.
185
//
186
/// \sa http://msdn.microsoft.com/en-us/library/4115fwez.aspx
187
//
188
static
auto
GetMultiByteCodePage
() ->
TCodePageId
189
{
return
static_cast<
TCodePageId
>
(::_getmbcp()); }
190
191
//
192
/// Sets the multi-byte code page identifier.
193
//
194
/// Wrapper function for the Windows API `_setmbcp`.
195
//
196
/// @param[in] idCodePage is the code page identifier to set.
197
//
198
/// \return true if successful.
199
//
200
/// \sa http://msdn.microsoft.com/en-us/library/883tf19a.aspx
201
//
202
static
auto
SetMultiByteCodePage
(
TCodePageId
idCodePage) ->
bool
203
{
return
!::_setmbcp(
static_cast<
int
>
(idCodePage)); }
204
205
/// @}
206
207
private
:
208
//
209
/// \name Code Page Internal Operations
210
/// @{
211
212
//
213
/// Internally implements the Meyers Singleton technique for building the code page list once, thread-safely.
214
//
215
static
auto
GetInstance() ->
const
TCodePages
&
216
{
217
static
TCodePages
c;
218
return
c;
219
}
220
221
TCodePages();
222
223
/// @}
224
225
};
// class TCodePages
226
227
}
// owl namespace
228
229
// Release macro definitions; they need not persist.
230
//
231
#undef OWL_SET_OEMCP_
232
#undef OWL_SET_ANSICP_
233
234
#endif
// OWL_CODEPAGES_H
owl::TCodePages
Encapsulates Windows code page functionality.
Definition
codepages.h:62
owl::TCodePages::GetIndex
static auto GetIndex(TCodePageId idCodePage) -> int
Searches the code page list for a code page identifier.
Definition
codepages.cpp:92
owl::TCodePages::SetMultiByteCodePage
static auto SetMultiByteCodePage(TCodePageId idCodePage) -> bool
Sets the multi-byte code page identifier.
Definition
codepages.h:202
owl::TCodePages::TCodePage
struct { TCodePageId CodePageId;bool Installed;tstring Name;} TCodePage
Definition
codepages.h:69
owl::TCodePages::TCodePageList
std::vector< TCodePage > TCodePageList
Definition
codepages.h:70
owl::TCodePages::SetOemCodePageId
static auto SetOemCodePageId(TCodePageId idCodePage) -> bool
Sets the current OEM code page identifier.
Definition
codepages.h:110
owl::TCodePages::SetAnsiCodePageId
static auto SetAnsiCodePageId(TCodePageId idCodePage) -> bool
Sets the current ANSI code page identifier.
Definition
codepages.h:138
owl::TCodePages::GetOemCodePageId
static auto GetOemCodePageId() -> TCodePageId
Retrieves the current OEM code page identifier.
Definition
codepages.h:94
owl::TCodePages::GetAnsiCodePageId
static auto GetAnsiCodePageId() -> TCodePageId
Retrieves the current ANSI code page identifier.
Definition
codepages.h:122
owl::TCodePages::GetMultiByteCodePage
static auto GetMultiByteCodePage() -> TCodePageId
Retieves the multi-byte code page identifier.
Definition
codepages.h:188
owl::TCodePages::GetCodePageInfo
static auto GetCodePageInfo(TCodePageId idCodePage) -> CPINFO
Retieves a CPINFO structure.
Definition
codepages.h:172
owl::TCodePages::GetCodePageList
static auto GetCodePageList() -> const TCodePageList &
Retrieves the code page list.
Definition
codepages.cpp:104
owl::TCodePages::TCodePageId
uint TCodePageId
Define the code page, code page object, and container types.
Definition
codepages.h:68
owl::TCodePages::GetCodePageInfoEx
static auto GetCodePageInfoEx(TCodePageId idCodePage) -> CPINFOEX
Retieves a CPINFOEX structure.
Definition
codepages.h:153
OWL_SET_OEMCP_
#define OWL_SET_OEMCP_(idCodePage)
Definition
codepages.h:28
OWL_SET_ANSICP_
#define OWL_SET_ANSICP_(idCodePage)
Definition
codepages.h:29
owl
Object Windows Library (OWLNext Core).
Definition
animctrl.h:22
owl::tstring
std::string tstring
Definition
defs.h:79
owl::uint
unsigned int uint
Definition
number.h:25
defs.h
General definitions used by all ObjectWindows programs.
defs.h
include
owl
codepages.h
Generated by
1.18.0