summaryrefslogtreecommitdiff
path: root/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java
blob: fd2033265c10071e5912386d29cff92cbb4e188f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * GtkTextAreaPeer.java -- Implements TextAreaPeer with GTK
 *
 * Copyright (c) 1998 Free Software Foundation, Inc.
 * Written by James E. Blair <corvus@gnu.org>
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Library General Public License as published 
 * by the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later verion.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; if not, write to the Free Software Foundation
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
 */

package gnu.java.awt.peer.gtk;
import java.awt.peer.*;
import java.awt.*;

public class GtkTextAreaPeer extends GtkTextComponentPeer
  implements TextAreaPeer
{

  native void gtkTextNew (Object edit, String text, int hscroll, int vscroll,
			  boolean visible);
  native void gtkTextGetSize (Object edit, int rows, int cols, int dims[]);
  native String gtkTextGetText (Object edit);
  native void gtkTextSetText (Object edit, String text);
  native void gtkTextInsert (Object edit, String text, int pos);
  native void gtkTextReplace (Object edit, String text, int start, int end);

  public GtkTextAreaPeer (TextArea ta, ComponentPeer cp)
    {
      super (ta);
      String text = ta.getText();
      int hscroll=0;
      int vscroll=0;

      switch (ta.getScrollbarVisibility())
	{
	case TextArea.SCROLLBARS_BOTH:
	  hscroll=vscroll=1;
	  break;
	case TextArea.SCROLLBARS_HORIZONTAL_ONLY:
	  hscroll=1;
	  break;
	case TextArea.SCROLLBARS_VERTICAL_ONLY:
	  vscroll=1;
	  break;
	}

      System.out.println ("TAP: new: "+ text + " - " + hscroll + " - " + vscroll);

      editable = new Object();

      gtkTextNew (editable, text, hscroll, vscroll, ta.isVisible ());

      Point p=ta.getLocation();
      gtkFixedPut (cp,p.x,p.y);
    }

  public Dimension getMinimumSize (int rows, int cols)
    {
      int dims[] = new int[2];

      gtkTextGetSize (editable, rows, cols, dims);

      System.out.println ("TAP: getMinimumSize " + cols + " = " + dims[0] + 
			  " x " + dims[1]);
      
      return (new Dimension (dims[0], dims[1]));
    }

  public Dimension getPreferredSize (int rows, int cols)
    {
      int dims[] = new int[2];

      gtkTextGetSize (editable, rows, cols, dims);

      System.out.println ("TAP: getPreferredSize " + cols + " = " + dims[0] + 
			  " x " + dims[1]);
      
      return (new Dimension (dims[0], dims[1]));
    }
  
  public String getText ()
    {
      System.out.println ("TAP: getText");
      return (gtkTextGetText(editable));
    }

  public void setText (String text)
    {
      System.out.println ("TAP: setText");
      gtkTextSetText (editable, text);
    }

  public void insert (String str, int pos)
    {
      gtkTextInsert (editable, str, pos);
    }

  public void replaceRange (String str, int start, int end)
    {
      gtkTextReplace (editable, str, start, end);
    }

  /* Deprecated */

  public Dimension minimumSize (int rows, int cols)
    {
      return getMinimumSize (rows, cols);
    }

  public Dimension preferredSize (int rows, int cols)
    {
      return getPreferredSize (rows, cols);
    }

  public void replaceText (String str, int start, int end)
    {
      replaceRange (str, start, end);
    }

  public void insertText (String str, int pos)
    {
      insert (str, pos);
    }
}