aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <unknown>2011-06-05 09:51:39 +1000
committernyamatongwe <unknown>2011-06-05 09:51:39 +1000
commitb78fcd78a98d59f6f42ccecb7be229a382af27dd (patch)
tree2f60ab8bd546941564180c6fdab29e8ae4fdc85f
parent6f86a715d8685a988868163b596e8ef22b7ade8f (diff)
downloadscintilla-mirror-b78fcd78a98d59f6f42ccecb7be229a382af27dd.tar.gz
Cocoa implementation of calltips.
-rw-r--r--cocoa/ScintillaCallTip.h63
-rw-r--r--cocoa/ScintillaCallTip.mm117
-rw-r--r--cocoa/ScintillaCocoa.h2
-rw-r--r--cocoa/ScintillaCocoa.mm159
4 files changed, 93 insertions, 248 deletions
diff --git a/cocoa/ScintillaCallTip.h b/cocoa/ScintillaCallTip.h
deleted file mode 100644
index 1d9766a6a..000000000
--- a/cocoa/ScintillaCallTip.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * ScintillaMacOSX.h
- * tutorial
- *
- * Created by Evan Jones on Sun Sep 01 2002.
- *
- */
-#ifndef SCINTILLA_CALLTIP_H
-#define SCINTILLA_CALLTIP_H
-
-#include "TView.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <time.h>
-
-#include "Platform.h"
-#include "Scintilla.h"
-
-static const OSType scintillaCallTipType = 'Scct';
-
-namespace Scintilla {
-
-class ScintillaCallTip : public TView
-{
-public:
- // Private so ScintillaCallTip objects can not be copied
- ScintillaCallTip(const ScintillaCallTip &) : TView( NULL ) {}
- ScintillaCallTip &operator=(const ScintillaCallTip &) { return * this; }
- ~ScintillaCallTip() {};
-
-public:
- /** This is the class ID that we've assigned to Scintilla. */
- static const CFStringRef kScintillaCallTipClassID;
- static const ControlKind kScintillaCallTipKind;
-
- ScintillaCallTip( void* windowid );
-
- /** Returns the HIView object kind, needed to subclass TView. */
- virtual ControlKind GetKind() { return kScintillaCallTipKind; }
-
-private:
-
- virtual ControlPartCode HitTest( const HIPoint& where );
- virtual void Draw( RgnHandle rgn, CGContextRef gc );
- virtual OSStatus MouseDown( HIPoint& location, UInt32 modifiers, EventMouseButton button, UInt32 clickCount );
- virtual OSStatus MouseUp( HIPoint& location, UInt32 modifiers, EventMouseButton button, UInt32 clickCount );
- virtual OSStatus MouseDragged( HIPoint& location, UInt32 modifiers, EventMouseButton button, UInt32 clickCount );
-
-public:
- static HIViewRef Create();
-private:
- static OSStatus Construct( HIViewRef inControl, TView** outView );
-
-};
-
-
-}
-
-
-#endif
diff --git a/cocoa/ScintillaCallTip.mm b/cocoa/ScintillaCallTip.mm
deleted file mode 100644
index ee9d2dfb7..000000000
--- a/cocoa/ScintillaCallTip.mm
+++ /dev/null
@@ -1,117 +0,0 @@
-
-#include "ScintillaCocoa.h"
-#include "ScintillaCallTip.h"
-#include "CallTip.h"
-
-using namespace Scintilla;
-
-const CFStringRef ScintillaCallTip::kScintillaCallTipClassID = CFSTR( "org.scintilla.calltip" );
-const ControlKind ScintillaCallTip::kScintillaCallTipKind = { 'ejon', 'Scct' };
-
-ScintillaCallTip::ScintillaCallTip( void* windowid ) :
- TView( reinterpret_cast<HIViewRef>( windowid ) )
-{
- ActivateInterface( kMouse );
- // debugPrint = true;
-}
-
-void ScintillaCallTip::Draw(
- RgnHandle /*inLimitRgn*/,
- CGContextRef inContext )
-{
- // Get a reference to the Scintilla C++ object
- CallTip* ctip = NULL;
- OSStatus err;
- err = GetControlProperty( GetViewRef(), scintillaCallTipType, 0, sizeof( ctip ), NULL, &ctip );
- assert(err == noErr);
- if (ctip == NULL) return;
-
- Rect contentBounds;
- GetControlBounds(GetViewRef(), &contentBounds);
-
- HIRect controlFrame;
- HIViewGetFrame( GetViewRef(), &controlFrame );
-
- // what is the global pos?
- Surface *surfaceWindow = Surface::Allocate();
- if (surfaceWindow) {
- surfaceWindow->Init(inContext, GetViewRef());
- ctip->PaintCT(surfaceWindow);
- surfaceWindow->Release();
- delete surfaceWindow;
- }
-
-}
-
-ControlPartCode ScintillaCallTip::HitTest( const HIPoint& where )
-{
- if ( CGRectContainsPoint( Bounds(), where ) )
- return 1;
- else
- return kControlNoPart;
-}
-
-OSStatus ScintillaCallTip::MouseDown(HIPoint& location, UInt32 /*inKeyModifiers*/, EventMouseButton button, UInt32 /*inClickCount*/ )
-{
- if ( button != kEventMouseButtonPrimary ) return eventNotHandledErr;
- CallTip* ctip = NULL;
- ScintillaCocoa *sciThis = NULL;
- OSStatus err = GetControlProperty( GetViewRef(), scintillaCallTipType, 0, sizeof( ctip ), NULL, &ctip );
- err = GetControlProperty( GetViewRef(), scintillaMacOSType, 0, sizeof( sciThis ), NULL, &sciThis );
- ctip->MouseClick( Scintilla::Point( static_cast<int>( location.x ), static_cast<int>( location.y ) ));
- sciThis->CallTipClick();
- return noErr;
-}
-
-OSStatus ScintillaCallTip::MouseUp(HIPoint& /*inMouseLocation*/, UInt32 /*inKeyModifiers*/, EventMouseButton button, UInt32 /*inClickCount*/ )
-{
- if ( button != kEventMouseButtonPrimary ) return eventNotHandledErr;
- return noErr;
-}
-
-OSStatus ScintillaCallTip::MouseDragged( HIPoint& location, UInt32 /*modifiers*/, EventMouseButton /*button*/, UInt32 /*clickCount*/ )
-{
- SetThemeCursor( kThemeArrowCursor );
- return noErr;
-}
-
-HIViewRef ScintillaCallTip::Create()
-{
- // Register the HIView, if needed
- static bool registered = false;
-
- if ( not registered )
- {
- TView::RegisterSubclass( kScintillaCallTipClassID, Construct );
- registered = true;
- }
-
- OSStatus err = noErr;
- EventRef event = CreateInitializationEvent();
- assert( event != NULL );
-
- HIViewRef control = NULL;
- err = HIObjectCreate( kScintillaCallTipClassID, event, reinterpret_cast<HIObjectRef*>( &control ) );
- ReleaseEvent( event );
- if ( err == noErr ) {
- Platform::DebugPrintf("ScintillaCallTip::Create control %08X\n",control);
- return control;
- }
- return NULL;
-}
-
-OSStatus ScintillaCallTip::Construct( HIViewRef inControl, TView** outView )
-{
- *outView = new ScintillaCallTip( inControl );
- Platform::DebugPrintf("ScintillaCallTip::Construct scintilla %08X\n",*outView);
- if ( *outView != NULL )
- return noErr;
- else
- return memFullErr;
-}
-
-extern "C" {
-HIViewRef scintilla_calltip_new() {
- return ScintillaCallTip::Create();
-}
-}
diff --git a/cocoa/ScintillaCocoa.h b/cocoa/ScintillaCocoa.h
index 639a714cc..545dc3607 100644
--- a/cocoa/ScintillaCocoa.h
+++ b/cocoa/ScintillaCocoa.h
@@ -161,6 +161,8 @@ public:
virtual bool CanPaste();
virtual void Paste();
virtual void Paste(bool rectangular);
+ void CTPaint(void* gc, NSRect rc);
+ void CallTipMouseDown(NSPoint pt);
virtual void CreateCallTipWindow(PRectangle rc);
virtual void AddToPopUp(const char *label, int cmd = 0, bool enabled = true);
virtual void ClaimSelection();
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm
index 9321666d8..f97520a81 100644
--- a/cocoa/ScintillaCocoa.mm
+++ b/cocoa/ScintillaCocoa.mm
@@ -684,76 +684,99 @@ void ScintillaCocoa::Paste(bool forceRectangular)
//--------------------------------------------------------------------------------------------------
-void ScintillaCocoa::CreateCallTipWindow(PRectangle rc)
-{
-/*
- // create a calltip window
- if (!ct.wCallTip.Created()) {
- WindowClass windowClass = kHelpWindowClass;
- WindowAttributes attributes = kWindowNoAttributes;
- Rect contentBounds;
- WindowRef outWindow;
-
- // convert PRectangle to Rect
- // this adjustment gets the calltip window placed in the correct location relative
- // to our editor window
- Rect bounds;
- OSStatus err;
- err = GetWindowBounds( this->GetOwner(), kWindowGlobalPortRgn, &bounds );
- assert( err == noErr );
- contentBounds.top = rc.top + bounds.top;
- contentBounds.bottom = rc.bottom + bounds.top;
- contentBounds.right = rc.right + bounds.left;
- contentBounds.left = rc.left + bounds.left;
-
- // create our calltip hiview
- HIViewRef ctw = scintilla_calltip_new();
- CallTip* objectPtr = &ct;
- ScintillaCocoa* sciThis = this;
- SetControlProperty( ctw, scintillaMacOSType, 0, sizeof( this ), &sciThis );
- SetControlProperty( ctw, scintillaCallTipType, 0, sizeof( objectPtr ), &objectPtr );
-
- CreateNewWindow(windowClass, attributes, &contentBounds, &outWindow);
- ControlRef root;
- CreateRootControl(outWindow, &root);
-
- HIViewRef hiroot = HIViewGetRoot (outWindow);
- HIViewAddSubview(hiroot, ctw);
-
- HIRect boundsRect;
- HIViewGetFrame(hiroot, &boundsRect);
- HIViewSetFrame( ctw, &boundsRect );
-
- // bind the size of the calltip to the size of it's container window
- HILayoutInfo layout = {
- kHILayoutInfoVersionZero,
- {
- { NULL, kHILayoutBindTop, 0 },
- { NULL, kHILayoutBindLeft, 0 },
- { NULL, kHILayoutBindBottom, 0 },
- { NULL, kHILayoutBindRight, 0 }
- },
- {
- { NULL, kHILayoutScaleAbsolute, 0 },
- { NULL, kHILayoutScaleAbsolute, 0 }
-
- },
- {
- { NULL, kHILayoutPositionTop, 0 },
- { NULL, kHILayoutPositionLeft, 0 }
- }
- };
- HIViewSetLayoutInfo(ctw, &layout);
-
- ct.wCallTip = root;
- ct.wDraw = ctw;
- ct.wCallTip.SetWindow(outWindow);
- HIViewSetVisible(ctw,true);
-
- }
-*/
+void ScintillaCocoa::CTPaint(void* gc, NSRect rc) {
+ Surface *surfaceWindow = Surface::Allocate();
+ if (surfaceWindow) {
+ surfaceWindow->Init(gc, wMain.GetID());
+ surfaceWindow->SetUnicodeMode(SC_CP_UTF8 == ct.codePage);
+ surfaceWindow->SetDBCSMode(ct.codePage);
+ ct.PaintCT(surfaceWindow);
+ surfaceWindow->Release();
+ delete surfaceWindow;
+ }
+}
+
+@interface CallTipView : NSControl {
+ ScintillaCocoa *sci;
+}
+
+@end
+
+@implementation CallTipView
+
+- (NSView*) initWithFrame: (NSRect) frame {
+ self = [super initWithFrame: frame];
+
+ if (self) {
+ sci = NULL;
+ }
+
+ return self;
+}
+
+- (void) dealloc {
+ [super dealloc];
+}
+
+- (BOOL) isFlipped {
+ return YES;
+}
+
+- (void) setSci: (ScintillaCocoa *) sci_ {
+ sci = sci_;
+}
+
+- (void) drawRect: (NSRect) needsDisplayInRect {
+ if (sci) {
+ CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
+ sci->CTPaint(context, needsDisplayInRect);
+ }
}
+- (void) mouseDown: (NSEvent *) event {
+ if (sci) {
+ sci->CallTipMouseDown([event locationInWindow]);
+ }
+}
+
+// On OS X, only the key view should modify the cursor so the calltip can't.
+// This view does not become key so resetCursorRects never called.
+- (void) resetCursorRects {
+ //[super resetCursorRects];
+ //[self addCursorRect: [self bounds] cursor: [NSCursor arrowCursor]];
+}
+
+@end
+
+void ScintillaCocoa::CallTipMouseDown(NSPoint pt) {
+ NSRect rectBounds = [(NSView *)(ct.wDraw.GetID()) bounds];
+ Point location(pt.x, rectBounds.size.height - pt.y);
+ ct.MouseClick(location);
+ CallTipClick();
+}
+
+void ScintillaCocoa::CreateCallTipWindow(PRectangle rc) {
+ if (!ct.wCallTip.Created()) {
+ NSRect ctRect = NSMakeRect(rc.top,rc.bottom, rc.Width(), rc.Height());
+ NSWindow *callTip = [[NSWindow alloc] initWithContentRect: ctRect
+ styleMask: NSBorderlessWindowMask
+ backing: NSBackingStoreBuffered
+ defer: NO];
+ [callTip setLevel:NSFloatingWindowLevel];
+ [callTip setHasShadow:YES];
+ NSRect ctContent = NSMakeRect(0,0, rc.Width(), rc.Height());
+ CallTipView *caption = [CallTipView alloc];
+ [caption initWithFrame: ctContent];
+ [caption setAutoresizingMask: NSViewWidthSizable | NSViewMaxYMargin];
+ [caption setSci: this];
+ [[callTip contentView] addSubview: caption];
+ [callTip orderFront:caption];
+ ct.wCallTip = callTip;
+ ct.wDraw = caption;
+ }
+}
+
+
void ScintillaCocoa::AddToPopUp(const char *label, int cmd, bool enabled)
{