src/table-utilities.c File Reference

Source code for the functions related to Synema's frames table. More...

#include <gtk/gtk.h>
#include <math.h>
#include "frame-table.h"
#include "frame-utilities.h"
#include "table-utilities.h"
Include dependency graph for table-utilities.c:

Go to the source code of this file.

Functions

frame_tslot_data_get (frame_table_t *tab, guint rows, guint cols)
void slot_data_set (frame_table_t *tab, guint rows, guint cols, frame_t *elem)
int slot_data_find_empty_slot (frame_table_t *tab, guint *rows, guint *cols, guint size_x, guint size_y)
int slot_data_resize (frame_table_t *tab, guint old_rows, guint old_cols, guint rows, guint cols)
int frame_table_size_changed (frame_table_t *tab, frame_t *elem, guint old_size_x, guint old_size_y, guint new_size_x, guint new_size_y)
int table_get_optimal_nb_cols (frame_table_t *tab)
int table_get_optimal_nb_rows (frame_table_t *tab)
int table_size_changed (frame_table_t *tab)
int table_add (frame_table_t *tab, frame_t *elem)
int table_add_with_coords (frame_table_t *tab, frame_t *elem, guint left, guint top)
int table_remove (frame_table_t *tab, frame_t *elem)
int table_swap_children (frame_table_t *tab, frame_t *child1, frame_t *child2)

Detailed Description

Source code for the functions related to Synema's frames table.

Author:
Steve Dodier <sidnioulz@gmail.com>
Timothée Ravier <timothee.ravier.romain@gmail.com>

This source code file contains functions useful for manipulating the GtkTable containing all the frames in Synema's GUI.

Definition in file table-utilities.c.


Function Documentation

int frame_table_size_changed ( frame_table_t tab,
frame_t elem,
guint  old_size_x,
guint  old_size_y,
guint  new_size_x,
guint  new_size_y 
)

Definition at line 104 of file table-utilities.c.

00105 {
00106     //TODO large frames management (all resizing / placing algorithms)
00107     return 0;
00108 }

int slot_data_find_empty_slot ( frame_table_t tab,
guint *  rows,
guint *  cols,
guint  size_x,
guint  size_y 
)

Definition at line 58 of file table-utilities.c.

00059 {
00060     guint table_rows, table_cols;
00061 
00062     g_object_get (tab->table, "n-columns", &table_cols, "n-rows", &table_rows, NULL);
00063     // g_print ("Table is %d,%d wide.\n", table_rows, table_cols);
00064 
00065     while ((*rows) < table_rows) {
00066         // g_print ("Looking at: %d,%d\n", *rows, *cols);
00067         if (slot_data_get (tab, *rows, *cols) == NULL) {
00068             //TODO regarder la taille des frames
00069             return 0;
00070         } else {
00071             if ((*cols) == (table_cols - 1)) {
00072                 (*cols) = 0;
00073                 (*rows)++;
00074             } else {
00075                 (*cols)++;
00076             }
00077         }
00078     }
00079 
00080     return 1;
00081     //TODO while < table(cols*rows) && != null ++
00082     //Recherche une place pour une frame.
00083     //Retourne 0 si libre (avec les coordonées pointées par les params), 1 sinon.
00084 }

frame_t* slot_data_get ( frame_table_t tab,
guint  rows,
guint  cols 
)

Definition at line 35 of file table-utilities.c.

00036 {
00037     guint table_cols;
00038 
00039     g_object_get (tab->table, "n-columns", &table_cols, NULL);
00040 
00041     return tab->slot_data[table_cols*rows + cols];
00042 }

int slot_data_resize ( frame_table_t tab,
guint  old_rows,
guint  old_cols,
guint  rows,
guint  cols 
)

Definition at line 86 of file table-utilities.c.

00087 {
00088     tab->slot_data = g_realloc (tab->slot_data, sizeof (frame_t*) * rows*cols);
00089 
00090     guint i,j;
00091     for (i = 0; i < rows; i++) {
00092         for (j = old_cols; j < cols; j++) {
00093             tab->slot_data[cols * i + j] = NULL;
00094         }
00095     }
00096     for (i = old_rows; i < rows; i++) {
00097         for (j = 0; j < old_cols; j++) {
00098             tab->slot_data[cols * i + j] = NULL;
00099         }
00100     }
00101     return 0;
00102 }

void slot_data_set ( frame_table_t tab,
guint  rows,
guint  cols,
frame_t elem 
)

Definition at line 46 of file table-utilities.c.

00047 {
00048     guint table_cols;
00049 
00050     g_object_get (tab->table, "n-columns", &table_cols, NULL);
00051     // g_print ("Data slot: %d,%d set !\n", rows, cols);
00052 
00053     tab->slot_data[table_cols * rows + cols] = elem;
00054 }

int table_add ( frame_table_t tab,
frame_t elem 
)

Definition at line 141 of file table-utilities.c.

