ui/motif/Grid.c

branch
newapi
changeset 426
3eb26df703bf
parent 425
effdc7283337
child 429
0921f8a5d535
equal deleted inserted replaced
425:effdc7283337 426:3eb26df703bf
50 //static char defaultTranslations[] = "<BtnDown>: mousedown()\n"; 50 //static char defaultTranslations[] = "<BtnDown>: mousedown()\n";
51 static char defaultTranslations[] = "\ 51 static char defaultTranslations[] = "\
52 <EnterWindow>: getfocus()\n\ 52 <EnterWindow>: getfocus()\n\
53 <LeaveWindow>: loosefocus()\n"; 53 <LeaveWindow>: loosefocus()\n";
54 54
55 static XtResource resources[] =
56 {
57 {
58 gridColumnSpacing,
59 gridColumnSpacing,
60 XmRDimension,
61 sizeof (Dimension),
62 XtOffsetOf( GridRec,
63 mywidget.columnspacing),
64 XmRImmediate,
65 (XtPointer) 0
66 },
67 {
68 gridRowSpacing,
69 gridRowSpacing,
70 XmRDimension,
71 sizeof (Dimension),
72 XtOffsetOf( GridRec,
73 mywidget.rowspacing),
74 XmRImmediate,
75 (XtPointer) 0
76 },
77 {
78 gridMargin,
79 gridMargin,
80 XmRDimension,
81 sizeof (Dimension),
82 XtOffsetOf( GridRec,
83 mywidget.margin),
84 XmRImmediate,
85 (XtPointer) 0
86 }
87 };
55 88
56 ///* 89 ///*
57 static XtResource constraints[] = 90 static XtResource constraints[] =
58 { 91 {
59 { 92 {
177 (XtPointer) 0 210 (XtPointer) 0
178 } 211 }
179 212
180 }; 213 };
181 //*/ 214 //*/
182 //static XtResource constraints[] = {};
183 215
184 GridClassRec gridClassRec = { 216 GridClassRec gridClassRec = {
185 // Core Class 217 // Core Class
186 { 218 {
187 //(WidgetClass)&constraintClassRec, // superclass 219 //(WidgetClass)&constraintClassRec, // superclass
188 (WidgetClass)&xmManagerClassRec, 220 (WidgetClass)&xmManagerClassRec,
189 "Grid", // class_name 221 "Grid", // class_name
190 sizeof(GridRec), // widget_size 222 sizeof(GridRec), // widget_size
191 grid_class_initialize, // class_initialize 223 grid_class_initialize, // class_initialize
192 NULL, // class_part_initialize 224 NULL, // class_part_initialize
193 FALSE, // class_inited 225 FALSE, // class_inited
194 (XtInitProc)grid_initialize, // initialize 226 (XtInitProc)grid_initialize, // initialize
195 NULL, // initialize_hook 227 NULL, // initialize_hook
196 grid_realize, // realize 228 grid_realize, // realize
197 actionslist, // actions 229 actionslist, // actions
198 XtNumber(actionslist), // num_actions 230 XtNumber(actionslist), // num_actions
199 NULL, // resources 231 resources, // resources
200 0, // num_resources 232 XtNumber(resources), // num_resources
201 NULLQUARK, // xrm_class 233 NULLQUARK, // xrm_class
202 True, // compress_motion 234 True, // compress_motion
203 True, // compress_exposure 235 True, // compress_exposure
204 True, // compress_enterleave 236 True, // compress_enterleave
205 False, // visible_interest 237 False, // visible_interest
463 } 495 }
464 } 496 }
465 span_max = 50000; // not sure if this is unreasonable low or high 497 span_max = 50000; // not sure if this is unreasonable low or high
466 } 498 }
467 499
468 500 // calc required size
469 for(int i=0;i<ncols;i++) { 501 for(int i=0;i<ncols;i++) {
470 if(cols[i].expand) { 502 if(cols[i].expand) {
471 num_cols_expanding++; 503 num_cols_expanding++;
472 } 504 }
473 req_width += cols[i].size; 505 req_width += cols[i].size;
478 } 510 }
479 req_height += rows[i].size; 511 req_height += rows[i].size;
480 } 512 }
481 513
482 if(req_width > 0 && req_height > 0) { 514 if(req_width > 0 && req_height > 0) {
515 // add col/row spacing
516 req_width += (ncols-1)*w->mywidget.columnspacing;
517 req_height += (nrows-1)*w->mywidget.rowspacing;
518
483 Widget parent = w->core.parent; 519 Widget parent = w->core.parent;
484 Dimension rwidth = req_width; 520 Dimension rwidth = req_width;
485 Dimension rheight = req_height; 521 Dimension rheight = req_height;
486 if(rwidth < w->core.width) { 522 if(rwidth < w->core.width) {
487 //rwidth = w->core.width; 523 //rwidth = w->core.width;
507 543
508 544
509 545
510 } 546 }
511 547
548 // how much space can we add to each expanding col/row
512 int hexpand = 0; 549 int hexpand = 0;
513 int width_diff = (int)w->core.width - req_width; 550 int width_diff = (int)w->core.width - req_width;
514 int hexpand2 = 0; 551 int hexpand2 = 0;
515 if(width_diff > 0 && num_cols_expanding > 0) { 552 if(width_diff > 0 && num_cols_expanding > 0) {
516 hexpand = width_diff / num_cols_expanding; 553 hexpand = width_diff / num_cols_expanding;
520 for(int i=0;i<ncols;i++) { 557 for(int i=0;i<ncols;i++) {
521 cols[i].pos = x; 558 cols[i].pos = x;
522 if(cols[i].expand) { 559 if(cols[i].expand) {
523 cols[i].size += hexpand + hexpand2; 560 cols[i].size += hexpand + hexpand2;
524 } 561 }
525 x += cols[i].size; 562 x += cols[i].size + w->mywidget.columnspacing;
526 563
527 hexpand2 = 0; 564 hexpand2 = 0;
528 } 565 }
529 566
530 int vexpand = 0; 567 int vexpand = 0;
538 for(int i=0;i<nrows;i++) { 575 for(int i=0;i<nrows;i++) {
539 rows[i].pos = y; 576 rows[i].pos = y;
540 if(rows[i].expand) { 577 if(rows[i].expand) {
541 rows[i].size += vexpand + vexpand2; 578 rows[i].size += vexpand + vexpand2;
542 } 579 }
543 y += rows[i].size; 580 y += rows[i].size += w->mywidget.rowspacing;
544 581
545 vexpand2 = 0; 582 vexpand2 = 0;
546 } 583 }
547 584
548 for(int i=0;i<w->composite.num_children;i++) { 585 for(int i=0;i<w->composite.num_children;i++) {
557 if(constraints->grid.hfill) { 594 if(constraints->grid.hfill) {
558 if(constraints->grid.colspan > 1) { 595 if(constraints->grid.colspan > 1) {
559 Dimension cwidth = 0; 596 Dimension cwidth = 0;
560 for(int j=0;j<constraints->grid.colspan;j++) { 597 for(int j=0;j<constraints->grid.colspan;j++) {
561 if(constraints->grid.x+j < ncols) { 598 if(constraints->grid.x+j < ncols) {
562 cwidth += cols[constraints->grid.x+j].size; 599 cwidth += cols[constraints->grid.x+j].size + (j > 0 ? w->mywidget.columnspacing : 0);
563 } 600 }
564 } 601 }
565 width = cwidth; 602 width = cwidth;
566 } else { 603 } else {
567 width = c.size; 604 width = c.size - w->mywidget.columnspacing;
568 } 605 }
569 } 606 }
570 if(constraints->grid.vfill) { 607 if(constraints->grid.vfill) {
571 if(constraints->grid.rowspan > 1) { 608 if(constraints->grid.rowspan > 1) {
572 Dimension cheight = 0; 609 Dimension cheight = 0;
573 for(int j=0;j<constraints->grid.rowspan;j++) { 610 for(int j=0;j<constraints->grid.rowspan;j++) {
574 if(constraints->grid.y+j < nrows) { 611 if(constraints->grid.y+j < nrows) {
575 cheight += rows[constraints->grid.y+j].size; 612 cheight += rows[constraints->grid.y+j].size + (j > 0 ? w->mywidget.rowspacing : 0);
576 } 613 }
577 } 614 }
578 height = cheight; 615 height = cheight;
579 } else { 616 } else {
580 height = r.size; 617 height = r.size - w->mywidget.rowspacing;
581 } 618 }
582 } 619 }
583 620
584 XtConfigureWidget(child, x, y, width, height, child->core.border_width); 621 XtConfigureWidget(child, x, y, width, height, child->core.border_width);
585 //printf("child %d %d - %d %d\n", (int)child->core.x, (int)child->core.y, (int)child->core.width, (int)child->core.height); 622 //printf("child %d %d - %d %d\n", (int)child->core.x, (int)child->core.y, (int)child->core.width, (int)child->core.height);

mercurial