@@ -931,8 +931,9 @@ - (void)save_figure:(id)sender;
931
931
typedef struct {
932
932
PyObject_HEAD
933
933
NSPopUpButton * menu;
934
- NSText * messagebox;
934
+ NSTextView * messagebox;
935
935
NavigationToolbar2Handler* handler;
936
+ int height;
936
937
} NavigationToolbar2;
937
938
938
939
@implementation NavigationToolbar2Handler
@@ -1139,7 +1140,9 @@ -(void)save_figure:(id)sender
1139
1140
const float gap = 2 ;
1140
1141
const int height = 36 ;
1141
1142
const int imagesize = 24 ;
1142
-
1143
+
1144
+ self->height = height;
1145
+
1143
1146
const char * basedir;
1144
1147
1145
1148
obj = PyObject_GetAttrString ((PyObject*)self, " canvas" );
@@ -1252,7 +1255,9 @@ -(void)save_figure:(id)sender
1252
1255
rect.size .width = 300 ;
1253
1256
rect.size .height = 0 ;
1254
1257
rect.origin .x += height;
1255
- NSText * messagebox = [[NSText alloc ] initWithFrame: rect];
1258
+ NSTextView * messagebox = [[NSTextView alloc ] initWithFrame: rect];
1259
+ messagebox.textContainer .maximumNumberOfLines = 2 ;
1260
+ messagebox.textContainer .lineBreakMode = NSLineBreakByTruncatingTail;
1256
1261
[messagebox setFont: font];
1257
1262
[messagebox setDrawsBackground: NO ];
1258
1263
[messagebox setSelectable: NO ];
@@ -1294,12 +1299,26 @@ -(void)save_figure:(id)sender
1294
1299
1295
1300
if (!PyArg_ParseTuple (args, " y" , &message)) return NULL ;
1296
1301
1297
- NSText * messagebox = self->messagebox ;
1302
+ NSTextView * messagebox = self->messagebox ;
1298
1303
1299
1304
if (messagebox)
1300
1305
{ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc ] init ];
1301
1306
NSString * text = [NSString stringWithUTF8String: message];
1302
1307
[messagebox setString: text];
1308
+
1309
+ // Adjust width with the window size
1310
+ NSRect rectWindow = [messagebox.superview frame ];
1311
+ NSRect rect = [messagebox frame ];
1312
+ rect.size .width = rectWindow.size .width - rect.origin .x ;
1313
+ [messagebox setFrame: rect];
1314
+
1315
+ // Adjust height with the content size
1316
+ [messagebox.layoutManager ensureLayoutForTextContainer: messagebox.textContainer];
1317
+ NSRect contentSize = [messagebox.layoutManager usedRectForTextContainer: messagebox.textContainer];
1318
+ rect = [messagebox frame ];
1319
+ rect.origin .y = 0.5 * (self->height - contentSize.size .height );
1320
+ [messagebox setFrame: rect];
1321
+
1303
1322
[pool release ];
1304
1323
}
1305
1324
0 commit comments