# kmdi Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kmdimainfrm.cpp

    00001 //----------------------------------------------------------------------------
    00002 //    filename             : kmdimainfrm.cpp
    00003 //----------------------------------------------------------------------------
    00004 //    Project              : KDE MDI extension
    00005 //
    00006 //    begin                : 07/1999       by Szymon Stefanek as part of kvirc
    00007 //                                         (an IRC application)
    00008 //    changes              : 09/1999       by Falk Brettschneider to create an
    00009 //                           - 06/2000     stand-alone Qt extension set of
    00010 //                                         classes and a Qt-based library
    00011 //                           2000-2003     maintained by the KDevelop project
    00012 //    patches              : 02/2000       by Massimo Morin (mmorin@schedsys.com)
    00013 //                           */2000        by Lars Beikirch (Lars.Beikirch@gmx.net)
    00014 //                           01/2003       by Jens Zurheide (jens.zurheide@gmx.de)
    00015 //
    00016 //    copyright            : (C) 1999-2003 by Szymon Stefanek (stefanek@tin.it)
    00017 //                                         and
    00018 //                                         Falk Brettschneider
    00019 //    email                :  falkbr@kdevelop.org (Falk Brettschneider)
    00020 //----------------------------------------------------------------------------
    00021 //
    00022 //----------------------------------------------------------------------------
    00023 //
    00024 //    This program is free software; you can redistribute it and/or modify
    00025 //    it under the terms of the GNU Library General Public License as
    00026 //    published by the Free Software Foundation; either version 2 of the
    00027 //    License, or (at your option) any later version.
    00028 //
    00029 //----------------------------------------------------------------------------
    00030
    00031
    00032 /*
    00033  * ATTENTION: please do you part to try to make this file legible.  It's
    00034  * extremely hard to read already.  Especially follow the indenting rules.
    00035  */
    00036 #include "config.h"
    00037
    00038 #include <assert.h>
    00039
    00040 #include <qcursor.h>
    00041 #include <qclipboard.h>
    00042 #include <qobjectlist.h>
    00043 #include <qpopupmenu.h>
    00044 #include <qmenubar.h>
    00045
    00046 #include <kmenubar.h>
    00047 #include <kapplication.h>
    00048 #include <kdebug.h>
    00049 #include <kdeversion.h>
    00050 #include <qtabwidget.h>
    00051 #include <klocale.h>
    00052
    00053 #include <kiconloader.h>
    00054 #include <kmdidockcontainer.h>
    00055
    00056
    00057 #include <qtoolbutton.h>
    00058 #include <qdockarea.h>
    00059 #include <qlayout.h>
    00060 #include <qtimer.h>
    00061 #include <qtextstream.h>
    00062 #include <qstring.h>
    00063 #include <qmap.h>
    00064 #include <qvaluelist.h>
    00065
    00066 #include "kmdimainfrm.h"
    00067 #include "kmditaskbar.h"
    00068 #include "kmdichildfrm.h"
    00069 #include "kmdichildarea.h"
    00070 #include "kmdichildview.h"
    00071 #include "kmdidockcontainer.h"
    00072 #include "kmditoolviewaccessor_p.h"
    00073 #include "kmdifocuslist.h"
    00074 #include "kmdidocumentviewtabwidget.h"
    00075 #include "kmdiguiclient.h"
    00076
    00077 #include "win_undockbutton.xpm"
    00078 #include "win_minbutton.xpm"
    00079 #include "win_restorebutton.xpm"
    00080 #include "win_closebutton.xpm"
    00081 #include "kde_undockbutton.xpm"
    00082 #include "kde_minbutton.xpm"
    00083 #include "kde_restorebutton.xpm"
    00084 #include "kde_closebutton.xpm"
    00085 #include "kde2_undockbutton.xpm"
    00086 #include "kde2_minbutton.xpm"
    00087 #include "kde2_restorebutton.xpm"
    00088 #include "kde2_closebutton.xpm"
    00089 #include "kde2laptop_undockbutton.xpm"
    00090 #include "kde2laptop_minbutton.xpm"
    00091 #include "kde2laptop_restorebutton.xpm"
    00092 #include "kde2laptop_closebutton.xpm"
    00093 #include "kde2laptop_closebutton_menu.xpm"
    00094
    00095 #ifdef Q_WS_X11
    00096 #ifndef NO_KDE
    00097 #include <X11/X.h> // schroder
    00098 #include <X11/Xlib.h> // schroder
    00099 #endif
    00100
    00101 #ifdef KeyRelease
    00102 /* I hate the defines in the X11 header files. Get rid of one of them */
    00103 #undef KeyRelease
    00104 #endif
    00105
    00106 #ifdef KeyPress
    00107 /* I hate the defines in the X11 header files. Get rid of one of them */
    00108 #undef KeyPress
    00109 #endif
    00110 #endif // Q_WS_X11 && ! K_WS_QTONLY
    00111
    00112 using namespace KParts;
    00113
    00114 KMdi::FrameDecor KMdiMainFrm::m_frameDecoration = KMdi::KDELook;
    00115
    00116 class KMdiMainFrmPrivate
    00117 {
    00118 public:
    00119     KMdiMainFrmPrivate() : focusList( 0 )
    00120     {
    00121         for ( int i = 0;i < 4;i++ )
    00122         {
    00123             activeDockPriority[ i ] = 0;
    00124             m_styleIDEAlMode = 0;
    00125             m_toolviewStyle = 0;
    00126         }
    00127     }
    00128     ~KMdiMainFrmPrivate()
    00129     {}
    00130     KMdiDockContainer* activeDockPriority[ 4 ];
    00131     KMdiFocusList *focusList;
    00132     int m_styleIDEAlMode;
    00133     int m_toolviewStyle;
    00134     KAction *closeWindowAction;
    00135 };
    00136
    00137 //============ constructor ============//
    00138 KMdiMainFrm::KMdiMainFrm( QWidget* parentWidget, const char* name, KMdi::MdiMode mdiMode, WFlags flags )
    00139         : KParts::DockMainWindow( parentWidget, name, flags )
    00140         , m_mdiMode( KMdi::UndefinedMode )
    00141         , m_pMdi( 0L )
    00142         , m_pTaskBar( 0L )
    00143         , m_pDocumentViews( 0L )
    00144         , m_pCurrentWindow( 0L )
    00145         , m_pWindowPopup( 0L )
    00146         , m_pTaskBarPopup( 0L )
    00147         , m_pWindowMenu( 0L )
    00148         , m_pDockMenu( 0L )
    00149         , m_pMdiModeMenu( 0L )
    00150         , m_pPlacingMenu( 0L )
    00151         , m_pMainMenuBar( 0L )
    00152         , m_pUndockButtonPixmap( 0L )
    00153         , m_pMinButtonPixmap( 0L )
    00154         , m_pRestoreButtonPixmap( 0L )
    00155         , m_pCloseButtonPixmap( 0L )
    00156         , m_pUndock( 0L )
    00157         , m_pMinimize( 0L )
    00158         , m_pRestore( 0L )
    00159         , m_pClose( 0L )
    00160         , m_bMaximizedChildFrmMode( false )
    00161         , m_oldMainFrmHeight( 0 )
    00162         , m_oldMainFrmMinHeight( 0 )
    00163         , m_oldMainFrmMaxHeight( 0 )
    00164         , m_bSDIApplication( false )
    00165         , m_pDockbaseAreaOfDocumentViews( 0L )
    00166         , m_pTempDockSession( 0L )
    00167         , m_bClearingOfWindowMenuBlocked( false )
    00168         , m_pDragEndTimer( 0L )
    00169         , m_bSwitching( false )
    00170         , m_leftContainer( 0 )
    00171         , m_rightContainer( 0 )
    00172         , m_topContainer( 0 )
    00173         , m_bottomContainer( 0 )
    00174         , d( new KMdiMainFrmPrivate() )
    00175         , m_mdiGUIClient( 0 )
    00176         , m_managedDockPositionMode( false )
    00177         , m_documentTabWidget( 0 )
    00178 {
    00179     kdDebug(760) << k_funcinfo << endl;
    00180     // Create the local lists of windows
    00181     m_pDocumentViews = new QPtrList<KMdiChildView>;
    00182     m_pDocumentViews->setAutoDelete( false );
    00183     m_pToolViews = new QMap<QWidget*, KMdiToolViewAccessor*>;
    00184
    00185     // This seems to be needed (re-check it after Qt2.0 comed out)
    00186     setFocusPolicy( ClickFocus );
    00187
    00188     // create the central widget
    00189     createMdiManager();
    00190
    00191     // cover KMdi's childarea by a dockwidget
    00192     m_pDockbaseAreaOfDocumentViews = createDockWidget( "mdiAreaCover", QPixmap(), 0L, "mdi_area_cover" );
    00193     m_pDockbaseAreaOfDocumentViews->setDockWindowTransient( this, true );
    00194     m_pDockbaseAreaOfDocumentViews->setEnableDocking( KDockWidget::DockNone );
    00195     m_pDockbaseAreaOfDocumentViews->setDockSite( KDockWidget::DockCorner );
    00196     m_pDockbaseAreaOfDocumentViews->setWidget( m_pMdi );
    00197     // set this dock to main view
    00198     setView( m_pDockbaseAreaOfDocumentViews );
    00199     setMainDockWidget( m_pDockbaseAreaOfDocumentViews );
    00200
    00201     // Apply options for the MDI manager
    00202     applyOptions();
    00203
    00204     m_pTaskBarPopup = new QPopupMenu( this, "taskbar_popup_menu" );
    00205     m_pWindowPopup = new QPopupMenu( this, "window_popup_menu" );
    00206
    00207     m_pWindowMenu = new QPopupMenu( this, "window_menu" );
    00208     m_pWindowMenu->setCheckable( true );
    00209     QObject::connect( m_pWindowMenu, SIGNAL( aboutToShow() ), this, SLOT( fillWindowMenu() ) );
    00210
    00211     m_pDockMenu = new QPopupMenu( this, "dock_menu" );
    00212     m_pDockMenu->setCheckable( true );
    00213
    00214     m_pMdiModeMenu = new QPopupMenu( this, "mdimode_menu" );
    00215     m_pMdiModeMenu->setCheckable( true );
    00216
    00217     m_pPlacingMenu = new QPopupMenu( this, "placing_menu" );
    00218
    00219     d->closeWindowAction = new KAction(i18n("&Close"),
    00220 #ifdef Q_WS_WIN
    00221         CTRL|Key_F4,
    00222 #else
    00223         0,
    00224 #endif
    00225         this, SLOT(closeActiveView()), actionCollection(), "window_close");
    00226
    00227     // the MDI view taskbar
    00228     createTaskBar();
    00229
    00230     // this is only a hack, but prevents us from crash because the buttons are otherwise
    00231     // not created before we switch the modes where we need them !!!
    00232     setMenuForSDIModeSysButtons( menuBar() );
    00233
    00234     switch ( mdiMode )
    00235     {
    00236     case KMdi::IDEAlMode:
    00237         kdDebug(760) << k_funcinfo << "Switching to IDEAl mode" << endl;
    00238         switchToIDEAlMode();
    00239         break;
    00240     case KMdi::TabPageMode:
    00241         kdDebug(760) << k_funcinfo << "Switching to tab page mode" << endl;
    00242         switchToTabPageMode();
    00243         break;
    00244     case KMdi::ToplevelMode:
    00245         kdDebug(760) << k_funcinfo << "Switching to top level mode" << endl;
    00246         switchToToplevelMode();
    00247         break;
    00248     default:
    00249         m_mdiMode = KMdi::ChildframeMode;
    00250         kdDebug(760) << k_funcinfo << "Switching to child frame mode" << endl;
    00251         break;
    00252     }
    00253
    00254     // drag end timer
    00255     m_pDragEndTimer = new QTimer();
    00256     connect( m_pDragEndTimer, SIGNAL( timeout() ), this, SLOT( dragEndTimeOut() ) );
    00257     connect( guiFactory(), SIGNAL( clientAdded( KXMLGUIClient* ) ),
    00258              this, SLOT( verifyToplevelHeight() ) );
    00259     connect( guiFactory(), SIGNAL( clientRemoved( KXMLGUIClient* ) ),
    00260              this, SLOT( verifyToplevelHeight() ) );
    00261 }
    00262
    00263 void KMdiMainFrm::verifyToplevelHeight()
    00264 {
    00265     if ( m_mdiMode != KMdi::ToplevelMode )
    00266         return;
    00267
    00268     //kdDebug(760) << k_funcinfo << endl;
    00269     int topDockHeight = topDock() ? topDock()->height() : 0;
    00270     int menuBarHeight = hasMenuBar() ? menuBar()->height() : 0;
    00271     setFixedHeight( topDockHeight + menuBarHeight );
    00272     resize( width(), height() );
    00273 }
    00274
    00275 void KMdiMainFrm::setStandardMDIMenuEnabled( bool showModeMenu )
    00276 {
    00277     m_mdiGUIClient = new KMDIPrivate::KMDIGUIClient( this, showModeMenu );
    00278     connect( m_mdiGUIClient, SIGNAL( toggleTop() ), this, SIGNAL( toggleTop() ) );
    00279     connect( m_mdiGUIClient, SIGNAL( toggleLeft() ), this, SIGNAL( toggleLeft() ) );
    00280     connect( m_mdiGUIClient, SIGNAL( toggleRight() ), this, SIGNAL( toggleRight() ) );
    00281     connect( m_mdiGUIClient, SIGNAL( toggleBottom() ), this, SIGNAL( toggleBottom() ) );
    00282
    00283     if ( m_mdiMode == KMdi::IDEAlMode )
    00284     {
    00285         if ( m_topContainer )
    00286             connect( this, SIGNAL( toggleTop() ), m_topContainer->getWidget(), SLOT( toggle() ) );
    00287         if ( m_leftContainer )
    00288             connect( this, SIGNAL( toggleLeft() ), m_leftContainer->getWidget(), SLOT( toggle() ) );
    00289         if ( m_rightContainer )
    00290             connect( this, SIGNAL( toggleRight() ), m_rightContainer->getWidget(), SLOT( toggle() ) );
    00291         if ( m_bottomContainer )
    00292             connect( this, SIGNAL( toggleBottom() ), m_bottomContainer->getWidget(), SLOT( toggle() ) );
    00293     }
    00294
    00295     emit mdiModeHasBeenChangedTo( m_mdiMode );
    00296 }
    00297
    00298 //============ ~KMdiMainFrm ============//
    00299 KMdiMainFrm::~KMdiMainFrm()
    00300 {
    00301     //save the children first to a list, as removing invalidates our iterator
    00302     QValueList<KMdiChildView*> children;
    00303     for ( KMdiChildView * w = m_pDocumentViews->first();w;w = m_pDocumentViews->next() )
    00304         children.append( w );
    00305
    00306     // safely close the windows so properties are saved...
    00307     QValueListIterator<KMdiChildView*> childIt;
    00308     for ( childIt = children.begin(); childIt != children.end(); ++childIt )
    00309     {
    00310         closeWindow( *childIt, false ); // without re-layout taskbar!
    00311     }
    00312
    00313     emit lastChildViewClosed();
    00314     delete m_pDocumentViews;
    00315     delete m_pToolViews;
    00316     m_pToolViews = 0;
    00317     delete m_pDragEndTimer;
    00318
    00319     delete m_pUndockButtonPixmap;
    00320     delete m_pMinButtonPixmap;
    00321     delete m_pRestoreButtonPixmap;
    00322     delete m_pCloseButtonPixmap;
    00323
    00324     //deletes added for Release-Version-Pop-Up-WinMenu-And-Go-Out-Problem
    00325     delete m_pDockMenu;
    00326     delete m_pMdiModeMenu;
    00327     delete m_pPlacingMenu;
    00328     delete m_pTaskBarPopup;
    00329     delete m_pWindowPopup;
    00330     delete m_pWindowMenu;
    00331     delete m_mdiGUIClient;
    00332     delete m_pTempDockSession;
    00333     m_mdiGUIClient = 0;
    00334     delete d;
    00335     d = 0;
    00336 }
    00337
    00338 //============ applyOptions ============//
    00339 //FIXME something wrong with this function. dunno what though
    00340 void KMdiMainFrm::applyOptions()
    00341 {
    00342     QPtrListIterator<KMdiChildView> it( *m_pDocumentViews );
    00343     for ( ; ( *it ); ++it )
    00344     {
    00345         QWidget* childFrame = 0L;
    00346         if ( ( *it )->mdiParent() )
    00347         {
    00348             kdDebug(760) << k_funcinfo << "using child view's mdi parent for resize hack" << endl;
    00349             childFrame = ( *it )->mdiParent();
    00350         }
    00351         else
    00352         {
    00353             kdDebug(760) << k_funcinfo << "using child view for resize hack" << endl;
    00354             childFrame = ( *it );
    00355         }
    00356
    00357         int w = childFrame->width();
    00358         int h = childFrame->height();
    00359         childFrame->resize( w + 1, h + 1 );
    00360         childFrame->resize( w - 1, h - 1 );
    00361     }
    00362 }
    00363
    00364 //============ createMdiManager ============//
    00365 void KMdiMainFrm::createMdiManager()
    00366 {
    00367     kdDebug(760) << k_funcinfo << "creating MDI manager" << endl;
    00368     m_pMdi = new KMdiChildArea( this );
    00369     setCentralWidget( m_pMdi );
    00370     QObject::connect( m_pMdi, SIGNAL( nowMaximized( bool ) ),
    00371                       this, SLOT( setEnableMaximizedChildFrmMode( bool ) ) );
    00372     QObject::connect( m_pMdi, SIGNAL( noMaximizedChildFrmLeft( KMdiChildFrm* ) ),
    00373                       this, SLOT( switchOffMaximizeModeForMenu( KMdiChildFrm* ) ) );
    00374     QObject::connect( m_pMdi, SIGNAL( sysButtonConnectionsMustChange( KMdiChildFrm*, KMdiChildFrm* ) ),
    00375                       this, SLOT( updateSysButtonConnections( KMdiChildFrm*, KMdiChildFrm* ) ) );
    00376     QObject::connect( m_pMdi, SIGNAL( popupWindowMenu( QPoint ) ),
    00377                       this, SLOT( popupWindowMenu( QPoint ) ) );
    00378     QObject::connect( m_pMdi, SIGNAL( lastChildFrmClosed() ),
    00379                       this, SIGNAL( lastChildFrmClosed() ) );
    00380 }
    00381
    00382 //============ createTaskBar ==============//
    00383 void KMdiMainFrm::createTaskBar()
    00384 {
    00385     m_pTaskBar = new KMdiTaskBar( this, QMainWindow::DockBottom );
    00386     m_pTaskBar->installEventFilter( this );
    00387 }
    00388
    00389 void KMdiMainFrm::slot_toggleTaskBar()
    00390 {
    00391     if ( !m_pTaskBar )
    00392         return;
    00393     m_pTaskBar->switchOn( !m_pTaskBar->isSwitchedOn() );
    00394 }
    00395
    00396 void KMdiMainFrm::resizeEvent( QResizeEvent *e )
    00397 {
    00398     if ( ( m_mdiMode == KMdi::ToplevelMode ) && !parentWidget() )
    00399     {
    00400         if ( e->oldSize().height() != e->size().height() )
    00401             return ;
    00402     }
    00403     KParts::DockMainWindow::resizeEvent( e );
    00404     if ( !m_mdiGUIClient )
    00405         return ;
    00406     setSysButtonsAtMenuPosition();
    00407 }
    00408
    00409 //================ setMinimumSize ===============//
    00410
    00411 void KMdiMainFrm::setMinimumSize( int minw, int minh )
    00412 {
    00413     if ( ( m_mdiMode == KMdi::ToplevelMode ) && !parentWidget() )
    00414         return ;
    00415     DockMainWindow::setMinimumSize( minw, minh );
    00416 }
    00417
    00418 //================ wrapper ===============//
    00419
    00420 KMdiChildView* KMdiMainFrm::createWrapper( QWidget *view, const QString& name, const QString& shortName )
    00421 {
    00422     Q_ASSERT( view ); // if this assert fails, then some part didn't return a widget. Fix the part ;)
    00423
    00424     KMdiChildView* pMDICover = new KMdiChildView( name /*caption*/, 0L /*parent*/,
    00425                                                   name.latin1() );
    00426     QBoxLayout* pLayout = new QHBoxLayout( pMDICover, 0, -1, "layout" );
    00427     view->reparent( pMDICover, QPoint( 0, 0 ) );
    00428     pLayout->addWidget( view );
    00429     //  pMDICover->setName(name);
    00430     pMDICover->setTabCaption( shortName );
    00431     pMDICover->setCaption( name );
    00432
    00433     const QPixmap* wndIcon = view->icon();
    00434     if ( wndIcon )
    00435         pMDICover->setIcon( *wndIcon );
    00436
    00437     pMDICover->trackIconAndCaptionChanges( view );
    00438     return pMDICover;
    00439 }
    00440
    00441 //================ addWindow ===============//
    00442
    00443 void KMdiMainFrm::addWindow( KMdiChildView* pWnd, int flags )
    00444 {
    00445     addWindow( pWnd, flags, -1 );
    00446 }
    00447
    00448 void KMdiMainFrm::addWindow( KMdiChildView* pWnd, int flags, int index )
    00449 {
    00450     if ( windowExists( pWnd, AnyView ) ) //already added
    00451         return;
    00452
    00453     if ( flags & KMdi::ToolWindow )
    00454     {
    00455         addToolWindow( pWnd );
    00456         // some kind of cascading
    00457         pWnd->move( m_pMdi->mapToGlobal( m_pMdi->getCascadePoint() ) );
    00458
    00459         return ;
    00460     }
    00461
    00462     d->closeWindowAction->setEnabled(true);
    00463
    00464     // common connections used when under MDI control
    00465     QObject::connect( pWnd, SIGNAL( clickedInWindowMenu( int ) ), this, SLOT( windowMenuItemActivated( int ) ) );
    00466     QObject::connect( pWnd, SIGNAL( focusInEventOccurs( KMdiChildView* ) ), this, SLOT( activateView( KMdiChildView* ) ) );
    00467     QObject::connect( pWnd, SIGNAL( childWindowCloseRequest( KMdiChildView* ) ), this, SLOT( childWindowCloseRequest( KMdiChildView* ) ) );
    00468     QObject::connect( pWnd, SIGNAL( attachWindow( KMdiChildView*, bool ) ), this, SLOT( attachWindow( KMdiChildView*, bool ) ) );
    00469     QObject::connect( pWnd, SIGNAL( detachWindow( KMdiChildView*, bool ) ), this, SLOT( detachWindow( KMdiChildView*, bool ) ) );
    00470     QObject::connect( pWnd, SIGNAL( clickedInDockMenu( int ) ), this, SLOT( dockMenuItemActivated( int ) ) );
    00471     QObject::connect( pWnd, SIGNAL( activated( KMdiChildView* ) ), this, SIGNAL( viewActivated( KMdiChildView* ) ) );
    00472     QObject::connect( pWnd, SIGNAL( deactivated( KMdiChildView* ) ), this, SIGNAL( viewDeactivated( KMdiChildView* ) ) );
    00473
    00474     if ( index == -1 )
    00475         m_pDocumentViews->append( pWnd );
    00476     else
    00477         m_pDocumentViews->insert( index, pWnd );
    00478
    00479     if ( m_pTaskBar )
    00480     {
    00481         KMdiTaskBarButton* but = m_pTaskBar->addWinButton( pWnd );
    00482         QObject::connect( pWnd, SIGNAL( tabCaptionChanged( const QString& ) ), but, SLOT( setNewText( const QString& ) ) );
    00483     }
    00484
    00485     // embed the view depending on the current MDI mode
    00486     if ( m_mdiMode == KMdi::TabPageMode || m_mdiMode == KMdi::IDEAlMode )
    00487     {
    00488         QPixmap pixmap;
    00489         if ( pWnd->icon() )
    00490             pixmap = *( pWnd->icon() );
    00491
    00492         m_documentTabWidget->insertTab( pWnd, pixmap, pWnd->tabCaption(), index );
    00493
    00494         connect( pWnd, SIGNAL( iconUpdated( QWidget*, QPixmap ) ), m_documentTabWidget, SLOT( updateIconInView( QWidget*, QPixmap ) ) );
    00495         connect( pWnd, SIGNAL( captionUpdated( QWidget*, const QString& ) ), m_documentTabWidget, SLOT( updateCaptionInView( QWidget*, const QString& ) ) );
    00496     }
    00497     else
    00498     {
    00499         if ( ( flags & KMdi::Detach ) || ( m_mdiMode == KMdi::ToplevelMode ) )
    00500         {
    00501             detachWindow( pWnd, !( flags & KMdi::Hide ) );
    00502             emit childViewIsDetachedNow( pWnd ); // fake it because detach won't call it in this case of addWindow-to-MDI
    00503         }
    00504         else
    00505             attachWindow( pWnd, !( flags & KMdi::Hide ), flags & KMdi::UseKMdiSizeHint );
    00506
    00507         if ( ( m_bMaximizedChildFrmMode && ( !m_bSDIApplication && ( flags & KMdi::Detach ) )
    00508                && m_mdiMode != KMdi::ToplevelMode ) || ( flags & KMdi::Maximize ) )
    00509         {
    00510             if ( !pWnd->isMaximized() )
    00511                 pWnd->maximize();
    00512         }
    00513
    00514         if ( !m_bSDIApplication || ( flags & KMdi::Detach ) )
    00515         {
    00516             if ( flags & KMdi::Minimize )
    00517                 pWnd->minimize();
    00518
    00519             if ( !( flags & KMdi::Hide ) )
    00520             {
    00521                 if ( pWnd->isAttached() )
    00522                     pWnd->mdiParent()->show();
    00523                 else
    00524                     pWnd->show();
    00525             }
    00526         }
    00527     }
    00528 }
    00529
    00530 //============ addWindow ============//
    00531 void KMdiMainFrm::addWindow( KMdiChildView* pWnd, QRect rectNormal, int flags )
    00532 {
    00533     addWindow( pWnd, flags );
    00534     if ( m_bMaximizedChildFrmMode && pWnd->isAttached() )
    00535         pWnd->setRestoreGeometry( rectNormal );
    00536     else
    00537         pWnd->setGeometry( rectNormal );
    00538 }
    00539
    00540 //============ addWindow ============//
    00541 void KMdiMainFrm::addWindow( KMdiChildView* pWnd, QPoint pos, int flags )
    00542 {
    00543     addWindow( pWnd, flags );
    00544     if ( m_bMaximizedChildFrmMode && pWnd->isAttached() )
    00545         pWnd->setRestoreGeometry( QRect( pos, pWnd->restoreGeometry().size() ) );
    00546     else
    00547         pWnd->move( pos );
    00548 }
    00549
    00550
    00551
    00552 KMdiToolViewAccessor *KMdiMainFrm::createToolWindow()
    00553 {
    00554     return new KMdiToolViewAccessor( this );
    00555 }
    00556
    00557
    00558 void KMdiMainFrm::deleteToolWindow( QWidget* pWnd )
    00559 {
    00560     if ( m_pToolViews->contains( pWnd ) )
    00561         deleteToolWindow( ( *m_pToolViews ) [ pWnd ] );
    00562 }
    00563
    00564 void KMdiMainFrm::deleteToolWindow( KMdiToolViewAccessor *accessor )
    00565 {
    00566     delete accessor;
    00567 }
    00568
    00569 //============ addWindow ============//
    00570 KMdiToolViewAccessor *KMdiMainFrm::addToolWindow( QWidget* pWnd, KDockWidget::DockPosition pos, QWidget* pTargetWnd,
    00571                                                   int percent, const QString& tabToolTip, const QString& tabCaption )
    00572 {
    00573     QWidget* tvta = pWnd;
    00574     KDockWidget* pDW = dockManager->getDockWidgetFromName( pWnd->name() );
    00575     if ( pDW )
    00576     {
    00577         // probably readDockConfig already created the widgetContainer, use that
    00578         pDW->setWidget( pWnd );
    00579
    00580         if ( pWnd->icon() )
    00581             pDW->setPixmap( *pWnd->icon() );
    00582
    00583         pDW->setTabPageLabel( ( tabCaption == 0 ) ? pWnd->caption() : tabCaption );
    00584         pDW->setToolTipString( tabToolTip );
    00585         dockManager->removeFromAutoCreateList( pDW );
    00586         pWnd = pDW;
    00587     }
    00588
    00589     QRect r = pWnd->geometry();
    00590
    00591     KMdiToolViewAccessor *mtva = new KMdiToolViewAccessor( this, pWnd, tabToolTip, ( tabCaption == 0 ) ? pWnd->caption() : tabCaption );
    00592     m_pToolViews->insert( tvta, mtva );
    00593
    00594     if ( pos == KDockWidget::DockNone )
    00595     {
    00596         mtva->d->widgetContainer->setEnableDocking( KDockWidget::DockNone );
    00597         mtva->d->widgetContainer->reparent( this, Qt::WType_TopLevel | Qt::WType_Dialog, r.topLeft(), true ); //pToolView->isVisible());
    00598     }
    00599     else //add and dock the toolview as a dockwidget view
    00600         mtva->place( pos, pTargetWnd, percent );
    00601
    00602
    00603     return mtva;
    00604 }
    00605
    00606 //============ attachWindow ============//
    00607 void KMdiMainFrm::attachWindow( KMdiChildView *pWnd, bool bShow, bool bAutomaticResize )
    00608 {
    00609     pWnd->installEventFilter( this );
    00610
    00611     // decide whether window shall be cascaded
    00612     bool bCascade = false;
    00613     QApplication::sendPostedEvents();
    00614     QRect frameGeo = pWnd->frameGeometry();
    00615     QPoint topLeftScreen = pWnd->mapToGlobal( QPoint( 0, 0 ) );
    00616     QPoint topLeftMdiChildArea = m_pMdi->mapFromGlobal( topLeftScreen );
    00617     QRect childAreaGeo = m_pMdi->geometry();
    00618     if ( topLeftMdiChildArea.x() < 0 || topLeftMdiChildArea.y() < 0 ||
    00619          ( topLeftMdiChildArea.x() + frameGeo.width() > childAreaGeo.width() ) ||
    00620          ( topLeftMdiChildArea.y() + frameGeo.height() > childAreaGeo.height() ) )
    00621     {
    00622         bCascade = true;
    00623     }
    00624
    00625     // create frame and insert child view
    00626     KMdiChildFrm *lpC = new KMdiChildFrm( m_pMdi );
    00627     pWnd->hide();
    00628     if ( !bCascade )
    00629         lpC->move( topLeftMdiChildArea );
    00630
    00631     lpC->setClient( pWnd, bAutomaticResize );
    00632     lpC->setFocus();
    00633     pWnd->youAreAttached( lpC );
    00634     if ( ( m_mdiMode == KMdi::ToplevelMode ) && !parentWidget() )
    00635     {
    00636         setMinimumHeight( m_oldMainFrmMinHeight );
    00637         setMaximumHeight( m_oldMainFrmMaxHeight );
    00638         resize( width(), m_oldMainFrmHeight );
    00639         m_oldMainFrmHeight = 0;
    00640         switchToChildframeMode();
    00641     }
    00642
    00643     m_pMdi->manageChild( lpC, false, bCascade );
    00644     if ( m_pMdi->topChild() && m_pMdi->topChild() ->isMaximized() )
    00645     {
    00646         QRect r = lpC->geometry();
    00647         lpC->setGeometry( -lpC->m_pClient->x(), -lpC->m_pClient->y(),
    00648                           m_pMdi->width() + KMDI_CHILDFRM_DOUBLE_BORDER,
    00649                           m_pMdi->height() + lpC->captionHeight() + KMDI_CHILDFRM_SEPARATOR + KMDI_CHILDFRM_DOUBLE_BORDER );
    00650         lpC->setRestoreGeometry( r );
    00651     }
    00652
    00653     if ( bShow )
    00654     {
    00655         lpC->show();
    00656     }
    00657
    00658 #undef FocusIn
    00659     QFocusEvent fe( QEvent::FocusIn );
    00660     QApplication::sendEvent( pWnd, &fe );
    00661
    00662     m_pCurrentWindow = pWnd;  // required for checking the active item
    00663 }
    00664
    00665 //============= detachWindow ==============//
    00666 void KMdiMainFrm::detachWindow( KMdiChildView *pWnd, bool bShow )
    00667 {
    00668     if ( pWnd->isAttached() )
    00669     {
    00670         pWnd->removeEventFilter( this );
    00671         pWnd->youAreDetached();
    00672         // this is only if it was attached and you want to detach it
    00673         if ( pWnd->parent() )
    00674         {
    00675             KMdiChildFrm * lpC = pWnd->mdiParent();
    00676             if ( lpC )
    00677             {
    00678                 if ( lpC->icon() )
    00679                 {
    00680                     QPixmap pixm( *( lpC->icon() ) );
    00681                     pWnd->setIcon( pixm );
    00682                 }
    00683                 QString capt( lpC->caption() );
    00684                 if ( !bShow )
    00685                     lpC->hide();
    00686                 lpC->unsetClient( m_undockPositioningOffset );
    00687                 m_pMdi->destroyChildButNotItsView( lpC, false ); //Do not focus the new top child , we loose focus...
    00688                 pWnd->setCaption( capt );
    00689             }
    00690         }
    00691     }
    00692     else
    00693     {
    00694         if ( pWnd->size().isEmpty() || ( pWnd->size() == QSize( 1, 1 ) ) )
    00695         {
    00696             if ( m_pCurrentWindow )
    00697             {
    00698                 pWnd->setGeometry( QRect( m_pMdi->getCascadePoint( m_pDocumentViews->count() - 1 ), m_pCurrentWindow->size() ) );
    00699             }
    00700             else
    00701             {
    00702                 pWnd->setGeometry( QRect( m_pMdi->getCascadePoint( m_pDocumentViews->count() - 1 ), defaultChildFrmSize() ) );
    00703             }
    00704         }
    00705 #ifdef Q_WS_X11
    00706         if ( mdiMode() == KMdi::ToplevelMode )
    00707         {
    00708             XSetTransientForHint( qt_xdisplay(), pWnd->winId(), topLevelWidget() ->winId() );
    00709         }
    00710 #endif
    00711
    00712         return ;
    00713     }
    00714
    00715 #ifdef Q_WS_X11
    00716     if ( mdiMode() == KMdi::ToplevelMode )
    00717     {
    00718         XSetTransientForHint( qt_xdisplay(), pWnd->winId(), topLevelWidget() ->winId() );
    00719     }
    00720 #endif
    00721
    00722     // this will show it...
    00723     if ( bShow )
    00724     {
    00725         activateView( pWnd );
    00726     }
    00727
    00728     emit childViewIsDetachedNow( pWnd );
    00729 }
    00730
    00731 //============== removeWindowFromMdi ==============//
    00732 void KMdiMainFrm::removeWindowFromMdi( KMdiChildView *pWnd )
    00733 {
    00734     Q_UNUSED( pWnd );
    00735     //Closes a child window. sends no close event : simply deletes it
    00736     //FIXME something wrong with this, but nobody knows whatcart
    00737 #if 0
    00738     if ( !( m_pWinList->removeRef( pWnd ) ) )
    00739         return ;
    00740     if ( m_pWinList->count() == 0 )
    00741         m_pCurrentWindow = 0L;
    00742
    00743     QObject::disconnect( pWnd, SIGNAL( attachWindow( KMdiChildView*, bool ) ), this, SLOT( attachWindow( KMdiChildView*, bool ) ) );
    00744     QObject::disconnect( pWnd, SIGNAL( detachWindow( KMdiChildView*, bool ) ), this, SLOT( detachWindow( KMdiChildView*, bool ) ) );
    00745     QObject::disconnect( pWnd, SIGNAL( focusInEventOccurs( KMdiChildView* ) ), this, SLOT( activateView( KMdiChildView* ) ) );
    00746     QObject::disconnect( pWnd, SIGNAL( childWindowCloseRequest( KMdiChildView* ) ), this, SLOT( childWindowCloseRequest( KMdiChildView* ) ) );
    00747     QObject::disconnect( pWnd, SIGNAL( clickedInWindowMenu( int ) ), this, SLOT( windowMenuItemActivated( int ) ) );
    00748     QObject::disconnect( pWnd, SIGNAL( clickedInDockMenu( int ) ), this, SLOT( dockMenuItemActivated( int ) ) );
    00749
    00750     if ( m_pTaskBar )
    00751     {
    00752         KMdiTaskBarButton * but = m_pTaskBar->getButton( pWnd );
    00753         if ( but != 0L )
    00754         {
    00755             QObject::disconnect( pWnd, SIGNAL( tabCaptionChanged( const QString& ) ), but, SLOT( setNewText( const QString& ) ) );
    00756         }
    00757         m_pTaskBar->removeWinButton( pWnd );
    00758     }
    00759
    00760     if ( m_mdiMode == KMdi::TabPageMode )
    00761     {
    00762         if ( m_pWinList->count() == 0 )
    00763         {
    00764             if ( !m_pDockbaseAreaOfDocumentViews )
    00765             {
    00766                 m_pDockbaseAreaOfDocumentViews = createDockWidget( "mdiAreaCover", QPixmap(), 0L, "mdi_area_cover" );
    00767                 m_pDockbaseAreaOfDocumentViews->setDockWindowTransient( this, true );
    00768
    00769                 m_pDockbaseAreaOfDocumentViews->setWidget( m_pMdi );
    00770                 setMainDockWidget( m_pDockbaseAreaOfDocumentViews );
    00771             }
    00772             m_pDockbaseOfTabPage->setDockSite( KDockWidget::DockFullSite );
    00773             m_pDockbaseAreaOfDocumentViews->setEnableDocking( KDockWidget::DockCenter );
    00774             m_pDockbaseAreaOfDocumentViews->manualDock( m_pDockbaseOfTabPage, KDockWidget::DockCenter );
    00775             m_pDockbaseAreaOfDocumentViews->setEnableDocking( KDockWidget::DockNone );
    00776             m_pDockbaseOfTabPage = m_pDockbaseAreaOfDocumentViews;
    00777             m_pClose->hide();
    00778         }
    00779         KDockWidget* pDockW = ( KDockWidget* ) pWnd->parentWidget();
    00780         pWnd->reparent( 0L, QPoint( 0, 0 ) );
    00781         pDockW->setWidget( 0L );
    00782         if ( pDockW == m_pDockbaseOfTabPage )
    00783         {
    00784             QTabWidget * pTab = ( QTabWidget* ) pDockW->parentWidget() ->parentWidget();
    00785             int cnt = pTab->count();
    00786             m_pDockbaseOfTabPage = ( KDockWidget* ) pTab->page( cnt - 2 );
    00787             if ( pDockW == m_pDockbaseOfTabPage )
    00788             {
    00789                 m_pDockbaseOfTabPage = ( KDockWidget* ) pTab->page( cnt - 1 ); // different to the one deleted next
    00790             }
    00791         }
    00792         delete pDockW;
    00793         if ( m_pWinList->count() == 1 )
    00794         {
    00795             m_pWinList->last() ->activate(); // all other views are activated by tab switch
    00796         }
    00797     }
    00798     else if ( pWnd->isAttached() )
    00799     {
    00800         pWnd->mdiParent() ->hide();
    00801         m_pMdi->destroyChildButNotItsView( pWnd->mdiParent() );
    00802     }
    00803     else
    00804     {
    00805         // is not attached
    00806         if ( m_pMdi->getVisibleChildCount() > 0 )
    00807         {
    00808             setActiveWindow();
    00809             m_pCurrentWindow = 0L;
    00810             KMdiChildView* pView = m_pMdi->topChild() ->m_pClient;
    00811             if ( pView )
    00812             {
    00813                 pView->activate();
    00814             }
    00815         }
    00816         else if ( m_pWinList->count() > 0 )
    00817         {
    00818             //crash?         m_pWinList->last()->activate();
    00819             //crash?         m_pWinList->last()->setFocus();
    00820         }
    00821     }
    00822
    00823     if ( pWnd->isToolView() )
    00824         pWnd->m_bToolView = false;
    00825
    00826     if ( !m_pCurrentWindow )
    00827         emit lastChildViewClosed();
    00828 #endif
    00829 }
    00830
    00831 //============== closeWindow ==============//
    00832 void KMdiMainFrm::closeWindow( KMdiChildView *pWnd, bool layoutTaskBar )
    00833 {
    00834     if ( !pWnd )
    00835         return ;
    00836     //Closes a child window. sends no close event : simply deletes it
    00837     m_pDocumentViews->removeRef( pWnd );
    00838     if ( m_pDocumentViews->count() == 0 )
    00839         m_pCurrentWindow = 0L;
    00840
    00841     if ( m_pTaskBar )
    00842     {
    00843         m_pTaskBar->removeWinButton( pWnd, layoutTaskBar );
    00844     }
    00845
    00846     if ( ( m_mdiMode == KMdi::TabPageMode ) || ( m_mdiMode == KMdi::IDEAlMode ) )
    00847     {
    00848         if ( !m_documentTabWidget )
    00849             return ; //oops
    00850         if ( m_pDocumentViews->count() == 0 )
    00851             m_pClose->hide();
    00852         pWnd->reparent( 0L, QPoint( 0, 0 ) );
    00853         kdDebug(760) << "-------- 1" << endl;
    00854         if ( m_pDocumentViews->count() == 1 )
    00855         {
    00856             m_pDocumentViews->last() ->activate(); // all other views are activated by tab switch
    00857         }
    00858     }
    00859     if ( ( m_mdiMode == KMdi::TabPageMode ) || ( m_mdiMode == KMdi::IDEAlMode ) )
    00860     {
    00861         if ( m_pDocumentViews->count() == 0 )
    00862         {
    00863             if ( !m_pDockbaseAreaOfDocumentViews )
    00864             {
    00865                 m_pDockbaseAreaOfDocumentViews = createDockWidget( "mdiAreaCover", QPixmap(), 0L, "mdi_area_cover" );
    00866                 m_pDockbaseAreaOfDocumentViews->setDockWindowTransient( this, true );
    00867                 m_pDockbaseAreaOfDocumentViews->setWidget( m_pMdi );
    00868                 setMainDockWidget( m_pDockbaseAreaOfDocumentViews );
    00869             }
    00870 #if 0
    00871             m_pDockbaseOfTabPage->setDockSite( KDockWidget::DockFullSite );
    00872             m_pDockbaseAreaOfDocumentViews->setEnableDocking( KDockWidget::DockCenter );
    00873             m_pDockbaseAreaOfDocumentViews->manualDock( m_pDockbaseOfTabPage, KDockWidget::DockCenter );
    00874             m_pDockbaseAreaOfDocumentViews->setEnableDocking( KDockWidget::DockNone );
    00875             m_pDockbaseOfTabPage = m_pDockbaseAreaOfDocumentViews;
    00876 #endif
    00877
    00878             m_pClose->hide();
    00879         }
    00880 #if 0
    00881         KDockWidget* pDockW = ( KDockWidget* ) pWnd->parentWidget();
    00882         pWnd->reparent( 0L, QPoint( 0, 0 ) );
    00883         pDockW->setWidget( 0L );
    00884         if ( pDockW == m_pDockbaseOfTabPage )
    00885         {
    00886             QTabWidget * pTab = ( QTabWidget* ) pDockW->parentWidget() ->parentWidget();
    00887             int cnt = pTab->count();
    00888             m_pDockbaseOfTabPage = ( KDockWidget* ) pTab->page( cnt - 2 );
    00889             if ( pDockW == m_pDockbaseOfTabPage )
    00890             {
    00891                 m_pDockbaseOfTabPage = ( KDockWidget* ) pTab->page( cnt - 1 ); // different to the one deleted next
    00892             }
    00893         }
    00894         delete pDockW;
    00895 #endif
    00896
    00897         delete pWnd;
    00898         if ( m_pDocumentViews->count() == 1 )
    00899         {
    00900             m_pDocumentViews->last() ->activate(); // all other views are activated by tab switch
    00901         }
    00902     }
    00903     else if ( pWnd->isAttached() )
    00904     {
    00905         m_pMdi->destroyChild( pWnd->mdiParent() );
    00906     }
    00907     else
    00908     {
    00909         delete pWnd;
    00910         // is not attached
    00911         if ( m_pMdi->getVisibleChildCount() > 0 )
    00912         {
    00913             setActiveWindow();
    00914             m_pCurrentWindow = 0L;
    00915             KMdiChildView* pView = m_pMdi->topChild() ->m_pClient;
    00916             if ( pView )
    00917             {
    00918                 pView->activate();
    00919             }
    00920         }
    00921         else if ( m_pDocumentViews->count() > 0 )
    00922         {
    00923             if ( m_pDocumentViews->current() )
    00924             {
    00925                 m_pDocumentViews->current() ->activate();
    00926                 m_pDocumentViews->current() ->setFocus();
    00927             }
    00928             else
    00929             {
    00930                 m_pDocumentViews->last() ->activate();
    00931                 m_pDocumentViews->last() ->setFocus();
    00932             }
    00933         }
    00934     }
    00935
    00936     if ( !m_pCurrentWindow )
    00937     {
    00938         d->closeWindowAction->setEnabled(false);
    00939         emit lastChildViewClosed();
    00940     }
    00941 }
    00942
    00943 //================== findWindow =================//
    00944 KMdiChildView* KMdiMainFrm::findWindow( const QString& caption )
    00945 {
    00946     QPtrListIterator<KMdiChildView> it( *m_pDocumentViews );
    00947     for ( ; ( *it ); ++it )
    00948     {
    00949         if ( ( *it )->caption() == caption )
    00950             return ( *it );
    00951     }
    00952     return 0L;
    00953 }
    00954
    00955 //================== activeWindow ===================//
    00956 KMdiChildView* KMdiMainFrm::activeWindow()
    00957 {
    00958     return m_pCurrentWindow;
    00959 }
    00960
    00961 //================== windowExists ? =================//
    00962 bool KMdiMainFrm::windowExists( KMdiChildView *pWnd, ExistsAs as )
    00963 {
    00964     if ( ( as == ToolView ) || ( as == AnyView ) )
    00965     {
    00966         if ( m_pToolViews->contains( pWnd ) )
    00967             return true;
    00968         if ( as == ToolView )
    00969             return false;
    00970     }
    00971
    00972     if ( m_pDocumentViews->findRef( pWnd ) != -1  )
    00973         return true;
    00974
    00975     return false;
    00976 }
    00977
    00978 QPopupMenu * KMdiMainFrm::windowPopup( KMdiChildView * pWnd, bool bIncludeTaskbarPopup )
    00979 {
    00980     m_pWindowPopup->clear();
    00981     if ( bIncludeTaskbarPopup )
    00982     {
    00983         m_pWindowPopup->insertItem( i18n( "Window" ), taskBarPopup( pWnd, false ) );
    00984         m_pWindowPopup->insertSeparator();
    00985     }
    00986     return m_pWindowPopup;
    00987 }
    00988
    00989 //================ taskBarPopup =================//
    00990 QPopupMenu* KMdiMainFrm::taskBarPopup( KMdiChildView *pWnd, bool /*bIncludeWindowPopup*/ )
    00991 {
    00992     //returns the g_pTaskBarPopup filled according to the KMdiChildView state
    00993     m_pTaskBarPopup->clear();
    00994     if ( pWnd->isAttached() )
    00995     {
    00996         m_pTaskBarPopup->insertItem( i18n( "Undock" ), pWnd, SLOT( detach() ) );
    00997         m_pTaskBarPopup->insertSeparator();
    00998         if ( pWnd->isMinimized() || pWnd->isMaximized() )
    00999             m_pTaskBarPopup->insertItem( i18n( "Restore" ), pWnd, SLOT( restore() ) );
    01000         if ( !pWnd->isMaximized() )
    01001             m_pTaskBarPopup->insertItem( i18n( "Maximize" ), pWnd, SLOT( maximize() ) );
    01002         if ( !pWnd->isMinimized() )
    01003             m_pTaskBarPopup->insertItem( i18n( "Minimize" ), pWnd, SLOT( minimize() ) );
    01004     }
    01005     else
    01006         m_pTaskBarPopup->insertItem( i18n( "Dock" ), pWnd, SLOT( attach() ) );
    01007     m_pTaskBarPopup->insertSeparator();
    01008     m_pTaskBarPopup->insertItem( i18n( "Close" ), pWnd, SLOT( close() ) );
    01009     // the window has a view...get the window popup
    01010     m_pTaskBarPopup->insertSeparator();
    01011     m_pTaskBarPopup->insertItem( i18n( "Operations" ), windowPopup( pWnd, false ) );  //alvoid recursion
    01012     return m_pTaskBarPopup;
    01013 }
    01014
    01015 void KMdiMainFrm::slotDocCurrentChanged( QWidget* pWidget )
    01016 {
    01017     KMdiChildView * pWnd = static_cast<KMdiChildView*>( pWidget );
    01018     pWnd->m_bMainframesActivateViewIsPending = true;
    01019
    01020     bool bActivateNecessary = true;
    01021     if ( m_pCurrentWindow != pWnd )
    01022         m_pCurrentWindow = pWnd;
    01023
    01024     if ( m_pTaskBar )
    01025         m_pTaskBar->setActiveButton( pWnd );
    01026
    01027     if ( m_documentTabWidget && ( m_mdiMode == KMdi::TabPageMode || m_mdiMode == KMdi::IDEAlMode ) )
    01028     {
    01029         m_documentTabWidget->showPage( pWnd );
    01030         pWnd->activate();
    01031     }
    01032     else
    01033     {
    01034         if ( pWnd->isAttached() )
    01035         {
    01036             if ( bActivateNecessary && ( m_pMdi->topChild() == pWnd->mdiParent() ) )
    01037                 pWnd->activate();
    01038
    01039             pWnd->mdiParent()->raiseAndActivate();
    01040         }
    01041         if ( !pWnd->isAttached() )
    01042         {
    01043             if ( bActivateNecessary )
    01044                 pWnd->activate();
    01045
    01046             m_pMdi->setTopChild( 0L ); // lose focus in the mainframe window
    01047             if ( !pWnd->isActiveWindow() )
    01048                 pWnd->setActiveWindow();
    01049
    01050             pWnd->raise();
    01051         }
    01052     }
    01053     if ( !switching() )
    01054         activeWindow()->updateTimeStamp();
    01055     emit collapseOverlapContainers();
    01056     pWnd->m_bMainframesActivateViewIsPending = false;
    01057 }
    01058
    01059
    01060 void KMdiMainFrm::activateView( KMdiChildView* pWnd )
    01061 {
    01062     pWnd->m_bMainframesActivateViewIsPending = true;
    01063
    01064     bool bActivateNecessary = true;
    01065     if ( m_pCurrentWindow != pWnd )
    01066         m_pCurrentWindow = pWnd;
    01067     else
    01068     {
    01069         bActivateNecessary = false;
    01070         // if this method is called as answer to view->activate(),
    01071         // interrupt it because it's not necessary
    01072         pWnd->m_bInterruptActivation = true;
    01073     }
    01074
    01075     if ( m_pTaskBar )
    01076         m_pTaskBar->setActiveButton( pWnd );
    01077
    01078     if ( m_documentTabWidget && m_mdiMode == KMdi::TabPageMode || m_mdiMode == KMdi::IDEAlMode )
    01079     {
    01080         m_documentTabWidget->showPage( pWnd );
    01081         pWnd->activate();
    01082     }
    01083     else
    01084     {
    01085         if ( pWnd->isAttached() )
    01086         {
    01087             if ( bActivateNecessary && ( m_pMdi->topChild() == pWnd->mdiParent() ) )
    01088                 pWnd->activate();
    01089
    01090             pWnd->mdiParent() ->raiseAndActivate();
    01091         }
    01092         if ( !pWnd->isAttached() )
    01093         {
    01094             if ( bActivateNecessary )
    01095                 pWnd->activate();
    01096
    01097             m_pMdi->setTopChild( 0L ); // lose focus in the mainframe window
    01098             if ( !pWnd->isActiveWindow() )
    01099                 pWnd->setActiveWindow();
    01100
    01101             pWnd->raise();
    01102         }
    01103     }
    01104
    01105     emit collapseOverlapContainers();
    01106
    01107     pWnd->m_bMainframesActivateViewIsPending = false;
    01108 }
    01109
    01110 void KMdiMainFrm::taskbarButtonRightClicked( KMdiChildView *pWnd )
    01111 {
    01112     activateView( pWnd ); // set focus
    01113     //QApplication::sendPostedEvents();
    01114     taskBarPopup( pWnd, true ) ->popup( QCursor::pos() );
    01115 }
    01116
    01117 void KMdiMainFrm::childWindowCloseRequest( KMdiChildView *pWnd )
    01118 {
    01119     KMdiViewCloseEvent * ce = new KMdiViewCloseEvent( pWnd );
    01120     QApplication::postEvent( this, ce );
    01121 }
    01122
    01123 bool KMdiMainFrm::event( QEvent* e )
    01124 {
    01125     if ( e->type() == QEvent::User )
    01126     {
    01127         KMdiChildView * pWnd = ( KMdiChildView* ) ( ( KMdiViewCloseEvent* ) e )->data();
    01128         if ( pWnd != 0L )
    01129             closeWindow( pWnd );
    01130         return true;
    01131         // A little hack: If MDI child views are moved implicietly by moving
    01132         // the main widget they should know this too. Unfortunately there seems to
    01133         // be no way to catch the move start / move stop situations for the main
    01134         // widget in a clean way. (There is no MouseButtonPress/Release or
    01135         // something like that.) Therefore we do the following: When we get the
    01136         // "first" move event we start a timer and interprete it as "drag begin".
    01137         // If we get the next move event and the timer is running we restart the
    01138         // timer and don't do anything else. If the timer elapses (this meens we
    01139         // haven't had any move event for a while) we interprete this as "drag
    01140         // end". If the moving didn't stop actually, we will later get another
    01141         // "drag begin", so we get a drag end too much, but this would be the same
    01142         // as if the user would stop moving for a little while.
    01143         // Actually we seem to be lucky that the timer does not elapse while we
    01144         // are moving -> so we have no obsolete drag end / begin
    01145     }
    01146     else if ( isVisible() && e->type() == QEvent::Move )
    01147     {
    01148         if ( m_pDragEndTimer->isActive() )
    01149         {
    01150             // this is not the first move -> stop old timer
    01151             m_pDragEndTimer->stop();
    01152         }
    01153         else
    01154         {
    01155             // this is the first move -> send the drag begin to all concerned views
    01156             QPtrListIterator<KMdiChildView> it( *m_pDocumentViews );
    01157             for ( ; ( *it ); ++it )
    01158             {
    01159                 KMdiChildFrmDragBeginEvent dragBeginEvent( 0L );
    01160                 QApplication::sendEvent( ( *it ), &dragBeginEvent );
    01161             }
    01162         }
    01163         m_pDragEndTimer->start( 200, true ); // single shot after 200 ms
    01164     }
    01165
    01166     return DockMainWindow::event( e );
    01167 }
    01168
    01169 bool KMdiMainFrm::eventFilter( QObject * /*obj*/, QEvent *e )
    01170 {
    01171     if ( e->type() == QEvent::Resize && m_mdiMode == KMdi::ToplevelMode )
    01172     {
    01173         verifyToplevelHeight();
    01174         return false; //let the rest of the resize magic do its work
    01175     }
    01176
    01177     if ( e->type() == QEvent::FocusIn )
    01178     {
    01179         QFocusEvent * pFE = ( QFocusEvent* ) e;
    01180         if ( pFE->reason() == QFocusEvent::ActiveWindow )
    01181         {
    01182             if ( m_pCurrentWindow && !m_pCurrentWindow->isHidden() &&
    01183                  !m_pCurrentWindow->isAttached() && m_pMdi->topChild() )
    01184             {
    01185                 return true;   // eat the event
    01186             }
    01187         }
    01188         if ( m_pMdi )
    01189         {
    01190             static bool focusTCIsPending = false;
    01191             if ( !focusTCIsPending && m_mdiMode == KMdi::ChildframeMode )
    01192             {
    01193                 focusTCIsPending = true;
    01194                 m_pMdi->focusTopChild();
    01195                 focusTCIsPending = false;
    01196             }
    01197         }
    01198     }
    01199     else if ( e->type() == QEvent::KeyRelease )
    01200     {
    01201         if ( switching() )
    01202         {
    01203             KAction * a = actionCollection() ->action( "view_last_window" ) ;
    01204             if ( a )
    01205             {
    01206                 const KShortcut cut( a->shortcut() );
    01207                 const KKeySequence& seq = cut.seq( 0 );
    01208                 const KKey& key = seq.key( 0 );
    01209                 int modFlags = key.modFlags();
    01210                 int state = ( ( QKeyEvent * ) e ) ->state();
    01211                 KKey key2( ( QKeyEvent * ) e );
    01212
    01217                 if ( state != ( ( QKeyEvent * ) e ) ->stateAfter() &&
    01218                         ( ( modFlags & KKey::CTRL ) > 0 ) == ( ( state & Qt::ControlButton ) > 0 ) &&
    01219                         ( ( modFlags & KKey::ALT ) > 0 ) == ( ( state & Qt::AltButton ) > 0 ) &&
    01220                         ( ( modFlags & KKey::WIN ) > 0 ) == ( ( state & Qt::MetaButton ) > 0 ) )
    01221                 {
    01222                     activeWindow() ->updateTimeStamp();
    01223                     setSwitching( false );
    01224                 }
    01225                 return true;
    01226             }
    01227             else
    01228             {
    01229                 kdDebug(760) << "KAction( \"view_last_window\") not found." << endl;
    01230             }
    01231         }
    01232     }
    01233     return false;  // standard event processing
    01234 }
    01235
    01239 void KMdiMainFrm::closeAllViews()
    01240 {
    01241     //save the children first to a list, as removing invalidates our iterator
    01242     QValueList<KMdiChildView*> children;
    01243     for ( KMdiChildView * w = m_pDocumentViews->first();w;w = m_pDocumentViews->next() )
    01244     {
    01245         children.append( w );
    01246     }
    01247     QValueListIterator<KMdiChildView *> childIt;
    01248     for ( childIt = children.begin(); childIt != children.end(); ++childIt )
    01249     {
    01250         ( *childIt )->close();
    01251     }
    01252 }
    01253
    01254
    01258 void KMdiMainFrm::iconifyAllViews()
    01259 {
    01260     kdDebug(760) << k_funcinfo << "minimizing all the views" << endl;
    01261     QPtrListIterator<KMdiChildView> it( *m_pDocumentViews );
    01262     for ( ; ( *it ); ++it )
    01263         ( *it )->minimize();
    01264 }
    01265
    01269 void KMdiMainFrm::closeActiveView()
    01270 {
    01271     kdDebug(760) << k_funcinfo << "closing the active view" << endl;
    01272     if ( m_pCurrentWindow )
    01273         m_pCurrentWindow->close();
    01274 }
    01275
    01277 void KMdiMainFrm::findRootDockWidgets( QPtrList<KDockWidget>* rootDockWidgetList, QValueList<QRect>* positionList )
    01278 {
    01279     //nothing is valid
    01280     if ( !rootDockWidgetList && !positionList )
    01281         return ;
    01282
    01283     // since we set some windows to toplevel, we must consider the window manager's window frame
    01284     const int frameBorderWidth = 7;  // @todo: Can we / do we need to ask the window manager?
    01285     const int windowTitleHeight = 10; // @todo:    -"-
    01286
    01287     QObjectList* pObjList = queryList( "KDockWidget" );
    01288     if ( pObjList->isEmpty() )
    01289         pObjList = queryList( "KDockWidget_Compat::KDockWidget" );
    01290
    01291     QObjectListIt it( *pObjList );
    01292     // for all dockwidgets (which are children of this mainwindow)
    01293     while ( ( *it ) )
    01294     {
    01295         KDockWidget* dockWindow = 0L; /* pDockW */
    01296         KDockWidget* rootDockWindow = 0L; /* pRootDockWindow */
    01297         KDockWidget* undockCandidate = 0L; /* pUndockCandidate */
    01298         QWidget* pW = static_cast<QWidget*>( ( *it ) );
    01299
    01300         // find the oldest ancestor of the current dockwidget that can be undocked
    01301         while ( !pW->isTopLevel() )
    01302         {
    01303             if ( ::qt_cast<KDockWidget*>( pW ) ||  pW->inherits( "KDockWidget_Compat::KDockWidget" ) )
    01304             {
    01305                 undockCandidate = static_cast<KDockWidget*>( pW );
    01306                 if ( undockCandidate->enableDocking() != KDockWidget::DockNone )
    01307                     rootDockWindow = undockCandidate;
    01308             }
    01309             pW = pW->parentWidget();
    01310         }
    01311
    01312         if ( rootDockWindow )
    01313         {
    01314             // if that oldest ancestor is not already in the list, append it
    01315             bool found = false;
    01316             if ( !rootDockWidgetList->isEmpty() )
    01317             {
    01318                 QPtrListIterator<KDockWidget> it2( *rootDockWidgetList );
    01319                 for ( ; it2.current() && !found; ++it2 )
    01320                 {
    01321                     dockWindow = it2.current();
    01322                     if ( dockWindow == rootDockWindow )
    01323                         found = true;
    01324                 }
    01325             }
    01326
    01327             if ( !found || rootDockWidgetList->isEmpty() )
    01328             {
    01329                     rootDockWidgetList->append( dockWindow );
    01330                     kdDebug(760) << k_funcinfo << "Appending " << rootDockWindow << " to our list of " <<
    01331                         "root dock windows" << endl;
    01332                     QPoint p = rootDockWindow->mapToGlobal( rootDockWindow->pos() ) - rootDockWindow->pos();
    01333                     QRect r( p.x(), p.y() + m_undockPositioningOffset.y(),
    01334                              rootDockWindow->width() - windowTitleHeight - frameBorderWidth * 2,
    01335                              rootDockWindow->height() - windowTitleHeight - frameBorderWidth * 2 );
    01336                     positionList->append( r );
    01337             }
    01338         }
    01339         ++it;
    01340     }
    01341     delete pObjList;
    01342 }
    01343
    01347 void KMdiMainFrm::switchToToplevelMode()
    01348 {
    01349     if ( m_mdiMode == KMdi::ToplevelMode )
    01350     {
    01351         emit mdiModeHasBeenChangedTo( KMdi::ToplevelMode );
    01352         return ;
    01353     }
    01354
    01355     KMdi::MdiMode oldMdiMode = m_mdiMode;
    01356
    01357     const int frameBorderWidth = 7;  // @todo: Can we / do we need to ask the window manager?
    01358     setUndockPositioningOffset( QPoint( 0, ( m_pTaskBar ? m_pTaskBar->height() : 0 ) + frameBorderWidth ) );
    01359
    01360     // 1.) select the dockwidgets to be undocked and store their geometry
    01361     QPtrList<KDockWidget> rootDockWidgetList;
    01362     QValueList<QRect> positionList;
    01363
    01364     // 2.) undock the MDI views of KMDI
    01365     switch( oldMdiMode )
    01366     {
    01367     case KMdi::ChildframeMode:
    01368         finishChildframeMode();
    01369         break;
    01370     case KMdi::TabPageMode:
    01371         finishTabPageMode();
    01372         break;
    01373     case KMdi::IDEAlMode:
    01374         finishIDEAlMode();
    01375         findRootDockWidgets( &rootDockWidgetList, &positionList );
    01376         break;
    01377     default:
    01378         break; //do nothing
    01379     }
    01380
    01381     // 3.) undock all these found oldest ancestors (being KDockWidgets)
    01382     QPtrListIterator<KDockWidget> kdwit( rootDockWidgetList );
    01383     for ( ; ( *kdwit ); ++kdwit )
    01384         ( *kdwit )->undock();
    01385
    01386     // 4.) recreate the MDI childframe area and hide it
    01387     if ( oldMdiMode == KMdi::TabPageMode || oldMdiMode == KMdi::IDEAlMode )
    01388     {
    01389         if ( !m_pDockbaseAreaOfDocumentViews )
    01390         {
    01391             m_pDockbaseAreaOfDocumentViews = createDockWidget( "mdiAreaCover", QPixmap(), 0L, "mdi_area_cover" );
    01392             m_pDockbaseAreaOfDocumentViews->setDockWindowTransient( this, true );
    01393             m_pDockbaseAreaOfDocumentViews->setEnableDocking( KDockWidget::DockNone );
    01394             m_pDockbaseAreaOfDocumentViews->setDockSite( KDockWidget::DockCorner );
    01395             m_pDockbaseAreaOfDocumentViews->setWidget( m_pMdi );
    01396         }
    01397         // set this dock to main view
    01398         setView( m_pDockbaseAreaOfDocumentViews );
    01399         setMainDockWidget( m_pDockbaseAreaOfDocumentViews );
    01400     }
    01401     //  QApplication::sendPostedEvents(); //why do we need to empty the event queue?
    01402     if ( !parentWidget() )
    01403     {
    01404         //if we don't have a parent widget ( which i expect we wouldn't )
    01405         //make sure we take into account the size of the docks provided by
    01406         //QMainWindow
    01407         int topDockHeight = topDock() ? topDock()->height() : 0;
    01408         int bottomDockHeight = bottomDock() ? bottomDock()->height() : 0;
    01409         int menuBarHeight = hasMenuBar() ? menuBar()->height() : 0;
    01410         if ( m_pDocumentViews->count() != 0 )
    01411             setFixedHeight( height() - m_pDockbaseAreaOfDocumentViews->height() );
    01412         else
    01413         {
    01414             kdDebug(760) << k_funcinfo << "height is: " << height() << endl;
    01415             kdDebug(760) << k_funcinfo << "top dock height: " << topDockHeight << endl;
    01416             kdDebug(760) << k_funcinfo << "bottom dock height: " << bottomDockHeight << endl;
    01417             kdDebug(760) << k_funcinfo << "menu bar height: " << menuBarHeight << endl;
    01418             kdDebug(760) << k_funcinfo << "dock base area height: " << m_pDockbaseAreaOfDocumentViews->height() << endl;
    01419             setFixedHeight( topDockHeight + menuBarHeight );
    01420         }
    01421     }
    01422
    01423     //FIXME although i don't know what to fix
    01424     // 5. show the child views again
    01425     QPtrListIterator<KMdiChildView> kmdicvit( *m_pDocumentViews );
    01426     for ( kmdicvit.toFirst(); ( *kmdicvit ); ++kmdicvit )
    01427     {
    01428 #ifdef Q_WS_X11
    01429         XSetTransientForHint( qt_xdisplay(), ( *kmdicvit )->winId(), winId() );
    01430 #endif
    01431         ( *kmdicvit )->show();
    01432     }
    01433
    01434     // 6.) reset all memorized positions of the undocked ones and show them again
    01435     QValueList<QRect>::Iterator qvlqrit;
    01436     QValueList<QRect>::Iterator qvlEnd = positionList.end();
    01437     for ( kmdicvit.toFirst(), qvlqrit = positionList.begin() ; ( *kmdicvit ) && qvlqrit != qvlEnd; ++kmdicvit, ++qvlqrit )
    01438     {
    01439         ( *kmdicvit )->setGeometry( ( *qvlqrit ) );
    01440         ( *kmdicvit )->show();
    01441     }
    01442
    01443     m_pDockbaseAreaOfDocumentViews->setDockSite( KDockWidget::DockNone );
    01444     m_mdiMode = KMdi::ToplevelMode;
    01445
    01446     kdDebug(760) << k_funcinfo << "Switch to toplevel mode completed" << endl;
    01447     emit mdiModeHasBeenChangedTo( KMdi::ToplevelMode );
    01448
    01449 }
    01450
    01451 void KMdiMainFrm::finishToplevelMode()
    01452 {
    01453     m_pDockbaseAreaOfDocumentViews->setDockSite( KDockWidget::DockCorner );
    01454 }
    01455
    01459 void KMdiMainFrm::switchToChildframeMode()
    01460 {
    01461     if ( m_mdiMode == KMdi::ChildframeMode )
    01462     {
    01463         emit mdiModeHasBeenChangedTo( KMdi::ChildframeMode );
    01464         return ;
    01465     }
    01466
    01467     QPtrList<KDockWidget> rootDockWidgetList;
    01468     QValueList<QRect> positionList;
    01469
    01470     if ( m_mdiMode == KMdi::TabPageMode )
    01471     {
    01472         kdDebug(760) << k_funcinfo << "finishing tab page mode" << endl;
    01473         // select the dockwidgets to be undocked and store their geometry
    01474         findRootDockWidgets( &rootDockWidgetList, &positionList );
    01475         kdDebug(760) << k_funcinfo << "Found " << rootDockWidgetList.count() << " widgets to undock" << endl;
    01476
    01477         // undock all these found oldest ancestors (being KDockWidgets)
    01478         QPtrListIterator<KDockWidget> it( rootDockWidgetList );
    01479         for ( ; ( *it ) ; ++it )
    01480             ( *it )->undock();
    01481
    01482         finishTabPageMode();
    01483     }
    01484     else if ( m_mdiMode == KMdi::ToplevelMode )
    01485     {
    01486         finishToplevelMode();
    01487     }
    01488     else if ( m_mdiMode == KMdi::IDEAlMode )
    01489     {
    01490         kdDebug(760) << k_funcinfo << "finishing ideal mode" << endl;
    01491         finishIDEAlMode( false );
    01492
    01493         // select the dockwidgets to be undocked and store their geometry
    01494         findRootDockWidgets( &rootDockWidgetList, &positionList );
    01495         kdDebug(760) << k_funcinfo << "Found " << rootDockWidgetList.count() << " widgets to undock" << endl;
    01496
    01497         // undock all these found oldest ancestors (being KDockWidgets)
    01498         QPtrListIterator<KDockWidget> it( rootDockWidgetList );
    01499         for ( ; ( *it ) ; ++it )
    01500             ( *it )->undock();
    01501
    01502         m_mdiMode = KMdi::TabPageMode;
    01503         finishTabPageMode();
    01504         m_mdiMode = KMdi::IDEAlMode;
    01505     }
    01506
    01507     if ( !m_pDockbaseAreaOfDocumentViews )
    01508     {
    01509         // cover KMdi's childarea by a dockwidget
    01510         m_pDockbaseAreaOfDocumentViews = createDockWidget( "mdiAreaCover", QPixmap(), 0L, "mdi_area_cover" );
    01511         m_pDockbaseAreaOfDocumentViews->setDockWindowTransient( this, true );
    01512         m_pDockbaseAreaOfDocumentViews->setEnableDocking( KDockWidget::DockNone );
    01513         m_pDockbaseAreaOfDocumentViews->setDockSite( KDockWidget::DockCorner );
    01514         m_pDockbaseAreaOfDocumentViews->setWidget( m_pMdi );
    01515         kdDebug(760) << k_funcinfo << "childarea is now covered by a dockwidget" << endl;
    01516     }
    01517
    01518     if ( m_pDockbaseAreaOfDocumentViews->isTopLevel() )
    01519     {
    01520         // set this dock to main view
    01521         setView( m_pDockbaseAreaOfDocumentViews );
    01522         setMainDockWidget( m_pDockbaseAreaOfDocumentViews );
    01523         m_pDockbaseAreaOfDocumentViews->setEnableDocking( KDockWidget::DockNone );
    01524         m_pDockbaseAreaOfDocumentViews->setDockSite( KDockWidget::DockCorner );
    01525         kdDebug(760) << k_funcinfo << "Dock base area has been set to the main view" << endl;
    01526     }
    01527     m_pDockbaseAreaOfDocumentViews->setWidget( m_pMdi ); //JW
    01528     m_pDockbaseAreaOfDocumentViews->show();
    01529
    01530     if ( ( m_mdiMode == KMdi::TabPageMode ) || ( m_mdiMode == KMdi::IDEAlMode ) )
    01531     {
    01532         kdDebug(760) << k_funcinfo << "trying to dock back the undock toolviews" << endl;
    01533         QPtrListIterator<KDockWidget> it( rootDockWidgetList );
    01534         for ( ; ( *it ); ++it )
    01535             ( *it )->dockBack();
    01536     }
    01537
    01538     if ( m_mdiMode == KMdi::ToplevelMode && m_pTempDockSession )
    01539     {
    01540         // restore the old dock scenario which we memorized at the time we switched to toplevel mode
    01541         kdDebug(760) << k_funcinfo << "Restoring old dock scenario memorized from toplevel mode" << endl;
    01542         QDomElement oldDockState = m_pTempDockSession->namedItem( "cur_dock_state" ).toElement();
    01543         readDockConfig( oldDockState );
    01544     }
    01545
    01546     KMdi::MdiMode oldMdiMode = m_mdiMode;
    01547     m_mdiMode = KMdi::ChildframeMode;
    01548
    01549     //FIXME although i don't know what to fix.
    01550     QPtrListIterator<KMdiChildView> it( *m_pDocumentViews );
    01551     for ( ; ( *it ); ++it )
    01552     {
    01553         KMdiChildView* pView = ( *it );
    01554         if ( !pView->isToolView() && pView->isAttached() )
    01555             attachWindow( pView, true );
    01556     }
    01557     for ( it.toFirst(); ( *it ); ++it )
    01558     {
    01559         KMdiChildView* pView = ( *it );
    01560         if ( !pView->isToolView() )
    01561             pView->show();
    01562     }
    01563     if ( ( oldMdiMode == KMdi::ToplevelMode ) && !parentWidget() )
    01564     {
    01565         setMinimumHeight( m_oldMainFrmMinHeight );
    01566         setMaximumHeight( m_oldMainFrmMaxHeight );
    01567         resize( width(), m_oldMainFrmHeight );
    01568         m_oldMainFrmHeight = 0;
    01569         kdDebug(760) << k_funcinfo << "left top level mode completely" << endl;
    01570         emit leftTopLevelMode();
    01571     }
    01572     emit mdiModeHasBeenChangedTo( KMdi::ChildframeMode );
    01573 }
    01574
    01575 void KMdiMainFrm::finishChildframeMode()
    01576 {
    01577     // save the old dock scenario of the dockwidget-like tool views to a DOM tree
    01578     kdDebug(760) << k_funcinfo << "saving the current dock scenario" << endl;
    01579     delete m_pTempDockSession;
    01580     m_pTempDockSession = new QDomDocument( "docksession" );
    01581     QDomElement curDockState = m_pTempDockSession->createElement( "cur_dock_state" );
    01582     m_pTempDockSession->appendChild( curDockState );
    01583     writeDockConfig( curDockState );
    01584
    01585     // detach all non-tool-views to toplevel
    01586     kdDebug(760) << k_funcinfo << "detaching all document views and moving them to toplevel" << endl;
    01587     QPtrListIterator<KMdiChildView> it( *m_pDocumentViews );
    01588     for ( ; ( *it ); ++it )
    01589     {
    01590         KMdiChildView* pView = ( *it );
    01591         if ( pView->isToolView() )
    01592             continue;
    01593         if ( pView->isAttached() )
    01594         {
    01595             if ( pView->isMaximized() )
    01596                 pView->mdiParent()->setGeometry( 0, 0, m_pMdi->width(), m_pMdi->height() );
    01597             detachWindow( pView, false );
    01598         }
    01599     }
    01600 }
    01601
    01605 void KMdiMainFrm::switchToTabPageMode()
    01606 {
    01607     if ( m_mdiMode == KMdi::TabPageMode )
    01608     {
    01609         emit mdiModeHasBeenChangedTo( KMdi::TabPageMode );
    01610         return ;  // nothing need to be done
    01611     }
    01612
    01613     switch( m_mdiMode )
    01614     {
    01615     case KMdi::ChildframeMode:
    01616         finishChildframeMode();
    01617         break;
    01618     case KMdi::ToplevelMode:
    01619         finishToplevelMode();
    01620         break;
    01621     case KMdi::IDEAlMode:
    01622         finishIDEAlMode( false );
    01623         emit mdiModeHasBeenChangedTo( KMdi::TabPageMode );
    01624         m_mdiMode = KMdi::TabPageMode;
    01625         return;
    01626         break;
    01627     default:
    01628         break;
    01629     }
    01630
    01631     setupTabbedDocumentViewSpace();
    01632     m_mdiMode = KMdi::TabPageMode;
    01633     if ( m_pCurrentWindow )
    01634         m_pCurrentWindow->setFocus();
    01635
    01636     m_pTaskBar->switchOn( false );
    01637
    01638     if ( m_pClose )
    01639     {
    01640         QObject::connect( m_pClose, SIGNAL( clicked() ), this, SLOT( closeViewButtonPressed() ) );
    01641         if ( m_pDocumentViews->count() > 0 )
    01642             m_pClose->show();
    01643     }
    01644     else
    01645         kdDebug(760) << "close button nonexistant. strange things might happen" << endl;
    01646
    01647     kdDebug(760) << "Switch to tab page mode complete" << endl;
    01648     emit mdiModeHasBeenChangedTo( KMdi::TabPageMode );
    01649 }
    01650
    01651 void KMdiMainFrm::finishTabPageMode()
    01652 {
    01653     // if tabified, release all views from their docking covers
    01654     if ( m_mdiMode == KMdi::TabPageMode )
    01655     {
    01656         m_pClose->hide();
    01657         QObject::disconnect( m_pClose, SIGNAL( clicked() ), this, SLOT( closeViewButtonPressed() ) );
    01658
    01659         QPtrListIterator<KMdiChildView> it( *m_pDocumentViews );
    01660         for ( ; it.current(); ++it )
    01661         {
    01662             KMdiChildView* pView = it.current();
    01663             if ( pView->isToolView() )
    01664                 continue;
    01665             kdDebug(760) << "KMdiMainFrm::finishTabPageMode: in loop" << endl;
    01666             QSize mins = pView->minimumSize();
    01667             QSize maxs = pView->maximumSize();
    01668             QSize sz = pView->size();
    01669             QWidget* pParent = pView->parentWidget();
    01670             QPoint p( pParent->mapToGlobal( pParent->pos() ) - pParent->pos() + m_undockPositioningOffset );
    01671             m_documentTabWidget->removePage( pView );
    01672             pView->reparent( 0, 0, p );
    01673             //         pView->reparent(0,0,p);
    01674             pView->resize( sz );
    01675             pView->setMinimumSize( mins.width(), mins.height() );
    01676             pView->setMaximumSize( maxs.width(), maxs.height() );
    01677             //         ((KDockWidget*)pParent)->undock(); // this destroys the dockwiget cover, too
    01678             //         pParent->close();
    01679             //         delete pParent;
    01680             //         if (centralWidget() == pParent) {
    01681             //            setCentralWidget(0L); // avoid dangling pointer
    01682             //         }
    01683         }
    01684         delete m_documentTabWidget;
    01685         m_documentTabWidget = 0;
    01686         m_pTaskBar->switchOn( true );
    01687     }
    01688 }
    01689
    01690
    01691
    01692 void KMdiMainFrm::setupTabbedDocumentViewSpace()
    01693 {
    01694     // resize to childframe mode size of the mainwindow if we were in toplevel mode
    01695     if ( ( m_mdiMode == KMdi::ToplevelMode ) && !parentWidget() )
    01696     {
    01697         setMinimumHeight( m_oldMainFrmMinHeight );
    01698         setMaximumHeight( m_oldMainFrmMaxHeight );
    01699         resize( width(), m_oldMainFrmHeight );
    01700         m_oldMainFrmHeight = 0;
    01701         //qDebug("TopLevelMode off");
    01702         emit leftTopLevelMode();
    01703         QApplication::sendPostedEvents();
    01704
    01705         // restore the old dock szenario which we memorized at the time we switched to toplevel mode
    01706         if ( m_pTempDockSession )
    01707         {
    01708             QDomElement oldDockState = m_pTempDockSession->namedItem( "cur_dock_state" ).toElement();
    01709             readDockConfig( oldDockState );
    01710         }
    01711     }
    01712
    01713 #if 0
    01714     if ( m_pDockbaseOfTabPage != m_pDockbaseAreaOfDocumentViews )
    01715     {
    01716         delete m_pDockbaseOfTabPage;
    01717         m_pDockbaseOfTabPage = m_pDockbaseAreaOfDocumentViews;
    01718     }
    01719 #endif
    01720     delete m_documentTabWidget;
    01721     m_documentTabWidget = new KMdiDocumentViewTabWidget( m_pDockbaseAreaOfDocumentViews );
    01722     connect( m_documentTabWidget, SIGNAL( currentChanged( QWidget* ) ), this, SLOT( slotDocCurrentChanged( QWidget* ) ) );
    01723     m_pDockbaseAreaOfDocumentViews->setWidget( m_documentTabWidget );
    01724     m_documentTabWidget->show();
    01725     QPtrListIterator<KMdiChildView> it4( *m_pDocumentViews );
    01726     for ( ; it4.current(); ++it4 )
    01727     {
    01728         KMdiChildView* pView = it4.current();
    01729         m_documentTabWidget->addTab( pView, pView->icon() ? *( pView->icon() ) : QPixmap(), pView->tabCaption() );
    01730         /*
    01731            connect(pView,SIGNAL(iconOrCaptionUdpated(QWidget*,QPixmap,const QString&)),
    01732            m_documentTabWidget,SLOT(updateView(QWidget*,QPixmap,const QString&)));
    01733          */
    01734         connect( pView, SIGNAL( iconUpdated( QWidget*, QPixmap ) ), m_documentTabWidget, SLOT( updateIconInView( QWidget*, QPixmap ) ) );
    01735         connect( pView, SIGNAL( captionUpdated( QWidget*, const QString& ) ), m_documentTabWidget, SLOT( updateCaptionInView( QWidget*, const QString& ) ) );
    01736
    01737     }
    01738 }
    01739
    01740
    01741 void KMdiMainFrm::setIDEAlModeStyle( int flags )
    01742 {
    01743     d->m_styleIDEAlMode = flags; // see KMultiTabBar for the first 3 bits
    01744     if ( m_leftContainer )
    01745     {
    01746         KMdiDockContainer * tmpL = ( KMdiDockContainer* ) ( m_leftContainer->getWidget()->qt_cast( "KMdiDockContainer" ) );
    01747         if ( tmpL )
    01748             tmpL->setStyle( flags );
    01749     }
    01750
    01751     if ( m_rightContainer )
    01752     {
    01753         KMdiDockContainer * tmpR = ( KMdiDockContainer* ) ( m_rightContainer->getWidget()->qt_cast( "KMdiDockContainer" ) );
    01754         if ( tmpR )
    01755             tmpR->setStyle( flags );
    01756     }
    01757
    01758     if ( m_topContainer )
    01759     {
    01760         KMdiDockContainer * tmpT = ( KMdiDockContainer* ) ( m_topContainer->getWidget()->qt_cast( "KMdiDockContainer" ) );
    01761         if ( tmpT )
    01762             tmpT->setStyle( flags );
    01763     }
    01764
    01765     if ( m_bottomContainer )
    01766     {
    01767         KMdiDockContainer * tmpB = ( KMdiDockContainer* ) ( m_bottomContainer->getWidget()->qt_cast( "KMdiDockContainer" ) );
    01768         if ( tmpB )
    01769             tmpB->setStyle( flags );
    01770     }
    01771 }
    01772
    01773 void KMdiMainFrm::setToolviewStyle( int flag )
    01774 {
    01775     if ( m_mdiMode == KMdi::IDEAlMode )
    01776     {
    01777         setIDEAlModeStyle( flag );
    01778     }
    01779     d->m_toolviewStyle = flag;
    01780     bool toolviewExists = false;
    01781     QMap<QWidget*, KMdiToolViewAccessor*>::Iterator it;
    01782     for ( it = m_pToolViews->begin(); it != m_pToolViews->end(); ++it )
    01783     {
    01784         KDockWidget *dockWidget = dynamic_cast<KDockWidget*>( it.data()->wrapperWidget() );
    01785         if ( dockWidget )
    01786         {
    01787             switch ( flag )
    01788             {
    01789             case KMdi::IconOnly:
    01790                 dockWidget->setTabPageLabel( QString::null );
    01791                 dockWidget->setPixmap( *( it.data()->wrappedWidget()->icon() ) );
    01792                 break;
    01793             case KMdi::TextOnly:
    01794                 dockWidget->setPixmap(); //FIXME: Does not hide the icon in the IDEAl mode.
    01795                 dockWidget->setTabPageLabel( it.data()->wrappedWidget()->caption() );
    01796                 break;
    01797             case KMdi::TextAndIcon:
    01798                 dockWidget->setPixmap( *( it.data()->wrappedWidget()->icon() ) );
    01799                 dockWidget->setTabPageLabel( it.data()->wrappedWidget()->caption() );
    01800             default:
    01801                 break;
    01802             }
    01803             toolviewExists = true;
    01804         }
    01805     }
    01806
    01807     if ( toolviewExists )
    01808     {
    01809         //workaround for the above FIXME to make switching to TextOnly mode work in IDEAl as well. Be sure that this version of switch* is called.
    01810         if ( m_mdiMode == KMdi::IDEAlMode && flag == KMdi::TextOnly )
    01811         {
    01812             KMdiMainFrm::switchToTabPageMode();
    01813             KMdiMainFrm::switchToIDEAlMode();
    01814         }
    01815         else
    01816         {
    01817             writeDockConfig();
    01818             readDockConfig();
    01819         }
    01820     }
    01821 }
    01822
    01826 void KMdiMainFrm::switchToIDEAlMode()
    01827 {
    01828     kdDebug(760) << k_funcinfo << "switching to IDEAl mode" << endl;
    01829
    01830     if ( m_mdiMode == KMdi::IDEAlMode )
    01831     {
    01832         emit mdiModeHasBeenChangedTo( KMdi::IDEAlMode );
    01833         return ;  // nothing need to be done
    01834     }
    01835
    01836     switch( m_mdiMode )
    01837     {
    01838     case KMdi::ChildframeMode:
    01839         finishChildframeMode();
    01840         break;
    01841     case KMdi::ToplevelMode:
    01842         finishToplevelMode();
    01843         break;
    01844     case KMdi::TabPageMode:
    01845         m_mdiMode = KMdi::IDEAlMode;
    01846         setupToolViewsForIDEALMode();
    01847         emit mdiModeHasBeenChangedTo( KMdi::IDEAlMode );
    01848         return;
    01849         break;
    01850     default:
    01851         break;
    01852     }
    01853
    01854     setupTabbedDocumentViewSpace();
    01855     m_mdiMode = KMdi::IDEAlMode;
    01856     setupToolViewsForIDEALMode();
    01857
    01858     if ( m_pCurrentWindow )
    01859         m_pCurrentWindow->setFocus();
    01860
    01861     m_pTaskBar->switchOn( false );
    01862
    01863     if ( m_pClose )
    01864     {
    01865         QObject::connect( m_pClose, SIGNAL( clicked() ), this, SLOT( closeViewButtonPressed() ) );
    01866         if ( m_pDocumentViews->count() > 0 )
    01867             m_pClose->show();
    01868     }
    01869     else
    01870         kdWarning(760) << k_funcinfo << "close button pointer does not exist!" << endl;
    01871
    01872     kdDebug(760) << k_funcinfo << "switch to IDEAl mode complete" << endl;
    01873
    01874     emit mdiModeHasBeenChangedTo( KMdi::IDEAlMode );
    01875 }
    01876
    01877
    01878 void KMdiMainFrm::dockToolViewsIntoContainers( QPtrList<KDockWidget>& widgetsToReparent, KDockWidget *container )
    01879 {
    01880     QPtrListIterator<KDockWidget> it( widgetsToReparent );
    01881     for ( ; ( *it ); ++it )
    01882     {
    01883         ( *it )->manualDock( container, KDockWidget::DockCenter, 20 );
    01884         ( *it )->loseFormerBrotherDockWidget();
    01885     }
    01886 }
    01887
    01888 void KMdiMainFrm::findToolViewsDockedToMain( QPtrList<KDockWidget>* list, KDockWidget::DockPosition dprtmw )
    01889 {
    01890     KDockWidget* mainDock = getMainDockWidget();
    01891     if ( mainDock->parentDockTabGroup() )
    01892     {
    01893         mainDock = dynamic_cast<KDockWidget*>( mainDock->parentDockTabGroup()->parent() );
    01894         // FIXME: will likely crash below due to unchecked cast
    01895     }
    01896
    01897     if ( !mainDock )
    01898     {
    01899         kdDebug(760) << k_funcinfo << "mainDock invalid. No main dock widget found." << endl;
    01900         return;
    01901     }
    01902
    01903     KDockWidget* widget = mainDock->findNearestDockWidget( dprtmw );
    01904     if ( widget && widget->parentDockTabGroup() )
    01905     {
    01906         widget = static_cast<KDockWidget*>( widget->parentDockTabGroup() ->parent() );
    01907
    01908         if ( widget )
    01909         {
    01910             KDockTabGroup* tg = dynamic_cast<KDockTabGroup*>( widget->getWidget() );
    01911             if ( tg )
    01912             {
    01913                 kdDebug(760) << k_funcinfo << "KDockTabGroup found" << endl;
    01914                 for ( int i = 0;i < tg->count();i++ )
    01915                     list->append( static_cast<KDockWidget*>( tg->page( i ) ) );
    01916             }
    01917             else
    01918                 list->append( widget );
    01919         }
    01920         else
    01921             kdDebug(760) << k_funcinfo << "no widget found" << endl;
    01922     }
    01923     else
    01924         kdDebug(760) << "No main dock widget found" << endl;
    01925 }
    01926
    01927
    01928 void KMdiMainFrm::setupToolViewsForIDEALMode()
    01929 {
    01930     m_leftContainer = createDockWidget( "KMdiDock::leftDock", SmallIcon( "misc" ), 0L, "Left Dock" );
    01931     m_rightContainer = createDockWidget( "KMdiDock::rightDock", SmallIcon( "misc" ), 0L, "Right Dock" );
    01932     m_topContainer = createDockWidget( "KMdiDock::topDock", SmallIcon( "misc" ), 0L, "Top Dock" );
    01933     m_bottomContainer = createDockWidget( "KMdiDock::bottomDock", SmallIcon( "misc" ), 0L, "Bottom Dock" );
    01934
    01935     KDockWidget *mainDock = getMainDockWidget();
    01936     KDockWidget *w = mainDock;
    01937     if ( mainDock->parentDockTabGroup() )
    01938         w = static_cast<KDockWidget*>( mainDock->parentDockTabGroup()->parent() );
    01939
    01940     QPtrList<KDockWidget> leftReparentWidgets;
    01941     QPtrList<KDockWidget> rightReparentWidgets;
    01942     QPtrList<KDockWidget> bottomReparentWidgets;
    01943     QPtrList<KDockWidget> topReparentWidgets;
    01944
    01945     if ( mainDock->parentDockTabGroup() )
    01946         mainDock = static_cast<KDockWidget*>( mainDock->parentDockTabGroup() ->parent() );
    01947
    01948     findToolViewsDockedToMain( &leftReparentWidgets, KDockWidget::DockLeft );
    01949     findToolViewsDockedToMain( &rightReparentWidgets, KDockWidget::DockRight );
    01950     findToolViewsDockedToMain( &bottomReparentWidgets, KDockWidget::DockBottom );
    01951     findToolViewsDockedToMain( &topReparentWidgets, KDockWidget::DockTop );
    01952
    01953     mainDock->setEnableDocking( KDockWidget::DockNone ); //::DockCorner);
    01954     mainDock->setDockSite( KDockWidget::DockCorner );
    01955
    01956
    01957     KMdiDockContainer *tmpDC;
    01958     m_leftContainer->setWidget( tmpDC = new KMdiDockContainer( m_leftContainer, this, KDockWidget::DockLeft, d->m_styleIDEAlMode ) );
    01959     m_leftContainer->setEnableDocking( KDockWidget::DockLeft );
    01960     m_leftContainer->manualDock( mainDock, KDockWidget::DockLeft, 20 );
    01961     tmpDC->init();
    01962     if ( m_mdiGUIClient )
    01963         connect ( this, SIGNAL( toggleLeft() ), tmpDC, SLOT( toggle() ) );
    01964     connect( this, SIGNAL( collapseOverlapContainers() ), tmpDC, SLOT( collapseOverlapped() ) );
    01965     connect( tmpDC, SIGNAL( activated( KMdiDockContainer* ) ), this, SLOT( setActiveToolDock( KMdiDockContainer* ) ) );
    01966     connect( tmpDC, SIGNAL( deactivated( KMdiDockContainer* ) ), this, SLOT( removeFromActiveDockList( KMdiDockContainer* ) ) );
    01967
    01968     m_rightContainer->setWidget( tmpDC = new KMdiDockContainer( m_rightContainer, this, KDockWidget::DockRight, d->m_styleIDEAlMode ) );
    01969     m_rightContainer->setEnableDocking( KDockWidget::DockRight );
    01970     m_rightContainer->manualDock( mainDock, KDockWidget::DockRight, 80 );
    01971     tmpDC->init();
    01972     if ( m_mdiGUIClient )
    01973         connect ( this, SIGNAL( toggleRight() ), tmpDC, SLOT( toggle() ) );
    01974     connect( this, SIGNAL( collapseOverlapContainers() ), tmpDC, SLOT( collapseOverlapped() ) );
    01975     connect( tmpDC, SIGNAL( activated( KMdiDockContainer* ) ), this, SLOT( setActiveToolDock( KMdiDockContainer* ) ) );
    01976     connect( tmpDC, SIGNAL( deactivated( KMdiDockContainer* ) ), this, SLOT( removeFromActiveDockList( KMdiDockContainer* ) ) );
    01977
    01978     m_topContainer->setWidget( tmpDC = new KMdiDockContainer( m_topContainer, this, KDockWidget::DockTop, d->m_styleIDEAlMode ) );
    01979     m_topContainer->setEnableDocking( KDockWidget::DockTop );
    01980     m_topContainer->manualDock( mainDock, KDockWidget::DockTop, 20 );
    01981     tmpDC->init();
    01982     if ( m_mdiGUIClient )
    01983         connect ( this, SIGNAL( toggleTop() ), tmpDC, SLOT( toggle() ) );
    01984     connect( this, SIGNAL( collapseOverlapContainers() ), tmpDC, SLOT( collapseOverlapped() ) );
    01985     connect( tmpDC, SIGNAL( activated( KMdiDockContainer* ) ), this, SLOT( setActiveToolDock( KMdiDockContainer* ) ) );
    01986     connect( tmpDC, SIGNAL( deactivated( KMdiDockContainer* ) ), this, SLOT( removeFromActiveDockList( KMdiDockContainer* ) ) );
    01987
    01988     m_bottomContainer->setWidget( tmpDC = new KMdiDockContainer( m_bottomContainer, this, KDockWidget::DockBottom, d->m_styleIDEAlMode ) );
    01989     m_bottomContainer->setEnableDocking( KDockWidget::DockBottom );
    01990     m_bottomContainer->manualDock( mainDock, KDockWidget::DockBottom, 80 );
    01991     tmpDC->init();
    01992     if ( m_mdiGUIClient )
    01993         connect ( this, SIGNAL( toggleBottom() ), tmpDC, SLOT( toggle() ) );
    01994     connect( this, SIGNAL( collapseOverlapContainers() ), tmpDC, SLOT( collapseOverlapped() ) );
    01995     connect( tmpDC, SIGNAL( activated( KMdiDockContainer* ) ), this, SLOT( setActiveToolDock( KMdiDockContainer* ) ) );
    01996     connect( tmpDC, SIGNAL( deactivated( KMdiDockContainer* ) ), this, SLOT( removeFromActiveDockList( KMdiDockContainer* ) ) );
    01997
    01998     m_leftContainer->setDockSite( KDockWidget::DockCenter );
    01999     m_rightContainer->setDockSite( KDockWidget::DockCenter );
    02000     m_topContainer->setDockSite( KDockWidget::DockCenter );
    02001     m_bottomContainer->setDockSite( KDockWidget::DockCenter );
    02002
    02003     dockToolViewsIntoContainers( leftReparentWidgets, m_leftContainer );
    02004     dockToolViewsIntoContainers( rightReparentWidgets, m_rightContainer );
    02005     dockToolViewsIntoContainers( bottomReparentWidgets, m_bottomContainer );
    02006     dockToolViewsIntoContainers( topReparentWidgets, m_topContainer );
    02007
    02008
    02009     dockManager->setSpecialLeftDockContainer( m_leftContainer );
    02010     dockManager->setSpecialRightDockContainer( m_rightContainer );
    02011     dockManager->setSpecialTopDockContainer( m_topContainer );
    02012     dockManager->setSpecialBottomDockContainer( m_bottomContainer );
    02013
    02014
    02015     ( ( KMdiDockContainer* ) ( m_leftContainer->getWidget() ) ) ->hideIfNeeded();
    02016     ( ( KMdiDockContainer* ) ( m_rightContainer->getWidget() ) ) ->hideIfNeeded();
    02017     ( ( KMdiDockContainer* ) ( m_topContainer->getWidget() ) ) ->hideIfNeeded();
    02018     ( ( KMdiDockContainer* ) ( m_bottomContainer->getWidget() ) ) ->hideIfNeeded();
    02019
    02020 }
    02021
    02022
    02023
    02024 void KMdiMainFrm::finishIDEAlMode( bool full )
    02025 {
    02026     // if tabified, release all views from their docking covers
    02027     if ( m_mdiMode == KMdi::IDEAlMode )
    02028     {
    02029         assert( m_pClose );
    02030         m_pClose->hide();
    02031         QObject::disconnect( m_pClose, SIGNAL( clicked() ), this, SLOT( closeViewButtonPressed() ) );
    02032
    02033
    02034         QStringList leftNames;
    02035         leftNames = prepareIdealToTabs( m_leftContainer );
    02036         int leftWidth = m_leftContainer->width();
    02037
    02038         QStringList rightNames;
    02039         rightNames = prepareIdealToTabs( m_rightContainer );
    02040         int rightWidth = m_rightContainer->width();
    02041
    02042         QStringList topNames;
    02043         topNames = prepareIdealToTabs( m_topContainer );
    02044         int topHeight = m_topContainer->height();
    02045
    02046         QStringList bottomNames;
    02047         bottomNames = prepareIdealToTabs( m_bottomContainer );
    02048         int bottomHeight = m_bottomContainer->height();
    02049
    02050
    02051         kdDebug(760) << "leftNames" << leftNames << endl;
    02052         kdDebug(760) << "rightNames" << rightNames << endl;
    02053         kdDebug(760) << "topNames" << topNames << endl;
    02054         kdDebug(760) << "bottomNames" << bottomNames << endl;
    02055
    02056         delete m_leftContainer;
    02057         m_leftContainer = 0;
    02058         delete m_rightContainer;
    02059         m_rightContainer = 0;
    02060         delete m_bottomContainer;
    02061         m_bottomContainer = 0;
    02062         delete m_topContainer;
    02063         m_topContainer = 0;
    02064
    02065
    02066         idealToolViewsToStandardTabs( bottomNames, KDockWidget::DockBottom, bottomHeight );
    02067         idealToolViewsToStandardTabs( leftNames, KDockWidget::DockLeft, leftWidth );
    02068         idealToolViewsToStandardTabs( rightNames, KDockWidget::DockRight, rightWidth );
    02069         idealToolViewsToStandardTabs( topNames, KDockWidget::DockTop, topHeight );
    02070
    02071         QApplication::sendPostedEvents();
    02072
    02073         if ( !full )
    02074             return ;
    02075
    02076         QPtrListIterator<KMdiChildView> it( *m_pDocumentViews );
    02077         for ( ; it.current(); ++it )
    02078         {
    02079             KMdiChildView* pView = it.current();
    02080             if ( pView->isToolView() )
    02081                 continue;
    02082             QSize mins = pView->minimumSize();
    02083             QSize maxs = pView->maximumSize();
    02084             QSize sz = pView->size();
    02085             QWidget* pParent = pView->parentWidget();
    02086             QPoint p( pParent->mapToGlobal( pParent->pos() ) - pParent->pos() + m_undockPositioningOffset );
    02087             pView->reparent( 0, 0, p );
    02088             pView->reparent( 0, 0, p );
    02089             pView->resize( sz );
    02090             pView->setMinimumSize( mins.width(), mins.height() );
    02091             pView->setMaximumSize( maxs.width(), maxs.height() );
    02092             KDockWidget* pDockW = 0L;
    02093             // find the oldest ancestor of the current dockwidget that can be undocked
    02094             do
    02095             {
    02096                 if ( pParent->inherits( "KDockWidget" ) || pParent->inherits( "KDockWidget_Compat::KDockWidget" ) )
    02097                 {
    02098                     pDockW = ( KDockWidget* ) pParent;
    02099                     pDockW->undock(); // this destroys the dockwiget cover, too
    02100                     if ( pParent != m_pDockbaseAreaOfDocumentViews )
    02101                     {
    02102                         pParent->close();
    02103                         delete pParent;
    02104                     }
    02105                 }
    02106                 else
    02107                 {
    02108                     pParent = pParent->parentWidget();
    02109                 }
    02110             }
    02111             while ( pParent && !pDockW );
    02112             if ( centralWidget() == pParent )
    02113             {
    02114                 setCentralWidget( 0L ); // avoid dangling pointer
    02115             }
    02116         }
    02117         m_pTaskBar->switchOn( true );
    02118
    02119     }
    02120
    02121 }
    02122
    02123 QStringList KMdiMainFrm::prepareIdealToTabs( KDockWidget* container )
    02124 {
    02125     KDockContainer * pDW = dynamic_cast<KDockContainer*>( container->getWidget() );
    02126     QStringList widgetNames = ( ( KMdiDockContainer* ) pDW ) ->containedWidgets();
    02127     for ( QStringList::iterator it = widgetNames.begin();it != widgetNames.end();++it )
    02128     {
    02129         KDockWidget* dw = ( KDockWidget* ) manager() ->getDockWidgetFromName( *it );
    02130         dw->undock();
    02131         dw->setLatestKDockContainer( 0 );
    02132         dw->loseFormerBrotherDockWidget();
    02133     }
    02134     return widgetNames;
    02135 }
    02136
    02137 void KMdiMainFrm::idealToolViewsToStandardTabs( QStringList widgetNames, KDockWidget::DockPosition pos, int size )
    02138 {
    02139     Q_UNUSED( size )
    02140
    02141     KDockWidget * mainDock = getMainDockWidget();
    02142     if ( mainDock->parentDockTabGroup() )
    02143     {
    02144         mainDock = static_cast<KDockWidget*>( mainDock->parentDockTabGroup() ->parent() );
    02145     }
    02146
    02147     if ( widgetNames.count() > 0 )
    02148     {
    02149         QStringList::iterator it = widgetNames.begin();
    02150         KDockWidget *dwpd = manager() ->getDockWidgetFromName( *it );
    02151         if ( !dwpd )
    02152         {
    02153             kdDebug(760) << "Fatal error in finishIDEAlMode" << endl;
    02154             return ;
    02155         }
    02156         dwpd->manualDock( mainDock, pos, 20 );
    02157         ++it;
    02158         for ( ;it != widgetNames.end();++it )
    02159         {
    02160             KDockWidget *tmpdw = manager() ->getDockWidgetFromName( *it );
    02161             if ( !tmpdw )
    02162             {
    02163                 kdDebug(760) << "Fatal error in finishIDEAlMode" << endl;
    02164                 return ;
    02165             }
    02166             tmpdw->manualDock( dwpd, KDockWidget::DockCenter, 20 );
    02167         }
    02168
    02169 #if 0
    02170         QWidget *wid = dwpd->parentDockTabGroup();
    02171         if ( !wid )
    02172             wid = dwpd;
    02173         wid->setGeometry( 0, 0, 20, 20 );
    02174         /*  wid->resize(
    02175             ((pos==KDockWidget::DockLeft) || (pos==KDockWidget::DockRight))?size:wid->width(),
    02176             ((pos==KDockWidget::DockLeft) || (pos==KDockWidget::DockRight))?wid->height():size);
    02177          */
    02178 #endif
    02179
    02180     }
    02181
    02182 }
    02183
    02184
    02192 void KMdiMainFrm::setMenuForSDIModeSysButtons( KMenuBar* pMenuBar )
    02193 {
    02194     if ( m_bSDIApplication )   // there are no buttons in the menubar in this mode (although the view is always maximized)
    02195         return ;
    02196
    02197     m_pMainMenuBar = pMenuBar;
    02198     if ( m_pMainMenuBar == 0L )
    02199         return ;  // use setMenuForSDIModeSysButtons( 0L) for unsetting the external main menu!
    02200
    02201     if ( !m_pUndock )
    02202         m_pUndock = new QToolButton( pMenuBar );
    02203     if ( !m_pRestore )
    02204         m_pRestore = new QToolButton( pMenuBar );
    02205     if ( !m_pMinimize )
    02206         m_pMinimize = new QToolButton( pMenuBar );
    02207     if ( !m_pClose )
    02208         m_pClose = new QToolButton( pMenuBar );
    02209     m_pUndock->setAutoRaise( false );
    02210     m_pMinimize->setAutoRaise( false );
    02211     m_pRestore->setAutoRaise( false );
    02212     m_pClose->setAutoRaise( false );
    02213
    02214     setSysButtonsAtMenuPosition();
    02215
    02216     delete m_pUndockButtonPixmap;
    02217     delete m_pMinButtonPixmap;
    02218     delete m_pRestoreButtonPixmap;
    02219     delete m_pCloseButtonPixmap;
    02220     // create the decoration pixmaps
    02221     if ( frameDecorOfAttachedViews() == KMdi::Win95Look )
    02222     {
    02223         m_pUndockButtonPixmap = new QPixmap( win_undockbutton );
    02224         m_pMinButtonPixmap = new QPixmap( win_minbutton );
    02225         m_pRestoreButtonPixmap = new QPixmap( win_restorebutton );
    02226         m_pCloseButtonPixmap = new QPixmap( win_closebutton );
    02227     }
    02228     else if ( frameDecorOfAttachedViews() == KMdi::KDE1Look )
    02229     {
    02230         m_pUndockButtonPixmap = new QPixmap( kde_undockbutton );
    02231         m_pMinButtonPixmap = new QPixmap( kde_minbutton );
    02232         m_pRestoreButtonPixmap = new QPixmap( kde_restorebutton );
    02233         m_pCloseButtonPixmap = new QPixmap( kde_closebutton );
    02234         m_pUndock->setAutoRaise( true );
    02235         m_pMinimize->setAutoRaise( true );
    02236         m_pRestore->setAutoRaise( true );
    02237         m_pClose->setAutoRaise( true );
    02238     }
    02239     else if ( frameDecorOfAttachedViews() == KMdi::KDELook )
    02240     {
    02241         m_pUndockButtonPixmap = new QPixmap( kde2_undockbutton );
    02242         m_pMinButtonPixmap = new QPixmap( kde2_minbutton );
    02243         m_pRestoreButtonPixmap = new QPixmap( kde2_restorebutton );
    02244         m_pCloseButtonPixmap = new QPixmap( kde2_closebutton );
    02245     }
    02246     else
    02247     {   // kde2laptop look
    02248         m_pUndockButtonPixmap = new QPixmap( kde2laptop_undockbutton );
    02249         m_pMinButtonPixmap = new QPixmap( kde2laptop_minbutton );
    02250         m_pRestoreButtonPixmap = new QPixmap( kde2laptop_restorebutton );
    02251         m_pCloseButtonPixmap = new QPixmap( kde2laptop_closebutton );
    02252     }
    02253
    02254     m_pUndock->hide();
    02255     m_pMinimize->hide();
    02256     m_pRestore->hide();
    02257     m_pClose->hide();
    02258
    02259     m_pUndock->setPixmap( *m_pUndockButtonPixmap );
    02260     m_pMinimize->setPixmap( *m_pMinButtonPixmap );
    02261     m_pRestore->setPixmap( *m_pRestoreButtonPixmap );
    02262     m_pClose->setPixmap( *m_pCloseButtonPixmap );
    02263 }
    02264
    02265 void KMdiMainFrm::setSysButtonsAtMenuPosition()
    02266 {
    02267     if ( m_pMainMenuBar == 0L )
    02268         return ;
    02269     if ( m_pMainMenuBar->parentWidget() == 0L )
    02270         return ;
    02271
    02272     int menuW = m_pMainMenuBar->parentWidget() ->width();
    02273     int h;
    02274     int y;
    02275     if ( frameDecorOfAttachedViews() == KMdi::Win95Look )
    02276         h = 16;
    02277     else if ( frameDecorOfAttachedViews() == KMdi::KDE1Look )
    02278         h = 20;
    02279     else if ( frameDecorOfAttachedViews() == KMdi::KDELook )
    02280         h = 16;
    02281     else
    02282         h = 14;
    02283     y = m_pMainMenuBar->height() / 2 - h / 2;
    02284
    02285     if ( frameDecorOfAttachedViews() == KMdi::KDELaptopLook )
    02286     {
    02287         int w = 27;
    02288         m_pUndock->setGeometry( ( menuW - ( w * 3 ) - 5 ), y, w, h );
    02289         m_pMinimize->setGeometry( ( menuW - ( w * 2 ) - 5 ), y, w, h );
    02290         m_pRestore->setGeometry( ( menuW - w - 5 ), y, w, h );
    02291     }
    02292     else
    02293     {
    02294         m_pUndock->setGeometry( ( menuW - ( h * 4 ) - 5 ), y, h, h );
    02295         m_pMinimize->setGeometry( ( menuW - ( h * 3 ) - 5 ), y, h, h );
    02296         m_pRestore->setGeometry( ( menuW - ( h * 2 ) - 5 ), y, h, h );
    02297         m_pClose->setGeometry( ( menuW - h - 5 ), y, h, h );
    02298     }
    02299 }
    02300
    02302 void KMdiMainFrm::activateNextWin()
    02303 {
    02304     KMdiIterator<KMdiChildView*>* it = createIterator();
    02305     KMdiChildView* aWin = activeWindow();
    02306     for ( it->first(); !it->isDone(); it->next() )
    02307     {
    02308         if ( it->currentItem() == aWin )
    02309         {
    02310             it->next();
    02311             if ( !it->currentItem() )
    02312             {
    02313                 it->first();
    02314             }
    02315             if ( it->currentItem() )
    02316             {
    02317                 activateView( it->currentItem() );
    02318             }
    02319             break;
    02320         }
    02321     }
    02322     delete it;
    02323 }
    02324
    02326 void KMdiMainFrm::activatePrevWin()
    02327 {
    02328     KMdiIterator<KMdiChildView*>* it = createIterator();
    02329     KMdiChildView* aWin = activeWindow();
    02330     for ( it->first(); !it->isDone(); it->next() )
    02331     {
    02332         if ( it->currentItem() == aWin )
    02333         {
    02334             it->prev();
    02335             if ( !it->currentItem() )
    02336             {
    02337                 it->last();
    02338             }
    02339             if ( it->currentItem() )
    02340             {
    02341                 activateView( it->currentItem() );
    02342             }
    02343             break;
    02344         }
    02345     }
    02346     delete it;
    02347 }
    02348
    02350 void KMdiMainFrm::activateFirstWin()
    02351 {
    02352     m_bSwitching= true; // flag that we are currently switching between windows
    02353     KMdiIterator<KMdiChildView*>* it = createIterator();
    02354     QMap<QDateTime, KMdiChildView*> m;
    02355     for ( it->first(); !it->isDone(); it->next() )
    02356     {
    02357         m.insert( it->currentItem() ->getTimeStamp(), it->currentItem() );
    02358     }
    02359
    02360     if ( !activeWindow() )
    02361         return ;
    02362
    02363     QDateTime current = activeWindow() ->getTimeStamp();
    02364     QMap<QDateTime, KMdiChildView*>::iterator pos( m.find( current ) );
    02365     QMap<QDateTime, KMdiChildView*>::iterator newPos = pos;
    02366     if ( pos != m.end() )
    02367     {
    02368         ++newPos;
    02369     }
    02370     if ( newPos != m.end() )
    02371     { // look ahead
    02372         ++pos;
    02373     }
    02374     else
    02375     {
    02376         pos = m.begin();
    02377     }
    02378     activateView( pos.data() );
    02379     delete it;
    02380 }
    02381
    02383 void KMdiMainFrm::activateLastWin()
    02384 {
    02385     m_bSwitching= true; // flag that we are currently switching between windows
    02386     KMdiIterator<KMdiChildView*>* it = createIterator();
    02387     QMap<QDateTime, KMdiChildView*> m;
    02388     for ( it->first(); !it->isDone(); it->next() )
    02389     {
    02390         m.insert( it->currentItem() ->getTimeStamp(), it->currentItem() );
    02391     }
    02392
    02393     if ( !activeWindow() )
    02394         return ;
    02395
    02396     QDateTime current = activeWindow() ->getTimeStamp();
    02397     QMap<QDateTime, KMdiChildView*>::iterator pos( m.find( current ) );
    02398     if ( pos != m.begin() )
    02399     {
    02400         --pos;
    02401     }
    02402     else
    02403     {
    02404         pos = m.end();
    02405         --pos;
    02406     }
    02407     activateView( pos.data() );
    02408     delete it;
    02409 }
    02410
    02412 void KMdiMainFrm::activateView( int index )
    02413 {
    02414     KMdiChildView * pView = m_pDocumentViews->first();
    02415     for ( int i = 0; pView && ( i < index ); i++ )
    02416     {
    02417         pView = m_pDocumentViews->next();
    02418     }
    02419     if ( pView )
    02420     {
    02421         pView->activate();
    02422     }
    02423 }
    02424
    02426 void KMdiMainFrm::setEnableMaximizedChildFrmMode( bool enableMaxChildFrameMode )
    02427 {
    02428     if ( enableMaxChildFrameMode )
    02429     {
    02430         kdDebug(760) << k_funcinfo << "Turning on maximized child frame mode" << endl;
    02431         m_bMaximizedChildFrmMode = true;
    02432
    02433         KMdiChildFrm* pCurrentChild = m_pMdi->topChild();
    02434
    02435         //If we have no child or there is no menubar, we do nothing
    02436         if ( !pCurrentChild || !m_pMainMenuBar )
    02437             return ;
    02438
    02439         QObject::connect( m_pUndock, SIGNAL( clicked() ), pCurrentChild, SLOT( undockPressed() ) );
    02440         QObject::connect( m_pMinimize, SIGNAL( clicked() ), pCurrentChild, SLOT( minimizePressed() ) );
    02441         QObject::connect( m_pRestore, SIGNAL( clicked() ), pCurrentChild, SLOT( maximizePressed() ) );
    02442         m_pMinimize->show();
    02443         m_pUndock->show();
    02444         m_pRestore->show();
    02445
    02446         if ( frameDecorOfAttachedViews() == KMdi::KDELaptopLook )
    02447         {
    02448             m_pMainMenuBar->insertItem( QPixmap( kde2laptop_closebutton_menu ), m_pMdi->topChild(), SLOT( closePressed() ), 0, -1, 0 );
    02449         }
    02450         else
    02451         {
    02452             m_pMainMenuBar->insertItem( *pCurrentChild->icon(), pCurrentChild->systemMenu(), -1, 0 );
    02453             if ( m_pClose )
    02454             {
    02455                 QObject::connect( m_pClose, SIGNAL( clicked() ), pCurrentChild, SLOT( closePressed() ) );
    02456                 m_pClose->show();
    02457             }
    02458             else
    02459                 kdDebug(760) << k_funcinfo << "no close button. things won't behave correctly" << endl;
    02460         }
    02461     }
    02462     else
    02463     {
    02464         if ( !m_bMaximizedChildFrmMode )
    02465             return ;  // already set, nothing to do
    02466
    02467         kdDebug(760) << k_funcinfo << "Turning off maximized child frame mode" << endl;
    02468         m_bMaximizedChildFrmMode = false;
    02469
    02470         KMdiChildFrm* pFrmChild = m_pMdi->topChild();
    02471         if ( pFrmChild && pFrmChild->m_pClient && pFrmChild->state() == KMdiChildFrm::Maximized )
    02472         {
    02473             pFrmChild->m_pClient->restore();
    02474             switchOffMaximizeModeForMenu( pFrmChild );
    02475         }
    02476     }
    02477 }
    02478
    02480 void KMdiMainFrm::switchOffMaximizeModeForMenu( KMdiChildFrm* oldChild )
    02481 {
    02482     // if there is no menubar given, those system buttons aren't possible
    02483     if ( !m_pMainMenuBar )
    02484         return ;
    02485
    02486     m_pMainMenuBar->removeItem( m_pMainMenuBar->idAt( 0 ) );
    02487
    02488     if ( oldChild )
    02489     {
    02490         Q_ASSERT( m_pClose );
    02491         QObject::disconnect( m_pUndock, SIGNAL( clicked() ), oldChild, SLOT( undockPressed() ) );
    02492         QObject::disconnect( m_pMinimize, SIGNAL( clicked() ), oldChild, SLOT( minimizePressed() ) );
    02493         QObject::disconnect( m_pRestore, SIGNAL( clicked() ), oldChild, SLOT( maximizePressed() ) );
    02494         QObject::disconnect( m_pClose, SIGNAL( clicked() ), oldChild, SLOT( closePressed() ) );
    02495     }
    02496     m_pUndock->hide();
    02497     m_pMinimize->hide();
    02498     m_pRestore->hide();
    02499     m_pClose->hide();
    02500 }
    02501
    02503 void KMdiMainFrm::updateSysButtonConnections( KMdiChildFrm* oldChild, KMdiChildFrm* newChild )
    02504 {
    02505     //qDebug("updateSysButtonConnections");
    02506     // if there is no menubar given, those system buttons aren't possible
    02507     if ( !m_pMainMenuBar )
    02508         return ;
    02509
    02510     if ( newChild )
    02511     {
    02512         if ( frameDecorOfAttachedViews() == KMdi::KDELaptopLook )
    02513             m_pMainMenuBar->insertItem( QPixmap( kde2laptop_closebutton_menu ), newChild, SLOT( closePressed() ), 0, -1, 0 );
    02514         else
    02515             m_pMainMenuBar->insertItem( *newChild->icon(), newChild->systemMenu(), -1, 0 );
    02516     }
    02517
    02518     if ( oldChild )
    02519     {
    02520         m_pMainMenuBar->removeItem( m_pMainMenuBar->idAt( 1 ) );
    02521         Q_ASSERT( m_pClose );
    02522         QObject::disconnect( m_pUndock, SIGNAL( clicked() ), oldChild, SLOT( undockPressed() ) );
    02523         QObject::disconnect( m_pMinimize, SIGNAL( clicked() ), oldChild, SLOT( minimizePressed() ) );
    02524         QObject::disconnect( m_pRestore, SIGNAL( clicked() ), oldChild, SLOT( maximizePressed() ) );
    02525         QObject::disconnect( m_pClose, SIGNAL( clicked() ), oldChild, SLOT( closePressed() ) );
    02526     }
    02527     if ( newChild )
    02528     {
    02529         Q_ASSERT( m_pClose );
    02530         QObject::connect( m_pUndock, SIGNAL( clicked() ), newChild, SLOT( undockPressed() ) );
    02531         QObject::connect( m_pMinimize, SIGNAL( clicked() ), newChild, SLOT( minimizePressed() ) );
    02532         QObject::connect( m_pRestore, SIGNAL( clicked() ), newChild, SLOT( maximizePressed() ) );
    02533         QObject::connect( m_pClose, SIGNAL( clicked() ), newChild, SLOT( closePressed() ) );
    02534     }
    02535 }
    02536
    02538 bool KMdiMainFrm::isViewTaskBarOn()
    02539 {
    02540     if ( m_pTaskBar )
    02541         return m_pTaskBar->isSwitchedOn();
    02542     else
    02543         return false;
    02544 }
    02545
    02547 void KMdiMainFrm::showViewTaskBar()
    02548 {
    02549     if ( m_pTaskBar )
    02550         m_pTaskBar->switchOn( true );
    02551 }
    02552
    02554 void KMdiMainFrm::hideViewTaskBar()
    02555 {
    02556     if ( m_pTaskBar )
    02557         m_pTaskBar->switchOn( false );
    02558 }
    02559
    02560 //=============== fillWindowMenu ===============//
    02561 void KMdiMainFrm::fillWindowMenu()
    02562 {
    02563     bool tabPageMode = false;
    02564     if ( m_mdiMode == KMdi::TabPageMode )
    02565         tabPageMode = true;
    02566
    02567     bool IDEAlMode = false;
    02568     if ( m_mdiMode == KMdi::IDEAlMode )
    02569         IDEAlMode = true;
    02570
    02571     bool noViewOpened = false;
    02572     if ( m_pDocumentViews->isEmpty() )
    02573         noViewOpened = true;
    02574
    02575     // construct the menu and its submenus
    02576     if ( !m_bClearingOfWindowMenuBlocked )
    02577         m_pWindowMenu->clear();
    02578
    02579     d->closeWindowAction->plug(m_pWindowMenu);
    02580
    02581     int closeAllId = m_pWindowMenu->insertItem( i18n( "Close &All" ), this, SLOT( closeAllViews() ) );
    02582     if ( noViewOpened )
    02583     {
    02584         d->closeWindowAction->setEnabled(false);
    02585         m_pWindowMenu->setItemEnabled( closeAllId, false );
    02586     }
    02587
    02588     if ( !tabPageMode && !IDEAlMode )
    02589     {
    02590         int iconifyId = m_pWindowMenu->insertItem( i18n( "&Minimize All" ), this, SLOT( iconifyAllViews() ) );
    02591         if ( noViewOpened )
    02592             m_pWindowMenu->setItemEnabled( iconifyId, false );
    02593     }
    02594
    02595     m_pWindowMenu->insertSeparator();
    02596     m_pWindowMenu->insertItem( i18n( "&MDI Mode" ), m_pMdiModeMenu );
    02597     m_pMdiModeMenu->clear();
    02598     m_pMdiModeMenu->insertItem( i18n( "&Toplevel Mode" ), this, SLOT( switchToToplevelMode() ) );
    02599     m_pMdiModeMenu->insertItem( i18n( "C&hildframe Mode" ), this, SLOT( switchToChildframeMode() ) );
    02600     m_pMdiModeMenu->insertItem( i18n( "Ta&b Page Mode" ), this, SLOT( switchToTabPageMode() ) );
    02601     m_pMdiModeMenu->insertItem( i18n( "I&DEAl Mode" ), this, SLOT( switchToIDEAlMode() ) );
    02602     switch ( m_mdiMode )
    02603     {
    02604     case KMdi::ToplevelMode:
    02605         m_pMdiModeMenu->setItemChecked( m_pMdiModeMenu->idAt( 0 ), true );
    02606         break;
    02607     case KMdi::ChildframeMode:
    02608         m_pMdiModeMenu->setItemChecked( m_pMdiModeMenu->idAt( 1 ), true );
    02609         break;
    02610     case KMdi::TabPageMode:
    02611         m_pMdiModeMenu->setItemChecked( m_pMdiModeMenu->idAt( 2 ), true );
    02612         break;
    02613     case KMdi::IDEAlMode:
    02614         m_pMdiModeMenu->setItemChecked( m_pMdiModeMenu->idAt( 3 ), true );
    02615         break;
    02616     default:
    02617         break;
    02618     }
    02619
    02620     m_pWindowMenu->insertSeparator();
    02621     if ( !tabPageMode && !IDEAlMode )
    02622     {
    02623         int placMenuId = m_pWindowMenu->insertItem( i18n( "&Tile" ), m_pPlacingMenu );
    02624         m_pPlacingMenu->clear();
    02625         m_pPlacingMenu->insertItem( i18n( "Ca&scade Windows" ), m_pMdi, SLOT( cascadeWindows() ) );
    02626         m_pPlacingMenu->insertItem( i18n( "Cascade &Maximized" ), m_pMdi, SLOT( cascadeMaximized() ) );
    02627         m_pPlacingMenu->insertItem( i18n( "Expand &Vertically" ), m_pMdi, SLOT( expandVertical() ) );
    02628         m_pPlacingMenu->insertItem( i18n( "Expand &Horizontally" ), m_pMdi, SLOT( expandHorizontal() ) );
    02629         m_pPlacingMenu->insertItem( i18n( "Tile &Non-Overlapped" ), m_pMdi, SLOT( tileAnodine() ) );
    02630         m_pPlacingMenu->insertItem( i18n( "Tile Overla&pped" ), m_pMdi, SLOT( tilePragma() ) );
    02631         m_pPlacingMenu->insertItem( i18n( "Tile V&ertically" ), m_pMdi, SLOT( tileVertically() ) );
    02632         if ( m_mdiMode == KMdi::ToplevelMode )
    02633         {
    02634             m_pWindowMenu->setItemEnabled( placMenuId, false );
    02635         }
    02636         m_pWindowMenu->insertSeparator();
    02637         int dockUndockId = m_pWindowMenu->insertItem( i18n( "&Dock/Undock" ), m_pDockMenu );
    02638         m_pDockMenu->clear();
    02639         m_pWindowMenu->insertSeparator();
    02640         if ( noViewOpened )
    02641         {
    02642             m_pWindowMenu->setItemEnabled( placMenuId, false );
    02643             m_pWindowMenu->setItemEnabled( dockUndockId, false );
    02644         }
    02645     }
    02646     int entryCount = m_pWindowMenu->count();
    02647
    02648     // for all child frame windows: give an ID to every window and connect them in the end with windowMenuItemActivated()
    02649     int i = 100;
    02650     KMdiChildView* pView = 0L;
    02651     QPtrListIterator<KMdiChildView> it( *m_pDocumentViews );
    02652     QValueList<QDateTime> timeStamps;
    02653     for ( ; it.current(); ++it )
    02654     {
    02655         pView = it.current();
    02656         QDateTime timeStamp( pView->getTimeStamp() );
    02657
    02658         if ( pView->isToolView() )
    02659         {
    02660             continue;
    02661         }
    02662
    02663         QString item;
    02664         // set titles of minimized windows in brackets
    02665         if ( pView->isMinimized() )
    02666         {
    02667             item += "(";
    02668             item += pView->caption();
    02669             item += ")";
    02670         }
    02671         else
    02672         {
    02673             item += " ";
    02674             item += pView->caption();
    02675         }
    02676
    02677         // insert the window entry sorted by access time
    02678         unsigned int indx;
    02679         unsigned int windowItemCount = m_pWindowMenu->count() - entryCount;
    02680         bool inserted = false;
    02681         QString tmpString;
    02682         QValueList<QDateTime>::iterator timeStampIterator = timeStamps.begin();
    02683         for ( indx = 0; indx <= windowItemCount; indx++, ++timeStampIterator )
    02684         {
    02685             bool putHere = false;
    02686             if ( ( *timeStampIterator ) < timeStamp )
    02687             {
    02688                 putHere = true;
    02689                 timeStamps.insert( timeStampIterator, timeStamp );
    02690             }
    02691             if ( putHere )
    02692             {
    02693                 m_pWindowMenu->insertItem( item, pView, SLOT( slot_clickedInWindowMenu() ), 0, -1, indx + entryCount );
    02694                 if ( pView == m_pCurrentWindow )
    02695                 {
    02696                     m_pWindowMenu->setItemChecked( m_pWindowMenu->idAt( indx + entryCount ), true );
    02697                 }
    02698                 pView->setWindowMenuID( i );
    02699                 if ( !tabPageMode )
    02700                 {
    02701                     m_pDockMenu->insertItem( item, pView, SLOT( slot_clickedInDockMenu() ), 0, -1, indx );
    02702                     if ( pView->isAttached() )
    02703                     {
    02704                         m_pDockMenu->setItemChecked( m_pDockMenu->idAt( indx ), true );
    02705                     }
    02706                 }
    02707                 inserted = true;
    02708                 break;
    02709                 indx = windowItemCount + 1;  // break the loop
    02710             }
    02711         }
    02712         if ( !inserted )
    02713         {  // append it
    02714             m_pWindowMenu->insertItem( item, pView, SLOT( slot_clickedInWindowMenu() ), 0, -1, windowItemCount + entryCount );
    02715             if ( pView == m_pCurrentWindow )
    02716             {
    02717                 m_pWindowMenu->setItemChecked( m_pWindowMenu->idAt( windowItemCount + entryCount ), true );
    02718             }
    02719             pView->setWindowMenuID( i );
    02720             if ( !tabPageMode )
    02721             {
    02722                 m_pDockMenu->insertItem( item, pView, SLOT( slot_clickedInDockMenu() ), 0, -1, windowItemCount );
    02723                 if ( pView->isAttached() )
    02724                 {
    02725                     m_pDockMenu->setItemChecked( m_pDockMenu->idAt( windowItemCount ), true );
    02726                 }
    02727             }
    02728         }
    02729         i++;
    02730     }
    02731 }
    02732
    02733 //================ windowMenuItemActivated ===============//
    02734
    02735 void KMdiMainFrm::windowMenuItemActivated( int id )
    02736 {
    02737     if ( id < 100 )
    02738         return ;
    02739     id -= 100;
    02740     KMdiChildView *pView = m_pDocumentViews->at( id );
    02741     if ( !pView )
    02742         return ;
    02743     if ( pView->isMinimized() )
    02744         pView->minimize();
    02745     if ( m_mdiMode != KMdi::TabPageMode )
    02746     {
    02747         KMdiChildFrm * pTopChild = m_pMdi->topChild();
    02748         if ( pTopChild )
    02749         {
    02750             if ( ( pView == pTopChild->m_pClient ) && pView->isAttached() )
    02751             {
    02752                 return ;
    02753             }
    02754         }
    02755     }
    02756     activateView( pView );
    02757 }
    02758
    02759 //================ dockMenuItemActivated ===============//
    02760
    02761 void KMdiMainFrm::dockMenuItemActivated( int id )
    02762 {
    02763     if ( id < 100 )
    02764         return ;
    02765     id -= 100;
    02766     KMdiChildView *pView = m_pDocumentViews->at( id );
    02767     if ( !pView )
    02768         return ;
    02769     if ( pView->isMinimized() )
    02770         pView->minimize();
    02771     if ( pView->isAttached() )
    02772     {
    02773         detachWindow( pView, true );
    02774     }
    02775     else
    02776     {   // is detached
    02777         attachWindow( pView, true );
    02778     }
    02779 }
    02780
    02781 //================ popupWindowMenu ===============//
    02782
    02783 void KMdiMainFrm::popupWindowMenu( QPoint p )
    02784 {
    02785     if ( !isFakingSDIApplication() )
    02786     {
    02787         m_pWindowMenu->popup( p );
    02788     }
    02789 }
    02790
    02791 //================ dragEndTimeOut ===============//
    02792 void KMdiMainFrm::dragEndTimeOut()
    02793 {
    02794     // send drag end to all concerned views.
    02795     KMdiChildView * pView;
    02796     for ( m_pDocumentViews->first(); ( pView = m_pDocumentViews->current() ) != 0L; m_pDocumentViews->next() )
    02797     {
    02798         KMdiChildFrmDragEndEvent dragEndEvent( 0L );
    02799         QApplication::sendEvent( pView, &dragEndEvent );
    02800     }
    02801 }
    02802
    02803 //================ setFrameDecorOfAttachedViews ===============//
    02804
    02805 void KMdiMainFrm::setFrameDecorOfAttachedViews( int frameDecor )
    02806 {
    02807     switch ( frameDecor )
    02808     {
    02809     case 0:
    02810         m_frameDecoration = KMdi::Win95Look;
    02811         break;
    02812     case 1:
    02813         m_frameDecoration = KMdi::KDE1Look;
    02814         break;
    02815     case 2:
    02816         m_frameDecoration = KMdi::KDELook;
    02817         break;
    02818     case 3:
    02819         m_frameDecoration = KMdi::KDELaptopLook;
    02820         break;
    02821     default:
    02822         qDebug( "unknown MDI decoration" );
    02823         break;
    02824     }
    02825     setMenuForSDIModeSysButtons( m_pMainMenuBar );
    02826     QPtrListIterator<KMdiChildView> it( *m_pDocumentViews );
    02827     for ( ; it.current(); ++it )
    02828     {
    02829         KMdiChildView* pView = it.current();
    02830         if ( pView->isToolView() )
    02831             continue;
    02832         if ( pView->isAttached() )
    02833             pView->mdiParent() ->redecorateButtons();
    02834     }
    02835 }
    02836
    02837 void KMdiMainFrm::fakeSDIApplication()
    02838 {
    02839     m_bSDIApplication = true;
    02840     if ( m_pTaskBar )
    02841         m_pTaskBar->close();
    02842     m_pTaskBar = 0L;
    02843 }
    02844
    02845 void KMdiMainFrm::closeViewButtonPressed()
    02846 {
    02847     KMdiChildView * pView = activeWindow();
    02848     if ( pView )
    02849     {
    02850         pView->close();
    02851     }
    02852 }
    02853
    02854 void KMdiMainFrm::setManagedDockPositionModeEnabled( bool enabled )
    02855 {
    02856     m_managedDockPositionMode = enabled;
    02857 }
    02858
    02859 void KMdiMainFrm::setActiveToolDock( KMdiDockContainer* td )
    02860 {
    02861     if ( td == d->activeDockPriority[ 0 ] )
    02862         return ;
    02863     if ( d->activeDockPriority[ 0 ] == 0 )
    02864     {
    02865         d->activeDockPriority[ 0 ] = td;
    02866         //        d->focusList=new KMdiFocusList(this);
    02867         //        if (m_pMdi)  d->focusList->addWidgetTree(m_pMdi);
    02868         //        if (m_documentTabWidget) d->focusList->addWidgetTree(m_documentTabWidget);
    02869         return ;
    02870     }
    02871     for ( int dst = 3, src = 2;src >= 0;dst--, src-- )
    02872     {
    02873         if ( d->activeDockPriority[ src ] == td )
    02874             src--;
    02875         if ( src < 0 )
    02876             break;
    02877         d->activeDockPriority[ dst ] = d->activeDockPriority[ src ];
    02878     }
    02879     d->activeDockPriority[ 0 ] = td;
    02880 }
    02881
    02882 void KMdiMainFrm::removeFromActiveDockList( KMdiDockContainer* td )
    02883 {
    02884     for ( int i = 0;i < 4;i++ )
    02885     {
    02886         if ( d->activeDockPriority[ i ] == td )
    02887         {
    02888             for ( ;i < 3;i++ )
    02889                 d->activeDockPriority[ i ] = d->activeDockPriority[ i + 1 ];
    02890             d->activeDockPriority[ 3 ] = 0;
    02891             break;
    02892         }
    02893     }
    02894     /*
    02895           if (d->activeDockPriority[0]==0) {
    02896           if (d->focusList) d->focusList->restore();
    02897           delete d->focusList;
    02898           d->focusList=0;
    02899           }
    02900      */
    02901 }
    02902
    02903 void KMdiMainFrm::prevToolViewInDock()
    02904 {
    02905     KMdiDockContainer * td = d->activeDockPriority[ 0 ];
    02906     if ( !td )
    02907         return ;
    02908     td->prevToolView();
    02909 }
    02910
    02911 void KMdiMainFrm::nextToolViewInDock()
    02912 {
    02913     KMdiDockContainer * td = d->activeDockPriority[ 0 ];
    02914     if ( !td )
    02915         return ;
    02916     td->nextToolView();
    02917 }
    02918
    02919 KMdi::TabWidgetVisibility KMdiMainFrm::tabWidgetVisibility()
    02920 {
    02921     if ( m_documentTabWidget )
    02922         return m_documentTabWidget->tabWidgetVisibility();
    02923
    02924     return KMdi::NeverShowTabs;
    02925 }
    02926
    02927 void KMdiMainFrm::setTabWidgetVisibility( KMdi::TabWidgetVisibility visibility )
    02928 {
    02929     if ( m_documentTabWidget )
    02930         m_documentTabWidget->setTabWidgetVisibility( visibility );
    02931 }
    02932
    02933 KTabWidget * KMdiMainFrm::tabWidget() const
    02934 {
    02935     return m_documentTabWidget;
    02936 }
    02937
    02938 #include "kmdimainfrm.moc"
    02939
    02940 // vim: ts=2 sw=2 et
    02941 // kate: space-indent off; tab-width 4; replace-tabs off; indent-mode csands;

This file is part of the documentation for kmdi Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:32:06 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003