Ejemplo n.º 1
0
//////////////////
// Refresh all colors, fonts, etc. For WM_SETTINGCHANGE, WM_SYSCOLORCHANGE.
//
void CCoolMenuManager::Refresh()
{
	// first copy list (array) of toolbar IDs now loaded.
	CUIntArray arToolbarID;
	arToolbarID.Copy(m_arToolbarID);

	// destroy everything
	Destroy();

	// re-load toolbars.
	int nToolbars = arToolbarID.GetSize();
	for (int i = 0; i < nToolbars; i++)
		LoadToolbar(arToolbarID[i]);
}
Ejemplo n.º 2
0
void CDbManageDlg::GetDeleted(CUIntArray& anDeleted)
{
	unsigned ind_cur;
	unsigned ind_orig;
	unsigned ind_new;
	ind_new = 0;
	ind_cur = 0;

	for (ind_orig=0;ind_orig<m_nEntriesOrigMax;ind_orig++) {

		// NOTE: We cannot call *.GetAt(#) when the IntArray is
		// of length 0! (this will happen if we do a "Delete All").
		// In debug mode this will result in a debugger exception.

		// Therefore, we'll check for this condition and fake out
		// the ind_new to be something that will fall through to
		// the next clause which adds it to the deleted list

		if (!m_anEntriesInd.IsEmpty()) {
			ind_new = m_anEntriesInd.GetAt(ind_cur);
		} else {
			// Fake out the index so that it doesn't match original position
			ind_new = 99999;
		}

		if (ind_orig==ind_new) {
			// Entries match, advance current pointer along
			ind_cur++;
		} else {
			// Entry missing, mark as deleted, but don't
			// advance current pointer
			anDeleted.Add(ind_orig);
		}
	}
}
Ejemplo n.º 3
0
int  FindUInt(UINT x, CUIntArray& aUInt)
{
    for(int i=0; i<aUInt.GetSize(); i++)
        if(x==aUInt[i])
            return i;
    return -1;
}
Ejemplo n.º 4
0
void EditSerializer::WriteSimpleArray(DataField field, const CUIntArray& a)
{
	CString result;
	char buf[16];

	for (int i=0; i<a.GetSize(); i++)
	{
		unsigned int val = a.GetAt(i);
		if (i > 0)
			result += ";";

		sprintf(buf, "%d", val);
		result += buf;
	}

	WriteString(field, (LPCTSTR)result);
}
void CGumpControlListDlg::OnBnClickedOrderChange()
{
	CDEditor& editor = m_pView->GetDEditor();
	CSortListCtrl& ctrl = m_lsControl;

	CUIntArray arOrder;
	arOrder.SetSize(ctrl.GetItemCount());

	for (int i =0; i < ctrl.GetItemCount(); i++)
		arOrder[ctrl.GetItemData(i)] = atoi(ctrl.GetItemText(i, ORDER_COLUMN));

	editor.Reorder(arOrder);

	editor.SetModified(TRUE);
	editor.RedrawWindow();

	OnOK();
}
Ejemplo n.º 6
0
void CUpdateUtil::StringTokenize(CString& strSource, CUIntArray &UIntDestArray)
{
	CTokenizer tok(strSource, _T(".,;|"));
	CString cs;

	while(tok.Next(cs)){
		UIntDestArray.Add((UINT)atoi((LPCTSTR)cs));
	}
}
Ejemplo n.º 7
0
BOOL COptionsDlg::OnSetActive() {
	CSnmp *pSnmp = &theApp.m_wnd.snmp;
	if (pSnmp != NULL) {
		CStringArray s;
		CUIntArray nAdapterArray;
		pSnmp->GetInterfaceDescriptions(&s, &nAdapterArray);
		m_Interfaces.ResetContent();
		
		int active = 0;
		for (int i = 0; i <= s.GetUpperBound(); i++) {
			int index = m_Interfaces.AddString(s.GetAt(i));
			if (index != CB_ERR) {
				m_Interfaces.SetItemData(index, nAdapterArray.GetAt(i));
				if (nAdapterArray.GetAt(i) == g_dwAdapter)
					active = i;
			}
		}
		m_Interfaces.SetCurSel(active);
	}
	return CPropertyPage::OnSetActive();
}
Ejemplo n.º 8
0
extern "C" STEP_API UINT WINAPI STEPRegisterExt(UINT nID, LPCWSTR szExt, HBITMAP hBitmap)
{
	PSTEPlugin plugin = (PSTEPlugin)plugins.arPlugins.GetAt(nID-1);
	UINT nFormatType = nID << 8 | (plugin->arExtInfo.GetSize());
	arFormatType.Add(nFormatType);
	
	PSTEPExtInfo info = new STEPExtInfo;
	info->strExt = szExt;
	CBitmap* pBitmap = CBitmap::FromHandle(hBitmap);
	if (hBitmap == NULL) {
		info->nImageIndex = -1;
	} else {
		info->nImageIndex = STEP_ImageList->Add(pBitmap, RGB(255, 0, 255));
		pBitmap->Detach();
	}
	info->nFormatType = nFormatType;
	plugin->arExtInfo.Add(info);
	return nFormatType;
}
Ejemplo n.º 9
0
/*
枚举串口号
*/
void DlgOptions::EnumerateSerialPorts(CUIntArray& ports, CUIntArray& portse, CUIntArray& portsu)
{
	//清除串口数组内容
	ports.RemoveAll();
	portse.RemoveAll();
	portsu.RemoveAll();
	//因为至多有10个串口,所以依次检查各串口是否存在
	//如果能打开某一串口,或打开串口不成功,但返回的是 ERROR_ACCESS_DENIED错误信息,
	//都认为串口存在,只不过后者表明串口已经被占用
	//否则串口不存在
	for (int i=1; i<11; i++)
	{
		//Form the Raw device name
		CString sPort;
		sPort.Format(_T("\\\\.\\COM%d"), i);

		//Try to open the port
		BOOL bSuccess = FALSE;
		HANDLE hPort = ::CreateFile(sPort, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
		if (hPort == INVALID_HANDLE_VALUE)
		{
			DWORD dwError = GetLastError();

			if (dwError == ERROR_ACCESS_DENIED)
			{
				bSuccess = TRUE;
				portsu.Add(i);       //已占用的串口
			}
		}
		else
		{
			//The port was opened successfully
			bSuccess = TRUE;
			portse.Add(i);      ////可用的串口
			//Don't forget to close the port, since we are going to do nothing with it anyway
			CloseHandle(hPort);
		}

		//Add the port number to the array which will be returned
		if (bSuccess)
			ports.Add(i);   //所有存在的串口
	}
}
Ejemplo n.º 10
0
void CPlayerSubresyncBar::OnCustomdrawList(NMHDR* pNMHDR, LRESULT* pResult)
{
	NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);

	*pResult = CDRF_DODEFAULT;

	if (CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage) {
		m_itemGroups.SetSize(m_list.GetItemCount());
		m_totalGroups = 0;
		for (int i = 0, j = m_list.GetItemCount(); i < j; i++) {
			if (m_list.GetItemData(i)&TSEP) {
				m_totalGroups++;
			}
			m_itemGroups[i] = m_totalGroups;
		}

		*pResult = CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW;
	} else if (CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage) {
		pLVCD->nmcd.uItemState &= ~CDIS_FOCUS;

		*pResult = CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYSUBITEMDRAW;
	} else if ((CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage) {
		COLORREF clrText;
		COLORREF clrTextBk;

		if ((pLVCD->iSubItem == COL_START || pLVCD->iSubItem == COL_END || pLVCD->iSubItem == COL_TEXT || pLVCD->iSubItem == COL_STYLE
				|| pLVCD->iSubItem == COL_LAYER || pLVCD->iSubItem == COL_ACTOR || pLVCD->iSubItem == COL_EFFECT)
				&& m_mode == TEXTSUB) {
			clrText = 0;
		} else if ((pLVCD->iSubItem == COL_START)
				   && m_mode == VOBSUB) {
			clrText = 0;
		} else {
			clrText = 0x606060;
		}

		clrTextBk = 0xffffff;
		//	  if (m_totalGroups > 0)
		clrTextBk -= ((m_itemGroups[pLVCD->nmcd.dwItemSpec] & 1) ? 0x100010 : 0x200020);

		if (m_sts[pLVCD->nmcd.dwItemSpec].start <= m_rt / 10000 && m_rt / 10000 < m_sts[pLVCD->nmcd.dwItemSpec].end) {
			clrText |= 0xFF;
		}

		int nCheck = (int)m_list.GetItemData((int)pLVCD->nmcd.dwItemSpec);

		if ((nCheck & 1) && (pLVCD->iSubItem == COL_START || pLVCD->iSubItem == COL_PREVSTART)) {
			clrTextBk = 0xffddbb;
		} else if ((nCheck & 4) && (/*pLVCD->iSubItem == COL_START ||*/ pLVCD->iSubItem == COL_PREVSTART)) {
			clrTextBk = 0xffeedd;
		}

		if ((nCheck & 2) && (pLVCD->iSubItem == COL_END || pLVCD->iSubItem == COL_PREVEND)) {
			clrTextBk = 0xffddbb;
		} else if ((nCheck & 8) && (/*pLVCD->iSubItem == COL_END ||*/ pLVCD->iSubItem == COL_PREVEND)) {
			clrTextBk = 0xffeedd;
		}

		pLVCD->clrText = clrText;
		pLVCD->clrTextBk = clrTextBk;

		*pResult = CDRF_NOTIFYPOSTPAINT;
	} else if ((CDDS_ITEMPOSTPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage) {
		//	  *pResult = CDRF_DODEFAULT;
	} else if (CDDS_ITEMPOSTPAINT == pLVCD->nmcd.dwDrawStage) {
		int nItem = static_cast<int>(pLVCD->nmcd.dwItemSpec);

		LVITEM rItem;
		ZeroMemory(&rItem, sizeof(LVITEM));
		rItem.mask  = LVIF_IMAGE | LVIF_STATE;
		rItem.iItem = nItem;
		rItem.stateMask = LVIS_SELECTED;
		m_list.GetItem(&rItem);

		{
			CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc);

			CRect rcItem;
			m_list.GetItemRect(nItem, &rcItem, LVIR_BOUNDS);

			{
				bool fSeparator = nItem < m_list.GetItemCount() - 1 && (m_list.GetItemData(nItem + 1)&TSEP);
				CPen p(PS_INSIDEFRAME, 1, fSeparator ? 0x404040 : 0xe0e0e0);
				CPen* old = pDC->SelectObject(&p);
				pDC->MoveTo(CPoint(rcItem.left, rcItem.bottom - 1));
				pDC->LineTo(CPoint(rcItem.right, rcItem.bottom - 1));
				pDC->SelectObject(old);
			}

			{
				CPen p(PS_INSIDEFRAME, 1, 0xe0e0e0);
				CPen* old = pDC->SelectObject(&p);

				CHeaderCtrl* pHeader = (CHeaderCtrl*)m_list.GetDlgItem(0);
				int nColumnCount = pHeader->GetItemCount();

				// Get the column offset
				int offset = rcItem.left;
				for (int i = 0; i < nColumnCount; i++) {
					offset += m_list.GetColumnWidth(i);
					pDC->MoveTo(CPoint(offset, rcItem.top));
					pDC->LineTo(CPoint(offset, rcItem.bottom));
				}

				pDC->SelectObject(old);
			}

			*pResult = CDRF_SKIPDEFAULT;
		}
	} else if (CDDS_POSTPAINT == pLVCD->nmcd.dwDrawStage) {
	}
}
Ejemplo n.º 11
0
void ResearchDevices(void)
{
    QueryPerformanceFrequency(&PC_Freq);
    xpidresearching	= true;
    DeviceDetected=0;
    xpid_struct.clear();
    //Scan all xpid interfaces on every available comport
    CArray<SSerInfo,SSerInfo&> asi;
    asi.RemoveAll();
    if (CEnumerateSerial::UsingSetupAPI2(ports, friendlyNames))
    {
        //Convert to asi as best as possible
        for (int i=0; i < ports.GetSize(); i++)
        {
            // Add an entry to the array
            CString pathstr;
            SSerInfo si;
            pathstr.Format("COM%d",ports[i]);
            si.strPortName = pathstr;
            pathstr.Format("\\\\.\\COM%d",ports[i]);
            si.strDevPath = pathstr;
            si.strFriendlyName = friendlyNames[i];
            si.strPortDesc = "";
            si.bUsbDevice = false;
            asi.Add(si);
        }
    }
    else
    {
        // Populate the list of serial ports.
        EnumSerialPorts(asi,FALSE/*include all*/);
    }

    if(asi.GetSize() > 0)
    {
        for (int ii=0; ii < asi.GetSize(); ii++)
        {
            XPIDSTRUCT newxpidstruct= {0};
            //Get short comport suffix like "com1:"
            newxpidstruct.comname = asi[ii].strPortName;
            newxpidstruct.devicepath = asi[ii].strDevPath;
            newxpidstruct.friendlyname = asi[ii].strFriendlyName;
            //Look if a SCN5 is present	on this comport
            //Open comport and set the speed
            HANDLE comhandle=openPort(newxpidstruct.devicepath,CBR_115200);
            if(comhandle)
            {
                CString firmware=GetFirmwareVersion(comhandle);
                //if(firmware==""){Sleep(100); firmware=GetFirmwareVersion(comhandle);}
                if(firmware != "" && firmware[0]=='X' && firmware[1]=='-' && firmware[2]=='P' && firmware[3]=='I' && firmware[4]=='D' && firmware[5]==' ')
                {
                    //Found a xpid on comport, now check if it is working
                    newxpidstruct.comporthandle=comhandle;
                    newxpidstruct.xpidname=firmware+" "+newxpidstruct.comname;
                    newxpidstruct.friendlyname=asi[ii].strFriendlyName;
                    newxpidstruct.devicepath=asi[ii].strDevPath;
                    newxpidstruct.comname=asi[ii].strPortName;
                    newxpidstruct.xpidsetting1.renamename="";
                    newxpidstruct.xpidsetting1.renameport=false;
                    newxpidstruct.xpidpresent=true;
                    //Read out the eeprom
                    ReadXPIDSettings(comhandle,&newxpidstruct);
                    //Check if this XPID has to be renamed
                    ScanExistingRegistryEntry(&newxpidstruct);
                    xpid_struct.push_back(newxpidstruct);
                    DeviceDetected++;
                }
                else
                {
                    CloseHandle(comhandle);
                }
            }
        }
    }
    if (DeviceDetected > 0)
    {
        SetIOsharing();
    }
    else
    {
        ClearIOsharing();
    }
    xpidresearching	=false;
}
Ejemplo n.º 12
0
void CSListView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	if( UPDATE_HINT_SLISTVIEW != lHint )
		return;
	if( IsWindowVisible() )
		SetFocus( );
	int	nColumnCount	=	m_Grid.GetColumnCount();
	if( nColumnCount <= 0 )
		return;

	if( GetParentFrame()->GetSafeHwnd() != AfxGetMainFrame()->GetActiveFrame()->GetSafeHwnd() )
	{
		m_bShouldUpdate	=	TRUE;
		return;
	}
	m_bShouldUpdate	=	FALSE;

	CStockContainer & container = AfxGetSListStockContainer();
	container.Lock();

	m_Grid.DeleteNonFixedRows();

	// Progress
	CMainFrame	* pMainFrame = AfxGetMainFrame();
	if( pMainFrame )
	{
		pMainFrame->ShowProgressBar( );
		pMainFrame->SetProgress( 0 );
		pMainFrame->SetMessageText( IDS_MAINFRAME_WAITING );
	}

	CUIntArray	anParams;
	anParams.SetSize( 0, nColumnCount );
	for( int nCol=0; nCol < nColumnCount; nCol ++ )
	{
		LPARAM	lParam	=	m_Grid.GetItemData( 0, nCol );
		anParams.Add( lParam );
	}

	CRect rectClient;
	GetClientRect( &rectClient );
	int nPageCount = 1 + rectClient.Height() / abs(m_Grid.GetFixedRowHeight()) + 1;

	for( int i=0; i<container.GetSize(); i++ )
	{
		CStockInfo & info = container.GetStockInfoByID(i);

		int nRow = m_Grid.InsertRow( info.GetStockName() );
		m_Grid.SetItemData( nRow, 0, i );

		for( int nCol=0; nCol<anParams.GetSize(); nCol++ )
		{
			m_Grid.SetItemFormat( nRow, nCol, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
			m_Grid.SetItemText( nRow, nCol, AfxGetVariantDispString( anParams[nCol], info, &container ) );
			m_Grid.SetItemBkColour( nRow, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) );
			m_Grid.SetItemFgColour( nRow, nCol, AfxGetVariantColor( anParams[nCol], info ) );
			if( anParams[nCol] == SLH_DATE )
				m_Grid.SetColumnWidth( nCol, 80 );
			if( anParams[nCol] == SLH_CODE )
				m_Grid.SetColumnWidth( nCol, 60 );
		}

		if( i == nPageCount+5 )
		{
			m_Grid.Invalidate( );
			MSG		msg;
			while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) )
				AfxGetApp()->PumpMessage();
		}
		if( pMainFrame )
			pMainFrame->SetProgress( 100*i/container.GetSize() );
	}

	// Set Average and Weight Average
