Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include "TaskPaneShellManager.hxx"
22 : :
23 : : #include "ViewShellManager.hxx"
24 : : #include <tools/diagnose_ex.h>
25 : : #include <vcl/window.hxx>
26 : :
27 : : #include <algorithm>
28 : :
29 : : namespace sd { namespace toolpanel {
30 : :
31 : 26 : TaskPaneShellManager::TaskPaneShellManager (
32 : : const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager,
33 : : const ViewShell& rViewShell)
34 : : : mpViewShellManager(rpViewShellManager),
35 : : mrViewShell(rViewShell),
36 [ + - ][ + - ]: 26 : maSubShells()
37 : : {
38 : 26 : }
39 : :
40 : :
41 : :
42 : :
43 [ + - ]: 26 : TaskPaneShellManager::~TaskPaneShellManager (void)
44 : : {
45 [ - + ]: 26 : while ( ! maSubShells.empty())
46 [ # # ]: 0 : RemoveSubShell(maSubShells.begin()->second.mpShell);
47 [ - + ]: 52 : }
48 : :
49 : :
50 : :
51 : :
52 : 15 : SfxShell* TaskPaneShellManager::CreateShell( ShellId nId, ::Window* , FrameView* )
53 : : {
54 [ + - ]: 15 : SubShells::const_iterator iShell (maSubShells.find(nId));
55 [ + - ]: 15 : if (iShell != maSubShells.end())
56 : 15 : return iShell->second.mpShell;
57 : : else
58 : 15 : return NULL;
59 : : }
60 : :
61 : :
62 : :
63 : :
64 : 15 : void TaskPaneShellManager::ReleaseShell (SfxShell* )
65 : : {
66 : : // Nothing to do.
67 : 15 : }
68 : :
69 : 15 : void TaskPaneShellManager::AddSubShell (
70 : : ShellId nId,
71 : : SfxShell* pShell,
72 : : ::Window* pWindow)
73 : : {
74 [ + - ]: 15 : if (pShell != NULL)
75 : : {
76 : 15 : maSubShells[nId] = ShellDescriptor(pShell,pWindow);
77 [ + - ]: 15 : if (pWindow != NULL)
78 : : {
79 [ + - ]: 15 : pWindow->AddEventListener(LINK(this,TaskPaneShellManager,WindowCallback));
80 [ - + ]: 15 : if (pWindow->IsReallyVisible())
81 : 0 : mpViewShellManager->ActivateSubShell(mrViewShell, nId);
82 : : }
83 : : else
84 : 0 : mpViewShellManager->ActivateSubShell(mrViewShell, nId);
85 : : }
86 : 15 : }
87 : :
88 : :
89 : :
90 : :
91 : 0 : void TaskPaneShellManager::RemoveSubShell (const ShellId i_nShellId)
92 : : {
93 [ # # ]: 0 : SubShells::iterator pos = maSubShells.find( i_nShellId );
94 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( pos != maSubShells.end(), "no shell for this ID" );
95 [ # # ]: 0 : if ( pos->second.mpWindow != NULL )
96 : : {
97 [ # # ][ # # ]: 0 : pos->second.mpWindow->RemoveEventListener( LINK( this, TaskPaneShellManager, WindowCallback ) );
98 : : }
99 [ # # ]: 0 : mpViewShellManager->DeactivateSubShell( mrViewShell, pos->first );
100 [ # # ]: 0 : maSubShells.erase( pos );
101 : : }
102 : :
103 : :
104 : :
105 : :
106 : 15 : void TaskPaneShellManager::RemoveSubShell (const SfxShell* pShell)
107 : : {
108 [ + - ]: 15 : if (pShell != NULL)
109 : : {
110 : 15 : SubShells::iterator iShell;
111 [ + - ]: 30 : for (iShell=maSubShells.begin(); iShell!=maSubShells.end(); ++iShell)
112 [ + - ]: 15 : if (iShell->second.mpShell == pShell)
113 : : {
114 [ + - ]: 15 : if (iShell->second.mpWindow != NULL)
115 : 15 : iShell->second.mpWindow->RemoveEventListener(
116 [ + - + - ]: 30 : LINK(this,TaskPaneShellManager,WindowCallback));
117 [ + - ]: 15 : mpViewShellManager->DeactivateSubShell(mrViewShell,iShell->first);
118 [ + - ]: 15 : maSubShells.erase(iShell);
119 : 15 : break;
120 : : }
121 : : }
122 : 15 : }
123 : :
124 : :
125 : :
126 : :
127 : 0 : void TaskPaneShellManager::MoveToTop (SfxShell* pShell)
128 : : {
129 : 0 : SubShells::const_iterator iShell;
130 [ # # ]: 0 : for (iShell=maSubShells.begin(); iShell!=maSubShells.end(); ++iShell)
131 [ # # ]: 0 : if (iShell->second.mpShell == pShell)
132 : : {
133 [ # # ]: 0 : ViewShellManager::UpdateLock aLocker (mpViewShellManager);
134 [ # # ]: 0 : mpViewShellManager->MoveSubShellToTop(mrViewShell,iShell->first);
135 [ # # ]: 0 : mpViewShellManager->MoveToTop(mrViewShell);
136 [ # # ]: 0 : break;
137 : : }
138 : 0 : }
139 : :
140 : :
141 : :
142 : :
143 : 160 : IMPL_LINK(TaskPaneShellManager, WindowCallback, VclWindowEvent*, pEvent)
144 : : {
145 [ + - ]: 160 : if (pEvent != NULL)
146 : : {
147 : 160 : SubShells::const_iterator iShell;
148 : 160 : ::Window* pWindow = pEvent->GetWindow();
149 [ + - ]: 160 : for (iShell=maSubShells.begin(); iShell!=maSubShells.end(); ++iShell)
150 [ + - ]: 160 : if (iShell->second.mpWindow == pWindow)
151 : 160 : break;
152 [ + - ]: 160 : if (iShell != maSubShells.end())
153 [ + + + ]: 160 : switch (pEvent->GetId())
154 : : {
155 : : case VCLEVENT_WINDOW_SHOW:
156 [ + - ]: 30 : mpViewShellManager->ActivateSubShell(mrViewShell,iShell->first);
157 : 30 : break;
158 : :
159 : : case VCLEVENT_WINDOW_HIDE:
160 : : // Do not activate the sub shell. This leads to
161 : : // problems with shapes currently being in text edit
162 : : // mode: Deactivating the shell leads to leaving the
163 : : // text editing mode.
164 : : // mpViewShellManager->DeactivateSubShell(mrViewShell,iShell->first);
165 : 160 : break;
166 : : }
167 : : }
168 : :
169 : 160 : return 0;
170 : : }
171 : :
172 : :
173 : : } } // end of namespace ::sd::toolpanel
174 : :
175 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|