Index: FL/Fl_Sys_Menu_Bar.H
===================================================================
--- FL/Fl_Sys_Menu_Bar.H	(revision 12570)
+++ FL/Fl_Sys_Menu_Bar.H	(working copy)
@@ -3,7 +3,7 @@
 //
 // MacOS system menu bar header file for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 1998-2010 by Bill Spitzak and others.
+// Copyright 1998-2017 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -21,7 +21,6 @@
 
 #include <FL/Fl_Menu_Bar.H>
 
-#if defined(__APPLE__) || defined(FL_DOXYGEN)
 
 /**
   A class to create, modify and delete menus that appear on Mac OS X in the menu bar at the top of the screen.
@@ -31,6 +30,17 @@
  a system menu at the top of the screen will be available. This menu will match an array
  of Fl_Menu_Item's exactly as with standard FLTK menus.
  
+ On the MacOS platform, the system menu bar of any FLTK app begins with the Application menu which the FLTK library
+ automatically constructs. Functions Fl_Mac_App_Menu::custom_application_menu_items() and
+ fl_mac_set_about() can be used to further customize
+ the Application menu. The FLTK library also constructs and handles a Window menu which can be
+ further customized (or even removed) calling
+ Fl_Sys_Menu_Bar::window_menu_style(window_menu_style_enum style).
+ Finally, a Help menu can be generated calling Fl_Sys_Menu_Bar::help_items().
+ Other member functions of this class allow the app to generate the rest of the system menu bar.
+ It is recommended to localize the system menu bar using the standard Mac OS X localization procedure
+ (see \ref osissues_localize).
+ 
  Changes to the menu state are immediately visible in the menubar when they are made
  using member functions of the Fl_Sys_Menu_Bar class. Other changes (e.g., by a call to
  Fl_Menu_Item::set()) should be followed by a call to update() to be
@@ -40,16 +50,34 @@
   \li no symbolic labels
   \li no embossed labels
   \li no font sizes
- 
-  You can configure a callback for the 'About' menu item to invoke your own code with fl_mac_set_about().
- */
+  */
 class FL_EXPORT Fl_Sys_Menu_Bar : public Fl_Menu_Bar {
+  //
+  // platform-independent part
+  //
+public:
+  /** Possible styles of the Window menu in the system menu bar */
+  typedef enum {
+    no_window_menu = 0,     ///< No Window menu in the system menu bar
+    tabbing_mode_none,      ///< No tabbed windows, but the system menu bar contains a Window menu
+    tabbing_mode_automatic, ///< Windows are created by themselves but can be tabbed later
+    tabbing_mode_preferred, ///< Windows are tabbed when created
+    tabbing_mode_by_class   ///< Add a "Merge Windows by Class" menu item
+  } window_menu_style_enum;
+  //
+  // MacOS-specific part
+  //
+#if defined(__APPLE__) || defined(FL_DOXYGEN)
+
+private:
+  static const Fl_Menu_Item *help_items_;
+  static window_menu_style_enum window_menu_style_;
 protected:
   void draw();
 public:
   Fl_Sys_Menu_Bar(int x,int y,int w,int h,const char *l=0);
   ~Fl_Sys_Menu_Bar();
-  /** Return the system menu's array of Fl_Menu_Item's 
+  /** Return the system menu's array of Fl_Menu_Item's
    */
   const Fl_Menu_Item *menu() const {return Fl_Menu_::menu();}
   void menu(const Fl_Menu_Item *m);
@@ -96,14 +124,56 @@
   void shortcut (int i, int s) { Fl_Menu_::shortcut(i, s); update(); }
   /** Turns the radio item "on" for the menu item and turns "off" adjacent radio items of the same group.*/
   void setonly (Fl_Menu_Item *item) { Fl_Menu_::setonly(item); update(); }
-};
+  static void create_window_menu();
+#if !defined(FL_DOXYGEN)
+  int find_first_window();
+  void new_window(Fl_Window *win);
+  void remove_window(Fl_Window *win);
+  void rename_window(Fl_Window *win);
+  static void compute_window_menu_state();
+#endif
+  /** Set this to a zero-ending array of Fl_Menu_Item 's to obtain a Help menu in the system menu bar.
+   The Help menu will be created last in the system menu bar, after the Window menu.
+   Under non MacOS platforms, this function does nothing.
+   \version 1.4
+   */
+  static void help_items(const Fl_Menu_Item *items) {help_items_ = items;}
+  /** Get the style of the Window menu in the system menu bar */
+  static window_menu_style_enum window_menu_style() { return window_menu_style_; }
+  /** Set the desired style of the Window menu in the system menu bar.
+  This function allows to control whether the system menu bar should contain a Window menu,
+  and if yes, whether new windows should be displayed in tabbed form. These are
+   the effects of various values for \p style :
+   
+  \li \c  no_window_menu : don't add a Window menu to the system menu bar
+   \li \c tabbing_mode_none :   add a simple Window menu to the system menu bar
+  \li \c  tabbing_mode_automatic : the window menu also contains "Merge All Windows" to group
+   all windows in a single tabbed display mode. This is the \b default Window menu style
+   for FLTK apps.
+  \li \c tabbing_mode_preferred : new windows are displayed in tabbed mode when first created
+  \li \c  tabbing_mode_by_class : the "Merge All Windows" Window menu item is replaced by "Merge Windows by Class".
+   This is useful if the app handles windows of distinct nature: windows
+   of the same class according to Fl_Window::xclass() are merged and displayed in tabbed form.
+   
+   The Window menu, if present, is entirely created and controlled by the FLTK library.
+   Mac OS version 10.12 or later must be running for windows to be displayed in tabbed form.
+   Under non MacOS platforms, this function does nothing.
+   \version 1.4
+   */
+  static void window_menu_style(window_menu_style_enum style) { window_menu_style_ = style; }
 
 #else
