cocoa: update all controls when screen.cursor is set to new value

git-svn-id: trunk@33613 -
This commit is contained in:
paul 2011-11-18 14:37:59 +00:00
parent 97db2e450d
commit af9d15b12b
5 changed files with 88 additions and 12 deletions

View File

@ -223,6 +223,9 @@ function CheckBitmap(ABitmap: HBITMAP; AStr: string): Boolean;
implementation implementation
uses
CocoaInt;
//todo: a better check! //todo: a better check!
function CheckDC(dc: HDC): TCocoaContext; function CheckDC(dc: HDC): TCocoaContext;
@ -421,6 +424,8 @@ end;
function TCocoaCursor.Install: TCocoaCursor; function TCocoaCursor.Install: TCocoaCursor;
begin begin
FCursor.push; FCursor.push;
// also request form cursors invalidation
CocoaWidgetSet.NSApp.keyWindow.resetCursorRects;
Result := nil; Result := nil;
end; end;

View File

@ -67,7 +67,7 @@ type
FTerminating: Boolean; FTerminating: Boolean;
pool : NSAutoreleasePool; pool : NSAutoreleasePool;
NSApp : NSApplication; FNSApp : NSApplication;
delegate : TCocoaAppDelegate; delegate : TCocoaAppDelegate;
protected protected
function GetAppHandle: THandle; override; function GetAppHandle: THandle; override;
@ -102,7 +102,7 @@ type
function RawImage_FromCocoaBitmap(out ARawImage: TRawImage; ABitmap, AMask: TCocoaBitmap; ARect: PRect = nil): Boolean; function RawImage_FromCocoaBitmap(out ARawImage: TRawImage; ABitmap, AMask: TCocoaBitmap; ARect: PRect = nil): Boolean;
function RawImage_DescriptionToBitmapType(ADesc: TRawImageDescription; out bmpType: TCocoaBitmapType): Boolean; function RawImage_DescriptionToBitmapType(ADesc: TRawImageDescription; out bmpType: TCocoaBitmapType): Boolean;
// function GetImagePixelData(AImage: CGImageRef; var bitmapByteCount: PtrUInt): Pointer; // function GetImagePixelData(AImage: CGImageRef; var bitmapByteCount: PtrUInt): Pointer;
property NSApp: NSApplication read FNSApp;
// the winapi compatibility methods // the winapi compatibility methods
{$I cocoawinapih.inc} {$I cocoawinapih.inc}
// the extra LCL interface methods // the extra LCL interface methods

View File

@ -39,8 +39,8 @@ begin
delegate:=TCocoaAppDelegate.alloc; delegate:=TCocoaAppDelegate.alloc;
{ Creates the application NSApp object } { Creates the application NSApp object }
NsApp := NSApplication.sharedApplication; FNsApp := NSApplication.sharedApplication;
NSApp.setDelegate(delegate); FNSApp.setDelegate(delegate);
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------

View File

