26
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: JNI implementation of CanvasGraphicsItemPainter class
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INTERNAL INCLUDES
|
|
20 |
#include "javax_microedition_lcdui_CanvasGraphicsItemPainter.h"
|
|
21 |
#include "CMIDCanvas.h" // userinclude in nokialcdui.component
|
|
22 |
|
|
23 |
// EXTERNAL INCLUDES
|
|
24 |
#include <MMIDCanvasGraphicsItemPainter.h>
|
|
25 |
#include <CMIDToolkit.h>
|
|
26 |
#include <jutils.h>
|
|
27 |
#include <jdebug.h>
|
|
28 |
|
|
29 |
/**
|
|
30 |
* Local helper function for disposing graphics item painter
|
|
31 |
* native side component.
|
|
32 |
*
|
|
33 |
* @param aItem The graphics item painter to be destroyed.
|
|
34 |
*/
|
|
35 |
LOCAL_C void Dispose(CMIDToolkit* aToolkit, MMIDCanvasGraphicsItemPainter* aItem)
|
|
36 |
{
|
|
37 |
aToolkit->DisposeObject(aItem);
|
|
38 |
}
|
|
39 |
|
|
40 |
/*
|
|
41 |
* Class: com_nokia_mid_ui_CanvasGraphicsItemPainter
|
|
42 |
* Method: _dispose
|
|
43 |
* Signature: (II)V
|
|
44 |
*/
|
|
45 |
JNIEXPORT void JNICALL Java_javax_microedition_lcdui_CanvasGraphicsItemPainter__1dispose(
|
|
46 |
JNIEnv* /* aJniEnv */,
|
|
47 |
jobject /* aPeer */,
|
|
48 |
jint aToolkitHandle,
|
|
49 |
jint aNativePeerHandle)
|
|
50 |
{
|
|
51 |
DEBUG("CanvasGraphicsItemPainter.cpp - dispose +");
|
|
52 |
|
|
53 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
54 |
|
|
55 |
MMIDCanvasGraphicsItemPainter* item =
|
|
56 |
MIDUnhandObject<MMIDCanvasGraphicsItemPainter>(aNativePeerHandle);
|
|
57 |
|
|
58 |
toolkit->ExecuteV(&Dispose, toolkit, item);
|
|
59 |
|
|
60 |
DEBUG("CanvasGraphicsItemPainter.cpp - dispose -");
|
|
61 |
}
|
|
62 |
|
|
63 |
LOCAL_C void CreateNativePeerL
|
|
64 |
(
|
|
65 |
CMIDToolkit* aToolkit,
|
|
66 |
jobject aPeer,
|
|
67 |
TInt* aNativePeerHandle,
|
|
68 |
int aWidth,
|
|
69 |
int aHeight
|
|
70 |
)
|
|
71 |
{
|
|
72 |
// Get LCDUI component factory.
|
|
73 |
MMIDComponentFactory* factory = aToolkit->ComponentFactory();
|
|
74 |
|
|
75 |
// Create new text canvas graphics item painter component.
|
|
76 |
MMIDCanvasGraphicsItemPainter* itemPainter =
|
|
77 |
factory->CreateCanvasGraphicsItemPainterL(aWidth, aHeight);
|
|
78 |
|
|
79 |
// Put the component to cleanup stack during the register operation.
|
|
80 |
CleanupDisposePushL(itemPainter);
|
|
81 |
|
|
82 |
// Register component to the LCDUI.
|
|
83 |
*aNativePeerHandle = aToolkit->RegisterComponentL(itemPainter, aPeer);
|
|
84 |
|
|
85 |
// Component can be popped from the cleanup stack.
|
|
86 |
CleanupPopComponent(itemPainter);
|
|
87 |
}
|
|
88 |
|
|
89 |
JNIEXPORT jint JNICALL
|
|
90 |
Java_javax_microedition_lcdui_CanvasGraphicsItemPainter__1createNativePeer
|
|
91 |
(
|
|
92 |
JNIEnv* aJniEnv,
|
|
93 |
jobject aPeer,
|
|
94 |
jint aToolkitHandle,
|
|
95 |
jint aWidth,
|
|
96 |
jint aHeight
|
|
97 |
)
|
|
98 |
{
|
|
99 |
CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkitHandle);
|
|
100 |
jobject peer = aJniEnv->NewWeakGlobalRef(aPeer);
|
|
101 |
TInt handle = -1;
|
|
102 |
|
|
103 |
TInt err = toolkit->ExecuteTrap(
|
|
104 |
&CreateNativePeerL,
|
|
105 |
toolkit,
|
|
106 |
peer,
|
|
107 |
&handle,
|
|
108 |
aWidth,
|
|
109 |
aHeight);
|
|
110 |
|
|
111 |
if (err != KErrNone)
|
|
112 |
{
|
|
113 |
// Global reference must be removed at this point if construction
|
|
114 |
// failed for some reason.
|
|
115 |
aJniEnv->DeleteWeakGlobalRef(static_cast<jweak>(peer));
|
|
116 |
|
|
117 |
return err;
|
|
118 |
}
|
|
119 |
|
|
120 |
return handle;
|
|
121 |
}
|
|
122 |
|
|
123 |
LOCAL_C void ResetFrameBuffer
|
|
124 |
(
|
|
125 |
MMIDCanvasGraphicsItemPainter* aPainter,
|
|
126 |
int aPositionX,
|
|
127 |
int aPositionY,
|
|
128 |
int aWidth,
|
|
129 |
int aHeight
|
|
130 |
)
|
|
131 |
{
|
|
132 |
aPainter->ResetFrameBuffer(
|
|
133 |
TPoint(aPositionX, aPositionY), TSize(aWidth, aHeight));
|
|
134 |
}
|
|
135 |
|
|
136 |
JNIEXPORT jint JNICALL
|
|
137 |
Java_javax_microedition_lcdui_CanvasGraphicsItemPainter__1resetFrameBuffer
|
|
138 |
(
|
|
139 |
JNIEnv* /* aJniEnv */,
|
|
140 |
jobject /* aPeer */,
|
|
141 |
jint aToolkitHandle,
|
|
142 |
jint aNativePeerHandle,
|
|
143 |
jint aPositionX,
|
|
144 |
jint aPositionY,
|
|
145 |
jint aWidth,
|
|
146 |
jint aHeight
|
|
147 |
)
|
|
148 |
{
|
|
149 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
150 |
MMIDCanvasGraphicsItemPainter* painter =
|
|
151 |
MIDUnhandObject< MMIDCanvasGraphicsItemPainter >(aNativePeerHandle);
|
|
152 |
|
|
153 |
TInt error = toolkit->ExecuteTrap(
|
|
154 |
&ResetFrameBuffer,
|
|
155 |
painter,
|
|
156 |
(TInt)aPositionX, (TInt)aPositionY,
|
|
157 |
(TInt)aWidth, (TInt)aHeight);
|
|
158 |
|
|
159 |
return error;
|
|
160 |
}
|