OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [native/] [jni/] [qt-peer/] [qtframepeer.cpp] - Blame information for rev 774

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* qtframepeer.cpp --
2
   Copyright (C)  2005  Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
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.
10
 
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.
15
 
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.
20
 
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.
25
 
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. */
37
 
38
#include <assert.h>
39
#include <QApplication>
40
#include <QIcon>
41
#include <QMainWindow>
42
#include <QMenuBar>
43
#include <QPixmap>
44
#include <QToolBar>
45
#include <QThread>
46
#include <gnu_java_awt_peer_qt_QtFramePeer.h>
47
#include "qtcomponent.h"
48
#include "qtstrings.h"
49
#include "qtimage.h"
50
#include "containers.h"
51
#include "keybindings.h"
52
#include "mainthreadinterface.h"
53
 
54
#define MenuSizeDefault 5
55
 
56
/*
57
 * Our QMainWindow subclass
58
 */
59
class MyFrame : public QMainWindow
60
{
61
public:
62
  MyFrame(JNIEnv *env, jobject obj) : QMainWindow(0, Qt::Window )
63
  {
64
    setup(env, obj);
65
  }
66
 
67
  ~MyFrame()
68
  {
69
    destroy();
70
  }
71
 
72
#define I_KNOW_WHAT_IM_DOING
73
#define PARENT QMainWindow
74
#include "eventmethods.h"
75
};
76
 
77
/**
78
 * Event wrapper for adding a menu bar to the frame
79
 * if the QMenuBar pointer is NULL, the current menu bar is removed.
80
 */
81
class FrameMenuEvent : public AWTEvent {
82
 
83
 private:
84
  QMainWindow *widget;
85
  QMenuBar *menu;
86
 
87
 public:
88
  FrameMenuEvent(QMainWindow *w, QMenuBar *mb) : AWTEvent()
89
  {
90
    widget = w;
91
    menu = mb;
92
  }
93
 
94
  void runEvent()
95
  {
96
    if( menu != NULL)
97
      widget->setMenuBar( menu );
98
    else
99
      delete widget->menuBar();
100
  }
101
};
102
 
103
/**
104
 * Returns the child widget for the frame (the centralWidget in qt terms)
105
 */
106
QWidget *frameChildWidget( JNIEnv *env, jobject component )
107
{
108
  jclass frameCls = env->FindClass( "java/awt/Frame" );
109
  assert( frameCls );
110
  jmethodID getPeerMID = env->GetMethodID( frameCls,
111
                                           "getPeer",
112
                                           "()Ljava/awt/peer/ComponentPeer;" );
113
  assert(getPeerMID);
114
 
115
  jobject framepeerobj = env->CallObjectMethod( component, getPeerMID, 0);
116
  if( framepeerobj == NULL )
117
    return (QWidget *)NULL;
118
 
119
  MyFrame *window = (MyFrame *)getNativeObject(env, framepeerobj);
120
  assert( window );
121
  return window;
122
}
123
 
124
/*
125
 * Constructs a QMainWindow native object.
126
 */
127
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_init
128
(JNIEnv *env, jobject obj)
129
{
130
  MyFrame *frame = new MyFrame(env, obj);
131
  assert( frame );
132
  frame->addToolBarBreak ( Qt::BottomToolBarArea );
133
  setNativeObject( env, obj, frame );
134
}
135
 
136
/**
137
 * Sets the icon image.
138
 */
139
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_setIcon
140
(JNIEnv *env, jobject obj, jobject image)
141
{
142
  QMainWindow *frame = (QMainWindow *) getNativeObject( env, obj );
143
  assert( frame );
144
 
145
  QIcon *i;
146
  if( image == NULL )
147
    {
148
      // remove icon
149
      i = new QIcon();
150
    }
151
  else
152
    {
153
      // set icon
154
      QImage *img = getQtImage( env, image );
155
      assert( img );
156
      i = new QIcon( QPixmap::fromImage( *img ) );
157
    }
158
  frame->setWindowIcon( *i );
159
  delete i;
160
}
161
 
162
/**
163
 * Returns the menu bar height for insets.
164
 */
165
JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_menuBarHeight
166
(JNIEnv *env, jobject obj)
167
{
168
  QMainWindow *frame = (QMainWindow *) getNativeObject( env, obj );
169
  assert( frame );
170
 
171
  QMenuBar *mb = frame->menuBar();
172
 
173
  return ( mb != NULL ) ? mb->sizeHint().height() : 0 ;
174
}
175
 
176
/*
177
 * set Menu bar.
178
 */
179
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_setMenu
180
(JNIEnv *env, jobject obj, jobject mbPeer)
181
{
182
  QMainWindow *frame = (QMainWindow *) getNativeObject( env, obj );
183
  assert( frame );
184
 
185
  QMenuBar *menubar = NULL;
186
 
187
  if( mbPeer != NULL )
188
    {
189
      menubar = (QMenuBar *) getNativeObject( env, mbPeer );
190
      assert( menubar );
191
    }
192
 
193
  mainThread->postEventToMain( new FrameMenuEvent( frame, menubar ) );
194
}
195
 
196
/**
197
 * Set the bounds of the maximized frame
198
 */
199
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_setMaximizedBounds (JNIEnv *env, jobject obj, jint w, jint h)
200
{
201
  QMainWindow *frame = (QMainWindow *) getNativeObject( env, obj );
202
  assert( frame );
203
  // FIXME
204
}
205
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.