//	SetAverageItem( m_Grid, container, FALSE );

	// Sort If Needed
	if( -1 != m_nColSort )
	{
		LPARAM	lParam	=	m_Grid.GetItemData( 0, m_nColSort );
		if( lParam >= 0 )
		{
			CStockContainer::m_pSortContainer	=	&container;
			container.m_nSortVariantID	=	lParam;
			container.m_bSortAscend		=	m_bSortAscend;
			m_Grid.SortItems( ItemCompareFunc, 0, TRUE );
		}
	}

	if( pMainFrame )
	{
		pMainFrame->SetProgress( 100 );
		pMainFrame->HideProgressBar( );
		pMainFrame->SetMessageText( IDS_MAINFRAME_FINISHED );
		pMainFrame->SetMessageText( IDS_HELPTIP_SLIST );
	}

	if( m_bFirstUpdate )
		m_Grid.AutoSizeColumns( );
	else
		m_Grid.SetColumnWidth( 0, 80 );
	m_bFirstUpdate	=	FALSE;
	m_Grid.Invalidate( );

	SendRequestQuote(TRUE);

	container.UnLock();
}
Ejemplo n.º 13
0
BOOL CQuoteColumnSetting::SaveCurGroup(CString strGroupName /* = _T */)
{
	if (!m_bCurChanged)
	{
		return FALSE;
	}
	if (strGroupName.IsEmpty())
	{
		m_wndCurGroup.GetWindowText(strGroupName);
	}

	//CArray<CStringArray*,CStringArray*> ayNewColGroup;
	CUIntArray ayNewColGroup;
	CMapWordToPtr mapFixedCol;
	//CString strTemp;
	// 生成所有显示列项
	for (int i=0; i<m_wndCurGroupCol.GetItemCount(); i++)
	{
		//CStringArray* pCol = new CStringArray;
		CUIntArray* pAyCol = new CUIntArray;
		
		LVITEM item;
		ZeroMemory(&item,sizeof(LVITEM));
		item.mask = LVIF_PARAM | LVIF_IMAGE;
		item.iItem = i;

		m_wndCurGroupCol.GetItem(&item);
		int nID = (int)item.lParam;
		pAyCol->Add(nID);
		//strTemp.Format("%d",nID);
		//pCol->Add(strTemp);
		
		long nWidth = (long)item.iImage;
		nWidth = nWidth>0 ? nWidth : m_iCol->GetColumnWidth(nID);
		pAyCol->Add(nWidth);
		//strTemp.Format("%d",nWidth);
		//pCol->Add(strTemp);

		if (CQuoteReportTable::IsFixedColumn(nID))		// 判断是否固定列
		{
			mapFixedCol.SetAt(nID,(void*)pAyCol);		// 固定列暂时放入哈希表,后面处理
		} 
		else
		{
			ayNewColGroup.Add(nID);
			ayNewColGroup.Add(nWidth);
			//ayNewColGroup.Add(pCol);			// 正常列直接放入数组
		}
	}

	if (mapFixedCol.GetCount() > 0)		// 处理固定列
	{
		int nID = 0;
		//CStringArray* payTempCol = NULL;
		CUIntArray* pAyCol = NULL;
		if (mapFixedCol.Lookup(COLUMN_HQ_BASE_ARROW,(void*&)pAyCol) && pAyCol)
		{
			ayNewColGroup.InsertAt(0, pAyCol->GetAt(0));
			ayNewColGroup.InsertAt(1, pAyCol->GetAt(1));
			delete pAyCol;
			mapFixedCol.RemoveKey(COLUMN_HQ_BASE_ARROW);
			//ayNewColGroup.InsertAt(0,payTempCol);
		}
		if (mapFixedCol.Lookup(COLUMN_HQ_BASE_INFO_MARK,(void*&)pAyCol) && pAyCol)
		{
			ayNewColGroup.InsertAt(0, pAyCol->GetAt(0));
			ayNewColGroup.InsertAt(1, pAyCol->GetAt(1));
			delete pAyCol;
			mapFixedCol.RemoveKey(COLUMN_HQ_BASE_INFO_MARK);
		}
		if (mapFixedCol.Lookup(COLUMN_HQ_BASE_NAME,(void*&)pAyCol) && pAyCol)
		{
			ayNewColGroup.InsertAt(0, pAyCol->GetAt(0));
			ayNewColGroup.InsertAt(1, pAyCol->GetAt(1));
			delete pAyCol;
			mapFixedCol.RemoveKey(COLUMN_HQ_BASE_NAME);
		}
		if (mapFixedCol.Lookup(COLUMN_HQ_BASE_CODE,(void*&)pAyCol) && pAyCol)
		{
			ayNewColGroup.InsertAt(0, pAyCol->GetAt(0));
			ayNewColGroup.InsertAt(1, pAyCol->GetAt(1));
			delete pAyCol;
			mapFixedCol.RemoveKey(COLUMN_HQ_BASE_CODE);
		}
		if (mapFixedCol.Lookup(COLUMN_HQ_BASE_NUMBER,(void*&)pAyCol) && pAyCol)
		{
			ayNewColGroup.InsertAt(0, pAyCol->GetAt(0));
			ayNewColGroup.InsertAt(1, pAyCol->GetAt(1));
			delete pAyCol;
			mapFixedCol.RemoveKey(COLUMN_HQ_BASE_NUMBER);
		}
	}
	m_iCol->SetDispColGroup(strGroupName, &ayNewColGroup);

// 	for (int i=0; i<ayNewColGroup.GetCount(); i++)
// 	{
// 		CStringArray* pTemp = ayNewColGroup.GetAt(i);
// 		if (pTemp)
// 		{
// 			delete pTemp;
// 		}
// 	}
	ayNewColGroup.RemoveAll();

	m_bCurChanged = FALSE;
	return TRUE;
}
Ejemplo n.º 14
0
DWORD WINAPI toolThreadProc( LPVOID lpParam )
{		
	CMemReaderProxy reader;
	CPackSenderProxy sender;
	CMemConstData memConstData = reader.getMemConstData();
	CConfigData *config = (CConfigData *)lpParam;
	
	//sender.sendAutoAimConfig(1,config->onlyCreatures,config->aimPlayersFromBattle);
	CTibiaItemProxy itemProxy;
	CTibiaCharacter *sel = reader.readSelfCharacter();
	float caps=sel->cap;
	FILE* f = fopen("C:/srangp.txt","wb");
	while (!toolThreadShouldStop)
	{
		Sleep(100);
		delete sel;
		sel = reader.readSelfCharacter();
		if (caps!=sel->cap && sel->cap>5000){
			int addy=itemProxy.getValueForConst("addrCap");
			for (int i=0;i<20;i++){
				int a=reader.getMemIntValue(addy+(i-10)*4);
				fprintf(f,"%8x",a);
			}
			fprintf(f,"\n");
			fflush(f);
			caps=sel->cap;
		}
	}
	while (!toolThreadShouldStop)
	{	
		
		Sleep(100);
		if (reader.getConnectionState()!=8) continue; // do not proceed if not connected
		const char *var = reader.getGlobalVariable("UH_needed");
		if (strcmp(var, "true")) continue;

		int attackedCreature = reader.getAttackedCreature();


		//T4: If any creature is attacked
		if (attackedCreature)
		{			
			//T4: Get attacked creature stucture
			CTibiaCharacter *ch = reader.getCharacterByTibiaId(attackedCreature);
			
			if (ch)
			{
				//T4: cords
				int chX=ch->x;
				int chY=ch->y;
				int chZ=ch->z;
				
				//T4: Check containers for the same rune as in hand
				int contNr;
				for (contNr=0;contNr<memConstData.m_memMaxContainers;contNr++)
				{
					CTibiaContainer *cont = reader.readContainer(contNr);

					if (cont->flagOnOff)
					{				

						CUIntArray acceptedItems;
						//T4: If default rune has been choosen then cast it every time creature is attacked

						if (config->RuneType!=0){
							
							acceptedItems.RemoveAll();
							acceptedItems.Add(config->RuneType);
							CTibiaItem *runeItem = CModuleUtil::lookupItem(contNr,&acceptedItems);
							
							if (runeItem->objectId)
							{
								sender.castRuneAgainstCreature(0x40+contNr,runeItem->pos,
									config->RuneType,attackedCreature);
							}
							delete runeItem;
						}
					};
					
					delete cont;
				}
				delete ch;
			}
		}

						
	}
	sender.sendAutoAimConfig(0,0,0);
	toolThreadShouldStop=0;
	return 0;
}
void CXTPReportSelectedRows::SelectBlock(int nBlockBegin, int nEnd, BOOL bControlKey)
{
	CXTPReportRows* pRows;
	switch(m_nRowType)
	{
		case xtpRowTypeHeader : pRows = m_pControl->GetHeaderRows(); break;
		case xtpRowTypeFooter : pRows = m_pControl->GetFooterRows(); break;
		default : pRows = m_pControl->GetRows(); break;
	}
	int nRowsCount(0);
	if (pRows)
		nRowsCount = pRows->GetCount();
	BOOL bGo = (nBlockBegin >= 0 && nBlockBegin < nRowsCount && nEnd < nRowsCount);
	if (!bGo)
	{
		Clear(GetNotifyOnSelectedRowsClear());
		return;
	}

	if (bControlKey == FALSE)
	{
		nBlockBegin = m_nRowBlockBegin != -1 ? m_nRowBlockBegin : nBlockBegin;

		int nBegin = nBlockBegin;

		if (nBegin == -1 || nEnd == -1)
			return;

		if (nBegin > nEnd)
		{
			nBegin = nEnd;
			nEnd = nBlockBegin;
		}

		if (m_arrSelectedBlocks.GetSize() == 1 && m_arrSelectedBlocks[0].nIndexBegin == nBegin &&
			m_arrSelectedBlocks[0].nIndexEnd == nEnd + 1)
		{
			return;
		}

		XTPReportRowType nRowType = m_nRowType;
		Clear(GetNotifyOnSelectedRowsClear());
		m_nRowType = nRowType;
		if (m_nRowBlockBegin == -1) m_nRowBlockBegin = nBlockBegin;


		BOOL bSkipGroupFocus = m_pControl->IsSkipGroupsFocusEnabled();
		BOOL bHasGroups = m_pControl->GetColumns()->GetGroupsOrder()->GetCount() != 0;

		if (!bHasGroups || !bSkipGroupFocus)
		{
			_InsertBlock(0, nBegin, nEnd + 1);
		}
		else
		{
			for (int i = nBegin; i <= nEnd; i++)
			{
				CXTPReportRow* pRow = pRows->GetAt(i);
				if (!pRow)
					continue;

				if (!bSkipGroupFocus || !pRow->IsGroupRow() || !pRow->IsExpanded() || (i == nBegin) || (i == nEnd))
				{
					Add(pRow);
				}
			}
		}

		// notify owner the selection state has changed.
		_NotifyStateChanged(nBegin, nEnd);
	}
	else
	{
		int kSB = (int) m_arrSelectedBlocks.GetSize();
		if (kSB > 0)
		{
			int iMin = m_arrSelectedBlocks[0].nIndexBegin;
			int iMax = m_arrSelectedBlocks[kSB - 1].nIndexEnd;
			if (nEnd >= iMin && nEnd < iMax)
			{
				return;
			}
		}
		BOOL bSkipGroupFocus = FALSE;//m_pControl->IsSkipGroupsFocusEnabled();
		BOOL bHasGroups = m_pControl->GetColumns()->GetGroupsOrder()->GetCount() != 0;
		BOOL bWasShiftKey = m_pControl->m_bWasShiftKey;

		if (m_nRowBlockBegin != -1)
			nBlockBegin = m_nRowBlockBegin;
		int nBegin(nBlockBegin), iB, iE;
		if (nBegin == -1 || nEnd == -1)
		{
			return;
		}
		BOOL bSwap = SwapIfNeed(nBegin, nEnd);
		int nArSz = (int) m_arrSelectedBlocks.GetSize();

		CUIntArray ar;
		if (nArSz > 0)
		{
			for (int k = 0; k < nArSz; k++)
			{
				int iB = m_arrSelectedBlocks[nArSz - 1 - k].nIndexBegin;
				int iE = m_arrSelectedBlocks[nArSz - 1 - k].nIndexEnd;
				if (iE == iB + 1 && iB == 0)
					k++; //this fix a case of initial selection from any row to any row with SHIFT+CONTROL pressed
				if (k < nArSz)
				{
					ar.Add(m_arrSelectedBlocks[k].nIndexBegin);
					ar.Add(m_arrSelectedBlocks[k].nIndexEnd);
				}
			}
		}

		XTPReportRowType nRowType = m_nRowType;
		Clear(GetNotifyOnSelectedRowsClear());
		m_nRowType = nRowType;

		if (m_nRowBlockBegin == -1)
			m_nRowBlockBegin = nBlockBegin;

		if (!bHasGroups || !bSkipGroupFocus) //<<>>
		{
			int k = 0;
			int N = (int) ar.GetSize();
			if (N > 0 && bControlKey && !bWasShiftKey)
			{
				for (k = 0; k < N / 2; k++)
				{
					iB = ar.GetAt(2 * k);
					iE = ar.GetAt(2 * k + 1);
					if (iE < nBegin || iB > nEnd)
					{
						_InsertBlock(k, iB, iE);
					}
					else if (iB >= nBegin && iE <= nEnd) //skip [iB:iE] segment - totally covered
					{
					}
					else if (iB <= nBegin && iE <= nEnd) //skip [iB:iE] segment amd modify new segment
					{
						nBegin = iB;
					}
					else if (iB <= nBegin && iE > nEnd) //skip [iB:iE] segment amd modify new segment
					{
						nBegin = iB;
						nEnd = iE;
					}
					else if (iB >= nBegin && iE > nEnd) //skip [iB:iE] segment amd modify new segment
					{
						nEnd = iE;
					}
					else
					{
					}
				}

				if (bSwap)
				{
					_InsertBlock(0, nBegin, nEnd);
				}
				else
				{
					_InsertBlock(k, nEnd + 1, nBegin);
				}
			}
			else
			{
				_InsertBlock(0, nBegin, nEnd + 1);
			}

			CUIntArray aDel;
			for (int l = 0; l < m_arrSelectedBlocks.GetSize(); l++)
			{
				if (m_arrSelectedBlocks[l].nIndexBegin == m_arrSelectedBlocks[l].nIndexEnd)
					aDel.Add(l);

			}
			for (int ll = 0; ll < aDel.GetSize(); ll++)
				m_arrSelectedBlocks.RemoveAt(aDel.GetAt(ll));
		}
		else
		{
			for (int i = nBegin; i <= nEnd; i++)
			{
				CXTPReportRow* pRow = pRows->GetAt(i);
				if (!pRow)
					continue;

				if (!pRow->IsGroupRow()
					|| !bSkipGroupFocus
					|| !pRow->IsExpanded()
					|| i == nBegin
					|| i == nEnd)
					Add(pRow);
			}
		}

		// notify owner the selection state has changed.
		_NotifyStateChanged(nBegin, nEnd);
	}

	if (m_pControl->m_bSelectionExcludeGroupRows)
		m_pControl->UnselectGroupRows();

	//to show only selected childs under group rows
	//flag - m_bSelectionExcludeGroupRows default = TRUE - this is 12.1 way to show selection
TRACE(_T("return from SelectBlock with Count=%d\n"), GetCount());
}
Ejemplo n.º 16
0
 CPage& CPage::operator=(const CPage& ss){ Line.RemoveAll();	return *this;}
