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( TQWidget::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 );
221 TQFocusEvent::setReason( TQFocusEvent::Other );
222 child->m_pClient->setFocus();
231 if ( child && child->
state() == KMdiChildFrm::Maximized )
233 int clientw = 0, clienth = 0;
234 if ( child->m_pClient != 0L )
236 clientw = child->m_pClient->width();
237 clienth = child->m_pClient->height();
239 child->resize( width() + KMDI_CHILDFRM_DOUBLE_BORDER,
240 height() + child->m_pCaption->
heightHint() + KMDI_CHILDFRM_SEPARATOR + KMDI_CHILDFRM_DOUBLE_BORDER );
244 TQWidget::resizeEvent( e );
252 if ( e->button() & TQt::RightButton )
260 if ( indexOfWindow < 0 )
262 indexOfWindow =
m_pZ->count();
263 kdDebug( 760 ) << k_funcinfo <<
"indexOfWindow was less than zero, using "
264 << indexOfWindow <<
" as new index" << endl;
268 if ( indexOfWindow == 0 )
270 kdDebug( 760 ) << k_funcinfo <<
"No windows. Returning TQPoint( 0, 0 ) as the cascade point" << endl;
274 bool topLevelMode =
false;
278 kdDebug( 760 ) << k_funcinfo <<
"Getting the cascade point for window index " << indexOfWindow << endl;
279 kdDebug( 760 ) << k_funcinfo <<
"Do we think we're in top level mode? " << topLevelMode << endl;
285 int h = ( topLevelMode ? TQApplication::desktop()->height() : height() );
286 int w = ( topLevelMode ? TQApplication::desktop()->width() : width() );
295 kdDebug( 760 ) << k_funcinfo <<
"child frame exists. resetting height and width values" << endl;
296 step = child->m_pCaption->
heightHint() + KMDI_CHILDFRM_BORDER;
297 availableHeight = h - child->minimumHeight();
298 availableWidth = w - child->minimumWidth();
301 for (
int i = 0; i < indexOfWindow; i++ )
307 if ( ax > availableWidth )
310 if ( ay > availableHeight )
322 if (
m_pZ->findRef( minimizedChild ) == -1 )
324 kdDebug( 760 ) << k_funcinfo <<
"child was minimized but wasn't in our list!" << endl;
328 kdDebug( 760 ) << k_funcinfo << endl;
329 if (
m_pZ->count() > 1 )
332 m_pZ->setAutoDelete(
false );
333 m_pZ->removeRef( minimizedChild );
334 m_pZ->setAutoDelete(
true );
335 m_pZ->insert( 0, minimizedChild );
339 kdDebug( 760 ) << k_funcinfo <<
"child just minimized from maximized state. maximize new top child" << endl;
341 if ( !minimizedChild )
344 if ( minimizedChild->
state() == KMdiChildFrm::Maximized )
347 minimizedChild->
setState( KMdiChildFrm::Maximized,
false );
360 kdDebug( 760 ) << k_funcinfo <<
"No more child windows left" << endl;
365 if ( !lastChild->m_pClient->hasFocus() )
368 TQPtrListIterator<KMdiChildFrm> it ( *
m_pZ );
369 for ( ; ( *it ); ++it )
371 if ( ( *it ) != lastChild )
372 ( *it )->m_pCaption->setActive(
false );
375 kdDebug( 760 ) << k_funcinfo <<
"Giving focus to " << lastChild->
caption() << endl;
384 kdDebug( 760 ) << k_funcinfo <<
"cascading windows but not changing their size" << endl;
386 TQPtrList<KMdiChildFrm> list( *
m_pZ );
387 list.setAutoDelete(
false );
388 while ( !list.isEmpty() )
391 if ( childFrm->
state() != KMdiChildFrm::Minimized )
393 if ( childFrm->
state() == KMdiChildFrm::Maximized )
406 kdDebug( 760 ) << k_funcinfo <<
"cascading windows. will make sure they are minimum sized" << endl;
408 TQPtrList<KMdiChildFrm> list( *
m_pZ );
410 list.setAutoDelete(
false );
411 while ( !list.isEmpty() )
414 if (childFrm->
state() != KMdiChildFrm::Minimized )
416 if (childFrm->
state() == KMdiChildFrm::Maximized )
420 childFrm->move( pnt );
421 TQSize curSize( width() - pnt.x(), height() - pnt.y() );
423 if ( ( childFrm->minimumSize().width() > curSize.width() ) ||
424 ( childFrm->minimumSize().height() > curSize.height() ) )
426 childFrm->resize( childFrm->minimumSize() );
429 childFrm->resize( curSize );
440 kdDebug( 760 ) << k_funcinfo <<
"expanding all child frames vertically" << endl;
442 TQPtrList<KMdiChildFrm> list( *
m_pZ );
443 list.setAutoDelete(
false );
444 while ( !list.isEmpty() )
447 if ( childFrm->
state() != KMdiChildFrm::Minimized )
449 if ( childFrm->
state() == KMdiChildFrm::Maximized )
452 childFrm->setGeometry( childFrm->x(), 0, childFrm->width(), height() );
462 kdDebug( 760 ) << k_funcinfo <<
"expanding all child frames horizontally" << endl;
464 TQPtrList<KMdiChildFrm> list( *
m_pZ );
465 list.setAutoDelete(
false );
466 while ( !list.isEmpty() )
469 if ( childFrm->
state() != KMdiChildFrm::Minimized )
471 if ( childFrm->
state() == KMdiChildFrm::Maximized )
474 childFrm->setGeometry( 0, childFrm->y(), width(), childFrm->height() );
484 int visibleChildCount = 0;
485 TQPtrListIterator<KMdiChildFrm> it( *
m_pZ );
486 for ( ; ( *it ); ++it )
488 if ( ( *it )->state() != KMdiChildFrm::Minimized && ( *it )->isVisible() )
491 return visibleChildCount;
496 kdDebug( 760 ) << k_funcinfo << endl;
502 kdDebug( 760 ) << k_funcinfo << endl;
504 static int colstable[ 9 ] = { 1, 1, 1, 2, 2, 2, 3, 3, 3 };
505 static int rowstable[ 9 ] = { 1, 2, 3, 2, 3, 3, 3, 3, 3 };
506 static int lastwindw[ 9 ] = { 1, 1, 1, 1, 2, 1, 3, 2, 1 };
507 static int colrecall[ 9 ] = { 0, 0, 0, 3, 3, 3, 6, 6, 6 };
508 static int rowrecall[ 9 ] = { 0, 0, 0, 0, 4, 4, 4, 4, 4 };
511 if ( numVisible < 1 )
513 kdDebug( 760 ) << k_funcinfo <<
"No visible child windows to tile" << endl;
518 int numToHandle = ( ( numVisible > maxWnds ) ? maxWnds : numVisible );
520 int xQuantum = width() / colstable[ numToHandle - 1 ];
524 widthToCompare = tcw->minimumWidth();
528 if ( xQuantum < widthToCompare )
530 if ( colrecall[ numToHandle - 1 ] != 0 )
537 int yQuantum = height() / rowstable[ numToHandle - 1 ];
540 heightToCompare = tcw->minimumHeight();
544 if ( yQuantum < heightToCompare )
546 if ( rowrecall[ numToHandle - 1 ] != 0 )
558 TQPtrListIterator<KMdiChildFrm> it( *
m_pZ );
559 for ( ; ( *it ); ++it )
562 if ( child->
state() != KMdiChildFrm::Minimized )
565 if ( child->
state() == KMdiChildFrm::Maximized )
568 if ( ( curWin % numToHandle ) == 0 )
569 child->setGeometry( curX, curY, xQuantum * lastwindw[ numToHandle - 1 ], yQuantum );
571 child->setGeometry( curX, curY, xQuantum, yQuantum );
574 if ( curCol < colstable[ numToHandle - 1 ] )
583 if ( curRow < rowstable[ numToHandle - 1 ] )
606 if ( numVisible < 1 )
609 int numCols = int( sqrt( (
double ) numVisible ) );
611 int *numRows =
new int[ numCols ];
614 while ( numCurCol < numCols )
616 numRows[numCurCol] = numCols;
620 int numDiff = numVisible - ( numCols * numCols );
621 int numCurDiffCol = numCols;
623 while ( numDiff > 0 )
626 numRows[numCurDiffCol]++;
628 if ( numCurDiffCol < 1 )
629 numCurDiffCol = numCols;
642 int xQuantum = width() / numCols;
643 int yQuantum = height() / numRows[numCurCol];
644 TQPtrListIterator<KMdiChildFrm> it( *
m_pZ );
645 for ( ; ( *it ); ++it )
648 if ( child->
state() != KMdiChildFrm::Minimized )
650 if ( child->
state() == KMdiChildFrm::Maximized )
653 child->setGeometry( curX, curY, xQuantum, yQuantum );
657 if ( numCurRow == numRows[numCurCol] )
663 if ( numCurCol != numCols )
664 yQuantum = height() / numRows[ numCurCol ];
671 if ( topChildWindow )
672 topChildWindow->m_pClient->
activate();
680 if ( numVisible < 1 )
683 int w = width() / numVisible;
686 if ( numVisible > 1 )
687 lastWidth = width() - ( w * ( numVisible - 1 ) );
693 int countVisible = 0;
695 TQPtrListIterator<KMdiChildFrm> it( *
m_pZ );
696 for ( ; ( *it ); ++it )
699 if ( child->
state() != KMdiChildFrm::Minimized )
701 if ( child->
state() == KMdiChildFrm::Maximized )
706 if ( countVisible < numVisible )
708 child->setGeometry( posX, 0, w, h );
713 child->setGeometry( posX, 0, lastWidth, h );
718 if ( topChildWindow )
719 topChildWindow->m_pClient->
activate();
727 TQPtrListIterator<KMdiChildFrm> it( *
m_pZ );
728 for ( ; ( *it ); ++it )
731 if ( child->
state() == KMdiChildFrm::Minimized )
734 if ( ( posX > 0 ) && ( posX + child->width() > width() ) )
737 posY -= child->height();
740 child->move( posX, posY - child->height() );
741 posX = child->geometry().right();
751 m_captionFontLineSpacing = fm.lineSpacing();
753 TQPtrListIterator<KMdiChildFrm> it( *
m_pZ );
754 for ( ; ( *it ); ++it )
781 TQColor& activeFG, TQColor& inactiveBG, TQColor& inactiveFG )
783 activeBG = TDEGlobalSettings::activeTitleColor();
784 activeFG = TDEGlobalSettings::activeTextColor();
785 inactiveBG = TDEGlobalSettings::inactiveTitleColor();
786 inactiveFG = TDEGlobalSettings::inactiveTextColor();
void destroyChild(KMdiChildFrm *child, bool focusTopChild=true)
Destroys a managed KMdiChildFrm Also deletes the client attached to this child.
TQColor m_captionInactiveBackColor
The foreground color of inactive MDI childframe window captions.
KMdiChildArea(TQWidget *parent)
Consruction.
TQPtrList< KMdiChildFrm > * m_pZ
Z Order stack of KMdiChildFrm childframe windows (top=last)
void cascadeMaximized()
Cascades all windows resizing them to the maximum available size.
TQColor m_captionActiveBackColor
The foreground color of the active MDI childframe window caption.
void lastChildFrmClosed()
Signals that the last attached (docked) MDI view has been closed.
void setMdiCaptionActiveForeColor(const TQColor &clr)
Sets the foreground color of the active MDI childframe window caption A relayout does not occur when ...
void expandVertical()
Maximize all windows but only in vertical direction.
KMdiChildFrm * topChild() const
Returns the topmost child (the active one) or 0 if there are no children.
TQColor m_captionInactiveForeColor
The background color of inactive MDI childframe window captions.
void manageChild(KMdiChildFrm *lpC, bool bShow=true, bool bCascade=true)
Appends a new KMdiChildFrm to this manager.
void focusTopChild()
Gives focus to the topmost child if it doesn't get focus automatically or you want to wait to give it...
void childMinimized(KMdiChildFrm *lpC, bool bWasMaximized)
Internally used.
void setMdiCaptionActiveBackColor(const TQColor &clr)
Sets the background color of the active MDI childframe window captions A relayout does not occur when...
void tilePragma()
Tile Pragma.
void destroyChildButNotItsView(KMdiChildFrm *lpC, bool bFocusTopChild=true)
Destroys a managed KMdiChildFrm Clients attached to the KMdiChildFrm are not deleted.
void layoutMinimizedChildren()
Position and layout the minimized child frames.
void expandHorizontal()
Maximize all windows but only in horizontal direction.
void popupWindowMenu(TQPoint)
Signals a KMdiMainFrm that the 'Window' popup menu must be shown.
void cascadeWindows()
Cascades all windows resizing them to the minimum size.
virtual void resizeEvent(TQResizeEvent *)
Automatically resizes a maximized MDI view and layouts the positions of minimized MDI views.
void setMdiCaptionInactiveBackColor(const TQColor &clr)
Sets the background color of inactive MDI childframe window captions A relayout does not occur when u...
void sysButtonConnectionsMustChange(KMdiChildFrm *, KMdiChildFrm *)
Signals a KMdiMainFrm that the signal/slot connections of the system buttons in the menubar (only in ...
int getVisibleChildCount() const
Returns the number of visible children.
void setMdiCaptionFont(const TQFont &fnt)
Sets the MDI childframe window caption font A relayout does not occur when using this function.
TQFont m_captionFont
The MDI childframe window caption font.
void tileVertically()
Tile all the windows in the child area vertically.
TQColor m_captionActiveForeColor
The background color of the active MDI childframe window captions.
void tileAllInternal(int maxWnds)
Internally used for the tile algorithm.
void setTopChild(KMdiChildFrm *child, bool setFocus=false)
Brings the child to the top of the stack The child is focused if setFocus is true.
void tileAnodine()
Tile Anodine.
void mousePressEvent(TQMouseEvent *e)
Shows the 'Window' popup menu on right mouse button click.
~KMdiChildArea()
Destructor : THERE should be no child windows anymore...
void setMdiCaptionInactiveForeColor(const TQColor &clr)
Sets the foreground color of inactive MDI childframe window captions A relayout does not occur when u...
static void getCaptionColors(const TQPalette &pal, TQColor &activeBG, TQColor &activeFG, TQColor &inactiveBG, TQColor &inactiveFG) TDE_DEPRECATED
Gets all caption colors, consistent with current WM settings (or other Desktop settings e....
void noMaximizedChildFrmLeft(KMdiChildFrm *)
Signals that there aren't maximized child frames any more.
TQSize m_defaultChildFrmSize
the default size of an newly created childframe
TQPoint getCascadePoint(int indexOfWindow=-1)
Calculates the cascade point for the given index.
int heightHint()
Returns the caption bar height depending on the used font.
MdiWindowState state() const
Returns the current state of the window.
void setState(MdiWindowState state, bool bAnimate=true)
Minimizes, Maximizes, or restores the window.
void restorePressed()
Handles a click on the Restore (Normalize) button.
const TQString & caption()
Gets the caption of this mdi child.
void unsetClient(TQPoint positionOffset=TQPoint(0, 0))
Reparents the client widget to 0 (desktop), moves with an offset from the original position Removes t...
void activate()
This method does the same as focusInEvent().