+  Fl_Sys_Menu_Bar(int x,int y,int w,int h,const char *l=0) : Fl_Menu_Bar(x, y, w, h, l) {}
 
-typedef Fl_Menu_Bar Fl_Sys_Menu_Bar;
+  static void create_window_menu() {}
+  static void help_items(const Fl_Menu_Item *items) {}
+  static window_menu_style_enum window_menu_style() {return no_window_menu;}
+  static void window_menu_style(window_menu_style_enum style) {}
 
 #endif // defined(__APPLE__) || defined(FL_DOXYGEN)
 
+};
+
 #endif // Fl_Sys_Menu_Bar_H
 
 //
Index: src/Fl_Sys_Menu_Bar.mm
===================================================================
--- src/Fl_Sys_Menu_Bar.mm	(revision 12572)
+++ src/Fl_Sys_Menu_Bar.mm	(working copy)
@@ -3,7 +3,7 @@
 //
 // MacOS system menu bar widget for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 1998-2013 by Bill Spitzak and others.
+// Copyright 1998-2017 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -542,6 +542,242 @@
     [item release];
   }
 }
+
+static void minimize_win_cb(Fl_Widget *, void *data)
+{
+  [[NSApp mainWindow] miniaturize:nil];
+}
+
+static void window_menu_cb(Fl_Widget *, void *data)
+{
+  if (data) ((Fl_Window*)data)->show();
+}
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
+
+static void previous_tab_cb(Fl_Widget *, void *data)
+{
+  [[NSApp mainWindow] selectPreviousTab:nil];
+}
+
+static void next_tab_cb(Fl_Widget *, void *data)
+{
+  [[NSApp mainWindow] selectNextTab:nil];
+}
+
+static void move_tab_cb(Fl_Widget *, void *data)
+{
+  [[NSApp mainWindow] moveTabToNewWindow:nil];
+  Fl_Sys_Menu_Bar::compute_window_menu_state();
+}
+
+static void merge_all_windows_cb(Fl_Widget *, void *)
+{
+  Fl_Window *first = Fl::first_window();
+  if (first) {
+    [(NSWindow*)fl_xid(first) mergeAllWindows:nil];
+    Fl_Sys_Menu_Bar::compute_window_menu_state();
+  }
+}
+
+static bool merge_windows_for_class(Fl_Window *first)
+{
+  bool retval = false;
+  Fl_Window *win = first;
+  NSWindow *nsw = (NSWindow*)fl_xid(first), *nsw2;
+  while ((win = Fl::next_window(win)) != NULL) {
+    int diff = strcmp(win->xclass(), first->xclass());
+    if (win->parent() || diff) continue;
+    nsw2 = (NSWindow*)fl_xid(win);
+    [nsw2 addTabbedWindow:nsw ordered:NSWindowAbove];
+    retval = true;
+  }
+  return retval;
+}
+
+static void merge_windows_by_class_cb(Fl_Widget *, void *)
+{
+encore:
+  Fl_Window *win = Fl::first_window();
+  NSWindow *nsw;
+  while (win) {
+    nsw = (NSWindow*)fl_xid(win);
+    if (!win->parent() && ![nsw tabbedWindows] && strcmp(win->xclass(), Fl_Window::default_xclass())) {
+      if (merge_windows_for_class(win)) goto encore;
+    }
+    win = Fl::next_window(win);
+  }
+  Fl_Sys_Menu_Bar::compute_window_menu_state();
+}
+#endif
+
+static bool window_menu_installed = false;
+
+/** Adds a Window menu, and optionally a Help menu, to the end of the system menu bar.
+ The default system menu bar contains a Window menu with a "Merge All Windows" item and no Help menu.
+ Call previously Fl_Sys_Menu_Bar::window_menu_style(window_menu_style_enum) and/or
+ Fl_Sys_Menu_Bar::help_items(const Fl_Menu_Item *) to get other Window and Help menu styles.
+ Function create_window_menu() is automatically called the first time a window is shown.
+ Alternatively, an app can call it after having populated the system menu bar,
+ for example with menu(const Fl_Menu_Item *), and before the first Fl_Window::show().
+ This function does nothing on non MacOS platforms.
+ \version 1.4
+*/
+void Fl_Sys_Menu_Bar::create_window_menu(void)
+{
+  if (window_menu_style() == no_window_menu) return;
+  if (window_menu_installed) return;
+  window_menu_installed = true;
+  int rank = 0;
+  if (fl_sys_menu_bar && fl_sys_menu_bar->menu()) {
+    if (fl_sys_menu_bar->find_index("Window") >= 0) { // there's already a "Window" menu -> don't create another
+      window_menu_style_ = no_window_menu;
+      return;
+    }
+    const Fl_Menu_Item *item = fl_sys_menu_bar->menu(), *item2;
+    while (true) {
+      item2 = item->next();
+      if (!item2->label() || strcmp(item2->label(), "Help") == 0) break;
+      item = item2;
+    }
+    rank = fl_sys_menu_bar->find_index(item2);
+  } else {
+    new Fl_Sys_Menu_Bar(0,0,0,0);
+  }
+  rank = fl_sys_menu_bar->insert(rank, "Window", 0, window_menu_cb, 0, FL_SUBMENU);
+  fl_sys_menu_bar->insert(rank+1, "", 0, NULL, 0, 0);
+  ((Fl_Menu_Item*)(fl_sys_menu_bar->menu() + rank+1))->label(NULL);
+  fl_sys_menu_bar->insert(++rank, "Minimize", FL_COMMAND+'m', minimize_win_cb, 0, FL_MENU_DIVIDER);
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
+  if (fl_mac_os_version >= 101200 && window_menu_style() != tabbing_mode_none) {
+    fl_sys_menu_bar->insert(++rank, "Show Previous Tab", FL_SHIFT+FL_CTRL+0x9, previous_tab_cb, 0, FL_MENU_INACTIVE);
+    fl_sys_menu_bar->insert(++rank, "Show Next Tab", FL_CTRL+0x9, next_tab_cb, 0, FL_MENU_INACTIVE);
+    fl_sys_menu_bar->insert(++rank, "Move Tab To New Window", 0, move_tab_cb, 0, FL_MENU_INACTIVE);
+    if (window_menu_style() == tabbing_mode_by_class)
+      fl_sys_menu_bar->insert(++rank, "Merge Windows by Class", 0, merge_windows_by_class_cb, 0, FL_MENU_INACTIVE | FL_MENU_DIVIDER);
+    else
+      fl_sys_menu_bar->insert(++rank, "Merge All Windows", 0, merge_all_windows_cb, 0, FL_MENU_INACTIVE | FL_MENU_DIVIDER);
+  }
+#endif
+  Fl_Menu_Item *item = (Fl_Menu_Item*)(fl_sys_menu_bar->menu()+rank);
+  item->user_data(&window_menu_style_);
+  if (help_items_ && fl_sys_menu_bar->find_index("Help") < 0) {
+    fl_sys_menu_bar->insert(rank+2, "Help", 0, NULL, (void*)help_items_, FL_SUBMENU_POINTER);
+  }
+}
+
+#if !defined(FL_DOXYGEN)
+
+// returns the index of the menu item just before the first window name
+int Fl_Sys_Menu_Bar::find_first_window()
+{
+  int count = size(), i;
+  for (i = 0; i < count; i++) {
+    if (menu()[i].user_data() == &window_menu_style_) break;
+  }
+  return i < count ? i : -1;
+}
+
+void Fl_Sys_Menu_Bar::new_window(Fl_Window *win)
+{
+  if (!window_menu_style() || !win->label()) return;
+  int index = find_first_window();
+  if (index < 0) return;
+  while ((menu()+index+1)->label()) index++;
+  int index2 = insert(index+1, win->iconlabel() ? win->iconlabel() : win->label(), 0, window_menu_cb, win, FL_MENU_RADIO);
+  setonly((Fl_Menu_Item*)menu()+index2);
+  compute_window_menu_state();
+}
+
+void Fl_Sys_Menu_Bar::remove_window(Fl_Window *win)
+{
+  if (!window_menu_style()) return;
+  int index = find_first_window() + 1;
+  if (index < 1) return;
+  while (true) {
+    Fl_Menu_Item *item = (Fl_Menu_Item*)menu() + index;
+    if (!item->label()) return;
+    if (item->user_data() == win) {
+      bool doit = item->value();
+      remove(index);
+      if (doit) {
+        item = (Fl_Menu_Item*)menu() + find_first_window() + 1;
+        if (item->label()) {
+          ((Fl_Window*)item->user_data())->show();
+          setonly(item);
+        }
+      }
+      return;
+    }
+    index++;
+  }
+  compute_window_menu_state();
+}
+
+void Fl_Sys_Menu_Bar::rename_window(Fl_Window *win)
+{
+  if (!window_menu_style()) return;
+  int index = find_first_window() + 1;
+  if (index < 1) return;
+  while (true) {
+    Fl_Menu_Item *item = (Fl_Menu_Item*)menu() + index;
+    if (!item->label()) return;
+    if (item->user_data() == win) {
+      replace(index, win->iconlabel() ? win->iconlabel() : win->label());
+      return;
+    }
+    index++;
+  }
+}
+
+void Fl_Sys_Menu_Bar::compute_window_menu_state() {
+  if (!window_menu_installed || fl_mac_os_version < 101200 || !fl_sys_menu_bar || !window_menu_style() ||
+      window_menu_style() == tabbing_mode_none) return;
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
+  // computes active/inactive state of the Window menu items
+  // according to presence/absence of tabbed and tabbable windows
+  const int index = fl_sys_menu_bar->find_first_window(); // The "Merge All Windows" item
+  if (index < 0) return;
+
+  // is the current window tabbed?
+  Fl_Window *win = Fl::first_window();
+  NSWindow *main = win ? (NSWindow*)fl_xid(win) : nil;
+  if ([main tabbedWindows]) {
+    ((Fl_Menu_Item*)(fl_sys_menu_bar->menu() + index-1))->activate();
+    ((Fl_Menu_Item*)(fl_sys_menu_bar->menu() + index-2))->activate();
+    ((Fl_Menu_Item*)(fl_sys_menu_bar->menu() + index-3))->activate();
+ }
+  else {
+    ((Fl_Menu_Item*)(fl_sys_menu_bar->menu() + index-1))->deactivate();
+    ((Fl_Menu_Item*)(fl_sys_menu_bar->menu() + index-2))->deactivate();
+    ((Fl_Menu_Item*)(fl_sys_menu_bar->menu() + index-3))->deactivate();
+  }
+  // is there any untabbed, tabbable window?
+  const Fl_Menu_Item *item = fl_sys_menu_bar->menu() + index + 1;
+  int total = 0, untabbed = 0;
+  while (item->label()) {
+    total++;
+    NSWindow *nsw = (NSWindow*)fl_xid( (Fl_Window*)item->user_data() );
+    if (![nsw tabbedWindows] && [nsw tabbingMode] != NSWindowTabbingModeDisallowed) {
+      untabbed++;
+    }
+    item++;
+  }
+  if (untabbed > 0 && total >= 2)
+    ((Fl_Menu_Item*)(fl_sys_menu_bar->menu() + index))->activate();
+  else
+    ((Fl_Menu_Item*)(fl_sys_menu_bar->menu() + index))->deactivate();
+
+  fl_sys_menu_bar->update();
+#endif
+}
+
+#endif // FL_DOXYGEN
+
+const Fl_Menu_Item *Fl_Sys_Menu_Bar::help_items_ = NULL;
+
+Fl_Sys_Menu_Bar::window_menu_style_enum Fl_Sys_Menu_Bar::window_menu_style_ = tabbing_mode_automatic;
+
 #endif /* __APPLE__ */ // PORTME: Fl_Screen_Driver - platform system menu bar
 
 //