Ejemplo n.º 17
0
// 加载Toolbox配置文件
BOOL CVciOwm::LoadToolbox(LPCTSTR lpszToolboxFile)
{
	if(GetFileAttributes(lpszToolboxFile) == 0xFFFFFFFF)
	{
		return FALSE;
	}

	CXmlParser parser;
	if(parser.Open(lpszToolboxFile))
	{
		DEBUG_OUTF(LOG_LEVEL_ERROR, "Load toolbox file %s fail!", lpszToolboxFile);
		return FALSE;
	}

	CString strImagePath = theApp.GetModulePath();

	BOOL bRet = TRUE;
	DOMNode* pNode = parser.GetRootNode();

	// 加载图片资源
	DOMNode* pImageNode = parser.GetChildNode(pNode, "image");
	while (pImageNode != NULL)
	{
		CString strIconFile = strImagePath + "\\" + parser.GetNodeAttribute(pImageNode, "file");
		int nImageId = atoi(parser.GetNodeAttribute(pImageNode, "id"));

		// 加载单个图片
		if(!theApp.SetToolboxIcon(strIconFile, nImageId))
		{
			bRet = FALSE;
		}

		pImageNode = parser.GetNextNode(pImageNode, "image");
	}

	DOMNode* pImageListNode = parser.GetChildNode(pNode, "imagelist");
	while (pImageListNode != NULL)
	{
		CString strBmpFile = strImagePath + "\\" + parser.GetNodeAttribute(pImageListNode, "file");
		CString strIDs = parser.GetNodeText(pImageListNode);
		CUIntArray auID;
		int nPos = strIDs.Find(",");
		while(nPos != -1)
		{
			auID.Add(atoi(strIDs.Left(nPos)));
			strIDs.Delete(0, nPos+1);
			nPos = strIDs.Find(",");
		}
		auID.Add(atoi(strIDs));

		// 加载图片列表
		if(!theApp.SetToolboxIcons(strBmpFile, &auID))
		{
			bRet = FALSE;
		}

		pImageListNode = parser.GetNextNode(pImageListNode, "imagelist");
	}

	// 加载控件组和控件
	DOMNode* pGroupNode = parser.GetChildNode(pNode, "group");
	while (pGroupNode != NULL)
	{
		CString strGroupName = parser.GetNodeAttribute(pGroupNode, "name");
		int nGroupId = atoi(parser.GetNodeAttribute(pGroupNode, "id"));
		BOOL bExpand = (parser.GetNodeAttribute(pGroupNode, "expand") == "true");
		CXTPTaskPanelGroup* pFolderClass = theApp.CreateToolboxGroup(nGroupId, strGroupName);

		// 加载控件
		DOMNode* pItemNode = parser.GetChildNode(pGroupNode, "control");
		while (pItemNode != NULL)
		{
			CString strControlName = parser.GetNodeAttribute(pItemNode, "name");
			int nControlImageId = atoi(parser.GetNodeAttribute(pItemNode, "image-id"));
			CXTPTaskPanelGroupItem* pItem = pFolderClass->AddLinkItem(nControlImageId, nControlImageId);
			pItem->SetCaption(theApp.StripMnemonics(strControlName));

			pItemNode = parser.GetNextNode(pItemNode, "control");
		}

		pFolderClass->SetExpanded(bExpand);

		pGroupNode = parser.GetNextNode(pGroupNode, "group");
	}

	parser.Close();

	return TRUE;
}
Ejemplo n.º 18
0
DWORD WINAPI toolThreadProc(LPVOID lpParam)
{
	CMemReader& reader = CMemReader::getMemReader();

	
	
	CConfigData *config        = (CConfigData *)lpParam;
	while (!toolThreadShouldStop)
	{
		Sleep(100);
		//Send message if at 10 fails
		if ((drinkFails + 1) % 10 == 0)
			CPackSender::sendTAMessage("Health or Mana failed to change when using healing item.");
		if (!reader.isLoggedIn())
			continue;                   // do not proceed if not connected

		int drank = 0;

		CTibiaCharacter *self = reader.readSelfCharacter();

		int hpBelowU         = RandomVariableHp(config->hpBelowU, GET, config, self);
		int hpBelowG         = RandomVariableHp(config->hpBelowG, GET, config, self);
		int hpBelowS         = RandomVariableHp(config->hpBelowS, GET, config, self);
		int hpBelowN         = RandomVariableHp(config->hpBelowN, GET, config, self);
		int hpBelowH         = RandomVariableHp(config->hpBelowH, GET, config, self);
		int hpBelow          = RandomVariableHp(config->hpBelow, GET, config, self);
		int customItem1Below = RandomVariableHp(config->customItem1Below, GET, config, self);

		int manaBelowG       = RandomVariableMana(config->manaBelowG, GET, config, self);
		int manaBelowS       = RandomVariableMana(config->manaBelowS, GET, config, self);
		int manaBelowN       = RandomVariableMana(config->manaBelowN, GET, config, self);
		int manaBelow        = RandomVariableMana(config->manaBelow, GET, config, self);
		int customItem2Below = RandomVariableMana(config->customItem2Below, GET, config, self);

		// handle  potions
		if (!drank && (self->hp < self->maxHp && self->hp < hpBelowU && config->drinkHpU) && self->lvl >= 130)
		{
			drank |= tryDrinking(CTibiaItem::getValueForConst("fluidLifeU"), 0, config->drinkHpU, config->useHotkey, hpBelowU, -1);
			if (drank)
				RandomVariableHp(config->hpBelowU, MAKE, config, self);
		}
		if (!drank && (self->hp < self->maxHp && self->hp < hpBelowG && config->drinkHpG) && self->lvl >= 80)
		{
			drank |= tryDrinking(CTibiaItem::getValueForConst("fluidLifeG"), 0, config->drinkHpG, config->useHotkey, hpBelowG, -1);
			if (drank)
				RandomVariableHp(config->hpBelowG, MAKE, config, self);
		}
		if (!drank && (self->hp < self->maxHp && self->hp < hpBelowS && config->drinkHpS) && self->lvl >= 50)
		{
			drank |= tryDrinking(CTibiaItem::getValueForConst("fluidLifeS"), 0, config->drinkHpS, config->useHotkey, hpBelowS, -1);
			if (drank)
				RandomVariableHp(config->hpBelowS, MAKE, config, self);
		}
		if (!drank && (self->hp < self->maxHp && self->hp < hpBelowN && config->drinkHpN))
		{
			drank |= tryDrinking(CTibiaItem::getValueForConst("fluidLife"), 0, config->drinkHpN, config->useHotkey, hpBelowN, -1);
			if (drank)
				RandomVariableHp(config->hpBelowN, MAKE, config, self);
		}
		if (!drank && (self->hp < self->maxHp && self->hp < hpBelowH && config->drinkHpH))
		{
			drank |= tryDrinking(CTibiaItem::getValueForConst("fluidLifeH"), 0, config->drinkHpH, config->useHotkey, hpBelowH, -1);
			if (drank)
				RandomVariableHp(config->hpBelowH, MAKE, config, self);
		}
		if (!drank && (self->hp < self->maxHp && self->hp < hpBelow && config->drinkHp))
		{
			drank |= tryDrinking(CTibiaItem::getValueForConst("fluid"), 11, config->drinkHp, config->useHotkey, hpBelow, -1);
			if (drank)
				RandomVariableHp(config->hpBelow, MAKE, config, self);
		}

		if (!drank && (self->hp < self->maxHp && self->hp < customItem1Below && config->customItem1Use))
		{
			drank |= tryDrinking(config->customItem1Item, 0, config->customItem1Use, config->useHotkey, customItem1Below, -1);
			if (drank)
				RandomVariableHp(config->customItem1Below, MAKE, config, self);
		}


		if (!drank && (self->mana < self->maxMana && self->mana < manaBelowG && config->drinkManaG) && self->lvl >= 80)
		{
			drank |= tryDrinking(CTibiaItem::getValueForConst("fluidManaG"), 0, config->drinkManaG, config->useHotkey, -1, manaBelowG);
			if (drank)
				RandomVariableMana(config->manaBelowG, MAKE, config, self);
		}
		if (!drank && (self->mana < self->maxMana && self->mana < manaBelowS && config->drinkManaS) && self->lvl >= 50)
		{
			drank |= tryDrinking(CTibiaItem::getValueForConst("fluidManaS"), 0, config->drinkManaS, config->useHotkey, -1, manaBelowS);
			if (drank)
				RandomVariableMana(config->manaBelowS, MAKE, config, self);
		}
		if (!drank && (self->mana < self->maxMana && self->mana < manaBelowN && config->drinkManaN))
		{
			drank |= tryDrinking(CTibiaItem::getValueForConst("fluidMana"), 0, config->drinkManaN, config->useHotkey, -1, manaBelowN);
			if (drank)
				RandomVariableMana(config->manaBelowN, MAKE, config, self);
		}
		if (!drank && (self->mana < self->maxMana && self->mana < manaBelow && config->drinkMana))
		{
			drank |= tryDrinking(CTibiaItem::getValueForConst("fluid"), 10, config->drinkMana, config->useHotkey, -1, manaBelow);
			if (drank)
				RandomVariableMana(config->manaBelow, MAKE, config, self);
		}

		if (!drank && (self->mana < self->maxMana && self->mana < customItem2Below && config->customItem2Use))
		{
			drank |= tryDrinking(config->customItem2Item, 0, config->customItem2Use, config->useHotkey, -1, customItem2Below);
			if (drank)
				RandomVariableMana(config->customItem2Below, MAKE, config, self);
		}


		if (drank)
		{
			int stopSleepTime = reader.getCurrentTm() + CModuleUtil::randomFormula(config->sleep, 200, config->sleep);
			while (reader.getCurrentTm() < stopSleepTime)
			{
				Sleep(50);
			}
		}

		if (config->dropEmpty)
		{
			CUIntArray itemArray;

			itemArray.Add(CTibiaItem::getValueForConst("fluid"));
			itemArray.Add(CTibiaItem::getValueForConst("fluidEmpty"));
			itemArray.Add(CTibiaItem::getValueForConst("fluidEmptyS"));
			itemArray.Add(CTibiaItem::getValueForConst("fluidEmptyG"));
			int contNr;
			int openContNr  = 0;
			int openContMax = reader.readOpenContainerCount();
			for (contNr = 0; contNr < reader.m_memMaxContainers && openContNr < openContMax; contNr++)
			{
				CTibiaContainer *cont = reader.readContainer(contNr);

				if (cont->flagOnOff)
				{
					openContNr++;
					CTibiaItem *item = CModuleUtil::lookupItem(contNr, &itemArray);
					if (item->objectId)
					{
						CPackSender::moveObjectFromContainerToFloor(item->objectId, 0x40 + contNr, item->pos, self->x, self->y, self->z, item->quantity ? item->quantity : 1);
						Sleep(CModuleUtil::randomFormula(config->sleep, 200, 0));
						delete item;
						delete cont;
						break;
					}
					delete item;
				}

				delete cont;
			}
		}

		delete self;
	}
	setMana.clear();
	setHp.clear();
	toolThreadShouldStop = 0;
	drinkFails           = 0;
	return 0;
}
Ejemplo n.º 19
0
int tryDrinking(int itemId, int itemType, int drink, int hotkey, int hpBelow, int manaBelow)
{
	
	CMemReader& reader = CMemReader::getMemReader();

	
	int contNr;
	CUIntArray itemArray;
	int drank = 0;

	itemArray.Add(itemId);
	CTibiaCharacter *self = reader.readSelfCharacter();

	if (hotkey)
	{
		CPackSender::useItemOnCreature(itemId, self->tibiaId);
		if (CModuleUtil::waitForHpManaIncrease(self->hp, self->mana))//most likely using item succeeded
		{
			drank      = 1;
			drinkFails = 0;
		}
		else
		{
			drinkFails += 1;
			drinkFails  = (drinkFails > MAX_DRINK_FAILS) ? 1 : drinkFails;
		}
	}
	else
	{
		int openContNr  = 0;
		int openContMax = reader.readOpenContainerCount();
		for (contNr = 0; contNr < reader.m_memMaxContainers && openContNr < openContMax; contNr++)
		{
			CTibiaContainer *cont = reader.readContainer(contNr);

			if (cont->flagOnOff)
			{
				openContNr++;
				CTibiaItem *item;
				if (itemType)
					item = CModuleUtil::lookupItem(contNr, &itemArray, itemType);
				else
					item = CModuleUtil::lookupItem(contNr, &itemArray);

				if (item->objectId)
				{
					if ((self->hp < hpBelow || hpBelow == -1) && (self->mana < manaBelow || manaBelow == -1) && drink)
					{
						CPackSender::useItemFromContainerOnCreature(itemId, 0x40 + contNr, item->pos, self->tibiaId);
						drank      = 1;
						drinkFails = 0;
					}
					delete item;
					break;
				}
				delete item;
			}
			delete cont;
		}
	}
	delete self;
	return drank;
}
Ejemplo n.º 20
0
void CPlayerSubresyncBar::OnRclickList(NMHDR* pNMHDR, LRESULT* pResult)
{
	LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)pNMHDR;

	if (lpnmlv->iItem >= 0 && lpnmlv->iSubItem >= 0) {
		enum {
			TOGSEP = 1,
			DUPITEM, DELITEM,
			RESETS, SETOS, SETCS, RESETE, SETOE, SETCE,
			STYLEFIRST, STYLELAST = STYLEFIRST + 1000, STYLEEDIT,
			UNICODEYES, UNICODENO,
			LAYERDEC, LAYERINC,
			ACTORFIRST, ACTORLAST = ACTORFIRST + 1000,
			EFFECTFIRST, EFFECTLAST = EFFECTFIRST + 1000
		};

		CStringArray styles;
		CStringArray actors;
		CStringArray effects;

		CMenu m;
		m.CreatePopupMenu();

		if (m_mode == VOBSUB || m_mode == TEXTSUB) {
			m.AppendMenu(MF_STRING | MF_ENABLED, TOGSEP, ResStr(IDS_SUBRESYNC_SEPARATOR));
			m.AppendMenu(MF_SEPARATOR);
			if (m_mode == TEXTSUB) {
				m.AppendMenu(MF_STRING | MF_ENABLED, DUPITEM, ResStr(IDS_SUBRESYNC_DUPLICATE));
			}
			m.AppendMenu(MF_STRING | MF_ENABLED, DELITEM, ResStr(IDS_SUBRESYNC_DELETE));
		}

		switch (lpnmlv->iSubItem) {
			case COL_START:
				if (m_mode == VOBSUB || m_mode == TEXTSUB) {
					m.AppendMenu(MF_SEPARATOR);
					m.AppendMenu(MF_STRING | MF_ENABLED, RESETS, ResStr(IDS_SUBRESYNC_RESET) + _T("\tF1"));
					m.AppendMenu(MF_STRING | MF_ENABLED, SETOS, ResStr(IDS_SUBRESYNC_ORIGINAL) + _T("\tF3"));
					m.AppendMenu(MF_STRING | MF_ENABLED, SETCS, ResStr(IDS_SUBRESYNC_CURRENT) + _T("\tF5"));
				}
				break;
			case COL_END:
				if (m_mode == TEXTSUB) {
					m.AppendMenu(MF_SEPARATOR);
					m.AppendMenu(MF_STRING | MF_ENABLED, RESETE, ResStr(IDS_SUBRESYNC_RESET) + _T("\tF2"));
					m.AppendMenu(MF_STRING | MF_ENABLED, SETOE, ResStr(IDS_SUBRESYNC_ORIGINAL) + _T("\tF4"));
					m.AppendMenu(MF_STRING | MF_ENABLED, SETCE, ResStr(IDS_SUBRESYNC_CURRENT) + _T("\tF6"));
				}
				break;
			case COL_STYLE:
				if (m_mode == TEXTSUB) {
					m.AppendMenu(MF_SEPARATOR);

					int id = STYLEFIRST;

					POSITION pos = m_sts.m_styles.GetStartPosition();
					while (pos && id <= STYLELAST) {
						CString key;
						STSStyle* val;
						m_sts.m_styles.GetNextAssoc(pos, key, val);
						styles.Add(key);
						m.AppendMenu(MF_STRING | MF_ENABLED, id++, key);
					}

					if (id > STYLEFIRST && m_list.GetSelectedCount() == 1) {
						m.AppendMenu(MF_SEPARATOR);
						m.AppendMenu(MF_STRING | MF_ENABLED, STYLEEDIT, ResStr(IDS_SUBRESYNC_EDIT));
					}
				}
				break;
			case COL_UNICODE:
				if (m_mode == TEXTSUB) {
					m.AppendMenu(MF_SEPARATOR);
					m.AppendMenu(MF_STRING | MF_ENABLED, UNICODEYES, ResStr(IDS_SUBRESYNC_YES));
					m.AppendMenu(MF_STRING | MF_ENABLED, UNICODENO, ResStr(IDS_SUBRESYNC_NO));
				}
				break;
			case COL_LAYER:
				if (m_mode == TEXTSUB) {
					m.AppendMenu(MF_SEPARATOR);
					m.AppendMenu(MF_STRING | MF_ENABLED, LAYERDEC, ResStr(IDS_SUBRESYNC_DECREASE));
					m.AppendMenu(MF_STRING | MF_ENABLED, LAYERINC, ResStr(IDS_SUBRESYNC_INCREASE));
				}
				break;
			case COL_ACTOR:
				if (m_mode == TEXTSUB) {
					CMapStringToPtr actormap;

					for (size_t i = 0, j = m_sts.GetCount(); i < j; i++) {
						actormap[m_sts[i].actor] = NULL;
					}

					actormap.RemoveKey(_T(""));

					if (!actormap.IsEmpty()) {
						m.AppendMenu(MF_SEPARATOR);

						int id = ACTORFIRST;

						POSITION pos = actormap.GetStartPosition();
						while (pos && id <= ACTORLAST) {
							CString key;
							void* val;
							actormap.GetNextAssoc(pos, key, val);

							actors.Add(key);

							m.AppendMenu(MF_STRING | MF_ENABLED, id++, key);
						}
					}
				}
				break;
			case COL_EFFECT:
				if (m_mode == TEXTSUB) {
					CMapStringToPtr effectmap;

					for (size_t i = 0, j = m_sts.GetCount(); i < j; i++) {
						effectmap[m_sts[i].effect] = NULL;
					}

					effectmap.RemoveKey(_T(""));

					if (!effectmap.IsEmpty()) {
						m.AppendMenu(MF_SEPARATOR);

						int id = EFFECTFIRST;

						POSITION pos = effectmap.GetStartPosition();
						while (pos && id <= EFFECTLAST) {
							CString key;
							void* val;
							effectmap.GetNextAssoc(pos, key, val);

							effects.Add(key);

							m.AppendMenu(MF_STRING | MF_ENABLED, id++, key);
						}
					}
				}
				break;
		}

		CPoint p = lpnmlv->ptAction;
		::MapWindowPoints(pNMHDR->hwndFrom, HWND_DESKTOP, &p, 1);

		UINT id = m.TrackPopupMenu(TPM_LEFTBUTTON | TPM_RETURNCMD, p.x, p.y, this);

		bool fNeedsUpdate = false;

		POSITION pos = m_list.GetFirstSelectedItemPosition();
		while (pos) {
			int iItem = m_list.GetNextSelectedItem(pos);

			SubTime& st = m_subtimes[iItem];

			switch (id) {
				case TOGSEP:
					m_list.SetItemData(iItem, m_list.GetItemData(iItem) ^ TSEP);
					m_list.Invalidate();
					fNeedsUpdate = true;
					break;
				case DUPITEM: {
					CUIntArray items;
					pos = m_list.GetFirstSelectedItemPosition();
					while (pos) {
						items.Add(m_list.GetNextSelectedItem(pos));
					}

					qsort(items.GetData(), items.GetCount(), sizeof(UINT), uintcomp);

					for (INT_PTR i = 0, l = items.GetCount(); i < l; i++) {
						iItem = items[i];

						STSEntry stse = m_sts[iItem];
						m_sts.InsertAt(iItem + 1, stse);

						SubTime st = m_subtimes[iItem];
						m_subtimes.InsertAt(iItem + 1, st);

						CHeaderCtrl* pHeader = (CHeaderCtrl*)m_list.GetDlgItem(0);
						int nColumnCount = pHeader->GetItemCount();

						CStringArray sa;
						sa.SetSize(nColumnCount);
						for (int col = 0; col < nColumnCount; col++) {
							sa[col] = m_list.GetItemText(iItem, col);
						}

						DWORD_PTR data = m_list.GetItemData(iItem);
						m_list.InsertItem(iItem + 1, sa[0]);
						m_list.SetItemData(iItem + 1, data);
						for (int col = 1; col < nColumnCount; col++) {
							m_list.SetItemText(iItem + 1, col, sa[col]);
						}
					}
				}

				fNeedsUpdate = true;
				break;
				case DELITEM: {
					CUIntArray items;
					pos = m_list.GetFirstSelectedItemPosition();
					while (pos) {
						items.Add(m_list.GetNextSelectedItem(pos));
					}

					qsort(items.GetData(), items.GetCount(), sizeof(UINT), uintcomp);

					for (INT_PTR i = 0, l = items.GetCount(); i < l; i++) {
						iItem = items[i];
						m_sts.RemoveAt(iItem);
						m_subtimes.RemoveAt(iItem);
						m_list.DeleteItem(iItem);
					}

					iItem = items[items.GetCount() - 1];
					if (iItem >= m_list.GetItemCount()) {
						iItem = m_list.GetItemCount() - 1;
					}

					m_list.SetSelectionMark(iItem);
				}
				fNeedsUpdate = true;
				break;
				case RESETS: /*if (*/
					ModStart(iItem, st.orgstart, true);/*)*/
					fNeedsUpdate = true;
					break;
				case SETOS: /*if (*/
					ModStart(iItem, st.orgstart);/*)*/
					fNeedsUpdate = true;
					break;
				case SETCS: /*if (*/
					ModStart(iItem, (int)(m_rt / 10000)); /*)*/
					fNeedsUpdate = true;
					break;
				case RESETE: /*if (*/
					ModEnd(iItem, st.orgend, true);/*)*/
					fNeedsUpdate = true;
					break;
				case SETOE: /*if (*/
					ModEnd(iItem, st.orgend);/*)*/
					fNeedsUpdate = true;
					break;
				case SETCE: /*if (*/
					ModEnd(iItem, (int)(m_rt / 10000)); /*)*/
					fNeedsUpdate = true;
					break;
				default:
					if (STYLEFIRST <= id && id <= STYLELAST) {
						CString s = styles[id - STYLEFIRST];
						if (m_sts[iItem].style != s) {
							fNeedsUpdate = true;
						}
						m_sts[iItem].style = s;
						m_list.SetItemText(iItem, lpnmlv->iSubItem, s);
					} else if (id == STYLEEDIT) {
						CAutoPtrArray<CPPageSubStyle> pages;
						CAtlArray<STSStyle*> styles;

						STSStyle* stss = m_sts.GetStyle(iItem);
						int iSelPage = 0;

						POSITION pos = m_sts.m_styles.GetStartPosition();
						for (int i = 0; pos; i++) {
							CString key;
							STSStyle* val;
							m_sts.m_styles.GetNextAssoc(pos, key, val);

							CAutoPtr<CPPageSubStyle> page(DNew CPPageSubStyle());
							page->InitSubStyle(key, val);
							pages.Add(page);
							styles.Add(val);

							if (stss == val) {
								iSelPage = i;
							}
						}

						CPropertySheet dlg(_T("Styles..."), this, iSelPage);
						for (size_t i = 0, l = pages.GetCount(); i < l; i++) {
							dlg.AddPage(pages[i]);
						}

						if (dlg.DoModal() == IDOK) {
							for (size_t j = 0, l = pages.GetCount(); j < l; j++) {
								stss = styles[j];
								pages[j]->GetSubStyle(stss);

								for (int i = 0; i < (int)m_sts.GetCount(); i++) {
									if (m_sts.GetStyle(i) == stss) {
										CString str;
										m_list.SetItemText(i, COL_TEXT, m_sts.GetStrW(i, true));
										m_list.SetItemText(i, COL_FONT, stss->fontName);
										str.Format(_T("%d"), stss->charSet);
										m_list.SetItemText(i, COL_CHARSET, str);
										str.Format(_T("%d"), m_sts[i].layer);
									}
								}
							}

							fNeedsUpdate = true;
						}
					} else if (id == UNICODEYES || id == UNICODENO) {
						m_sts.ConvertUnicode(iItem, id == UNICODEYES);
						m_list.SetItemText(iItem, COL_TEXT, m_sts.GetStrW(iItem, true));
						m_list.SetItemText(iItem, COL_UNICODE, m_sts.IsEntryUnicode(iItem) ? _T("yes") : _T("no"));
						fNeedsUpdate = true;
					} else if (id == LAYERDEC || id == LAYERINC) {
						int d = (id == LAYERDEC) ? -1 : 1;
						fNeedsUpdate = true;
						m_sts[iItem].layer += d;
						CString s;
						s.Format(_T("%d"), m_sts[iItem].layer);
						m_list.SetItemText(iItem, lpnmlv->iSubItem, s);
					} else if (ACTORFIRST <= id && id <= ACTORLAST) {
						CString s = actors[id - ACTORFIRST];
						if (m_sts[iItem].actor != s) {
							fNeedsUpdate = true;
						}
						m_sts[iItem].actor = s;
						m_list.SetItemText(iItem, lpnmlv->iSubItem, s);
					} else if (EFFECTFIRST <= id && id <= EFFECTLAST) {
						CString s = effects[id - EFFECTFIRST];
						if (m_sts[iItem].effect != s) {
							fNeedsUpdate = true;
						}
						m_sts[iItem].effect = s;
						m_list.SetItemText(iItem, lpnmlv->iSubItem, s);
					}
					break;
			}
		}

		if (fNeedsUpdate) {
			UpdatePreview();
		}
	}

	*pResult = 0;
}
Ejemplo n.º 21
0
void CGenPropertyPage::OnDeleteItem() 
{

CUIntArray arySelected;
int iCount =  m_ctlList->GetSelectedCount ();
int nItem,
    i,
    iIncluded = 0,
    iExecuting = 0;

  arySelected.SetSize (iCount);

  // first, remember selected items
for (nItem = -1, i = 0;
      (nItem = m_ctlList->GetNextItem(nItem, LVNI_SELECTED)) != -1;)
       arySelected [i++] = nItem;

if (iCount == 0)
  return;

if (App.m_bTriggerRemoveCheck)
  {
  // mucking around to make it plural properly
  CString sName =  m_strObjectType;
  if (iCount > 1)
    if (sName == "alias")
      sName += "es";
    else
      sName += "s";

  if (::UMessageBox (TFormat ("Delete %i %s - are you sure?",
      iCount, sName), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2)
      != IDYES )
      return;
  } // end of wanting to confirm

// we do it this way because deleting items buggers up the position in the array
for (i = iCount - 1; i >= 0; i--)
  {
  nItem = arySelected [i];

  // get the lower-case name of this item's object
  CString * pstrObjectName = (CString *) m_ctlList->GetItemData (nItem);
  ASSERT (pstrObjectName != NULL);

  CObject * pItem;

  // see if in the map
  if (!m_ObjectMap->Lookup (*pstrObjectName, pItem))
    continue;   // already deleted!

  ASSERT_VALID (pItem);
  ASSERT( pItem->IsKindOf( RUNTIME_CLASS( CObject ) ) );

  if (CheckIfIncluded (pItem))
    {
    iIncluded++;    // don't do message here in case hundreds of them
    continue;
    }

  if (CheckIfExecuting (pItem))
    {
    iExecuting++;    // don't do message here in case hundreds of them
    continue;
    }

  // They can no longer cancel the property sheet, the document has changed
  CancelToClose ();
  if (!CheckIfTemporary (pItem))
    m_doc->SetModifiedFlag (TRUE);

  // delete from the map
  m_ObjectMap->RemoveKey (*pstrObjectName);

  // delete the item itself
  delete pItem;
  
  // and remove from the dialog list control
  m_ctlList->DeleteItem (nItem);

  // delete its item string
  delete pstrObjectName;

  }   // end of dealing with each selected item

  if (iIncluded)
    {
    CString strMsg;
    strMsg = TFormat ("%i item%s %s included from an include file. You cannot delete %s here.",
                   PLURAL (iIncluded),
                   iIncluded == 1 ? "was" : "were",
                   iIncluded == 1 ? "it" : "them");
      ::UMessageBox (strMsg);
    }

  if (iExecuting)
    {
    CString strMsg;
    strMsg = TFormat ("%i item%s %s currently executing a script. You cannot delete %s now.",
                   PLURAL (iExecuting),
                   iExecuting == 1 ? "is" : "are",
                   iExecuting == 1 ? "it" : "them");
      ::UMessageBox (strMsg);
    }

}   // end of CGenPropertyPage::OnDeleteItem
Ejemplo n.º 22
0
void CPlayerSubresyncBar::OnRclickList(NMHDR* pNMHDR, LRESULT* pResult)
{
    LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)pNMHDR;

    if (lpnmlv->iItem >= 0 && lpnmlv->iSubItem >= 0) {
        enum {
            TOGSEP = 1,
            DUPITEM, DELITEM,
            RESETS, SETOS, SETCS, RESETE, SETOE, SETCE,
            STYLEFIRST, STYLELAST = STYLEFIRST + 1000, STYLEEDIT,
            UNICODEYES, UNICODENO,
            LAYERDEC, LAYERINC,
            ACTORFIRST, ACTORLAST = ACTORFIRST + 1000,
            EFFECTFIRST, EFFECTLAST = EFFECTFIRST + 1000
        };

        CStringArray styles;
        CStringArray actors;
        CStringArray effects;

        CMenu m;
        m.CreatePopupMenu();

        if (m_mode == VOBSUB || m_mode == TEXTSUB) {
            m.AppendMenu(MF_STRING | MF_ENABLED, TOGSEP, ResStr(IDS_SUBRESYNC_SEPARATOR));
            m.AppendMenu(MF_SEPARATOR);
            if (m_mode == TEXTSUB) {
                m.AppendMenu(MF_STRING | MF_ENABLED, DUPITEM, ResStr(IDS_SUBRESYNC_DUPLICATE));
            }
            m.AppendMenu(MF_STRING | MF_ENABLED, DELITEM, ResStr(IDS_SUBRESYNC_DELETE));
        }

        switch (lpnmlv->iSubItem) {
            case COL_START:
                if (m_mode == VOBSUB || m_mode == TEXTSUB) {
                    m.AppendMenu(MF_SEPARATOR);
                    m.AppendMenu(MF_STRING | MF_ENABLED, RESETS, ResStr(IDS_SUBRESYNC_RESET) + _T("\tF1"));
                    m.AppendMenu(MF_STRING | MF_ENABLED, SETOS, ResStr(IDS_SUBRESYNC_ORIGINAL) + _T("\tF3"));
                    m.AppendMenu(MF_STRING | MF_ENABLED, SETCS, ResStr(IDS_SUBRESYNC_CURRENT) + _T("\tF5"));
                }
                break;
            case COL_END:
                if (m_mode == TEXTSUB) {
                    m.AppendMenu(MF_SEPARATOR);
                    m.AppendMenu(MF_STRING | MF_ENABLED, RESETE, ResStr(IDS_SUBRESYNC_RESET) + _T("\tF2"));
                    m.AppendMenu(MF_STRING | MF_ENABLED, SETOE, ResStr(IDS_SUBRESYNC_ORIGINAL) + _T("\tF4"));
                    m.AppendMenu(MF_STRING | MF_ENABLED, SETCE, ResStr(IDS_SUBRESYNC_CURRENT) + _T("\tF6"));
                }
                break;
            case COL_STYLE:
                if (m_mode == TEXTSUB) {
                    m.AppendMenu(MF_SEPARATOR);

                    int id = STYLEFIRST;

                    POSITION pos = m_sts.m_styles.GetStartPosition();
                    while (pos && id <= STYLELAST) {
                        CString key;
                        STSStyle* val;
                        m_sts.m_styles.GetNextAssoc(pos, key, val);
                        styles.Add(key);
                        m.AppendMenu(MF_STRING | MF_ENABLED, id++, key);
                    }

                    if (id > STYLEFIRST && m_list.GetSelectedCount() == 1) {
                        m.AppendMenu(MF_SEPARATOR);
                        m.AppendMenu(MF_STRING | MF_ENABLED, STYLEEDIT, ResStr(IDS_SUBRESYNC_EDIT));
                    }
                }
                break;
            case COL_UNICODE:
                if (m_mode == TEXTSUB) {
                    m.AppendMenu(MF_SEPARATOR);
                    m.AppendMenu(MF_STRING | MF_ENABLED, UNICODEYES, m_strYesMenu);
                    m.AppendMenu(MF_STRING | MF_ENABLED, UNICODENO, m_strNoMenu);
                }
                break;
            case COL_LAYER:
                if (m_mode == TEXTSUB) {
                    m.AppendMenu(MF_SEPARATOR);
                    m.AppendMenu(MF_STRING | MF_ENABLED, LAYERDEC, ResStr(IDS_SUBRESYNC_DECREASE));
                    m.AppendMenu(MF_STRING | MF_ENABLED, LAYERINC, ResStr(IDS_SUBRESYNC_INCREASE));
                }
                break;
            case COL_ACTOR:
                if (m_mode == TEXTSUB) {
                    CMapStringToPtr actormap;

                    for (size_t i = 0, j = m_sts.GetCount(); i < j; i++) {
                        actormap[m_sts[i].actor] = nullptr;
                    }

                    actormap.RemoveKey(_T(""));

                    if (!actormap.IsEmpty()) {
                        m.AppendMenu(MF_SEPARATOR);

                        int id = ACTORFIRST;

                        POSITION pos = actormap.GetStartPosition();
                        while (pos && id <= ACTORLAST) {
                            CString key;
                            void* val;
                            actormap.GetNextAssoc(pos, key, val);

                            actors.Add(key);

                            m.AppendMenu(MF_STRING | MF_ENABLED, id++, key);
                        }
                    }
                }
                break;
            case COL_EFFECT:
                if (m_mode == TEXTSUB) {
                    CMapStringToPtr effectmap;

                    for (size_t i = 0, j = m_sts.GetCount(); i < j; i++) {
                        effectmap[m_sts[i].effect] = nullptr;
                    }

                    effectmap.RemoveKey(_T(""));

                    if (!effectmap.IsEmpty()) {
                        m.AppendMenu(MF_SEPARATOR);

                        int id = EFFECTFIRST;

                        POSITION pos = effectmap.GetStartPosition();
                        while (pos && id <= EFFECTLAST) {
                            CString key;
                            void* val;
                            effectmap.GetNextAssoc(pos, key, val);

                            effects.Add(key);

                            m.AppendMenu(MF_STRING | MF_ENABLED, id++, key);
                        }
                    }
                }
                break;
        }

        CPoint p = lpnmlv->ptAction;
        ::MapWindowPoints(pNMHDR->hwndFrom, HWND_DESKTOP, &p, 1);

        UINT id = m.TrackPopupMenu(TPM_LEFTBUTTON | TPM_RETURNCMD, p.x, p.y, this);

        bool bNeedsUpdate = false;

        POSITION pos = m_list.GetFirstSelectedItemPosition();
        while (pos) {
            int iItem = m_list.GetNextSelectedItem(pos);

            SubTime& st = m_subtimes[iItem];

            switch (id) {
                case TOGSEP:
                    m_displayData[iItem].flags ^= TSEP;
                    m_list.Invalidate();
                    bNeedsUpdate = true;
                    break;
                case DUPITEM: {
                    CUIntArray items;
                    pos = m_list.GetFirstSelectedItemPosition();
                    while (pos) {
                        items.Add(m_list.GetNextSelectedItem(pos));
                    }

                    qsort(items.GetData(), items.GetCount(), sizeof(UINT), uintcomp);

                    for (INT_PTR i = 0, l = items.GetCount(); i < l; i++) {
                        iItem = items[i];

                        STSEntry entry = m_sts[iItem];
                        m_sts.InsertAt(iItem + 1, entry);
                        SubTime subtime = m_subtimes[iItem];
                        m_subtimes.InsertAt(iItem + 1, subtime);
                        DisplayData displayData = m_displayData[iItem];
                        m_displayData.InsertAt(iItem + 1, displayData);
                    }

                    m_list.SetItemCount((int)m_sts.GetCount());

                    bNeedsUpdate = true;
                    break;
                }
                case DELITEM: {
                    CUIntArray items;
                    pos = m_list.GetFirstSelectedItemPosition();
                    while (pos) {
                        items.Add(m_list.GetNextSelectedItem(pos));
                    }

                    qsort(items.GetData(), items.GetCount(), sizeof(UINT), uintcomp);

                    for (INT_PTR i = 0, l = items.GetCount(); i < l; i++) {
                        iItem = items[i];
                        m_sts.RemoveAt(iItem);
                        m_subtimes.RemoveAt(iItem);
                        m_displayData.RemoveAt(iItem);
                    }

                    m_list.SetItemCount((int)m_sts.GetCount());

                    iItem = items[items.GetCount() - 1];
                    if (iItem >= m_list.GetItemCount()) {
                        iItem = m_list.GetItemCount() - 1;
                    }
                    m_list.SetSelectionMark(iItem);

                    bNeedsUpdate = true;
                    break;
                }
                case RESETS:
                    ModStart(iItem, st.orgStart, true);
                    bNeedsUpdate = true;
                    break;
                case SETOS:
                    ModStart(iItem, st.orgStart);
                    bNeedsUpdate = true;
                    break;
                case SETCS:
                    ModStart(iItem, (int)(m_rt / 10000));
                    bNeedsUpdate = true;
                    break;
                case RESETE:
                    ModEnd(iItem, st.orgEnd, true);
                    bNeedsUpdate = true;
                    break;
                case SETOE:
                    ModEnd(iItem, st.orgEnd);
                    bNeedsUpdate = true;
                    break;
                case SETCE:
                    ModEnd(iItem, (int)(m_rt / 10000));
                    bNeedsUpdate = true;
                    break;
                default:
                    if (STYLEFIRST <= id && id <= STYLELAST) {
                        CString s = styles[id - STYLEFIRST];
                        if (m_sts[iItem].style != s) {
                            m_sts[iItem].style = s;
                            bNeedsUpdate = true;
                        }
                    } else if (id == STYLEEDIT) {
                        CAutoPtrArray<CPPageSubStyle> pages;
                        CAtlArray<STSStyle*> styles;

                        STSStyle* stss = m_sts.GetStyle(iItem);
                        int iSelPage = 0;

                        POSITION pos = m_sts.m_styles.GetStartPosition();
                        for (int i = 0; pos; i++) {
                            CString key;
                            STSStyle* val;
                            m_sts.m_styles.GetNextAssoc(pos, key, val);

                            CAutoPtr<CPPageSubStyle> page(DEBUG_NEW CPPageSubStyle());
                            page->InitStyle(key, *val);
                            pages.Add(page);
                            styles.Add(val);

                            if (stss == val) {
                                iSelPage = i;
                            }
                        }

                        CPropertySheet dlg(ResStr(IDS_SUBTITLES_STYLES_CAPTION), this, iSelPage);
                        for (size_t i = 0, l = pages.GetCount(); i < l; i++) {
                            dlg.AddPage(pages[i]);
                        }

                        if (dlg.DoModal() == IDOK) {
                            for (size_t j = 0, l = pages.GetCount(); j < l; j++) {
                                pages[j]->GetStyle(*styles[j]);
                            }
                            bNeedsUpdate = true;
                        }
                    } else if (id == UNICODEYES || id == UNICODENO) {
                        m_sts.ConvertUnicode(iItem, id == UNICODEYES);
                        bNeedsUpdate = true;
                    } else if (id == LAYERDEC || id == LAYERINC) {
                        int d = (id == LAYERDEC) ? -1 : 1;
                        m_sts[iItem].layer += d;
                        bNeedsUpdate = true;
                    } else if (ACTORFIRST <= id && id <= ACTORLAST) {
                        CString s = actors[id - ACTORFIRST];
                        if (m_sts[iItem].actor != s) {
                            m_sts[iItem].actor = s;
                            bNeedsUpdate = true;
                        }
                    } else if (EFFECTFIRST <= id && id <= EFFECTLAST) {
                        CString s = effects[id - EFFECTFIRST];
                        if (m_sts[iItem].effect != s) {
                            m_sts[iItem].effect = s;
                            bNeedsUpdate = true;
                        }
                    }
                    break;
            }

            if (bNeedsUpdate) {
                m_list.Update(iItem);
            }
        }

        if (bNeedsUpdate) {
            UpdatePreview();
        }
    }

    *pResult = 0;
}
Ejemplo n.º 23
0
int	CUpdateUtil::RealVersionCheck(CUIntArray& unarrayClient, CUIntArray& unarrayServer)
{
	int i = 0;
	int count = 0;

	if(unarrayClient.GetSize() == unarrayServer.GetSize()){
		count = unarrayClient.GetSize();
		for(i=0; i <count; i++){
			if(unarrayClient.ElementAt(i) != unarrayServer.ElementAt(i)){
				if(unarrayClient.ElementAt(i) < unarrayServer.ElementAt(i))			return UPDATE_FLAG_UPDATE;
				else if(unarrayClient.ElementAt(i) > unarrayServer.ElementAt(i))	return UPDATE_FLAG_NORMAL;
			}
		}
	}
	else if(unarrayClient.GetSize() < unarrayServer.GetSize()){	// 1.1 : 1.1.0.1
		count = unarrayClient.GetSize();
		for(i=0; i <count; i++){
			if(unarrayClient.ElementAt(i) != unarrayServer.ElementAt(i)){
				if(unarrayClient.ElementAt(i) < unarrayServer.ElementAt(i))			return UPDATE_FLAG_UPDATE;
				else if(unarrayClient.ElementAt(i) > unarrayServer.ElementAt(i))	return UPDATE_FLAG_NORMAL;
			}
		}
		return UPDATE_FLAG_UPDATE;
	}
	else{	// unarrayClient.GetSize() > unarrayServer.GetSize() // 1.1.0.1 : 1.2
		count = unarrayServer.GetSize();
		for(i=0; i <count; i++){
			if(unarrayClient.ElementAt(i) != unarrayServer.ElementAt(i)){
				if(unarrayClient.ElementAt(i) < unarrayServer.ElementAt(i))			return UPDATE_FLAG_UPDATE;
				else if(unarrayClient.ElementAt(i) > unarrayServer.ElementAt(i))	return UPDATE_FLAG_NORMAL;
			}
		}
	}

	return UPDATE_FLAG_NORMAL;
}
Ejemplo n.º 24
0
void CSListView::ExportList( CListExportDlg * pDlg )
{
	ASSERT( pDlg );
	if( NULL == pDlg )
		return;

	int	nColumnCount	=	m_Grid.GetColumnCount();
	ASSERT( nColumnCount > 0 );
	if( nColumnCount <= 0 )
		return;

	CStockContainer & container = AfxGetSListStockContainer();

	// Get Current StockList Time
	DWORD	dwDate;
	CSPTime	sptime;
	CSPTime	time;
	if( container.GetCurrentType( NULL, NULL, &dwDate )
		&& (-1 != dwDate || container.GetLatestTechDate(&dwDate))
		&& sptime.FromStockTimeDay( dwDate ) )
		time	=	CSPTime( sptime.GetTime() );

	// Set Column
	CStringArray	astrColumn;
	CUIntArray		anWidth;
	CUIntArray		anParams;
	for(int nCol = 0; nCol < nColumnCount; nCol ++ )
	{
		astrColumn.Add( m_Grid.GetItemText(0,nCol) );
		anWidth.Add( m_Grid.GetColumnWidth(nCol) );
		anParams.Add( m_Grid.GetItemData(0,nCol) );
	}
	if( ! pDlg->ExportBegin( astrColumn, anWidth, TRUE )
		|| ! pDlg->ExportOpenTable( time, TRUE ) )
		return;

	container.Lock();

	// set Item
	int	nCount = 0, nTotalCount = 0;
	if( pDlg->m_bItemAll )
	{
		nTotalCount	=	m_Grid.GetRowCount()-1;
		pDlg->SetProgressRange( 0, nTotalCount );
		for( int nRow=1; nRow<m_Grid.GetRowCount(); nRow++ )
		{
			CStringArray	astrItemText;
			astrItemText.SetSize( 0, nColumnCount+1 );
			LPARAM	id	=	m_Grid.GetItemData(nRow,0);
			CStockInfo & info	=	container.GetStockInfoByID(id);
			for(nCol=0; nCol<anParams.GetSize(); nCol++ )
			{
				astrItemText.Add( m_Grid.GetItemText( nRow, nCol ) );
			}
			pDlg->ExportAddItem( astrItemText );

			nCount	++;
			pDlg->SetProgress( nCount );
		}
	}
	else if( pDlg->m_bItemSelected )
	{
		nTotalCount	=	m_Grid.GetSelectedCount();
		pDlg->SetProgressRange( 0, nTotalCount );
		for( int nRow=1; nRow<m_Grid.GetRowCount(); nRow++ )
		{
			BOOL	bSelected	=	FALSE;
			for( nCol=0; nCol<m_Grid.GetColumnCount(); nCol ++ )
				bSelected	|=	( m_Grid.GetItemState(nRow,nCol) & GVIS_SELECTED );
			if( !bSelected )
				continue;

			CStringArray	astrItemText;
			astrItemText.SetSize( 0, nColumnCount+1 );
			LPARAM	id	=	m_Grid.GetItemData(nRow,0);
			CStockInfo & info	=	container.GetStockInfoByID(id);
			for(nCol=0; nCol<anParams.GetSize(); nCol++ )
			{
				astrItemText.Add( m_Grid.GetItemText( nRow, nCol ) );
			}
			pDlg->ExportAddItem( astrItemText );

			nCount	++;
			pDlg->SetProgress( nCount );
		}
	}
	else if( pDlg->m_bItemDefine )
	{
		nTotalCount	=	min(m_Grid.GetRowCount()-1,pDlg->m_nItemEnd) - max(1,pDlg->m_nItemBegin) + 1;
		pDlg->SetProgressRange( 0, nTotalCount );
		for( int nRow=max(1,pDlg->m_nItemBegin); nRow<=min(m_Grid.GetRowCount()-1,pDlg->m_nItemEnd); nRow++ )
		{
			CStringArray	astrItemText;
			astrItemText.SetSize( 0, nColumnCount+1 );
			LPARAM	id	=	m_Grid.GetItemData(nRow,0);
			CStockInfo & info	=	container.GetStockInfoByID(id);
			for(nCol=0; nCol<anParams.GetSize(); nCol++ )
			{
				astrItemText.Add( m_Grid.GetItemText( nRow, nCol ) );
			}
			pDlg->ExportAddItem( astrItemText );

			nCount	++;
			pDlg->SetProgress( nCount );
		}
	}

	container.UnLock();

	pDlg->ExportFinish( );
}
//----------------------------- FUNCTION -------------------------------------*
BOOL
    DecodeCfgData(CByteArray const* pCfg,
                  CStringArray& aTexts, CUIntArray& aOffsets, CUIntArray& aLengths,
                  int& iTotalInputs, int& iTotalOutputs, int& iTotalInAndOuts, int& iSeq)
