4 #include "bcwidgetgrid.h"
7 BC_WidgetGrid::BC_WidgetGrid(int x1, int y1, int x2, int y2,int cgs,int rgs){
8 x_l = x1; // x position
9 y_t = y1; // y position
10 x_r = x2; // right margin (used only in get_w_wm)
11 y_b = y2; // left margin (used only in get_w_wm)
15 for (int r = 0; r < BC_WG_Rows; r++)
16 for (int c = 0; c < BC_WG_Cols; c++) {
17 widget_types[r][c] = BC_WT_NONE;
18 widget_valign[r][c] = VALIGN_CENTER;
19 widget_halign[r][c] = HALIGN_LEFT;
23 BC_RelocatableWidget * BC_WidgetGrid::add(BC_RelocatableWidget *h, int row, int column) {
24 widget_types[row][column] = BC_WT_RelocatableWidget;
25 widget_widgs[row][column] = h;
29 int BC_WidgetGrid::getw_h(int row, int column) {
30 switch (widget_types[row][column]) {
33 case BC_WT_RelocatableWidget:
34 return(widget_widgs[row][column]->get_h());
38 int BC_WidgetGrid::getw_w(int row, int column) {
39 switch (widget_types[row][column]) {
42 case BC_WT_RelocatableWidget:
43 return(widget_widgs[row][column]->get_w());
47 void BC_WidgetGrid::setw_position(int row,int column,int x, int y) {
48 switch (widget_types[row][column]) {
51 case BC_WT_RelocatableWidget:
52 widget_widgs[row][column]->reposition_widget(x,y);
57 void BC_WidgetGrid::clear_widget(int row, int column){
58 widget_types[row][column] = BC_WT_NONE;
61 int BC_WidgetGrid::guess_x(int colno){
64 for (int i = 0; i < colno; i++)
65 x += maxw[i] + colgaps;
69 int BC_WidgetGrid::guess_y(int colno){
72 for (int i = 0; i < colno; i++)
73 y += maxh[i] + rowgaps;
77 int BC_WidgetGrid::get_w_wm(){
78 return (x_l + get_w() + x_r);
82 int BC_WidgetGrid::get_w(){
85 for (int i = 0; i < BC_WG_Cols; i++)
87 x += maxw[i] + colgaps;
91 int BC_WidgetGrid::get_h_wm(){
92 return (y_t + get_h() + y_b);
95 int BC_WidgetGrid::get_h(){
98 for (int i = 0; i < BC_WG_Rows; i++)
100 y += maxh[i] + rowgaps;
104 void BC_WidgetGrid::set_align(int r,int c,int va, int ha){
105 widget_valign[r][c] = va;
106 widget_halign[r][c] = ha;
109 int BC_WidgetGrid::reposition_widget(int x, int y, int w1, int h){
116 void BC_WidgetGrid::move_widgets(){
121 for (r = 0; r < BC_WG_Rows; r++) {
123 for (c = 0; c < BC_WG_Cols; c++) {
124 switch (widget_valign[r][c]){
129 yn = y + (maxh[r] - getw_h(r,c))/2;
132 yn = y + (maxh[r] - getw_h(r,c));
136 switch (widget_halign[r][c]){
141 xn = x + (maxw[c] - getw_w(r,c))/2;
144 xn = x + (maxw[c] - getw_w(r,c));
147 setw_position(r,c,xn,yn); // + (maxh[r] - getw_h(r,c))/2);
148 x += colgaps + maxw[c];
150 y += rowgaps + maxh[r];
154 void BC_WidgetGrid::calculate_maxs(){
156 for (r = 0; r < BC_WG_Rows; r++) {
158 for (c = 0; c < BC_WG_Cols; c++) {
159 if (getw_h(r,c) > maxh[r])
160 maxh[r] = getw_h(r,c);
163 for (c = 0; c < BC_WG_Cols; c++) {
165 for (r = 0; r < BC_WG_Rows; r++) {
166 if (getw_w(r,c) > maxw[c])
167 maxw[c] = getw_w(r,c);
172 void BC_WidgetGrid::print(){
173 printf("\nWidget Grid: Widths: x_l=%d y_t=%d x_r=%d y_b=%d\n",x_l,y_t,x_r,y_b);
175 for (int r = 0; r < BC_WG_Rows; r++) {
176 for (int c = 0; c < BC_WG_Cols; c++) {
177 printf("%d,%d\t",getw_w(r,c),getw_h(r,c));
179 printf("MAX: %d\n",maxh[r]);
181 printf("---------------------------------------------\n");
182 for (int c = 0; c < BC_WG_Cols; c++)
183 printf("%d\t",maxw[c]);