@@ -934,20 +934,19 @@ -(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+ rect.size .width = bounds.size .width - rect.origin .x ;
940+ rect.origin .x = bounds.size .width - rect.size .width ;
941+ NSTextView * messagebox = [[[NSTextView alloc ] initWithFrame: rect] autorelease ];
941942 messagebox.textContainer .maximumNumberOfLines = 2 ;
942943 messagebox.textContainer .lineBreakMode = NSLineBreakByTruncatingTail;
944+ messagebox.alignment = NSTextAlignmentRight;
943945 [messagebox setFont: font];
944946 [messagebox setDrawsBackground: NO ];
945947 [messagebox setSelectable: NO ];
946948 /* if selectable, the messagebox can become first responder,
947949 * 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];
951950 [[window contentView ] addSubview: messagebox];
952951 [messagebox release ];
953952 [[window contentView ] display ];
@@ -974,25 +973,29 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
974973{
975974 const char * message;
976975
977- if (!PyArg_ParseTuple (args, " y " , &message)) { return NULL ; }
976+ if (!PyArg_ParseTuple (args, " s " , &message)) { return NULL ; }
978977
979978 NSTextView * messagebox = self->messagebox ;
980979
981980 if (messagebox) {
982981 NSString * text = [NSString stringWithUTF8String: message];
983982 [messagebox setString: text];
984983
985- // Adjust width with the window size
984+ // Adjust width and height with the window size and content
986985 NSRect rectWindow = [messagebox.superview frame ];
987986 NSRect rect = [messagebox frame ];
987+ // Entire region to the right of the buttons
988988 rect.size .width = rectWindow.size .width - rect.origin .x ;
989989 [messagebox setFrame: rect];
990-
991- // Adjust height with the content size
990+ // We want to control the vertical position of
991+ // the rect by the content size to center it vertically
992+ // TODO: This seems to disable the cursor updates with newlines that
993+ // are included in the image hover text. It is only when trying
994+ // to set the frame height based on the contentRect's size.
992995 [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 ) ;
996+ NSRect contentRect = [messagebox.layoutManager usedRectForTextContainer: messagebox.textContainer];
997+ rect. origin . y = 0.5 * (self-> height - contentRect. size . height ) ;
998+ rect.size . height = contentRect. size .height ;
996999 [messagebox setFrame: rect];
9971000 }
9981001
0 commit comments