Skip to content

Commit 7d85a4a

Browse files
committed
8286872: Refactor add/modify notification icon (TrayIcon)
Backport-of: 9f562ef7546c80e6ddce7b932f3f5ca17c741d21
1 parent 7ef7c81 commit 7d85a4a

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

src/java.desktop/windows/native/libawt/windows/awt_TrayIcon.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,7 @@ MsgRouting AwtTrayIcon::WmTaskbarCreated() {
496496
// Update the icon image
497497
item->m_trayIcon->UpdateImage();
498498
}
499-
BOOL result = item->m_trayIcon->SendTrayMessage(NIM_ADD);
500-
// 6270114: Instructs the taskbar to behave according to the Shell version 5.0
501-
if (result) {
502-
item->m_trayIcon->SendTrayMessage(NIM_SETVERSION);
503-
}
499+
item->m_trayIcon->AddTrayIcon();
504500
}
505501
m_bDPIChanged = false;
506502
return mrDoDefault;
@@ -748,7 +744,7 @@ void AwtTrayIcon::SetToolTip(LPCTSTR tooltip)
748744
_tcscpy_s(m_nid.szTip, TRAY_ICON_TOOLTIP_MAX_SIZE, tooltip);
749745
}
750746

751-
SendTrayMessage(NIM_MODIFY);
747+
ModifyTrayIcon();
752748
}
753749

754750
void AwtTrayIcon::_SetToolTip(void *param)
@@ -816,10 +812,10 @@ void AwtTrayIcon::_UpdateIcon(void *param)
816812
JNI_CHECK_PEER_GOTO(self, ret);
817813
trayIcon = (AwtTrayIcon *)pData;
818814

819-
BOOL result = trayIcon->SendTrayMessage(jupdate == JNI_TRUE ? NIM_MODIFY : NIM_ADD);
820-
// 6270114: Instructs the taskbar to behave according to the Shell version 5.0
821-
if (result && jupdate == JNI_FALSE) {
822-
trayIcon->SendTrayMessage(NIM_SETVERSION);
815+
if (jupdate == JNI_TRUE) {
816+
trayIcon->ModifyTrayIcon();
817+
} else {
818+
trayIcon->AddTrayIcon();
823819
}
824820
ret:
825821
env->DeleteGlobalRef(self);
@@ -868,7 +864,7 @@ void AwtTrayIcon::DisplayMessage(LPCTSTR caption, LPCTSTR text, LPCTSTR msgType)
868864
_tcscpy_s(m_nid.szInfo, TRAY_ICON_BALLOON_INFO_MAX_SIZE, text);
869865
}
870866

871-
SendTrayMessage(NIM_MODIFY);
867+
ModifyTrayIcon();
872868
m_nid.uFlags &= ~NIF_INFO;
873869
}
874870

src/java.desktop/windows/native/libawt/windows/awt_TrayIcon.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class AwtTrayIcon: public AwtObject {
5252

5353
virtual void Dispose();
5454

55-
BOOL SendTrayMessage(DWORD dwMessage);
5655
void LinkObjects(JNIEnv *env, jobject peer);
5756
void UnlinkObjects();
5857

@@ -154,6 +153,20 @@ class AwtTrayIcon: public AwtObject {
154153
TrayIconListItem* m_next;
155154
};
156155

156+
BOOL SendTrayMessage(DWORD dwMessage);
157+
158+
INLINE void AddTrayIcon() {
159+
BOOL result = SendTrayMessage(NIM_ADD);
160+
// 6270114: Instructs the taskbar to behave according to the Shell version 5.0
161+
if (result) {
162+
SendTrayMessage(NIM_SETVERSION);
163+
}
164+
}
165+
166+
INLINE void ModifyTrayIcon() {
167+
SendTrayMessage(NIM_MODIFY);
168+
}
169+
157170
static bool m_bDPIChanged;
158171

159172
public:

0 commit comments

Comments
 (0)