コード例 #1
0
  public MacMainFrameDecorator(@NotNull final IdeFrameImpl frame, final boolean navBar) {
    myFrame = frame;

    final ID window = MacUtil.findWindowForTitle(frame.getTitle());
    if (window == null) return;

    if (CURRENT_SETTER == null) {
      CURRENT_SETTER = navBar ? NAVBAR_SETTER : TOOLBAR_SETTER;
      CURRENT_GETTER = navBar ? NAVBAR_GETTER : TOOLBAR_GETTER;
      SHOWN = CURRENT_GETTER.fun(null);
    }

    UISettings.getInstance().addUISettingsListener(this, this);

    final ID pool = invoke("NSAutoreleasePool", "new");

    int v = UNIQUE_COUNTER.incrementAndGet();
    if (Patches.APPLE_BUG_ID_10514018) {
      frame.addWindowListener(
          new WindowAdapter() {
            @Override
            public void windowDeiconified(WindowEvent e) {
              if (e.getWindow() == frame && frame.getState() == Frame.ICONIFIED) {
                frame.setState(Frame.NORMAL);
              }
            }
          });
    }
    try {
      if (SystemInfo.isMacOSLion) {
        if (!FULL_SCREEN_AVAILABLE) return;

        FullScreenUtilities.addFullScreenListenerTo(
            frame,
            new FullScreenAdapter() {
              @Override
              public void windowEnteredFullScreen(AppEvent.FullScreenEvent event) {
                myInFullScreen = true;

                JRootPane rootPane = frame.getRootPane();
                if (rootPane != null) rootPane.putClientProperty(FULL_SCREEN, Boolean.TRUE);
                if (Patches.APPLE_BUG_ID_10207064) {
                  // fix problem with bottom empty bar
                  // it seems like the title is still visible in fullscreen but the window itself
                  // shifted up for titlebar height
                  // and the size of the frame is still calculated to be the height of the screen
                  // which is wrong
                  // so just add these titlebar height to the frame height once again
                  Timer timer =
                      new Timer(
                          300,
                          new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                              SwingUtilities.invokeLater(
                                  new Runnable() {
                                    @Override
                                    public void run() {
                                      frame.setSize(
                                          frame.getWidth(),
                                          frame.getHeight() + frame.getInsets().top);
                                    }
                                  });
                            }
                          });
                  timer.setRepeats(false);
                  timer.start();
                }
              }

              @Override
              public void windowExitedFullScreen(AppEvent.FullScreenEvent event) {
                myInFullScreen = false;
                frame.storeFullScreenStateIfNeeded(false);

                JRootPane rootPane = frame.getRootPane();
                if (rootPane != null) rootPane.putClientProperty(FULL_SCREEN, null);
              }
            });
      } else {
        // toggle toolbar
        String className = "IdeaToolbar" + v;
        final ID ownToolbar =
            Foundation.allocateObjcClassPair(Foundation.getObjcClass("NSToolbar"), className);
        Foundation.registerObjcClassPair(ownToolbar);

        ID toolbar =
            invoke(
                invoke(className, "alloc"), "initWithIdentifier:", Foundation.nsString(className));
        Foundation.cfRetain(toolbar);

        invoke(toolbar, "setVisible:", 0); // hide native toolbar by default

        Foundation.addMethod(
            ownToolbar, Foundation.createSelector("setVisible:"), SET_VISIBLE_CALLBACK, "v*");
        Foundation.addMethod(ownToolbar, Foundation.createSelector("isVisible"), IS_VISIBLE, "B*");

        invoke(window, "setToolbar:", toolbar);
        invoke(window, "setShowsToolbarButton:", 1);
      }
    } finally {
      invoke(pool, "release");
    }
  }