4 * Copyright (C) 2005 Pierre Dumuid
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "bcwidgetgrid.h"
29 BC_WidgetGrid::BC_WidgetGrid(int x1, int y1, int x2, int y2,int cgs,int rgs){
30 x_l = x1; // x position
31 y_t = y1; // y position
32 x_r = x2; // right margin (used only in get_w_wm)
33 y_b = y2; // left margin (used only in get_w_wm)
37 for (int r = 0; r < BC_WG_Rows; r++)
40 for (int c = 0; c < BC_WG_Cols; c++)
43 for (int r = 0; r < BC_WG_Rows; r++)
44 for (int c = 0; c < BC_WG_Cols; c++) {
45 widget_types[r][c] = BC_WT_NONE;
46 widget_valign[r][c] = VALIGN_CENTER;
47 widget_halign[r][c] = HALIGN_LEFT;
48 widget_colspan[r][c] = 1;
49 widget_rowspan[r][c] = 1;
53 BC_RelocatableWidget * BC_WidgetGrid::add(BC_RelocatableWidget *h, int row, int column) {
54 widget_types[row][column] = BC_WT_RelocatableWidget;
55 widget_widgs[row][column] = h;
61 void BC_WidgetGrid::calculate_maxs(){
63 for (r = 0; r < BC_WG_Rows; r++) {
65 for (c = 0; c < BC_WG_Cols; c++) {
66 if ((widget_rowspan[r][c] == 1) && (getw_h(r,c) > maxh[r]))
67 maxh[r] = getw_h(r,c);
71 for (c = 0; c < BC_WG_Cols; c++) {
73 for (r = 0; r < BC_WG_Rows; r++) {
74 if ((widget_colspan[r][c] == 1) && (getw_w(r,c) > maxw[c]))
75 maxw[c] = getw_w(r,c);
79 // Fix up for row & colspans:
80 for (c = 0; c < BC_WG_Cols; c++) {
81 for (r = 0; r < BC_WG_Rows; r++) {
82 int c_cs = MIN(BC_WG_Cols - c + 1, widget_colspan[r][c]);
83 int c_rs = MIN(BC_WG_Rows - c + 1, widget_rowspan[r][c]);
85 if ((widget_colspan[r][c] > 1)) {
88 for (c2 = c; c2 < c + c_cs; c2++) {
91 if (csw < getw_w(r,c)) {
92 for (c2 = c; c2 < c + c_cs; c2++) {
93 maxw[c2] += (csw - getw_w(r,c))/c_cs;
98 if ((widget_rowspan[r][c] > 1)) {
101 for (r2 = c; r2 < r + c_rs; r2++) {
104 if (csh < getw_h(r,c)) {
105 for (r2 = c; r2 < r + c_rs; r2++) {
106 maxh[r2] += (csh - getw_h(r,c))/c_rs;
114 void BC_WidgetGrid::clear_widget(int row, int column){
115 widget_types[row][column] = BC_WT_NONE;
118 int BC_WidgetGrid::get_h(){
121 for (int i = 0; i < BC_WG_Rows; i++)
123 y += maxh[i] + rowgaps;
127 int BC_WidgetGrid::get_h_wm(){
128 return (y_t + get_h() + y_b);
131 int BC_WidgetGrid::get_w(){
134 for (int i = 0; i < BC_WG_Cols; i++)
136 x += maxw[i] + colgaps;
140 int BC_WidgetGrid::get_w_wm(){
141 return (x_l + get_w() + x_r);
144 int BC_WidgetGrid::getw_h(int row, int column) {
145 switch (widget_types[row][column]) {
146 case BC_WT_RelocatableWidget:
147 return(widget_widgs[row][column]->get_h());
153 int BC_WidgetGrid::getw_w(int row, int column) {
154 switch (widget_types[row][column]) {
155 case BC_WT_RelocatableWidget:
156 return(widget_widgs[row][column]->get_w());
162 int BC_WidgetGrid::guess_x(int colno){
165 for (int i = 0; i < colno; i++)
166 x += maxw[i] + colgaps;
170 int BC_WidgetGrid::guess_y(int colno){
173 for (int i = 0; i < colno; i++)
174 y += maxh[i] + rowgaps;
178 void BC_WidgetGrid::move_widgets(){
183 for (r = 0; r < BC_WG_Rows; r++) {
185 for (c = 0; c < BC_WG_Cols; c++) {
186 switch (widget_valign[r][c]){
192 yn = y + (maxh[r] - getw_h(r,c))/2;
195 yn = y + (maxh[r] - getw_h(r,c));
199 switch (widget_halign[r][c]){
205 xn = x + (maxw[c] - getw_w(r,c))/2;
208 xn = x + (maxw[c] - getw_w(r,c));
211 setw_position(r,c,xn,yn); // + (maxh[r] - getw_h(r,c))/2);
212 x += colgaps + maxw[c];
214 y += rowgaps + maxh[r];
218 void BC_WidgetGrid::print(){
219 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);
221 for (int r = 0; r < BC_WG_Rows; r++) {
222 for (int c = 0; c < BC_WG_Cols; c++) {
223 printf("%d,%d\t",getw_w(r,c),getw_h(r,c));
225 printf("MAX: %d\n",maxh[r]);
227 printf("---------------------------------------------\n");
228 for (int c = 0; c < BC_WG_Cols; c++)
229 printf("%d\t",maxw[c]);
234 int BC_WidgetGrid::reposition_widget(int x, int y, int w1, int h){
241 void BC_WidgetGrid::set_align(int r,int c,int va, int ha){
242 widget_valign[r][c] = va;
243 widget_halign[r][c] = ha;
246 void BC_WidgetGrid::set_crspan(int r,int c,int cs, int rs){
247 widget_colspan[r][c] = cs;
248 widget_rowspan[r][c] = rs;
251 void BC_WidgetGrid::set_minw(int c,int w){
255 void BC_WidgetGrid::set_minh(int c,int h){
259 void BC_WidgetGrid::setw_position(int row,int column,int x, int y) {
260 switch (widget_types[row][column]) {
263 case BC_WT_RelocatableWidget:
264 widget_widgs[row][column]->reposition_widget(x,y);
270 BC_WidgetGridList::BC_WidgetGridList()
271 : ArrayList<BC_WidgetGrid*>()
275 BC_WidgetGridList::~BC_WidgetGridList()