OpChangeBrush Class Reference

base class for operations to change various features of the brush More...

#include <opdrbrsh.h>

Inheritance diagram for OpChangeBrush:

SelOperation UndoableOperation Operation MessageHandler ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 OpChangeBrush ()
 Constructor.
 ~OpChangeBrush ()
virtual void DoWithParam (OpDescriptor *, OpParam *pOpParam)
 This changes the flag specified in FlagType (given in pOpParam->Param1) in all the selected brush objects to have the same as state of pOpParam->Param2.
virtual void GetOpName (String_256 *OpName)
 The GetOpName fn is overridden so that we return back a description appropriate to the type of attribute that the operation applies.

Static Public Member Functions

static BOOL Declare ()
 Adds the operation to the list of all known operations.
static OpState GetState (String_256 *Description, OpDescriptor *)
 Find out the state of the operation at the specific time.

Protected Member Functions

BOOL ChangeLineWidth (const double &PropChange, NodeRenderableInk *pInk)
 To change the linewidth applied to pInk by the specified proportion.

Private Member Functions

 CC_DECLARE_DYNCREATE (OpChangeBrush)

Private Attributes

ChangeBrushType ChangeType

Detailed Description

base class for operations to change various features of the brush

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/11/99
See also:
-

Definition at line 346 of file opdrbrsh.h.


Constructor & Destructor Documentation

OpChangeBrush::OpChangeBrush  ) 
 

Constructor.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/99
Returns:
-

Definition at line 2387 of file opdrbrsh.cpp.

02388 {
02389      ChangeType = CHANGEBRUSH_NONE; 
02390 }

OpChangeBrush::~OpChangeBrush  )  [inline]
 

Definition at line 354 of file opdrbrsh.h.

00354 {}


Member Function Documentation

OpChangeBrush::CC_DECLARE_DYNCREATE OpChangeBrush   )  [private]
 

BOOL OpChangeBrush::ChangeLineWidth const double &  PropChange,
NodeRenderableInk pInk
[protected]
 

To change the linewidth applied to pInk by the specified proportion.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/99
Parameters:
PropChange - the proportion to change the line width by (must be > 0) [INPUTS] pInk - the node whose line width we want to change
Returns:
-
Notes: What we must do here is get in a situation where we have a line width attribut that applies only to this ink node,as we don't want to be changing other peoples line widths. Therefore if pInk doesn't have a line width child we will make one for it

Definition at line 2689 of file opdrbrsh.cpp.

