Compare commits

...

6 Commits

Author SHA1 Message Date
Vyacheslav Moklev
25bcf746ca Review fix: self-assignment check 2019-03-15 10:09:34 +03:00
Vyacheslav Moklev
d9dce384fb Review fix: SmartHolder cleanup 2019-03-14 18:40:08 +03:00
Vyacheslav Moklev
84c9929306 JBR-1274 Common Item Dialog sometimes crash the process
Prevent from freeing memory with CoTaskMemFree twice
2019-03-14 18:14:18 +03:00
Vyacheslav Moklev
baf57ea6d9 JBR-1273 Common Item Dialog does not open when wrong path to directory is passed
Handle set directory / set file properly
2019-03-14 13:31:43 +03:00
Vyacheslav Moklev
3c6078a41c JBR-1271 Wrong parent of native windows dialogs
Set a proper parent to a dialog window
2019-03-13 13:50:50 +03:00
Vyacheslav Moklev
6df40dc1c1 JBR-1269 Common Item Dialog does not appear on Alt+Tab or click in windows toolbar
JBR-1270 Common Item Dialog does not have an icon

Select a proper window handle
2019-03-13 13:04:21 +03:00

View File

@@ -58,7 +58,13 @@ class CoTaskStringHolder {
public: public:
CoTaskStringHolder() : m_str(NULL) {} CoTaskStringHolder() : m_str(NULL) {}
CoTaskStringHolder(CoTaskStringHolder& other) {
m_str = other.m_str;
other.m_str = NULL;
}
CoTaskStringHolder& operator=(CoTaskStringHolder& other) { CoTaskStringHolder& operator=(CoTaskStringHolder& other) {
if (m_str == other.m_str) return *this;
Clean(); Clean();
m_str = other.m_str; m_str = other.m_str;
other.m_str = NULL; other.m_str = NULL;
@@ -84,8 +90,10 @@ private:
LPTSTR m_str; LPTSTR m_str;
void Clean() { void Clean() {
if (m_str) if (m_str) {
::CoTaskMemFree(m_str); ::CoTaskMemFree(m_str);
m_str = NULL;
}
} }
}; };
@@ -97,6 +105,7 @@ public:
SmartHolderBase& operator=(const SmartHolderBase&) = delete; SmartHolderBase& operator=(const SmartHolderBase&) = delete;
void Attach(T* other) { void Attach(T* other) {
if (m_pointer == other) return;
Clean(); Clean();
m_pointer = other; m_pointer = other;
} }
@@ -116,8 +125,10 @@ protected:
T* m_pointer; T* m_pointer;
virtual void Clean() { virtual void Clean() {
if (m_pointer) if (m_pointer) {
delete m_pointer; delete m_pointer;
m_pointer = NULL;
}
} }
}; };
@@ -128,8 +139,10 @@ class SmartHolder : public SmartHolderBase<T> {
template <typename T> template <typename T>
class SmartHolder<T[]> : public SmartHolderBase<T> { class SmartHolder<T[]> : public SmartHolderBase<T> {
virtual void Clean() { virtual void Clean() {
if (m_pointer) if (m_pointer) {
delete [] m_pointer; delete [] m_pointer;
m_pointer = NULL;
}
} }
}; };
@@ -525,10 +538,9 @@ private:
HWND hdlg; HWND hdlg;
OLE_HRT(pWindow->GetWindow(&hdlg)); OLE_HRT(pWindow->GetWindow(&hdlg));
HWND parent = ::GetParent(hdlg);
jobject peer = data->peer; jobject peer = data->peer;
env->CallVoidMethod(peer, AwtFileDialog::setHWndMID, (jlong)parent); env->CallVoidMethod(peer, AwtFileDialog::setHWndMID, (jlong)hdlg);
::SetProp(parent, ModalDialogPeerProp, reinterpret_cast<HANDLE>(peer)); ::SetProp(hdlg, ModalDialogPeerProp, reinterpret_cast<HANDLE>(peer));
// fix for 4508670 - disable CS_SAVEBITS // fix for 4508670 - disable CS_SAVEBITS
DWORD style = ::GetClassLong(hdlg, GCL_STYLE); DWORD style = ::GetClassLong(hdlg, GCL_STYLE);
@@ -537,13 +549,13 @@ private:
// set appropriate icon for parentless dialogs // set appropriate icon for parentless dialogs
jobject awtParent = env->GetObjectField(peer, AwtFileDialog::parentID); jobject awtParent = env->GetObjectField(peer, AwtFileDialog::parentID);
if (awtParent == NULL) { if (awtParent == NULL) {
::SendMessage(parent, WM_SETICON, (WPARAM)ICON_BIG, ::SendMessage(hdlg, WM_SETICON, (WPARAM)ICON_BIG,
(LPARAM)AwtToolkit::GetInstance().GetAwtIcon()); (LPARAM)AwtToolkit::GetInstance().GetAwtIcon());
} else { } else {
AwtWindow *awtWindow = (AwtWindow *)JNI_GET_PDATA(awtParent); AwtWindow *awtWindow = (AwtWindow *)JNI_GET_PDATA(awtParent);
::SendMessage(parent, WM_SETICON, (WPARAM)ICON_BIG, ::SendMessage(hdlg, WM_SETICON, (WPARAM)ICON_BIG,
(LPARAM)(awtWindow->GetHIcon())); (LPARAM)(awtWindow->GetHIcon()));
::SendMessage(parent, WM_SETICON, (WPARAM)ICON_SMALL, ::SendMessage(hdlg, WM_SETICON, (WPARAM)ICON_SMALL,
(LPARAM)(awtWindow->GetHIconSm())); (LPARAM)(awtWindow->GetHIconSm()));
env->DeleteLocalRef(awtParent); env->DeleteLocalRef(awtParent);
} }
@@ -634,7 +646,12 @@ AwtFileDialog::Show(void *p)
parentless dialogs we use NULL to show them in the taskbar, parentless dialogs we use NULL to show them in the taskbar,
and for all other dialogs AwtToolkit's HWND is used. and for all other dialogs AwtToolkit's HWND is used.
*/ */
HWND hwndOwner = awtParent ? AwtToolkit::GetInstance().GetHWnd() : NULL; /* [moklev] This fix does not needed anymore
* Tested on Windows 10 with example from JDK-4080029
* Revert the fix and set the proper parent to keep correct position of modal dialogs
*/
// HWND hwndOwner = awtParent ? AwtToolkit::GetInstance().GetHWnd() : NULL;
HWND hwndOwner = awtParent ? awtParent->GetHWnd() : NULL;
if (title == NULL || env->GetStringLength(title)==0) { if (title == NULL || env->GetStringLength(title)==0) {
title = JNU_NewStringPlatform(env, L" "); title = JNU_NewStringPlatform(env, L" ");
@@ -725,16 +742,23 @@ AwtFileDialog::Show(void *p)
OLE_HRT(pfd->SetFileTypes(s_fileFilterCount, s_fileFilterSpec)); OLE_HRT(pfd->SetFileTypes(s_fileFilterCount, s_fileFilterSpec));
OLE_HRT(pfd->SetFileTypeIndex(1)); OLE_HRT(pfd->SetFileTypeIndex(1));
IShellItemPtr directoryItem; {
OLE_NEXT_TRY IShellItemPtr directoryItem;
OLE_HRT(CreateShellItem(directoryBuffer, directoryItem)); OLE_TRY
OLE_HRT(pfd->SetFolder(directoryItem)); OLE_HRT(CreateShellItem(directoryBuffer, directoryItem));
OLE_CATCH OLE_HRT(pfd->SetFolder(directoryItem));
OLE_CATCH
CoTaskStringHolder shortName = GetShortName(fileBuffer);
if (shortName) {
OLE_HRT(pfd->SetFileName(shortName));
} }
{
CoTaskStringHolder shortName = GetShortName(fileBuffer);
if (shortName) {
OLE_TRY
OLE_HRT(pfd->SetFileName(shortName));
OLE_CATCH
}
}
OLE_CATCH OLE_CATCH
} }
@@ -795,7 +819,7 @@ AwtFileDialog::Show(void *p)
AwtDialog::ModalActivateNextWindow(NULL, target, peer); AwtDialog::ModalActivateNextWindow(NULL, target, peer);
if (useCommonItemDialog) { if (!useCommonItemDialog) {
VERIFY(::SetCurrentDirectory(currentDirectory)); VERIFY(::SetCurrentDirectory(currentDirectory));
} }