xref: /trunk/main/sd/source/ui/func/fusnapln.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "fusnapln.hxx"
28cdf0e10cSrcweir #include <svl/aeitem.hxx>
29cdf0e10cSrcweir #include <vcl/msgbox.hxx>
30cdf0e10cSrcweir #include <sfx2/request.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include "strings.hrc"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "sdattr.hxx"
36cdf0e10cSrcweir #include "View.hxx"
37cdf0e10cSrcweir #include "ViewShell.hxx"
38cdf0e10cSrcweir #include "DrawViewShell.hxx"
39cdf0e10cSrcweir #ifndef SD_WINDOW_SHELL_HXX
40cdf0e10cSrcweir #include "Window.hxx"
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #include "sdenumdef.hxx"
43cdf0e10cSrcweir #include "sdresid.hxx"
44cdf0e10cSrcweir #include "sdabstdlg.hxx"
45cdf0e10cSrcweir #include "app.hrc"
46cdf0e10cSrcweir #include <svx/svdpagv.hxx>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir namespace sd {
49cdf0e10cSrcweir 
50cdf0e10cSrcweir TYPEINIT1( FuSnapLine, FuPoor );
51cdf0e10cSrcweir 
52cdf0e10cSrcweir /*************************************************************************
53cdf0e10cSrcweir |*
54cdf0e10cSrcweir |* Konstruktor
55cdf0e10cSrcweir |*
56cdf0e10cSrcweir \************************************************************************/
57cdf0e10cSrcweir 
FuSnapLine(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)58cdf0e10cSrcweir FuSnapLine::FuSnapLine(ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView,
59cdf0e10cSrcweir                        SdDrawDocument* pDoc, SfxRequest& rReq) :
60cdf0e10cSrcweir     FuPoor(pViewSh, pWin, pView, pDoc, rReq)
61cdf0e10cSrcweir {
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
Create(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)64cdf0e10cSrcweir FunctionReference FuSnapLine::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     FunctionReference xFunc( new FuSnapLine( pViewSh, pWin, pView, pDoc, rReq ) );
67cdf0e10cSrcweir     xFunc->DoExecute(rReq);
68cdf0e10cSrcweir     return xFunc;
69cdf0e10cSrcweir }
70cdf0e10cSrcweir 
DoExecute(SfxRequest & rReq)71cdf0e10cSrcweir void FuSnapLine::DoExecute( SfxRequest& rReq )
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     const SfxItemSet* pArgs = rReq.GetArgs();
74cdf0e10cSrcweir     SdrPageView* pPV = 0;
75cdf0e10cSrcweir     sal_uInt16  nHelpLine = 0;
76cdf0e10cSrcweir     sal_Bool    bCreateNew = sal_True;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     // Get index of snap line or snap point from the request.
79cdf0e10cSrcweir     SFX_REQUEST_ARG (rReq, pHelpLineIndex, SfxUInt32Item, ID_VAL_INDEX, sal_False);
80cdf0e10cSrcweir     if (pHelpLineIndex != NULL)
81cdf0e10cSrcweir     {
82cdf0e10cSrcweir         nHelpLine = static_cast<sal_uInt16>(pHelpLineIndex->GetValue());
83cdf0e10cSrcweir         // Reset the argument pointer to trigger the display of the dialog.
84cdf0e10cSrcweir         pArgs = NULL;
85cdf0e10cSrcweir     }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     if ( !pArgs )
88cdf0e10cSrcweir     {
89cdf0e10cSrcweir         SfxItemSet aNewAttr(mpViewShell->GetPool(), ATTR_SNAPLINE_START, ATTR_SNAPLINE_END);
90cdf0e10cSrcweir         bool bLineExist (false);
91cdf0e10cSrcweir         pPV = mpView->GetSdrPageView();
92cdf0e10cSrcweir         Point aLinePos;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         if (pHelpLineIndex == NULL)
95cdf0e10cSrcweir         {
96cdf0e10cSrcweir             // The index of the snap line is not provided as argument to the
97cdf0e10cSrcweir             // request.  Determine it from the mouse position.
98cdf0e10cSrcweir 
99cdf0e10cSrcweir             aLinePos = static_cast<DrawViewShell*>(mpViewShell)->GetMousePos();
100cdf0e10cSrcweir             static_cast<DrawViewShell*>(mpViewShell)->SetMousePosFreezed( sal_False );
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 
103cdf0e10cSrcweir             if ( aLinePos.X() >= 0 )
104cdf0e10cSrcweir             {
105cdf0e10cSrcweir                 aLinePos = mpWindow->PixelToLogic(aLinePos);
106cdf0e10cSrcweir                 sal_uInt16 nHitLog = (sal_uInt16) mpWindow->PixelToLogic(Size(HITPIX,0)).Width();
107cdf0e10cSrcweir                 bLineExist = mpView->PickHelpLine(aLinePos, nHitLog, *mpWindow, nHelpLine, pPV);
108cdf0e10cSrcweir                 if ( bLineExist )
109cdf0e10cSrcweir                     aLinePos = (pPV->GetHelpLines())[nHelpLine].GetPos();
110cdf0e10cSrcweir                 else
111cdf0e10cSrcweir                     pPV = mpView->GetSdrPageView();
112cdf0e10cSrcweir 
113cdf0e10cSrcweir                 pPV->LogicToPagePos(aLinePos);
114cdf0e10cSrcweir             }
115cdf0e10cSrcweir             else
116cdf0e10cSrcweir                 aLinePos = Point(0,0);
117cdf0e10cSrcweir         }
118cdf0e10cSrcweir         else
119cdf0e10cSrcweir         {
120cdf0e10cSrcweir             OSL_ASSERT(pPV!=NULL);
121cdf0e10cSrcweir             aLinePos = (pPV->GetHelpLines())[nHelpLine].GetPos();
122cdf0e10cSrcweir             pPV->LogicToPagePos(aLinePos);
123cdf0e10cSrcweir             bLineExist = true;
124cdf0e10cSrcweir         }
125cdf0e10cSrcweir         aNewAttr.Put(SfxUInt32Item(ATTR_SNAPLINE_X, aLinePos.X()));
126cdf0e10cSrcweir         aNewAttr.Put(SfxUInt32Item(ATTR_SNAPLINE_Y, aLinePos.Y()));
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
129cdf0e10cSrcweir         AbstractSdSnapLineDlg* pDlg = pFact ? pFact->CreateSdSnapLineDlg( NULL, aNewAttr, mpView ) : 0;
130cdf0e10cSrcweir         if( pDlg )
131cdf0e10cSrcweir         {
132cdf0e10cSrcweir             if ( bLineExist )
133cdf0e10cSrcweir             {
134cdf0e10cSrcweir                 pDlg->HideRadioGroup();
135cdf0e10cSrcweir 
136cdf0e10cSrcweir                 const SdrHelpLine& rHelpLine = (pPV->GetHelpLines())[nHelpLine];
137cdf0e10cSrcweir 
138cdf0e10cSrcweir                 if ( rHelpLine.GetKind() == SDRHELPLINE_POINT )
139cdf0e10cSrcweir                 {
140cdf0e10cSrcweir                     pDlg->SetText(String(SdResId(STR_SNAPDLG_SETPOINT)));
141cdf0e10cSrcweir                     pDlg->SetInputFields(sal_True, sal_True);
142cdf0e10cSrcweir                 }
143cdf0e10cSrcweir                 else
144cdf0e10cSrcweir                 {
145cdf0e10cSrcweir                     pDlg->SetText(String(SdResId(STR_SNAPDLG_SETLINE)));
146cdf0e10cSrcweir 
147cdf0e10cSrcweir                     if ( rHelpLine.GetKind() == SDRHELPLINE_VERTICAL )
148cdf0e10cSrcweir                         pDlg->SetInputFields(sal_True, sal_False);
149cdf0e10cSrcweir                     else
150cdf0e10cSrcweir                         pDlg->SetInputFields(sal_False, sal_True);
151cdf0e10cSrcweir                 }
152cdf0e10cSrcweir                 bCreateNew = sal_False;
153cdf0e10cSrcweir             }
154cdf0e10cSrcweir             else
155cdf0e10cSrcweir                 pDlg->HideDeleteBtn();
156cdf0e10cSrcweir 
157cdf0e10cSrcweir             sal_uInt16 nResult = pDlg->Execute();
158cdf0e10cSrcweir 
159cdf0e10cSrcweir             pDlg->GetAttr(aNewAttr);
160cdf0e10cSrcweir             delete pDlg;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir             switch( nResult )
163cdf0e10cSrcweir             {
164cdf0e10cSrcweir                 case RET_OK:
165cdf0e10cSrcweir                     rReq.Done(aNewAttr);
166cdf0e10cSrcweir                     pArgs = rReq.GetArgs();
167cdf0e10cSrcweir                     break;
168cdf0e10cSrcweir 
169cdf0e10cSrcweir                 case RET_SNAP_DELETE:
170cdf0e10cSrcweir                     // Fangobjekt loeschen
171cdf0e10cSrcweir                     if ( !bCreateNew )
172cdf0e10cSrcweir                         pPV->DeleteHelpLine(nHelpLine);
173cdf0e10cSrcweir                     // und weiter wie bei default
174cdf0e10cSrcweir                 default:
175cdf0e10cSrcweir                     return;
176cdf0e10cSrcweir             }
177cdf0e10cSrcweir         }
178cdf0e10cSrcweir     }
179cdf0e10cSrcweir     Point aHlpPos;
180cdf0e10cSrcweir 
181cdf0e10cSrcweir     aHlpPos.X() = ((const SfxUInt32Item&) pArgs->Get(ATTR_SNAPLINE_X)).GetValue();
182cdf0e10cSrcweir     aHlpPos.Y() = ((const SfxUInt32Item&) pArgs->Get(ATTR_SNAPLINE_Y)).GetValue();
183cdf0e10cSrcweir     pPV->PagePosToLogic(aHlpPos);
184cdf0e10cSrcweir 
185cdf0e10cSrcweir     if ( bCreateNew )
186cdf0e10cSrcweir     {
187cdf0e10cSrcweir         SdrHelpLineKind eKind;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         pPV = mpView->GetSdrPageView();
190cdf0e10cSrcweir 
191cdf0e10cSrcweir         switch ( (SnapKind) ((const SfxAllEnumItem&)
192cdf0e10cSrcweir                  pArgs->Get(ATTR_SNAPLINE_KIND)).GetValue() )
193cdf0e10cSrcweir         {
194cdf0e10cSrcweir             case SK_HORIZONTAL  : eKind = SDRHELPLINE_HORIZONTAL;   break;
195cdf0e10cSrcweir             case SK_VERTICAL    : eKind = SDRHELPLINE_VERTICAL;     break;
196cdf0e10cSrcweir             default             : eKind = SDRHELPLINE_POINT;        break;
197cdf0e10cSrcweir         }
198cdf0e10cSrcweir         pPV->InsertHelpLine(SdrHelpLine(eKind, aHlpPos));
199cdf0e10cSrcweir     }
200cdf0e10cSrcweir     else
201cdf0e10cSrcweir     {
202cdf0e10cSrcweir         const SdrHelpLine& rHelpLine = (pPV->GetHelpLines())[nHelpLine];
203cdf0e10cSrcweir         pPV->SetHelpLine(nHelpLine, SdrHelpLine(rHelpLine.GetKind(), aHlpPos));
204cdf0e10cSrcweir     }
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
Activate()207cdf0e10cSrcweir void FuSnapLine::Activate()
208cdf0e10cSrcweir {
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
Deactivate()211cdf0e10cSrcweir void FuSnapLine::Deactivate()
212cdf0e10cSrcweir {
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir } // end of namespace sd
216