1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include "precompiled_sfx2.hxx"
23 
24 #include "SidebarDockingWindow.hxx"
25 #include "sfx2/sidebar/SidebarChildWindow.hxx"
26 #include "SidebarController.hxx"
27 
28 #include "sfx2/bindings.hxx"
29 #include "sfx2/dispatch.hxx"
30 #include <tools/link.hxx>
31 
32 using namespace css;
33 using namespace cssu;
34 
35 
36 namespace sfx2 { namespace sidebar {
37 
38 
39 SidebarDockingWindow::SidebarDockingWindow(
40     SfxBindings* pSfxBindings,
41     SidebarChildWindow& rChildWindow,
42     Window* pParentWindow,
43     WinBits nBits)
44     : SfxDockingWindow(pSfxBindings, &rChildWindow, pParentWindow, nBits),
45       mpSidebarController()
46 {
47     // Get the XFrame from the bindings.
48     if (pSfxBindings==NULL || pSfxBindings->GetDispatcher()==NULL)
49     {
50         OSL_ASSERT(pSfxBindings!=NULL);
51         OSL_ASSERT(pSfxBindings->GetDispatcher()!=NULL);
52     }
53     else
54     {
55         const SfxViewFrame* pViewFrame = pSfxBindings->GetDispatcher()->GetFrame();
56         const SfxFrame& rFrame = pViewFrame->GetFrame();
57         mpSidebarController.set(new sfx2::sidebar::SidebarController(this, rFrame.GetFrameInterface()));
58     }
59 }
60 
61 
62 
63 
64 SidebarDockingWindow::~SidebarDockingWindow (void)
65 {
66     DoDispose();
67 }
68 
69 
70 
71 
72 void SidebarDockingWindow::DoDispose (void)
73 {
74 }
75 
76 
77 
78 
79 void SidebarDockingWindow::GetFocus()
80 {
81     mpSidebarController->GetFocusManager().GrabFocus();
82 }
83 
84 
85 
86 
87 SfxChildWindow* SidebarDockingWindow::GetChildWindow (void)
88 {
89     return GetChildWindow_Impl();
90 }
91 
92 
93 
94 
95 sal_Bool SidebarDockingWindow::Close (void)
96 {
97     if (mpSidebarController.is())
98     {
99         // Do not close the floating window.
100         // Dock it and close just the deck instead.
101         SetFloatingMode(sal_False);
102         mpSidebarController->RequestCloseDeck();
103         mpSidebarController->NotifyResize();
104         return sal_False;
105     }
106     else
107         return SfxDockingWindow::Close();
108 }
109 
110 
111 
112 
113 SfxChildAlignment SidebarDockingWindow::CheckAlignment (
114     SfxChildAlignment eCurrentAlignment,
115     SfxChildAlignment eRequestedAlignment)
116 {
117     switch (eRequestedAlignment)
118     {
119         case SFX_ALIGN_TOP:
120         case SFX_ALIGN_HIGHESTTOP:
121         case SFX_ALIGN_LOWESTTOP:
122         case SFX_ALIGN_BOTTOM:
123         case SFX_ALIGN_LOWESTBOTTOM:
124         case SFX_ALIGN_HIGHESTBOTTOM:
125             return eCurrentAlignment;
126 
127         case SFX_ALIGN_LEFT:
128         case SFX_ALIGN_RIGHT:
129         case SFX_ALIGN_FIRSTLEFT:
130         case SFX_ALIGN_LASTLEFT:
131         case SFX_ALIGN_FIRSTRIGHT:
132         case SFX_ALIGN_LASTRIGHT:
133             return eRequestedAlignment;
134 
135         default:
136             return eRequestedAlignment;
137     }
138 }
139 
140 
141 } } // end of namespace sfx2::sidebar
142