#include <textops.h>
Inheritance diagram for OpCreateTextObject:
Public Member Functions | |
OpCreateTextObject () | |
OpCreateTextObject constructor. | |
void | GetOpName (String_256 *OpName) |
Returns the name of the operation. | |
void | DoImmediate (Spread *pSpread, DocCoord Anchor, NodePath *pPath, ClickModifiers ClickMods, DocCoord StoryWidth=DocCoord(MinDocCoord, MinDocCoord)) |
This function starts and ends the operation of inserting a text object onto a spread. It is the DO function. | |
void | DoDrag (Spread *pSpread, DocCoord Anchor, ClickModifiers ClickMods) |
Call to start a drag operation to create a wrapping story with a width. | |
void | DragPointerMove (DocCoord PointerPos, ClickModifiers ClickMods, Spread *pSpread, BOOL bSolidDrag) |
Called after the user moves the mouse during a drag operation. Updates the on screen drag indication. | |
void | DragFinished (DocCoord PointerPos, ClickModifiers ClickMods, Spread *pSpread, BOOL Success, BOOL bSolidDrag) |
Called at the end of a drag operation. Creates a text story if the user did not cancel the drag. | |
void | RenderDragBlobs (DocRect EditPathBBox, Spread *pSpread, BOOL bSolidDrag) |
Draws the drag blobs, in this case a line from the start to the current pos. | |
Protected Attributes | |
DocCoord | m_CurrentOtherEnd |
DocCoord | m_AnchorPoint |
Spread * | m_pStartSpread |
Private Member Functions | |
CC_DECLARE_DYNCREATE (OpCreateTextObject) |
Definition at line 190 of file textops.h.
|
OpCreateTextObject constructor.
Definition at line 279 of file textops.cpp.
|
|
|
|
Call to start a drag operation to create a wrapping story with a width.
Definition at line 472 of file textops.cpp. 00473 { 00474 // Snap the starting point 00475 DocView::SnapCurrent(pSpread, &Anchor); 00476 00477 // Init member vars 00478 m_AnchorPoint = Anchor; 00479 m_CurrentOtherEnd = Anchor; 00480 m_pStartSpread = pSpread; 00481 00482 // Eor on the drag blobs for the first time 00483 DocRect EditPathBBox = m_pStartSpread->GetBoundingRect(); 00484 RenderDragBlobs(EditPathBBox, m_pStartSpread, FALSE); 00485 00486 // And tell the Dragging system that we need drags to happen 00487 StartDrag( DRAGTYPE_AUTOSCROLL, NULL, &m_AnchorPoint, FALSE ); 00488 }
|
|
This function starts and ends the operation of inserting a text object onto a spread. It is the DO function.
Definition at line 301 of file textops.cpp. 00303 { 00304 // Snap the click point 00305 DocView::SnapCurrent(pSpread, &Anchor); 00306 00307 // create the text object 00308 TextStory* pTextStory = NULL; 00309 ALLOC_WITH_FAIL(pTextStory, (TextStory::CreateTextObject(Anchor)), this); 00310 BOOL ok = (pTextStory != NULL); 00311 00312 // Create a word-wrapping story on a path 00313 if (ok && pPath==NULL && StoryWidth!=DocCoord(MinDocCoord,MinDocCoord)) 00314 { 00315 // Set the wrapping width 00316 pTextStory->SetWordWrapping(TRUE); 00317 pTextStory->SetStoryWidth((MILLIPOINT)Anchor.Distance(StoryWidth)); 00318 00319 // Set the angle on the story too. 00320 double StoryRot = atan2((double)StoryWidth.y-Anchor.y, (double)StoryWidth.x-Anchor.x)*(180/PI); 00321 00322 // Construct a rotation matrix and apply to the story 00323 Trans2DMatrix StoryRotMat(Matrix(Anchor, StoryRot)); 00324 pTextStory->Transform(StoryRotMat); 00325 } 00326 00327 // Start the operation 00328 if (ok) 00329 ok = DoStartSelOp(FALSE, TRUE, TRUE, FALSE); 00330 00331 // Hide any existing empty text story 00332 if (ok) 00333 ok = OpDeleteTextStory::RemoveEmptyFocusStory(this); 00334 00335 // Apply the current attributes to the TextStory 00336 if (ok) 00337 ok = pOurDoc->GetAttributeMgr().ApplyCurrentAttribsToNode((NodeRenderableInk*)pTextStory); 00338 00339 // Add it to the document and invalidate the region 00340 if (ok) 00341 { 00342 if (pPath == NULL) 00343 ok = DoInsertNewNode(pTextStory, pSpread, FALSE, TRUE, FALSE); 00344 else 00345 ok = DoInsertNewNode(pTextStory, pPath, NEXT, FALSE, TRUE, FALSE); 00346 } 00347 00348 // Move the path into it if required 00349 if (ok && pPath!=NULL) 00350 { 00351 // Work out how far along the line the click was, CTRL is position at left 00352 MILLIPOINT KernDist = 0; 00353 if (!ClickMods.Constrain) 00354 { 00355 double dist = 0.0; 00356 ok = pPath->InkPath.DistanceTo(Anchor, &dist); 00357 if (ok) 00358 KernDist = (MILLIPOINT)dist; 00359 } 00360 00361 // If SHIFT click or path is closed then we don't want the story to wrap 00362 BOOL PathIsClosed = pPath->InkPath.IsSubPathClosed(pPath->InkPath.GetNumCoords()-1); 00363 if (ClickMods.Adjust || PathIsClosed) 00364 { 00365 pTextStory->SetWordWrapping(FALSE); 00366 pTextStory->SetLeftIndent(0); 00367 00368 // Old style indent via a kern at the start 00369 // Get the size of an em at the caret 00370 CaretNode* pCaret = pTextStory->GetCaret(); 00371 if (ok && (pCaret != NULL) && (KernDist > 0)) 00372 { 00373 FormatRegion FRegion; 00374 ok = FRegion.Init(pCaret); 00375 00376 CharMetrics CharMet; 00377 if (ok) 00378 ok = FRegion.GetCharMetrics(&CharMet, FONTEMCHAR); 00379 00380 // Insert a kern at the start of the text 00381 if (ok) 00382 { 00383 KernDist = (INT32)((KernDist / (double)CharMet.FontEmWidth)*1000); 00384 KernCode* pKern = new KernCode(); 00385 if (pKern == NULL) 00386 ok = FALSE; 00387 else 00388 { 00389 DocCoord kd(KernDist,0); 00390 pKern->SetValue(kd); 00391 ok = DoInsertNewNode(pKern,pTextStory->FindFirstChild(CC_RUNTIME_CLASS(TextLine)), 00392 FIRSTCHILD,FALSE,FALSE,FALSE); 00393 // Also insert a zero kern so the caret appears in the correct 00394 if (ok) 00395 { 00396 KernCode* pKern = new KernCode(); 00397 if (pKern == NULL) 00398 ok = FALSE; 00399 else 00400 { 00401 DocCoord kd(0,0); 00402 pKern->SetValue(kd); 00403 ok = DoInsertNewNode(pKern,pTextStory->FindFirstChild(CC_RUNTIME_CLASS(TextLine)), 00404 FIRSTCHILD,FALSE,FALSE,FALSE); 00405 } 00406 } 00407 } 00408 } 00409 } 00410 } 00411 else 00412 { 00413 pTextStory->SetWordWrapping(TRUE); 00414 pTextStory->SetLeftIndent(KernDist); 00415 } 00416 00417 00418 //Localise attributes of the story 00419 if (ok) ok = DoLocaliseCommonAttributes(pTextStory); 00420 00421 // Move the path into the story 00422 if (ok) ok = DoMoveNode(pPath, pTextStory, FIRSTCHILD); 00423 if (ok) pPath->DeSelect(FALSE); 00424 00425 // Factor back out the common attributes 00426 if (ok) ok = DoFactorOutCommonChildAttributes(pTextStory); 00427 } 00428 00429 // Mark the document as modified (as we don't have an opDescriptor) 00430 if (ok) 00431 pOurDoc->SetModified(TRUE); 00432 00433 // Now format the new story to position the caret 00434 if (ok) 00435 ok = PrePostTextAction::DoFormatStory(this, pTextStory); 00436 00437 // Select the caret and give it the focus 00438 if (ok) 00439 { 00440 // Only select caret if we added to ok layer 00441 Layer* pLayer = (Layer*)pTextStory->FindParent(CC_RUNTIME_CLASS(Layer)); 00442 if ((pLayer != NULL) && pLayer->IsVisible() && !pLayer->IsLocked()) 00443 { 00444 pTextStory->GetCaret()->Select(TRUE); 00445 TextStory::SetFocusStory(pTextStory); 00446 DialogManager::DefaultKeyboardFocus(); // Gives input focus to mainframe 00447 } 00448 } 00449 00450 // Clear any failure 00451 if (!ok) 00452 { 00453 InformError(); 00454 FailAndExecute(); 00455 } 00456 00457 End(); 00458 }
|
|
Called at the end of a drag operation. Creates a text story if the user did not cancel the drag.
Reimplemented from Operation. Definition at line 547 of file textops.cpp. 00548 { 00549 EndDrag(); 00550 00551 // Take off the drag blobs 00552 DocRect EditPathBBox = m_pStartSpread->GetBoundingRect(); 00553 RenderDragBlobs(EditPathBBox, m_pStartSpread, bSolidDrag); 00554 00555 if (Success) 00556 { 00557 // If the drag ended (too) close to the start then we don't want to create a wrapping story 00558 DocRect PointerBlobRect; 00559 GetApplication()->GetBlobManager()->GetBlobRect(m_AnchorPoint, &PointerBlobRect); 00560 00561 // Call the CreateImmediate function to do all the work. 00562 if (PointerBlobRect.ContainsCoord(m_CurrentOtherEnd)) 00563 DoImmediate(m_pStartSpread, m_AnchorPoint, NULL, ClickMods); 00564 else 00565 DoImmediate(m_pStartSpread, m_AnchorPoint, NULL, ClickMods, m_CurrentOtherEnd); 00566 } 00567 }
|
|
Called after the user moves the mouse during a drag operation. Updates the on screen drag indication.
Reimplemented from Operation. Definition at line 503 of file textops.cpp. 00504 { 00505 // Rub out the old drag blob 00506 DocRect EditPathBBox = m_pStartSpread->GetBoundingRect(); 00507 RenderDragBlobs(EditPathBBox, m_pStartSpread, bSolidDrag); 00508 00509 // Should we ever have multiple spreads this code will prove useful 00510 if (pSpread != m_pStartSpread) 00511 PointerPos = MakeRelativeToSpread(m_pStartSpread, pSpread, PointerPos); 00512 00513 // Constrain options 00514 // none - horizontal story 00515 // SHIFT - unconstrained 00516 // CTRL - angle constrain 00517 if (!ClickMods.Adjust && !ClickMods.Constrain) 00518 PointerPos.y = m_AnchorPoint.y; 00519 if (ClickMods.Constrain) 00520 DocView::ConstrainToAngle(m_AnchorPoint, &PointerPos); 00521 DocView::SnapCurrent(pSpread, &PointerPos); 00522 00523 m_CurrentOtherEnd = PointerPos; 00524 00525 // Put the drag blobs back on in the new position 00526 RenderDragBlobs(EditPathBBox, m_pStartSpread, bSolidDrag); 00527 00528 // Set the status line to be helpful 00529 String_256 HelpString(_R(IDS_TEXTTOOL_DRAGCREATEPARA)); 00530 GetApplication()->UpdateStatusBarText(&HelpString); 00531 }
|
|
Returns the name of the operation.
Reimplemented from Operation. Definition at line 620 of file textops.cpp. 00621 { 00622 *OpName = String_256(_R(IDS_CREATETEXTOBJECT)); 00623 }
|
|
Draws the drag blobs, in this case a line from the start to the current pos.
Reimplemented from Operation. Definition at line 580 of file textops.cpp. 00581 { 00582 // If being called from DocView::RenderView, then the spread could be wrong - so 00583 // convert the rectangle if necessary. 00584 if (pSpread != m_pStartSpread) 00585 { 00586 EditPathBBox.lo = MakeRelativeToSpread(m_pStartSpread, pSpread, EditPathBBox.lo); 00587 EditPathBBox.hi = MakeRelativeToSpread(m_pStartSpread, pSpread, EditPathBBox.hi); 00588 } 00589 00590 // start a rendering loop 00591 RenderRegion* pRegion = DocView::RenderOnTop(NULL, pSpread, ClippedEOR); 00592 while (pRegion) 00593 { 00594 // Draw the line 00595 pRegion->SetFillColour(COLOUR_NONE); 00596 pRegion->SetLineColour(COLOUR_XORNEW); 00597 pRegion->DrawLine(m_AnchorPoint, m_CurrentOtherEnd); 00598 00599 // Draw a box at the anchor 00600 pRegion->SetLineColour(COLOUR_BEZIERBLOB); 00601 pRegion->SetFillColour(COLOUR_BEZIERBLOB); 00602 pRegion->DrawBlob(m_AnchorPoint, BT_UNSELECTED); 00603 00604 // Get the Next render region 00605 pRegion = DocView::GetNextOnTop(NULL); 00606 } 00607 }
|
|
|
|
|
|
|