28 #include "tdemdichildarea.h"
29 #include "tdemdichildarea.moc"
31 #include "tdemdidefines.h"
33 #include <tdeconfig.h>
35 #include <tdeglobal.h>
36 #include <tdeglobalsettings.h>
39 #include <tqpopupmenu.h>
49 : TQFrame( parent,
"tdemdi_childarea" )
51 setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
54 m_captionFontLineSpacing = fm.lineSpacing();
59 m_pZ =
new TQPtrList<KMdiChildFrm>;
60 m_pZ->setAutoDelete(
true );
61 setFocusPolicy( TQ_ClickFocus );
74 kdDebug( 760 ) << k_funcinfo <<
"Adding child " << child <<
" to be managed" << endl;
78 if (
m_pZ->findRef( child ) != -1 )
82 while (
m_pZ->findNextRef( child ) != -1 )
87 m_pZ->append( child );
89 m_pZ->insert( 0, child );
96 if ( top && top->
state() == KMdiChildFrm::Maximized )
98 kdDebug( 760 ) << k_funcinfo <<
"Maximizing the new child" << endl;
100 top->
setState( KMdiChildFrm::Normal,
false );
101 child->
setState( KMdiChildFrm::Maximized,
false );
111 kdDebug( 760 ) << k_funcinfo <<
"Removing child " << child->
caption() << endl;
112 bool wasMaximized = ( child->
state() == KMdiChildFrm::Maximized );
116 child->blockSignals(
true );
117 m_pZ->setAutoDelete(
false );
118 m_pZ->removeRef( child );
126 newTopChild->
setState( KMdiChildFrm::Maximized,
false );
134 m_pZ->setAutoDelete(
true );
143 kdDebug( 760 ) << k_funcinfo <<
"Removing child " << child->
caption() << endl;
144 bool wasMaximized = ( child->
state() == KMdiChildFrm::Maximized );
149 m_pZ->setAutoDelete(
false );
150 m_pZ->removeRef( child );
158 newTopChild->
setState( KMdiChildFrm::Maximized,
false );
165 m_pZ->setAutoDelete(
true );
178 kdDebug( 760 ) << k_funcinfo <<
"Setting " << child->
caption() <<
" as the new top child" << endl;
179 m_pZ->setAutoDelete(
false );
181 m_pZ->removeRef( child );
182 m_pZ->setAutoDelete(
true );
185 TQPtrListIterator<KMdiChildFrm> it( *
m_pZ );
186 for ( ; ( *it ); ++it )
187 ( *it )->m_pCaption->setActive(
false );
190 bool topChildMaximized =
false;
191 if ( maximizedChild && maximizedChild->
state() == KMdiChildFrm::Maximized )
192 topChildMaximized =
true;
194 m_pZ->append( child );
196 int nChildAreaMinW = 0, nChildAreaMinH = 0;
197 int nChildAreaMaxW = TQWIDGETSIZE_MAX, nChildAreaMaxH = TQWIDGETSIZE_MAX;
198 if ( topChildMaximized && child->m_pClient )
201 nChildAreaMinW = child->m_pClient->minimumWidth();
202 nChildAreaMinH = child->m_pClient->minimumHeight();
209 setMinimumSize( nChildAreaMinW, nChildAreaMinH );
210 setMaximumSize( nChildAreaMaxW, nChildAreaMaxH );
212 if ( topChildMaximized )
214 child->
setState( KMdiChildFrm::Maximized,
false );
215 maximizedChild->
setState( KMdiChildFrm::Normal,
false );
222 child->m_pClient->setFocus();
224 TQFocusEvent::setReason( TQFocusEvent::Other );
225 child->m_pClient->setFocus();
235 if ( child && child->
state() == KMdiChildFrm::Maximized )
237 int clientw = 0, clienth = 0;
238 if ( child->m_pClient != 0L )
240 clientw = child->m_pClient->width();
241 clienth = child->m_pClient->height();
243 child->resize( width() + KMDI_CHILDFRM_DOUBLE_BORDER,
244 height() + child->m_pCaption->
heightHint() + KMDI_CHILDFRM_SEPARATOR + KMDI_CHILDFRM_DOUBLE_BORDER );
256 if ( e->button() & Qt::RightButton )
264 if ( indexOfWindow < 0 )
266 indexOfWindow =
m_pZ->count();
267 kdDebug( 760 ) << k_funcinfo <<
"indexOfWindow was less than zero, using "
268 << indexOfWindow <<
" as new index" << endl;
272 if ( indexOfWindow == 0 )
274 kdDebug( 760 ) << k_funcinfo <<
"No windows. Returning TQPoint( 0, 0 ) as the cascade point" << endl;
278 bool topLevelMode =
false;
282 kdDebug( 760 ) << k_funcinfo <<
"Getting the cascade point for window index " << indexOfWindow << endl;
283 kdDebug( 760 ) << k_funcinfo <<
"Do we think we're in top level mode? " << topLevelMode << endl;
289 int h = ( topLevelMode ? TQApplication::desktop()->height() : height() );
290 int w = ( topLevelMode ? TQApplication::desktop()->width() : width() );
299 kdDebug( 760 ) << k_funcinfo <<
"child frame exists. resetting height and width values" << endl;
300 step = child->m_pCaption->
heightHint() + KMDI_CHILDFRM_BORDER;
301 availableHeight = h - child->minimumHeight();
302 availableWidth = w - child->minimumWidth();
305 for (
int i = 0; i < indexOfWindow; i++ )
311 if ( ax > availableWidth )
314 if ( ay > availableHeight )
326 if (
m_pZ->findRef( minimizedChild ) == -1 )
328 kdDebug( 760 ) << k_funcinfo <<
"child was minimized but wasn't in our list!" << endl;
332 kdDebug( 760 ) << k_funcinfo << endl;
333 if (
m_pZ->count() > 1 )
336 m_pZ->setAutoDelete(
false );
337 m_pZ->removeRef( minimizedChild );
338 m_pZ->setAutoDelete(
true );
339 m_pZ->insert( 0, minimizedChild );
343 kdDebug( 760 ) << k_funcinfo <<
"child just minimized from maximized state. maximize new top child" << endl;
345 if ( !minimizedChild )
348 if ( minimizedChild->
state() == KMdiChildFrm::Maximized )
351 minimizedChild->
setState( KMdiChildFrm::Maximized,
false );
364 kdDebug( 760 ) << k_funcinfo <<
"No more child windows left" << endl;
369 if ( !lastChild->m_pClient->hasFocus() )
372 TQPtrListIterator<KMdiChildFrm> it ( *
m_pZ );
373 for ( ; ( *it ); ++it )
375 if ( ( *it ) != lastChild )
376 ( *it )->m_pCaption->setActive(
false );
379 kdDebug( 760 ) << k_funcinfo <<
"Giving focus to " << lastChild->
caption() << endl;
388 kdDebug( 760 ) << k_funcinfo <<
"cascading windows but not changing their size" << endl;
390 TQPtrList<KMdiChildFrm> list( *
m_pZ );
391 list.setAutoDelete(
false );
392 while ( !list.isEmpty() )
395 if ( childFrm->
state() != KMdiChildFrm::Minimized )
397 if ( childFrm->
state() == KMdiChildFrm::Maximized )
410 kdDebug( 760 ) << k_funcinfo <<
"cascading windows. will make sure they are minimum sized" << endl;
412 TQPtrList<KMdiChildFrm> list( *
m_pZ );
414 list.setAutoDelete(
false );
415 while ( !list.isEmpty() )
418 if (childFrm->
state() != KMdiChildFrm::Minimized )
420 if (childFrm->
state() == KMdiChildFrm::Maximized )
424 childFrm->move( pnt );
425 TQSize curSize( width() - pnt.x(), height() - pnt.y() );
427 if ( ( childFrm->minimumSize().width() > curSize.width() ) ||
428 ( childFrm->minimumSize().height() > curSize.height() ) )
430 childFrm->resize( childFrm->minimumSize() );
433 childFrm->resize( curSize );
444 kdDebug( 760 ) << k_funcinfo <<
"expanding all child frames vertically" << endl;
446 TQPtrList<KMdiChildFrm> list( *
m_pZ );
447 list.setAutoDelete(
false );
448 while ( !list.isEmpty() )
451 if ( childFrm->
state() != KMdiChildFrm::Minimized )
453 if ( childFrm->
state() == KMdiChildFrm::Maximized )
456 childFrm->setGeometry( childFrm->x(), 0, childFrm->width(), height() );
466 kdDebug( 760 ) << k_funcinfo <<
"expanding all child frames horizontally" << endl;
468 TQPtrList<KMdiChildFrm> list( *
m_pZ );
469 list.setAutoDelete(
false );
470 while ( !list.isEmpty() )
473 if ( childFrm->
state() != KMdiChildFrm::Minimized )
475 if ( childFrm->
state() == KMdiChildFrm::Maximized )
478 childFrm->setGeometry( 0, childFrm->y(), width(), childFrm->height() );
488 int visibleChildCount = 0;
489 TQPtrListIterator<KMdiChildFrm> it( *
m_pZ );
490 for ( ; ( *it ); ++it )
492 if ( ( *it )->state() != KMdiChildFrm::Minimized && ( *it )->isVisible() )
495 return visibleChildCount;
500 kdDebug( 760 ) << k_funcinfo << endl;
506 kdDebug( 760 ) << k_funcinfo << endl;
508 static int colstable[ 9 ] = { 1, 1, 1, 2, 2, 2, 3, 3, 3 };
509 static int rowstable[ 9 ] = { 1, 2, 3, 2, 3, 3, 3, 3, 3 };
510 static int lastwindw[ 9 ] = { 1, 1, 1, 1, 2, 1, 3, 2, 1 };
511 static int colrecall[ 9 ] = { 0, 0, 0, 3, 3, 3, 6, 6, 6 };
512 static int rowrecall[ 9 ] = { 0, 0, 0, 0, 4, 4, 4, 4, 4 };
515 if ( numVisible < 1 )
517 kdDebug( 760 ) << k_funcinfo <<
"No visible child windows to tile" << endl;
522 int numToHandle = ( ( numVisible > maxWnds ) ? maxWnds : numVisible );
524 int xQuantum = width() / colstable[ numToHandle - 1 ];
528 widthToCompare = tcw->minimumWidth();
532 if ( xQuantum < widthToCompare )
534 if ( colrecall[ numToHandle - 1 ] != 0 )
541 int yQuantum = height() / rowstable[ numToHandle - 1 ];
544 heightToCompare = tcw->minimumHeight();
548 if ( yQuantum < heightToCompare )
550 if ( rowrecall[ numToHandle - 1 ] != 0 )
562 TQPtrListIterator<KMdiChildFrm> it( *
m_pZ );
563 for ( ; ( *it ); ++it )
566 if ( child->
state() != KMdiChildFrm::Minimized )
569 if ( child->
state() == KMdiChildFrm::Maximized )
572 if ( ( curWin % numToHandle ) == 0 )
573 child->setGeometry( curX, curY, xQuantum * lastwindw[ numToHandle - 1 ], yQuantum );
575 child->setGeometry( curX, curY, xQuantum, yQuantum );
578 if ( curCol < colstable[ numToHandle - 1 ] )
587 if ( curRow < rowstable[ numToHandle - 1 ] )
610 if ( numVisible < 1 )
613 int numCols = int( sqrt( (
double ) numVisible ) );
615 int *numRows =
new int[ numCols ];
618 while ( numCurCol < numCols )
620 numRows[numCurCol] = numCols;
624 int numDiff = numVisible - ( numCols * numCols );
625 int numCurDiffCol = numCols;
627 while ( numDiff > 0 )
630 numRows[numCurDiffCol]++;
632 if ( numCurDiffCol < 1 )
633 numCurDiffCol = numCols;
646 int xQuantum = width() / numCols;
647 int yQuantum = height() / numRows[numCurCol];
648 TQPtrListIterator<KMdiChildFrm> it( *
m_pZ );
649 for ( ; ( *it ); ++it )
652 if ( child->
state() != KMdiChildFrm::Minimized )
654 if ( child->
state() == KMdiChildFrm::Maximized )
657 child->setGeometry( curX, curY, xQuantum, yQuantum );
661 if ( numCurRow == numRows[numCurCol] )
667 if ( numCurCol != numCols )
668 yQuantum = height() / numRows[ numCurCol ];
675 if ( topChildWindow )
676 topChildWindow->m_pClient->
activate();
684 if ( numVisible < 1 )
687 int w = width() / numVisible;
690 if ( numVisible > 1 )
691 lastWidth = width() - ( w * ( numVisible - 1 ) );
697 int countVisible = 0;
699 TQPtrListIterator<KMdiChildFrm> it( *
m_pZ );
700 for ( ; ( *it ); ++it )
703 if ( child->
state() != KMdiChildFrm::Minimized )
705 if ( child->
state() == KMdiChildFrm::Maximized )
710 if ( countVisible < numVisible )
712 child->setGeometry( posX, 0, w, h );
717 child->setGeometry( posX, 0, lastWidth, h );
722 if ( topChildWindow )
723 topChildWindow->m_pClient->
activate();
731 TQPtrListIterator<KMdiChildFrm> it( *
m_pZ );
732 for ( ; ( *it ); ++it )
735 if ( child->
state() == KMdiChildFrm::Minimized )
738 if ( ( posX > 0 ) && ( posX + child->width() > width() ) )
741 posY -= child->height();
744 child->move( posX, posY - child->height() );
745 posX = child->geometry().right();
755 m_captionFontLineSpacing = fm.lineSpacing();
757 TQPtrListIterator<KMdiChildFrm> it( *
m_pZ );
758 for ( ; ( *it ); ++it )
785 TQColor& activeFG, TQColor& inactiveBG, TQColor& inactiveFG )
787 activeBG = TDEGlobalSettings::activeTitleColor();
788 activeFG = TDEGlobalSettings::activeTextColor();
789 inactiveBG = TDEGlobalSettings::inactiveTitleColor();
790 inactiveFG = TDEGlobalSettings::inactiveTextColor();