02690 {
02691     ERROR2IF(PropChange <= 0, FALSE, "Negative value passed to OpChangeBrush::ChangeLineWidth");
02692     ERROR2IF(pInk == NULL, FALSE, "Null input pointer to OpChangeBrush::ChangeLineWidth");
02693 
02694     // first get our current line width
02695     AttrLineWidth* pLineWidth = NULL;
02696     
02697     // search for it underneath us, if we can't find it we'll make a new one
02698     Node* pNode = pInk->FindFirstChild();
02699     while (pNode != NULL)
02700     {
02701         if (pNode->IsAnAttribute() && ((NodeAttribute*)pNode)->IsALineWidthAttr())
02702         {
02703             pLineWidth = (AttrLineWidth*)pNode;
02704             break;
02705         }
02706         pNode = pNode->FindNext();
02707     }
02708     if (pLineWidth != NULL)
02709     {
02710         // Try to hide the Node    
02711         NodeHidden* Hidden; 
02712         ALLOC_WITH_FAIL(Hidden,(new NodeHidden(pLineWidth)),this);
02713         if (Hidden == NULL)
02714         {          
02715             return (FALSE); 
02716         }
02717 
02718         // Try to create a ShowNodeAction which will show the node that we have just hidden. 
02719         
02720         ShowNodeAction* UndoShowNodeAction; 
02721 
02722         if (ShowNodeAction::Init(this,  
02723                                  &UndoActions, 
02724                                  Hidden, 
02725                                  TRUE, 
02726                                  (Action**)(&UndoShowNodeAction),
02727                                  TRUE) == AC_FAIL)
02728         {   
02729             // We must unhide the NodeToHide manually, cos no action will do it for us 
02730             Hidden->ShowNode(); // Hidden is deleted don't worry 
02731             return FALSE; 
02732         }
02733     }
02734     else
02735     {
02736         // there isn't a line width child, so we must be in a compound node or something.
02737         pInk->FindAppliedAttribute(CC_RUNTIME_CLASS(AttrLineWidth), (NodeAttribute**)&pLineWidth);
02738 
02739         if (pInk == NULL)
02740         {
02741             ERROR3("Unable to find line width node");
02742             return FALSE;
02743         }
02744     }
02745 
02746     // Make a new line width to insert
02747     AttrLineWidth* pNewLineWidth = new AttrLineWidth;
02748     if (pNewLineWidth == NULL)
02749     {
02750         ERROR1RAW(_R(IDE_NOMORE_MEMORY));
02751         return FALSE;
02752     }
02753 
02754     // insert the new attribute
02755     pNewLineWidth->AttachNode(pInk, FIRSTCHILD);
02756 
02757     // Create a hide node action to hide the node when we undo 
02758     HideNodeAction* UndoHideNodeAction;     
02759     if (HideNodeAction::Init(this, &UndoActions, pNewLineWidth,  TRUE,  ( Action**)(&UndoHideNodeAction))      
02760                               == AC_FAIL)
02761     {
02762         delete pNewLineWidth;
02763         return FALSE;
02764     }
02765 
02766     
02767 
02768     double OldWidth = (double)pLineWidth->Value.LineWidth;
02769     double NewWidth = OldWidth * PropChange;
02770     
02771     pNewLineWidth->Value.LineWidth = (MILLIPOINT)NewWidth;
02772 
02773     // change the control by abusing an op descriptor
02774     OpChangeLineWidthOpDesc* pDesc = (OpChangeLineWidthOpDesc*)OpDescriptor::FindOpDescriptor(OPTOKEN_CHANGELINEWIDTH);
02775     if (pDesc)
02776     {
02777         String_256 StrWidth = TEXT("");
02778         Convert::DoubleToString(NewWidth*0.001, &StrWidth, 2);
02779         StrWidth += TEXT("pt");
02780         pDesc->SetLineWidthGadgets(StrWidth);
02781     }
02782 
02783 
02784     return TRUE;
02785 
02786 }

BOOL OpChangeBrush::Declare  )  [static]
 

Adds the operation to the list of all known operations.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/99
Returns:
TRUE if all went OK, FALSE otherwise

Definition at line 2405 of file opdrbrsh.cpp.

02406 {
02407     return (RegisterOpDescriptor(
02408                                 0, 
02409                                 0,
02410                                 CC_RUNTIME_CLASS(OpChangeBrush), 
02411                                 OPTOKEN_CHANGEBRUSH,
02412                                 OpChangeBrush::GetState,
02413                                 0,  /* help ID */
02414                                 0,  /* bubble ID */
02415                                 0   /* bitmap ID */
02416                                 ));
02417 }

void OpChangeBrush::DoWithParam OpDescriptor ,
OpParam pOpParam
[virtual]
 

This changes the flag specified in FlagType (given in pOpParam->Param1) in all the selected brush objects to have the same as state of pOpParam->Param2.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/99
Returns:
-

Reimplemented from Operation.

Definition at line 2551 of file opdrbrsh.cpp.

