fix osx win-fixed-size

This commit is contained in:
David Rose 2010-09-12 00:10:59 +00:00
parent 5a635059b6
commit a49e684dbe
2 changed files with 93 additions and 33 deletions

View File

@ -229,7 +229,11 @@ event_handler(EventHandlerCallRef myHandler, EventRef event) {
WindowRef window = NULL; WindowRef window = NULL;
GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL,
sizeof(WindowRef), NULL, &window); sizeof(window), NULL, &window);
UInt32 attributes = 0;
GetEventParameter(event, kEventParamAttributes, typeUInt32, NULL,
sizeof(attributes), NULL, &attributes);
if (osxdisplay_cat.is_spam()) { if (osxdisplay_cat.is_spam()) {
osxdisplay_cat.spam() osxdisplay_cat.spam()
@ -276,6 +280,23 @@ event_handler(EventHandlerCallRef myHandler, EventRef event) {
SetUserFocusWindow (window); SetUserFocusWindow (window);
break; break;
case kEventWindowBoundsChanging:
// Gives us a chance to intercept resize attempts
if (attributes & kWindowBoundsChangeSizeChanged) {
// If the window is supposed to be fixed-size, enforce this.
if (_properties.get_fixed_size()) {
Rect bounds;
GetEventParameter(event, kEventParamCurrentBounds,
typeQDRectangle, NULL, sizeof(bounds), NULL, &bounds);
bounds.right = bounds.left + _properties.get_x_size();
bounds.bottom = bounds.top + _properties.get_y_size();
SetEventParameter(event, kEventParamCurrentBounds,
typeQDRectangle, sizeof(bounds), &bounds);
result = noErr;
}
}
break;
case kEventWindowBoundsChanged: // called for resize and moves (drag) case kEventWindowBoundsChanged: // called for resize and moves (drag)
do_resize(); do_resize();
break; break;
@ -1199,6 +1220,11 @@ os_open_window(WindowProperties &req_properties) {
} }
} else */ } else */
{ {
int attributes = kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute;
if (req_properties.has_fixed_size() && req_properties.get_fixed_size()) {
attributes &= ~kWindowResizableAttribute;
}
if (req_properties.has_undecorated() && req_properties.get_undecorated()) { if (req_properties.has_undecorated() && req_properties.get_undecorated()) {
// create a unmovable .. no edge window.. // create a unmovable .. no edge window..
@ -1207,7 +1233,10 @@ os_open_window(WindowProperties &req_properties) {
<< "Creating undecorated window\n"; << "Creating undecorated window\n";
} }
CreateNewWindow(kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowNoTitleBarAttribute, &r, &_osx_window); // We don't want a resize box either.
attributes &= ~kWindowResizableAttribute;
attributes |= kWindowNoTitleBarAttribute;
CreateNewWindow(kDocumentWindowClass, attributes, &r, &_osx_window);
} else { } else {
// create a window with crome and sizing and sucj // create a window with crome and sizing and sucj
// In this case, we want to constrain the window to the // In this case, we want to constrain the window to the
@ -1225,7 +1254,7 @@ os_open_window(WindowProperties &req_properties) {
osxdisplay_cat.debug() osxdisplay_cat.debug()
<< "Creating standard window\n"; << "Creating standard window\n";
} }
CreateNewWindow(kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute, &r, &_osx_window); CreateNewWindow(kDocumentWindowClass, attributes, &r, &_osx_window);
add_a_window(_osx_window); add_a_window(_osx_window);
} }
} }
@ -1238,6 +1267,7 @@ os_open_window(WindowProperties &req_properties) {
{ kEventClassWindow, kEventWindowActivated }, { kEventClassWindow, kEventWindowActivated },
{ kEventClassWindow, kEventWindowDeactivated }, { kEventClassWindow, kEventWindowDeactivated },
{ kEventClassWindow, kEventWindowClose }, { kEventClassWindow, kEventWindowClose },
{ kEventClassWindow, kEventWindowBoundsChanging },
{ kEventClassWindow, kEventWindowBoundsChanged }, { kEventClassWindow, kEventWindowBoundsChanged },
{ kEventClassWindow, kEventWindowCollapsed }, { kEventClassWindow, kEventWindowCollapsed },

View File

@ -133,26 +133,32 @@ TinyOsxGraphicsWindow* TinyOsxGraphicsWindow::GetCurrentOSxWindow(WindowRef wind
// Description: The standard window event handler for non-fullscreen // Description: The standard window event handler for non-fullscreen
// windows. // windows.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
OSStatus TinyOsxGraphicsWindow::event_handler(EventHandlerCallRef myHandler, EventRef event) { OSStatus TinyOsxGraphicsWindow::
event_handler(EventHandlerCallRef myHandler, EventRef event) {
OSStatus result = eventNotHandledErr; OSStatus result = eventNotHandledErr;
UInt32 the_class = GetEventClass(event); UInt32 the_class = GetEventClass(event);
UInt32 kind = GetEventKind(event); UInt32 kind = GetEventKind(event);
WindowRef window = NULL; WindowRef window = NULL;
GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window); GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL,
sizeof(window), NULL, &window);
UInt32 attributes = 0;
GetEventParameter(event, kEventParamAttributes, typeUInt32, NULL,
sizeof(attributes), NULL, &attributes);
if (tinydisplay_cat.is_spam()) { if (tinydisplay_cat.is_spam()) {
tinydisplay_cat.spam() << ClockObject::get_global_clock()->get_real_time() << " event_handler: " << (void *)this << ", " << window << ", " << the_class << ", " << kind << "\n"; tinydisplay_cat.spam() << ClockObject::get_global_clock()->get_real_time() << " event_handler: " << (void *)this << ", " << window << ", " << the_class << ", " << kind << "\n";
} }
switch (the_class) { switch (the_class) {
case kEventClassMouse: case kEventClassMouse:
result = handleWindowMouseEvents (myHandler, event); result = handleWindowMouseEvents (myHandler, event);
break; break;
case kEventClassWindow: case kEventClassWindow:
switch (kind) { switch (kind) {
case kEventWindowCollapsing: case kEventWindowCollapsing:
/* /*
Rect r; Rect r;
@ -179,27 +185,44 @@ OSStatus TinyOsxGraphicsWindow::event_handler(EventHandlerCallRef myHandler, Eve
if (window == FrontNonFloatingWindow ()) if (window == FrontNonFloatingWindow ())
SetUserFocusWindow (window); SetUserFocusWindow (window);
break; break;
case kEventWindowBoundsChanged: // called for resize and moves (drag)
DoResize(); case kEventWindowBoundsChanging:
break; // Gives us a chance to intercept resize attempts
case kEventWindowZoomed: if (attributes & kWindowBoundsChangeSizeChanged) {
break; // If the window is supposed to be fixed-size, enforce this.
case kEventWindowCollapsed: if (_properties.get_fixed_size()) {
{ Rect bounds;
WindowProperties properties; GetEventParameter(event, kEventParamCurrentBounds,
properties.set_minimized(true); typeQDRectangle, NULL, sizeof(bounds), NULL, &bounds);
system_changed_properties(properties); bounds.right = bounds.left + _properties.get_x_size();
bounds.bottom = bounds.top + _properties.get_y_size();
SetEventParameter(event, kEventParamCurrentBounds,
typeQDRectangle, sizeof(bounds), &bounds); result = noErr;
} }
break; }
case kEventWindowExpanded: break;
{
WindowProperties properties; case kEventWindowBoundsChanged: // called for resize and moves (drag)
properties.set_minimized(false); DoResize();
system_changed_properties(properties); break;
} case kEventWindowZoomed:
break; break;
case kEventWindowCollapsed:
{
WindowProperties properties;
properties.set_minimized(true);
system_changed_properties(properties);
} }
break; break;
case kEventWindowExpanded:
{
WindowProperties properties;
properties.set_minimized(false);
system_changed_properties(properties);
}
break;
}
break;
} }
return result; return result;
@ -433,7 +456,6 @@ void TinyOsxGraphicsWindow::ReleaseSystemResources() {
_pending_icon = NULL; _pending_icon = NULL;
} }
if (_current_icon != NULL) { if (_current_icon != NULL) {
cerr << "release current icon\n";
CGImageRelease(_current_icon); CGImageRelease(_current_icon);
_current_icon = NULL; _current_icon = NULL;
} }
@ -951,16 +973,23 @@ bool TinyOsxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties) {
} }
else */ else */
{ {
int attributes = kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute;
if (req_properties.has_fixed_size() && req_properties.get_fixed_size()) {
attributes &= ~kWindowResizableAttribute;
}
if (req_properties.has_undecorated() && req_properties.get_undecorated()) { // create a unmovable .. no edge window.. if (req_properties.has_undecorated() && req_properties.get_undecorated()) { // create a unmovable .. no edge window..
tinydisplay_cat.info() << "Creating undecorated window\n"; tinydisplay_cat.info() << "Creating undecorated window\n";
CreateNewWindow(kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowNoTitleBarAttribute, &r, &_osx_window); // We don't want a resize box either.
attributes &= ~kWindowResizableAttribute;
attributes |= kWindowNoTitleBarAttribute;
CreateNewWindow(kDocumentWindowClass, attributes, &r, &_osx_window);
} }
else else
{ // create a window with crome and sizing and sucj { // create a window with crome and sizing and sucj
// In this case, we want to constrain the window to the // In this case, we want to constrain the window to the
// available size. // available size.
Rect bounds; Rect bounds;
GetAvailableWindowPositioningBounds(GetMainDevice(), &bounds); GetAvailableWindowPositioningBounds(GetMainDevice(), &bounds);
@ -970,7 +999,7 @@ bool TinyOsxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties) {
r.bottom = min(r.bottom, bounds.bottom); r.bottom = min(r.bottom, bounds.bottom);
tinydisplay_cat.info() << "Creating standard window\n"; tinydisplay_cat.info() << "Creating standard window\n";
CreateNewWindow(kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute, &r, &_osx_window); CreateNewWindow(kDocumentWindowClass, attributes, &r, &_osx_window);
AddAWindow(_osx_window); AddAWindow(_osx_window);
} }
} }
@ -986,6 +1015,7 @@ bool TinyOsxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties) {
{ kEventClassWindow, kEventWindowActivated }, { kEventClassWindow, kEventWindowActivated },
{ kEventClassWindow, kEventWindowDeactivated }, { kEventClassWindow, kEventWindowDeactivated },
{ kEventClassWindow, kEventWindowClose }, { kEventClassWindow, kEventWindowClose },
{ kEventClassWindow, kEventWindowBoundsChanging },
{ kEventClassWindow, kEventWindowBoundsChanged }, { kEventClassWindow, kEventWindowBoundsChanged },
{ kEventClassWindow, kEventWindowCollapsed }, { kEventClassWindow, kEventWindowCollapsed },