root/java/org/gnu/emacs/EmacsDialogButtonLayout.java

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. onMeasure
  2. onLayout

     1 /* Communication module for Android terminals.  -*- c-file-style: "GNU" -*-
     2 
     3 Copyright (C) 2023 Free Software Foundation, Inc.
     4 
     5 This file is part of GNU Emacs.
     6 
     7 GNU Emacs is free software: you can redistribute it and/or modify
     8 it under the terms of the GNU General Public License as published by
     9 the Free Software Foundation, either version 3 of the License, or (at
    10 your option) any later version.
    11 
    12 GNU Emacs is distributed in the hope that it will be useful,
    13 but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 GNU General Public License for more details.
    16 
    17 You should have received a copy of the GNU General Public License
    18 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
    19 
    20 package org.gnu.emacs;
    21 
    22 
    23 
    24 import android.content.Context;
    25 
    26 import android.view.View;
    27 import android.view.View.MeasureSpec;
    28 import android.view.ViewGroup;
    29 
    30 
    31 
    32 /* This ``view group'' implements a container widget for multiple
    33    buttons of the type found in pop-up dialogs.  It is used when
    34    displaying a dialog box that contains more than three buttons, as
    35    the default dialog box widget is not capable of holding more than
    36    that many.  */
    37 
    38 
    39 
    40 public final class EmacsDialogButtonLayout extends ViewGroup
    41 {
    42   public
    43   EmacsDialogButtonLayout (Context context)
    44   {
    45     super (context);
    46   }
    47 
    48   @Override
    49   protected void
    50   onMeasure (int widthMeasureSpec, int heightMeasureSpec)
    51   {
    52     int width, count, i, x, y, height, spec, tempSpec;
    53     View view;
    54 
    55     /* Obtain the width of this widget and create the measure
    56        specification used to measure children.  */
    57 
    58     width = MeasureSpec.getSize (widthMeasureSpec);
    59     spec = MeasureSpec.makeMeasureSpec (0, MeasureSpec.UNSPECIFIED);
    60     tempSpec
    61       = MeasureSpec.makeMeasureSpec (width, MeasureSpec.AT_MOST);
    62     x = y = height = 0;
    63 
    64     /* Run through each widget.  */
    65 
    66     count = getChildCount ();
    67 
    68     for (i = 0; i < count; ++i)
    69       {
    70         view = getChildAt (i);
    71 
    72         /* Measure this view.  */
    73         view.measure (spec, spec);
    74 
    75         if (width - x < view.getMeasuredWidth ())
    76           {
    77             /* Move onto the next line, unless this line is empty.  */
    78 
    79             if (x != 0)
    80               {
    81                 y += height;
    82                 height = x = 0;
    83               }
    84 
    85             if (view.getMeasuredWidth () > width)
    86               /* Measure the view again, this time forcing it to be at
    87                  most width wide, if it is not already.  */
    88               view.measure (tempSpec, spec);
    89           }
    90 
    91         height = Math.max (height, view.getMeasuredHeight ());
    92         x += view.getMeasuredWidth ();
    93       }
    94 
    95     /* Now set the measured size of this widget.  */
    96     setMeasuredDimension (width, y + height);
    97   }
    98 
    99   @Override
   100   protected void
   101   onLayout (boolean changed, int left, int top, int right,
   102             int bottom)
   103   {
   104     int width, count, i, x, y, height, spec, tempSpec;
   105     View view;
   106 
   107     /* Obtain the width of this widget and create the measure
   108        specification used to measure children.  */
   109 
   110     width = getMeasuredWidth ();
   111     spec = MeasureSpec.makeMeasureSpec (0, MeasureSpec.UNSPECIFIED);
   112     tempSpec
   113       = MeasureSpec.makeMeasureSpec (width, MeasureSpec.AT_MOST);
   114     x = y = height = 0;
   115 
   116     /* Run through each widget.  */
   117 
   118     count = getChildCount ();
   119 
   120     for (i = 0; i < count; ++i)
   121       {
   122         view = getChildAt (i);
   123 
   124         /* Measure this view.  */
   125         view.measure (spec, spec);
   126 
   127         if (width - x < view.getMeasuredWidth ())
   128           {
   129             /* Move onto the next line, unless this line is empty.  */
   130 
   131             if (x != 0)
   132               {
   133                 y += height;
   134                 height = x = 0;
   135               }
   136 
   137             if (view.getMeasuredWidth () > width)
   138               /* Measure the view again, this time forcing it to be at
   139                  most width wide, if it is not already.  */
   140               view.measure (tempSpec, spec);
   141           }
   142 
   143         /* Now assign this view its position.  */
   144         view.layout (x, y, x + view.getMeasuredWidth (),
   145                      y + view.getMeasuredHeight ());
   146 
   147         /* And move on to the next widget.  */
   148         height = Math.max (height, view.getMeasuredHeight ());
   149         x += view.getMeasuredWidth ();
   150       }
   151   }
   152 };

/* [<][>][^][v][top][bottom][index][help] */