02552 {
02553     ERROR3IF(pOpParam == NULL,"NULL OpParam ptr");
02554     if (pOpParam == NULL) return;
02555 
02556     ChangeBrushOpParam* pChangeParam = (ChangeBrushOpParam*)pOpParam;
02557 
02558     // find all the brushes in the current selection
02559     List NodeList;
02560     BevelTools::BuildListOfSelectedNodes(&NodeList, CC_RUNTIME_CLASS(NodeRenderableInk));
02561 
02562     BOOL ok = !NodeList.IsEmpty();
02563     if (ok) ok = DoStartSelOp(FALSE,FALSE);
02564 
02565     NodeListItem * pItem = NULL;
02566     
02567     Spread* pSpread = Document::GetSelectedSpread();
02568     if (pSpread == NULL)
02569     {
02570         ERROR3("Wheres the spread!?");
02571         return;
02572     }
02573     
02574     if (ok)
02575     {
02576         
02577         pItem = (NodeListItem *)NodeList.GetHead();
02578 
02579         Node* pSelNode = NULL;
02580 
02581         if (pItem)
02582         {
02583             pSelNode = pItem->pNode;
02584         }
02585         
02586         while (pSelNode != NULL && ok)
02587         {
02588             Node* pNode = pSelNode;
02589 
02590             pItem = (NodeListItem *)NodeList.GetNext(pItem);
02591 
02592             if (pItem)
02593             {
02594                 pSelNode = pItem->pNode;
02595             }
02596             else
02597             {
02598                 pSelNode = NULL;
02599             }
02600             
02601             AttrBrushType* pAttrBrush = ((NodeRenderableInk*)pNode)->GetAppliedBrushAttribute();
02602             if (pAttrBrush != NULL && pAttrBrush->GetBrushHandle() != BrushHandle_NoBrush)
02603             {
02604                 // We now have a selected node with a brush attribute so:
02605                 //  Invalidate the node's region
02606                 //  Store the current state of brush flag in an undo actiom
02607                 //  Change the flag to the setting in Param2
02608 
02609                 ChangeBrushAction* pAction;
02610     
02611                 
02612                 // Ask the node if it's ok to do the op
02613                 ObjChangeFlags cFlags;
02614                 ObjChangeParam ObjChange(OBJCHANGE_STARTING,cFlags,NULL,this);
02615                 ok = pNode->AllowOp(&ObjChange, TRUE);
02616             //  TRACEUSER( "Diccon", _T("CHANGE BRUSH ACTION\n"));
02617                 DocRect PreActRect =((NodeRenderableBounded*)pNode)->GetBoundingRect();
02618                 // invalidate the brush's region
02619                 if (ok) ok = DoInvalidateNodeRegion((NodeRenderableBounded*)pNode,TRUE,FALSE);
02620             //  if (ok) ok = (InvalidateBoundsAction::Init(this,&UndoActions,(NodeRenderableBounded*)pNode,TRUE) != AC_FAIL);
02621 
02622                 // invalidate it before
02623                 if (ok) ok = DoInvalidateRegion(pSpread, PreActRect);
02624                 
02625                 INT32 OldSize = pAttrBrush->GetDefaultLineWidth();
02626 
02627                 // change the brush in an undoable way
02628                 if (ok) ok = ChangeBrushAction::Init(this,&UndoActions,(NodeRenderableInk*)pNode,
02629                                                     pChangeParam,&pAction) != AC_FAIL;
02630                 
02631                 // have we changed the size of the brush? Depends on what our param says
02632                 INT32 NewSize = pAttrBrush->GetDefaultLineWidth();
02633                 
02634                 if (pChangeParam->ChangeLineWidth())
02635                 {
02636                     double SizeChange = (double)NewSize / (double)OldSize;
02637                     ok = ChangeLineWidth(SizeChange, (NodeRenderableInk*)pNode);
02638                 }
02639                 
02640                 DocRect PostActRect = ((NodeRenderableBounded*)pNode)->GetBoundingRect();
02641             
02642                 if (ok) ok = DoInvalidateNodeRegion((NodeRenderableBounded*)pNode,TRUE,FALSE);
02643             
02644                 // invalidate it after
02645                 if (ok) ok = DoInvalidateRegion(pSpread, PostActRect);
02646                 
02647             }
02648             
02649         }
02650     }
02651     NodeList.DeleteAll();
02652     
02653 
02654     if (ok) 
02655     {
02656         // Inform the effected parents of the change
02657         ObjChangeFlags cFlags;
02658         ObjChangeParam ObjChange(OBJCHANGE_FINISHED,cFlags,NULL,this);
02659         UpdateChangedNodes(&ObjChange);
02660 
02661         // Note the way the selected brush were changed
02662         ChangeType = pChangeParam->ChangeType;
02663     }
02664     else
02665         FailAndExecute();
02666 
02667     End();
02668 }

