summaryrefslogtreecommitdiff
path: root/src/Fl_cocoa.mm
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2015-11-24 14:26:52 +0000
committerManolo Gouy <Manolo>2015-11-24 14:26:52 +0000
commitb0696db39a39d9c2aadd35f74902ff22535e4d1b (patch)
tree84b876ad7ba4d38ba20e8cbb5cbb75d5ea0571da /src/Fl_cocoa.mm
parenta2b8700a82f9d1eda078c91464c17a98146174b8 (diff)
Added new method Fl_Copy_Surface::draw_decorated_window()
that copies a window to the clipboard together with its title bar and borders. This requires very little new code because the capture of window decorations is shared with the Fl_Paged_Device::print window() method. The device test program is changed to call the new method. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10928 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_cocoa.mm')
-rw-r--r--src/Fl_cocoa.mm39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index d05d3ad5b..8089f75df 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -3855,6 +3855,45 @@ int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
}
@end
+
+void Fl_Copy_Surface::draw_decorated_window(Fl_Window* win, int delta_x, int delta_y)
+{
+ int bx, by, bt;
+ get_window_frame_sizes(bx, by, bt);
+ draw(win, 0, bt); // draw the window content
+ if (win->border()) {
+ // draw the window title bar
+ CGContextSaveGState(gc);
+ CGContextTranslateCTM(gc, 0, bt);
+ CGContextScaleCTM(gc, 1, -1);
+ Fl_X::clip_to_rounded_corners(gc, win->w(), bt);
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
+ CALayer *layer = fl_mac_os_version >= 101000 ?
+ [[[fl_xid(win) standardWindowButton:NSWindowCloseButton] superview] layer] : nil; // 10.5
+ if (layer) {
+ CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB();
+ // for unknown reason, rendering the layer to the Fl_Copy_Surface pdf graphics context does not work;
+ // we use an auxiliary bitmap context
+ CGContextRef auxgc = CGBitmapContextCreate(NULL, win->w(), bt, 8, 0, cspace, kCGImageAlphaPremultipliedLast);
+ CGColorSpaceRelease(cspace);
+ CGContextClearRect(auxgc, CGRectMake(0, 0, win->w(), bt));
+ CGContextTranslateCTM(auxgc, 0, bt);
+ CGContextScaleCTM(auxgc, 1, -1);
+ [layer renderInContext:auxgc]; // 10.5
+ fl_draw_image((uchar*)CGBitmapContextGetData(auxgc), 0, 0, win->w(), bt, 4, CGBitmapContextGetBytesPerRow(auxgc));
+ CGContextRelease(auxgc);
+ } else
+#endif
+ {
+ CGImageRef img = Fl_X::CGImage_from_window_rect(win, 0, -bt, win->w(), bt);
+ CGContextDrawImage(gc, CGRectMake(0, 0, win->w(), bt), img);
+ CFRelease(img);
+ }
+ CGContextRestoreGState(gc);
+ }
+}
+
+
static void createAppleMenu(void)
{
static BOOL donethat = NO;