TabStopDragOp Class Reference

Operation to handle tab stop dragging. More...

#include <textinfo.h>

Inheritance diagram for TabStopDragOp:

Operation MessageHandler ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 TabStopDragOp ()
 Constructor.
 ~TabStopDragOp ()
 Destructor.
void DoWithParam (OpDescriptor *pOpDesc, OpParam *pParam)
 Main entry point of operation.
void DragPointerMove (DocCoord PointerPos, ClickModifiers ClickMods, Spread *, BOOL bSolidDrag)
 Called when the mouse moves during a drag.
ResourceID GetStatusLineID ()
 Return resource ID appropriate for current drag (and mouse on/off ruler status).
void UpdateStatusLineAndPos (UserCoord *ToolPos, Spread *pSpread)
 Display appropriate status text and update displayed coordinates.
virtual void DragFinished (DocCoord PointerPos, ClickModifiers ClickMods, Spread *, BOOL Success, BOOL bSolidDrag)
 Responds to the drag of a tab stop ending.

Static Public Member Functions

static BOOL Init ()
 Register the TabStopDragOp operation.
static OpState GetState (String_256 *Description, OpDescriptor *)
 Func for determining the usability of this op.

Private Member Functions

void DoDrag (Spread *pThisSpread)
 Starts a drag for a new or existing tab stop.

Static Private Member Functions

static BOOL IsMouseOverRuler ()
 Test to see where the mouse pointer is. It will return TRUE if the mouse is over either ruler, or the origin gadget.
static DocCoord SnapAndConvert (UserCoord *DragPos, Spread *pSpread, DocView *pDocView)
 Snap the tool-specific coordinates and convert to doc coords.

Private Attributes

SpreadpSpread
MILLIPOINT Ordinate
INT32 CursorStackID
Cursorm_pTabCursor
Cursorm_pDelCursor
BOOL m_TabCursorShown
ResourceID m_CurrentStatusTextID
TabStopDragOpParamm_pParam

Detailed Description

Operation to handle tab stop dragging.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
12/07/06

Definition at line 527 of file textinfo.h.


Constructor & Destructor Documentation

TabStopDragOp::TabStopDragOp  ) 
 

Constructor.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
23/07/06

Definition at line 3857 of file textinfo.cpp.

TabStopDragOp::~TabStopDragOp  ) 
 

Destructor.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
23/07/06

Definition at line 3872 of file textinfo.cpp.

03873 {
03874     if (m_pTabCursor) delete m_pTabCursor;
03875     if (m_pDelCursor) delete m_pDelCursor;
03876     if (m_pParam) delete m_pParam;
03877 }


Member Function Documentation

void TabStopDragOp::DoDrag Spread pThisSpread  )  [private]
 

Starts a drag for a new or existing tab stop.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
12/07/06
Parameters:
pThisSpread = ptr to spread drag started in (NULL means get selected spread) [INPUTS] PointerPos = coord of point clicked

Definition at line 3928 of file textinfo.cpp.

