1 /* qtscrollpanepeer.cpp --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 #include <QScrollArea>
41 #include <gnu_java_awt_peer_qt_QtScrollPanePeer.h>
42 #include "qtcomponent.h"
43 #include "containers.h"
44 #include "mainthreadinterface.h"
45 #include "componentevent.h"
46 #include "keybindings.h"
48 // Constants in java.awt.ScrollPane
49 #define SCROLLBARS_AS_NEEDED 0
50 #define SCROLLBARS_ALWAYS 1
51 #define SCROLLBARS_NEVER 2
54 class MyScrollArea
: public QScrollArea
57 MyScrollArea(JNIEnv
*env
, jobject obj
, QWidget
*parent
) : QScrollArea( parent
)
67 #define I_KNOW_WHAT_IM_DOING
68 #define PARENT QScrollArea
69 #include "eventmethods.h"
73 class ScrollPanePolicy
: public AWTEvent
{
77 Qt::ScrollBarPolicy policy
;
80 ScrollPanePolicy(QScrollArea
*w
, Qt::ScrollBarPolicy p
) : AWTEvent()
88 widget
->setHorizontalScrollBarPolicy(policy
);
89 widget
->setVerticalScrollBarPolicy(policy
);
94 * Returns the child widget, given the owner Component.
96 QWidget
*scrollPaneChildWidget( JNIEnv
*env
, jobject component
)
98 jclass scrollpaneCls
= env
->FindClass( "java/awt/ScrollPane" );
99 jmethodID getPeerMID
= env
->GetMethodID( scrollpaneCls
,
101 "()Ljava/awt/peer/ComponentPeer;");
102 assert(getPeerMID
!= 0);
103 jobject scrollpanepeerobj
= env
->CallObjectMethod( component
, getPeerMID
, NULL
);
104 QScrollArea
*view
= (QScrollArea
*) getNativeObject( env
, scrollpanepeerobj
);
106 return view
->viewport();
110 * Creates a QScrollArea object.
112 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_init
113 (JNIEnv
*env
, jobject obj
)
115 QWidget
*parentWidget
= (QWidget
*) getParentWidget( env
, obj
);
116 assert( parentWidget
);
117 // QScrollArea *pane = new MyScrollArea( env, obj, parentWidget );
118 QScrollArea
*pane
= new QScrollArea( parentWidget
);
120 setNativeObject( env
, obj
, pane
);
126 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_childResized
127 (JNIEnv
*env
, jobject obj
, jint w
, jint h
)
129 QScrollArea
*view
= (QScrollArea
*) getNativeObject( env
, obj
);
132 QWidget
*child
= view
->viewport();
134 // child->setGeometry( 0, 0, w, h );
136 mainThread
->postEventToMain( new AWTResizeEvent(child
, 0, 0, w
, h
) );
140 * Returns the horizontal scrollbar height.
142 JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_getHScrollbarHeight
143 (JNIEnv
*env
, jobject obj
)
145 QScrollArea
*pane
= (QScrollArea
*) getNativeObject( env
, obj
);
147 QScrollBar
*hbar
= pane
->horizontalScrollBar();
150 if(!hbar
->isVisible())
152 int height
= hbar
->height();
158 * Returns the vertical scrollbar width.
160 JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_getVScrollbarWidth
161 (JNIEnv
*env
, jobject obj
)
163 QScrollArea
*pane
= (QScrollArea
*) getNativeObject( env
, obj
);
165 QScrollBar
*vbar
= pane
->verticalScrollBar();
168 if(!vbar
->isVisible())
170 int width
= vbar
->width();
176 * Sets the current upper-left corner to x, y.
178 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_setScrollPosition
179 (JNIEnv
*env
, jobject obj
, jint x
, jint y
)
181 QScrollArea
*pane
= (QScrollArea
*) getNativeObject( env
, obj
);
183 // pane->scrollContentsBy( x, y );
187 * Sets the scrollbar policy
189 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_setPolicy
190 (JNIEnv
*env
, jobject obj
, jint policy
)
192 QScrollArea
*pane
= (QScrollArea
*) getNativeObject( env
, obj
);
195 Qt::ScrollBarPolicy qtpolicy
;
198 case SCROLLBARS_ALWAYS
:
199 qtpolicy
= Qt::ScrollBarAlwaysOn
;
202 case SCROLLBARS_NEVER
:
203 qtpolicy
= Qt::ScrollBarAlwaysOff
;
207 case SCROLLBARS_AS_NEEDED
:
208 qtpolicy
= Qt::ScrollBarAsNeeded
;
212 mainThread
->postEventToMain( new ScrollPanePolicy( pane
, qtpolicy
) );