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_sc.hxx" 26 27 #include "fuconpol.hxx" 28 #include "tabvwsh.hxx" 29 #include "sc.hrc" 30 #include "drawview.hxx" 31 32 // #98185# Create default drawing objects via keyboard 33 #include <svx/svdopath.hxx> 34 #include <basegfx/polygon/b2dpolygon.hxx> 35 #include <basegfx/point/b2dpoint.hxx> 36 37 // Pixelabstand zum Schliessen von Freihand-Zeichnungen 38 #ifndef CLOSE_PIXDIST 39 #define CLOSE_PIXDIST 5 40 #endif 41 42 //------------------------------------------------------------------------ 43 44 /************************************************************************* 45 |* 46 |* Konstruktor 47 |* 48 \************************************************************************/ 49 50 FuConstPolygon::FuConstPolygon(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP, 51 SdrModel* pDoc, SfxRequest& rReq) 52 : FuConstruct(pViewSh, pWin, pViewP, pDoc, rReq) 53 { 54 } 55 56 /************************************************************************* 57 |* 58 |* Destruktor 59 |* 60 \************************************************************************/ 61 62 FuConstPolygon::~FuConstPolygon() 63 { 64 } 65 66 /************************************************************************* 67 |* 68 |* MouseButtonDown-event 69 |* 70 \************************************************************************/ 71 72 sal_Bool __EXPORT FuConstPolygon::MouseButtonDown(const MouseEvent& rMEvt) 73 { 74 // #95491# remember button state for creation of own MouseEvents 75 SetMouseButtonCode(rMEvt.GetButtons()); 76 77 sal_Bool bReturn = FuConstruct::MouseButtonDown(rMEvt); 78 79 SdrViewEvent aVEvt; 80 (void)pView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt); 81 if (aVEvt.eEvent == SDREVENT_BEGTEXTEDIT) 82 { 83 // Texteingabe hier nicht zulassen 84 aVEvt.eEvent = SDREVENT_BEGDRAGOBJ; 85 pView->EnableExtendedMouseEventDispatcher(sal_False); 86 } 87 else 88 { 89 pView->EnableExtendedMouseEventDispatcher(sal_True); 90 } 91 92 if ( pView->MouseButtonDown(rMEvt, pWindow) ) 93 bReturn = sal_True; 94 95 return bReturn; 96 } 97 98 /************************************************************************* 99 |* 100 |* MouseMove-event 101 |* 102 \************************************************************************/ 103 104 sal_Bool __EXPORT FuConstPolygon::MouseMove(const MouseEvent& rMEvt) 105 { 106 pView->MouseMove(rMEvt, pWindow); 107 sal_Bool bReturn = FuConstruct::MouseMove(rMEvt); 108 return bReturn; 109 } 110 111 /************************************************************************* 112 |* 113 |* MouseButtonUp-event 114 |* 115 \************************************************************************/ 116 117 sal_Bool __EXPORT FuConstPolygon::MouseButtonUp(const MouseEvent& rMEvt) 118 { 119 // #95491# remember button state for creation of own MouseEvents 120 SetMouseButtonCode(rMEvt.GetButtons()); 121 122 sal_Bool bReturn = sal_False; 123 sal_Bool bSimple = sal_False; 124 125 SdrViewEvent aVEvt; 126 (void)pView->PickAnything(rMEvt, SDRMOUSEBUTTONUP, aVEvt); 127 128 pView->MouseButtonUp(rMEvt, pWindow); 129 130 if (aVEvt.eEvent == SDREVENT_ENDCREATE) 131 { 132 bReturn = sal_True; 133 bSimple = sal_True; // Doppelklick nicht weiterreichen 134 } 135 136 sal_Bool bParent; 137 if (bSimple) 138 bParent = FuConstruct::SimpleMouseButtonUp(rMEvt); 139 else 140 bParent = FuConstruct::MouseButtonUp(rMEvt); 141 142 return (bParent || bReturn); 143 } 144 145 /************************************************************************* 146 |* 147 |* Tastaturereignisse bearbeiten 148 |* 149 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls 150 |* FALSE. 151 |* 152 \************************************************************************/ 153 154 sal_Bool __EXPORT FuConstPolygon::KeyInput(const KeyEvent& rKEvt) 155 { 156 sal_Bool bReturn = FuConstruct::KeyInput(rKEvt); 157 158 return(bReturn); 159 } 160 161 /************************************************************************* 162 |* 163 |* Function aktivieren 164 |* 165 \************************************************************************/ 166 167 void FuConstPolygon::Activate() 168 { 169 pView->EnableExtendedMouseEventDispatcher(sal_True); 170 171 SdrObjKind eKind; 172 173 switch (GetSlotID()) 174 { 175 case SID_DRAW_POLYGON_NOFILL: 176 case SID_DRAW_XPOLYGON_NOFILL: 177 { 178 eKind = OBJ_PLIN; 179 } 180 break; 181 182 case SID_DRAW_POLYGON: 183 case SID_DRAW_XPOLYGON: 184 { 185 eKind = OBJ_POLY; 186 } 187 break; 188 189 case SID_DRAW_BEZIER_NOFILL: 190 { 191 eKind = OBJ_PATHLINE; 192 } 193 break; 194 195 case SID_DRAW_BEZIER_FILL: 196 { 197 eKind = OBJ_PATHFILL; 198 } 199 break; 200 201 case SID_DRAW_FREELINE_NOFILL: 202 { 203 eKind = OBJ_FREELINE; 204 } 205 break; 206 207 case SID_DRAW_FREELINE: 208 { 209 eKind = OBJ_FREEFILL; 210 } 211 break; 212 213 default: 214 { 215 eKind = OBJ_PATHLINE; 216 } 217 break; 218 } 219 220 pView->SetCurrentObj(sal::static_int_cast<sal_uInt16>(eKind)); 221 222 pView->SetEditMode(SDREDITMODE_CREATE); 223 224 FuConstruct::Activate(); 225 226 aNewPointer = Pointer( POINTER_DRAW_POLYGON ); 227 aOldPointer = pWindow->GetPointer(); 228 pViewShell->SetActivePointer( aNewPointer ); 229 } 230 231 /************************************************************************* 232 |* 233 |* Function deaktivieren 234 |* 235 \************************************************************************/ 236 237 void FuConstPolygon::Deactivate() 238 { 239 pView->SetEditMode(SDREDITMODE_EDIT); 240 241 pView->EnableExtendedMouseEventDispatcher(sal_False); 242 243 FuConstruct::Deactivate(); 244 245 pViewShell->SetActivePointer( aOldPointer ); 246 } 247 248 // #98185# Create default drawing objects via keyboard 249 SdrObject* FuConstPolygon::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle) 250 { 251 // case SID_DRAW_POLYGON: 252 // case SID_DRAW_POLYGON_NOFILL: 253 // case SID_DRAW_BEZIER_NOFILL: 254 // case SID_DRAW_FREELINE_NOFILL: 255 256 SdrObject* pObj = SdrObjFactory::MakeNewObject( 257 pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(), 258 0L, pDrDoc); 259 260 if(pObj) 261 { 262 if(pObj->ISA(SdrPathObj)) 263 { 264 basegfx::B2DPolyPolygon aPoly; 265 266 switch(nID) 267 { 268 case SID_DRAW_BEZIER_NOFILL: 269 { 270 basegfx::B2DPolygon aInnerPoly; 271 272 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom())); 273 274 const basegfx::B2DPoint aCenterBottom(rRectangle.Center().X(), rRectangle.Bottom()); 275 aInnerPoly.appendBezierSegment( 276 aCenterBottom, 277 aCenterBottom, 278 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y())); 279 280 const basegfx::B2DPoint aCenterTop(rRectangle.Center().X(), rRectangle.Top()); 281 aInnerPoly.appendBezierSegment( 282 aCenterTop, 283 aCenterTop, 284 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top())); 285 286 aPoly.append(aInnerPoly); 287 break; 288 } 289 case SID_DRAW_FREELINE_NOFILL: 290 { 291 basegfx::B2DPolygon aInnerPoly; 292 293 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom())); 294 295 aInnerPoly.appendBezierSegment( 296 basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()), 297 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Top()), 298 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y())); 299 300 aInnerPoly.appendBezierSegment( 301 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()), 302 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()), 303 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top())); 304 305 aPoly.append(aInnerPoly); 306 break; 307 } 308 case SID_DRAW_POLYGON: 309 case SID_DRAW_POLYGON_NOFILL: 310 { 311 basegfx::B2DPolygon aInnerPoly; 312 const sal_Int32 nWdt(rRectangle.GetWidth()); 313 const sal_Int32 nHgt(rRectangle.GetHeight()); 314 315 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom())); 316 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 30) / 100, rRectangle.Top() + (nHgt * 70) / 100)); 317 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top() + (nHgt * 15) / 100)); 318 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 65) / 100, rRectangle.Top())); 319 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + nWdt, rRectangle.Top() + (nHgt * 30) / 100)); 320 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 50) / 100)); 321 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 75) / 100)); 322 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Bottom(), rRectangle.Right())); 323 324 if(SID_DRAW_POLYGON_NOFILL == nID) 325 { 326 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom())); 327 } 328 else 329 { 330 aInnerPoly.setClosed(true); 331 } 332 333 aPoly.append(aInnerPoly); 334 break; 335 } 336 } 337 338 ((SdrPathObj*)pObj)->SetPathPoly(aPoly); 339 } 340 else 341 { 342 DBG_ERROR("Object is NO path object"); 343 } 344 345 pObj->SetLogicRect(rRectangle); 346 } 347 348 return pObj; 349 } 350 351 // eof 352