03929 {
03930     TRACEUSER("wuerthne", _T("DoDrag"));
03931     pSpread = pThisSpread;
03932 
03933     if (pSpread == NULL)
03934         pSpread = Document::GetSelectedSpread();
03935 
03936     ERROR3IF(pSpread == NULL,"pSpread == NULL");
03937     if (pSpread == NULL)
03938     {
03939         End();
03940         return;
03941     }
03942 
03943     Ordinate = m_pParam->StartPos.x;
03944     TRACEUSER("wuerthne", _T("starting drag at %d"), Ordinate);
03945 
03946     if (m_pTabCursor != NULL) delete m_pTabCursor;
03947 
03948     ResourceID CursorID = _R(IDCSR_TEXT_LEFTTAB);
03949     switch(m_pParam->DragType)
03950     {
03951         case DragTabStop: case DragNew:
03952             switch(m_pParam->DraggedTabStop.GetType())
03953             {
03954                 case RightTab:
03955                     CursorID = _R(IDCSR_TEXT_RIGHTTAB);
03956                     break;
03957                 case CentreTab:
03958                     CursorID = _R(IDCSR_TEXT_CENTTAB);
03959                     break;
03960                 case DecimalTab:
03961                     CursorID = _R(IDCSR_TEXT_DECTAB);
03962                     break;
03963                 default:
03964                     break;
03965             }
03966             break;
03967         case DragLeftMargin:
03968             CursorID = _R(IDCSR_TEXT_LEFTMAR);
03969             break;
03970         case DragRightMargin:
03971             CursorID = _R(IDCSR_TEXT_RIGHTMAR);
03972             break;
03973         case DragFirstIndent:
03974             CursorID = _R(IDCSR_TEXT_FIRSTIND);
03975             break;
03976         default:
03977             break;
03978     }
03979     m_pTabCursor = new Cursor(TOOLID_TEXT, CursorID);
03980     
03981     if (m_pTabCursor != NULL)
03982         CursorStackID = CursorStack::GPush(m_pTabCursor);
03983     m_TabCursorShown = TRUE;
03984 
03985     // Tell the Dragging system to start a drag operation
03986     // We would like to use DRAGTYPE_DEFERRED here, but unfortunately, that also scrolls
03987     // vertically, which is very much in the way. So, until there is something like
03988     // DRAGTYPE_DEFERRED_HORIZONTAL, disable auto-scrolling.
03989     StartDrag(DRAGTYPE_NOSCROLL);
03990 
03991     // show the mouse follower at the (possibly snapped) starting position
03992     // and update the status text
03993     m_CurrentStatusTextID = 0;
03994     UpdateStatusLineAndPos(&m_pParam->StartPos, pSpread);
03995     // Temporary fix: The status bar does not want to show this message, so at least
03996     // make sure that the text is updated after first mouse move
03997     m_CurrentStatusTextID = 0;
03998 }

void TabStopDragOp::DoWithParam OpDescriptor pOpDesc,
OpParam pParam
[virtual]
 

Main entry point of operation.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
12/07/06
Parameters:
pOpDesc = ptr to the Op Desc associated with this op [INPUTS] pParam = parameter block (dynamically created in TextInfoBarOp::OnRulerClick)

Reimplemented from Operation.

Definition at line 3910 of file textinfo.cpp.

03911 {
03912     m_pParam = (TabStopDragOpParam*)pParam;
03913     DoDrag(Document::GetSelectedSpread());
03914 }

void TabStopDragOp::DragFinished DocCoord  PointerPos,
ClickModifiers  ClickMods,
Spread pSpread,
BOOL  Success,
BOOL  bSolidDrag
[virtual]
 

Responds to the drag of a tab stop ending.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
12/07/06
Parameters:
PointerPos = coord of the pointer [INPUTS] ClickMods = info on the click modifiers pSpread = ptr to spread (not used) Success = TRUE if drag ended successfully, FALSE if drag terminated (by pressing Escape)

Reimplemented from Operation.

Definition at line 4197 of file textinfo.cpp.

