00001 #include "clip.h"
00002 #include "bctitle.h"
00003 #include "bcpot.h"
00004 #include "bcslider.h"
00005 #include "bcwidgetgrid.h"
00006
00007
00008 BC_WidgetGrid::BC_WidgetGrid(int x1, int y1, int x2, int y2,int cgs,int rgs){
00009 x_l = x1;
00010 y_t = y1;
00011 x_r = x2;
00012 y_b = y2;
00013 rowgaps = rgs;
00014 colgaps = cgs;
00015
00016 for (int r = 0; r < BC_WG_Rows; r++)
00017 minh[r] = 0;
00018
00019 for (int c = 0; c < BC_WG_Cols; c++)
00020 minw[c] = 0;
00021
00022 for (int r = 0; r < BC_WG_Rows; r++)
00023 for (int c = 0; c < BC_WG_Cols; c++) {
00024 widget_types[r][c] = BC_WT_NONE;
00025 widget_valign[r][c] = VALIGN_CENTER;
00026 widget_halign[r][c] = HALIGN_LEFT;
00027 widget_colspan[r][c] = 1;
00028 widget_rowspan[r][c] = 1;
00029 }
00030 }
00031
00032 BC_RelocatableWidget * BC_WidgetGrid::add(BC_RelocatableWidget *h, int row, int column) {
00033 widget_types[row][column] = BC_WT_RelocatableWidget;
00034 widget_widgs[row][column] = h;
00035 return(h);
00036 }
00037
00038
00039
00040 void BC_WidgetGrid::calculate_maxs(){
00041 int r,c;
00042 for (r = 0; r < BC_WG_Rows; r++) {
00043 maxh[r] = minh[r];
00044 for (c = 0; c < BC_WG_Cols; c++) {
00045 if ((widget_rowspan[r][c] == 1) && (getw_h(r,c) > maxh[r]))
00046 maxh[r] = getw_h(r,c);
00047 }
00048 }
00049
00050 for (c = 0; c < BC_WG_Cols; c++) {
00051 maxw[c] = minw[c];
00052 for (r = 0; r < BC_WG_Rows; r++) {
00053 if ((widget_colspan[r][c] == 1) && (getw_w(r,c) > maxw[c]))
00054 maxw[c] = getw_w(r,c);
00055 }
00056 }
00057
00058
00059 for (c = 0; c < BC_WG_Cols; c++) {
00060 for (r = 0; r < BC_WG_Rows; r++) {
00061 int c_cs = MIN(BC_WG_Cols - c + 1, widget_colspan[r][c]);
00062 int c_rs = MIN(BC_WG_Rows - c + 1, widget_rowspan[r][c]);
00063
00064 if ((widget_colspan[r][c] > 1)) {
00065 int csw = 0;
00066 int c2;
00067 for (c2 = c; c2 < c + c_cs; c2++) {
00068 csw += maxw[c2];
00069 }
00070 if (csw < getw_w(r,c)) {
00071 for (c2 = c; c2 < c + c_cs; c2++) {
00072 maxw[c2] += (csw - getw_w(r,c))/c_cs;
00073 }
00074 }
00075 }
00076
00077 if ((widget_rowspan[r][c] > 1)) {
00078 int csh = 0;
00079 int r2;
00080 for (r2 = c; r2 < r + c_rs; r2++) {
00081 csh += maxh[r2];
00082 }
00083 if (csh < getw_h(r,c)) {
00084 for (r2 = c; r2 < r + c_rs; r2++) {
00085 maxh[r2] += (csh - getw_h(r,c))/c_rs;
00086 }
00087 }
00088 }
00089 }
00090 }
00091 }
00092
00093 void BC_WidgetGrid::clear_widget(int row, int column){
00094 widget_types[row][column] = BC_WT_NONE;
00095 }
00096
00097 int BC_WidgetGrid::get_h(){
00098 calculate_maxs();
00099 int y = 0;
00100 for (int i = 0; i < BC_WG_Rows; i++)
00101 if (maxh[i] > 0)
00102 y += maxh[i] + rowgaps;
00103 return (y);
00104 }
00105
00106 int BC_WidgetGrid::get_h_wm(){
00107 return (y_t + get_h() + y_b);
00108 }
00109
00110 int BC_WidgetGrid::get_w(){
00111 calculate_maxs();
00112 int x = 0;
00113 for (int i = 0; i < BC_WG_Cols; i++)
00114 if (maxw[i] > 0)
00115 x += maxw[i] + colgaps;
00116 return (x);
00117 }
00118
00119 int BC_WidgetGrid::get_w_wm(){
00120 return (x_l + get_w() + x_r);
00121 }
00122
00123 int BC_WidgetGrid::getw_h(int row, int column) {
00124 switch (widget_types[row][column]) {
00125 case BC_WT_NONE:
00126 return(0);
00127 case BC_WT_RelocatableWidget:
00128 return(widget_widgs[row][column]->get_h());
00129 }
00130 }
00131
00132 int BC_WidgetGrid::getw_w(int row, int column) {
00133 switch (widget_types[row][column]) {
00134 case BC_WT_NONE:
00135 return(0);
00136 case BC_WT_RelocatableWidget:
00137 return(widget_widgs[row][column]->get_w());
00138 }
00139 }
00140
00141 int BC_WidgetGrid::guess_x(int colno){
00142 calculate_maxs();
00143 int x = x_l;
00144 for (int i = 0; i < colno; i++)
00145 x += maxw[i] + colgaps;
00146 return (x);
00147 }
00148
00149 int BC_WidgetGrid::guess_y(int colno){
00150 calculate_maxs();
00151 int y = y_t;
00152 for (int i = 0; i < colno; i++)
00153 y += maxh[i] + rowgaps;
00154 return (y);
00155 }
00156
00157 void BC_WidgetGrid::move_widgets(){
00158 calculate_maxs();
00159 int r,c,x,y;
00160 int xn,yn;
00161 y = y_t;
00162 for (r = 0; r < BC_WG_Rows; r++) {
00163 x = x_l;
00164 for (c = 0; c < BC_WG_Cols; c++) {
00165 switch (widget_valign[r][c]){
00166 case VALIGN_TOP:
00167 yn = y;
00168 break;
00169 case VALIGN_CENTER:
00170 yn = y + (maxh[r] - getw_h(r,c))/2;
00171 break;
00172 case VALIGN_BOTTOM:
00173 yn = y + (maxh[r] - getw_h(r,c));
00174 break;
00175 }
00176
00177 switch (widget_halign[r][c]){
00178 case HALIGN_LEFT:
00179 xn = x;
00180 break;
00181 case HALIGN_CENTER:
00182 xn = x + (maxw[c] - getw_w(r,c))/2;
00183 break;
00184 case HALIGN_RIGHT:
00185 xn = x + (maxw[c] - getw_w(r,c));
00186 break;
00187 }
00188 setw_position(r,c,xn,yn);
00189 x += colgaps + maxw[c];
00190 }
00191 y += rowgaps + maxh[r];
00192 }
00193 }
00194
00195 void BC_WidgetGrid::print(){
00196 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);
00197 calculate_maxs();
00198 for (int r = 0; r < BC_WG_Rows; r++) {
00199 for (int c = 0; c < BC_WG_Cols; c++) {
00200 printf("%d,%d\t",getw_w(r,c),getw_h(r,c));
00201 }
00202 printf("MAX: %d\n",maxh[r]);
00203 }
00204 printf("---------------------------------------------\n");
00205 for (int c = 0; c < BC_WG_Cols; c++)
00206 printf("%d\t",maxw[c]);
00207 printf("\n\n");
00208
00209 }
00210
00211 int BC_WidgetGrid::reposition_widget(int x, int y, int w1, int h){
00212 x_l = x;
00213 y_t = y;
00214 move_widgets();
00215 return(0);
00216 }
00217
00218 void BC_WidgetGrid::set_align(int r,int c,int va, int ha){
00219 widget_valign[r][c] = va;
00220 widget_halign[r][c] = ha;
00221 }
00222
00223 void BC_WidgetGrid::set_crspan(int r,int c,int cs, int rs){
00224 widget_colspan[r][c] = cs;
00225 widget_rowspan[r][c] = rs;
00226 }
00227
00228 void BC_WidgetGrid::set_minw(int c,int w){
00229 minw[c] = w;
00230 }
00231
00232 void BC_WidgetGrid::set_minh(int c,int h){
00233 minh[c] = h;
00234 }
00235
00236 void BC_WidgetGrid::setw_position(int row,int column,int x, int y) {
00237 switch (widget_types[row][column]) {
00238 case BC_WT_NONE:
00239 break;
00240 case BC_WT_RelocatableWidget:
00241 widget_widgs[row][column]->reposition_widget(x,y);
00242 break;
00243 }
00244 }
00245
00246
00247 BC_WidgetGridList::BC_WidgetGridList()
00248 : ArrayList<BC_WidgetGrid*>()
00249 {
00250 }
00251
00252 BC_WidgetGridList::~BC_WidgetGridList()
00253 {
00254 }
00255