Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Resizeable Window #316

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions darwin/window.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
BOOL suppressSizeChanged;
int fullscreen;
int borderless;
int resizeable;
};

@implementation uiprivNSWindow
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions test/menus.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ uiMenuItem *enableThisItem;
uiMenuItem *forceCheckedItem;
uiMenuItem *forceUncheckedItem;
uiMenuItem *whatWindowItem;
uiMenuItem *resizeableItem;
uiMenu *moreTestsMenu;
uiMenuItem *quitEnabledItem;
uiMenuItem *prefsEnabledItem;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions unix/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct uiWindow {

uiControl *child;
int margined;
int resizeable;

int (*onClosing)(uiWindow *, void *);
void *onClosingData;
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions windows/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct uiWindow {
int (*onClosing)(uiWindow *, void *);
void *onClosingData;
int margined;
int resizeable;
BOOL hasMenubar;
void (*onContentSizeChanged)(uiWindow *, void *);
void *onContentSizeChangedData;
Expand Down Expand Up @@ -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)
Expand Down