示例#1
0
void AStyleFormat::LoadDynamicLibrary()
// STATIC function to dynamically load the AStyle library.
{
	// check if already loaded
	if (aslib.IsLoaded())
	{
		ShowMessageDialog(wxString::Format(
		                      "AStyle library %s is already loaded!",
		                      GetDynamicLibraryName().c_str()),
		                  wxOK | wxICON_INFORMATION);
		return;
	}
	// load the library
	wxString libName = GetDynamicLibraryName();
	aslib.Load(libName, wxDL_DEFAULT | wxDL_QUIET);
	if (!aslib.IsLoaded())
	{
		ShowMessageDialog(wxString::Format(
		                      "Cannot load the AStyle library:\n%s.\n"
		                      "This must be corrected to format the text!",
		                      libName.c_str()),
		                  wxOK | wxICON_ERROR);
		return;
	}

	// get the AStyleMain address
	fpAStyleMain = (fpASMain) aslib.GetSymbol("AStyleMain");
	if (fpAStyleMain == nullptr)
	{
		ShowMessageDialog(wxString::Format(
		                      "Cannot find the symbol AStyleMain in %s.\n"
		                      "The function must be undecorated in the library.\n"
		                      "This must be corrected to format the text!",
		                      libName.c_str()),
		                  wxOK | wxICON_ERROR);
		return;
	}

	// verify AStyleGetVersion function - the function address is obtained when it is called
	fpAStyleGetVersion = (fpASVer) aslib.GetSymbol("AStyleGetVersion");
	if (fpAStyleGetVersion == nullptr)
	{
		ShowMessageDialog(wxString::Format(
		                      "Cannot find the symbol AStyleGetVersion in %s.\n"
		                      "The function must be undecorated in the library.\n"
		                      "This must be corrected to obtain the version!",
		                      libName.c_str()),
		                  wxOK | wxICON_ERROR);
		return;
	}

	// keep the dynamic library in memory
	aslibHandle = aslib.Detach();
}
示例#2
0
char* AStyleFormat::CallAStyleMain(const char* textIn, const char* options) const
{
#ifdef ASTYLE_DYLIB
	// format using dll dynamic load
	if (fpAStyleMain == nullptr)	// cannot use aslib.IsLoaded() after Detach()
	{
		ShowMessageDialog(wxString::Format(
		                      "Error calling the function AStyleMain.\n"
		                      "The AStyle library %s is not loaded.\n"
		                      "The text cannot be formatted.\n"
		                      "This must be corrected to format the text!",
		                      GetDynamicLibraryName().c_str()),
		                  wxOK | wxICON_ERROR);
		return nullptr;
	}

	char* textOut = fpAStyleMain(textIn,
	                             options,
	                             ErrorHandler,
	                             MemoryAlloc);
#else
	// format using static library
	char* textOut = AStyleMain(textIn,
	                           options,
	                           ErrorHandler,
	                           MemoryAlloc);
#endif	// ASTYLE_DYLIB
	return textOut;
}
示例#3
0
static int messagebubble(int buttonif, const char *message)
{
    sceDisplayWaitVblankStart();
    sceKernelDelayThread(100 * 1000);
    ShowMessageDialog(message, buttonif);
    sceKernelDelayThread(300 * 1000);
    sceUtilityMsgDialogShutdownStart();
    return 1;
}
示例#4
0
void STDCALL AStyleFormat::ErrorHandler(int errorNumber, const char* errorMessage)
// Method to handle error messages from messages from Artistic Style.
// This method is called only if there are errors when AStyleMain is called.
// This is for debugging and there should be no errors when the calling
// parameters are correct.
{
	wxString msgOut = wxString::FromUTF8(errorMessage);
	ShowMessageDialog(wxString::Format("astyle formatting error %d\n%s", errorNumber, msgOut.c_str()),
	                  wxOK | wxICON_ERROR);
}
示例#5
0
void ExportSingleTableDataset(wxWindow* pWnd, const CPLString &sPath, const wxString &sName, wxGxObjectFilter* const pFilter, IGxDataset* const pGxDataset)
{
    wxCHECK_RET(pFilter && pGxDataset, wxT("The input pointer is NULL"));

    wxGISProgressDlg ProgressDlg(_("Exporting..."), _("Begin operation..."), 100, pWnd);
    ProgressDlg.SetAddPercentToMessage(false);
    ProgressDlg.ShowProgress(true);

    wxGISDataset* pDataset = pGxDataset->GetDataset(false, &ProgressDlg);
    wxGISTable* pTable = wxDynamicCast(pDataset, wxGISTable);

    if (NULL == pTable)
    {
        wxMessageBox(_("The table is empty"), _("Error"), wxCENTRE | wxICON_ERROR | wxOK, pWnd);
        wxLogError(_("wxGISFeatureDataset pointer is null returned"));
        return;
    }

    //create progress dialog
    if (!pTable->IsOpened())
    {
        if (!pTable->Open(0, 0, false, &ProgressDlg))
        {
            wxMessageBox(ProgressDlg.GetLastMessage(), _("Error"), wxCENTRE | wxICON_ERROR | wxOK, pWnd);
            wxLogError(ProgressDlg.GetLastMessage());
            wsDELETE(pTable);
            return;
        }
    }

    if (!ExportFormat(pTable, sPath, sName, pFilter, wxGISNullSpatialFilter, NULL, NULL, static_cast<ITrackCancel*>(&ProgressDlg)))
    {
        ShowMessageDialog(pWnd, ProgressDlg.GetWarnings());
    }
    else if (ProgressDlg.GetWarningCount() > 0)
    {
        ShowMessageDialog(pWnd, ProgressDlg.GetWarnings());
    }

    wsDELETE(pTable);
}
示例#6
0
bool AStyleFormat::InsertSelectionMarkers()
// Insert selection markers.
// Beginning marker at end of the PREVIOUS line.
// Ending marker at the end of the last selected line.
{
	assert(m_stc != nullptr);
	int selMin = m_stc->GetSelectionStart();
	int selMax = m_stc->GetSelectionEnd();
	if (selMax == selMin)
	{
		ShowMessageDialog("No text is selected, no text will be formatted!\n"
		                  "The selection may have been removed during processing.",
		                  wxOK | wxICON_ERROR);
		return false;
	}
	int minLine = m_stc->LineFromPosition(selMin);
	int maxLine = m_stc->LineFromPosition(selMax);
	// see if anything is actually selected on the last line
	int selMaxTest = m_stc->PositionFromLine(maxLine);
	if (selMax == selMaxTest)
		--maxLine;
	// insert max marker first so it's position doesn't change
	int selMaxLineEOLPos = m_stc->GetLineEndPosition(maxLine);
	if (m_stc->GetCharAt(selMaxLineEOLPos - 1) == '*')		// don't create '*/'
		m_stc->InsertTextRaw(selMaxLineEOLPos, (' ' + m_maxSelectionMarker).c_str());
	else
		m_stc->InsertTextRaw(selMaxLineEOLPos, m_maxSelectionMarker.c_str());
	// insert min marker at end of the PREVIOUS line
	if (minLine > 0)
	{
		int selMinLineEOLPos = m_stc->GetLineEndPosition(minLine - 1);
		if (m_stc->GetCharAt(selMinLineEOLPos - 1) == '*')		// don't create '*/'
			m_stc->InsertTextRaw(selMinLineEOLPos, (' ' + m_minSelectionMarker).c_str());
		else
			m_stc->InsertTextRaw(selMinLineEOLPos, m_minSelectionMarker.c_str());
	}
	else
	{
		// special handling for line 0
		int eolMode = m_stc->GetEOLMode();
		std::string eol;
		if (eolMode == wxSTC_EOL_CRLF)
			eol = "\r\n";
		else if (eolMode == wxSTC_EOL_LF)
			eol = "\n";
		else
			eol = "\r";
		// insert a new line 0 and flag
		m_stc->InsertTextRaw(0, (m_minSelectionMarker + eol).c_str());
		m_line0Inserted = true;
	}
	return true;
}
示例#7
0
bool AStyleFormat::InsertFormattedText(const char* textOut)
// Insert the output selected formatted text into the original unformatted string.
{
	assert(m_stc != nullptr);
	// find formatted text in the formatted output string
	char* minOut = nullptr;
	char* maxOut = nullptr;
	minOut = strstr(const_cast<char*>(textOut), m_minSelectionMarker.c_str());
	if (minOut != nullptr)
		maxOut = strstr(minOut, m_maxSelectionMarker.c_str());
	if (minOut == nullptr || maxOut == nullptr)
	{
		ShowMessageDialog("Unable to find an output selection marker during replacement!\n"
		                  "The entire document will be replaced for debugging.",
		                  wxOK | wxICON_ERROR);
		m_stc->ClearAll();
		m_stc->SetTextRaw(textOut);
		return false;
	}
	// find original text in the styled text control
	int minSTC = -1;
	int maxSTC = -1;
	minSTC = m_stc->FindText(0, m_stc->GetTextLength(), m_minSelectionMarker, wxSTC_FIND_MATCHCASE);
	if (minSTC >= 0)
		maxSTC = m_stc->FindText(minSTC, m_stc->GetTextLength(), m_maxSelectionMarker, wxSTC_FIND_MATCHCASE);
	if (minSTC < 0 || maxSTC < 0)
	{
		ShowMessageDialog("Unable to find a STC selection marker during replacement!\n"
		                  "The document with markers will be retained for debugging.",
		                  wxOK | wxICON_ERROR);
		return false;
	}
	// replace the original selected text with the formatted text
	wxString selectedTextOut(minOut, wxConvUTF8, maxOut - minOut);
	m_stc->SetTargetStart(minSTC);
	m_stc->SetTargetEnd(maxSTC);
	m_stc->ReplaceTarget(selectedTextOut);
	return true;
}
示例#8
0
void AStyleFormat::RestoreFirstVisibleLine() const
// Remove the first visible line marker and restore the viewing position.
{
	assert(m_stc != nullptr);
	int firstVisibleLine = 0;
	int firstVisiblePosition = m_stc->FindText(
	                               0, m_stc->GetTextLength(), m_firstLineMarker, wxSTC_FIND_MATCHCASE);
	// TODO: fix this
	// formatting removes the beginning space in the marker
	if (firstVisiblePosition < 0)
	{
		wxString zeroPosText = ' ' + m_stc->GetTextRange(
		                           0, static_cast<int>(m_firstLineMarker.length()) - 1);
		if (zeroPosText == m_firstLineMarker)
		{
			firstVisiblePosition = 0;
			m_stc->InsertTextRaw(0, " ");
		}
	}
	// end of fix
	if (firstVisiblePosition >= 0)
	{
		firstVisibleLine = m_stc->LineFromPosition(firstVisiblePosition);
		// there may be a marker after this
		int markerEnd = firstVisiblePosition + static_cast<int>(m_firstLineMarker.length());
		// trim extra whitespace
		wxString whitespaceChars = " \t";
		while ((firstVisiblePosition > 0)
		        && (whitespaceChars.Find(static_cast<wxChar>(
		                                     m_stc->GetCharAt(firstVisiblePosition - 1))) != wxNOT_FOUND))
			--firstVisiblePosition;
		// remove the marker
		m_stc->SetTargetStart(firstVisiblePosition);
		m_stc->SetTargetEnd(markerEnd);
		m_stc->ReplaceTarget(wxEmptyString);
	}
	else
	{
		ShowMessageDialog("Unable to find the visible-line marker!\n"
		                  "The viewing position will not be restored.",
		                  wxOK | wxICON_ERROR);
	}
	// restore the first visible line
	m_stc->SetFirstVisibleLine(firstVisibleLine);
	// set cursor position
	int currentPosOut = m_stc->PositionFromLine(firstVisibleLine);
	m_stc->GotoPos(currentPosOut);
}
示例#9
0
wxString AStyleFormat::GetAStyleVersion() const
{
#ifdef ASTYLE_DYLIB
	// get version using dll dynamic load
	if (fpAStyleGetVersion == nullptr)	// cannot use aslib.IsLoaded() after Detach()
	{
		ShowMessageDialog(wxString::Format(
		                      "Error calling the function AStyleGetVersion.\n"
		                      "The AStyle library %s is not loaded.\n"
		                      "The version cannot be obtained!",
		                      GetDynamicLibraryName().c_str()),
		                  wxOK | wxICON_ERROR);
		return "????";
	}

	const char* versionCStr = fpAStyleGetVersion();
	// convert the version to a unicode string
	wxString version = wxString(versionCStr, wxConvUTF8);
#else
	// get the version as a unicode string
	wxString version = wxString(AStyleGetVersion(), wxConvUTF8);
#endif	// ASTYLE_DYLIB
	return version;
}
示例#10
0
void AStyleFormat::FormatSource(wxStyledTextCtrl* stc, const wxString& optionsWx)
// Format the entire text in the styled text control.
{
	m_stc = stc;
	m_selectionReversed = false;
	m_line0Inserted = false;
	int xOffset = stc->GetXOffset();
	// check if text is selected
#ifdef NDEBUG
	int selMin = stc->GetSelectionStart();
	int selMax = stc->GetSelectionEnd();
	if (selMax - selMin > 4)	// allow slop
	{
		if (ShowMessageDialog("Do you want to format the entire source?",
		                      wxYES_NO  | wxICON_QUESTION) == wxID_NO)
			return;
	}
#endif
	// insert markers
	stc->BeginUndoAction();
	InsertFirstVisibleLineMarker();
	InsertBookmarkMarkers(1, m_bookmark1Marker);
	// format text
	char* textOut = FormatSTCText(optionsWx);
	if (textOut != nullptr)
		m_stc->SetTextRaw(textOut);
	delete [] textOut;
	textOut = nullptr;
	// restore viewing position
	RestoreBookmarks(1, m_bookmark1Marker);
	RestoreFirstVisibleLine();
	// restore the window
	stc->EndUndoAction();
	stc->SetXOffset(xOffset);
	m_stc = nullptr;
}
示例#11
0
QMessageBox::StandardButton gui::MainWindow::ShowQuestion(const QString& message, const QString& title /*= ""*/, QMessageBox::StandardButtons buttons /*= QMessageBox::Yes | QMessageBox::No*/) const
{
	assert(buttons != QMessageBox::NoButton);
	return ShowMessageDialog(message, title, QMessageBox::Question, buttons);
}
示例#12
0
void gui::MainWindow::ShowMessage(const QString& message, const QString& title /*= ""*/, QMessageBox::Icon icon /*= QMessageBox::Information*/) const
{
	ShowMessageDialog(message, title, icon, QMessageBox::NoButton);
}
示例#13
0
bool AStyleFormat::RestoreSelection() const
// Remove the selection markers and select the text.
// The entire lines are selected.
{
	assert(m_stc != nullptr);
	bool returnValue = true;
	// the first visible line must later be restored
	int firstVisibleLine = m_stc->GetFirstVisibleLine();
	// find the selection markers
	int minPosition = -1;
	int maxPosition = -1;
	minPosition = m_stc->FindText(0, m_stc->GetTextLength(), m_minSelectionMarker, wxSTC_FIND_MATCHCASE);
	if (minPosition >= 0)
		maxPosition = m_stc->FindText(minPosition, m_stc->GetTextLength(), m_maxSelectionMarker, wxSTC_FIND_MATCHCASE);
	else
		maxPosition = m_stc->FindText(0, m_stc->GetTextLength(), m_maxSelectionMarker, wxSTC_FIND_MATCHCASE);
	int minLine = -1;
	int maxLine = -1;
	// get the max line number and remove the marker
	// remove max first so it's position doesn't change
	if (maxPosition > 0)
	{
		maxLine = m_stc->LineFromPosition(maxPosition);
		int maxEndPosition = maxPosition + static_cast<int>(m_maxSelectionMarker.length());
		// trim extra whitespace
		wxString whitespaceChars = " \t";
		while ((maxPosition > 0)
		        && (whitespaceChars.Find(static_cast<wxChar>(
		                                     m_stc->GetCharAt(maxPosition - 1))) != wxNOT_FOUND))
			--maxPosition;
		// remove the marker
		m_stc->SetTargetStart(maxPosition);
		m_stc->SetTargetEnd(maxEndPosition);
		m_stc->ReplaceTarget(wxEmptyString);
	}
	// get the min line number and remove the marker
	if (minPosition >= 0)
	{
		minLine = m_stc->LineFromPosition(minPosition);
		int minEndPosition = minPosition + static_cast<int>(m_minSelectionMarker.length());
		// if a marker line was inserted, remove the entire line
		if (m_line0Inserted	&& minLine == 0)
			minEndPosition = m_stc->LineLength(0);
		// trim extra whitespace
		wxString whitespaceChars = " \t";
		while ((minPosition > 0)
		        && (whitespaceChars.Find(static_cast<wxChar>(
		                                     m_stc->GetCharAt(minPosition - 1))) != wxNOT_FOUND))
			--minPosition;
		// remove the marker
		m_stc->SetTargetStart(minPosition);
		m_stc->SetTargetEnd(minEndPosition);
		m_stc->ReplaceTarget(wxEmptyString);
	}
	if ((minLine >= 0) && (maxLine >= 0))
	{
		// select the text
		// minimum marker was placed at the end of the previous line
		int selMin = m_stc->PositionFromLine(minLine + 1);
		// if a marker line was inserted select line 0
		if (m_line0Inserted && minLine == 0)
			selMin = 0;
		// select to the start of the following line
		else
			++maxLine;
		int selMax = m_stc->PositionFromLine(maxLine);
		// NOTE: reverse selection does not currently work (July 2013)
//		if (!m_selectionReversed)
		m_stc->SetSelection(selMin, selMax);
//		else
//			m_stc->SetSelection(selMax, selMin);
	}
	else
	{
		ShowMessageDialog("Unable to find a selection marker during restore!\n"
		                  "The formatted text will not be selected.",
		                  wxOK | wxICON_ERROR);
		returnValue = false;
	}
	// restore the first visible line
	if (m_line0Inserted)
		--firstVisibleLine;
	m_stc->SetFirstVisibleLine(firstVisibleLine);
	return returnValue;
}
示例#14
0
void ExportMultipleVectorDatasets(wxWindow* pWnd, const CPLString &sPath, wxGxObjectFilter* const pFilter, wxVector<EXPORTED_DATASET> &paDatasets)
{
    wxCHECK_RET(pWnd && pFilter && paDatasets.size() > 1, wxT("The input pointer is NULL or datasets array is empty"));

    wxGISProgressDlg ProgressDlg(_("Exporting..."), _("Begin operation..."), 100, pWnd);
    ProgressDlg.SetAddPercentToMessage(false);
    ProgressDlg.ShowProgress(true);

    for (size_t i = 0; i < paDatasets.size(); ++i)
    {
        ProgressDlg.SetTitle(wxString::Format(_("Proceed %ld of %ld..."), i + 1, paDatasets.size()));
        wxGISDataset* pDataset = paDatasets[i].pDSet->GetDataset(false, &ProgressDlg);
        wxVector<wxGISFeatureDataset*> apFeatureDatasets;
        if (pDataset->GetSubsetsCount() == 0)
        {
            wxGISFeatureDataset* pFeatureDataset = wxDynamicCast(pDataset, wxGISFeatureDataset);
            if (NULL != pFeatureDataset)
            {
                pFeatureDataset->Reference();
                apFeatureDatasets.push_back(pFeatureDataset);
            }
        }
        else
        {
            for (size_t j = 0; j < pDataset->GetSubsetsCount(); ++j)
            {
                wxGISFeatureDataset* pFeatureDataset = wxDynamicCast(pDataset->GetSubset(j), wxGISFeatureDataset);
                if (NULL != pFeatureDataset)
                {
                    pFeatureDataset->Reference();
                    apFeatureDatasets.push_back(pFeatureDataset);
                }
            }
        }

        if (apFeatureDatasets.size() == 0)
        {
            wxMessageBox(_("The dataset is empty"), _("Error"), wxCENTRE | wxICON_ERROR | wxOK, pWnd);
            wxLogError(_("wxGISFeatureDataset pointer is null returned"));
            return;
        }

        for (size_t j = 0; j < apFeatureDatasets.size(); ++j)
        {
            if(!ProgressDlg.Continue())
                break;
            if (!apFeatureDatasets[j]->IsOpened())
            {
                if (!apFeatureDatasets[j]->Open(0, TRUE, false, &ProgressDlg))
                {
                    wxMessageBox(ProgressDlg.GetLastMessage(), _("Error"), wxCENTRE | wxICON_ERROR | wxOK, pWnd);
                    wxLogError(ProgressDlg.GetLastMessage());
                    wsDELETE(apFeatureDatasets[j]);
                    continue;
                }
            }

            if (!ExportFormat(apFeatureDatasets[j], sPath, paDatasets[i].sName, pFilter, wxGISNullSpatialFilter, NULL, NULL, true, static_cast<ITrackCancel*>(&ProgressDlg)))
            {
                wxMessageBox(ProgressDlg.GetLastMessage(), _("Error"), wxCENTRE | wxICON_ERROR | wxOK, pWnd);
                wxLogError(ProgressDlg.GetLastMessage());
                wsDELETE(apFeatureDatasets[j]);
                continue;
            }
            wsDELETE(apFeatureDatasets[j]);
        }
    }

    if (ProgressDlg.GetWarningCount() > 0 && ProgressDlg.Continue())
    {
        ShowMessageDialog(pWnd, ProgressDlg.GetWarnings());
    }
}