< prev index next >

modules/graphics/src/main/native-glass/gtk/GlassWindow.cpp

Print this page


   1 /*
   2  * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 #include <com_sun_glass_ui_gtk_GtkWindow.h>
  26 #include <com_sun_glass_events_WindowEvent.h>
  27 #include <com_sun_glass_events_ViewEvent.h>
  28 
  29 #include <cstdlib>
  30 #include <cstring>
  31 #include "glass_gtkcompat.h"
  32 #include "glass_general.h"
  33 #include "glass_evloop.h"
  34 #include "glass_window.h"
  35 
  36 #define JLONG_TO_WINDOW_CTX(ptr) ((WindowContext*)JLONG_TO_PTR(ptr))
  37 
  38 static WindowFrameType glass_mask_to_window_frame_type(jint mask) {
  39     if (mask & com_sun_glass_ui_gtk_GtkWindow_TRANSPARENT) {
  40         return TRANSPARENT;
  41     }
  42     if (mask & com_sun_glass_ui_gtk_GtkWindow_TITLED) {
  43         return TITLED;
  44     }
  45     return UNTITLED;
  46 }
  47 
  48 static WindowType glass_mask_to_window_type(jint mask) {
  49     if (mask & com_sun_glass_ui_gtk_GtkWindow_POPUP) {
  50         return POPUP;
  51     }


  66     }
  67     if (mask & com_sun_glass_ui_gtk_GtkWindow_MINIMIZABLE) {
  68         func |= GDK_FUNC_MINIMIZE;
  69     }
  70 
  71     return (GdkWMFunction) func;
  72 }
  73 
  74 extern "C" {
  75 
  76 /*
  77  * Class:     com_sun_glass_ui_gtk_GtkWindow
  78  * Method:    _createWindow
  79  * Signature: (JJI)J
  80  */
  81 JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_gtk_GtkWindow__1createWindow
  82   (JNIEnv * env, jobject obj, jlong owner, jlong screen, jint mask)
  83 {
  84     (void)env;
  85 

  86     WindowContext* ctx = new WindowContextTop(obj,
  87             (WindowContext*)JLONG_TO_PTR(owner),
  88             screen,
  89             glass_mask_to_window_frame_type(mask),
  90             glass_mask_to_window_type(mask),
  91             glass_mask_to_wm_function(mask)
  92             );
  93 
  94     return PTR_TO_JLONG(ctx);
  95 }
  96 
  97 /*
  98  * Class:     com_sun_glass_ui_gtk_GtkWindow
  99  * Method:    _createChildWindow
 100  * Signature: (J)J
 101  */
 102 JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_gtk_GtkWindow__1createChildWindow
 103   (JNIEnv * env, jobject obj , jlong owner)
 104 {
 105     (void)env;
 106 
 107     GdkWindow *parent_window = NULL;
 108     GtkWidget *parent_widget = NULL;
 109     WindowContextPlug *parent_ctx = NULL;
 110     WindowContext *ctx = NULL;
 111 
 112     parent_window = GLASS_GDK_WINDOW_LOOKUP_FOR_DISPLAY(
 113                         gdk_display_get_default(),
 114                         (GdkNativeWindow)PTR_TO_JLONG(owner));
 115 
 116     if (parent_window != NULL) {
 117         parent_ctx = (WindowContextPlug *)g_object_get_data(G_OBJECT(parent_window), GDK_WINDOW_DATA_CONTEXT);
 118         // HACK: do not use get_gtk_window()
 119         // the method is intended to return GtkWindow that can be used for FileChooser
 120         // (OK, that's also a hack, but still...)
 121         if (parent_ctx != NULL) {
 122             parent_widget = GTK_WIDGET(parent_ctx->get_gtk_window());
 123         }
 124     }
 125 
 126     if (parent_widget == NULL) {
 127         // If 'owner' is a bad handle, then the child window is created unparented
 128         ctx = new WindowContextPlug(obj, JLONG_TO_PTR(owner));
 129     } else {
 130         ctx = new WindowContextChild(obj,
 131                         JLONG_TO_PTR(owner),
 132                         parent_ctx->gtk_container,
 133                         parent_ctx);
 134     }


   1 /*
   2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 #include <com_sun_glass_ui_gtk_GtkWindow.h>
  26 #include <com_sun_glass_events_WindowEvent.h>
  27 #include <com_sun_glass_events_ViewEvent.h>
  28 
  29 #include <cstdlib>
  30 #include <cstring>

  31 #include "glass_general.h"
  32 #include "glass_evloop.h"
  33 #include "glass_window.h"
  34 
  35 #define JLONG_TO_WINDOW_CTX(ptr) ((WindowContext*)JLONG_TO_PTR(ptr))
  36 
  37 static WindowFrameType glass_mask_to_window_frame_type(jint mask) {
  38     if (mask & com_sun_glass_ui_gtk_GtkWindow_TRANSPARENT) {
  39         return TRANSPARENT;
  40     }
  41     if (mask & com_sun_glass_ui_gtk_GtkWindow_TITLED) {
  42         return TITLED;
  43     }
  44     return UNTITLED;
  45 }
  46 
  47 static WindowType glass_mask_to_window_type(jint mask) {
  48     if (mask & com_sun_glass_ui_gtk_GtkWindow_POPUP) {
  49         return POPUP;
  50     }


  65     }
  66     if (mask & com_sun_glass_ui_gtk_GtkWindow_MINIMIZABLE) {
  67         func |= GDK_FUNC_MINIMIZE;
  68     }
  69 
  70     return (GdkWMFunction) func;
  71 }
  72 
  73 extern "C" {
  74 
  75 /*
  76  * Class:     com_sun_glass_ui_gtk_GtkWindow
  77  * Method:    _createWindow
  78  * Signature: (JJI)J
  79  */
  80 JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_gtk_GtkWindow__1createWindow
  81   (JNIEnv * env, jobject obj, jlong owner, jlong screen, jint mask)
  82 {
  83     (void)env;
  84 
  85     WindowContext* parent = JLONG_TO_WINDOW_CTX(owner);
  86     WindowContext* ctx = new WindowContextTop(obj,
  87             parent,
  88             screen,
  89             glass_mask_to_window_frame_type(mask),
  90             glass_mask_to_window_type(mask),
  91             glass_mask_to_wm_function(mask)
  92             );
  93 
  94     return PTR_TO_JLONG(ctx);
  95 }
  96 
  97 /*
  98  * Class:     com_sun_glass_ui_gtk_GtkWindow
  99  * Method:    _createChildWindow
 100  * Signature: (J)J
 101  */
 102 JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_gtk_GtkWindow__1createChildWindow
 103   (JNIEnv * env, jobject obj , jlong owner)
 104 {
 105     (void)env;
 106 
 107     GdkWindow *parent_window = NULL;
 108     GtkWidget *parent_widget = NULL;
 109     WindowContextPlug *parent_ctx = NULL;
 110     WindowContext *ctx = NULL;
 111 
 112     parent_window = gdk_x11_window_lookup_for_display(
 113                         gdk_display_get_default(),
 114                         (Window)PTR_TO_JLONG(owner));
 115 
 116     if (parent_window != NULL) {
 117         parent_ctx = (WindowContextPlug *)g_object_get_data(G_OBJECT(parent_window), GDK_WINDOW_DATA_CONTEXT);
 118         // HACK: do not use get_gtk_window()
 119         // the method is intended to return GtkWindow that can be used for FileChooser
 120         // (OK, that's also a hack, but still...)
 121         if (parent_ctx != NULL) {
 122             parent_widget = GTK_WIDGET(parent_ctx->get_gtk_window());
 123         }
 124     }
 125 
 126     if (parent_widget == NULL) {
 127         // If 'owner' is a bad handle, then the child window is created unparented
 128         ctx = new WindowContextPlug(obj, JLONG_TO_PTR(owner));
 129     } else {
 130         ctx = new WindowContextChild(obj,
 131                         JLONG_TO_PTR(owner),
 132                         parent_ctx->gtk_container,
 133                         parent_ctx);
 134     }


< prev index next >