From 9f6eeb0b5d320efe2e42a4ce0fe7efc1770c1e71 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Wed, 24 Mar 2010 21:31:43 +0100 Subject: [PATCH] editor: portability fixes This is mostly just nit-pickery that allows most of the editor to be compiled with MinGW. The nasty COM-stuff for the XML-loader in syncdocument.cpp is still not compiling, though. There's also some missing resource definitions, it seems. --- editor/editor.cpp | 16 ++++++++-------- editor/syncdocument.h | 1 + editor/trackview.cpp | 17 +++++++++++------ editor/trackview.h | 10 +++++----- sync/base.h | 4 +++- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/editor/editor.cpp b/editor/editor.cpp index 08e45cc..af56477 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -2,14 +2,14 @@ * For conditions of distribution and use, see copyright notice in COPYING */ +#include "../sync/base.h" #include #include "resource.h" -#define WIN32_LEAN_AND_MEAN -#include #include #include #include +#include // Windows XP look and feel. Seems to enable Vista look as well. #pragma comment(linker, \ @@ -53,7 +53,7 @@ static LRESULT CALLBACK setRowsDialogProc(HWND hDlg, UINT message, WPARAM wParam /* create row-string */ char temp[256]; - _snprintf_s(temp, 256, "%d", *rows); + snprintf(temp, 256, "%d", *rows); /* set initial row count */ SetDlgItemText(hDlg, IDC_SETROWS_EDIT, temp); @@ -440,7 +440,7 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA case WM_ROWCHANGED: { char temp[256]; - _snprintf_s(temp, 256, "%d", lParam ); + snprintf(temp, 256, "%d", lParam ); SendMessage(statusBarWin, SB_SETTEXT, 1, (LPARAM)temp); } break; @@ -448,7 +448,7 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA case WM_TRACKCHANGED: { char temp[256]; - _snprintf_s(temp, 256, "%d", lParam); + snprintf(temp, 256, "%d", lParam); SendMessage(statusBarWin, SB_SETTEXT, 2, (LPARAM)temp); } break; @@ -459,9 +459,9 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA if (document.num_tracks > 0) { sync_track *t = document.tracks[document.getTrackIndexFromPos(trackView->getEditTrack())]; float row = float(trackView->getEditRow()); - _snprintf_s(temp, 256, "%f", sync_get_val(t, row)); + snprintf(temp, 256, "%f", sync_get_val(t, row)); } else - _snprintf_s(temp, 256, "---"); + snprintf(temp, 256, "---"); SendMessage(statusBarWin, SB_SETTEXT, 3, (LPARAM)temp); } break; @@ -631,7 +631,7 @@ int main(int argc, char* argv[]) if (INVALID_SOCKET != clientSocket) { char temp[256]; - _snprintf_s(temp, 256, "Connected to %s", inet_ntoa(client.sin_addr)); + snprintf(temp, 256, "Connected to %s", inet_ntoa(client.sin_addr)); SendMessage(statusBarWin, SB_SETTEXT, 0, (LPARAM)temp); document.clientSocket = NetworkSocket(clientSocket); document.clientRemap.clear(); diff --git a/editor/syncdocument.h b/editor/syncdocument.h index 19a0c07..6f64007 100644 --- a/editor/syncdocument.h +++ b/editor/syncdocument.h @@ -9,6 +9,7 @@ #include #include #include +#include #include class NetworkSocket diff --git a/editor/trackview.cpp b/editor/trackview.cpp index 02e239f..0dce4cc 100644 --- a/editor/trackview.cpp +++ b/editor/trackview.cpp @@ -4,6 +4,11 @@ #include "trackview.h" #include +#include +#include + +using std::min; +using std::max; static const char *trackViewWindowClassName = "TrackView"; @@ -229,7 +234,7 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks) /* if ((row % 4) == 0) SetTextColor(hdc, GetSysColor(COLOR_BTNTEXT)); else SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT)); */ - _snprintf_s(temp, 256, "%0*Xh", 5, row); + snprintf(temp, 256, "%0*Xh", 5, row); TextOut(hdc, leftMargin.left, leftMargin.top, temp, int(strlen(temp)) @@ -309,12 +314,12 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks) } /* format the text */ if (drawEditString) - _snprintf_s(temp, 256, editString.c_str()); + snprintf(temp, 256, editString.c_str()); else if (idx < 0) - _snprintf_s(temp, 256, " ---"); + snprintf(temp, 256, " ---"); else { float val = t->keys[idx].value; - _snprintf_s(temp, 256, "% .2f", val); + snprintf(temp, 256, "% .2f", val); } COLORREF oldCol; @@ -348,7 +353,7 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks) { RECT topPadding; - topPadding.top = max(rcTracks.top, topMarginHeight); + topPadding.top = max(int(rcTracks.top), topMarginHeight); topPadding.bottom = getScreenY(0); topPadding.left = rcTracks.left; topPadding.right = rcTracks.right; @@ -1130,7 +1135,7 @@ LRESULT TrackView::windowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) return FALSE; } -static LRESULT CALLBACK trackViewWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK trackViewWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { // Get the TrackView instance (if any) #pragma warning(suppress:4312) /* remove a pointless warning */ diff --git a/editor/trackview.h b/editor/trackview.h index d6ebd42..d4beaa2 100644 --- a/editor/trackview.h +++ b/editor/trackview.h @@ -86,7 +86,7 @@ public: private: // some nasty hackery to forward the window messages - friend static LRESULT CALLBACK trackViewWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); + friend LRESULT CALLBACK trackViewWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT windowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); // events @@ -108,10 +108,10 @@ private: void invalidateRange(int startTrack, int stopTrack, int startRow, int stopRow) { RECT rect; - rect.left = getScreenX(min(startTrack, stopTrack)); - rect.right = getScreenX(max(startTrack, stopTrack) + 1); - rect.top = getScreenY(min(startRow, stopRow)); - rect.bottom = getScreenY(max(startRow, stopRow) + 1); + rect.left = getScreenX(std::min(startTrack, stopTrack)); + rect.right = getScreenX(std::max(startTrack, stopTrack) + 1); + rect.top = getScreenY(std::min(startRow, stopRow)); + rect.bottom = getScreenY(std::max(startRow, stopRow) + 1); InvalidateRect(hwnd, &rect, FALSE); } diff --git a/sync/base.h b/sync/base.h index 73a152f..7fcbec3 100644 --- a/sync/base.h +++ b/sync/base.h @@ -8,11 +8,13 @@ #ifdef _MSC_VER #define inline __inline #define strdup _strdup +#define snprintf _snprintf #endif #ifdef WIN32 - #include #define WIN32_LEAN_AND_MEAN + #define NOMINMAX + #include #include #else #include