56 |
/* |
/* |
57 |
* Our QMainWindow subclass |
* Our QMainWindow subclass |
58 |
*/ |
*/ |
59 |
class MyWindow : public QMainWindow |
class MyFrame : public QMainWindow |
60 |
{ |
{ |
61 |
public: |
public: |
62 |
MyWindow(JNIEnv *env, jobject obj) : QMainWindow(0, Qt::Window ) |
MyFrame(JNIEnv *env, jobject obj) : QMainWindow(0, Qt::Window ) |
63 |
{ |
{ |
64 |
setup(env, obj); |
setup(env, obj); |
65 |
} |
} |
66 |
|
|
67 |
~MyWindow() |
~MyFrame() |
68 |
{ |
{ |
69 |
destroy(); |
destroy(); |
70 |
} |
} |
101 |
}; |
}; |
102 |
|
|
103 |
/** |
/** |
|
* Event wrapper for getting the menu bar height |
|
|
*/ |
|
|
class FrameGetMenuHeightEvent : public AWTEvent { |
|
|
|
|
|
private: |
|
|
QMainWindow *frame; |
|
|
int **value; |
|
|
|
|
|
public: |
|
|
FrameGetMenuHeightEvent(QMainWindow *w, int **v) : AWTEvent() |
|
|
{ |
|
|
frame = w; |
|
|
value = v; |
|
|
} |
|
|
|
|
|
void runEvent() |
|
|
{ |
|
|
QMenuBar *mb = frame->menuBar(); |
|
|
assert( mb ); |
|
|
int *v = (int *)malloc( sizeof( int ) ); |
|
|
*v = mb->sizeHint().height(); |
|
|
*value = v; |
|
|
} |
|
|
}; |
|
|
|
|
|
/** |
|
104 |
* Returns the child widget for the frame (the centralWidget in qt terms) |
* Returns the child widget for the frame (the centralWidget in qt terms) |
105 |
*/ |
*/ |
106 |
QWidget *frameChildWidget( JNIEnv *env, jobject component ) |
QWidget *frameChildWidget( JNIEnv *env, jobject component ) |
116 |
if( framepeerobj == NULL ) |
if( framepeerobj == NULL ) |
117 |
return (QWidget *)NULL; |
return (QWidget *)NULL; |
118 |
|
|
119 |
MyWindow *window = (MyWindow *)getNativeObject(env, framepeerobj); |
MyFrame *window = (MyFrame *)getNativeObject(env, framepeerobj); |
120 |
assert( window ); |
assert( window ); |
121 |
return window; |
return window; |
122 |
} |
} |
127 |
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_init |
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_init |
128 |
(JNIEnv *env, jobject obj) |
(JNIEnv *env, jobject obj) |
129 |
{ |
{ |
130 |
MyWindow *frame = new MyWindow(env, obj); |
MyFrame *frame = new MyFrame(env, obj); |
131 |
assert( frame ); |
assert( frame ); |
132 |
|
frame->addToolBarBreak ( Qt::BottomToolBarArea ); |
|
QWidget *central = new QWidget( frame ); |
|
|
assert( central ); |
|
|
|
|
133 |
setNativeObject( env, obj, frame ); |
setNativeObject( env, obj, frame ); |
134 |
} |
} |
135 |
|
|
168 |
QMainWindow *frame = (QMainWindow *) getNativeObject( env, obj ); |
QMainWindow *frame = (QMainWindow *) getNativeObject( env, obj ); |
169 |
assert( frame ); |
assert( frame ); |
170 |
|
|
171 |
int *value = NULL; |
QMenuBar *mb = frame->menuBar(); |
|
mainThread->postEventToMain( new FrameGetMenuHeightEvent( frame, &value ) ); |
|
|
|
|
|
while(value == NULL); // (Busy) wait for the value to |
|
|
// get set by the main thread. |
|
172 |
|
|
173 |
return (jint)(*value); |
return ( mb != NULL ) ? mb->sizeHint().height() : 0 ; |
174 |
} |
} |
175 |
|
|
176 |
/* |
/* |