aboutsummaryrefslogtreecommitdiffstats
path: root/src/win.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-01-12 10:30:10 -0500
committerDavid Robillard <d@drobilla.net>2023-01-14 11:53:28 -0500
commitbd4f79646f623e929e6aa22bea028952b515aeef (patch)
treee2dcc2635bb2b12b9c552755b35a0343005ce88a /src/win.c
parent786a28e4a2bc9fce95a8d2e6cd1a4c76d2ae1a0f (diff)
downloadpugl-bd4f79646f623e929e6aa22bea028952b515aeef.tar.gz
pugl-bd4f79646f623e929e6aa22bea028952b515aeef.tar.bz2
pugl-bd4f79646f623e929e6aa22bea028952b515aeef.zip
Add general string hint interface
This replaces the window title and class name APIs with a more general one that can be easily extended to other things, like icon names, more detailed application hints, and so on.
Diffstat (limited to 'src/win.c')
-rw-r--r--src/win.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/win.c b/src/win.c
index b3ecf7f..db3f98c 100644
--- a/src/win.c
+++ b/src/win.c
@@ -269,7 +269,7 @@ puglRealize(PuglView* view)
view->hints[PUGL_REFRESH_RATE] = (int)devMode.dmDisplayFrequency;
// Register window class if necessary
- if (!puglRegisterWindowClass(view->world->className)) {
+ if (!puglRegisterWindowClass(view->world->strings[PUGL_CLASS_NAME])) {
return PUGL_REGISTRATION_FAILED;
}
@@ -280,7 +280,7 @@ puglRealize(PuglView* view)
}
// Set basic window hints and attributes
- puglSetWindowTitle(view, view->title ? view->title : "");
+ puglSetViewString(view, PUGL_WINDOW_TITLE, view->strings[PUGL_WINDOW_TITLE]);
puglSetTransientParent(view, view->transientParent);
view->impl->scaleFactor = puglWinGetViewScaleFactor(view);
@@ -370,7 +370,7 @@ puglFreeViewInternals(PuglView* view)
void
puglFreeWorldInternals(PuglWorld* world)
{
- UnregisterClass(world->className, NULL);
+ UnregisterClass(world->strings[PUGL_CLASS_NAME], NULL);
free(world->impl);
}
@@ -1153,12 +1153,16 @@ puglGetNativeView(PuglView* view)
}
PuglStatus
-puglSetWindowTitle(PuglView* view, const char* title)
+puglViewStringChanged(PuglView* const view,
+ const PuglStringHint key,
+ const char* const value)
{
- puglSetString(&view->title, title);
+ if (!view->impl->hwnd) {
+ return PUGL_SUCCESS;
+ }
- if (view->impl->hwnd) {
- wchar_t* wtitle = puglUtf8ToWideChar(title);
+ if (key == PUGL_WINDOW_TITLE) {
+ wchar_t* const wtitle = puglUtf8ToWideChar(value);
if (wtitle) {
SetWindowTextW(view->impl->hwnd, wtitle);
free(wtitle);
@@ -1548,19 +1552,19 @@ puglWinCreateWindow(PuglView* const view,
HWND* const hwnd,
HDC* const hdc)
{
- const char* className = (const char*)view->world->className;
- const unsigned winFlags = puglWinGetWindowFlags(view);
- const unsigned winExFlags = puglWinGetWindowExFlags(view);
- const PuglRect frame = getInitialFrame(view);
+ const char* className = (const char*)view->world->strings[PUGL_CLASS_NAME];
// The meaning of "parent" depends on the window type (WS_CHILD)
PuglNativeView parent = view->parent ? view->parent : view->transientParent;
// Calculate initial window rectangle
- RECT wr = {(long)frame.x,
- (long)frame.y,
- (long)frame.x + frame.width,
- (long)frame.y + frame.height};
+ const unsigned winFlags = puglWinGetWindowFlags(view);
+ const unsigned winExFlags = puglWinGetWindowExFlags(view);
+ const PuglRect frame = getInitialFrame(view);
+ RECT wr = {(long)frame.x,
+ (long)frame.y,
+ (long)frame.x + frame.width,
+ (long)frame.y + frame.height};
AdjustWindowRectEx(&wr, winFlags, FALSE, winExFlags);
// Create window and get drawing context