/[classpath]/classpath/native/jni/qt-peer/qtframepeer.cpp
ViewVC logotype

Diff of /classpath/native/jni/qt-peer/qtframepeer.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2.2.1 by gnu_andrew, Tue Aug 16 16:22:39 2005 UTC revision 1.2.2.2 by gnu_andrew, Sat Sep 10 15:32:04 2005 UTC
# Line 35  this exception to your version of the li Line 35  this exception to your version of the li
35  obligated to do so.  If you do not wish to do so, delete this  obligated to do so.  If you do not wish to do so, delete this
36  exception statement from your version. */  exception statement from your version. */
37    
38    #include <assert.h>
39  #include <QApplication>  #include <QApplication>
40    #include <QIcon>
41  #include <QMainWindow>  #include <QMainWindow>
42  #include <QMenuBar>  #include <QMenuBar>
43    #include <QPixmap>
44  #include <QToolBar>  #include <QToolBar>
45  #include <QThread>  #include <QThread>
46  #include <gnu_java_awt_peer_qt_QtFramePeer.h>  #include <gnu_java_awt_peer_qt_QtFramePeer.h>
47  #include "qtcomponent.h"  #include "qtcomponent.h"
48  #include "qtstrings.h"  #include "qtstrings.h"
49    #include "qtimage.h"
50  #include "containers.h"  #include "containers.h"
51  #include "keybindings.h"  #include "keybindings.h"
52  #include "mainthreadinterface.h"  #include "mainthreadinterface.h"
# Line 52  exception statement from your version. * Line 56  exception statement from your version. *
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    }    }
71    
72  #define I_KNOW_WHAT_IM_DOING  #define I_KNOW_WHAT_IM_DOING
73  #define PARENT QMainWindow  #define PARENT QMainWindow
74  #include "eventmethods.cpp"  #include "eventmethods.h"
75  };  };
76    
77  /**  /**
# Line 97  class FrameMenuEvent : public AWTEvent { Line 101  class FrameMenuEvent : public AWTEvent {
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;  
     if( mb->isVisible() )  
       v = mb->size().height();  
   
     if(v <= 0 || v >= 0xFFFFF )  // Work around for strange values.  
       v = MenuSizeDefault;  
   
     *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 )
# Line 138  QWidget *frameChildWidget( JNIEnv *env, Line 111  QWidget *frameChildWidget( JNIEnv *env,
111                                             "getPeer",                                             "getPeer",
112                                             "()Ljava/awt/peer/ComponentPeer;" );                                             "()Ljava/awt/peer/ComponentPeer;" );
113    assert(getPeerMID);    assert(getPeerMID);
   jobject framepeerobj = env->CallObjectMethod( component, getPeerMID, 0);  
114    
115    QMainWindow *window = (QMainWindow *)getNativeObject(env, framepeerobj);    jobject framepeerobj = env->CallObjectMethod( component, getPeerMID, 0);
116      if( framepeerobj == NULL )
117        return (QWidget *)NULL;
118    
119    return window->centralWidget();    MyFrame *window = (MyFrame *)getNativeObject(env, framepeerobj);
120      assert( window );
121      return window;
122  }  }
123    
124  /*  /*
# Line 151  QWidget *frameChildWidget( JNIEnv *env, Line 127  QWidget *frameChildWidget( JNIEnv *env,
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 );
133      setNativeObject( env, obj, frame );
134    }
135    
136    QWidget *central = new QWidget( frame );  /**
137    assert( central );   * 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    frame->setCentralWidget( central );    QIcon *i;
146    setNativeObject( env, obj, frame );    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  /**  /**
# Line 170  JNIEXPORT jint JNICALL Java_gnu_java_awt Line 168  JNIEXPORT jint JNICALL Java_gnu_java_awt
168    QMainWindow *frame = (QMainWindow *) getNativeObject( env, obj );    QMainWindow *frame = (QMainWindow *) getNativeObject( env, obj );
169    assert( frame );    assert( frame );
170    
171    int value = 0;    QMenuBar *mb = frame->menuBar();
   mainThread->postEventToMain( new FrameGetMenuHeightEvent( frame, &value ) );  
   
   while(value == 0); // (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  /*  /*
# Line 199  JNIEXPORT void JNICALL Java_gnu_java_awt Line 193  JNIEXPORT void JNICALL Java_gnu_java_awt
193    mainThread->postEventToMain( new FrameMenuEvent( frame, menubar ) );    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    

Legend:
Removed from v.1.2.2.1  
changed lines
  Added in v.1.2.2.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26