void cMemoryStream::seek(const int distance, const basicInput::seekMethod method) { if (!__canSeek(distance, method)) { XSTL_THROW(cException, EXCEPTION_SEEK_ERROR); } switch (method) { case IO_SEEK_SET: if (distance <= 0) m_filePosition = 0; else m_filePosition = t_min((uint)(distance), m_data->getSize()); break; case IO_SEEK_CUR: if ((distance < 0) && ((uint)(-distance) > m_filePosition)) m_filePosition = 0; else { m_filePosition+= distance; m_filePosition = t_min(m_filePosition, m_data->getSize()); } break; case IO_SEEK_END: // distance is negative, see __canSeek. if ((distance < 0) && ((uint)(-distance) > m_data->getSize())) m_filePosition = 0; else m_filePosition = m_data->getSize() + distance; break; } }
CMyRect MergeRect(const CMyRect& rc1, const CMyRect& rc2) { return CMyRect( t_min(rc1.left , rc2.left), t_min(rc1.top , rc2.top), t_max(rc1.right , rc2.right), t_max(rc1.bottom, rc2.bottom) ); }
static bool MakeDiffTmpFile_core(CTextOutputStream& out, HWND hwnd, CEditView& view, bool bBom) { CLogicInt y = CLogicInt(0); const wchar_t* pLineData; if( !hwnd ){ const CDocLineMgr& docMgr = view.m_pcEditDoc->m_cDocLineMgr; for(;;){ CLogicInt nLineLen; pLineData = docMgr.GetLine(y)->GetDocLineStrWithEOL(&nLineLen); // 正常終了 if( 0 == nLineLen || NULL == pLineData ) break; if( bBom ){ CNativeW cLine2(L"\ufeff"); cLine2.AppendString(pLineData, nLineLen); out.WriteString(cLine2.GetStringPtr(), cLine2.GetStringLength()); bBom = false; }else{ out.WriteString(pLineData,nLineLen); } y++; } }else if( IsSakuraMainWindow(hwnd) ) { const int max_size = (int)GetDllShareData().m_sWorkBuffer.GetWorkBufferCount<const EDIT_CHAR>(); pLineData = GetDllShareData().m_sWorkBuffer.GetWorkBuffer<const EDIT_CHAR>(); for(;;){ int nLineOffset = 0; int nLineLen = 0; //初回用仮値 do{ // m_sWorkBuffer#m_Workの排他制御。外部コマンド出力/TraceOut/Diffが対象 LockGuard<CMutex> guard( CShareData::GetMutexShareWork() ); { nLineLen = ::SendMessageAny( hwnd, MYWM_GETLINEDATA, y, nLineOffset ); if( nLineLen == 0 ){ return true; } // EOF => 正常終了 if( nLineLen < 0 ){ return false; } // 何かエラー if( bBom ){ CNativeW cLine2(L"\ufeff"); cLine2.AppendString(pLineData, t_min(nLineLen, max_size)); out.WriteString(cLine2.GetStringPtr(), cLine2.GetStringLength()); bBom = false; }else{ out.WriteString(pLineData, t_min(nLineLen, max_size)); } } nLineOffset += max_size; }while(max_size < nLineLen); y++; } }else{ return false; } if( bBom ){ out.WriteString(L"\ufeff", 1); } return true; }
/*! 画面の互換ビットマップを作成または更新する。 必要の無いときは何もしない。 @param cx ウィンドウの高さ @param cy ウィンドウの幅 @return true: ビットマップを利用可能 / false: ビットマップの作成・更新に失敗 @date 2007.09.09 Moca CEditView::OnSizeから分離。 単純に生成するだけだったものを、仕様変更に従い内容コピーを追加。 サイズが同じときは何もしないように変更 @par 互換BMPにはキャレット・カーソル位置横縦線・対括弧以外の情報を全て書き込む。 選択範囲変更時の反転処理は、画面と互換BMPの両方を別々に変更する。 カーソル位置横縦線変更時には、互換BMPから画面に元の情報を復帰させている。 */ bool CEditView::CreateOrUpdateCompatibleBitmap( int cx, int cy ) { if( NULL == m_hdcCompatDC ){ return false; } // サイズを64の倍数で整列 int nBmpWidthNew = ((cx + 63) & (0x7fffffff - 63)); int nBmpHeightNew = ((cy + 63) & (0x7fffffff - 63)); if( nBmpWidthNew != m_nCompatBMPWidth || nBmpHeightNew != m_nCompatBMPHeight ){ #if 0 MYTRACE( _T("CEditView::CreateOrUpdateCompatibleBitmap( %d, %d ): resized\n"), cx, cy ); #endif HDC hdc = ::GetDC( GetHwnd() ); HBITMAP hBitmapNew = NULL; if( m_hbmpCompatBMP ){ // BMPの更新 HDC hdcTemp = ::CreateCompatibleDC( hdc ); hBitmapNew = ::CreateCompatibleBitmap( hdc, nBmpWidthNew, nBmpHeightNew ); if( hBitmapNew ){ HBITMAP hBitmapOld = (HBITMAP)::SelectObject( hdcTemp, hBitmapNew ); // 前の画面内容をコピーする ::BitBlt( hdcTemp, 0, 0, t_min( nBmpWidthNew,m_nCompatBMPWidth ), t_min( nBmpHeightNew, m_nCompatBMPHeight ), m_hdcCompatDC, 0, 0, SRCCOPY ); ::SelectObject( hdcTemp, hBitmapOld ); ::SelectObject( m_hdcCompatDC, m_hbmpCompatBMPOld ); ::DeleteObject( m_hbmpCompatBMP ); } ::DeleteDC( hdcTemp ); }else{ // BMPの新規作成 hBitmapNew = ::CreateCompatibleBitmap( hdc, nBmpWidthNew, nBmpHeightNew ); } if( hBitmapNew ){ m_hbmpCompatBMP = hBitmapNew; m_nCompatBMPWidth = nBmpWidthNew; m_nCompatBMPHeight = nBmpHeightNew; m_hbmpCompatBMPOld = (HBITMAP)::SelectObject( m_hdcCompatDC, m_hbmpCompatBMP ); }else{ // 互換BMPの作成に失敗 // 今後も失敗を繰り返す可能性が高いので // m_hdcCompatDCをNULLにすることで画面バッファ機能をこのウィンドウのみ無効にする。 // 2007.09.29 genta 関数化.既存のBMPも解放 UseCompatibleDC(FALSE); } ::ReleaseDC( GetHwnd(), hdc ); } return NULL != m_hbmpCompatBMP; }
int findMinCost(string A, int n, string B, int m, int c0, int c1, int c2) { // write code here if(n==0 && m == 0) return 0; int dp[n+1][m+1]; dp[0][0] = 0; for(int i = 1; i <= m; ++i) dp[0][i] = dp[0][i-1] + c0; for(int i = 1; i <= n; ++i) dp[i][0] = dp[i-1][0] + c1; for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) { if(A[i-1] == B[j-1]) dp[i][j] = dp[i-1][j-1]; else dp[i][j] = t_min(dp[i-1][j-1]+c2,dp[i-1][j]+c1,dp[i][j-1]+c0); } return dp[n][m]; }
uint basicInput::pipeRead(void *buffer, const uint length) { uint8 *array = (uint8 *)buffer; // The array buffer uint readed = 0; // Total readed uint readedAtOnce = 0; // How many uint8 readed in order. uint leftSize = length; // How many bytes to read more. /* Reading loop */ while (leftSize > 0) { // Try to read readedAtOnce = read(array, t_min(leftSize, getPipeReadBestRequest())); // Increase counters array += readedAtOnce; leftSize -= readedAtOnce; readed += readedAtOnce; // Test whether we reached the end of the stream if (isEOS()) { return readed; } } return readed; }
uint cMemoryStream::read(void *buffer, const uint length) { uint sread = t_min(m_data->getSize() - m_filePosition, length); cOS::memcpy(buffer, m_data->getBuffer() + m_filePosition, sread); m_filePosition+= sread; return sread; }
character* makeString(char* string) { static character temp[MAX_STRING]; uint len = t_min((int)strlen(string), (int)MAX_STRING); for (uint i = 0; i < len; i++) { temp[i] = (character)string[i]; } temp[len] = cChar::getNullCharacter(); return temp; }
void CGraphics::ClearBrush() { //元のブラシに戻す if(!m_vBrushes.empty()){ ::SelectObject(m_hdc,m_vBrushes[0]); } //ブラシをすべて削除 (0番要素以外) int nSize = (int)m_vBrushes.size(); for(int i=1;i<nSize;i++){ ::DeleteObject(m_vBrushes[i]); } m_vBrushes.resize(t_min(1,(int)m_vBrushes.size())); }
unsigned int cCacheStream::write(const void *buffer, const unsigned int length) { // Only if the buffer is full, empty it if (m_writePosition == m_writeCache.getSize()) { m_stream->pipeWrite(m_writeCache.getBuffer(), m_writePosition); m_writePosition = 0; // Notice that this transaction should be append! } // Add the rest of the buffer unsigned int written = t_min(length, (unsigned int)(m_writeCache.getSize() - m_writePosition)); cOS::memcpy(m_writeCache.getBuffer() + m_writePosition, buffer, written); m_writePosition+= written; return written; }
bool cNtHeader::cNtPeFileMapping::memread(addressNumericValue address, void* buffer, uint length, cFragmentsDescriptor*) const { // TODO! // For now the fragmentation is ignore because it's irrelevant if (!m_parent->m_memoryImage.isEmpty()) { cForkStreamPtr stream = m_parent->m_memoryImage->fork(); stream->seek(address, basicInput::IO_SEEK_SET); stream->pipeRead((uint8*)buffer, length); return true; } // Reset buffer memset(buffer, IMAGE_RDATA_CELL_CODE , length); cList<cSectionPtr>::iterator i = m_parent->m_sections.begin(); for (; i != m_parent->m_sections.end(); ++i) { cNtSectionHeader& ntSection = *((cNtSectionHeader*)(*i).getPointer()); // For each section check if we have data within the range addressNumericValue SectionAddress = ntSection.VirtualAddress; addressNumericValue SectionLength = ntSection.SizeOfRawData; addressNumericValue SectionEnd = SectionAddress + SectionLength; if ((SectionEnd > address) && (SectionAddress < (address + length))) { // There is some overlapped addressNumericValue cBegin = t_max(SectionAddress, address); addressNumericValue cEnd = t_min(SectionEnd, (address + length)); cForkStreamPtr stream = ntSection.getSectionContentAccesser()->fork(); stream->seek(cBegin - SectionAddress, basicInput::IO_SEEK_SET); stream->pipeRead((uint8*)buffer + (cBegin - address), cEnd - cBegin); } } return true; }
unsigned int cCacheStream::read(void *buffer, const unsigned int length) { // Read more data if (m_readPosition == m_readUse) { // Try to fill up buffer m_readUse = m_stream->read(m_readCache.getBuffer(), m_readCache.getSize()); m_readPosition = 0; } // Return back data unsigned int lread = t_min(length, (unsigned int)(m_readUse - m_readPosition)); cOS::memcpy(buffer, m_readCache.getBuffer() + m_readPosition, lread); m_readPosition+= lread; return lread; }
uint cMemoryStream::write(const void *buffer, const uint length) { uint swrite = t_min(m_data->getSize() - m_filePosition, length); /* Normal copy of the data */ cOS::memcpy(m_data->getBuffer() + m_filePosition, buffer, swrite); m_filePosition+= swrite; if ((swrite != length) && (m_fixedSize == FALSE)) { /* Increase the array and write the left bytes */ uint lsize = length - swrite; m_data->changeSize(m_data->getSize() + lsize); cOS::memcpy(m_data->getBuffer() + m_filePosition, (BYTE *)(buffer) + swrite, lsize); m_filePosition+= lsize; swrite = length; } return swrite; }
void basicOutput::writeFixedSizeString(const cString& string, uint numberOfCharacters, int unicodeSize) { cBuffer buffer(numberOfCharacters * unicodeSize); uint8* buf = buffer.getBuffer(); memset(buf, 0, buffer.getSize()); uint count = t_min(string.length(), numberOfCharacters); for (uint i = 0; i < count; i++) { switch (unicodeSize) { case 1: buf[i] = cChar::covert2Ascii(string[i]); break; case 2: ((uint16*)buf)[i] = string[i]; break; case 4: ((uint32*)buf)[i] = string[i]; break; default: CHECK_FAIL(); } } pipeWrite(buffer, buffer.getSize()); }
void Ephemeris<Frame>::ComputeApsides(not_null<MassiveBody const*> const body1, not_null<MassiveBody const*> const body2, DiscreteTrajectory<Frame>& apoapsides1, DiscreteTrajectory<Frame>& periapsides1, DiscreteTrajectory<Frame>& apoapsides2, DiscreteTrajectory<Frame>& periapsides2) { not_null<ContinuousTrajectory<Frame> const*> const body1_trajectory = trajectory(body1); not_null<ContinuousTrajectory<Frame> const*> const body2_trajectory = trajectory(body2); typename ContinuousTrajectory<Frame>::Hint hint1; typename ContinuousTrajectory<Frame>::Hint hint2; // Computes the derivative of the squared distance between |body1| and |body2| // at time |t|. auto const evaluate_square_distance_derivative = [body1_trajectory, body2_trajectory, &hint1, &hint2]( Instant const& t) -> Variation<Square<Length>> { DegreesOfFreedom<Frame> const body1_degrees_of_freedom = body1_trajectory->EvaluateDegreesOfFreedom(t, &hint1); DegreesOfFreedom<Frame> const body2_degrees_of_freedom = body2_trajectory->EvaluateDegreesOfFreedom(t, &hint2); RelativeDegreesOfFreedom<Frame> const relative = body1_degrees_of_freedom - body2_degrees_of_freedom; return 2.0 * InnerProduct(relative.displacement(), relative.velocity()); }; std::experimental::optional<Instant> previous_time; std::experimental::optional<Variation<Square<Length>>> previous_squared_distance_derivative; for (Instant time = t_min(); time <= t_max(); time += parameters_.step()) { Variation<Square<Length>> const squared_distance_derivative = evaluate_square_distance_derivative(time); if (previous_squared_distance_derivative && Sign(squared_distance_derivative) != Sign(*previous_squared_distance_derivative)) { CHECK(previous_time); // The derivative of |squared_distance| changed sign. Find its zero by // bisection, this is the time of the apsis. Then compute the apsis and // append it to one of the output trajectories. Instant const apsis_time = Bisect(evaluate_square_distance_derivative, *previous_time, time); DegreesOfFreedom<Frame> const apsis1_degrees_of_freedom = body1_trajectory->EvaluateDegreesOfFreedom(apsis_time, &hint1); DegreesOfFreedom<Frame> const apsis2_degrees_of_freedom = body2_trajectory->EvaluateDegreesOfFreedom(apsis_time, &hint2); if (Sign(squared_distance_derivative).Negative()) { apoapsides1.Append(apsis_time, apsis1_degrees_of_freedom); apoapsides2.Append(apsis_time, apsis2_degrees_of_freedom); } else { periapsides1.Append(apsis_time, apsis1_degrees_of_freedom); periapsides2.Append(apsis_time, apsis2_degrees_of_freedom); } } previous_time = time; previous_squared_distance_derivative = squared_distance_derivative; } }
unsigned int add_arc_as_cubics(int max_recursion, Builder *B, float tol, vec2 start_pt, vec2 end_pt, vec2 center, float radius, float start_angle, float angle) { /* One way to approximate an arc with a cubic-bezier is as * follows (taken from GLyphy which is likely take its * computations from Cairo). * * D = tan(angle / 4) * p0 = start of arc * p3 = end of arc * vp = p3 - p1 * jp = J(vp) * A = (1 - D^2) / 3 * B = (2 * D) / 3 * p1 = p0 + A * vp - B * jp * p2 = p1 - A * vp - B * jp * * and the error between the arc and [p0, p1, p2, p3] is given by * * error <= |vp| * |D|^5 / (54(1 + D^2)) * * Now, |angle| < 2 * PI, implies |angle| / 4 < PI / 4 thus |D| < 1, giving * * error <= |vp| * |D|^5 / 27 * * thus we need: * * |tan(|angle| / 4)|^5 < (27 * tol) / |vp| * * since, tan() is increasing function, * * |angle| < 4 * pow(atan((27 * tol) / |vp|), 0.20f) * */ vec2 vp(end_pt - start_pt); vec2 jp(-vp.y(), vp.x()); float mag_vp(vp.magnitude()); float goal, angle_max; if (mag_vp < tol) { B->line_to(end_pt); return 1; } /* half the tolerance for the cubic to quadratic and half * the tolerance for arc to cubic. */ tol *= 0.5f; goal = t_min(1.0f, (27.0f * tol) / vp.magnitude()); angle_max = t_min(FASTUIDRAW_PI, 4.0f * std::pow(fastuidraw::t_atan(goal), 0.20f)); float angle_remaining(angle); float current_angle(start_angle); float angle_direction(t_sign(angle)); float angle_advance(angle_max * angle_direction); vec2 last_pt(start_pt); unsigned int return_value(0); while (t_abs(angle_remaining) > angle_max) { float next_angle(current_angle + angle_advance); float cos_next_angle(t_cos(next_angle)); float sin_next_angle(t_sin(next_angle)); vec2 next_delta, next_pt; next_pt.x() = center.x() + cos_next_angle * radius; next_pt.y() = center.y() + sin_next_angle * radius; return_value += add_arc_as_single_cubic(max_recursion, B, tol, last_pt, next_pt, angle_advance); current_angle += angle_advance; angle_remaining -= angle_advance; last_pt = next_pt; } return_value += add_arc_as_single_cubic(max_recursion, B, tol, last_pt, end_pt, angle_remaining); return return_value; }
bool SafeMemoryAccesser::memread(addressNumericValue address, void* buffer, uint length, cFragmentsDescriptor* fragments) const { if (length == 0) return true; // Check out-of-range exception getAddress(address + length - 1); // Get the first address addressNumericValue addr = getAddress(address); // Start copying page-by page if (MemoryManager::chkMemPresent(getPtr(addr), length)) { // Easy implementation... cOS::memcpy(buffer, getPtr(address), length); return true; } // Some more complex implementation. Read only the present pages uint pageSize = MemoryManager::getPageSize(addr); addressNumericValue page = MemoryManager::alignToStartPage(addr); // Get the page boundries uint8* data = (uint8*)buffer; uint left = (page + pageSize) - addr; left = t_min(left, length); // Check for internal errors addressNumericValue endAddress = addr + length; bool isFragment = false; addressNumericValue startFragment = 0; do { // Copy memory if (MemoryManager::isPagePresent(page)) { if (isFragment && (fragments != NULL)) { // NOTE: The driver works with a single address convenstion! fragments->appendFragmentBlock(startFragment, addr - 1); isFragment = false; } cOS::memcpy(data, getPtr(addr), left); } else { // Eye-catcher startFragment = addr; isFragment = true; memset(data, PAGEOUT_DEFAULT_BYTE_VALUE, left); } // Add indexes data+= left; addr+= left; page+= pageSize; pageSize = MemoryManager::getPageSize(page); left = t_min(pageSize, endAddress - addr); } while (left > 0); // Add the last fragmentation if (isFragment && (fragments != NULL)) // NOTE: The driver works with a single address convenstion! fragments->appendFragmentBlock(startFragment, endAddress); return false; }
/*! 指定位置のColorIndexの取得 CEditView::DrawLogicLineを元にしたためCEditView::DrawLogicLineに 修正があった場合は、ここも修正が必要。 */ CColor3Setting CEditView::GetColorIndex( const CLayout* pcLayout, CLayoutYInt nLineNum, int nIndex, SColorStrategyInfo* pInfo, // 2010.03.31 ryoji 追加 bool bPrev // 指定位置の色変更直前まで 2010.06.19 ryoji 追加 ) { EColorIndexType eRet = COLORIDX_TEXT; if(!pcLayout){ CColor3Setting cColor = { COLORIDX_TEXT, COLORIDX_TEXT, COLORIDX_TEXT }; return cColor; } // 2014.12.30 Skipモードの時もCOLORIDX_TEXT if (CColorStrategyPool::getInstance()->IsSkipBeforeLayout()) { CColor3Setting cColor = { COLORIDX_TEXT, COLORIDX_TEXT, COLORIDX_TEXT }; return cColor; } const CLayoutColorInfo* colorInfo; const CLayout* pcLayoutLineFirst = pcLayout; CLayoutYInt nLineNumFirst = nLineNum; { // 2002/2/10 aroka CMemory変更 pInfo->m_pLineOfLogic = pcLayout->GetDocLineRef()->GetPtr(); // 論理行の最初のレイアウト情報を取得 -> pcLayoutLineFirst while( 0 != pcLayoutLineFirst->GetLogicOffset() ){ pcLayoutLineFirst = pcLayoutLineFirst->GetPrevLayout(); nLineNumFirst--; // 論理行の先頭まで戻らないと確実には正確な色は得られない // (正規表現キーワードにマッチした長い強調表示がその位置のレイアウト行頭をまたいでいる場合など) //if( pcLayout->GetLogicOffset() - pcLayoutLineFirst->GetLogicOffset() > 260 ) // break; } // 2005.11.20 Moca 色が正しくないことがある問題に対処 eRet = pcLayoutLineFirst->GetColorTypePrev(); /* 現在の色を指定 */ // 02/12/18 ai colorInfo = pcLayoutLineFirst->GetColorInfo(); pInfo->m_nPosInLogic = pcLayoutLineFirst->GetLogicOffset(); //CColorStrategyPool初期化 CColorStrategyPool* pool = CColorStrategyPool::getInstance(); pool->SetCurrentView(this); pool->NotifyOnStartScanLogic(); // 2009.02.07 ryoji この関数では pInfo->CheckChangeColor() で色を調べるだけなので以下の処理は不要 // ////############超仮。本当はVisitorを使うべき //class TmpVisitor{ //public: // static int CalcLayoutIndex(const CLayout* pcLayout) // { // int n = -1; // while(pcLayout){ // pcLayout = pcLayout->GetPrevLayout(); //prev or null // n++; // } // return n; // } //}; //pInfo->pDispPos->SetLayoutLineRef(CLayoutInt(TmpVisitor::CalcLayoutIndex(pcLayout))); // 2013.12.11 Moca カレント行の色替えで必要になりました pInfo->m_pDispPos->SetLayoutLineRef(nLineNumFirst); } //文字列参照 const CDocLine* pcDocLine = pcLayout->GetDocLineRef(); CStringRef cLineStr(pcDocLine->GetPtr(),pcDocLine->GetLengthWithEOL()); //color strategy CColorStrategyPool* pool = CColorStrategyPool::getInstance(); pInfo->m_pStrategy = pool->GetStrategyByColor(eRet); if(pInfo->m_pStrategy){ pInfo->m_pStrategy->InitStrategyStatus(); pInfo->m_pStrategy->SetStrategyColorInfo(colorInfo); } const CLayout* pcLayoutNext = pcLayoutLineFirst->GetNextLayout(); CLayoutYInt nLineNumScan = nLineNumFirst; int nPosTo = pcLayout->GetLogicOffset() + t_min(nIndex, (int)pcLayout->GetLengthWithEOL() - 1); while(pInfo->m_nPosInLogic <= nPosTo){ if( bPrev && pInfo->m_nPosInLogic == nPosTo ) break; //色切替 pInfo->CheckChangeColor(cLineStr); //1文字進む pInfo->m_nPosInLogic += CNativeW::GetSizeOfChar( cLineStr.GetPtr(), cLineStr.GetLength(), pInfo->m_nPosInLogic ); if( pcLayoutNext && pcLayoutNext->GetLogicOffset() <= pInfo->m_nPosInLogic ){ nLineNumScan++; pInfo->m_pDispPos->SetLayoutLineRef(nLineNumScan); pcLayoutNext = pcLayoutNext->GetNextLayout(); } } CColor3Setting cColor; pInfo->DoChangeColor(&cColor); return cColor; }
void CEditView::DrawBackImage(HDC hdc, RECT& rcPaint, HDC hdcBgImg) { #if 0 // テスト背景パターン static int testColorIndex = 0; testColorIndex = testColorIndex % 7; COLORREF cols[7] = {RGB(255,255,255), RGB(200,255,255),RGB(255,200,255),RGB(255,255,200), RGB(200,200,255),RGB(255,200,200),RGB(200,255,200), }; COLORREF colorOld = ::SetBkColor(hdc, cols[testColorIndex]); MyFillRect(hdc, rcPaint); ::SetBkColor(hdc, colorOld); testColorIndex++; #else CTypeSupport cTextType(this,COLORIDX_TEXT); COLORREF colorOld = ::SetBkColor(hdc, cTextType.GetBackColor()); const CTextArea& area = GetTextArea(); const CEditDoc& doc = *m_pcEditDoc; const STypeConfig& typeConfig = doc.m_cDocType.GetDocumentAttribute(); CMyRect rcImagePos; switch( typeConfig.m_backImgPos ){ case BGIMAGE_TOP_LEFT: case BGIMAGE_BOTTOM_LEFT: case BGIMAGE_CENTER_LEFT: rcImagePos.left = area.GetAreaLeft(); break; case BGIMAGE_TOP_RIGHT: case BGIMAGE_BOTTOM_RIGHT: case BGIMAGE_CENTER_RIGHT: rcImagePos.left = area.GetAreaRight() - doc.m_nBackImgWidth; break; case BGIMAGE_TOP_CENTER: case BGIMAGE_BOTTOM_CENTER: case BGIMAGE_CENTER: rcImagePos.left = area.GetAreaLeft() + area.GetAreaWidth()/2 - doc.m_nBackImgWidth/2; break; default: assert_warning(0 != typeConfig.m_backImgPos); break; } switch( typeConfig.m_backImgPos ){ case BGIMAGE_TOP_LEFT: case BGIMAGE_TOP_RIGHT: case BGIMAGE_TOP_CENTER: rcImagePos.top = area.GetAreaTop(); break; case BGIMAGE_BOTTOM_LEFT: case BGIMAGE_BOTTOM_RIGHT: case BGIMAGE_BOTTOM_CENTER: rcImagePos.top = area.GetAreaBottom() - doc.m_nBackImgHeight; break; case BGIMAGE_CENTER_LEFT: case BGIMAGE_CENTER_RIGHT: case BGIMAGE_CENTER: rcImagePos.top = area.GetAreaTop() + area.GetAreaHeight()/2 - doc.m_nBackImgHeight/2; break; default: assert_warning(0 != typeConfig.m_backImgPos); break; } rcImagePos.left += typeConfig.m_backImgPosOffset.x; rcImagePos.top += typeConfig.m_backImgPosOffset.y; // スクロール時の画面の端を作画するときの位置あたりへ移動 if( typeConfig.m_backImgScrollX ){ int tile = typeConfig.m_backImgRepeatX ? doc.m_nBackImgWidth : INT_MAX; Int posX = (area.GetViewLeftCol() % tile) * GetTextMetrics().GetCharPxWidth(); rcImagePos.left -= posX % tile; } if( typeConfig.m_backImgScrollY ){ int tile = typeConfig.m_backImgRepeatY ? doc.m_nBackImgHeight : INT_MAX; Int posY = (area.GetViewTopLine() % tile) * GetTextMetrics().GetHankakuDy(); rcImagePos.top -= posY % tile; } if( typeConfig.m_backImgRepeatX ){ if( 0 < rcImagePos.left ){ // rcImagePos.left = rcImagePos.left - (rcImagePos.left / doc.m_nBackImgWidth + 1) * doc.m_nBackImgWidth; rcImagePos.left = rcImagePos.left % doc.m_nBackImgWidth - doc.m_nBackImgWidth; } } if( typeConfig.m_backImgRepeatY ){ if( 0 < rcImagePos.top ){ // rcImagePos.top = rcImagePos.top - (rcImagePos.top / doc.m_nBackImgHeight + 1) * doc.m_nBackImgHeight; rcImagePos.top = rcImagePos.top % doc.m_nBackImgHeight - doc.m_nBackImgHeight; } } rcImagePos.SetSize(doc.m_nBackImgWidth, doc.m_nBackImgHeight); RECT rc = rcPaint; // rc.left = t_max((int)rc.left, area.GetAreaLeft()); rc.top = t_max((int)rc.top, area.GetRulerHeight()); // ルーラーを除外 const int nXEnd = area.GetAreaRight(); const int nYEnd = area.GetAreaBottom(); CMyRect rcBltAll; rcBltAll.SetLTRB(INT_MAX, INT_MAX, -INT_MAX, -INT_MAX); CMyRect rcImagePosOrg = rcImagePos; for(; rcImagePos.top <= nYEnd; ){ for(; rcImagePos.left <= nXEnd; ){ CMyRect rcBlt; if( ::IntersectRect(&rcBlt, &rc, &rcImagePos) ){ ::BitBlt( hdc, rcBlt.left, rcBlt.top, rcBlt.right - rcBlt.left, rcBlt.bottom - rcBlt.top, hdcBgImg, rcBlt.left - rcImagePos.left, rcBlt.top - rcImagePos.top, SRCCOPY ); rcBltAll.left = t_min(rcBltAll.left, rcBlt.left); rcBltAll.top = t_min(rcBltAll.top, rcBlt.top); rcBltAll.right = t_max(rcBltAll.right, rcBlt.right); rcBltAll.bottom = t_max(rcBltAll.bottom, rcBlt.bottom); } rcImagePos.left += doc.m_nBackImgWidth; rcImagePos.right += doc.m_nBackImgWidth; if( !typeConfig.m_backImgRepeatX ){ break; } } rcImagePos.left = rcImagePosOrg.left; rcImagePos.right = rcImagePosOrg.right; rcImagePos.top += doc.m_nBackImgHeight; rcImagePos.bottom += doc.m_nBackImgHeight; if( !typeConfig.m_backImgRepeatY ){ break; } } if( rcBltAll.left != INT_MAX ){ // 上下左右ななめの隙間を埋める CMyRect rcFill; LONG& x1 = rc.left; LONG& x2 = rcBltAll.left; LONG& x3 = rcBltAll.right; LONG& x4 = rc.right; LONG& y1 = rc.top; LONG& y2 = rcBltAll.top; LONG& y3 = rcBltAll.bottom; LONG& y4 = rc.bottom; if( y1 < y2 ){ rcFill.SetLTRB(x1,y1, x4,y2); MyFillRect(hdc, rcFill); } if( x1 < x2 ){ rcFill.SetLTRB(x1,y2, x2,y3); MyFillRect(hdc, rcFill); } if( x3 < x4 ){ rcFill.SetLTRB(x3,y2, x4,y3); MyFillRect(hdc, rcFill); } if( y3 < y4 ){ rcFill.SetLTRB(x1,y3, x4,y4); MyFillRect(hdc, rcFill); } }else{ MyFillRect(hdc, rc); } ::SetBkColor(hdc, colorOld); #endif }
cString basicInput::readUnicodeNullString(const uint numberOfCharacter /* = MAX_CHAR */) { cString ret(nil, t_min(numberOfCharacter, (uint)cString::DefaultStringPage)); readUnicodeString(ret, 0, numberOfCharacter); return ret; }
cString basicInput::readAsciiDosString(const uint numberOfCharacter /* = MAX_CHAR */) { cString ret(nil, t_min(numberOfCharacter, (uint)cString::DefaultStringPage)); readAsciiString(ret, '$', numberOfCharacter); return ret; }
/* コマンド一覧 */ void CViewCommander::Command_MENU_ALLFUNC( void ) { UINT uFlags; POINT po; RECT rc; HMENU hMenu; HMENU hMenuPopUp; int i; int j; int nId; // From Here Sept. 15, 2000 JEPRO // サブメニュー、特に「その他」のコマンドに対してステータスバーに表示されるキーアサイン情報が // メニューで隠れないように右にずらした // (本当はこの「コマンド一覧」メニューをダイアログに変更しバーをつまんで自由に移動できるようにしたい) // po.x = 0; po.x = 540; // To Here Sept. 15, 2000 (Oct. 7, 2000 300→500; Nov. 3, 2000 500→540) po.y = 0; CEditWnd* pCEditWnd = GetEditWindow(); // Sep. 10, 2002 genta ::GetClientRect( pCEditWnd->GetHwnd(), &rc ); po.x = t_min( po.x, rc.right ); ::ClientToScreen( pCEditWnd->GetHwnd(), &po ); ::GetWindowRect( pCEditWnd->m_cSplitterWnd.GetHwnd() , &rc ); po.y = rc.top; pCEditWnd->GetMenuDrawer().ResetContents(); // Oct. 3, 2001 genta CFuncLookup& FuncLookup = GetDocument()->m_cFuncLookup; hMenu = ::CreatePopupMenu(); //Oct. 14, 2000 JEPRO 「--未定義--」を表示させないように変更したことで1番(カーソル移動系)が前にシフトされた(この変更によって i=1→i=0 と変更) // Oct. 3, 2001 genta for( i = 0; i < FuncLookup.GetCategoryCount(); i++ ){ hMenuPopUp = ::CreatePopupMenu(); for( j = 0; j < FuncLookup.GetItemCount(i); j++ ){ // Oct. 3, 2001 genta int code = FuncLookup.Pos2FuncCode( i, j, false ); // 2007.11.02 ryoji 未登録マクロ非表示を明示指定 if( code != 0 ){ WCHAR szLabel[300]; FuncLookup.Pos2FuncName( i, j, szLabel, 256 ); uFlags = MF_BYPOSITION | MF_STRING | MF_ENABLED; // Oct. 3, 2001 genta pCEditWnd->GetMenuDrawer().MyAppendMenu( hMenuPopUp, uFlags, code, szLabel, L"" ); } } // Oct. 3, 2001 genta pCEditWnd->GetMenuDrawer().MyAppendMenu( hMenu, MF_BYPOSITION | MF_STRING | MF_POPUP, (UINT_PTR)hMenuPopUp , FuncLookup.Category2Name(i) , _T("")); // pCEditWnd->GetMenuDrawer().MyAppendMenu( hMenu, MF_BYPOSITION | MF_STRING | MF_POPUP, (UINT)hMenuPopUp , nsFuncCode::ppszFuncKind[i] ); } nId = ::TrackPopupMenu( hMenu, TPM_TOPALIGN | TPM_LEFTALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON , po.x, po.y, 0, GetMainWindow()/*GetHwnd()*/, NULL ); ::DestroyMenu( hMenu ); if( 0 != nId ){ /* コマンドコードによる処理振り分け */ // HandleCommand( nFuncID, true, 0, 0, 0, 0 ); ::PostMessageCmd( GetMainWindow(), WM_COMMAND, MAKELONG( nId, 0 ), (LPARAM)NULL ); } return; }
/* * Start the testing */ int main(int argc, const char** argv) { uint i; uint totalAllocated = 0; uint8* pointers[MAX_POINTERS]; for (i = 0; i < MAX_POINTERS; i++) { pointers[i] = NULL; } cOSDef::systemTime start = cOS::getSystemTime(); #ifdef FAST_ALLOCATE_DELETE_TEST // Second test: How fast is operator new/delete... cList<Data> m_ptr; for (i = 0; i < 100000; i++) { if ((cOS::rand() & 1) == 1) { uint length = (cOS::rand() % MAX_POINTERS) + 1; length = t_min(length, XdkMemoryTestSingleton::getManagerMemoryLength() - totalAllocated); if (length != 0) { Data data; data.size = length; data.ptr = new uint8[length]; if (data.ptr != NULL) { m_ptr.append(data); totalAllocated+= length; } else { cout << "$"; cout.flush(); } } } if ((cOS::rand() & 1) == 1) { if (m_ptr.begin() != m_ptr.end()) { Data data = *m_ptr.begin(); delete[] data.ptr; totalAllocated-= data.size; m_ptr.remove(m_ptr.begin()); } } if ((i % 0x1FF) == 0) { cout << "."; cout.flush(); } } #else // First test: Random allocation and filling... uint pointersLength[MAX_POINTERS]; // The loop for (i = 0; i < 100000; i++) { if ((cOS::rand() & 1) == 1) { // Allocate uint ptr = 0; for (; ptr < MAX_POINTERS; ptr++) { if (pointers[ptr] == NULL) { uint length = (cOS::rand() % MAX_POINTERS) + 1; length = t_min(length, XdkMemoryTestSingleton::getManagerMemoryLength() - totalAllocated); if (length == 0) break; totalAllocated+= length; pointersLength[ptr] = length; pointers[ptr] = new uint8[length]; #ifdef TEST_INTERNAL_BLOCKS memset(pointers[ptr], (uint8)pointersLength[ptr], length); #endif // TEST_INTERNAL_BLOCKS break; } } } else { // Free for (uint k = 0; k < 10; k++) { uint ptr = cOS::rand() % MAX_POINTERS; if (pointers[ptr] != NULL) { // Test memory bool ok = true; #ifdef TEST_INTERNAL_BLOCKS for (uint x = 0; x < pointersLength[ptr]; x++) ok = ok && (pointers[ptr][x] == (uint8)pointersLength[ptr]); CHECK(ok); #endif // TEST_INTERNAL_BLOCKS // Free it totalAllocated-= pointersLength[ptr]; delete[] pointers[ptr]; pointers[ptr] = NULL; if ((cOS::rand() & 1) == 1) break; } } } // Test #ifdef TEST_INTERNAL_BLOCKS if ((i & 0x1F) == 0x1F) { bool ok = true; for (uint j = 0; j < MAX_POINTERS; j++) { if (pointers[j] != NULL) for (uint x = 0; x < pointersLength[j]; x++) ok = ok && (pointers[j][x] == (uint8)pointersLength[j]); } CHECK(ok); } #endif // TEST_INTERNAL_BLOCKS if ((i % 0x1FF) == 0) { cout << "."; cout.flush(); } } #endif // FAST_ALLOCATE_DELETE_TEST uint timePassed = cOS::calculateTimesDiffMilli(cOS::getSystemTime(), start); cout << endl; cout << "Number of milliseconds pass: "******"Seconds: " << timePassed / 1000 << endl; cout << "Minutes: " << timePassed / (1000 * 60) << endl; return 0; }