Ejemplo n.º 1
0
bool
DragSortableListView::HandleDropMessage(const BMessage* message,
	int32 dropIndex)
{
	DragSortableListView *list = NULL;
	if (message->FindPointer("list", (void **)&list) != B_OK || list != this)
		return false;

	BList items;
	int32 index;
	for (int32 i = 0; message->FindInt32("index", i, &index) == B_OK; i++) {
		BListItem* item = ItemAt(index);
		if (item != NULL)
			items.AddItem((void*)item);
	}

	if (items.CountItems() == 0)
		return false;

	if ((modifiers() & B_SHIFT_KEY) != 0)
		CopyItems(items, dropIndex);
	else
		MoveItems(items, dropIndex);

	return true;
}
Ejemplo n.º 2
0
//-----------------------------------------------------------------------------
void Profile::CopyItems(JSON* root, String prefix)
{
    JSON* item = root->GetFirstItem();
    while (item)
    {
        String item_name;
        if (prefix.IsEmpty())
            item_name = item->Name;
        else
            item_name = prefix + "." + item->Name;

        if (item->Type == JSON_Object)
        {   // recursively copy the children
            
            CopyItems(item, item_name);
        }
        else
        {
            //Settings.Set(item_name, item->Value);
            SetValue(item);
        }

        item = root->GetNextItem(item);
    }
}
Ejemplo n.º 3
0
	void Vector<T>::Delete(int ieMin, int ieLim, T * prge)
{
	AssertObj(this);
	Assert((uint)ieMin <= (uint)ieLim && (uint)ieLim <= (uint)m_ieLim);
	AssertArrayN(prge, ieLim - ieMin);
	if ((uint)ieLim > (uint)m_ieLim)
		throw std::invalid_argument("ieLim");
	if ((uint)ieMin > (uint)ieLim)
		throw std::invalid_argument("ieMin");

	if (ieMin == ieLim)
		return;

	if (prge)
	{
		// More efficient to destroy the existing objects at the destination, then do a raw
		// binary copy across than to invoke assignment operators.
		::DestroyRange(prge, ieLim - ieMin);
		CopyItems(m_prge + ieMin, prge, ieLim - ieMin);
	}
	else
		::DestroyRange(m_prge + ieMin, ieLim - ieMin);

	if (ieLim < m_ieLim)
		MoveItems(m_prge + ieLim, m_prge + ieMin, m_ieLim - ieLim);
	m_ieLim -= ieLim - ieMin;

	AssertObj(this);
}
Ejemplo n.º 4
0
  double CalculateSequence(const std::vector<ExpressionItem*> i_items,
                           size_t i_startLoc,
                           size_t i_endLoc)
  {
    std::vector<ExpressionItem*> currentPriorityResult = CopyItems(i_items,
                                                                   i_startLoc,
                                                                   i_endLoc);
    for (int priority = 0;
         priority < OperatorPrioritiesCount;
         ++priority)
    {
      std::vector<ExpressionItem*> newResult = CalculateSequenceForPriority(currentPriorityResult,
                                                                            static_cast<OperatorPriority>(priority));
      ClearItems(currentPriorityResult);
      currentPriorityResult = newResult;
    }

    assert(currentPriorityResult.size() == 1);
    assert(currentPriorityResult[0]->Type() == ExpressionItemTypeOperand);

    Operand* operand = dynamic_cast<Operand*>(currentPriorityResult[0]);
    double result = operand->GetValue();
    ClearItems(currentPriorityResult);

    return result;
  }
Ejemplo n.º 5
0
//-----------------------------------------------------------------------------
bool Profile::LoadDeviceFile(unsigned int productId, const char* printedSerialNumber)
{
	if (printedSerialNumber[0] == 0)
        return false;

    String path = BasePath + "/Devices.json";

    // Load the device profiles
    Ptr<JSON> root = *JSON::Load(path);
    if (root == NULL)
        return false;

    // Quick sanity check of the file type and format before we parse it
    JSON* version = root->GetFirstItem();
    if (version && version->Name == "Oculus Device Profile Version")
    {   
        int major = atoi(version->Value.ToCStr());
        if (major > MAX_DEVICE_PROFILE_MAJOR_VERSION)
            return false;   // don't parse the file on unsupported major version number
    }
    else
    {
        return false;
    }   

    JSON* device = root->GetNextItem(version);
    while (device)
    {   
        if (device->Name == "Device")
        {   
            JSON* product_item = device->GetItemByName("ProductID");
            JSON* serial_item = device->GetItemByName("Serial");
            if (product_item && serial_item &&
				(product_item->dValue == productId) && (serial_item->Value == printedSerialNumber))
            {   
                // found the entry for this device so recursively copy all the settings to the profile
                CopyItems(device, "");
                return true;   
            }
        }

        device = root->GetNextItem(device);
    }
    
    return false;
}
Ejemplo n.º 6
0
/*****************************************************************************
 * DragSortableListView::MessageReceived
 *****************************************************************************/