Index: src/Fl_cocoa.mm
===================================================================
--- src/Fl_cocoa.mm	(revision 12570)
+++ src/Fl_cocoa.mm	(working copy)
@@ -58,6 +58,7 @@
 #include <limits.h>
 #include <dlfcn.h>
 #include <string.h>
+#include <FL/Fl_Sys_Menu_Bar.H>
 
 #import <Cocoa/Cocoa.h>
 
@@ -828,8 +829,8 @@
   }
   
   fl_unlock_function();
-  NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask 
-                                      untilDate:[NSDate dateWithTimeIntervalSinceNow:time] 
+  NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask
+                                      untilDate:[NSDate dateWithTimeIntervalSinceNow:time]
                                          inMode:NSDefaultRunLoopMode dequeue:YES];  
   if (event != nil) {
     got_events = 1;
@@ -1302,9 +1303,14 @@
 }
 - (void)windowDidMove:(NSNotification *)notif
 {
-  fl_lock_function();
   FLWindow *nsw = (FLWindow*)[notif object];
   Fl_Window *window = [nsw getFl_Window];
+  if ([[nsw contentView] frame].size.height != window->h()) {
+    // the contentView, but not the window frame, is resized. This happens with tabbed windows.
+    [self windowDidResize:notif];
+    return;
+  }
+  fl_lock_function();
   resize_from_system = window;
   NSPoint pt2;
   pt2 = [nsw convertBaseToScreen:NSMakePoint(0, [[nsw contentView] frame].size.height)];
@@ -1390,6 +1396,20 @@
   Fl_Window *window = [nsw getFl_Window];
   Fl::first_window(window);
   update_e_xy_and_e_xy_root(nsw);
+  if (fl_sys_menu_bar && Fl_Sys_Menu_Bar::window_menu_style()) {
+    // select the corresponding Window menu item
+    int index = fl_sys_menu_bar->find_first_window() + 1;
+    while (index > 0) {
+      Fl_Menu_Item *item = (Fl_Menu_Item*)fl_sys_menu_bar->menu() + index;
+      if (!item->label()) break;
+      if (item->user_data() == window) {
+        fl_sys_menu_bar->setonly(item);
+        Fl_Sys_Menu_Bar::compute_window_menu_state();
+        break;
+      }
+      index++;
+    }
+  }
   fl_unlock_function();
 }
 - (void)windowDidDeminiaturize:(NSNotification *)notif
