editor: get rid of some TCHARism

We dont need unicode everywhere. TCHARism is just noise.
This commit is contained in:
Erik Faye-Lund 2010-03-24 18:08:31 +01:00
parent 7934871684
commit 06c75438cf
7 changed files with 75 additions and 78 deletions

View File

@ -24,9 +24,9 @@
#include "recentfiles.h"
#include <vector>
const TCHAR *mainWindowClassName = _T("MainWindow");
const TCHAR *mainWindowTitle = _T("GNU Rocket System");
const TCHAR *keyName = _T("SOFTWARE\\GNU Rocket");
const char *mainWindowClassName = "MainWindow";
const char *mainWindowTitle = "GNU Rocket System";
const char *keyName = "SOFTWARE\\GNU Rocket";
HWND hwnd = NULL;
TrackView *trackView = NULL;
@ -51,8 +51,8 @@ static LRESULT CALLBACK setRowsDialogProc(HWND hDlg, UINT message, WPARAM wParam
assert(NULL != rows);
/* create row-string */
TCHAR temp[256];
_sntprintf_s(temp, 256, _T("%d"), *rows);
char temp[256];
_snprintf_s(temp, 256, "%d", *rows);
/* set initial row count */
SetDlgItemText(hDlg, IDC_SETROWS_EDIT, temp);
@ -64,9 +64,9 @@ static LRESULT CALLBACK setRowsDialogProc(HWND hDlg, UINT message, WPARAM wParam
if (LOWORD(wParam) == IDOK)
{
/* get value */
TCHAR temp[256];
char temp[256];
GetDlgItemText(hDlg, IDC_SETROWS_EDIT, temp, 256);
int result = _tstoi(temp);
int result = atoi(temp);
/* update editor */
SendMessage(GetParent(hDlg), WM_SETROWS, 0, result);
@ -100,8 +100,8 @@ static LRESULT CALLBACK biasSelectionDialogProc(HWND hDlg, UINT message, WPARAM
assert(NULL != intialBias);
/* create bias-string */
TCHAR temp[256];
_sntprintf_s(temp, 256, _T("%d"), *intialBias);
char temp[256];
_snprintf(temp, 256, "%d", *intialBias);
/* set initial bias */
SetDlgItemText(hDlg, IDC_SETROWS_EDIT, temp);
@ -112,9 +112,9 @@ static LRESULT CALLBACK biasSelectionDialogProc(HWND hDlg, UINT message, WPARAM
if (LOWORD(wParam) == IDOK)
{
/* get value */
TCHAR temp[256];
char temp[256];
GetDlgItemText(hDlg, IDC_BIASSELECTION_EDIT, temp, 256);
int bias = _tstoi(temp);
int bias = atoi(temp);
/* update editor */
SendMessage(GetParent(hDlg), WM_BIASSELECTION, 0, LPARAM(bias));
@ -139,8 +139,8 @@ static LRESULT CALLBACK biasSelectionDialogProc(HWND hDlg, UINT message, WPARAM
void setWindowFileName(std::string fileName)
{
TCHAR drive[_MAX_DRIVE],dir[_MAX_DIR],fname[_MAX_FNAME],ext[_MAX_EXT];
_tsplitpath(fileName.c_str(), drive, dir, fname, ext);
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());
}
@ -201,7 +201,7 @@ void loadDocument(const std::string &_fileName)
SendMessage(hwnd, WM_CURRVALDIRTY, 0, 0);
InvalidateRect(trackViewWin, NULL, FALSE);
}
else MessageBox(hwnd, _T("failed to open file"), mainWindowTitle, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
else MessageBox(hwnd, "failed to open file", mainWindowTitle, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
}
void fileOpen()
@ -249,7 +249,7 @@ void fileSaveAs()
mruFileList.update();
DrawMenuBar(hwnd);
}
else MessageBox(hwnd, _T("Failed to save file"), mainWindowTitle, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
else MessageBox(hwnd, "Failed to save file", mainWindowTitle, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
}
}
@ -259,7 +259,7 @@ void fileSave()
else if (!document.save(fileName.c_str()))
{
document.sendSaveCommand();
MessageBox(hwnd, _T("Failed to save file"), mainWindowTitle, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
MessageBox(hwnd, "Failed to save file", mainWindowTitle, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
}
}
@ -267,7 +267,7 @@ void attemptQuit()
{
if (document.modified())
{
UINT res = MessageBox(hwnd, _T("Save before exit?"), mainWindowTitle, MB_YESNOCANCEL | MB_ICONQUESTION);
UINT res = MessageBox(hwnd, "Save before exit?", mainWindowTitle, MB_YESNOCANCEL | MB_ICONQUESTION);
if (IDYES == res) fileSave();
if (IDCANCEL != res) DestroyWindow(hwnd);
}
@ -298,10 +298,10 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
int statwidths[] = { 150, 150 + 32, 150 + 32 * 2, 150 + 32 * 4};
SendMessage(statusBarWin, SB_SETPARTS, sizeof(statwidths) / sizeof(int), (LPARAM)statwidths);
SendMessage(statusBarWin, SB_SETTEXT, 0, (LPARAM)_T("Not connected"));
SendMessage(statusBarWin, SB_SETTEXT, 1, (LPARAM)_T("0"));
SendMessage(statusBarWin, SB_SETTEXT, 2, (LPARAM)_T("0"));
SendMessage(statusBarWin, SB_SETTEXT, 3, (LPARAM)_T("---"));
SendMessage(statusBarWin, SB_SETTEXT, 0, (LPARAM)"Not connected");
SendMessage(statusBarWin, SB_SETTEXT, 1, (LPARAM)"0");
SendMessage(statusBarWin, SB_SETTEXT, 2, (LPARAM)"0");
SendMessage(statusBarWin, SB_SETTEXT, 3, (LPARAM)"---");
if (ERROR_SUCCESS != RegOpenKey(HKEY_CURRENT_USER, keyName, &regConfigKey))
{
@ -421,7 +421,7 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
HINSTANCE hInstance = GetModuleHandle(NULL);
int rows = int(trackView->getRows());
INT_PTR result = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_SETROWS), hwnd, (DLGPROC)setRowsDialogProc, (LPARAM)&rows);
if (FAILED(result)) MessageBox(hwnd, _T("unable to create dialog box"), mainWindowTitle, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
if (FAILED(result)) MessageBox(hwnd, "unable to create dialog box", mainWindowTitle, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
}
break;
@ -430,7 +430,7 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
HINSTANCE hInstance = GetModuleHandle(NULL);
int initialBias = 0;
INT_PTR result = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_BIASSELECTION), hwnd, (DLGPROC)biasSelectionDialogProc, (LPARAM)&initialBias);
if (FAILED(result)) MessageBox(hwnd, _T("unable to create dialog box"), mainWindowTitle, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
if (FAILED(result)) MessageBox(hwnd, "unable to create dialog box", mainWindowTitle, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
}
break;
}
@ -438,29 +438,29 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
case WM_ROWCHANGED:
{
TCHAR temp[256];
_sntprintf_s(temp, 256, _T("%d"), lParam );
char temp[256];
_snprintf_s(temp, 256, "%d", lParam );
SendMessage(statusBarWin, SB_SETTEXT, 1, (LPARAM)temp);
}
break;
case WM_TRACKCHANGED:
{
TCHAR temp[256];
_sntprintf_s(temp, 256, _T("%d"), lParam);
char temp[256];
_snprintf_s(temp, 256, "%d", lParam);
SendMessage(statusBarWin, SB_SETTEXT, 2, (LPARAM)temp);
}
break;
case WM_CURRVALDIRTY:
{
TCHAR temp[256];
char temp[256];
if (document.num_tracks > 0) {
sync_track *t = document.tracks[document.getTrackIndexFromPos(trackView->getEditTrack())];
float row = float(trackView->getEditRow());
_sntprintf_s(temp, 256, _T("%f"), sync_get_val(t, row));
_snprintf_s(temp, 256, "%f", sync_get_val(t, row));
} else
_sntprintf_s(temp, 256, _T("---"));
_snprintf_s(temp, 256, "---");
SendMessage(statusBarWin, SB_SETTEXT, 3, (LPARAM)temp);
}
break;
@ -530,7 +530,7 @@ SOCKET clientConnect(SOCKET serverSocket, sockaddr_in *host)
return clientSocket;
}
int _tmain(int argc, _TCHAR* argv[])
int main(int argc, char* argv[])
{
#ifdef _DEBUG
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
@ -624,13 +624,13 @@ int _tmain(int argc, _TCHAR* argv[])
// look for new clients
if (select(0, &fds, NULL, NULL, &timeout) > 0)
{
SendMessage(statusBarWin, SB_SETTEXT, 0, (LPARAM)_T("Accepting..."));
SendMessage(statusBarWin, SB_SETTEXT, 0, (LPARAM)"Accepting...");
sockaddr_in client;
clientSocket = clientConnect(serverSocket, &client);
if (INVALID_SOCKET != clientSocket)
{
TCHAR temp[256];
_sntprintf_s(temp, 256, _T("Connected to %s"), inet_ntoa(client.sin_addr));
char temp[256];
_snprintf_s(temp, 256, "Connected to %s", inet_ntoa(client.sin_addr));
SendMessage(statusBarWin, SB_SETTEXT, 0, (LPARAM)temp);
document.clientSocket = NetworkSocket(clientSocket);
document.clientRemap.clear();
@ -638,7 +638,7 @@ int _tmain(int argc, _TCHAR* argv[])
document.sendSetRowCommand(trackView->getEditRow());
guiConnected = true;
}
else SendMessage(statusBarWin, SB_SETTEXT, 0, (LPARAM)_T("Not Connected."));
else SendMessage(statusBarWin, SB_SETTEXT, 0, (LPARAM)"Not Connected.");
}
}
@ -699,7 +699,7 @@ int _tmain(int argc, _TCHAR* argv[])
{
document.clientPaused = true;
InvalidateRect(trackViewWin, NULL, FALSE);
SendMessage(statusBarWin, SB_SETTEXT, 0, (LPARAM)_T("Not Connected."));
SendMessage(statusBarWin, SB_SETTEXT, 0, (LPARAM)"Not Connected.");
guiConnected = false;
}

View File

@ -70,10 +70,10 @@ void RecentFiles::update()
menuEntry += char('1' + i);
menuEntry += " ";
TCHAR path[_MAX_PATH], drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];
_tsplitpath(it->c_str(), drive, dir, fname, ext);
if (_tcslen(dir) > MAX_DIR_LEN) _tcscpy(dir, _T("\\..."));
_tmakepath(path, drive, dir, fname, ext);
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);
AppendMenu(mruFileMenu, MF_STRING, ID_RECENTFILES_FILE1 + i, menuEntry.c_str());

View File

@ -11,6 +11,5 @@
#include <list>
#include <stdio.h>
#include <tchar.h>
#include <assert.h>
#define ASSERT(x) assert(x)

View File

@ -1,6 +1,5 @@
#include "syncdocument.h"
#include <string>
#include <tchar.h>
SyncDocument::~SyncDocument()
{
@ -81,19 +80,19 @@ bool SyncDocument::save(const std::string &fileName)
{
char temp[256];
_variant_t varNodeType((short)MSXML2::NODE_ELEMENT);
MSXML2::IXMLDOMElementPtr rootNode = doc->createElement(_T("tracks"));
MSXML2::IXMLDOMElementPtr rootNode = doc->createElement("tracks");
doc->appendChild(rootNode);
_snprintf(temp, 256, "%d", getRows());
rootNode->setAttribute(_T("rows"), temp);
rootNode->setAttribute("rows", temp);
for (size_t i = 0; i < num_tracks; ++i) {
const sync_track *t = tracks[i];
MSXML2::IXMLDOMElementPtr trackElem = doc->createElement(_T("track"));
trackElem->setAttribute(_T("name"), t->name);
MSXML2::IXMLDOMElementPtr trackElem = doc->createElement("track");
trackElem->setAttribute("name", t->name);
rootNode->appendChild(doc->createTextNode(_T("\n\t")));
rootNode->appendChild(doc->createTextNode("\n\t"));
rootNode->appendChild(trackElem);
for (int i = 0; i < (int)t->num_keys; ++i) {
@ -101,25 +100,25 @@ bool SyncDocument::save(const std::string &fileName)
float value = t->keys[i].value;
char interpolationType = char(t->keys[i].type);
MSXML2::IXMLDOMElementPtr keyElem = doc->createElement(_T("key"));
MSXML2::IXMLDOMElementPtr keyElem = doc->createElement("key");
_snprintf(temp, 256, _T("%d"), row);
keyElem->setAttribute(_T("row"), temp);
_snprintf(temp, 256, "%d", row);
keyElem->setAttribute("row", temp);
_snprintf(temp, 256, _T("%f"), value);
keyElem->setAttribute(_T("value"), temp);
_snprintf(temp, 256, "%f", value);
keyElem->setAttribute("value", temp);
_snprintf(temp, 256, _T("%d"), interpolationType);
keyElem->setAttribute(_T("interpolation"), temp);
_snprintf(temp, 256, "%d", interpolationType);
keyElem->setAttribute("interpolation", temp);
trackElem->appendChild(doc->createTextNode(_T("\n\t\t")));
trackElem->appendChild(doc->createTextNode("\n\t\t"));
trackElem->appendChild(keyElem);
}
if (t->num_keys)
trackElem->appendChild(doc->createTextNode(_T("\n\t")));
trackElem->appendChild(doc->createTextNode("\n\t"));
}
if (0 != num_tracks)
rootNode->appendChild(doc->createTextNode(_T("\n")));
rootNode->appendChild(doc->createTextNode("\n"));
doc->save(fileName.c_str());

View File

@ -74,7 +74,7 @@ public:
~SyncDocument();
size_t createTrack(const std::basic_string<TCHAR> &name)
size_t createTrack(const std::string &name)
{
size_t index = sync_create_track(this, name.c_str());
trackOrder.push_back(index);

View File

@ -4,16 +4,15 @@
#include "trackview.h"
#include <vector>
#include <tchar.h>
static const TCHAR *trackViewWindowClassName = _T("TrackView");
static const char *trackViewWindowClassName = "TrackView";
static DWORD darken(DWORD col, float amt)
{
return RGB(GetRValue(col) * amt, GetGValue(col) * amt, GetBValue(col) * amt);
}
static int getMaxCharacterWidth(HDC hdc, TCHAR *chars, size_t len)
static int getMaxCharacterWidth(HDC hdc, char *chars, size_t len)
{
int maxDigitWidth = 0;
for (size_t i = 0; i < len; ++i)
@ -25,9 +24,9 @@ static int getMaxCharacterWidth(HDC hdc, TCHAR *chars, size_t len)
return maxDigitWidth;
}
static int getMaxCharacterWidthFromString(HDC hdc, TCHAR *chars)
static int getMaxCharacterWidthFromString(HDC hdc, char *chars)
{
return getMaxCharacterWidth(hdc, chars, _tcslen(chars));
return getMaxCharacterWidth(hdc, chars, strlen(chars));
}
TrackView::TrackView()
@ -60,7 +59,7 @@ TrackView::TrackView()
editBrush = CreateSolidBrush(RGB(255, 255, 0)); // yellow
clipboardFormat = RegisterClipboardFormat(_T("syncdata"));
clipboardFormat = RegisterClipboardFormat("syncdata");
assert(0 != clipboardFormat);
}
@ -91,10 +90,10 @@ void TrackView::setFont(HFONT font)
rowHeight = tm.tmHeight + tm.tmExternalLeading;
fontWidth = tm.tmAveCharWidth;
trackWidth = getMaxCharacterWidthFromString(hdc, _T("0123456789.")) * 16;
trackWidth = getMaxCharacterWidthFromString(hdc, "0123456789.") * 16;
topMarginHeight = rowHeight + 4;
leftMarginWidth = getMaxCharacterWidthFromString(hdc, _T("0123456789abcdefh")) * 8;
leftMarginWidth = getMaxCharacterWidthFromString(hdc, "0123456789abcdefh") * 8;
}
int TrackView::getScreenY(int row) const
@ -195,7 +194,7 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
const SyncDocument *doc = getDocument();
if (NULL == doc) return;
TCHAR temp[256];
char temp[256];
int firstRow = editRow - windowRows / 2 - 1;
int lastRow = editRow + windowRows / 2 + 1;
@ -230,10 +229,10 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
/* if ((row % 4) == 0) SetTextColor(hdc, GetSysColor(COLOR_BTNTEXT));
else SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT)); */
_sntprintf_s(temp, 256, _T("%0*Xh"), 5, row);
_snprintf_s(temp, 256, "%0*Xh", 5, row);
TextOut(hdc,
leftMargin.left, leftMargin.top,
temp, int(_tcslen(temp))
temp, int(strlen(temp))
);
}
@ -310,19 +309,19 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
}
/* format the text */
if (drawEditString)
_sntprintf_s(temp, 256, editString.c_str());
_snprintf_s(temp, 256, editString.c_str());
else if (idx < 0)
_sntprintf_s(temp, 256, _T(" ---"));
_snprintf_s(temp, 256, " ---");
else {
float val = t->keys[idx].value;
_sntprintf_s(temp, 256, _T("% .2f"), val);
_snprintf_s(temp, 256, "% .2f", val);
}
COLORREF oldCol;
if (selected) oldCol = SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
TextOut(hdc,
patternDataRect.left, patternDataRect.top,
temp, int(_tcslen(temp))
temp, int(strlen(temp))
);
if (selected) SetTextColor(hdc, oldCol);
}
@ -381,7 +380,7 @@ void TrackView::editCopy()
if (FAILED(OpenClipboard(getWin())))
{
MessageBox(NULL, _T("Failed to open clipboard"), NULL, MB_OK);
MessageBox(NULL, "Failed to open clipboard", NULL, MB_OK);
return;
}
@ -454,7 +453,7 @@ void TrackView::editPaste()
if (FAILED(OpenClipboard(getWin())))
{
MessageBox(NULL, _T("Failed to open clipboard"), NULL, MB_OK);
MessageBox(NULL, "Failed to open clipboard", NULL, MB_OK);
return;
}
@ -753,7 +752,7 @@ void TrackView::editEnterValue()
int idx = sync_find_key(t, editRow);
if (idx >= 0)
newKey = t->keys[idx]; // copy old key
newKey.value = float(_tstof(editString.c_str())); // modify value
newKey.value = float(atof(editString.c_str())); // modify value
editString.clear();
SyncDocument::Command *cmd = doc->getSetKeyFrameCommand(int(trackIndex), newKey);
@ -1197,7 +1196,7 @@ HWND TrackView::create(HINSTANCE hInstance, HWND hwndParent)
{
HWND hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
trackViewWindowClassName, _T(""),
trackViewWindowClassName, "",
WS_VSCROLL | WS_HSCROLL | WS_CHILD | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, // x, y
CW_USEDEFAULT, CW_USEDEFAULT, // width, height

View File

@ -189,7 +189,7 @@ private:
SyncDocument *document;
std::basic_string<TCHAR> editString;
std::string editString;
HWND hwnd;