00142 {
00143     guint size_x = ((elem->size == NORMAL) ? NORMAL_WIDTH_SLOTS : LARGE_WIDTH_SLOTS);
00144     guint size_y = ((elem->size == NORMAL) ? NORMAL_HEIGHT_SLOTS : LARGE_HEIGHT_SLOTS);
00145     guint           columns = 0, rows = 0;
00146     
00147     table_size_changed (tab); //FIXME Signal_conect...
00148     tab->children_size[elem->size]++;
00149     
00150     if (!slot_data_find_empty_slot (tab, &rows, &columns, size_x, size_y)) {
00151         gtk_table_attach_defaults (GTK_TABLE (tab->table), frame_get_root_widget (elem), columns, columns+1, rows, rows+1);
00152         //FIXME Lorsque la gestion des tailles sera ok, remplacer par: columns, columns+size_x, rows, rows+size_y
00153         //g_print ("Table slot: %d,%d set !\n", rows, columns);
00154         slot_data_set (tab, rows, columns, elem); //TODO regarder la taille
00155         elem->hidden = FALSE;
00156     } /*else {
00157         g_print ("Plus de place, la frame va dans la liste.\n"); //TODO implement list
00158     }*/
00159 
00160     return 0;
00161 }

int table_add_with_coords ( frame_table_t tab,
frame_t elem,
guint  left,
guint  top 
)

Definition at line 163 of file table-utilities.c.

00164 {
00165     table_size_changed (tab); //FIXME Signal_conect...
00166     
00167     tab->children_size[elem->size]++;
00168     gtk_table_attach_defaults (GTK_TABLE (tab->table), frame_get_root_widget (elem), left, left+1, top, top+1);
00169     elem->hidden = FALSE;
00170     slot_data_set (tab, top, left, elem); //TODO regarder la taille
00171 
00172     return 0;
00173 }

int table_get_optimal_nb_cols ( frame_table_t tab  ) 

Definition at line 110 of file table-utilities.c.

00111 {
00112     return 3; //FIXME implement
00113     //TODO obtenir le nombre de small frame que l'on peut positionner en largeur
00114 }

int table_get_optimal_nb_rows ( frame_table_t tab  ) 

Definition at line 116 of file table-utilities.c.

00117 {
00118     return 2; //FIXME implement
00119     //TODO obtenir le nombre de small frame que l'on peut positionner en hauteur
00120 }

int table_remove ( frame_table_t tab,
frame_t elem 
)

Definition at line 176 of file table-utilities.c.

00177 {
00178     GtkWidget       *elemwidget = frame_get_root_widget (elem);
00179     //GValue            val         = {0,};
00180     int             top = 0, left = 0;
00181     guint           table_rows, table_cols;
00182     
00183     g_object_get (tab->table, "n-columns", &table_cols, "n-rows", &table_rows, NULL);
00184     
00185 /*  gtk_container_child_get_property (GTK_CONTAINER (table), elemwidget, "top-attach", &val);*/
00186 /*  top = g_value_get_int (&val);*/
00187 /*  g_value_unset (&val);*/
00188 /*  */
00189 /*  gtk_container_child_get_property (GTK_CONTAINER (table), elemwidget, "left-attach", &val);*/
00190 /*  left = g_value_get_int (&val);*/
00191 /*  g_value_unset (&val);*/
00192     
00193     while (slot_data_get (tab, top, left) != elem ) {
00194         //g_print ("Looking at: %d,%d\n", top, left);
00195         if (top < table_rows) {
00196             if (left == (table_cols-1)) {
00197                 left = 0;
00198                 top++;
00199             }
00200             else {
00201                 left++;
00202             }
00203         } else {
00204             g_warning ("table_remove: The frame is not in the table");
00205             return 1;
00206         }
00207     }
00208     
00209     //TODO regarder la taille des frames
00210     
00211     //g_print ("Data slot: %d,%d removed !\n",top ,left);
00212     slot_data_set (tab, top, left, NULL);
00213     
00214     g_object_ref (elemwidget);
00215     elem->hidden = TRUE;
00216     gtk_container_remove (GTK_CONTAINER (tab->table), elemwidget);
00217     tab->children_size[elem->size]--;
00218     
00219     return 0;
00220 }

int table_size_changed ( frame_table_t tab  ) 

Definition at line 122 of file table-utilities.c.

00123 {
00124     guint           table_rows, table_cols;
00125     guint           optimal_rows, optimal_cols;
00126     
00127     g_object_get (tab->table, "n-columns", &table_cols, "n-rows", &table_rows, NULL);
00128         
00129     optimal_rows = table_get_optimal_nb_rows (tab);
00130     optimal_cols = table_get_optimal_nb_cols (tab);
00131     //TODO attention si pas de resize !
00132     
00133     gtk_table_resize (GTK_TABLE (tab->table), optimal_rows, optimal_cols);
00134     slot_data_resize (tab, table_rows, table_cols, optimal_rows, optimal_cols); 
00135     
00136     // g_print ("The table is now resized to (%d,%d).\n", optimal_rows, optimal_cols);
00137     
00138     return 0;
00139 }

int table_swap_children ( frame_table_t tab,
frame_t child1,
frame_t child2 
)

Definition at line 222 of file table-utilities.c.

00223 {
00224     //guint child1_col, child1_row, child2_col, child2_row;
00225     
00226     //frame_t *slot_data_get (tab, guint rows, guint cols)
00227     //void slot_data_set (tab, guint rows, guint cols, frame_t *elem)
00228     return 0;
00229 }

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Tue Jan 12 00:48:45 2010 for ENSIBSynema by  doxygen 1.6.1