/// Performs deserialization for the class /// @param stream Power Tab input stream to load from /// @param version File version /// @return True if the object was deserialized, false if not bool ChordDiagram::DoDeserialize(PowerTabInputStream& stream, wxWord version) { //------Last Checked------// // - Jan 14, 2005 m_chordName.Deserialize(stream, version); wxCHECK(stream.CheckState(), false); stream >> m_topFret; wxCHECK(stream.CheckState(), false); wxByte count = 0; stream >> count; wxCHECK(stream.CheckState(), false); size_t i = 0; for (; i < count; i++) { wxByte fretNumber = 0; stream >> fretNumber; wxCHECK(stream.CheckState(), false); m_fretNumberArray.Add(fretNumber); } return (true); }
// forward the message to the appropriate item bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT *item) { // only owner-drawn control should receive this message wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), false ); DRAWITEMSTRUCT *pStruct = (DRAWITEMSTRUCT *)item; UINT itemID = pStruct->itemID; // the item may be -1 for an empty listbox if ( itemID == (UINT)-1 ) return false; long data = ListBox_GetItemData(GetHwnd(), pStruct->itemID); wxCHECK( data && (data != LB_ERR), false ); wxListBoxItem *pItem = (wxListBoxItem *)data; wxDCTemp dc((WXHDC)pStruct->hDC); wxPoint pt1(pStruct->rcItem.left, pStruct->rcItem.top); wxPoint pt2(pStruct->rcItem.right, pStruct->rcItem.bottom); wxRect rect(pt1, pt2); return pItem->OnDrawItem(dc, rect, (wxOwnerDrawn::wxODAction)pStruct->itemAction, (wxOwnerDrawn::wxODStatus)pStruct->itemState); }
/// Passes the results of a test to the test suite callback function /// @param record Indicates whether or note the results of the test should be recorded to the results tree ctrl if the test was successful /// @param startTime The time when the test was started /// @param testName Name of the test /// @param success Indicates the success/failure of the test /// @param fileName Name of the file where the test occurred /// @param lineNumber Line number in the file where the test occurred bool TestSuite::Test(bool record, wxLongLong startTime, const wxChar* testName, bool success, char* fileName, size_t lineNumber) { //------Last Checked------// // - Dec 2, 2004 // Calculate the time to execute the test (in seconds) wxLongLong span = ::wxGetLocalTimeMillis() - startTime; double executionTime = ((double)span.ToLong()) / 1000.0; // If the test suite isn't being executed, bail out if (!IsExecuted()) return (false); // Update the success or failure of the test if (success) m_passed++; else m_failed++; wxCHECK(testName != NULL, false); wxCHECK(fileName != NULL, false); wxCHECK(m_testSuiteCallback != NULL, false); // Create a temp string used for the filename (since it's ANSI and we want it this to work on Unicode builds) wxString tempFileName(fileName); // Send the results of the test to the callback return (m_testSuiteCallback(this, testName, success, tempFileName, lineNumber, record, executionTime, m_clientData)); }
// Overrides bool PowerTabView::OnCreate(wxDocument *doc, long flags) { //------Last Checked------// // - Jan 27, 2005 WXUNUSED(flags); MainFrame* mainFrame = GetMainFrame(); wxCHECK(mainFrame != NULL, false); m_frame = mainFrame->CreateChildFrame(doc, this); wxCHECK(m_frame != NULL, false); m_frame->SetTitle(wxT("PowerTabView")); m_canvas = CreateCanvas(this, m_frame); wxCHECK(m_canvas != NULL, false); #ifdef __X__ // X seems to require a forced resize int x, y; m_frame->GetSize(&x, &y); m_frame->SetSize(-1, -1, x, y); #endif m_frame->Show(true); Activate(true); return (true); }
// Overrides bool PowerTabTuningView::OnCreate(wxDocument* doc, long flags) { //------Last Checked------// // - Dec 30, 2004 WXUNUSED(flags); MainFrame* mainFrame = GetMainFrame(); wxCHECK(mainFrame != NULL, false); m_frame = mainFrame->CreateChildFrame(doc, this); wxCHECK(m_frame != NULL, false); m_window = CreateViewWindow(); wxCHECK(m_window != NULL, false); #ifdef __X__ // X seems to require a forced resize int x, y; m_frame->GetSize(&x, &y); m_frame->SetSize(-1, -1, x, y); #endif m_frame->Show(true); Activate(true); return (true); }
// Fret Number Functions /// Sets the fret number for an existing string in the chordDiagram /// @param string String to set the fret number for /// @param fretNumber Fret number to set /// @return True if the fret number was set, false if not bool ChordDiagram::SetFretNumber(wxUint32 string, wxByte fretNumber) { //------Last Checked------// // - Jan 15, 2005 wxCHECK(IsValidString(string), false); wxCHECK(IsValidFretNumber(fretNumber), false); m_fretNumberArray[string] = fretNumber; return (true); }
bool wxPropertyGridInterface::SetColumnProportion( unsigned int column, int proportion ) { wxCHECK(m_pState, false); wxPropertyGrid* pg = m_pState->GetGrid(); wxCHECK(pg, false); wxCHECK(pg->HasFlag(wxPG_SPLITTER_AUTO_CENTER), false); m_pState->DoSetColumnProportion(column, proportion); return true; }
bool CXmlFile::Save(wxString* error) { wxCHECK(m_fileName.IsOk(), false); wxCHECK(m_pDocument, false); bool res = SaveXmlFile(m_fileName, GetElement(), error); wxLogNull log; m_modificationTime = m_fileName.GetModificationTime(); return res; }
// Serialization Functions /// Performs serialization for the class /// @param stream Power Tab output stream to serialize to /// @return True if the object was serialized, false if not bool ChordText::DoSerialize(PowerTabOutputStream& stream) { //------Last Checked------// // - Jan 3, 2005 stream << m_position; wxCHECK(stream.CheckState(), false); m_chordName.Serialize(stream); wxCHECK(stream.CheckState(), false); return (stream.CheckState()); }
int wxStatusBarEx::GetFieldIndex(int field) { if (field >= 0) { wxCHECK(field <= GetFieldsCount(), -1); } else { field = GetFieldsCount() + field; wxCHECK(field >= 0, -1); } return field; }
bool wxTreeMultiXmlMapper::InitWizard(const wxFileName &xmlfile, const wxString &start_tag) { wxCHECK(m_ctrl, false); // create a new XML document InitXML(); wxCHECK(m_tiDoc, false); // load the contents from disk if(m_tiDoc->LoadFile(xmlfile.GetFullPath().c_str())) return DoInitWizard(start_tag); return false; }
bool wxTreeMultiXmlMapper::InitWizard(const wxString &xmlstring, const wxString &start_tag) { wxCHECK(m_ctrl, false); InitXML(); wxCHECK(m_tiDoc, false); // parse given XML string m_tiDoc->Parse(xmlstring.c_str()); if(!m_tiDoc->Error()) return DoInitWizard(start_tag); return false; }
// Serialize Functions /// Performs serialization for the class /// @param stream Power Tab output stream to serialize to /// @return True if the object was serialized, false if not bool System::DoSerialize(PowerTabOutputStream& stream) { //------Last Checked------// // - Jan 14, 2005 stream.WriteMFCRect(m_rect); wxCHECK(stream.CheckState(), false); // Note: End bar is stored as a byte; we use Barline class to make it easier // for the user wxByte endBar = (wxByte)((m_endBar.GetType() << 5) | (m_endBar.GetRepeatCount())); stream << endBar << m_positionSpacing << m_rhythmSlashSpacingAbove << m_rhythmSlashSpacingBelow << m_extraSpacing; wxCHECK(stream.CheckState(), false); m_startBar.Serialize(stream); wxCHECK(stream.CheckState(), false); m_directionArray.Serialize(stream); wxCHECK(stream.CheckState(), false); m_chordTextArray.Serialize(stream); wxCHECK(stream.CheckState(), false); m_rhythmSlashArray.Serialize(stream); wxCHECK(stream.CheckState(), false); m_staffArray.Serialize(stream); wxCHECK(stream.CheckState(), false); m_barlineArray.Serialize(stream); wxCHECK(stream.CheckState(), false); return (stream.CheckState()); }
// Serialization Functions /// Performs deserialization for the class /// @param stream Power Tab input stream to load from /// @param version File version /// @return True if the object was deserialized, false if not bool OldRehearsalSign::DoDeserialize(PowerTabInputStream& stream, wxWord version) { //------Last Checked------// // - Dec 29, 2004 WXUNUSED(version); stream >> m_system >> m_position >> m_data >> m_letter; wxCHECK(stream.CheckState(), false); stream.ReadMFCString(m_description); wxCHECK(stream.CheckState(), false); return (stream.CheckState()); }
// recursive CAICHHashTree* CAICHHashTree::FindHash(uint64 nStartPos, uint64 nSize, uint8* nLevel) { (*nLevel)++; wxCHECK(*nLevel <= 22, NULL); wxCHECK(nStartPos + nSize <= m_nDataSize, NULL); wxCHECK(nSize <= m_nDataSize, NULL); if (nStartPos == 0 && nSize == m_nDataSize) { // this is the searched hash return this; } else if (m_nDataSize <= m_nBaseSize) { // sanity // this is already the last level, cant go deeper wxFAIL; return NULL; } else { uint64 nBlocks = m_nDataSize / m_nBaseSize + ((m_nDataSize % m_nBaseSize != 0 )? 1:0); uint64 nLeft = (((m_bIsLeftBranch) ? nBlocks+1:nBlocks) / 2)* m_nBaseSize; uint64 nRight = m_nDataSize - nLeft; if (nStartPos < nLeft) { if (nStartPos + nSize > nLeft) { // sanity wxFAIL; return NULL; } if (m_pLeftTree == NULL) { m_pLeftTree = new CAICHHashTree(nLeft, true, (nLeft <= PARTSIZE) ? EMBLOCKSIZE : PARTSIZE); } else { wxASSERT( m_pLeftTree->m_nDataSize == nLeft ); } return m_pLeftTree->FindHash(nStartPos, nSize, nLevel); } else { nStartPos -= nLeft; if (nStartPos + nSize > nRight) { // sanity wxFAIL; return NULL; } if (m_pRightTree == NULL) { m_pRightTree = new CAICHHashTree(nRight, false, (nRight <= PARTSIZE) ? EMBLOCKSIZE : PARTSIZE); } else { wxASSERT( m_pRightTree->m_nDataSize == nRight ); } return m_pRightTree->FindHash(nStartPos, nSize, nLevel); } } }
/// Performs serialization for the class /// @param stream Power Tab output stream to serialize to /// @return True if the object was serialized, false if not bool FontSetting::DoSerialize(PowerTabOutputStream& stream) { //------Last Checked------// // - Dec 5, 2004 stream.WriteMFCString(m_faceName); wxCHECK(stream.CheckState(), false); stream << m_pointSize << m_weight << m_italic << m_underline << m_strikeOut; wxCHECK(stream.CheckState(), false); stream.WriteWin32ColorRef(m_color); wxCHECK(stream.CheckState(), false); return (stream.CheckState()); }
/// Performs deserialization for the class /// @param stream Power Tab input stream to load from /// @param version File version /// @return True if the object was deserialized, false if not bool FontSetting::DoDeserialize(PowerTabInputStream& stream, wxWord version) { //------Last Checked------// // - Dec 5, 2004 stream.ReadMFCString(m_faceName); wxCHECK(stream.CheckState(), false); stream >> m_pointSize >> m_weight >> m_italic >> m_underline >> m_strikeOut; wxCHECK(stream.CheckState(), false); stream.ReadWin32ColorRef(m_color); wxCHECK(stream.CheckState(), false); return (stream.CheckState()); }
/// Inserts the columns used by the list control /// @return True if the columns were inserted, false if not bool PowerTabTuningViewWindow::InsertColumns() { //------Last Checked------// // - Dec 30, 2004 InsertColumn(COLUMN_NAME, wxT("Name")); wxCHECK(GetColumnCount() == 1, false); InsertColumn(COLUMN_STRINGS, wxT("Strings"), wxLIST_FORMAT_CENTER); wxCHECK(GetColumnCount() == 2, false); InsertColumn(COLUMN_SPELLING, wxT("Spelling")); wxCHECK(GetColumnCount() == 3, false); return (true); }
// NB: can't forward this to wxListBoxItem because LB_SETITEMDATA // message is not yet sent when we get here! bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT *item) { // only owner-drawn control should receive this message wxCHECK( HasFlag(wxLB_OWNERDRAW), false ); MEASUREITEMSTRUCT *pStruct = (MEASUREITEMSTRUCT *)item; #ifdef __WXWINCE__ HDC hdc = GetDC(NULL); #else HDC hdc = CreateIC(wxT("DISPLAY"), NULL, NULL, 0); #endif { wxDCTemp dc((WXHDC)hdc); dc.SetFont(GetFont()); pStruct->itemHeight = dc.GetCharHeight() + 2 * LISTBOX_EXTRA_SPACE; pStruct->itemWidth = dc.GetCharWidth(); } #ifdef __WXWINCE__ ReleaseDC(NULL, hdc); #else DeleteDC(hdc); #endif return true; }
pugi::xml_node CXmlFile::Load() { Close(); m_error.clear(); wxCHECK(!m_fileName.empty(), m_element); std::wstring redirectedName = GetRedirectedName(); GetXmlFile(redirectedName); if (!m_element) { wxString err = wxString::Format(_("The file '%s' could not be loaded."), m_fileName); if (m_error.empty()) { err += wxString(_T("\n")) + _("Make sure the file can be accessed and is a well-formed XML document."); } else { err += _T("\n") + m_error; } // Try the backup file GetXmlFile(redirectedName + _T("~")); if (!m_element) { // Loading backup failed. If both original and backup file are empty, create new file. if (fz::local_filesys::get_size(fz::to_native(redirectedName)) <= 0 && fz::local_filesys::get_size(fz::to_native(redirectedName + _T("~"))) <= 0) { m_error.clear(); CreateEmpty(); m_modificationTime = fz::local_filesys::get_modification_time(fz::to_native(redirectedName)); return m_element; } // File corrupt and no functional backup, give up. m_error = err; m_modificationTime.clear(); return m_element; } // Loading the backup file succeeded, restore file bool res; { wxLogNull null; res = wxCopyFile(redirectedName + _T("~"), redirectedName); } if (!res) { // Could not restore backup, give up. Close(); m_error = err.ToStdWstring(); m_error += _T("\n") + wxString::Format(_("The valid backup file %s could not be restored"), redirectedName + _T("~")).ToStdWstring(); m_modificationTime.clear(); return m_element; } // We no longer need the backup wxRemoveFile(redirectedName + _T("~")); m_error.clear(); } m_modificationTime = fz::local_filesys::get_modification_time(fz::to_native(redirectedName)); return m_element; }
const wxChar *wxRegKey::GetStdKeyShortName(size_t key) { // return empty string if key is invalid wxCHECK( key < nStdKeys, wxEmptyString ); return aStdKeys[key].szShortName; }
// Number Functions /// Converts an arabic number to it's roman numeral equivalent /// @param number Number to convert /// @param upperCase If true, forces the roman numeral to upper case /// @return Roman numeral wxString wxArabicToRoman(wxInt32 number, bool upperCase) { //------Last Checked------// // - Dec 7, 2004 // Can only convert 1 to 5999 wxCHECK(((number > 0) && (number < 6000)), wxT("")); wxString returnValue; while (number >= 1000) {number -= 1000; returnValue += wxT("m");} while (number >= 900) {number -= 900; returnValue += wxT("cm");} while (number >= 500) {number -= 500; returnValue += wxT("d");} while (number >= 400) {number -= 400; returnValue += wxT("cd");} while (number >= 100) {number -= 100; returnValue += wxT("c");} while (number >= 90) {number -= 90; returnValue += wxT("xc");} while (number >= 50) {number -= 50; returnValue += wxT("l");} while (number >= 40) {number -= 40; returnValue += wxT("xl");} while (number >= 10) {number -= 10; returnValue += wxT("x");} while (number >= 9) {number -= 9; returnValue += wxT("ix");} while (number >= 5) {number -= 5; returnValue += wxT("v");} while (number >= 4) {number -= 4; returnValue += wxT("iv");} while (number >= 1) {number -= 1; returnValue += wxT("i");} // Force the text to upper case if (upperCase) returnValue.MakeUpper(); return (returnValue); }
/// Extracts the nth substring from a delimited string /// This is a wxWidgets port of MFC's AfxExtractSubString /// @param string Holds the returned substring /// @param fullString String to extract the substring from /// @param subString Zero-based index of the substring to extract /// @param separator Character used to separator the substrings /// @return True if the substring was extracted, false if not bool wxExtractSubString(wxString& string, const wxChar* fullString, wxUint32 subString, wxChar separator) { //------Last Verified------// // - Nov 27, 2004 wxCHECK(fullString != (wxChar*)NULL, false); string.Clear(); while (subString--) { fullString = wxStrchr(fullString, separator); if (fullString == NULL) { string.Clear(); // return empty string as well return (false); } fullString++; // point past the separator } const wxChar* end = wxStrchr(fullString, separator); wxInt32 length = (end == NULL) ? wxStrlen_(fullString) : (wxInt32)(end - fullString); wxASSERT(length >= 0); memcpy(string.GetWriteBuf(length), fullString, length * sizeof(wxChar)); string.UngetWriteBuf(); // Need to call ReleaseBuffer // after calling GetBufferSetLength return (true); }
// allocates memory needed to store a C string of length nLen bool wxStringImpl::AllocBuffer(size_t nLen) { // allocating 0 sized buffer doesn't make sense, all empty strings should // reuse g_strEmpty wxASSERT( nLen > 0 ); // make sure that we don't overflow wxCHECK( nLen < (INT_MAX / sizeof(wxStringCharType)) - (sizeof(wxStringData) + EXTRA_ALLOC + 1), false ); STATISTICS_ADD(Length, nLen); // allocate memory: // 1) one extra character for '\0' termination // 2) sizeof(wxStringData) for housekeeping info wxStringData* pData = (wxStringData*) malloc(sizeof(wxStringData) + (nLen + EXTRA_ALLOC + 1)*sizeof(wxStringCharType)); if ( pData == NULL ) { // allocation failures are handled by the caller return false; } pData->nRefs = 1; pData->nDataLength = nLen; pData->nAllocLength = nLen + EXTRA_ALLOC; m_pchData = pData->data(); // data starts after wxStringData m_pchData[nLen] = wxT('\0'); return true; }
bool wxNativeContainerWindow::Create(wxNativeContainerWindowHandle win) { wxCHECK( win, false ); if ( !wxTopLevelWindow::Create(NULL, wxID_ANY, "") ) return false; // we need to realize the window first before reparenting it gtk_widget_realize(m_widget); gdk_window_reparent(gtk_widget_get_window(m_widget), win, 0, 0); #ifdef GDK_WINDOWING_X11 // if the native window is destroyed, our own window will be destroyed too // but GTK doesn't expect it and will complain about "unexpectedly // destroyed" GdkWindow, so intercept to DestroyNotify ourselves to fix // this and also destroy the associated C++ object when its window is // destroyed gdk_window_add_filter(gtk_widget_get_window(m_widget), wxNativeContainerWindowFilter, this); #endif // GDK_WINDOWING_X11 // we should be initially visible as we suppose that the native window we // wrap is (we could use gdk_window_is_visible() to test for this but this // doesn't make much sense unless we also react to visibility changes, so // just suppose it's always shown for now) Show(); return true; }
long wxListBox::OS2OnMeasure( WXMEASUREITEMSTRUCT* pItem ) { if (!pItem) pItem = (WXMEASUREITEMSTRUCT*)new OWNERITEM; POWNERITEM pMeasureStruct = (POWNERITEM)pItem; wxScreenDC vDc; // // Only owner-drawn control should receive this message // wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), FALSE ); vDc.SetFont(GetFont()); wxCoord vHeight; wxCoord vWidth; GetSize( &vWidth ,NULL ); pMeasureStruct->rclItem.xRight = (USHORT)vWidth; pMeasureStruct->rclItem.xLeft = 0; pMeasureStruct->rclItem.yTop = 0; pMeasureStruct->rclItem.yBottom = 0; vHeight = (wxCoord)(vDc.GetCharHeight() * 2.5); pMeasureStruct->rclItem.yTop = (USHORT)vHeight; return long(MRFROM2SHORT((USHORT)vHeight, (USHORT)vWidth)); } // end of wxListBox::OS2OnMeasure
TiXmlElement* CXmlFile::Load(const wxFileName& fileName) { if (fileName.IsOk()) SetFileName(fileName); wxCHECK(m_fileName.IsOk(), 0); delete m_pDocument; m_pDocument = 0; TiXmlElement* pElement = GetXmlFile(m_fileName); if (!pElement) { m_modificationTime = wxDateTime(); return 0; } { wxLogNull log; m_modificationTime = m_fileName.GetModificationTime(); } m_pDocument = pElement->GetDocument(); return pElement; }
/// Gets the fret number on a given string /// @param string String to get the fret number for /// @return The fret number on the string wxByte ChordDiagram::GetFretNumber(wxUint32 string) const { //------Last Checked------// // - Jan 15, 2005 wxCHECK(IsValidString(string), 0); return (m_fretNumberArray[string]); }
TiXmlElement* CXmlFile::Load(const wxFileName& fileName) { if (fileName.IsOk()) SetFileName(fileName); wxCHECK(m_fileName.IsOk(), 0); delete m_pDocument; m_pDocument = 0; wxString error; TiXmlElement* pElement = GetXmlFile(m_fileName, &error); if (!pElement) { if (!error.empty()) { m_error.Printf(_("The file '%s' could not be loaded."), m_fileName.GetFullPath().c_str()); if (!error.empty()) m_error += _T("\n") + error; else m_error += wxString(_T("\n")) + _("Make sure the file can be accessed and is a well-formed XML document."); m_modificationTime = wxDateTime(); } return 0; } { wxLogNull log; m_modificationTime = m_fileName.GetModificationTime(); } m_pDocument = pElement->GetDocument(); return pElement; }
wxPGProperty* wxPropertyGridInterface::RemoveProperty( wxPGPropArg id ) { wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty) wxCHECK( !p->GetChildCount() || p->HasFlag(wxPG_PROP_AGGREGATE), wxNullProperty); wxPropertyGridPageState* state = p->GetParentState(); wxPropertyGrid* grid = state->GetGrid(); if ( grid->GetState() == state ) { grid->DoSelectProperty(NULL, wxPG_SEL_DELETING|wxPG_SEL_NOVALIDATE); } state->DoDelete( p, false ); // Mark the property as 'unattached' p->m_parentState = NULL; p->m_parent = NULL; RefreshGrid(state); return p; }