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 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sd.hxx" 26 27 #include "fusnapln.hxx" 28 #include <svl/aeitem.hxx> 29 #include <vcl/msgbox.hxx> 30 #include <sfx2/request.hxx> 31 32 33 #include "strings.hrc" 34 35 #include "sdattr.hxx" 36 #include "View.hxx" 37 #include "ViewShell.hxx" 38 #include "DrawViewShell.hxx" 39 #ifndef SD_WINDOW_SHELL_HXX 40 #include "Window.hxx" 41 #endif 42 #include "sdenumdef.hxx" 43 #include "sdresid.hxx" 44 #include "sdabstdlg.hxx" 45 #include "app.hrc" 46 #include <svx/svdpagv.hxx> 47 48 namespace sd { 49 50 TYPEINIT1( FuSnapLine, FuPoor ); 51 52 /************************************************************************* 53 |* 54 |* Konstruktor 55 |* 56 \************************************************************************/ 57 58 FuSnapLine::FuSnapLine(ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, 59 SdDrawDocument* pDoc, SfxRequest& rReq) : 60 FuPoor(pViewSh, pWin, pView, pDoc, rReq) 61 { 62 } 63 64 FunctionReference FuSnapLine::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq ) 65 { 66 FunctionReference xFunc( new FuSnapLine( pViewSh, pWin, pView, pDoc, rReq ) ); 67 xFunc->DoExecute(rReq); 68 return xFunc; 69 } 70 71 void FuSnapLine::DoExecute( SfxRequest& rReq ) 72 { 73 const SfxItemSet* pArgs = rReq.GetArgs(); 74 SdrPageView* pPV = 0; 75 sal_uInt16 nHelpLine = 0; 76 sal_Bool bCreateNew = sal_True; 77 78 // Get index of snap line or snap point from the request. 79 SFX_REQUEST_ARG (rReq, pHelpLineIndex, SfxUInt32Item, ID_VAL_INDEX, sal_False); 80 if (pHelpLineIndex != NULL) 81 { 82 nHelpLine = static_cast<sal_uInt16>(pHelpLineIndex->GetValue()); 83 // Reset the argument pointer to trigger the display of the dialog. 84 pArgs = NULL; 85 } 86 87 if ( !pArgs ) 88 { 89 SfxItemSet aNewAttr(mpViewShell->GetPool(), ATTR_SNAPLINE_START, ATTR_SNAPLINE_END); 90 bool bLineExist (false); 91 pPV = mpView->GetSdrPageView(); 92 Point aLinePos; 93 94 if (pHelpLineIndex == NULL) 95 { 96 // The index of the snap line is not provided as argument to the 97 // request. Determine it from the mouse position. 98 99 aLinePos = static_cast<DrawViewShell*>(mpViewShell)->GetMousePos(); 100 static_cast<DrawViewShell*>(mpViewShell)->SetMousePosFreezed( sal_False ); 101 102 103 if ( aLinePos.X() >= 0 ) 104 { 105 aLinePos = mpWindow->PixelToLogic(aLinePos); 106 sal_uInt16 nHitLog = (sal_uInt16) mpWindow->PixelToLogic(Size(HITPIX,0)).Width(); 107 bLineExist = mpView->PickHelpLine(aLinePos, nHitLog, *mpWindow, nHelpLine, pPV); 108 if ( bLineExist ) 109 aLinePos = (pPV->GetHelpLines())[nHelpLine].GetPos(); 110 else 111 pPV = mpView->GetSdrPageView(); 112 113 pPV->LogicToPagePos(aLinePos); 114 } 115 else 116 aLinePos = Point(0,0); 117 } 118 else 119 { 120 OSL_ASSERT(pPV!=NULL); 121 aLinePos = (pPV->GetHelpLines())[nHelpLine].GetPos(); 122 pPV->LogicToPagePos(aLinePos); 123 bLineExist = true; 124 } 125 aNewAttr.Put(SfxUInt32Item(ATTR_SNAPLINE_X, aLinePos.X())); 126 aNewAttr.Put(SfxUInt32Item(ATTR_SNAPLINE_Y, aLinePos.Y())); 127 128 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create(); 129 AbstractSdSnapLineDlg* pDlg = pFact ? pFact->CreateSdSnapLineDlg( NULL, aNewAttr, mpView ) : 0; 130 if( pDlg ) 131 { 132 if ( bLineExist ) 133 { 134 pDlg->HideRadioGroup(); 135 136 const SdrHelpLine& rHelpLine = (pPV->GetHelpLines())[nHelpLine]; 137 138 if ( rHelpLine.GetKind() == SDRHELPLINE_POINT ) 139 { 140 pDlg->SetText(String(SdResId(STR_SNAPDLG_SETPOINT))); 141 pDlg->SetInputFields(sal_True, sal_True); 142 } 143 else 144 { 145 pDlg->SetText(String(SdResId(STR_SNAPDLG_SETLINE))); 146 147 if ( rHelpLine.GetKind() == SDRHELPLINE_VERTICAL ) 148 pDlg->SetInputFields(sal_True, sal_False); 149 else 150 pDlg->SetInputFields(sal_False, sal_True); 151 } 152 bCreateNew = sal_False; 153 } 154 else 155 pDlg->HideDeleteBtn(); 156 157 sal_uInt16 nResult = pDlg->Execute(); 158 159 pDlg->GetAttr(aNewAttr); 160 delete pDlg; 161 162 switch( nResult ) 163 { 164 case RET_OK: 165 rReq.Done(aNewAttr); 166 pArgs = rReq.GetArgs(); 167 break; 168 169 case RET_SNAP_DELETE: 170 // Fangobjekt loeschen 171 if ( !bCreateNew ) 172 pPV->DeleteHelpLine(nHelpLine); 173 // und weiter wie bei default 174 default: 175 return; 176 } 177 } 178 } 179 Point aHlpPos; 180 181 aHlpPos.X() = ((const SfxUInt32Item&) pArgs->Get(ATTR_SNAPLINE_X)).GetValue(); 182 aHlpPos.Y() = ((const SfxUInt32Item&) pArgs->Get(ATTR_SNAPLINE_Y)).GetValue(); 183 pPV->PagePosToLogic(aHlpPos); 184 185 if ( bCreateNew ) 186 { 187 SdrHelpLineKind eKind; 188 189 pPV = mpView->GetSdrPageView(); 190 191 switch ( (SnapKind) ((const SfxAllEnumItem&) 192 pArgs->Get(ATTR_SNAPLINE_KIND)).GetValue() ) 193 { 194 case SK_HORIZONTAL : eKind = SDRHELPLINE_HORIZONTAL; break; 195 case SK_VERTICAL : eKind = SDRHELPLINE_VERTICAL; break; 196 default : eKind = SDRHELPLINE_POINT; break; 197 } 198 pPV->InsertHelpLine(SdrHelpLine(eKind, aHlpPos)); 199 } 200 else 201 { 202 const SdrHelpLine& rHelpLine = (pPV->GetHelpLines())[nHelpLine]; 203 pPV->SetHelpLine(nHelpLine, SdrHelpLine(rHelpLine.GetKind(), aHlpPos)); 204 } 205 } 206 207 void FuSnapLine::Activate() 208 { 209 } 210 211 void FuSnapLine::Deactivate() 212 { 213 } 214 215 } // end of namespace sd 216