Bugfix : Zooming works correct, no more errors on screen.
[xara-cairo.git] / wxOil / dockbar.cpp
blob02cca1a29b62bae25a58e2c1eb461d38a5b3162b
1 // $Id: dockbar.cpp 1282 2006-06-09 09:46:49Z alex $
2 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
3 ================================XARAHEADERSTART===========================
5 Xara LX, a vector drawing and manipulation program.
6 Copyright (C) 1993-2006 Xara Group Ltd.
7 Copyright on certain contributions may be held in joint with their
8 respective authors. See AUTHORS file for details.
10 LICENSE TO USE AND MODIFY SOFTWARE
11 ----------------------------------
13 This file is part of Xara LX.
15 Xara LX is free software; you can redistribute it and/or modify it
16 under the terms of the GNU General Public License version 2 as published
17 by the Free Software Foundation.
19 Xara LX and its component source files are distributed in the hope
20 that it will be useful, but WITHOUT ANY WARRANTY; without even the
21 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 See the GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License along
25 with Xara LX (see the file GPL in the root directory of the
26 distribution); if not, write to the Free Software Foundation, Inc., 51
27 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 ADDITIONAL RIGHTS
31 -----------------
33 Conditional upon your continuing compliance with the GNU General Public
34 License described above, Xara Group Ltd grants to you certain additional
35 rights.
37 The additional rights are to use, modify, and distribute the software
38 together with the wxWidgets library, the wxXtra library, and the "CDraw"
39 library and any other such library that any version of Xara LX relased
40 by Xara Group Ltd requires in order to compile and execute, including
41 the static linking of that library to XaraLX. In the case of the
42 "CDraw" library, you may satisfy obligation under the GNU General Public
43 License to provide source code by providing a binary copy of the library
44 concerned and a copy of the license accompanying it.
46 Nothing in this section restricts any of the rights you have under
47 the GNU General Public License.
50 SCOPE OF LICENSE
51 ----------------
53 This license applies to this program (XaraLX) and its constituent source
54 files only, and does not necessarily apply to other Xara products which may
55 in part share the same code base, and are subject to their own licensing
56 terms.
58 This license does not apply to files in the wxXtra directory, which
59 are built into a separate library, and are subject to the wxWindows
60 license contained within that directory in the file "WXXTRA-LICENSE".
62 This license does not apply to the binary libraries (if any) within
63 the "libs" directory, which are subject to a separate license contained
64 within that directory in the file "LIBS-LICENSE".
67 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
68 ----------------------------------------------
70 Subject to the terms of the GNU Public License (see above), you are
71 free to do whatever you like with your modifications. However, you may
72 (at your option) wish contribute them to Xara's source tree. You can
73 find details of how to do this at:
74 http://www.xaraxtreme.org/developers/
76 Prior to contributing your modifications, you will need to complete our
77 contributor agreement. This can be found at:
78 http://www.xaraxtreme.org/developers/contribute/
80 Please note that Xara will not accept modifications which modify any of
81 the text between the start and end of this header (marked
82 XARAHEADERSTART and XARAHEADEREND).
85 MARKS
86 -----
88 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
89 designs are registered or unregistered trademarks, design-marks, and/or
90 service marks of Xara Group Ltd. All rights in these marks are reserved.
93 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
94 http://www.xara.com/
96 =================================XARAHEADEREND============================
99 #include "camtypes.h"
100 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED]
101 //#include "dockbar.h" - in camtypes.h [AUTOMATICALLY REMOVED]
102 //#include "childbar.h"
103 #include "camframe.h"
104 //#include "camafx.h"
105 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
106 #include "basebar.h"
108 #define IS_CHICAGO ((LOBYTE(LOWORD(GetVersion()))) > 3)
110 #define MIN_GALLERY_SLOT_WIDTH 100
112 BOOL OILFixedDockingBar::allowTidyBars = TRUE;
114 #if 0
116 /////////////////////////////////////////////////////////////////////////////////////////////
117 // OILDockingBar Base Class //
118 /////////////////////////////////////////////////////////////////////////////////////////////
120 IMPLEMENT_DYNAMIC(OILDockingBar ,CControlBar)
122 #ifdef _DEBUG
123 #undef THIS_FILE
124 static char BASED_CODE THIS_FILE[] = __FILE__;
125 #endif
129 // A pointer to the last dock which has changed size
130 // used to reduce the number of recalc layouts
131 OILDockingBar * OILDockingBar::ChangedDock=NULL;
133 // Flag used as above
134 BOOL OILDockingBar::DoRecalc = FALSE;
136 /////////////////////////////////////////////////////////////////////////////////////////////
137 // OILDockingBar Message Map
138 /////////////////////////////////////////////////////////////////////////////////////////////
140 BEGIN_MESSAGE_MAP( OILDockingBar,CControlBar)
141 //{{AFX_MSG_MAP( OILDockingBar )
142 //}}AFX_MSG_MAP
143 END_MESSAGE_MAP( )
146 /////////////////////////////////////////////////////////////////////////////////////////////
147 // OILDockingBar Creation Destruction and Initialisation
148 /////////////////////////////////////////////////////////////////////////////////////////////
150 /********************************************************************************************
152 > OILDockingBar::OILDockingBar()
154 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
155 Created: 5/3/94
156 Inputs: -
157 Outputs: -
158 Returns: -
159 Purpose: Creates an OILDockingBar object.
160 Errors: -
161 SeeAlso:
163 ********************************************************************************************/
165 OILDockingBar::OILDockingBar()
167 ControlSize=SMALL_CONTROLS;
168 HasBigControls = FALSE;
171 /********************************************************************************************
173 > OILDockingBar::~OILDockingBar()
175 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
176 Created: 5/3/94
177 Inputs: -
178 Outputs: -
179 Returns: -
180 Purpose: Destroys an OILDockingBar object and deletes all BarList items
181 Errors: -
182 SeeAlso:
184 ********************************************************************************************/
186 OILDockingBar::~OILDockingBar()
188 ChildBars.DeleteAll();
192 /******************************************************************************************
193 > void OILDockingBar::OnUpdateCmdUI()
195 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
196 Created: 5/3/94
197 Inputs: -
198 Outputs: -
199 Returns: -
200 Purpose: -
201 Errors: -
202 SeeAlso:
204 ********************************************************************************************/
206 void OILDockingBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
212 /********************************************************************************************
214 > BOOL OILDockingBar::RemoveBar(OILChildBar * ThisBar)
216 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
217 Created: 15/3/94
218 Inputs: -
219 Outputs: -
220 Returns: Succed or Fail
221 Purpose: Remove OILChildBar from List and delete ListItem if successful
222 Errors: -
223 SeeAlso:
225 ********************************************************************************************/
227 BOOL OILDockingBar::RemoveBar(OILChildBar* ThisBar)
229 ERROR2IF(ThisBar ==NULL,FALSE,"Trying to remove a NULL Child Bar");
230 // Remove a child Bar from the list
231 if (ChildBars.RemoveItem((ListItem*)ThisBar)!=NULL)
234 delete ThisBar; // Delete ChildBar object
235 return TRUE;
238 else // Trying to delete an unknown bar
240 ERROR2IF(TRUE,FALSE,"Failed to Remove Child Bar from list");
244 /********************************************************************************************
246 > BOOL OILDockingBar::SetNewHwnd(HWND OldHwnd,HWND NewHwnd)
248 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
249 Created: 15/3/94
250 Inputs: -
251 Outputs: -
252 Returns: TRUE if success FALSE otherwise
253 Purpose: change the hwnd of a bar list item
254 Errors: -
255 SeeAlso:
257 ********************************************************************************************/
259 BOOL OILDockingBar::SetNewHwnd(HWND OldHwnd,HWND NewHwnd)
261 OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead();
262 while (ThisChild != NULL)
265 if (ThisChild->GetHwnd()==OldHwnd) // found the bar
267 ThisChild->SetHwnd(NewHwnd);
268 return TRUE;
270 ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);
272 }// end while
273 ENSURE(ThisChild!=NULL,"Couldn't find HWND in BarList");
274 return FALSE;
278 /********************************************************************************************
280 > OILChildBar * OILDockingBar::IsBarInList(HWND)
282 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
283 Created: 15/3/94
284 Inputs: -
285 Outputs: -
286 Returns: Found Child or NULL
287 Purpose: determine whether a childbar is in this docks list
288 Errors: -
289 SeeAlso:
291 ********************************************************************************************/
293 OILChildBar * OILDockingBar::IsBarInList(HWND hwnd)
295 OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead();
296 while (ThisChild != NULL)
299 if (ThisChild->GetHwnd()==hwnd) // found the bar
300 return ThisChild;
302 ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);
304 }// end while
306 return NULL;
309 /********************************************************************************************
311 > OILChildBar * OILDockingBar::IsBarInList(StringBase * Name )
313 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
314 Created: 15/3/94
315 Inputs: -
316 Outputs: -
317 Returns: Found Child or NULL
318 Purpose: determine whether a childbar is in this docks list
319 Errors: -
320 SeeAlso:
322 ********************************************************************************************/
324 OILChildBar * OILDockingBar::IsBarInList(StringBase *Name)
326 OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead();
327 while (ThisChild != NULL)
329 char buff[64];
330 ::GetWindowText(ThisChild->GetHwnd(),buff,63);
331 if (String_32(buff)== *Name) // found the bar
332 return ThisChild;
334 ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);
336 }// end while
338 return NULL;
340 /********************************************************************************************
342 > HWND OILDockingBar::IsScreenPointInBar(CPoint pnt)
344 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
345 Created: 15/3/94
346 Inputs: -
347 Outputs: -
348 Returns: Found HWND or NULL
349 Purpose: determine whether a screen point is in a childbar of this dock
350 Errors: -
351 SeeAlso:
353 ********************************************************************************************/
355 HWND OILDockingBar::IsScreenPointInBar(CPoint pnt)
358 OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead();
359 HWND hwnd;
360 while (ThisChild != NULL)
362 if (hwnd = ThisChild->GetHwnd()) // found the bar
364 CRect sRect;
365 ::GetWindowRect(hwnd,&sRect);
366 if(sRect.PtInRect(pnt))
368 return hwnd;
371 ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);
372 }// end while
374 return NULL;
376 /********************************************************************************************
378 > KernelBarPos * OILDockingBar::GetBarPos(HWND)
380 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
381 Created: 15/3/94
382 Inputs: -
383 Outputs: -
384 Returns: Found Position
385 Purpose: To return a Pointer to the KernelBarPos of a Child dialogbar
386 Errors: -
387 SeeAlso:
389 ********************************************************************************************/
391 KernelBarPos * OILDockingBar::GetBarPos(HWND hwnd)
393 OILChildBar * ThisChild;
394 if ((ThisChild=IsBarInList(hwnd))!=NULL)
396 return ThisChild->GetBarPos();
397 else
399 return NULL;
403 /********************************************************************************************
405 > CRect OILDockingBar::GetBarRect(StringBase * Name)
407 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
408 Created: 15/3/94
409 Inputs: -
410 Outputs: -
411 Returns: Found Position
412 Purpose: To return the rectangle of the specified bar
413 Errors: -
414 SeeAlso:
416 ********************************************************************************************/
418 CRect OILDockingBar::GetBarRect(StringBase * Name)
420 OILChildBar * ThisChild;
421 if ((ThisChild=IsBarInList(Name))!=NULL)
422 return ThisChild->GetRectFromBar();
423 else
424 return CRect(0, 0, 0, 0);
429 /****************************************************************************
431 > CRect OILDockingBar::GetBarRect(HWND hwnd)
433 Author: Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
434 Created: 01/12/2004
436 Inputs: hwnd -
437 Returns:
438 Purpose: To return the rectangle of the specified bar
440 ****************************************************************************/
442 CRect OILDockingBar::GetBarRect(HWND hwnd)
444 OILChildBar * ThisChild;
445 if ((ThisChild=IsBarInList(hwnd))!=NULL)
446 return ThisChild->GetRectFromBar();
447 else
448 return CRect(0, 0, 0, 0);
452 /********************************************************************************************
454 > KernelBarPos * OILDockingBar::GetBarPos(StringBase * Name)
456 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
457 Created: 15/3/94
458 Inputs: -
459 Outputs: -
460 Returns: Found Position
461 Purpose: To return a Pointer to the KernelBarPos of a Child dialogbar
462 Errors: -
463 SeeAlso:
465 ********************************************************************************************/
467 KernelBarPos * OILDockingBar::GetBarPos(StringBase * Name)
469 OILChildBar * ThisChild;
470 if ((ThisChild=IsBarInList(Name))!=NULL)
472 return ThisChild->GetBarPos();
473 else
475 return NULL;
478 /********************************************************************************************
480 > void OILDockingBar::SetBigControlState(BOOL Big)
482 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
483 Created: 5/3/94
484 Inputs: -
485 Outputs: -
486 Returns: -
487 Purpose: Sets Big Control state
488 Errors: -
489 SeeAlso:
491 ********************************************************************************************/
493 void OILDockingBar::SetBigControlState(BOOL Big )
495 HasBigControls = Big;
496 if (Big)
497 ControlSize=LARGE_CONTROLS;
498 else
499 ControlSize=SMALL_CONTROLS;
501 // tell all child windows that control sizes have changed
502 OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead();
503 while (ThisChild != NULL)
505 ThisChild->Resize(ControlSize);
506 ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);
507 }// end while
511 /********************************************************************************************
513 > BOOL OILDockingBar::IsBigControls()
515 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
516 Created: 5/4/94
517 Inputs: -
518 Outputs: -
519 Returns: True if BigControls
520 Purpose: Determines whether DockingBar contains large controls
521 Errors: -
522 SeeAlso:
524 ********************************************************************************************/
526 BOOL OILDockingBar::IsBigControls()
529 return HasBigControls;
534 /////////////////////////////////////////////////////////////////////////////////////////////
535 // OILFixedDockingBar
536 /////////////////////////////////////////////////////////////////////////////////////////////
539 IMPLEMENT_DYNAMIC(OILFixedDockingBar ,OILDockingBar)
543 /////////////////////////////////////////////////////////////////////////////////////////////
544 // OILFixedDockingBar Message Map
545 /////////////////////////////////////////////////////////////////////////////////////////////
547 BEGIN_MESSAGE_MAP( OILFixedDockingBar, OILDockingBar )
548 //{{AFX_MSG_MAP( OILFixedDockingBar )
549 ON_MESSAGE(WM_SIZEPARENT, OnSizeParent)
550 //}}AFX_MSG_MAP
551 END_MESSAGE_MAP( )
553 /********************************************************************************************
555 > BOOL OILFixedDockingBar::Create(CWnd* pParentWnd,DockBarType ReqType, UINT32 id)
557 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
558 Created: 5/3/94
559 Inputs: -
560 Outputs: -
561 Returns: -
562 Purpose: Creates the OILDockingBar window.
563 Errors: -
564 SeeAlso:
566 ********************************************************************************************/
568 BOOL OILFixedDockingBar::Create(CWnd* pParentWnd,DockBarType ReqType, UINT32 id)
570 // BackBrush.CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
571 BOOL CreatedWindow;
572 ENSURE(pParentWnd,"DockingBar must have a Parent");
574 ENSURE((ReqType == DOCKBAR_LEFT) ||
575 (ReqType == DOCKBAR_RIGHT) ||
576 (ReqType == DOCKBAR_TOP) ||
577 (ReqType == DOCKBAR_BOTTOM),
578 "OILFIxedDockingBar constructor: Invalid DockingBar type");
580 DockType=ReqType; // Type of this instance
581 Parent=pParentWnd; // Parent of this bar
582 CRect rect; // Rectangle for Create
583 rect.SetRectEmpty();
585 #if _MSC_VER < 1200
586 #ifndef WIN32
587 DWORD
588 #endif
589 m_dwStyle = WS_CHILD|WS_VISIBLE |WS_CLIPCHILDREN;
590 #else
591 // VC6 doesn't like any style flags other than CBRS_ flags set
592 // for CControlBar-derived windows
593 m_dwStyle = 0;
594 #endif // _MSC_VER
596 // create the HWND
597 CreatedWindow = CWnd::Create(NULL,
599 m_dwStyle,
600 rect,Parent,
601 id, NULL);
604 #if _MSC_VER >= 1200
605 // Must make the control bar visible in VC6 builds
606 ShowWindow(SW_SHOW);
607 #endif // _MSC_VER
609 return CreatedWindow;
614 /********************************************************************************************
616 > OILFixedDockingBar::OILFixedDockingBar()
618 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
619 Created: 5/3/94
620 Inputs: -
621 Outputs: -
622 Returns: -
623 Purpose: Creates an OILDockingBar object.
624 Errors: -
625 SeeAlso:
627 ********************************************************************************************/
629 OILFixedDockingBar::OILFixedDockingBar()
631 NoOfSlots = 0;
632 ControlSize = SMALL_CONTROLS;
633 HasBigControls = FALSE;
634 DockSize.cy = DockSize.cx = 0;
635 Position.x = Position.y = -1;
636 allowTidyBars = TRUE;
637 for (INT32 i = 0; i < MAX_SLOTS; i++)
638 SlotSize[i] = SMALL_CONTROLS;
641 /********************************************************************************************
643 > BOOL OILFixedDockingBar::DeleteBars()
645 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
646 Created: 5/3/94
647 Inputs: -
648 Outputs: -
649 Returns: -
650 Purpose: deletes all BarList items
651 Errors: -
652 SeeAlso:
654 ********************************************************************************************/
656 BOOL OILFixedDockingBar::DeleteBars()
658 NoOfSlots = 0;
659 for (INT32 i = 0; i < MAX_SLOTS; i++)
660 SlotSize[i] = ControlSize;
661 DockSize.cy = DockSize.cx = 0;
662 Position.x = Position.y = -1;
663 ChildBars.DeleteAll();
664 return TRUE;
667 /////////////////////////////////////////////////////////////////////////////////////////////
668 // Message Handling
669 ////////////////////////////////////////////////////////////////////////////////////////////
672 /********************************************************************************************
674 > void OILFixedDockingBar::DoPaint(WPARAM, LPARAM lParam)
676 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
677 Created: 5/3/94
678 Inputs: pointer to a device context
679 Outputs: -
680 Returns: -
681 Purpose: Paints docking bar background and border
682 Errors: -
683 SeeAlso:
685 ********************************************************************************************/
686 void OILFixedDockingBar::DoPaint(CDC* pDC)
689 ASSERT_VALID(pDC);
691 CRect rect;
692 GetClientRect(rect); // get the size of this bar
693 CBrush hbrFrame (GetSysColor(COLOR_BTNFACE));
696 COLORREF Outline;
697 if(IS_CHICAGO)
698 Outline = GetSysColor(COLOR_BTNSHADOW);
699 else
700 Outline = GetSysColor(COLOR_WINDOWFRAME);
702 CPen hpen(PS_SOLID,1,Outline);
704 // paint bodge to avoid double lines
706 CBrush * hOldBrush = pDC->SelectObject(&hbrFrame);
707 CPen * hOldPen = pDC->SelectObject(&hpen);
709 //pDC->FillRect(&rect,&hbrFrame);
712 switch (DockType)
715 case DOCKBAR_LEFT:
716 pDC->Rectangle(rect.left-1,rect.top-1,rect.right,rect.bottom+1);
717 break;
718 case DOCKBAR_TOP:
719 pDC->Rectangle(rect.left-1,rect.top-1,rect.right+1,rect.bottom);
720 break;
721 case DOCKBAR_RIGHT:
722 pDC->Rectangle(rect.left,rect.top-1,rect.right+1,rect.bottom+1);
723 break;
724 case DOCKBAR_BOTTOM:
725 pDC->Rectangle(rect.left-1,rect.top,rect.right+1,rect.bottom+1);
726 break;
730 pDC->SelectObject(hOldBrush);
731 pDC->SelectObject(hOldPen);
735 /********************************************************************************************
737 > void OILFixedDockingBar::RepositionWindow(AFX_SIZEPARENTPARAMS FAR* lpLayout,
738 HWND hWnd, LPCRECT lpRect)
740 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
741 Created: 6/9/94
742 Inputs: -
743 Outputs: -
744 Returns: -
745 Purpose: Is called from OnSizeParent to reposition the docking bars - replacing
746 Afx_RepositionWindow which forces a total redraw !
747 Errors: -
749 ********************************************************************************************/
752 void OILFixedDockingBar::RepositionWindow(AFX_SIZEPARENTPARAMS FAR* lpLayout,
753 HWND hWnd, LPCRECT lpRect)
756 if(hWnd == NULL)
758 ENSURE(FALSE,"Reposition NULL Window ");
759 return ;
761 if(lpRect == NULL)
763 ENSURE(FALSE,"NULL Reposition Rectangle");
764 return;
767 CRect InvalRect(0,0,0,0);
769 CRect Check(lpRect);
770 // check whether this is an empty bar
771 BOOL Empty = Check.Width() == 0 || Check.Height() == 0;
773 // Reposition the window but dont force a redraw
774 // we use SetWindowPos rather than DeferWindowPos - this allows us
775 // to position the window and then invalidate a part of it
777 if (!Empty) // calculate a rectangle to invalidate
779 CRect rectOld;
780 GetWindowRect(rectOld); //old window position in screen coords
781 GetParent()->ClientToScreen(&Check);
783 // no change - get out of here
784 if(Check==rectOld)
785 return ;
787 switch (DockType)
789 case DOCKBAR_TOP:
790 if(Check.left == rectOld.left)
792 if (Check.right > rectOld.right )
793 InvalRect.SetRect(rectOld.right,Check.top,Check.right,Check.bottom);
794 else if(Check.right < rectOld.right )
795 InvalRect.SetRect(Check.right,Check.top,rectOld.right,Check.bottom);
796 else
797 InvalRect.SetRect(Check.left,Check.top,rectOld.right,Check.bottom);
799 else //do whole area
801 InvalRect.SetRect(min(rectOld.left,Check.left),
802 min(rectOld.top,Check.top),
803 max(rectOld.right,Check.right),
804 max(rectOld.bottom,Check.bottom));
806 break;
807 case DOCKBAR_BOTTOM:
808 if( Check.left != rectOld.left || Check.top != rectOld.top)
809 InvalRect.SetRect(Check.left,Check.top,Check.right,Check.bottom);
810 else
811 InvalRect.SetRect(rectOld.right,Check.top,Check.right,Check.bottom);
813 break;
814 case DOCKBAR_LEFT:
815 if(Check.top == rectOld.top)
817 if (Check.bottom > rectOld.bottom )
818 InvalRect.SetRect(Check.left,rectOld.bottom,Check.right,Check.bottom);
819 else
820 InvalRect.SetRect(Check.left,Check.bottom,Check.right,rectOld.bottom);
822 else //do whole area
824 InvalRect.SetRect(min(rectOld.left,Check.left),
825 min(rectOld.top,Check.top),
826 max(rectOld.right,Check.right),
827 max(rectOld.bottom,Check.bottom));
829 break;
830 case DOCKBAR_RIGHT:
831 if( Check.left != rectOld.left || Check.top != rectOld.top)
832 InvalRect.SetRect(Check.left,Check.top,Check.right,Check.bottom);
833 else
834 InvalRect.SetRect(Check.left,rectOld.bottom,Check.right,Check.bottom);
835 break;
836 case DOCKBAR_FLOAT:
837 InvalRect.SetRect(rectOld.left,rectOld.bottom,rectOld.right,rectOld.bottom);
838 break;
842 SetWindowPos(NULL, lpRect->left,
843 lpRect->top, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top,
844 SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOREDRAW);
847 if(!Empty)
849 // we need a touch of bit twiddling here to make sure that
850 // paint messages are sent out to the dock and their bars
851 INT32 OldStyle = ::GetWindowLong(hWnd,GWL_STYLE);
852 ::SetWindowLong(hWnd,GWL_STYLE,OldStyle & ~WS_CLIPCHILDREN);
854 //Convert back to parent coords
855 GetParent()->ScreenToClient(&InvalRect);
857 // invalidate 'new' area
858 GetParent()->InvalidateRect(&InvalRect,FALSE);
859 GetParent()->UpdateWindow();
861 // set the style back to it's original state
862 ::SetWindowLong(hWnd,GWL_STYLE,OldStyle);
866 /********************************************************************************************
868 > LRESULT OILFixedDockingBar::OnSizeParent(WPARAM, LPARAM lParam)
870 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
871 Created: 10/3/94
872 Inputs: -
873 Outputs: -
874 Returns: -
875 Purpose: Afx private Message - Resizes Docking Bar and Parent MDIClient Window
876 Errors: -
877 SeeAlso: MFC\src\barcore.ccp - MFC TechNote 24
879 ********************************************************************************************/
882 LRESULT OILFixedDockingBar::OnSizeParent(WPARAM, LPARAM lParam)
884 AFX_SIZEPARENTPARAMS FAR* lpLayout = (AFX_SIZEPARENTPARAMS FAR*)lParam;
885 CRect rect(0,0,0,0);
886 CRect LayoutRect(lpLayout->rect);
888 SetSize(LayoutRect,&rect);
890 switch (DockType)
893 case DOCKBAR_LEFT:
894 lpLayout->rect.left += TotalSlotSizes();// left-hand side of this window
895 // if(IS_CHICAGO)
896 // lpLayout->rect.left--;
897 break;
898 case DOCKBAR_RIGHT:
899 lpLayout->rect.right -= TotalSlotSizes();// right-hand side of this window
900 break;
901 case DOCKBAR_TOP:
902 lpLayout->rect.top += TotalSlotSizes();// top of this window
903 // if(IS_CHICAGO)
904 // lpLayout->rect.top--;
905 break;
906 case DOCKBAR_BOTTOM:
907 lpLayout->rect.bottom -= TotalSlotSizes();// bottom of this window
908 // if(IS_CHICAGO)
909 // lpLayout->rect.bottom ++;
910 break;
911 default:
912 ENSURE(0, "Unknown Dockingbar type!");
913 break;
916 // call our Reposition window for more redraw control
917 //_Afx
918 RepositionWindow(lpLayout, m_hWnd, &rect);
919 return 0;
924 /////////////////////////////////////////////////////////////////////////////////////////////
925 // OILFixedDocking Bar General Functions
926 /////////////////////////////////////////////////////////////////////////////////////////////
929 INT32 OILFixedDockingBar::TotalSlotSizes(INT32 Slot /* = -1 */)
931 if (Slot == -1)
932 Slot = NoOfSlots;
934 // Sum slot sizes
935 INT32 TotalSize = 0;
936 for (INT32 i = 0; i < Slot; i++)
937 TotalSize += SlotSize[i];
939 return(TotalSize);
942 /********************************************************************************************
944 > void OILFixedDockingBar::SetBigControlState(BOOL Big)
946 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
947 Created: 5/3/94
948 Inputs: -
949 Outputs: -
950 Returns: -
951 Purpose: Sets Big Control state
952 Errors: -
953 SeeAlso:
955 ********************************************************************************************/
957 void OILFixedDockingBar::SetBigControlState(BOOL Big )
959 // check that state has actually changed
960 if (Big != HasBigControls )
962 ::LockWindowUpdate(GetMainFrame()->GetSafeHwnd());
963 HasBigControls = Big;
964 ControlSizes NewSize;
965 if (Big)
966 NewSize = LARGE_CONTROLS;
967 else
968 NewSize = SMALL_CONTROLS;
970 // Set any slots that are the old size to new size
971 // TODOG: This needs to change
972 for (INT32 i = 0; i < MAX_SLOTS; i++)
974 if (SlotSize[i] == ControlSize)
975 SlotSize[i] = NewSize;
977 // for (INT32 i = 0; i < MAX_SLOTS; i++)
978 // {
979 // SlotSize[i] = NewSize;
980 // }
982 // Call the base class to update the ControlSize member
983 // and resize the child bars
984 OILDockingBar::SetBigControlState(Big);
986 // have to be a bit careful here DialogBar will delete and add new items
987 // to this list when it receives the RESIZECONTROLS Message
988 OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead();
989 OILChildBar * Next;
990 OILChildBar * EndList =(OILChildBar *) ChildBars.GetTail();
992 while (ThisChild != NULL)
994 Next =(OILChildBar *) ChildBars.GetNext(ThisChild);
995 ::SendMessage(ThisChild->GetHwnd(), WM_RESIZECONTROLS, 0,0);
996 ThisChild = Next;
997 if (ThisChild == NULL)
998 break;
999 if (ThisChild == EndList)
1001 ::SendMessage(ThisChild->GetHwnd(), WM_RESIZECONTROLS, 0,0);
1002 break;
1006 // update the bars for the new slot sizes
1007 ThisChild =(OILChildBar *) ChildBars.GetHead();
1008 while (ThisChild != NULL)
1010 ThisChild->UpdatePos();
1011 ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);
1014 // check for any overlap
1015 if (Big)
1016 CheckAndCorrectOverlap();
1018 ::LockWindowUpdate(NULL);
1019 ((CFrameWnd*)Parent)->RecalcLayout();
1023 /********************************************************************************************
1025 > BOOL OILFixedDockingBar::IsScreenPointinDock(CPoint here)
1027 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1028 Created: 30/3/94
1029 Inputs: Screen Point
1030 Outputs: -
1031 Returns: TRUE/FALSE
1032 Purpose: determines whether a screen point is currently in or near a fixed dockingbar
1033 Errors: -
1034 SeeAlso:
1036 ********************************************************************************************/
1038 BOOL OILFixedDockingBar::IsScreenPointInDock(CPoint here)
1040 CRect rect(0,0,DockSize.cx,DockSize.cy);
1041 // virtual rectangle to give a positive hit when the
1042 // real window has no size
1043 if (NoOfSlots==0)
1045 switch (DockType)
1047 case DOCKBAR_LEFT:
1048 rect.right = ControlSize;
1049 break;
1050 case DOCKBAR_RIGHT:
1051 rect.left = - (INT32)ControlSize;
1052 break;
1053 case DOCKBAR_TOP:
1054 rect.bottom = ControlSize;
1055 break;
1056 case DOCKBAR_BOTTOM:
1057 rect.top = - (INT32)ControlSize;
1058 break;
1061 ClientToScreen(&rect);
1062 return rect.PtInRect(here);
1067 /********************************************************************************************
1069 > void OILFixedDockingBar::GetDockScreenRect(CRect * BarRect)
1071 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1072 Created: 30/3/94
1073 Inputs: Screen rect
1074 Outputs: -
1075 Returns: -
1076 Purpose: determines whether a screen rectangle intersects a fixed dockingbar
1077 Errors: -
1078 SeeAlso:
1080 ********************************************************************************************/
1082 void OILFixedDockingBar::GetDockScreenRect(CRect * BarRect)
1084 CRect rect ;
1085 GetClientRect(&rect);
1086 ClientToScreen(&rect); //screen coords of this dock
1087 BarRect->CopyRect(rect);
1094 /********************************************************************************************
1096 > BOOL OILFixedDockingBar::IsScreenRectInDock(CRect BarRect)
1098 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1099 Created: 30/3/94
1100 Inputs: Screen rect
1101 Outputs: -
1102 Returns: TRUE/FALSE
1103 Purpose: determines whether a screen rectangle intersects a fixed dockingbar
1104 Errors: -
1105 SeeAlso:
1107 ********************************************************************************************/
1109 BOOL OILFixedDockingBar::IsScreenRectInDock(CRect BarRect)
1112 CRect rect(0,0,DockSize.cx,DockSize.cy);
1113 if (NoOfSlots==0) //docking bar has no width/height
1116 switch (DockType) //make a rectangle for the intersection test
1118 case DOCKBAR_LEFT:
1119 case DOCKBAR_RIGHT:
1120 rect.right = 1;
1121 break;
1122 case DOCKBAR_TOP:
1123 case DOCKBAR_BOTTOM:
1124 rect.bottom = 1;
1125 break;
1129 ClientToScreen(&rect); //screen coords of this dock
1130 rect&=BarRect; //do intersection
1131 return !(rect.IsRectEmpty());
1136 /********************************************************************************************
1138 > void OILFixedDockingBar::SetSize()
1140 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1141 Created: 10/3/94
1142 Inputs: MDIClient area
1143 Outputs: new bar size
1144 Returns: -
1145 Purpose: Sizes a DockingBar Window according to type and the MainFrame Client Window .
1146 Errors: -
1147 SeeAlso:
1149 ********************************************************************************************/
1151 void OILFixedDockingBar::SetSize(CRect ClientRect,CRect * rect)
1154 rect->CopyRect(&ClientRect); // Copy MDIFrame Rect into target rect
1155 switch (DockType) // now size according to type
1158 case DOCKBAR_LEFT:
1159 rect->right =ClientRect.left + TotalSlotSizes();
1160 break;
1161 case DOCKBAR_RIGHT:
1162 rect->left = ClientRect.right - TotalSlotSizes();
1163 break;
1164 case DOCKBAR_TOP:
1165 rect->bottom = ClientRect.top + TotalSlotSizes();
1166 break;
1167 case DOCKBAR_BOTTOM:
1168 rect->top = ClientRect.bottom - TotalSlotSizes();
1169 break;
1172 //Keep a record of Bar size
1173 DockSize.cx=rect->right-rect->left;
1174 DockSize.cy=rect->bottom-rect->top;
1177 /********************************************************************************************
1179 > INT32 OILFixedDockingBar::PointToSlot(CPoint ThisPoint);
1181 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1182 Created: 10/3/94
1183 Inputs: a point
1184 Outputs: -
1185 Returns: slot number according to dock type
1186 Purpose: determine Slot number according to DockType given a Client Coord
1187 Errors: -
1188 SeeAlso:
1190 ********************************************************************************************/
1192 INT32 OILFixedDockingBar::PointToSlot(CPoint* ThisPoint)
1194 if (ControlSize == 0)
1195 return(0);
1197 INT32 Value = 0;
1198 // return a slot number according to dock type and control size
1199 switch (DockType)
1201 case DOCKBAR_TOP:
1202 case DOCKBAR_BOTTOM:
1203 Value = ThisPoint->y;
1204 break;
1206 case DOCKBAR_LEFT:
1207 case DOCKBAR_RIGHT:
1208 Value = ThisPoint->x;
1209 break;
1212 INT32 Total = 0;
1213 // Loop through slots until size totals more than coord
1214 for (INT32 i = 0; i < MAX_SLOTS; i++)
1216 Total += SlotSize[i];
1217 if (Total > Value)
1218 return(i);
1221 return(0);
1225 /********************************************************************************************
1227 > void OILFixedDockingBar::BarPosToClient();
1229 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1230 Created: 10/3/94
1231 Inputs: a point
1232 Outputs: Client x/y given slot and position
1233 Returns: -
1234 Purpose: determine Client coordinate in dock from a KernelBarPos
1235 Errors: -
1236 SeeAlso:
1238 ********************************************************************************************/
1240 void OILFixedDockingBar::BarPosToClient(KernelBarPos Pos,CPoint * Point)
1242 // return a slot number according to dock type and control size
1243 switch (DockType)
1245 case DOCKBAR_TOP:
1246 case DOCKBAR_BOTTOM:
1247 Point->x = Pos.Position;
1248 Point->y = TotalSlotSizes(Pos.Slot);
1249 break;
1251 case DOCKBAR_LEFT:
1252 case DOCKBAR_RIGHT:
1253 Point->y = Pos.Position;
1254 Point->x = TotalSlotSizes(Pos.Slot);
1255 break;
1259 /********************************************************************************************
1261 > void OILFixedDockingBar::BarPosToScreen(KernelBarPos Pos,CPoint * Point);
1263 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1264 Created: 10/3/94
1265 Inputs: a point
1266 Outputs: Screen x/y given slot and position
1267 Returns: -
1268 Purpose: determine Screen coordinate in dock from a KernelBarPos
1269 Errors: -
1270 SeeAlso:
1272 ********************************************************************************************/
1274 void OILFixedDockingBar::BarPosToScreen(KernelBarPos Pos,CPoint * Point)
1276 BarPosToClient(Pos, Point); // Get the client position
1277 ClientToScreen(Point); // And convert to screen coords
1280 /********************************************************************************************
1282 > INT32 OILFixedDockingBar::PointToPosition()
1284 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1285 Created: 10/3/94
1286 Inputs: CPoint
1287 Outputs: -
1288 Returns: position in slot according to dock type
1289 Purpose: determine pixel offset inslot according to Docktype given a client coord
1290 Errors: -
1291 SeeAlso:
1293 ********************************************************************************************/
1295 INT32 OILFixedDockingBar::PointToPosition(CPoint* ThisPoint)
1297 //return pixel offset in slot according to dock type
1298 switch (DockType)
1300 case DOCKBAR_TOP:
1301 case DOCKBAR_BOTTOM:
1302 return ThisPoint->x;
1303 break;
1305 case DOCKBAR_LEFT:
1306 case DOCKBAR_RIGHT:
1307 return ThisPoint->y;
1308 break;
1310 return 0;
1315 ////////////////////////////////////////////////////////////////////////////////////////////
1316 // Child Bar Placement
1317 ////////////////////////////////////////////////////////////////////////////////////////////
1319 /********************************************************************************************
1321 > INT32 OILFixedDockingBar::GetIntersectPercent(OILChildbar * ThisBar)
1323 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1324 Created: 15/3/94
1325 Inputs: -
1326 Outputs: -
1327 Returns: Percentage of interesect area with other bars in this dock
1328 Purpose:
1329 Errors: -
1330 SeeAlso:
1332 ********************************************************************************************/
1334 INT32 OILFixedDockingBar::GetIntersectPercent(OILChildBar * ThisBar)
1337 CRect CheckRect;
1338 CRect TempNew;
1339 CRect ThisRect = ThisBar->GetRectClient();
1340 CPoint ThisPoint = ThisBar->GetPos();
1342 INT32 ThisArea = ThisRect.right*ThisRect.bottom;
1343 INT32 FoundArea = 0;
1344 CSize FoundSize;
1346 OILChildBar* ThisChild = (OILChildBar *) ChildBars.GetHead();
1347 while (ThisChild != NULL)
1349 if (ThisBar != ThisChild) // Dont check against itself !!
1351 TempNew = ThisRect+ThisPoint; // New bar rect + point offset
1352 // this will be overwritten by the &= operation
1353 CheckRect = ThisChild->GetRectClient()+ThisChild->GetPos();// Found bar origin +point offset
1354 TempNew &= CheckRect; // Intersection of Found and New Bar
1355 if (!TempNew.IsRectEmpty()) // Check for overlap
1357 FoundSize = TempNew.Size();
1358 FoundArea += FoundSize.cx*FoundSize.cy; // total area so far
1362 ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);
1365 if (ThisArea==0)
1366 return 0;
1368 return (INT32) ceill(((float)(FoundArea*100))/(float)ThisArea);// return percentage overlap
1372 /********************************************************************************************
1374 > void OILFixedDockingBar::PutInSlot(CPoint * point, INT32 Size)
1376 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1377 Created: 15/3/94
1378 Inputs: -
1379 Outputs: pointer to new bar slot position
1380 Returns: -
1381 Purpose: snap an x or y coordinate to nearest slot
1382 Errors: -
1383 SeeAlso:
1385 ********************************************************************************************/
1387 void OILFixedDockingBar::PutInSlot(CPoint* position, INT32 Size)
1389 // TRACE( _T("PutInSlot x - %d y - %d\n"), position->x, position->y);
1391 INT32 PointSlot = PointToSlot(position);
1392 // TRACE( _T("PointSlot = %d\n"), PointSlot);
1393 INT32 SlotStart = TotalSlotSizes(PointSlot);
1394 // TRACE( _T("SlotStart = %d\n"), SlotStart);
1395 INT32 MidPoint = SlotStart + (SlotSize[PointSlot] / 2);
1397 INT32 BarMidPoint = 0;
1398 // TRACE( _T("MidPoint = %d\n"), MidPoint);
1399 INT32 SlotEnd = SlotStart + SlotSize[PointSlot];
1400 // TRACE( _T("SlotEnd = %d\n"), SlotEnd);
1402 switch (DockType)
1404 case DOCKBAR_BOTTOM: // snap y to nearest slot
1405 case DOCKBAR_TOP:
1406 BarMidPoint = position->y + (Size / 2);
1407 if (position->x < 0)
1408 position->x = 0;
1410 if (position->y < MidPoint)
1412 position->y = SlotStart;
1414 else
1416 position->y = SlotStart + SlotSize[PointSlot];
1418 break;
1420 case DOCKBAR_LEFT: // snap y to nearest slot
1421 case DOCKBAR_RIGHT:
1422 BarMidPoint = position->x + (Size / 2);
1424 if (position->y < 0)
1425 position->y = 0;
1427 if (BarMidPoint < SlotEnd)
1429 position->x = SlotStart;
1431 else
1433 position->x = SlotStart + SlotSize[PointSlot];
1436 /* if (position->x < MidPoint)
1438 position->x = SlotStart;
1440 else
1442 position->x = SlotStart + SlotSize[PointSlot];
1444 break;
1446 // TRACE( _T("NewPos x - %d y - %d\n"), position->x, position->y);
1449 /********************************************************************************************
1451 > OILFixedDockingBar::ShiftBarPos(CPoint * position, INT32 Amount)
1453 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1454 Created: 15/3/94
1455 Inputs:
1456 Outputs: -
1457 Returns: Success / Fail
1458 Purpose: Shift a bar by given amount - checks new position is in dock bounds
1459 note this means the current visible size of the dock
1460 Errors: -
1461 SeeAlso:
1463 ********************************************************************************************/
1465 BOOL OILFixedDockingBar::ShiftBarPos(CPoint * position, INT32 Amount)
1467 INT32 NewPos;
1469 switch (DockType)
1471 case DOCKBAR_LEFT: // check that new position is within dockbar
1472 case DOCKBAR_RIGHT:
1473 NewPos = position->y + Amount; // shift y position
1474 if (NewPos < 0 || NewPos >= DockSize.cy) // test bounds
1475 return FALSE; // outside dock
1476 position->y = NewPos; // OK set position
1477 break;
1479 case DOCKBAR_TOP:
1480 case DOCKBAR_BOTTOM:
1481 NewPos = position->x + Amount;
1482 if (NewPos < 0 || NewPos >= DockSize.cx)
1483 return FALSE;
1484 position->x = NewPos; // OK set position
1485 break;
1488 return TRUE;
1491 /********************************************************************************************
1493 > OILFixedDockingBar::ShiftBarSlot(CPoint * position, INT32 NoSlots)
1495 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1496 Created: 3/5/94
1497 Inputs:
1498 Outputs: -
1499 Returns: Success / Fail
1500 Purpose: Shift a bar by the given number of slots
1501 Errors: -
1502 SeeAlso:
1504 ********************************************************************************************/
1506 BOOL OILFixedDockingBar::ShiftBarSlot(CPoint* position, INT32 NoSlots)
1508 INT32 StartSlot = PointToSlot(position);
1509 INT32 NewPos = TotalSlotSizes(NoSlots + StartSlot);
1511 switch (DockType)
1513 case DOCKBAR_LEFT:
1514 case DOCKBAR_RIGHT:
1515 position->x = NewPos; // OK set position
1516 break;
1518 case DOCKBAR_TOP:
1519 case DOCKBAR_BOTTOM:
1520 position->y = NewPos; // OK set position
1521 break;
1524 return TRUE;
1527 /********************************************************************************************
1529 > OILFixedDockingBar::CheckAndCorrectOverlap()
1531 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1532 Created: 24/4/94
1533 Inputs: -
1534 Outputs: -
1535 Returns: -
1536 Purpose: To tidy up any posible overlap after changing the size of the bars
1537 ( between Small/Large controls etc..)
1538 Errors: -
1539 SeeAlso: -
1541 ********************************************************************************************/
1543 void OILFixedDockingBar::CheckAndCorrectOverlap()
1545 DoRecalc = FALSE ;
1546 INT32 RightOfLastBar = 0;
1547 INT32 ThisBarStart = 0;
1548 INT32 ThisSlot = 0;
1549 INT32 LastSlot = 0;
1550 INT32 AmountToMove = 0;
1551 BOOL TidyUpSlots = FALSE ;
1552 INT32 index=0;
1554 OILChildBar * ThisChild = (OILChildBar *) ChildBars.GetHead();
1555 if (ThisChild == NULL)
1556 return ;
1557 CPoint ThisPos = ThisChild->GetPos();
1558 RightOfLastBar = PointToPosition( &ThisPos ) + ThisChild->GetExtent();
1559 LastSlot = PointToSlot( &ThisPos );
1561 while (ThisChild != NULL)
1563 // get next bar
1564 ThisChild = (OILChildBar *) ChildBars.GetNext( ThisChild );
1566 // end of list
1567 if (ThisChild == NULL)
1568 break;
1570 // get positional info on this bar
1571 ThisPos = ThisChild->GetPos();
1572 ThisBarStart = PointToPosition( &ThisPos );
1573 ThisSlot = PointToSlot( &ThisPos );
1575 if ( ThisSlot == LastSlot )
1577 // calculate overlap
1578 AmountToMove = RightOfLastBar-ThisBarStart;
1580 // check for overlap
1581 if ( AmountToMove > 0 )
1583 // can we move this bar within this slot ?
1584 if (ShiftBarPos( &ThisPos, AmountToMove ))
1586 ThisChild->SetPos( ThisPos );
1588 else
1590 // Insert a slot and move there
1591 InsertSlot( ThisSlot + 1 );
1592 ShiftBarSlot( &ThisPos,1 );
1593 ThisChild->SetPos( ThisPos );
1594 TidyUpSlots = TRUE;
1595 RightOfLastBar = ThisBarStart = 0;
1600 RightOfLastBar = PointToPosition( &ThisPos ) + ThisChild->GetExtent();
1601 LastSlot = ThisSlot;
1605 if (TidyUpSlots)
1606 TidySlots();
1607 if (DoRecalc)
1608 ((CFrameWnd*)Parent)->RecalcLayout();
1609 DoRecalc = FALSE ;
1613 /********************************************************************************************
1615 > OILFixedDockingBar::CanShuffleForward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
1617 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1618 Created: 24/3/94
1619 Inputs: -
1620 Outputs: -
1621 Returns: Success / Fail if bar can be shuffled backward without going out of dock bounds
1622 NB a bar can extend beyond the dock but can never be placed entirely outside
1623 its dock.
1624 Purpose: determine whether bars in this slot can be shuffled along without
1625 leaving the dock
1626 Errors: -
1627 SeeAlso: CanShuffleBackward / CanShuffleBackward / DoShuffleForward
1629 ********************************************************************************************/
1631 BOOL OILFixedDockingBar::CanShuffleForward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
1634 if (Start==NULL)
1635 return FALSE;
1637 INT32 RightOfBar = 0;
1638 INT32 LeftOfBar = 0;
1639 CPoint FoundPos;
1640 INT32 AmountToMove = Amount;
1642 OILChildBar * ThisChild = Start;
1644 while (ThisChild != End)
1647 FoundPos = ThisChild->GetPos();
1648 if (!ShiftBarPos(&FoundPos,AmountToMove))// check if we're shuffling out of bounds
1649 return FALSE; // we've run out of room
1651 RightOfBar = PointToPosition(&FoundPos) + ThisChild->GetExtent();
1653 ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);
1655 if (ThisChild == End || ThisChild == NULL)
1656 LeftOfBar = RightOfBar;
1657 else
1658 LeftOfBar = PointToPosition(&(ThisChild->GetPos()));
1660 AmountToMove = RightOfBar - LeftOfBar;
1662 if (AmountToMove == 0) // break if nothing to move
1663 break;
1666 if (AmountToMove > 0)
1667 return FALSE;
1668 return TRUE;
1671 /********************************************************************************************
1673 > OILFixedDockingBar::DoShuffleForward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
1675 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1676 Created: 24/3/94
1677 Inputs: -
1678 Outputs: -
1679 Returns: Success / Fail if bar would be placed below dockstart
1680 Purpose: Attempts to make space in slot for a new bar by shuffling all bars to the left
1681 each iteration resets Amount to the new overlap with the previous bar
1682 Errors: -
1683 SeeAlso: CanShuffleBackward / CanShuffleBackward / DoShuffleForward
1685 ********************************************************************************************/
1687 BOOL OILFixedDockingBar::DoShuffleForward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
1690 if (Start==NULL)
1691 return FALSE;
1693 if (!CanShuffleForward(Start,End,Amount))
1694 return FALSE;
1696 INT32 RightOfBar;
1697 INT32 LeftOfBar;
1698 CPoint FoundPos;
1699 INT32 AmountToMove = Amount; // set to initial overlap
1700 OILChildBar * ThisChild = Start;
1702 while (ThisChild!=End)
1705 FoundPos=ThisChild->GetPos();
1707 if (ShiftBarPos(&FoundPos,AmountToMove)) //check for valid movement
1708 ThisChild->SetPos(FoundPos); //move the bar
1710 RightOfBar = PointToPosition(&FoundPos) + ThisChild->GetExtent();
1712 ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);
1714 if (ThisChild == End || ThisChild == NULL)
1715 LeftOfBar = RightOfBar;
1716 else
1717 LeftOfBar = PointToPosition(&(ThisChild->GetPos()));
1719 AmountToMove = RightOfBar - LeftOfBar; // find overlap
1721 if (AmountToMove == 0)
1722 break; // break if nothing to move
1725 if (AmountToMove>0)
1726 return FALSE;
1727 return TRUE;
1730 /********************************************************************************************
1732 > OILFixedDockingBar::CanShuffleBackward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
1734 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1735 Created: 24/3/94
1736 Inputs: -
1737 Outputs: -
1738 Returns: Success / Fail if bar can be shuffled backward without going out of dock bounds
1739 NB a bar can extend beyond the dock but can never be placed entirely outside
1740 its dock.
1741 Purpose: determine whether bars in this slot can be shuffled along without
1742 leaving the dock
1743 Errors: -
1744 SeeAlso: DoShuffleBackward / CanShuffleForward / DoShuffleForward
1746 ********************************************************************************************/
1748 BOOL OILFixedDockingBar::CanShuffleBackward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
1751 if (Start==NULL)
1752 return FALSE;
1754 INT32 RightOfBar;
1755 INT32 LeftOfBar;
1756 CPoint FoundPos;
1757 INT32 AmountToMove=Amount; // set to initial overlap
1758 OILChildBar * ThisChild= Start;
1760 while (ThisChild!=End)
1763 FoundPos=ThisChild->GetPos();
1764 if (!ShiftBarPos(&FoundPos,-AmountToMove)) //check for valid movement
1765 return FALSE; //we've run out of room
1767 LeftOfBar=PointToPosition(&FoundPos);
1768 ThisChild =(OILChildBar *) ChildBars.GetPrev(ThisChild);
1769 if (ThisChild==NULL) // break if end of list
1770 break;
1772 RightOfBar = PointToPosition(&(ThisChild->GetPos())) + ThisChild->GetExtent();
1774 AmountToMove=RightOfBar-LeftOfBar;
1775 if (AmountToMove<=0) // break if nothing to move
1776 break;
1779 return TRUE;
1782 /********************************************************************************************
1784 > OILFixedDockingBar::DoShuffleBackward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
1786 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1787 Created: 24/3/94
1788 Inputs: -
1789 Outputs: -
1790 Returns: Success/Fail if bar has been shuffled forwards
1791 Purpose: Move all bars in this slot <<<<
1792 Errors: -
1793 SeeAlso: CanShuffleBackward / CanShuffleForward / DoShuffleForward
1795 ********************************************************************************************/
1797 BOOL OILFixedDockingBar::DoShuffleBackward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
1800 if (Start==NULL)
1801 return FALSE;
1803 if (!CanShuffleBackward(Start,End,Amount))
1804 return FALSE;
1806 INT32 RightOfBar;
1807 INT32 LeftOfBar;
1808 CPoint FoundPos;
1809 INT32 AmountToMove=Amount;
1810 OILChildBar * ThisChild= Start;
1812 while (ThisChild!=End)
1815 FoundPos=ThisChild->GetPos();
1816 if (ShiftBarPos(&FoundPos,-AmountToMove)) // Check valid move
1817 ThisChild->SetPos(FoundPos); // Move the bar
1819 LeftOfBar=PointToPosition(&(ThisChild->GetPos()));
1820 ThisChild =(OILChildBar *) ChildBars.GetPrev(ThisChild);
1821 if (ThisChild==NULL) // break if end of list
1822 break;
1824 RightOfBar = PointToPosition(&(ThisChild->GetPos())) + ThisChild->GetExtent();
1826 AmountToMove=RightOfBar-LeftOfBar;
1827 if (AmountToMove<=0) // break if nothing to move
1828 break;
1831 return TRUE;
1834 /********************************************************************************************
1836 > OILFixedDockingBar::GetOverLap(OILChildBar * ThisBar,INT32 SlotNo, INT32 * ForwardOverlap,
1837 INT32 * BackwardOverlap)
1839 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1840 Created: 23/3/94
1841 Inputs: New ChildBar - Slot No
1842 Outputs: ForwardOverlap BackwardOverlap
1843 Returns: Pointer to nearest bar if found
1844 Purpose:
1845 Errors:
1846 SeeAlso:
1848 ********************************************************************************************/
1850 OILChildBar * OILFixedDockingBar::GetOverLap(OILChildBar * ThisBar,INT32 SlotNo,
1851 INT32 * ForwardOverlap,INT32 * BackwardOverlap)
1853 ENSURE(SlotNo >= 0 && SlotNo < NoOfSlots,"Slot Out Of Range");
1855 CPoint FoundPos; // current bar pos
1856 OILChildBar * StartSlot = GetSlotHead(SlotNo);// get pointers to head of this slot and next
1857 OILChildBar *StartNextSlot = GetSlotHead(SlotNo+1);
1859 // failed to find any bars on this slot
1860 if (StartSlot == NULL)
1861 return FALSE;
1863 INT32 CheckPos = 0; // position of current bar in list
1864 INT32 ThisPos=PointToPosition(&(ThisBar->GetPos()));// initial position of new bar
1865 OILChildBar * ThisChild = StartSlot; // Set to start of first bar in this slot
1866 OILChildBar * FoundNearest = NULL; // will return a pointer to the closest bar
1867 *BackwardOverlap = 0; // initalise Overlaps
1868 *ForwardOverlap = 0;
1870 // check the list until we get to the end of the list / get to the end of this slot
1871 // or find a bar with a higher position than the new one
1872 while (TRUE)
1874 //TRACE( _T("Check %d against %d ThisChild %p"),ThisPos,CheckPos,ThisChild);
1875 if (ThisChild != NULL)
1877 CheckPos = PointToPosition(&(ThisChild->GetPos()));
1879 if (ThisPos<CheckPos||ThisChild == StartNextSlot||ThisChild == NULL)
1881 // Ok we've gone past it
1882 if (ThisChild == NULL) // check if we're past the end of the list
1884 ThisChild = (OILChildBar *) ChildBars.GetTail();
1886 else
1888 ThisChild =(OILChildBar *) ChildBars.GetPrev(ThisChild);
1890 if (ThisChild==NULL) // Special case - front of list
1892 *BackwardOverlap = 0;
1893 FoundNearest = NULL;
1894 ThisChild =(OILChildBar *) ChildBars.GetHead( );
1896 else // Check for backwards overlap
1898 // get bottom right corner of current bar
1899 FoundPos = ThisChild->GetPos();
1900 CheckPos = PointToPosition(&FoundPos)+ ThisChild->GetExtent();
1901 // keep a pointer to found bar
1902 FoundNearest = ThisChild;
1903 //TRACE( _T("FOUND BAR %d on slot %d"),PointToPosition(FoundNearest->GetPos()),
1904 // PointToSlot(FoundNearest->GetPos()));
1905 *BackwardOverlap = CheckPos - ThisPos ;
1906 ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);
1908 // is there another bar to the right in this slot
1909 if (ThisChild != NULL && ThisChild != StartNextSlot)
1911 // if so check for forward overlap
1912 FoundPos = ThisBar->GetPos() ;
1913 CheckPos = PointToPosition(&FoundPos)+ ThisBar->GetExtent();
1914 INT32 NextPos = PointToPosition(&(ThisChild->GetPos()));
1915 if (CheckPos>NextPos)
1916 *ForwardOverlap = CheckPos-NextPos ;
1918 break; // break from while loop if nearest bar or end of list found
1920 ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);
1921 }// end while
1923 if (*BackwardOverlap < 0)
1924 *BackwardOverlap = 0;
1926 if (*ForwardOverlap < 0)
1927 * ForwardOverlap = 0;
1928 return FoundNearest;
1933 /****************************************************************************
1935 > OILChildBar* OILFixedDockingBar::GetGalleryOverLap(OILChildBar* ThisBar,
1936 INT32 SlotNo,INT32 * ForwardOverlap,INT32 * BackwardOverlap)
1938 Author: Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
1939 Created: 18/11/2004
1941 Inputs: ThisBar - pointer to a OILChildBar
1942 SlotNo -
1943 ForwardOverlap- pointer to a INT32
1944 BackwardOverlap- pointer to a INT32
1945 Returns: NULL in times of grief
1946 Purpose:
1948 ****************************************************************************/
1950 BOOL OILFixedDockingBar::GetGalleryOverLap(OILChildBar* ThisBar,INT32 SlotNo,
1951 INT32 * ForwardOverlap,INT32 * BackwardOverlap,
1952 OILChildBar** ppPrevious, OILChildBar** ppNext)
1954 // ENSURE(SlotNo >= 0 && SlotNo < NoOfSlots,"Slot Out Of Range");
1956 CPoint FoundPos; // current bar pos
1958 *BackwardOverlap = 0; // initalise Overlaps
1959 *ForwardOverlap = 0;
1960 if (ppPrevious)
1961 *ppPrevious = NULL;
1962 if (ppNext)
1963 *ppNext = NULL;
1965 INT32 ThisMin = ThisBar->GetKPPos(); // initial position of new bar
1966 INT32 ThisMax = ThisMin + ThisBar->GetExtent(); // initial position of new bar
1968 // TRACE( _T("ThisMin = %d\n"), ThisMin);
1970 OILChildBar* StartSlot = GetSlotHead(SlotNo); // get pointer to head of this slot
1971 // failed to find any bars on this slot
1972 if (StartSlot == NULL)
1974 *BackwardOverlap = -ThisMin;
1975 *ForwardOverlap = ThisMax - DockSize.cy;
1976 return TRUE;
1979 OILChildBar* CheckBar = StartSlot; // Set to start of first bar in this slot
1981 // check the list until we get to the end of the list / get to the end of this slot
1982 // or find a bar with a higher position than the new one
1983 while (CheckBar && (CheckBar->GetKPSlot() == SlotNo) &&
1984 (CheckBar == ThisBar || CheckBar->GetKPPos() < ThisMin))
1986 CheckBar = (OILChildBar*)ChildBars.GetNext(CheckBar);
1989 // if (CheckBar)
1990 // {
1991 // TRACE( _T("CheckBar at %d\n"), CheckBar->GetKPPos());
1992 // }
1993 // else
1994 // {
1995 // TRACE( _T("CheckBar is NULL\n"));
1996 // }
1998 // At this point we must be in one of the following states
1999 OILChildBar* PreviousBar = CheckBar ? (OILChildBar*)ChildBars.GetPrev(CheckBar) : (OILChildBar*)ChildBars.GetTail();
2000 if (PreviousBar == ThisBar)
2001 PreviousBar = (OILChildBar*)ChildBars.GetPrev(PreviousBar);
2002 if (PreviousBar && PreviousBar->GetKPSlot() != SlotNo)
2003 PreviousBar = NULL;
2005 // if (PreviousBar)
2006 // {
2007 // TRACE( _T("PreviousBar at %d\n"), PreviousBar->GetKPPos());
2008 // }
2009 // else
2010 // {
2011 // TRACE( _T("PreviousBar is NULL\n"));
2012 // }
2014 if (!CheckBar || CheckBar->GetKPSlot() != SlotNo)
2016 // CheckBar is NULL implies that the previous bar is in this slot
2017 // CheckBar->GetKPSlot() != SlotNo implies the same as above
2018 // Calculate forward overlap from extent of dock (no bars after us in slot)
2019 // Calculate backward overlap from PreviousBar
2021 *ForwardOverlap = ThisMax - DockSize.cy;
2022 if (PreviousBar)
2024 if (ppPrevious)
2025 *ppPrevious = PreviousBar;
2026 *BackwardOverlap = (PreviousBar->GetKPPos() + PreviousBar->GetExtent()) - ThisMin;
2028 else
2030 *BackwardOverlap = -ThisMin;
2033 else
2035 // Calculate forward overlap with CheckBar
2036 // Calculate backward overlap with PreviousBar or from zero if NULL or wrong slot
2038 if (ppNext)
2039 *ppNext = CheckBar;
2040 *ForwardOverlap = ThisMax - CheckBar->GetKPPos();
2042 if (PreviousBar)
2044 if (ppPrevious)
2045 *ppPrevious = PreviousBar;
2046 *BackwardOverlap = (PreviousBar->GetKPPos() + PreviousBar->GetExtent()) - ThisMin;
2048 else
2050 *BackwardOverlap = -ThisMin;
2054 return TRUE;
2058 /********************************************************************************************
2060 > OILFixedDockingBar::PlaceBarInSlot(OILChildBar * ThisBar)
2062 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
2063 Created: 23/3/94
2064 Inputs: New ChildBar - Slot No
2065 Outputs: -
2066 Returns: Success / Fail
2067 Purpose: attempts to shuffle bars in a given slot allowing a new bar to be placed with
2068 no overlap
2069 Errors: Assert ThisBar != NULL
2070 SeeAlso:
2072 ********************************************************************************************/
2073 BOOL OILFixedDockingBar::PlaceBarInSlot(OILChildBar * ThisBar, INT32 SlotNo)
2075 ENSURE(ThisBar != NULL,"Trying To Place A Null Bar");
2076 ENSURE(SlotNo >= 0 && SlotNo < NoOfSlots,"Slot Out of Range");
2078 CPoint FoundPos; // current bar pos
2079 CPoint LastPos ; // copy of last pos
2080 // get pointers to head of this slot and next
2081 OILChildBar * StartSlot=GetSlotHead(SlotNo);
2082 OILChildBar * StartNextSlot=GetSlotHead(SlotNo+1);
2083 BOOL DoneShuffleForward = FALSE;
2084 if (StartSlot==NULL)
2085 return FALSE; // failed to find any bars on this slot
2087 INT32 ThisPos=PointToPosition(&(ThisBar->GetPos())); // initial position in slot
2088 INT32 BackwardOverlap ;
2089 INT32 ForwardOverlap ;
2090 INT32 ForwardDone ;
2091 // get a pointer to the nearest bar and overlaps on either side
2092 OILChildBar * FoundNearest=GetOverLap(ThisBar,SlotNo,&ForwardOverlap,&BackwardOverlap);
2094 ForwardDone = ForwardOverlap;
2096 if (FoundNearest==NULL) // trying to insert at the front of a slot
2098 FoundPos=ThisBar->GetPos();
2099 // can we place the new bar in the space at the front of the slot
2100 if (ShiftBarPos(&FoundPos,-ForwardOverlap))
2101 ThisBar->SetPos(FoundPos);
2102 // if not can we shuffle the bars in the slot to make space
2103 else
2105 if (!(DoneShuffleForward =DoShuffleForward(StartSlot,StartNextSlot, ForwardOverlap)))
2106 return FALSE; //shuffle failed
2109 else // trying to insert between two bars
2112 /*TRACE( _T("Insert between bars %d on slot %d back overlap %d forward %d"),
2113 PointToPosition(FoundNearest->GetPos()),PointToSlot(FoundNearest->GetPos()),
2114 BackwardOverlap,ForwardOverlap);
2116 if (ForwardOverlap > 0)
2118 // try to shuffle all bars in this slot ahead of new bar to make space
2119 if (!(DoneShuffleForward =DoShuffleForward((OILChildBar *) ChildBars.GetNext(FoundNearest),
2120 StartNextSlot, ForwardOverlap)))
2122 LastPos = FoundPos=ThisBar->GetPos();
2123 //TRACE( _T("failed ->>> shift - moving <<<- and attempting whole shuffle <<<-"));
2124 if (ShiftBarPos(&FoundPos,-ForwardOverlap))
2126 ThisBar->SetPos(FoundPos);
2127 FoundNearest = GetOverLap(ThisBar,SlotNo,&ForwardOverlap,&BackwardOverlap);
2128 if (BackwardOverlap > 0)
2130 if (!DoShuffleBackward(FoundNearest,
2131 (OILChildBar *)ChildBars.GetPrev(StartSlot),
2132 BackwardOverlap))
2134 // return to state before failure
2135 ThisBar->SetPos(LastPos);
2136 return FALSE;
2140 else
2142 // return to state before failure
2143 ThisBar->SetPos(LastPos);
2144 return FALSE;
2146 return FALSE;
2148 }// end if ForwardOverlap>0
2151 if (BackwardOverlap > 0)
2153 // try to shuffle all bars in this slot behind new bar to make space
2154 if (!DoShuffleBackward(FoundNearest,(OILChildBar *) ChildBars.GetPrev(StartSlot),
2155 BackwardOverlap))
2157 LastPos = FoundPos = ThisBar->GetPos();
2158 //TRACE( _T("failed <<<- shift - moving->>> and attempting whole shuffle ->>>"));
2159 if (ShiftBarPos(&FoundPos,BackwardOverlap))
2161 ThisBar->SetPos(FoundPos);
2162 FoundNearest = GetOverLap(ThisBar,SlotNo,&ForwardOverlap,&BackwardOverlap);
2163 if (ForwardOverlap > 0)
2165 if (!DoShuffleForward((OILChildBar *) ChildBars.GetNext(FoundNearest),
2166 StartNextSlot, ForwardOverlap))
2168 // return to state before fail - we may have shuffled the bars >>>
2169 ThisBar->SetPos(LastPos);
2170 if (DoneShuffleForward)
2171 DoShuffleBackward((OILChildBar *) ChildBars.GetNext(FoundNearest),
2172 StartNextSlot, ForwardDone);
2173 return FALSE;
2177 else
2179 // return to state before fail
2180 ThisBar->SetPos(LastPos);
2181 if (DoneShuffleForward)
2182 DoShuffleForward((OILChildBar *) ChildBars.GetNext(FoundNearest),
2183 StartNextSlot, ForwardDone);
2184 return FALSE;
2187 }// end if BackwardOverlap>0
2189 }// end else (FoundNearest != NULL)
2190 return TRUE;
2195 /****************************************************************************
2197 > BOOL OILFixedDockingBar::PlaceGalleryInSlot(OILChildBar * ThisBar, INT32 SlotNo)
2199 Author: Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
2200 Created: 18/11/2004
2202 Inputs: ThisBar - pointer to a OILChildBar
2203 SlotNo -
2204 Returns: TRUE if ok, FALSE if bother
2205 Purpose:
2207 ****************************************************************************/
2209 BOOL OILFixedDockingBar::PlaceGalleryInSlot(OILChildBar * ThisBar, INT32 SlotNo)
2211 ENSURE(ThisBar != NULL,"Trying To Place A Null Bar");
2212 // ENSURE(SlotNo >= 0 && SlotNo < NoOfSlots,"Slot Out of Range");
2214 if (!allowTidyBars)
2215 return(TRUE);
2217 CPoint FoundPos; // current bar pos
2218 CPoint LastPos ; // copy of last pos
2219 BOOL DoneShuffleForward = FALSE;
2221 INT32 ThisPos = ThisBar->GetKPPos(); // initial position in slot
2222 // get a pointer to the nearest bars and overlaps on either side
2223 INT32 BackwardOverlap ;
2224 INT32 ForwardOverlap ;
2225 OILChildBar* PreviousBar = NULL;
2226 OILChildBar* NextBar = NULL;
2228 GetGalleryOverLap(ThisBar,SlotNo,&ForwardOverlap,&BackwardOverlap, &PreviousBar, &NextBar);
2229 // TRACE( _T("GalleryOverlap - Back = %d, Fore = %d, Prev = %p, Next = %p\n"), BackwardOverlap, ForwardOverlap, PreviousBar, NextBar);
2231 // If both Next and Previous are NULL then this is the only bar in the slot and we can shortcut
2232 if (!PreviousBar && !NextBar)
2234 ThisBar->GetBarPos()->Position = 0;
2235 ThisBar->UpdatePos();
2236 ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), DockSize.cy);
2237 return(TRUE);
2240 // First off we scan through all the bars in the slot and
2241 // shuffle all the bars away from this one
2243 BOOL bMoved = FALSE;
2244 OILChildBar* FirstBar = GetSlotHead(SlotNo);
2245 OILChildBar* LastBar = NULL; // pointer to last bar in slot
2246 OILChildBar* TempBar = FirstBar;
2247 while (TempBar && TempBar->GetKPSlot() == SlotNo)
2249 LastBar = TempBar;
2250 TempBar = (OILChildBar*)ChildBars.GetNext(TempBar);
2253 if (PreviousBar)
2255 OILChildBar* MoveBar = FirstBar;
2256 OILChildBar* EndBar = (OILChildBar*)ChildBars.GetNext(PreviousBar);
2257 INT32 CurPos = 0;
2258 while (MoveBar && MoveBar != EndBar)
2260 if (MoveBar->GetBarPos()->Position != CurPos)
2262 MoveBar->GetBarPos()->Position = CurPos;
2263 MoveBar->UpdatePos();
2264 bMoved = TRUE;
2266 CurPos += MoveBar->GetExtent();
2267 MoveBar = (OILChildBar*)ChildBars.GetNext(MoveBar);
2271 if (NextBar)
2273 OILChildBar* MoveBar = LastBar;
2274 OILChildBar* EndBar = (OILChildBar*)ChildBars.GetPrev(NextBar);
2275 INT32 CurEnd = DockSize.cy;
2276 while (MoveBar && MoveBar != EndBar)
2278 INT32 CurPos = CurEnd - MoveBar->GetExtent();
2279 if (MoveBar->GetBarPos()->Position != CurPos)
2281 MoveBar->GetBarPos()->Position = CurPos;
2282 MoveBar->UpdatePos();
2283 bMoved = TRUE;
2285 CurEnd = CurPos;
2286 MoveBar = (OILChildBar*)ChildBars.GetPrev(MoveBar);
2290 if (bMoved)
2292 GetGalleryOverLap(ThisBar,SlotNo,&ForwardOverlap,&BackwardOverlap, &PreviousBar, &NextBar);
2293 // TRACE( _T("GalleryOverlapAfterShuffle - Back = %d, Fore = %d, Prev = %p, Next = %p\n"), BackwardOverlap, ForwardOverlap, PreviousBar, NextBar);
2296 // If Previous is NULL and there is a backward overlap
2297 if (!PreviousBar && BackwardOverlap != 0)
2299 // Move and resize this bar to fill the start of the slot
2300 ThisBar->GetBarPos()->Position = 0;
2301 ThisBar->UpdatePos();
2302 ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), ThisBar->GetExtent() - BackwardOverlap);
2304 GetGalleryOverLap(ThisBar,SlotNo,&ForwardOverlap,&BackwardOverlap, &PreviousBar, &NextBar);
2305 // TRACE( _T("GalleryOverlapNoPrev - Back = %d, Fore = %d, Prev = %p, Next = %p\n"), BackwardOverlap, ForwardOverlap, PreviousBar, NextBar);
2308 // If Next is NULL and there is a forward overlap
2309 if (!NextBar && ForwardOverlap != 0)
2311 // Resize this bar to fill the end of the slot
2312 ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), ThisBar->GetExtent() - ForwardOverlap);
2313 INT32 TempBack = 0;
2314 INT32 TempFor = 0;
2315 GetGalleryOverLap(ThisBar,SlotNo,&TempFor,&TempBack, NULL, NULL);
2316 if (TempFor > 0)
2318 ThisBar->GetBarPos()->Position -= TempFor;
2319 ThisBar->UpdatePos();
2321 GetGalleryOverLap(ThisBar,SlotNo,&ForwardOverlap,&BackwardOverlap, &PreviousBar, &NextBar);
2322 // TRACE( _T("GalleryOverlapNoNext - Back = %d, Fore = %d, Prev = %p, Next = %p\n"), BackwardOverlap, ForwardOverlap, PreviousBar, NextBar);
2325 // If Previous is not NULL then the bars before need to be resized to fit in the available space
2326 if (BackwardOverlap != 0)
2328 if (PreviousBar)
2330 if (BackwardOverlap > 0)
2332 INT32 AmountToShrink = BackwardOverlap;
2333 INT32 AmountToMove = 0;
2334 OILChildBar* ShrinkBar = PreviousBar;
2335 while (AmountToShrink > 0 && ShrinkBar && ShrinkBar->GetKPSlot() == SlotNo)
2337 INT32 OldExt = ShrinkBar->GetExtent();
2338 ::SendMessage(ShrinkBar->GetHwnd(), WM_SETGALLERYSIZE, ShrinkBar->GetBarSize(), ShrinkBar->GetExtent() - AmountToShrink);
2339 INT32 AmountShrunk = OldExt - ShrinkBar->GetExtent();
2340 AmountToShrink -= AmountShrunk;
2341 if (AmountToShrink > 0)
2343 if (ShrinkBar->GetBarPos()->Position > 0)
2345 AmountToMove = (ShrinkBar->GetBarPos()->Position < AmountToShrink) ? ShrinkBar->GetBarPos()->Position : AmountToShrink;
2346 ShrinkBar->GetBarPos()->Position -= AmountToMove;
2347 ShrinkBar->UpdatePos();
2348 AmountToShrink = AmountToMove;
2351 ShrinkBar = (OILChildBar*)ChildBars.GetPrev(ShrinkBar);
2354 if (AmountToShrink > 0)
2356 // We still have some backward overlap so set the first bar to 0
2357 // and move each bar upto This by the forward overlap
2358 OILChildBar* MoveBar = GetSlotHead(SlotNo);
2359 OILChildBar* EndBar = (OILChildBar*)ChildBars.GetNext(PreviousBar);
2360 INT32 TempBack = 0;
2361 INT32 TempFor = 0;
2362 MoveBar->GetBarPos()->Position = 0;
2363 MoveBar->UpdatePos();
2364 MoveBar = (OILChildBar*)ChildBars.GetNext(MoveBar);
2365 while (MoveBar && MoveBar != EndBar)
2367 GetGalleryOverLap(MoveBar,SlotNo,&TempFor,&TempBack, NULL, NULL);
2368 if (TempBack != 0)
2370 MoveBar->GetBarPos()->Position += TempBack;
2371 MoveBar->UpdatePos();
2373 MoveBar = (OILChildBar*)ChildBars.GetNext(MoveBar);
2376 GetGalleryOverLap(ThisBar,SlotNo,&TempFor,&TempBack, NULL, NULL);
2377 ThisBar->GetBarPos()->Position += TempBack;
2378 ThisBar->UpdatePos();
2379 GetGalleryOverLap(ThisBar,SlotNo,&ForwardOverlap,&BackwardOverlap, &PreviousBar, &NextBar);
2380 // TRACE( _T("GalleryOverlapShrunkPrev - Back = %d, Fore = %d, Prev = %p, Next = %p\n"), BackwardOverlap, ForwardOverlap, PreviousBar, NextBar);
2383 else
2385 // Need to fill up the gap
2386 ::SendMessage(PreviousBar->GetHwnd(), WM_SETGALLERYSIZE, PreviousBar->GetBarSize(), PreviousBar->GetExtent() - BackwardOverlap);
2389 else
2391 // No windows before so move position and size of ThisBar to fill the start of the slot
2392 ThisBar->GetBarPos()->Position = 0;
2393 ThisBar->UpdatePos();
2394 INT32 OldExt = ThisBar->GetExtent();
2395 ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), ThisBar->GetExtent() - BackwardOverlap);
2396 INT32 NewExt = ThisBar->GetExtent();
2397 if (NewExt != (OldExt - BackwardOverlap))
2399 // TRACE( _T("Failed to fit ThisBar ar start of slot\n"));
2404 // If Next is not NULL then the bars after need to be resized to fit in the available space
2405 if (ForwardOverlap != 0)
2407 if (NextBar)
2409 if (ForwardOverlap > 0)
2411 INT32 AmountToShrink = ForwardOverlap;
2412 INT32 AmountToMove = 0;
2413 OILChildBar* ShrinkBar = NextBar;
2414 while (AmountToShrink > 0 && ShrinkBar && ShrinkBar->GetKPSlot() == SlotNo)
2416 INT32 OldExt = ShrinkBar->GetExtent();
2417 ::SendMessage(ShrinkBar->GetHwnd(), WM_SETGALLERYSIZE, ShrinkBar->GetBarSize(), ShrinkBar->GetExtent() - AmountToShrink);
2418 INT32 AmountShrunk = OldExt - ShrinkBar->GetExtent();
2420 ShrinkBar->GetBarPos()->Position += AmountToShrink;
2421 ShrinkBar->UpdatePos();
2422 AmountToShrink -= AmountShrunk;
2424 ShrinkBar = (OILChildBar*)ChildBars.GetNext(ShrinkBar);
2427 if (AmountToShrink > 0)
2429 // We still have some forward overlap so shrink this bar
2430 // and move each bar upto the end to fill the gaps
2431 // This means that all bars after this are the smallest possible size
2433 // If we can't shrink this bar enough then loop backwards from PreviousBar
2434 // shrinking each bar in turn until enough space has been made
2436 INT32 OldExt = ThisBar->GetExtent();
2437 ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), ThisBar->GetExtent() - AmountToShrink);
2438 INT32 AmountShrunk = OldExt - ThisBar->GetExtent();
2439 AmountToShrink -= AmountShrunk;
2441 if (AmountToShrink > 0)
2443 ThisBar->GetBarPos()->Position -= AmountToShrink;
2444 ThisBar->UpdatePos();
2446 OILChildBar* ShrinkBar = PreviousBar;
2447 while (ShrinkBar && ShrinkBar->GetKPSlot() == SlotNo && AmountToShrink > 0)
2449 INT32 OldExt = ShrinkBar->GetExtent();
2450 ::SendMessage(ShrinkBar->GetHwnd(), WM_SETGALLERYSIZE, ShrinkBar->GetBarSize(), ShrinkBar->GetExtent() - AmountToShrink);
2451 INT32 AmountShrunk = OldExt - ShrinkBar->GetExtent();
2452 if (AmountShrunk > 0)
2454 AmountToShrink -= AmountShrunk;
2455 // Shift all bars upto nextbar by AmountShrunk
2456 OILChildBar* MoveBar = (OILChildBar*)ChildBars.GetNext(ShrinkBar);
2457 while (MoveBar && MoveBar != NextBar)
2459 MoveBar->GetBarPos()->Position -= AmountShrunk;
2460 MoveBar->UpdatePos();
2461 MoveBar = (OILChildBar*)ChildBars.GetNext(MoveBar);
2464 ShrinkBar = (OILChildBar*)ChildBars.GetPrev(ShrinkBar);
2468 INT32 TempBack = 0;
2469 INT32 TempFor = 0;
2470 OILChildBar* LastBar = NULL;
2471 OILChildBar* MoveBar = NextBar;
2472 MoveBar->GetBarPos()->Position = ThisBar->GetBarPos()->Position + ThisBar->GetExtent();
2473 MoveBar->UpdatePos();
2474 MoveBar = (OILChildBar*)ChildBars.GetNext(MoveBar);
2475 while (MoveBar && MoveBar->GetKPSlot() == SlotNo)
2477 GetGalleryOverLap(MoveBar,SlotNo,&TempFor,&TempBack, NULL, NULL);
2478 if (TempBack != 0)
2480 MoveBar->GetBarPos()->Position += TempBack;
2481 MoveBar->UpdatePos();
2483 LastBar = MoveBar;
2484 MoveBar = (OILChildBar*)ChildBars.GetNext(MoveBar);
2487 if (LastBar && TempFor + TempBack > 0)
2489 ::SendMessage(LastBar->GetHwnd(), WM_SETGALLERYSIZE, LastBar->GetBarSize(), LastBar->GetExtent() - (TempFor + TempBack));
2494 else
2496 // There is a gap before the next bar so move and resize the next bar to
2497 // fill it up
2498 NextBar->GetBarPos()->Position += ForwardOverlap;
2499 NextBar->UpdatePos();
2500 ::SendMessage(NextBar->GetHwnd(), WM_SETGALLERYSIZE, NextBar->GetBarSize(), NextBar->GetExtent() - ForwardOverlap);
2503 else
2505 // No windows after so change size of ThisBar to fill the end of the slot
2506 ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), ThisBar->GetExtent() - ForwardOverlap);
2510 return TRUE;
2516 /********************************************************************************************
2518 > OILFixedDockingBar::TidySlots()
2520 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
2521 Created: 15/3/94
2522 Inputs: -
2523 Outputs: -
2524 Returns: -
2525 Purpose: move bars to fill any empty slots
2526 Errors: -
2527 SeeAlso:
2529 ********************************************************************************************/
2531 void OILFixedDockingBar::TidySlots()
2533 INT32 LastSlot = -1;
2534 INT32 FoundSlot = 0;
2535 INT32 NumSlots = NoOfSlots; // Remember original number of slots
2536 CPoint FoundPos; // current bar pos
2538 if (allowTidyBars)
2540 /* OILChildBar* FoundBar = (OILChildBar*)ChildBars.GetHead();
2541 while (FoundBar != NULL)
2543 FoundPos = FoundBar->GetPos();
2544 FoundSlot = PointToSlot(&FoundPos);
2545 if (FoundSlot > LastSlot+1) // check for empty slots
2547 LastSlot ++; // skip last none empty slot
2548 while (LastSlot < FoundSlot)
2550 RemoveSlot(LastSlot++); // remove empty slots
2551 // LastSlot++;
2555 LastSlot = FoundSlot;
2556 FoundBar = (OILChildBar*)ChildBars.GetNext(FoundBar);
2557 } // end while
2560 INT32 TempF = 0;
2561 INT32 TempB = 0;
2562 OILChildBar* TempPrev = NULL;
2563 OILChildBar* TempNext = NULL;
2564 GetGalleryOverLap(NextBar, SlotNo, &TempF, &TempB, &TempPrev, &TempNext);
2565 if (TempF > 0)
2567 // Next bar is overlapping forward
2568 // Shrink ThisBar by overlap and move next backwards
2569 NextBar->GetBarPos()->Position -= TempF;
2570 NextBar->UpdatePos();
2571 ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), ThisBar->GetExtent() - TempF);
2576 // Reset this to correct value for current bars
2577 NoOfSlots = CountSlots();
2578 // For each slot we do a tidy on the slot
2579 for (FoundSlot = 0; FoundSlot < NoOfSlots; FoundSlot++)
2581 OILChildBar* CheckBar = GetSlotHead(FoundSlot); // get pointer to head of this slot
2582 if (CheckBar)
2584 if (SlotSize[FoundSlot] != ControlSize)
2586 OILChildBar* ThisBar = CheckBar;
2588 // Now check through again in reverse order
2589 OILChildBar* LastBar = NULL; // pointer to last bar in slot
2590 while (ThisBar && ThisBar->GetKPSlot() == FoundSlot)
2592 LastBar = ThisBar;
2593 ThisBar = (OILChildBar*)ChildBars.GetNext(ThisBar);
2596 ThisBar = LastBar;
2597 // check the list until we get to the end of the list / get to the end of this slot
2598 while (ThisBar && (ThisBar->GetKPSlot() == FoundSlot))
2600 INT32 BackwardOverlap = 0;
2601 INT32 ForwardOverlap = 0;
2602 OILChildBar* PreviousBar = NULL;
2603 OILChildBar* NextBar = NULL;
2605 GetGalleryOverLap(ThisBar,FoundSlot,&ForwardOverlap,&BackwardOverlap, &PreviousBar, &NextBar);
2606 // TRACE( _T("TidyOverlapB - This = %p, Back = %d, Fore = %d, Prev = %p, Next = %p\n"), ThisBar, BackwardOverlap, ForwardOverlap, PreviousBar, NextBar);
2608 BOOL bCheck = FALSE;
2609 // Move the bar by BackwardOverlap
2610 if (BackwardOverlap != 0)
2612 ThisBar->GetBarPos()->Position += BackwardOverlap;
2613 ThisBar->UpdatePos();
2614 bCheck = TRUE;
2616 // Resize the bar by (-ForwardOverlap-BackwardOverlap)
2617 INT32 SizeDiff = -(ForwardOverlap+BackwardOverlap);
2618 if (SizeDiff != 0)
2620 ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), ThisBar->GetExtent() + SizeDiff);
2621 bCheck = TRUE;
2624 if (bCheck)
2626 GetGalleryOverLap(ThisBar,FoundSlot,&ForwardOverlap,&BackwardOverlap, &PreviousBar, &NextBar);
2627 // TRACE( _T("CheckOverlap - This = %p, Back = %d, Fore = %d, Prev = %p, Next = %p\n"), ThisBar, BackwardOverlap, ForwardOverlap, PreviousBar, NextBar);
2628 if (ForwardOverlap > 0)
2630 // Move the bar backwards by ForwardOverlap
2631 ThisBar->GetBarPos()->Position -= ForwardOverlap;
2632 ThisBar->UpdatePos();
2636 ThisBar = (OILChildBar*)ChildBars.GetPrev(ThisBar);
2641 // First we do a forward scan removing any overlaps as we go
2642 // check the list until we get to the end of the list / get to the end of this slot
2643 ThisBar = CheckBar;
2644 while (ThisBar && (ThisBar->GetKPSlot() == FoundSlot))
2646 INT32 BackwardOverlap = 0;
2647 INT32 ForwardOverlap = 0;
2648 OILChildBar* PreviousBar = NULL;
2649 OILChildBar* NextBar = NULL;
2651 GetGalleryOverLap(ThisBar,FoundSlot,&ForwardOverlap,&BackwardOverlap, &PreviousBar, &NextBar);
2652 // TRACE( _T("TidyOverlapF - This = %p, Back = %d, Fore = %d, Prev = %p, Next = %p\n"), ThisBar, BackwardOverlap, ForwardOverlap, PreviousBar, NextBar);
2654 // Move the bar by BackwardOverlap
2655 if (BackwardOverlap != 0)
2657 ThisBar->GetBarPos()->Position += BackwardOverlap;
2658 ThisBar->UpdatePos();
2660 // Resize the bar by (-ForwardOverlap-BackwardOverlap)
2661 INT32 SizeDiff = -(ForwardOverlap+BackwardOverlap);
2662 if (SizeDiff != 0)
2664 ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, ThisBar->GetBarSize(), ThisBar->GetExtent() + SizeDiff);
2667 ThisBar = (OILChildBar*)ChildBars.GetNext(ThisBar);
2673 else if (FoundSlot < NoOfSlots)
2675 RemoveSlot(FoundSlot--); // No bars so remove the slot and go back a slot
2676 NoOfSlots--;
2681 INT32 SlotsNow = CountSlots(); // check if number of slots has changed
2683 if (SlotsNow != NumSlots) // and RecalcLayout if it has
2685 NoOfSlots = SlotsNow;
2686 DoRecalc = TRUE;
2688 else
2690 OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead();
2692 while (ThisChild != NULL)
2694 ThisChild->InvalidateIfMoved();
2695 ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);
2697 }// end while
2702 /********************************************************************************************
2704 > OILFixedDockingBar::CountSlots()
2706 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
2707 Created: 15/3/94
2708 Inputs: -
2709 Outputs: -
2710 Returns: number of slots in this dock
2711 Purpose: Count how many slots are in this bar
2712 Errors: -
2713 SeeAlso:
2715 ********************************************************************************************/
2717 INT32 OILFixedDockingBar::CountSlots()
2719 if (ChildBars.IsEmpty()) // no bars in list
2720 return(0);
2722 OILChildBar* FoundBar = (OILChildBar*)ChildBars.GetTail();
2723 if (FoundBar == NULL) // Shouldn't happen but I'll check to make sure
2724 return(0);
2726 return(FoundBar->GetKPSlot() + 1);
2728 /* INT32 FoundSlot = 0;
2729 INT32 HighSlot = 0;
2730 OILChildBar * FoundBar =(OILChildBar *) ChildBars.GetHead();
2732 while (FoundBar != NULL) // find the highest slot number in the list
2735 FoundSlot = PointToSlot(&(FoundBar->GetPos()));
2736 if (FoundSlot > HighSlot)
2737 HighSlot = FoundSlot;
2739 FoundBar =(OILChildBar *) ChildBars.GetNext(FoundBar);
2741 } // end while
2743 return HighSlot+1; // slots are numbered from 0 so add 1 to return value
2747 /********************************************************************************************
2749 > OILFixedDockingBar::RemoveSlot(INT32 SlotNo)
2751 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
2752 Created: 15/3/94
2753 Inputs: -
2754 Outputs: -
2755 Returns: -
2756 Purpose: Remove a slot - shuffle all ChildBars beyond this slot backwards
2757 Errors: ASSERT slot number >0
2758 SeeAlso:
2760 ********************************************************************************************/
2762 void OILFixedDockingBar::RemoveSlot(INT32 SlotNo)
2764 ASSERT(SlotNo >= 0 && SlotNo < NoOfSlots);
2765 // INT32 FoundSlot;
2766 CRect FoundRect;
2767 CPoint FoundPos;
2768 OILChildBar * FoundBar =(OILChildBar *) ChildBars.GetHead();
2769 INT32 MoveSize = SlotSize[SlotNo]; // The size of the slot being removed
2771 // Set the last slot to the default size
2772 SlotSize[MAX_SLOTS-1] = ControlSize;
2773 // And copy the slot sizes down in the array
2774 for (INT32 i = SlotNo; i < (MAX_SLOTS - 1); i++)
2776 SlotSize[i] = SlotSize[i+1];
2779 // look for bars in or above slot to be removed
2780 // shuffle any found back one slot
2781 while (FoundBar != NULL)
2783 KernelBarPos* pPos = FoundBar->GetBarPos();
2784 // FoundPos = FoundBar->GetPos();
2785 // FoundSlot = PointToSlot(&FoundPos);
2787 ERROR3IF(pPos->Slot == SlotNo, "Deleting non-empty slot");
2789 switch (DockType) // check if found slot => remove slot
2790 { // if so pull back one slot
2791 case DOCKBAR_TOP:
2792 case DOCKBAR_BOTTOM:
2793 if (pPos->Slot > SlotNo)
2795 // FoundPos.y -= MoveSize;
2796 pPos->Slot -= 1; // Move it back a slot
2797 FoundBar->UpdatePos();
2799 break;
2800 case DOCKBAR_LEFT:
2801 case DOCKBAR_RIGHT:
2802 if (pPos->Slot > SlotNo)
2804 // FoundPos.x -= MoveSize;
2805 pPos->Slot -= 1; // Move it back a slot
2806 FoundBar->UpdatePos();
2808 break;
2809 }// end switch
2810 // FoundBar->SetPos(FoundPos);
2811 FoundBar =(OILChildBar *) ChildBars.GetNext(FoundBar);
2813 } // end while
2816 /********************************************************************************************
2818 > OILFixedDockingBar::InsertSlot(INT32 SlotNo, INT32 NewSize = -1)
2820 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
2821 Created: 15/3/94
2822 Inputs: -
2823 Outputs: -
2824 Returns: -
2825 Purpose: Insert a Slot - shuffle all ChildBars beyond this slot number forwards
2826 Errors: ASSERT Slot number >0
2827 SeeAlso:
2829 ********************************************************************************************/
2831 void OILFixedDockingBar::InsertSlot(INT32 SlotNo, INT32 NewSize)
2833 ASSERT(SlotNo >= 0 && SlotNo < NoOfSlots);
2834 KernelBarPos* pPos = NULL;
2836 if (NewSize == -1)
2837 NewSize = ControlSize;
2839 // First we add up all the slot sizes
2840 INT32 TotalSize = TotalSlotSizes();
2841 CRect MainRect;
2842 GetMainFrame()->GetClientRect(&MainRect);
2843 INT32 MaxSize = (MainRect.Width() * 48) / 100;
2845 INT32 AmountToShrink = MaxSize - TotalSize - NewSize;
2846 // If the new slot will make the total too large then
2847 if (AmountToShrink > 0)
2849 // If the new slot is a gallery then try changing NewSize
2850 if (NewSize != ControlSize)
2852 // Calculate the new size for this slot
2853 NewSize = (NewSize - AmountToShrink) < MIN_GALLERY_SLOT_WIDTH ? MIN_GALLERY_SLOT_WIDTH : NewSize - AmountToShrink;
2854 // Recalculate the amount to shrink
2855 AmountToShrink = MaxSize - TotalSize - NewSize;
2858 // If not a gallery or couldn't shrink enough then find another slot to shrink
2859 if (AmountToShrink > 0)
2861 for (INT32 i = 0; i < NoOfSlots; i++)
2863 if (SlotSize[i] != ControlSize)
2865 INT32 OldSize = SlotSize[i];
2866 if (OldSize > MIN_GALLERY_SLOT_WIDTH)
2868 // Calculate the new size for this slot
2869 INT32 SetSize = (OldSize - AmountToShrink) < MIN_GALLERY_SLOT_WIDTH ? MIN_GALLERY_SLOT_WIDTH : OldSize - AmountToShrink;
2871 // Resize the slot
2872 SetSlotSize(i, SetSize);
2874 // Recalculate the amount to shrink
2875 AmountToShrink -= (OldSize - SlotSize[i]);
2879 if (AmountToShrink == 0)
2880 break;
2885 // Copy the slot sizes up in the array
2886 for (INT32 i = (MAX_SLOTS - 1); i > SlotNo; i--)
2888 SlotSize[i] = SlotSize[i-1];
2890 // And set the slot inserted to the default size
2891 SlotSize[SlotNo] = NewSize;
2893 OILChildBar* FoundBar = (OILChildBar*) ChildBars.GetHead();
2894 // look for bars in or above slot to be inserted
2895 // shuffle any found forward one slot
2896 while (FoundBar != NULL)
2898 pPos = FoundBar->GetBarPos();
2899 if (pPos->Slot >= SlotNo)
2901 (pPos->Slot)++;
2902 FoundBar->UpdatePos();
2903 }// end if
2904 FoundBar = (OILChildBar*) ChildBars.GetNext(FoundBar);
2905 } // end while
2908 /********************************************************************************************
2910 > OILFixedDockingBar::GetSlotHead(CPoint ThisPoint)
2912 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
2913 Created: 23/3/94
2914 Inputs: -
2915 Outputs: -
2916 Returns: A Pointer to the first ChildBar in a given slot - NULL if none found
2917 Purpose: Find the first bar in this slot and return a pointer to it
2918 Errors: -
2919 SeeAlso:
2921 ********************************************************************************************/
2923 OILChildBar * OILFixedDockingBar::GetSlotHead(INT32 SlotNo)
2925 CPoint FoundPos;
2926 INT32 FoundSlot;
2927 OILChildBar * FoundBar =(OILChildBar *) ChildBars.GetHead();
2929 while (FoundBar != NULL) // find first bar in this slot
2931 // FoundPos = FoundBar->GetPos();
2932 // FoundSlot = PointToSlot(&FoundPos);
2933 FoundSlot = FoundBar->GetKPSlot();
2934 if (FoundSlot == SlotNo)
2935 return FoundBar;
2936 else if (FoundSlot > SlotNo)
2937 return NULL;
2939 FoundBar = (OILChildBar*) ChildBars.GetNext(FoundBar);
2942 return NULL; // no bars found
2945 /********************************************************************************************
2947 > OILFixedDockingBar::IsPointInBar(CPoint ThisPoint)
2949 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
2950 Created: 15/3/94
2951 Inputs: -
2952 Outputs: -
2953 Returns: A Pointer to a ChildBar if one is found - NULL if none found
2954 Purpose: -
2955 Errors: -
2956 SeeAlso:
2958 ********************************************************************************************/
2960 OILChildBar * OILFixedDockingBar::IsPointInBar(CPoint ThisPoint)
2963 CPoint FoundPos;
2964 CRect FoundRect;
2965 OILChildBar * FoundBar =(OILChildBar *) ChildBars.GetHead();
2967 while (FoundBar != NULL)
2970 FoundPos = FoundBar->GetPos(); // get FoundBar position and size
2971 FoundRect = FoundBar->GetRectClient();
2972 FoundRect += FoundPos; // offset rect
2973 if (FoundRect.PtInRect(ThisPoint)) // check for point in found rectangle
2974 return FoundBar;
2976 FoundBar =(OILChildBar *) ChildBars.GetNext(FoundBar);
2979 return NULL;
2982 /********************************************************************************************
2984 > OILFixedDockingBar::PositionBar(OILChildBar * ThisBar)
2986 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
2987 Created: 15/3/94
2988 Inputs: -
2989 Outputs: -
2990 Returns: -
2991 Purpose: Positions a Control Bar in this dock according to percentage overlap with
2992 other bars - If overlap > 30 a new slot will be inserted - If overlap >0
2993 < 30 it will attempt to shuffle other bars to make space
2994 Errors: -
2995 SeeAlso:
2997 ********************************************************************************************/
2999 void OILFixedDockingBar::PositionBar(OILChildBar * ThisBar)
3001 ASSERT(ThisBar != NULL);
3002 // CPoint ThisPos = ThisBar->GetPos(); //`get initial slot and position
3003 // INT32 ThisSlot = PointToSlot(&ThisPos);
3004 INT32 ThisSlot = ThisBar->GetBarPos()->Slot;
3006 // First we determine if this slot is suitable for this bar
3007 // e.g. dropping a gallery into a slot with normal bars is bad
3008 INT32 ThisSize = ThisBar->GetBarSize();
3009 // TRACE( _T("PB# ThisSize = %d\n"), ThisSize);
3011 INT32 SizeOfBarsInSlot = 0;
3012 INT32 NumBarsInSlot = 0;
3013 INT32 FoundSlot = 0;
3014 OILChildBar* FoundBar = GetSlotHead(ThisSlot);
3015 while (FoundBar != NULL) // find the largest bar in this slot
3017 FoundSlot = FoundBar->GetBarPos()->Slot;
3018 if (FoundSlot > ThisSlot) // Gone past the bars in this slot so stop
3020 break;
3022 else if (FoundSlot == ThisSlot)
3024 NumBarsInSlot++;
3025 INT32 FoundSize = FoundBar->GetBarSize();
3026 if (FoundSize > SizeOfBarsInSlot)
3027 SizeOfBarsInSlot = FoundSize;
3029 FoundBar = (OILChildBar*)ChildBars.GetNext(FoundBar);
3030 } // end while
3031 // TRACE( _T("PB# SizeOfBarsInSlot = %d\n"), SizeOfBarsInSlot);
3033 if (ThisSize != ControlSize)
3035 // If there are no bars in this slot then
3036 if (SizeOfBarsInSlot == 0)
3038 // set this slot to the required size for this bar
3039 SetSlotSize(ThisSlot, ThisSize);
3041 else
3043 // If this bar already contains a gallery then add this bar to this slot
3044 if (SizeOfBarsInSlot == ControlSize)
3046 InsertSlot(ThisSlot, ThisSize);
3048 else
3050 // set this slot to the required size for this bar
3051 SetSlotSize(ThisSlot, ThisSize);
3055 // Make sure this gets updated as it isn't in the slot yet
3056 ThisBar->UpdatePos();
3057 ::SendMessage(ThisBar->GetHwnd(), WM_SETGALLERYSIZE, SlotSize[ThisSlot], ThisBar->GetExtent());
3059 PlaceGalleryInSlot(ThisBar, ThisSlot);
3061 return;
3064 // At this point we must be positioning a normal bar
3066 // If this slot contains galleries then insert a new slot
3067 if (SizeOfBarsInSlot != 0 && SizeOfBarsInSlot != ControlSize)
3069 InsertSlot(ThisSlot); // just insert a new slot
3070 return;
3073 INT32 AreaOverlapPercent = GetIntersectPercent(ThisBar); // get Percentage Overlap
3075 if (AreaOverlapPercent > 30)
3077 // TRACE( _T("PB# > 30 inserting slot %d\n"),ThisSlot);
3078 InsertSlot(ThisSlot); // just insert a new slot
3080 else if (AreaOverlapPercent > 0)
3082 // TRACE( _T("PB# > 0 trying to place %d\n"),ThisSlot);
3084 if (!PlaceBarInSlot(ThisBar,ThisSlot))// try to shuffle and make space for this bar
3086 // TRACE( _T("PB# Couldn't place - inserting slot %d\n"),ThisSlot);
3087 InsertSlot(ThisSlot); // couldn't shuffle so insert a new slot
3090 } // do nothing if we find no overlaping bars
3095 /********************************************************************************************
3097 > OILFixedDockingBar::PlaceBar(HWND hdialog,CPoint here, CSize size)
3099 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3100 Created: 15/3/94
3101 Inputs: WindowHandle CPoint
3102 Outputs: -
3103 Returns: Success/Fail
3104 Purpose: Creates a new Child Bar then inserts it in the list - it also checks
3105 for overlap with any other bars and shuffles them until a suitable
3106 position is found
3107 Errors: -
3108 SeeAlso:
3110 ********************************************************************************************/
3112 BOOL OILFixedDockingBar::PlaceBar(HWND hdialogbar,CPoint here, CSize size)
3114 // TRACE( _T("PlaceBar x - %d y - %d\n"), here.x, here.y);
3116 DoRecalc = FALSE;
3117 OILChildBar * NewChild;
3118 //check the new window is not already attached to this bar
3119 if (IsBarInList(hdialogbar)!=NULL)
3122 TRACEALL( _T("ChildBar with this handle is already attached to this window\n"));
3123 return FALSE;
3126 if ((NewChild= new OILChildBar(hdialogbar,DockType,ControlSize))==NULL)
3129 TRACE( _T("Couldn't create new ChildBar"));
3130 return FALSE;
3134 ScreenToClient(&here); // convert to client coordinates
3135 PutInSlot(&here, NewChild->GetBarSize()); // pull to the nearest slot and set initial positions
3136 NewChild->SetPos(here); // fix initial position and size
3137 PositionBar(NewChild); // decide where to place the bar
3138 InsertBarInList(NewChild); // insert bar into list
3139 TidySlots(); // tidy slots - shuffle bars to fill empty slots
3141 if (ChangedDock != NULL && ChangedDock != this)
3142 ((OILFixedDockingBar*)ChangedDock)->TidySlots();
3144 if (DoRecalc && ! GetMainFrame()->IsChangingViewMode() )
3145 ((CFrameWnd*)Parent)->RecalcLayout();
3146 DoRecalc = FALSE ;
3147 ChangedDock = NULL;
3149 #ifdef _DEBUG
3150 if (IsUserName("GerryX"))
3152 Dump_List();
3154 #endif
3155 return TRUE;
3158 /********************************************************************************************
3160 > OILFixedDockingBar::AppendToSlot(INT32 SlotNo,CPoint * here)
3162 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3163 Created: 27/5/94
3164 Inputs: -
3165 Outputs: -
3166 Returns: -
3167 Purpose: Tags this bar onto the end of the last bar in SlotNo
3168 Errors: -
3169 SeeAlso:
3171 ********************************************************************************************/
3173 void OILFixedDockingBar::AppendToSlot(INT32 SlotNo,CPoint * here)
3175 INT32 FoundSlot = 0;
3176 INT32 LastPos = 0;
3177 INT32 LastSlot = 0;
3178 INT32 size = 0 ;
3179 KernelBarPos* pFoundPos = NULL;
3181 OILChildBar* FoundBar = (OILChildBar*)ChildBars.GetHead();
3182 while (FoundBar != NULL) // find the highest slot number in the list
3184 pFoundPos = FoundBar->GetBarPos();
3185 FoundSlot = pFoundPos->Slot;
3186 if (FoundSlot > SlotNo)
3188 break;
3190 else if (FoundSlot == SlotNo)
3192 LastPos = pFoundPos->Position + FoundBar->GetExtent();
3196 /* while (FoundBar != NULL) // find the highest slot number in the list
3198 pFoundPos = FoundBar->GetBarPos();
3199 FoundSlot = pFoundPos->Slot;
3200 if (FoundSlot > LastSlot)
3201 LastPos = 0;
3202 // gone past this slot
3203 if (FoundSlot > SlotNo)
3204 break;
3205 // get position
3206 switch(DockType)
3208 case DOCKBAR_TOP:
3209 case DOCKBAR_BOTTOM:
3210 size = FoundBar->GetRectClient().Width() ;
3211 break;
3213 case DOCKBAR_LEFT:
3214 case DOCKBAR_RIGHT:
3215 size = FoundBar->GetRectClient().Height();
3216 break;
3219 LastPos=PointToPosition(&(FoundBar->GetPos()))+ size;
3220 // new slot - reset LastPos
3222 LastSlot = FoundSlot;
3223 FoundBar =(OILChildBar *) ChildBars.GetNext(FoundBar);
3225 } // end while
3227 if (LastSlot < SlotNo)
3228 LastPos =0;
3230 switch (DockType)
3232 case DOCKBAR_TOP:
3233 case DOCKBAR_BOTTOM:
3234 here->x = LastPos;
3235 break;
3237 case DOCKBAR_LEFT:
3238 case DOCKBAR_RIGHT:
3239 here->y = LastPos;
3240 break;
3245 /********************************************************************************************
3247 > OILFixedDockingBar::PlaceBar(HWND hdialog,KernelBarPos Position, CSize size)
3249 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3250 Created: 15/3/94
3251 Inputs: Window Handle and KernelBarPos
3252 Outputs:
3253 Returns: Success/Fail
3254 Purpose: Overloaded function - creates a new Child Bar and inserts it in the list
3255 If BarPos.Position is -1 the bar will be forced into the given slot
3256 Errors: -
3257 SeeAlso:
3259 ********************************************************************************************/
3260 BOOL OILFixedDockingBar::PlaceBar(HWND hdialogbar,KernelBarPos BarPos, CSize size)
3262 // if (DockType == DOCKBAR_RIGHT)
3263 // {
3264 // TRACE( _T("PlaceBar slot - %d pos - %d\n"), BarPos.x, BarPos.y);
3265 // }
3267 DoRecalc = FALSE ;
3268 CPoint here;
3269 // get a client coordinate for this slot/offset
3270 BarPosToClient(BarPos,&here);
3271 // TRACE( _T("Client x - %d y - %d\n"), here.x, here.y);
3272 OILChildBar * NewChild;
3273 //check the new window is not already attached to this bar
3274 if (IsBarInList(hdialogbar)!=NULL)
3276 ReleaseBar(hdialogbar,FALSE);
3278 if ((NewChild= new OILChildBar(hdialogbar,DockType,ControlSize))==NULL)
3280 TRACE( _T("Couldn't create new ChildBar"));
3281 return FALSE;
3284 // check whether we need to force this bar into given slot
3285 if (BarPos.Position == -1)
3287 if (BarPos.Slot > NoOfSlots -1)
3289 BarPos.Slot = NoOfSlots -1;
3290 BarPosToClient(BarPos,&here);
3291 // TRACE( _T("Client x - %d y - %d\n"), here.x, here.y);
3293 // ScreenToClient(&here); // convert to client coordinates
3294 AppendToSlot(BarPos.Slot,&here); // Get available position on this slot
3295 NewChild->SetPos(here); //
3296 InsertBarInList(NewChild); // insert bar into list
3297 INT32 SlotsNow = CountSlots(); // check if number of slots has changed
3298 if (SlotsNow != NoOfSlots) // and RecalcLayout if it has
3300 NoOfSlots = SlotsNow;
3301 DoRecalc = TRUE;
3304 else
3306 // ScreenToClient(&here); // convert to client coordinates
3307 PutInSlot(&here, NewChild->GetBarSize()); // pull to the nearest slot and set initial positions
3308 NewChild->SetPos(here); // fix initial position and size
3309 PositionBar(NewChild); // decide where to place the bar
3310 InsertBarInList(NewChild); // insert bar into list
3311 TidySlots(); // tidy slots - shuffle bars to fill empty slots
3314 // check whether another dock has changed
3315 // if so tidy slot s and recalc layout etc..
3316 if (ChangedDock != NULL && ChangedDock != this)
3317 ((OILFixedDockingBar*)ChangedDock)->TidySlots();
3319 if (DoRecalc && ! GetMainFrame()->IsChangingViewMode())
3320 ((CFrameWnd*)Parent)->RecalcLayout();
3321 DoRecalc = FALSE ;
3323 ChangedDock = NULL;
3325 #ifdef _DEBUG
3326 if (IsUserName("GerryX"))
3328 Dump_List();
3330 #endif
3331 return TRUE;
3334 /********************************************************************************************
3336 > OILFixedDockingBar::PlaceBarAt(HWND hdialog,KernelBarPos Position)
3338 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3339 Created: 15/3/94
3340 Inputs: Window Handle and KernelBarPos
3341 Outputs:
3342 Returns: Success/Fail
3343 Purpose:
3344 Errors: -
3345 SeeAlso:
3347 ********************************************************************************************/
3350 BOOL OILFixedDockingBar::PlaceBarAt(HWND hdialogbar,KernelBarPos BarPos)
3353 // Find this child bar
3354 OILChildBar * ThisChild = (OILChildBar *) ChildBars.GetHead();
3355 while (ThisChild != NULL)
3357 if (ThisChild->GetHwnd() == hdialogbar) //found the bar
3359 break;
3361 ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);
3364 ENSURE(ThisChild!=NULL,"Can't find Bar in DockingBar List");
3366 ThisChild->SetPos(BarPos); // set child position
3368 return TRUE;
3372 /********************************************************************************************
3374 > OILFixedBar::InsertBarInList(OILChildBar * ThisBar)
3376 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3377 Created: 15/3/94
3378 Inputs: -
3379 Outputs: -
3380 Returns: Success
3381 Purpose: Inserts a ChildBar in the list in slot and position order
3382 Errors: -
3383 SeeAlso:
3385 ********************************************************************************************/
3387 BOOL OILFixedDockingBar::InsertBarInList(OILChildBar * ThisBar)
3390 ASSERT(ThisBar!=NULL);
3391 CPoint ThisPos=ThisBar->GetPos();
3392 CPoint FoundPos;
3393 OILChildBar * FoundBar =(OILChildBar *) ChildBars.GetHead();
3395 INT32 FoundSlot;
3396 INT32 FoundPosition;
3397 // get insert bar Slot and Position
3398 INT32 ThisSlot = PointToSlot(&ThisPos);
3399 INT32 ThisPosition = PointToPosition(&ThisPos);
3401 while (FoundBar != NULL)
3403 FoundPos = FoundBar->GetPos();
3404 FoundSlot = PointToSlot(&FoundPos);
3405 FoundPosition = PointToPosition(&FoundPos);
3406 if (FoundSlot > ThisSlot) // past target slot - just insert before Found slot
3408 ChildBars.InsertBefore((ListItem *)FoundBar,(ListItem *)ThisBar);
3409 return TRUE;
3411 else if (FoundSlot == ThisSlot) // Found a bar in the target slot
3413 if (FoundPosition > ThisPosition) // Put in position order
3415 ChildBars.InsertBefore((ListItem *)FoundBar,(ListItem *)ThisBar);
3416 return TRUE;
3419 FoundBar =(OILChildBar *) ChildBars.GetNext(FoundBar);
3420 } // end while
3422 // nothing found - Add to tail
3423 ChildBars.AddTail((ListItem *)ThisBar);
3424 return TRUE;
3427 /******************************************************************************************
3428 > OILFixedDockingBar::ReleaseBar(HWND hdialog,BOOL DoTidy)
3430 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3431 Created: 29/3/94
3432 Inputs: -
3433 Outputs: -
3434 Returns: Success/Fail
3435 Purpose: Search for a ChildBar with a given window handle - if found
3436 call RemoveBar to remove from list and delete Child Object
3437 Errors: -
3438 SeeAlso:
3440 ********************************************************************************************/
3442 BOOL OILFixedDockingBar::ReleaseBar(HWND hdialog,BOOL DoTidy)
3444 DoRecalc = FALSE ;
3445 // Find this child bar
3446 OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead();
3447 while (ThisChild != NULL)
3449 if (ThisChild->GetHwnd() == hdialog) //found the bar
3451 if (!RemoveBar(ThisChild)) //remove the bar
3452 return FALSE;
3453 ChangedDock = this; //"this" will be used later to force a layout tidy
3454 if (DoTidy)
3455 TidySlots();
3456 if (DoRecalc && ! GetMainFrame()->IsChangingViewMode())
3458 // there is not point in doing this if camelot is dying!
3459 // especially since this fails up our floating toolbar!
3460 if (!(GetApplication()->CamelotIsDying ()))
3462 ((CFrameWnd*)Parent)->RecalcLayout();
3465 DoRecalc = FALSE ;
3466 return TRUE;
3468 ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);
3469 }// end while
3471 return FALSE;
3476 /****************************************************************************
3478 > BOOL OILFixedDockingBar::SetSlotSize(INT32 SlotNo, INT32 NewSize)
3480 Author: Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
3481 Created: 22/10/2004
3483 Inputs: SlotNo - Index of the slot to be resized
3484 NewSize - New size of the slot
3485 Returns: TRUE if ok, FALSE if failed for any reason
3486 Purpose: Changes the size of a slot
3488 ****************************************************************************/
3490 BOOL OILFixedDockingBar::SetSlotSize(INT32 SlotNo, INT32 NewSize)
3492 if (SlotNo < 0 ||
3493 SlotNo >= MAX_SLOTS ||
3494 NewSize < ControlSize)
3495 return(FALSE);
3497 // if (SlotSize[SlotNo] != NewSize)
3498 // {
3499 // First we add up all the slot sizes
3500 if (NewSize < MIN_GALLERY_SLOT_WIDTH)
3501 NewSize = MIN_GALLERY_SLOT_WIDTH;
3502 INT32 OldSize = (SlotNo < NoOfSlots) ? SlotSize[SlotNo] : 0;
3503 INT32 TotalSize = TotalSlotSizes();
3504 CRect MainRect;
3505 GetMainFrame()->GetClientRect(&MainRect);
3506 INT32 MaxSize = (MainRect.Width() * 48) / 100;
3507 INT32 AmountToShrink = (NewSize > OldSize) ? (TotalSize - OldSize + NewSize) - MaxSize : 0;
3508 if (AmountToShrink < 0)
3509 AmountToShrink = 0;
3511 // If the new slot will make the total too large then
3512 if (AmountToShrink > 0)
3514 for (INT32 i = 0; i < NoOfSlots; i++)
3516 if (i != SlotNo && SlotSize[i] != ControlSize)
3518 INT32 OldSize = SlotSize[i];
3519 if (OldSize > MIN_GALLERY_SLOT_WIDTH)
3521 // Calculate the new size for this slot
3522 INT32 SetSize = (OldSize - AmountToShrink) < MIN_GALLERY_SLOT_WIDTH ? MIN_GALLERY_SLOT_WIDTH : OldSize - AmountToShrink;
3524 // Resize the slot
3525 SetSlotSize(i, SetSize);
3527 // Recalculate the amount to shrink
3528 AmountToShrink -= (OldSize - SlotSize[i]);
3532 if (AmountToShrink == 0)
3533 break;
3537 NewSize -= AmountToShrink;
3538 if (NewSize >= MIN_GALLERY_SLOT_WIDTH)
3540 SlotSize[SlotNo] = NewSize;
3543 KernelBarPos* FoundPos;
3544 OILChildBar* FoundBar = (OILChildBar*) ChildBars.GetHead();
3545 DoRecalc = TRUE;
3547 // Look for bars in or above the slot to be resized
3548 // If in the slot then resize them
3549 // If above the slot then move by the difference of the sizes
3550 while (FoundBar != NULL)
3552 FoundPos = FoundBar->GetBarPos();
3553 if (FoundPos->Slot == SlotNo)
3555 ::SendMessage(FoundBar->GetHwnd(), WM_SETGALLERYSIZE, NewSize, FoundBar->GetExtent());
3557 else // if (FoundPos->Slot > SlotNo)
3559 FoundBar->UpdatePos();
3561 FoundBar =(OILChildBar*) ChildBars.GetNext(FoundBar);
3563 } // end while
3564 // }
3566 return(TRUE);
3572 /////////////////////////////////////////////////////////////////////////////////////////////
3573 // OILFloaters
3574 /////////////////////////////////////////////////////////////////////////////////////////////
3577 IMPLEMENT_DYNAMIC(OILFloaters ,OILDockingBar)
3580 /////////////////////////////////////////////////////////////////////////////////////////////
3581 // OILFloaters Message Map
3582 /////////////////////////////////////////////////////////////////////////////////////////////
3584 BEGIN_MESSAGE_MAP( OILFloaters, OILDockingBar )
3585 //{{AFX_MSG_MAP( OILFloaters )
3586 ON_WM_LBUTTONDOWN()
3587 ON_WM_RBUTTONDOWN()
3588 ON_WM_LBUTTONDBLCLK()
3589 ON_MESSAGE(WM_SIZEPARENT, OnSizeParent)
3590 //}}AFX_MSG_MAP
3591 END_MESSAGE_MAP( )
3593 /********************************************************************************************
3595 > OILFloaters::Create(CWnd * pParentWnd)
3597 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3598 Created: 29/3/94
3599 Inputs: -
3600 Outputs: -
3601 Returns: -
3602 Purpose: Assigns a Parent window and Sets DockBar Type
3603 Errors: -
3604 SeeAlso:
3606 ********************************************************************************************/
3608 BOOL OILFloaters::Create(CWnd* pParentWnd)
3611 ASSERT_VALID(pParentWnd); // must have a parent
3613 Parent = pParentWnd; // Parent of this bar
3615 DockType = DOCKBAR_FLOAT; // Type of this instance
3616 return TRUE;
3619 /********************************************************************************************
3621 > OILFloaters::OILFloaters()
3623 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3624 Created: 5/3/94
3625 Inputs: -
3626 Outputs: -
3627 Returns: -
3628 Purpose: Creates and inits a OILFloaters object.
3629 Errors: -
3630 SeeAlso:
3632 ********************************************************************************************/
3634 OILFloaters::OILFloaters()
3636 ControlSize = SMALL_CONTROLS;
3637 HasBigControls = FALSE;
3641 /********************************************************************************************
3643 > BOOL OILFloaters::DeleteBars()
3645 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3646 Created: 5/3/94
3647 Inputs: -
3648 Outputs: -
3649 Returns: -
3650 Purpose: deletes all BarList items
3651 Errors: -
3652 SeeAlso:
3654 ********************************************************************************************/
3656 BOOL OILFloaters::DeleteBars()
3658 ControlSize = SMALL_CONTROLS;
3659 HasBigControls = FALSE;
3660 ChildBars.DeleteAll();
3661 return TRUE;
3663 /********************************************************************************************
3665 > OILFloaters::PlaceBar(HWND hdialog,CPoint here, CSize size = CSize(0,0))
3667 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3668 Created: 15/3/94
3669 Inputs: WindowHandle CPoint
3670 Outputs: -
3671 Returns: Success/Fail
3672 Purpose: Creates a new Child Bar then inserts it in the list - it also checks
3673 for overlap with any other bars and shuffles them until a suitable
3674 position is found;
3675 Errors: -
3676 SeeAlso:
3678 ********************************************************************************************/
3680 BOOL OILFloaters::PlaceBar(HWND hdialogbar,CPoint here, CSize size)
3682 // TRACE( _T("PlaceBar x - %d y - %d w - %d h - %d\n"), here.x, here.y, size.cx, size.cy);
3683 DoRecalc = FALSE ;
3684 OILChildBar * NewChild;
3686 if ((NewChild = new OILChildBar(hdialogbar,DockType,ControlSize))==NULL)
3688 TRACE( _T("Couldn't create new ChildBar/n"));
3689 return FALSE;
3692 NewChild->SetPos(here, size); // fix initial position and size
3693 InsertBarInList(NewChild); // insert bar into list
3695 if (ChangedDock != NULL && ChangedDock != this)
3696 ((OILFixedDockingBar*)ChangedDock)->TidySlots();
3698 if (DoRecalc)
3699 ((CFrameWnd*)Parent)->RecalcLayout();
3700 DoRecalc = FALSE ;
3701 ChangedDock=NULL;
3703 #ifdef _DEBUG
3704 if (IsUserName("GerryX"))
3706 Dump_List();
3708 #endif
3710 return TRUE;
3714 /********************************************************************************************
3716 > OILFloaters::PlaceBar(HWND hdialog,KernelBarPos Position, CSize size)
3718 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3719 Created: 15/3/94
3720 Inputs: Window Handle and KernelBarPos
3721 Outputs:
3722 Returns: Success/Fail
3723 Purpose: Overloaded function - creates a new Child Bar and inserts it in the list
3724 it assumes that there will be no overlap with other bars - this should only
3725 be called when positioning bars from file as these will have already been
3726 positioned and shuffled etc by the other PlaceBar function.
3727 Errors: -
3728 SeeAlso:
3730 ********************************************************************************************/
3732 BOOL OILFloaters::PlaceBar(HWND hdialogbar,KernelBarPos BarPos, CSize size)
3734 // TRACE( _T("PlaceBar slot - %d pos - %d Type - %d\n"), BarPos.x, BarPos.y, BarPos.Dock);
3736 DoRecalc = FALSE ;
3737 OILChildBar * NewChild;
3738 if ((NewChild= new OILChildBar(hdialogbar,DockType,ControlSize))==NULL)
3740 TRACEALL( _T("Couldn't create new ChildBar\n"));
3741 return FALSE;
3744 NewChild->SetPos(BarPos); // set child position
3745 InsertBarInList(NewChild); // insert in list
3747 if (ChangedDock != NULL && ChangedDock != this)
3748 ((OILFixedDockingBar*)ChangedDock)->TidySlots();
3750 if (DoRecalc)
3751 ((CFrameWnd*)Parent)->RecalcLayout();
3752 DoRecalc = FALSE ;
3754 ChangedDock=NULL;
3756 #ifdef _DEBUG
3757 if (IsUserName("GerryX"))
3759 Dump_List();
3761 #endif
3762 return TRUE;
3765 /********************************************************************************************
3767 > OILFloaters::InsertBarInList(OILChildBar * ThisBar)
3769 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3770 Created: 15/3/94
3771 Inputs: -
3772 Outputs: -
3773 Returns: Success
3774 Purpose: Inserts a ChildBar at the tail of the list
3775 Errors: -
3776 SeeAlso:
3778 ********************************************************************************************/
3780 BOOL OILFloaters::InsertBarInList(OILChildBar * ThisBar)
3783 ASSERT(ThisBar!=NULL);
3784 //Add to tail
3785 ChildBars.AddTail((ListItem *)ThisBar);
3787 return TRUE;
3790 /******************************************************************************************
3791 > OILFloatersBar::ReleaseBar(HWND hdialog,BOOL DoTidy)
3793 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3794 Created: 29/3/94
3795 Inputs: -
3796 Outputs: -
3797 Returns: Success/Fail
3798 Purpose: Search for a ChildBar with a given window handle - if found
3799 call RemoveBar to remove from list and delete Child Object
3800 Errors: -
3801 SeeAlso:
3803 ********************************************************************************************/
3805 BOOL OILFloaters::ReleaseBar(HWND hdialog,BOOL DoTidy)
3808 OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead();
3809 while (ThisChild != NULL)
3812 if (ThisChild->GetHwnd() == hdialog) //found the bar
3814 RemoveBar(ThisChild); //remove the bar
3815 return TRUE;
3817 ThisChild =(OILChildBar *) ChildBars.GetNext(ThisChild);
3819 }// end while
3820 //TRACE( _T("Remove Bar failed %d"),hdialog);
3821 return FALSE;
3824 /********************************************************************************************
3826 > BOOL OILFloaters::RecreateBarsAfterSettingChange()
3828 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3829 Created: 5/3/94
3830 Inputs: -
3831 Outputs: -
3832 Returns: -
3833 Purpose: Sets Big Control state
3834 Errors: -
3835 SeeAlso:
3837 ********************************************************************************************/
3838 // UIC
3840 BOOL OILFloaters::RecreateBarsAfterSettingChange()
3843 if(!BaseBar::HaveNonClientMetricsChanged())
3844 return FALSE;
3846 OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead();
3847 OILChildBar * Next;
3848 OILChildBar * EndList =(OILChildBar *) ChildBars.GetTail();
3851 while (ThisChild != NULL)
3853 Next =(OILChildBar *) ChildBars.GetNext(ThisChild);
3854 ::SendMessage(ThisChild->GetHwnd(), WM_RESIZECONTROLS, 0,0);
3856 ThisChild = Next;
3857 if (ThisChild == NULL) break;
3858 //ENSURE(ThisChild != NULL,"Bar Item = NULL");
3859 if (ThisChild == EndList)
3861 ::SendMessage(ThisChild->GetHwnd(), WM_RESIZECONTROLS, 0,0);
3862 break;
3866 return TRUE;
3868 /********************************************************************************************
3870 > OILFloaters::SetBigControlState(BOOL Big)
3872 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3873 Created: 5/3/94
3874 Inputs: -
3875 Outputs: -
3876 Returns: -
3877 Purpose: Sets Big Control state
3878 Errors: -
3879 SeeAlso:
3881 ********************************************************************************************/
3883 void OILFloaters::SetBigControlState(BOOL Big )
3885 if (Big != HasBigControls)
3887 HasBigControls = Big;
3888 if (Big)
3890 ControlSize = LARGE_CONTROLS;
3891 else
3893 ControlSize = SMALL_CONTROLS;
3895 // have to be a bit careful here DialogBar will delete and add new items
3896 // to this list when it receives the RESIZECONTROLS Message
3897 OILChildBar * ThisChild =(OILChildBar *) ChildBars.GetHead();
3898 OILChildBar * Next;
3899 OILChildBar * EndList =(OILChildBar *) ChildBars.GetTail();
3902 while (ThisChild != NULL)
3904 Next =(OILChildBar *) ChildBars.GetNext(ThisChild);
3905 ::SendMessage(ThisChild->GetHwnd(), WM_RESIZECONTROLS, 0,0);
3907 ThisChild = Next;
3908 if (ThisChild == NULL) break;
3909 //ENSURE(ThisChild != NULL,"Bar Item = NULL");
3910 if (ThisChild == EndList)
3912 ::SendMessage(ThisChild->GetHwnd(), WM_RESIZECONTROLS, 0,0);
3913 break;
3921 /////////////////////////////////////////////////////////////////////////////////////////////
3922 // OILFixedDockingBar diagnostics
3923 /////////////////////////////////////////////////////////////////////////////////////////////
3925 #ifdef _DEBUG
3926 void OILFixedDockingBar::AssertValid() const
3928 CControlBar::AssertValid();
3931 void OILFixedDockingBar::Dump(CDumpContext& dc) const
3933 CControlBar::Dump(dc);
3934 AFX_DUMP1(dc, "\nControlSize = ", (UINT32)ControlSize);
3935 AFX_DUMP1(dc, "\nNo Of Slots = ", (UINT32)NoOfSlots);
3936 AFX_DUMP1(dc, "\nWidth = ", (UINT32)DockSize.cx);
3937 AFX_DUMP1(dc, "\nHeight = ", DockSize.cy);
3940 void OILFixedDockingBar::Dump_List()
3943 CPoint ThisPos;
3944 KernelBarPos * KPos;
3946 TRACE( _T("FIXED DOCK BAR ----------\n"));
3947 OILChildBar * FoundBar =(OILChildBar *) ChildBars.GetHead();
3948 while (FoundBar != NULL)
3950 KPos=FoundBar->GetBarPos();
3951 TRACE( _T("Kernel Data slot - %d pos - %d DockType - %d\n"),KPos->Slot,KPos->Position,KPos->Dock);
3952 ThisPos=FoundBar->GetPos();
3953 TRACE( _T("Dump Bar slot - %d pos - %d\n"),PointToSlot(&ThisPos),PointToPosition(&ThisPos));
3954 FoundBar =(OILChildBar *) ChildBars.GetNext(FoundBar);
3956 TRACE( _T("....................................................................................\n"));
3960 #endif
3962 /////////////////////////////////////////////////////////////////////////////////////////////
3963 // OILDockingBar diagnostics
3964 /////////////////////////////////////////////////////////////////////////////////////////////
3966 #ifdef _DEBUG
3967 void OILDockingBar::AssertValid() const
3969 CControlBar::AssertValid();
3972 void OILDockingBar::Dump(CDumpContext& dc) const
3974 CControlBar::Dump(dc);
3978 void OILDockingBar::Dump_List()
3983 #endif
3985 /////////////////////////////////////////////////////////////////////////////////////////////
3986 // OILFloaters diagnostics
3987 /////////////////////////////////////////////////////////////////////////////////////////////
3989 #ifdef _DEBUG
3990 void OILFloaters::AssertValid() const
3992 CControlBar::AssertValid();
3995 void OILFloaters::Dump(CDumpContext& dc) const
3997 CControlBar::Dump(dc);
4001 void OILFloaters::Dump_List()
4004 CPoint ThisPos;
4005 KernelBarPos * KPos;
4007 TRACE( _T("..... FLOATING BARS .....\n "));
4008 OILChildBar * FoundBar =(OILChildBar *) ChildBars.GetHead();
4009 while (FoundBar != NULL)
4011 KPos=FoundBar->GetBarPos();
4012 TRACE( _T("Kernel Data slot - %d pos - %d Type - %d\n"),KPos->x,KPos->y,KPos->Dock);
4013 ThisPos=FoundBar->GetPos();
4014 TRACE( _T("Dump Bar Hwnd %d\n"),FoundBar->GetHwnd());
4015 FoundBar =(OILChildBar *) ChildBars.GetNext(FoundBar);
4017 TRACE( _T("..................................................................................\n"));
4021 #endif
4023 #endif