1 /* GtkTextAreaPeer.java -- Implements TextAreaPeer with GTK 2 Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. 3 4 This file is part of GNU Classpath. 5 6 GNU Classpath is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 GNU Classpath is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GNU Classpath; see the file COPYING. If not, write to the 18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 19 02111-1307 USA. 20 21 Linking this library statically or dynamically with other modules is 22 making a combined work based on this library. Thus, the terms and 23 conditions of the GNU General Public License cover the whole 24 combination. 25 26 As a special exception, the copyright holders of this library give you 27 permission to link this library with independent modules to produce an 28 executable, regardless of the license terms of these independent 29 modules, and to copy and distribute the resulting executable under 30 terms of your choice, provided that you also meet, for each linked 31 independent module, the terms and conditions of the license of that 32 module. An independent module is a module which is not derived from 33 or based on this library. If you modify this library, you may extend 34 this exception to your version of the library, but you are not 35 obligated to do so. If you do not wish to do so, delete this 36 exception statement from your version. */ 37 38 39 package gnu.java.awt.peer.gtk; 40 41 import java.awt.Dimension; 42 import java.awt.Font; 43 import java.awt.FontMetrics; 44 import java.awt.TextArea; 45 import java.awt.peer.TextAreaPeer; 46 47 public class GtkTextAreaPeer extends GtkTextComponentPeer 48 implements TextAreaPeer 49 { create(int width, int height, int scrollbarVisibility)50 native void create (int width, int height, int scrollbarVisibility); 51 gtkSetFont(String name, int style, int size)52 native void gtkSetFont (String name, int style, int size); 53 create()54 void create () 55 { 56 Font f = awtComponent.getFont (); 57 58 // By default, Sun sets a TextArea's font when its peer is 59 // created. If f != null then the peer's font is set by 60 // GtkComponent.create. 61 if (f == null) 62 { 63 f = new Font ("Fixed", Font.PLAIN, 12); 64 awtComponent.setFont (f); 65 } 66 67 FontMetrics fm; 68 if (GtkToolkit.useGraphics2D ()) 69 fm = new GdkClasspathFontPeerMetrics (f); 70 else 71 fm = new GdkFontMetrics (f); 72 73 TextArea ta = ((TextArea) awtComponent); 74 int rows = ta.getRows (); 75 int cols = ta.getColumns (); 76 77 int width = cols * fm.getMaxAdvance (); 78 int height = rows * (fm.getMaxDescent () + fm.getMaxAscent ()); 79 80 create (width, height, ta.getScrollbarVisibility ()); 81 } 82 GtkTextAreaPeer(TextArea ta)83 public GtkTextAreaPeer (TextArea ta) 84 { 85 super (ta); 86 } 87 insert(String str, int pos)88 public native void insert (String str, int pos); replaceRange(String str, int start, int end)89 public native void replaceRange (String str, int start, int end); 90 getMinimumSize(int rows, int cols)91 public Dimension getMinimumSize (int rows, int cols) 92 { 93 return minimumSize (rows, cols); 94 } 95 getPreferredSize(int rows, int cols)96 public Dimension getPreferredSize (int rows, int cols) 97 { 98 return preferredSize (rows, cols); 99 } 100 getHScrollbarHeight()101 native int getHScrollbarHeight (); getVScrollbarWidth()102 native int getVScrollbarWidth (); 103 104 // Deprecated minimumSize(int rows, int cols)105 public Dimension minimumSize (int rows, int cols) 106 { 107 TextArea ta = ((TextArea) awtComponent); 108 int hScrollbarHeight = 0; 109 int vScrollbarWidth = 0; 110 int height = 0; 111 int width = 0; 112 113 if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH 114 || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_HORIZONTAL_ONLY) 115 height = getHScrollbarHeight (); 116 117 if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH 118 || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_VERTICAL_ONLY) 119 width = getVScrollbarWidth (); 120 121 Font f = awtComponent.getFont (); 122 if (f == null) 123 return new Dimension (width, height); 124 125 FontMetrics fm; 126 if (GtkToolkit.useGraphics2D ()) 127 fm = new GdkClasspathFontPeerMetrics (f); 128 else 129 fm = new GdkFontMetrics (f); 130 131 width += cols * fm.getMaxAdvance (); 132 height += rows * (fm.getMaxDescent () + fm.getMaxAscent ()); 133 134 return new Dimension (width, height); 135 } 136 preferredSize(int rows, int cols)137 public Dimension preferredSize (int rows, int cols) 138 { 139 TextArea ta = ((TextArea) awtComponent); 140 int hScrollbarHeight = 0; 141 int vScrollbarWidth = 0; 142 int height = 0; 143 int width = 0; 144 145 if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH 146 || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_HORIZONTAL_ONLY) 147 height = getHScrollbarHeight (); 148 149 if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH 150 || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_VERTICAL_ONLY) 151 width = getVScrollbarWidth (); 152 153 Font f = awtComponent.getFont (); 154 if (f == null) 155 return new Dimension (width, height); 156 157 FontMetrics fm; 158 if (GtkToolkit.useGraphics2D ()) 159 fm = new GdkClasspathFontPeerMetrics (f); 160 else 161 fm = new GdkFontMetrics (f); 162 163 width += cols * fm.getMaxAdvance (); 164 height += rows * (fm.getMaxDescent () + fm.getMaxAscent ()); 165 166 return new Dimension (width, height); 167 } 168 replaceText(String str, int start, int end)169 public void replaceText (String str, int start, int end) 170 { 171 replaceRange (str, start, end); 172 } 173 insertText(String str, int pos)174 public void insertText (String str, int pos) 175 { 176 insert (str, pos); 177 } 178 setFont(Font f)179 public void setFont (Font f) 180 { 181 gtkSetFont (f.getName (), f.getStyle (), f.getSize ()); 182 } 183 } 184