5 #include "bcwidgetgrid.h"
8 BC_WidgetGrid::BC_WidgetGrid(int x1, int y1, int x2, int y2,int cgs,int rgs){
9 x_l = x1; // x position
10 y_t = y1; // y position
11 x_r = x2; // right margin (used only in get_w_wm)
12 y_b = y2; // left margin (used only in get_w_wm)
16 for (int r = 0; r < BC_WG_Rows; r++)
19 for (int c = 0; c < BC_WG_Cols; c++)
22 for (int r = 0; r < BC_WG_Rows; r++)
23 for (int c = 0; c < BC_WG_Cols; c++) {
24 widget_types[r][c] = BC_WT_NONE;
25 widget_valign[r][c] = VALIGN_CENTER;
26 widget_halign[r][c] = HALIGN_LEFT;
27 widget_colspan[r][c] = 1;
28 widget_rowspan[r][c] = 1;
32 BC_RelocatableWidget * BC_WidgetGrid::add(BC_RelocatableWidget *h, int row, int column) {
33 widget_types[row][column] = BC_WT_RelocatableWidget;
34 widget_widgs[row][column] = h;
40 void BC_WidgetGrid::calculate_maxs(){
42 for (r = 0; r < BC_WG_Rows; r++) {
44 for (c = 0; c < BC_WG_Cols; c++) {
45 if ((widget_rowspan[r][c] == 1) && (getw_h(r,c) > maxh[r]))
46 maxh[r] = getw_h(r,c);
50 for (c = 0; c < BC_WG_Cols; c++) {
52 for (r = 0; r < BC_WG_Rows; r++) {
53 if ((widget_colspan[r][c] == 1) && (getw_w(r,c) > maxw[c]))
54 maxw[c] = getw_w(r,c);
58 // Fix up for row & colspans:
59 for (c = 0; c < BC_WG_Cols; c++) {
60 for (r = 0; r < BC_WG_Rows; r++) {
61 int c_cs = MIN(BC_WG_Cols - c + 1, widget_colspan[r][c]);
62 int c_rs = MIN(BC_WG_Rows - c + 1, widget_rowspan[r][c]);
64 if ((widget_colspan[r][c] > 1)) {
67 for (c2 = c; c2 < c + c_cs; c2++) {
70 if (csw < getw_w(r,c)) {
71 for (c2 = c; c2 < c + c_cs; c2++) {
72 maxw[c2] += (csw - getw_w(r,c))/c_cs;
77 if ((widget_rowspan[r][c] > 1)) {
80 for (r2 = c; r2 < r + c_rs; r2++) {
83 if (csh < getw_h(r,c)) {
84 for (r2 = c; r2 < r + c_rs; r2++) {
85 maxh[r2] += (csh - getw_h(r,c))/c_rs;
93 void BC_WidgetGrid::clear_widget(int row, int column){
94 widget_types[row][column] = BC_WT_NONE;
97 int BC_WidgetGrid::get_h(){
100 for (int i = 0; i < BC_WG_Rows; i++)
102 y += maxh[i] + rowgaps;
106 int BC_WidgetGrid::get_h_wm(){
107 return (y_t + get_h() + y_b);
110 int BC_WidgetGrid::get_w(){
113 for (int i = 0; i < BC_WG_Cols; i++)
115 x += maxw[i] + colgaps;
119 int BC_WidgetGrid::get_w_wm(){
120 return (x_l + get_w() + x_r);
123 int BC_WidgetGrid::getw_h(int row, int column) {
124 switch (widget_types[row][column]) {
127 case BC_WT_RelocatableWidget:
128 return(widget_widgs[row][column]->get_h());
132 int BC_WidgetGrid::getw_w(int row, int column) {
133 switch (widget_types[row][column]) {
136 case BC_WT_RelocatableWidget:
137 return(widget_widgs[row][column]->get_w());
141 int BC_WidgetGrid::guess_x(int colno){
144 for (int i = 0; i < colno; i++)
145 x += maxw[i] + colgaps;
149 int BC_WidgetGrid::guess_y(int colno){
152 for (int i = 0; i < colno; i++)
153 y += maxh[i] + rowgaps;
157 void BC_WidgetGrid::move_widgets(){
162 for (r = 0; r < BC_WG_Rows; r++) {
164 for (c = 0; c < BC_WG_Cols; c++) {
165 switch (widget_valign[r][c]){
170 yn = y + (maxh[r] - getw_h(r,c))/2;
173 yn = y + (maxh[r] - getw_h(r,c));
177 switch (widget_halign[r][c]){
182 xn = x + (maxw[c] - getw_w(r,c))/2;
185 xn = x + (maxw[c] - getw_w(r,c));
188 setw_position(r,c,xn,yn); // + (maxh[r] - getw_h(r,c))/2);
189 x += colgaps + maxw[c];
191 y += rowgaps + maxh[r];
195 void BC_WidgetGrid::print(){
196 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);
198 for (int r = 0; r < BC_WG_Rows; r++) {
199 for (int c = 0; c < BC_WG_Cols; c++) {
200 printf("%d,%d\t",getw_w(r,c),getw_h(r,c));
202 printf("MAX: %d\n",maxh[r]);
204 printf("---------------------------------------------\n");
205 for (int c = 0; c < BC_WG_Cols; c++)
206 printf("%d\t",maxw[c]);
211 int BC_WidgetGrid::reposition_widget(int x, int y, int w1, int h){
218 void BC_WidgetGrid::set_align(int r,int c,int va, int ha){
219 widget_valign[r][c] = va;
220 widget_halign[r][c] = ha;
223 void BC_WidgetGrid::set_crspan(int r,int c,int cs, int rs){
224 widget_colspan[r][c] = cs;
225 widget_rowspan[r][c] = rs;
228 void BC_WidgetGrid::set_minw(int c,int w){
232 void BC_WidgetGrid::set_minh(int c,int h){
236 void BC_WidgetGrid::setw_position(int row,int column,int x, int y) {
237 switch (widget_types[row][column]) {
240 case BC_WT_RelocatableWidget:
241 widget_widgs[row][column]->reposition_widget(x,y);
247 BC_WidgetGridList::BC_WidgetGridList()
248 : ArrayList<BC_WidgetGrid*>()
252 BC_WidgetGridList::~BC_WidgetGridList()