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