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
33 Conditional upon your continuing compliance with the GNU General Public
34 License described above, Xara Group Ltd grants to you certain additional
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.
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
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).
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.
96 =================================XARAHEADEREND============================
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]
108 #define IS_CHICAGO ((LOBYTE(LOWORD(GetVersion()))) > 3)
110 #define MIN_GALLERY_SLOT_WIDTH 100
112 BOOL
OILFixedDockingBar::allowTidyBars
= TRUE
;
116 /////////////////////////////////////////////////////////////////////////////////////////////
117 // OILDockingBar Base Class //
118 /////////////////////////////////////////////////////////////////////////////////////////////
120 IMPLEMENT_DYNAMIC(OILDockingBar
,CControlBar
)
124 static char BASED_CODE THIS_FILE
[] = __FILE__
;
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 )
146 /////////////////////////////////////////////////////////////////////////////////////////////
147 // OILDockingBar Creation Destruction and Initialisation
148 /////////////////////////////////////////////////////////////////////////////////////////////
150 /********************************************************************************************
152 > OILDockingBar::OILDockingBar()
154 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
159 Purpose: Creates an OILDockingBar object.
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>
180 Purpose: Destroys an OILDockingBar object and deletes all BarList items
184 ********************************************************************************************/
186 OILDockingBar::~OILDockingBar()
188 ChildBars
.DeleteAll();
192 /******************************************************************************************
193 > void OILDockingBar::OnUpdateCmdUI()
195 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
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>
220 Returns: Succed or Fail
221 Purpose: Remove OILChildBar from List and delete ListItem if successful
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
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>
252 Returns: TRUE if success FALSE otherwise
253 Purpose: change the hwnd of a bar list item
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
);
270 ThisChild
=(OILChildBar
*) ChildBars
.GetNext(ThisChild
);
273 ENSURE(ThisChild
!=NULL
,"Couldn't find HWND in BarList");
278 /********************************************************************************************
280 > OILChildBar * OILDockingBar::IsBarInList(HWND)
282 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
286 Returns: Found Child or NULL
287 Purpose: determine whether a childbar is in this docks list
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
302 ThisChild
=(OILChildBar
*) ChildBars
.GetNext(ThisChild
);
309 /********************************************************************************************
311 > OILChildBar * OILDockingBar::IsBarInList(StringBase * Name )
313 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
317 Returns: Found Child or NULL
318 Purpose: determine whether a childbar is in this docks list
322 ********************************************************************************************/
324 OILChildBar
* OILDockingBar::IsBarInList(StringBase
*Name
)
326 OILChildBar
* ThisChild
=(OILChildBar
*) ChildBars
.GetHead();
327 while (ThisChild
!= NULL
)
330 ::GetWindowText(ThisChild
->GetHwnd(),buff
,63);
331 if (String_32(buff
)== *Name
) // found the bar
334 ThisChild
=(OILChildBar
*) ChildBars
.GetNext(ThisChild
);
340 /********************************************************************************************
342 > HWND OILDockingBar::IsScreenPointInBar(CPoint pnt)
344 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
348 Returns: Found HWND or NULL
349 Purpose: determine whether a screen point is in a childbar of this dock
353 ********************************************************************************************/
355 HWND
OILDockingBar::IsScreenPointInBar(CPoint pnt
)
358 OILChildBar
* ThisChild
=(OILChildBar
*) ChildBars
.GetHead();
360 while (ThisChild
!= NULL
)
362 if (hwnd
= ThisChild
->GetHwnd()) // found the bar
365 ::GetWindowRect(hwnd
,&sRect
);
366 if(sRect
.PtInRect(pnt
))
371 ThisChild
=(OILChildBar
*) ChildBars
.GetNext(ThisChild
);
376 /********************************************************************************************
378 > KernelBarPos * OILDockingBar::GetBarPos(HWND)
380 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
384 Returns: Found Position
385 Purpose: To return a Pointer to the KernelBarPos of a Child dialogbar
389 ********************************************************************************************/
391 KernelBarPos
* OILDockingBar::GetBarPos(HWND hwnd
)
393 OILChildBar
* ThisChild
;
394 if ((ThisChild
=IsBarInList(hwnd
))!=NULL
)
396 return ThisChild
->GetBarPos();
403 /********************************************************************************************
405 > CRect OILDockingBar::GetBarRect(StringBase * Name)
407 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
411 Returns: Found Position
412 Purpose: To return the rectangle of the specified bar
416 ********************************************************************************************/
418 CRect
OILDockingBar::GetBarRect(StringBase
* Name
)
420 OILChildBar
* ThisChild
;
421 if ((ThisChild
=IsBarInList(Name
))!=NULL
)
422 return ThisChild
->GetRectFromBar();
424 return CRect(0, 0, 0, 0);
429 /****************************************************************************
431 > CRect OILDockingBar::GetBarRect(HWND hwnd)
433 Author: Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
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();
448 return CRect(0, 0, 0, 0);
452 /********************************************************************************************
454 > KernelBarPos * OILDockingBar::GetBarPos(StringBase * Name)
456 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
460 Returns: Found Position
461 Purpose: To return a Pointer to the KernelBarPos of a Child dialogbar
465 ********************************************************************************************/
467 KernelBarPos
* OILDockingBar::GetBarPos(StringBase
* Name
)
469 OILChildBar
* ThisChild
;
470 if ((ThisChild
=IsBarInList(Name
))!=NULL
)
472 return ThisChild
->GetBarPos();
478 /********************************************************************************************
480 > void OILDockingBar::SetBigControlState(BOOL Big)
482 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
487 Purpose: Sets Big Control state
491 ********************************************************************************************/
493 void OILDockingBar::SetBigControlState(BOOL Big
)
495 HasBigControls
= Big
;
497 ControlSize
=LARGE_CONTROLS
;
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
);
511 /********************************************************************************************
513 > BOOL OILDockingBar::IsBigControls()
515 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
519 Returns: True if BigControls
520 Purpose: Determines whether DockingBar contains large controls
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
)
553 /********************************************************************************************
555 > BOOL OILFixedDockingBar::Create(CWnd* pParentWnd,DockBarType ReqType, UINT32 id)
557 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
562 Purpose: Creates the OILDockingBar window.
566 ********************************************************************************************/
568 BOOL
OILFixedDockingBar::Create(CWnd
* pParentWnd
,DockBarType ReqType
, UINT32 id
)
570 // BackBrush.CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
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
589 m_dwStyle
= WS_CHILD
|WS_VISIBLE
|WS_CLIPCHILDREN
;
591 // VC6 doesn't like any style flags other than CBRS_ flags set
592 // for CControlBar-derived windows
597 CreatedWindow
= CWnd::Create(NULL
,
605 // Must make the control bar visible in VC6 builds
609 return CreatedWindow
;
614 /********************************************************************************************
616 > OILFixedDockingBar::OILFixedDockingBar()
618 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
623 Purpose: Creates an OILDockingBar object.
627 ********************************************************************************************/
629 OILFixedDockingBar::OILFixedDockingBar()
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>
650 Purpose: deletes all BarList items
654 ********************************************************************************************/
656 BOOL
OILFixedDockingBar::DeleteBars()
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();
667 /////////////////////////////////////////////////////////////////////////////////////////////
669 ////////////////////////////////////////////////////////////////////////////////////////////
672 /********************************************************************************************
674 > void OILFixedDockingBar::DoPaint(WPARAM, LPARAM lParam)
676 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
678 Inputs: pointer to a device context
681 Purpose: Paints docking bar background and border
685 ********************************************************************************************/
686 void OILFixedDockingBar::DoPaint(CDC
* pDC
)
692 GetClientRect(rect
); // get the size of this bar
693 CBrush
hbrFrame (GetSysColor(COLOR_BTNFACE
));
698 Outline
= GetSysColor(COLOR_BTNSHADOW
);
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);
716 pDC
->Rectangle(rect
.left
-1,rect
.top
-1,rect
.right
,rect
.bottom
+1);
719 pDC
->Rectangle(rect
.left
-1,rect
.top
-1,rect
.right
+1,rect
.bottom
);
722 pDC
->Rectangle(rect
.left
,rect
.top
-1,rect
.right
+1,rect
.bottom
+1);
725 pDC
->Rectangle(rect
.left
-1,rect
.top
,rect
.right
+1,rect
.bottom
+1);
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>
745 Purpose: Is called from OnSizeParent to reposition the docking bars - replacing
746 Afx_RepositionWindow which forces a total redraw !
749 ********************************************************************************************/
752 void OILFixedDockingBar::RepositionWindow(AFX_SIZEPARENTPARAMS FAR
* lpLayout
,
753 HWND hWnd
, LPCRECT lpRect
)
758 ENSURE(FALSE
,"Reposition NULL Window ");
763 ENSURE(FALSE
,"NULL Reposition Rectangle");
767 CRect
InvalRect(0,0,0,0);
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
780 GetWindowRect(rectOld
); //old window position in screen coords
781 GetParent()->ClientToScreen(&Check
);
783 // no change - get out of here
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
);
797 InvalRect
.SetRect(Check
.left
,Check
.top
,rectOld
.right
,Check
.bottom
);
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
));
808 if( Check
.left
!= rectOld
.left
|| Check
.top
!= rectOld
.top
)
809 InvalRect
.SetRect(Check
.left
,Check
.top
,Check
.right
,Check
.bottom
);
811 InvalRect
.SetRect(rectOld
.right
,Check
.top
,Check
.right
,Check
.bottom
);
815 if(Check
.top
== rectOld
.top
)
817 if (Check
.bottom
> rectOld
.bottom
)
818 InvalRect
.SetRect(Check
.left
,rectOld
.bottom
,Check
.right
,Check
.bottom
);
820 InvalRect
.SetRect(Check
.left
,Check
.bottom
,Check
.right
,rectOld
.bottom
);
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
));
831 if( Check
.left
!= rectOld
.left
|| Check
.top
!= rectOld
.top
)
832 InvalRect
.SetRect(Check
.left
,Check
.top
,Check
.right
,Check
.bottom
);
834 InvalRect
.SetRect(Check
.left
,rectOld
.bottom
,Check
.right
,Check
.bottom
);
837 InvalRect
.SetRect(rectOld
.left
,rectOld
.bottom
,rectOld
.right
,rectOld
.bottom
);
842 SetWindowPos(NULL
, lpRect
->left
,
843 lpRect
->top
, lpRect
->right
- lpRect
->left
, lpRect
->bottom
- lpRect
->top
,
844 SWP_NOACTIVATE
|SWP_NOZORDER
|SWP_NOREDRAW
);
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>
875 Purpose: Afx private Message - Resizes Docking Bar and Parent MDIClient Window
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
;
886 CRect
LayoutRect(lpLayout
->rect
);
888 SetSize(LayoutRect
,&rect
);
894 lpLayout
->rect
.left
+= TotalSlotSizes();// left-hand side of this window
896 // lpLayout->rect.left--;
899 lpLayout
->rect
.right
-= TotalSlotSizes();// right-hand side of this window
902 lpLayout
->rect
.top
+= TotalSlotSizes();// top of this window
904 // lpLayout->rect.top--;
907 lpLayout
->rect
.bottom
-= TotalSlotSizes();// bottom of this window
909 // lpLayout->rect.bottom ++;
912 ENSURE(0, "Unknown Dockingbar type!");
916 // call our Reposition window for more redraw control
918 RepositionWindow(lpLayout
, m_hWnd
, &rect
);
924 /////////////////////////////////////////////////////////////////////////////////////////////
925 // OILFixedDocking Bar General Functions
926 /////////////////////////////////////////////////////////////////////////////////////////////
929 INT32
OILFixedDockingBar::TotalSlotSizes(INT32 Slot
/* = -1 */)
936 for (INT32 i
= 0; i
< Slot
; i
++)
937 TotalSize
+= SlotSize
[i
];
942 /********************************************************************************************
944 > void OILFixedDockingBar::SetBigControlState(BOOL Big)
946 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
951 Purpose: Sets Big Control state
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
;
966 NewSize
= LARGE_CONTROLS
;
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++)
979 // SlotSize[i] = NewSize;
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();
990 OILChildBar
* EndList
=(OILChildBar
*) ChildBars
.GetTail();
992 while (ThisChild
!= NULL
)
994 Next
=(OILChildBar
*) ChildBars
.GetNext(ThisChild
);
995 ::SendMessage(ThisChild
->GetHwnd(), WM_RESIZECONTROLS
, 0,0);
997 if (ThisChild
== NULL
)
999 if (ThisChild
== EndList
)
1001 ::SendMessage(ThisChild
->GetHwnd(), WM_RESIZECONTROLS
, 0,0);
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
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>
1029 Inputs: Screen Point
1032 Purpose: determines whether a screen point is currently in or near a fixed dockingbar
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
1048 rect
.right
= ControlSize
;
1051 rect
.left
= - (INT32
)ControlSize
;
1054 rect
.bottom
= ControlSize
;
1056 case DOCKBAR_BOTTOM
:
1057 rect
.top
= - (INT32
)ControlSize
;
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>
1076 Purpose: determines whether a screen rectangle intersects a fixed dockingbar
1080 ********************************************************************************************/
1082 void OILFixedDockingBar::GetDockScreenRect(CRect
* BarRect
)
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>
1103 Purpose: determines whether a screen rectangle intersects a fixed dockingbar
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
1123 case DOCKBAR_BOTTOM
:
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>
1142 Inputs: MDIClient area
1143 Outputs: new bar size
1145 Purpose: Sizes a DockingBar Window according to type and the MainFrame Client Window .
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
1159 rect
->right
=ClientRect
.left
+ TotalSlotSizes();
1162 rect
->left
= ClientRect
.right
- TotalSlotSizes();
1165 rect
->bottom
= ClientRect
.top
+ TotalSlotSizes();
1167 case DOCKBAR_BOTTOM
:
1168 rect
->top
= ClientRect
.bottom
- TotalSlotSizes();
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>
1185 Returns: slot number according to dock type
1186 Purpose: determine Slot number according to DockType given a Client Coord
1190 ********************************************************************************************/
1192 INT32
OILFixedDockingBar::PointToSlot(CPoint
* ThisPoint
)
1194 if (ControlSize
== 0)
1198 // return a slot number according to dock type and control size
1202 case DOCKBAR_BOTTOM
:
1203 Value
= ThisPoint
->y
;
1208 Value
= ThisPoint
->x
;
1213 // Loop through slots until size totals more than coord
1214 for (INT32 i
= 0; i
< MAX_SLOTS
; i
++)
1216 Total
+= SlotSize
[i
];
1225 /********************************************************************************************
1227 > void OILFixedDockingBar::BarPosToClient();
1229 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1232 Outputs: Client x/y given slot and position
1234 Purpose: determine Client coordinate in dock from a KernelBarPos
1238 ********************************************************************************************/
1240 void OILFixedDockingBar::BarPosToClient(KernelBarPos Pos
,CPoint
* Point
)
1242 // return a slot number according to dock type and control size
1246 case DOCKBAR_BOTTOM
:
1247 Point
->x
= Pos
.Position
;
1248 Point
->y
= TotalSlotSizes(Pos
.Slot
);
1253 Point
->y
= Pos
.Position
;
1254 Point
->x
= TotalSlotSizes(Pos
.Slot
);
1259 /********************************************************************************************
1261 > void OILFixedDockingBar::BarPosToScreen(KernelBarPos Pos,CPoint * Point);
1263 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1266 Outputs: Screen x/y given slot and position
1268 Purpose: determine Screen coordinate in dock from a KernelBarPos
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>
1288 Returns: position in slot according to dock type
1289 Purpose: determine pixel offset inslot according to Docktype given a client coord
1293 ********************************************************************************************/
1295 INT32
OILFixedDockingBar::PointToPosition(CPoint
* ThisPoint
)
1297 //return pixel offset in slot according to dock type
1301 case DOCKBAR_BOTTOM
:
1302 return ThisPoint
->x
;
1307 return ThisPoint
->y
;
1315 ////////////////////////////////////////////////////////////////////////////////////////////
1316 // Child Bar Placement
1317 ////////////////////////////////////////////////////////////////////////////////////////////
1319 /********************************************************************************************
1321 > INT32 OILFixedDockingBar::GetIntersectPercent(OILChildbar * ThisBar)
1323 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1327 Returns: Percentage of interesect area with other bars in this dock
1332 ********************************************************************************************/
1334 INT32
OILFixedDockingBar::GetIntersectPercent(OILChildBar
* ThisBar
)
1339 CRect ThisRect
= ThisBar
->GetRectClient();
1340 CPoint ThisPoint
= ThisBar
->GetPos();
1342 INT32 ThisArea
= ThisRect
.right
*ThisRect
.bottom
;
1343 INT32 FoundArea
= 0;
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
);
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>
1379 Outputs: pointer to new bar slot position
1381 Purpose: snap an x or y coordinate to nearest slot
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);
1404 case DOCKBAR_BOTTOM
: // snap y to nearest slot
1406 BarMidPoint
= position
->y
+ (Size
/ 2);
1407 if (position
->x
< 0)
1410 if (position
->y
< MidPoint
)
1412 position
->y
= SlotStart
;
1416 position
->y
= SlotStart
+ SlotSize
[PointSlot
];
1420 case DOCKBAR_LEFT
: // snap y to nearest slot
1422 BarMidPoint
= position
->x
+ (Size
/ 2);
1424 if (position
->y
< 0)
1427 if (BarMidPoint
< SlotEnd
)
1429 position
->x
= SlotStart
;
1433 position
->x
= SlotStart
+ SlotSize
[PointSlot
];
1436 /* if (position->x < MidPoint)
1438 position->x = SlotStart;
1442 position->x = SlotStart + SlotSize[PointSlot];
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>
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
1463 ********************************************************************************************/
1465 BOOL
OILFixedDockingBar::ShiftBarPos(CPoint
* position
, INT32 Amount
)
1471 case DOCKBAR_LEFT
: // check that new position is within dockbar
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
1480 case DOCKBAR_BOTTOM
:
1481 NewPos
= position
->x
+ Amount
;
1482 if (NewPos
< 0 || NewPos
>= DockSize
.cx
)
1484 position
->x
= NewPos
; // OK set position
1491 /********************************************************************************************
1493 > OILFixedDockingBar::ShiftBarSlot(CPoint * position, INT32 NoSlots)
1495 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1499 Returns: Success / Fail
1500 Purpose: Shift a bar by the given number of slots
1504 ********************************************************************************************/
1506 BOOL
OILFixedDockingBar::ShiftBarSlot(CPoint
* position
, INT32 NoSlots
)
1508 INT32 StartSlot
= PointToSlot(position
);
1509 INT32 NewPos
= TotalSlotSizes(NoSlots
+ StartSlot
);
1515 position
->x
= NewPos
; // OK set position
1519 case DOCKBAR_BOTTOM
:
1520 position
->y
= NewPos
; // OK set position
1527 /********************************************************************************************
1529 > OILFixedDockingBar::CheckAndCorrectOverlap()
1531 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1536 Purpose: To tidy up any posible overlap after changing the size of the bars
1537 ( between Small/Large controls etc..)
1541 ********************************************************************************************/
1543 void OILFixedDockingBar::CheckAndCorrectOverlap()
1546 INT32 RightOfLastBar
= 0;
1547 INT32 ThisBarStart
= 0;
1550 INT32 AmountToMove
= 0;
1551 BOOL TidyUpSlots
= FALSE
;
1554 OILChildBar
* ThisChild
= (OILChildBar
*) ChildBars
.GetHead();
1555 if (ThisChild
== NULL
)
1557 CPoint ThisPos
= ThisChild
->GetPos();
1558 RightOfLastBar
= PointToPosition( &ThisPos
) + ThisChild
->GetExtent();
1559 LastSlot
= PointToSlot( &ThisPos
);
1561 while (ThisChild
!= NULL
)
1564 ThisChild
= (OILChildBar
*) ChildBars
.GetNext( ThisChild
);
1567 if (ThisChild
== NULL
)
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
);
1590 // Insert a slot and move there
1591 InsertSlot( ThisSlot
+ 1 );
1592 ShiftBarSlot( &ThisPos
,1 );
1593 ThisChild
->SetPos( ThisPos
);
1595 RightOfLastBar
= ThisBarStart
= 0;
1600 RightOfLastBar
= PointToPosition( &ThisPos
) + ThisChild
->GetExtent();
1601 LastSlot
= ThisSlot
;
1608 ((CFrameWnd
*)Parent
)->RecalcLayout();
1613 /********************************************************************************************
1615 > OILFixedDockingBar::CanShuffleForward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
1617 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
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
1624 Purpose: determine whether bars in this slot can be shuffled along without
1627 SeeAlso: CanShuffleBackward / CanShuffleBackward / DoShuffleForward
1629 ********************************************************************************************/
1631 BOOL
OILFixedDockingBar::CanShuffleForward(OILChildBar
* Start
,OILChildBar
* End
, INT32 Amount
)
1637 INT32 RightOfBar
= 0;
1638 INT32 LeftOfBar
= 0;
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
;
1658 LeftOfBar
= PointToPosition(&(ThisChild
->GetPos()));
1660 AmountToMove
= RightOfBar
- LeftOfBar
;
1662 if (AmountToMove
== 0) // break if nothing to move
1666 if (AmountToMove
> 0)
1671 /********************************************************************************************
1673 > OILFixedDockingBar::DoShuffleForward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
1675 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
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
1683 SeeAlso: CanShuffleBackward / CanShuffleBackward / DoShuffleForward
1685 ********************************************************************************************/
1687 BOOL
OILFixedDockingBar::DoShuffleForward(OILChildBar
* Start
,OILChildBar
* End
, INT32 Amount
)
1693 if (!CanShuffleForward(Start
,End
,Amount
))
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
;
1717 LeftOfBar
= PointToPosition(&(ThisChild
->GetPos()));
1719 AmountToMove
= RightOfBar
- LeftOfBar
; // find overlap
1721 if (AmountToMove
== 0)
1722 break; // break if nothing to move
1730 /********************************************************************************************
1732 > OILFixedDockingBar::CanShuffleBackward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
1734 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
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
1741 Purpose: determine whether bars in this slot can be shuffled along without
1744 SeeAlso: DoShuffleBackward / CanShuffleForward / DoShuffleForward
1746 ********************************************************************************************/
1748 BOOL
OILFixedDockingBar::CanShuffleBackward(OILChildBar
* Start
,OILChildBar
* End
, INT32 Amount
)
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
1772 RightOfBar
= PointToPosition(&(ThisChild
->GetPos())) + ThisChild
->GetExtent();
1774 AmountToMove
=RightOfBar
-LeftOfBar
;
1775 if (AmountToMove
<=0) // break if nothing to move
1782 /********************************************************************************************
1784 > OILFixedDockingBar::DoShuffleBackward(OILChildBar * Start,OILChildBar * End, INT32 Amount)
1786 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1790 Returns: Success/Fail if bar has been shuffled forwards
1791 Purpose: Move all bars in this slot <<<<
1793 SeeAlso: CanShuffleBackward / CanShuffleForward / DoShuffleForward
1795 ********************************************************************************************/
1797 BOOL
OILFixedDockingBar::DoShuffleBackward(OILChildBar
* Start
,OILChildBar
* End
, INT32 Amount
)
1803 if (!CanShuffleBackward(Start
,End
,Amount
))
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
1824 RightOfBar
= PointToPosition(&(ThisChild
->GetPos())) + ThisChild
->GetExtent();
1826 AmountToMove
=RightOfBar
-LeftOfBar
;
1827 if (AmountToMove
<=0) // break if nothing to move
1834 /********************************************************************************************
1836 > OILFixedDockingBar::GetOverLap(OILChildBar * ThisBar,INT32 SlotNo, INT32 * ForwardOverlap,
1837 INT32 * BackwardOverlap)
1839 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
1841 Inputs: New ChildBar - Slot No
1842 Outputs: ForwardOverlap BackwardOverlap
1843 Returns: Pointer to nearest bar if found
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
)
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
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();
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
);
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>
1941 Inputs: ThisBar - pointer to a OILChildBar
1943 ForwardOverlap- pointer to a INT32
1944 BackwardOverlap- pointer to a INT32
1945 Returns: NULL in times of grief
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;
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
;
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
);
1991 // TRACE( _T("CheckBar at %d\n"), CheckBar->GetKPPos());
1995 // TRACE( _T("CheckBar is NULL\n"));
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
)
2007 // TRACE( _T("PreviousBar at %d\n"), PreviousBar->GetKPPos());
2011 // TRACE( _T("PreviousBar is NULL\n"));
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
;
2025 *ppPrevious
= PreviousBar
;
2026 *BackwardOverlap
= (PreviousBar
->GetKPPos() + PreviousBar
->GetExtent()) - ThisMin
;
2030 *BackwardOverlap
= -ThisMin
;
2035 // Calculate forward overlap with CheckBar
2036 // Calculate backward overlap with PreviousBar or from zero if NULL or wrong slot
2040 *ForwardOverlap
= ThisMax
- CheckBar
->GetKPPos();
2045 *ppPrevious
= PreviousBar
;
2046 *BackwardOverlap
= (PreviousBar
->GetKPPos() + PreviousBar
->GetExtent()) - ThisMin
;
2050 *BackwardOverlap
= -ThisMin
;
2058 /********************************************************************************************
2060 > OILFixedDockingBar::PlaceBarInSlot(OILChildBar * ThisBar)
2062 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
2064 Inputs: New ChildBar - Slot No
2066 Returns: Success / Fail
2067 Purpose: attempts to shuffle bars in a given slot allowing a new bar to be placed with
2069 Errors: Assert ThisBar != NULL
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
;
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
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
),
2134 // return to state before failure
2135 ThisBar
->SetPos(LastPos
);
2142 // return to state before failure
2143 ThisBar
->SetPos(LastPos
);
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
),
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
);
2179 // return to state before fail
2180 ThisBar
->SetPos(LastPos
);
2181 if (DoneShuffleForward
)
2182 DoShuffleForward((OILChildBar
*) ChildBars
.GetNext(FoundNearest
),
2183 StartNextSlot
, ForwardDone
);
2187 }// end if BackwardOverlap>0
2189 }// end else (FoundNearest != NULL)
2195 /****************************************************************************
2197 > BOOL OILFixedDockingBar::PlaceGalleryInSlot(OILChildBar * ThisBar, INT32 SlotNo)
2199 Author: Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
2202 Inputs: ThisBar - pointer to a OILChildBar
2204 Returns: TRUE if ok, FALSE if bother
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");
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
);
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
)
2250 TempBar
= (OILChildBar
*)ChildBars
.GetNext(TempBar
);
2255 OILChildBar
* MoveBar
= FirstBar
;
2256 OILChildBar
* EndBar
= (OILChildBar
*)ChildBars
.GetNext(PreviousBar
);
2258 while (MoveBar
&& MoveBar
!= EndBar
)
2260 if (MoveBar
->GetBarPos()->Position
!= CurPos
)
2262 MoveBar
->GetBarPos()->Position
= CurPos
;
2263 MoveBar
->UpdatePos();
2266 CurPos
+= MoveBar
->GetExtent();
2267 MoveBar
= (OILChildBar
*)ChildBars
.GetNext(MoveBar
);
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();
2286 MoveBar
= (OILChildBar
*)ChildBars
.GetPrev(MoveBar
);
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
);
2315 GetGalleryOverLap(ThisBar
,SlotNo
,&TempFor
,&TempBack
, NULL
, NULL
);
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)
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
);
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
);
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);
2385 // Need to fill up the gap
2386 ::SendMessage(PreviousBar
->GetHwnd(), WM_SETGALLERYSIZE
, PreviousBar
->GetBarSize(), PreviousBar
->GetExtent() - BackwardOverlap
);
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)
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
);
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
);
2480 MoveBar
->GetBarPos()->Position
+= TempBack
;
2481 MoveBar
->UpdatePos();
2484 MoveBar
= (OILChildBar
*)ChildBars
.GetNext(MoveBar
);
2487 if (LastBar
&& TempFor
+ TempBack
> 0)
2489 ::SendMessage(LastBar
->GetHwnd(), WM_SETGALLERYSIZE
, LastBar
->GetBarSize(), LastBar
->GetExtent() - (TempFor
+ TempBack
));
2496 // There is a gap before the next bar so move and resize the next bar to
2498 NextBar
->GetBarPos()->Position
+= ForwardOverlap
;
2499 NextBar
->UpdatePos();
2500 ::SendMessage(NextBar
->GetHwnd(), WM_SETGALLERYSIZE
, NextBar
->GetBarSize(), NextBar
->GetExtent() - ForwardOverlap
);
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
);
2516 /********************************************************************************************
2518 > OILFixedDockingBar::TidySlots()
2520 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
2525 Purpose: move bars to fill any empty slots
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
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
2555 LastSlot = FoundSlot;
2556 FoundBar = (OILChildBar*)ChildBars.GetNext(FoundBar);
2562 OILChildBar* TempPrev = NULL;
2563 OILChildBar* TempNext = NULL;
2564 GetGalleryOverLap(NextBar, SlotNo, &TempF, &TempB, &TempPrev, &TempNext);
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
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
)
2593 ThisBar
= (OILChildBar
*)ChildBars
.GetNext(ThisBar
);
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();
2616 // Resize the bar by (-ForwardOverlap-BackwardOverlap)
2617 INT32 SizeDiff
= -(ForwardOverlap
+BackwardOverlap
);
2620 ::SendMessage(ThisBar
->GetHwnd(), WM_SETGALLERYSIZE
, ThisBar
->GetBarSize(), ThisBar
->GetExtent() + SizeDiff
);
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
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
);
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
2681 INT32 SlotsNow
= CountSlots(); // check if number of slots has changed
2683 if (SlotsNow
!= NumSlots
) // and RecalcLayout if it has
2685 NoOfSlots
= SlotsNow
;
2690 OILChildBar
* ThisChild
=(OILChildBar
*) ChildBars
.GetHead();
2692 while (ThisChild
!= NULL
)
2694 ThisChild
->InvalidateIfMoved();
2695 ThisChild
=(OILChildBar
*) ChildBars
.GetNext(ThisChild
);
2702 /********************************************************************************************
2704 > OILFixedDockingBar::CountSlots()
2706 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
2710 Returns: number of slots in this dock
2711 Purpose: Count how many slots are in this bar
2715 ********************************************************************************************/
2717 INT32
OILFixedDockingBar::CountSlots()
2719 if (ChildBars
.IsEmpty()) // no bars in list
2722 OILChildBar
* FoundBar
= (OILChildBar
*)ChildBars
.GetTail();
2723 if (FoundBar
== NULL
) // Shouldn't happen but I'll check to make sure
2726 return(FoundBar
->GetKPSlot() + 1);
2728 /* INT32 FoundSlot = 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);
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>
2756 Purpose: Remove a slot - shuffle all ChildBars beyond this slot backwards
2757 Errors: ASSERT slot number >0
2760 ********************************************************************************************/
2762 void OILFixedDockingBar::RemoveSlot(INT32 SlotNo
)
2764 ASSERT(SlotNo
>= 0 && SlotNo
< NoOfSlots
);
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
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();
2802 if (pPos
->Slot
> SlotNo
)
2804 // FoundPos.x -= MoveSize;
2805 pPos
->Slot
-= 1; // Move it back a slot
2806 FoundBar
->UpdatePos();
2810 // FoundBar->SetPos(FoundPos);
2811 FoundBar
=(OILChildBar
*) ChildBars
.GetNext(FoundBar
);
2816 /********************************************************************************************
2818 > OILFixedDockingBar::InsertSlot(INT32 SlotNo, INT32 NewSize = -1)
2820 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
2825 Purpose: Insert a Slot - shuffle all ChildBars beyond this slot number forwards
2826 Errors: ASSERT Slot number >0
2829 ********************************************************************************************/
2831 void OILFixedDockingBar::InsertSlot(INT32 SlotNo
, INT32 NewSize
)
2833 ASSERT(SlotNo
>= 0 && SlotNo
< NoOfSlots
);
2834 KernelBarPos
* pPos
= NULL
;
2837 NewSize
= ControlSize
;
2839 // First we add up all the slot sizes
2840 INT32 TotalSize
= TotalSlotSizes();
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
;
2872 SetSlotSize(i
, SetSize
);
2874 // Recalculate the amount to shrink
2875 AmountToShrink
-= (OldSize
- SlotSize
[i
]);
2879 if (AmountToShrink
== 0)
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
)
2902 FoundBar
->UpdatePos();
2904 FoundBar
= (OILChildBar
*) ChildBars
.GetNext(FoundBar
);
2908 /********************************************************************************************
2910 > OILFixedDockingBar::GetSlotHead(CPoint ThisPoint)
2912 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
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
2921 ********************************************************************************************/
2923 OILChildBar
* OILFixedDockingBar::GetSlotHead(INT32 SlotNo
)
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
)
2936 else if (FoundSlot
> SlotNo
)
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>
2953 Returns: A Pointer to a ChildBar if one is found - NULL if none found
2958 ********************************************************************************************/
2960 OILChildBar
* OILFixedDockingBar::IsPointInBar(CPoint ThisPoint
)
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
2976 FoundBar
=(OILChildBar
*) ChildBars
.GetNext(FoundBar
);
2982 /********************************************************************************************
2984 > OILFixedDockingBar::PositionBar(OILChildBar * ThisBar)
2986 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
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
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
3022 else if (FoundSlot
== ThisSlot
)
3025 INT32 FoundSize
= FoundBar
->GetBarSize();
3026 if (FoundSize
> SizeOfBarsInSlot
)
3027 SizeOfBarsInSlot
= FoundSize
;
3029 FoundBar
= (OILChildBar
*)ChildBars
.GetNext(FoundBar
);
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
);
3043 // If this bar already contains a gallery then add this bar to this slot
3044 if (SizeOfBarsInSlot
== ControlSize
)
3046 InsertSlot(ThisSlot
, ThisSize
);
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
);
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
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>
3101 Inputs: WindowHandle CPoint
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
3110 ********************************************************************************************/
3112 BOOL
OILFixedDockingBar::PlaceBar(HWND hdialogbar
,CPoint here
, CSize size
)
3114 // TRACE( _T("PlaceBar x - %d y - %d\n"), here.x, here.y);
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"));
3126 if ((NewChild
= new OILChildBar(hdialogbar
,DockType
,ControlSize
))==NULL
)
3129 TRACE( _T("Couldn't create new ChildBar"));
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();
3150 if (IsUserName("GerryX"))
3158 /********************************************************************************************
3160 > OILFixedDockingBar::AppendToSlot(INT32 SlotNo,CPoint * here)
3162 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3167 Purpose: Tags this bar onto the end of the last bar in SlotNo
3171 ********************************************************************************************/
3173 void OILFixedDockingBar::AppendToSlot(INT32 SlotNo
,CPoint
* here
)
3175 INT32 FoundSlot
= 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
)
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)
3202 // gone past this slot
3203 if (FoundSlot > SlotNo)
3209 case DOCKBAR_BOTTOM:
3210 size = FoundBar->GetRectClient().Width() ;
3215 size = FoundBar->GetRectClient().Height();
3219 LastPos=PointToPosition(&(FoundBar->GetPos()))+ size;
3220 // new slot - reset LastPos
3222 LastSlot = FoundSlot;
3223 FoundBar =(OILChildBar *) ChildBars.GetNext(FoundBar);
3227 if (LastSlot < SlotNo)
3233 case DOCKBAR_BOTTOM
:
3245 /********************************************************************************************
3247 > OILFixedDockingBar::PlaceBar(HWND hdialog,KernelBarPos Position, CSize size)
3249 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3251 Inputs: Window Handle and KernelBarPos
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
3259 ********************************************************************************************/
3260 BOOL
OILFixedDockingBar::PlaceBar(HWND hdialogbar
,KernelBarPos BarPos
, CSize size
)
3262 // if (DockType == DOCKBAR_RIGHT)
3264 // TRACE( _T("PlaceBar slot - %d pos - %d\n"), BarPos.x, BarPos.y);
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"));
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
;
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();
3326 if (IsUserName("GerryX"))
3334 /********************************************************************************************
3336 > OILFixedDockingBar::PlaceBarAt(HWND hdialog,KernelBarPos Position)
3338 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3340 Inputs: Window Handle and KernelBarPos
3342 Returns: Success/Fail
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
3361 ThisChild
=(OILChildBar
*) ChildBars
.GetNext(ThisChild
);
3364 ENSURE(ThisChild
!=NULL
,"Can't find Bar in DockingBar List");
3366 ThisChild
->SetPos(BarPos
); // set child position
3372 /********************************************************************************************
3374 > OILFixedBar::InsertBarInList(OILChildBar * ThisBar)
3376 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3381 Purpose: Inserts a ChildBar in the list in slot and position order
3385 ********************************************************************************************/
3387 BOOL
OILFixedDockingBar::InsertBarInList(OILChildBar
* ThisBar
)
3390 ASSERT(ThisBar
!=NULL
);
3391 CPoint ThisPos
=ThisBar
->GetPos();
3393 OILChildBar
* FoundBar
=(OILChildBar
*) ChildBars
.GetHead();
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
);
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
);
3419 FoundBar
=(OILChildBar
*) ChildBars
.GetNext(FoundBar
);
3422 // nothing found - Add to tail
3423 ChildBars
.AddTail((ListItem
*)ThisBar
);
3427 /******************************************************************************************
3428 > OILFixedDockingBar::ReleaseBar(HWND hdialog,BOOL DoTidy)
3430 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
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
3440 ********************************************************************************************/
3442 BOOL
OILFixedDockingBar::ReleaseBar(HWND hdialog
,BOOL DoTidy
)
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
3453 ChangedDock
= this; //"this" will be used later to force a layout tidy
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();
3468 ThisChild
=(OILChildBar
*) ChildBars
.GetNext(ThisChild
);
3476 /****************************************************************************
3478 > BOOL OILFixedDockingBar::SetSlotSize(INT32 SlotNo, INT32 NewSize)
3480 Author: Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
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
)
3493 SlotNo
>= MAX_SLOTS
||
3494 NewSize
< ControlSize
)
3497 // if (SlotSize[SlotNo] != NewSize)
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();
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)
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
;
3525 SetSlotSize(i
, SetSize
);
3527 // Recalculate the amount to shrink
3528 AmountToShrink
-= (OldSize
- SlotSize
[i
]);
3532 if (AmountToShrink
== 0)
3537 NewSize
-= AmountToShrink
;
3538 if (NewSize
>= MIN_GALLERY_SLOT_WIDTH
)
3540 SlotSize
[SlotNo
] = NewSize
;
3543 KernelBarPos
* FoundPos
;
3544 OILChildBar
* FoundBar
= (OILChildBar
*) ChildBars
.GetHead();
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
);
3572 /////////////////////////////////////////////////////////////////////////////////////////////
3574 /////////////////////////////////////////////////////////////////////////////////////////////
3577 IMPLEMENT_DYNAMIC(OILFloaters
,OILDockingBar
)
3580 /////////////////////////////////////////////////////////////////////////////////////////////
3581 // OILFloaters Message Map
3582 /////////////////////////////////////////////////////////////////////////////////////////////
3584 BEGIN_MESSAGE_MAP( OILFloaters
, OILDockingBar
)
3585 //{{AFX_MSG_MAP( OILFloaters )
3588 ON_WM_LBUTTONDBLCLK()
3589 ON_MESSAGE(WM_SIZEPARENT
, OnSizeParent
)
3593 /********************************************************************************************
3595 > OILFloaters::Create(CWnd * pParentWnd)
3597 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3602 Purpose: Assigns a Parent window and Sets DockBar Type
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
3619 /********************************************************************************************
3621 > OILFloaters::OILFloaters()
3623 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3628 Purpose: Creates and inits a OILFloaters object.
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>
3650 Purpose: deletes all BarList items
3654 ********************************************************************************************/
3656 BOOL
OILFloaters::DeleteBars()
3658 ControlSize
= SMALL_CONTROLS
;
3659 HasBigControls
= FALSE
;
3660 ChildBars
.DeleteAll();
3663 /********************************************************************************************
3665 > OILFloaters::PlaceBar(HWND hdialog,CPoint here, CSize size = CSize(0,0))
3667 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3669 Inputs: WindowHandle CPoint
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
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);
3684 OILChildBar
* NewChild
;
3686 if ((NewChild
= new OILChildBar(hdialogbar
,DockType
,ControlSize
))==NULL
)
3688 TRACE( _T("Couldn't create new ChildBar/n"));
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();
3699 ((CFrameWnd
*)Parent
)->RecalcLayout();
3704 if (IsUserName("GerryX"))
3714 /********************************************************************************************
3716 > OILFloaters::PlaceBar(HWND hdialog,KernelBarPos Position, CSize size)
3718 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3720 Inputs: Window Handle and KernelBarPos
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.
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);
3737 OILChildBar
* NewChild
;
3738 if ((NewChild
= new OILChildBar(hdialogbar
,DockType
,ControlSize
))==NULL
)
3740 TRACEALL( _T("Couldn't create new ChildBar\n"));
3744 NewChild
->SetPos(BarPos
); // set child position
3745 InsertBarInList(NewChild
); // insert in list
3747 if (ChangedDock
!= NULL
&& ChangedDock
!= this)
3748 ((OILFixedDockingBar
*)ChangedDock
)->TidySlots();
3751 ((CFrameWnd
*)Parent
)->RecalcLayout();
3757 if (IsUserName("GerryX"))
3765 /********************************************************************************************
3767 > OILFloaters::InsertBarInList(OILChildBar * ThisBar)
3769 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3774 Purpose: Inserts a ChildBar at the tail of the list
3778 ********************************************************************************************/
3780 BOOL
OILFloaters::InsertBarInList(OILChildBar
* ThisBar
)
3783 ASSERT(ThisBar
!=NULL
);
3785 ChildBars
.AddTail((ListItem
*)ThisBar
);
3790 /******************************************************************************************
3791 > OILFloatersBar::ReleaseBar(HWND hdialog,BOOL DoTidy)
3793 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
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
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
3817 ThisChild
=(OILChildBar
*) ChildBars
.GetNext(ThisChild
);
3820 //TRACE( _T("Remove Bar failed %d"),hdialog);
3824 /********************************************************************************************
3826 > BOOL OILFloaters::RecreateBarsAfterSettingChange()
3828 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3833 Purpose: Sets Big Control state
3837 ********************************************************************************************/
3840 BOOL
OILFloaters::RecreateBarsAfterSettingChange()
3843 if(!BaseBar::HaveNonClientMetricsChanged())
3846 OILChildBar
* ThisChild
=(OILChildBar
*) ChildBars
.GetHead();
3848 OILChildBar
* EndList
=(OILChildBar
*) ChildBars
.GetTail();
3851 while (ThisChild
!= NULL
)
3853 Next
=(OILChildBar
*) ChildBars
.GetNext(ThisChild
);
3854 ::SendMessage(ThisChild
->GetHwnd(), WM_RESIZECONTROLS
, 0,0);
3857 if (ThisChild
== NULL
) break;
3858 //ENSURE(ThisChild != NULL,"Bar Item = NULL");
3859 if (ThisChild
== EndList
)
3861 ::SendMessage(ThisChild
->GetHwnd(), WM_RESIZECONTROLS
, 0,0);
3868 /********************************************************************************************
3870 > OILFloaters::SetBigControlState(BOOL Big)
3872 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
3877 Purpose: Sets Big Control state
3881 ********************************************************************************************/
3883 void OILFloaters::SetBigControlState(BOOL Big
)
3885 if (Big
!= HasBigControls
)
3887 HasBigControls
= Big
;
3890 ControlSize
= LARGE_CONTROLS
;
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();
3899 OILChildBar
* EndList
=(OILChildBar
*) ChildBars
.GetTail();
3902 while (ThisChild
!= NULL
)
3904 Next
=(OILChildBar
*) ChildBars
.GetNext(ThisChild
);
3905 ::SendMessage(ThisChild
->GetHwnd(), WM_RESIZECONTROLS
, 0,0);
3908 if (ThisChild
== NULL
) break;
3909 //ENSURE(ThisChild != NULL,"Bar Item = NULL");
3910 if (ThisChild
== EndList
)
3912 ::SendMessage(ThisChild
->GetHwnd(), WM_RESIZECONTROLS
, 0,0);
3921 /////////////////////////////////////////////////////////////////////////////////////////////
3922 // OILFixedDockingBar diagnostics
3923 /////////////////////////////////////////////////////////////////////////////////////////////
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()
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"));
3962 /////////////////////////////////////////////////////////////////////////////////////////////
3963 // OILDockingBar diagnostics
3964 /////////////////////////////////////////////////////////////////////////////////////////////
3967 void OILDockingBar::AssertValid() const
3969 CControlBar::AssertValid();
3972 void OILDockingBar::Dump(CDumpContext
& dc
) const
3974 CControlBar::Dump(dc
);
3978 void OILDockingBar::Dump_List()
3985 /////////////////////////////////////////////////////////////////////////////////////////////
3986 // OILFloaters diagnostics
3987 /////////////////////////////////////////////////////////////////////////////////////////////
3990 void OILFloaters::AssertValid() const
3992 CControlBar::AssertValid();
3995 void OILFloaters::Dump(CDumpContext
& dc
) const
3997 CControlBar::Dump(dc
);
4001 void OILFloaters::Dump_List()
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"));