void OpChangeBrush::GetOpName String_256 OpName  )  [virtual]
 

The GetOpName fn is overridden so that we return back a description appropriate to the type of attribute that the operation applies.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/99
Parameters:
- [INPUTS]
The undo string for the operation [OUTPUTS]
Returns:

Errors: -

See also:
-

Reimplemented from Operation.

Definition at line 2482 of file opdrbrsh.cpp.

02483 { 
02484     UINT32 IDS = _R(IDS_MARKN_EMPTY);
02485 
02486     switch (ChangeType)
02487     {
02488         case CHANGEBRUSH_NONE:              break;
02489         case CHANGEBRUSH_SPACING:           IDS = _R(IDS_BRUSHSPACING_UNDO);    break;
02490         case CHANGEBRUSH_SPACING_INCRPROP:  IDS = _R(IDS_BRUSHSPACING_INCR);    break;
02491         case CHANGEBRUSH_SPACING_INCRCONST: IDS = _R(IDS_BRUSHSPACING_INCR);    break;
02492         case CHANGEBRUSH_SPACING_MAXRAND:   IDS = _R(IDS_BRUSHSPACING_MAXRAND); break;
02493         case CHANGEBRUSH_SPACING_RANDSEED:  IDS = _R(IDS_BRUSHSPACING_RANDSEED); break;
02494         case CHANGEBRUSH_SCALING:           IDS = _R(IDS_BRUSHSCALING_UNDO);    break;
02495         case CHANGEBRUSH_SCALING_INCR:      IDS = _R(IDS_BRUSHSCALING_INCR);    break;
02496         case CHANGEBRUSH_SCALING_INCRCONST: IDS = _R(IDS_BRUSHSCALING_INCR);    break;
02497         case CHANGEBRUSH_SCALING_MAXRAND:   IDS = _R(IDS_BRUSHSCALING_MAXRAND); break;
02498         case CHANGEBRUSH_SCALING_RANDSEED:  IDS = _R(IDS_BRUSHSCALING_RANDSEED); break;
02499         case CHANGEBRUSH_SCALING_PRESSURE:  IDS = _R(IDS_BRUSHSCALING_PRESSURE); break;
02500         case CHANGEBRUSH_OFFSET_TYPE:       IDS = _R(IDS_BRUSHOFFSET_TYPE_UNDO);break;
02501         case CHANGEBRUSH_OFFSET_TYPE_SEED:  IDS = _R(IDS_OFFSETTYPE_RANDSEED);  break;
02502         case CHANGEBRUSH_OFFSET_VAL:        IDS = _R(IDS_BRUSHOFFSET_VAL_UNDO); break;
02503         case CHANGEBRUSH_OFFSET_VALSEED:    IDS = _R(IDS_OFFSETVAL_RANDSEED);   break;
02504         case CHANGEBRUSH_OFFSET_SEEDS:      IDS = _R(IDS_OFFSETVAL_RANDSEED);   break;
02505         case CHANGEBRUSH_OFFSET_INCRPROP:   IDS = _R(IDS_BRUSHOFFSET_INCR);     break;
02506         case CHANGEBRUSH_OFFSET_INCRCONST:  IDS = _R(IDS_BRUSHOFFSET_INCR);     break;
02507         case CHANGEBRUSH_OFFSET_MAXRAND:    IDS = _R(IDS_OFFSETVAL_MAXRAND);    break;
02508         case CHANGEBRUSH_TILED:             IDS = _R(IDS_BRUSHTILE_UNDO);       break;
02509         case CHANGEBRUSH_TANGENTIAL:        IDS = _R(IDS_BRUSHROTATE_UNDO);     break;
02510         case CHANGEBRUSH_ROTATE_ANGLE:      IDS = _R(IDS_BRUSHROTATE_ANGLE_UNDO); break;
02511         case CHANGEBRUSH_ROTATE_INCRPROP:   IDS = _R(IDS_BRUSHROTATE_ANGLE_UNDO); break;
02512         case CHANGEBRUSH_ROTATE_INCRCONST:  IDS = _R(IDS_BRUSHROTATE_INCR);      break;
02513         case CHANGEBRUSH_ROTATE_PRESSURE:   IDS = _R(IDS_BRUSHROTATE_PRESSURE);  break;
02514         case CHANGEBRUSH_NAME:              IDS = _R(IDS_BRUSHNAME_UNDO);       break;
02515         case CHANGEBRUSH_SEQUENCE:          IDS = _R(IDS_BRUSHNAME_UNDO);       break;
02516         case CHANGEBRUSH_SEQUENCE_RANDSEED: IDS = _R(IDS_SEQUENCE_RANDSEED);    break;
02517         case CHANGEBRUSH_USELOCALFILLCOL:   IDS = _R(IDS_BRUSH_USELOCAL_FILLCOL);   break;
02518         case CHANGEBRUSH_USELOCALTRANSP:    IDS = _R(IDS_BRUSH_USELOCAL_TRANSP);    break;
02519         case CHANGEBRUSH_USENAMEDCOL:       IDS = _R(IDS_BRUSH_USELOCAL_FILLCOL);   break;
02520         case CHANGEBRUSH_ALL:               IDS = _R(IDS_BRUSH_CHANGEALL);      break;
02521         case CHANGEBRUSH_ROTATE_MAXRAND:    IDS = _R(IDS_ROTATE_MAXRAND);       break;
02522         case CHANGEBRUSH_ROTATE_RANDSEED:   IDS = _R(IDS_ROTATE_RANDSEED);      break;
02523         case CHANGEBRUSH_HUE_INCR:          IDS = _R(IDS_ROTATE_RANDSEED);      break;
02524         case CHANGEBRUSH_HUE_MAXRAND:       IDS = _R(IDS_BRUSH_HUE_RANDOM);     break;
02525         case CHANGEBRUSH_FILL_SEEDS:        IDS = _R(IDS_BRUSH_HUE_RANDSEED);   break;
02526         case CHANGEBRUSH_SAT_MAXRAND:       IDS = _R(IDS_BRUSH_SAT_RANDOM);     break;
02527         case CHANGEBRUSH_SAT_RANDSEED:      IDS = _R(IDS_BRUSH_SAT_RANDSEED);   break;
02528         case CHANGEBRUSH_TRANSP:            IDS = _R(IDS_BRUSHTRANSP);          break;
02529         case CHANGEBRUSH_TRANSP_PRESSURE:   IDS = _R(IDS_BRUSHTRANSP_PRESSURE); break;
02530         case CHANGEBRUSH_REGEN:             break;
02531         
02532         default: ERROR3_PF(("Unknown flag type (%d)",ChangeType));  break;
02533     }
02534 
02535     *OpName = String_256(IDS);
02536 }  

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

