From caec39281bcaac4cd26b6d81f1418b086d0476c0 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 16 Jun 2016 00:58:40 -0400 Subject: [PATCH] And implemented the new sizing stuff on OS X. --- README.md | 5 ++++- darwin/window.m | 42 ++++++++++++++++++++++++++++++++++++++++-- doc/windowmovesize | 3 +++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 doc/windowmovesize diff --git a/README.md b/README.md index 86a83fa7..4b615c8e 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,10 @@ This README is being written.
## Updates -*Note that today's entry may be updated later today Eastern Time.* +*Note that today's entry (Eastern Time) may be updated later today.* + +* **16 June 2016** + * Added `uiWindowContentSize()`, `uiWindowSetContentSize()`, and `uiWindowOnContentSizeChanged()` methods for manipulating uiWindow content sizes. Note the use of "content size"; the size you work with does NOT include window decorations (titlebars, menus, etc.). * **15 June 2016** * Added `uiFormDelete()`; thanks to @emersion. diff --git a/darwin/window.m b/darwin/window.m index 7cab10b4..03c86ac1 100644 --- a/darwin/window.m +++ b/darwin/window.m @@ -12,6 +12,9 @@ struct uiWindow { void (*onPositionChanged)(uiWindow *, void *); void *onPositionChangedData; BOOL suppressPositionChanged; + void (*onContentSizeChanged)(uiWindow *, void *); + void *onContentSizeChangedData; + BOOL suppressSizeChanged; }; @interface windowDelegateClass : NSObject { @@ -19,6 +22,7 @@ struct uiWindow { } - (BOOL)windowShouldClose:(id)sender; - (void)windowDidMove:(NSNotification *)note; +- (void)windowDidResize:(NSNotification *)note; - (void)registerWindow:(uiWindow *)w; - (void)unregisterWindow:(uiWindow *)w; - (uiWindow *)lookupWindow:(NSWindow *)w; @@ -61,6 +65,15 @@ struct uiWindow { (*(w->onPositionChanged))(w, w->onPositionChangedData); } +- (void)windowDidResize:(NSNotification *)note +{ + uiWindow *w; + + w = [self lookupWindow:((NSWindow *) [note object])]; + if (!w->suppressSizeChanged) + (*(w->onContentSizeChanged))(w, w->onContentSizeChangedData); +} + - (void)registerWindow:(uiWindow *)w { mapSet(self->windows, w->window, w); @@ -250,7 +263,9 @@ void uiWindowSetPosition(uiWindow *w, int x, int y) void uiWindowCenter(uiWindow *w) { + w->suppressPositionChanged = YES; [w->window center]; + w->suppressPositionChanged = NO; } void uiWindowOnPositionChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data) @@ -259,6 +274,28 @@ void uiWindowOnPositionChanged(uiWindow *w, void (*f)(uiWindow *, void *), void w->onPositionChangedData = data; } +void uiWindowContentSize(uiWindow *w, int *width, int *height) +{ + NSRect r; + + r = [w->window contentRectForFrameRect:[w->window frame]]; + *width = r.size.width; + *height = r.size.height; +} + +void uiWindowSetContentSize(uiWindow *w, int width, int height) +{ + w->suppressSizeChanged = YES; + [w->window setContentSize:NSMakeSize(width, height)]; + w->suppressSizeChanged = NO; +} + +void uiWindowOnContentSizeChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data) +{ + w->onContentSizeChanged = f; + w->onContentSizeChangedData = data; +} + void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data) { w->onClosing = f; @@ -300,7 +337,7 @@ static int defaultOnClosing(uiWindow *w, void *data) return 0; } -static void defaultOnPositionChanged(uiWindow *w, void *data) +static void defaultOnPositionContentSizeChanged(uiWindow *w, void *data) { // do nothing } @@ -329,7 +366,8 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) } [windowDelegate registerWindow:w]; uiWindowOnClosing(w, defaultOnClosing, NULL); - uiWindowOnPositionChanged(w, defaultOnPositionChanged, NULL); + uiWindowOnPositionChanged(w, defaultOnPositionContentSizeChanged, NULL); + uiWindowOnContentSizeChanged(w, defaultOnPositionContentSizeChanged, NULL); return w; } diff --git a/doc/windowmovesize b/doc/windowmovesize new file mode 100644 index 00000000..ec8bd966 --- /dev/null +++ b/doc/windowmovesize @@ -0,0 +1,3 @@ +you should never need to use these functions +they are provided only for the cases when ABSOLUTELY NECESSARY +the operating system may ignore your requests, for instance, if you are giving it invalid numbers or a size too small to fit; this is all system-defined