aboutsummaryrefslogtreecommitdiff
path: root/src/Container.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Container.cc')
-rw-r--r--src/Container.cc81
1 files changed, 70 insertions, 11 deletions
diff --git a/src/Container.cc b/src/Container.cc
index be3a57b..0bec346 100644
--- a/src/Container.cc
+++ b/src/Container.cc
@@ -33,6 +33,7 @@
33Container::Container(const FbTk::FbWindow &parent): 33Container::Container(const FbTk::FbWindow &parent):
34 FbTk::FbWindow(parent, 0, 0, 1, 1, ExposureMask), 34 FbTk::FbWindow(parent, 0, 0, 1, 1, ExposureMask),
35 m_align(RELATIVE), 35 m_align(RELATIVE),
36 m_orientation(FbTk::ROT0),
36 m_max_size_per_client(60), 37 m_max_size_per_client(60),
37 m_max_total_size(0), 38 m_max_total_size(0),
38 m_selected(0), 39 m_selected(0),
@@ -104,6 +105,7 @@ void Container::insertItem(Item item, int pos) {
104 if (item->parent() != this) 105 if (item->parent() != this)
105 return; 106 return;
106 107
108 item->setOrientation(m_orientation);
107 if (pos >= size() || pos < 0) { 109 if (pos >= size() || pos < 0) {
108 m_item_list.push_back(item); 110 m_item_list.push_back(item);
109 } else if (pos == 0) { 111 } else if (pos == 0) {
@@ -273,6 +275,9 @@ void Container::setMaxTotalSize(unsigned int size) {
273 unsigned int old = m_max_total_size; 275 unsigned int old = m_max_total_size;
274 m_max_total_size = size; 276 m_max_total_size = size;
275 277
278 repositionItems();
279 return;
280
276 if (m_max_total_size && width() > m_max_total_size) { 281 if (m_max_total_size && width() > m_max_total_size) {
277 resize(m_max_total_size, height()); 282 resize(m_max_total_size, height());
278 } else if (!m_max_total_size && old) { // going from restricted to unrestricted 283 } else if (!m_max_total_size && old) { // going from restricted to unrestricted
@@ -366,13 +371,25 @@ void Container::repositionItems() {
366 if (empty() || m_update_lock) 371 if (empty() || m_update_lock)
367 return; 372 return;
368 373
369 //!! TODO vertical position 374 /**
375 NOTE: all calculations here are done in non-rotated space
376 */
370 377
371 unsigned int max_width_per_client = maxWidthPerClient(); 378 unsigned int max_width_per_client = maxWidthPerClient();
372 unsigned int borderW = m_item_list.front()->borderWidth(); 379 unsigned int borderW = m_item_list.front()->borderWidth();
373 unsigned int num_items = m_item_list.size(); 380 unsigned int num_items = m_item_list.size();
374 381
375 unsigned int total_width = width(); 382 unsigned int total_width;
383 unsigned int cur_width;
384 unsigned int height;
385 // unrotate
386 if (m_orientation == FbTk::ROT0 || m_orientation == FbTk::ROT180) {
387 total_width = cur_width = width();
388 height = this->height();
389 } else {
390 total_width = cur_width = this->height();
391 height = width();
392 }
376 393
377 // if we have a max total size, then we must also resize ourself 394 // if we have a max total size, then we must also resize ourself
378 // within that bound 395 // within that bound
@@ -387,12 +404,20 @@ void Container::repositionItems() {
387 } else 404 } else
388 max_width_per_client = 1; 405 max_width_per_client = 1;
389 } 406 }
390 if (total_width != width()) { 407
408 if (total_width != cur_width) {
391 // calling Container::resize here risks infinite loops 409 // calling Container::resize here risks infinite loops
392 if (align == RIGHT) 410 unsigned int neww = total_width, newh = height;
393 FbTk::FbWindow::moveResize(x() - (total_width - width()), y(), total_width, height()); 411 translateSize(m_orientation, neww, newh);
394 else 412 if (align == RIGHT || m_orientation == FbTk::ROT270) {
395 FbTk::FbWindow::resize(total_width, height()); 413 int deltax = - (total_width - cur_width);
414 int deltay = 0;
415 FbTk::translateCoords(m_orientation, deltax, deltay, total_width, height);
416
417 FbTk::FbWindow::moveResize(x() + deltax, y() + deltay, neww, newh);
418 } else {
419 FbTk::FbWindow::resize(neww, newh);
420 }
396 } 421 }
397 } 422 }
398 423
@@ -410,6 +435,8 @@ void Container::repositionItems() {
410 next_x = total_width - max_width_per_client - borderW; 435 next_x = total_width - max_width_per_client - borderW;
411 } 436 }
412 437
438 int tmpx, tmpy;
439 unsigned int tmpw, tmph;
413 for (; it != it_end; ++it, next_x += direction*(max_width_per_client + borderW + extra)) { 440 for (; it != it_end; ++it, next_x += direction*(max_width_per_client + borderW + extra)) {
414 // we only need to do error stuff with alignment RELATIVE 441 // we only need to do error stuff with alignment RELATIVE
415 if (rounding_error != 0 && align == RELATIVE) { 442 if (rounding_error != 0 && align == RELATIVE) {
@@ -418,11 +445,20 @@ void Container::repositionItems() {
418 } else { 445 } else {
419 extra = 0; 446 extra = 0;
420 } 447 }
448 // rotate the x and y coords
449 tmpx = next_x;
450 tmpy = -borderW;
451 tmpw = max_width_per_client + extra;
452 tmph = height;
453
454 FbTk::translateCoords(m_orientation, tmpx, tmpy, total_width, height);
455 FbTk::translatePosition(m_orientation, tmpx, tmpy, tmpw, tmph);
456 FbTk::translateSize(m_orientation, tmpw, tmph);
457
421 // resize each clients including border in size 458 // resize each clients including border in size
422 (*it)->moveResize(next_x, 459 (*it)->moveResize(tmpx, tmpy,
423 -borderW, 460 tmpw, tmph);
424 max_width_per_client + extra, 461
425 height());
426 // moveresize does a clear 462 // moveresize does a clear
427 } 463 }
428 464
@@ -476,3 +512,26 @@ void Container::clear() {
476 (*it)->clear(); 512 (*it)->clear();
477 513
478} 514}
515
516void Container::setOrientation(FbTk::Orientation orient) {
517 if (m_orientation == orient)
518 return;
519
520 ItemList::iterator it = m_item_list.begin();
521 ItemList::iterator it_end = m_item_list.end();
522 for (; it != it_end; ++it)
523 (*it)->setOrientation(orient);
524
525 if ((m_orientation == FbTk::ROT0 || m_orientation == FbTk::ROT180) &&
526 (orient == FbTk::ROT90 || orient == FbTk::ROT270) ||
527 (m_orientation == FbTk::ROT90 || m_orientation == FbTk::ROT270) &&
528 (orient == FbTk::ROT0 || orient == FbTk::ROT180)) {
529 // flip width and height
530 m_orientation = orient;
531 resize(height(), width());
532 } else {
533 m_orientation = orient;
534 repositionItems();
535 }
536
537}