Exemplo n.º 1
0
/* Calculates the ideal size of the toolbar */
static void _etk_toolbar_size_request(Etk_Widget *widget, Etk_Size *size)
{
   Etk_Toolbar *toolbar;

   if (!(toolbar = ETK_TOOLBAR(widget)) || !size)
      return;
   etk_widget_size_request(ETK_WIDGET(toolbar->box), size);
}
Exemplo n.º 2
0
/* Recursively requests the size of all the widgets */
static void _etk_main_size_request_recursive(Etk_Widget *widget)
{
   Eina_List *l;
   Etk_Size unused_size;

   if (!widget)
      return;

   etk_widget_size_request(widget, &unused_size);
   for (l = widget->children; l; l = l->next)
      _etk_main_size_request_recursive(ETK_WIDGET(l->data));
}
Exemplo n.º 3
0
/* Resizes the toolbar to the allocated size */
static void _etk_toolbar_size_allocate(Etk_Widget *widget, Etk_Geometry geometry)
{
   Etk_Toolbar *toolbar;
   Etk_Size size;

   if (!(toolbar = ETK_TOOLBAR(widget)))
      return;

   etk_widget_size_request(toolbar->box, &size);
   geometry.w = ETK_MAX(geometry.w, size.w);
   etk_widget_size_allocate(ETK_WIDGET(toolbar->box), geometry);
}
Exemplo n.º 4
0
/* Calculates the ideal size of the vbox */
static void _etk_vbox_size_request(Etk_Widget *widget, Etk_Size *size)
{
   Etk_VBox *vbox;
   Etk_Box *box;
   Etk_Container *container;
   Etk_Box_Cell *cell;
   Etk_Widget *child;
   Etk_Size child_size;
   int num_visible_children;
   int i, j;

   if (!(vbox = ETK_VBOX(widget)) || !size)
      return;

   box = ETK_BOX(vbox);
   container = ETK_CONTAINER(vbox);
   size->w = 0;
   size->h = 0;
   num_visible_children = 0;

   for (i = 0; i < 2; i++)
   {
      box->request_sizes[i] = realloc(box->request_sizes[i], box->cells_count[i] * sizeof(int));
      for (cell = box->first_cell[i], j = 0; cell; cell = cell->next, j++)
      {
         child = cell->child;
         box->request_sizes[i][j] = 0;

         if (!etk_widget_is_visible(child))
            continue;

         etk_widget_size_request(child, &child_size);

         if (box->homogeneous)
         {
            if (size->h < child_size.h + 2 * cell->padding)
               size->h = child_size.h + 2 * cell->padding;
         }
         else
         {
            box->request_sizes[i][j] = child_size.h + 2 * cell->padding;
            size->h += box->request_sizes[i][j];
         }

         if (size->w < child_size.w)
            size->w = child_size.w;

         num_visible_children++;
      }
   }
   if (box->homogeneous)
   {
      for (i = 0; i < 2; i++)
      {
         for (j = 0; j < box->cells_count[i]; j++)
            box->request_sizes[i][j] = size->h;
      }
      size->h *= num_visible_children;
   }
   if (num_visible_children > 1)
      size->h += (num_visible_children - 1) * box->spacing;

   size->w += 2 * container->border_width;
   size->h += 2 * container->border_width;
}
Exemplo n.º 5
0
/* Calculates the ideal size of the table */
static void _etk_table_size_request(Etk_Widget *widget, Etk_Size *size_requisition)
{
   Etk_Table *table;
   Etk_Widget *child;
   Etk_Table_Cell *cell;
   Etk_Size child_size;
   Etk_Bool hexpand = ETK_FALSE, vexpand = ETK_FALSE;
   Eina_List *l;
   int i;

   if (!(table = ETK_TABLE(widget)) || !size_requisition)
      return;

   if (!table->cells)
   {
      size_requisition->w = 0;
      size_requisition->h = 0;
   }
   else
   {
      /*********************************************
       * Phase 1: We calculate the width of the cols of the table
       *********************************************/

      /* Horizontally-homogeneous table */
      if (table->homogeneous & ETK_TABLE_HHOMOGENEOUS)
      {
         int max_col_width = CELL_MIN_SIZE;
         int cell_size;

         /* We calculate the maximum size of a cell */
         for (l = table->cells_list; l; l = l->next)
         {
            cell = l->data;
            child = cell->child;
            etk_widget_size_request(child, &child_size);

            cell_size = (2 * cell->x_padding + child_size.w) / (cell->right_attach - cell->left_attach + 1);
            if (max_col_width < cell_size)
               max_col_width = cell_size;
            hexpand |= (cell->fill_policy & ETK_TABLE_HEXPAND);
         }

         for (i = 0; i < table->num_cols; i++)
         {
            table->cols[i].requested_size = max_col_width;
            table->cols[i].expand = !!hexpand;
         }

         size_requisition->w = table->num_cols * max_col_width;
      }
      /* Non horizontally-homogeneous table */
      else
      {
         for (i = 0; i < table->num_cols; i++)
         {
            table->cols[i].requested_size = CELL_MIN_SIZE;
            table->cols[i].expand = ETK_FALSE;
         }

         /* We first treat the children that span only one column */
         for (l = table->cells_list; l; l = l->next)
         {
            cell = l->data;
            child = cell->child;

            if (cell->left_attach == cell->right_attach)
            {
               etk_widget_size_request(child, &child_size);
               if (table->cols[cell->left_attach].requested_size < child_size.w + 2 * cell->x_padding)
                  table->cols[cell->left_attach].requested_size = child_size.w + 2 * cell->x_padding;
               table->cols[cell->left_attach].expand |= ((cell->fill_policy & ETK_TABLE_HEXPAND) != 0);
               hexpand |= (cell->fill_policy & ETK_TABLE_HEXPAND);
            }
         }
         /* Then, we treat the children that span several columns */
         for (l = table->cells_list; l; l = l->next)
         {
            int cells_size;
            int num_expandable_cells;
            int free_space;
            float delta;

            cell = l->data;
            child = cell->child;

            if (cell->left_attach < cell->right_attach)
            {
               cells_size = 0;
               num_expandable_cells = 0;

               etk_widget_size_request(child, &child_size);
               for (i = cell->left_attach; i <= cell->right_attach; i++)
               {
                  cells_size += table->cols[i].requested_size;
                  if (!hexpand && (cell->fill_policy & ETK_TABLE_HEXPAND))
                     table->cols[i].expand = ETK_TRUE;
                  if (table->cols[i].expand)
                     num_expandable_cells++;
               }

               free_space = child_size.w - cells_size;
               if (free_space > 0)
               {
                  if (num_expandable_cells <= 0)
                  {
                     delta = (float)free_space / (cell->right_attach - cell->left_attach + 1);
                     for (i = cell->left_attach; i <= cell->right_attach; i++)
                        table->cols[i].requested_size += (int)(delta * (i + 1)) - (int)(delta * i);
                  }
                  else
                  {
                     delta = (float)free_space / num_expandable_cells;
                     for (i = cell->left_attach; i <= cell->right_attach; i++)
                     {
                        if (table->cols[i].expand)
                           table->cols[i].requested_size += (int)(delta * (i + 1)) - (int)(delta * i);
                     }
                  }
               }
            }
         }

         size_requisition->w = 0;
         for (i = 0; i < table->num_cols; i++)
            size_requisition->w += table->cols[i].requested_size;
      }


      /*********************************************
       * Phase 2: We calculate the height of the rows of the table
       *********************************************/

      /* Vertically-homogeneous table */
      if (table->homogeneous & ETK_TABLE_VHOMOGENEOUS)
      {
         int max_row_height = CELL_MIN_SIZE;
         int cell_size;

         /* We calculate the maximum size of a cell */
         for (l = table->cells_list; l; l = l->next)
         {
            cell = l->data;
            child = cell->child;
            etk_widget_size_request(child, &child_size);

            cell_size = (2 * cell->y_padding + child_size.h) / (cell->bottom_attach - cell->top_attach + 1);
            if (max_row_height < cell_size)
               max_row_height = cell_size;
            vexpand |= (cell->fill_policy & ETK_TABLE_VEXPAND);
         }

         for (i = 0; i < table->num_rows; i++)
         {
            table->rows[i].requested_size = max_row_height;
            table->rows[i].expand = !!vexpand;
         }

         size_requisition->h = table->num_rows * max_row_height;
      }
      /* Non vertically-homogeneous table */
      else
      {
         for (i = 0; i < table->num_rows; i++)
         {
            table->rows[i].requested_size = CELL_MIN_SIZE;
            table->rows[i].expand = ETK_FALSE;
         }

         /* We first treat the children that span only one row */
         for (l = table->cells_list; l; l = l->next)
         {
            cell = l->data;
            child = cell->child;

            if (cell->top_attach == cell->bottom_attach)
            {
               etk_widget_size_request(child, &child_size);
               if (table->rows[cell->top_attach].requested_size < child_size.h + 2 * cell->y_padding)
                  table->rows[cell->top_attach].requested_size = child_size.h + 2 * cell->y_padding;
               table->rows[cell->top_attach].expand |= ((cell->fill_policy & ETK_TABLE_VEXPAND) != 0);
               vexpand |= (cell->fill_policy & ETK_TABLE_VEXPAND);
            }
         }
         /* Then, we treat the children that span several rows */
         for (l = table->cells_list; l; l = l->next)
         {
            int cells_size;
            int num_expandable_cells;
            int free_space;
            float delta;

            cell = l->data;
            child = cell->child;

            if (cell->top_attach < cell->bottom_attach)
            {
               cells_size = 0;
               num_expandable_cells = 0;

               etk_widget_size_request(child, &child_size);
               for (i = cell->top_attach; i <= cell->bottom_attach; i++)
               {
                  cells_size += table->rows[i].requested_size;
                  if (!vexpand && (cell->fill_policy & ETK_TABLE_VEXPAND))
                     table->rows[i].expand = ETK_TRUE;
                  if (table->rows[i].expand)
                     num_expandable_cells++;
               }

               free_space = child_size.h - cells_size;
               if (free_space > 0)
               {
                  if (num_expandable_cells <= 0)
                  {
                     delta = (float)free_space / (cell->bottom_attach - cell->top_attach + 1);
                     for (i = cell->top_attach; i <= cell->bottom_attach; i++)
                        table->rows[i].requested_size += (int)(delta * (i + 1)) - (int)(delta * i);
                  }
                  else
                  {
                     delta = (float)free_space / num_expandable_cells;
                     for (i = cell->top_attach; i <= cell->bottom_attach; i++)
                     {
                        if (table->rows[i].expand)
                           table->rows[i].requested_size += (int)(delta * (i + 1)) - (int)(delta * i);
                     }
                  }
               }
            }
         }

         size_requisition->h = 0;
         for (i = 0; i < table->num_rows; i++)
            size_requisition->h += table->rows[i].requested_size;
      }
   }

   size_requisition->w += 2 * ETK_CONTAINER(table)->border_width;
   size_requisition->h += 2 * ETK_CONTAINER(table)->border_width;
}