OpShortenBar Class Reference

Will cut down the size of a bar to the number of buttons requested by deleting the last buttons in the bar. More...

#include <opdupbar.h>

Inheritance diagram for OpShortenBar:

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

Public Member Functions

 OpShortenBar ()
 OpShortenBar constructor.
void DoWithParam (OpDescriptor *token, OpParam *pOpParam)
 Removes buttons from the bar so as to leave fewer.
BOOL TrimBarDownToThisManyButtons (const StringBase &BarName, INT32 NewNoOfButtons)
 Removes buttons from the bar so as to leave fewer.

Static Public Member Functions

static BOOL Init ()
 OpShortenBar initialiser method.
static OpState GetState (String_256 *, OpDescriptor *)
 For finding the operations state.

Detailed Description

Will cut down the size of a bar to the number of buttons requested by deleting the last buttons in the bar.

Author:
Simon_Knight (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/10/99

Definition at line 183 of file opdupbar.h.


Constructor & Destructor Documentation

OpShortenBar::OpShortenBar  ) 
 

OpShortenBar constructor.

Author:
Simon_Knight (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/10/99
Returns:
Errors: -
See also:
CarbonCopyOp

Definition at line 662 of file opdupbar.cpp.

00662                           : CarbonCopyOp()                              
00663 {                              
00664 }


Member Function Documentation

void OpShortenBar::DoWithParam OpDescriptor token,
OpParam pOpParam
[virtual]
 

Removes buttons from the bar so as to leave fewer.

Author:
Simon_Knight (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/10/99
Parameters:
OpParam - describes the bar to be dupicated [INPUTS]
  • and the name to call the copy
- [OUTPUTS]
Returns:
-

Errors: -

See also:
TrimBarDownToThisManyButtons

Reimplemented from Operation.

Definition at line 740 of file opdupbar.cpp.

00741 {
00742     if (DoStartSelOp(FALSE,TRUE))  // Try to record the selection state
00743     {
00744         // unpack the names of the bar to be copied and the new bars name from the params
00745         TrimBarDownToThisManyButtons(((OpParamShortenBar *)pOpParam)->m_BarName,
00746                                     ((OpParamShortenBar *)pOpParam)->m_NoOfButtons);
00747 
00748         // end the op
00749         End();
00750 
00751         DialogBarOp::SetSystemStateChanged();
00752         DialogBarOp::UpdateStateOfAllBars(); 
00753 
00754     }
00755     else
00756     {
00757         FailAndExecute();
00758         End();
00759     }
00760 }

OpState OpShortenBar::GetState String_256 UIDescription,
OpDescriptor Bob
[static]
 

For finding the operations state.

Author:
Simon_Knight (Xara Group Ltd) <camelotdev@xara.com> based on Jason
Date:
15/10/99
Returns:
The state of the OpShortenBar

Reimplemented from CarbonCopyOp.

Definition at line 713 of file opdupbar.cpp.

00714 {
00715     OpState OpSt;
00716 
00717     // if we don't allow it
00718     OpSt.Greyed = TRUE;
00719     Spread* pSpread = Document::GetSelectedSpread();
00720     if (pSpread && !pSpread->FindActiveLayer()->IsFrame())
00721         OpSt.Greyed = FALSE;
00722 
00723     return(OpSt);   
00724 }

BOOL OpShortenBar::Init void   )  [static]
 

OpShortenBar initialiser method.

Author:
Simon_Knight (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/10/99
Returns:
TRUE if the operation could be successfully initialised FALSE if no more memory could be allocated

Errors: ERROR will be called if there was insufficient memory to allocate the operation.

See also:
-

Reimplemented from SimpleCCObject.

Definition at line 682 of file opdupbar.cpp.

00683 {
00684     return  (RegisterOpDescriptor(0,
00685                                 _R(IDS_BARDUPLICATIONOP),
00686                                 CC_RUNTIME_CLASS(OpShortenBar),
00687                                 OPTOKEN_SHORTENBAROP,
00688                                 OpShortenBar::GetState,
00689                                 0,                  // help ID 
00690                                 0, //_R(IDBBL_BARDUPLICATIONOP),// bubble help
00691                                 0,                  // resource ID
00692                                 0, //_R(IDC_BC_CREATE),     // control ID
00693                                 SYSTEMBAR_ILLEGAL,  // Bar ID
00694                                 TRUE,               // Receive messages
00695                                 FALSE,
00696                                 FALSE,
00697                                 0,
00698                                 (GREY_WHEN_NO_CURRENT_DOC | DONT_GREY_WHEN_SELECT_INSIDE) ));
00699 }

BOOL OpShortenBar::TrimBarDownToThisManyButtons const StringBase BarName,
INT32  NewNoOfButtons
 

Removes buttons from the bar so as to leave fewer.

Author:
Simon_Knight (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/10/99
Parameters:
BarName - Name of the bar in for a trim [INPUTS] NewNoOfButtons - No of buttons that we want in this bar
- [OUTPUTS]
Returns:
TRUE if it succeeds. FALSE if you try to increase the number of buttons by using this function or it fails in some way.

Errors: -

Definition at line 776 of file opdupbar.cpp.

00777 {
00778     // find me the buttons in this bar
00779     String_256 templayer;
00780     templayer.Load(_R(IDS_ROLLOVER_DEFAULT));
00781 
00782     // count the buttons on the default layer
00783     // every button bar requires a member to be on the default layer
00784     // so there is no point in counting any other layer
00785     Layer * pDef = SliceHelper::FindLayerCalled(templayer);
00786 
00787     if (!pDef) return FALSE; // no default layer found
00788 
00789     INT32 NumberOfButtons = 0;
00790 
00791     // store of example attribs of each button in this bar
00792     // but we don't need this data so we can throw it away afterwards
00793     // MAX_BUTTONS_IN_A_BAR = 20
00794     TemplateAttribute ** ppFoundButton[MAX_BUTTONS_IN_A_BAR];
00795     DocRect ButtonRect[MAX_BUTTONS_IN_A_BAR];
00796     BYTE    Order[MAX_BUTTONS_IN_A_BAR];
00797 
00798     // scan down from the default layer counting the different button names
00799     // that all have the same bar name
00800     SliceHelper::CountButtonsInBarScan(pDef, (TemplateAttribute **) ppFoundButton, &NumberOfButtons, BarName);
00801 
00802     if (NumberOfButtons == 0 || NumberOfButtons <= NewNoOfButtons ) return FALSE;
00803 
00804 
00805     // build up a list of the buttons in the bar
00806     // so that we can shift them along
00807     // it must be better to use a list than keep on
00808     // scanning each time
00809 
00810     Layer * pLayer = NULL;
00811 
00812     List BarList;
00813 
00814     templayer.Load(_R(IDS_ROLLOVER_DEFAULT));
00815     pLayer = SliceHelper::FindLayerCalled(templayer);
00816     if (pLayer)
00817         SliceHelper::BuildListOfNodesInBar(&BarList, pLayer, BarName);
00818 
00819     templayer.Load(_R(IDS_ROLLOVER_MOUSE));
00820     pLayer = SliceHelper::FindLayerCalled(templayer);
00821     if (pLayer)
00822         SliceHelper::BuildListOfNodesInBar(&BarList, pLayer, BarName);
00823 
00824     templayer.Load(_R(IDS_ROLLOVER_CLICKED));
00825     pLayer = SliceHelper::FindLayerCalled(templayer);
00826     if (pLayer)
00827         SliceHelper::BuildListOfNodesInBar(&BarList, pLayer, BarName);
00828 
00829     templayer.Load(_R(IDS_ROLLOVER_SELECTED));
00830     pLayer = SliceHelper::FindLayerCalled(templayer);
00831     if (pLayer)
00832         SliceHelper::BuildListOfNodesInBar(&BarList, pLayer, BarName);
00833 
00834     // init stuff for the translation
00835     String_256  ButtonName = "";
00836     NodeListItem *pNodeListItem = NULL;
00837     NodeListItem *pDelThisToo = NULL;
00838     Node *pNode = NULL;
00839     Node *pParent = NULL;
00840     
00841     INT32 i = 0;
00842 
00843     // how big is each rect of the gallery?
00844     for (i = 0; i < NumberOfButtons; i++)
00845     {
00846         Order[i] = i; // init order
00847 
00848         ButtonName = ((TemplateAttribute *) ppFoundButton[i])->GetParam();
00849         pNodeListItem = (NodeListItem *)BarList.GetHead();
00850         ButtonRect[i].MakeEmpty();
00851 
00852         while(pNodeListItem)
00853         {
00854             pNode = pNodeListItem->pNode;
00855             if (pNode) 
00856             {
00857                 pParent = pNode->FindParent();
00858                 if (pParent && ButtonName.CompareTo(((TemplateAttribute *)pNode)->GetParam()) == 0)
00859                 {
00860                     // transform the node into its new location in the bar
00861                     ButtonRect[i] = ButtonRect[i].Union(((NodeRenderableBounded *)pParent)->GetBoundingRect());
00862                 }
00863             }
00864             // find the next item in the list
00865             pNodeListItem = (NodeListItem *)BarList.GetNext(pNodeListItem);
00866         }
00867     }
00868 
00869     // sort them by location
00870     for (i = 0; i < NumberOfButtons; i++)
00871     {
00872         for (INT32 j = i+1; j < NumberOfButtons; j++)
00873         {
00874             if (ButtonRect[Order[j]].hiy > ButtonRect[Order[i]].hiy)
00875             {
00876                 BYTE t = Order[j];
00877                 Order[j] = Order[i];
00878                 Order[i] = t;
00879             }
00880             else
00881             if (ButtonRect[Order[j]].hiy == ButtonRect[Order[i]].hiy &&
00882                 ButtonRect[Order[j]].lox < ButtonRect[Order[i]].lox)
00883             {
00884                 BYTE t = Order[j];
00885                 Order[j] = Order[i];
00886                 Order[i] = t;
00887             }
00888         }
00889     }
00890 
00891     // tidy up the list
00892     pNodeListItem = (NodeListItem *)BarList.GetHead();
00893     pParent = NULL;
00894     // Prepare an ObjChangeParam so we can mark which nodes will allow this op to happen to them
00895     ObjChangeFlags cFlags(TRUE); // flag says deleting okay?
00896     ObjChangeParam ObjChange(OBJCHANGE_STARTING,cFlags,NULL,this);
00897 
00898 
00899     while(pNodeListItem)
00900     {
00901         pDelThisToo = pNodeListItem;
00902 
00903         // delete any node that is ordered after NewNoOfButtons
00904         // by finding out if the name of this item in the bar
00905         // is the same as any that occur after the required
00906         // number of buttons in the bar
00907         pParent = pNodeListItem->pNode->FindParent();
00908         if (pParent)
00909             {
00910                 ButtonName = ((TemplateAttribute *)pNodeListItem->pNode)->GetParam();
00911 
00912                 for (i = NewNoOfButtons; i < NumberOfButtons; i++)
00913                 {
00914                     if (ButtonName.CompareTo(((TemplateAttribute *) ppFoundButton[Order[i]])->GetParam()) == 0
00915                         && pParent->AllowOp(&ObjChange))
00916                     {
00917                         // We also need to invalidate the region of the node now that it has been transformed
00918                         DoInvalidateNodeRegion((NodeRenderableBounded*) pParent, TRUE, FALSE);
00919 
00920                         // remove the node from the excess button
00921                         pParent->SetSelected(FALSE);
00922                         DoHideNode(pParent, TRUE);
00923                         
00924                         i = NumberOfButtons; // shortcut out
00925                     }
00926                 }
00927             }
00928 
00929         pNodeListItem = (NodeListItem *)BarList.GetNext(pNodeListItem);
00930 
00931         // tidy up the list as we go along
00932         BarList.RemoveItem((NodeListItem *)pDelThisToo);
00933         delete pDelThisToo;
00934     }
00935 
00936     // touch the bar in question
00937     NameGallery * pNameGallery = NameGallery::Instance();
00938     if (pNameGallery)
00939     {
00940         pNameGallery->m_TouchedBar = SliceHelper::GetBarNumberFromBarName(BarName);
00941     }
00942 
00943     ObjChange.Define(OBJCHANGE_FINISHED,cFlags,NULL,this);
00944     UpdateChangedNodes(&ObjChange);
00945     
00946     BROADCAST_TO_ALL(SelChangingMsg(SelChangingMsg::NONCOLOURATTCHANGED));
00947 
00948     return TRUE;
00949 }


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