CtrlCore: Fixed mouse event handling popup related issues in MacOS

git-svn-id: svn://ultimatepp.org/upp/trunk@15019 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2020-09-12 08:14:41 +00:00
parent fcbd28fe3a
commit 174a032126
5 changed files with 47 additions and 11 deletions

View file

@ -32,7 +32,7 @@ void SyncPopupFocus(NSWindow *win)
Ctrl *q = Ctrl::GetFocusCtrl();
if(q) {
q = q->GetTopCtrl();
if(q->IsPopUp() && q->GetNSWindow() != win) {
if(q->IsPopUp() && q->GetNSWindow() != win && q->IsCocoActive()) {
q = q->GetOwner();
if(q) q->SetFocus();
}

View file

@ -25,6 +25,7 @@ public:
void *GetNSWindow() const;
void *GetNSView() const;
bool IsCocoActive() const;
void RegisterCocoaDropFormats();

View file

@ -80,12 +80,20 @@ struct RectCG {
}
@end
@interface CocoWindow : NSWindow
{
@public
Upp::Ptr<Upp::Ctrl> ctrl;
bool active;
}
@end
struct Upp::MMCtrl {
static void SyncRect(CocoView *view);
};
struct Upp::CocoTop {
NSWindow *window = NULL;
CocoWindow *window = NULL;
CocoView *view = NULL;
Ptr<Ctrl> owner;
};

View file

@ -125,6 +125,36 @@ struct MMImp {
Rect r = view->ctrl->GetRect();
Upp::Point p(DPI(np.x), DPI(np.y));
coco_mouse_pos = p + r.TopLeft();
if(event == Ctrl::MOUSEMOVE) {
static Point coco_mouse_pos_old(-10000, -10000);
if(coco_mouse_pos_old == coco_mouse_pos) { // duplicate for another window, ignore
sCurrentMouseEvent__ = NULL;
return false;
}
coco_mouse_pos_old = coco_mouse_pos;
if(coco_capture)
coco_capture->DispatchMouse(event, coco_mouse_pos - coco_capture->GetScreenRect().TopLeft(), 120 * sgn(zd));
else {
Vector<Ctrl *> t = Ctrl::GetTopCtrls(); // Find window that contains the mouse, from the top
for(NSNumber *num in [NSWindow windowNumbersWithOptions:0]) { // All app windows
NSWindow *win = [NSApp windowWithWindowNumber:[num integerValue]];
if(win) {
int q = FindMatch(t, [&](Ctrl *t) { return t->GetNSWindow() == win; });
if(q >= 0) {
Ctrl *w = t[q];
Rect r = w->GetRect(); // same as ScreenRect
if(w->IsEnabled() && r.Contains(coco_mouse_pos)) {
w->DispatchMouse(event, coco_mouse_pos - r.TopLeft(), 120 * sgn(zd));
break;
}
}
}
}
}
}
else
if(view->ctrl->IsEnabled() && (view->ctrl->HasWndCapture() || r.Contains(coco_mouse_pos)))
view->ctrl->DispatchMouse(event, p, 120 * sgn(zd));
sCurrentMouseEvent__ = NULL;
@ -413,4 +443,4 @@ struct MMImp {
@end
#endif
#endif

View file

@ -4,14 +4,6 @@
#define LLOG(x)
@interface CocoWindow : NSWindow
{
@public
Upp::Ptr<Upp::Ctrl> ctrl;
bool active;
}
@end
@implementation CocoWindow
- (void)becomeKeyWindow {
@ -362,6 +354,11 @@ void TopWindow::Overlap(bool effect)
[top->coco->window deminiaturize:top->coco->window];
}
bool Ctrl::IsCocoActive() const
{
return top && top->coco && top->coco->window && top->coco->window->active;
}
}
#endif