aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
Diffstat (limited to 'c')
-rw-r--r--c/datalistview.cpp1
-rw-r--r--c/debug.cpp3
-rw-r--r--c/episodelistview.cpp3
-rw-r--r--c/layout.cpp2
-rw-r--r--c/layout.h2
-rw-r--r--c/listview.cpp2
-rw-r--r--c/main.cpp2
-rw-r--r--c/pl.h2
-rw-r--r--c/util.h19
-rw-r--r--c/wcharptr.cpp64
-rw-r--r--c/wcharptr.h33
-rw-r--r--c/win.cpp (renamed from c/common.cpp)60
-rw-r--r--c/win.h (renamed from c/common.h)45
13 files changed, 128 insertions, 110 deletions
diff --git a/c/datalistview.cpp b/c/datalistview.cpp
index e6cc6ca..e44592b 100644
--- a/c/datalistview.cpp
+++ b/c/datalistview.cpp
@@ -5,7 +5,6 @@
#include <SWI-Prolog.h>
#include "resource.h"
-#include "common.h"
#include "datalistview.h"
#include "episodelistview.h"
#include "listview.h"
diff --git a/c/debug.cpp b/c/debug.cpp
index 07006a9..934533b 100644
--- a/c/debug.cpp
+++ b/c/debug.cpp
@@ -1,8 +1,9 @@
#include <cstddef>
+#include <cstdio>
#include <windows.h>
-#include "common.h"
#include "debug.h"
+#include "win.h"
struct Avg {
int id;
diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp
index 313f82f..b3a581d 100644
--- a/c/episodelistview.cpp
+++ b/c/episodelistview.cpp
@@ -4,11 +4,12 @@
#include <SWI-Prolog.h>
#include "resource.h"
-#include "common.h"
#include "datalistview.h"
#include "episodelistview.h"
#include "listview.h"
#include "pl.h"
+#include "util.h"
+#include "win.h"
EpisodeListView::EpisodeListView(const HWND hWndParent)
: ListView(hWndParent, (HMENU)IDC_EPISODELISTVIEW, 0)
diff --git a/c/layout.cpp b/c/layout.cpp
index 94978bb..cbfb831 100644
--- a/c/layout.cpp
+++ b/c/layout.cpp
@@ -1,9 +1,9 @@
#include <windows.h>
-#include "common.h"
#include "episodelistview.h"
#include "datalistview.h"
#include "layout.h"
+#include "win.h"
extern HWND g_hWnd;
extern HWND g_hWndStatus;
diff --git a/c/layout.h b/c/layout.h
index 752e660..578f065 100644
--- a/c/layout.h
+++ b/c/layout.h
@@ -3,9 +3,9 @@
#include <windows.h>
-#include "common.h"
#include "datalistview.h"
#include "pl.h"
+#include "win.h"
void UpdateLayout(int w = 0, int h = 0);
diff --git a/c/listview.cpp b/c/listview.cpp
index 531e9dd..107d34b 100644
--- a/c/listview.cpp
+++ b/c/listview.cpp
@@ -1,9 +1,9 @@
#include <windows.h>
#include <commctrl.h>
-#include "common.h"
#include "listview.h"
#include "layout.h"
+#include "win.h"
extern HFONT g_hfNormal;
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
diff --git a/c/main.cpp b/c/main.cpp
index 87b15be..c237e31 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -6,11 +6,11 @@
#include "debug.h"
#include "resource.h"
-#include "common.h"
#include "datalistview.h"
#include "episodelistview.h"
#include "layout.h"
#include "pl.h"
+#include "util.h"
/* Looked-up constants. */
int g_dpi = 96;
diff --git a/c/pl.h b/c/pl.h
index 28e13b0..670c926 100644
--- a/c/pl.h
+++ b/c/pl.h
@@ -5,7 +5,7 @@
#include <windows.h>
#include <SWI-Prolog.h>
-#include "common.h"
+#include "wcharptr.h"
wchar_ptr PlString(const term_t t, const int flags = CVT_WRITE);
diff --git a/c/util.h b/c/util.h
new file mode 100644
index 0000000..babe0c5
--- /dev/null
+++ b/c/util.h
@@ -0,0 +1,19 @@
+#ifndef UTIL_H
+#define UTIL_H
+
+#include <memory>
+
+template<size_t N, typename... T>
+inline int Swprintf(wchar_t (&buf)[N], const wchar_t* const fmt, T... xs)
+{
+ return _snwprintf_s(buf, N, _TRUNCATE, fmt, xs...);
+}
+
+inline int Cmp(const int a, const int b)
+{
+ if (a == b) return 0;
+ if (a > b) return 1;
+ return -1;
+}
+
+#endif
diff --git a/c/wcharptr.cpp b/c/wcharptr.cpp
new file mode 100644
index 0000000..e406ed1
--- /dev/null
+++ b/c/wcharptr.cpp
@@ -0,0 +1,64 @@
+#include <utility>
+#include <windows.h>
+
+#include "wcharptr.h"
+#include "win.h"
+
+wchar_ptr::wchar_ptr() noexcept {}
+
+wchar_ptr::wchar_ptr(wchar_t* const s) noexcept : m_p(s) {}
+
+wchar_ptr& wchar_ptr::operator=(wchar_t* const s) noexcept
+{
+ if (m_p != s) {
+ delete m_p;
+ m_p = s;
+ }
+ return *this;
+}
+
+wchar_ptr::wchar_ptr(wchar_ptr&& other) noexcept
+ : m_p(std::exchange(other.m_p, nullptr)) {}
+
+wchar_ptr& wchar_ptr::operator=(wchar_ptr&& other) noexcept
+{
+ std::swap(m_p, other.m_p);
+ return *this;
+}
+
+wchar_ptr::operator wchar_t*() noexcept
+{
+ return m_p;
+}
+
+wchar_t* wchar_ptr::release() noexcept
+{
+ wchar_t* p2 = m_p;
+ m_p = nullptr;
+ return p2;
+}
+
+wchar_ptr::~wchar_ptr() noexcept
+{
+ delete m_p;
+}
+
+wchar_ptr wchar_ptr::from_narrow(const char* const src, const int cp)
+{
+ int cbMultiByte = strlen(src)+1;
+ int cchWideChar = MultiByteToWideChar(cp, 0, src, cbMultiByte, NULL, 0);
+ wchar_t* dst = new wchar_t[cchWideChar];
+ if (!MultiByteToWideChar(cp, 0, src, cbMultiByte, dst, cchWideChar)) {
+ delete dst;
+ throw Win32Error();
+ }
+ return dst;
+}
+
+wchar_ptr wchar_ptr::copy(const wchar_t* const src)
+{
+ const int cb = wcslen(src)+1;
+ wchar_t* dst = new wchar_t[cb];
+ memcpy(dst, src, cb*sizeof(wchar_t));
+ return dst;
+}
diff --git a/c/wcharptr.h b/c/wcharptr.h
new file mode 100644
index 0000000..1f579b5
--- /dev/null
+++ b/c/wcharptr.h
@@ -0,0 +1,33 @@
+#ifndef WCHARPTR_H
+#define WCHARPTR_H
+
+#include <windows.h>
+
+/* wchar_ptr: Simple wrapper for wide C strings. */
+struct wchar_ptr
+{
+ /* Named copy constructors (expensive). */
+ static wchar_ptr from_narrow(const char* buf, int cp = CP_UTF8);
+ static wchar_ptr copy(const wchar_t* s);
+
+ /* Non-explicit copies are disabled. */
+ wchar_ptr(wchar_ptr& other) = delete;
+ wchar_ptr& operator=(wchar_ptr& other) = delete;
+
+ wchar_ptr() noexcept;
+ ~wchar_ptr();
+ operator wchar_t*() noexcept;
+
+ wchar_ptr(wchar_t* s) noexcept;
+ wchar_ptr& operator=(wchar_t* s) noexcept;
+
+ wchar_ptr(wchar_ptr&& other) noexcept;
+ wchar_ptr& operator=(wchar_ptr&& other) noexcept;
+
+ /* Return pointer, releasing ownership. */
+ wchar_t *release() noexcept;
+private:
+ wchar_t* m_p = nullptr;
+};
+
+#endif
diff --git a/c/common.cpp b/c/win.cpp
index 0a54f69..435e739 100644
--- a/c/common.cpp
+++ b/c/win.cpp
@@ -1,65 +1,7 @@
#include <utility>
#include <windows.h>
-#include "common.h"
-
-wchar_ptr::wchar_ptr() noexcept {}
-
-wchar_ptr::wchar_ptr(wchar_t* const s) noexcept : m_p(s) {}
-
-wchar_ptr& wchar_ptr::operator=(wchar_t* const s) noexcept
-{
- if (m_p != s) {
- delete m_p;
- m_p = s;
- }
- return *this;
-}
-
-wchar_ptr::wchar_ptr(wchar_ptr&& other) noexcept : m_p(std::exchange(other.m_p, nullptr)) {}
-
-wchar_ptr& wchar_ptr::operator=(wchar_ptr&& other) noexcept
-{
- std::swap(m_p, other.m_p);
- return *this;
-}
-
-wchar_ptr::operator wchar_t*() noexcept
-{
- return m_p;
-}
-
-wchar_t* wchar_ptr::release() noexcept
-{
- wchar_t* p2 = m_p;
- m_p = nullptr;
- return p2;
-}
-
-wchar_ptr::~wchar_ptr() noexcept
-{
- delete m_p;
-}
-
-wchar_ptr wchar_ptr::from_narrow(const char* const src, const int cp)
-{
- int cbMultiByte = strlen(src)+1;
- int cchWideChar = MultiByteToWideChar(cp, 0, src, cbMultiByte, NULL, 0);
- wchar_t* dst = new wchar_t[cchWideChar];
- if (!MultiByteToWideChar(cp, 0, src, cbMultiByte, dst, cchWideChar)) {
- delete dst;
- throw Win32Error();
- }
- return dst;
-}
-
-wchar_ptr wchar_ptr::copy(const wchar_t* const src)
-{
- const int cb = wcslen(src)+1;
- wchar_t* dst = new wchar_t[cb];
- memcpy(dst, src, cb*sizeof(wchar_t));
- return dst;
-}
+#include "win.h"
Win32Error::Win32Error() : code(GetLastError()) {}
Win32Error::Win32Error(const DWORD code) : code(code) {}
diff --git a/c/common.h b/c/win.h
index 70c2c32..038f8ea 100644
--- a/c/common.h
+++ b/c/win.h
@@ -1,40 +1,12 @@
-#ifndef COMMON_H
-#define COMMON_H
+#ifndef WIN_H
+#define WIN_H
-#include <memory>
#include <optional>
#include <windows.h>
int EBMessageBox(const wchar_t* wszText, const wchar_t* wszCaption, unsigned uType);
int GetRelativeCursorPos(HWND hWnd, POINT* pt);
-/* wchar_ptr: Simple wrapper for wide C strings. */
-struct wchar_ptr
-{
- /* Named copy constructors (expensive). */
- static wchar_ptr from_narrow(const char* buf, int cp = CP_UTF8);
- static wchar_ptr copy(const wchar_t* s);
-
- /* Non-explicit copies are disabled. */
- wchar_ptr(wchar_ptr& other) = delete;
- wchar_ptr& operator=(wchar_ptr& other) = delete;
-
- wchar_ptr() noexcept;
- ~wchar_ptr();
- operator wchar_t*() noexcept;
-
- wchar_ptr(wchar_t* s) noexcept;
- wchar_ptr& operator=(wchar_t* s) noexcept;
-
- wchar_ptr(wchar_ptr&& other) noexcept;
- wchar_ptr& operator=(wchar_ptr&& other) noexcept;
-
- /* Return pointer, releasing ownership. */
- wchar_t *release() noexcept;
-private:
- wchar_t* m_p = nullptr;
-};
-
/* Win32Error: Exception for Windows API errors. */
struct Win32Error : public std::exception
{
@@ -67,12 +39,6 @@ T* Library::GetProcAddress(const char* const szProc)
return (T*)(void*)::GetProcAddress(m_hModule, szProc);
}
-template<size_t N, typename... T>
-inline int Swprintf(wchar_t (&buf)[N], const wchar_t* const fmt, T... xs)
-{
- return _snwprintf_s(buf, N, _TRUNCATE, fmt, xs...);
-}
-
/* Variable template for caching values from GetSystemMetrics. */
template <int I>
auto Metric = GetSystemMetrics(I);
@@ -103,13 +69,6 @@ inline int Dpi(const int i)
return MulDiv(i, g_dpi, 96);
}
-inline int Cmp(const int a, const int b)
-{
- if (a == b) return 0;
- if (a > b) return 1;
- return -1;
-}
-
/* Get window rectangle relative to parent. */
inline BOOL GetRelativeRect(const HWND hWnd, RECT* const rr)
{