And implemented the new sizing stuff on OS X.

This commit is contained in:
Pietro Gagliardi 2016-06-16 00:58:40 -04:00
parent 88bb697bbd
commit caec39281b
3 changed files with 47 additions and 3 deletions

View File

@ -16,7 +16,10 @@ This README is being written.<br>
## 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.

View File

@ -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<NSWindowDelegate> {
@ -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;
}

3
doc/windowmovesize Normal file
View File

@ -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