@@ -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,7 @@ -(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];
1256
1259
[messagebox setFont: font];
1257
1260
[messagebox setDrawsBackground: NO ];
1258
1261
[messagebox setSelectable: NO ];
@@ -1294,12 +1297,26 @@ -(void)save_figure:(id)sender
1294
1297
1295
1298
if (!PyArg_ParseTuple (args, " y" , &message)) return NULL ;
1296
1299
1297
- NSText * messagebox = self->messagebox ;
1300
+ NSTextView * messagebox = self->messagebox ;
1298
1301
1299
1302
if (messagebox)
1300
1303
{ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc ] init ];
1301
1304
NSString * text = [NSString stringWithUTF8String: message];
1302
1305
[messagebox setString: text];
1306
+
1307
+ // Adjust width with the window size
1308
+ NSRect window_rect = [messagebox.superview frame ];
1309
+ NSRect rect = [messagebox frame ];
1310
+ rect.size .width = window_rect.size .width - rect.origin .x ;
1311
+ [messagebox setFrame: rect];
1312
+
1313
+ // Adjust height with the content size
1314
+ [messagebox.layoutManager ensureLayoutForTextContainer: messagebox.textContainer];
1315
+ NSRect contentSize = [messagebox.layoutManager usedRectForTextContainer: messagebox.textContainer];
1316
+ rect = [messagebox frame ];
1317
+ rect.origin .y = 0.5 * (self->height - contentSize.size .height );
1318
+ [messagebox setFrame: rect];
1319
+
1303
1320
[pool release ];
1304
1321
}
1305
1322
0 commit comments