04199 {
04200     TRACEUSER("wuerthne", _T("tab stop drag ended"));
04201 
04202     TextInfoBarOp::TabStopDragFinished();
04203     if (Success)
04204     {
04205         DocView *pDocView = DocView::GetCurrent();
04206 
04207         // we need to snap in tool space, i.e., text ruler space
04208         UserCoord UserPos = PointerPos.ToUser(pSpread);
04209         UserPos.x -= TextInfoBarOp::GetRulerOrigin();
04210         DocCoord SnappedPointerPos = SnapAndConvert(&UserPos, pSpread, pDocView);
04211         // the returned coordinate is in spread coords
04212         UserPos = SnappedPointerPos.ToUser(pSpread);
04213         Ordinate = UserPos.x - TextInfoBarOp::GetRulerOrigin();
04214         TRACEUSER("wuerthne", _T("with success at %d"), Ordinate);
04215         
04216         switch(m_pParam->DragType)
04217         {
04218             case DragNew:
04219                 if (IsMouseOverRuler())
04220                 {
04221                     TextInfoBarOp::DoAddTabStop(Ordinate);
04222                 }
04223                 // if the mouse is not over the ruler, we simply refrain from adding a tab stop
04224                 // so there is nothing to do
04225                 break;
04226             case DragTabStop:
04227                 if (IsMouseOverRuler())
04228                 {
04229                     TxtTabStop NewTabStop(m_pParam->DraggedTabStop);
04230                     NewTabStop.SetPosition(Ordinate);
04231                     TextInfoBarOp::DoAddTabStop(NewTabStop);
04232                 }
04233                 else
04234                 {
04235                     // delete the dragged tab stop; we can do that by simply applying the shown
04236                     // ruler - we have removed the tab stop from the shown ruler when the
04237                     // drag started
04238                     TextInfoBarOp::DoApplyShownRuler();
04239                 }
04240                 break;
04241             case DragLeftMargin:
04242                 // dragged off the ruler means reset to 0
04243                 if (!IsMouseOverRuler()) Ordinate = 0;
04244                 TextInfoBarOp::DoChangeLeftMargin(Ordinate);
04245                 break;
04246             case DragFirstIndent:
04247                 // dragged off the ruler means reset to 0
04248                 if (!IsMouseOverRuler()) Ordinate = 0;
04249                 TextInfoBarOp::DoChangeFirstIndent(Ordinate);
04250                 break;
04251             case DragRightMargin:
04252                 // dragged off the ruler means reset the right margin to the physical width of the object
04253                 TextInfoBarOp::DoChangeRightMargin(Ordinate, !IsMouseOverRuler());
04254                 break;
04255         }
04256     }
04257     // in any case, we redraw the ruler - this is necessary if the drag was aborted, too, because
04258     // we want to restore the dragged tab stop or margin marker and we also want to restore the
04259     // implicit tab stops
04260     TextInfoBarOp::ForceRulerRedraw();
04261     // End the Drag
04262     EndDrag();
04263 
04264     // Restore cursor
04265     if (CursorStackID != TABSTOPDRAG_CURSORID_UNSET)
04266     {
04267         CursorStack::GPop(CursorStackID);
04268         CursorStackID = TABSTOPDRAG_CURSORID_UNSET;
04269     }
04270 
04271     if (m_pTabCursor != NULL)
04272     {
04273         delete m_pTabCursor;
04274         m_pTabCursor = NULL;
04275     }
04276     if (m_pDelCursor != NULL)
04277     {
04278         delete m_pDelCursor;
04279         m_pDelCursor = NULL;
04280     }
04281     if (m_pParam != NULL)
04282     {
04283         delete m_pParam;
04284         m_pParam = NULL;
04285     }
04286     
04287     End();
04288 }

void TabStopDragOp::DragPointerMove DocCoord  PointerPos,
ClickModifiers  ClickMods,
Spread pSpread,
BOOL  bSolidDrag
[virtual]
 

Called when the mouse moves during a drag.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
23/07/06
Parameters:
PointerPos = current mouse coords [INPUTS] ClickMods = modifiers pSpread = the spread bSolidDrag = whether the drag is solid

Reimplemented from Operation.

Definition at line 4140 of file textinfo.cpp.

04142 {
04143     // find out whether we need to change the mouse cursor
04144     if (m_pParam->DragType == DragNew || m_pParam->DragType == DragTabStop)
04145     {
04146         if (IsMouseOverRuler())
04147         {
04148             // the mouse is over the ruler - are we showing the correct "drag tab" cursor?
04149             if (!m_TabCursorShown && m_pTabCursor)
04150             {
04151                 // no, so show it
04152                 CursorStack::GSetTop(m_pTabCursor, CursorStackID);
04153                 m_TabCursorShown = TRUE;
04154             }
04155         }
04156         else
04157         {
04158             // the mouse is not over the ruler - are we showing the correct "delete tab" cursor?
04159             if (m_TabCursorShown)
04160             {
04161                 // no, so show it
04162                 if (!m_pDelCursor)
04163                 {
04164                     m_pDelCursor = new Cursor(TOOLID_TEXT, _R(IDCSR_TEXT_DELTAB));
04165                 }
04166                 if (m_pDelCursor)
04167                 {
04168                     CursorStack::GSetTop(m_pDelCursor, CursorStackID);
04169                     m_TabCursorShown = FALSE;
04170                 }
04171             }
04172         }
04173     }
04174     
04175     // we update the mouse follower - we need to make sure that snapping is done in
04176     // our tool space (i.e., in text ruler coordinates), not in document space
04177     UserCoord UserPos = PointerPos.ToUser(pSpread);
04178     UserPos.x -= TextInfoBarOp::GetRulerOrigin();
04179     UpdateStatusLineAndPos(&UserPos, pSpread);
04180 }

