Exemple #1
0
// 将结点插入链表
void CDoubleLinkerInfo::insert(CDoubleLinker* pNode)
{
    if (pNode == NULL) {
        return;
    }

    // 没有Next和Prev的节点才能插入链表(无效节点),防止重复插入
    if (pNode->GetNext() != NULL || pNode->GetPrev() != NULL) {
        return;
    }

    if (mpEnd != NULL) {
        // 有数据,则直接将数据插入尾部,并设为尾指针
        mpEnd->SetNext(pNode);
        pNode->SetPrev(mpEnd);
        pNode->SetNext(NULL);
        SetEnd(pNode);
    } else {
        // 尾指针没数据,那么头指针也肯定没数据
        SetHead(pNode);
        SetEnd(pNode);
        pNode->Clear();
    }

    miCnt++;
}
Exemple #2
0
//=============================================================================
void TitleUnit::calc()
{
	_bg.calc();

	static const float COIN_POS_X_TH_MAX = 200 * Screen::RATIO;
	static const float COIN_POS_X_TH_MIN = -10 * Screen::RATIO;
	static const float COIN_FALL_SPEED = 4 * Screen::RATIO;
	static const float COIN_FALL_MAX_Y = 282 * Screen::RATIO;
	static const float COIN_AUTO_MOVE_X_SPEED = 160.0f * Screen::RATIO;

	Math::Vector3 coinpos = _coinModel->GetPosition();
	if (coinpos.y < COIN_FALL_MAX_Y) coinpos.y += COIN_FALL_SPEED;
	if (_coinCounter == 0) coinpos.x -= (coinpos.x - COIN_AUTO_MOVE_X_SPEED) * 0.03f;
	else {
		if (abs(_coinSpeed) > 1.0f) {
			_coinSpeed -= _coinSpeed * 0.1f;
		} else {
			_coinSpeed = 0;
		}
		coinpos.x += _coinSpeed;
	}
	_coinModel->SetPosition(coinpos);
	_coinModel->SetRotation(Math::Vector3(0, 0, (coinpos.x - COIN_AUTO_MOVE_X_SPEED) * 2.0f));

	LOGI("titleUnit, x=%3.3f", coinpos.x);
	if (coinpos.x > COIN_POS_X_TH_MAX) {
		SetEnd(true);
		SetNextID(UNIT_PUZZLE_NO_TIMELIMIT);
	} else if (coinpos.x < COIN_POS_X_TH_MIN) {
		SetEnd(true);
		SetNextID(UNIT_PUZZLE);
	}

	if (!_coinTouched && _coinCounter > 0) _coinCounter--;
}
Exemple #3
0
//
// Set the end pointer for the buffer area(s) indicated by anArea.
//
EXPORT_C void TStreamBuf::SetEnd(TArea anArea,TUint8* anEnd)
	{
	__ASSERT_ALWAYS(!(anArea&~(ERead|EWrite)),Panic(EStreamAreaInvalid));
	if (anArea&ERead)
		SetEnd(ERead,anEnd);
	if (anArea&EWrite)
		SetEnd(EWrite,anEnd);
	}
