OSDN Git Service

If the font is changed, update the minimum window size and force the window to be...
authorEric Branlund <ebranlund@fastmail.com>
Wed, 18 Sep 2019 01:54:36 +0000 (18:54 -0700)
committerEric Branlund <ebranlund@fastmail.com>
Wed, 18 Sep 2019 01:54:36 +0000 (18:54 -0700)
src/main-cocoa.m

index 405affd..04b1af8 100644 (file)
@@ -463,6 +463,9 @@ static int resize_pending_changes(struct PendingChanges* pc, int nrow)
  * defaults */
 - (void)resizeTerminalWithContentRect: (NSRect)contentRect saveToDefaults: (BOOL)saveToDefaults;
 
+/* Change the minimum size for the window associated with the context. */
+- (void)setMinimumWindowSize;
+
 /* Called from the view to indicate that it is starting or ending live resize */
 - (void)viewWillStartLiveResize:(AngbandView *)view;
 - (void)viewDidEndLiveResize:(AngbandView *)view;
@@ -1075,6 +1078,23 @@ static int compare_advances(const void *ap, const void *bp)
         /* Adjust terminal to fit window with new font; save the new columns
                 * and rows since they could be changed */
         NSRect contentRect = [self->primaryWindow contentRectForFrameRect: [self->primaryWindow frame]];
+
+       [self setMinimumWindowSize];
+       NSSize size = self->primaryWindow.contentMinSize;
+       BOOL windowNeedsResizing = NO;
+       if (contentRect.size.width < size.width) {
+           contentRect.size.width = size.width;
+           windowNeedsResizing = YES;
+       }
+       if (contentRect.size.height < size.height) {
+           contentRect.size.height = size.height;
+           windowNeedsResizing = YES;
+       }
+       if (windowNeedsResizing) {
+           size.width = contentRect.size.width;
+           size.height = contentRect.size.height;
+           [self->primaryWindow setContentSize:size];
+       }
         [self resizeTerminalWithContentRect: contentRect saveToDefaults: YES];
     }
 
@@ -1646,6 +1666,24 @@ static NSMenuItem *superitem(NSMenuItem *self)
     Term_activate( old );
 }
 
+- (void)setMinimumWindowSize
+{
+    NSSize minsize;
+
+    if ([self terminalIndex] == 0) {
+       minsize.width = 80;
+       minsize.height = 24;
+    } else {
+       minsize.width = 1;
+       minsize.height = 1;
+    }
+    minsize.width =
+       minsize.width * self->tileSize.width + self->borderSize.width * 2.0;
+    minsize.height =
+        minsize.height * self->tileSize.height + self->borderSize.height * 2.0;
+    [[self makePrimaryWindow] setContentMinSize:minsize];
+}
+
 - (void)saveWindowVisibleToDefaults: (BOOL)windowVisible
 {
        int termIndex = [self terminalIndex];
@@ -1960,43 +1998,16 @@ static void Term_init_cocoa(term *t)
 
     /* Get the window */
     NSWindow *window = [context makePrimaryWindow];
-    NSString *title;
-
     /* Set its title and, for auxiliary terms, tentative size */
-    if (termIdx == 0)
-    {
-       title = [NSString stringWithCString:angband_term_name[0]
+    NSString *title = [NSString stringWithCString:angband_term_name[termIdx]
 #ifdef JP
-                             encoding:NSJapaneseEUCStringEncoding
-#else
-                             encoding:NSMacOSRomanStringEncoding
-#endif
-       ];
-        [window setTitle:title];
-
-        /* Set minimum size (80x24) */
-        NSSize minsize;
-        minsize.width = 80 * context->tileSize.width + context->borderSize.width * 2.0;
-        minsize.height = 24 * context->tileSize.height + context->borderSize.height * 2.0;
-        [window setContentMinSize:minsize];
-    }
-    else
-    {
-       title = [NSString stringWithCString:angband_term_name[termIdx]
-#ifdef JP
-                             encoding:NSJapaneseEUCStringEncoding
+                               encoding:NSJapaneseEUCStringEncoding
 #else
-                             encoding:NSMacOSRomanStringEncoding
+                               encoding:NSMacOSRomanStringEncoding
 #endif
-       ];
-        [window setTitle:title];
-        /* Set minimum size (1x1) */
-        NSSize minsize;
-        minsize.width = context->tileSize.width + context->borderSize.width * 2.0;
-        minsize.height = context->tileSize.height + context->borderSize.height * 2.0;
-        [window setContentMinSize:minsize];
-    }
-    
+    ];
+    [window setTitle:title];
+    [context setMinimumWindowSize];
     
     /* If this is the first term, and we support full screen (Mac OS X Lion or
         * later), then allow it to go full screen (sweet). Allow other terms to be