aboutsummaryrefslogtreecommitdiffhomepage
path: root/macosx/ScintillaCallTip.cxx
blob: 6799b435a9dde7b254a0da6882554cc488eeec89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "ScintillaMacOSX.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;
    ScintillaMacOSX *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();
}
}