summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2016-04-19 14:25:47 +0000
committerManolo Gouy <Manolo>2016-04-19 14:25:47 +0000
commitf9edd867538f44af3eaf56cb8673b05668b56428 (patch)
tree760895218ea2803d7ab49371ebe5db81abd4903d
parent034cfc94a31b92a02454630da1edb27670633ebb (diff)
Move several of the methods of class Fl_X for Mac platform to class Fl_Cocoa_Window_Driver.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11657 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--FL/mac.H23
-rw-r--r--src/Fl_Gl_Window.cxx13
-rw-r--r--src/Fl_cocoa.mm79
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm2
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx3
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H16
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx4
7 files changed, 72 insertions, 68 deletions
diff --git a/FL/mac.H b/FL/mac.H
index 302783edb..7deaf0df8 100644
--- a/FL/mac.H
+++ b/FL/mac.H
@@ -86,15 +86,11 @@ typedef unsigned int NSUInteger;
#endif
#ifdef __OBJC__
-@class NSCursor;
@class NSOpenGLPixelFormat;
@class NSOpenGLContext;
-@class CALayer;
#else
-class NSCursor;
class NSOpenGLPixelFormat;
class NSOpenGLContext;
-class CALayer;
#endif // __OBJC__
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4
@@ -116,9 +112,6 @@ typedef float CGFloat;
#endif
#endif // CGFLOAT_DEFINED
-//extern CGRect fl_cgrectmake_cocoa(int x, int y, int w, int h);
-extern NSCursor *fl_default_cursor;
-
// This object contains all mac-specific stuff about a window:
// WARNING: this object is highly subject to change!
class Fl_X {
@@ -130,14 +123,6 @@ public:
static Fl_X* first;
static Fl_X* i(const Fl_Window* w) {return (Fl_X*)w->i;}
static void make(Fl_Window*);
- CGRect* subRect() { return subRect_; } // getter
- void subRect(CGRect *r) { subRect_ = r; } // setter
- bool mapped_to_retina(); // is window mapped to retina display?
- void mapped_to_retina(bool); // sets whether window is mapped to retina display
- bool changed_resolution(); // did window just moved to display with another resolution?
- void changed_resolution(bool);// sets whether window just moved to display with another resolution
- bool in_windowDidResize(); // is window performing windowDidResize?
- void in_windowDidResize(bool); // sets whether window is performing windowDidResize
// 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);
@@ -146,14 +131,6 @@ public:
static void GLcontext_release(NSOpenGLContext*);
static void GLcontext_makecurrent(NSOpenGLContext*);
static void GL_cleardrawable(void);
- void destroy(void);
- static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
- static unsigned char *bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
-private:
- CGRect* subRect_; // makes sure subwindow remains inside its parent window
- // stores 3 binary flags: whether window is mapped to retina display; whether resolution just changed;
- // whether window is OpenGL and is currently being resized.
- unsigned mapped_to_retina_;
};
extern Window fl_window;
diff --git a/src/Fl_Gl_Window.cxx b/src/Fl_Gl_Window.cxx
index 590a61ee3..0078c089b 100644
--- a/src/Fl_Gl_Window.cxx
+++ b/src/Fl_Gl_Window.cxx
@@ -24,11 +24,13 @@ extern int fl_gl_load_plugin;
#include <FL/Fl.H>
#include <FL/Fl_Graphics_Driver.H>
+#include <FL/Fl_Window_Driver.H>
#include <FL/x.H>
#include "Fl_Gl_Choice.H"
#ifdef __APPLE__ // PORTME: platform OpenGL management
#include <FL/gl.h>
#include <OpenGL/OpenGL.h>
+#include "drivers/Cocoa/Fl_Cocoa_Window_Driver.H"
#endif
#include <FL/Fl_Gl_Window.H>
#include <FL/Fl_Device.H>
@@ -110,7 +112,8 @@ void Fl_Gl_Window::show() {
int Fl_Gl_Window::pixels_per_unit()
{
- return (fl_mac_os_version >= 100700 && Fl::use_high_res_GL() && Fl_X::i(this) && Fl_X::i(this)->mapped_to_retina()) ? 2 : 1;
+ return (fl_mac_os_version >= 100700 && Fl::use_high_res_GL() && Fl_X::i(this) &&
+ ((Fl_Cocoa_Window_Driver*)driver())->mapped_to_retina()) ? 2 : 1;
}
#endif // __APPLE__ // PORTME: platform OpenGL management
@@ -194,8 +197,9 @@ void Fl_Gl_Window::make_current() {
// printf("make_current: context_=%p\n", context_);
#if defined(__APPLE__) // PORTME: platform OpenGL management
// detect if the window was moved between low and high resolution displays
- if (Fl_X::i(this)->changed_resolution()){
- Fl_X::i(this)->changed_resolution(false);
+ Fl_Cocoa_Window_Driver *d = (Fl_Cocoa_Window_Driver*)driver();
+ if (d->changed_resolution()){
+ d->changed_resolution(false);
invalidate();
Fl_X::GLcontext_update(context_);
}
@@ -438,7 +442,8 @@ void Fl_Gl_Window::resize(int X,int Y,int W,int H) {
#ifdef __APPLE__ // PORTME: platform OpenGL management
Fl_X *flx = Fl_X::i(this);
- if (flx && flx->in_windowDidResize()) Fl_X::GLcontext_update(context_);
+ Fl_Cocoa_Window_Driver *d = (Fl_Cocoa_Window_Driver*)driver();
+ if (flx && d->in_windowDidResize()) Fl_X::GLcontext_update(context_);
#endif
#if ! ( defined(__APPLE__) || defined(WIN32) ) // PORTME: platform OpenGL management
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index 0e2e72beb..667115b73 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -754,7 +754,8 @@ void Fl_Cocoa_Screen_Driver::remove_timeout(Fl_Timeout_Handler cb, void* data)
srect = CGRectIntersection(prect, srect); // area of subwindow inside its parent
from = parent;
}
- CGRect *r = Fl_X::i(w)->subRect();
+ Fl_Cocoa_Window_Driver *d = (Fl_Cocoa_Window_Driver*)w->driver();
+ CGRect *r = d->subRect();
CGRect current_clip = (r ? *r : full); // current subwindow clip
if (!CGRectEqualToRect(srect, current_clip)) { // if new clip differs from current clip
delete r;
@@ -764,7 +765,7 @@ void Fl_Cocoa_Screen_Driver::remove_timeout(Fl_Timeout_Handler cb, void* data)
r = new CGRect(srect);
if (r->size.width == 0 && r->size.height == 0) r->origin.x = r->origin.y = 0;
}
- Fl_X::i(w)->subRect(r);
+ d->subRect(r);
}
}
@@ -1229,34 +1230,34 @@ static void orderfront_subwindows(FLWindow *xid)
static const unsigned windowDidResize_mask = 1;
-bool Fl_X::in_windowDidResize() {
- return mapped_to_retina_ & windowDidResize_mask;
+bool Fl_Cocoa_Window_Driver::in_windowDidResize() {
+ return window_flags_ & windowDidResize_mask;
}
-void Fl_X::in_windowDidResize(bool b) {
- if (b) mapped_to_retina_ |= windowDidResize_mask;
- else mapped_to_retina_ &= ~windowDidResize_mask;
+void Fl_Cocoa_Window_Driver::in_windowDidResize(bool b) {
+ if (b) window_flags_ |= windowDidResize_mask;
+ else window_flags_ &= ~windowDidResize_mask;
}
static const unsigned mapped_mask = 2;
static const unsigned changed_mask = 4;
-bool Fl_X::mapped_to_retina() {
- return mapped_to_retina_ & mapped_mask;
+bool Fl_Cocoa_Window_Driver::mapped_to_retina() {
+ return window_flags_ & mapped_mask;
}
-void Fl_X::mapped_to_retina(bool b) {
- if (b) mapped_to_retina_ |= mapped_mask;
- else mapped_to_retina_ &= ~mapped_mask;
+void Fl_Cocoa_Window_Driver::mapped_to_retina(bool b) {
+ if (b) window_flags_ |= mapped_mask;
+ else window_flags_ &= ~mapped_mask;
}
-bool Fl_X::changed_resolution() {
- return mapped_to_retina_ & changed_mask;
+bool Fl_Cocoa_Window_Driver::changed_resolution() {
+ return window_flags_ & changed_mask;
}
-void Fl_X::changed_resolution(bool b) {
- if (b) mapped_to_retina_ |= changed_mask;
- else mapped_to_retina_ &= ~changed_mask;
+void Fl_Cocoa_Window_Driver::changed_resolution(bool b) {
+ if (b) window_flags_ |= changed_mask;
+ else window_flags_ &= ~changed_mask;
}
@@ -1349,12 +1350,13 @@ static FLWindowDelegate *flwindowdelegate_instance = nil;
parent = parent->window();
}
resize_from_system = window;
- if (window->as_gl_window() && Fl_X::i(window)) Fl_X::i(window)->in_windowDidResize(true);
+ Fl_Cocoa_Window_Driver *d = (Fl_Cocoa_Window_Driver*)window->driver();
+ if (window->as_gl_window() && Fl_X::i(window)) d->in_windowDidResize(true);
update_e_xy_and_e_xy_root(nsw);
window->resize((int)pt2.x, (int)pt2.y, (int)r.size.width, (int)r.size.height);
[nsw recursivelySendToSubwindows:@selector(setSubwindowFrame)];
[nsw recursivelySendToSubwindows:@selector(checkSubwindowFrame)];
- if (window->as_gl_window() && Fl_X::i(window)) Fl_X::i(window)->in_windowDidResize(false);
+ if (window->as_gl_window() && Fl_X::i(window)) d->in_windowDidResize(false);
fl_unlock_function();
}
- (void)windowDidResignKey:(NSNotification *)notif
@@ -1923,24 +1925,25 @@ static void handleUpdateEvent( Fl_Window *window )
{
if ( !window ) return;
Fl_X *i = Fl_X::i( window );
+ Fl_Cocoa_Window_Driver *d = (Fl_Cocoa_Window_Driver*)window->driver();
if (fl_mac_os_version >= 100700) { // determine whether window is mapped to a retina display
- bool previous = i->mapped_to_retina();
+ bool previous = d->mapped_to_retina();
// rewrite next call that requires 10.7 and therefore triggers a compiler warning on old SDKs
//NSSize s = [[i->xid contentView] convertSizeToBacking:NSMakeSize(10, 10)];
typedef NSSize (*convertSizeIMP)(id, SEL, NSSize);
static convertSizeIMP addr = (convertSizeIMP)[NSView instanceMethodForSelector:@selector(convertSizeToBacking:)];
NSSize s = addr([i->xid contentView], @selector(convertSizeToBacking:), NSMakeSize(10, 10));
- i->mapped_to_retina( int(s.width + 0.5) > 10 );
- if (window->driver()->wait_for_expose_value == 0 && previous != i->mapped_to_retina()) i->changed_resolution(true);
+ d->mapped_to_retina( int(s.width + 0.5) > 10 );
+ if (d->wait_for_expose_value == 0 && previous != d->mapped_to_retina()) d->changed_resolution(true);
}
- window->driver()->wait_for_expose_value = 0;
+ d->wait_for_expose_value = 0;
if ( i->region ) {
Fl_Graphics_Driver::default_driver().XDestroyRegion(i->region);
i->region = 0;
}
window->clear_damage(FL_DAMAGE_ALL);
- window->driver()->flush();
+ d->flush();
window->clear_damage();
}
@@ -2944,13 +2947,14 @@ void Fl_X::make(Fl_Window* w)
}
Fl_X *x = new Fl_X;
- w->driver()->other_xid = 0; // room for doublebuffering image map. On OS X this is only used by overlay windows
+ 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;
- x->subRect(0);
- ((Fl_Cocoa_Window_Driver*)w->pWindowDriver)->gc = 0;
- x->mapped_to_retina(false);
- x->changed_resolution(false);
- x->in_windowDidResize(false);
+ d->subRect(0);
+ d->gc = 0;
+ d->mapped_to_retina(false);
+ d->changed_resolution(false);
+ d->in_windowDidResize(false);
NSRect crect;
if (w->fullscreen_active()) {
@@ -3251,7 +3255,7 @@ void Fl_Cocoa_Window_Driver::make_current()
q_release_context();
Fl_X *i = Fl_X::i(pWindow);
fl_window = i->xid;
- ((Fl_Quartz_Graphics_Driver*)Fl_Display_Device::display_device()->driver())->high_resolution( i->mapped_to_retina() );
+ ((Fl_Quartz_Graphics_Driver*)Fl_Display_Device::display_device()->driver())->high_resolution( mapped_to_retina() );
NSGraphicsContext *nsgc;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
@@ -3272,7 +3276,7 @@ void Fl_Cocoa_Window_Driver::make_current()
CGContextScaleCTM(gc, 1.0f, -1.0f); // now 0,0 is top-left point of the window
// for subwindows, limit drawing to inside of parent window
// half pixel offset is necessary for clipping as done by fl_cgrectmake_cocoa()
- if (i->subRect()) CGContextClipToRect(gc, CGRectOffset(*(i->subRect()), -0.5, -0.5));
+ if (subRect()) CGContextClipToRect(gc, CGRectOffset(*(subRect()), -0.5, -0.5));
// this is the context with origin at top left of (sub)window
CGContextSaveGState(gc);
@@ -3498,7 +3502,8 @@ int Fl_Darwin_System_Driver::clipboard_contains(const char *type) {
return found != nil;
}
-void Fl_X::destroy() {
+void Fl_Cocoa_Window_Driver::destroy() {
+ FLWindow *xid = fl_xid(pWindow);
if (xid) {
[xid close];
}
@@ -4115,7 +4120,7 @@ static NSBitmapImageRep* rect_to_NSBitmapImageRep(Fl_Window *win, int x, int y,
}
-unsigned char *Fl_X::bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel)
+unsigned char *Fl_Cocoa_Window_Driver::bitmap_from_window_rect(int x, int y, int w, int h, int *bytesPerPixel)
/* Returns a capture of a rectangle of a mapped window as a pre-multiplied RGBA array of bytes.
Alpha values are always 1 (except for the angles of a window title bar)
so pre-multiplication can be ignored.
@@ -4123,6 +4128,7 @@ unsigned char *Fl_X::bitmap_from_window_rect(Fl_Window *win, int x, int y, int w
delete[] the returned pointer after use
*/
{
+ Fl_Window *win = pWindow;
NSBitmapImageRep *bitmap = rect_to_NSBitmapImageRep(win, x, y, w, h);
if (bitmap == nil) return NULL;
*bytesPerPixel = [bitmap bitsPerPixel]/8;
@@ -4192,12 +4198,13 @@ static void nsbitmapProviderReleaseData (void *info, const void *data, size_t si
[(NSBitmapImageRep*)info release];
}
-CGImageRef Fl_X::CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h)
+CGImageRef Fl_Cocoa_Window_Driver::CGImage_from_window_rect(int x, int y, int w, int h)
/* Returns a capture of a rectangle of a mapped window as a CGImage.
With retina displays, the returned image has twice the width and height.
CFRelease the returned CGImageRef after use
*/
{
+ Fl_Window *win = pWindow;
CGImageRef img;
NSBitmapImageRep *bitmap = rect_to_NSBitmapImageRep(win, x, y, w, h);
if (fl_mac_os_version >= 100500) {
@@ -4296,7 +4303,7 @@ void Fl_Cocoa_Window_Driver::capture_titlebar_and_borders(Fl_Shared_Image*& top,
if (layer) {
Fl_Cocoa_Window_Driver::draw_layer_to_context(layer, auxgc, w(), htop);
} else {
- CGImageRef img = Fl_X::CGImage_from_window_rect(pWindow, 0, -htop, w(), htop);
+ CGImageRef img = CGImage_from_window_rect(0, -htop, w(), htop);
CGContextSaveGState(auxgc);
clip_to_rounded_corners(auxgc, w(), htop);
CGContextDrawImage(auxgc, CGRectMake(0, 0, w(), htop), img);
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm b/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm
index aa23818e6..2003f2d46 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm
+++ b/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm
@@ -373,7 +373,7 @@ void Fl_Cocoa_Printer_Driver::print_window_part(Fl_Window *win, int x, int y, in
Fl_Window *save_front = Fl::first_window();
win->show();
Fl::check();
- CGImageRef img = Fl_X::CGImage_from_window_rect(win, x, y, w, h);
+ CGImageRef img = ((Fl_Cocoa_Window_Driver*)win->driver())->CGImage_from_window_rect(x, y, w, h);
if (save_front != win) save_front->show();
current->set_current();
((Fl_Quartz_Graphics_Driver*)driver())->draw_CGImage(img,delta_x, delta_y, w, h, 0,0,w,h);
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
index d4054affc..1506fbbc4 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
+++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
@@ -339,7 +339,8 @@ Fl_Cocoa_Screen_Driver::read_image(uchar *p, // I - Pixel buffer or NULL to all
if( (sw - x < w) || (sh - y < h) ) return NULL;
}
else { // reading from current window
- base = Fl_X::bitmap_from_window_rect(Fl_Window::current(),x,y,w,h,&delta);
+ Fl_Cocoa_Window_Driver *d = (Fl_Cocoa_Window_Driver*)Fl_Window::current()->driver();
+ base = d->bitmap_from_window_rect(x,y,w,h,&delta);
if (!base) return NULL;
rowBytes = delta*w;
x = y = 0;
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H
index caf705cbe..406182967 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H
+++ b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H
@@ -66,7 +66,10 @@ class FL_EXPORT Fl_Cocoa_Window_Driver : public Fl_Window_Driver
private:
void shape_bitmap_(Fl_Image* b);
void shape_alpha_(Fl_Image* img, int offset);
-
+ CGRect* subRect_; // makes sure subwindow remains inside its parent window
+ // stores 3 binary flags: whether window is mapped to retina display; whether resolution just changed;
+ // whether window is OpenGL and is currently being resized.
+ unsigned window_flags_;
public:
Fl_Cocoa_Window_Driver(Fl_Window*);
~Fl_Cocoa_Window_Driver();
@@ -74,6 +77,17 @@ public:
NSCursor *cursor;
static void q_release_context(Fl_Cocoa_Window_Driver *x = 0); // free all resources associated with gc
void set_key_window();
+ bool mapped_to_retina(); // is window mapped to retina display?
+ void mapped_to_retina(bool); // sets whether window is mapped to retina display
+ bool changed_resolution(); // did window just moved to display with another resolution?
+ void changed_resolution(bool);// sets whether window just moved to display with another resolution
+ bool in_windowDidResize(); // is window performing windowDidResize?
+ void in_windowDidResize(bool); // sets whether window is performing windowDidResize
+ CGRect* subRect() { return subRect_; } // getter
+ void subRect(CGRect *r) { subRect_ = r; } // setter
+ void destroy();
+ unsigned char *bitmap_from_window_rect(int x, int y, int w, int h, int *bytesPerPixel);
+ CGImageRef CGImage_from_window_rect(int x, int y, int w, int h);
// --- window data
virtual int decorated_w();
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
index df1bb114e..8e1b59ee2 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
+++ b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
@@ -240,7 +240,7 @@ void Fl_Cocoa_Window_Driver::hide() {
if ( ip->xid == fl_window )
fl_window = 0;
if (ip->region) Fl_Graphics_Driver::default_driver().XDestroyRegion(ip->region);
- ip->destroy();
+ destroy();
delete ip;
}
@@ -273,7 +273,7 @@ void Fl_Cocoa_Window_Driver::decoration_sizes(int *top, int *left, int *right,
int Fl_Cocoa_Window_Driver::scroll(int src_x, int src_y, int src_w, int src_h, int dest_x, int dest_y, void (*draw_area)(void*, int,int,int,int), void* data)
{
- CGImageRef img = Fl_X::CGImage_from_window_rect(Fl_Window::current(), src_x, src_y, src_w, src_h);
+ CGImageRef img = CGImage_from_window_rect(src_x, src_y, src_w, src_h);
if (img) {
((Fl_Quartz_Graphics_Driver*)fl_graphics_driver)->draw_CGImage(img,dest_x,dest_y,src_w,src_h,0,0,src_w,src_h);
CFRelease(img);