componentevent.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* componentevent.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 <QWidget>
  33. #include <QPoint>
  34. #include "componentevent.h"
  35. AWTInitEvent::AWTInitEvent(JNIEnv *env, jobject obj) : AWTEvent()
  36. {
  37. env->GetJavaVM( &vm );
  38. target = env->NewGlobalRef( obj );
  39. }
  40. void AWTInitEvent::runEvent()
  41. {
  42. JNIEnv *env;
  43. vm->GetEnv((void **)&env, JNI_VERSION_1_1);
  44. jclass targetCls = env->GetObjectClass( target );
  45. // call init()
  46. jmethodID mID = env->GetMethodID( targetCls,
  47. "init",
  48. "()V" );
  49. env->CallVoidMethod( target, mID );
  50. // call notify()
  51. mID = env->GetMethodID( targetCls,
  52. "notify",
  53. "()V" );
  54. assert(mID != NULL);
  55. env->MonitorEnter( target );
  56. env->CallVoidMethod( target, mID );
  57. env->MonitorExit( target );
  58. env->DeleteGlobalRef( target );
  59. }
  60. AWTShowEvent::AWTShowEvent(QWidget *w, bool v) : AWTEvent()
  61. {
  62. widget = w;
  63. visible = v;
  64. }
  65. void AWTShowEvent::runEvent()
  66. {
  67. widget->setVisible( visible );
  68. }
  69. AWTEnableEvent::AWTEnableEvent(QWidget *w, bool v) : AWTEvent()
  70. {
  71. widget = w;
  72. enabled = v;
  73. }
  74. void AWTEnableEvent::runEvent()
  75. {
  76. widget->setEnabled( enabled );
  77. }
  78. AWTCursorEvent::AWTCursorEvent(QWidget *w, Qt::CursorShape s) : AWTEvent()
  79. {
  80. widget = w;
  81. shape = s;
  82. }
  83. void AWTCursorEvent::runEvent()
  84. {
  85. QCursor *s = new QCursor(shape);
  86. widget->setCursor( *s );
  87. }
  88. AWTResizeEvent::AWTResizeEvent(QWidget *wid, int x0, int y0, int w0, int h0)
  89. {
  90. widget = wid;
  91. x = x0; y = y0;
  92. w = w0; h = h0;
  93. if(w == 0 && h == 0) w = h = 10;
  94. }
  95. void AWTResizeEvent::runEvent()
  96. {
  97. QRect g = widget->geometry();
  98. if(g.x() != x || g.y() != y || g.width() != w || g.height() != h)
  99. widget->setGeometry( x, y, w, h );
  100. }
  101. AWTBackgroundEvent::AWTBackgroundEvent(QWidget *wid, bool fg, QColor *clr)
  102. {
  103. widget = wid;
  104. foreground = fg;
  105. color = clr;
  106. }
  107. void AWTBackgroundEvent::runEvent()
  108. {
  109. QPalette p = widget->palette();
  110. if (foreground)
  111. {
  112. p.setColor(QPalette::Active, QPalette::Foreground, *color);
  113. p.setColor(QPalette::Active, QPalette::Text, *color);
  114. }
  115. else
  116. {
  117. p.setColor(QPalette::Active, QPalette::Background, *color);
  118. p.setColor(QPalette::Active, QPalette::Button, *color);
  119. p.setColor(QPalette::Active, QPalette::Base, *color);
  120. p.setColor(QPalette::Active, QPalette::AlternateBase, *color);
  121. }
  122. widget->setPalette(p);
  123. widget->repaint();
  124. delete color;
  125. }
  126. AWTGetOriginEvent::AWTGetOriginEvent(QWidget *w, JNIEnv *env, jobject obj) : AWTEvent()
  127. {
  128. widget = w;
  129. env->GetJavaVM( &vm );
  130. target = env->NewGlobalRef( obj );
  131. }
  132. void AWTGetOriginEvent::runEvent()
  133. {
  134. JNIEnv *env;
  135. vm->GetEnv((void **)&env, JNI_VERSION_1_1);
  136. jclass targetCls = env->GetObjectClass( target );
  137. QPoint *p = new QPoint( widget->mapToGlobal( QPoint(0, 0) ) );
  138. // call init()
  139. jmethodID mID = env->GetMethodID( targetCls,
  140. "setLocation",
  141. "(II)V" );
  142. env->CallVoidMethod( target, mID, p->x(), p->y() );
  143. delete p;
  144. // call notify()
  145. mID = env->GetMethodID( targetCls,
  146. "notify",
  147. "()V" );
  148. assert(mID != NULL);
  149. env->MonitorEnter( target );
  150. env->CallVoidMethod( target, mID );
  151. env->MonitorExit( target );
  152. env->DeleteGlobalRef( target );
  153. }
  154. GetSizeEvent::GetSizeEvent(QWidget *w, JNIEnv *env, jobject obj, bool p) : AWTEvent()
  155. {
  156. widget = w;
  157. env->GetJavaVM( &vm );
  158. target = env->NewGlobalRef( obj );
  159. pref = p;
  160. }
  161. void GetSizeEvent::runEvent()
  162. {
  163. JNIEnv *env;
  164. vm->GetEnv((void **)&env, JNI_VERSION_1_1);
  165. jclass targetCls = env->GetObjectClass( target );
  166. QPoint *p = new QPoint( widget->mapToGlobal( QPoint(0, 0) ) );
  167. QSize s;
  168. if( pref )
  169. s = widget->sizeHint();
  170. else
  171. s = widget->minimumSizeHint();
  172. // call init()
  173. jmethodID mID = env->GetMethodID( targetCls,
  174. "setSize",
  175. "(II)V" );
  176. env->CallVoidMethod( target, mID, s.width(), s.height() );
  177. // call notify()
  178. mID = env->GetMethodID( targetCls,
  179. "notify",
  180. "()V" );
  181. assert(mID != NULL);
  182. env->MonitorEnter( target );
  183. env->CallVoidMethod( target, mID );
  184. env->MonitorExit( target );
  185. env->DeleteGlobalRef( target );
  186. }