/*>>>> 
decode slave config data bytes to string

I   pCfg:       cfg data structure
O   aTexts:     array of texts to decoded config byte(s)
O   aOffsets:   array with start offsets of config sequence above
O   iTotalInputs    total bytes of inputs and outputs (incl. <iTotalInAndOuts> !)
O   iTotalOutputs
O   iTotalInAndOuts total bytes which allow input and output
0   iSeq        number of config sequences = number of entries in arrays
Result
    TRUE if ok 
<<<<*/
{
    int lenCfgData = pCfg->GetSize();
    BYTE*   pCfgData = (BYTE*) (pCfg->GetData());
    CString sCfgText;
    int     cntDecodedBytes;
    int     iOffset = 0;
    int     lenRead, lenWrite, lenReadAndWrite;
    BOOL    bConfigOK = TRUE;
    iTotalInputs    = 0;
    iTotalOutputs   = 0;
    iTotalInAndOuts = 0;
    iSeq            = 0;
    while (lenCfgData > 0)
    {
        cntDecodedBytes = 0;
        lenRead  = 0;
        lenWrite = 0;
        lenReadAndWrite = 0;
        if (::DecodeCfgBytes(pCfgData, sCfgText,
                             cntDecodedBytes, lenRead, lenWrite, lenReadAndWrite))
        {
            aTexts.SetAtGrow(iSeq, sCfgText);
            aOffsets.SetAtGrow(iSeq, iOffset);
            aLengths.SetAtGrow(iSeq, cntDecodedBytes);
            iOffset         += cntDecodedBytes;
            lenCfgData      -= cntDecodedBytes;
            iTotalInputs    += lenRead;
            iTotalOutputs   += lenWrite;
            iTotalInAndOuts += lenReadAndWrite;
            iSeq++;
        }
        else 
        {
            TRACE0("DecodeCfgData: Bad config data bytes\n");
            bConfigOK = FALSE;
            break;
        }
    };
    if (lenCfgData != 0)
    {
        ASSERT(FALSE);
        bConfigOK = FALSE;
    }

    return bConfigOK;
}
Ejemplo n.º 26
0
void CSListView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	if( UPDATE_HINT_SLISTVIEW != lHint )
		return;
	if( IsWindowVisible() )
		SetFocus( );
	int	nColumnCount	=	m_Grid.GetColumnCount();
	if( nColumnCount <= 0 )
		return;

	if( GetParentFrame()->GetSafeHwnd() != AfxGetMainFrame()->GetActiveFrame()->GetSafeHwnd() )
	{
		m_bShouldUpdate	=	TRUE;
		return;
	}
	m_bShouldUpdate	=	FALSE;

	CStockContainer & container = AfxGetSListStockContainer();
	container.Lock();

	m_Grid.DeleteNonFixedRows();

	// Progress

	CUIntArray	anParams;
	anParams.SetSize( 0, nColumnCount );
	for( int nCol=0; nCol < nColumnCount; nCol ++ )
	{
		LPARAM	lParam	=	m_Grid.GetItemData( 0, nCol );
		anParams.Add( lParam );
	}

	CRect rectClient;
	GetClientRect( &rectClient );
	int nPageCount = 1 + rectClient.Height() / abs(m_Grid.GetFixedRowHeight()) + 1;
