kdockwidget.cpp

00001 
00002 /* This file is part of the KDE libraries
00003    Copyright (C) 2000 Max Judin <novaprint@mtu-net.ru>
00004    Copyright (C) 2002,2003 Joseph Wenninger <jowenn@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License version 2 as published by the Free Software Foundation.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 #include "kdockwidget.h"
00021 #include "kdockwidget_private.h"
00022 #include "kdockwidget_p.h"
00023 
00024 #include <qapplication.h>
00025 #include <qlayout.h>
00026 #include <qpainter.h>
00027 #include <qobjectlist.h>
00028 #include <qstrlist.h>
00029 #include <qcursor.h>
00030 #include <qwidgetlist.h>
00031 #include <qtabwidget.h>
00032 #include <qtooltip.h>
00033 #include <qstyle.h>
00034 
00035 #ifndef NO_KDE2
00036 #include <kconfig.h>
00037 #include <kglobal.h>
00038 #include <klocale.h>
00039 #include <ktoolbar.h>
00040 #include <kpopupmenu.h>
00041 #include <kwin.h>
00042 #include <kdebug.h>
00043 #include <kglobalsettings.h>
00044 
00045 #include "config.h"
00046 #ifdef Q_WS_X11
00047 #include <X11/X.h>
00048 #include <X11/Xlib.h>
00049 #endif
00050 
00051 #else
00052 #include <qtoolbar.h>
00053 #include <qpopupmenu.h>
00054 #endif
00055 
00056 #include <stdlib.h>
00057 
00058 #undef BORDERLESS_WINDOWS
00059 
00060 #define DOCK_CONFIG_VERSION "0.0.5"
00061 
00062 static const char* const dockback_xpm[]={
00063 "6 6 2 1",
00064 "# c black",
00065 ". c None",
00066 "......",
00067 ".#....",
00068 "..#..#",
00069 "...#.#",
00070 "....##",
00071 "..####"};
00072 
00073 static const char* const todesktop_xpm[]={
00074 "5 5 2 1",
00075 "# c black",
00076 ". c None",
00077 "####.",
00078 "##...",
00079 "#.#..",
00080 "#..#.",
00081 "....#"};
00082 
00083 static const char* const not_close_xpm[]={
00084 "5 5 2 1",
00085 "# c black",
00086 ". c None",
00087 "#####",
00088 "#...#",
00089 "#...#",
00090 "#...#",
00091 "#####"};
00092 
00102 KDockMainWindow::KDockMainWindow( QWidget* parent, const char *name, WFlags f)
00103 :KMainWindow( parent, name, f )
00104 {
00105   QString new_name = QString(name) + QString("_DockManager");
00106   dockManager = new KDockManager( this, new_name.latin1() );
00107   mainDockWidget = 0L;
00108 }
00109 
00110 KDockMainWindow::~KDockMainWindow()
00111 {
00112     delete dockManager;
00113 }
00114 
00115 void KDockMainWindow::setMainDockWidget( KDockWidget* mdw )
00116 {
00117   if ( mainDockWidget == mdw ) return;
00118   mainDockWidget = mdw;
00119   dockManager->setMainDockWidget2(mdw);
00120 }
00121 
00122 void KDockMainWindow::setView( QWidget *view )
00123 {
00124   if ( view->isA("KDockWidget") ){
00125     if ( view->parent() != this ) ((KDockWidget*)view)->applyToWidget( this );
00126   }
00127 
00128 #ifndef NO_KDE2
00129   KMainWindow::setCentralWidget(view);
00130 #else
00131   QMainWindow::setCentralWidget(view);
00132 #endif
00133 }
00134 
00135 KDockWidget* KDockMainWindow::createDockWidget( const QString& name, const QPixmap &pixmap, QWidget* parent, const QString& strCaption, const QString& strTabPageLabel)
00136 {
00137   return new KDockWidget( dockManager, name.latin1(), pixmap, parent, strCaption, strTabPageLabel );
00138 }
00139 
00140 void KDockMainWindow::makeDockVisible( KDockWidget* dock )
00141 {
00142   if ( dock )
00143     dock->makeDockVisible();
00144 }
00145 
00146 void KDockMainWindow::makeDockInvisible( KDockWidget* dock )
00147 {
00148   if ( dock )
00149     dock->undock();
00150 }
00151 
00152 void KDockMainWindow::makeWidgetDockVisible( QWidget* widget )
00153 {
00154   makeDockVisible( dockManager->findWidgetParentDock(widget) );
00155 }
00156 
00157 void KDockMainWindow::writeDockConfig(QDomElement &base)
00158 {
00159   dockManager->writeConfig(base);
00160 }
00161 
00162 void KDockMainWindow::readDockConfig(QDomElement &base)
00163 {
00164   dockManager->readConfig(base);
00165 }
00166 
00167 #ifndef NO_KDE2
00168 void KDockMainWindow::writeDockConfig( KConfig* c, QString group )
00169 {
00170   dockManager->writeConfig( c, group );
00171 }
00172 
00173 void KDockMainWindow::readDockConfig( KConfig* c, QString group )
00174 {
00175   dockManager->readConfig( c, group );
00176 }
00177 #endif
00178 
00179 void KDockMainWindow::slotDockWidgetUndocked()
00180 {
00181   QObject* pSender = (QObject*) sender();
00182   if (!pSender->inherits("KDockWidget")) return;
00183   KDockWidget* pDW = (KDockWidget*) pSender;
00184   emit dockWidgetHasUndocked( pDW);
00185 }
00186 
00187 /*************************************************************************/
00188 KDockWidgetAbstractHeaderDrag::KDockWidgetAbstractHeaderDrag( KDockWidgetAbstractHeader* parent, KDockWidget* dock, const char* name )
00189 :QFrame( parent, name )
00190 {
00191   dw = dock;
00192   installEventFilter( dock->dockManager() );
00193 }
00194 /*************************************************************************/
00195 KDockWidgetHeaderDrag::KDockWidgetHeaderDrag( KDockWidgetAbstractHeader* parent, KDockWidget* dock, const char* name )
00196 :KDockWidgetAbstractHeaderDrag( parent, dock, name )
00197 {
00198 }
00199 
00200 void KDockWidgetHeaderDrag::paintEvent( QPaintEvent* )
00201 {
00202   QPainter paint;
00203 
00204   paint.begin( this );
00205 
00206   style().drawPrimitive (QStyle::PE_DockWindowHandle, &paint, QRect(0,0,width(), height()), colorGroup());
00207 
00208   paint.end();
00209 }
00210 /*************************************************************************/
00211 KDockWidgetAbstractHeader::KDockWidgetAbstractHeader( KDockWidget* parent, const char* name )
00212 :QFrame( parent, name )
00213 {
00214 }
00215 /*************************************************************************/
00216 KDockWidgetHeader::KDockWidgetHeader( KDockWidget* parent, const char* name )
00217 :KDockWidgetAbstractHeader( parent, name )
00218 {
00219 #ifdef BORDERLESS_WINDOWS
00220   setCursor(QCursor(ArrowCursor));
00221 #endif
00222   d = new KDockWidgetHeaderPrivate( this );
00223 
00224   layout = new QHBoxLayout( this );
00225   layout->setResizeMode( QLayout::Minimum );
00226 
00227   drag = new KDockWidgetHeaderDrag( this, parent );
00228 
00229   closeButton = new KDockButton_Private( this, "DockCloseButton" );
00230   QToolTip::add( closeButton, i18n("Close") );
00231   closeButton->setPixmap( style().stylePixmap (QStyle::SP_TitleBarCloseButton , this));
00232   closeButton->setFixedSize(closeButton->pixmap()->width(),closeButton->pixmap()->height());
00233   connect( closeButton, SIGNAL(clicked()), parent, SIGNAL(headerCloseButtonClicked()));
00234   connect( closeButton, SIGNAL(clicked()), parent, SLOT(undock()));
00235 
00236   stayButton = new KDockButton_Private( this, "DockStayButton" );
00237   QToolTip::add( stayButton, i18n("Freeze the window geometry", "Freeze") );
00238   stayButton->setToggleButton( true );
00239   stayButton->setPixmap( const_cast< const char** >(not_close_xpm) );
00240   stayButton->setFixedSize(closeButton->pixmap()->width(),closeButton->pixmap()->height());
00241   connect( stayButton, SIGNAL(clicked()), this, SLOT(slotStayClicked()));
00242 
00243   dockbackButton = new KDockButton_Private( this, "DockbackButton" );
00244   QToolTip::add( dockbackButton, i18n("Dock this window", "Dock") );
00245   dockbackButton->setPixmap( const_cast< const char** >(dockback_xpm));
00246   dockbackButton->setFixedSize(closeButton->pixmap()->width(),closeButton->pixmap()->height());
00247   connect( dockbackButton, SIGNAL(clicked()), parent, SIGNAL(headerDockbackButtonClicked()));
00248   connect( dockbackButton, SIGNAL(clicked()), parent, SLOT(dockBack()));
00249 
00250   d->toDesktopButton = new KDockButton_Private( this, "ToDesktopButton" );
00251   QToolTip::add( d->toDesktopButton, i18n("Detach") );
00252   d->toDesktopButton->setPixmap( const_cast< const char** >(todesktop_xpm));
00253   d->toDesktopButton->setFixedSize(closeButton->pixmap()->width(),closeButton->pixmap()->height());
00254   connect( d->toDesktopButton, SIGNAL(clicked()), parent, SLOT(toDesktop()));
00255   stayButton->hide();
00256 
00257   d->dummy = new QWidget( this );
00258   d->dummy->setFixedSize( 1,closeButton->pixmap()->height() );
00259 
00260 
00261   layout->addWidget( drag );
00262   layout->addWidget( dockbackButton );
00263   layout->addWidget( d->toDesktopButton );
00264   layout->addWidget( d->dummy);
00265   layout->addWidget( stayButton );
00266   layout->addWidget( closeButton );
00267   layout->activate();
00268   d->dummy->hide();
00269   drag->setFixedHeight( layout->minimumSize().height() );
00270 }
00271 
00272 void KDockWidgetHeader::setTopLevel( bool isTopLevel )
00273 {
00274   d->topLevel = isTopLevel;
00275   if ( isTopLevel ){
00276     KDockWidget* par = (KDockWidget*)parent();
00277     if( par && par->isDockBackPossible() )
00278         dockbackButton->show();
00279     else
00280         dockbackButton->hide();
00281 
00282     stayButton->hide();
00283     closeButton->hide();
00284     d->toDesktopButton->hide();
00285     drag->setEnabled( true );
00286   } else {
00287     dockbackButton->hide();
00288     stayButton->hide();
00289     if (!d->forceCloseButtonHidden) closeButton->show();
00290     if( d->showToDesktopButton )
00291       d->toDesktopButton->show();
00292   }
00293   layout->activate();
00294 
00295    bool dontShowDummy=drag->isVisibleTo(this) || dockbackButton->isVisibleTo(this) ||
00296         d->toDesktopButton->isVisibleTo(this) || stayButton->isVisibleTo(this) ||
00297         closeButton->isVisibleTo(this);
00298    for (QPtrListIterator<KDockButton_Private> it( d->btns );it.current();++it) {
00299         dontShowDummy=dontShowDummy || (it.current()->isVisibleTo(this));
00300    }
00301    if (dontShowDummy) d->dummy->hide(); else d->dummy->show();
00302 
00303   updateGeometry();
00304 }
00305 
00306 void KDockWidgetHeader::forceCloseButtonHidden(bool hidden) {
00307   d->forceCloseButtonHidden=hidden;
00308   if (hidden) closeButton->hide();
00309   else closeButton->show();
00310 }
00311 
00312 KDockWidgetHeaderDrag *KDockWidgetHeader::dragPanel() {
00313     return drag;
00314 }
00315 
00316 void KDockWidgetHeader::setDragPanel( KDockWidgetHeaderDrag* nd )
00317 {
00318   if ( !nd ) return;
00319 
00320   delete layout;
00321   layout = new QHBoxLayout( this );
00322   layout->setResizeMode( QLayout::Minimum );
00323 
00324   delete drag;
00325   drag = nd;
00326   if (drag->parentWidget()!=this) {
00327     drag->reparent(this,QPoint(0,0));
00328   }
00329 
00330 
00331   layout->addWidget( drag );
00332   layout->addWidget( dockbackButton );
00333   layout->addWidget( d->dummy );
00334   layout->addWidget( d->toDesktopButton );
00335   layout->addWidget( stayButton );
00336   bool dontShowDummy=drag->isVisibleTo(this) || dockbackButton->isVisibleTo(this) ||
00337     d->toDesktopButton->isVisibleTo(this) || stayButton->isVisibleTo(this) ||
00338     closeButton->isVisibleTo(this);
00339   for (QPtrListIterator<KDockButton_Private> it( d->btns );it.current();++it) {
00340       layout->addWidget(it.current());
00341     dontShowDummy=dontShowDummy || (it.current()->isVisibleTo(this));
00342   }
00343   if (dontShowDummy) d->dummy->hide(); else d->dummy->show();
00344   layout->addWidget( closeButton );
00345   layout->activate();
00346   kdDebug(282)<<"KdockWidgetHeader::setDragPanel:minimum height="<<layout->minimumSize().height()<<endl;
00347   //FIXME somebody left this here, but we don't know what the hell it's for.
00348   drag->setFixedHeight( closeButton->height()); // /*layout->minimumS*/sizeHint().height() );
00349 }
00350 
00351 void KDockWidgetHeader::addButton(KDockButton_Private* btn) {
00352     if (!btn) return;
00353 
00354     if (btn->parentWidget()!=this) {
00355         btn->reparent(this,QPoint(0,0));
00356     }
00357     btn->setFixedSize(closeButton->pixmap()->width(),closeButton->pixmap()->height());
00358     if (!d->btns.containsRef(btn)) d->btns.append(btn);
00359 
00360     btn->show();
00361 
00362     delete layout;
00363     layout = new QHBoxLayout( this );
00364     layout->setResizeMode( QLayout::Minimum );
00365 
00366     layout->addWidget( drag );
00367     layout->addWidget( dockbackButton );
00368     layout->addWidget( d->toDesktopButton );
00369     layout->addWidget( d->dummy);
00370     layout->addWidget( stayButton );
00371      bool dontShowDummy=drag->isVisibleTo(this) || dockbackButton->isVisibleTo(this) ||
00372             d->toDesktopButton->isVisibleTo(this) || stayButton->isVisibleTo(this) ||
00373             closeButton->isVisibleTo(this);
00374      for (QPtrListIterator<KDockButton_Private> it( d->btns );it.current();++it) {
00375             layout->addWidget(it.current());
00376         dontShowDummy=dontShowDummy || (it.current()->isVisibleTo(this));
00377     }
00378     if (dontShowDummy) d->dummy->hide(); else d->dummy->show();
00379     layout->addWidget( closeButton );
00380     layout->activate();
00381     drag->setFixedHeight( layout->minimumSize().height() );
00382 }
00383 
00384 void KDockWidgetHeader::removeButton(KDockButton_Private* btn) {
00385     if (btn->parentWidget()==this) {
00386         if (d->btns.containsRef(btn)) d->btns.removeRef(btn);
00387         delete btn;
00388     }
00389 }
00390 
00391 
00392 void KDockWidgetHeader::slotStayClicked()
00393 {
00394   setDragEnabled(!stayButton->isOn());
00395 }
00396 
00397 bool KDockWidgetHeader::dragEnabled() const
00398 {
00399   return drag->isEnabled();
00400 }
00401 
00402 void KDockWidgetHeader::showUndockButton(bool show)
00403 {
00404   kdDebug(282)<<"KDockWidgetHeader::showUndockButton("<<show<<")"<<endl;
00405   if( d->showToDesktopButton == show )
00406     return;
00407 
00408   d->showToDesktopButton = show;
00409   if( !show || d->topLevel )
00410     d->toDesktopButton->hide( );
00411   else
00412     d->toDesktopButton->show( );
00413 }
00414 
00415 void KDockWidgetHeader::setDragEnabled(bool b)
00416 {
00417   stayButton->setOn(!b);
00418   closeButton->setEnabled(b);
00419   drag->setEnabled(b);
00420 }
00421 
00422 #ifndef NO_KDE2
00423 void KDockWidgetHeader::saveConfig( KConfig* c )
00424 {
00425   c->writeEntry( QString("%1%2").arg(parent()->name()).arg(":stayButton"), stayButton->isOn() );
00426 }
00427 
00428 void KDockWidgetHeader::loadConfig( KConfig* c )
00429 {
00430   setDragEnabled( !c->readBoolEntry( QString("%1%2").arg(parent()->name()).arg(":stayButton"), false ) );
00431 }
00432 #endif
00433 
00434 /*************************************************************************/
00435 
00436 class KDockManager::KDockManagerPrivate
00437 {
00438 public:
00442   QRect dragRect;
00443 
00447   QRect oldDragRect;
00448 
00452   bool readyToDrag;
00453 
00457   QPoint dragOffset;
00458 
00462   bool splitterOpaqueResize;
00463   bool splitterKeepSize;
00464   bool splitterHighResolution;
00465 
00466   QGuardedPtr<KDockWidget> mainDockWidget;
00467 
00468   QObjectList containerDocks;
00469 
00470   QGuardedPtr<KDockWidget> leftContainer;
00471   QGuardedPtr<KDockWidget> topContainer;
00472   QGuardedPtr<KDockWidget> rightContainer;
00473   QGuardedPtr<KDockWidget> bottomContainer;
00474   int m_readDockConfigMode;
00475 };
00476 
00477 
00478 /*************************************************************************/
00479 KDockWidget::KDockWidget( KDockManager* dockManager, const char* name, const QPixmap &pixmap, QWidget* parent, const QString& strCaption, const QString& strTabPageLabel, WFlags f)
00480 #ifdef BORDERLESS_WINDOWS
00481 : QWidget( parent, name, f )//| WType_Dialog | WStyle_Customize | WStyle_NoBorder )
00482 #else
00483 : QWidget( parent, name, f )
00484 #endif
00485   ,formerBrotherDockWidget(0L)
00486   ,currentDockPos(DockNone)
00487   ,formerDockPos(DockNone)
00488   ,widget(0L)
00489   ,pix(new QPixmap(pixmap))
00490   ,prevSideDockPosBeforeDrag(DockNone)
00491   ,isGroup(false)
00492 {
00493   d = new KDockWidgetPrivate();  // create private data
00494 
00495   d->_parent = parent;
00496 
00497   layout = new QVBoxLayout( this );
00498   layout->setResizeMode( QLayout::Minimum );
00499 
00500   manager = dockManager;
00501   manager->childDock->append( this );
00502   installEventFilter( manager );
00503 
00504   eDocking = DockFullDocking;
00505   sDocking = DockFullSite;
00506 
00507   header = 0L;
00508   setHeader( new KDockWidgetHeader( this, "AutoCreatedDockHeader" ) );
00509 
00510   if( strCaption.isNull() )
00511     setCaption( name );
00512   else
00513     setCaption( strCaption);
00514 
00515   if( strTabPageLabel == " ")
00516     setTabPageLabel( caption());
00517   else
00518     setTabPageLabel( strTabPageLabel);
00519 
00520   isTabGroup = false;
00521   d->isContainer =false;
00522   setIcon( pixmap);
00523   widget = 0L;
00524 
00525   QObject::connect(this, SIGNAL(hasUndocked()), manager->main, SLOT(slotDockWidgetUndocked()) );
00526   applyToWidget( parent, QPoint(0,0) );
00527 }
00528 
00529 void KDockWidget::setPixmap(const QPixmap& pixmap) {
00530     delete pix;
00531     pix=new QPixmap(pixmap);
00532     setIcon(*pix);
00533     KDockTabGroup *dtg=parentDockTabGroup();
00534     if (dtg)
00535         dtg->changeTab(this,pixmap,dtg->tabLabel(this));
00536      QWidget *contWid=parentDockContainer();
00537          if (contWid) {
00538             KDockContainer *x = dynamic_cast<KDockContainer*>(contWid);
00539                 if (x) {
00540                         x->setPixmap(this,pixmap);
00541                 }
00542          }
00543 }
00544 
00545 const QPixmap& KDockWidget::pixmap() const {
00546     return *pix;
00547 }
00548 
00549 KDockWidget::~KDockWidget()
00550 {
00551   d->pendingDtor = true;
00552   if ( !manager->undockProcess ){
00553     d->blockHasUndockedSignal = true;
00554     undock();
00555     d->blockHasUndockedSignal = false;
00556   }
00557 
00558   if (latestKDockContainer()) {
00559     KDockContainer *x = dynamic_cast<KDockContainer*>(latestKDockContainer());
00560     if (x) {
00561       x->removeWidget(this);
00562     }
00563   }
00564   emit iMBeingClosed();
00565   if (manager->d) manager->d->containerDocks.remove(this);
00566   manager->childDock->remove( this );
00567   delete pix;
00568   delete d; // destroy private data
00569   d=0;
00570 }
00571 
00572 void KDockWidget::paintEvent(QPaintEvent* pe)
00573 {
00574     QWidget::paintEvent(pe);
00575         QPainter paint;
00576         paint.begin( this );
00577         style().drawPrimitive (QStyle::PE_Panel, &paint, QRect(0,0,width(), height()), colorGroup());
00578         paint.end();
00579 }
00580 
00581 void KDockWidget::leaveEvent(QEvent *e)
00582 {
00583     QWidget::leaveEvent(e);
00584 #ifdef BORDERLESS_WINDOWS
00585     if (parent()) return;
00586 //  setCursor(QCursor(ArrowCursor));
00587 #endif
00588 }
00589 
00590 void KDockWidget::mousePressEvent(QMouseEvent* mme)
00591 {
00592 #ifdef BORDERLESS_WINDOWS
00593     if (!parent())
00594     {
00595         kdDebug(282)<<"KDockWidget::mousePressEvent"<<endl;
00596 
00597         bool bbottom;
00598         bool bleft;
00599         bool bright;
00600         bool btop;
00601         int styleheight;
00602         QPoint mp;
00603         mp=mme->pos();
00604             styleheight=2*style().pixelMetric(QStyle::PM_DefaultFrameWidth,this);
00605         bbottom=mp.y()>=height()-styleheight;
00606         btop=mp.y()<=styleheight;
00607         bleft=mp.x()<=styleheight;
00608         bright=mp.x()>=width()-styleheight;
00609         kdDebug(282)<<"mousemovevent"<<endl;
00610         d->resizing=true;
00611         if (bright)
00612         {
00613             if (btop)
00614             {
00615                 d->resizeMode=KDockWidgetPrivate::ResizeTopRight;
00616                 d->resizePos=QPoint(width(),0)-mme->pos();
00617 
00618             }
00619             else
00620             {
00621                 d->resizePos=QPoint(width(),height())-mme->pos();
00622                 if (bbottom) d->resizeMode=KDockWidgetPrivate::ResizeBottomRight;
00623                 else d->resizeMode=KDockWidgetPrivate::ResizeRight;
00624             }
00625         }
00626         else if (bleft)
00627         {
00628             if (btop) setCursor(QCursor(SizeFDiagCursor));
00629             else
00630             if (bbottom) setCursor(QCursor(SizeBDiagCursor));
00631             else setCursor(QCursor(SizeHorCursor));
00632         }
00633         else
00634         if (bbottom)
00635         {
00636             d->resizeMode=KDockWidgetPrivate::ResizeBottom;
00637             d->resizePos=QPoint(0,height())-mme->pos();
00638         }
00639         else
00640         if  (btop) setCursor(QCursor(SizeVerCursor));
00641         else d->resizing=false;
00642 
00643         if (d->resizing) grabMouse(cursor());
00644 
00645     }
00646 #endif
00647     QWidget::mousePressEvent(mme);
00648 }
00649 
00650 void KDockWidget::mouseReleaseEvent(QMouseEvent* ev)
00651 {
00652 #ifdef BORDERLESS_WINDOWS
00653     d->resizing=false;
00654     releaseMouse();
00655 #endif
00656     QWidget::mouseReleaseEvent(ev);
00657 }
00658 
00659 void  KDockWidget::mouseMoveEvent(QMouseEvent* mme)
00660 {
00661     QWidget::mouseMoveEvent(mme);
00662 #ifdef BORDERLESS_WINDOWS
00663     if (parent()) return;
00664 
00665     if (d->resizing)
00666     {
00667         switch (d->resizeMode)
00668         {
00669             case KDockWidgetPrivate::ResizeRight:
00670                 resize(mme->pos().x()+d->resizePos.x(),height());
00671                 break;
00672             case KDockWidgetPrivate::ResizeBottomRight:
00673                 resize(mme->pos().x()+d->resizePos.x(),mme->pos().y()+d->resizePos.y());
00674                 break;
00675             case KDockWidgetPrivate::ResizeBottom:
00676                 resize(width(),mme->pos().y()+d->resizePos.y());
00677                 break;
00678             default:
00679                 break;
00680         }
00681         return;
00682     }
00683 
00684 
00685     bool bbottom;
00686     bool bleft;
00687     bool bright;
00688     bool btop;
00689     int styleheight;
00690     QPoint mp;
00691     mp=mme->pos();
00692         styleheight=2*style().pixelMetric(QStyle::PM_DefaultFrameWidth,this);
00693     bbottom=mp.y()>=height()-styleheight;
00694     btop=mp.y()<=styleheight;
00695     bleft=mp.x()<=styleheight;
00696     bright=mp.x()>=width()-styleheight;
00697     kdDebug(282)<<"mousemovevent"<<endl;
00698     if (bright)
00699     {
00700         if (btop) setCursor(QCursor(SizeBDiagCursor));
00701         else
00702         if (bbottom) setCursor(QCursor(SizeFDiagCursor));
00703         else setCursor(QCursor(SizeHorCursor));
00704     }
00705     else if (bleft)
00706     {
00707         if (btop) setCursor(QCursor(SizeFDiagCursor));
00708         else
00709         if (bbottom) setCursor(QCursor(SizeBDiagCursor));
00710         else setCursor(QCursor(SizeHorCursor));
00711     }
00712     else
00713     if (bbottom ||  btop) setCursor(QCursor(SizeVerCursor));
00714     else setCursor(QCursor(ArrowCursor));
00715 #endif
00716 }
00717 
00718 void KDockWidget::setLatestKDockContainer(QWidget* container)
00719 {
00720     if (container)
00721     {
00722         if (dynamic_cast<KDockContainer*>(container))
00723             d->container=container;
00724         else
00725             d->container=0;
00726     }
00727 }
00728 
00729 QWidget* KDockWidget::latestKDockContainer()
00730 {
00731     if (!(d->container)) return 0;
00732     if (dynamic_cast<KDockContainer*>(d->container.operator->())) return d->container;
00733     return 0;
00734 }
00735 
00736 
00737 
00738 KDockWidgetAbstractHeader *KDockWidget::getHeader() {
00739     return header;
00740 }
00741 
00742 void KDockWidget::setHeader( KDockWidgetAbstractHeader* h )
00743 {
00744   if ( !h ) return;
00745 
00746   if ( header ){
00747     delete header;
00748     delete layout;
00749     header = h;
00750     layout = new QVBoxLayout( this );
00751     layout->setResizeMode( QLayout::Minimum );
00752     layout->addWidget( header );
00753      setWidget( widget );
00754   } else {
00755     header = h;
00756     layout->addWidget( header );
00757   }
00758   kdDebug(282)<<caption()<<": KDockWidget::setHeader"<<endl;
00759   setEnableDocking(eDocking);
00760 }
00761 
00762 void KDockWidget::setEnableDocking( int pos )
00763 {
00764   eDocking = pos;
00765   if( header && header->inherits( "KDockWidgetHeader" ) )
00766      ( ( KDockWidgetHeader* ) header )->showUndockButton( pos & DockDesktop );
00767   updateHeader();
00768 }
00769 
00770 void KDockWidget::updateHeader()
00771 {
00772   if ( parent() ){
00773 #ifdef BORDERLESS_WINDOWS
00774       layout->setMargin(0);
00775       setMouseTracking(false);
00776       setCursor(QCursor(ArrowCursor));
00777 #endif
00778 
00779     if ( (parent() == manager->main) || isGroup || (eDocking == KDockWidget::DockNone) ){
00780       header->hide();
00781     } else {
00782       header->setTopLevel( false );
00783       if (widget && dynamic_cast<KDockContainer*>(widget))
00784         header->hide();
00785       else
00786         header->show();
00787     }
00788   } else {
00789     header->setTopLevel( true );
00790     header->show();
00791 #ifdef BORDERLESS_WINDOWS
00792       layout->setMargin(2*style().pixelMetric(QStyle::PM_DefaultFrameWidth,this));
00793       setMouseTracking(true);
00794 #endif
00795   }
00796 }
00797 
00798 void KDockWidget::applyToWidget( QWidget* s, const QPoint& p )
00799 {
00800   if ( parent() != s )
00801   {
00802     hide();
00803     reparent(s, 0, QPoint(0,0), false);
00804   }
00805 
00806   if ( s && s->inherits("KDockMainWindow") ){
00807     ((KDockMainWindow*)s)->setView( this );
00808   }
00809 
00810   if ( manager && s == manager->main ){
00811       setGeometry( QRect(QPoint(0,0), manager->main->geometry().size()) );
00812   }
00813 
00814   if ( !s )
00815   {
00816     move(p);
00817 
00818 #ifndef NO_KDE2
00819 #ifdef Q_WS_X11
00820     if (d->transient && d->_parent)
00821       XSetTransientForHint( qt_xdisplay(), winId(), d->_parent->winId() );
00822 
00823 #ifdef BORDERLESS_WINDOWS
00824     KWin::setType( winId(), NET::Override); //d->windowType );
00825 //      setWFlags(WStyle_Customize | WStyle_NoBorder | WStyle_Tool);
00826 #else
00827     KWin::setType( winId(), d->windowType );
00828 #endif // BORDERLESS_WINDOW
00829 #endif // Q_WS_X11
00830 #endif
00831 
00832   }
00833   updateHeader();
00834 
00835   setIcon(*pix);
00836 }
00837 
00838 void KDockWidget::show()
00839 {
00840   if ( parent() || manager->main->isVisible() )
00841     if ( !parent() ){
00842      emit manager->setDockDefaultPos( this );
00843      emit setDockDefaultPos();
00844      if ( parent() ){
00845         makeDockVisible();
00846       } else {
00847         QWidget::show();
00848       }
00849     } else {
00850      QWidget::show();
00851     }
00852 }
00853 
00854 #ifndef NO_KDE2
00855 
00856 void KDockWidget::setDockWindowType (NET::WindowType windowType)
00857 {
00858   d->windowType = windowType;
00859   applyToWidget( parentWidget(), QPoint(0,0) );
00860 }
00861 
00862 #endif
00863 
00864 void KDockWidget::setDockWindowTransient (QWidget *parent, bool transientEnabled)
00865 {
00866   d->_parent = parent;
00867   d->transient = transientEnabled;
00868   applyToWidget( parentWidget(), QPoint(0,0) );
00869 }
00870 
00871 QWidget *KDockWidget::transientTo() {
00872     if (d->transient && d->_parent) return d->_parent; else return 0;
00873 }
00874 
00875 bool KDockWidget::event( QEvent *event )
00876 {
00877   switch ( event->type() )
00878   {
00879     #undef FocusIn
00880     case QEvent::FocusIn:
00881       if (widget && !d->pendingFocusInEvent) {
00882          d->pendingFocusInEvent = true;
00883          widget->setFocus();
00884       }
00885       d->pendingFocusInEvent = false;
00886       break;
00887     case QEvent::ChildRemoved:
00888       if ( widget == ((QChildEvent*)event)->child() ) widget = 0L;
00889       break;
00890     case QEvent::Show:
00891       if ( widget ) widget->show();
00892       emit manager->change();
00893       break;
00894     case QEvent::Hide:
00895       if ( widget ) widget->hide();
00896       emit manager->change();
00897       break;
00898     case QEvent::CaptionChange:
00899       if ( parentWidget() ){
00900         if ( parent()->inherits("KDockSplitter") ){
00901           ((KDockSplitter*)(parent()))->updateName();
00902         }
00903         if ( parentDockTabGroup() ){
00904           setDockTabName( parentDockTabGroup() );
00905           parentDockTabGroup()->setTabLabel( this, tabPageLabel() );
00906         }
00907       }
00908       break;
00909     case QEvent::Close:
00910       emit iMBeingClosed();
00911       break;
00912     default:
00913       break;
00914   }
00915   return QWidget::event( event );
00916 }
00917 
00918 KDockWidget *KDockWidget::findNearestDockWidget(DockPosition pos)
00919 {
00920     if (!parent()) return 0;
00921     if (!parent()->inherits("KDockSplitter")) return 0;
00922     Orientation orientation=((pos==DockLeft) || (pos==DockRight)) ? Vertical:Horizontal;
00923         if (((KDockSplitter*)(parent()))->orientation()==orientation)
00924         {
00925             KDockWidget *neighbor=
00926                 ((pos==DockLeft)||(pos==DockTop))?
00927                 static_cast<KDockWidget*>(((KDockSplitter*)(parent()))->getFirst()):
00928                 static_cast<KDockWidget*>(((KDockSplitter*)(parent()))->getLast());
00929 
00930             if (neighbor==this)
00931             return (static_cast<KDockWidget*>(parent()->parent())->findNearestDockWidget(pos));
00932             else
00933             if (neighbor->getWidget() && (neighbor->getWidget()->qt_cast("KDockTabGroup")))
00934                 return (KDockWidget*)(((KDockTabGroup*)neighbor->getWidget())->page(0));
00935             else
00936             return neighbor;
00937         }
00938         else
00939         return (static_cast<KDockWidget*>(parent()->parent())->findNearestDockWidget(pos));
00940 
00941     return 0;
00942 }
00943 
00944 
00945 KDockWidget* KDockWidget::manualDock( KDockWidget* target, DockPosition dockPos, int spliPos, QPoint pos, bool check, int tabIndex )
00946 {
00947   if (this == target)
00948     return 0L;  // docking to itself not possible
00949 
00950 //  kdDebug(282)<<"manualDock called "<<endl;
00951   bool success = true; // tested flag
00952 
00953   // Check to make sure that we can dock in to the position wee
00954   // were told to dock in to
00955   if ( !(eDocking & (int)dockPos) ){
00956     success = false;
00957 //  kdDebug(282)<<"KDockWidget::manualDock(): success = false (1)"<<endl;
00958   }
00959 
00960   // fix for apps which use a value > 100%. The splitter position must be between 0..100
00961   // The old behavior on high resolution was 0..10000. So likely the value is >100.
00962   if (spliPos > 100) {
00963       spliPos = spliPos / 100;
00964       kdDebug(282) << "KDockWidget::manualDock(): fix splitter position: " << spliPos << endl;
00965   }
00966 
00967   KDockWidget *tmpTarget = 0;
00968   switch (dockPos) {
00969     case DockLeft:
00970         tmpTarget=dockManager()->d->leftContainer;
00971         break;
00972     case DockRight:
00973         tmpTarget=dockManager()->d->rightContainer;
00974         break;
00975     case DockBottom:
00976         tmpTarget=dockManager()->d->bottomContainer;
00977         break;
00978     case DockTop:
00979         tmpTarget=dockManager()->d->topContainer;
00980         break;
00981     default:
00982         tmpTarget = 0;
00983   }
00984 
00985   //If we're not the target, and the target is our dock manager's main window
00986   //dock into the temp target as chosen above
00987   if ( tmpTarget && target && this != tmpTarget && target == dockManager()->d->mainDockWidget )
00988     return manualDock(tmpTarget,DockCenter,spliPos,pos,check,tabIndex);
00989 
00990   // check if the target allows us to oock into the requested position
00991   if ( target && !(target->sDocking & (int)dockPos) ){
00992     success = false;
00993 //  kdDebug(282)<<"KDockWidget::manualDock(): success = false (2)"<<endl;
00994   }
00995 
00996   /* if we have a parent, and it's not a KDockSplitter, and we don't have a parent
00997    * dock tab group, and our parent isn't a KDockContainer, and we have no explicit
00998    * parent dock container...we can't do much yet */
00999   if ( parent() && !parent()->inherits("KDockSplitter") && !parentDockTabGroup() &&
01000     !(dynamic_cast<KDockContainer*>(parent())) && !parentDockContainer()){
01001 //  kdDebug(282)<<"KDockWidget::manualDock(): success = false (3)"<<endl;
01002 //  kdDebug(282)<<parent()->name()<<endl;
01003     success = false;
01004   }
01005 
01006   /* If all of our attempts to dock back so far have failed and we have a target
01007    * and we're not being called recursively (i guess that's what check is for)
01008    * then attempt to dock back to ourselves. */
01009   if ( !success ){
01010     // try to make another manualDock
01011     KDockWidget* dock_result = 0L;
01012     if ( target && !check ){
01013       KDockWidget::DockPosition another__dockPos = KDockWidget::DockNone;
01014       switch ( dockPos ){
01015         case KDockWidget::DockLeft  : another__dockPos = KDockWidget::DockRight ; break;
01016         case KDockWidget::DockRight : another__dockPos = KDockWidget::DockLeft  ; break;
01017         case KDockWidget::DockTop   : another__dockPos = KDockWidget::DockBottom; break;
01018         case KDockWidget::DockBottom: another__dockPos = KDockWidget::DockTop   ; break;
01019         default: break;
01020       }
01021       dock_result = target->manualDock( this, another__dockPos, spliPos, pos, true, tabIndex );
01022     }
01023     return dock_result;
01024   }
01025   // end check block
01026 
01027   d->blockHasUndockedSignal = true;
01028   undock();
01029   d->blockHasUndockedSignal = false;
01030 
01031   //we have no docking target, so we're undocking
01032   if ( !target ){
01033     move( pos );
01034     show();
01035     emit manager->change();
01036     return this;
01037   }
01038 
01039 //  kdDebug(282)<<"Looking for  KDockTabGroup"<<endl;
01040   KDockTabGroup* parentTab = target->parentDockTabGroup();
01041   if ( parentTab ){
01042     // add to existing TabGroup
01043     applyToWidget( parentTab );
01044     parentTab->insertTab( this, icon() ? *icon() : QPixmap(),
01045                           tabPageLabel(), tabIndex );
01046 
01047     QWidget *wantTransient=parentTab->transientTo();
01048     target->setDockWindowTransient(wantTransient,wantTransient);
01049 
01050     setDockTabName( parentTab );
01051     if( !toolTipStr.isEmpty())
01052       parentTab->setTabToolTip( this, toolTipStr);
01053 
01054     currentDockPos = KDockWidget::DockCenter;
01055     emit manager->change();
01056     return (KDockWidget*)parentTab->parent();
01057   }
01058   else
01059   {
01060 //      kdDebug(282)<<"Looking for  KDockContainer"<<endl;
01061     QWidget *contWid=target->parentDockContainer();
01062       if (!contWid) contWid=target->widget;
01063       if (contWid)
01064       {
01065         KDockContainer *cont=dynamic_cast<KDockContainer*>(contWid);
01066           if (cont)
01067           {
01068             if (latestKDockContainer() && (latestKDockContainer()!=contWid)) {
01069                 KDockContainer* dc = dynamic_cast<KDockContainer*>(latestKDockContainer());
01070                 if (dc) {
01071                     dc->removeWidget(this);
01072                 }
01073             }
01074 //          kdDebug(282)<<"KDockContainerFound"<<endl;
01075             applyToWidget( contWid );
01076             cont->insertWidget( this, icon() ? *icon() : QPixmap(),
01077                         tabPageLabel(), tabIndex );
01078             setLatestKDockContainer(contWid);
01079 //          setDockTabName( parentTab );
01080             if( !toolTipStr.isEmpty())
01081             cont->setToolTip( this, toolTipStr);
01082 
01083             currentDockPos = KDockWidget::DockCenter;
01084             emit manager->change();
01085             return (KDockWidget*)(cont->parentDockWidget());
01086 
01087           }
01088       }
01089   }
01090 
01091   // create a new dockwidget that will contain the target and this
01092   QWidget* parentDock = target->parentWidget();
01093   KDockWidget* newDock = new KDockWidget( manager, "tempName", QPixmap(""), parentDock );
01094   newDock->currentDockPos = target->currentDockPos;
01095 
01096   if ( dockPos == KDockWidget::DockCenter ){
01097     newDock->isTabGroup = true;
01098   } else {
01099     newDock->isGroup = true;
01100   }
01101   newDock->eDocking = (target->eDocking & eDocking) & (~(int)KDockWidget::DockCenter);
01102 
01103   newDock->applyToWidget( parentDock );
01104 
01105   if ( !parentDock ){
01106     // dock to a toplevel dockwidget means newDock is toplevel now
01107     newDock->move( target->frameGeometry().topLeft() );
01108     newDock->resize( target->geometry().size() );
01109     if ( target->isVisibleToTLW() ) newDock->show();
01110   }
01111 
01112   // redirect the dockback button to the new dockwidget
01113   if( target->formerBrotherDockWidget ) {
01114     newDock->setFormerBrotherDockWidget(target->formerBrotherDockWidget);
01115     if( formerBrotherDockWidget )
01116       target->loseFormerBrotherDockWidget();
01117     }
01118   newDock->formerDockPos = target->formerDockPos;
01119 
01120 
01121  // HERE SOMETING CREATING CONTAINERS SHOULD BE ADDED !!!!!
01122   if ( dockPos == KDockWidget::DockCenter )
01123   {
01124     KDockTabGroup* tab = new KDockTabGroup( newDock, "_dock_tab");
01125     QObject::connect(tab, SIGNAL(currentChanged(QWidget*)), d, SLOT(slotFocusEmbeddedWidget(QWidget*)));
01126     newDock->setWidget( tab );
01127 
01128     target->applyToWidget( tab );
01129     applyToWidget( tab );
01130 
01131 
01132     tab->insertTab( target, target->icon() ? *(target->icon()) : QPixmap(),
01133                     target->tabPageLabel() );
01134 
01135 
01136 
01137     if( !target->toolTipString().isEmpty())
01138      tab->setTabToolTip( target, target->toolTipString());
01139 
01140     tab->insertTab( this, icon() ? *icon() : QPixmap(),
01141                     tabPageLabel(), tabIndex );
01142 
01143     QRect geom=newDock->geometry();
01144     QWidget *wantTransient=tab->transientTo();
01145     newDock->setDockWindowTransient(wantTransient,wantTransient);
01146     newDock->setGeometry(geom);
01147 
01148     if( !toolTipString().isEmpty())
01149       tab->setTabToolTip( this, toolTipString());
01150 
01151     setDockTabName( tab );
01152     tab->show();
01153 
01154     currentDockPos = DockCenter;
01155     target->formerDockPos = target->currentDockPos;
01156     target->currentDockPos = DockCenter;
01157   }
01158   else {
01159     // if to dock not to the center of the target dockwidget,
01160     // dock to newDock
01161     KDockSplitter* panner = 0L;
01162     if ( dockPos == KDockWidget::DockTop  || dockPos == KDockWidget::DockBottom ) panner = new KDockSplitter( newDock, "_dock_split_", Horizontal, spliPos );
01163     if ( dockPos == KDockWidget::DockLeft || dockPos == KDockWidget::DockRight  ) panner = new KDockSplitter( newDock, "_dock_split_", Vertical , spliPos );
01164     newDock->setWidget( panner );
01165 
01166     panner->setOpaqueResize(manager->splitterOpaqueResize());
01167     panner->setKeepSize(manager->splitterKeepSize());
01168     panner->setFocusPolicy( NoFocus );
01169     target->applyToWidget( panner );
01170     applyToWidget( panner );
01171     target->formerDockPos = target->currentDockPos;
01172     if ( dockPos == KDockWidget::DockRight) {
01173       panner->activate( target, this );
01174       currentDockPos = KDockWidget::DockRight;
01175       target->currentDockPos = KDockWidget::DockLeft;
01176     }
01177     else if( dockPos == KDockWidget::DockBottom) {
01178       panner->activate( target, this );
01179       currentDockPos = KDockWidget::DockBottom;
01180       target->currentDockPos = KDockWidget::DockTop;
01181     }
01182     else if( dockPos == KDockWidget::DockTop) {
01183       panner->activate( this, target );
01184       currentDockPos = KDockWidget::DockTop;
01185       target->currentDockPos = KDockWidget::DockBottom;
01186     }
01187     else if( dockPos == KDockWidget::DockLeft) {
01188       panner->activate( this, target );
01189       currentDockPos = KDockWidget::DockLeft;
01190       target->currentDockPos = KDockWidget::DockRight;
01191     }
01192     target->show();
01193     show();
01194     panner->show();
01195   }
01196 
01197   if ( parentDock ){
01198     if ( parentDock->inherits("KDockSplitter") ){
01199       KDockSplitter* sp = (KDockSplitter*)parentDock;
01200       sp->deactivate();
01201       if ( sp->getFirst() == target )
01202         sp->activate( newDock, 0L );
01203       else
01204         sp->activate( 0L, newDock );
01205     }
01206   }
01207 
01208   newDock->show();
01209   emit target->docking( this, dockPos );
01210   emit manager->replaceDock( target, newDock );
01211   emit manager->change();
01212 
01213   return newDock;
01214 }
01215 
01216 KDockTabGroup* KDockWidget::parentDockTabGroup() const
01217 {
01218   if ( !parent() ) return 0L;
01219   QWidget* candidate = parentWidget()->parentWidget();
01220   if ( candidate && candidate->inherits("KDockTabGroup") ) return (KDockTabGroup*)candidate;
01221   return 0L;
01222 }
01223 
01224 QWidget *KDockWidget::parentDockContainer() const
01225 {
01226   if (!parent()) return 0L;
01227   QWidget* candidate = parentWidget()->parentWidget();
01228   if (candidate && dynamic_cast<KDockContainer*>(candidate)) return candidate;
01229   return 0L;
01230 }
01231 
01232 
01233 void KDockWidget::setForcedFixedWidth(int w)
01234 {
01235     d->forcedWidth=w;
01236     setFixedWidth(w);
01237     if (!parent()) return;
01238     if (parent()->inherits("KDockSplitter"))
01239         static_cast<KDockSplitter*>(parent()->qt_cast("KDockSplitter"))->setForcedFixedWidth(this,w);
01240 }
01241 
01242 void KDockWidget::setForcedFixedHeight(int h)
01243 {
01244     d->forcedHeight=h;
01245     setFixedHeight(h);
01246     if (!parent()) return;
01247     if (parent()->inherits("KDockSplitter"))
01248         static_cast<KDockSplitter*>(parent()->qt_cast("KDockSplitter"))->setForcedFixedHeight(this,h);
01249 }
01250 
01251 int KDockWidget::forcedFixedWidth()
01252 {
01253     return d->forcedWidth;
01254 }
01255 
01256 int KDockWidget::forcedFixedHeight()
01257 {
01258     return d->forcedHeight;
01259 }
01260 
01261 void KDockWidget::restoreFromForcedFixedSize()
01262 {
01263     d->forcedWidth=-1;
01264     d->forcedHeight=-1;
01265     setMinimumWidth(0);
01266     setMaximumWidth(32000);
01267     setMinimumHeight(0);
01268     setMaximumHeight(32000);
01269     if (!parent()) return;
01270     if (parent()->inherits("KDockSplitter"))
01271         static_cast<KDockSplitter*>(parent()->qt_cast("KDockSplitter"))->restoreFromForcedFixedSize(this);
01272 }
01273 
01274 void KDockWidget::toDesktop()
01275 {
01276    QPoint p = mapToGlobal( QPoint( -30, -30 ) );
01277    if( p.x( ) < 0 )
01278       p.setX( 0 );
01279    if( p.y( ) < 0 )
01280       p.setY( 0 );
01281    manualDock( 0, DockDesktop, 50, p );
01282 }
01283 
01284 KDockWidget::DockPosition KDockWidget::currentDockPosition() const
01285 {
01286     return currentDockPos;
01287 }
01288 
01289 void KDockWidget::undock()
01290 {
01291 //  kdDebug(282)<<"KDockWidget::undock()"<<endl;
01292 
01293   manager->d->dragRect = QRect ();
01294   manager->drawDragRectangle ();
01295 
01296   QWidget* parentW = parentWidget();
01297   if ( !parentW ){
01298     hide();
01299     if (!d->blockHasUndockedSignal)
01300       emit hasUndocked();
01301     return;
01302   }
01303 
01304   formerDockPos = currentDockPos;
01305   currentDockPos = KDockWidget::DockDesktop;
01306 
01307   manager->blockSignals(true);
01308   manager->undockProcess = true;
01309 
01310   bool isV = parentW->isVisibleToTLW();
01311 
01312   //UNDOCK HAS TO BE IMPLEMENTED CORRECTLY :)
01313   KDockTabGroup* parentTab = parentDockTabGroup();
01314   if ( parentTab ){
01315     d->index = parentTab->indexOf( this); // memorize the page position in the tab widget
01316     parentTab->removePage( this );
01317 /*
01318     QWidget *wantTransient=parentTab->transientTo();
01319     target->setDockWindowTransient(wantTransient,wantTransient);
01320  */
01321     setFormerBrotherDockWidget((KDockWidget*)parentTab->page(0));
01322     applyToWidget( 0L );
01323     if ( parentTab->count() == 1 ){
01324 
01325       // last subdock widget in the tab control
01326       KDockWidget* lastTab = (KDockWidget*)parentTab->page(0);
01327       parentTab->removePage( lastTab );
01328 /*      QWidget *wantTransient=parentTab->transientTo();
01329       target->setDockWindowTransient(wantTransient,wantTransient);*/
01330 
01331       lastTab->applyToWidget( 0L );
01332       lastTab->move( parentTab->mapToGlobal(parentTab->frameGeometry().topLeft()) );
01333 
01334       // KDockTabGroup always have a parent that is a KDockWidget
01335       KDockWidget* parentOfTab = (KDockWidget*)parentTab->parent();
01336       delete parentTab; // KDockTabGroup
01337 
01338       QWidget* parentOfDockWidget = parentOfTab->parentWidget();
01339       if ( !parentOfDockWidget ){
01340           if ( isV ) lastTab->show();
01341       } else {
01342         if ( parentOfDockWidget->inherits("KDockSplitter") ){
01343           KDockSplitter* split = (KDockSplitter*)parentOfDockWidget;
01344           lastTab->applyToWidget( split );
01345           split->deactivate();
01346           if ( split->getFirst() == parentOfTab ){
01347             split->activate( lastTab );
01348             if ( ((KDockWidget*)split->parent())->splitterOrientation == Vertical )
01349               emit ((KDockWidget*)split->getAnother(parentOfTab))->docking( parentOfTab, KDockWidget::DockLeft );
01350             else
01351               emit ((KDockWidget*)split->getAnother(parentOfTab))->docking( parentOfTab, KDockWidget::DockTop );
01352           } else {
01353             split->activate( 0L, lastTab );
01354             if ( ((KDockWidget*)split->parent())->splitterOrientation == Vertical )
01355               emit ((KDockWidget*)split->getAnother(parentOfTab))->docking( parentOfTab, KDockWidget::DockRight );
01356             else
01357               emit ((KDockWidget*)split->getAnother(parentOfTab))->docking( parentOfTab, KDockWidget::DockBottom );
01358           }
01359           split->show();
01360         } else {
01361           lastTab->applyToWidget( parentOfDockWidget );
01362         }
01363         lastTab->show();
01364       }
01365       manager->blockSignals(false);
01366       emit manager->replaceDock( parentOfTab, lastTab );
01367       lastTab->currentDockPos = parentOfTab->currentDockPos;
01368       emit parentOfTab->iMBeingClosed();
01369       manager->blockSignals(true);
01370       delete parentOfTab;
01371 
01372     } else {
01373       setDockTabName( parentTab );
01374     }
01375   } else {
01376  /*********************************************************************************************/
01377   //QWidget* containerWidget = (QWidget*)parent();
01378   bool undockedFromContainer=false;
01379   if (d->container)
01380   {
01381 //    kdDebug(282)<<"undocked from dockcontainer"<<endl;
01382       undockedFromContainer=true;
01383       KDockContainer* dc = dynamic_cast<KDockContainer*>(d->container.operator->());
01384       if (dc) {
01385           dc->undockWidget(this);
01386           setFormerBrotherDockWidget(dc->parentDockWidget());
01387       }
01388       applyToWidget( 0L );
01389   }
01390    if (!undockedFromContainer) {
01391 /*********************************************************************************************/
01392     if ( parentW->inherits("KDockSplitter") ){
01393       KDockSplitter* parentSplitterOfDockWidget = (KDockSplitter*)parentW;
01394       d->splitPosInPercent = parentSplitterOfDockWidget->separatorPosInPercent();
01395 
01396       KDockWidget* secondWidget = (KDockWidget*)parentSplitterOfDockWidget->getAnother( this );
01397       KDockWidget* group        = (KDockWidget*)parentSplitterOfDockWidget->parentWidget();
01398       setFormerBrotherDockWidget(secondWidget);
01399       applyToWidget( 0L );
01400       group->hide();
01401 
01402       if ( !group->parentWidget() ){
01403         secondWidget->applyToWidget( 0L, group->frameGeometry().topLeft() );
01404         secondWidget->resize( group->width(), group->height() );
01405       } else {
01406         QWidget* obj = group->parentWidget();
01407         secondWidget->applyToWidget( obj );
01408         if ( obj->inherits("KDockSplitter") ){
01409           KDockSplitter* parentOfGroup = (KDockSplitter*)obj;
01410           parentOfGroup->deactivate();
01411 
01412           if ( parentOfGroup->getFirst() == group )
01413             parentOfGroup->activate( secondWidget );
01414           else
01415             parentOfGroup->activate( 0L, secondWidget );
01416         }
01417       }
01418       secondWidget->currentDockPos = group->currentDockPos;
01419       secondWidget->formerDockPos  = group->formerDockPos;
01420       delete parentSplitterOfDockWidget;
01421       manager->blockSignals(false);
01422       emit manager->replaceDock( group, secondWidget );
01423       emit group->iMBeingClosed();
01424       manager->blockSignals(true);
01425       delete group;
01426 
01427       if ( isV ) secondWidget->show();
01428     } else {
01429       if (!d->pendingDtor) {
01430         // don't reparent in the dtor of this
01431         applyToWidget( 0L );
01432       }
01433     }
01434 /*********************************************************************************************/
01435   }
01436   }
01437   manager->blockSignals(false);
01438   if (!d->blockHasUndockedSignal)
01439     emit manager->change();
01440   manager->undockProcess = false;
01441 
01442   if (!d->blockHasUndockedSignal)
01443     emit hasUndocked();
01444 }
01445 
01446 void KDockWidget::setWidget( QWidget* mw )
01447 {
01448   if ( !mw ) return;
01449 
01450   if ( mw->parent() != this ){
01451     mw->reparent(this, 0, QPoint(0,0), false);
01452   }
01453 
01454 #ifdef BORDERLESS_WINDOWS
01455   if (!mw->ownCursor()) mw->setCursor(QCursor(ArrowCursor));
01456 #endif
01457   widget = mw;
01458   delete layout;
01459 
01460   layout = new QVBoxLayout( this );
01461   layout->setResizeMode( QLayout::Minimum );
01462 
01463   KDockContainer* dc = dynamic_cast<KDockContainer*>(widget);
01464   if (dc)
01465   {
01466     d->isContainer=true;
01467     manager->d->containerDocks.append(this);
01468   }
01469   else
01470   {
01471     d->isContainer=false;
01472   }
01473 
01474   {
01475      header->show();
01476      layout->addWidget( header );
01477      layout->addWidget( widget,1 );
01478   }
01479   updateHeader();
01480   emit widgetSet(mw);
01481 }
01482 
01483 void KDockWidget::setDockTabName( KDockTabGroup* tab )
01484 {
01485   QString listOfName;
01486   QString listOfCaption;
01487   for ( int i = 0; i < tab->count(); ++i ) {
01488     QWidget *w = tab->page( i );
01489     listOfCaption.append( w->caption() ).append(",");
01490     listOfName.append( w->name() ).append(",");
01491   }
01492   listOfCaption.remove( listOfCaption.length()-1, 1 );
01493   listOfName.remove( listOfName.length()-1, 1 );
01494 
01495   tab->parentWidget()->setName( listOfName.utf8() );
01496   tab->parentWidget()->setCaption( listOfCaption );
01497 
01498   tab->parentWidget()->repaint( false ); // KDockWidget->repaint
01499   if ( tab->parentWidget()->parent() )
01500     if ( tab->parentWidget()->parent()->inherits("KDockSplitter") )
01501       ((KDockSplitter*)(tab->parentWidget()->parent()))->updateName();
01502 }
01503 
01504 bool KDockWidget::mayBeHide() const
01505 {
01506   bool f = (parent() != manager->main);
01507   return ( !isGroup && !isTabGroup && f && isVisible() && ( eDocking != (int)KDockWidget::DockNone ) );
01508 }
01509 
01510 bool KDockWidget::mayBeShow() const
01511 {
01512   bool f = (parent() != manager->main);
01513   return ( !isGroup && !isTabGroup && f && !isVisible() );
01514 }
01515 
01516 void KDockWidget::changeHideShowState()
01517 {
01518   if ( mayBeHide() ){
01519     undock();
01520     return;
01521   }
01522 
01523   if ( mayBeShow() ){
01524     if ( manager->main->inherits("KDockMainWindow") ){
01525       ((KDockMainWindow*)manager->main)->makeDockVisible(this);
01526     } else {
01527       makeDockVisible();
01528     }
01529   }
01530 }
01531 
01532 void KDockWidget::makeDockVisible()
01533 {
01534   if ( parentDockTabGroup() ){
01535     parentDockTabGroup()->showPage( this );
01536   }
01537   if (parentDockContainer()) {
01538     QWidget *contWid=parentDockContainer();
01539     KDockContainer *x = dynamic_cast<KDockContainer*>(contWid);
01540     if (x) {
01541       x->showWidget(this);
01542     }
01543   }
01544   if ( isVisible() ) return;
01545 
01546   QWidget* p = parentWidget();
01547   while ( p ){
01548     if ( !p->isVisible() )
01549       p->show();
01550     p = p->parentWidget();
01551   }
01552   if( !parent() ) // is undocked
01553     dockBack();
01554   show();
01555 }
01556 
01557 void KDockWidget::setFormerBrotherDockWidget(KDockWidget *dockWidget)
01558 {
01559   formerBrotherDockWidget = dockWidget;
01560   if( formerBrotherDockWidget )
01561     QObject::connect( formerBrotherDockWidget, SIGNAL(iMBeingClosed()),
01562                       this, SLOT(loseFormerBrotherDockWidget()) );
01563 }
01564 
01565 void KDockWidget::loseFormerBrotherDockWidget()
01566 {
01567   if( formerBrotherDockWidget )
01568     QObject::disconnect( formerBrotherDockWidget, SIGNAL(iMBeingClosed()),
01569                          this, SLOT(loseFormerBrotherDockWidget()) );
01570   formerBrotherDockWidget = 0L;
01571   repaint();
01572 }
01573 
01574 void KDockWidget::dockBack()
01575 {
01576   if( formerBrotherDockWidget) {
01577     // search all children if it tries to dock back to a child
01578     bool found = false;
01579     QObjectList* cl = queryList("KDockWidget");
01580     QObjectListIt it( *cl );
01581     QObject * obj;
01582     while ( !found && (obj=it.current()) != 0 ) {
01583       ++it;
01584       QWidget* widg = (QWidget*)obj;
01585       if( widg == formerBrotherDockWidget)
01586         found = true;
01587     }
01588     delete cl;
01589 
01590     if( !found) {
01591       // can dock back to the former brother dockwidget
01592       manualDock( formerBrotherDockWidget, formerDockPos, d->splitPosInPercent, QPoint(0,0), false, d->index);
01593       formerBrotherDockWidget = 0L;
01594       makeDockVisible();
01595       return;
01596     }
01597   }
01598 
01599   // else dockback to the dockmainwindow (default behavior)
01600   manualDock( ((KDockMainWindow*)manager->main)->getMainDockWidget(), formerDockPos, d->splitPosInPercent, QPoint(0,0), false, d->index);
01601   formerBrotherDockWidget = 0L;
01602   if (parent())
01603     makeDockVisible();
01604 }
01605 
01606 bool KDockWidget::isDockBackPossible() const
01607 {
01608   if( !(formerBrotherDockWidget) || !(formerBrotherDockWidget->dockSite() & formerDockPos))
01609     return false;
01610   else
01611     return true;
01612 }
01613 
01614 /**************************************************************************************/
01615 
01616 
01617 KDockManager::KDockManager( QWidget* mainWindow , const char* name )
01618 :QObject( mainWindow, name )
01619   ,main(mainWindow)
01620   ,currentDragWidget(0L)
01621   ,currentMoveWidget(0L)
01622   ,childDockWidgetList(0L)
01623   ,autoCreateDock(0L)
01624   ,storeW(0)
01625   ,storeH(0)
01626   ,dragging(false)
01627   ,undockProcess(false)
01628   ,dropCancel(true)
01629 {
01630   d = new KDockManagerPrivate;
01631 
01632   d->readyToDrag = false;
01633   d->mainDockWidget=0;
01634 
01635 #ifndef NO_KDE2
01636   d->splitterOpaqueResize = KGlobalSettings::opaqueResize();
01637 #else
01638   d->splitterOpaqueResize = false;
01639 #endif
01640 
01641   d->splitterKeepSize = false;
01642   d->splitterHighResolution = false;
01643   d->m_readDockConfigMode = WrapExistingWidgetsOnly; // default as before
01644 
01645   main->installEventFilter( this );
01646 
01647   undockProcess = false;
01648 
01649   menuData = new QPtrList<MenuDockData>;
01650   menuData->setAutoDelete( true );
01651   menuData->setAutoDelete( true );
01652 
01653 #ifndef NO_KDE2
01654   menu = new KPopupMenu();
01655 #else
01656   menu = new QPopupMenu();
01657 #endif
01658 
01659   connect( menu, SIGNAL(aboutToShow()), SLOT(slotMenuPopup()) );
01660   connect( menu, SIGNAL(activated(int)), SLOT(slotMenuActivated(int)) );
01661 
01662   childDock = new QObjectList();
01663   childDock->setAutoDelete( false );
01664 }
01665 
01666 
01667 void KDockManager::setMainDockWidget2(KDockWidget *w)
01668 {
01669   d->mainDockWidget=w;
01670 }
01671 
01672 KDockManager::~KDockManager()
01673 {
01674   delete menuData;
01675   delete menu;
01676 
01677   QObjectListIt it( *childDock );
01678   KDockWidget * obj;
01679 
01680   while ( (obj=(KDockWidget*)it.current()) ) {
01681     delete obj;
01682   }
01683   delete childDock;
01684   delete d;
01685   d=0;
01686 }
01687 
01688 void KDockManager::activate()
01689 {
01690   QObjectListIt it( *childDock );
01691   KDockWidget * obj;
01692 
01693   while ( (obj=(KDockWidget*)it.current()) ) {
01694     ++it;
01695     if ( obj->widget ) obj->widget->show();
01696     if ( !obj->parentDockTabGroup() ){
01697         obj->show();
01698     }
01699   }
01700   if ( !main->inherits("QDialog") ) main->show();
01701 }
01702 
01703 bool KDockManager::eventFilter( QObject *obj, QEvent *event )
01704 {
01705 
01706   if ( obj->inherits("KDockWidgetAbstractHeaderDrag") ){
01707     KDockWidget* pDockWdgAtCursor = 0L;
01708     KDockWidget* curdw = ((KDockWidgetAbstractHeaderDrag*)obj)->dockWidget();
01709     switch ( event->type() ){
01710       case QEvent::MouseButtonDblClick:
01711         if (curdw->currentDockPos == KDockWidget::DockDesktop)  curdw->dockBack();
01712         else
01713     {
01714         curdw->toDesktop();
01715         // curdw->manualDock (0, KDockWidget::DockDesktop);
01716     }
01717         break;
01718 
01719       case QEvent::MouseButtonPress:
01720         if ( ((QMouseEvent*)event)->button() == LeftButton ){
01721           if ( curdw->eDocking != (int)KDockWidget::DockNone ){
01722             dropCancel = true;
01723             curdw->setFocus();
01724             qApp->processOneEvent();
01725 
01726             currentDragWidget = curdw;
01727             currentMoveWidget = 0L;
01728             childDockWidgetList = new QWidgetList();
01729             childDockWidgetList->append( curdw );
01730             findChildDockWidget( curdw, childDockWidgetList );
01731 
01732             //d->oldDragRect = QRect(); should fix rectangle not erased problem
01733             d->dragRect = QRect(curdw->geometry());
01734             QPoint p = curdw->mapToGlobal(QPoint(0,0));
01735             d->dragRect.moveTopLeft(p);
01736             drawDragRectangle();
01737             d->readyToDrag = true;
01738 
01739             d->dragOffset = QCursor::pos()-currentDragWidget->mapToGlobal(QPoint(0,0));
01740           }
01741 
01742         }
01743         break;
01744       case QEvent::MouseButtonRelease:
01745         if ( ((QMouseEvent*)event)->button() == LeftButton ){
01746           if ( dragging ){
01747             if ( !dropCancel )
01748               drop();
01749             else
01750               cancelDrop();
01751           }
01752           if (d->readyToDrag) {
01753               d->readyToDrag = false;
01754               //d->oldDragRect = QRect(); should fix rectangle not erased problem
01755               d->dragRect = QRect(curdw->geometry());
01756               QPoint p = curdw->mapToGlobal(QPoint(0,0));
01757               d->dragRect.moveTopLeft(p);
01758               drawDragRectangle();
01759               currentDragWidget = 0L;
01760               delete childDockWidgetList;
01761               childDockWidgetList = 0L;
01762           }
01763           dragging = false;
01764           dropCancel = true;
01765         }
01766         break;
01767       case QEvent::MouseMove:
01768         if ( dragging ) {
01769 
01770 #ifdef BORDERLESS_WINDOWS
01771 //BEGIN TEST
01772       KDockWidget *oldMoveWidget;
01773       if (!curdw->parent())
01774       {
01775         curdw->move(QCursor::pos()-d->dragOffset);
01776             pDockWdgAtCursor = findDockWidgetAt( QCursor::pos()-QPoint(0,d->dragOffset.y()+3) );
01777                 oldMoveWidget = currentMoveWidget;
01778       }
01779       else
01780       {
01781             pDockWdgAtCursor = findDockWidgetAt( QCursor::pos() );
01782                 oldMoveWidget = currentMoveWidget;
01783       }
01784 //END TEST
01785 #else
01786       pDockWdgAtCursor = findDockWidgetAt( QCursor::pos() );
01787           KDockWidget* oldMoveWidget = currentMoveWidget;
01788 #endif
01789 
01790       if ( currentMoveWidget  && pDockWdgAtCursor == currentMoveWidget ) { //move
01791             dragMove( currentMoveWidget, currentMoveWidget->mapFromGlobal( QCursor::pos() ) );
01792             break;
01793           } else {
01794             if (dropCancel && curdw) {
01795               d->dragRect = QRect(curdw->geometry());
01796               QPoint p = curdw->mapToGlobal(QPoint(0,0));
01797               d->dragRect.moveTopLeft(p);
01798             }else
01799               d->dragRect = QRect();
01800 
01801             drawDragRectangle();
01802           }
01803 
01804           if ( !pDockWdgAtCursor && !(curdw->eDocking & (int)KDockWidget::DockDesktop) ){
01805               // just moving at the desktop
01806               currentMoveWidget = pDockWdgAtCursor;
01807               curPos = KDockWidget::DockDesktop;
01808           } else {
01809             if ( oldMoveWidget && pDockWdgAtCursor != currentMoveWidget ) { //leave
01810               currentMoveWidget = pDockWdgAtCursor;
01811               curPos = KDockWidget::DockDesktop;
01812             }
01813           }
01814 
01815           if ( oldMoveWidget != pDockWdgAtCursor && pDockWdgAtCursor ) { //enter pDockWdgAtCursor
01816             currentMoveWidget = pDockWdgAtCursor;
01817             curPos = KDockWidget::DockDesktop;
01818           }
01819         } else {
01820           if (d->readyToDrag) {
01821             d->readyToDrag = false;
01822           }
01823           if ( (((QMouseEvent*)event)->state() == LeftButton) &&
01824                (curdw->eDocking != (int)KDockWidget::DockNone) ) {
01825             startDrag( curdw);
01826           }
01827         }
01828     break;
01829       default:
01830         break;
01831     }
01832   }
01833   return QObject::eventFilter( obj, event );
01834 }
01835 
01836 KDockWidget* KDockManager::findDockWidgetAt( const QPoint& pos )
01837 {
01838   dropCancel = true;
01839 
01840   if (!currentDragWidget)
01841     return 0L; // pointer access safety
01842 
01843   if (currentDragWidget->eDocking == (int)KDockWidget::DockNone ) return 0L;
01844 
01845   QWidget* p = QApplication::widgetAt( pos );
01846   if ( !p ) {
01847     dropCancel = false;
01848     return 0L;
01849   }
01850 #if defined(_OS_WIN32_) || defined(Q_OS_WIN32)
01851   p = p->topLevelWidget();
01852 #endif
01853   QWidget* w = 0L;
01854   findChildDockWidget( w, p, p->mapFromGlobal(pos) );
01855   if ( !w ){
01856     if ( !p->inherits("KDockWidget") ) {
01857       return 0L;
01858     }
01859     w = p;
01860   }
01861   if ( qt_find_obj_child( w, "KDockSplitter", "_dock_split_" ) ) return 0L;
01862   if ( qt_find_obj_child( w, "KDockTabGroup", "_dock_tab" ) ) return 0L;
01863   if (dynamic_cast<KDockContainer*>(w)) return 0L;
01864 
01865   if (!childDockWidgetList) return 0L;
01866   if ( childDockWidgetList->find(w) != -1 ) return 0L;
01867   if ( currentDragWidget->isGroup && ((KDockWidget*)w)->parentDockTabGroup() ) return 0L;
01868 
01869   KDockWidget* www = (KDockWidget*)w;
01870   if ( www->sDocking == (int)KDockWidget::DockNone ) return 0L;
01871   if( !www->widget )
01872     return 0L;
01873 
01874   KDockWidget::DockPosition curPos = KDockWidget::DockDesktop;
01875   QPoint cpos  = www->mapFromGlobal( pos );
01876 
01877   int ww = www->widget->width() / 3;
01878   int hh = www->widget->height() / 3;
01879 
01880   if ( cpos.y() <= hh ){
01881     curPos = KDockWidget::DockTop;
01882   } else
01883     if ( cpos.y() >= 2*hh ){
01884       curPos = KDockWidget::DockBottom;
01885     } else
01886       if ( cpos.x() <= ww ){
01887         curPos = KDockWidget::DockLeft;
01888       } else
01889         if ( cpos.x() >= 2*ww ){
01890           curPos = KDockWidget::DockRight;
01891         } else
01892             curPos = KDockWidget::DockCenter;
01893 
01894   if ( !(www->sDocking & (int)curPos) ) return 0L;
01895   if ( !(currentDragWidget->eDocking & (int)curPos) ) return 0L;
01896   if ( www->manager != this ) return 0L;
01897 
01898   dropCancel = false;
01899   return www;
01900 }
01901 
01902 void KDockManager::findChildDockWidget( QWidget*& ww, const QWidget* p, const QPoint& pos )
01903 {
01904   if ( p->children() ) {
01905     QWidget *w;
01906     QObjectListIt it( *p->children() );
01907     it.toLast();
01908     while ( it.current() ) {
01909       if ( it.current()->isWidgetType() ) {
01910         w = (QWidget*)it.current();
01911         if ( w->isVisible() && w->geometry().contains(pos) ) {
01912           if ( w->inherits("KDockWidget") ) ww = w;
01913           findChildDockWidget( ww, w, w->mapFromParent(pos) );
01914           return;
01915         }
01916       }
01917       --it;
01918     }
01919   }
01920   return;
01921 }
01922 
01923 void KDockManager::findChildDockWidget( const QWidget* p, QWidgetList*& list )
01924 {
01925   if ( p->children() ) {
01926     QWidget *w;
01927     QObjectListIt it( *p->children() );
01928     it.toLast();
01929     while ( it.current() ) {
01930       if ( it.current()->isWidgetType() ) {
01931         w = (QWidget*)it.current();
01932         if ( w->isVisible() ) {
01933           if ( w->inherits("KDockWidget") ) list->append( w );
01934           findChildDockWidget( w, list );
01935         }
01936       }
01937       --it;
01938     }
01939   }
01940   return;
01941 }
01942 
01943 void KDockManager::startDrag( KDockWidget* w )
01944 {
01945   if(( w->currentDockPos == KDockWidget::DockLeft) || ( w->currentDockPos == KDockWidget::DockRight)
01946    || ( w->currentDockPos == KDockWidget::DockTop) || ( w->currentDockPos == KDockWidget::DockBottom)) {
01947     w->prevSideDockPosBeforeDrag = w->currentDockPos;
01948 
01949     if ( w->parentWidget()->inherits("KDockSplitter") ){
01950       KDockSplitter* parentSplitterOfDockWidget = (KDockSplitter*)(w->parentWidget());
01951       w->d->splitPosInPercent = parentSplitterOfDockWidget->separatorPosInPercent();
01952     }
01953   }
01954 
01955   curPos = KDockWidget::DockDesktop;
01956   dragging = true;
01957 
01958   QApplication::setOverrideCursor(QCursor(sizeAllCursor));
01959 }
01960 
01961 void KDockManager::dragMove( KDockWidget* dw, QPoint pos )
01962 {
01963   QPoint p = dw->mapToGlobal( dw->widget->pos() );
01964   KDockWidget::DockPosition oldPos = curPos;
01965 
01966   QSize r = dw->widget->size();
01967   if ( dw->parentDockTabGroup() ){
01968     curPos = KDockWidget::DockCenter;
01969     if ( oldPos != curPos ) {
01970       d->dragRect.setRect( p.x()+2, p.y()+2, r.width()-4, r.height()-4 );
01971     }
01972     return;
01973   }
01974 
01975   int w = r.width() / 3;
01976   int h = r.height() / 3;
01977 
01978   if ( pos.y() <= h ){
01979     curPos = KDockWidget::DockTop;
01980     w = r.width();
01981   } else
01982     if ( pos.y() >= 2*h ){
01983       curPos = KDockWidget::DockBottom;
01984       p.setY( p.y() + 2*h );
01985       w = r.width();
01986     } else
01987       if ( pos.x() <= w ){
01988         curPos = KDockWidget::DockLeft;
01989         h = r.height();
01990       } else
01991         if ( pos.x() >= 2*w ){
01992           curPos = KDockWidget::DockRight;
01993           p.setX( p.x() + 2*w );
01994           h = r.height();
01995         } else
01996           {
01997             curPos = KDockWidget::DockCenter;
01998             p.setX( p.x() + w );
01999             p.setY( p.y() + h );
02000           }
02001 
02002   if ( oldPos != curPos ) {
02003     d->dragRect.setRect( p.x(), p.y(), w, h );
02004     drawDragRectangle();
02005   }
02006 }
02007 
02008 
02009 void KDockManager::cancelDrop()
02010 {
02011   QApplication::restoreOverrideCursor();
02012 
02013   delete childDockWidgetList;
02014   childDockWidgetList = 0L;
02015 
02016   d->dragRect = QRect();  // cancel drawing
02017   drawDragRectangle();    // only the old rect will be deleted
02018 }
02019 
02020 
02021 void KDockManager::drop()
02022 {
02023   d->dragRect = QRect();  // cancel drawing
02024   drawDragRectangle();    // only the old rect will be deleted
02025 
02026   QApplication::restoreOverrideCursor();
02027 
02028   delete childDockWidgetList;
02029   childDockWidgetList = 0L;
02030 
02031   if ( dropCancel ) return;
02032   if ( !currentMoveWidget && (!(currentDragWidget->eDocking & (int)KDockWidget::DockDesktop)) ) {
02033     d->dragRect = QRect();  // cancel drawing
02034     drawDragRectangle();    // only the old rect will be deleted
02035     return;
02036   }
02037   if ( !currentMoveWidget && !currentDragWidget->parent() ) {
02038     currentDragWidget->move( QCursor::pos() - d->dragOffset );
02039   }
02040   else {
02041     // curPos is the current target DockPosition.
02042     // currentDragWidget->prevSideDockPosBeforeDrag is where the dockwidget comes from.
02043     // currentDragWidget->formerDockPos is the position *before* the dockwidget was in
02044     // position currentDragWidget->prevSideDockPosBeforeDrag.
02045     int splitPos = currentDragWidget->d->splitPosInPercent;
02046     KDockWidget::DockPosition previousPosition = currentDragWidget->prevSideDockPosBeforeDrag;
02047 
02048 //    kdDebug() << splitPos << endl;
02049 //    kdDebug() << "curPos: " << curPos << endl;
02050 //    kdDebug() << "formerDockPos: " << currentDragWidget->formerDockPos<< endl;
02051 //    kdDebug() << "prevSideDockPosBeforeDrag: " << currentDragWidget->prevSideDockPosBeforeDrag<< endl;
02052 
02053     // Now we *need* to "invert" the procentual value, if the dockwidget moves from top/left
02054     // to bottom/right or vice versa. This keeps the dockwidget's size on its new position.
02055     // A special case is, when the dock position was DockNone, then we have to look for the
02056     // formerDockPos to get things right.
02057     if( (curPos != previousPosition)
02058        && (curPos != KDockWidget::DockCenter) && (curPos != KDockWidget::DockDesktop)) {
02059 
02060       if (previousPosition == KDockWidget::DockNone)
02061         previousPosition = currentDragWidget->formerDockPos;
02062 
02063       switch( previousPosition ) {
02064       case KDockWidget::DockLeft:
02065         if(curPos != KDockWidget::DockTop && curPos != KDockWidget::DockLeft)
02066           splitPos = 100 - splitPos;
02067         break;
02068 
02069       case KDockWidget::DockRight:
02070         if(curPos != KDockWidget::DockBottom && curPos != KDockWidget::DockRight)
02071           splitPos = 100 - splitPos;
02072         break;
02073 
02074       case KDockWidget::DockTop:
02075         if(curPos != KDockWidget::DockLeft && curPos != KDockWidget::DockTop )
02076           splitPos = 100 - splitPos;
02077         break;
02078 
02079       case KDockWidget::DockBottom:
02080         if(curPos != KDockWidget::DockRight && curPos != KDockWidget::DockBottom )
02081           splitPos = 100 - splitPos;
02082         break;
02083 
02084       default: break;
02085       }
02086     }
02087     // set new prevSideDockPosBeforeDrag
02088     currentDragWidget->prevSideDockPosBeforeDrag = curPos;
02089     currentDragWidget->manualDock( currentMoveWidget, curPos , splitPos, QCursor::pos() - d->dragOffset );
02090     currentDragWidget->makeDockVisible();
02091   }
02092 }
02093 
02094 
02095 static QDomElement createStringEntry(QDomDocument &doc, const QString &tagName, const QString &str)
02096 {
02097     QDomElement el = doc.createElement(tagName);
02098 
02099     el.appendChild(doc.createTextNode(str));
02100     return el;
02101 }
02102 
02103 
02104 static QDomElement createBoolEntry(QDomDocument &doc, const QString &tagName, bool b)
02105 {
02106     return createStringEntry(doc, tagName, QString::fromLatin1(b? "true" : "false"));
02107 }
02108 
02109 
02110 static QDomElement createNumberEntry(QDomDocument &doc, const QString &tagName, int n)
02111 {
02112     return createStringEntry(doc, tagName, QString::number(n));
02113 }
02114 
02115 
02116 static QDomElement createRectEntry(QDomDocument &doc, const QString &tagName, const QRect &rect)
02117 {
02118     QDomElement el = doc.createElement(tagName);
02119 
02120     QDomElement xel = doc.createElement("x");
02121     xel.appendChild(doc.createTextNode(QString::number(rect.x())));
02122     el.appendChild(xel);
02123     QDomElement yel = doc.createElement("y");
02124     yel.appendChild(doc.createTextNode(QString::number(rect.y())));
02125     el.appendChild(yel);
02126     QDomElement wel = doc.createElement("width");
02127     wel.appendChild(doc.createTextNode(QString::number(rect.width())));
02128     el.appendChild(wel);
02129     QDomElement hel = doc.createElement("height");
02130     hel.appendChild(doc.createTextNode(QString::number(rect.height())));
02131     el.appendChild(hel);
02132 
02133     return el;
02134 }
02135 
02136 
02137 static QDomElement createListEntry(QDomDocument &doc, const QString &tagName,
02138                                    const QString &subTagName, const QStrList &list)
02139 {
02140     QDomElement el = doc.createElement(tagName);
02141 
02142     QStrListIterator it(list);
02143     for (; it.current(); ++it) {
02144         QDomElement subel = doc.createElement(subTagName);
02145         subel.appendChild(doc.createTextNode(QString::fromLatin1(it.current())));
02146         el.appendChild(subel);
02147     }
02148 
02149     return el;
02150 }
02151 
02152 
02153 static QString stringEntry(QDomElement &base, const QString &tagName)
02154 {
02155     return base.namedItem(tagName).firstChild().toText().data();
02156 }
02157 
02158 
02159 static bool boolEntry(QDomElement &base, const QString &tagName)
02160 {
02161     return base.namedItem(tagName).firstChild().toText().data() == "true";
02162 }
02163 
02164 
02165 static int numberEntry(QDomElement &base, const QString &tagName)
02166 {
02167     return stringEntry(base, tagName).toInt();
02168 }
02169 
02170 
02171 static QRect rectEntry(QDomElement &base, const QString &tagName)
02172 {
02173     QDomElement el = base.namedItem(tagName).toElement();
02174 
02175     int x = numberEntry(el, "x");
02176     int y = numberEntry(el, "y");
02177     int width = numberEntry(el, "width");
02178     int height = numberEntry(el,  "height");
02179 
02180     return QRect(x, y, width, height);
02181 }
02182 
02183 
02184 static QStrList listEntry(QDomElement &base, const QString &tagName, const QString &subTagName)
02185 {
02186     QStrList list;
02187 
02188     for( QDomNode n = base.namedItem(tagName).firstChild(); !n.isNull(); n = n.nextSibling() )
02189     {
02190         QDomElement subel = n.toElement();
02191         if (subel.tagName() == subTagName)
02192             list.append(subel.firstChild().toText().data().latin1());
02193     }
02194 
02195     return list;
02196 }
02197 
02198 
02199 void KDockManager::writeConfig(QDomElement &base)
02200 {
02201     // First of all, clear the tree under base
02202     while (!base.firstChild().isNull())
02203         base.removeChild(base.firstChild());
02204     QDomDocument doc = base.ownerDocument();
02205 
02206     QStrList nameList;
02207     QString mainWidgetStr;
02208 
02209     // collect widget names
02210     QStringList nList;
02211     QObjectListIt it(*childDock);
02212     KDockWidget *obj1;
02213     while ( (obj1=(KDockWidget*)it.current()) ) {
02214         if ( obj1->parent() == main )
02215             mainWidgetStr = QString::fromLatin1(obj1->name());
02216         nList.append(obj1->name());
02217         ++it;
02218     }
02219 
02220     for (QObjectListIt it(d->containerDocks);it.current();++it)
02221     {
02222         KDockContainer* dc = dynamic_cast<KDockContainer*>(((KDockWidget*)it.current())->widget);
02223         if (dc) {
02224                 dc->prepareSave(nList);
02225         }
02226     }
02227 
02228     QStringList::Iterator nListIt=nList.begin();
02229     while ( nListIt!=nList.end() ) {
02230         KDockWidget *obj = getDockWidgetFromName( *nListIt);
02231         if ((obj->isGroup && (!obj->d->isContainer)) && (nameList.find( obj->firstName.latin1() ) == -1
02232                              || nameList.find(obj->lastName.latin1()) == -1)) {
02233             // Skip until children are saved (why?)
02234             ++nListIt;
02235 //            nList.next();
02236 //falk?            if ( !nList.current() ) nList.first();
02237             continue;
02238         }
02239 
02240         QDomElement groupEl;
02241     if (obj->d->isContainer) {
02242             KDockContainer* x = dynamic_cast<KDockContainer*>(obj->widget);
02243             if (x) {
02244             groupEl=doc.createElement("dockContainer");
02245                 x->save(groupEl);
02246             }
02247         } else
02248         if (obj->isGroup) {
02250             groupEl = doc.createElement("splitGroup");
02251 
02252             groupEl.appendChild(createStringEntry(doc, "firstName", obj->firstName));
02253             groupEl.appendChild(createStringEntry(doc, "secondName", obj->lastName));
02254             groupEl.appendChild(createNumberEntry(doc, "orientation", (int)obj->splitterOrientation));
02255             groupEl.appendChild(createNumberEntry(doc, "separatorPos", ((KDockSplitter*)obj->widget)->separatorPosInPercent()));
02256         } else if (obj->isTabGroup) {
02258             groupEl = doc.createElement("tabGroup");
02259 
02260             QStrList list;
02261             for ( int i = 0; i < ((KDockTabGroup*)obj->widget)->count(); ++i )
02262                 list.append( ((KDockTabGroup*)obj->widget)->page( i )->name() );
02263             groupEl.appendChild(createListEntry(doc, "tabs", "tab", list));
02264             groupEl.appendChild(createNumberEntry(doc, "currentTab", ((KDockTabGroup*)obj->widget)->currentPageIndex()));
02265             if (!obj->parent()) {
02266                 groupEl.appendChild(createStringEntry(doc, "dockBackTo", obj->formerBrotherDockWidget ? obj->formerBrotherDockWidget->name() : ""));
02267                 groupEl.appendChild(createNumberEntry(doc, "dockBackToPos", obj->formerDockPos));
02268             }
02269         } else {
02271             groupEl = doc.createElement("dock");
02272             groupEl.appendChild(createStringEntry(doc, "tabCaption", obj->tabPageLabel()));
02273             groupEl.appendChild(createStringEntry(doc, "tabToolTip", obj->toolTipString()));
02274             if (!obj->parent()) {
02275                 groupEl.appendChild(createStringEntry(doc, "dockBackTo", obj->formerBrotherDockWidget ? obj->formerBrotherDockWidget->name() : ""));
02276                 groupEl.appendChild(createNumberEntry(doc, "dockBackToPos", obj->formerDockPos));
02277             }
02278         }
02279 
02280         groupEl.appendChild(createStringEntry(doc, "name", QString::fromLatin1(obj->name())));
02281         groupEl.appendChild(createBoolEntry(doc, "hasParent", obj->parent()));
02282         if ( !obj->parent() ) {
02283             groupEl.appendChild(createRectEntry(doc, "geometry", QRect(main->frameGeometry().topLeft(), main->size())));
02284             groupEl.appendChild(createBoolEntry(doc, "visible", obj->isVisible()));
02285         }
02286         if (obj->header && obj->header->inherits("KDockWidgetHeader")) {
02287             KDockWidgetHeader *h = static_cast<KDockWidgetHeader*>(obj->header);
02288             groupEl.appendChild(createBoolEntry(doc, "dragEnabled", h->dragEnabled()));
02289         }
02290 
02291         base.appendChild(groupEl);
02292         nameList.append(obj->name());
02293         nList.remove(nListIt);
02294         nListIt=nList.begin();
02295     }
02296 
02297     if (main->inherits("KDockMainWindow")) {
02298         KDockMainWindow *dmain = (KDockMainWindow*)main;
02299         QString centralWidgetStr = QString(dmain->centralWidget()? dmain->centralWidget()->name() : "");
02300         base.appendChild(createStringEntry(doc, "centralWidget", centralWidgetStr));
02301         QString mainDockWidgetStr = QString(dmain->getMainDockWidget()? dmain->getMainDockWidget()->name() : "");
02302         base.appendChild(createStringEntry(doc, "mainDockWidget", mainDockWidgetStr));
02303     } else {
02304         base.appendChild(createStringEntry(doc, "mainWidget", mainWidgetStr));
02305     }
02306 
02307     base.appendChild(createRectEntry(doc, "geometry", QRect(main->frameGeometry().topLeft(), main->size())));
02308 }
02309 
02310 
02311 void KDockManager::readConfig(QDomElement &base)
02312 {
02313     if (base.namedItem("group").isNull()
02314         && base.namedItem("tabgroup").isNull()
02315         && base.namedItem("dock").isNull()
02316     && base.namedItem("dockContainer").isNull()) {
02317         activate();
02318         return;
02319     }
02320 
02321     autoCreateDock = new QObjectList();
02322     autoCreateDock->setAutoDelete( true );
02323 
02324     bool isMainVisible = main->isVisible();
02325     main->hide();
02326 
02327     QObjectListIt it(*childDock);
02328     KDockWidget *obj1;
02329     while ( (obj1=(KDockWidget*)it.current()) ) {
02330         if ( !obj1->isGroup && !obj1->isTabGroup ) {
02331             if ( obj1->parent() )
02332                 obj1->undock();
02333             else
02334                 obj1->hide();
02335         }
02336         ++it;
02337     }
02338 
02339     // firstly, recreate all common dockwidgets
02340     for( QDomNode n = base.firstChild(); !n.isNull(); n = n.nextSibling() )
02341     {
02342         QDomElement childEl = n.toElement();
02343         if (childEl.tagName() != "dock") continue;
02344 
02345         // Read an ordinary dock widget
02346         KDockWidget *obj = getDockWidgetFromName(stringEntry(childEl, "name"));
02347         obj->setTabPageLabel(stringEntry(childEl, "tabCaption"));
02348         obj->setToolTipString(stringEntry(childEl, "tabToolTip"));
02349 
02350         if (!boolEntry(childEl, "hasParent")) {
02351             QRect r = rectEntry(childEl, "geometry");
02352             obj = getDockWidgetFromName(stringEntry(childEl, "name"));
02353             obj->applyToWidget(0);
02354             obj->setGeometry(r);
02355             if (boolEntry(childEl, "visible"))
02356                 obj->QWidget::show();
02357         }
02358 
02359         if (obj && obj->header && obj->header->inherits("KDockWidgetHeader")) {
02360             KDockWidgetHeader *h = static_cast<KDockWidgetHeader*>(obj->header);
02361             h->setDragEnabled(boolEntry(childEl, "dragEnabled"));
02362         }
02363     }
02364 
02365     // secondly, now iterate again and create the groups and tabwidgets, apply the dockwidgets to them
02366     for( QDomNode n = base.firstChild(); !n.isNull(); n = n.nextSibling() )
02367     {
02368         QDomElement childEl = n.toElement();
02369         if (childEl.isNull()) continue;
02370 
02371         KDockWidget *obj = 0;
02372 
02373     if (childEl.tagName() == "dockContainer") {
02374 
02375         KDockWidget *cont=getDockWidgetFromName(stringEntry(childEl, "name"));
02376         kdDebug(282)<<"dockContainer: "<<stringEntry(childEl,"name")<<endl;
02377         if (!(cont->d->isContainer)) {
02378             kdDebug(282)<<"restoration of dockContainer is only supported for already existing dock containers"<<endl;
02379         } else {
02380             KDockContainer *dc=dynamic_cast<KDockContainer*>(cont->getWidget());
02381             if (!dc) kdDebug(282)<<"Error while trying to handle dockcontainer configuration restoration"<<endl;
02382                 else {
02383                     dc->load(childEl);
02384                     removeFromAutoCreateList(cont);
02385                 }
02386 
02387         }
02388     }
02389     else
02390         if (childEl.tagName() == "splitGroup") {
02391             // Read a group
02392             QString name = stringEntry(childEl, "name");
02393             QString firstName = stringEntry(childEl, "firstName");
02394             QString secondName = stringEntry(childEl, "secondName");
02395             int orientation = numberEntry(childEl, "orientation");
02396             int separatorPos = numberEntry(childEl, "separatorPos");
02397 
02398             KDockWidget *first = getDockWidgetFromName(firstName);
02399             KDockWidget *second = getDockWidgetFromName(secondName);
02400             if (first && second) {
02401                 obj = first->manualDock(second,
02402                                         (orientation == (int)Vertical)? KDockWidget::DockLeft : KDockWidget::DockTop,
02403                                         separatorPos);
02404                 if (obj)
02405                     obj->setName(name.latin1());
02406             }
02407         } else if (childEl.tagName() == "tabGroup") {
02408             // Read a tab group
02409             QString name = stringEntry(childEl, "name");
02410             QStrList list = listEntry(childEl, "tabs", "tab");
02411 
02412             KDockWidget *d1 = getDockWidgetFromName( list.first() );
02413             list.next();
02414             KDockWidget *d2 = getDockWidgetFromName( list.current() );
02415 
02416             KDockWidget *obj = d2->manualDock( d1, KDockWidget::DockCenter );
02417             if (obj) {
02418                 KDockTabGroup *tab = (KDockTabGroup*)obj->widget;
02419                 list.next();
02420                 while (list.current() && obj) {
02421                     KDockWidget *tabDock = getDockWidgetFromName(list.current());
02422                     obj = tabDock->manualDock(d1, KDockWidget::DockCenter);
02423                     list.next();
02424                 }
02425                 if (obj) {
02426                     obj->setName(name.latin1());
02427                     tab->showPage(tab->page(numberEntry(childEl, "currentTab")));
02428                 }
02429             }
02430         } else {
02431             continue;
02432         }
02433 
02434         if (!boolEntry(childEl, "hasParent")) {
02435             QRect r = rectEntry(childEl, "geometry");
02436             obj = getDockWidgetFromName(stringEntry(childEl, "name"));
02437             obj->applyToWidget(0);
02438             obj->setGeometry(r);
02439             if (boolEntry(childEl, "visible"))
02440                 obj->QWidget::show();
02441         }
02442 
02443         if (obj && obj->header && obj->header->inherits("KDockWidgetHeader")) {
02444             KDockWidgetHeader *h = static_cast<KDockWidgetHeader*>(obj->header);
02445             h->setDragEnabled(boolEntry(childEl, "dragEnabled"));
02446         }
02447     }
02448 
02449     // thirdly, now that all ordinary dockwidgets are created,
02450     // iterate them again and link them with their corresponding dockwidget for the dockback action
02451     for( QDomNode n = base.firstChild(); !n.isNull(); n = n.nextSibling() )
02452     {
02453         QDomElement childEl = n.toElement();
02454 
02455         if (childEl.tagName() != "dock" && childEl.tagName() != "tabGroup")
02456             continue;
02457 
02458         KDockWidget *obj = 0;
02459 
02460         if (!boolEntry(childEl, "hasParent")) {
02461             // Read a common toplevel dock widget
02462             obj = getDockWidgetFromName(stringEntry(childEl, "name"));
02463             QString name = stringEntry(childEl, "dockBackTo");
02464             if (!name.isEmpty()) {
02465                 obj->setFormerBrotherDockWidget(getDockWidgetFromName(name));
02466             }
02467             obj->formerDockPos = KDockWidget::DockPosition(numberEntry(childEl, "dockBackToPos"));
02468             obj->updateHeader();
02469         }
02470     }
02471 
02472     if (main->inherits("KDockMainWindow")) {
02473         KDockMainWindow *dmain = (KDockMainWindow*)main;
02474 
02475         QString mv = stringEntry(base, "centralWidget");
02476         if (!mv.isEmpty() && getDockWidgetFromName(mv) ) {
02477             KDockWidget *mvd  = getDockWidgetFromName(mv);
02478             mvd->applyToWidget(dmain);
02479             mvd->show();
02480             dmain->setCentralWidget(mvd);
02481         }
02482         QString md = stringEntry(base, "mainDockWidget");
02483         if (!md.isEmpty() && getDockWidgetFromName(md)) {
02484             KDockWidget *mvd  = getDockWidgetFromName(md);
02485             dmain->setMainDockWidget(mvd);
02486         }
02487     } else {
02488         QString mv = stringEntry(base, "mainWidget");
02489         if (!mv.isEmpty() && getDockWidgetFromName(mv)) {
02490             KDockWidget *mvd  = getDockWidgetFromName(mv);
02491             mvd->applyToWidget(main);
02492             mvd->show();
02493         }
02494 
02495         // only resize + move non-mainwindows
02496         QRect mr = rectEntry(base, "geometry");
02497         main->move(mr.topLeft());
02498         main->resize(mr.size());
02499     }
02500 
02501     if (isMainVisible)
02502         main->show();
02503 
02504     if (d->m_readDockConfigMode == WrapExistingWidgetsOnly) {
02505         finishReadDockConfig(); // remove empty dockwidgets
02506     }
02507 }
02508 
02509 void KDockManager::removeFromAutoCreateList(KDockWidget* pDockWidget)
02510 {
02511     if (!autoCreateDock) return;
02512     autoCreateDock->setAutoDelete(false);
02513     autoCreateDock->removeRef(pDockWidget);
02514     autoCreateDock->setAutoDelete(true);
02515 }
02516 
02517 void KDockManager::finishReadDockConfig()
02518 {
02519     delete autoCreateDock;
02520     autoCreateDock = 0;
02521 }
02522 
02523 void KDockManager::setReadDockConfigMode(int mode)
02524 {
02525     d->m_readDockConfigMode = mode;
02526 }
02527 
02528 #ifndef NO_KDE2
02529 void KDockManager::writeConfig( KConfig* c, QString group )
02530 {
02531   //debug("BEGIN Write Config");
02532   if ( !c ) c = KGlobal::config();
02533   if ( group.isEmpty() ) group = "dock_setting_default";
02534 
02535   c->setGroup( group );
02536   c->writeEntry( "Version", DOCK_CONFIG_VERSION );
02537 
02538   QStringList nameList;
02539   QStringList findList;
02540   QObjectListIt it( *childDock );
02541   KDockWidget * obj;
02542 
02543   // collect KDockWidget's name
02544   QStringList nList;
02545   while ( (obj=(KDockWidget*)it.current()) ) {
02546     ++it;
02547     //debug("  +Add subdock %s", obj->name());
02548     nList.append( obj->name() );
02549     if ( obj->parent() == main )
02550       c->writeEntry( "Main:view", obj->name() );
02551   }
02552 
02553 //  kdDebug(282)<<QString("list size: %1").arg(nList.count())<<endl;
02554   for (QObjectListIt it(d->containerDocks);it.current();++it)
02555   {
02556     KDockContainer* dc = dynamic_cast<KDockContainer*>(((KDockWidget*)it.current())->widget);
02557     if (dc) {
02558         dc->prepareSave(nList);
02559     }
02560   }
02561 //  kdDebug(282)<<QString("new list size: %1").arg(nList.count())<<endl;
02562 
02563   QStringList::Iterator nListIt=nList.begin();
02564   while ( nListIt!=nList.end() ){
02565     //debug("  -Try to save %s", nList.current());
02566     obj = getDockWidgetFromName( *nListIt );
02567     QString cname = obj->name();
02568     if ( obj->header ){
02569       obj->header->saveConfig( c );
02570     }
02571     if (obj->d->isContainer) {
02572        KDockContainer* x = dynamic_cast<KDockContainer*>(obj->widget);
02573        if (x) {
02574           x->save(c,group);
02575        }
02576     }
02577 /*************************************************************************************************/
02578     if ( obj->isGroup ){
02579       if ( (findList.find( obj->firstName ) != findList.end()) && (findList.find( obj->lastName ) != findList.end() )){
02580 
02581         c->writeEntry( cname+":type", "GROUP");
02582         if ( !obj->parent() ){
02583           c->writeEntry( cname+":parent", "___null___");
02584           c->writeEntry( cname+":geometry", QRect(obj->frameGeometry().topLeft(), obj->size()) );
02585           c->writeEntry( cname+":visible", obj->isVisible());
02586         } else {
02587           c->writeEntry( cname+":parent", "yes");
02588         }
02589         c->writeEntry( cname+":first_name", obj->firstName );
02590         c->writeEntry( cname+":last_name", obj->lastName );
02591         c->writeEntry( cname+":orientation", (int)obj->splitterOrientation );
02592         c->writeEntry( cname+":sepPos", ((KDockSplitter*)obj->widget)->separatorPosInPercent() );
02593 
02594         nameList.append( obj->name() );
02595         findList.append( obj->name() );
02596         //debug("  Save %s", nList.current());
02597         nList.remove(nListIt);
02598         nListIt=nList.begin(); //nList.first();
02599       } else {
02600 /*************************************************************************************************/
02601         //debug("  Skip %s", nList.current());
02602         //if ( findList.find( obj->firstName ) == -1 )
02603         //  debug("  ? Not found %s", obj->firstName);
02604         //if ( findList.find( obj->lastName ) == -1 )
02605         //  debug("  ? Not found %s", obj->lastName);
02606         ++nListIt;
02607         // if ( !nList.current() ) nList.first();
02608     if (nListIt==nList.end()) nListIt=nList.begin();
02609       }
02610     } else {
02611 /*************************************************************************************************/
02612       if ( obj->isTabGroup){
02613         c->writeEntry( cname+":type", "TAB_GROUP");
02614         if ( !obj->parent() ){
02615           c->writeEntry( cname+":parent", "___null___");
02616           c->writeEntry( cname+":geometry", QRect(obj->frameGeometry().topLeft(), obj->size()) );
02617           c->writeEntry( cname+":visible", obj->isVisible());
02618           c->writeEntry( cname+":dockBackTo", obj->formerBrotherDockWidget ? obj->formerBrotherDockWidget->name() : "");
02619           c->writeEntry( cname+":dockBackToPos", obj->formerDockPos);
02620         } else {
02621           c->writeEntry( cname+":parent", "yes");
02622         }
02623         QStrList list;
02624         for ( int i = 0; i < ((KDockTabGroup*)obj->widget)->count(); ++i )
02625           list.append( ((KDockTabGroup*)obj->widget)->page( i )->name() );
02626         c->writeEntry( cname+":tabNames", list );
02627         c->writeEntry( cname+":curTab", ((KDockTabGroup*)obj->widget)->currentPageIndex() );
02628 
02629         nameList.append( obj->name() );
02630         findList.append( obj->name() ); // not really need !!!
02631         //debug("  Save %s", nList.current());
02632         nList.remove(nListIt);
02633         nListIt=nList.begin();
02634       } else {
02635 /*************************************************************************************************/
02636         c->writeEntry( cname+":tabCaption", obj->tabPageLabel());
02637         c->writeEntry( cname+":tabToolTip", obj->toolTipString());
02638         if ( !obj->parent() ){
02639           c->writeEntry( cname+":type", "NULL_DOCK");
02640           c->writeEntry( cname+":geometry", QRect(obj->frameGeometry().topLeft(), obj->size()) );
02641           c->writeEntry( cname+":visible", obj->isVisible());
02642           c->writeEntry( cname+":dockBackTo", obj->formerBrotherDockWidget ? obj->formerBrotherDockWidget->name() : "");
02643           c->writeEntry( cname+":dockBackToPos", obj->formerDockPos);
02644         } else {
02645           c->writeEntry( cname+":type", "DOCK");
02646         }
02647         nameList.append( cname.latin1() );
02648         //debug("  Save %s", nList.current());
02649         findList.append( obj->name() );
02650         nList.remove(nListIt);
02651         nListIt=nList.begin();
02652       }
02653     }
02654   }
02655   c->writeEntry( "NameList", nameList );
02656 
02657   c->writeEntry( "Main:Geometry", QRect(main->frameGeometry().topLeft(), main->size()) );
02658   c->writeEntry( "Main:visible", main->isVisible()); // curently nou use
02659 
02660   if ( main->inherits("KDockMainWindow") ){
02661     KDockMainWindow* dmain = (KDockMainWindow*)main;
02662     // for KDockMainWindow->setView() in readConfig()
02663     c->writeEntry( "Main:view", dmain->centralWidget() ? dmain->centralWidget()->name():"" );
02664     c->writeEntry( "Main:dock", dmain->getMainDockWidget()     ? dmain->getMainDockWidget()->name()    :"" );
02665   }
02666 
02667   c->sync();
02668   //debug("END Write Config");
02669 }
02670 #include <qmessagebox.h>
02671 void KDockManager::readConfig( KConfig* c, QString group )
02672 {
02673   if ( !c ) c = KGlobal::config();
02674   if ( group.isEmpty() ) group = "dock_setting_default";
02675 
02676   c->setGroup( group );
02677   QStrList nameList;
02678   c->readListEntry( "NameList", nameList );
02679   QString ver = c->readEntry( "Version", "0.0.1" );
02680   nameList.first();
02681   if ( !nameList.current() || ver != DOCK_CONFIG_VERSION ){
02682     activate();
02683     return;
02684   }
02685 
02686   autoCreateDock = new QObjectList();
02687   autoCreateDock->setAutoDelete( true );
02688 
02689   bool isMainVisible = main->isVisible();
02690  // if (isMainVisible)  // CCC
02691   //QMessageBox::information(0,"","hallo");
02692 //COMMENTED4TESTING  main->hide();
02693 
02694   QObjectListIt it( *childDock );
02695   KDockWidget * obj;
02696 
02697   while ( (obj=(KDockWidget*)it.current()) ){
02698     ++it;
02699     if ( !obj->isGroup && !obj->isTabGroup )
02700     {
02701       if ( obj->parent() ) obj->undock(); else obj->hide();
02702     }
02703   }
02704 
02705   // firstly, only the common dockwidgets,
02706   // they must be restored before e.g. tabgroups are restored
02707   nameList.first();
02708   while ( nameList.current() ){
02709     QString oname = nameList.current();
02710     c->setGroup( group );
02711     QString type = c->readEntry( oname + ":type" );
02712     obj = 0L;
02713 
02714     if ( type == "NULL_DOCK" || c->readEntry( oname + ":parent") == "___null___" ){
02715       QRect r = c->readRectEntry( oname + ":geometry" );
02716       obj = getDockWidgetFromName( oname );
02717       obj->applyToWidget( 0L );
02718       obj->setGeometry(r);
02719 
02720       c->setGroup( group );
02721       obj->setTabPageLabel(c->readEntry( oname + ":tabCaption" ));
02722       obj->setToolTipString(c->readEntry( oname + ":tabToolTip" ));
02723       if ( c->readBoolEntry( oname + ":visible" ) ){
02724         obj->QWidget::show();
02725       }
02726     }
02727 
02728     if ( type == "DOCK"  ){
02729       obj = getDockWidgetFromName( oname );
02730       obj->setTabPageLabel(c->readEntry( oname + ":tabCaption" ));
02731       obj->setToolTipString(c->readEntry( oname + ":tabToolTip" ));
02732     }
02733 
02734     if (obj && obj->d->isContainer) {
02735         dynamic_cast<KDockContainer*>(obj->widget)->load(c,group);
02736         removeFromAutoCreateList(obj);
02737     }
02738     if ( obj && obj->header){
02739       obj->header->loadConfig( c );
02740     }
02741     nameList.next();
02742   }
02743 
02744   // secondly, after the common dockwidgets, restore the groups and tabgroups
02745   nameList.first();
02746   while ( nameList.current() ){
02747     QString oname = nameList.current();
02748     c->setGroup( group );
02749     QString type = c->readEntry( oname + ":type" );
02750     obj = 0L;
02751 
02752     if ( type == "GROUP" ){
02753       KDockWidget* first = getDockWidgetFromName( c->readEntry( oname + ":first_name" ) );
02754       KDockWidget* last  = getDockWidgetFromName( c->readEntry( oname + ":last_name"  ) );
02755       int sepPos = c->readNumEntry( oname + ":sepPos" );
02756 
02757       Orientation p = (Orientation)c->readNumEntry( oname + ":orientation" );
02758       if ( first  && last ){
02759         obj = first->manualDock( last, ( p == Vertical ) ? KDockWidget::DockLeft : KDockWidget::DockTop, sepPos );
02760         if (obj){
02761           obj->setName( oname.latin1() );
02762         }
02763       }
02764     }
02765 
02766     if ( type == "TAB_GROUP" ){
02767       QStrList list;
02768       KDockWidget* tabDockGroup = 0L;
02769       c->readListEntry( oname+":tabNames", list );
02770       KDockWidget* d1 = getDockWidgetFromName( list.first() );
02771       list.next();
02772       KDockWidget* d2 = getDockWidgetFromName( list.current() );
02773       tabDockGroup = d2->manualDock( d1, KDockWidget::DockCenter );
02774       if ( tabDockGroup ){
02775         KDockTabGroup* tab = dynamic_cast<KDockTabGroup*>(tabDockGroup->widget);
02776         list.next();
02777         while ( list.current() && tabDockGroup ){
02778           KDockWidget* tabDock = getDockWidgetFromName( list.current() );
02779           tabDockGroup = tabDock->manualDock( d1, KDockWidget::DockCenter );
02780           list.next();
02781         }
02782         if ( tabDockGroup ){
02783           tabDockGroup->setName( oname.latin1() );
02784           c->setGroup( group );
02785           if (tab)
02786             tab->showPage( tab->page( c->readNumEntry( oname+":curTab" ) ) );
02787         }
02788       }
02789       obj = tabDockGroup;
02790     }
02791 
02792     if (obj && obj->d->isContainer)  dynamic_cast<KDockContainer*>(obj->widget)->load(c,group);
02793     if ( obj && obj->header){
02794       obj->header->loadConfig( c );
02795     }
02796     nameList.next();
02797   }
02798 
02799   // thirdly, now that all ordinary dockwidgets are created,
02800   // iterate them again and link the toplevel ones of them with their corresponding dockwidget for the dockback action
02801   nameList.first();
02802   while ( nameList.current() ){
02803     QString oname = nameList.current();
02804     c->setGroup( group );
02805     QString type = c->readEntry( oname + ":type" );
02806     obj = 0L;
02807 
02808     if ( type == "NULL_DOCK" || c->readEntry( oname + ":parent") == "___null___" ){
02809       obj = getDockWidgetFromName( oname );
02810       c->setGroup( group );
02811       QString name = c->readEntry( oname + ":dockBackTo" );
02812       if (!name.isEmpty()) {
02813           obj->setFormerBrotherDockWidget(getDockWidgetFromName( name ));
02814       }
02815       obj->formerDockPos = KDockWidget::DockPosition(c->readNumEntry( oname + ":dockBackToPos" ));
02816     }
02817 
02818     nameList.next();
02819   }
02820 
02821   if ( main->inherits("KDockMainWindow") ){
02822     KDockMainWindow* dmain = (KDockMainWindow*)main;
02823 
02824     c->setGroup( group );
02825     QString mv = c->readEntry( "Main:view" );
02826     if ( !mv.isEmpty() && getDockWidgetFromName( mv ) ){
02827       KDockWidget* mvd  = getDockWidgetFromName( mv );
02828       mvd->applyToWidget( dmain );
02829       mvd->show();
02830       dmain->setView( mvd );
02831     }
02832     c->setGroup( group );
02833     QString md = c->readEntry( "Main:dock" );
02834     if ( !md.isEmpty() && getDockWidgetFromName( md ) ){
02835       KDockWidget* mvd  = getDockWidgetFromName( md );
02836       dmain->setMainDockWidget( mvd );
02837     }
02838   } else {
02839     c->setGroup( group );
02840     QString mv = c->readEntry( "Main:view" );
02841     if ( !mv.isEmpty() && getDockWidgetFromName( mv ) ){
02842       KDockWidget* mvd  = getDockWidgetFromName( mv );
02843       mvd->applyToWidget( main );
02844       mvd->show();
02845     }
02846 
02847   }
02848 
02849   // delete all autocreate dock
02850   if (d->m_readDockConfigMode == WrapExistingWidgetsOnly) {
02851     finishReadDockConfig(); // remove empty dockwidgets
02852   }
02853 
02854   c->setGroup( group );
02855 
02856   QRect mr = c->readRectEntry("Main:Geometry");
02857 
02858   if (!main->inherits("KDockMainWindow"))
02859     main->move(mr.topLeft());
02860 
02861   main->resize(mr.size());
02862 
02863   if ( isMainVisible ) main->show();
02864 }
02865 #endif
02866 
02867 
02868 void KDockManager::dumpDockWidgets() {
02869   QObjectListIt it( *childDock );
02870   KDockWidget * obj;
02871   while ( (obj=(KDockWidget*)it.current()) ) {
02872     ++it;
02873     kdDebug(282)<<"KDockManager::dumpDockWidgets:"<<obj->name()<<endl;
02874   }
02875 
02876 }
02877 
02878 KDockWidget* KDockManager::getDockWidgetFromName( const QString& dockName )
02879 {
02880   QObjectListIt it( *childDock );
02881   KDockWidget * obj;
02882   while ( (obj=(KDockWidget*)it.current()) ) {
02883     ++it;
02884     if ( QString(obj->name()) == dockName ) return obj;
02885   }
02886 
02887   KDockWidget* autoCreate = 0L;
02888   if ( autoCreateDock ){
02889     kdDebug(282)<<"Autocreating dock: "<<dockName<<endl;
02890     autoCreate = new KDockWidget( this, dockName.latin1(), QPixmap("") );
02891     autoCreateDock->append( autoCreate );
02892   }
02893   return autoCreate;
02894 }
02895 void KDockManager::setSplitterOpaqueResize(bool b)
02896 {
02897   d->splitterOpaqueResize = b;
02898 }
02899 
02900 bool KDockManager::splitterOpaqueResize() const
02901 {
02902   return d->splitterOpaqueResize;
02903 }
02904 
02905 void KDockManager::setSplitterKeepSize(bool b)
02906 {
02907   d->splitterKeepSize = b;
02908 }
02909 
02910 bool KDockManager::splitterKeepSize() const
02911 {
02912   return d->splitterKeepSize;
02913 }
02914 
02915 void KDockManager::setSplitterHighResolution(bool b)
02916 {
02917   d->splitterHighResolution = b;
02918 }
02919 
02920 bool KDockManager::splitterHighResolution() const
02921 {
02922   return d->splitterHighResolution;
02923 }
02924 
02925 void KDockManager::slotMenuPopup()
02926 {
02927   menu->clear();
02928   menuData->clear();
02929 
02930   QObjectListIt it( *childDock );
02931   KDockWidget * obj;
02932   int numerator = 0;
02933   while ( (obj=(KDockWidget*)it.current()) ) {
02934     ++it;
02935     if ( obj->mayBeHide() )
02936     {
02937       menu->insertItem( obj->icon() ? *(obj->icon()) : QPixmap(), i18n("Hide %1").arg(obj->caption()), numerator++ );
02938       menuData->append( new MenuDockData( obj, true ) );
02939     }
02940 
02941     if ( obj->mayBeShow() )
02942     {
02943       menu->insertItem( obj->icon() ? *(obj->icon()) : QPixmap(), i18n("Show %1").arg(obj->caption()), numerator++ );
02944       menuData->append( new MenuDockData( obj, false ) );
02945     }
02946   }
02947 }
02948 
02949 void KDockManager::slotMenuActivated( int id )
02950 {
02951   MenuDockData* data = menuData->at( id );
02952   data->dock->changeHideShowState();
02953 }
02954 
02955 KDockWidget* KDockManager::findWidgetParentDock( QWidget* w ) const
02956 {
02957   QObjectListIt it( *childDock );
02958   KDockWidget * dock;
02959   KDockWidget * found = 0L;
02960 
02961   while ( (dock=(KDockWidget*)it.current()) ) {
02962     ++it;
02963     if ( dock->widget == w ){ found  = dock; break; }
02964   }
02965   return found;
02966 }
02967 
02968 void KDockManager::drawDragRectangle()
02969 {
02970 #ifdef BORDERLESS_WINDOWS
02971     return
02972 #endif
02973   if (d->oldDragRect == d->dragRect)
02974     return;
02975 
02976   int i;
02977   QRect oldAndNewDragRect[2];
02978   oldAndNewDragRect[0] = d->oldDragRect;
02979   oldAndNewDragRect[1] = d->dragRect;
02980 
02981   // 2 calls, one for the old and one for the new drag rectangle
02982   for (i = 0; i <= 1; i++) {
02983     if (oldAndNewDragRect[i].isEmpty())
02984       continue;
02985 
02986     KDockWidget* pDockWdgAtRect = (KDockWidget*) QApplication::widgetAt( oldAndNewDragRect[i].topLeft(), true );
02987     if (!pDockWdgAtRect)
02988       continue;
02989 
02990     bool isOverMainWdg = false;
02991     bool unclipped;
02992     KDockMainWindow* pMain = 0L;
02993     KDockWidget* pTLDockWdg = 0L;
02994     QWidget* topWdg;
02995     if (pDockWdgAtRect->topLevelWidget() == main) {
02996       isOverMainWdg = true;
02997       topWdg = pMain = (KDockMainWindow*) main;
02998       unclipped = pMain->testWFlags( WPaintUnclipped );
02999       pMain->setWFlags( WPaintUnclipped );
03000     }
03001     else {
03002       topWdg = pTLDockWdg = (KDockWidget*) pDockWdgAtRect->topLevelWidget();
03003       unclipped = pTLDockWdg->testWFlags( WPaintUnclipped );
03004       pTLDockWdg->setWFlags( WPaintUnclipped );
03005     }
03006 
03007     // draw the rectangle unclipped over the main dock window
03008     QPainter p;
03009     p.begin( topWdg );
03010       if ( !unclipped ) {
03011         if (isOverMainWdg)
03012           pMain->clearWFlags(WPaintUnclipped);
03013         else
03014           pTLDockWdg->clearWFlags(WPaintUnclipped);
03015       }
03016       // draw the rectangle
03017       p.setRasterOp(Qt::NotXorROP);
03018       QRect r = oldAndNewDragRect[i];
03019       r.moveTopLeft( r.topLeft() - topWdg->mapToGlobal(QPoint(0,0)) );
03020       p.drawRect(r.x(), r.y(), r.width(), r.height());
03021     p.end();
03022   }
03023 
03024   // memorize the current rectangle for later removing
03025   d->oldDragRect = d->dragRect;
03026 }
03027 
03028 void KDockManager::setSpecialLeftDockContainer(KDockWidget* container) {
03029     d->leftContainer=container;
03030 }
03031 
03032 void KDockManager::setSpecialTopDockContainer(KDockWidget* container) {
03033     d->topContainer=container;
03034 }
03035 
03036 void KDockManager::setSpecialRightDockContainer(KDockWidget* container) {
03037     d->rightContainer=container;
03038 
03039 }
03040 
03041 void KDockManager::setSpecialBottomDockContainer(KDockWidget* container) {
03042     d->bottomContainer=container;
03043 }
03044 
03045 
03046 KDockArea::KDockArea( QWidget* parent, const char *name)
03047 :QWidget( parent, name)
03048 {
03049   QString new_name = QString(name) + QString("_DockManager");
03050   dockManager = new KDockManager( this, new_name.latin1() );
03051   mainDockWidget = 0L;
03052 }
03053 
03054 KDockArea::~KDockArea()
03055 {
03056     delete dockManager;
03057 }
03058 
03059 KDockWidget* KDockArea::createDockWidget( const QString& name, const QPixmap &pixmap, QWidget* parent, const QString& strCaption, const QString& strTabPageLabel)
03060 {
03061   return new KDockWidget( dockManager, name.latin1(), pixmap, parent, strCaption, strTabPageLabel );
03062 }
03063 
03064 void KDockArea::makeDockVisible( KDockWidget* dock )
03065 {
03066   if ( dock )
03067     dock->makeDockVisible();
03068 }
03069 
03070 void KDockArea::makeDockInvisible( KDockWidget* dock )
03071 {
03072   if ( dock )
03073     dock->undock();
03074 }
03075 
03076 void KDockArea::makeWidgetDockVisible( QWidget* widget )
03077 {
03078   makeDockVisible( dockManager->findWidgetParentDock(widget) );
03079 }
03080 
03081 void KDockArea::writeDockConfig(QDomElement &base)
03082 {
03083   dockManager->writeConfig(base);
03084 }
03085 
03086 void KDockArea::readDockConfig(QDomElement &base)
03087 {
03088   dockManager->readConfig(base);
03089 }
03090 
03091 void KDockArea::slotDockWidgetUndocked()
03092 {
03093   QObject* pSender = (QObject*) sender();
03094   if (!pSender->inherits("KDockWidget")) return;
03095   KDockWidget* pDW = (KDockWidget*) pSender;
03096   emit dockWidgetHasUndocked( pDW);
03097 }
03098 
03099 void KDockArea::resizeEvent(QResizeEvent *rsize)
03100 {
03101   QWidget::resizeEvent(rsize);
03102   if (children()){
03103 #ifndef NO_KDE2
03104 //    kdDebug(282)<<"KDockArea::resize"<<endl;
03105 #endif
03106     QObjectList *list=queryList("QWidget",0,false);
03107 
03108     QObjectListIt it( *list ); // iterate over the buttons
03109     QObject *obj;
03110 
03111     while ( (obj = it.current()) != 0 ) {
03112         // for each found object...
03113         ((QWidget*)obj)->setGeometry(QRect(QPoint(0,0),size()));
03114     break;
03115     }
03116     delete list;
03117 #if 0
03118     KDockSplitter *split;
03119 //    for (unsigned int i=0;i<children()->count();i++)
03120     {
03121 //      QPtrList<QObject> list(children());
03122 //       QObject *obj=((QPtrList<QObject*>)children())->at(i);
03123     QObject *obj=children()->getFirst();
03124        if (split = dynamic_cast<KDockSplitter*>(obj))
03125        {
03126           split->setGeometry( QRect(QPoint(0,0), size() ));
03127 //    break;
03128        }
03129     }
03130 #endif
03131    }
03132 }
03133 
03134 #ifndef NO_KDE2
03135 void KDockArea::writeDockConfig( KConfig* c, QString group )
03136 {
03137   dockManager->writeConfig( c, group );
03138 }
03139 
03140 void KDockArea::readDockConfig( KConfig* c, QString group )
03141 {
03142   dockManager->readConfig( c, group );
03143 }
03144 
03145 void KDockArea::setMainDockWidget( KDockWidget* mdw )
03146 {
03147   if ( mainDockWidget == mdw ) return;
03148   mainDockWidget = mdw;
03149   mdw->applyToWidget(this);
03150 }
03151 #endif
03152 
03153 
03154 
03155 // KDOCKCONTAINER - AN ABSTRACTION OF THE KDOCKTABWIDGET
03156 KDockContainer::KDockContainer(){m_overlapMode=false; m_childrenListBegin=0; m_childrenListEnd=0;}
03157 KDockContainer::~KDockContainer(){
03158 
03159     if (m_childrenListBegin)
03160     {
03161         struct ListItem *tmp=m_childrenListBegin;
03162         while (tmp)
03163         {
03164             struct ListItem *tmp2=tmp->next;
03165             free(tmp->data);
03166             delete tmp;
03167             tmp=tmp2;
03168         }
03169         m_childrenListBegin=0;
03170         m_childrenListEnd=0;
03171     }
03172 
03173 }
03174 
03175 void KDockContainer::activateOverlapMode(int nonOverlapSize) {
03176     m_nonOverlapSize=nonOverlapSize;
03177     m_overlapMode=true;
03178     if (parentDockWidget() && parentDockWidget()->parent()) {
03179         kdDebug(282)<<"KDockContainer::activateOverlapMode: recalculating sizes"<<endl;
03180         KDockSplitter *sp= static_cast<KDockSplitter*>(parentDockWidget()->
03181             parent()->qt_cast("KDockSplitter"));
03182         if (sp)
03183             sp->resizeEvent(0);
03184     }
03185 }
03186 
03187 void KDockContainer::deactivateOverlapMode() {
03188     if (!m_overlapMode) return;
03189     m_overlapMode=false;
03190     if (parentDockWidget() && parentDockWidget()->parent()) {
03191         kdDebug(282)<<"KDockContainer::deactivateOverlapMode: recalculating sizes"<<endl;
03192         KDockSplitter *sp= static_cast<KDockSplitter*>(parentDockWidget()->
03193             parent()->qt_cast("KDockSplitter"));
03194         if (sp)
03195             sp->resizeEvent(0);
03196         }
03197 }
03198 
03199 bool KDockContainer::isOverlapMode() {
03200     return m_overlapMode;
03201 }
03202 
03203 
03204 bool KDockContainer::dockDragEnter(KDockWidget*, QMouseEvent *) { return false;}
03205 bool KDockContainer::dockDragMove(KDockWidget*, QMouseEvent *) { return false;}
03206 bool KDockContainer::dockDragLeave(KDockWidget*, QMouseEvent *) { return false;}
03207 
03208 
03209 KDockWidget *KDockContainer::parentDockWidget(){return 0;}
03210 
03211 QStringList KDockContainer::containedWidgets() const {
03212     QStringList tmp;
03213     for (struct ListItem *it=m_childrenListBegin;it;it=it->next) {
03214         tmp<<QString(it->data);
03215     }
03216 
03217     return tmp;
03218 }
03219 
03220 void KDockContainer::showWidget(KDockWidget *) {
03221 }
03222 
03223 void KDockContainer::insertWidget (KDockWidget *dw, QPixmap, const QString &, int &)
03224     {
03225         struct ListItem *it=new struct ListItem;
03226         it->data=strdup(dw->name());
03227         it->next=0;
03228 
03229         if (m_childrenListEnd)
03230         {
03231             m_childrenListEnd->next=it;
03232             it->prev=m_childrenListEnd;
03233             m_childrenListEnd=it;
03234         }
03235         else
03236         {
03237             it->prev=0;
03238             m_childrenListEnd=it;
03239             m_childrenListBegin=it;
03240         }
03241     }
03242 void KDockContainer::removeWidget (KDockWidget *dw){
03243     for (struct ListItem *tmp=m_childrenListBegin;tmp;tmp=tmp->next)
03244     {
03245         if (!strcmp(tmp->data,dw->name()))
03246         {
03247             free(tmp->data);
03248             if (tmp->next) tmp->next->prev=tmp->prev;
03249             if (tmp->prev) tmp->prev->next=tmp->next;
03250             if (tmp==m_childrenListBegin) m_childrenListBegin=tmp->next;
03251             if (tmp==m_childrenListEnd) m_childrenListEnd=tmp->prev;
03252             delete tmp;
03253             break;
03254         }
03255     }
03256 }
03257 
03258 //m_children.remove(dw->name());}
03259 void KDockContainer::undockWidget (KDockWidget *){;}
03260 void KDockContainer::setToolTip(KDockWidget *, QString &){;}
03261 void KDockContainer::setPixmap(KDockWidget*,const QPixmap&){;}
03262 void KDockContainer::load (KConfig*, const QString&){;}
03263 void KDockContainer::save (KConfig*, const QString&){;}
03264 void KDockContainer::load (QDomElement&){;}
03265 void KDockContainer::save (QDomElement&){;}
03266 void KDockContainer::prepareSave(QStringList &names)
03267 {
03268 
03269     for (struct ListItem *tmp=m_childrenListBegin;tmp; tmp=tmp->next)
03270         names.remove(tmp->data);
03271 //  for (uint i=0;i<m_children.count();i++)
03272 //  {
03273 //      names.remove(m_children.at(i));
03274 //  }
03275 }
03276 
03277 
03278 QWidget *KDockTabGroup::transientTo() {
03279     QWidget *tT=0;
03280     for (int i=0;i<count();i++) {
03281         KDockWidget *dw=static_cast<KDockWidget*>(page(i)->qt_cast("KDockWidget"));
03282         QWidget *tmp;
03283         if ((tmp=dw->transientTo())) {
03284             if (!tT) tT=tmp;
03285             else {
03286                 if (tT!=tmp) {
03287                     kdDebug(282)<<"KDockTabGroup::transientTo: widget mismatch"<<endl;
03288                     return 0;
03289                 }
03290             }
03291         }
03292     }
03293 
03294     kdDebug(282)<<"KDockTabGroup::transientTo: "<<(tT?"YES":"NO")<<endl;
03295 
03296     return tT;
03297 }
03298 
03299 void KDockWidgetAbstractHeader::virtual_hook( int, void* )
03300 { /*BASE::virtual_hook( id, data );*/ }
03301 
03302 void KDockWidgetAbstractHeaderDrag::virtual_hook( int, void* )
03303 { /*BASE::virtual_hook( id, data );*/ }
03304 
03305 void KDockWidgetHeaderDrag::virtual_hook( int id, void* data )
03306 { KDockWidgetAbstractHeaderDrag::virtual_hook( id, data ); }
03307 
03308 void KDockWidgetHeader::virtual_hook( int id, void* data )
03309 { KDockWidgetAbstractHeader::virtual_hook( id, data ); }
03310 
03311 void KDockTabGroup::virtual_hook( int, void* )
03312 { /*BASE::virtual_hook( id, data );*/ }
03313 
03314 void KDockWidget::virtual_hook( int, void* )
03315 { /*BASE::virtual_hook( id, data );*/ }
03316 
03317 void KDockManager::virtual_hook( int, void* )
03318 { /*BASE::virtual_hook( id, data );*/ }
03319 
03320 void KDockMainWindow::virtual_hook( int id, void* data )
03321 { KMainWindow::virtual_hook( id, data ); }
03322 
03323 void KDockArea::virtual_hook( int, void* )
03324 { /*KMainWindow::virtual_hook( id, data );*/ }
03325 
03326 
03327 #ifndef NO_INCLUDE_MOCFILES // for Qt-only projects, because tmake doesn't take this name
03328 #include "kdockwidget.moc"
03329 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys