diff options
| author | Manolo Gouy <Manolo> | 2011-04-15 21:38:05 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2011-04-15 21:38:05 +0000 |
| commit | 9ff9cf123046b64be860a48438566ed6a9f5c541 (patch) | |
| tree | e5d0ddae9a4d580082fba1c0f98190dc50595e4d /src/Fl_cocoa.mm | |
| parent | c473215f2a1ac2659e92973ff9ecaf1579ffc313 (diff) | |
Added Fl_Paged_Device::print_window() to print a window with its title bar and frame.
Added Fl_Window::decorated_w() and Fl_Window::decorated_h() that return the size
of a window with its title bar and frame.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8593 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_cocoa.mm')
| -rw-r--r-- | src/Fl_cocoa.mm | 89 |
1 files changed, 59 insertions, 30 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index eac031a28..0951e1c06 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -1417,12 +1417,20 @@ void fl_close_display() { // Gets the border sizes and the titlebar size static void get_window_frame_sizes(int &bx, int &by, int &bt) { - if (NSApp == nil) fl_open_display(); - NSRect inside = { {20,20}, {100,100} }; - NSRect outside = [NSWindow frameRectForContentRect:inside styleMask:NSTitledWindowMask]; - bx = int(outside.origin.x - inside.origin.x); - by = int(outside.origin.y - inside.origin.y); - bt = int(outside.size.height - inside.size.height - by); + static bool first = true; + static int top, left, bottom; + if (first) { + first = false; + if (NSApp == nil) fl_open_display(); + NSRect inside = { {20,20}, {100,100} }; + NSRect outside = [NSWindow frameRectForContentRect:inside styleMask:NSTitledWindowMask]; + left = int(outside.origin.x - inside.origin.x); + bottom = int(outside.origin.y - inside.origin.y); + top = int(outside.size.height - inside.size.height) - bottom; + } + bx = left; + by = bottom; + bt = top; } /* @@ -2861,7 +2869,7 @@ int Fl_X::screen_init(XRectangle screens[], float dpi[]) { Fl_Printer printer; //Fl_PostScript_File_Device printer; - int w, h, wh; + int w, h, ww, wh; Fl_Window *win = Fl::first_window(); if(!win) return; if( printer.start_job(1) ) return; @@ -2869,13 +2877,9 @@ int Fl_X::screen_init(XRectangle screens[], float dpi[]) // scale the printer device so that the window fits on the page float scale = 1; printer.printable_rect(&w, &h); - wh = win->h(); - int bx, by, bt = 0; - if (win->border()) { - get_window_frame_sizes(bx, by, bt); - wh += bt; - } - if (win->w()>w || wh>h) { + ww = win->decorated_w(); + wh = win->decorated_h(); + if (ww>w || wh>h) { scale = (float)w/win->w(); if ((float)h/wh < scale) scale = (float)h/wh; printer.scale(scale); @@ -2888,22 +2892,7 @@ int Fl_X::screen_init(XRectangle screens[], float dpi[]) printer.rotate(20.); printer.print_widget( win, - win->w()/2, - win->h()/2 ); #else - if (bt) { // print the window title bar - //printer.print_window_part(win, 0, -bt, win->w(), bt, 0, 1); - Fl_Display_Device::display_device()->set_current(); - win->show(); - fl_gc = NULL; - Fl::check(); - win->make_current(); - CGImageRef img = Fl_X::CGImage_from_window_rect(win, 0, -bt, win->w(), bt); - printer.set_current(); - CGRect rect = { { 0, 1 }, { win->w(), bt } }; - Fl_X::q_begin_image(rect, 0, 0, win->w(), bt); - CGContextDrawImage(fl_gc, rect, img); - Fl_X::q_end_image(); - CGImageRelease(img); - } - printer.print_widget(win, 0, bt); + printer.print_window(win); #endif printer.end_page(); printer.end_job(); @@ -3401,6 +3390,46 @@ Window fl_xid(const Fl_Window* w) return Fl_X::i(w)->xid; } +int Fl_Window::decorated_w() +{ + if (this->parent() || !border()) return w(); + int bx, by, bt; + get_window_frame_sizes(bx, by, bt); + return w() + 2 * bx; +} + +int Fl_Window::decorated_h() +{ + if (this->parent() || !border()) return h(); + int bx, by, bt; + get_window_frame_sizes(bx, by, bt); + return h() + bt + by; +} + +void Fl_Paged_Device::print_window(Fl_Window *win, int x_offset, int y_offset) +{ + if (win->parent() || !win->border()) { + this->print_widget(win, x_offset, y_offset); + return; + } + int bx, by, bt; + get_window_frame_sizes(bx, by, bt); + Fl_Display_Device::display_device()->set_current(); // send win to front and make it current + win->show(); + fl_gc = NULL; + Fl::check(); + win->make_current(); + // capture the window title bar from screen + CGImageRef img = Fl_X::CGImage_from_window_rect(win, 0, -bt, win->w(), bt); + this->set_current(); // back to the Fl_Paged_Device + CGRect rect = { { 0, 1 }, { win->w(), bt } }; // print the title bar + Fl_X::q_begin_image(rect, 0, 0, win->w(), bt); + CGContextDrawImage(fl_gc, rect, img); + Fl_X::q_end_image(); + CGImageRelease(img); + this->print_widget(win, x_offset, y_offset + bt); // print the window inner part +} + #include <dlfcn.h> /* Returns the address of a Carbon function after dynamically loading the Carbon library if needed. |
