mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-14 04:18:36 +00:00
Added code that sets the application icon and added temporary resources (old mC1 icon).
Updated to latest win32cpp to start using the localization.
This commit is contained in:
parent
8cb6178229
commit
0c8d9725a3
@ -45,6 +45,8 @@
|
||||
#include <core/Library/LocalDB.h>
|
||||
#include <core/Pluginfactory.h>
|
||||
|
||||
#include <cube/resources/resource.h>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using namespace musik::cube;
|
||||
@ -79,6 +81,17 @@ MainWindowController::~MainWindowController()
|
||||
|
||||
void MainWindowController::OnMainWindowCreated(Window* window)
|
||||
{
|
||||
|
||||
// Start by setting the icon
|
||||
HICON icon = LoadIcon(Application::Instance(), MAKEINTRESOURCE( IDI_MAINFRAME ) );
|
||||
if ( icon ){
|
||||
|
||||
SendMessage( window->Handle(), WM_SETICON, WPARAM( ICON_SMALL ), LPARAM( icon ) );
|
||||
SendMessage( window->Handle(), WM_SETICON, WPARAM( ICON_BIG ), LPARAM( icon ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
static const int TransportViewHeight = 54;
|
||||
|
||||
this->mainWindow.MoveTo(200, 200);
|
||||
|
@ -451,7 +451,15 @@
|
||||
RelativePath=".\pch.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resources\resource.rc"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
<Global
|
||||
Name="RESOURCE_FILE"
|
||||
Value=".\resources\resource.rc"
|
||||
/>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
|
BIN
src/cube/resources/mC2.ico
Normal file
BIN
src/cube/resources/mC2.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 158 KiB |
5
src/cube/resources/resource.h
Normal file
5
src/cube/resources/resource.h
Normal file
@ -0,0 +1,5 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by resource.rc
|
||||
//
|
||||
#define IDI_MAINFRAME 100
|
15
src/cube/resources/resource.rc
Normal file
15
src/cube/resources/resource.rc
Normal file
@ -0,0 +1,15 @@
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Icon
|
||||
//
|
||||
|
||||
// Icon with lowest ID value placed first to ensure application icon
|
||||
// remains consistent on all systems.
|
||||
IDI_MAINFRAME ICON "mC2.ico"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
301
src/win32cpp/DateTime.cpp
Normal file
301
src/win32cpp/DateTime.cpp
Normal file
@ -0,0 +1,301 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License Agreement:
|
||||
//
|
||||
// The following are Copyright © 2008, André Wösten
|
||||
//
|
||||
// Sources and Binaries of: mC2, win32cpp
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// * Neither the name of the author nor the names of other contributors may
|
||||
// be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <pch.hpp>
|
||||
#include <win32cpp/DateTime.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
#include <sstream>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using namespace win32cpp;
|
||||
|
||||
DateTime::DateTime() : locale(NULL)
|
||||
{
|
||||
// use current local time
|
||||
this->SetLocaltime();
|
||||
}
|
||||
|
||||
DateTime::DateTime(Locale* useLocale) : locale(useLocale)
|
||||
{
|
||||
// use current local time
|
||||
::GetLocalTime(&this->curDateTime);
|
||||
}
|
||||
|
||||
DateTime::DateTime(Locale* useLocale, const SYSTEMTIME& dateTime) :
|
||||
locale(useLocale),
|
||||
curDateTime(dateTime)
|
||||
{
|
||||
// use given time
|
||||
;
|
||||
}
|
||||
|
||||
DateTime::~DateTime()
|
||||
{
|
||||
}
|
||||
|
||||
void DateTime::SetSystemtime(void)
|
||||
{
|
||||
::GetSystemTime(&this->curDateTime);
|
||||
}
|
||||
|
||||
void DateTime::FromSystemtime(const SYSTEMTIME& dateTime)
|
||||
{
|
||||
this->curDateTime = dateTime;
|
||||
}
|
||||
|
||||
void DateTime::SetLocaltime(void)
|
||||
{
|
||||
::GetLocalTime(&this->curDateTime);
|
||||
}
|
||||
|
||||
bool DateTime::FromSQLDateTime(const uistring& sqlDate)
|
||||
{
|
||||
// match YYYY-MM-DD HH:MM:SS
|
||||
// HH:MM:SS is optional
|
||||
boost::cmatch matches;
|
||||
boost::regex e("(\\d{4})-(\\d{2})-(\\d{2})(?: (\\d{2}):(\\d{2}):(\\d{2}))?");
|
||||
|
||||
std::string str = ShrinkString(sqlDate);
|
||||
const char* cstr = str.c_str();
|
||||
|
||||
if(boost::regex_match(cstr, matches, e))
|
||||
{
|
||||
for(unsigned int i = 1; i <= 6; i++)
|
||||
{
|
||||
int c;
|
||||
if(matches[i].matched)
|
||||
{
|
||||
std::string match(matches[i].first, matches[i].second);
|
||||
std::stringstream mstream(match);
|
||||
mstream >> c;
|
||||
}
|
||||
else
|
||||
{
|
||||
c = 0;
|
||||
}
|
||||
|
||||
switch(i)
|
||||
{
|
||||
case 1: this->curDateTime.wYear = c; break;
|
||||
case 2: this->curDateTime.wMonth = c; break;
|
||||
case 3: this->curDateTime.wDay = c; break;
|
||||
case 4: this->curDateTime.wHour = c; break;
|
||||
case 5: this->curDateTime.wMinute = c; break;
|
||||
case 6: this->curDateTime.wSecond = c; break;
|
||||
}
|
||||
}
|
||||
|
||||
this->curDateTime.wMilliseconds = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void DateTime::Set(int year = -1, int month = -1, int dow = -1, int day = -1, int hour = -1, int minute = -1, int second = -1, int millisecond = -1)
|
||||
{
|
||||
// use negative numbers if you don't want to set an element
|
||||
if(year >= 0) this->curDateTime.wYear = year;
|
||||
if(month >= 0) this->curDateTime.wMonth = month;
|
||||
if(dow >= 0) this->curDateTime.wDayOfWeek = dow;
|
||||
if(day >= 0) this->curDateTime.wDay = day;
|
||||
if(hour >= 0) this->curDateTime.wHour = hour;
|
||||
if(minute >= 0) this->curDateTime.wMinute = minute;
|
||||
if(second >= 0) this->curDateTime.wSecond = second;
|
||||
if(millisecond >= 0) this->curDateTime.wMilliseconds = millisecond;
|
||||
}
|
||||
|
||||
uistring DateTime::FormatDate(const uistring& format, DWORD flags = 0)
|
||||
{
|
||||
TCHAR formatted[64];
|
||||
LPCTSTR fstr = NULL;
|
||||
WORD langid = (this->locale != NULL)
|
||||
? (this->locale->LangID())
|
||||
: LOCALE_USER_DEFAULT;
|
||||
|
||||
if(!format.empty()) fstr = format.c_str();
|
||||
|
||||
int ret = ::GetDateFormat(
|
||||
MAKELCID(langid, SORT_DEFAULT),
|
||||
flags,
|
||||
&this->curDateTime,
|
||||
fstr,
|
||||
formatted,
|
||||
64
|
||||
);
|
||||
|
||||
if(!ret) {
|
||||
throw Win32Exception();
|
||||
}
|
||||
|
||||
return uistring(formatted);
|
||||
}
|
||||
|
||||
uistring DateTime::FormatTime(const uistring& format, DWORD flags = 0)
|
||||
{
|
||||
TCHAR formatted[64];
|
||||
LPCTSTR fstr = NULL;
|
||||
WORD langid = (this->locale != NULL)
|
||||
? (this->locale->LangID())
|
||||
: LOCALE_USER_DEFAULT;
|
||||
|
||||
if(!format.empty()) fstr = format.c_str();
|
||||
|
||||
int ret = ::GetTimeFormat(
|
||||
MAKELCID(langid, SORT_DEFAULT),
|
||||
flags,
|
||||
&this->curDateTime,
|
||||
fstr,
|
||||
formatted,
|
||||
64
|
||||
);
|
||||
|
||||
if(!ret) {
|
||||
throw Win32Exception();
|
||||
}
|
||||
|
||||
return uistring(formatted);
|
||||
}
|
||||
|
||||
uistring DateTime::Date()
|
||||
{
|
||||
// is a locale set?
|
||||
if(this->locale)
|
||||
{
|
||||
// get format string for dates
|
||||
uistring fmtDate = this->locale->DateFormat();
|
||||
if(fmtDate.empty())
|
||||
{
|
||||
// if the date format is empty, use the locale-specific
|
||||
return this->FormatDate(_T(""), DATE_SHORTDATE);
|
||||
}
|
||||
else
|
||||
{
|
||||
// if the date format is given, use it
|
||||
return this->FormatDate(fmtDate);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// if no locale is set, use the user/system-specific
|
||||
// (which is ALWAYS installed and supported)
|
||||
return this->FormatDate(_T(""), DATE_SHORTDATE);
|
||||
}
|
||||
}
|
||||
|
||||
uistring DateTime::Time()
|
||||
{
|
||||
// is a locale set?
|
||||
if(this->locale)
|
||||
{
|
||||
// get format string for times
|
||||
uistring fmtTime = this->locale->TimeFormat();
|
||||
if(fmtTime.empty())
|
||||
{
|
||||
// if the time format is empty, use the locale-specific
|
||||
return this->FormatTime(_T(""));
|
||||
}
|
||||
else
|
||||
{
|
||||
// if the time format is given, use it
|
||||
return this->FormatTime(fmtTime);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// if no locale is set, use the user/system-specific
|
||||
// (which is ALWAYS installed and supported)
|
||||
return this->FormatTime(_T(""));
|
||||
}
|
||||
}
|
||||
|
||||
uistring DateTime::MonthString()
|
||||
{
|
||||
// if a locale is given and installed, return specified by locale
|
||||
if(this->locale && this->locale->SystemSupport())
|
||||
{
|
||||
return this->FormatDate(_T("MMMM"));
|
||||
}
|
||||
|
||||
// otherwise, use the standard names, passing them through the translation map of the locale
|
||||
// if a locale is not installed in the NLS-subsystem of windows
|
||||
switch(this->curDateTime.wMonth)
|
||||
{
|
||||
case 1: return _(_T("January"));
|
||||
case 2: return _(_T("February"));
|
||||
case 3: return _(_T("March"));
|
||||
case 4: return _(_T("April"));
|
||||
case 5: return _(_T("May"));
|
||||
case 6: return _(_T("June"));
|
||||
case 7: return _(_T("July"));
|
||||
case 8: return _(_T("August"));
|
||||
case 9: return _(_T("September"));
|
||||
case 10: return _(_T("October"));
|
||||
case 11: return _(_T("November"));
|
||||
case 12: return _(_T("December"));
|
||||
}
|
||||
|
||||
return _T("(null)");
|
||||
}
|
||||
|
||||
uistring DateTime::DayOfWeekString()
|
||||
{
|
||||
// if a locale is given and installed, return specified by locale
|
||||
if(this->locale && this->locale->SystemSupport())
|
||||
{
|
||||
return this->FormatDate(_T("dddd"));
|
||||
}
|
||||
|
||||
// otherwise, use the standard names, passing them through the translation map of the locale
|
||||
// if a locale is not installed in the NLS-subsystem of windows
|
||||
switch(this->curDateTime.wDayOfWeek)
|
||||
{
|
||||
case 0: return _(_T("Sunday"));
|
||||
case 1: return _(_T("Monday"));
|
||||
case 2: return _(_T("Tuesday"));
|
||||
case 3: return _(_T("Wednesday"));
|
||||
case 4: return _(_T("Thursday"));
|
||||
case 5: return _(_T("Friday"));
|
||||
case 6: return _(_T("Saturday"));
|
||||
}
|
||||
|
||||
return _T("(null)");
|
||||
}
|
||||
|
94
src/win32cpp/DateTime.hpp
Normal file
94
src/win32cpp/DateTime.hpp
Normal file
@ -0,0 +1,94 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License Agreement:
|
||||
//
|
||||
// The following are Copyright © 2008, André Wösten
|
||||
//
|
||||
// Sources and Binaries of: mC2, win32cpp
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// * Neither the name of the author nor the names of other contributors may
|
||||
// be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <win32cpp/Locale.hpp>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace win32cpp {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// DateTime
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DateTime {
|
||||
private:
|
||||
SYSTEMTIME curDateTime;
|
||||
Locale* locale;
|
||||
public:
|
||||
int Year() const { return this->curDateTime.wYear; }
|
||||
int Month() const { return this->curDateTime.wMonth; }
|
||||
int DayOfWeek() const { return this->curDateTime.wDayOfWeek; }
|
||||
int Day() const { return this->curDateTime.wDay; }
|
||||
int Hour() const { return this->curDateTime.wHour; }
|
||||
int Minute() const { return this->curDateTime.wMinute; }
|
||||
int Second() const { return this->curDateTime.wSecond; }
|
||||
int Millisecond() const { return this->curDateTime.wMilliseconds; }
|
||||
|
||||
uistring MonthString();
|
||||
uistring DayOfWeekString();
|
||||
|
||||
uistring Date();
|
||||
uistring Time();
|
||||
ULONG Timestamp() const;
|
||||
|
||||
uistring FormatDate(const uistring& format, DWORD flags);
|
||||
uistring FormatTime(const uistring& format, DWORD flags);
|
||||
|
||||
const PSYSTEMTIME
|
||||
Win32Systemtime();
|
||||
|
||||
void Set(int year, int month, int dow, int day, int hour, int minute, int second, int millisecond);
|
||||
void SetSystemtime(void);
|
||||
void SetLocaltime(void);
|
||||
|
||||
void FromSystemtime(const SYSTEMTIME& dateTime);
|
||||
bool FromSQLDateTime(const uistring& sqlDate);
|
||||
|
||||
/* ctor */ DateTime();
|
||||
/* ctor */ DateTime(Locale* useLocale);
|
||||
/* ctor */ DateTime(Locale* useLocale, const SYSTEMTIME& dateTime);
|
||||
/* dtor */ ~DateTime();
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
@ -50,11 +50,15 @@ using namespace win32cpp;
|
||||
|
||||
Locale::Locale()
|
||||
{
|
||||
;
|
||||
// set default language identifier
|
||||
// 0x0409 = English (United States) / en-US / Codepage 1252
|
||||
this->localeID = 0x0409;
|
||||
}
|
||||
|
||||
Locale::Locale(const uistring& dirName, const uistring& locale)
|
||||
{
|
||||
Locale();
|
||||
|
||||
this->SetLocaleDirectory(dirName);
|
||||
if(!this->LoadConfig(locale))
|
||||
{
|
||||
@ -80,30 +84,54 @@ uistring Locale::Translate(const uistring& original)
|
||||
|
||||
bool Locale::LoadConfig(const uistring& localeName)
|
||||
{
|
||||
uistring path = this->localeDirectory + L"\\" + localeName + L".ini";
|
||||
uistring path = this->localeDirectory + _T("\\" + localeName + L".ini");
|
||||
|
||||
if(!fs::exists(path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
config.SetFileName(path);
|
||||
this->config.SetFileName(path);
|
||||
|
||||
// read locale configuration
|
||||
this->config.SetSection(_T("config"));
|
||||
|
||||
// read name (for combo box displaying the languages)
|
||||
this->localeName = this->config.Value(_T("name"));
|
||||
if(this->localeName.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// read locale identifier, necessary for e.g. DateTime
|
||||
// (http://msdn.microsoft.com/en-us/library/ms776260(VS.85).aspx)
|
||||
// example: 0x0407 for german
|
||||
uistring temp = this->config.Value(_T("locale_identifier"));
|
||||
int id = HexToInt(temp.c_str());
|
||||
if(id != 0)
|
||||
{
|
||||
this->localeID = static_cast<WORD>(id);
|
||||
}
|
||||
|
||||
// read format strings for date/time formatting
|
||||
this->dateFormat = this->config.Value(_T("locale_date"));
|
||||
this->timeFormat = this->config.Value(_T("locale_time"));
|
||||
|
||||
// generate translation map
|
||||
for(int i = 1; ; i++)
|
||||
{
|
||||
// convert int to tchar
|
||||
TCHAR section[8];
|
||||
_stprintf_s(section, L"%d", i);
|
||||
_stprintf_s(section, _T("%d"), i);
|
||||
|
||||
if(config.SectionExists(uistring(section)))
|
||||
if(this->config.SectionExists(uistring(section)))
|
||||
{
|
||||
config.SetSection(section);
|
||||
this->config.SetSection(section);
|
||||
|
||||
// put translation into map
|
||||
uistring
|
||||
original = config.Value(L"original"),
|
||||
translated = config.Value(L"translated");
|
||||
original = config.Value(_T("original")),
|
||||
translated = config.Value(_T("translated"));
|
||||
|
||||
this->translationMap[original] = translated;
|
||||
}
|
||||
@ -135,3 +163,45 @@ void Locale::SetLocaleDirectory(const uistring &dirName)
|
||||
|
||||
this->localeDirectory = uistring(localeDir);
|
||||
}
|
||||
|
||||
LocaleList Locale::EnumLocales(void)
|
||||
{
|
||||
uistring path = this->localeDirectory;
|
||||
|
||||
// check if path is valid
|
||||
if(!fs::exists(path) && fs::is_directory(path))
|
||||
{
|
||||
throw new Exception("Could not enumerate. Directory with locales is invalid.");
|
||||
}
|
||||
|
||||
// iterate through locale directory and collect available locales
|
||||
LocaleList localeList;
|
||||
|
||||
// convert directory to boost path
|
||||
fs::path localePath(ShrinkString(path), fs::native);
|
||||
|
||||
// now iterate...
|
||||
fs::directory_iterator iEnd;
|
||||
for(fs::directory_iterator iDir(localePath); iDir != iEnd; ++iDir)
|
||||
{
|
||||
// lame conversion =(
|
||||
std::string dirEntryA = iDir->path().leaf();
|
||||
uistring dirEntryW = WidenString(dirEntryA.c_str());
|
||||
|
||||
// read name of config
|
||||
Config entryConfig(path + _T("\\") + dirEntryW);
|
||||
if(entryConfig.SectionExists(_T("config")))
|
||||
{
|
||||
entryConfig.SetSection(_T("config"));
|
||||
localeList[dirEntryW.c_str()] = entryConfig.Value(_T("name"));
|
||||
}
|
||||
}
|
||||
|
||||
return localeList;
|
||||
}
|
||||
|
||||
|
||||
BOOL Locale::SystemSupport() const
|
||||
{
|
||||
return ::IsValidLocale(this->localeID, LCID_INSTALLED);
|
||||
}
|
||||
|
@ -38,8 +38,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <varargs.h>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace win32cpp {
|
||||
@ -48,13 +46,17 @@ namespace win32cpp {
|
||||
// Locale
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef std::vector<uistring> LocaleList;
|
||||
typedef std::map<uistring, uistring> LocaleList;
|
||||
typedef std::map<uistring, uistring> LocaleTranslationMap;
|
||||
|
||||
class Locale {
|
||||
private:
|
||||
Config config;
|
||||
uistring localeDirectory;
|
||||
uistring localeName;
|
||||
WORD localeID;
|
||||
uistring dateFormat;
|
||||
uistring timeFormat;
|
||||
|
||||
LocaleTranslationMap
|
||||
translationMap;
|
||||
@ -64,6 +66,12 @@ public:
|
||||
void SetLocaleDirectory(const uistring& dirName);
|
||||
LocaleList EnumLocales(void);
|
||||
uistring Translate(const uistring& original);
|
||||
uistring LocaleName(void) const { return this->localeName; }
|
||||
WORD LangID(void) const { return this->localeID; }
|
||||
uistring DateFormat(void) const { return this->dateFormat; }
|
||||
uistring TimeFormat(void) const { return this->timeFormat; }
|
||||
BOOL SystemSupport(void) const;
|
||||
|
||||
|
||||
static Locale* Instance()
|
||||
{
|
||||
|
@ -51,6 +51,84 @@ uistring win32cpp::Escape(uistring string){
|
||||
return string;
|
||||
}
|
||||
|
||||
uistring win32cpp::WidenString(const char* str)
|
||||
{
|
||||
uistring tstr;
|
||||
int len = (int)strlen(str) + 1;
|
||||
|
||||
uichar* t = new uichar[len];
|
||||
if (t == NULL) throw std::bad_alloc();
|
||||
|
||||
mbstowcs(t, str, len);
|
||||
tstr = t;
|
||||
|
||||
delete[] t;
|
||||
|
||||
return tstr;
|
||||
}
|
||||
|
||||
std::string win32cpp::ShrinkString(const uistring& str)
|
||||
{
|
||||
std::string cstr;
|
||||
int len = (int)str.length() + 1;
|
||||
|
||||
char* t = new char[len];
|
||||
if (t == NULL) throw std::bad_alloc();
|
||||
|
||||
wcstombs(t, str.c_str(), len);
|
||||
cstr = t;
|
||||
|
||||
delete[] t;
|
||||
|
||||
return cstr;
|
||||
}
|
||||
|
||||
int win32cpp::HexToInt(const uichar* value)
|
||||
{
|
||||
struct CHexMap
|
||||
{
|
||||
TCHAR chr;
|
||||
int value;
|
||||
};
|
||||
const int HexMapL = 16;
|
||||
CHexMap HexMap[HexMapL] =
|
||||
{
|
||||
{'0', 0}, {'1', 1},
|
||||
{'2', 2}, {'3', 3},
|
||||
{'4', 4}, {'5', 5},
|
||||
{'6', 6}, {'7', 7},
|
||||
{'8', 8}, {'9', 9},
|
||||
{'A', 10}, {'B', 11},
|
||||
{'C', 12}, {'D', 13},
|
||||
{'E', 14}, {'F', 15}
|
||||
};
|
||||
TCHAR *mstr = _tcsupr(_tcsdup(value));
|
||||
TCHAR *s = mstr;
|
||||
int result = 0;
|
||||
if (*s == '0' && *(s + 1) == 'X') s += 2;
|
||||
bool firsttime = true;
|
||||
while (*s != '\0')
|
||||
{
|
||||
bool found = false;
|
||||
for (int i = 0; i < HexMapL; i++)
|
||||
{
|
||||
if (*s == HexMap[i].chr)
|
||||
{
|
||||
if (!firsttime) result <<= 4;
|
||||
result |= HexMap[i].value;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) break;
|
||||
s++;
|
||||
firsttime = false;
|
||||
}
|
||||
free(mstr);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
@ -47,6 +47,9 @@ namespace win32cpp {
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
uistring Escape(uistring string);
|
||||
int HexToInt(const uichar* value);
|
||||
uistring WidenString(const char* str);
|
||||
std::string ShrinkString(const uistring& str);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -43,19 +43,17 @@
|
||||
#include <win32cpp/Win32Config.hpp> // Must be first!
|
||||
|
||||
#include <win32cpp/Application.hpp>
|
||||
#include <win32cpp/ApplicationThread.hpp>
|
||||
#include <win32cpp/BarLayout.hpp>
|
||||
#include <win32cpp/Button.hpp>
|
||||
#include <win32cpp/Color.hpp>
|
||||
#include <win32cpp/Config.hpp>
|
||||
#include <win32cpp/Container.hpp>
|
||||
#include <win32cpp/DateTime.hpp>
|
||||
#include <win32cpp/DeviceContext.hpp>
|
||||
#include <win32cpp/EditView.hpp>
|
||||
#include <win32cpp/Exception.hpp>
|
||||
#include <win32cpp/FolderBrowseDialog.hpp>
|
||||
#include <win32cpp/Font.hpp>
|
||||
#include <win32cpp/Frame.hpp>
|
||||
#include <win32cpp/ILayout.hpp>
|
||||
#include <win32cpp/Label.hpp>
|
||||
#include <win32cpp/LinearLayout.hpp>
|
||||
#include <win32cpp/ListView.hpp>
|
||||
@ -63,17 +61,14 @@
|
||||
#include <win32cpp/MemoryDC.hpp>
|
||||
#include <win32cpp/Menu.hpp>
|
||||
#include <win32cpp/Panel.hpp>
|
||||
#include <win32cpp/ProgressBar.hpp>
|
||||
#include <win32cpp/RedrawLock.hpp>
|
||||
#include <win32cpp/Splitter.hpp>
|
||||
#include <win32cpp/Trackbar.hpp>
|
||||
#include <win32cpp/Splitter.hpp>
|
||||
#include <win32cpp/TabView.hpp>
|
||||
#include <win32cpp/Timer.hpp>
|
||||
#include <win32cpp/TopLevelWindow.hpp>
|
||||
#include <win32cpp/Types.hpp>
|
||||
#include <win32cpp/Utility.hpp>
|
||||
#include <win32cpp/Window.hpp>
|
||||
#include <win32cpp/WindowGeometry.hpp>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Version="8,00"
|
||||
Name="win32cpp"
|
||||
ProjectGUID="{E618F29F-BF28-441A-B039-9E10A631D881}"
|
||||
RootNamespace="win32cpp"
|
||||
@ -464,6 +464,14 @@
|
||||
RelativePath=".\Config.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DateTime.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DateTime.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Locale.cpp"
|
||||
>
|
||||
|
Loading…
x
Reference in New Issue
Block a user