OpState TabStopDragOp::GetState String_256 Description,
OpDescriptor
[static]
 

Func for determining the usability of this op.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
12/07/06
Parameters:
Description = ptr to place description of why this op can't happen [INPUTS] pOpDesc = ptr to the Op Desc associated with this op
Returns:
An OpState object

Definition at line 3892 of file textinfo.cpp.

03893 {
03894     OpState State;
03895     return State;
03896 }

ResourceID TabStopDragOp::GetStatusLineID  ) 
 

Return resource ID appropriate for current drag (and mouse on/off ruler status).

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
25/07/06

Definition at line 4095 of file textinfo.cpp.

04096 {
04097     UINT32 IDS = _R(IDS_TEXTTOOL_DRAGTABSTOP);
04098     switch(m_pParam->DragType)
04099     {
04100         case DragLeftMargin:
04101             IDS = _R(IDS_TEXTTOOL_DRAGLEFTMARGIN);
04102             break;
04103         case DragRightMargin:
04104             IDS = _R(IDS_TEXTTOOL_DRAGRIGHTMARGIN);
04105             break;
04106         case DragFirstIndent:
04107             IDS = _R(IDS_TEXTTOOL_DRAGFIRSTINDENT);
04108             break;
04109         case DragTabStop:
04110             if (m_TabCursorShown)
04111                 IDS = _R(IDS_TEXTTOOL_DRAGTABSTOP);
04112             else
04113                 IDS = _R(IDS_TEXTTOOL_DELTABSTOP);
04114             break;
04115         case DragNew:
04116             if (m_TabCursorShown)
04117                 IDS = _R(IDS_TEXTTOOL_CREATETABSTOP);
04118             else
04119                 IDS = _R(IDS_TEXTTOOL_CANCELTABSTOP);
04120             break;
04121     }
04122     return IDS;
04123 }

BOOL TabStopDragOp::Init void   )  [static]
 

Register the TabStopDragOp operation.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
12/07/06
Returns:
FALSE if failed

Reimplemented from SimpleCCObject.

Definition at line 3835 of file textinfo.cpp.

03836 {
03837     return RegisterOpDescriptor(0, 
03838                                 0,
03839                                 CC_RUNTIME_CLASS(TabStopDragOp), 
03840                                 OPTOKEN_TABSTOPDRAG,
03841                                 TabStopDragOp::GetState,
03842                                 0,  /* help ID */
03843                                 0,  /* bubble ID */
03844                                 0   /* bitmap ID */);
03845 }

BOOL TabStopDragOp::IsMouseOverRuler  )  [static, private]
 

Test to see where the mouse pointer is. It will return TRUE if the mouse is over either ruler, or the origin gadget.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Returns:
TRUE if mouse is over a ruler, FALSE otherwise
See also:
OpGuideline::IsMouseOverRuler() - copied from there

Definition at line 4303 of file textinfo.cpp.

04304 {
04305     DocView* pDocView = DocView::GetSelected();
04306     if (pDocView != NULL)
04307     {
04308         CCamView* pCCamView = pDocView->GetConnectionToOilView();
04309         return (pCCamView->IsMouseOverRuler() != OVER_NO_RULERS);
04310     }
04311 
04312     return FALSE;
04313 }

DocCoord TabStopDragOp::SnapAndConvert UserCoord DragPos,
Spread pSpread,
DocView pDocView
[static, private]
 

Snap the tool-specific coordinates and convert to doc coords.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
24/08/06
Parameters:
DragPos - mouse position (in tool coords, i.e., user coords with the tool [INPUTS] origin applied) pSpread - the current spread pDocView - the current doc view
Returns:
Snapped spread coordinates (ready for passing to the status line)

Definition at line 4015 of file textinfo.cpp.

