editor: support unicode filenames
This commit is contained in:
parent
f5c2fc032e
commit
f22e5c3bcd
@ -24,8 +24,9 @@
|
|||||||
#include "recentfiles.h"
|
#include "recentfiles.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
const char *mainWindowClassName = "MainWindow";
|
const wchar_t *mainWindowClassName = L"MainWindow";
|
||||||
const char *mainWindowTitle = "GNU Rocket System";
|
const char *mainWindowTitle = "GNU Rocket System";
|
||||||
|
const wchar_t *mainWindowTitleW = L"GNU Rocket System";
|
||||||
const char *keyName = "SOFTWARE\\GNU Rocket";
|
const char *keyName = "SOFTWARE\\GNU Rocket";
|
||||||
|
|
||||||
HWND hwnd = NULL;
|
HWND hwnd = NULL;
|
||||||
@ -137,12 +138,12 @@ static LRESULT CALLBACK biasSelectionDialogProc(HWND hDlg, UINT message, WPARAM
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setWindowFileName(std::string fileName)
|
void setWindowFileName(std::wstring fileName)
|
||||||
{
|
{
|
||||||
char drive[_MAX_DRIVE],dir[_MAX_DIR],fname[_MAX_FNAME],ext[_MAX_EXT];
|
wchar_t drive[_MAX_DRIVE],dir[_MAX_DIR],fname[_MAX_FNAME],ext[_MAX_EXT];
|
||||||
_splitpath(fileName.c_str(), drive, dir, fname, ext);
|
_wsplitpath(fileName.c_str(), drive, dir, fname, ext);
|
||||||
std::string windowTitle = std::string(fname) + std::string(" - ") + std::string(mainWindowTitle);
|
std::wstring windowTitle = std::wstring(fname) + std::wstring(L" - ") + std::wstring(mainWindowTitleW);
|
||||||
SetWindowText(hwnd, windowTitle.c_str());
|
SetWindowTextW(hwnd, windowTitle.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
HMENU findSubMenuContaining(HMENU menu, UINT id)
|
HMENU findSubMenuContaining(HMENU menu, UINT id)
|
||||||
@ -163,7 +164,7 @@ HMENU findSubMenuContaining(HMENU menu, UINT id)
|
|||||||
return (HMENU)0;
|
return (HMENU)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string fileName;
|
std::wstring fileName;
|
||||||
|
|
||||||
void fileNew()
|
void fileNew()
|
||||||
{
|
{
|
||||||
@ -175,7 +176,7 @@ void fileNew()
|
|||||||
t->keys = NULL;
|
t->keys = NULL;
|
||||||
t->num_keys = 0;
|
t->num_keys = 0;
|
||||||
}
|
}
|
||||||
setWindowFileName("Untitled");
|
setWindowFileName(L"Untitled");
|
||||||
fileName.clear();
|
fileName.clear();
|
||||||
|
|
||||||
document.clearUndoStack();
|
document.clearUndoStack();
|
||||||
@ -183,7 +184,7 @@ void fileNew()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loadDocument(const std::string &_fileName)
|
void loadDocument(const std::wstring &_fileName)
|
||||||
{
|
{
|
||||||
fileNew();
|
fileNew();
|
||||||
if (document.load(_fileName))
|
if (document.load(_fileName))
|
||||||
@ -206,18 +207,18 @@ void loadDocument(const std::string &_fileName)
|
|||||||
|
|
||||||
void fileOpen()
|
void fileOpen()
|
||||||
{
|
{
|
||||||
char temp[_MAX_FNAME + 1];
|
wchar_t temp[_MAX_FNAME + 1];
|
||||||
temp[0] = '\0'; // clear string
|
temp[0] = L'\0'; // clear string
|
||||||
|
|
||||||
OPENFILENAME ofn;
|
OPENFILENAMEW ofn;
|
||||||
ZeroMemory(&ofn, sizeof(ofn));
|
ZeroMemory(&ofn, sizeof(ofn));
|
||||||
ofn.lStructSize = sizeof(ofn);
|
ofn.lStructSize = sizeof(ofn);
|
||||||
ofn.lpstrFile = temp;
|
ofn.lpstrFile = temp;
|
||||||
ofn.nMaxFile = _MAX_FNAME;
|
ofn.nMaxFile = _MAX_FNAME;
|
||||||
ofn.lpstrDefExt = "rocket";
|
ofn.lpstrDefExt = L"rocket";
|
||||||
ofn.lpstrFilter = "ROCKET File (*.rocket)\0*.rocket\0All Files (*.*)\0*.*\0\0";
|
ofn.lpstrFilter = L"ROCKET File (*.rocket)\0*.rocket\0All Files (*.*)\0*.*\0\0";
|
||||||
ofn.Flags = OFN_SHOWHELP | OFN_FILEMUSTEXIST;
|
ofn.Flags = OFN_SHOWHELP | OFN_FILEMUSTEXIST;
|
||||||
if (GetOpenFileName(&ofn))
|
if (GetOpenFileNameW(&ofn))
|
||||||
{
|
{
|
||||||
loadDocument(temp);
|
loadDocument(temp);
|
||||||
}
|
}
|
||||||
@ -225,19 +226,19 @@ void fileOpen()
|
|||||||
|
|
||||||
void fileSaveAs()
|
void fileSaveAs()
|
||||||
{
|
{
|
||||||
char temp[_MAX_FNAME + 1];
|
wchar_t temp[_MAX_FNAME + 1];
|
||||||
temp[0] = '\0';
|
temp[0] = '\0';
|
||||||
|
|
||||||
OPENFILENAME ofn;
|
OPENFILENAMEW ofn;
|
||||||
ZeroMemory(&ofn, sizeof(ofn));
|
ZeroMemory(&ofn, sizeof(ofn));
|
||||||
ofn.lStructSize = sizeof(ofn);
|
ofn.lStructSize = sizeof(ofn);
|
||||||
ofn.lpstrFile = temp;
|
ofn.lpstrFile = temp;
|
||||||
ofn.nMaxFile = _MAX_FNAME;
|
ofn.nMaxFile = _MAX_FNAME;
|
||||||
ofn.lpstrDefExt = "rocket";
|
ofn.lpstrDefExt = L"rocket";
|
||||||
ofn.lpstrFilter = "ROCKET File (*.rocket)\0*.rocket\0All Files (*.*)\0*.*\0\0";
|
ofn.lpstrFilter = L"ROCKET File (*.rocket)\0*.rocket\0All Files (*.*)\0*.*\0\0";
|
||||||
ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
|
ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
|
||||||
|
|
||||||
if (GetSaveFileName(&ofn))
|
if (GetSaveFileNameW(&ofn))
|
||||||
{
|
{
|
||||||
if (document.save(temp))
|
if (document.save(temp))
|
||||||
{
|
{
|
||||||
@ -398,7 +399,7 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
|
|||||||
case ID_RECENTFILES_FILE5:
|
case ID_RECENTFILES_FILE5:
|
||||||
{
|
{
|
||||||
int index = LOWORD(wParam) - ID_RECENTFILES_FILE1;
|
int index = LOWORD(wParam) - ID_RECENTFILES_FILE1;
|
||||||
std::string fileName;
|
std::wstring fileName;
|
||||||
if (mruFileList.getEntry(index, fileName))
|
if (mruFileList.getEntry(index, fileName))
|
||||||
{
|
{
|
||||||
loadDocument(fileName);
|
loadDocument(fileName);
|
||||||
@ -466,16 +467,16 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
return DefWindowProcW(hwnd, msg, wParam, lParam);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ATOM registerMainWindowClass(HINSTANCE hInstance)
|
static ATOM registerMainWindowClass(HINSTANCE hInstance)
|
||||||
{
|
{
|
||||||
WNDCLASSEX wc;
|
WNDCLASSEXW wc;
|
||||||
|
|
||||||
wc.cbSize = sizeof(WNDCLASSEX);
|
wc.cbSize = sizeof(wc);
|
||||||
wc.style = 0;
|
wc.style = 0;
|
||||||
wc.lpfnWndProc = mainWindowProc;
|
wc.lpfnWndProc = mainWindowProc;
|
||||||
wc.cbClsExtra = 0;
|
wc.cbClsExtra = 0;
|
||||||
@ -484,11 +485,11 @@ static ATOM registerMainWindowClass(HINSTANCE hInstance)
|
|||||||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||||
wc.hbrBackground = (HBRUSH)0;
|
wc.hbrBackground = (HBRUSH)0;
|
||||||
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
|
wc.lpszMenuName = MAKEINTRESOURCEW(IDR_MENU);
|
||||||
wc.lpszClassName = mainWindowClassName;
|
wc.lpszClassName = mainWindowClassName;
|
||||||
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
||||||
|
|
||||||
return RegisterClassEx(&wc);
|
return RegisterClassExW(&wc);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@ -586,10 +587,10 @@ int main(int argc, char* argv[])
|
|||||||
trackView = new TrackView();
|
trackView = new TrackView();
|
||||||
trackView->setDocument(&document);
|
trackView->setDocument(&document);
|
||||||
|
|
||||||
hwnd = CreateWindowEx(
|
hwnd = CreateWindowExW(
|
||||||
0,
|
0,
|
||||||
mainWindowClassName,
|
mainWindowClassName,
|
||||||
mainWindowTitle,
|
mainWindowTitleW,
|
||||||
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
|
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
|
||||||
CW_USEDEFAULT, CW_USEDEFAULT, // x, y
|
CW_USEDEFAULT, CW_USEDEFAULT, // x, y
|
||||||
CW_USEDEFAULT, CW_USEDEFAULT, // width, height
|
CW_USEDEFAULT, CW_USEDEFAULT, // width, height
|
||||||
@ -721,6 +722,6 @@ int main(int argc, char* argv[])
|
|||||||
delete trackView;
|
delete trackView;
|
||||||
trackView = NULL;
|
trackView = NULL;
|
||||||
|
|
||||||
UnregisterClass(mainWindowClassName, hInstance);
|
UnregisterClassW(mainWindowClassName, hInstance);
|
||||||
return int(msg.wParam);
|
return int(msg.wParam);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,25 +5,26 @@
|
|||||||
|
|
||||||
#define MAX_DIR_LEN 64
|
#define MAX_DIR_LEN 64
|
||||||
|
|
||||||
static bool setRegString(HKEY key, const std::string &name, const std::string &value)
|
static bool setRegString(HKEY key, const std::wstring &name, const std::wstring &value)
|
||||||
{
|
{
|
||||||
return ERROR_SUCCESS == RegSetValueEx(key, name.c_str(), 0, REG_SZ, (BYTE *)value.c_str(), (DWORD)value.size());
|
return ERROR_SUCCESS == RegSetValueExW(key, name.c_str(), 0, REG_SZ, (BYTE *)value.c_str(), (DWORD)(value.size() + 1) * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool getRegString(HKEY key, const std::string &name, std::string &out)
|
static bool getRegString(HKEY key, const std::wstring &name, std::wstring &out)
|
||||||
{
|
{
|
||||||
DWORD size = 0;
|
DWORD size = 0;
|
||||||
DWORD type = 0;
|
DWORD type = 0;
|
||||||
if (ERROR_SUCCESS != RegQueryValueEx(key, name.c_str(), 0, &type, (LPBYTE)NULL, &size)) return false;
|
if (ERROR_SUCCESS != RegQueryValueExW(key, name.c_str(), 0, &type, (LPBYTE)NULL, &size)) return false;
|
||||||
if (REG_SZ != type) return false;
|
if (REG_SZ != type) return false;
|
||||||
|
|
||||||
out.resize(size);
|
assert(!(size % 1));
|
||||||
DWORD ret = RegQueryValueEx(key, name.c_str(), 0, &type, (LPBYTE)&out[0], &size);
|
out.resize(size / 2);
|
||||||
while (out.size() > 0 && out[out.size() - 1] == '\0') out.resize(out.size() - 1);
|
DWORD ret = RegQueryValueExW(key, name.c_str(), 0, &type, (LPBYTE)&out[0], &size);
|
||||||
|
while (out.size() > 0 && out[out.size() - 1] == L'\0') out.resize(out.size() - 1);
|
||||||
|
|
||||||
assert(ret == ERROR_SUCCESS);
|
assert(ret == ERROR_SUCCESS);
|
||||||
assert(REG_SZ == type);
|
assert(REG_SZ == type);
|
||||||
assert(size == out.size() + 1);
|
assert(size == (out.size() + 1) * 2);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -32,7 +33,7 @@ void RecentFiles::load(HKEY key)
|
|||||||
{
|
{
|
||||||
for (size_t i = 0; i < 5; ++i)
|
for (size_t i = 0; i < 5; ++i)
|
||||||
{
|
{
|
||||||
std::string fileName;
|
std::wstring fileName;
|
||||||
if (getRegString(key, getEntryName(i), fileName))
|
if (getRegString(key, getEntryName(i), fileName))
|
||||||
{
|
{
|
||||||
mruList.push_back(fileName);
|
mruList.push_back(fileName);
|
||||||
@ -44,7 +45,7 @@ void RecentFiles::load(HKEY key)
|
|||||||
|
|
||||||
void RecentFiles::save(HKEY key)
|
void RecentFiles::save(HKEY key)
|
||||||
{
|
{
|
||||||
std::list<std::string>::const_iterator it;
|
std::list<std::wstring>::const_iterator it;
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0, it = mruList.begin(); it != mruList.end(); ++it, ++i)
|
for (i = 0, it = mruList.begin(); it != mruList.end(); ++it, ++i)
|
||||||
{
|
{
|
||||||
@ -53,7 +54,7 @@ void RecentFiles::save(HKEY key)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecentFiles::insert(const std::string &fileName)
|
void RecentFiles::insert(const std::wstring &fileName)
|
||||||
{
|
{
|
||||||
mruList.remove(fileName); // remove, if present
|
mruList.remove(fileName); // remove, if present
|
||||||
mruList.push_front(fileName); // add to front
|
mruList.push_front(fileName); // add to front
|
||||||
@ -63,28 +64,28 @@ void RecentFiles::insert(const std::string &fileName)
|
|||||||
void RecentFiles::update()
|
void RecentFiles::update()
|
||||||
{
|
{
|
||||||
while (0 != RemoveMenu(mruFileMenu, 0, MF_BYPOSITION));
|
while (0 != RemoveMenu(mruFileMenu, 0, MF_BYPOSITION));
|
||||||
std::list<std::string>::const_iterator it;
|
std::list<std::wstring>::const_iterator it;
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0, it = mruList.begin(); it != mruList.end(); ++it, ++i)
|
for (i = 0, it = mruList.begin(); it != mruList.end(); ++it, ++i)
|
||||||
{
|
{
|
||||||
assert(i <= 5);
|
assert(i <= 5);
|
||||||
std::string menuEntry = std::string("&");
|
std::wstring menuEntry = std::wstring(L"&");
|
||||||
menuEntry += char('1' + i);
|
menuEntry += wchar_t(L'1' + i);
|
||||||
menuEntry += " ";
|
menuEntry += L" ";
|
||||||
|
|
||||||
char path[_MAX_PATH], drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];
|
wchar_t path[_MAX_PATH], drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];
|
||||||
_splitpath(it->c_str(), drive, dir, fname, ext);
|
_wsplitpath(it->c_str(), drive, dir, fname, ext);
|
||||||
if (strlen(dir) > MAX_DIR_LEN) strcpy(dir, "\\...");
|
if (wcslen(dir) > MAX_DIR_LEN) wcscpy(dir, L"\\...");
|
||||||
_makepath(path, drive, dir, fname, ext);
|
_wmakepath(path, drive, dir, fname, ext);
|
||||||
menuEntry += std::string(path);
|
menuEntry += std::wstring(path);
|
||||||
|
|
||||||
AppendMenu(mruFileMenu, MF_STRING, ID_RECENTFILES_FILE1 + i, menuEntry.c_str());
|
AppendMenuW(mruFileMenu, MF_STRING, ID_RECENTFILES_FILE1 + i, menuEntry.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RecentFiles::getEntry(size_t index, std::string &out) const
|
bool RecentFiles::getEntry(size_t index, std::wstring &out) const
|
||||||
{
|
{
|
||||||
std::list<std::string>::const_iterator it;
|
std::list<std::wstring>::const_iterator it;
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0, it = mruList.begin(); it != mruList.end(); ++it, ++i)
|
for (i = 0, it = mruList.begin(); it != mruList.end(); ++it, ++i)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -9,7 +9,7 @@ public:
|
|||||||
|
|
||||||
void load(HKEY key);
|
void load(HKEY key);
|
||||||
void save(HKEY key);
|
void save(HKEY key);
|
||||||
void insert(const std::string &fileName);
|
void insert(const std::wstring &fileName);
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
size_t getEntryCount() const
|
size_t getEntryCount() const
|
||||||
@ -17,16 +17,16 @@ public:
|
|||||||
return mruList.size();
|
return mruList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getEntry(size_t index, std::string &out) const;
|
bool getEntry(size_t index, std::wstring &out) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::string getEntryName(size_t i)
|
static std::wstring getEntryName(size_t i)
|
||||||
{
|
{
|
||||||
std::string temp = std::string("RecentFile");
|
std::wstring temp = std::wstring(L"RecentFile");
|
||||||
temp += char('0' + i);
|
temp += char(L'0' + i);
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<std::string> mruList;
|
std::list<std::wstring> mruList;
|
||||||
HMENU mruFileMenu;
|
HMENU mruFileMenu;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -10,7 +10,7 @@ SyncDocument::~SyncDocument()
|
|||||||
|
|
||||||
#import <msxml3.dll> named_guids
|
#import <msxml3.dll> named_guids
|
||||||
|
|
||||||
bool SyncDocument::load(const std::string &fileName)
|
bool SyncDocument::load(const std::wstring &fileName)
|
||||||
{
|
{
|
||||||
MSXML2::IXMLDOMDocumentPtr doc(MSXML2::CLSID_DOMDocument);
|
MSXML2::IXMLDOMDocumentPtr doc(MSXML2::CLSID_DOMDocument);
|
||||||
try
|
try
|
||||||
@ -73,7 +73,7 @@ bool SyncDocument::load(const std::string &fileName)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SyncDocument::save(const std::string &fileName)
|
bool SyncDocument::save(const std::wstring &fileName)
|
||||||
{
|
{
|
||||||
MSXML2::IXMLDOMDocumentPtr doc(MSXML2::CLSID_DOMDocument);
|
MSXML2::IXMLDOMDocumentPtr doc(MSXML2::CLSID_DOMDocument);
|
||||||
try
|
try
|
||||||
|
|||||||
@ -351,8 +351,8 @@ public:
|
|||||||
std::swap(trackOrder[t1], trackOrder[t2]);
|
std::swap(trackOrder[t1], trackOrder[t2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool load(const std::string &fileName);
|
bool load(const std::wstring &fileName);
|
||||||
bool save(const std::string &fileName);
|
bool save(const std::wstring &fileName);
|
||||||
|
|
||||||
bool modified()
|
bool modified()
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user