Browse Source

Handling win32 hide/show messages.

tags/2021-05-28
jules 13 years ago
parent
commit
710dec8a1e
3 changed files with 59 additions and 78 deletions
  1. +7
    -1
      modules/juce_core/native/juce_posix_SharedCode.h
  2. +7
    -1
      modules/juce_events/native/juce_mac_MessageManager.mm
  3. +45
    -76
      modules/juce_gui_basics/native/juce_win32_Windowing.cpp

+ 7
- 1
modules/juce_core/native/juce_posix_SharedCode.h View File

@@ -573,10 +573,16 @@ MemoryMappedFile::~MemoryMappedFile()
} }
//============================================================================== //==============================================================================
#if JUCE_PROJUCER_LIVE_BUILD
extern "C" const char* juce_getCurrentExecutablePath();
#endif
File juce_getExecutableFile(); File juce_getExecutableFile();
File juce_getExecutableFile() File juce_getExecutableFile()
{ {
#if JUCE_ANDROID
#if JUCE_PROJUCER_LIVE_BUILD
return File (juce_getCurrentExecutablePath());
#elif JUCE_ANDROID
return File (android.appFile); return File (android.appFile);
#else #else
struct DLAddrReader struct DLAddrReader


+ 7
- 1
modules/juce_events/native/juce_mac_MessageManager.mm View File

@@ -212,7 +212,10 @@ void MessageManager::runDispatchLoop()
// must only be called by the message thread! // must only be called by the message thread!
jassert (isThisTheMessageThread()); jassert (isThisTheMessageThread());
#if JUCE_CATCH_UNHANDLED_EXCEPTIONS
#if JUCE_PROJUCER_LIVE_BUILD
runDispatchLoopUntil (std::numeric_limits<int>::max());
#else
#if JUCE_CATCH_UNHANDLED_EXCEPTIONS
@try @try
{ {
[NSApp run]; [NSApp run];
@@ -229,15 +232,18 @@ void MessageManager::runDispatchLoop()
#else #else
[NSApp run]; [NSApp run];
#endif #endif
#endif
} }
} }
void MessageManager::stopDispatchLoop() void MessageManager::stopDispatchLoop()
{ {
quitMessagePosted = true; quitMessagePosted = true;
#if ! JUCE_PROJUCER_LIVE_BUILD
[NSApp stop: nil]; [NSApp stop: nil];
[NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated) [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
[NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1]; [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
#endif
} }
#if JUCE_MODAL_LOOPS_PERMITTED #if JUCE_MODAL_LOOPS_PERMITTED


+ 45
- 76
modules/juce_gui_basics/native/juce_win32_Windowing.cpp View File

@@ -797,7 +797,6 @@ public:
void toBehind (ComponentPeer* other) void toBehind (ComponentPeer* other)
{ {
HWNDComponentPeer* const otherPeer = dynamic_cast <HWNDComponentPeer*> (other); HWNDComponentPeer* const otherPeer = dynamic_cast <HWNDComponentPeer*> (other);
jassert (otherPeer != nullptr); // wrong type of window? jassert (otherPeer != nullptr); // wrong type of window?
if (otherPeer != nullptr) if (otherPeer != nullptr)
@@ -1163,14 +1162,10 @@ private:
static bool isHWNDBlockedByModalComponents (HWND h) static bool isHWNDBlockedByModalComponents (HWND h)
{ {
for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;) for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
{
Component* const c = Desktop::getInstance().getComponent (i);
if (c != nullptr
&& (! c->isCurrentlyBlockedByAnotherModalComponent())
&& IsChild ((HWND) c->getWindowHandle(), h))
return false;
}
if (Component* const c = Desktop::getInstance().getComponent (i))
if ((! c->isCurrentlyBlockedByAnotherModalComponent())
&& IsChild ((HWND) c->getWindowHandle(), h))
return false;
return true; return true;
} }
@@ -1215,8 +1210,7 @@ private:
case WM_SYSKEYDOWN: case WM_SYSKEYDOWN:
if (isHWNDBlockedByModalComponents (m.hwnd)) if (isHWNDBlockedByModalComponents (m.hwnd))
{ {
Component* const modal = Component::getCurrentlyModalComponent (0);
if (modal != nullptr)
if (Component* const modal = Component::getCurrentlyModalComponent (0))
modal->inputAttemptWhenModal(); modal->inputAttemptWhenModal();
return true; return true;
@@ -1351,9 +1345,7 @@ private:
{ {
if (isUsingUpdateLayeredWindow()) if (isUsingUpdateLayeredWindow())
{ {
HWND parentHwnd = GetParent (hwnd);
if (parentHwnd != 0)
if (HWND parentHwnd = GetParent (hwnd))
{ {
RECT parentRect; RECT parentRect;
GetWindowRect (parentHwnd, &parentRect); GetWindowRect (parentHwnd, &parentRect);
@@ -1957,8 +1949,7 @@ private:
void forwardMessageToParent (UINT message, WPARAM wParam, LPARAM lParam) const void forwardMessageToParent (UINT message, WPARAM wParam, LPARAM lParam) const
{ {
HWND parentH = GetParent (hwnd);
if (parentH != 0)
if (HWND parentH = GetParent (hwnd))
PostMessage (parentH, message, wParam, lParam); PostMessage (parentH, message, wParam, lParam);
} }
@@ -1995,11 +1986,11 @@ private:
&& (styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable); && (styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable);
} }
LRESULT handleSizeConstraining (RECT* const r, const WPARAM wParam)
LRESULT handleSizeConstraining (RECT& r, const WPARAM wParam)
{ {
if (isConstrainedNativeWindow()) if (isConstrainedNativeWindow())
{ {
Rectangle<int> pos (rectangleFromRECT (*r));
Rectangle<int> pos (rectangleFromRECT (r));
constrainer->checkBounds (pos, windowBorder.addedTo (component.getBounds()), constrainer->checkBounds (pos, windowBorder.addedTo (component.getBounds()),
Desktop::getInstance().getDisplays().getTotalBounds (true), Desktop::getInstance().getDisplays().getTotalBounds (true),
@@ -2007,23 +1998,23 @@ private:
wParam == WMSZ_LEFT || wParam == WMSZ_TOPLEFT || wParam == WMSZ_BOTTOMLEFT, wParam == WMSZ_LEFT || wParam == WMSZ_TOPLEFT || wParam == WMSZ_BOTTOMLEFT,
wParam == WMSZ_BOTTOM || wParam == WMSZ_BOTTOMLEFT || wParam == WMSZ_BOTTOMRIGHT, wParam == WMSZ_BOTTOM || wParam == WMSZ_BOTTOMLEFT || wParam == WMSZ_BOTTOMRIGHT,
wParam == WMSZ_RIGHT || wParam == WMSZ_TOPRIGHT || wParam == WMSZ_BOTTOMRIGHT); wParam == WMSZ_RIGHT || wParam == WMSZ_TOPRIGHT || wParam == WMSZ_BOTTOMRIGHT);
r->left = pos.getX();
r->top = pos.getY();
r->right = pos.getRight();
r->bottom = pos.getBottom();
r.left = pos.getX();
r.top = pos.getY();
r.right = pos.getRight();
r.bottom = pos.getBottom();
} }
return TRUE; return TRUE;
} }
LRESULT handlePositionChanging (WINDOWPOS* const wp)
LRESULT handlePositionChanging (WINDOWPOS& wp)
{ {
if (isConstrainedNativeWindow()) if (isConstrainedNativeWindow())
{ {
if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE)
if ((wp.flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE)
&& ! Component::isMouseButtonDownAnywhere()) && ! Component::isMouseButtonDownAnywhere())
{ {
Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
Rectangle<int> pos (wp.x, wp.y, wp.cx, wp.cy);
const Rectangle<int> current (windowBorder.addedTo (component.getBounds())); const Rectangle<int> current (windowBorder.addedTo (component.getBounds()));
constrainer->checkBounds (pos, current, constrainer->checkBounds (pos, current,
@@ -2032,13 +2023,18 @@ private:
pos.getX() != current.getX() && pos.getRight() == current.getRight(), pos.getX() != current.getX() && pos.getRight() == current.getRight(),
pos.getY() == current.getY() && pos.getBottom() != current.getBottom(), pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
pos.getX() == current.getX() && pos.getRight() != current.getRight()); pos.getX() == current.getX() && pos.getRight() != current.getRight());
wp->x = pos.getX();
wp->y = pos.getY();
wp->cx = pos.getWidth();
wp->cy = pos.getHeight();
wp.x = pos.getX();
wp.y = pos.getY();
wp.cx = pos.getWidth();
wp.cy = pos.getHeight();
} }
} }
if (((wp.flags & SWP_SHOWWINDOW) != 0 && ! component.isVisible()))
component.setVisible (true);
else if (((wp.flags & SWP_HIDEWINDOW) != 0 && component.isVisible()))
component.setVisible (false);
return 0; return 0;
} }
@@ -2135,9 +2131,7 @@ private:
public: public:
static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam) static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
{ {
HWNDComponentPeer* const peer = getOwnerOfWindow (h);
if (peer != nullptr)
if (HWNDComponentPeer* const peer = getOwnerOfWindow (h))
{ {
jassert (isValidPeer (peer)); jassert (isValidPeer (peer));
return peer->peerWindowProc (h, message, wParam, lParam); return peer->peerWindowProc (h, message, wParam, lParam);
@@ -2162,9 +2156,7 @@ private:
static Point<int> getCurrentMousePosGlobal() noexcept static Point<int> getCurrentMousePosGlobal() noexcept
{ {
const DWORD mp = GetMessagePos();
return Point<int> (GET_X_LPARAM (mp),
GET_Y_LPARAM (mp));
return getPointFromLParam (GetMessagePos());
} }
Point<int> getCurrentMousePos() noexcept Point<int> getCurrentMousePos() noexcept
@@ -2239,8 +2231,8 @@ private:
return 0; return 0;
//============================================================================== //==============================================================================
case WM_SIZING: return handleSizeConstraining ((RECT*) lParam, wParam);
case WM_WINDOWPOSCHANGING: return handlePositionChanging ((WINDOWPOS*) lParam);
case WM_SIZING: return handleSizeConstraining (*(RECT*) lParam, wParam);
case WM_WINDOWPOSCHANGING: return handlePositionChanging (*(WINDOWPOS*) lParam);
case WM_WINDOWPOSCHANGED: case WM_WINDOWPOSCHANGED:
{ {
@@ -2350,9 +2342,9 @@ private:
return 0; return 0;
case WM_QUERYENDSESSION: case WM_QUERYENDSESSION:
if (JUCEApplication::getInstance() != nullptr)
if (JUCEApplication* const app = JUCEApplication::getInstance())
{ {
JUCEApplication::getInstance()->systemRequestedQuit();
app->systemRequestedQuit();
return MessageManager::getInstance()->hasStopMessageBeenSent(); return MessageManager::getInstance()->hasStopMessageBeenSent();
} }
return TRUE; return TRUE;
@@ -2468,9 +2460,7 @@ private:
{ {
if (component.isCurrentlyBlockedByAnotherModalComponent()) if (component.isCurrentlyBlockedByAnotherModalComponent())
{ {
Component* const current = Component::getCurrentlyModalComponent();
if (current != nullptr)
if (Component* const current = Component::getCurrentlyModalComponent())
current->inputAttemptWhenModal(); current->inputAttemptWhenModal();
return true; return true;
@@ -2494,8 +2484,7 @@ private:
{ {
compositionInProgress = false; compositionInProgress = false;
HIMC hImc = ImmGetContext (hWnd);
if (hImc != 0)
if (HIMC hImc = ImmGetContext (hWnd))
{ {
ImmNotifyIME (hImc, NI_COMPOSITIONSTR, CPS_COMPLETE, 0); ImmNotifyIME (hImc, NI_COMPOSITIONSTR, CPS_COMPLETE, 0);
ImmReleaseContext (hWnd, hImc); ImmReleaseContext (hWnd, hImc);
@@ -2506,9 +2495,8 @@ private:
void handleStartComposition (ComponentPeer& owner) void handleStartComposition (ComponentPeer& owner)
{ {
reset(); reset();
TextInputTarget* const target = owner.findCurrentTextInputTarget();
if (target != nullptr)
if (TextInputTarget* const target = owner.findCurrentTextInputTarget())
target->insertTextAtCaret (String::empty); target->insertTextAtCaret (String::empty);
} }
@@ -2517,9 +2505,7 @@ private:
if (compositionInProgress) if (compositionInProgress)
{ {
// If this occurs, the user has cancelled the composition, so clear their changes.. // If this occurs, the user has cancelled the composition, so clear their changes..
TextInputTarget* const target = owner.findCurrentTextInputTarget();
if (target != nullptr)
if (TextInputTarget* const target = owner.findCurrentTextInputTarget())
{ {
target->setHighlightedRegion (compositionRange); target->setHighlightedRegion (compositionRange);
target->insertTextAtCaret (String::empty); target->insertTextAtCaret (String::empty);
@@ -2529,9 +2515,7 @@ private:
target->setTemporaryUnderlining (Array<Range<int> >()); target->setTemporaryUnderlining (Array<Range<int> >());
} }
HIMC hImc = ImmGetContext (hWnd);
if (hImc != 0)
if (HIMC hImc = ImmGetContext (hWnd))
{ {
ImmNotifyIME (hImc, NI_CLOSECANDIDATE, 0, 0); ImmNotifyIME (hImc, NI_CLOSECANDIDATE, 0, 0);
ImmReleaseContext (hWnd, hImc); ImmReleaseContext (hWnd, hImc);
@@ -2793,12 +2777,9 @@ bool Process::isForegroundProcess()
fg = GetAncestor (fg, GA_ROOT); fg = GetAncestor (fg, GA_ROOT);
for (int i = ComponentPeer::getNumPeers(); --i >= 0;) for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
{
HWNDComponentPeer* const wp = dynamic_cast <HWNDComponentPeer*> (ComponentPeer::getPeer (i));
if (wp != nullptr && wp->isInside (fg))
return true;
}
if (HWNDComponentPeer* const wp = dynamic_cast <HWNDComponentPeer*> (ComponentPeer::getPeer (i)))
if (wp->isInside (fg))
return true;
return false; return false;
} }
@@ -3015,13 +2996,9 @@ void SystemClipboard::copyTextToClipboard (const String& text)
if (bytesNeeded > 0) if (bytesNeeded > 0)
{ {
HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT, bytesNeeded + sizeof (WCHAR));
if (bufH != 0)
if (HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT, bytesNeeded + sizeof (WCHAR)))
{ {
WCHAR* const data = static_cast <WCHAR*> (GlobalLock (bufH));
if (data != nullptr)
if (WCHAR* const data = static_cast <WCHAR*> (GlobalLock (bufH)))
{ {
text.copyToUTF16 (data, (int) bytesNeeded); text.copyToUTF16 (data, (int) bytesNeeded);
GlobalUnlock (bufH); GlobalUnlock (bufH);
@@ -3042,13 +3019,9 @@ String SystemClipboard::getTextFromClipboard()
if (OpenClipboard (0) != 0) if (OpenClipboard (0) != 0)
{ {
HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
if (bufH != 0)
if (HANDLE bufH = GetClipboardData (CF_UNICODETEXT))
{ {
const WCHAR* const data = (const WCHAR*) GlobalLock (bufH);
if (data != nullptr)
if (const WCHAR* const data = (const WCHAR*) GlobalLock (bufH))
{ {
result = String (data, (size_t) (GlobalSize (bufH) / sizeof (WCHAR))); result = String (data, (size_t) (GlobalSize (bufH) / sizeof (WCHAR)));
GlobalUnlock (bufH); GlobalUnlock (bufH);
@@ -3074,9 +3047,7 @@ StringArray JUCE_CALLTYPE JUCEApplication::getCommandLineParameterArray()
StringArray s; StringArray s;
int argc = 0; int argc = 0;
LPWSTR* const argv = CommandLineToArgvW (GetCommandLineW(), &argc);
if (argv != nullptr)
if (LPWSTR* const argv = CommandLineToArgvW (GetCommandLineW(), &argc))
{ {
s = StringArray (argv + 1, argc - 1); s = StringArray (argv + 1, argc - 1);
LocalFree (argv); LocalFree (argv);
@@ -3148,9 +3119,7 @@ static HICON extractFileHICON (const File& file)
Image juce_createIconForFile (const File& file) Image juce_createIconForFile (const File& file)
{ {
Image image; Image image;
HICON icon = extractFileHICON (file);
if (icon != 0)
if (HICON icon = extractFileHICON (file))
{ {
image = IconConverters::createImageFromHICON (icon); image = IconConverters::createImageFromHICON (icon);
DestroyIcon (icon); DestroyIcon (icon);


Loading…
Cancel
Save