void RocketMenuPlugin::HighlightItem(Rocket::Core::Element *e) { static ColorAnimation colorAnimation(rgb(255,255,255), rgb(235, 156, 9), 1); DocumentData *doc_data = GetDocumentData(e->GetOwnerDocument()); if (doc_data != NULL) { if (doc_data->active_item != e && !e->IsClassSet("disabled")) { if (doc_data->active_item != NULL) { m_animation->CancelAnimation(doc_data->active_item); OptionsData *options_data = GetOptionsData(doc_data->active_item); if (options_data != NULL) { ShowElement(options_data->hdr, false); ShowElement(options_data->ftr, false); } RangeData *range_data = GetRangeData(doc_data->active_item); if (range_data != NULL) { ShowElement(range_data->hdr, false); ShowElement(range_data->ftr, false); } KeyData *key_data = GetKeyData(doc_data->active_item); if (key_data != NULL) { UpdateKeyChooser(key_data, doc_data->active_key, false); } } if (e != NULL) { if (e->GetParentNode()->HasAttribute("scroll")) { DoScroll(doc_data->active_item, e, e->GetParentNode()->GetParentNode()); } if (!e->HasAttribute("noanim")) { m_animation->AnimateElement(e, AnimationTypeBounce, 0.3f, &colorAnimation); } AttachCursor(e, doc_data->cursor_left, doc_data->cursor_right); OptionsData *options_data = GetOptionsData(e); if (options_data != NULL) { ShowElement(options_data->hdr, true); ShowElement(options_data->ftr, true); } RangeData *range_data = GetRangeData(e); if (range_data != NULL) { ShowElement(range_data->hdr, true); ShowElement(range_data->ftr, true); } KeyData *key_data = GetKeyData(e); if (key_data != NULL) { UpdateKeyChooser(key_data, doc_data->active_key, true); } m_delegate->DidActivateItem(e); } doc_data->active_item = e; } } }
void QFitRangeWidget::RangeTypCmb_activated( int num ) { if (!fbFillWidget) { EnableEditsForRangeType(num); GetRangeData(); } }
float RocketMenuPlugin::GetRangeValue(Rocket::Core::Element *menu_item) { RangeData *data = GetRangeData(menu_item); if (data != NULL) { return data->value; } return 0.0f; }
void RocketMenuPlugin::SetRangeValue(Rocket::Core::Element *menu_item, float value, bool notify_delegate) { RangeData *data = GetRangeData(menu_item); if (data != NULL) { Rocket::Core::String tmp; // printf("=======\n"); // data->range->GetAttribute("min")->GetInto(tmp); // printf("min: %s\n", tmp.CString()); // data->range->GetAttribute("max")->GetInto(tmp); // printf("max: %s\n", tmp.CString()); // data->range->GetAttribute("value")->GetInto(tmp); // printf("value: %s\n", tmp.CString()); // data->range->GetAttribute("step")->GetInto(tmp); // printf("step: %s\n", tmp.CString()); data->value = clamp(value, data->min, data->max); data->range->SetAttribute("value", (data->value - data->min)/(data->max - data->min)); #if 0 float position = data->rail_x + data->value/(data->max-data->min)*data->rail_length; data->grip->SetProperty("left", Rocket::Core::Property(position, Rocket::Core::Property::PX)); #endif // if (m_delegate != NULL && notify_delegate) { // m_delegate->DidChangeRangeValue(menu_item, value); // } } }
// Called when an element is destroyed. void RocketMenuPlugin::OnElementDestroy(Rocket::Core::Element* element) { OptionsData *options_data = GetOptionsData(element); if (options_data != NULL) { delete options_data; SetOptionsData(element, NULL); } RangeData *range_data = GetRangeData(element); if (range_data != NULL) { delete range_data; SetRangeData(element, NULL); } KeyData *key_data = GetKeyData(element); if (key_data != NULL) { delete key_data; SetKeyData(element, NULL); } }
void RocketMenuPlugin::ProcessEvent(Rocket::Core::Event& event) { Rocket::Core::Element *element = event.GetCurrentElement(); if (event.GetType() == "click") { if (element->GetTagName() == "ftr") { SetNextItemValue(element->GetParentNode()->GetParentNode()); event.StopPropagation(); } else if (element->GetTagName() == "hdr") { SetPreviousItemValue(element->GetParentNode()->GetParentNode()); event.StopPropagation(); } else { DoItemAction(ItemActionEnter, element); } } else if (event.GetType() == "mousemove") { if (element->GetTagName() == "div") { HighlightItem(element); } else if (element->GetTagName() == "key1") { Rocket::Core::Element *menu_item = element->GetParentNode()->GetParentNode(); SetActiveKeySlot(menu_item, 0); } else if (element->GetTagName() == "key2") { Rocket::Core::Element *menu_item = element->GetParentNode()->GetParentNode(); SetActiveKeySlot(menu_item, 1); } } else if (event.GetType() == "change") { if (m_delegate != NULL && element->GetOwnerDocument()->IsVisible()) { Rocket::Core::Element *menu_item = element->GetParentNode()->GetParentNode(); RangeData *data = GetRangeData(menu_item); const Rocket::Core::Dictionary *p = event.GetParameters(); float v = p->Get("value")->Get<float>(); float new_value = data->min + v*(data->max - data->min); if (fabs(new_value-data->value) > 0.001f) { data->value = new_value; m_delegate->DidChangeRangeValue(menu_item, data->value); } } } }
void QFitRangeWidget::RightEdt_textChanged( const QString & ) { GetRangeData(); }
void QFitRangeWidget::AxisNumSpin_valueChanged( int ) { GetRangeData(); }
//**************************************************************************************** BOOL CBCGPGridSerializeManager::WriteToArchive (CArchive& archive) { if (GetRangeCount () == 0) { return FALSE; // no data } ASSERT (m_idRangesOffset.m_nRow >= 0); ASSERT (m_idRangesOffset.m_nColumn >= 0); //---------------------- // Store serialized data //---------------------- // int - format type // int - ranges common offset: row // int - ranges common offset: column // int - range count // ranges array: // int - range offset: row \ // int - range offset: column | range // int - range size: row count | // int - range size: columns count | // UINT - size in bytes | range data | // BYTE - range data | / try { archive << (int) m_ClipboardFormatType; //------------------------------------ // Store common offset for all ranges: //------------------------------------ archive << m_idRangesOffset.m_nRow; archive << m_idRangesOffset.m_nColumn; //---------------------- // Store list of ranges: //---------------------- archive << (int) GetRangeCount (); for (int i = 0; i < GetRangeCount (); i++) { CBCGPGridRange range; if (!GetRange (i, range)) { return FALSE; } //------------- // Store range: //------------- if (range.m_nTop < 0 || range.m_nLeft < 0) { return FALSE; } const int nRowCount = range.m_nBottom - range.m_nTop + 1; if (nRowCount <= 0) { return FALSE; } const int nColCount = range.m_nRight - range.m_nLeft + 1; if (nColCount <= 0) { return FALSE; } archive << (int) range.m_nTop; archive << (int) range.m_nLeft; archive << nRowCount; archive << nColCount; //------------------ // Store range data: //------------------ UINT nDataSize = 0; BYTE* pData = GetRangeData (i, nDataSize); if (pData == NULL || nDataSize <= 0) { return FALSE; } archive << nDataSize; archive.Write (pData, nDataSize); } } catch (CArchiveException* pEx) { TRACE(_T("CBCGPGridSerializeManager::WriteToArchive. Archive exception\r\n")); pEx->Delete (); return FALSE; } return TRUE; }
//**************************************************************************************** BOOL CBCGPGridSerializeManager::DoDropRows (CBCGPGridItemID idDropTo, CBCGPGridItemID idDragFrom, BOOL bMove, BOOL bInsertAfter) { ASSERT (m_pOwnerGrid != NULL); ASSERT (m_ClipboardFormatType == CF_Rows); if (GetRangeCount () == 0) { return FALSE; // no data } // Copied rows are already removed if called from Paste or dragged from another app BOOL bNoRemove = idDragFrom.IsNull (); //--------------------- // Calculate new offset //--------------------- idDragFrom.SetNull (); if (bInsertAfter) { idDropTo.m_nRow++; } CBCGPGridItemID idTo = GetDropOffset (idDragFrom, idDropTo); ASSERT (idTo.m_nRow >= 0); ASSERT (idTo.m_nColumn >= 0); //---------------- // Mark selection: (save ranges to remove selection later) //---------------- CleanUpImplementationData (); if (bNoRemove) { m_arrCutRanges.SetSize (0); } else { m_arrCutRanges.SetSize (GetRangeCount ()); for (int i = 0; i < GetRangeCount (); i++) { CBCGPGridRange rangeOrder; if (!GetRange (i, rangeOrder)) { return FALSE; } rangeOrder.m_nTop += m_idRangesOffset.m_nRow; rangeOrder.m_nBottom += m_idRangesOffset.m_nRow; m_arrCutRanges [i] = (CMarkedGridRange) rangeOrder; if (rangeOrder.m_nTop < idDropTo.m_nRow && rangeOrder.m_nBottom >= idDropTo.m_nRow) { //idDropTo = rangeOrder.m_nTop; return FALSE; // can't insert inside range } } } //------------- // Drop ranges: //------------- for (int i = 0; i < GetRangeCount (); i++) { CBCGPGridRange rangeOrder; if (!GetRange (i, rangeOrder)) { return FALSE; } if (rangeOrder.m_nTop < 0 || rangeOrder.m_nBottom < rangeOrder.m_nTop) { return FALSE; } const int nRowOffset = -rangeOrder.m_nTop + idTo.m_nRow + (int)m_lstNewRows.GetCount (); rangeOrder.m_nTop += nRowOffset; rangeOrder.m_nBottom += nRowOffset; //------------ // Drop range: //------------ UINT nDataSize = 0; BYTE* pData = GetRangeData (i, nDataSize); if (pData == NULL || nDataSize <= 0) { return FALSE; } CMemFile f(pData, nDataSize); CArchive archive (&f, CArchive::load); if (!ReadRowsFromArchive (archive, rangeOrder)) { return FALSE; } archive.Close (); } if (!m_bSkipData) { //--------------------------- // Remove previous selection: //--------------------------- CBCGPGridItemID id; m_pOwnerGrid->SetCurSel (id, SM_NONE, FALSE); //------------------------- // Insert new rows to grid: //------------------------- InsertNewSelection (idTo.m_nRow, m_lstNewRows); if (bMove) { //--------------------- // Remove marked items (previous selection): //--------------------- if (!RemovePreviosSelection ()) { return FALSE; // can't clear non empty items } } UpdateSelectionRect (idTo); m_pOwnerGrid->AdjustLayout (); //------------------- // Set new selection: //------------------- CBCGPGridRange rangeSel = m_InsertRange; if (rangeSel.IsValid ()) { CBCGPGridItemID idFirst (rangeSel.m_nTop); CBCGPGridItemID idSecond (rangeSel.m_nBottom); m_pOwnerGrid->SetCurSel (idFirst, SM_FIRST_CLICK | SM_SINGE_SEL_GROUP, FALSE); m_pOwnerGrid->SetCurSel (idSecond, SM_SECOND_CLICK | SM_CONTINUE_SEL_GROUP, TRUE); } } CleanUpImplementationData (); return TRUE; }
//**************************************************************************************** BOOL CBCGPGridSerializeManager::DoDropItems (CBCGPGridItemID idDropTo, CBCGPGridItemID idDragFrom, BOOL bMove) { // idDropTo - index // idDragFrom - index ASSERT (m_pOwnerGrid != NULL); ASSERT (m_ClipboardFormatType == CF_Items); if (GetRangeCount () == 0) { return FALSE; // no data } //--------------------- // Calculate new offset //--------------------- CBCGPGridItemID idTo = GetDropOffset (idDragFrom, idDropTo); ASSERT (idTo.m_nRow >= 0); ASSERT (idTo.m_nColumn >= 0); //------------------------------------ // Can replace content of target area: //------------------------------------ if (!m_bSkipData) { if (!CanReplaceNewSelection (idTo, TRUE)) { return FALSE; // can't clear non empty items } } if (!m_bSkipData && bMove) { //------------------------------------- // Clear content of previous selection: //------------------------------------- if (!ClearPreviousSelection (FALSE)) { return FALSE; // can't clear non empty items } } //------------- // Drop ranges: //------------- int i = 0; for (i = 0; i < GetRangeCount (); i++) { CBCGPGridRange rangeOrder; if (!GetRange (i, rangeOrder)) { return FALSE; } rangeOrder.m_nLeft += idTo.m_nColumn; rangeOrder.m_nRight += idTo.m_nColumn; rangeOrder.m_nTop += idTo.m_nRow; rangeOrder.m_nBottom += idTo.m_nRow; if (rangeOrder.m_nBottom > m_nLastRow || rangeOrder.m_nRight > m_nLastColumn) { return FALSE; // out of grid range } //------------ // Drop range: //------------ UINT nDataSize = 0; BYTE* pData = GetRangeData (i, nDataSize); if (pData == NULL || nDataSize <= 0) { return FALSE; } CMemFile f(pData, nDataSize); CArchive archive (&f, CArchive::load | CArchive::bNoFlushOnDelete); if (!ReadItemsFromArchive (archive, rangeOrder)) { return FALSE; } archive.Close (); } if (!m_bSkipData) { //--------------------------- // Remove previous selection: //--------------------------- UpdateSelectionRect (m_idRangesOffset); //--------------- // Set selection: //--------------- BOOL bFirst = TRUE; for (i = 0; i < GetRangeCount (); i++) { CBCGPGridRange rangeOrder; if (!GetRange (i, rangeOrder)) { continue; } rangeOrder.m_nLeft += idTo.m_nColumn; rangeOrder.m_nRight += idTo.m_nColumn; rangeOrder.m_nTop += idTo.m_nRow; rangeOrder.m_nBottom += idTo.m_nRow; CBCGPGridRange rangeIndex; if (!OrderToIndex (rangeOrder, rangeIndex)) { continue; } CBCGPGridItemID idFirst (rangeIndex.m_nTop, rangeIndex.m_nLeft); CBCGPGridItemID idSecond (rangeIndex.m_nBottom, rangeIndex.m_nRight); DWORD dwSelMode = bFirst ? SM_SINGE_SEL_GROUP : SM_ADD_SEL_GROUP; bFirst = FALSE; m_pOwnerGrid->SetCurSel (idFirst, SM_FIRST_CLICK | dwSelMode, FALSE); m_pOwnerGrid->SetCurSel (idSecond, SM_SECOND_CLICK | SM_CONTINUE_SEL_GROUP, FALSE); } UpdateSelectionRect (idTo); } return TRUE; }
void RocketMenuPlugin::DecreaseRangeValue(Rocket::Core::Element *menu_item) { RangeData *data = GetRangeData(menu_item); if (data != NULL) { SetRangeValue(menu_item, data->value - data->step); } }