1 /*
2 * Copyright (c) 1996, 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
302 for (i = 0; i < nCount; i++) {
303 InsertString(i, strings[i]);
304 delete [] strings[i];
305 }
306 delete[] strings;
307 if (toSelect != -1) {
308 Select(toSelect);
309 }
310
311 AdjustHorizontalScrollbar();
312 }
313
314 /*
315 * There currently is no good place to cache java.awt.Dimension field
316 * ids. If this method gets called a lot, one such place should be found.
317 * -- br 07/18/97.
318 */
319 jobject AwtList::PreferredItemSize(JNIEnv *env)
320 {
321 jobject peer = GetPeer(env);
322 jobject dimension = JNU_CallMethodByName(env, NULL, peer, "preferredSize",
323 "(I)Ljava/awt/Dimension;",
324 1).l;
325
326 DASSERT(!safe_ExceptionOccurred(env));
327 if (dimension == NULL) {
328 return NULL;
329 }
330 /* This size is too big for each item height. */
331 (env)->SetIntField(dimension, AwtDimension::heightID, GetFontHeight(env));
332
333 return dimension;
334 }
335
336 // Every time something gets added to the list, we increase the max width
337 // of items that have ever been added. If it surpasses the width of the
338 // listbox, we show the scrollbar. When things get deleted, we shrink
339 // the scroll region back down and hide the scrollbar, if needed.
340 void AwtList::AdjustHorizontalScrollbar()
341 {
342 // The border width is added to the horizontal extent to ensure that we
|
1 /*
2 * Copyright (c) 1996, 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
302 for (i = 0; i < nCount; i++) {
303 InsertString(i, strings[i]);
304 delete [] strings[i];
305 }
306 delete[] strings;
307 if (toSelect != -1) {
308 Select(toSelect);
309 }
310
311 AdjustHorizontalScrollbar();
312 }
313
314 /*
315 * There currently is no good place to cache java.awt.Dimension field
316 * ids. If this method gets called a lot, one such place should be found.
317 * -- br 07/18/97.
318 */
319 jobject AwtList::PreferredItemSize(JNIEnv *env)
320 {
321 jobject peer = GetPeer(env);
322 jobject dimension = JNU_CallMethodByName(env, NULL, peer, "getPreferredSize",
323 "(I)Ljava/awt/Dimension;",
324 1).l;
325
326 DASSERT(!safe_ExceptionOccurred(env));
327 if (dimension == NULL) {
328 return NULL;
329 }
330 /* This size is too big for each item height. */
331 (env)->SetIntField(dimension, AwtDimension::heightID, GetFontHeight(env));
332
333 return dimension;
334 }
335
336 // Every time something gets added to the list, we increase the max width
337 // of items that have ever been added. If it surpasses the width of the
338 // listbox, we show the scrollbar. When things get deleted, we shrink
339 // the scroll region back down and hide the scrollbar, if needed.
340 void AwtList::AdjustHorizontalScrollbar()
341 {
342 // The border width is added to the horizontal extent to ensure that we
|