CtrlCore: Cocoa: Now using NSTrackingArea, focus and other bugs

git-svn-id: svn://ultimatepp.org/upp/trunk@12328 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2018-10-02 15:40:41 +00:00
parent df85cae278
commit a7d1972fc1
12 changed files with 79 additions and 48 deletions

View file

@ -39,7 +39,7 @@ private:
Vector<Rect> clip;
Color fill = Null;
void Push();
void Pop();

View file

@ -10,26 +10,6 @@ int Ctrl::WndCaretTime;
bool Ctrl::WndCaretVisible;
static NSAutoreleasePool *main_coco_pool;
static NSEvent *current_event;
static NSEvent *GetNextEvent(NSDate *until)
{
if(!current_event) {
current_event = [NSApp nextEventMatchingMask:NSEventMaskAny
untilDate:until
inMode:NSDefaultRunLoopMode dequeue:YES];
[current_event retain];
}
return current_event;
}
static void ReleaseCurrentEvent()
{
if(current_event) {
[current_event release];
current_event = nil;
}
}
void SyncPopupFocus(NSWindow *win)
{
@ -97,12 +77,6 @@ void CocoInit(int argc, const char **argv, const char **envptr)
Ctrl::Csizeinit();
}
void CocoExit()
{
ReleaseCurrentEvent();
[main_coco_pool release];
}
int Ctrl::GetKbdDelay()
{
GuiLock __;
@ -115,6 +89,34 @@ int Ctrl::GetKbdSpeed()
return int(1000 * NSEvent.keyRepeatInterval);
}
static NSEvent *current_event;
static NSEvent *GetNextEvent(NSDate *until)
{
if(!current_event) {
current_event = [NSApp nextEventMatchingMask:NSEventMaskAny
untilDate:until
inMode:NSDefaultRunLoopMode
dequeue:YES];
[current_event retain];
}
return current_event;
}
static void ReleaseCurrentEvent()
{
if(current_event) {
[current_event release];
current_event = nil;
}
}
void CocoExit()
{
ReleaseCurrentEvent();
[main_coco_pool release];
}
bool Ctrl::IsWaitingEvent()
{
return GetNextEvent(nil);

View file

@ -106,7 +106,7 @@ void Ctrl::Create(Ctrl *owner, dword style, bool active)
top = new Top;
top->coco = new CocoTop;
top->coco->owner = owner;
NSRect frame = DesktopRect(GetRect());
CocoWindow *window = [[CocoWindow alloc] initWithContentRect:frame styleMask: style
backing:NSBackingStoreBuffered defer:false];
@ -117,6 +117,8 @@ void Ctrl::Create(Ctrl *owner, dword style, bool active)
window->ctrl = this;
window->active = active;
window.backgroundColor = [NSColor clearColor];
isopen = true;
CocoView *view = [[[CocoView alloc] initWithFrame:frame] autorelease];
view->ctrl = this;
@ -125,10 +127,9 @@ void Ctrl::Create(Ctrl *owner, dword style, bool active)
[window setDelegate:view];
[window setAcceptsMouseMovedEvents:YES];
[window makeFirstResponder:view];
[window makeKeyAndOrderFront:view];
[window makeKeyAndOrderFront:window];
MMCtrl::SyncRect(view);
isopen = true;
mmtopctrl.Add(this);
RegisterCocoaDropFormats();
@ -177,6 +178,7 @@ void Ctrl::WndScrollView(const Rect& r, int dx, int dy)
bool Ctrl::IsWndOpen() const {
GuiLock __;
// DLOG("IsWndOpen " << Upp::Name(this) << ": " << (bool)top);
return top;
}
@ -224,17 +226,15 @@ void TopWindow::Open(Ctrl *owner)
SetRect((center == 1 ? owner->GetRect() : owner ? owner->GetWorkArea()
: GetPrimaryWorkArea())
.CenterRect(GetRect().GetSize()));
placefocus = true;
Create(owner, GetMMStyle(), true);
ActivateWnd();
SyncCaption();
SyncSizeHints();
PlaceFocus();
if(state == MAXIMIZED)
Maximize();
if(state == MINIMIZED)
Minimize();
// if(top)
// top->placefocus = true;
// Note: window is activated and PlaceFocus invoked by event, later
}
void TopWindow::Open()

View file

@ -57,7 +57,8 @@ void SystemDraw::Pop()
offset.Drop();
if(clip.GetCount())
clip.Drop();
CGContextRestoreGState(cgHandle);
if(cgHandle)
CGContextRestoreGState(cgHandle);
fill = Null;
}

View file