@@ -1856,7 +1876,13 @@
 
 
 // Gets the border sizes and the titlebar size
-static void get_window_frame_sizes(int &bx, int &by, int &bt) {
+static void get_window_frame_sizes(int &bx, int &by, int &bt, Fl_Window *win) {
+  FLWindow *flw = fl_xid(win);
+  if (flw) {
+    bt = [flw frame].size.height - [[flw contentView] frame].size.height;
+    bx = by = 0;
+    return;
+  }
   static int top = 0, left, bottom;
   if (!top) {
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@@ -1940,7 +1966,7 @@
     } else {
       ret = 1;
     }
-    get_window_frame_sizes(bx, by, bt);
+    get_window_frame_sizes(bx, by, bt, w);
   }
   // The coordinates of the whole window, including non-client area
   xoff = bx;
@@ -2260,6 +2286,7 @@
 /*
  * Gets called when a window is created or resized, or moved between retina and non-retina displays
  * (with Mac OS ≥ 10.11 also when deminiaturized)
+ * (with Mac OS ≥ 10.12 also when window is tabbed/untabbed)
  */
 - (void)drawRect:(NSRect)rect
 {
@@ -2266,6 +2293,9 @@
   fl_lock_function();
   FLWindow *cw = (FLWindow*)[self window];
   Fl_Window *window = [cw getFl_Window];
+  if (!window->parent() && rect.size.height != window->h() ) { // this happens with tabbed window
+    window->resize([cw frame].origin.x, main_screen_height - ([cw frame].origin.y + rect.size.height), rect.size.width, rect.size.height);
+  }
   through_drawRect = YES;
   Fl_Cocoa_Window_Driver *d = Fl_Cocoa_Window_Driver::driver(window);
   if (fl_mac_os_version >= 100700) { // determine whether window is mapped to a retina display
@@ -2907,6 +2937,8 @@
   fl_open_display();
   NSInteger winlevel = NSNormalWindowLevel;
   NSUInteger winstyle;
+  
+  Fl_Sys_Menu_Bar::create_window_menu(); // effective once at most
   Fl_Window* w = pWindow;
   if (w->parent()) {
     w->border(0);
@@ -3016,6 +3048,17 @@
                                     contentRect:crect
                                       styleMask:winstyle];
   [cw setFrameOrigin:crect.origin];
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
+  if (fl_mac_os_version >= 101200) {
+    if (!w->parent() && (winstyle & NSTitledWindowMask) && (winstyle & NSResizableWindowMask)
+        && !w->modal() && !w->non_modal() && Fl_Sys_Menu_Bar::window_menu_style() > Fl_Sys_Menu_Bar::tabbing_mode_none) {
+      if (Fl_Sys_Menu_Bar::window_menu_style() == Fl_Sys_Menu_Bar::tabbing_mode_preferred) [cw setTabbingMode:NSWindowTabbingModePreferred];
+      else [cw setTabbingMode:NSWindowTabbingModeAutomatic];
+    } else {
+      [cw setTabbingMode:NSWindowTabbingModeDisallowed];
+    }
+  }
+#endif
   if (!w->parent()) {
     [cw setHasShadow:YES];
     [cw setAcceptsMouseMovedEvents:YES];
@@ -3092,7 +3135,10 @@
   } else { // a top-level window
     [cw makeKeyAndOrderFront:nil];
   }
-  
+  if (fl_sys_menu_bar && Fl_Sys_Menu_Bar::window_menu_style() && !w->parent() && w->border() && !w->modal() && !w->non_modal()) {
+    fl_sys_menu_bar->new_window(w);
+  }
+
   int old_event = Fl::e_number;
   w->handle(Fl::e_number = FL_SHOW);
   Fl::e_number = old_event;
@@ -3108,7 +3154,7 @@
  */
 void Fl_Cocoa_Window_Driver::size_range() {
   int bx, by, bt;
-  get_window_frame_sizes(bx, by, bt);
+  get_window_frame_sizes(bx, by, bt, pWindow);
   Fl_Window_Driver::size_range();
   NSSize minSize = NSMakeSize(minw(), minh() + bt);
   NSSize maxSize = NSMakeSize(maxw() ? maxw():32000, maxh() ? maxh() + bt:32000);
@@ -3159,6 +3205,7 @@
 void Fl_Cocoa_Window_Driver::label(const char *name, const char *mininame) {
   if (shown() || Fl_X::i(pWindow)) {
     q_set_window_title(fl_xid(pWindow), name, mininame);
+    if (fl_sys_menu_bar && Fl_Sys_Menu_Bar::window_menu_style()) fl_sys_menu_bar->rename_window(pWindow);
   }
 }
 
@@ -3217,7 +3264,7 @@
       }
       pWindow->Fl_Group::resize(X,Y,W,H);
       // transmit changes in FLTK coords to cocoa
-      get_window_frame_sizes(bx, by, bt);
+      get_window_frame_sizes(bx, by, bt, pWindow);
       bx = X; by = Y;
       parent = pWindow->window();
       while (parent) {
@@ -3250,6 +3297,8 @@
       x(X); y(Y);
     }
   }
+  // useful when a tabbed window is manually dragged away to become a stand-alone window
+  Fl_Sys_Menu_Bar::compute_window_menu_state();
 }
 
 
@@ -3535,6 +3584,7 @@
 }
 
 void Fl_Cocoa_Window_Driver::destroy(FLWindow *xid) {
+  if (fl_sys_menu_bar && Fl_Sys_Menu_Bar::window_menu_style()) fl_sys_menu_bar->remove_window([xid getFl_Window]);
   [xid close];
 }
 
