From 9bc66277898b76c36ef651cfa347d3dc6d4a028c Mon Sep 17 00:00:00 2001 From: graann Date: Fri, 12 Jul 2019 14:46:45 +0300 Subject: [PATCH] Borderless UI: Use TitlePane.background only (#IDEA-211054) GitOrigin-RevId: 08229036f709ae654bfa681da19d4ed9fb6831b4 --- .../header/CustomHeaderMenuBar.kt | 36 ++++++++++++ .../header/MainFrameHeader.kt | 25 +------- .../com/intellij/ui/plaf/beg/IdeaMenuUI.java | 58 +++++++++++++------ 3 files changed, 76 insertions(+), 43 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/openapi/wm/impl/customFrameDecorations/header/CustomHeaderMenuBar.kt diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/customFrameDecorations/header/CustomHeaderMenuBar.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/customFrameDecorations/header/CustomHeaderMenuBar.kt new file mode 100644 index 000000000000..81926d10db29 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/customFrameDecorations/header/CustomHeaderMenuBar.kt @@ -0,0 +1,36 @@ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.openapi.wm.impl.customFrameDecorations.header + +import com.intellij.ide.DataManager +import com.intellij.openapi.actionSystem.ActionGroup +import com.intellij.openapi.actionSystem.ex.ActionManagerEx +import com.intellij.openapi.actionSystem.impl.ActionMenu +import com.intellij.openapi.wm.impl.IdeMenuBar +import com.intellij.util.ui.JBUI +import java.awt.Graphics +import javax.swing.border.Border + +class CustomHeaderMenuBar : IdeMenuBar(ActionManagerEx.getInstanceEx(), DataManager.getInstance()) { + override fun getBorder(): Border? { + return JBUI.Borders.empty() + } + + override fun paintBackground(g: Graphics?) { + + } + + override fun createActionMenu(enableMnemonics: Boolean, isDarkMenu: Boolean, action: ActionGroup?): ActionMenu { + val actionMenu = super.createActionMenu(enableMnemonics, isDarkMenu, action) + actionMenu.isOpaque = false + + return actionMenu + } + + init { + isOpaque = false + } + } + + + + diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/customFrameDecorations/header/MainFrameHeader.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/customFrameDecorations/header/MainFrameHeader.kt index 0c009b601f1b..bd2210a43ca6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/customFrameDecorations/header/MainFrameHeader.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/customFrameDecorations/header/MainFrameHeader.kt @@ -1,29 +1,22 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.wm.impl.customFrameDecorations.header -import com.intellij.ide.DataManager import com.intellij.ide.ui.UISettings import com.intellij.ide.ui.UISettingsListener import com.intellij.openapi.Disposable -import com.intellij.openapi.actionSystem.ActionGroup -import com.intellij.openapi.actionSystem.ex.ActionManagerEx -import com.intellij.openapi.actionSystem.impl.ActionMenu import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.project.Project import com.intellij.openapi.util.Disposer import com.intellij.openapi.wm.impl.IdeMenuBar import com.intellij.openapi.wm.impl.customFrameDecorations.header.titleLabel.CustomDecorationPath import com.intellij.ui.awt.RelativeRectangle -import com.intellij.util.ui.JBUI import net.miginfocom.swing.MigLayout import java.awt.Frame -import java.awt.Graphics import java.awt.Rectangle import java.util.* import javax.swing.JFrame import javax.swing.JPanel import javax.swing.SwingUtilities -import javax.swing.border.Border import javax.swing.event.ChangeListener class MainFrameHeader(frame: JFrame) : FrameHeader(frame){ @@ -39,23 +32,7 @@ class MainFrameHeader(frame: JFrame) : FrameHeader(frame){ layout = MigLayout("novisualpadding, fillx, ins 0, gap 0, top", "$H_GAP[pref!]$H_GAP[][pref!]") add(productIcon) - myIdeMenu = object : IdeMenuBar(ActionManagerEx.getInstanceEx(), DataManager.getInstance()) { - override fun getBorder(): Border? { - return JBUI.Borders.empty() - } - - override fun paintBackground(g: Graphics?) { - - } - - override fun createActionMenu(enableMnemonics: Boolean, isDarkMenu: Boolean, action: ActionGroup?): ActionMenu { - val actionMenu = super.createActionMenu(enableMnemonics, isDarkMenu, action) - - return actionMenu - } - }.apply { - isOpaque = false - } + myIdeMenu = CustomHeaderMenuBar() mainMenuUpdater = UISettingsListener { myIdeMenu.isVisible = UISettings.instance.showMainMenu diff --git a/platform/platform-impl/src/com/intellij/ui/plaf/beg/IdeaMenuUI.java b/platform/platform-impl/src/com/intellij/ui/plaf/beg/IdeaMenuUI.java index 9afde0b72004..b69ea420b5aa 100644 --- a/platform/platform-impl/src/com/intellij/ui/plaf/beg/IdeaMenuUI.java +++ b/platform/platform-impl/src/com/intellij/ui/plaf/beg/IdeaMenuUI.java @@ -3,6 +3,7 @@ package com.intellij.ui.plaf.beg; import com.intellij.ide.ui.UISettings; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.wm.impl.IdeFrameDecorator; import com.intellij.ui.scale.JBUIScale; import com.intellij.util.ui.JBInsets; import com.intellij.util.ui.UIUtil; @@ -98,24 +99,11 @@ public class IdeaMenuUI extends BasicMenuUI{ jMenu.getText() != null ? defaultTextIconGap : 0, defaultTextIconGap ); - Color color2 = g.getColor(); + Color mainColor = g.getColor(); if (comp.isOpaque()){ - g.setColor(jMenu.getBackground()); - g.fillRect(0, 0, jMenu.getWidth(), jMenu.getHeight()); - if (buttonmodel.isArmed() || buttonmodel.isSelected()){ - if (UIUtil.isUnderAquaLookAndFeel()) { - myAquaSelectedBackgroundPainter.paintBorder(comp, g, 0, 0, jMenu.getWidth(), jMenu.getHeight()); - } else { - g.setColor(selectionBackground); - if (allowedIcon != null && !(UIUtil.isUnderIntelliJLaF() || UIUtil.isUnderDarcula())) { - g.fillRect(k, 0, jMenu.getWidth() - k, jMenu.getHeight()); - } - else { - g.fillRect(0, 0, jMenu.getWidth(), jMenu.getHeight()); - } - } - } - g.setColor(color2); + fillOpaque(g, comp, jMenu, buttonmodel, allowedIcon, mainColor); + } else { + fillOpaqueFalse(g, comp, jMenu, buttonmodel, allowedIcon, mainColor); } if (allowedIcon != null){ if (buttonmodel.isArmed() || buttonmodel.isSelected()){ @@ -127,7 +115,7 @@ public class IdeaMenuUI extends BasicMenuUI{ if (useCheckAndArrow()){ allowedIcon.paintIcon(comp, g, ourCheckIconRect.x, ourCheckIconRect.y); } - g.setColor(color2); + g.setColor(mainColor); if (menuItem.isArmed()){ drawIconBorder(g); } @@ -193,10 +181,42 @@ public class IdeaMenuUI extends BasicMenuUI{ } } } - g.setColor(color2); + g.setColor(mainColor); g.setFont(font); } + protected void fillOpaque(Graphics g, JComponent comp, JMenu jMenu, ButtonModel buttonmodel, Icon allowedIcon, Color mainColor) { + g.setColor(jMenu.getBackground()); + g.fillRect(0, 0, jMenu.getWidth(), jMenu.getHeight()); + if (buttonmodel.isArmed() || buttonmodel.isSelected()){ + paintHover(g, comp, jMenu, allowedIcon); + } + g.setColor(mainColor); + } + + protected void fillOpaqueFalse(Graphics g, JComponent comp, JMenu jMenu, ButtonModel buttonmodel, Icon allowedIcon, Color mainColor) { + if(IdeFrameDecorator.isCustomDecorationActive()) { + if (buttonmodel.isArmed() || buttonmodel.isSelected()) { + paintHover(g, comp, jMenu, allowedIcon); + } + g.setColor(mainColor); + } + } + + protected final void paintHover(Graphics g, JComponent comp, JMenu jMenu, Icon allowedIcon) { + if (UIUtil.isUnderAquaLookAndFeel()) { + myAquaSelectedBackgroundPainter.paintBorder(comp, g, 0, 0, jMenu.getWidth(), jMenu.getHeight()); + } else { + g.setColor(selectionBackground); + if (allowedIcon != null && !(UIUtil.isUnderIntelliJLaF() || UIUtil.isUnderDarcula())) { + g.fillRect(k, 0, jMenu.getWidth() - k, jMenu.getHeight()); + } + else { + g.fillRect(0, 0, jMenu.getWidth(), jMenu.getHeight()); + } + } + } + private boolean useCheckAndArrow() { return !((JMenu)menuItem).isTopLevelMenu(); }