1 /*
2 * Copyright (c) 2005, 2015, 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
141 int x, int y, int width, int height, int placement);
142 private native void native_paint_flat_box(
143 int widgetType, int state, int shadowType, String detail,
144 int x, int y, int width, int height, boolean hasFocus);
145 private native void native_paint_focus(
146 int widgetType, int state, String detail,
147 int x, int y, int width, int height);
148 private native void native_paint_handle(
149 int widgetType, int state, int shadowType, String detail,
150 int x, int y, int width, int height, int orientation);
151 private native void native_paint_hline(
152 int widgetType, int state, String detail,
153 int x, int y, int width, int height);
154 private native void native_paint_option(
155 int widgetType, int synthState, String detail,
156 int x, int y, int width, int height);
157 private native void native_paint_shadow(
158 int widgetType, int state, int shadowType, String detail,
159 int x, int y, int width, int height, int synthState, int dir);
160 private native void native_paint_slider(
161 int widgetType, int state, int shadowType, String detail,
162 int x, int y, int width, int height, int orientation);
163 private native void native_paint_vline(
164 int widgetType, int state, String detail,
165 int x, int y, int width, int height);
166 private native void native_paint_background(
167 int widgetType, int state, int x, int y, int width, int height);
168 private native Object native_get_gtk_setting(int property);
169 private native void nativeSetRangeValue(int widgetType, double value,
170 double min, double max,
171 double visible);
172
173 private native void nativeStartPainting(int w, int h);
174 private native int nativeFinishPainting(int[] buffer, int width, int height);
175 private native void native_switch_theme();
176
177 static {
178 // Make sure the awt toolkit is loaded so we have access to native
179 // methods.
180 Toolkit.getDefaultToolkit();
181
182 // Initialize regionToWidgetTypeMap
474 state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
475 int widget = getWidgetType(context.getComponent(), id).ordinal();
476 native_paint_hline(widget, state, detail, x - x0, y - y0, w, h);
477 }
478
479 public void paintOption(Graphics g, SynthContext context,
480 Region id, String detail, int x, int y, int w, int h) {
481
482 int synthState = context.getComponentState();
483 int widget = getWidgetType(context.getComponent(), id).ordinal();
484 native_paint_option(widget, synthState, detail, x - x0, y - y0, w, h);
485 }
486
487 public void paintShadow(Graphics g, SynthContext context,
488 Region id, int state, ShadowType shadowType, String detail,
489 int x, int y, int w, int h) {
490
491 int gtkState =
492 GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
493 int synthState = context.getComponentState();
494 int dir = getTextDirection(context);
495 int widget = getWidgetType(context.getComponent(), id).ordinal();
496 native_paint_shadow(widget, gtkState, shadowType.ordinal(), detail,
497 x - x0, y - y0, w, h, synthState, dir);
498 }
499
500 public void paintSlider(Graphics g, SynthContext context,
501 Region id, int state, ShadowType shadowType, String detail,
502 int x, int y, int w, int h, Orientation orientation) {
503
504 state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
505 int widget = getWidgetType(context.getComponent(), id).ordinal();
506 native_paint_slider(widget, state, shadowType.ordinal(), detail,
507 x - x0, y - y0, w, h, orientation.ordinal());
508 }
509
510 public void paintVline(Graphics g, SynthContext context,
511 Region id, int state, String detail, int x, int y, int w, int h) {
512
513 state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
514 int widget = getWidgetType(context.getComponent(), id).ordinal();
515 native_paint_vline(widget, state, detail, x - x0, y - y0, w, h);
516 }
517
518 public void paintBackground(Graphics g, SynthContext context,
519 Region id, int state, Color color, int x, int y, int w, int h) {
520
521 state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
522 int widget = getWidgetType(context.getComponent(), id).ordinal();
523 native_paint_background(widget, state, x - x0, y - y0, w, h);
524 }
525
526 private final static ColorModel[] COLOR_MODELS = {
527 // Transparency.OPAQUE
561 }
562
563 /*
564 * Allocate a native offscreen buffer of the specified size.
565 */
566 public void startPainting(Graphics g,
567 int x, int y, int w, int h, Object... args) {
568 nativeStartPainting(w, h);
569 x0 = x;
570 y0 = y;
571 w0 = w;
572 h0 = h;
573 graphics = g;
574 cacheArgs = args;
575 }
576
577 /**
578 * Convenience method that delegates to finishPainting() with
579 * caching enabled.
580 */
581 public void finishPainting() {
582 finishPainting(true);
583 }
584
585 /**
586 * Called to indicate that painting is finished. We create a new
587 * BufferedImage from the offscreen buffer, (optionally) cache it,
588 * and paint it.
589 */
590 public void finishPainting(boolean useCache) {
591 DataBufferInt dataBuffer = new DataBufferInt(w0 * h0);
592 // Note that stealData() requires a markDirty() afterwards
593 // since we modify the data in it.
594 int transparency =
595 nativeFinishPainting(SunWritableRaster.stealData(dataBuffer, 0),
596 w0, h0);
597 SunWritableRaster.markDirty(dataBuffer);
598
599 int[] bands = BAND_OFFSETS[transparency - 1];
600 WritableRaster raster = Raster.createPackedRaster(
601 dataBuffer, w0, h0, w0, bands, null);
602
603 ColorModel cm = COLOR_MODELS[transparency - 1];
604 Image img = new BufferedImage(cm, raster, false, null);
605 if (useCache) {
606 cache.setImage(getClass(), null, w0, h0, cacheArgs, img);
607 }
608 graphics.drawImage(img, x0, y0, null);
609 }
610
611 /**
612 * Notify native layer of theme change, and flush cache
613 */
614 public void themeChanged() {
615 synchronized(sun.awt.UNIXToolkit.GTK_LOCK) {
616 native_switch_theme();
617 }
618 cache.flush();
619 }
620
621 /* GtkSettings enum mirrors that in gtk2_interface.h */
622 public Object getSetting(Settings property) {
623 synchronized(sun.awt.UNIXToolkit.GTK_LOCK) {
624 return native_get_gtk_setting(property.ordinal());
625 }
626 }
627
628 /**
|
1 /*
2 * Copyright (c) 2005, 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
141 int x, int y, int width, int height, int placement);
142 private native void native_paint_flat_box(
143 int widgetType, int state, int shadowType, String detail,
144 int x, int y, int width, int height, boolean hasFocus);
145 private native void native_paint_focus(
146 int widgetType, int state, String detail,
147 int x, int y, int width, int height);
148 private native void native_paint_handle(
149 int widgetType, int state, int shadowType, String detail,
150 int x, int y, int width, int height, int orientation);
151 private native void native_paint_hline(
152 int widgetType, int state, String detail,
153 int x, int y, int width, int height);
154 private native void native_paint_option(
155 int widgetType, int synthState, String detail,
156 int x, int y, int width, int height);
157 private native void native_paint_shadow(
158 int widgetType, int state, int shadowType, String detail,
159 int x, int y, int width, int height, int synthState, int dir);
160 private native void native_paint_slider(
161 int widgetType, int state, int shadowType, String detail, int x,
162 int y, int width, int height, int orientation, boolean hasFocus);
163 private native void native_paint_vline(
164 int widgetType, int state, String detail,
165 int x, int y, int width, int height);
166 private native void native_paint_background(
167 int widgetType, int state, int x, int y, int width, int height);
168 private native Object native_get_gtk_setting(int property);
169 private native void nativeSetRangeValue(int widgetType, double value,
170 double min, double max,
171 double visible);
172
173 private native void nativeStartPainting(int w, int h);
174 private native int nativeFinishPainting(int[] buffer, int width, int height);
175 private native void native_switch_theme();
176
177 static {
178 // Make sure the awt toolkit is loaded so we have access to native
179 // methods.
180 Toolkit.getDefaultToolkit();
181
182 // Initialize regionToWidgetTypeMap
474 state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
475 int widget = getWidgetType(context.getComponent(), id).ordinal();
476 native_paint_hline(widget, state, detail, x - x0, y - y0, w, h);
477 }
478
479 public void paintOption(Graphics g, SynthContext context,
480 Region id, String detail, int x, int y, int w, int h) {
481
482 int synthState = context.getComponentState();
483 int widget = getWidgetType(context.getComponent(), id).ordinal();
484 native_paint_option(widget, synthState, detail, x - x0, y - y0, w, h);
485 }
486
487 public void paintShadow(Graphics g, SynthContext context,
488 Region id, int state, ShadowType shadowType, String detail,
489 int x, int y, int w, int h) {
490
491 int gtkState =
492 GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
493 int synthState = context.getComponentState();
494 Container parent = context.getComponent().getParent();
495 if(GTKLookAndFeel.is3()) {
496 if (parent != null && parent.getParent() instanceof JComboBox) {
497 if (parent.getParent().hasFocus()) {
498 synthState |= SynthConstants.FOCUSED;
499 }
500 }
501 }
502 int dir = getTextDirection(context);
503 int widget = getWidgetType(context.getComponent(), id).ordinal();
504 native_paint_shadow(widget, gtkState, shadowType.ordinal(), detail,
505 x - x0, y - y0, w, h, synthState, dir);
506 }
507
508 public void paintSlider(Graphics g, SynthContext context,
509 Region id, int state, ShadowType shadowType, String detail, int x,
510 int y, int w, int h, Orientation orientation, boolean hasFocus) {
511
512 state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
513 int widget = getWidgetType(context.getComponent(), id).ordinal();
514 native_paint_slider(widget, state, shadowType.ordinal(), detail,
515 x - x0, y - y0, w, h, orientation.ordinal(), hasFocus);
516 }
517
518 public void paintVline(Graphics g, SynthContext context,
519 Region id, int state, String detail, int x, int y, int w, int h) {
520
521 state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
522 int widget = getWidgetType(context.getComponent(), id).ordinal();
523 native_paint_vline(widget, state, detail, x - x0, y - y0, w, h);
524 }
525
526 public void paintBackground(Graphics g, SynthContext context,
527 Region id, int state, Color color, int x, int y, int w, int h) {
528
529 state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
530 int widget = getWidgetType(context.getComponent(), id).ordinal();
531 native_paint_background(widget, state, x - x0, y - y0, w, h);
532 }
533
534 private final static ColorModel[] COLOR_MODELS = {
535 // Transparency.OPAQUE
569 }
570
571 /*
572 * Allocate a native offscreen buffer of the specified size.
573 */
574 public void startPainting(Graphics g,
575 int x, int y, int w, int h, Object... args) {
576 nativeStartPainting(w, h);
577 x0 = x;
578 y0 = y;
579 w0 = w;
580 h0 = h;
581 graphics = g;
582 cacheArgs = args;
583 }
584
585 /**
586 * Convenience method that delegates to finishPainting() with
587 * caching enabled.
588 */
589 public BufferedImage finishPainting() {
590 return finishPainting(true);
591 }
592
593 /**
594 * Called to indicate that painting is finished. We create a new
595 * BufferedImage from the offscreen buffer, (optionally) cache it,
596 * and paint it.
597 */
598 public BufferedImage finishPainting(boolean useCache) {
599 DataBufferInt dataBuffer = new DataBufferInt(w0 * h0);
600 // Note that stealData() requires a markDirty() afterwards
601 // since we modify the data in it.
602 int transparency =
603 nativeFinishPainting(SunWritableRaster.stealData(dataBuffer, 0),
604 w0, h0);
605 SunWritableRaster.markDirty(dataBuffer);
606
607 int[] bands = BAND_OFFSETS[transparency - 1];
608 WritableRaster raster = Raster.createPackedRaster(
609 dataBuffer, w0, h0, w0, bands, null);
610
611 ColorModel cm = COLOR_MODELS[transparency - 1];
612 BufferedImage img = new BufferedImage(cm, raster, false, null);
613 if (useCache) {
614 cache.setImage(getClass(), null, w0, h0, cacheArgs, img);
615 }
616 graphics.drawImage(img, x0, y0, null);
617 return img;
618 }
619
620 /**
621 * Notify native layer of theme change, and flush cache
622 */
623 public void themeChanged() {
624 synchronized(sun.awt.UNIXToolkit.GTK_LOCK) {
625 native_switch_theme();
626 }
627 cache.flush();
628 }
629
630 /* GtkSettings enum mirrors that in gtk2_interface.h */
631 public Object getSetting(Settings property) {
632 synchronized(sun.awt.UNIXToolkit.GTK_LOCK) {
633 return native_get_gtk_setting(property.ordinal());
634 }
635 }
636
637 /**
|