Exemple #4
0
RelationData::RelationData(const BrowserRelation * model,
                           BrowserRelation * r)
    : ClassMemberData((ClassMemberData *) model->get_data()),
      Labeled<RelationData>(all, 0), is_deleted(FALSE), is_unconsistent(FALSE)
{
    RelationData * md = (RelationData *) model->get_data();

    type = md->type;
    name = md->name;
    a = md->a;
    b = md->b;
    set_association(md->association);
    original_id = 0;

    if (md->start == model) {
        SetStart(r);

        if (md->end_removed_from == 0) {
            // bi dir, self to model became self to r
            SetEnd(new BrowserRelation((md->get_end_class() == (BrowserClass *) model->parent())
                                      ? (BrowserClass *) r->parent() : md->get_end_class(),
                                      this));
            end_removed_from = 0;
        }
        else {
            // uni dir
            SetEnd(0);
            end_removed_from = (md->end_removed_from == (BrowserClass *) model->parent())
                               ? (BrowserClass *) r->parent() : md->end_removed_from;
            connect(end_removed_from->get_data(), SIGNAL(deleted()),
                    this, SLOT(end_deleted()));
        }
    }
    else {
        // bi dir, self to model became self to r
        SetEnd(r);
        SetStart(new BrowserRelation((md->get_start_class() == (BrowserClass *) model->parent())
                                     ? (BrowserClass *) r->parent() : md->get_start_class(),
                                     this));
        end_removed_from = 0;
    }

    if (get_start_class() == md->get_start_class())
        // to not have two times the same role name
        a.role = 0;

    if ((end != 0) && (get_end_class() == md->get_end_class()))
        // to not have two times the same role name
        b.role = 0;
}
Exemple #5
0
Card::Card(string tFName, string tName, string tSuit, int tVal, int tNum, string tFile, string tFacedown)
{
	fullName = tFName;	//Full name of card. (ie. Ace of Spade)
	name = tName;		//Name of card such as King or 5
	suit = tSuit;		//Suit of card such as Club
	value = tVal;		//Value of card (Ace can be 1 or 11 points in Blackjack)
	number = tNum;		//Number of card to help find filename
	selected = false;		//Flag to tell if card is selected
	fileName = tFile;	//Filename for card image
	facedownFileName = tFacedown; 
	faceDown = true;
	Texture = LoadTexture(facedownFileName, TransColor);
	
	//Coordinates of card's position
	x = 0;
	y = 0;
	//Definition of sprite sheet
	NumCol = 1;
	FrameW = 71;
	FrameH = 96;
	Delay = 135;
	ScaleX = 1;
	ScaleY = 1;
	SetStart(0); 
	SetEnd(0);
	SetDirection(1);
}
Exemple #6
0
///////////////////////////////////////////////////////////////////////////////
//
// TCDLib : copie constructeur
//
///////////////////////////////////////////////////////////////////////////////
TCDLib::TCDLib(TCDLib *aCDLib, TCD*aCD):TCD(aCDLib->mStateManager)
{
    _IN=aCDLib->GetIN();
    strcpy(itsTag,aCDLib->GetTag());
    strcpy(itsSubfield,aCDLib->GetSubfield());
    itsTagContainsWildcard = aCDLib->TagContainsWildcard();
    itsTagIsWildcard = aCDLib->TagIsWildcard();
    itsSubfieldContainsWildcard = aCDLib->SubfieldContainsWildcard();

    itsOccurrenceNumber=aCDLib->GetOccurrenceNumber();
    itsTagOccurrenceNumber=aCDLib->GetTagOccurrenceNumber();
    itsSubOccurrenceNumber=aCDLib->GetSubOccurrenceNumber();
    SetBeginning(aCDLib->GetBeginning());
    SetEnd(aCDLib->GetEnd());
    if (aCDLib->GetNext())
    {
        itsNext = (TCD *)new TCDLib((TCDLib*)aCDLib->GetNext());
        itsNext->SetPrevious((TCD*)this);
    }
    else
        itsNext = NULL;
    itsPrevious = NULL;
    SetContent(aCDLib->GetContent(), aCD);
    mStateManager=aCDLib->mStateManager;
}
Exemple #7
0
		void JobLoading::OnExec()
		{
			// ロードする
			reinterpret_cast<iJobLoading *>(m_pImpl)->Load(&m_pLoadedBuf, m_LoadedSize);

			// 終了
			SetEnd();
		}
Exemple #8
0
 /** Mark the main information for a bond
     \param idx The unique bond index for this bond (inside an OBMol)
     \param begin The 'beginning' atom for the bond
     \param end The 'end' atom for the bond
     \param order The bond order (i.e., 1 = single, 2 = double... 5 = aromatic)
     \param flags Any initial property flags
  **/
 void OBBond::Set(int idx,OBAtom *begin,OBAtom *end,int order,int flags)
 {
   SetIdx(idx);
   SetBegin(begin);
   SetEnd(end);
   SetBondOrder(order);
   SetFlag(flags);
 }
void MazeRenderer::CreateFromMazeGenerator(const MazeGenerator& mg, irr::scene::ISceneManager *smgr)
{
	XSize = mg.YSize;
	YSize = mg.XSize;
	SetStart(mg.StartY,mg.StartX);
	SetEnd(mg.EndY,mg.EndX);

	CreateFromVectorString(smgr,mg.Convert());

	CollisionManager = smgr->getSceneCollisionManager();
}
Exemple #10
0
void EDA_RECT::Merge( const wxPoint& aPoint )
{
    Normalize();        // ensure width and height >= 0

    wxPoint  end = GetEnd();
    // Change origin and size in order to contain the given rect
    m_Pos.x = std::min( m_Pos.x, aPoint.x );
    m_Pos.y = std::min( m_Pos.y, aPoint.y );
    end.x   = std::max( end.x, aPoint.x );
    end.y   = std::max( end.y, aPoint.y );
    SetEnd( end );
}
Exemple #11
0
void TDesBuf::Consolidate()
//
// Update the descriptor's length as well as the read limit.
//
	{
	TUint8* ptr=Ptr(EWrite);
	if (ptr==NULL)
		return;			// ERead only desbuf
	TUint8* base=Base();
	TInt len=Max(Des().Length(),ptr-base);
	Des().SetLength(len);
	SetEnd(ERead,base+len);
	}
