Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / native / jni / qt-peer / qtscrollpanepeer.cpp
blobb7bf64a907882d78363029e6677abc98dd6f4e9b
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)
9 any later version.
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
19 02110-1301 USA.
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
24 combination.
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. */
38 #include <assert.h>
39 #include <QScrollArea>
40 #include <QScrollBar>
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
56 public:
57 MyScrollArea(JNIEnv *env, jobject obj, QWidget *parent) : QScrollArea( parent )
59 setup(env, obj);
62 ~MyScrollArea()
64 destroy();
67 #define I_KNOW_WHAT_IM_DOING
68 #define PARENT QScrollArea
69 #include "eventmethods.h"
73 class ScrollPanePolicy : public AWTEvent {
75 private:
76 QScrollArea *widget;
77 Qt::ScrollBarPolicy policy;
79 public:
80 ScrollPanePolicy(QScrollArea *w, Qt::ScrollBarPolicy p) : AWTEvent()
82 widget = w;
83 policy = p;
86 void runEvent()
88 widget->setHorizontalScrollBarPolicy(policy);
89 widget->setVerticalScrollBarPolicy(policy);
93 /**
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,
100 "getPeer",
101 "()Ljava/awt/peer/ComponentPeer;");
102 assert(getPeerMID != 0);
103 jobject scrollpanepeerobj = env->CallObjectMethod( component, getPeerMID, NULL );
104 QScrollArea *view = (QScrollArea *) getNativeObject( env, scrollpanepeerobj );
105 assert(view != 0);
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 );
119 assert( pane );
120 setNativeObject( env, obj, pane );
124 * Resize the child.
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 );
130 assert( view );
132 QWidget *child = view->viewport();
133 assert( child );
134 // child->setGeometry( 0, 0, w, h );
135 // child->update();
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 );
146 assert( pane );
147 QScrollBar *hbar = pane->horizontalScrollBar();
148 if(hbar == NULL)
149 return 0;
150 if(!hbar->isVisible())
151 return 0;
152 int height = hbar->height();
154 return 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 );
164 assert( pane );
165 QScrollBar *vbar = pane->verticalScrollBar();
166 if(vbar == NULL)
167 return 0;
168 if(!vbar->isVisible())
169 return 0;
170 int width = vbar->width();
172 return 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 );
182 assert( pane );
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 );
193 assert( pane );
195 Qt::ScrollBarPolicy qtpolicy;
196 switch( policy )
198 case SCROLLBARS_ALWAYS:
199 qtpolicy = Qt::ScrollBarAlwaysOn;
200 break;
202 case SCROLLBARS_NEVER:
203 qtpolicy = Qt::ScrollBarAlwaysOff;
204 break;
206 default:
207 case SCROLLBARS_AS_NEEDED:
208 qtpolicy = Qt::ScrollBarAsNeeded;
209 break;
212 mainThread->postEventToMain( new ScrollPanePolicy( pane, qtpolicy ) );