kdeui Library API Documentation

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