void CSoldierBase::Command(Sint32 n)
{
	switch( n ){
	case enSoldierCommandFuttobi:
		//吹っ飛びダウン
		m_sWalkType = enWalkTypeEscape;
		SetTargetPosition(9600*100);
		ChangeMoveType( enMoveTypeFlyDown );
		SetFuttobi(180);
		SetEnd();
		break;
	}
	
}
Exemple #13
0
// 从链表中删除该结点
// 这个函数应该是不安全的,但为了效率,所以这样处理
// 如果该node不是这个链表中的元素,这里也会处理,当该元素是其他链表的中间元素,则不会出任何问题
// 如果该node不是其他链表的中间元素,那么那个链表将被破坏,而且下面会崩溃,因为prev或next其中一个肯定为空
// 所以在外层使用的是有一定得注意
int CDoubleLinkerInfo::erase(CDoubleLinker* pNode)
{
    int iRet = -1;

    if (pNode == NULL) {
        return iRet;
    }

    if (pNode == mpHead && pNode == mpEnd) {
        // 只有一个元素
        Clear();
        iRet = 0;
    } else if (pNode == mpHead) {
        // 头指针
        if (pNode->GetNext() == NULL) {
            return -1;
        }

        pNode->GetNext()->SetPrev(NULL);
        SetHead(pNode->GetNext());
        iRet = 1;
    } else if (pNode == mpEnd) {
        // 尾指针
        if (pNode->GetPrev() == NULL) {
            return -1;
        }

        pNode->GetPrev()->SetNext(NULL);
        SetEnd(pNode->GetPrev());
        iRet = 2;
    } else {
        // 有Next和Prev的节点才能从链表中删除(有效节点)
        if (pNode->GetNext() == NULL || pNode->GetPrev() == NULL) {
            return -1;
        }

        // 在链表中间
        pNode->GetPrev()->SetNext(pNode->GetNext());
        pNode->GetNext()->SetPrev(pNode->GetPrev());
        iRet = 3;
    }

    if (miCnt > 0) {
        miCnt--;
    }

    pNode->Clear();

    return iRet;
}
Exemple #14
0
bool RelationData::check_end_visibility()
{
    if (!navigable(end)) {
        if (end_removed_from == 0) {
            end_removed_from = end->extract();
            SetEnd(0);
            connect(end_removed_from->get_data(), SIGNAL(deleted()),
                    this, SLOT(end_deleted()));
        }

        return FALSE;
    }

    if (end_removed_from != 0) {
        disconnect(end_removed_from->get_data(), SIGNAL(deleted()),
                   this, SLOT(end_deleted()));
        SetEnd(BrowserRelation::reinsert(end_removed_from, this));
        end_removed_from = 0;
        end->update_stereotype();
    }

    return TRUE;
}
// ---------------------------------------------------------
// RFavouritesBuf::Open
// ---------------------------------------------------------
//
TInt RFavouritesBuf::Open
( RFavouritesHandle& aHandle, TInt aFunction, TIpcArgs& aArgs )
    {
    iBuf.iLen = 0;
	SetBuf( ERead | EWrite, iBuf.iData, iBuf.iData );   // Initially empty.
    TPckg<TFavouritesBuf> buf( iBuf );
    aArgs.Set( 3, &buf );
    TInt err = RFavouritesHandle::Open( aHandle, aFunction, aArgs );
    if ( !err && iBuf.iLen > 0 )
        {
        // If aFunction provided data, it is already here.
        SetEnd( ERead, iBuf.iData + iBuf.iLen );
        }
    return err;
    }