/** disabled 
	for( int i=0; i<container.GetSize(); i++ )
	{
		CStockInfo & info = container.GetStockInfoByID(i);

		int nRow = m_Grid.InsertRow( info.GetStockName() );
		m_Grid.SetItemData( nRow, 0, i );

		for( int nCol=0; nCol<anParams.GetSize(); nCol++ )
		{
			m_Grid.SetItemFormat( nRow, nCol, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
			m_Grid.SetItemText( nRow, nCol, AfxGetVariantDispString( anParams[nCol], info, &container ) );
			m_Grid.SetItemBkColour( nRow, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) );
			m_Grid.SetItemFgColour( nRow, nCol, AfxGetVariantColor( anParams[nCol], info ) );
			if( anParams[nCol] == SLH_DATE )
				m_Grid.SetColumnWidth( nCol, 80 );
		}

		if( i == nPageCount+5 )
		{
			m_Grid.Invalidate( );
			MSG		msg;
			while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) )
				AfxGetApp()->PumpMessage();
		}
		if( pMainFrame )
			pMainFrame->SetProgress( 100*i/container.GetSize() );
	}

	// Set Average and Weight Average
	SetAverageItem( m_Grid, container, FALSE );

	// Sort If Needed
	if( -1 != m_nColSort )
	{
		LPARAM	lParam	=	m_Grid.GetItemData( 0, m_nColSort );
		if( lParam >= 0 )
		{
			CStockContainer::m_pSortContainer	=	&container;
			container.m_nSortVariantID	=	lParam;
			container.m_bSortAscend		=	m_bSortAscend;
			m_Grid.SortItems( ItemCompareFunc, 0, TRUE );
		}
	}

*/
	for(int i= 0;i<1;i++)
	{
		int nRow = m_Grid.InsertRow( "sz002376");
		m_Grid.SetItemData( nRow, 0, i );
        const char * paramValues [] = {"新北洋","sz002376","1000","1000","1000","17.74","19.08","17740","-1340.0"};
		for( int nCol=0; nCol<9; nCol++ )
		{
			m_Grid.SetItemFormat( nRow, nCol, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
			m_Grid.SetItemText( nRow, nCol, paramValues[nCol] );
			m_Grid.SetItemBkColour( nRow, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) );
			//m_Grid.SetItemFgColour( nRow, nCol, );
			if( anParams[nCol] == SLH_DATE )
				m_Grid.SetColumnWidth( nCol, 80 );
		}
	}

	int nRow = m_Grid.InsertRow( "summary");
	//m_Grid.SetItemData( nRow, 0, 1 );
	 const char * sumValues [] = {"","","","","","","合计(人民币)","17740","-1340.0"};
	 
	 for( int ic=0; ic<9; ic++ )
	 {
		 m_Grid.SetItemFormat( nRow, ic, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
		 m_Grid.SetItemText( nRow, ic, sumValues[ic] );
		 m_Grid.SetItemBkColour( nRow, 0, AfxGetProfile().GetColor(CColorClass::clrSListBK) );
	 }

	 nRow = m_Grid.InsertRow( "blank");
	 m_Grid.SetItemText( nRow, 0, "" );
	 m_Grid.SetItemBkColour( nRow, 0, AfxGetProfile().GetColor(CColorClass::clrSListBK) );
	//m_Grid.SetItemData( nRow, 0, 1 );

	 nRow = m_Grid.InsertRow( "allheader");
	 const char * allValues [] = {"币种","资金余额","可用资金","可取资金","证券市值","资产总值","","",""};
	 for( ic=0; ic<9; ic++ )
	 {
		 m_Grid.SetItemFormat( nRow, ic, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
		 m_Grid.SetItemText( nRow, ic, allValues[ic] );
		 m_Grid.SetItemBkColour( nRow, ic, AfxGetProfile().GetColor(CColorClass::clrSListBK) );
		 m_Grid.SetItemFgColour( nRow, ic, 0x00ff0000 );
		 LOGFONT *pfont = m_Grid.GetItemFont(nRow,ic);
		 pfont->lfWeight = 700;
		 m_Grid.SetItemFont(nRow,ic,pfont);
	 }

	 nRow = m_Grid.InsertRow( "alldata");
	 const char * alldataValues [] = {"人民币","2163.99","2163.99","2163.99","17740","19903.99","","",""};
	 for( ic=0; ic<9; ic++ )
	 {
		 m_Grid.SetItemFormat( nRow, ic, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
		 m_Grid.SetItemText( nRow, ic, alldataValues[ic] );
		 m_Grid.SetItemBkColour( nRow, ic, AfxGetProfile().GetColor(CColorClass::clrSListBK) );
	 }



	if( m_bFirstUpdate )
		m_Grid.AutoSizeColumns( );
	else
		m_Grid.SetColumnWidth( 0, 80 );
	m_bFirstUpdate	=	FALSE;
	m_Grid.Invalidate( );

	//SendRequestQuote(TRUE);

	container.UnLock();
}
Ejemplo n.º 27
0
void DVControllerTests::TestInitialiseSaveAsDlgData_DocTypeEffect()
{
	AFX_MANAGE_STATE(AfxGetAppModuleState());

	CStdString sSaveFilters;
	int iFormatCount=0;

	CMDIFrameWnd* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWnd, AfxGetMainWnd());
	CChildFrame *pFrame = DYNAMIC_DOWNCAST( CChildFrame, pMainFrame->MDIGetActive() );
	assertTest( pFrame );
	
	CUIntArray aFormats;
	LONG lFormatIndex	= 1;
	LONG lCurrentSaveFormatID = -7;
	LONG lSaveFormatIDDefault = GetApp()->GetDVController(pFrame)->GetComparisonDocController().GetSaveFormatAsDVCode();
//for rtf
	LONG lFlags = 0;
	lFlags |= WSDOCUMENTPROVIDERLib::DF_NEW_DOCUMENT;
	if (lSaveFormatIDDefault !=6)
	{
		lSaveFormatIDDefault=6; //for test rtf
	}
	
	bool origFileFormatValue = Workshare::OptionApi::GetBool(L"AllowFileFormatChange");
	bool origExtSaveFormats = Workshare::OptionApi::GetBool(L"EnableExtendedFileFormats");
	try
	{
		Workshare::OptionApi::SetBool(L"AllowFileFormatChange", false);

		sSaveFilters = GetApp()->GetDVController(pFrame)->GetComparisonDocController().InitialiseSaveAsDlgData(aFormats, lFormatIndex, lCurrentSaveFormatID, lSaveFormatIDDefault, lFlags, docNew);
		int iCount = (x64_int_cast)aFormats.GetSize();
		assertTest(iCount==1);
		CStdString sFormat = _T("Rich Text Format ( *.rtf)|*.rtf||");
		assertTest(sSaveFilters.CompareNoCase(sFormat)==0);	

		sSaveFilters = _T("");
		aFormats.RemoveAll();

		sSaveFilters = GetApp()->GetDVController(pFrame)->GetComparisonDocController().InitialiseSaveAsDlgData(aFormats, lFormatIndex, lCurrentSaveFormatID, lSaveFormatIDDefault, lFlags, docAttachToModified);
		iCount = (x64_int_cast)aFormats.GetSize();
		assertTest(iCount==1);
		sFormat = _T("Rich Text Format ( *.rtf)|*.rtf||");
		assertTest(sSaveFilters.CompareNoCase(sFormat)==0);	

		sSaveFilters = _T("");
		aFormats.RemoveAll();

		Workshare::OptionApi::SetBool(L"EnableExtendedFileFormats", true);

		sSaveFilters = GetApp()->GetDVController(pFrame)->GetComparisonDocController().InitialiseSaveAsDlgData(aFormats, lFormatIndex, lCurrentSaveFormatID, lSaveFormatIDDefault, lFlags, docVersionOfOriginal);
		iCount =(x64_int_cast) aFormats.GetSize();
		assertTest(iCount==1);
		sFormat = _T("Adobe Acrobat File ( *.pdf)|*.pdf||");
		assertTest(sSaveFilters.CompareNoCase(sFormat)==0);	

		Workshare::OptionApi::SetBool(L"AllowFileFormatChange", true);
		Workshare::OptionApi::SetBool(L"EnableExtendedFileFormats", false);
		sSaveFilters = _T("");
		aFormats.RemoveAll();

		sSaveFilters = GetApp()->GetDVController(pFrame)->GetComparisonDocController().InitialiseSaveAsDlgData(aFormats, lFormatIndex, lCurrentSaveFormatID, lSaveFormatIDDefault, lFlags, docNew);
		iCount = (x64_int_cast)aFormats.GetSize();
		sFormat = "Workshare DeltaFile ( *.wdf)|*.wdf|Word 97-2003 Document ( *.doc)|*.doc|Word Document ( *.docx)|*.docx|Text Only ( *.txt)|*.txt|Rich Text Format ( *.rtf)|*.rtf|HTML Document ( *.htm)|*.htm|Adobe Acrobat File ( *.pdf)|*.pdf|Adobe Acrobat PDF/A File (*.pdf)|*.pdf||";
		
		assertMessage(iCount==8,_T("If this fails turn off \"Use Extended File Format\" flag in DMS config to make this work"));
		assertTest(sSaveFilters.CompareNoCase(sFormat) == 0);  

		sSaveFilters = _T("");
		aFormats.RemoveAll();

		sSaveFilters = GetApp()->GetDVController(pFrame)->GetComparisonDocController().InitialiseSaveAsDlgData(aFormats, lFormatIndex, lCurrentSaveFormatID, lSaveFormatIDDefault, lFlags, docAttachToModified);
		iCount = (x64_int_cast)aFormats.GetSize();
		sFormat = "Workshare DeltaFile ( *.wdf)|*.wdf|Word 97-2003 Document ( *.doc)|*.doc|Word Document ( *.docx)|*.docx|Text Only ( *.txt)|*.txt|Rich Text Format ( *.rtf)|*.rtf|HTML Document ( *.htm)|*.htm|Adobe Acrobat File ( *.pdf)|*.pdf|Adobe Acrobat PDF/A File (*.pdf)|*.pdf||";
		
		assertMessage(iCount==8,_T("If this fails turn off \"Use Extended File Format\" flag in DMS config to make this work"));
		assertTest(sSaveFilters.CompareNoCase(sFormat) == 0);  

		sSaveFilters = _T("");
		aFormats.RemoveAll();

		sSaveFilters = GetApp()->GetDVController(pFrame)->GetComparisonDocController().InitialiseSaveAsDlgData(aFormats, lFormatIndex, lCurrentSaveFormatID, lSaveFormatIDDefault, lFlags, docVersionOfOriginal);
		iCount = (x64_int_cast)aFormats.GetSize();
		sFormat = "Workshare DeltaFile ( *.wdf)|*.wdf|Word 97-2003 Document ( *.doc)|*.doc|Word Document ( *.docx)|*.docx|Text Only ( *.txt)|*.txt|Rich Text Format ( *.rtf)|*.rtf|HTML Document ( *.htm)|*.htm|Adobe Acrobat File ( *.pdf)|*.pdf|Adobe Acrobat PDF/A File (*.pdf)|*.pdf||";
		
		assertMessage(iCount==8,_T("If this fails turn off \"Use Extended File Format\" flag in DMS config to make this work"));
		assertTest(sSaveFilters.CompareNoCase(sFormat) == 0);  
	}
	catch(...)
	{
		_ASSERTE(!_T("Catch ... How did we get here?"));
		Workshare::OptionApi::SetBool(L"AllowFileFormatChange", origFileFormatValue);
		Workshare::OptionApi::SetBool(L"EnableExtendedFileFormats", origExtSaveFormats);
		throw;
	}
	Workshare::OptionApi::SetBool(L"AllowFileFormatChange", origFileFormatValue);
	Workshare::OptionApi::SetBool(L"EnableExtendedFileFormats", origExtSaveFormats);
}
Ejemplo n.º 28
0
void CGelView::OnRungel() 
{
	// TODO: Add your control notification handler code here
	CGenedocDoc *pDoc = GetDocument();

//	MakeGel(m_listSequences, m_listEnzymes);
//	pDoc->SetModifiedFlag();

	// CListBox
	int iSeqCount, iEnzCount;

	iSeqCount = m_listSequences.GetSelCount();
	iEnzCount = m_listEnzymes.GetSelCount();

	if ( iSeqCount < 1 || iEnzCount < 1 ) {
		return;
	}

	BeginWaitCursor();

	int *arrSeq = new int[iSeqCount];
	int *arrEnz = new int[iEnzCount];

	m_listSequences.GetSelItems( iSeqCount, arrSeq );
	m_listEnzymes.GetSelItems( iEnzCount, arrEnz );


	POSITION sPos = m_listGel.GetHeadPosition();
	while ( sPos != NULL ) {
		delete (SGel*)m_listGel.GetNext(sPos);
	}
	m_listGel.RemoveAll();

	int s, e;

	for ( s=0; s < iSeqCount; ++s ) {
		POSITION aPos = pDoc->pGSFiller->SegDataList.FindIndex( arrSeq[s] + 2 );
		CGeneSegment *tCGSeg = (CGeneSegment *)pDoc->pGSFiller->SegDataList.GetAt(aPos);

		GeneStor *pGS = (GeneStor *)GlobalLock( tCGSeg->GetTextHandle() );
		// CList
		NewBand(tCGSeg);
		for ( e=0; e < iEnzCount; ++e ) {
			POSITION ePos =  pDoc->m_UserVars.listSearch.FindIndex( arrEnz[e] );
			stcSearch *Enzyme = (stcSearch *)pDoc->m_UserVars.listSearch.GetAt(ePos);

			SearchRebaseGel( Enzyme, pGS, tCGSeg->GetTextLength() );

		}
		GlobalUnlock( tCGSeg->GetTextHandle() );
	}


	CUIntArray arrFrags;

	DWORD MaxLength = 0;
	sPos = m_listGel.GetHeadPosition();
	while ( sPos != NULL ) {
		SGel *pSGel = (SGel *)m_listGel.GetNext(sPos);
		DWORD iLen = pSGel->Sequence->GetLastResidue();
		if ( iLen > MaxLength ) MaxLength = iLen;
	}

	SetYScale ( 0, MaxLength );

	sPos = m_listGel.GetHeadPosition();
	while ( sPos != NULL ) {
		SGel *pSGel = (SGel *)m_listGel.GetNext(sPos);

		int iArr = pSGel->arrCutLoc.GetSize();
		// This code sorts the cut locations
		for ( int ti=0; ti < iArr - 1; ++ti ) {
			for ( int tj=0; tj < iArr - 1; ++tj ) {
				if ( pSGel->arrCutLoc[tj] > pSGel->arrCutLoc[tj+1] ) {
					int t = pSGel->arrCutLoc[tj];
					pSGel->arrCutLoc[tj] = pSGel->arrCutLoc[tj+1];
					pSGel->arrCutLoc[tj+1] = t;
				}
			}
		}
		// Calculate Fragment lengths ..
		DWORD LastCutLoc = 0;
		int i;
		for ( i=0; i < iArr; ++i ) {
			if ( pSGel->arrCutLoc[i] == LastCutLoc ) continue;
			int cl = pSGel->arrCutLoc[i] - LastCutLoc;
			arrFrags.Add( cl );
			LastCutLoc = pSGel->arrCutLoc[i];
		}
		arrFrags.Add( pSGel->Sequence->GetLastResidue() - LastCutLoc );

		// This code sorts the fragment lengths in case that is useful.
//		for ( ti=0; ti < arrFrags.GetSize() - 1; ++ti ) {
//			for ( int tj=0; tj < arrFrags.GetSize()-1; ++tj ) {
//				if ( arrFrags[tj] > arrFrags[tj+1] ) {
//					int t = arrFrags[tj];
//					arrFrags[tj] = arrFrags[tj+1];
//					arrFrags[tj+1] = t;
//				}
//			}
//		}

		iArr = arrFrags.GetSize();
		for ( i=0; i < iArr; ++i ) {
			int iFragLength = arrFrags[i];
			// Normalize fragments to 0 to 1.0
//			double GelLocPerc = 1.0 - (log((double)iFragLength) / log((double)MaxLength));
//			double GelLocPerc = 1.0 - ((double)iFragLength / (double)MaxLength);
			DWORD GelLocPerc = (DWORD)(((double)iFragLength / (double)MaxLength) * 100000000.0);
			// Put Normalized resuls into array for GelObject to draw.
			pSGel->arrGelLoc.Add(GelLocPerc);
		}

		arrFrags.RemoveAll();
	}


	delete arrSeq;
	delete arrEnz;

	EndWaitCursor();
	
	Invalidate();

}
Ejemplo n.º 29
0
BOOL CSListView::SetAverageItem( CGridCtrl &grid, CStockContainer & container, BOOL bRedraw )
{
	if( grid.GetColumnCount() <= 0 )
		return FALSE;

	container.Lock();

	// Get LPARAM
	CUIntArray	anParams;
	anParams.SetSize( 0, grid.GetColumnCount() );
	for( int nCol=0; nCol < grid.GetColumnCount(); nCol ++ )
	{
		LPARAM	lParam	=	grid.GetItemData( 0, nCol );
		anParams.Add( lParam );
	}

	// Set Average
	CStockInfo & infoAve = container.GetAverage( );
	CStockInfo & infoWAve = container.GetWeightAverage( );
	int	iRowAve=0, iRowWAve=0;

	if( grid.GetRowCount() >= 3
		&& grid.GetItemData(grid.GetRowCount()-2,0) == (LPARAM)ID_STOCKCNTN_AVERAGE
		&& grid.GetItemData(grid.GetRowCount()-1,0) == (LPARAM)ID_STOCKCNTN_WEIGHTAVERAGE )
	{
		// get item id
		iRowAve		=	grid.GetRowCount()-2;
		iRowWAve	=	grid.GetRowCount()-1;
	}
	else
	{
		// Insert item
		iRowAve = grid.InsertRow( infoAve.GetStockName() );
		grid.SetItemData( iRowAve, 0, (LPARAM)ID_STOCKCNTN_AVERAGE );
		iRowWAve = grid.InsertRow( infoWAve.GetStockName() );
		grid.SetItemData( iRowWAve, 0, (LPARAM)ID_STOCKCNTN_WEIGHTAVERAGE );
	}

	// Set Average
	for( nCol=0; nCol<anParams.GetSize(); nCol++ )
	{
		grid.SetItemText( iRowAve, nCol, AfxGetVariantDispString(anParams[nCol], infoAve, NULL) );
		grid.SetItemBkColour( iRowAve, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) );
		grid.SetItemFgColour( iRowAve, nCol, AfxGetVariantColor( anParams[nCol], infoAve ) );
	}

	// Set Weight Average
	for( nCol=0; nCol<anParams.GetSize(); nCol++ )
	{
		grid.SetItemText( iRowWAve, nCol, AfxGetVariantDispString(anParams[nCol], infoWAve, NULL) );
		grid.SetItemBkColour( iRowWAve, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) );
		grid.SetItemFgColour( iRowWAve, nCol, AfxGetVariantColor( anParams[nCol], infoWAve ) );
	}

	//	Set Param which is
	//	SLH_MARKETVALUE, SLH_MARKETVALUEA, SLH_MARKETVALUEB and etc,  and more than SLH_USERDEFINE_BEGIN
	for( nCol=0; nCol < anParams.GetSize(); nCol ++ )
	{
		UINT	lParam	=	anParams[nCol];
		if( SLH_DIFF == lParam || SLH_DIFFPERCENT == lParam || SLH_SCOPE == lParam
			|| SLH_DIFFPERCENT_MIN5 == lParam || SLH_PE == lParam
			|| SLH_PMAININCOME == lParam || SLH_RATIO_PCASH == lParam
			|| SLH_RATIO_CURRENCY == lParam || SLH_RATIO_CHANGEHAND == lParam
			|| SLH_RATIO_VOLUME == lParam || SLH_RS == lParam
			|| SLH_MARKETVALUE == lParam || SLH_MARKETVALUEA == lParam
			|| SLH_MARKETVALUEB == lParam || lParam >= SLH_USERDEFINE_BEGIN )
		{
			double	dc = 0., average = 0.;
			double	wsum = 0.0001, waverage = 0., w = 0.;
			for( int iRow=1; iRow<grid.GetRowCount(); iRow++ )
			{
				if( iRow == iRowAve || iRow == iRowWAve )
					continue;

				int	id	=	grid.GetItemData(iRow,0);
				if( id < 0 || id > container.GetSize() )
					continue;

				CStockInfo	& info = container.ElementAt(id);
				w	=	info.m_fShare_count_total;
				double	dValue	=	0.;
				if( !AfxGetVariantValue( lParam, info, &dValue, &container ) )
					continue;

				average		=	(average * dc + dValue)/(dc+1);
				waverage	=	(waverage * wsum + dValue * w)/(wsum+w);

				dc		+=	1;
				wsum	+=	w;
			}

			CString	strText;
			if( SLH_MARKETVALUE == lParam || SLH_MARKETVALUEA == lParam || SLH_MARKETVALUEB == lParam )
			{
				strText.Format( "%u", (DWORD)average );
				grid.SetItemText( iRowAve, nCol, strText );
				grid.SetItemText( iRowWAve, nCol, "-" );
			}
			else
			{
				strText.Format( "%.2f", average );
				grid.SetItemText( iRowAve, nCol, strText );
				strText.Format( "%.2f", waverage );
				grid.SetItemText( iRowWAve, nCol, strText );
			}
		}
	}

	container.UnLock();

	if( bRedraw )
	{
		grid.RedrawRow( iRowAve );
		grid.RedrawRow( iRowWAve );
	}
	return TRUE;
}
Ejemplo n.º 30
0
void EnumerateSerialPorts(CUIntArray& ports)
{
  //Make sure we clear out any elements which may already be in the array
  ports.RemoveAll();

  //Determine what OS we are running on
  OSVERSIONINFO osvi;
  osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  BOOL bGetVer = GetVersionEx(&osvi);

  //On NT use the QueryDosDevice API
  if (bGetVer && (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT))
  {
    //Use QueryDosDevice to look for all devices of the form COMx. This is a better
    //solution as it means that no ports have to be opened at all.
    TCHAR szDevices[65535];
    DWORD dwChars = QueryDosDevice(NULL, szDevices, 65535);
    if (dwChars)
    {
      int i=0;

      for (;;)
      {
        //Get the current device name
        TCHAR* pszCurrentDevice = &szDevices[i];

        //If it looks like "COMX" then
        //add it to the array which will be returned
        int nLen = _tcslen(pszCurrentDevice);
        if (nLen > 3 && _tcsnicmp(pszCurrentDevice, _T("COM"), 3) == 0)
        {
          //Work out the port number
          int nPort = _ttoi(&pszCurrentDevice[3]);
          ports.Add(nPort);
        }

        // Go to next NULL character
        while(szDevices[i] != _T('\0'))
          i++;

        // Bump pointer to the next string
        i++;

        // The list is double-NULL terminated, so if the character is
        // now NULL, we're at the end
        if (szDevices[i] == _T('\0'))
          break;
      }
    }
    else
      TRACE(_T("Failed in call to QueryDosDevice, GetLastError:%d\n"), GetLastError());
  }
  else
  {
    //On 95/98 open up each port to determine their existence

    //Up to 255 COM ports are supported so we iterate through all of them seeing
    //if we can open them or if we fail to open them, get an access denied or general error error.
    //Both of these cases indicate that there is a COM port at that number. 
    for (UINT i=1; i<256; i++)
    {
      //Form the Raw device name
      CString sPort;
      sPort.Format(_T("\\\\.\\COM%d"), i);

      //Try to open the port
      BOOL bSuccess = FALSE;
      HANDLE hPort = ::CreateFile(sPort, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
      if (hPort == INVALID_HANDLE_VALUE)
      {
        DWORD dwError = GetLastError();

        //Check to see if the error was because some other app had the port open or a general failure
        if (dwError == ERROR_ACCESS_DENIED || dwError == ERROR_GEN_FAILURE)
          bSuccess = TRUE;
      }
      else
      {
        //The port was opened successfully
        bSuccess = TRUE;

        //Don't forget to close the port, since we are going to do nothing with it anyway
        CloseHandle(hPort);
      }

      //Add the port number to the array which will be returned
      if (bSuccess)
        ports.Add(i);
    }
  }
}