void
DragSortableListView::MessageReceived(BMessage* message)
{
    switch ( message->what )
    {
        case B_MODIFIERS_CHANGED:
            ModifiersChanged();
            break;
        case B_SIMPLE_DATA:
        {
            DragSortableListView *list = NULL;
            if ( message->FindPointer( "list", (void **)&list ) == B_OK
                 && list == this )
            {
                int32 count = CountItems();
                if ( fDropIndex < 0 || fDropIndex > count )
                    fDropIndex = count;
                BList items;
                int32 index;
                for ( int32 i = 0; message->FindInt32( "index", i, &index ) == B_OK; i++ )
                    if ( BListItem* item = ItemAt(index) )
                        items.AddItem( (void*)item );
                if ( items.CountItems() > 0 )
                {
                    if ( modifiers() & B_SHIFT_KEY )
                        CopyItems( items, fDropIndex );
                    else
                        MoveItems( items, fDropIndex );
                }
                fDropIndex = -1;
            }
            break;
        }
        default:
            BListView::MessageReceived( message );
            break;
    }
}
Ejemplo n.º 7
0
// MessageReceived
void
DragSortableListView::MessageReceived(BMessage* message)
{
	if (message->what == fDragCommand) {
		DragSortableListView *list = NULL;
		if (message->FindPointer("list", (void **)&list) == B_OK
			 && list == this) {
			int32 count = CountItems();
			if (fDropIndex < 0 || fDropIndex > count)
				fDropIndex = count;
			BList items;
			int32 index;
			for (int32 i = 0; message->FindInt32("index", i, &index) == B_OK; i++)
				if (BListItem* item = ItemAt(index))
					items.AddItem((void*)item);
			if (items.CountItems() > 0) {
				if (modifiers() & B_SHIFT_KEY)
					CopyItems(items, fDropIndex);
				else
					MoveItems(items, fDropIndex);
			}
			fDropIndex = -1;
		}
	} else {
		switch (message->what) {
			case MSG_TICK: {
				float scrollV = 0.0;
				BRect rect(Bounds());
				BPoint point;
				uint32 buttons;
				GetMouse(&point, &buttons, false);
				if (rect.Contains(point)) {
					// calculate the vertical scrolling offset
					float hotDist = rect.Height() * SCROLL_AREA;
					if (point.y > rect.bottom - hotDist)
						scrollV = hotDist - (rect.bottom - point.y);
					else if (point.y < rect.top + hotDist)
						scrollV = (point.y - rect.top) - hotDist;
				}
				// scroll
				if (scrollV != 0.0 && fScrollView) {
					if (BScrollBar* scrollBar = fScrollView->ScrollBar(B_VERTICAL)) {
						float value = scrollBar->Value();
						scrollBar->SetValue(scrollBar->Value() + scrollV);
						if (scrollBar->Value() != value) {
							// update mouse position
							uint32 buttons;
							BPoint point;
							GetMouse(&point, &buttons, false);
							uint32 transit = Bounds().Contains(point) ? B_INSIDE_VIEW : B_OUTSIDE_VIEW;
							MouseMoved(point, transit, &fDragMessageCopy);
						}
					}
				}
				break;
			}
//			case B_MODIFIERS_CHANGED:
//				ModifiersChanged();
//				break;
			case B_MOUSE_WHEEL_CHANGED: {
				BListView::MessageReceived(message);
				BPoint point;
				uint32 buttons;
				GetMouse(&point, &buttons, false);
				uint32 transit = Bounds().Contains(point) ? B_INSIDE_VIEW : B_OUTSIDE_VIEW;
				MouseMoved(point, transit, &fDragMessageCopy);
				break;
			}
			default:
				BListView::MessageReceived(message);
				break;
		}
	}
}
Ejemplo n.º 8
0
void CCeWatchDlg::OnCutItems ()
{
    if (CopyItems ())
        m_VarList.DeleteSelectedVar ();
}
Ejemplo n.º 9
0
void CCeWatchDlg::OnCopyItems ()
{
    CopyItems ();
}
Ejemplo n.º 10
0
/*----------------------------------------------------------------------------------------------
	Convert the 16-bit Unicode string to UTF-8, returning the length in bytes of the UTF-8
	string.  Care is taken not to overflow the output buffer.

	@param rgchDst Pointer to an output array of (8-bit) characters.
	@param cchMaxDst Maximum number of (8-bit) characters that can be stored in rgchDst.
	@param rgchwSrc Pointer to an input array of wide (Unicode) characters.
	@param cchwSrc Number of wide characters in rgchwSrc.  This may be greater than the number
					of actual Unicode characters due to surrogate pairs.
	@param fXml Flag whether the output needs to have XML character code escapes for "<>&"".

	@return Number of characters required for the output buffer. If cchMaxDst is less than or
					equal to the return value, all of the output was written.
----------------------------------------------------------------------------------------------*/
int ConvertUtf16ToXmlUtf8(char * rgchDst, int cchMaxDst, const wchar * rgchwSrc, int cchwSrc,
	bool fXml)
{
	AssertArray(rgchDst, cchMaxDst);
	AssertArray(rgchwSrc, cchwSrc);

	int cchChar;
	char rgchChar[8];
	const char * prgchChar;
	const wchar * pchw;
	const wchar * pchwLim = rgchwSrc + cchwSrc;

	// TODO SteveMc(ShonK): This needs a better name. When you decide on hungarian tags for
	// the constants above use the same tag here.
	byte bFirstMark = 0;

	int cchDst = 0;

	for (pchw = rgchwSrc; pchw < pchwLim; )
	{
		ulong luChar = *pchw++;
		if (kSurrogateHighFirst <= luChar && luChar <= kSurrogateHighLast && pchw < pchwLim)
		{
			ulong luChar2 = *pchw;
			if (kSurrogateLowFirst <= luChar2 && luChar2 <= kSurrogateLowLast)
			{
				luChar -= kSurrogateHighFirst;
				luChar <<= kSurrogateShift;
				luChar += luChar2 - kSurrogateLowFirst;
				luChar += kSurrogateBase;
				++pchw;
			}
		}
		if (luChar > kUnicodeMax)
		{
			luChar = kReplacementChar;
		}

		prgchChar = NULL;

		if (luChar < kUtf8Min2)
		{
			if (fXml)
			{
				switch (luChar)
				{
				case '<':
					prgchChar = "&lt;";
					cchChar = 4;
					break;
				case '>':
					prgchChar = "&gt;";
					cchChar = 4;
					break;
				case '&':
					prgchChar = "&amp;";
					cchChar = 5;
					break;
				case '"':
					prgchChar = "&quot;";
					cchChar = 6;
					break;
				default:
					bFirstMark = kUtf8Flag1;
					cchChar = 1;
					break;
				}
			}
			else
			{
				bFirstMark = kUtf8Flag1;
				cchChar = 1;
			}
		}
		else if (luChar < kUtf8Min3)
		{
			bFirstMark = kUtf8Flag2;
			cchChar = 2;
		}
		else if (luChar < kUtf8Min4)
		{
			bFirstMark = kUtf8Flag3;
			cchChar = 3;
		}
		else if (luChar < kUtf8Min5)
		{
			bFirstMark = kUtf8Flag4;
			cchChar = 4;
		}
		else if (luChar < kUtf8Min6)
		{
			bFirstMark = kUtf8Flag5;
			cchChar = 5;
		}
		else
		{
			bFirstMark = kUtf8Flag6;
			cchChar = 6;
		}

		if (!prgchChar)
		{
			prgchChar = rgchChar;

			char * pch = &rgchChar[cchChar];

			switch (cchChar)
			{
			case 6:
				*--pch = (char)((luChar & kByteMask) | kByteMark);
				luChar >>= kByteShift;
				// fall through
			case 5:
				*--pch = (char)((luChar & kByteMask) | kByteMark);
				luChar >>= kByteShift;
				// fall through
			case 4:
				*--pch = (char)((luChar & kByteMask) | kByteMark);
				luChar >>= kByteShift;
				// fall through
			case 3:
				*--pch = (char)((luChar & kByteMask) | kByteMark);
				luChar >>= kByteShift;
				// fall through
			case 2:
				*--pch = (char)((luChar & kByteMask) | kByteMark);
				luChar >>= kByteShift;
				// fall through
			case 1:
				*--pch = (char)(luChar | bFirstMark);
				break;
			default:
				Assert(false);		// can't happen!!
			}
		}

		if (cchDst < cchMaxDst)
		{
			CopyItems(prgchChar, rgchDst + cchDst, Min(cchChar, cchMaxDst - cchDst));
		}
		else
		{
			// REVIEW: should we somehow signal an error on overflowing the output buffer?
			ThrowHr(E_OUTOFMEMORY, StrUni(L"BUFFER OVERFLOW in ConvertUtf16ToXmlUtf8()").Chars());
		}
		cchDst += cchChar;
	}