Exemple #16
0
void EDA_RECT::Merge( const EDA_RECT& aRect )
{
    Normalize();        // ensure width and height >= 0
    EDA_RECT rect = aRect;
    rect.Normalize();   // ensure width and height >= 0
    wxPoint  end = GetEnd();
    wxPoint  rect_end = rect.GetEnd();

    // Change origin and size in order to contain the given rect
    m_Pos.x = std::min( m_Pos.x, rect.m_Pos.x );
    m_Pos.y = std::min( m_Pos.y, rect.m_Pos.y );
    end.x   = std::max( end.x, rect_end.x );
    end.y   = std::max( end.y, rect_end.y );
    SetEnd( end );
}
Exemple #17
0
////////////////// OPERATIONS ///////////////////////////////
int
IADSR::Set(char* mess, float value){

  switch (FindMsg(mess)){

  case 31:
    SetInit(value);
    return 1;

  case 32:
    SetEnd(value);
    return 1;

  default:
    return ADSR::Set(mess,value);
  }

}
Exemple #18
0
void RelationData::garbage(BrowserRelation * r)
{
    if (r == start) {
        SetStart(0);

        if ((end == 0) ||
            (end->get_data() == 0)) // bi-dir rel, reverse rel wasn't read
            delete this;
    }
    else if (start == 0)
        // end -> start read, but start -> end not read
        delete this;
    else {
        SetEnd(0);

        if (start == 0)
            delete this;
    }
}
Exemple #19
0
int cMessageSender::Start(SOCKET Sock, bool isTcp)
{
	if(isEnd() == false)
	{
		Stop();
	}


	SetEnd(false);
	SetSock(Sock);


	if(isTcp)
		m_pThread = new std::thread(ThreadJob, this);
	else
		m_pThread = new std::thread(UdpThreadJob, this);


	return 0;
}
Exemple #20
0
bool Location::Expand(const Location * pLocation)
{
    AssertIfNull(pLocation);

    bool LocationChanged = false;

    if (pLocation->StartsBefore(this))
    {
        SetStart(pLocation);
        LocationChanged = true;
    }

    if (pLocation->EndsAfter(this))
    {
        SetEnd(pLocation);
        LocationChanged = true;
    }

    return LocationChanged;
}
Exemple #21
0
int cMessageSender::Stop()
{
	if(isEnd()) return -1;


	SetEnd(true);
	Sleep(100);


	if(m_pThread != NULL)
	{
		m_pThread->join();


		delete m_pThread;
		m_pThread = NULL;
	}


	return 0;
}
void MovieLooperUI::PositionIndicator::MouseMoved(BPoint pt, uint32 code, const BMessage *msg)
{
	if (startMoving)
	{
		// if there is a change in x
		// and it's not too small
		// and it's not past endCoord
		if (floor(pt.x) != floor(startCoord)
			&& pt.x >= 3.0
			&& pt.x <= (endCoord-5.0))
		{
			SetStart((int64)floor((pt.x/(Bounds().Width()-6.0))*frameCount));
			float oldCoord = startCoord;
			startCoord = pt.x;
			if (oldCoord > startCoord)
				Draw(BRect(1.0,1.0,oldCoord+4.0,Bounds().bottom-1.0));
			else
				Draw(BRect(1.0,1.0,startCoord+4.0,Bounds().bottom-1.0));
		}
	}
	else if (endMoving)
	{
		// if there is a change in x
		// and it's not too big
		// and it's not past startCoord
		if (floor(pt.x) != floor(endCoord)
			&& pt.x <= Bounds().right-3.0
			&& pt.x >= (startCoord+5.0))
		{
			SetEnd((int64)floor((pt.x/(Bounds().Width()-6.0))*frameCount));
			float oldCoord = endCoord;
			endCoord = pt.x;
			if (oldCoord < endCoord)
				Draw(BRect(oldCoord-4.0,1.0,Bounds().right-1.0,Bounds().bottom-1.0));
			else
				Draw(BRect(endCoord-4.0,1.0,Bounds().right-1.0,Bounds().bottom-1.0));
			
		}
	}
}
Exemple #23
0
void EDGE_MODULE::Flip( const wxPoint& aCentre )
{
    wxPoint pt;

    switch( GetShape() )
    {
    case S_ARC:
        SetAngle( -GetAngle() );
        //Fall through
    default:
    case S_SEGMENT:
        pt = GetStart();
        MIRROR( pt.y, aCentre.y );
        SetStart( pt );

        pt = GetEnd();
        MIRROR( pt.y, aCentre.y );
        SetEnd( pt );

        MIRROR( m_Start0.y, 0 );
        MIRROR( m_End0.y, 0 );
        break;

    case S_POLYGON:
        // polygon corners coordinates are always relative to the
        // footprint position, orientation 0
        for( auto iter = m_Poly.Iterate(); iter; iter++ )
        {
            MIRROR( iter->y, 0 );
        }
	break;
    }

    // DRAWSEGMENT items are not usually on copper layers, but
    // it can happen in microwave apps.
    // However, currently, only on Front or Back layers.
    // So the copper layers count is not taken in account
    SetLayer( FlipLayer( GetLayer() ) );
}
Exemple #24
0
PTEXT win_get_line(HANDLE hFile)
{
//   extern HANDLE hStdin;
   #define WORKSPACE 1024  // character for workspace
   PTEXT workline=(PTEXT)NULL;
   uint32_t length = 0;
   do
   {
      // create a workspace to read input from the file.
      workline=SegAppend(workline,SegCreate(WORKSPACE));
      SetEnd( workline );
      // read a line of input from the file.
      if( !ReadConsole( hFile
                           , GetText(workline)
                           , WORKSPACE
                           , &length
                           , NULL) ) // if no input read.
      {
         if (PRIORLINE(workline)) // if we've read some.
         {
            PTEXT t;
            workline=PRIORLINE(workline); // go back one.
            SegBreak(t = NEXTLINE(workline));
            LineRelease(t);  // destroy the current segment.
         }
         else
         {
            LineRelease(workline);            // destory only segment.
            workline = NULL;
         }
         break;  // get out of the loop- there is no more to read.
      }
   }
   while (GetText(workline)[length-1]!='\n'); //while not at the end of the line.
   if (workline&&length)  // if I got a line, and there was some length to it.
      SetStart(workline);   // set workline to the beginning.
   return(workline);      // return the line read from the file.
}
Exemple #25
0
RelationData::RelationData(UmlCode e, int id)
    : Labeled<RelationData>(all, id), is_deleted(FALSE), is_unconsistent(FALSE), type(e)
{
    a.isa_class_relation = b.isa_class_relation = FALSE;
    a.isa_volatile_relation = b.isa_volatile_relation = FALSE;
    a.isa_const_relation = b.isa_const_relation = FALSE;
    a.is_derived = b.is_derived =  FALSE;
    a.is_derivedunion = b.is_derivedunion =  FALSE;
    a.is_ordered = b.is_ordered =  FALSE;
    a.is_unique = b.is_unique =  FALSE;
    a.uml_visibility = b.uml_visibility = UmlDefaultVisibility;
    a.cpp_virtual_inheritance = b.cpp_virtual_inheritance = FALSE;
    a.cpp_visibility = b.cpp_visibility = UmlDefaultVisibility;
    a.cpp_mutable = b.cpp_mutable = FALSE;
    a.java_transient = b.java_transient = FALSE;
    a.idl_truncatable_inheritance = b.idl_truncatable_inheritance = FALSE;
    a.idl_case = b.idl_case = 0;
    name = default_name(e);
    SetStart(0);
    SetEnd(0);
    end_removed_from = 0;
    original_id = 0;
}
void EDGE_MODULE::Flip(const wxPoint& aCentre )
{
    wxPoint pt;

    switch( GetShape() )
    {
    case S_ARC:
        SetAngle( -GetAngle() );
        //Fall through
    default:
    case S_SEGMENT:
        pt = GetStart();
        pt.y -= aCentre.y;
        pt.y  = -pt.y;
        pt.y += aCentre.y;
        SetStart( pt );

        pt = GetEnd();
        pt.y -= aCentre.y;
        pt.y  = -pt.y;
        pt.y += aCentre.y;
        SetEnd( pt );

        NEGATE( m_Start0.y );
        NEGATE( m_End0.y );
        break;

    case S_POLYGON:
        // polygon corners coordinates are always relative to the
        // footprint position, orientation 0
        for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ )
            NEGATE( m_PolyPoints[ii].y );
    }

    SetLayer( FlipLayer( GetLayer() ) );
}
nsresult
nsTypeAheadFind::GetSearchContainers(nsISupports *aContainer,
                                     nsISelectionController *aSelectionController,
                                     bool aIsFirstVisiblePreferred,
                                     bool aFindPrev,
                                     nsIPresShell **aPresShell,
                                     nsPresContext **aPresContext)
{
  NS_ENSURE_ARG_POINTER(aContainer);
  NS_ENSURE_ARG_POINTER(aPresShell);
  NS_ENSURE_ARG_POINTER(aPresContext);

  *aPresShell = nullptr;
  *aPresContext = nullptr;

  nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
  if (!docShell)
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();

  nsRefPtr<nsPresContext> presContext;
  docShell->GetPresContext(getter_AddRefs(presContext));

  if (!presShell || !presContext)
    return NS_ERROR_FAILURE;

  nsIDocument* doc = presShell->GetDocument();

  if (!doc)
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsIContent> rootContent;
  nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(doc));
  if (htmlDoc) {
    nsCOMPtr<nsIDOMHTMLElement> bodyEl;
    htmlDoc->GetBody(getter_AddRefs(bodyEl));
    rootContent = do_QueryInterface(bodyEl);
  }

  if (!rootContent)
    rootContent = doc->GetRootElement();
 
  nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootContent));

  if (!rootNode)
    return NS_ERROR_FAILURE;

  if (!mSearchRange) {
    mSearchRange = new nsRange(doc);
  }
  nsCOMPtr<nsIDOMNode> searchRootNode = rootNode;

  // Hack for XMLPrettyPrinter. nsFind can't handle complex anonymous content.
  // If the root node has an XBL binding then there's not much we can do in
  // in general, but we can try searching the binding's first child, which
  // in the case of XMLPrettyPrinter contains the visible pretty-printed
  // content.
  nsXBLBinding* binding = rootContent->GetXBLBinding();
  if (binding) {
    nsIContent* anonContent = binding->GetAnonymousContent();
    if (anonContent) {
      searchRootNode = do_QueryInterface(anonContent->GetFirstChild());
    }
  }
  mSearchRange->SelectNodeContents(searchRootNode);

  if (!mStartPointRange) {
    mStartPointRange = new nsRange(doc);
  }
  mStartPointRange->SetStart(searchRootNode, 0);
  mStartPointRange->Collapse(true); // collapse to start

  if (!mEndPointRange) {
    mEndPointRange = new nsRange(doc);
  }
  nsCOMPtr<nsINode> searchRootTmp = do_QueryInterface(searchRootNode);
  mEndPointRange->SetEnd(searchRootNode, searchRootTmp->Length());
  mEndPointRange->Collapse(false); // collapse to end

  // Consider current selection as null if
  // it's not in the currently focused document
  nsCOMPtr<nsIDOMRange> currentSelectionRange;
  nsCOMPtr<nsIPresShell> selectionPresShell = GetPresShell();
  if (aSelectionController && selectionPresShell && selectionPresShell == presShell) {
    nsCOMPtr<nsISelection> selection;
    aSelectionController->GetSelection(
      nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
    if (selection)
      selection->GetRangeAt(0, getter_AddRefs(currentSelectionRange));
  }

  if (!currentSelectionRange) {
    // Ensure visible range, move forward if necessary
    // This uses ignores the return value, but usese the side effect of
    // IsRangeVisible. It returns the first visible range after searchRange
    IsRangeVisible(presShell, presContext, mSearchRange, 
                   aIsFirstVisiblePreferred, true, 
                   getter_AddRefs(mStartPointRange), nullptr);
  }
  else {
    int32_t startOffset;
    nsCOMPtr<nsIDOMNode> startNode;
    if (aFindPrev) {
      currentSelectionRange->GetStartContainer(getter_AddRefs(startNode));
      currentSelectionRange->GetStartOffset(&startOffset);
    } else {
      currentSelectionRange->GetEndContainer(getter_AddRefs(startNode));
      currentSelectionRange->GetEndOffset(&startOffset);
    }
    if (!startNode)
      startNode = rootNode;    

    // We need to set the start point this way, other methods haven't worked
    mStartPointRange->SelectNode(startNode);
    mStartPointRange->SetStart(startNode, startOffset);
  }

  mStartPointRange->Collapse(true); // collapse to start

  presShell.forget(aPresShell);
  presContext.forget(aPresContext);

  return NS_OK;
}
Exemple #28
0
// ExtendToLength ----------------------------
// ---------------
void plAGAnim::ExtendToLength(float length)
{
    if (length > GetEnd())
        SetEnd(length);
}
/**********************************************************************
* CTextRun::Speak() *
*-------------------*
*	Description:  
*       Uses *plStart and *plEnd to find the nearest start and 
*       endpoints for speaking (to the nearest word).
*       Returns these values in plStart and plEnd.
*		Speaks the text associated with this CTextRun from *plStart 
*       to *plEnd.  
*       
*       If *plStart is not within the range, then 
*       start at the beginning.  If lEnd is not within range, then
*       end at the end.  
*
* 	Return:
*       S_OK
*       E_POINTER
*		Return value of CTextRun::Speak()
**********************************************************************/
HRESULT CTextRun::Speak( ISpVoice &rVoice, 
                               long *plStart,
                               long *plEnd )
{
    if ( !plStart || !plEnd )
    {
        return E_POINTER;
    }
    _ASSERTE( m_cpTextRange );
    if ( !m_cpTextRange )
    {
        return E_UNEXPECTED;
    }

    // Save the old range
    long lOldStart = GetStart();
    long lOldEnd = GetEnd();

    // Out of range start or end means we start speaking from the start
    // or end (resp.) of the text range.
    
    if ( WithinRange( *plStart ) )
    {
        // The start needs to be moved
        SetStart( *plStart );
    }
    else
    {
        *plStart = GetStart();
    }

    if ( WithinRange( *plEnd ) )
    {
        // The end needs to be moved
        SetEnd( *plEnd );
    }
    else
    {
        *plEnd = GetEnd();
    }

    // Expand to include whole words
    m_cpTextRange->Expand( tomWord, NULL );

    // Get the new start and end so that we can pass them back
    m_cpTextRange->GetStart( plStart );
    m_cpTextRange->GetEnd( plEnd );

    // We should never speak past the end of this run, even if expanding to include
    // whole words caused extra text to be included 
    // (e.g. if you typed "This is a sentence" and dictated some text that 
    // consumed leading spaces right afterwards)
    *plStart = __max( *plStart, lOldStart );
    *plEnd = __min( *plEnd, lOldEnd );
    SetStart( *plStart );
    SetEnd( *plEnd );

    // Pass to the CTextRun::Speak() that speaks an entire run
    HRESULT hr = Speak( rVoice );

    // Restore the old range limits
    SetStart( lOldStart );
    SetEnd( lOldEnd );

    return hr;
}   /* CTextRun::Speak */
/**********************************************************************
* CTextRun::Concatenate *
*-----------------------*
*	Description:  
*		If possible, concatenates pNext (pPrev if fConcatAfter is false)
*       onto the end of this.
*       Another CTextRun can always be concatenated on, unless it 
*       contains dictation.
*
* 	Return:
*		E_NOMERGE if could not be merged (because pTextRun is dictation)
*       E_FULLMERGE
**********************************************************************/
MERGERESULT CTextRun::Concatenate( CTextRun *pTextRun, bool fConcatAfter )
{
    if ( !pTextRun || !m_cpTextRange )
    {
        return E_NOMERGE;
    }

    // Check for compatibility: In this case, neither mergee can be 
    // a dict run
    if ( IsDict() || pTextRun->IsDict() )
    {
        return E_NOMERGE;
    }

    // lNewBound will be the new end (resp. start) of the run, if the 
    // concatenation is successful
    long lNewBound;
   
    // Concatenation is possible iff one run ends exactly where the other
    // begins.
    // If concatenation is possible, do it.
    if ( fConcatAfter )
    {
        // Will be concatenating pTextRun onto the end of this
        if ( GetEnd() != pTextRun->GetStart() )
        {
            // They are not consecutive runs
            return E_NOMERGE;
        }

        // lNewBound will be the new end of the run, if the 
        // concatenation is successful
        lNewBound = pTextRun->GetEnd();
        
        // Swallow up pTextRun by setting our end to its end
        SetEnd( lNewBound );

        // Make pTextRun degenerate
        pTextRun->SetStart( lNewBound );
        
    }
    else
    {
        // Will be concatenating pTextRun onto the beginning of this
        if ( GetStart() != pTextRun->GetEnd() )
        {
            return E_NOMERGE;
        }

        // lNewBound will be the new start of the run, if the 
        // concatenation is successful
        lNewBound = pTextRun->GetStart();

        // Swallow up pTextRun by setting our start to its start
        SetStart( lNewBound );

        // Make pTextRun degenerate
        pTextRun->SetEnd( lNewBound );
    }

    return E_FULLMERGE;
}   /* CTextRun::Concatenate */