qtdialogpeer.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* qtdialogpeer.cpp --
  2. Copyright (C) 2005 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. #include <assert.h>
  32. #include <qdialog.h>
  33. #include <gnu_java_awt_peer_qt_QtDialogPeer.h>
  34. #include "qtcomponent.h"
  35. #include "containers.h"
  36. #include "qtstrings.h"
  37. #include "keybindings.h"
  38. #include "mainthreadinterface.h"
  39. class MyDialog : public QDialog
  40. {
  41. public:
  42. MyDialog(JNIEnv *env, jobject obj, QWidget *parent) : QDialog(parent)
  43. {
  44. setup(env, obj);
  45. }
  46. ~MyDialog()
  47. {
  48. destroy();
  49. }
  50. #define I_KNOW_WHAT_IM_DOING
  51. #define PARENT QDialog
  52. #include "eventmethods.h"
  53. };
  54. class DialogSettingsEvent : public AWTEvent {
  55. private:
  56. QDialog *widget;
  57. bool modal;
  58. bool value;
  59. public:
  60. DialogSettingsEvent(QDialog *w, bool m, bool v) : AWTEvent()
  61. {
  62. widget = w;
  63. modal = m;
  64. value = v;
  65. }
  66. void runEvent()
  67. {
  68. if( modal )
  69. widget->setModal( value );
  70. else
  71. widget->setSizeGripEnabled( value );
  72. }
  73. };
  74. class DialogResizeEvent : public AWTEvent {
  75. private:
  76. QWidget *widget;
  77. bool fixed;
  78. int x, y, w, h;
  79. public:
  80. DialogResizeEvent(QWidget *wid, int x0, int y0, int w0, int h0, bool f)
  81. {
  82. widget = wid;
  83. fixed = f;
  84. x = x0; y = y0;
  85. w = w0; h = h0;
  86. if(w == 0 && h == 0) w = h = 10;
  87. }
  88. void runEvent()
  89. {
  90. if( fixed )
  91. widget->setFixedSize( w, h );
  92. widget->setGeometry( x, y, w, h );
  93. }
  94. };
  95. /*
  96. * Constructs a QDialog native object.
  97. */
  98. JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtDialogPeer_init
  99. (JNIEnv *env, jobject obj)
  100. {
  101. QWidget *parentWidget = (QWidget *) getParentWidget( env, obj );
  102. // QDialog *dialog = new QDialog(parentWidget);
  103. MyDialog *dialog = new MyDialog(env, obj, parentWidget);
  104. assert( dialog );
  105. setNativeObject( env, obj, dialog );
  106. }
  107. /*
  108. * Sets the modality of the dialog.
  109. */
  110. JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtDialogPeer_setModal
  111. (JNIEnv *env, jobject obj, jboolean flag)
  112. {
  113. QDialog *dialog = (QDialog *) getNativeObject( env, obj );
  114. assert( dialog );
  115. mainThread->postEventToMain( new DialogSettingsEvent(dialog, true, (flag == JNI_TRUE)));
  116. }
  117. /*
  118. * Set resizeable.
  119. */
  120. JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtDialogPeer_setResizable
  121. (JNIEnv *env, jobject obj, jboolean flag)
  122. {
  123. QDialog *dialog = (QDialog *) getNativeObject( env, obj );
  124. assert( dialog );
  125. mainThread->postEventToMain( new DialogSettingsEvent(dialog, false, (flag == JNI_TRUE)));
  126. }
  127. /*
  128. * Overloaded to allow for size locking.
  129. */
  130. JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtDialogPeer_setBoundsNative
  131. (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height, jboolean fixed)
  132. {
  133. QWidget *widget = (QWidget *) getNativeObject( env, obj );
  134. assert( widget );
  135. QRect g = widget->geometry();
  136. if(g.x() != x || g.y() != y ||
  137. g.width() != width || g.height() != height)
  138. mainThread->postEventToMain( new DialogResizeEvent( widget, x, y, width, height, (fixed == JNI_TRUE) ) );
  139. }