@ -171,7 +171,6 @@ void Ctrl::SetMouseCursor(const Image& img)
{
if(GetDragAndDropSource())
return;
int64 h = img.GetAuxData();
if(h) {
[GetNSCursor(h) set];
@ -242,6 +241,7 @@ Draw& ImageDraw::Alpha()
ImageDraw::~ImageDraw()
{
CGContextRelease(cgHandle);
handle = NULL; // avoid releasing invalid handle in ~SystemDraw
}
Image ImageDraw::GetStraight()

View file

@ -168,11 +168,11 @@ struct MMImp {
{
LLOG("Become key " << Upp::Name(ctrl));
ctrl->ActivateWnd();
/* auto tw = dynamic_cast<TopWindow *>(ctrl);
if(tw && ctrl->top && ctrl->top->placefocus) {
auto tw = dynamic_cast<TopWindow *>(ctrl);
if(tw && tw->placefocus) {
tw->PlaceFocus();
ctrl->top->placefocus = false;
}*/
tw->placefocus = false;
}
}
static void ResignKey(Upp::Ctrl *ctrl)
@ -341,6 +341,22 @@ struct MMImp {
return Upp::MMImp::DnD(ctrl, sender, true) != NSDragOperationNone;
}
- (void)updateTrackingAreas
{
for(NSTrackingArea *t in [self trackingAreas])
[self removeTrackingArea:t];
Upp::Size sz = ctrl->GetScreenRect().GetSize();
NSTrackingArea *ta = [[NSTrackingArea alloc]
initWithRect:NSMakeRect(0, 0, sz.cx, sz.cy)
options:NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways|
NSTrackingInVisibleRect|NSTrackingMouseMoved|NSTrackingCursorUpdate
owner:self
userInfo:nil];
[self addTrackingArea:ta];
[ta release];
}
@end
#endif

View file

@ -1,6 +1,8 @@
//$ class TopWindow {
protected:
friend struct MMImp;
bool placefocus;
dword GetMMStyle() const;

View file

@ -272,7 +272,7 @@ bool Ctrl::IsOpen() const
{
GuiLock __;
const Ctrl *q = GetTopCtrl();
return q->IsWndOpen() && q->isopen;
return q->isopen && q->IsWndOpen();
}
void Ctrl::Show(bool ashow) {

View file

@ -2,7 +2,7 @@
namespace Upp {
#define LLOG(x) // DLOG(x)
#define LLOG(x) // DLOG(x)
Ptr<Ctrl> Ctrl::focusCtrl;
Ptr<Ctrl> Ctrl::focusCtrlWnd;
@ -228,7 +228,7 @@ bool Ctrl::SetFocus0(bool activate)
{
GuiLock __;
USRLOG(" SETFOCUS " << Desc(this));
LLOG("Ctrl::SetFocus " << Desc(this));
LLOG("Ctrl::SetFocus " << Desc(this) << ", activate: " << activate);
LLOG("focusCtrlWnd " << UPP::Name(focusCtrlWnd));
LLOG("Ctrl::SetFocus0 -> deferredSetFocus = NULL; was: " << UPP::Name(defferedSetFocus));
defferedSetFocus = NULL;

View file

@ -23,7 +23,9 @@ void TopWindow::ActiveFocus0(Ctrl& ctrl)
{
if(IsChild()) return;
activefocus = &ctrl;
if(IsForeground()) ctrl.SetWantFocus();
LLOG("ActiveFocus0");
if(IsForeground())
ctrl.SetWantFocus();
}
void TopWindow::Activate()
@ -55,6 +57,7 @@ void TopWindow::Deactivate()
void TopWindow::PlaceFocus()
{
LLOG("PlaceFocus " << Upp::Name(this));
if(activefocus)
activefocus->SetFocus();
else

View file

@ -1,9 +1,9 @@
sooner:
- fix modifier keys (read before each event)
- Ctrl key gets stuck
- modal disabled window can be closed
- Uword cursor is blinking even in background
- initial focus in uword
- icondes - rightclick on image in the list, then move mouse over color ramp - weird focus issue happens
* Mac menu
@ -65,6 +65,13 @@ later:
done:
[uword] CGContextRestoreGState: invalid context
- fix modifier keys (read before each event)
- Ctrl key gets stuck
- initial focus in uword
- after mouse up, cursor changes to arrow
- IconDes could show hotspots always
* cursor trouble osscilation

View file

@ -396,7 +396,7 @@ Rect EditField::GetCaretRect(int pos) const
{
return RectC(GetCaret(pos) - sc + 2 * !no_internal_margin
- font.GetRightSpace('o') + font.GetLeftSpace('o'), GetTy(),
1, min(GetSize().cy - 2 * GetTy(), font.GetCy()));
DPI(1), min(GetSize().cy - 2 * GetTy(), font.GetCy()));
}
void EditField::SyncCaret()