/src/libreoffice/sd/source/ui/func/fusnapln.cxx
Line | Count | Source |
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 | | #include <fusnapln.hxx> |
21 | | #include <svl/intitem.hxx> |
22 | | #include <sfx2/request.hxx> |
23 | | #include <svx/svxids.hrc> |
24 | | |
25 | | #include <strings.hrc> |
26 | | #include <sdattr.hrc> |
27 | | |
28 | | #include <View.hxx> |
29 | | #include <ViewShell.hxx> |
30 | | #include <DrawViewShell.hxx> |
31 | | #include <Window.hxx> |
32 | | #include <sdenumdef.hxx> |
33 | | #include <sdresid.hxx> |
34 | | #include <sdabstdlg.hxx> |
35 | | #include <svx/svdpagv.hxx> |
36 | | |
37 | | namespace sd { |
38 | | |
39 | | |
40 | | FuSnapLine::FuSnapLine(ViewShell& rViewSh, ::sd::Window* pWin, ::sd::View* pView, |
41 | | SdDrawDocument& rDoc, SfxRequest& rReq) : |
42 | 0 | FuPoor(rViewSh, pWin, pView, rDoc, rReq) |
43 | 0 | { |
44 | 0 | } |
45 | | |
46 | | rtl::Reference<FuPoor> FuSnapLine::Create( ViewShell& rViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument& rDoc, SfxRequest& rReq ) |
47 | 0 | { |
48 | 0 | rtl::Reference<FuPoor> xFunc( new FuSnapLine( rViewSh, pWin, pView, rDoc, rReq ) ); |
49 | 0 | xFunc->DoExecute(rReq); |
50 | 0 | return xFunc; |
51 | 0 | } |
52 | | |
53 | | void FuSnapLine::DoExecute( SfxRequest& rReq ) |
54 | 0 | { |
55 | 0 | const SfxItemSet* pArgs = rReq.GetArgs(); |
56 | 0 | sal_uInt16 nHelpLine = 0; |
57 | 0 | bool bCreateNew = true; |
58 | | |
59 | | // Get index of snap line or snap point from the request. |
60 | 0 | const SfxUInt32Item* pHelpLineIndex = rReq.GetArg(ID_VAL_INDEX); |
61 | 0 | if (pHelpLineIndex != nullptr) |
62 | 0 | { |
63 | 0 | nHelpLine = static_cast<sal_uInt16>(pHelpLineIndex->GetValue()); |
64 | | // Reset the argument pointer to trigger the display of the dialog. |
65 | 0 | pArgs = nullptr; |
66 | 0 | } |
67 | |
|
68 | 0 | SdrPageView* pPV = mpView->GetSdrPageView(); |
69 | |
|
70 | 0 | if (!pArgs) |
71 | 0 | { |
72 | 0 | SfxItemSet aNewAttr(SfxItemSet::makeFixedSfxItemSet<ATTR_SNAPLINE_START, ATTR_SNAPLINE_END>(mrViewShell.GetPool())); |
73 | 0 | bool bLineExist (false); |
74 | 0 | Point aLinePos; |
75 | |
|
76 | 0 | if (pHelpLineIndex == nullptr) |
77 | 0 | { |
78 | | // The index of the snap line is not provided as argument to the |
79 | | // request. Determine it from the mouse position. |
80 | |
|
81 | 0 | aLinePos = static_cast<DrawViewShell*>(&mrViewShell)->GetMousePos(); |
82 | |
|
83 | 0 | if ( aLinePos.X() >= 0 ) |
84 | 0 | { |
85 | 0 | aLinePos = mpWindow->PixelToLogic(aLinePos); |
86 | 0 | sal_uInt16 nHitLog = static_cast<sal_uInt16>(mpWindow->PixelToLogic(Size(HITPIX,0)).Width()); |
87 | 0 | bLineExist = mpView->PickHelpLine(aLinePos, nHitLog, *mpWindow->GetOutDev(), nHelpLine, pPV); |
88 | 0 | if ( bLineExist ) |
89 | 0 | aLinePos = (pPV->GetHelpLines())[nHelpLine].GetPos(); |
90 | 0 | else |
91 | 0 | pPV = mpView->GetSdrPageView(); |
92 | |
|
93 | 0 | pPV->LogicToPagePos(aLinePos); |
94 | 0 | } |
95 | 0 | else |
96 | 0 | aLinePos = Point(0,0); |
97 | 0 | } |
98 | 0 | else |
99 | 0 | { |
100 | 0 | assert(pPV!=nullptr); |
101 | 0 | aLinePos = (pPV->GetHelpLines())[nHelpLine].GetPos(); |
102 | 0 | pPV->LogicToPagePos(aLinePos); |
103 | 0 | bLineExist = true; |
104 | 0 | } |
105 | 0 | aNewAttr.Put(SfxInt32Item(ATTR_SNAPLINE_X, aLinePos.X())); |
106 | 0 | aNewAttr.Put(SfxInt32Item(ATTR_SNAPLINE_Y, aLinePos.Y())); |
107 | |
|
108 | 0 | SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create(); |
109 | 0 | vcl::Window* pWin = mrViewShell.GetActiveWindow(); |
110 | 0 | ScopedVclPtr<AbstractSdSnapLineDlg> pDlg( pFact->CreateSdSnapLineDlg(pWin ? pWin->GetFrameWeld() : nullptr, aNewAttr, mpView) ); |
111 | |
|
112 | 0 | if ( bLineExist ) |
113 | 0 | { |
114 | 0 | pDlg->HideRadioGroup(); |
115 | |
|
116 | 0 | const SdrHelpLine& rHelpLine = (pPV->GetHelpLines())[nHelpLine]; |
117 | |
|
118 | 0 | if ( rHelpLine.GetKind() == SdrHelpLineKind::Point ) |
119 | 0 | { |
120 | 0 | pDlg->SetText(SdResId(STR_SNAPDLG_SETPOINT)); |
121 | 0 | pDlg->SetInputFields(true, true); |
122 | 0 | } |
123 | 0 | else |
124 | 0 | { |
125 | 0 | pDlg->SetText(SdResId(STR_SNAPDLG_SETLINE)); |
126 | |
|
127 | 0 | if ( rHelpLine.GetKind() == SdrHelpLineKind::Vertical ) |
128 | 0 | pDlg->SetInputFields(true, false); |
129 | 0 | else |
130 | 0 | pDlg->SetInputFields(false, true); |
131 | 0 | } |
132 | 0 | bCreateNew = false; |
133 | 0 | } |
134 | 0 | else |
135 | 0 | pDlg->HideDeleteBtn(); |
136 | |
|
137 | 0 | sal_uInt16 nResult = pDlg->Execute(); |
138 | |
|
139 | 0 | pDlg->GetAttr(aNewAttr); |
140 | 0 | pDlg.disposeAndClear(); |
141 | |
|
142 | 0 | switch( nResult ) |
143 | 0 | { |
144 | 0 | case RET_OK: |
145 | 0 | rReq.Done(aNewAttr); |
146 | 0 | pArgs = rReq.GetArgs(); |
147 | 0 | break; |
148 | | |
149 | 0 | case RET_SNAP_DELETE: |
150 | | // delete snap object |
151 | 0 | if ( !bCreateNew ) |
152 | 0 | pPV->DeleteHelpLine(nHelpLine); |
153 | 0 | [[fallthrough]]; |
154 | 0 | default: |
155 | 0 | return; |
156 | 0 | } |
157 | 0 | } |
158 | 0 | Point aHlpPos; |
159 | |
|
160 | 0 | aHlpPos.setX( pArgs->Get(ATTR_SNAPLINE_X).GetValue() ); |
161 | 0 | aHlpPos.setY( pArgs->Get(ATTR_SNAPLINE_Y).GetValue() ); |
162 | 0 | pPV->PagePosToLogic(aHlpPos); |
163 | |
|
164 | 0 | if ( bCreateNew ) |
165 | 0 | { |
166 | 0 | SdrHelpLineKind eKind; |
167 | |
|
168 | 0 | pPV = mpView->GetSdrPageView(); |
169 | |
|
170 | 0 | switch ( static_cast<SnapKind>(pArgs->Get(ATTR_SNAPLINE_KIND).GetValue()) ) |
171 | 0 | { |
172 | 0 | case SnapKind::Horizontal : eKind = SdrHelpLineKind::Horizontal; break; |
173 | 0 | case SnapKind::Vertical : eKind = SdrHelpLineKind::Vertical; break; |
174 | 0 | default : eKind = SdrHelpLineKind::Point; break; |
175 | 0 | } |
176 | 0 | pPV->InsertHelpLine(SdrHelpLine(eKind, aHlpPos)); |
177 | 0 | } |
178 | 0 | else |
179 | 0 | { |
180 | 0 | const SdrHelpLine& rHelpLine = (pPV->GetHelpLines())[nHelpLine]; |
181 | 0 | pPV->SetHelpLine(nHelpLine, SdrHelpLine(rHelpLine.GetKind(), aHlpPos)); |
182 | 0 | } |
183 | 0 | } |
184 | | |
185 | | void FuSnapLine::Activate() |
186 | 0 | { |
187 | 0 | } |
188 | | |
189 | | void FuSnapLine::Deactivate() |
190 | 0 | { |
191 | 0 | } |
192 | | |
193 | | } // end of namespace sd |
194 | | |
195 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |