Fix potential memory error in Mac OS code for printing window titlebars.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@11370 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
71ed0752fb
commit
014ea2f871
@ -4478,8 +4478,9 @@ void Fl_Paged_Device::print_window(Fl_Window *win, int x_offset, int y_offset)
|
||||
return;
|
||||
}
|
||||
Fl_Display_Device::display_device()->set_current(); // send win to front and make it current
|
||||
const char *title = win->label();
|
||||
win->label(""); // temporarily set a void window title
|
||||
NSString *title = [fl_xid(win) title];
|
||||
[title retain];
|
||||
[fl_xid(win) setTitle:@""]; // temporarily set a void window title
|
||||
win->show();
|
||||
fl_gc = NULL;
|
||||
Fl::check();
|
||||
@ -4490,7 +4491,7 @@ void Fl_Paged_Device::print_window(Fl_Window *win, int x_offset, int y_offset)
|
||||
img = Fl_X::CGImage_from_window_rect(win, 0, -bt, win->w(), bt);
|
||||
else
|
||||
bitmap = Fl_X::bitmap_from_window_rect(win, 0, -bt, win->w(), bt, &bpp);
|
||||
win->label(title); // put back the window title
|
||||
[fl_xid(win) setTitle:title]; // put back the window title
|
||||
this->set_current(); // back to the Fl_Paged_Device
|
||||
if (img && to_quartz) { // print the title bar
|
||||
CGRect rect = CGRectMake(x_offset, y_offset, win->w(), bt);
|
||||
@ -4505,7 +4506,7 @@ void Fl_Paged_Device::print_window(Fl_Window *win, int x_offset, int y_offset)
|
||||
delete rgb;
|
||||
delete[] bitmap;
|
||||
}
|
||||
if (title) { // print the window title
|
||||
if (win->label()) { // print the window title
|
||||
const int skip = 65; // approx width of the zone of the 3 window control buttons
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
||||
if (fl_mac_os_version >= 100400 && to_quartz) { // use Cocoa string drawing with exact title bar font
|
||||
@ -4514,13 +4515,12 @@ void Fl_Paged_Device::print_window(Fl_Window *win, int x_offset, int y_offset)
|
||||
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:fl_gc flipped:YES]];//10.4
|
||||
NSDictionary *attr = [NSDictionary dictionaryWithObject:[NSFont titleBarFontOfSize:0]
|
||||
forKey:NSFontAttributeName];
|
||||
NSString *title_s = [fl_xid(win) title];
|
||||
NSSize size = [title_s sizeWithAttributes:attr];
|
||||
NSSize size = [title sizeWithAttributes:attr];
|
||||
int x = x_offset + win->w()/2 - size.width/2;
|
||||
if (x < x_offset+skip) x = x_offset+skip;
|
||||
NSRect r = NSMakeRect(x, y_offset+bt/2+4, win->w() - skip, bt);
|
||||
[[NSGraphicsContext currentContext] setShouldAntialias:YES];
|
||||
[title_s drawWithRect:r options:(NSStringDrawingOptions)0 attributes:attr]; // 10.4
|
||||
[title drawWithRect:r options:(NSStringDrawingOptions)0 attributes:attr]; // 10.4
|
||||
[[NSGraphicsContext currentContext] setShouldAntialias:NO];
|
||||
[NSGraphicsContext setCurrentContext:current];
|
||||
}
|
||||
@ -4529,13 +4529,14 @@ void Fl_Paged_Device::print_window(Fl_Window *win, int x_offset, int y_offset)
|
||||
{
|
||||
fl_font(FL_HELVETICA, 14);
|
||||
fl_color(FL_BLACK);
|
||||
int x = x_offset + win->w()/2 - fl_width(title)/2;
|
||||
int x = x_offset + win->w()/2 - fl_width(win->label())/2;
|
||||
if (x < x_offset+skip) x = x_offset+skip;
|
||||
fl_push_clip(x_offset, y_offset, win->w(), bt);
|
||||
fl_draw(title, x, y_offset+bt/2+4);
|
||||
fl_draw(win->label(), x, y_offset+bt/2+4);
|
||||
fl_pop_clip();
|
||||
}
|
||||
}
|
||||
[title release];
|
||||
this->print_widget(win, x_offset, y_offset + bt); // print the window inner part
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user