04016 {
04017     // Snapping is tricky because when snapping to the grid we do not want to snap the
04018     // absolute mouse position but instead our text ruler-specific coordinates, so that
04019     // for instance, a 1mm grid allows us to place tab stops at exact multiples of 1mm,
04020     // irrespective of where the text object happens to be located (it need not be at
04021     // an exact multiple of 1mm). When snapping to a guideline, however, we need to snap
04022     // the absolute position.
04023 
04024     // So, first try guideline snapping
04025     UserCoord AbsoluteDragPos = *DragPos;
04026     AbsoluteDragPos.x += TextInfoBarOp::GetRulerOrigin();
04027     DocCoord VirtualSpreadCoords = AbsoluteDragPos.ToSpread(pSpread);
04028     BOOL Snapped = FALSE;
04029     if (pDocView->GetSnapToGuidesState())
04030         Snapped = pDocView->ForceSnapToGuides(pSpread, &VirtualSpreadCoords, GUIDELINE_VERT);
04031     DocCoord PointerPos = VirtualSpreadCoords;
04032     if (!Snapped)
04033     {
04034         // try grid snapping
04035         // NB - to fool the snapping code we transform our user coords with origin applied
04036         //      to spread coordinates and then let it snap, then we apply the tool origin
04037         //      in the opposite direction, i.e., the origin shift is only applied for the
04038         //      snapping operation and we end up with normal spread coordinates that can
04039         //      be passed to the status line
04040         DocCoord VirtualSpreadCoords = DragPos->ToSpread(pSpread);
04041         if (pDocView->GetSnapToGridState())
04042             pDocView->ForceSnapToGrid(pSpread, &VirtualSpreadCoords);
04043         PointerPos = VirtualSpreadCoords;
04044         PointerPos.x += TextInfoBarOp::GetRulerOrigin();
04045     }
04046     return PointerPos;
04047 }

void TabStopDragOp::UpdateStatusLineAndPos UserCoord DragPos,
Spread pSpread
 

Display appropriate status text and update displayed coordinates.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
25/07/06
Parameters:
DragPos - mouse position (in tool coords, i.e., user coords with the tool [INPUTS] origin applied) pSpread - the current spread

Definition at line 4061 of file textinfo.cpp.

04062 {
04063     DocView *pDocView = DocView::GetCurrent();
04064     DocCoord PointerPos = SnapAndConvert(DragPos, pSpread, pDocView);
04065     StatusLine* pStatusLine=GetApplication()->GetpStatusLine();
04066     if (pStatusLine)
04067     {
04068         // always pass Snap=FALSE otherwise the pointer changes to the "snapped" pointer
04069         pStatusLine->UpdateMousePosAndSnap(&PointerPos, pSpread, pDocView, FALSE);
04070         ResourceID ID = GetStatusLineID();
04071         if (ID != m_CurrentStatusTextID)
04072         {
04073             // put up some status line help
04074             TRACEUSER("wuerthne", _T("Resource ID is %d"), ID);
04075             m_CurrentStatusTextID = ID;
04076             String_256 Str;
04077             if (Str.Load(ID))
04078             {
04079                 TRACEUSER("wuerthne", _T("updating status line %s"), (TCHAR*)Str);
04080                 pStatusLine->UpdateText(&Str, TRUE);
04081             }
04082         }
04083     }
04084 }


Member Data Documentation

INT32 TabStopDragOp::CursorStackID [private]
 

Definition at line 553 of file textinfo.h.

ResourceID TabStopDragOp::m_CurrentStatusTextID [private]
 

Definition at line 557 of file textinfo.h.

Cursor* TabStopDragOp::m_pDelCursor [private]
 

Definition at line 555 of file textinfo.h.

TabStopDragOpParam* TabStopDragOp::m_pParam [private]
 

Definition at line 558 of file textinfo.h.

Cursor* TabStopDragOp::m_pTabCursor [private]
 

Definition at line 554 of file textinfo.h.

BOOL TabStopDragOp::m_TabCursorShown [private]
 

Definition at line 556 of file textinfo.h.

MILLIPOINT TabStopDragOp::Ordinate [private]
 

Definition at line 552 of file textinfo.h.

Spread* TabStopDragOp::pSpread [private]
 

Definition at line 551 of file textinfo.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 04:01:39 2007 for Camelot by  doxygen 1.4.4