Find out the state of the operation at the specific time.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/99
Parameters:
Description - GetState fills this string with an approriate description [OUTPUTS] of the current state of the operation
Returns:
The state of the operation, so that menu items (ticks and greying) can be done properly

Definition at line 2435 of file opdrbrsh.cpp.

02436 {
02437     OpState State(FALSE,TRUE); // It's not ticked, but it is greyed by default
02438     
02439     /*
02440     List NodeList;
02441     BevelTools::BuildListOfSelectedNodes(&NodeList, CC_RUNTIME_CLASS(NodeBrush));
02442 
02443     if (!NodeList.IsEmpty())
02444     {
02445         State.Greyed = FALSE;
02446     }
02447 
02448     NodeList.DeleteAll();   
02449     */
02450     // find out if there are any brushed nodes in the selection
02451     SelRange *pSel = GetApplication ()->FindSelection();
02452     if (pSel != NULL)
02453     {
02454         Node *pNode = pSel->FindFirst();
02455         while (pNode != NULL)
02456         {
02457             if (pNode->IsBrushed())
02458                 State.Greyed = FALSE;
02459             pNode = pSel->FindNext(pNode);
02460         }
02461     }
02462     return State;
02463 
02464 }


Member Data Documentation

ChangeBrushType OpChangeBrush::ChangeType [private]
 

Definition at line 369 of file opdrbrsh.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:57:37 2007 for Camelot by  doxygen 1.4.4