- if (best != NULL) {
- Point *pt = new Point(best->origin());
- if (screen.colPlacementDirection() != BScreen::TopBottom)
- pt->setY(pt->y() + (best->h() - win_size.h()));
- if (screen.rowPlacementDirection() != BScreen::LeftRight)
- pt->setX(pt->x() + (best->w() - win_size.w()));
- return pt;
- } else
- return NULL; //fall back to cascade
+
+ if (screen->getPlacementPolicy() == BScreen::RowSmartPlacement) {
+ if(screen->getRowPlacementDirection() == BScreen::LeftRight) {
+ if(screen->getColPlacementDirection() == BScreen::TopBottom)
+ std::sort(spaces.begin(), spaces.end(), rowLRTB);
+ else
+ std::sort(spaces.begin(), spaces.end(), rowLRBT);
+ } else {
+ if(screen->getColPlacementDirection() == BScreen::TopBottom)
+ std::sort(spaces.begin(), spaces.end(), rowRLTB);
+ else
+ std::sort(spaces.begin(), spaces.end(), rowRLBT);
+ }
+ } else {
+ if(screen->getColPlacementDirection() == BScreen::TopBottom) {
+ if(screen->getRowPlacementDirection() == BScreen::LeftRight)
+ std::sort(spaces.begin(), spaces.end(), colLRTB);
+ else
+ std::sort(spaces.begin(), spaces.end(), colRLTB);
+ } else {
+ if(screen->getRowPlacementDirection() == BScreen::LeftRight)
+ std::sort(spaces.begin(), spaces.end(), colLRBT);
+ else
+ std::sort(spaces.begin(), spaces.end(), colRLBT);
+ }
+ }
+
+ rectList::const_iterator sit = spaces.begin(), spaces_end = spaces.end();
+ for(; sit != spaces_end; ++sit) {
+ if (sit->width() >= win.width() && sit->height() >= win.height())
+ break;
+ }
+
+ if (sit == spaces_end)
+ return False;
+
+ //set new position based on the empty space found
+ const Rect& where = *sit;
+ win.setX(where.x());
+ win.setY(where.y());
+
+ // adjust the location() based on left/right and top/bottom placement
+ if (screen->getPlacementPolicy() == BScreen::RowSmartPlacement) {
+ if (screen->getRowPlacementDirection() == BScreen::RightLeft)
+ win.setX(where.right() - win.width());
+ if (screen->getColPlacementDirection() == BScreen::BottomTop)
+ win.setY(where.bottom() - win.height());
+ } else {
+ if (screen->getColPlacementDirection() == BScreen::BottomTop)
+ win.setY(win.y() + where.height() - win.height());
+ if (screen->getRowPlacementDirection() == BScreen::RightLeft)
+ win.setX(win.x() + where.width() - win.width());
+ }
+ return True;