@ -93,7 +93,7 @@ type
procedure MouseClick(ClickCount: Integer); virtual; abstract; procedure MouseClick(ClickCount: Integer); virtual; abstract;
procedure MouseMove(x,y: Integer); virtual; abstract; procedure MouseMove(x,y: Integer); virtual; abstract;
procedure Draw(ctx: NSGraphicsContext; const bounds, dirty: NSRect); virtual; abstract; procedure Draw(ctx: NSGraphicsContext; const bounds, dirty: NSRect); virtual; abstract;
procedure ResetCursorRects; virtual; abstract; function ResetCursorRects: Boolean; virtual; abstract;
end; end;
{ TWindowCallback } { TWindowCallback }
@ -141,9 +141,12 @@ type
procedure resetCursorRects; override; procedure resetCursorRects; override;
end; end;
{ TCocoaTextField }
TCocoaTextField = objcclass(NSTextField) TCocoaTextField = objcclass(NSTextField)
callback : TCommonCallback; callback : TCommonCallback;
function acceptsFirstResponder: Boolean; override; function acceptsFirstResponder: Boolean; override;
procedure resetCursorRects; override;
end; end;
{ TCocoaSecureTextField } { TCocoaSecureTextField }
@ -151,12 +154,16 @@ type
TCocoaSecureTextField = objcclass(NSSecureTextField) TCocoaSecureTextField = objcclass(NSSecureTextField)
callback : TCommonCallback; callback : TCommonCallback;
function acceptsFirstResponder: Boolean; override; function acceptsFirstResponder: Boolean; override;
procedure resetCursorRects; override;
end; end;
{ TCocoaTextView }
TCocoaTextView = objcclass(NSTextView) TCocoaTextView = objcclass(NSTextView)
callback : TCommonCallback; callback : TCommonCallback;
function acceptsFirstResponder: Boolean; override; function acceptsFirstResponder: Boolean; override;
procedure resetCursorRects; override;
end; end;
{ TCocoaWindow } { TCocoaWindow }
@ -192,6 +199,7 @@ type
TCocoaScrollView = objcclass(NSScrollView) TCocoaScrollView = objcclass(NSScrollView)
callback : TCommonCallback; callback : TCommonCallback;
procedure resetCursorRects; override;
end; end;
@ -220,12 +228,14 @@ type
function numberOfItemsInComboBox(combo: TCocoaComboBox): NSInteger; function numberOfItemsInComboBox(combo: TCocoaComboBox): NSInteger;
message 'numberOfItemsInComboBox:'; message 'numberOfItemsInComboBox:';
procedure dealloc; override; procedure dealloc; override;
procedure resetCursorRects; override;
end; end;
{ TCocoaScrollBar } { TCocoaScrollBar }
TCocoaScrollBar = objcclass(NSScroller) TCocoaScrollBar = objcclass(NSScroller)
callback : TCommonCallback; callback : TCommonCallback;
procedure resetCursorRects; override;
end; end;
TCocoaListView = objcclass; TCocoaListView = objcclass;
@ -251,16 +261,42 @@ type
objectValueForTableColumn: NSTableColumn; row: NSInteger):id; objectValueForTableColumn: NSTableColumn; row: NSInteger):id;
message 'tableView:objectValueForTableColumn:row:'; message 'tableView:objectValueForTableColumn:row:';
procedure dealloc; override; procedure dealloc; override;
procedure resetCursorRects; override;
end; end;
{ TCocoaGroupBox } { TCocoaGroupBox }
TCocoaGroupBox = objcclass(NSBox) TCocoaGroupBox = objcclass(NSBox)
callback : TCommonCallback; callback : TCommonCallback;
procedure resetCursorRects; override;
end; end;
implementation implementation
{ TCocoaScrollView }
procedure TCocoaScrollView.resetCursorRects;
begin
if not callback.resetCursorRects then
inherited resetCursorRects;
end;
{ TCocoaScrollBar }
procedure TCocoaScrollBar.resetCursorRects;
begin
if not callback.resetCursorRects then
inherited resetCursorRects;
end;
{ TCocoaGroupBox }
procedure TCocoaGroupBox.resetCursorRects;
begin
if not callback.resetCursorRects then
inherited resetCursorRects;
end;
{ TCocoaButton } { TCocoaButton }
procedure TCocoaButton.actionButtonClick(sender: NSObject); procedure TCocoaButton.actionButtonClick(sender: NSObject);
@ -294,8 +330,8 @@ end;
procedure TCocoaButton.resetCursorRects; procedure TCocoaButton.resetCursorRects;
begin begin
callback.resetCursorRects; if not callback.resetCursorRects then
inherited resetCursorRects; inherited resetCursorRects;
end; end;
procedure TCocoaButton.mouseDown(event: NSEvent); procedure TCocoaButton.mouseDown(event: NSEvent);
@ -334,6 +370,15 @@ begin
Result:=true; Result:=true;
end; end;
procedure TCocoaTextField.resetCursorRects;
begin
// this will not work well because
// cocoa replaced TextField and TextView cursors in
// mouseEntered, mouseMoved and CursorUpdate
if not callback.resetCursorRects then
inherited resetCursorRects;
end;
{ TCocoaTextView } { TCocoaTextView }
function TCocoaTextView.acceptsFirstResponder: Boolean; function TCocoaTextView.acceptsFirstResponder: Boolean;
@ -341,6 +386,12 @@ begin
Result:=true; Result:=true;
end; end;
procedure TCocoaTextView.resetCursorRects;
begin
if not callback.resetCursorRects then
inherited resetCursorRects;
end;
{ TCocoaWindow } { TCocoaWindow }
function TCocoaWindow.windowShouldClose(sender: id): LongBool; function TCocoaWindow.windowShouldClose(sender: id): LongBool;
@ -441,6 +492,12 @@ begin
Result:=True; Result:=True;
end; end;
procedure TCocoaSecureTextField.resetCursorRects;
begin
if not callback.resetCursorRects then
inherited resetCursorRects;
end;
{ TWindowCallback } { TWindowCallback }
constructor TWindowCallback.Create(AOwner: NSWindow); constructor TWindowCallback.Create(AOwner: NSWindow);
@ -458,8 +515,8 @@ end;
procedure TCocoaCustomControl.resetCursorRects; procedure TCocoaCustomControl.resetCursorRects;
begin begin
callback.resetCursorRects; if not callback.resetCursorRects then
inherited resetCursorRects; inherited resetCursorRects;
end; end;
{ LCLObjectExtension } { LCLObjectExtension }
@ -692,6 +749,12 @@ begin
inherited dealloc; inherited dealloc;
end; end;
procedure TCocoaListView.resetCursorRects;
begin
if not callback.resetCursorRects then
inherited resetCursorRects;
end;
{ TCocoaStringList } { TCocoaStringList }
procedure TCocoaStringList.Changed; procedure TCocoaStringList.Changed;
@ -746,6 +809,12 @@ begin
inherited dealloc; inherited dealloc;
end; end;
procedure TCocoaComboBox.resetCursorRects;
begin
if not callback.resetCursorRects then
inherited resetCursorRects;
end;
{ TCocoaMenu } { TCocoaMenu }
procedure TCocoaMenu.lclItemSelected(sender:id); procedure TCocoaMenu.lclItemSelected(sender:id);

