diff options
| author | Manolo Gouy <Manolo> | 2016-04-19 15:00:02 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2016-04-19 15:00:02 +0000 |
| commit | 6600993adc787768217609c93dd0b3cab581864e (patch) | |
| tree | 2c1e1456e33b363db4225c3f00e6964d05bbaea3 | |
| parent | f9edd867538f44af3eaf56cb8673b05668b56428 (diff) | |
Transform Fl_X::make(Fl_Window*) for Mac platform into Fl_X *Fl_Cocoa_Window_Driver::makeWindow()
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11658 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
| -rw-r--r-- | FL/Fl_Window_Driver.H | 3 | ||||
| -rw-r--r-- | FL/mac.H | 12 | ||||
| -rw-r--r-- | src/Fl_cocoa.mm | 342 | ||||
| -rw-r--r-- | src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H | 1 |
4 files changed, 177 insertions, 181 deletions
diff --git a/FL/Fl_Window_Driver.H b/FL/Fl_Window_Driver.H index 67fc2dfb3..08b396821 100644 --- a/FL/Fl_Window_Driver.H +++ b/FL/Fl_Window_Driver.H @@ -74,6 +74,7 @@ public: int shown() const { return pWindow->shown(); } /** returns the parent of the window. */ Fl_Group *parent() const { return pWindow->parent(); } + char show_iconic() { return pWindow->show_iconic_; } // --- accessors to private window data int minw(); @@ -93,6 +94,8 @@ public: void x(int X); void y(int Y); void current(Fl_Window *c); + void show_iconic(char c) { pWindow->show_iconic_ = c; } + void i(Fl_X *x) { pWindow->i = x; } /** for an Fl_Overlay_Window, returns the value of its overlay_ member variable */ Fl_Window *overlay() { return pWindow->as_overlay_window() ? pWindow->as_overlay_window()->overlay_ : NULL; @@ -35,16 +35,7 @@ typedef class FLWindow *Window; // pointer to the FLWindow objective-c class #include <FL/Fl_System_Driver.H> #include <FL/Fl_Widget.H> // for Fl_Callback -#if !(defined(FL_LIBRARY) || defined(FL_INTERNALS)) // this part is used when compiling an application program - -typedef struct CGContext* CGContextRef; -typedef struct OpaquePMPrintSettings* PMPrintSettings; -typedef struct OpaquePMPageFormat* PMPageFormat; -typedef struct OpaquePMPrintSession* PMPrintSession; -typedef struct CGImage* CGImageRef; -typedef struct __CFData* CFMutableDataRef; // used in Fl_Copy_Surface.H - -#else // this part must be compiled when building the FLTK libraries +#if (defined(FL_LIBRARY) || defined(FL_INTERNALS)) // this part must be compiled when building the FLTK libraries // Standard MacOS C/C++ includes... #include <ApplicationServices/ApplicationServices.h> @@ -122,7 +113,6 @@ public: Fl_X *next; // chain of mapped windows static Fl_X* first; static Fl_X* i(const Fl_Window* w) {return (Fl_X*)w->i;} - static void make(Fl_Window*); // Cocoa additions static NSOpenGLPixelFormat *mode_to_NSOpenGLPixelFormat(int mode, const int*); // computes NSOpenGLPixelFormat from Gl window's mode static NSOpenGLContext* create_GLcontext_for_window(NSOpenGLPixelFormat *pixelformat, NSOpenGLContext *shared_ctx, Fl_Window *window); diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 667115b73..77f2d4d16 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -2879,182 +2879,183 @@ void Fl_Cocoa_Window_Driver::flush() /* * go ahead, create that (sub)window */ -void Fl_X::make(Fl_Window* w) +Fl_X* Fl_Cocoa_Window_Driver::makeWindow() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - Fl_Group::current(0); - fl_open_display(); - NSInteger winlevel = NSNormalWindowLevel; - NSUInteger winstyle; - if (w->parent()) { - w->border(0); - Fl_Window::show_iconic_ = 0; - } - if (w->border()) winstyle = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask; - else winstyle = NSBorderlessWindowMask; - if (Fl_Window::show_iconic_ && !w->parent()) { // prevent window from being out of work area when created iconized - int sx, sy, sw, sh; - Fl::screen_work_area (sx, sy, sw, sh, w->x(), w->y()); - if (w->x() < sx) w->x(sx); - if (w->y() < sy) w->y(sy); + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + Fl_Group::current(0); + fl_open_display(); + NSInteger winlevel = NSNormalWindowLevel; + NSUInteger winstyle; + Fl_Window* w = pWindow; + if (w->parent()) { + w->border(0); + show_iconic(0); + } + if (w->border()) winstyle = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask; + else winstyle = NSBorderlessWindowMask; + if (show_iconic() && !w->parent()) { // prevent window from being out of work area when created iconized + int sx, sy, sw, sh; + Fl::screen_work_area (sx, sy, sw, sh, w->x(), w->y()); + if (w->x() < sx) x(sx); + if (w->y() < sy) y(sy); + } + int xp = w->x(); + int yp = w->y(); + int wp = w->w(); + int hp = w->h(); + if (size_range_set()) { + if ( minh() != maxh() || minw() != maxw()) { + if (w->border()) winstyle |= NSResizableWindowMask; } - int xp = w->x(); - int yp = w->y(); - int wp = w->w(); - int hp = w->h(); - if (w->size_range_set) { - if ( w->minh != w->maxh || w->minw != w->maxw) { - if (w->border()) winstyle |= NSResizableWindowMask; - } + } else { + if (w->resizable()) { + Fl_Widget *o = w->resizable(); + int minw = o->w(); if (minw > 100) minw = 100; + int minh = o->h(); if (minh > 100) minh = 100; + w->size_range(w->w() - o->w() + minw, w->h() - o->h() + minh, 0, 0); + if (w->border()) winstyle |= NSResizableWindowMask; } else { - if (w->resizable()) { - Fl_Widget *o = w->resizable(); - int minw = o->w(); if (minw > 100) minw = 100; - int minh = o->h(); if (minh > 100) minh = 100; - w->size_range(w->w() - o->w() + minw, w->h() - o->h() + minh, 0, 0); - if (w->border()) winstyle |= NSResizableWindowMask; - } else { - w->size_range(w->w(), w->h(), w->w(), w->h()); - } + w->size_range(w->w(), w->h(), w->w(), w->h()); } - int xwm = xp, ywm = yp, bt, bx, by; - - if (!fake_X_wm(w, xwm, ywm, bt, bx, by)) { - // menu windows and tooltips - if (w->modal()||w->tooltip_window()) { - winlevel = modal_window_level(); - } - } - if (w->modal()) { - winstyle &= ~NSMiniaturizableWindowMask; + } + int xwm = xp, ywm = yp, bt, bx, by; + + if (!fake_X_wm(w, xwm, ywm, bt, bx, by)) { + // menu windows and tooltips + if (w->modal()||w->tooltip_window()) { winlevel = modal_window_level(); } - else if (w->non_modal()) { - winlevel = non_modal_window_level(); - } - - if (by+bt) { - wp += 2*bx; - hp += 2*by+bt; - } - if (w->force_position()) { - if (!Fl::grab()) { - xp = xwm; yp = ywm; - w->x(xp);w->y(yp); - } - xp -= bx; - yp -= by+bt; + } + if (w->modal()) { + winstyle &= ~NSMiniaturizableWindowMask; + winlevel = modal_window_level(); + } + else if (w->non_modal()) { + winlevel = non_modal_window_level(); + } + + if (by+bt) { + wp += 2*bx; + hp += 2*by+bt; + } + if (force_position()) { + if (!Fl::grab()) { + xp = xwm; yp = ywm; + x(xp);y(yp); } + xp -= bx; + yp -= by+bt; + } - Fl_X *x = new Fl_X; - Fl_Cocoa_Window_Driver *d = (Fl_Cocoa_Window_Driver*)w->pWindowDriver; - d->other_xid = 0; // room for doublebuffering image map. On OS X this is only used by overlay windows - x->region = 0; - d->subRect(0); - d->gc = 0; - d->mapped_to_retina(false); - d->changed_resolution(false); - d->in_windowDidResize(false); + Fl_X *x = new Fl_X; + other_xid = 0; // room for doublebuffering image map. On OS X this is only used by overlay windows + x->region = 0; + subRect(0); + gc = 0; + mapped_to_retina(false); + changed_resolution(false); + in_windowDidResize(false); - NSRect crect; - if (w->fullscreen_active()) { - int top, bottom, left, right; - int sx, sy, sw, sh, X, Y, W, H; - - top = w->fullscreen_screen_top; - bottom = w->fullscreen_screen_bottom; - left = w->fullscreen_screen_left; - right = w->fullscreen_screen_right; - - if ((top < 0) || (bottom < 0) || (left < 0) || (right < 0)) { - top = Fl::screen_num(w->x(), w->y(), w->w(), w->h()); - bottom = top; - left = top; - right = top; - } - - Fl::screen_xywh(sx, sy, sw, sh, top); - Y = sy; - Fl::screen_xywh(sx, sy, sw, sh, bottom); - H = sy + sh - Y; - Fl::screen_xywh(sx, sy, sw, sh, left); - X = sx; - Fl::screen_xywh(sx, sy, sw, sh, right); - W = sx + sw - X; - - w->resize(X, Y, W, H); - - winstyle = NSBorderlessWindowMask; - winlevel = NSStatusWindowLevel; - } - crect.origin.x = w->x(); // correct origin set later for subwindows - crect.origin.y = main_screen_height - (w->y() + w->h()); - crect.size.width=w->w(); - crect.size.height=w->h(); - FLWindow *cw = [[FLWindow alloc] initWithFl_W:w - contentRect:crect - styleMask:winstyle]; - [cw setFrameOrigin:crect.origin]; - if (!w->parent()) { - [cw setHasShadow:YES]; - [cw setAcceptsMouseMovedEvents:YES]; - } - if (w->is_shaped()) { - [cw setOpaque:NO]; // shaped windows must be non opaque - [cw setBackgroundColor:[NSColor clearColor]]; // and with transparent background color - } - x->xid = cw; - x->w = w; w->i = x; - w->driver()->wait_for_expose_value = 1; - if (!w->parent()) { - x->next = Fl_X::first; - Fl_X::first = x; - } else if (Fl_X::first) { - x->next = Fl_X::first->next; - Fl_X::first->next = x; - } - else { - x->next = NULL; - Fl_X::first = x; - } - FLView *myview = [[FLView alloc] initWithFrame:crect]; - [cw setContentView:myview]; - [myview release]; - [cw setLevel:winlevel]; + NSRect crect; + if (w->fullscreen_active()) { + int top, bottom, left, right; + int sx, sy, sw, sh, X, Y, W, H; - q_set_window_title(cw, w->label(), w->iconlabel()); - if (!w->force_position()) { - if (w->modal()) { - [cw center]; - } else if (w->non_modal()) { - [cw center]; - } else { - static NSPoint delta = NSZeroPoint; - delta = [cw cascadeTopLeftFromPoint:delta]; - } - crect = [cw frame]; // synchronize FLTK's and the system's window coordinates - w->x(int(crect.origin.x)); - w->y(int(main_screen_height - (crect.origin.y + w->h()))); - } - if(w->menu_window()) { // make menu windows slightly transparent - [cw setAlphaValue:0.97]; + top = fullscreen_screen_top(); + bottom = fullscreen_screen_bottom(); + left = fullscreen_screen_left(); + right = fullscreen_screen_right(); + + if ((top < 0) || (bottom < 0) || (left < 0) || (right < 0)) { + top = Fl::screen_num(w->x(), w->y(), w->w(), w->h()); + bottom = top; + left = top; + right = top; } - // Install DnD handlers - [myview registerForDraggedTypes:[NSArray arrayWithObjects:UTF8_pasteboard_type, NSFilenamesPboardType, nil]]; - - if (w->size_range_set) w->pWindowDriver->size_range(); - if ( w->border() || (!w->modal() && !w->tooltip_window()) ) { - Fl_Tooltip::enter(0); + Fl::screen_xywh(sx, sy, sw, sh, top); + Y = sy; + Fl::screen_xywh(sx, sy, sw, sh, bottom); + H = sy + sh - Y; + Fl::screen_xywh(sx, sy, sw, sh, left); + X = sx; + Fl::screen_xywh(sx, sy, sw, sh, right); + W = sx + sw - X; + + w->resize(X, Y, W, H); + + winstyle = NSBorderlessWindowMask; + winlevel = NSStatusWindowLevel; + } + crect.origin.x = w->x(); // correct origin set later for subwindows + crect.origin.y = main_screen_height - (w->y() + w->h()); + crect.size.width=w->w(); + crect.size.height=w->h(); + FLWindow *cw = [[FLWindow alloc] initWithFl_W:w + contentRect:crect + styleMask:winstyle]; + [cw setFrameOrigin:crect.origin]; + if (!w->parent()) { + [cw setHasShadow:YES]; + [cw setAcceptsMouseMovedEvents:YES]; + } + if (w->is_shaped()) { + [cw setOpaque:NO]; // shaped windows must be non opaque + [cw setBackgroundColor:[NSColor clearColor]]; // and with transparent background color + } + x->xid = cw; + x->w = w; + i(x); + w->driver()->wait_for_expose_value = 1; + if (!w->parent()) { + x->next = Fl_X::first; + Fl_X::first = x; + } else if (Fl_X::first) { + x->next = Fl_X::first->next; + Fl_X::first->next = x; + } + else { + x->next = NULL; + Fl_X::first = x; + } + FLView *myview = [[FLView alloc] initWithFrame:crect]; + [cw setContentView:myview]; + [myview release]; + [cw setLevel:winlevel]; + + q_set_window_title(cw, w->label(), w->iconlabel()); + if (!force_position()) { + if (w->modal()) { + [cw center]; + } else if (w->non_modal()) { + [cw center]; + } else { + static NSPoint delta = NSZeroPoint; + delta = [cw cascadeTopLeftFromPoint:delta]; } - - if (w->modal()) Fl::modal_ = w; - - w->set_visible(); - if ( w->border() || (!w->modal() && !w->tooltip_window()) ) Fl::handle(FL_FOCUS, w); - [cw setDelegate:[FLWindowDelegate singleInstance]]; - if (Fl_Window::show_iconic_) { - Fl_Window::show_iconic_ = 0; + crect = [cw frame]; // synchronize FLTK's and the system's window coordinates + this->x(int(crect.origin.x)); + this->y(int(main_screen_height - (crect.origin.y + w->h()))); + } + if(w->menu_window()) { // make menu windows slightly transparent + [cw setAlphaValue:0.97]; + } + // Install DnD handlers + [myview registerForDraggedTypes:[NSArray arrayWithObjects:UTF8_pasteboard_type, NSFilenamesPboardType, nil]]; + + if (size_range_set()) size_range(); + + if ( w->border() || (!w->modal() && !w->tooltip_window()) ) { + Fl_Tooltip::enter(0); + } + + if (w->modal()) Fl::modal_ = w; + + w->set_visible(); + if ( w->border() || (!w->modal() && !w->tooltip_window()) ) Fl::handle(FL_FOCUS, w); + [cw setDelegate:[FLWindowDelegate singleInstance]]; + if (show_iconic()) { + show_iconic(0); w->handle(FL_SHOW); // create subwindows if any [cw recursivelySendToSubwindows:@selector(display)]; // draw the window and its subwindows before its icon is computed [cw miniaturize:nil]; @@ -3071,12 +3072,13 @@ void Fl_X::make(Fl_Window* w) [cw makeKeyAndOrderFront:nil]; } - int old_event = Fl::e_number; - w->handle(Fl::e_number = FL_SHOW); - Fl::e_number = old_event; - - // if (w->modal()) { Fl::modal_ = w; fl_fix_focus(); } - [pool release]; + int old_event = Fl::e_number; + w->handle(Fl::e_number = FL_SHOW); + Fl::e_number = old_event; + + // if (w->modal()) { Fl::modal_ = w; fl_fix_focus(); } + [pool release]; + return x; } @@ -3139,7 +3141,7 @@ void Fl_Cocoa_Window_Driver::show() { Fl_X *top = NULL; if (parent()) top = Fl_X::i(pWindow->top_window()); if (!shown() && (!parent() || (top && ![top->xid isMiniaturized]))) { - Fl_X::make(pWindow); + makeWindow(); } else { if ( !parent() ) { Fl_X *i = Fl_X::i(pWindow); diff --git a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H index 406182967..3f7f0ab64 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H +++ b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H @@ -94,6 +94,7 @@ public: virtual int decorated_h(); // --- window management + virtual Fl_X *makeWindow(); virtual void take_focus(); virtual void flush(); virtual void flush_double(); |