@@ -4273,7 +4323,7 @@
   if (!shown() || parent() || !border() || !visible())
     return w();
   int bx, by, bt;
-  get_window_frame_sizes(bx, by, bt);
+  get_window_frame_sizes(bx, by, bt, pWindow);
   return w() + 2 * bx;
 }
 
@@ -4282,7 +4332,7 @@
   if (!shown() || parent() || !border() || !visible())
     return h();
   int bx, by, bt;
-  get_window_frame_sizes(bx, by, bt);
+  get_window_frame_sizes(bx, by, bt, pWindow);
   return h() + bt + by;
 }
 
Index: test/utf8.cxx
===================================================================
--- test/utf8.cxx	(revision 12570)
+++ test/utf8.cxx	(working copy)
@@ -30,6 +30,7 @@
 #include <FL/Fl_Output.H>
 #include <FL/fl_draw.H>
 #include <FL/fl_utf8.h>
+#include <FL/Fl_Sys_Menu_Bar.H>
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -352,7 +353,7 @@
         textgroup->end();
       }  
       Fl_Group *fontgroup = new Fl_Group(0, 105, 380, 315);
-      {        
+      {
         fontobj = new Fl_Hold_Browser(10, 110, 290, 270);
         fontobj->box(FL_FRAME_BOX);
         fontobj->color(53, 3);
@@ -701,6 +702,15 @@
 
   fl_set_status(0, 370, 100, 30);
   
+  Fl_Sys_Menu_Bar::window_menu_style(Fl_Sys_Menu_Bar::tabbing_mode_preferred);
+  //Fl_Sys_Menu_Bar::window_menu_style(Fl_Sys_Menu_Bar::tabbing_mode_none);
+  //Fl_Sys_Menu_Bar::window_menu_style(Fl_Sys_Menu_Bar::no_window_menu);
+  /*static Fl_Menu_Item help[] = {
+    {"do something",0,0,0,0},
+    {0}
+  };
+  Fl_Sys_Menu_Bar::help_items(help);*/
+  
   main_win->show(argc,argv);
 
   fnt_chooser_win->show();
