OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [gnu/] [java/] [awt/] [peer/] [gtk/] [GtkTextAreaPeer.java] - Blame information for rev 791

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 769 jeremybenn
/* 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., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 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.Rectangle;
45
import java.awt.TextArea;
46
import java.awt.im.InputMethodRequests;
47
import java.awt.peer.TextAreaPeer;
48
import java.awt.peer.TextComponentPeer;
49
 
50
public class GtkTextAreaPeer extends GtkComponentPeer
51
  implements TextComponentPeer, TextAreaPeer
52
{
53
  private static transient int DEFAULT_ROWS = 10;
54
  private static transient int DEFAULT_COLS = 80;
55
 
56
  native void create (int width, int height, int scrollbarVisibility);
57
 
58
  /**
59
   * Overridden to set Font for text widget inside scrolled window.
60
   */
61
  protected native void gtkWidgetModifyFont(String name, int style, int size);
62
 
63
  native void gtkWidgetRequestFocus ();
64
 
65
  public native void connectSignals ();
66
 
67
  public native int getCaretPosition ();
68
  public native void setCaretPosition (int pos);
69
  public native int getSelectionStart ();
70
  public native int getSelectionEnd ();
71
  public native String getText ();
72
  public native void select (int start, int end);
73
  public native void setEditable (boolean state);
74
  public native void setText (String text);
75
 
76
  public int getIndexAtPoint(int x, int y)
77
  {
78
    // FIXME
79
    return 0;
80
  }
81
 
82
  public Rectangle getCharacterBounds (int pos)
83
  {
84
    // FIXME
85
    return null;
86
  }
87
 
88
  public long filterEvents (long filter)
89
  {
90
    // FIXME
91
    return filter;
92
  }
93
 
94
  void create ()
95
  {
96
    Font f = awtComponent.getFont ();
97
 
98
    // By default, Sun sets a TextArea's font when its peer is
99
    // created.  If f != null then the peer's font is set by
100
    // GtkComponent.create.
101
    if (f == null)
102
      {
103
        f = new Font ("Dialog", Font.PLAIN, 12);
104
        awtComponent.setFont (f);
105
      }
106
 
107
    FontMetrics fm = getFontMetrics (f);
108
 
109
    TextArea ta = ((TextArea) awtComponent);
110
    int sizeRows = ta.getRows ();
111
    int sizeCols = ta.getColumns ();
112
 
113
    sizeRows = sizeRows == 0 ? DEFAULT_ROWS : sizeRows;
114
    sizeCols = sizeCols == 0 ? DEFAULT_COLS : sizeCols;
115
 
116
    int width = sizeCols * fm.getMaxAdvance ();
117
    int height = sizeRows * (fm.getMaxDescent () + fm.getMaxAscent ());
118
 
119
    create (width, height, ta.getScrollbarVisibility ());
120
    setEditable (ta.isEditable ());
121
  }
122
 
123
  public GtkTextAreaPeer (TextArea ta)
124
  {
125
    super (ta);
126
 
127
    setText (ta.getText ());
128
    setCaretPosition (0);
129
  }
130
 
131
  public native void insert (String str, int pos);
132
  public native void replaceRange (String str, int start, int end);
133
 
134
  public Dimension getMinimumSize (int rows, int cols)
135
  {
136
    return minimumSize (rows == 0 ? DEFAULT_ROWS : rows,
137
                        cols == 0 ? DEFAULT_COLS : cols);
138
  }
139
 
140
  public Dimension getPreferredSize (int rows, int cols)
141
  {
142
    return preferredSize (rows == 0 ? DEFAULT_ROWS : rows,
143
                          cols == 0 ? DEFAULT_COLS : cols);
144
  }
145
 
146
  native int getHScrollbarHeight ();
147
  native int getVScrollbarWidth ();
148
 
149
  // Deprecated
150
  public Dimension minimumSize (int rows, int cols)
151
  {
152
    TextArea ta = ((TextArea) awtComponent);
153
    int height = 0;
154
    int width = 0;
155
 
156
    if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH
157
        || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_HORIZONTAL_ONLY)
158
      height = getHScrollbarHeight ();
159
 
160
    if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH
161
        || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_VERTICAL_ONLY)
162
      width = getVScrollbarWidth ();
163
 
164
    Font f = awtComponent.getFont ();
165
    if (f == null)
166
      return new Dimension (width, height);
167
 
168
    FontMetrics fm = getFontMetrics (f);
169
 
170
    int sizeRows = rows == 0 ? DEFAULT_ROWS : rows;
171
    int sizeCols = cols == 0 ? DEFAULT_COLS : cols;
172
 
173
    width += sizeCols * fm.getMaxAdvance ();
174
    height += sizeRows * (fm.getMaxDescent () + fm.getMaxAscent ());
175
 
176
    return new Dimension (width, height);
177
  }
178
 
179
  public Dimension preferredSize (int rows, int cols)
180
  {
181
    TextArea ta = ((TextArea) awtComponent);
182
    int height = 0;
183
    int width = 0;
184
 
185
    if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH
186
        || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_HORIZONTAL_ONLY)
187
      height = getHScrollbarHeight ();
188
 
189
    if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH
190
        || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_VERTICAL_ONLY)
191
      width = getVScrollbarWidth ();
192
 
193
    Font f = awtComponent.getFont ();
194
    if (f == null)
195
      return new Dimension (width, height);
196
 
197
    FontMetrics fm = getFontMetrics (f);
198
 
199
    int sizeRows = rows == 0 ? DEFAULT_ROWS : rows;
200
    int sizeCols = cols == 0 ? DEFAULT_COLS : cols;
201
 
202
    width += sizeCols * fm.getMaxAdvance ();
203
    height += sizeRows * (fm.getMaxDescent () + fm.getMaxAscent ());
204
 
205
    return new Dimension (width, height);
206
  }
207
 
208
  public void replaceText (String str, int start, int end)
209
  {
210
    replaceRange (str, start, end);
211
  }
212
 
213
  public void insertText (String str, int pos)
214
  {
215
    insert (str, pos);
216
  }
217
 
218
  public InputMethodRequests getInputMethodRequests()
219
  {
220
      // FIXME: implement
221
    return null;
222
  }
223
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.