View File

@ -34,7 +34,7 @@ type
procedure MouseClick(clickCount: Integer); override; procedure MouseClick(clickCount: Integer); override;
procedure MouseMove(x,y: Integer); override; procedure MouseMove(x,y: Integer); override;
procedure Draw(ControlContext: NSGraphicsContext; const bounds, dirty: NSRect); override; procedure Draw(ControlContext: NSGraphicsContext; const bounds, dirty: NSRect); override;
procedure ResetCursorRects; override; function ResetCursorRects: Boolean; override;
end; end;
{ TCocoaWSWinControl } { TCocoaWSWinControl }
@ -162,12 +162,13 @@ begin
end; end;
end; end;
procedure TLCLCommonCallback.ResetCursorRects; function TLCLCommonCallback.ResetCursorRects: Boolean;
var var
ACursor: TCursor; ACursor: TCursor;
AControl: TControl; AControl: TControl;
View: NSView; View: NSView;
begin begin
Result := False;
if Owner.isKindOfClass_(NSWindow) then if Owner.isKindOfClass_(NSWindow) then
View := NSwindow(Owner).contentView View := NSwindow(Owner).contentView
else else
@ -183,7 +184,8 @@ begin
// traverse visible child controls // traverse visible child controls
ACursor := Target.Cursor; ACursor := Target.Cursor;
end; end;
if ACursor <> crDefault then Result := ACursor <> crDefault;
if Result then
View.addCursorRect_cursor(View.visibleRect, TCocoaCursor(Screen.Cursors[ACursor]).Cursor); View.addCursorRect_cursor(View.visibleRect, TCocoaCursor(Screen.Cursors[ACursor]).Cursor);
end; end;
end; end;