@@ -934,20 +934,20 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
934934 [self ->handler installCallbacks: actions forButtons: buttons];
935935
936936 NSFont * font = [NSFont systemFontOfSize: 0.0 ];
937- rect.size .width = 300 ;
938- rect.size .height = 0 ;
939- rect.origin .x += height;
940- NSTextView * messagebox = [[NSTextView alloc ] initWithFrame: rect];
937+ // rect.origin.x is now at the far right edge of the buttons
938+ // we want the messagebox to take up the rest of the toolbar area
939+ // Make it a zero-width box if we don't have enough room
940+ rect.size .width = fmax (bounds.size .width - rect.origin .x , 0 );
941+ rect.origin .x = bounds.size .width - rect.size .width ;
942+ NSTextView * messagebox = [[[NSTextView alloc ] initWithFrame: rect] autorelease ];
941943 messagebox.textContainer .maximumNumberOfLines = 2 ;
942944 messagebox.textContainer .lineBreakMode = NSLineBreakByTruncatingTail;
945+ messagebox.alignment = NSTextAlignmentRight;
943946 [messagebox setFont: font];
944947 [messagebox setDrawsBackground: NO ];
945948 [messagebox setSelectable: NO ];
946949 /* if selectable, the messagebox can become first responder,
947950 * which is not supposed to happen */
948- rect = [messagebox frame ];
949- rect.origin .y = 0.5 * (height - rect.size .height );
950- [messagebox setFrameOrigin: rect.origin];
951951 [[window contentView ] addSubview: messagebox];
952952 [messagebox release ];
953953 [[window contentView ] display ];
@@ -974,26 +974,31 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
974974{
975975 const char * message;
976976
977- if (!PyArg_ParseTuple (args, " y " , &message)) { return NULL ; }
977+ if (!PyArg_ParseTuple (args, " s " , &message)) { return NULL ; }
978978
979979 NSTextView * messagebox = self->messagebox ;
980980
981981 if (messagebox) {
982982 NSString * text = [NSString stringWithUTF8String: message];
983983 [messagebox setString: text];
984984
985- // Adjust width with the window size
985+ // Adjust width and height with the window size and content
986986 NSRect rectWindow = [messagebox.superview frame ];
987987 NSRect rect = [messagebox frame ];
988+ // Entire region to the right of the buttons
988989 rect.size .width = rectWindow.size .width - rect.origin .x ;
989990 [messagebox setFrame: rect];
990-
991- // Adjust height with the content size
991+ // We want to control the vertical position of
992+ // the rect by the content size to center it vertically
992993 [messagebox.layoutManager ensureLayoutForTextContainer: messagebox.textContainer];
993- NSRect contentSize = [messagebox.layoutManager usedRectForTextContainer: messagebox.textContainer];
994- rect = [messagebox frame ] ;
995- rect.origin . y = 0.5 * (self-> height - contentSize. size .height ) ;
994+ NSRect contentRect = [messagebox.layoutManager usedRectForTextContainer: messagebox.textContainer];
995+ rect. origin . y = 0.5 * (self-> height - contentRect. size . height ) ;
996+ rect.size . height = contentRect. size .height ;
996997 [messagebox setFrame: rect];
998+ // Disable cursorRects so that the cursor doesn't get updated by events
999+ // in NSApp (like resizing TextViews), we want to handle the cursor
1000+ // changes from within MPL with set_cursor() ourselves
1001+ [[messagebox.superview window ] disableCursorRects ];
9971002 }
9981003
9991004 Py_RETURN_NONE;
0 commit comments