dockbar.cpp

Go to the documentation of this file.
00001 // $Id: dockbar.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 #include "camtypes.h"
00100 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00101 //#include "dockbar.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00102 //#include "childbar.h"
00103 #include "camframe.h"
00104 //#include "camafx.h"
00105 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00106 #include "basebar.h"
00107 
00108 #define IS_CHICAGO ((LOBYTE(LOWORD(GetVersion()))) > 3)
00109 
00110 #define MIN_GALLERY_SLOT_WIDTH 100
00111 
00112 BOOL OILFixedDockingBar::allowTidyBars = TRUE;
00113 
00114 #if 0
00115 
00117 //                                   OILDockingBar Base Class                                                          //
00119 
00120 IMPLEMENT_DYNAMIC(OILDockingBar ,CControlBar)
00121 
00122 #ifdef _DEBUG
00123     #undef THIS_FILE
00124     static char BASED_CODE THIS_FILE[] = __FILE__;
00125 #endif
00126 
00127 
00128 
00129 // A pointer to the last dock which has changed size
00130 // used to reduce the number of recalc layouts
00131 OILDockingBar * OILDockingBar::ChangedDock=NULL;
00132 
00133 // Flag used as above
00134 BOOL OILDockingBar::DoRecalc = FALSE;
00135  
00137 //      OILDockingBar Message Map
00139 
00140 BEGIN_MESSAGE_MAP( OILDockingBar,CControlBar)
00141     //{{AFX_MSG_MAP( OILDockingBar )
00142     //}}AFX_MSG_MAP
00143 END_MESSAGE_MAP( )
00144 
00145 
00147 //      OILDockingBar Creation Destruction and Initialisation
00149 
00150 /********************************************************************************************
00151 
00152 >   OILDockingBar::OILDockingBar()
00153 
00154     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00155     Created:    5/3/94
00156     Inputs:     -
00157     Outputs:    -
00158     Returns:    -
00159     Purpose:    Creates an OILDockingBar object.
00160     Errors:     -
00161     SeeAlso:    
00162 
00163 ********************************************************************************************/
00164                     
00165 OILDockingBar::OILDockingBar()
00166 { 
00167     ControlSize=SMALL_CONTROLS;
00168     HasBigControls = FALSE;
00169 }
00170  
00171 /********************************************************************************************
00172 
00173 >   OILDockingBar::~OILDockingBar()
00174 
00175     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00176     Created:    5/3/94
00177     Inputs:     -
00178     Outputs:    -
00179     Returns:    -
00180     Purpose:    Destroys an OILDockingBar object and deletes all BarList items
00181     Errors:     -
00182     SeeAlso:    
00183 
00184 ********************************************************************************************/
00185 
00186 OILDockingBar::~OILDockingBar()
00187 {
00188     ChildBars.DeleteAll();
00189 }
00190  
00191 
00192 /******************************************************************************************
00193 >   void OILDockingBar::OnUpdateCmdUI()
00194 
00195     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00196     Created:    5/3/94
00197     Inputs:     -
00198     Outputs:    -
00199     Returns:    -
00200     Purpose:    - 
00201     Errors:     -
00202     SeeAlso:    
00203 
00204 ********************************************************************************************/
00205 
00206 void OILDockingBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
00207 {
00208 
00209 }
00210 
00211 
00212 /********************************************************************************************
00213 
00214 >   BOOL OILDockingBar::RemoveBar(OILChildBar * ThisBar)
00215 
00216     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00217     Created:    15/3/94
00218     Inputs:     -
00219     Outputs:    -
00220     Returns:    Succed or Fail
00221     Purpose:    Remove OILChildBar from List and delete ListItem if successful                  
00222     Errors:     -
00223     SeeAlso:    
00224 
00225 ********************************************************************************************/
00226 
00227 BOOL OILDockingBar::RemoveBar(OILChildBar* ThisBar)
00228 {
00229     ERROR2IF(ThisBar ==NULL,FALSE,"Trying to remove a NULL Child Bar");
00230     // Remove a child Bar from the list
00231     if (ChildBars.RemoveItem((ListItem*)ThisBar)!=NULL)
00232     {
00233 
00234         delete ThisBar;     // Delete ChildBar object
00235         return TRUE;
00236 
00237     }
00238     else                    // Trying to delete an unknown bar
00239     {
00240         ERROR2IF(TRUE,FALSE,"Failed to Remove Child Bar from list");
00241     }
00242 }
00243 
00244 /********************************************************************************************
00245 
00246 >   BOOL OILDockingBar::SetNewHwnd(HWND OldHwnd,HWND NewHwnd)
00247 
00248     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00249     Created:    15/3/94
00250     Inputs:     -
00251     Outputs:    -
00252     Returns:    TRUE if success FALSE otherwise
00253     Purpose:    change the hwnd of a bar list item
00254     Errors:     -
00255     SeeAlso:    
00256 
00257 ********************************************************************************************/
00258 
00259 BOOL OILDockingBar::SetNewHwnd(HWND OldHwnd,HWND NewHwnd)
00260 {
00261     OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead(); 
00262     while (ThisChild != NULL)
00263     {
00264 
00265         if (ThisChild->GetHwnd()==OldHwnd)  // found the bar
00266         {
00267             ThisChild->SetHwnd(NewHwnd);
00268             return TRUE;
00269         }
00270         ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);    
00271 
00272     }// end while
00273     ENSURE(ThisChild!=NULL,"Couldn't find HWND in BarList");
00274     return FALSE;
00275 }
00276 
00277 
00278 /********************************************************************************************
00279 
00280 >   OILChildBar * OILDockingBar::IsBarInList(HWND)
00281 
00282     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00283     Created:    15/3/94
00284     Inputs:     -
00285     Outputs:    -
00286     Returns:    Found Child or NULL
00287     Purpose:    determine whether a childbar is in this docks list
00288     Errors:     -
00289     SeeAlso:    
00290 
00291 ********************************************************************************************/
00292 
00293 OILChildBar * OILDockingBar::IsBarInList(HWND hwnd)
00294 {
00295     OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead(); 
00296     while (ThisChild != NULL)
00297     {
00298 
00299         if (ThisChild->GetHwnd()==hwnd) // found the bar
00300             return ThisChild;
00301 
00302         ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);    
00303 
00304     }// end while
00305 
00306     return NULL;
00307 }
00308 
00309   /********************************************************************************************
00310 
00311 >   OILChildBar * OILDockingBar::IsBarInList(StringBase * Name )
00312 
00313     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00314     Created:    15/3/94
00315     Inputs:     -
00316     Outputs:    -
00317     Returns:    Found Child or NULL
00318     Purpose:    determine whether a childbar is in this docks list
00319     Errors:     -
00320     SeeAlso:    
00321 
00322 ********************************************************************************************/
00323 
00324 OILChildBar * OILDockingBar::IsBarInList(StringBase *Name)
00325 {
00326     OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead(); 
00327     while (ThisChild != NULL)
00328     {
00329         char buff[64];
00330         ::GetWindowText(ThisChild->GetHwnd(),buff,63); 
00331         if (String_32(buff)== *Name)    // found the bar
00332             return ThisChild;
00333 
00334         ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);    
00335 
00336     }// end while
00337 
00338     return NULL;
00339 }
00340 /********************************************************************************************
00341 
00342 >   HWND OILDockingBar::IsScreenPointInBar(CPoint pnt)
00343 
00344     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00345     Created:    15/3/94
00346     Inputs:     -
00347     Outputs:    -
00348     Returns:    Found HWND or NULL
00349     Purpose:    determine whether a screen point is in a childbar of this dock
00350     Errors:     -
00351     SeeAlso:    
00352 
00353 ********************************************************************************************/
00354 
00355 HWND OILDockingBar::IsScreenPointInBar(CPoint pnt) 
00356 {
00357 
00358     OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead(); 
00359     HWND hwnd;
00360     while (ThisChild != NULL)
00361     {
00362         if (hwnd = ThisChild->GetHwnd())    // found the bar
00363         {
00364             CRect sRect;
00365             ::GetWindowRect(hwnd,&sRect);
00366             if(sRect.PtInRect(pnt))
00367             {
00368                 return hwnd;
00369             }
00370         }
00371         ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);    
00372     }// end while
00373 
00374     return NULL;
00375 }
00376 /********************************************************************************************
00377 
00378 >   KernelBarPos * OILDockingBar::GetBarPos(HWND)
00379 
00380     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00381     Created:    15/3/94
00382     Inputs:     -
00383     Outputs:    -
00384     Returns:    Found Position 
00385     Purpose:    To return a Pointer to the KernelBarPos of a Child dialogbar
00386     Errors:     -
00387     SeeAlso:    
00388 
00389 ********************************************************************************************/
00390 
00391 KernelBarPos * OILDockingBar::GetBarPos(HWND hwnd)
00392 {
00393     OILChildBar * ThisChild;
00394     if ((ThisChild=IsBarInList(hwnd))!=NULL)
00395     
00396         return ThisChild->GetBarPos();
00397     else
00398     
00399         return NULL;    
00400 }
00401 
00402 
00403  /********************************************************************************************
00404 
00405 >   CRect OILDockingBar::GetBarRect(StringBase * Name)
00406 
00407     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00408     Created:    15/3/94
00409     Inputs:     -
00410     Outputs:    -
00411     Returns:    Found Position 
00412     Purpose:    To return the rectangle of the specified bar
00413     Errors:     -
00414     SeeAlso:    
00415 
00416 ********************************************************************************************/
00417 
00418 CRect OILDockingBar::GetBarRect(StringBase * Name)
00419 {
00420     OILChildBar * ThisChild;
00421     if ((ThisChild=IsBarInList(Name))!=NULL)
00422         return ThisChild->GetRectFromBar();
00423     else
00424         return CRect(0, 0, 0, 0);
00425 }
00426 
00427 
00428 
00429 /****************************************************************************
00430 
00431 >   CRect OILDockingBar::GetBarRect(HWND hwnd)
00432 
00433     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
00434     Created:    01/12/2004
00435 
00436     Inputs:     hwnd        - 
00437     Returns:    
00438     Purpose:    To return the rectangle of the specified bar
00439 
00440 ****************************************************************************/
00441 
00442 CRect OILDockingBar::GetBarRect(HWND hwnd)
00443 {
00444     OILChildBar * ThisChild;
00445     if ((ThisChild=IsBarInList(hwnd))!=NULL)
00446         return ThisChild->GetRectFromBar();
00447     else
00448         return CRect(0, 0, 0, 0);
00449 }
00450 
00451 
00452 /********************************************************************************************
00453 
00454 >   KernelBarPos * OILDockingBar::GetBarPos(StringBase * Name)
00455 
00456     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00457     Created:    15/3/94
00458     Inputs:     -
00459     Outputs:    -
00460     Returns:    Found Position 
00461     Purpose:    To return a Pointer to the KernelBarPos of a Child dialogbar
00462     Errors:     -
00463     SeeAlso:    
00464 
00465 ********************************************************************************************/
00466 
00467 KernelBarPos * OILDockingBar::GetBarPos(StringBase * Name)
00468 {
00469     OILChildBar * ThisChild;
00470     if ((ThisChild=IsBarInList(Name))!=NULL)
00471     
00472         return ThisChild->GetBarPos();
00473     else
00474     
00475         return NULL;    
00476 }
00477 
00478 /********************************************************************************************
00479 
00480 >   void OILDockingBar::SetBigControlState(BOOL Big)
00481 
00482     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00483     Created:    5/3/94
00484     Inputs:     -
00485     Outputs:    -
00486     Returns:    -
00487     Purpose:    Sets Big Control state
00488     Errors:     -
00489     SeeAlso:    
00490                                                       
00491 ********************************************************************************************/
00492 
00493 void OILDockingBar::SetBigControlState(BOOL Big )
00494 {
00495     HasBigControls = Big;
00496     if (Big)
00497         ControlSize=LARGE_CONTROLS;
00498     else
00499         ControlSize=SMALL_CONTROLS;
00500 
00501     // tell all child windows that control sizes have changed
00502     OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead(); 
00503     while (ThisChild != NULL)
00504     {
00505         ThisChild->Resize(ControlSize);
00506         ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);    
00507     }// end while
00508     
00509 }
00510 
00511 /********************************************************************************************
00512 
00513 >   BOOL OILDockingBar::IsBigControls()
00514 
00515     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00516     Created:    5/4/94
00517     Inputs:     -
00518     Outputs:    -
00519     Returns:    True if BigControls
00520     Purpose:    Determines whether DockingBar contains large controls
00521     Errors:     -
00522     SeeAlso:    
00523 
00524 ********************************************************************************************/
00525 
00526 BOOL OILDockingBar::IsBigControls()
00527 {
00528 
00529     return  HasBigControls;
00530 }
00531 
00532 
00533 
00535 //              OILFixedDockingBar
00537 
00538 
00539 IMPLEMENT_DYNAMIC(OILFixedDockingBar ,OILDockingBar)
00540 
00541 
00542 
00543 
00544 //      OILFixedDockingBar Message Map
00546 
00547 BEGIN_MESSAGE_MAP( OILFixedDockingBar, OILDockingBar )
00548     //{{AFX_MSG_MAP( OILFixedDockingBar )
00549     ON_MESSAGE(WM_SIZEPARENT, OnSizeParent) 
00550     //}}AFX_MSG_MAP
00551 END_MESSAGE_MAP( )
00552 
00553 /********************************************************************************************
00554 
00555 >   BOOL OILFixedDockingBar::Create(CWnd* pParentWnd,DockBarType ReqType, UINT32 id)
00556 
00557     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00558     Created:    5/3/94
00559     Inputs:     -
00560     Outputs:    -
00561     Returns:    -
00562     Purpose:    Creates the OILDockingBar window.
00563     Errors:     -
00564     SeeAlso:    
00565 
00566 ********************************************************************************************/
00567 
00568 BOOL OILFixedDockingBar::Create(CWnd* pParentWnd,DockBarType ReqType, UINT32 id)
00569 {
00570 //  BackBrush.CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
00571     BOOL CreatedWindow;
00572     ENSURE(pParentWnd,"DockingBar must have a Parent");
00573 
00574     ENSURE((ReqType == DOCKBAR_LEFT) ||
00575            (ReqType == DOCKBAR_RIGHT) ||
00576            (ReqType == DOCKBAR_TOP) ||
00577            (ReqType == DOCKBAR_BOTTOM),
00578            "OILFIxedDockingBar constructor: Invalid DockingBar type");
00579 
00580     DockType=ReqType;   // Type of this instance
00581     Parent=pParentWnd;  // Parent of this bar
00582     CRect rect;         // Rectangle for Create
00583     rect.SetRectEmpty();
00584 
00585     #if _MSC_VER < 1200
00586         #ifndef WIN32
00587             DWORD
00588         #endif
00589             m_dwStyle = WS_CHILD|WS_VISIBLE |WS_CLIPCHILDREN;
00590     #else
00591         // VC6 doesn't like any style flags other than CBRS_ flags set 
00592         // for CControlBar-derived windows
00593         m_dwStyle = 0;
00594     #endif // _MSC_VER
00595 
00596     // create the HWND
00597     CreatedWindow = CWnd::Create(NULL,
00598                         0,
00599                         m_dwStyle,
00600                         rect,Parent,
00601                         id, NULL);
00602 
00603 
00604     #if _MSC_VER >= 1200
00605     // Must make the control bar visible in VC6 builds
00606     ShowWindow(SW_SHOW);
00607     #endif // _MSC_VER
00608 
00609     return CreatedWindow;
00610 }
00611 
00612 
00613 
00614 /********************************************************************************************
00615 
00616 >   OILFixedDockingBar::OILFixedDockingBar()
00617 
00618     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00619     Created:    5/3/94
00620     Inputs:     -
00621     Outputs:    -
00622     Returns:    -
00623     Purpose:    Creates an OILDockingBar object.
00624     Errors:     -
00625     SeeAlso:    
00626 
00627 ********************************************************************************************/
00628                     
00629 OILFixedDockingBar::OILFixedDockingBar()
00630 { 
00631     NoOfSlots = 0; 
00632     ControlSize = SMALL_CONTROLS;
00633     HasBigControls = FALSE;
00634     DockSize.cy = DockSize.cx = 0;
00635     Position.x = Position.y = -1;
00636     allowTidyBars = TRUE;
00637     for (INT32 i = 0; i < MAX_SLOTS; i++)
00638         SlotSize[i] = SMALL_CONTROLS;
00639 }
00640 
00641 /********************************************************************************************
00642 
00643 >   BOOL OILFixedDockingBar::DeleteBars()
00644 
00645     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00646     Created:    5/3/94
00647     Inputs:     -
00648     Outputs:    -
00649     Returns:    -
00650     Purpose:    deletes all BarList items
00651     Errors:     -
00652     SeeAlso:    
00653 
00654 ********************************************************************************************/
00655 
00656 BOOL OILFixedDockingBar::DeleteBars()
00657 {
00658     NoOfSlots = 0; 
00659     for (INT32 i = 0; i < MAX_SLOTS; i++)
00660         SlotSize[i] = ControlSize;
00661     DockSize.cy = DockSize.cx = 0;
00662     Position.x = Position.y = -1;
00663     ChildBars.DeleteAll();
00664     return TRUE;
00665 } 
00666 
00668 //  Message Handling                                              
00670 
00671 
00672 /********************************************************************************************
00673 
00674 >   void OILFixedDockingBar::DoPaint(WPARAM, LPARAM lParam)
00675 
00676     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00677     Created:    5/3/94
00678     Inputs:     pointer to a device context
00679     Outputs:    -
00680     Returns:    -
00681     Purpose:    Paints docking bar background and border      
00682     Errors:     -
00683     SeeAlso:    
00684 
00685 ********************************************************************************************/
00686 void OILFixedDockingBar::DoPaint(CDC* pDC)
00687 {
00688     
00689     ASSERT_VALID(pDC);
00690         
00691     CRect rect;
00692     GetClientRect(rect);                                // get the size of this bar
00693     CBrush  hbrFrame (GetSysColor(COLOR_BTNFACE));
00694     
00695     
00696     COLORREF Outline;
00697     if(IS_CHICAGO)
00698         Outline = GetSysColor(COLOR_BTNSHADOW);
00699     else
00700         Outline = GetSysColor(COLOR_WINDOWFRAME);
00701 
00702     CPen hpen(PS_SOLID,1,Outline);
00703 
00704     // paint bodge to avoid double lines
00705         
00706     CBrush * hOldBrush = pDC->SelectObject(&hbrFrame);
00707     CPen   * hOldPen = pDC->SelectObject(&hpen);
00708     
00709     //pDC->FillRect(&rect,&hbrFrame);
00710     
00711     
00712     switch (DockType)
00713     {
00714 
00715         case DOCKBAR_LEFT:
00716             pDC->Rectangle(rect.left-1,rect.top-1,rect.right,rect.bottom+1);
00717             break;
00718         case DOCKBAR_TOP:
00719             pDC->Rectangle(rect.left-1,rect.top-1,rect.right+1,rect.bottom);
00720             break;
00721         case DOCKBAR_RIGHT:
00722             pDC->Rectangle(rect.left,rect.top-1,rect.right+1,rect.bottom+1);
00723             break;
00724         case DOCKBAR_BOTTOM:
00725             pDC->Rectangle(rect.left-1,rect.top,rect.right+1,rect.bottom+1);
00726             break;
00727 
00728     }
00729     
00730     pDC->SelectObject(hOldBrush);
00731     pDC->SelectObject(hOldPen);
00732 }
00733 
00734 
00735 /********************************************************************************************
00736 
00737 >   void OILFixedDockingBar::RepositionWindow(AFX_SIZEPARENTPARAMS FAR* lpLayout, 
00738                 HWND hWnd, LPCRECT lpRect)
00739 
00740     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00741     Created:    6/9/94
00742     Inputs:     -
00743     Outputs:    -
00744     Returns:    -
00745     Purpose:    Is called from OnSizeParent to reposition the docking bars - replacing
00746                 Afx_RepositionWindow which forces a total redraw !
00747     Errors:     -
00748 
00749 ********************************************************************************************/
00750 
00751 
00752 void OILFixedDockingBar::RepositionWindow(AFX_SIZEPARENTPARAMS FAR* lpLayout, 
00753                 HWND hWnd, LPCRECT lpRect)
00754 {
00755     
00756     if(hWnd == NULL)
00757     {
00758         ENSURE(FALSE,"Reposition NULL Window ");
00759         return ;
00760     }
00761     if(lpRect == NULL)
00762     {   
00763         ENSURE(FALSE,"NULL Reposition Rectangle");
00764         return;
00765     }
00766     
00767     CRect InvalRect(0,0,0,0);
00768 
00769     CRect Check(lpRect); 
00770     // check whether this is an empty bar
00771     BOOL Empty = Check.Width() == 0 || Check.Height() == 0;
00772         
00773     // Reposition the window but dont force a redraw    
00774     // we use SetWindowPos rather than DeferWindowPos - this allows us
00775     // to position the window and then invalidate a part of it
00776 
00777     if (!Empty) // calculate a rectangle to invalidate
00778     {
00779         CRect rectOld;
00780         GetWindowRect(rectOld);             //old window position in screen coords
00781         GetParent()->ClientToScreen(&Check);
00782 
00783         // no change - get out of here
00784         if(Check==rectOld)
00785             return ;
00786 
00787         switch (DockType)
00788         {
00789         case DOCKBAR_TOP:
00790             if(Check.left == rectOld.left)
00791             {
00792                 if (Check.right > rectOld.right )
00793                     InvalRect.SetRect(rectOld.right,Check.top,Check.right,Check.bottom);
00794                 else if(Check.right < rectOld.right )
00795                     InvalRect.SetRect(Check.right,Check.top,rectOld.right,Check.bottom);
00796                 else
00797                     InvalRect.SetRect(Check.left,Check.top,rectOld.right,Check.bottom);
00798             }
00799             else //do whole area
00800             {
00801                InvalRect.SetRect(min(rectOld.left,Check.left),
00802                                  min(rectOld.top,Check.top),
00803                                  max(rectOld.right,Check.right),
00804                                  max(rectOld.bottom,Check.bottom));
00805             }               
00806             break;
00807         case DOCKBAR_BOTTOM:
00808             if( Check.left  !=  rectOld.left    ||  Check.top   !=  rectOld.top)
00809                 InvalRect.SetRect(Check.left,Check.top,Check.right,Check.bottom);
00810             else
00811                 InvalRect.SetRect(rectOld.right,Check.top,Check.right,Check.bottom);
00812         
00813             break;
00814         case DOCKBAR_LEFT:
00815             if(Check.top == rectOld.top)
00816             {
00817                 if (Check.bottom > rectOld.bottom )
00818                     InvalRect.SetRect(Check.left,rectOld.bottom,Check.right,Check.bottom);
00819                 else 
00820                     InvalRect.SetRect(Check.left,Check.bottom,Check.right,rectOld.bottom);
00821             }
00822             else //do whole area
00823             {
00824                InvalRect.SetRect(min(rectOld.left,Check.left),
00825                                  min(rectOld.top,Check.top),
00826                                  max(rectOld.right,Check.right),
00827                                  max(rectOld.bottom,Check.bottom));
00828             }
00829             break;
00830         case DOCKBAR_RIGHT:
00831             if( Check.left  !=  rectOld.left    ||  Check.top   !=  rectOld.top)
00832                 InvalRect.SetRect(Check.left,Check.top,Check.right,Check.bottom);
00833             else
00834                 InvalRect.SetRect(Check.left,rectOld.bottom,Check.right,Check.bottom);
00835             break;
00836         case DOCKBAR_FLOAT:
00837             InvalRect.SetRect(rectOld.left,rectOld.bottom,rectOld.right,rectOld.bottom);
00838             break;
00839         }
00840     }
00841     
00842     SetWindowPos(NULL, lpRect->left, 
00843         lpRect->top, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top,
00844         SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOREDRAW);
00845     
00846     
00847     if(!Empty)
00848     {
00849         // we need a touch of bit twiddling here to make sure that 
00850         // paint messages are sent out to the dock and their bars
00851         INT32 OldStyle = ::GetWindowLong(hWnd,GWL_STYLE);
00852         ::SetWindowLong(hWnd,GWL_STYLE,OldStyle & ~WS_CLIPCHILDREN);
00853         
00854         //Convert back to parent coords
00855         GetParent()->ScreenToClient(&InvalRect);
00856     
00857         // invalidate  'new' area
00858         GetParent()->InvalidateRect(&InvalRect,FALSE);
00859         GetParent()->UpdateWindow();
00860         
00861         // set the style back to it's original state 
00862         ::SetWindowLong(hWnd,GWL_STYLE,OldStyle);
00863     }
00864 }
00865 
00866 /********************************************************************************************
00867 
00868 >   LRESULT OILFixedDockingBar::OnSizeParent(WPARAM, LPARAM lParam)
00869 
00870     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00871     Created:    10/3/94
00872     Inputs:     -
00873     Outputs:    -
00874     Returns:    -
00875     Purpose:    Afx private Message  - Resizes Docking Bar and Parent MDIClient Window
00876     Errors:     -
00877     SeeAlso:    MFC\src\barcore.ccp - MFC TechNote 24   
00878 
00879 ********************************************************************************************/
00880 
00881 
00882 LRESULT OILFixedDockingBar::OnSizeParent(WPARAM, LPARAM lParam)
00883 {
00884     AFX_SIZEPARENTPARAMS FAR* lpLayout = (AFX_SIZEPARENTPARAMS FAR*)lParam;
00885     CRect rect(0,0,0,0);
00886     CRect LayoutRect(lpLayout->rect);
00887 
00888     SetSize(LayoutRect,&rect);
00889 
00890     switch (DockType)
00891     {
00892 
00893     case DOCKBAR_LEFT:
00894         lpLayout->rect.left += TotalSlotSizes();// left-hand side of this window
00895 //      if(IS_CHICAGO)
00896 //          lpLayout->rect.left--;
00897         break;
00898     case DOCKBAR_RIGHT:
00899         lpLayout->rect.right -= TotalSlotSizes();// right-hand side of this window
00900         break;
00901     case DOCKBAR_TOP:
00902         lpLayout->rect.top += TotalSlotSizes();//  top of this window
00903 //      if(IS_CHICAGO)
00904 //          lpLayout->rect.top--;
00905         break;
00906     case DOCKBAR_BOTTOM:
00907         lpLayout->rect.bottom -= TotalSlotSizes();// bottom of this window
00908 //      if(IS_CHICAGO)
00909 //          lpLayout->rect.bottom ++;   
00910         break;
00911     default:
00912         ENSURE(0, "Unknown Dockingbar type!");
00913         break;
00914     }
00915     
00916     // call our Reposition window for more redraw control
00917     //_Afx
00918     RepositionWindow(lpLayout, m_hWnd, &rect);
00919     return 0;
00920 }
00921 
00922 
00923 
00925 //          OILFixedDocking Bar General Functions
00927 
00928 
00929 INT32 OILFixedDockingBar::TotalSlotSizes(INT32 Slot /* = -1 */)
00930 {
00931     if (Slot == -1)
00932         Slot = NoOfSlots;
00933 
00934     // Sum slot sizes
00935     INT32 TotalSize = 0;
00936     for (INT32 i = 0; i < Slot; i++)
00937         TotalSize += SlotSize[i];
00938 
00939     return(TotalSize);
00940 }
00941 
00942 /********************************************************************************************
00943 
00944 >   void OILFixedDockingBar::SetBigControlState(BOOL Big)
00945 
00946     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00947     Created:    5/3/94
00948     Inputs:     -
00949     Outputs:    -
00950     Returns:    -
00951     Purpose:    Sets Big Control state
00952     Errors:     -
00953     SeeAlso:    
00954 
00955 ********************************************************************************************/
00956 
00957 void OILFixedDockingBar::SetBigControlState(BOOL Big )
00958 {
00959     // check that state has actually changed
00960     if (Big != HasBigControls )
00961     {
00962         ::LockWindowUpdate(GetMainFrame()->GetSafeHwnd());
00963         HasBigControls = Big;
00964         ControlSizes NewSize;
00965         if (Big)
00966             NewSize = LARGE_CONTROLS;
00967         else
00968             NewSize = SMALL_CONTROLS;
00969 
00970         // Set any slots that are the old size to new size
00971         // TODOG: This needs to change
00972         for (INT32 i = 0; i < MAX_SLOTS; i++)
00973         {
00974             if (SlotSize[i] == ControlSize)
00975                 SlotSize[i] = NewSize;
00976         }
00977 //      for (INT32 i = 0; i < MAX_SLOTS; i++)
00978 //      {
00979 //          SlotSize[i] = NewSize;
00980 //      }
00981 
00982         // Call the base class to update the ControlSize member
00983         // and resize the child bars
00984         OILDockingBar::SetBigControlState(Big);
00985         
00986         // have to be a bit careful here DialogBar will delete and add new items
00987         // to this list when it receives the RESIZECONTROLS Message 
00988         OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead();
00989         OILChildBar * Next; 
00990         OILChildBar * EndList =(OILChildBar *) ChildBars.GetTail(); 
00991 
00992         while (ThisChild != NULL)
00993         {
00994             Next =(OILChildBar *) ChildBars.GetNext(ThisChild);
00995             ::SendMessage(ThisChild->GetHwnd(), WM_RESIZECONTROLS, 0,0);
00996             ThisChild = Next;
00997             if (ThisChild == NULL)
00998                 break;
00999             if (ThisChild == EndList)
01000             {
01001                 ::SendMessage(ThisChild->GetHwnd(), WM_RESIZECONTROLS, 0,0);
01002                 break;
01003             }       
01004         }
01005 
01006         // update the bars for the new slot sizes
01007         ThisChild =(OILChildBar *) ChildBars.GetHead(); 
01008         while (ThisChild != NULL)
01009         {
01010             ThisChild->UpdatePos();
01011             ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);    
01012         }
01013         
01014         // check for any overlap
01015         if (Big)
01016             CheckAndCorrectOverlap();
01017 
01018         ::LockWindowUpdate(NULL);
01019         ((CFrameWnd*)Parent)->RecalcLayout();
01020     }
01021 }
01022 
01023 /********************************************************************************************
01024             
01025 >   BOOL OILFixedDockingBar::IsScreenPointinDock(CPoint here)
01026 
01027     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01028     Created:    30/3/94
01029     Inputs:     Screen Point
01030     Outputs:    -       
01031     Returns:    TRUE/FALSE
01032     Purpose:    determines whether a screen point is currently in or near a fixed dockingbar
01033     Errors:     -
01034     SeeAlso:    
01035 
01036 ********************************************************************************************/
01037            
01038 BOOL OILFixedDockingBar::IsScreenPointInDock(CPoint here)
01039 {
01040     CRect rect(0,0,DockSize.cx,DockSize.cy);
01041     // virtual rectangle to give a positive hit when the
01042     // real window has no size
01043     if (NoOfSlots==0)
01044     {
01045         switch (DockType)
01046         {
01047         case DOCKBAR_LEFT:
01048             rect.right = ControlSize;
01049             break;
01050         case DOCKBAR_RIGHT:
01051             rect.left =  - (INT32)ControlSize;
01052             break;
01053         case DOCKBAR_TOP:
01054             rect.bottom = ControlSize;                      
01055             break;
01056         case DOCKBAR_BOTTOM:
01057             rect.top = - (INT32)ControlSize;                        
01058             break;
01059         }
01060     }
01061     ClientToScreen(&rect);
01062     return rect.PtInRect(here);
01063 
01064 }
01065 
01066 
01067 /********************************************************************************************
01068 
01069 >   void OILFixedDockingBar::GetDockScreenRect(CRect * BarRect)
01070 
01071     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01072     Created:    30/3/94
01073     Inputs:     Screen rect
01074     Outputs:    -       
01075     Returns:    -
01076     Purpose:    determines whether a screen rectangle intersects a fixed dockingbar
01077     Errors:     -
01078     SeeAlso:    
01079 
01080 ********************************************************************************************/
01081            
01082 void OILFixedDockingBar::GetDockScreenRect(CRect * BarRect)
01083 {
01084     CRect rect ; 
01085     GetClientRect(&rect);
01086     ClientToScreen(&rect);          //screen coords of this dock
01087     BarRect->CopyRect(rect);
01088 }
01089 
01090 
01091 
01092 
01093 
01094 /********************************************************************************************
01095 
01096 >   BOOL OILFixedDockingBar::IsScreenRectInDock(CRect BarRect)
01097 
01098     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01099     Created:    30/3/94
01100     Inputs:     Screen rect
01101     Outputs:    -       
01102     Returns:    TRUE/FALSE
01103     Purpose:    determines whether a screen rectangle intersects a fixed dockingbar
01104     Errors:     -
01105     SeeAlso:    
01106 
01107 ********************************************************************************************/
01108            
01109 BOOL OILFixedDockingBar::IsScreenRectInDock(CRect BarRect)
01110 {
01111 
01112     CRect rect(0,0,DockSize.cx,DockSize.cy);
01113     if (NoOfSlots==0)               //docking bar has no width/height 
01114     {
01115 
01116         switch (DockType)           //make a rectangle for the intersection test
01117         {
01118         case DOCKBAR_LEFT:
01119         case DOCKBAR_RIGHT:
01120             rect.right = 1;
01121             break;
01122         case DOCKBAR_TOP:
01123         case DOCKBAR_BOTTOM:
01124             rect.bottom = 1;                        
01125             break;
01126         }
01127 
01128     }
01129     ClientToScreen(&rect);          //screen coords of this dock
01130     rect&=BarRect;                  //do intersection
01131     return !(rect.IsRectEmpty());
01132 }
01133 
01134 
01135 
01136 /********************************************************************************************
01137 
01138 >   void OILFixedDockingBar::SetSize()
01139 
01140     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01141     Created:    10/3/94
01142     Inputs:     MDIClient area
01143     Outputs:    new bar size        
01144     Returns:    -
01145     Purpose:    Sizes a DockingBar Window according to type and the MainFrame Client Window .
01146     Errors:     -
01147     SeeAlso:    
01148 
01149 ********************************************************************************************/
01150                     
01151 void OILFixedDockingBar::SetSize(CRect ClientRect,CRect * rect)
01152 {
01153 
01154     rect->CopyRect(&ClientRect);    // Copy MDIFrame Rect into target rect
01155     switch  (DockType)              // now size according to type
01156     {
01157 
01158     case DOCKBAR_LEFT:
01159         rect->right =ClientRect.left + TotalSlotSizes();
01160         break;
01161     case DOCKBAR_RIGHT:
01162         rect->left = ClientRect.right - TotalSlotSizes();
01163         break;
01164     case DOCKBAR_TOP:
01165         rect->bottom = ClientRect.top + TotalSlotSizes();
01166         break;
01167     case DOCKBAR_BOTTOM:
01168         rect->top = ClientRect.bottom - TotalSlotSizes();
01169         break;
01170 
01171     }
01172     //Keep a record of Bar size
01173     DockSize.cx=rect->right-rect->left;
01174     DockSize.cy=rect->bottom-rect->top;
01175 }
01176    
01177 /********************************************************************************************
01178 
01179 >   INT32 OILFixedDockingBar::PointToSlot(CPoint ThisPoint);
01180 
01181     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01182     Created:    10/3/94
01183     Inputs:     a point 
01184     Outputs:    -       
01185     Returns:    slot number according to dock type
01186     Purpose:    determine Slot number according to DockType given a Client Coord
01187     Errors:     -
01188     SeeAlso:    
01189 
01190 ********************************************************************************************/
01191                     
01192 INT32 OILFixedDockingBar::PointToSlot(CPoint* ThisPoint)
01193 {
01194     if (ControlSize == 0)
01195         return(0);
01196 
01197     INT32 Value = 0;
01198     // return a slot number according to dock type and control size
01199     switch  (DockType)
01200     {
01201         case DOCKBAR_TOP:
01202         case DOCKBAR_BOTTOM:
01203             Value = ThisPoint->y;
01204             break;
01205 
01206         case DOCKBAR_LEFT:
01207         case DOCKBAR_RIGHT:
01208             Value = ThisPoint->x;
01209             break;
01210     }
01211 
01212     INT32 Total = 0;
01213     // Loop through slots until size totals more than coord
01214     for (INT32 i = 0; i < MAX_SLOTS; i++)
01215     {
01216         Total += SlotSize[i];
01217         if (Total > Value)
01218             return(i);
01219     }
01220     
01221     return(0);
01222 }
01223 
01224 
01225 /********************************************************************************************
01226 
01227 >   void OILFixedDockingBar::BarPosToClient();
01228 
01229     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01230     Created:    10/3/94
01231     Inputs:     a point 
01232     Outputs:    Client x/y given slot and position      
01233     Returns:    -
01234     Purpose:    determine Client coordinate in dock from a KernelBarPos
01235     Errors:     -
01236     SeeAlso:    
01237 
01238 ********************************************************************************************/
01239                     
01240 void  OILFixedDockingBar::BarPosToClient(KernelBarPos Pos,CPoint * Point)
01241 {
01242     // return a slot number according to dock type and control size
01243     switch  (DockType)
01244     {
01245         case DOCKBAR_TOP:
01246         case DOCKBAR_BOTTOM:
01247             Point->x = Pos.Position;
01248             Point->y = TotalSlotSizes(Pos.Slot);
01249             break;
01250 
01251         case DOCKBAR_LEFT:
01252         case DOCKBAR_RIGHT:
01253             Point->y = Pos.Position;
01254             Point->x = TotalSlotSizes(Pos.Slot);
01255             break;
01256     }
01257 }
01258 
01259 /********************************************************************************************
01260 
01261 >   void OILFixedDockingBar::BarPosToScreen(KernelBarPos Pos,CPoint * Point);
01262 
01263     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01264     Created:    10/3/94
01265     Inputs:     a point 
01266     Outputs:    Screen x/y given slot and position      
01267     Returns:    -
01268     Purpose:    determine Screen coordinate in dock from a KernelBarPos
01269     Errors:     -
01270     SeeAlso:    
01271 
01272 ********************************************************************************************/
01273                     
01274 void  OILFixedDockingBar::BarPosToScreen(KernelBarPos Pos,CPoint * Point)
01275 {
01276     BarPosToClient(Pos, Point);     // Get the client position
01277     ClientToScreen(Point);          // And convert to screen coords
01278 }
01279 
01280 /********************************************************************************************
01281 
01282 >   INT32 OILFixedDockingBar::PointToPosition()
01283 
01284     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01285     Created:    10/3/94
01286     Inputs:     CPoint
01287     Outputs:    -
01288     Returns:    position in slot according to dock type
01289     Purpose:    determine pixel offset inslot according to Docktype given a client coord
01290     Errors:     -
01291     SeeAlso:    
01292 
01293 ********************************************************************************************/
01294 
01295 INT32 OILFixedDockingBar::PointToPosition(CPoint* ThisPoint)
01296 {
01297     //return pixel offset in slot according to dock type
01298     switch  (DockType)
01299     {
01300         case DOCKBAR_TOP:
01301         case DOCKBAR_BOTTOM:
01302             return ThisPoint->x;
01303             break;
01304 
01305         case DOCKBAR_LEFT:
01306         case DOCKBAR_RIGHT:
01307             return ThisPoint->y;
01308             break;
01309     }
01310     return 0;
01311  }                  
01312 
01313 
01314 
01316  // Child Bar Placement 
01318 
01319 /********************************************************************************************
01320 
01321 >   INT32 OILFixedDockingBar::GetIntersectPercent(OILChildbar * ThisBar)
01322 
01323     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01324     Created:    15/3/94
01325     Inputs:     -
01326     Outputs:    -
01327     Returns:    Percentage of interesect area with other bars in this dock
01328     Purpose:    
01329     Errors:     -
01330     SeeAlso:    
01331 
01332 ********************************************************************************************/
01333 
01334 INT32 OILFixedDockingBar::GetIntersectPercent(OILChildBar * ThisBar)
01335 {
01336     
01337     CRect  CheckRect;                                           
01338     CRect  TempNew;                                                                                                 
01339     CRect  ThisRect = ThisBar->GetRectClient();
01340     CPoint ThisPoint = ThisBar->GetPos();
01341 
01342     INT32 ThisArea = ThisRect.right*ThisRect.bottom;
01343     INT32 FoundArea = 0;
01344     CSize FoundSize;
01345 
01346     OILChildBar* ThisChild = (OILChildBar *) ChildBars.GetHead(); 
01347     while (ThisChild != NULL)
01348     {
01349         if (ThisBar != ThisChild)               // Dont check against itself !! 
01350         {
01351             TempNew = ThisRect+ThisPoint;       // New bar rect + point offset  
01352                                             // this will be overwritten by the &= operation
01353             CheckRect = ThisChild->GetRectClient()+ThisChild->GetPos();// Found bar origin +point offset
01354             TempNew &= CheckRect;               // Intersection of Found and New Bar
01355             if (!TempNew.IsRectEmpty())     // Check for overlap
01356             {
01357                 FoundSize = TempNew.Size();
01358                 FoundArea += FoundSize.cx*FoundSize.cy; // total area so far
01359             }
01360         }
01361 
01362         ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);        
01363     }
01364 
01365     if (ThisArea==0)
01366         return 0;
01367 
01368     return (INT32) ceill(((float)(FoundArea*100))/(float)ThisArea);// return percentage overlap
01369 }
01370 
01371 
01372 /********************************************************************************************
01373 
01374 >   void OILFixedDockingBar::PutInSlot(CPoint * point, INT32 Size)
01375 
01376     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01377     Created:    15/3/94
01378     Inputs:     -
01379     Outputs:    pointer to new bar slot position
01380     Returns:    -
01381     Purpose:    snap an x or y coordinate to nearest slot
01382     Errors:     -
01383     SeeAlso:    
01384 
01385 ********************************************************************************************/
01386 
01387 void OILFixedDockingBar::PutInSlot(CPoint* position, INT32 Size)
01388 {
01389 //  TRACE( _T("PutInSlot x - %d  y - %d\n"), position->x, position->y);
01390     
01391     INT32 PointSlot = PointToSlot(position);
01392 //  TRACE( _T("PointSlot = %d\n"), PointSlot);
01393     INT32 SlotStart = TotalSlotSizes(PointSlot);
01394 //  TRACE( _T("SlotStart = %d\n"), SlotStart);
01395     INT32 MidPoint = SlotStart + (SlotSize[PointSlot] / 2);
01396 
01397     INT32 BarMidPoint = 0;
01398 //  TRACE( _T("MidPoint = %d\n"), MidPoint);
01399     INT32 SlotEnd = SlotStart + SlotSize[PointSlot];
01400 //  TRACE( _T("SlotEnd = %d\n"), SlotEnd);
01401 
01402     switch (DockType)
01403     {
01404     case DOCKBAR_BOTTOM:                            // snap y to nearest slot
01405     case DOCKBAR_TOP:
01406         BarMidPoint = position->y + (Size / 2);
01407         if (position->x < 0)
01408             position->x = 0; 
01409 
01410         if (position->y < MidPoint)
01411         {
01412             position->y = SlotStart;
01413         }
01414         else
01415         {
01416             position->y = SlotStart + SlotSize[PointSlot];
01417         }
01418         break;
01419 
01420     case DOCKBAR_LEFT:                          // snap y to nearest slot
01421     case DOCKBAR_RIGHT:
01422         BarMidPoint = position->x + (Size / 2);
01423 
01424         if (position->y < 0)
01425             position->y = 0; 
01426 
01427         if (BarMidPoint < SlotEnd)
01428         {
01429             position->x = SlotStart;
01430         }
01431         else
01432         {
01433             position->x = SlotStart + SlotSize[PointSlot];
01434         }
01435         
01436 /*      if (position->x < MidPoint)
01437         {
01438             position->x = SlotStart;
01439         }
01440         else
01441         {
01442             position->x = SlotStart + SlotSize[PointSlot];
01443         }*/
01444         break;
01445     }
01446 //  TRACE( _T("NewPos x - %d  y - %d\n"), position->x, position->y);
01447 }
01448 
01449 /********************************************************************************************
01450 
01451 >   OILFixedDockingBar::ShiftBarPos(CPoint * position, INT32 Amount)
01452 
01453     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01454     Created:    15/3/94
01455     Inputs:         
01456     Outputs:    -
01457     Returns:    Success / Fail 
01458     Purpose:    Shift a bar by given amount - checks new position is in dock bounds 
01459                 note this means the current visible size of the dock    
01460     Errors:     -
01461     SeeAlso:    
01462 
01463 ********************************************************************************************/
01464 
01465 BOOL OILFixedDockingBar::ShiftBarPos(CPoint * position, INT32 Amount)
01466 {
01467     INT32 NewPos;
01468 
01469     switch (DockType)
01470     {
01471     case DOCKBAR_LEFT:                              // check that new position is within dockbar
01472     case DOCKBAR_RIGHT:
01473         NewPos = position->y + Amount;              // shift y position
01474         if (NewPos < 0 || NewPos >= DockSize.cy)    // test bounds
01475             return FALSE;                           // outside dock
01476         position->y = NewPos;                       // OK set position
01477         break;
01478 
01479     case DOCKBAR_TOP:
01480     case DOCKBAR_BOTTOM:
01481         NewPos = position->x + Amount;
01482         if (NewPos < 0 || NewPos >= DockSize.cx)
01483             return FALSE;
01484         position->x = NewPos;                       // OK set position
01485         break;
01486     }
01487 
01488     return TRUE;
01489 }
01490 
01491 /********************************************************************************************
01492 
01493 >   OILFixedDockingBar::ShiftBarSlot(CPoint * position, INT32 NoSlots)
01494 
01495     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01496     Created:    3/5/94
01497     Inputs:         
01498     Outputs:    -
01499     Returns:    Success / Fail 
01500     Purpose:    Shift a bar by the given number of slots    
01501     Errors:     -
01502     SeeAlso:    
01503 
01504 ********************************************************************************************/
01505 
01506 BOOL OILFixedDockingBar::ShiftBarSlot(CPoint* position, INT32 NoSlots)
01507 {
01508     INT32 StartSlot = PointToSlot(position);
01509     INT32 NewPos = TotalSlotSizes(NoSlots + StartSlot);
01510 
01511     switch (DockType)
01512     {
01513     case DOCKBAR_LEFT:
01514     case DOCKBAR_RIGHT:
01515         position->x = NewPos;       // OK set position
01516         break;
01517 
01518     case DOCKBAR_TOP:
01519     case DOCKBAR_BOTTOM:
01520         position->y = NewPos;       // OK set position
01521         break;
01522     }
01523 
01524     return TRUE;
01525 }
01526 
01527 /********************************************************************************************
01528 
01529 >   OILFixedDockingBar::CheckAndCorrectOverlap()
01530 
01531     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01532     Created:    24/4/94
01533     Inputs:     -
01534     Outputs:    -
01535     Returns:    -
01536     Purpose:    To tidy up any posible overlap after changing the size of the bars
01537                 ( between Small/Large controls etc..)       
01538     Errors:     -
01539     SeeAlso:    -
01540 
01541 ********************************************************************************************/
01542 
01543 void OILFixedDockingBar::CheckAndCorrectOverlap()
01544 {
01545     DoRecalc = FALSE ;
01546     INT32   RightOfLastBar  = 0;  
01547     INT32   ThisBarStart = 0;
01548     INT32   ThisSlot    = 0;
01549     INT32   LastSlot    = 0;
01550     INT32   AmountToMove = 0;
01551     BOOL    TidyUpSlots = FALSE ;
01552     INT32 index=0;
01553 
01554     OILChildBar * ThisChild = (OILChildBar *) ChildBars.GetHead();
01555     if (ThisChild == NULL)
01556         return ;
01557     CPoint ThisPos = ThisChild->GetPos();
01558     RightOfLastBar = PointToPosition( &ThisPos ) + ThisChild->GetExtent();
01559     LastSlot = PointToSlot( &ThisPos ); 
01560 
01561     while (ThisChild != NULL)
01562     {
01563         // get next bar
01564         ThisChild = (OILChildBar *) ChildBars.GetNext( ThisChild ); 
01565 
01566         // end of list 
01567         if (ThisChild == NULL)
01568             break;
01569 
01570         // get positional info on this bar
01571         ThisPos = ThisChild->GetPos();
01572         ThisBarStart = PointToPosition( &ThisPos );
01573         ThisSlot = PointToSlot( &ThisPos );
01574 
01575         if ( ThisSlot == LastSlot )
01576         {
01577             // calculate overlap
01578             AmountToMove = RightOfLastBar-ThisBarStart;
01579 
01580             // check for overlap
01581             if ( AmountToMove > 0 ) 
01582             {
01583                 // can we move this bar within this slot ?
01584                 if (ShiftBarPos( &ThisPos, AmountToMove ))
01585                 {
01586                     ThisChild->SetPos( ThisPos );
01587                 }
01588                 else
01589                 {
01590                     // Insert a slot and move there
01591                     InsertSlot( ThisSlot + 1 );
01592                     ShiftBarSlot( &ThisPos,1 );
01593                     ThisChild->SetPos( ThisPos );
01594                     TidyUpSlots = TRUE;
01595                     RightOfLastBar = ThisBarStart = 0;
01596                 }
01597             }
01598         }
01599                 
01600         RightOfLastBar = PointToPosition( &ThisPos ) + ThisChild->GetExtent();
01601         LastSlot = ThisSlot;
01602     
01603     }
01604 
01605     if (TidyUpSlots)
01606         TidySlots();
01607     if (DoRecalc)
01608         ((CFrameWnd*)Parent)->RecalcLayout();       
01609     DoRecalc = FALSE ;
01610 }
01611 
01612 
01613 /********************************************************************************************
01614 
01615 >   OILFixedDockingBar::CanShuffleForward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
01616 
01617     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01618     Created:    24/3/94
01619     Inputs:     -
01620     Outputs:    -
01621     Returns:    Success / Fail if bar can be shuffled backward without going out of dock bounds
01622                 NB a bar can extend beyond the dock but can never be placed entirely outside
01623                 its dock.
01624     Purpose:    determine  whether bars in this slot can be shuffled along without
01625                 leaving the dock            
01626     Errors:     -
01627     SeeAlso:    CanShuffleBackward / CanShuffleBackward / DoShuffleForward
01628 
01629 ********************************************************************************************/
01630 
01631 BOOL OILFixedDockingBar::CanShuffleForward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
01632 {
01633 
01634     if (Start==NULL)
01635         return FALSE;
01636 
01637     INT32   RightOfBar = 0;
01638     INT32   LeftOfBar = 0;
01639     CPoint  FoundPos;
01640     INT32   AmountToMove = Amount;
01641 
01642     OILChildBar * ThisChild = Start;
01643 
01644     while (ThisChild != End)
01645     {
01646 
01647         FoundPos = ThisChild->GetPos();
01648         if (!ShiftBarPos(&FoundPos,AmountToMove))// check if we're shuffling out of bounds
01649                return FALSE;                    // we've run out of room 
01650 
01651         RightOfBar = PointToPosition(&FoundPos)  + ThisChild->GetExtent();
01652         
01653         ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);    
01654 
01655         if (ThisChild == End || ThisChild == NULL)
01656             LeftOfBar = RightOfBar;
01657         else
01658             LeftOfBar = PointToPosition(&(ThisChild->GetPos()));
01659     
01660         AmountToMove = RightOfBar - LeftOfBar;
01661 
01662         if (AmountToMove == 0)                                      // break if nothing to move
01663           break;
01664 
01665     }
01666     if (AmountToMove > 0)
01667         return FALSE;
01668     return TRUE;
01669 }
01670 
01671 /********************************************************************************************
01672 
01673 >   OILFixedDockingBar::DoShuffleForward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
01674 
01675     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01676     Created:    24/3/94
01677     Inputs:     -
01678     Outputs:    -
01679     Returns:    Success / Fail if bar would be placed below dockstart
01680     Purpose:    Attempts to make space in slot for a new bar by shuffling all bars to the left
01681                 each iteration resets Amount to the new overlap with the previous bar               
01682     Errors:     -   
01683     SeeAlso:    CanShuffleBackward / CanShuffleBackward / DoShuffleForward
01684 
01685 ********************************************************************************************/
01686 
01687 BOOL OILFixedDockingBar::DoShuffleForward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
01688 {
01689 
01690     if (Start==NULL)
01691         return FALSE;
01692 
01693     if (!CanShuffleForward(Start,End,Amount))
01694         return FALSE;
01695 
01696     INT32 RightOfBar;
01697     INT32 LeftOfBar;
01698     CPoint FoundPos;
01699     INT32 AmountToMove = Amount;                        // set to initial overlap
01700     OILChildBar * ThisChild = Start;
01701 
01702     while (ThisChild!=End)
01703     {
01704     
01705         FoundPos=ThisChild->GetPos();
01706 
01707         if (ShiftBarPos(&FoundPos,AmountToMove))        //check for valid movement
01708             ThisChild->SetPos(FoundPos);                //move the bar
01709 
01710         RightOfBar = PointToPosition(&FoundPos)  + ThisChild->GetExtent();
01711 
01712         ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);    
01713 
01714         if (ThisChild == End || ThisChild == NULL)
01715             LeftOfBar = RightOfBar;
01716         else
01717             LeftOfBar = PointToPosition(&(ThisChild->GetPos()));
01718 
01719         AmountToMove = RightOfBar - LeftOfBar;          // find overlap 
01720 
01721         if (AmountToMove == 0)
01722           break;                                    // break if nothing to move
01723     
01724     }
01725     if (AmountToMove>0)
01726         return FALSE;
01727     return TRUE;
01728 }
01729 
01730 /********************************************************************************************
01731 
01732 >   OILFixedDockingBar::CanShuffleBackward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
01733 
01734     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01735     Created:    24/3/94
01736     Inputs:     -
01737     Outputs:    -
01738     Returns:    Success / Fail if bar can be shuffled backward without going out of dock bounds
01739                 NB a bar can extend beyond the dock but can never be placed entirely outside
01740                 its dock.
01741     Purpose:    determine  whether bars in this slot can be shuffled along without
01742                 leaving the dock    
01743     Errors:     -
01744     SeeAlso:    DoShuffleBackward / CanShuffleForward / DoShuffleForward    
01745 
01746 ********************************************************************************************/
01747 
01748 BOOL OILFixedDockingBar::CanShuffleBackward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
01749 {
01750     
01751     if (Start==NULL)
01752         return FALSE;
01753 
01754     INT32 RightOfBar;
01755     INT32 LeftOfBar;
01756     CPoint FoundPos;
01757     INT32 AmountToMove=Amount;                    // set to initial overlap
01758     OILChildBar * ThisChild= Start;
01759 
01760     while (ThisChild!=End)
01761     {
01762     
01763         FoundPos=ThisChild->GetPos();
01764         if (!ShiftBarPos(&FoundPos,-AmountToMove))  //check for valid movement
01765             return FALSE;                           //we've run out of room
01766 
01767         LeftOfBar=PointToPosition(&FoundPos);
01768         ThisChild =(OILChildBar *) ChildBars.GetPrev(ThisChild);    
01769         if (ThisChild==NULL)                           // break if end of list
01770             break;
01771 
01772         RightOfBar = PointToPosition(&(ThisChild->GetPos()))  + ThisChild->GetExtent();
01773 
01774         AmountToMove=RightOfBar-LeftOfBar;
01775         if (AmountToMove<=0)                          // break if nothing to move
01776           break;
01777 
01778     }
01779     return TRUE;
01780 }
01781 
01782 /********************************************************************************************
01783 
01784 >   OILFixedDockingBar::DoShuffleBackward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
01785 
01786     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01787     Created:    24/3/94
01788     Inputs:     -
01789     Outputs:    -
01790     Returns:    Success/Fail if bar has been shuffled forwards 
01791     Purpose:    Move all bars in this slot <<<<         
01792     Errors:     -
01793     SeeAlso:    CanShuffleBackward / CanShuffleForward / DoShuffleForward   
01794 
01795 ********************************************************************************************/
01796 
01797 BOOL OILFixedDockingBar::DoShuffleBackward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
01798 {
01799 
01800     if (Start==NULL)
01801         return FALSE;
01802 
01803     if (!CanShuffleBackward(Start,End,Amount))
01804         return FALSE;
01805 
01806     INT32 RightOfBar;
01807     INT32 LeftOfBar;
01808     CPoint FoundPos;
01809     INT32 AmountToMove=Amount;
01810     OILChildBar * ThisChild= Start;
01811 
01812     while (ThisChild!=End)
01813     {
01814 
01815         FoundPos=ThisChild->GetPos();
01816         if (ShiftBarPos(&FoundPos,-AmountToMove))   // Check valid move
01817             ThisChild->SetPos(FoundPos);           // Move the bar
01818 
01819         LeftOfBar=PointToPosition(&(ThisChild->GetPos()));
01820         ThisChild =(OILChildBar *) ChildBars.GetPrev(ThisChild);    
01821         if (ThisChild==NULL)                     // break if end of list
01822             break;
01823 
01824         RightOfBar = PointToPosition(&(ThisChild->GetPos()))  + ThisChild->GetExtent();
01825 
01826         AmountToMove=RightOfBar-LeftOfBar;
01827         if (AmountToMove<=0)                     // break if nothing to move
01828           break;
01829 
01830     }
01831     return TRUE;
01832 }
01833 
01834  /********************************************************************************************
01835 
01836 >   OILFixedDockingBar::GetOverLap(OILChildBar * ThisBar,INT32 SlotNo, INT32 * ForwardOverlap,
01837                                     INT32 * BackwardOverlap)
01838 
01839     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01840     Created:    23/3/94
01841     Inputs:     New ChildBar - Slot No 
01842     Outputs:    ForwardOverlap BackwardOverlap
01843     Returns:    Pointer to nearest bar if found 
01844     Purpose:    
01845     Errors:     
01846     SeeAlso:    
01847 
01848 ********************************************************************************************/
01849 
01850 OILChildBar * OILFixedDockingBar::GetOverLap(OILChildBar * ThisBar,INT32 SlotNo,
01851                                             INT32 * ForwardOverlap,INT32 * BackwardOverlap)
01852 {
01853     ENSURE(SlotNo >= 0 && SlotNo < NoOfSlots,"Slot Out Of Range");
01854 
01855     CPoint FoundPos;                            // current bar pos
01856     OILChildBar * StartSlot = GetSlotHead(SlotNo);// get pointers to head of this slot and next 
01857     OILChildBar *StartNextSlot = GetSlotHead(SlotNo+1);
01858 
01859     // failed to find any bars on this slot
01860     if (StartSlot == NULL)
01861         return FALSE;
01862     
01863     INT32 CheckPos = 0;                                                                                 // position of current bar in list
01864     INT32 ThisPos=PointToPosition(&(ThisBar->GetPos()));// initial position of new bar
01865     OILChildBar * ThisChild = StartSlot;            // Set to start of first bar in this slot
01866     OILChildBar * FoundNearest = NULL;             // will return a pointer to the closest bar 
01867     *BackwardOverlap = 0;                          // initalise Overlaps
01868     *ForwardOverlap = 0;
01869 
01870     // check the list until we get to the end of the list / get to the end of this slot 
01871     // or find a bar with a higher position than the new one
01872     while (TRUE)
01873     {
01874         //TRACE( _T("Check %d against %d ThisChild %p"),ThisPos,CheckPos,ThisChild);
01875         if (ThisChild != NULL)
01876         {
01877             CheckPos = PointToPosition(&(ThisChild->GetPos()));
01878         }
01879         if (ThisPos<CheckPos||ThisChild == StartNextSlot||ThisChild == NULL)
01880         {
01881             // Ok we've gone past it
01882             if (ThisChild == NULL)   // check if we're past the end of the list
01883             {
01884                 ThisChild = (OILChildBar *) ChildBars.GetTail();
01885             }                                                                                                                              
01886             else
01887             {
01888                 ThisChild =(OILChildBar *) ChildBars.GetPrev(ThisChild);
01889             }                                                       
01890             if (ThisChild==NULL)            // Special case -  front of list
01891             {
01892                 *BackwardOverlap = 0;
01893                 FoundNearest = NULL;
01894                 ThisChild =(OILChildBar *) ChildBars.GetHead( );
01895             }
01896             else                        // Check for backwards overlap
01897             {
01898                 // get bottom right corner of current bar
01899                 FoundPos = ThisChild->GetPos();
01900                 CheckPos = PointToPosition(&FoundPos)+ ThisChild->GetExtent();
01901                 // keep a pointer to found bar 
01902                 FoundNearest = ThisChild;
01903                 //TRACE( _T("FOUND BAR  %d on slot %d"),PointToPosition(FoundNearest->GetPos()),
01904                 //  PointToSlot(FoundNearest->GetPos()));
01905                 *BackwardOverlap = CheckPos - ThisPos  ;
01906                 ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);
01907             }               
01908             // is there another bar to the right in this slot   
01909             if (ThisChild != NULL && ThisChild != StartNextSlot)
01910             { 
01911                 // if so check for forward overlap
01912                 FoundPos = ThisBar->GetPos() ;
01913                 CheckPos = PointToPosition(&FoundPos)+ ThisBar->GetExtent();
01914                 INT32 NextPos   = PointToPosition(&(ThisChild->GetPos()));
01915                 if (CheckPos>NextPos)
01916                       *ForwardOverlap = CheckPos-NextPos  ;
01917             }
01918             break;  // break from while loop if nearest bar or end of list found 
01919         }
01920         ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);    
01921     }// end while
01922 
01923     if (*BackwardOverlap < 0)
01924         *BackwardOverlap = 0;
01925 
01926     if (*ForwardOverlap < 0)
01927         * ForwardOverlap = 0;
01928     return FoundNearest;
01929 }
01930 
01931 
01932 
01933 /****************************************************************************
01934 
01935 >   OILChildBar* OILFixedDockingBar::GetGalleryOverLap(OILChildBar* ThisBar,
01936                     INT32 SlotNo,INT32 * ForwardOverlap,INT32 * BackwardOverlap)
01937 
01938     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
01939     Created:    18/11/2004
01940 
01941     Inputs:     ThisBar     - pointer to a OILChildBar
01942                 SlotNo      - 
01943                 ForwardOverlap- pointer to a INT32 
01944                 BackwardOverlap- pointer to a INT32 
01945     Returns:    NULL in times of grief
01946     Purpose:    
01947 
01948 ****************************************************************************/
01949 
01950 BOOL OILFixedDockingBar::GetGalleryOverLap(OILChildBar* ThisBar,INT32 SlotNo,
01951                                             INT32 * ForwardOverlap,INT32 * BackwardOverlap,
01952                                             OILChildBar** ppPrevious, OILChildBar** ppNext)
01953 {
01954 //  ENSURE(SlotNo >= 0 && SlotNo < NoOfSlots,"Slot Out Of Range");
01955 
01956     CPoint FoundPos;                            // current bar pos
01957 
01958     *BackwardOverlap = 0;                          // initalise Overlaps
01959     *ForwardOverlap = 0;
01960     if (ppPrevious)
01961         *ppPrevious = NULL;
01962     if (ppNext)
01963         *ppNext = NULL;
01964 
01965     INT32 ThisMin = ThisBar->GetKPPos();                // initial position of new bar
01966     INT32 ThisMax = ThisMin + ThisBar->GetExtent(); // initial position of new bar
01967 
01968 //  TRACE( _T("ThisMin = %d\n"), ThisMin);
01969 
01970     OILChildBar* StartSlot = GetSlotHead(SlotNo); // get pointer to head of this slot
01971     // failed to find any bars on this slot
01972     if (StartSlot == NULL)
01973     {
01974         *BackwardOverlap = -ThisMin;
01975         *ForwardOverlap = ThisMax - DockSize.cy;
01976         return TRUE;
01977     }
01978 
01979     OILChildBar* CheckBar = StartSlot;              // Set to start of first bar in this slot
01980 
01981     // check the list until we get to the end of the list / get to the end of this slot 
01982     // or find a bar with a higher position than the new one
01983     while (CheckBar && (CheckBar->GetKPSlot() == SlotNo) &&
01984             (CheckBar == ThisBar || CheckBar->GetKPPos() < ThisMin))
01985     {
01986         CheckBar = (OILChildBar*)ChildBars.GetNext(CheckBar);
01987     }
01988 
01989 //  if (CheckBar)
01990 //  {
01991 //      TRACE( _T("CheckBar at %d\n"), CheckBar->GetKPPos());
01992 //  }
01993 //  else
01994 //  {
01995 //      TRACE( _T("CheckBar is NULL\n"));
01996 //  }
01997 
01998     // At this point we must be in one of the following states
01999     OILChildBar* PreviousBar = CheckBar ? (OILChildBar*)ChildBars.GetPrev(CheckBar) : (OILChildBar*)ChildBars.GetTail();
02000     if (PreviousBar == ThisBar)
02001         PreviousBar = (OILChildBar*)ChildBars.GetPrev(PreviousBar);
02002     if (PreviousBar && PreviousBar->GetKPSlot() != SlotNo)
02003         PreviousBar = NULL;
02004 
02005 //  if (PreviousBar)
02006 //  {
02007 //      TRACE( _T("PreviousBar at %d\n"), PreviousBar->GetKPPos());
02008 //  }
02009 //  else
02010 //  {
02011 //      TRACE( _T("PreviousBar is NULL\n"));
02012 //  }
02013 
02014     if (!CheckBar || CheckBar->GetKPSlot() != SlotNo)
02015     {
02016         // CheckBar is NULL implies that the previous bar is in this slot
02017         // CheckBar->GetKPSlot() != SlotNo implies the same as above
02018         // Calculate forward overlap from extent of dock (no bars after us in slot)
02019         // Calculate backward overlap from PreviousBar
02020 
02021         *ForwardOverlap = ThisMax - DockSize.cy;
02022         if (PreviousBar)
02023         {
02024             if (ppPrevious)
02025                 *ppPrevious = PreviousBar;
02026             *BackwardOverlap = (PreviousBar->GetKPPos() + PreviousBar->GetExtent()) - ThisMin;
02027         }
02028         else
02029         {
02030             *BackwardOverlap = -ThisMin;
02031         }
02032     }
02033     else
02034     {
02035         // Calculate forward overlap with CheckBar
02036         // Calculate backward overlap with PreviousBar or from zero if NULL or wrong slot
02037 
02038         if (ppNext)
02039             *ppNext = CheckBar;
02040         *ForwardOverlap = ThisMax - CheckBar->GetKPPos();
02041 
02042         if (PreviousBar)
02043         {
02044             if (ppPrevious)
02045                 *ppPrevious = PreviousBar;
02046             *BackwardOverlap = (PreviousBar->GetKPPos() + PreviousBar->GetExtent()) - ThisMin;
02047         }
02048         else
02049         {
02050             *BackwardOverlap = -ThisMin;
02051         }
02052     }
02053 
02054     return TRUE;
02055 }
02056 
02057 
02058 /********************************************************************************************
02059 
02060 >   OILFixedDockingBar::PlaceBarInSlot(OILChildBar * ThisBar)
02061 
02062     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
02063     Created:    23/3/94
02064     Inputs:     New ChildBar - Slot No
02065     Outputs:    -
02066     Returns:    Success / Fail 
02067     Purpose:    attempts to shuffle bars in a given slot allowing a new bar to be placed with
02068                 no overlap
02069     Errors:     Assert ThisBar != NULL
02070     SeeAlso:    
02071 
02072 ********************************************************************************************/
02073 BOOL OILFixedDockingBar::PlaceBarInSlot(OILChildBar * ThisBar, INT32 SlotNo)
02074 {
02075     ENSURE(ThisBar != NULL,"Trying To Place A Null Bar");
02076     ENSURE(SlotNo >= 0 && SlotNo < NoOfSlots,"Slot Out of Range");
02077 
02078     CPoint FoundPos;                                    // current bar pos
02079     CPoint LastPos ;                                    // copy of last pos
02080     // get pointers to head of this slot and next
02081     OILChildBar * StartSlot=GetSlotHead(SlotNo);
02082     OILChildBar * StartNextSlot=GetSlotHead(SlotNo+1);
02083     BOOL DoneShuffleForward = FALSE;
02084     if (StartSlot==NULL)
02085         return FALSE;                                   // failed to find any bars on this slot
02086 
02087     INT32 ThisPos=PointToPosition(&(ThisBar->GetPos()));        // initial position in slot
02088     INT32 BackwardOverlap ;                              
02089     INT32 ForwardOverlap ;
02090     INT32 ForwardDone   ;
02091     // get a pointer to the nearest bar and overlaps on either side
02092     OILChildBar * FoundNearest=GetOverLap(ThisBar,SlotNo,&ForwardOverlap,&BackwardOverlap);
02093     
02094     ForwardDone = ForwardOverlap;
02095 
02096     if (FoundNearest==NULL)     // trying to insert at the front of a slot
02097     {
02098         FoundPos=ThisBar->GetPos();
02099         // can we place the new bar in the space at the front of the slot
02100         if (ShiftBarPos(&FoundPos,-ForwardOverlap))
02101             ThisBar->SetPos(FoundPos);
02102         // if not can we shuffle the bars in the slot to make space
02103         else 
02104         {
02105             if (!(DoneShuffleForward =DoShuffleForward(StartSlot,StartNextSlot, ForwardOverlap)))
02106                 return FALSE;       //shuffle failed
02107         }
02108     }
02109     else    // trying to insert between two bars
02110     {
02111     
02112         /*TRACE( _T("Insert between bars %d on slot %d back overlap %d forward %d"),
02113             PointToPosition(FoundNearest->GetPos()),PointToSlot(FoundNearest->GetPos()),
02114                             BackwardOverlap,ForwardOverlap);
02115         */                  
02116         if (ForwardOverlap > 0)
02117         {
02118             // try to shuffle all bars in this slot  ahead of new bar to make space
02119             if (!(DoneShuffleForward =DoShuffleForward((OILChildBar *) ChildBars.GetNext(FoundNearest),
02120                                  StartNextSlot, ForwardOverlap))) 
02121             {
02122                 LastPos = FoundPos=ThisBar->GetPos();
02123                 //TRACE( _T("failed ->>> shift -  moving <<<- and attempting whole shuffle <<<-"));
02124                 if (ShiftBarPos(&FoundPos,-ForwardOverlap))
02125                 {
02126                     ThisBar->SetPos(FoundPos);
02127                     FoundNearest = GetOverLap(ThisBar,SlotNo,&ForwardOverlap,&BackwardOverlap);
02128                     if (BackwardOverlap > 0)
02129                     {
02130                         if (!DoShuffleBackward(FoundNearest,
02131                                             (OILChildBar *)ChildBars.GetPrev(StartSlot),
02132                                             BackwardOverlap))
02133                         {
02134                             // return to state before failure
02135                             ThisBar->SetPos(LastPos);
02136                             return FALSE;
02137                         }
02138                     }
02139                 }
02140                 else
02141                 {   
02142                     // return to state before failure
02143                     ThisBar->SetPos(LastPos); 
02144                     return FALSE;
02145                 }
02146                 return FALSE;
02147             }
02148         }// end if ForwardOverlap>0
02149         
02150         
02151         if (BackwardOverlap > 0)
02152         {
02153             // try to shuffle all bars in this slot  behind new bar to make space
02154             if (!DoShuffleBackward(FoundNearest,(OILChildBar *) ChildBars.GetPrev(StartSlot),
02155                                   BackwardOverlap))
02156             {
02157                 LastPos = FoundPos = ThisBar->GetPos();
02158                 //TRACE( _T("failed <<<- shift -  moving->>> and attempting whole shuffle ->>>"));
02159                 if (ShiftBarPos(&FoundPos,BackwardOverlap))
02160                 {
02161                     ThisBar->SetPos(FoundPos);
02162                     FoundNearest = GetOverLap(ThisBar,SlotNo,&ForwardOverlap,&BackwardOverlap);
02163                     if (ForwardOverlap > 0)
02164                     {
02165                         if (!DoShuffleForward((OILChildBar *) ChildBars.GetNext(FoundNearest),
02166                                      StartNextSlot, ForwardOverlap))
02167                         {
02168                             // return to state before fail - we may have shuffled the bars >>> 
02169                             ThisBar->SetPos(LastPos);
02170                             if (DoneShuffleForward)
02171                                 DoShuffleBackward((OILChildBar *) ChildBars.GetNext(FoundNearest),
02172                                                  StartNextSlot, ForwardDone);
02173                             return FALSE;
02174                         }
02175                     }
02176                 }
02177                 else 
02178                 {
02179                     // return to state before fail
02180                     ThisBar->SetPos(LastPos);
02181                     if (DoneShuffleForward)
02182                         DoShuffleForward((OILChildBar *) ChildBars.GetNext(FoundNearest),
02183                                          StartNextSlot, ForwardDone);
02184                     return FALSE;
02185                 }
02186             } 
02187         }// end if BackwardOverlap>0
02188 
02189     }// end else  (FoundNearest != NULL)        
02190     return TRUE;
02191 }
02192 
02193 
02194 
02195 /****************************************************************************
02196 
02197 >   BOOL OILFixedDockingBar::PlaceGalleryInSlot(OILChildBar * ThisBar, INT32 SlotNo)
02198 
02199     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
02200     Created:    18/11/2004
02201 
02202     Inputs:     ThisBar     - pointer to a OILChildBar 
02203                 SlotNo      - 
02204     Returns:    TRUE if ok, FALSE if bother
02205     Purpose:    
02206 
02207 ****************************************************************************/
02208 
02209 BOOL OILFixedDockingBar::PlaceGalleryInSlot(OILChildBar * ThisBar, INT32 SlotNo)
02210 {
02211     ENSURE(ThisBar != NULL,"Trying To Place A Null Bar");
02212 //  ENSURE(SlotNo >= 0 && SlotNo < NoOfSlots,"Slot Out of Range");
02213 
02214     if (!allowTidyBars)
02215         return(TRUE);
02216 
02217     CPoint FoundPos;                                    // current bar pos
02218     CPoint LastPos ;                                    // copy of last pos
02219     BOOL DoneShuffleForward = FALSE;
02220 
02221     INT32 ThisPos = ThisBar->GetKPPos();        // initial position in slot
02222     // get a pointer to the nearest bars and overlaps on either side
02223     INT32 BackwardOverlap ;                              
02224     INT32 ForwardOverlap ;
02225     OILChildBar* PreviousBar = NULL;
02226     OILChildBar* NextBar = NULL;
02227 
02228     GetGalleryOverLap(ThisBar,SlotNo,&ForwardOverlap,&BackwardOverlap, &PreviousBar, &NextBar);
02229 //  TRACE( _T("GalleryOverlap - Back = %d, Fore = %d, Prev = %p, Next = %p\n"), BackwardOverlap, ForwardOverlap, PreviousBar, NextBar);
02230 
02231     // If both Next and Previous are NULL then this is the only bar in the slot and we can shortcut
02232     if (!PreviousBar && !NextBar)
02233     {
02234         ThisBar->GetBarPos()->Position = 0;
02235         ThisBar->UpdatePos();
02236         ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), DockSize.cy);
02237         return(TRUE);
02238     }
02239 
02240     // First off we scan through all the bars in the slot and 
02241     // shuffle all the bars away from this one
02242 
02243     BOOL bMoved = FALSE;
02244     OILChildBar* FirstBar = GetSlotHead(SlotNo);
02245     OILChildBar* LastBar = NULL;        // pointer to last bar in slot
02246     OILChildBar* TempBar = FirstBar;
02247     while (TempBar && TempBar->GetKPSlot() == SlotNo)
02248     {
02249         LastBar = TempBar;
02250         TempBar = (OILChildBar*)ChildBars.GetNext(TempBar);
02251     }
02252     
02253     if (PreviousBar)
02254     {
02255         OILChildBar* MoveBar = FirstBar;
02256         OILChildBar* EndBar = (OILChildBar*)ChildBars.GetNext(PreviousBar);
02257         INT32 CurPos = 0;
02258         while (MoveBar && MoveBar != EndBar)
02259         {
02260             if (MoveBar->GetBarPos()->Position != CurPos)
02261             {
02262                 MoveBar->GetBarPos()->Position = CurPos;
02263                 MoveBar->UpdatePos();
02264                 bMoved = TRUE;
02265             }
02266             CurPos += MoveBar->GetExtent();
02267             MoveBar = (OILChildBar*)ChildBars.GetNext(MoveBar);
02268         }
02269     }
02270 
02271     if (NextBar)
02272     {
02273         OILChildBar* MoveBar = LastBar;
02274         OILChildBar* EndBar = (OILChildBar*)ChildBars.GetPrev(NextBar);
02275         INT32 CurEnd = DockSize.cy;
02276         while (MoveBar && MoveBar != EndBar)
02277         {
02278             INT32 CurPos = CurEnd - MoveBar->GetExtent();
02279             if (MoveBar->GetBarPos()->Position != CurPos)
02280             {
02281                 MoveBar->GetBarPos()->Position = CurPos;
02282                 MoveBar->UpdatePos();
02283                 bMoved = TRUE;
02284             }
02285             CurEnd = CurPos;
02286             MoveBar = (OILChildBar*)ChildBars.GetPrev(MoveBar);
02287         }
02288     }
02289 
02290     if (bMoved)
02291     {
02292         GetGalleryOverLap(ThisBar,SlotNo,&ForwardOverlap,&BackwardOverlap, &PreviousBar, &NextBar);
02293 //      TRACE( _T("GalleryOverlapAfterShuffle - Back = %d, Fore = %d, Prev = %p, Next = %p\n"), BackwardOverlap, ForwardOverlap, PreviousBar, NextBar);
02294     }
02295 
02296     // If Previous is NULL and there is a backward overlap
02297     if (!PreviousBar && BackwardOverlap != 0)
02298     {
02299         // Move and resize this bar to fill the start of the slot
02300         ThisBar->GetBarPos()->Position = 0;
02301         ThisBar->UpdatePos();
02302         ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), ThisBar->GetExtent() - BackwardOverlap);
02303 
02304         GetGalleryOverLap(ThisBar,SlotNo,&ForwardOverlap,&BackwardOverlap, &PreviousBar, &NextBar);
02305 //      TRACE( _T("GalleryOverlapNoPrev - Back = %d, Fore = %d, Prev = %p, Next = %p\n"), BackwardOverlap, ForwardOverlap, PreviousBar, NextBar);
02306     }
02307 
02308     // If Next is NULL and there is a forward overlap
02309     if (!NextBar && ForwardOverlap != 0)
02310     {
02311         // Resize this bar to fill the end of the slot
02312         ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), ThisBar->GetExtent() - ForwardOverlap);
02313         INT32 TempBack = 0;
02314         INT32 TempFor = 0;
02315         GetGalleryOverLap(ThisBar,SlotNo,&TempFor,&TempBack, NULL, NULL);
02316         if (TempFor > 0)
02317         {
02318             ThisBar->GetBarPos()->Position -= TempFor;
02319             ThisBar->UpdatePos();
02320         }
02321         GetGalleryOverLap(ThisBar,SlotNo,&ForwardOverlap,&BackwardOverlap, &PreviousBar, &NextBar);
02322 //      TRACE( _T("GalleryOverlapNoNext - Back = %d, Fore = %d, Prev = %p, Next = %p\n"), BackwardOverlap, ForwardOverlap, PreviousBar, NextBar);
02323     }
02324 
02325     // If Previous is not NULL then the bars before need to be resized to fit in the available space
02326     if (BackwardOverlap != 0)
02327     {
02328         if (PreviousBar)
02329         {
02330             if (BackwardOverlap > 0)
02331             {
02332                 INT32 AmountToShrink = BackwardOverlap;
02333                 INT32 AmountToMove = 0;
02334                 OILChildBar* ShrinkBar = PreviousBar;
02335                 while (AmountToShrink > 0 && ShrinkBar && ShrinkBar->GetKPSlot() == SlotNo)
02336                 {
02337                     INT32 OldExt = ShrinkBar->GetExtent();
02338                     ::SendMessage(ShrinkBar->GetHwnd(), WM_SETGALLERYSIZE, ShrinkBar->GetBarSize(), ShrinkBar->GetExtent() - AmountToShrink);
02339                     INT32 AmountShrunk = OldExt - ShrinkBar->GetExtent();
02340                     AmountToShrink -= AmountShrunk;
02341                     if (AmountToShrink > 0)
02342                     {
02343                         if (ShrinkBar->GetBarPos()->Position > 0)
02344                         {
02345                             AmountToMove = (ShrinkBar->GetBarPos()->Position < AmountToShrink) ? ShrinkBar->GetBarPos()->Position : AmountToShrink;
02346                             ShrinkBar->GetBarPos()->Position -= AmountToMove;
02347                             ShrinkBar->UpdatePos();
02348                             AmountToShrink = AmountToMove;
02349                         }
02350                     }
02351                     ShrinkBar = (OILChildBar*)ChildBars.GetPrev(ShrinkBar);
02352                 }
02353 
02354                 if (AmountToShrink > 0)
02355                 {
02356                     // We still have some backward overlap so set the first bar to 0 
02357                     // and move each bar upto This by the forward overlap
02358                     OILChildBar* MoveBar = GetSlotHead(SlotNo);
02359                     OILChildBar* EndBar = (OILChildBar*)ChildBars.GetNext(PreviousBar);
02360                     INT32 TempBack = 0;
02361                     INT32 TempFor = 0;
02362                     MoveBar->GetBarPos()->Position = 0;
02363                     MoveBar->UpdatePos();
02364                     MoveBar = (OILChildBar*)ChildBars.GetNext(MoveBar);
02365                     while (MoveBar && MoveBar != EndBar)
02366                     {
02367                         GetGalleryOverLap(MoveBar,SlotNo,&TempFor,&TempBack, NULL, NULL);
02368                         if (TempBack != 0)
02369                         {
02370                             MoveBar->GetBarPos()->Position += TempBack;
02371                             MoveBar->UpdatePos();
02372                         }
02373                         MoveBar = (OILChildBar*)ChildBars.GetNext(MoveBar);
02374                     }
02375 
02376                     GetGalleryOverLap(ThisBar,SlotNo,&TempFor,&TempBack, NULL, NULL);
02377                     ThisBar->GetBarPos()->Position += TempBack;
02378                     ThisBar->UpdatePos();
02379                     GetGalleryOverLap(ThisBar,SlotNo,&ForwardOverlap,&BackwardOverlap, &PreviousBar, &NextBar);
02380 //                  TRACE( _T("GalleryOverlapShrunkPrev - Back = %d, Fore = %d, Prev = %p, Next = %p\n"), BackwardOverlap, ForwardOverlap, PreviousBar, NextBar);
02381                 }
02382             }
02383             else
02384             {
02385                 // Need to fill up the gap
02386                 ::SendMessage(PreviousBar->GetHwnd(), WM_SETGALLERYSIZE, PreviousBar->GetBarSize(), PreviousBar->GetExtent() - BackwardOverlap);
02387             }
02388         }
02389         else
02390         {
02391             // No windows before so move position and size of ThisBar to fill the start of the slot
02392             ThisBar->GetBarPos()->Position = 0;
02393             ThisBar->UpdatePos();
02394             INT32 OldExt = ThisBar->GetExtent();
02395             ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), ThisBar->GetExtent() - BackwardOverlap);
02396             INT32 NewExt = ThisBar->GetExtent();
02397             if (NewExt != (OldExt - BackwardOverlap))
02398             {
02399 //              TRACE( _T("Failed to fit ThisBar ar start of slot\n"));
02400             }
02401         }
02402     }
02403 
02404     // If Next is not NULL then the bars after need to be resized to fit in the available space
02405     if (ForwardOverlap != 0)
02406     {
02407         if (NextBar)
02408         {
02409             if (ForwardOverlap > 0)
02410             {
02411                 INT32 AmountToShrink = ForwardOverlap;
02412                 INT32 AmountToMove = 0;
02413                 OILChildBar* ShrinkBar = NextBar;
02414                 while (AmountToShrink > 0 && ShrinkBar && ShrinkBar->GetKPSlot() == SlotNo)
02415                 {
02416                     INT32 OldExt = ShrinkBar->GetExtent();
02417                     ::SendMessage(ShrinkBar->GetHwnd(), WM_SETGALLERYSIZE, ShrinkBar->GetBarSize(), ShrinkBar->GetExtent() - AmountToShrink);
02418                     INT32 AmountShrunk = OldExt - ShrinkBar->GetExtent();
02419                     
02420                     ShrinkBar->GetBarPos()->Position += AmountToShrink;
02421                     ShrinkBar->UpdatePos();
02422                     AmountToShrink -= AmountShrunk;
02423 
02424                     ShrinkBar = (OILChildBar*)ChildBars.GetNext(ShrinkBar);
02425                 }
02426 
02427                 if (AmountToShrink > 0)
02428                 {
02429                     // We still have some forward overlap so shrink this bar
02430                     // and move each bar upto the end to fill the gaps
02431                     // This means that all bars after this are the smallest possible size
02432 
02433                     // If we can't shrink this bar enough then loop backwards from PreviousBar
02434                     // shrinking each bar in turn until enough space has been made
02435                     
02436                     INT32 OldExt = ThisBar->GetExtent();
02437                     ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), ThisBar->GetExtent() - AmountToShrink);
02438                     INT32 AmountShrunk = OldExt - ThisBar->GetExtent();
02439                     AmountToShrink -= AmountShrunk;
02440 
02441                     if (AmountToShrink > 0)
02442                     {
02443                         ThisBar->GetBarPos()->Position -= AmountToShrink;
02444                         ThisBar->UpdatePos();
02445                         
02446                         OILChildBar* ShrinkBar = PreviousBar;
02447                         while (ShrinkBar && ShrinkBar->GetKPSlot() == SlotNo && AmountToShrink > 0)
02448                         {
02449                             INT32 OldExt = ShrinkBar->GetExtent();
02450                             ::SendMessage(ShrinkBar->GetHwnd(), WM_SETGALLERYSIZE, ShrinkBar->GetBarSize(), ShrinkBar->GetExtent() - AmountToShrink);
02451                             INT32 AmountShrunk = OldExt - ShrinkBar->GetExtent();
02452                             if (AmountShrunk > 0)
02453                             {
02454                                 AmountToShrink -= AmountShrunk;
02455                                 // Shift all bars upto nextbar by AmountShrunk
02456                                 OILChildBar* MoveBar = (OILChildBar*)ChildBars.GetNext(ShrinkBar);
02457                                 while (MoveBar && MoveBar != NextBar)
02458                                 {
02459                                     MoveBar->GetBarPos()->Position -= AmountShrunk;
02460                                     MoveBar->UpdatePos();
02461                                     MoveBar = (OILChildBar*)ChildBars.GetNext(MoveBar);
02462                                 }
02463                             }
02464                             ShrinkBar = (OILChildBar*)ChildBars.GetPrev(ShrinkBar);
02465                         }
02466                     }
02467 
02468                     INT32 TempBack = 0;
02469                     INT32 TempFor = 0;
02470                     OILChildBar* LastBar = NULL;
02471                     OILChildBar* MoveBar = NextBar;
02472                     MoveBar->GetBarPos()->Position = ThisBar->GetBarPos()->Position + ThisBar->GetExtent();
02473                     MoveBar->UpdatePos();
02474                     MoveBar = (OILChildBar*)ChildBars.GetNext(MoveBar);
02475                     while (MoveBar && MoveBar->GetKPSlot() == SlotNo)
02476                     {
02477                         GetGalleryOverLap(MoveBar,SlotNo,&TempFor,&TempBack, NULL, NULL);
02478                         if (TempBack != 0)
02479                         {
02480                             MoveBar->GetBarPos()->Position += TempBack;
02481                             MoveBar->UpdatePos();
02482                         }
02483                         LastBar = MoveBar;
02484                         MoveBar = (OILChildBar*)ChildBars.GetNext(MoveBar);
02485                     }
02486 
02487                     if (LastBar && TempFor + TempBack > 0)
02488                     {
02489                         ::SendMessage(LastBar->GetHwnd(), WM_SETGALLERYSIZE, LastBar->GetBarSize(), LastBar->GetExtent() - (TempFor + TempBack));
02490                     }
02491                 }
02492         
02493             }
02494             else
02495             {
02496                 // There is a gap before the next bar so move and resize the next bar to
02497                 // fill it up
02498                 NextBar->GetBarPos()->Position += ForwardOverlap;
02499                 NextBar->UpdatePos();
02500                 ::SendMessage(NextBar->GetHwnd(), WM_SETGALLERYSIZE, NextBar->GetBarSize(), NextBar->GetExtent() - ForwardOverlap);
02501             }
02502         }
02503         else
02504         {
02505             // No windows after so change size of ThisBar to fill the end of the slot
02506             ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), ThisBar->GetExtent() - ForwardOverlap);
02507         }
02508     }
02509 
02510     return TRUE;
02511 }
02512 
02513 
02514 
02515 
02516 /********************************************************************************************
02517 
02518 >   OILFixedDockingBar::TidySlots()
02519 
02520     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
02521     Created:    15/3/94
02522     Inputs:     -
02523     Outputs:    -
02524     Returns:    - 
02525     Purpose:    move bars to fill any empty slots  
02526     Errors:     -
02527     SeeAlso:    
02528 
02529 ********************************************************************************************/
02530 
02531 void OILFixedDockingBar::TidySlots()
02532 {    
02533     INT32 LastSlot = -1;
02534     INT32 FoundSlot = 0;
02535     INT32 NumSlots = NoOfSlots;                 // Remember original number of slots
02536     CPoint FoundPos;                            // current bar pos
02537 
02538     if (allowTidyBars)
02539     {
02540 /*      OILChildBar* FoundBar = (OILChildBar*)ChildBars.GetHead();
02541         while (FoundBar != NULL)
02542         {
02543             FoundPos = FoundBar->GetPos();
02544             FoundSlot = PointToSlot(&FoundPos);
02545             if (FoundSlot > LastSlot+1)     // check for empty slots 
02546             {
02547                 LastSlot ++;                    // skip last none empty slot
02548                 while (LastSlot < FoundSlot)
02549                 {           
02550                     RemoveSlot(LastSlot++); // remove empty slots
02551 //                  LastSlot++;
02552                 }
02553             }
02554 
02555             LastSlot = FoundSlot;
02556             FoundBar = (OILChildBar*)ChildBars.GetNext(FoundBar);
02557         } // end while
02558 */
02559 /*
02560                 INT32 TempF = 0;
02561                 INT32 TempB = 0;
02562                 OILChildBar* TempPrev = NULL;
02563                 OILChildBar* TempNext = NULL;
02564                 GetGalleryOverLap(NextBar, SlotNo, &TempF, &TempB, &TempPrev, &TempNext);
02565                 if (TempF > 0)
02566                 {
02567                     // Next bar is overlapping forward
02568                     // Shrink ThisBar by overlap and move next backwards
02569                     NextBar->GetBarPos()->Position -= TempF;
02570                     NextBar->UpdatePos();
02571                     ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), ThisBar->GetExtent() - TempF);
02572                 }
02573 */      
02574         
02575         
02576         // Reset this to correct value for current bars
02577         NoOfSlots = CountSlots();
02578         // For each slot we do a tidy on the slot
02579         for (FoundSlot = 0; FoundSlot < NoOfSlots; FoundSlot++)
02580         {
02581             OILChildBar* CheckBar = GetSlotHead(FoundSlot); // get pointer to head of this slot
02582             if (CheckBar)
02583             {
02584                 if (SlotSize[FoundSlot] != ControlSize)
02585                 {
02586                     OILChildBar* ThisBar = CheckBar;
02587 
02588                     // Now check through again in reverse order
02589                     OILChildBar* LastBar = NULL;        // pointer to last bar in slot
02590                     while (ThisBar && ThisBar->GetKPSlot() == FoundSlot)
02591                     {
02592                         LastBar = ThisBar;
02593                         ThisBar = (OILChildBar*)ChildBars.GetNext(ThisBar);
02594                     }
02595 
02596                     ThisBar = LastBar;
02597                     // check the list until we get to the end of the list / get to the end of this slot 
02598                     while (ThisBar && (ThisBar->GetKPSlot() == FoundSlot))
02599                     {
02600                         INT32 BackwardOverlap = 0;
02601                         INT32 ForwardOverlap = 0;
02602                         OILChildBar* PreviousBar = NULL;
02603                         OILChildBar* NextBar = NULL;
02604 
02605                         GetGalleryOverLap(ThisBar,FoundSlot,&ForwardOverlap,&BackwardOverlap, &PreviousBar, &NextBar);
02606 //                      TRACE( _T("TidyOverlapB - This = %p, Back = %d, Fore = %d, Prev = %p, Next = %p\n"), ThisBar, BackwardOverlap, ForwardOverlap, PreviousBar, NextBar);
02607 
02608                         BOOL bCheck = FALSE;
02609                         // Move the bar by BackwardOverlap
02610                         if (BackwardOverlap != 0)
02611                         {
02612                             ThisBar->GetBarPos()->Position += BackwardOverlap;
02613                             ThisBar->UpdatePos();
02614                             bCheck = TRUE;
02615                         }
02616                         // Resize the bar by (-ForwardOverlap-BackwardOverlap)
02617                         INT32 SizeDiff = -(ForwardOverlap+BackwardOverlap);
02618                         if (SizeDiff != 0)
02619                         {
02620                             ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), ThisBar->GetExtent() + SizeDiff);
02621                             bCheck = TRUE;
02622                         }                       
02623 
02624                         if (bCheck)
02625                         {
02626                             GetGalleryOverLap(ThisBar,FoundSlot,&ForwardOverlap,&BackwardOverlap, &PreviousBar, &NextBar);
02627 //                          TRACE( _T("CheckOverlap - This = %p, Back = %d, Fore = %d, Prev = %p, Next = %p\n"), ThisBar, BackwardOverlap, ForwardOverlap, PreviousBar, NextBar);
02628                             if (ForwardOverlap > 0)
02629                             {
02630                                 // Move the bar backwards by ForwardOverlap
02631                                 ThisBar->GetBarPos()->Position -= ForwardOverlap;
02632                                 ThisBar->UpdatePos();
02633                             }
02634                         }
02635 
02636                         ThisBar = (OILChildBar*)ChildBars.GetPrev(ThisBar);
02637                     }
02638         
02639 
02640 
02641                     // First we do a forward scan removing any overlaps as we go
02642                     // check the list until we get to the end of the list / get to the end of this slot 
02643                     ThisBar = CheckBar;
02644                     while (ThisBar && (ThisBar->GetKPSlot() == FoundSlot))
02645                     {
02646                         INT32 BackwardOverlap = 0;
02647                         INT32 ForwardOverlap = 0;
02648                         OILChildBar* PreviousBar = NULL;
02649                         OILChildBar* NextBar = NULL;
02650 
02651                         GetGalleryOverLap(ThisBar,FoundSlot,&ForwardOverlap,&BackwardOverlap, &PreviousBar, &NextBar);
02652 //                      TRACE( _T("TidyOverlapF - This = %p, Back = %d, Fore = %d, Prev = %p, Next = %p\n"), ThisBar, BackwardOverlap, ForwardOverlap, PreviousBar, NextBar);
02653 
02654                         // Move the bar by BackwardOverlap
02655                         if (BackwardOverlap != 0)
02656                         {
02657                             ThisBar->GetBarPos()->Position += BackwardOverlap;
02658                             ThisBar->UpdatePos();
02659                         }
02660                         // Resize the bar by (-ForwardOverlap-BackwardOverlap)
02661                         INT32 SizeDiff = -(ForwardOverlap+BackwardOverlap);
02662                         if (SizeDiff != 0)
02663                         {
02664                             ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), ThisBar->GetExtent() + SizeDiff);
02665                         }                       
02666 
02667                         ThisBar = (OILChildBar*)ChildBars.GetNext(ThisBar);
02668                     }
02669 
02670                 
02671                 }
02672             }
02673             else if (FoundSlot < NoOfSlots)
02674             {
02675                 RemoveSlot(FoundSlot--);        // No bars so remove the slot and go back a slot
02676                 NoOfSlots--;
02677             }
02678         }
02679     }
02680     
02681     INT32 SlotsNow = CountSlots();  // check if number of slots has changed
02682 
02683     if (SlotsNow != NumSlots)       // and RecalcLayout if it has
02684     {
02685         NoOfSlots = SlotsNow;
02686         DoRecalc = TRUE;
02687     }   
02688     else
02689     {
02690         OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead(); 
02691     
02692         while (ThisChild != NULL)
02693         {
02694             ThisChild->InvalidateIfMoved();
02695             ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);    
02696     
02697         }// end while
02698     }
02699 }
02700 
02701 
02702 /********************************************************************************************
02703 
02704 >   OILFixedDockingBar::CountSlots()
02705 
02706     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
02707     Created:    15/3/94
02708     Inputs:     -
02709     Outputs:    -
02710     Returns:    number of slots in this dock
02711     Purpose:    Count how many slots are in this bar 
02712     Errors:     -
02713     SeeAlso:    
02714 
02715 ********************************************************************************************/
02716 
02717 INT32 OILFixedDockingBar::CountSlots()
02718 {
02719     if (ChildBars.IsEmpty())        // no bars in list
02720         return(0);
02721 
02722     OILChildBar* FoundBar = (OILChildBar*)ChildBars.GetTail();
02723     if (FoundBar == NULL)           // Shouldn't happen but I'll check to make sure
02724         return(0);
02725 
02726     return(FoundBar->GetKPSlot() + 1);
02727 
02728 /*  INT32 FoundSlot = 0;
02729     INT32 HighSlot = 0;
02730     OILChildBar * FoundBar =(OILChildBar *) ChildBars.GetHead();
02731 
02732     while (FoundBar != NULL)   // find the highest slot number in the list
02733     {
02734     
02735         FoundSlot = PointToSlot(&(FoundBar->GetPos()));
02736         if (FoundSlot > HighSlot)
02737             HighSlot = FoundSlot;
02738 
02739         FoundBar =(OILChildBar *) ChildBars.GetNext(FoundBar);
02740     
02741     } // end while
02742     
02743     return HighSlot+1;      // slots are numbered from 0 so add 1 to return value
02744 */
02745 }
02746 
02747 /********************************************************************************************
02748 
02749 >   OILFixedDockingBar::RemoveSlot(INT32 SlotNo)
02750 
02751     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
02752     Created:    15/3/94
02753     Inputs:     -
02754     Outputs:    -
02755     Returns:    -
02756     Purpose:    Remove a slot - shuffle all ChildBars beyond this slot backwards
02757     Errors:     ASSERT slot number >0
02758     SeeAlso:    
02759 
02760 ********************************************************************************************/
02761 
02762 void OILFixedDockingBar::RemoveSlot(INT32 SlotNo)
02763 { 
02764     ASSERT(SlotNo >= 0 && SlotNo < NoOfSlots);
02765 //  INT32 FoundSlot;
02766     CRect FoundRect;
02767     CPoint FoundPos;
02768     OILChildBar * FoundBar =(OILChildBar *) ChildBars.GetHead();
02769     INT32 MoveSize = SlotSize[SlotNo];      // The size of the slot being removed
02770 
02771     // Set the last slot to the default size
02772     SlotSize[MAX_SLOTS-1] = ControlSize;
02773     // And copy the slot sizes down in the array
02774     for (INT32 i = SlotNo; i < (MAX_SLOTS - 1); i++)
02775     {
02776         SlotSize[i] = SlotSize[i+1];
02777     }
02778 
02779     // look for bars in or above slot to be removed
02780     // shuffle any found back one slot
02781     while (FoundBar != NULL)
02782     {
02783         KernelBarPos* pPos = FoundBar->GetBarPos();
02784 //      FoundPos = FoundBar->GetPos();
02785 //      FoundSlot = PointToSlot(&FoundPos);
02786 
02787         ERROR3IF(pPos->Slot == SlotNo, "Deleting non-empty slot");
02788         
02789         switch (DockType)                   // check if found slot => remove slot
02790         {                                   // if so pull back one slot
02791             case DOCKBAR_TOP:
02792             case DOCKBAR_BOTTOM:
02793                 if (pPos->Slot > SlotNo)
02794                 {
02795 //                  FoundPos.y -= MoveSize;
02796                     pPos->Slot -= 1;        // Move it back a slot
02797                     FoundBar->UpdatePos();
02798                 }
02799                 break;
02800             case DOCKBAR_LEFT:
02801             case DOCKBAR_RIGHT:
02802                 if (pPos->Slot > SlotNo)
02803                 {
02804 //                  FoundPos.x -= MoveSize;
02805                     pPos->Slot -= 1;        // Move it back a slot
02806                     FoundBar->UpdatePos();
02807                 }
02808                 break;
02809         }// end switch
02810 //      FoundBar->SetPos(FoundPos);
02811         FoundBar =(OILChildBar *) ChildBars.GetNext(FoundBar);
02812     
02813     } // end while
02814 }
02815 
02816 /********************************************************************************************
02817 
02818 >   OILFixedDockingBar::InsertSlot(INT32 SlotNo, INT32 NewSize = -1)
02819 
02820     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
02821     Created:    15/3/94
02822     Inputs:     -
02823     Outputs:    -
02824     Returns:    -
02825     Purpose:    Insert a Slot - shuffle all ChildBars  beyond this slot number  forwards
02826     Errors:     ASSERT Slot number >0
02827     SeeAlso:    
02828 
02829 ********************************************************************************************/
02830 
02831 void OILFixedDockingBar::InsertSlot(INT32 SlotNo, INT32 NewSize)
02832 { 
02833     ASSERT(SlotNo >= 0 && SlotNo < NoOfSlots);
02834     KernelBarPos* pPos = NULL;
02835 
02836     if (NewSize == -1)
02837         NewSize = ControlSize;
02838 
02839     // First we add up all the slot sizes
02840     INT32 TotalSize = TotalSlotSizes();
02841     CRect MainRect;
02842     GetMainFrame()->GetClientRect(&MainRect);
02843     INT32 MaxSize = (MainRect.Width() * 48) / 100;
02844 
02845     INT32 AmountToShrink = MaxSize - TotalSize - NewSize;
02846     // If the new slot will make the total too large then
02847     if (AmountToShrink > 0)
02848     {
02849         // If the new slot is a gallery then try changing NewSize
02850         if (NewSize != ControlSize)
02851         {
02852             // Calculate the new size for this slot
02853             NewSize = (NewSize - AmountToShrink) < MIN_GALLERY_SLOT_WIDTH ? MIN_GALLERY_SLOT_WIDTH : NewSize - AmountToShrink;
02854             // Recalculate the amount to shrink
02855             AmountToShrink = MaxSize - TotalSize - NewSize;
02856         }
02857 
02858         // If not a gallery or couldn't shrink enough then find another slot to shrink
02859         if (AmountToShrink > 0)
02860         {
02861             for (INT32 i = 0; i < NoOfSlots; i++)
02862             {
02863                 if (SlotSize[i] != ControlSize)
02864                 {
02865                     INT32 OldSize = SlotSize[i];
02866                     if (OldSize > MIN_GALLERY_SLOT_WIDTH)
02867                     {
02868                         // Calculate the new size for this slot
02869                         INT32 SetSize = (OldSize - AmountToShrink) < MIN_GALLERY_SLOT_WIDTH ? MIN_GALLERY_SLOT_WIDTH : OldSize - AmountToShrink;
02870 
02871                         // Resize the slot
02872                         SetSlotSize(i, SetSize);
02873                         
02874                         // Recalculate the amount to shrink
02875                         AmountToShrink -= (OldSize - SlotSize[i]);
02876                     }
02877                 }
02878 
02879                 if (AmountToShrink == 0)
02880                     break;
02881             }
02882         }
02883     }
02884 
02885     // Copy the slot sizes up in the array
02886     for (INT32 i = (MAX_SLOTS - 1); i > SlotNo; i--)
02887     {
02888         SlotSize[i] = SlotSize[i-1];
02889     }
02890     // And set the slot inserted to the default size
02891     SlotSize[SlotNo] = NewSize;
02892     
02893     OILChildBar* FoundBar = (OILChildBar*) ChildBars.GetHead();
02894     // look for bars in or above slot to be inserted
02895     // shuffle any found forward one slot
02896     while (FoundBar != NULL)
02897     {
02898         pPos = FoundBar->GetBarPos();
02899         if (pPos->Slot >= SlotNo)
02900         {
02901             (pPos->Slot)++;
02902             FoundBar->UpdatePos();
02903         }// end if
02904         FoundBar = (OILChildBar*) ChildBars.GetNext(FoundBar);
02905     } // end while
02906 }
02907 
02908 /********************************************************************************************
02909 
02910 >   OILFixedDockingBar::GetSlotHead(CPoint ThisPoint)
02911 
02912     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
02913     Created:    23/3/94
02914     Inputs:     -
02915     Outputs:    -
02916     Returns:    A Pointer to the first ChildBar in a given slot -  NULL if none found
02917     Purpose:    Find the first bar in this slot and return a pointer to it   
02918     Errors:     -
02919     SeeAlso:    
02920 
02921 ********************************************************************************************/
02922 
02923 OILChildBar * OILFixedDockingBar::GetSlotHead(INT32 SlotNo)
02924 {
02925     CPoint FoundPos;
02926     INT32 FoundSlot;
02927     OILChildBar * FoundBar =(OILChildBar *) ChildBars.GetHead();
02928 
02929     while (FoundBar != NULL)   // find first bar in this slot
02930     {
02931 //      FoundPos = FoundBar->GetPos();
02932 //      FoundSlot = PointToSlot(&FoundPos);
02933         FoundSlot = FoundBar->GetKPSlot();
02934         if (FoundSlot == SlotNo)
02935             return FoundBar;
02936         else if (FoundSlot > SlotNo)
02937             return NULL;
02938 
02939         FoundBar = (OILChildBar*) ChildBars.GetNext(FoundBar);
02940     }
02941 
02942     return NULL;        // no bars found
02943 }
02944 
02945 /********************************************************************************************
02946 
02947 >   OILFixedDockingBar::IsPointInBar(CPoint ThisPoint)
02948 
02949     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
02950     Created:    15/3/94
02951     Inputs:     -
02952     Outputs:    -
02953     Returns:    A Pointer to a ChildBar if one is found - NULL if none found
02954     Purpose:    -    
02955     Errors:     -
02956     SeeAlso:    
02957 
02958 ********************************************************************************************/
02959 
02960 OILChildBar * OILFixedDockingBar::IsPointInBar(CPoint ThisPoint)
02961 {
02962     
02963     CPoint FoundPos;
02964     CRect FoundRect;
02965     OILChildBar * FoundBar =(OILChildBar *) ChildBars.GetHead();
02966 
02967     while (FoundBar != NULL)
02968     {
02969     
02970         FoundPos = FoundBar->GetPos();      // get FoundBar position and size
02971         FoundRect = FoundBar->GetRectClient();
02972         FoundRect += FoundPos;              // offset rect 
02973         if (FoundRect.PtInRect(ThisPoint))  // check for point in found rectangle
02974             return FoundBar;
02975         
02976         FoundBar =(OILChildBar *) ChildBars.GetNext(FoundBar);  
02977     
02978     }
02979     return NULL;
02980 }
02981 
02982 /********************************************************************************************
02983 
02984 >   OILFixedDockingBar::PositionBar(OILChildBar * ThisBar)
02985 
02986     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
02987     Created:    15/3/94
02988     Inputs:     -
02989     Outputs:    -
02990     Returns:    -
02991     Purpose:    Positions a Control Bar in this dock according to percentage overlap with
02992                 other bars  - If overlap > 30 a new slot will be inserted - If overlap >0
02993                 < 30 it will attempt to shuffle other bars to make space
02994     Errors:     -
02995     SeeAlso:    
02996 
02997 ********************************************************************************************/
02998 
02999 void OILFixedDockingBar::PositionBar(OILChildBar * ThisBar)
03000 {
03001     ASSERT(ThisBar != NULL);
03002 //  CPoint ThisPos = ThisBar->GetPos();                     //`get initial slot and position
03003 //  INT32 ThisSlot = PointToSlot(&ThisPos);
03004     INT32 ThisSlot = ThisBar->GetBarPos()->Slot;
03005 
03006     // First we determine if this slot is suitable for this bar
03007     // e.g. dropping a gallery into a slot with normal bars is bad
03008     INT32 ThisSize = ThisBar->GetBarSize();
03009 //  TRACE( _T("PB# ThisSize = %d\n"), ThisSize);
03010 
03011     INT32 SizeOfBarsInSlot = 0;
03012     INT32 NumBarsInSlot = 0;
03013     INT32 FoundSlot = 0;
03014     OILChildBar* FoundBar = GetSlotHead(ThisSlot);
03015     while (FoundBar != NULL)   // find the largest bar in this slot
03016     {
03017         FoundSlot = FoundBar->GetBarPos()->Slot;
03018         if (FoundSlot > ThisSlot)   // Gone past the bars in this slot so stop
03019         {
03020             break;
03021         }
03022         else if (FoundSlot == ThisSlot)
03023         {
03024             NumBarsInSlot++;
03025             INT32 FoundSize = FoundBar->GetBarSize();
03026             if (FoundSize > SizeOfBarsInSlot)
03027                 SizeOfBarsInSlot = FoundSize;
03028         }
03029         FoundBar = (OILChildBar*)ChildBars.GetNext(FoundBar);
03030     } // end while
03031 //  TRACE( _T("PB# SizeOfBarsInSlot = %d\n"), SizeOfBarsInSlot);
03032 
03033     if (ThisSize != ControlSize)
03034     {
03035         // If there are no bars in this slot then
03036         if (SizeOfBarsInSlot == 0)
03037         {
03038             // set this slot to the required size for this bar
03039             SetSlotSize(ThisSlot, ThisSize);
03040         }
03041         else
03042         {
03043             // If this bar already contains a gallery then add this bar to this slot
03044             if (SizeOfBarsInSlot == ControlSize)
03045             {
03046                 InsertSlot(ThisSlot, ThisSize);
03047             }
03048             else
03049             {
03050                 // set this slot to the required size for this bar
03051                 SetSlotSize(ThisSlot, ThisSize);
03052             }
03053 
03054         }
03055         // Make sure this gets updated as it isn't in the slot yet
03056         ThisBar->UpdatePos();
03057         ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, SlotSize[ThisSlot], ThisBar->GetExtent());
03058 
03059         PlaceGalleryInSlot(ThisBar, ThisSlot);
03060 
03061         return;
03062     }
03063 
03064     // At this point we must be positioning a normal bar
03065 
03066     // If this slot contains galleries then insert a new slot
03067     if (SizeOfBarsInSlot != 0 && SizeOfBarsInSlot != ControlSize)
03068     {
03069         InsertSlot(ThisSlot);                               // just insert a new slot
03070         return;
03071     }
03072 
03073     INT32 AreaOverlapPercent = GetIntersectPercent(ThisBar);    // get Percentage Overlap
03074     
03075     if (AreaOverlapPercent > 30)
03076     {
03077 //      TRACE( _T("PB# > 30 inserting slot %d\n"),ThisSlot);
03078         InsertSlot(ThisSlot);                               // just insert a new slot  
03079     }
03080     else if (AreaOverlapPercent > 0)
03081     {
03082 //      TRACE( _T("PB# > 0 trying to place %d\n"),ThisSlot);
03083     
03084         if (!PlaceBarInSlot(ThisBar,ThisSlot))// try to shuffle and make space for this bar
03085         {
03086 //          TRACE( _T("PB# Couldn't place - inserting slot %d\n"),ThisSlot);
03087             InsertSlot(ThisSlot);             // couldn't shuffle so insert a new slot
03088         }
03089     
03090     } // do nothing if we find no overlaping bars
03091     
03092 } 
03093 
03094 
03095 /********************************************************************************************
03096 
03097 >   OILFixedDockingBar::PlaceBar(HWND hdialog,CPoint here, CSize size)
03098 
03099     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
03100     Created:    15/3/94
03101     Inputs:     WindowHandle CPoint 
03102     Outputs:    -
03103     Returns:    Success/Fail
03104     Purpose:    Creates a new Child Bar  then inserts it in the list - it also checks
03105                 for overlap with any other bars and shuffles them until a suitable
03106                 position is found   
03107     Errors:     -
03108     SeeAlso:    
03109 
03110 ********************************************************************************************/
03111 
03112 BOOL OILFixedDockingBar::PlaceBar(HWND hdialogbar,CPoint here, CSize size)
03113 {
03114 //  TRACE( _T("PlaceBar x - %d  y - %d\n"), here.x, here.y);
03115     
03116     DoRecalc = FALSE;
03117     OILChildBar * NewChild;
03118     //check the new window is not already attached to this bar
03119     if (IsBarInList(hdialogbar)!=NULL)
03120     {
03121     
03122         TRACEALL( _T("ChildBar with this handle is already attached to this window\n"));
03123         return FALSE;
03124     
03125     }
03126     if ((NewChild= new OILChildBar(hdialogbar,DockType,ControlSize))==NULL)
03127     {
03128 
03129         TRACE( _T("Couldn't create new ChildBar"));
03130         return FALSE;
03131 
03132     }
03133     
03134     ScreenToClient(&here);      // convert to client coordinates
03135     PutInSlot(&here, NewChild->GetBarSize());           // pull to the nearest slot and set initial positions
03136     NewChild->SetPos(here);     // fix initial position and size
03137     PositionBar(NewChild);      // decide where to place the bar
03138     InsertBarInList(NewChild);  // insert bar into list
03139     TidySlots();    // tidy slots - shuffle bars to fill empty slots 
03140 
03141     if (ChangedDock != NULL && ChangedDock != this)
03142         ((OILFixedDockingBar*)ChangedDock)->TidySlots();
03143 
03144     if (DoRecalc && ! GetMainFrame()->IsChangingViewMode() )
03145         ((CFrameWnd*)Parent)->RecalcLayout();       
03146     DoRecalc = FALSE ;
03147     ChangedDock = NULL;
03148 
03149     #ifdef _DEBUG
03150         if (IsUserName("GerryX"))
03151         {
03152             Dump_List();    
03153         }
03154     #endif
03155     return TRUE;
03156 }
03157 
03158 /********************************************************************************************
03159 
03160 >   OILFixedDockingBar::AppendToSlot(INT32 SlotNo,CPoint * here)
03161 
03162     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
03163     Created:    27/5/94
03164     Inputs:     -
03165     Outputs:    -
03166     Returns:    -
03167     Purpose:    Tags  this bar onto the end of the last bar in SlotNo 
03168     Errors:     -
03169     SeeAlso:    
03170 
03171 ********************************************************************************************/
03172 
03173 void OILFixedDockingBar::AppendToSlot(INT32 SlotNo,CPoint * here)
03174 {
03175     INT32 FoundSlot = 0;
03176     INT32 LastPos = 0;
03177     INT32 LastSlot = 0;
03178     INT32 size = 0 ;
03179     KernelBarPos* pFoundPos = NULL;
03180 
03181     OILChildBar* FoundBar = (OILChildBar*)ChildBars.GetHead();
03182     while (FoundBar != NULL)   // find the highest slot number in the list
03183     {
03184         pFoundPos = FoundBar->GetBarPos();
03185         FoundSlot = pFoundPos->Slot;
03186         if (FoundSlot > SlotNo)
03187         {
03188             break;
03189         }
03190         else if (FoundSlot == SlotNo)
03191         {
03192             LastPos = pFoundPos->Position + FoundBar->GetExtent();
03193         }
03194     }   
03195 
03196 /*  while (FoundBar != NULL)   // find the highest slot number in the list
03197     {
03198         pFoundPos = FoundBar->GetBarPos();
03199         FoundSlot = pFoundPos->Slot;
03200         if (FoundSlot > LastSlot)
03201             LastPos = 0;
03202         // gone past this slot
03203         if (FoundSlot > SlotNo)
03204             break;
03205         // get position
03206         switch(DockType)
03207         {
03208             case DOCKBAR_TOP:
03209             case DOCKBAR_BOTTOM:
03210                 size = FoundBar->GetRectClient().Width() ;
03211                 break;
03212 
03213             case DOCKBAR_LEFT:
03214             case DOCKBAR_RIGHT:
03215                 size = FoundBar->GetRectClient().Height();
03216                 break;
03217 
03218         }
03219         LastPos=PointToPosition(&(FoundBar->GetPos()))+ size;
03220         // new slot - reset LastPos
03221     
03222         LastSlot = FoundSlot;
03223         FoundBar =(OILChildBar *) ChildBars.GetNext(FoundBar);
03224         
03225     } // end while
03226     
03227     if (LastSlot < SlotNo)
03228         LastPos =0;
03229 */  
03230     switch  (DockType)
03231     {
03232         case DOCKBAR_TOP:
03233         case DOCKBAR_BOTTOM:
03234             here->x = LastPos;
03235             break;
03236 
03237         case DOCKBAR_LEFT:
03238         case DOCKBAR_RIGHT:
03239             here->y = LastPos;
03240             break;
03241     }   
03242     
03243 }
03244 
03245 /********************************************************************************************
03246 
03247 >   OILFixedDockingBar::PlaceBar(HWND hdialog,KernelBarPos Position, CSize size)
03248 
03249     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
03250     Created:    15/3/94
03251     Inputs:     Window Handle and KernelBarPos 
03252     Outputs:    
03253     Returns:    Success/Fail
03254     Purpose:    Overloaded function - creates a new Child Bar and inserts it in the list
03255                 If BarPos.Position is -1 the bar will be forced into the given slot 
03256     Errors:     -
03257     SeeAlso:    
03258 
03259 ********************************************************************************************/
03260 BOOL OILFixedDockingBar::PlaceBar(HWND hdialogbar,KernelBarPos BarPos, CSize size)
03261 {   
03262 //  if (DockType == DOCKBAR_RIGHT)
03263 //  {
03264 //      TRACE( _T("PlaceBar slot - %d  pos - %d\n"), BarPos.x, BarPos.y);
03265 //  }
03266 
03267     DoRecalc = FALSE ;
03268     CPoint here;
03269     // get a client coordinate for this slot/offset
03270     BarPosToClient(BarPos,&here);                                    
03271 //  TRACE( _T("Client x - %d  y - %d\n"), here.x, here.y);
03272     OILChildBar * NewChild;
03273     //check the new window is not already attached to this bar
03274     if (IsBarInList(hdialogbar)!=NULL)
03275     {
03276         ReleaseBar(hdialogbar,FALSE);   
03277     }
03278     if ((NewChild= new OILChildBar(hdialogbar,DockType,ControlSize))==NULL)
03279     {
03280         TRACE( _T("Couldn't create new ChildBar"));
03281         return FALSE;
03282     }
03283 
03284     // check whether we need to force this bar into given slot
03285     if (BarPos.Position == -1)
03286     {
03287         if (BarPos.Slot > NoOfSlots -1)
03288         {
03289             BarPos.Slot = NoOfSlots -1;
03290             BarPosToClient(BarPos,&here);       
03291 //          TRACE( _T("Client x - %d  y - %d\n"), here.x, here.y);
03292         }
03293 //      ScreenToClient(&here);              // convert to client coordinates
03294         AppendToSlot(BarPos.Slot,&here);    // Get available position on this slot
03295         NewChild->SetPos(here);             //
03296         InsertBarInList(NewChild);          // insert bar into list
03297         INT32 SlotsNow = CountSlots();      // check if number of slots has changed
03298         if (SlotsNow != NoOfSlots)          // and RecalcLayout if it has
03299         {
03300             NoOfSlots = SlotsNow;
03301             DoRecalc = TRUE;
03302         }   
03303     }
03304     else
03305     {
03306 //      ScreenToClient(&here);      // convert to client coordinates
03307         PutInSlot(&here, NewChild->GetBarSize());           // pull to the nearest slot and set initial positions
03308         NewChild->SetPos(here);     // fix initial position and size
03309         PositionBar(NewChild);      // decide where to place the bar
03310         InsertBarInList(NewChild);  // insert bar into list
03311         TidySlots();                // tidy slots - shuffle bars to fill empty slots 
03312     }
03313     
03314     // check whether another dock has changed
03315     // if so tidy slot s and recalc layout etc..
03316     if (ChangedDock != NULL && ChangedDock != this)
03317         ((OILFixedDockingBar*)ChangedDock)->TidySlots();
03318     
03319     if (DoRecalc && ! GetMainFrame()->IsChangingViewMode())
03320         ((CFrameWnd*)Parent)->RecalcLayout();       
03321     DoRecalc = FALSE ;
03322     
03323     ChangedDock = NULL;
03324 
03325     #ifdef _DEBUG
03326         if (IsUserName("GerryX"))
03327         {
03328             Dump_List();    
03329         }
03330     #endif
03331     return TRUE;
03332 }
03333 
03334 /********************************************************************************************
03335 
03336 >   OILFixedDockingBar::PlaceBarAt(HWND hdialog,KernelBarPos Position)
03337 
03338     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
03339     Created:    15/3/94
03340     Inputs:     Window Handle and KernelBarPos 
03341     Outputs:    
03342     Returns:    Success/Fail
03343     Purpose:    
03344     Errors:     -
03345     SeeAlso:    
03346 
03347 ********************************************************************************************/
03348 
03349 
03350 BOOL OILFixedDockingBar::PlaceBarAt(HWND hdialogbar,KernelBarPos BarPos)
03351 {
03352 
03353     // Find this child bar 
03354     OILChildBar * ThisChild = (OILChildBar *) ChildBars.GetHead();
03355     while (ThisChild != NULL)               
03356     {
03357         if (ThisChild->GetHwnd() == hdialogbar) //found the bar
03358         {
03359             break;
03360         }           
03361         ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);    
03362     }
03363     
03364     ENSURE(ThisChild!=NULL,"Can't find Bar in DockingBar List");
03365     
03366     ThisChild->SetPos(BarPos);  // set child position
03367 
03368     return TRUE;
03369 }
03370 
03371 
03372 /********************************************************************************************
03373 
03374 >   OILFixedBar::InsertBarInList(OILChildBar * ThisBar)
03375 
03376     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
03377     Created:    15/3/94
03378     Inputs:     -
03379     Outputs:    -
03380     Returns:    Success
03381     Purpose:    Inserts a ChildBar in the list in slot and position order 
03382     Errors:     -
03383     SeeAlso:    
03384 
03385 ********************************************************************************************/
03386  
03387 BOOL OILFixedDockingBar::InsertBarInList(OILChildBar * ThisBar)
03388 {
03389 
03390     ASSERT(ThisBar!=NULL);
03391     CPoint ThisPos=ThisBar->GetPos();
03392     CPoint FoundPos;
03393     OILChildBar * FoundBar =(OILChildBar *) ChildBars.GetHead();
03394 
03395     INT32 FoundSlot;
03396     INT32 FoundPosition;
03397     // get insert bar Slot and Position 
03398     INT32 ThisSlot = PointToSlot(&ThisPos);
03399     INT32 ThisPosition = PointToPosition(&ThisPos);
03400 
03401     while (FoundBar != NULL)
03402     {
03403         FoundPos = FoundBar->GetPos();
03404         FoundSlot = PointToSlot(&FoundPos);
03405         FoundPosition = PointToPosition(&FoundPos);
03406         if (FoundSlot > ThisSlot)       // past target slot - just insert before Found slot
03407         {
03408              ChildBars.InsertBefore((ListItem *)FoundBar,(ListItem *)ThisBar);
03409              return TRUE;
03410         }
03411         else if (FoundSlot == ThisSlot)     // Found a bar in the target slot
03412         {
03413             if (FoundPosition > ThisPosition)   // Put in position order
03414             {
03415                 ChildBars.InsertBefore((ListItem *)FoundBar,(ListItem *)ThisBar);
03416                 return TRUE;
03417             }
03418         }
03419         FoundBar =(OILChildBar *) ChildBars.GetNext(FoundBar);
03420     } // end while
03421 
03422     // nothing found - Add to tail 
03423     ChildBars.AddTail((ListItem *)ThisBar);             
03424     return TRUE;
03425 }
03426 
03427 /******************************************************************************************
03428 >   OILFixedDockingBar::ReleaseBar(HWND hdialog,BOOL DoTidy)
03429 
03430     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
03431     Created:    29/3/94
03432     Inputs:     -
03433     Outputs:    -
03434     Returns:    Success/Fail
03435     Purpose:    Search for a ChildBar with a given window handle - if found
03436                 call RemoveBar to remove from list and delete Child Object  
03437     Errors:     -
03438     SeeAlso:    
03439 
03440 ********************************************************************************************/ 
03441 
03442 BOOL    OILFixedDockingBar::ReleaseBar(HWND hdialog,BOOL DoTidy)
03443 {
03444     DoRecalc = FALSE ;
03445     // Find this child bar
03446     OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead(); 
03447     while (ThisChild != NULL)               
03448     {
03449         if (ThisChild->GetHwnd() == hdialog)    //found the bar
03450         {
03451             if (!RemoveBar(ThisChild))      //remove the bar
03452                 return FALSE;
03453             ChangedDock = this;         //"this" will be used later to force a layout tidy
03454             if (DoTidy)
03455                 TidySlots();
03456             if (DoRecalc && ! GetMainFrame()->IsChangingViewMode())
03457             {
03458                 // there is not point in doing this if camelot is dying!
03459                 // especially since this fails up our floating toolbar!
03460                 if (!(GetApplication()->CamelotIsDying ()))
03461                 {
03462                     ((CFrameWnd*)Parent)->RecalcLayout();       
03463                 }
03464             }
03465             DoRecalc = FALSE ;
03466             return TRUE;
03467         }           
03468         ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);    
03469     }// end while
03470     
03471   return FALSE;
03472 }
03473 
03474 
03475 
03476 /****************************************************************************
03477 
03478 >   BOOL OILFixedDockingBar::SetSlotSize(INT32 SlotNo, INT32 NewSize)
03479 
03480     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
03481     Created:    22/10/2004
03482 
03483     Inputs:     SlotNo      - Index of the slot to be resized
03484                 NewSize     - New size of the slot
03485     Returns:    TRUE if ok, FALSE if failed for any reason
03486     Purpose:    Changes the size of a slot
03487 
03488 ****************************************************************************/
03489 
03490 BOOL OILFixedDockingBar::SetSlotSize(INT32 SlotNo, INT32 NewSize)
03491 {
03492     if (SlotNo < 0 ||
03493         SlotNo >= MAX_SLOTS ||
03494         NewSize < ControlSize)
03495         return(FALSE);
03496     
03497 //  if (SlotSize[SlotNo] != NewSize)
03498 //  {
03499         // First we add up all the slot sizes
03500         if (NewSize < MIN_GALLERY_SLOT_WIDTH)
03501             NewSize = MIN_GALLERY_SLOT_WIDTH;
03502         INT32 OldSize = (SlotNo < NoOfSlots) ? SlotSize[SlotNo] : 0;
03503         INT32 TotalSize = TotalSlotSizes();
03504         CRect MainRect;
03505         GetMainFrame()->GetClientRect(&MainRect);
03506         INT32 MaxSize = (MainRect.Width() * 48) / 100;
03507         INT32 AmountToShrink = (NewSize > OldSize) ? (TotalSize - OldSize + NewSize) - MaxSize : 0;
03508         if (AmountToShrink < 0)
03509             AmountToShrink = 0;
03510 
03511         // If the new slot will make the total too large then
03512         if (AmountToShrink > 0)
03513         {
03514             for (INT32 i = 0; i < NoOfSlots; i++)
03515             {
03516                 if (i != SlotNo && SlotSize[i] != ControlSize)
03517                 {
03518                     INT32 OldSize = SlotSize[i];
03519                     if (OldSize > MIN_GALLERY_SLOT_WIDTH)
03520                     {
03521                         // Calculate the new size for this slot
03522                         INT32 SetSize = (OldSize - AmountToShrink) < MIN_GALLERY_SLOT_WIDTH ? MIN_GALLERY_SLOT_WIDTH : OldSize - AmountToShrink;
03523 
03524                         // Resize the slot
03525                         SetSlotSize(i, SetSize);
03526                         
03527                         // Recalculate the amount to shrink
03528                         AmountToShrink -= (OldSize - SlotSize[i]);
03529                     }
03530                 }
03531 
03532                 if (AmountToShrink == 0)
03533                     break;
03534             }
03535         }
03536 
03537         NewSize -= AmountToShrink;
03538         if (NewSize >= MIN_GALLERY_SLOT_WIDTH)
03539         {
03540             SlotSize[SlotNo] = NewSize;
03541         }
03542 
03543         KernelBarPos* FoundPos;
03544         OILChildBar* FoundBar = (OILChildBar*) ChildBars.GetHead();
03545         DoRecalc = TRUE;
03546         
03547         // Look for bars in or above the slot to be resized
03548         // If in the slot then resize them
03549         // If above the slot then move by the difference of the sizes
03550         while (FoundBar != NULL)
03551         {
03552             FoundPos = FoundBar->GetBarPos();
03553             if (FoundPos->Slot == SlotNo)
03554             {
03555                 ::SendMessage(FoundBar->GetHwnd(), WM_SETGALLERYSIZE, NewSize, FoundBar->GetExtent());
03556             }
03557             else // if (FoundPos->Slot > SlotNo)
03558             {
03559                 FoundBar->UpdatePos();
03560             }
03561             FoundBar =(OILChildBar*) ChildBars.GetNext(FoundBar);
03562         
03563         } // end while
03564 //  }
03565 
03566     return(TRUE);
03567 }
03568 
03569 
03570 
03571 
03573 //              OILFloaters
03575 
03576 
03577 IMPLEMENT_DYNAMIC(OILFloaters ,OILDockingBar)
03578 
03579 
03580 
03581 //      OILFloaters Message Map
03583  
03584 BEGIN_MESSAGE_MAP( OILFloaters, OILDockingBar )
03585     //{{AFX_MSG_MAP( OILFloaters )
03586     ON_WM_LBUTTONDOWN()
03587     ON_WM_RBUTTONDOWN()
03588     ON_WM_LBUTTONDBLCLK()
03589     ON_MESSAGE(WM_SIZEPARENT, OnSizeParent) 
03590     //}}AFX_MSG_MAP
03591 END_MESSAGE_MAP( )
03592 
03593 /********************************************************************************************
03594 
03595 >   OILFloaters::Create(CWnd * pParentWnd)
03596 
03597     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
03598     Created:    29/3/94
03599     Inputs:     -
03600     Outputs:    -
03601     Returns:    -
03602     Purpose:    Assigns a Parent window and Sets DockBar Type
03603     Errors:     -
03604     SeeAlso:    
03605 
03606 ********************************************************************************************/
03607 
03608 BOOL OILFloaters::Create(CWnd* pParentWnd)
03609 {
03610     
03611     ASSERT_VALID(pParentWnd);   // must have a parent
03612 
03613     Parent = pParentWnd;        // Parent of this bar
03614 
03615     DockType = DOCKBAR_FLOAT;   // Type of this instance
03616     return TRUE;
03617 } 
03618 
03619 /********************************************************************************************
03620 
03621 >   OILFloaters::OILFloaters()
03622 
03623     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
03624     Created:    5/3/94
03625     Inputs:     -
03626     Outputs:    -
03627     Returns:    -
03628     Purpose:    Creates and inits a OILFloaters object.
03629     Errors:     -
03630     SeeAlso:    
03631 
03632 ********************************************************************************************/
03633                     
03634 OILFloaters::OILFloaters()
03635 { 
03636     ControlSize = SMALL_CONTROLS;
03637     HasBigControls = FALSE; 
03638 }
03639 
03640 
03641 /********************************************************************************************
03642 
03643 >   BOOL OILFloaters::DeleteBars()
03644 
03645     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
03646     Created:    5/3/94
03647     Inputs:     -
03648     Outputs:    -
03649     Returns:    -
03650     Purpose:    deletes all BarList items
03651     Errors:     -
03652     SeeAlso:    
03653 
03654 ********************************************************************************************/
03655 
03656 BOOL OILFloaters::DeleteBars()
03657 {
03658     ControlSize = SMALL_CONTROLS;
03659     HasBigControls = FALSE;
03660     ChildBars.DeleteAll();
03661     return TRUE;
03662 }
03663 /********************************************************************************************
03664 
03665 >   OILFloaters::PlaceBar(HWND hdialog,CPoint here, CSize size = CSize(0,0))
03666 
03667     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
03668     Created:    15/3/94
03669     Inputs:     WindowHandle CPoint 
03670     Outputs:    -
03671     Returns:    Success/Fail
03672     Purpose:    Creates a new Child Bar  then inserts it in the list - it also checks
03673                 for overlap with any other bars and shuffles them until a suitable
03674                 position is found;  
03675     Errors:     -
03676     SeeAlso:    
03677 
03678 ********************************************************************************************/
03679 
03680 BOOL OILFloaters::PlaceBar(HWND hdialogbar,CPoint here, CSize size)
03681 {
03682 //  TRACE( _T("PlaceBar x - %d  y - %d  w - %d  h - %d\n"), here.x, here.y, size.cx, size.cy);
03683     DoRecalc = FALSE ;
03684     OILChildBar * NewChild;
03685 
03686     if ((NewChild = new OILChildBar(hdialogbar,DockType,ControlSize))==NULL)
03687     {
03688         TRACE( _T("Couldn't create new ChildBar/n"));
03689         return FALSE;
03690     }
03691     
03692     NewChild->SetPos(here, size);       // fix initial position and size
03693     InsertBarInList(NewChild);  // insert bar into list
03694     
03695     if (ChangedDock != NULL && ChangedDock != this)
03696         ((OILFixedDockingBar*)ChangedDock)->TidySlots();
03697 
03698     if (DoRecalc)
03699         ((CFrameWnd*)Parent)->RecalcLayout();       
03700     DoRecalc = FALSE ;
03701     ChangedDock=NULL;
03702 
03703     #ifdef _DEBUG
03704         if (IsUserName("GerryX"))
03705         {
03706             Dump_List();
03707         }
03708     #endif
03709     
03710     return TRUE;
03711 }
03712 
03713 
03714 /********************************************************************************************
03715 
03716 >   OILFloaters::PlaceBar(HWND hdialog,KernelBarPos Position, CSize size)
03717 
03718     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
03719     Created:    15/3/94
03720     Inputs:     Window Handle and KernelBarPos 
03721     Outputs:    
03722     Returns:    Success/Fail
03723     Purpose:    Overloaded function - creates a new Child Bar and inserts it in the list
03724                 it assumes that there will be no overlap with other bars - this should only
03725                 be called when positioning bars from file as these will have already been
03726                 positioned and shuffled etc by the other PlaceBar function.
03727     Errors:     -
03728     SeeAlso:    
03729 
03730 ********************************************************************************************/
03731 
03732 BOOL OILFloaters::PlaceBar(HWND hdialogbar,KernelBarPos BarPos, CSize size)
03733 {
03734 //  TRACE( _T("PlaceBar slot - %d  pos - %d Type - %d\n"), BarPos.x, BarPos.y, BarPos.Dock);
03735     
03736     DoRecalc = FALSE ;
03737     OILChildBar * NewChild;
03738     if ((NewChild= new OILChildBar(hdialogbar,DockType,ControlSize))==NULL)
03739     {
03740         TRACEALL( _T("Couldn't create new ChildBar\n"));
03741         return FALSE;
03742     }
03743     
03744     NewChild->SetPos(BarPos);   // set child position
03745     InsertBarInList(NewChild);  // insert in list
03746     
03747     if (ChangedDock != NULL && ChangedDock != this)
03748         ((OILFixedDockingBar*)ChangedDock)->TidySlots();
03749     
03750     if (DoRecalc)
03751         ((CFrameWnd*)Parent)->RecalcLayout();       
03752     DoRecalc = FALSE ;
03753     
03754     ChangedDock=NULL;
03755     
03756     #ifdef _DEBUG
03757         if (IsUserName("GerryX"))
03758         {
03759             Dump_List();
03760         }
03761     #endif
03762     return TRUE;
03763 }
03764 
03765 /********************************************************************************************
03766 
03767 >   OILFloaters::InsertBarInList(OILChildBar * ThisBar)
03768 
03769     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
03770     Created:    15/3/94
03771     Inputs:     -
03772     Outputs:    -
03773     Returns:    Success
03774     Purpose:    Inserts a ChildBar at the tail of the list 
03775     Errors:     -
03776     SeeAlso:    
03777 
03778 ********************************************************************************************/
03779  
03780 BOOL OILFloaters::InsertBarInList(OILChildBar * ThisBar)
03781 {
03782     
03783     ASSERT(ThisBar!=NULL);
03784     //Add to tail 
03785     ChildBars.AddTail((ListItem *)ThisBar);             
03786 
03787     return TRUE;
03788 }
03789 
03790 /******************************************************************************************
03791 >   OILFloatersBar::ReleaseBar(HWND hdialog,BOOL DoTidy)
03792 
03793     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
03794     Created:    29/3/94
03795     Inputs:     -
03796     Outputs:    -
03797     Returns:    Success/Fail
03798     Purpose:    Search for a ChildBar with a given window handle - if found
03799                 call RemoveBar to remove from list and delete Child Object  
03800     Errors:     -
03801     SeeAlso:    
03802 
03803 ********************************************************************************************/ 
03804 
03805 BOOL    OILFloaters::ReleaseBar(HWND hdialog,BOOL DoTidy)
03806 {
03807     
03808     OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead(); 
03809     while (ThisChild != NULL)               
03810     {
03811     
03812         if (ThisChild->GetHwnd() == hdialog)    //found the bar
03813         {
03814             RemoveBar(ThisChild);           //remove the bar
03815             return TRUE;
03816         }           
03817         ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);    
03818     
03819     }// end while
03820     //TRACE( _T("Remove Bar failed %d"),hdialog);
03821     return FALSE;
03822 }
03823 
03824 /********************************************************************************************
03825 
03826 >   BOOL OILFloaters::RecreateBarsAfterSettingChange()
03827 
03828     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
03829     Created:    5/3/94
03830     Inputs:     -
03831     Outputs:    -
03832     Returns:    -
03833     Purpose:    Sets Big Control state
03834     Errors:     -
03835     SeeAlso:    
03836                                                       
03837 ********************************************************************************************/
03838 // UIC 
03839 
03840 BOOL OILFloaters::RecreateBarsAfterSettingChange()
03841 {
03842     
03843     if(!BaseBar::HaveNonClientMetricsChanged())
03844         return FALSE;
03845 
03846     OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead();
03847     OILChildBar * Next; 
03848     OILChildBar * EndList =(OILChildBar *) ChildBars.GetTail();
03849     
03850 
03851     while (ThisChild != NULL)
03852     {
03853         Next =(OILChildBar *) ChildBars.GetNext(ThisChild);
03854         ::SendMessage(ThisChild->GetHwnd(), WM_RESIZECONTROLS, 0,0);
03855         
03856         ThisChild = Next;
03857         if (ThisChild == NULL) break;
03858         //ENSURE(ThisChild != NULL,"Bar Item = NULL");
03859         if (ThisChild == EndList)
03860         {
03861             ::SendMessage(ThisChild->GetHwnd(), WM_RESIZECONTROLS, 0,0);
03862             break;
03863         }       
03864     }
03865 
03866  return TRUE;
03867 }
03868 /********************************************************************************************
03869 
03870 >   OILFloaters::SetBigControlState(BOOL Big)
03871 
03872     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
03873     Created:    5/3/94
03874     Inputs:     -
03875     Outputs:    -
03876     Returns:    -
03877     Purpose:    Sets Big Control state
03878     Errors:     -
03879     SeeAlso:    
03880                                                       
03881 ********************************************************************************************/
03882 
03883 void OILFloaters::SetBigControlState(BOOL Big )
03884 {
03885     if (Big != HasBigControls)
03886     {
03887         HasBigControls = Big;
03888         if (Big)
03889 
03890             ControlSize = LARGE_CONTROLS;
03891         else
03892     
03893             ControlSize = SMALL_CONTROLS;
03894 
03895         // have to be a bit careful here DialogBar will delete and add new items
03896         // to this list when it receives the RESIZECONTROLS Message 
03897         OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead();
03898         OILChildBar * Next; 
03899         OILChildBar * EndList =(OILChildBar *) ChildBars.GetTail();
03900         
03901 
03902         while (ThisChild != NULL)
03903         {
03904             Next =(OILChildBar *) ChildBars.GetNext(ThisChild);
03905             ::SendMessage(ThisChild->GetHwnd(), WM_RESIZECONTROLS, 0,0);
03906             
03907             ThisChild = Next;
03908             if (ThisChild == NULL) break;
03909             //ENSURE(ThisChild != NULL,"Bar Item = NULL");
03910             if (ThisChild == EndList)
03911             {
03912                 ::SendMessage(ThisChild->GetHwnd(), WM_RESIZECONTROLS, 0,0);
03913                 break;
03914             }       
03915         }
03916     }
03917 }
03918  
03919 
03920  
03922 // OILFixedDockingBar diagnostics
03924 
03925 #ifdef _DEBUG
03926 void OILFixedDockingBar::AssertValid() const
03927 {
03928     CControlBar::AssertValid();
03929 }
03930 
03931 void OILFixedDockingBar::Dump(CDumpContext& dc) const
03932 {
03933     CControlBar::Dump(dc);
03934     AFX_DUMP1(dc, "\nControlSize = ", (UINT32)ControlSize);
03935     AFX_DUMP1(dc, "\nNo Of Slots  = ", (UINT32)NoOfSlots);
03936     AFX_DUMP1(dc, "\nWidth = ", (UINT32)DockSize.cx);
03937     AFX_DUMP1(dc, "\nHeight = ", DockSize.cy);
03938 }
03939 
03940 void OILFixedDockingBar::Dump_List()
03941 {
03942 
03943     CPoint ThisPos;
03944     KernelBarPos * KPos;
03945     
03946     TRACE( _T("FIXED DOCK BAR ----------\n"));
03947     OILChildBar * FoundBar =(OILChildBar *) ChildBars.GetHead();
03948     while (FoundBar != NULL)
03949     {
03950         KPos=FoundBar->GetBarPos();
03951         TRACE( _T("Kernel Data slot - %d  pos - %d DockType - %d\n"),KPos->Slot,KPos->Position,KPos->Dock);
03952         ThisPos=FoundBar->GetPos();
03953         TRACE( _T("Dump Bar    slot - %d  pos - %d\n"),PointToSlot(&ThisPos),PointToPosition(&ThisPos));
03954         FoundBar =(OILChildBar *) ChildBars.GetNext(FoundBar);  
03955     }
03956     TRACE( _T("....................................................................................\n"));
03957 
03958  }
03959 
03960 #endif
03961 
03963 // OILDockingBar diagnostics
03965 
03966 #ifdef _DEBUG
03967 void OILDockingBar::AssertValid() const
03968 {
03969     CControlBar::AssertValid();
03970 }
03971 
03972 void OILDockingBar::Dump(CDumpContext& dc) const
03973 {
03974     CControlBar::Dump(dc);
03975 
03976 }
03977 
03978  void OILDockingBar::Dump_List()
03979  {
03980 
03981  }
03982 
03983 #endif
03984 
03986 // OILFloaters diagnostics
03988 
03989 #ifdef _DEBUG
03990 void OILFloaters::AssertValid() const
03991 {
03992     CControlBar::AssertValid();
03993 }
03994 
03995 void OILFloaters::Dump(CDumpContext& dc) const
03996 {
03997     CControlBar::Dump(dc);
03998 
03999 }
04000 
04001 void OILFloaters::Dump_List()
04002 {
04003     
04004     CPoint ThisPos;
04005     KernelBarPos * KPos;
04006     
04007     TRACE( _T("..... FLOATING BARS  .....\n "));
04008     OILChildBar * FoundBar =(OILChildBar *) ChildBars.GetHead();
04009     while (FoundBar != NULL)
04010     {
04011         KPos=FoundBar->GetBarPos();
04012         TRACE( _T("Kernel Data slot - %d  pos - %d Type - %d\n"),KPos->x,KPos->y,KPos->Dock);
04013         ThisPos=FoundBar->GetPos();
04014         TRACE( _T("Dump Bar Hwnd %d\n"),FoundBar->GetHwnd());
04015         FoundBar =(OILChildBar *) ChildBars.GetNext(FoundBar);  
04016     }
04017     TRACE( _T("..................................................................................\n"));
04018 
04019 }
04020 
04021 #endif
04022 
04023 #endif

Generated on Sat Nov 10 03:48:24 2007 for Camelot by  doxygen 1.4.4