This commit is contained in:
Niklas Mischkulnig 2021-01-02 10:21:40 -05:00 committed by GitHub
commit 9de075daf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 0 deletions

View File

@ -16,6 +16,7 @@ struct uiWindow {
BOOL suppressSizeChanged;
int fullscreen;
int borderless;
int resizeable;
};
@implementation uiprivNSWindow
@ -357,6 +358,21 @@ void uiWindowSetMargined(uiWindow *w, int margined)
uiprivSingleChildConstraintsSetMargined(&(w->constraints), w->margined);
}
int uiWindowResizeable(uiWindow *w)
{
return w->resizeable;
}
void uiWindowSetResizeable(uiWindow *w, int resizeable)
{
w->resizeable = resizeable;
if(resizeable) {
[w->window setStyleMask:[w->window styleMask] | NSResizableWindowMask];
} else {
[w->window setStyleMask:[w->window styleMask] & ~NSResizableWindowMask];
}
}
static int defaultOnClosing(uiWindow *w, void *data)
{
return 0;

View File

@ -17,6 +17,7 @@ uiMenuItem *enableThisItem;
uiMenuItem *forceCheckedItem;
uiMenuItem *forceUncheckedItem;
uiMenuItem *whatWindowItem;
uiMenuItem *resizeableItem;
uiMenu *moreTestsMenu;
uiMenuItem *quitEnabledItem;
uiMenuItem *prefsEnabledItem;
@ -50,6 +51,11 @@ static void whatWindow(uiMenuItem *item, uiWindow *w, void *data)
printf("menu item clicked on window %p\n", (void *) w);
}
static void toggleResize(uiMenuItem *item, uiWindow *w, void *data)
{
uiWindowSetResizeable(w, uiMenuItemChecked(item));
}
void initMenus(void)
{
fileMenu = uiNewMenu("File");
@ -79,6 +85,9 @@ void initMenus(void)
uiMenuAppendSeparator(testMenu);
whatWindowItem = uiMenuAppendItem(testMenu, "What Window?");
uiMenuItemOnClicked(whatWindowItem, whatWindow, NULL);
resizeableItem = uiMenuAppendCheckItem(testMenu, "Enable Resize");
uiMenuItemSetChecked(resizeableItem, 1);
uiMenuItemOnClicked(resizeableItem, toggleResize, NULL);
moreTestsMenu = uiNewMenu("More Tests");
quitEnabledItem = uiMenuAppendCheckItem(moreTestsMenu, "Quit Item Enabled");

2
ui.h
View File

@ -130,6 +130,8 @@ _UI_EXTERN void uiWindowSetBorderless(uiWindow *w, int borderless);
_UI_EXTERN void uiWindowSetChild(uiWindow *w, uiControl *child);
_UI_EXTERN int uiWindowMargined(uiWindow *w);
_UI_EXTERN void uiWindowSetMargined(uiWindow *w, int margined);
_UI_EXTERN int uiWindowResizeable(uiWindow *w);
_UI_EXTERN void uiWindowSetResizeable(uiWindow *w, int resizeable);
_UI_EXTERN uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar);
typedef struct uiButton uiButton;

View File

@ -19,6 +19,7 @@ struct uiWindow {
uiControl *child;
int margined;
int resizeable;
int (*onClosing)(uiWindow *, void *);
void *onClosingData;
@ -229,6 +230,17 @@ void uiWindowSetMargined(uiWindow *w, int margined)
uiprivSetMargined(w->childHolderContainer, w->margined);
}
int uiWindowResizeable(uiWindow *w)
{
return w->resizeable;
}
void uiWindowSetResizeable(uiWindow *w, int resizeable)
{
w->resizeable = resizeable;
gtk_window_set_resizable(w->window, resizeable);
}
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
{
uiWindow *w;

View File

@ -13,6 +13,7 @@ struct uiWindow {
int (*onClosing)(uiWindow *, void *);
void *onClosingData;
int margined;
int resizeable;
BOOL hasMenubar;
void (*onContentSizeChanged)(uiWindow *, void *);
void *onContentSizeChangedData;
@ -428,6 +429,21 @@ void uiWindowSetMargined(uiWindow *w, int margined)
windowRelayout(w);
}
int uiWindowResizeable(uiWindow *w)
{
return w->resizeable;
}
void uiWindowSetResizeable(uiWindow *w, int resizeable)
{
w->resizeable = resizeable;
if (w->resizeable) {
setStyle(w->hwnd, getStyle(w->hwnd) | WS_THICKFRAME | WS_MAXIMIZEBOX);
} else {
setStyle(w->hwnd, getStyle(w->hwnd) & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX);
}
}
// see http://blogs.msdn.com/b/oldnewthing/archive/2003/09/11/54885.aspx and http://blogs.msdn.com/b/oldnewthing/archive/2003/09/13/54917.aspx
// TODO use clientSizeToWindowSize()
static void setClientSize(uiWindow *w, int width, int height, BOOL hasMenubar, DWORD style, DWORD exstyle)