示例#1
0
文件: search.cpp 项目: bihai/fbide
void MyFrame::FindClose ( wxFindDialogEvent& event ) {

    if (event.GetDialog() == FindDialog) {
        FindDialog->Destroy();
        FindDialog = NULL;
    }

    else if (event.GetDialog() == ReplaceDialog) {
        ReplaceDialog->Destroy();
        ReplaceDialog = NULL;
    }
    return;
}
示例#2
0
void MyFrame::OnFindDialog(wxFindDialogEvent& event)
{
    wxEventType type = event.GetEventType();

    if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT )
    {
        wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
                     type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""),
                     event.GetFindString().c_str(),
                     DecodeFindDialogEventFlags(event.GetFlags()).c_str());
    }
    else if ( type == wxEVT_COMMAND_FIND_REPLACE ||
              type == wxEVT_COMMAND_FIND_REPLACE_ALL )
    {
        wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
                     type == wxEVT_COMMAND_FIND_REPLACE_ALL ? _T("all ") : wxT(""),
                     event.GetFindString().c_str(),
                     event.GetReplaceString().c_str(),
                     DecodeFindDialogEventFlags(event.GetFlags()).c_str());
    }
    else if ( type == wxEVT_COMMAND_FIND_CLOSE )
    {
        wxFindReplaceDialog *dlg = event.GetDialog();

        int idMenu;
        const wxChar *txt;
        if ( dlg == m_dlgFind )
        {
            txt = _T("Find");
            idMenu = DIALOGS_FIND;
            m_dlgFind = NULL;
        }
        else if ( dlg == m_dlgReplace )
        {
            txt = _T("Replace");
            idMenu = DIALOGS_REPLACE;
            m_dlgReplace = NULL;
        }
        else
        {
            txt = _T("Unknown");
            idMenu = wxID_ANY;

            wxFAIL_MSG( _T("unexpected event") );
        }

        wxLogMessage(wxT("%s dialog is being closed."), txt);

        if ( idMenu != wxID_ANY )
        {
            GetMenuBar()->Check(idMenu, false);
        }

        dlg->Destroy();
    }
    else
    {
        wxLogError(wxT("Unknown find dialog event!"));
    }
}
示例#3
0
void SavvyEditor::AppFrame::OnFindDialog(wxFindDialogEvent& a_Event)
{
	wxEventType type = a_Event.GetEventType();

	if (type == wxEVT_FIND || type == wxEVT_FIND_NEXT)
	{
		if (!DoFind(a_Event.GetFindString(), a_Event.GetFlags()))
		{
			wxMessageBox(wxT("No more matches."), DEFAULT_FRAME_TITLE);
		}
	}
	else if (type == wxEVT_FIND_REPLACE)
	{
		if (!DoReplace(a_Event.GetFindString(), a_Event.GetReplaceString(), a_Event.GetFlags()))
		{
			wxMessageBox(wxT("Nothing to replace."), DEFAULT_FRAME_TITLE);
		}
	}
	else if (type == wxEVT_FIND_REPLACE_ALL)
	{
		int numReplaced = DoReplaceAll(a_Event.GetFindString(), a_Event.GetReplaceString(), a_Event.GetFlags());
		if (numReplaced > 0)
		{
			wxString numString = wxString::Format(wxT("%i"), numReplaced);
			numString.Append(" occurrences replaced.");
			wxMessageBox(numString, DEFAULT_FRAME_TITLE);
		}
		else
		{
			wxMessageBox(wxT("Nothing to replace."), DEFAULT_FRAME_TITLE);
		}
	}
	else if (type == wxEVT_FIND_CLOSE)
	{
		wxFindReplaceDialog *dlg = a_Event.GetDialog();

		int idMenu;
		const wxChar *txt;
		if (dlg == m_FindDialog)
		{
			txt = wxT("Find");
			idMenu = ID_FindDialog;
			m_FindDialog = NULL;
		}
		else if (dlg == m_ReplaceDialog)
		{
			txt = wxT("Replace");
			idMenu = ID_ReplaceDialog;
			m_ReplaceDialog = NULL;
		}
		else
		{
			txt = wxT("Unknown");
			idMenu = wxID_ANY;

			wxFAIL_MSG(wxT("unexpected event"));
		}

		if (idMenu != wxID_ANY)
		{
			GetMenuBar()->Check(idMenu, false);
		}

		dlg->Destroy();
	}
	else
	{
		wxLogError(wxT("Unknown find dialog event!"));
	}
}
示例#4
0
//----------------------------------------
void CRichTextFrame::OnFindDialog(wxFindDialogEvent& event)
{
    wxEventType type = event.GetEventType();

    if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT )
    {
      /*
        wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
                     type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""),
                     event.GetFindString().c_str(),
                     DecodeFindDialogEventFlags(event.GetFlags()).c_str());
        */
        wxString sSearch = event.GetFindString();
        wxString sText = m_textCtrl->GetValue();
        //sText.Replace(wxT( "\n" ), wxT( " \n" ) ) ;
        int iStart = -1;
        long from = m_textCtrl->GetInsertionPoint();
        long to = 0;
        m_textCtrl->GetSelection(&from, &to);
        bool matchCase = ((event.GetFlags() & wxFR_MATCHCASE) == wxFR_MATCHCASE);
        bool down = ((event.GetFlags() & wxFR_DOWN) == wxFR_DOWN);
        if (matchCase)
        {
          if (down)
          {
            from = to + 1;
            iStart =  sText.find (sSearch, from);
          }
          else
          {
            from = from - 1;
            iStart =  sText.rfind (sSearch, from);
          }
        }
        else
        {
          if (down)
          {
            from = to + 1;
            iStart =  CTools::FindNoCase(sText.c_str(), sSearch.c_str(), from);
          }
          else
          {
            from = from - 1;
            iStart =  CTools::RFindNoCase(sText.c_str(), sSearch.c_str(), from);
          }
        }
        if (iStart < 0)
        {
          wxMessageBox(wxString::Format("Cannot find the string '%s'", 
                                        sSearch.c_str()),
                      "Find text...",
                      wxOK | wxICON_EXCLAMATION,
                      this);
          event.GetDialog()->SetFocus();
        }
        else
        {
          int iEnd = iStart + sSearch.Length();
          m_textCtrl->SetFocus();
          m_textCtrl->SetInsertionPoint(iEnd+1);
          m_textCtrl->SetSelection (iStart, iEnd);

        }

    }
    else if ( type == wxEVT_COMMAND_FIND_CLOSE )
    {
        wxFindReplaceDialog *dlg = event.GetDialog();

        if ( dlg == m_dlgFind )
        {
            m_dlgFind = NULL;
        }

        dlg->Destroy();
    }
    else
    {
        //wxLogError(wxT("Unknown find dialog event!"));
    }
}
示例#5
0
void NyqBench::OnFindDialog(wxFindDialogEvent & e)
{
   wxEventType type = e.GetEventType();

   if (type == wxEVT_COMMAND_FIND_CLOSE) {
      wxFindReplaceDialog *dlg = e.GetDialog();

      dlg->Destroy();

      int flags = mFindData.GetFlags();

      gPrefs->Write(wxT("NyqBench/Find/Down"), (flags & wxFR_DOWN) != 0);
      gPrefs->Write(wxT("NyqBench/Find/Word"), (flags & wxFR_WHOLEWORD) != 0);
      gPrefs->Write(wxT("NyqBench/Find/Case"), (flags & wxFR_MATCHCASE) != 0);

      mFindDlg = NULL;
      mFindText = NULL;

      return;
   }

   wxString text = mFindText->GetValue();

#if defined(__WXMSW__)
   // We cheat on Windows.  We know that the Windows text control
   // uses CRLF for line endings and if we don't account for that,
   // the selection positions will be off.
   //
   // Not sure why I thought I needed this, but it appears not to
   // be.  Leaving just in case.
   //
   // text.Replace(wxT("\n"), wxT("\r\n"));
#endif

   size_t startpos = mFindText->GetInsertionPoint();
   size_t len = mFindText->GetLastPosition();
   size_t pos;

   wxString find = e.GetFindString();
   bool down = (e.GetFlags() & wxFR_DOWN) != 0;
   bool mixed = (e.GetFlags() & wxFR_MATCHCASE) != 0;

   if (!mixed) {
      text.MakeUpper();
      find.MakeUpper();
   }

   if (down) {
      pos = text.find(find, startpos);
      if (type == wxEVT_COMMAND_FIND_NEXT && pos == startpos && pos < len) {
         pos = text.find(find, startpos + 1);
      }
   }
   else {
      pos = text.rfind(find, startpos);
      if (type == wxEVT_COMMAND_FIND_NEXT && pos == startpos && pos > 0) {
         pos = text.rfind(find, startpos - 1);
      }
   }

   if (pos == wxString::npos) {
      AudacityMessageBox(_("No matches found"),
                   _("Nyquist Effect Workbench"),
                   wxOK | wxCENTER,
                   e.GetDialog());

      return;
   }

   mFindText->SetInsertionPoint((long)pos);

#if defined(__WXGTK__)
   // GTK's selection and intertion pointer interact where the insertion
   // pointer winds up after the second parameter, so we reverse them to
   // force the pointer at the beginning of the selection.  Doing so
   // allows reverse find to work properly.
   mFindText->SetSelection((long)(pos + find.Length()), (long)pos);
#else
   mFindText->SetSelection((long)pos, (long)(pos + find.Length()));
#endif

#if defined(__WXMAC__)
   // Doing this coaxes the text control to update the selection.  Without
   // it the selection doesn't appear to change if the found string is within
   // the currently displayed text, i.e., no reposition is needed.
   mFindText->Show(false);
   mFindText->Show(true);
#endif
}