예제 #1
0
BOOL CEditView::InitializeReplace()
	// helper to do find first if no selection
{
	ASSERT_VALID(this);

	_AFX_EDIT_STATE* pEditState = _afxEditState;

	// do find next if no selection
	int nStartChar, nEndChar;
	GetEditCtrl().GetSel(nStartChar, nEndChar);
	if (nStartChar == nEndChar)
	{
		if (!FindText(pEditState->strFind, pEditState->bNext,
			pEditState->bCase))
		{
			// text not found
			OnTextNotFound(pEditState->strFind);
		}
		return FALSE;
	}

	if (!SameAsSelected(pEditState->strFind, pEditState->bCase))
	{
		if (!FindText(pEditState->strFind, pEditState->bNext,
			pEditState->bCase))
		{
			// text not found
			OnTextNotFound(pEditState->strFind);
		}
		return FALSE;
	}

	ASSERT_VALID(this);
	return TRUE;
}
예제 #2
0
파일: editor.cpp 프로젝트: 8l/objeck-lang
void Edit::ReplaceText(const wxString &find_string)
{
  int found_start, found_end;
  const int select_start = GetSelectionStart();
  const int select_end = GetSelectionEnd();

  // replace & search
  if (select_start > -1 && select_end > select_start) {
    const wxString select_string = GetSelectedText();
    if (select_string == find_string) {
      ReplaceSelection(m_FindData.GetReplaceString());
      // search
      if (FindText(found_start, found_end, false)) {
        SetSelection(found_start, found_end);
      }
      else {
        wxMessageDialog dialog(this, wxT("Cannot find the text \"" + find_string + "\" from current position"), wxT("Find"));
        dialog.ShowModal();
      }
    }
  }
  // search
  else if (FindText(found_start, found_end, false)) {
    SetSelection(found_start, found_end);
  }
}
예제 #3
0
bool SearchableEditor::find(bool newSearch)
{
    if (!fd)
        fd = new FindDialog(this, ::wxGetTopLevelParent(this));
    if (newSearch || findTextM.empty())
    {
        if (newSearch)
        {
            // find selected text
            wxString findText(GetSelectedText());
            // failing that initialize with the word at the caret
            if (findText.empty())
            {
                int pos = GetCurrentPos();
                int start = WordStartPosition(pos, true);
                int end = WordEndPosition(pos, true);
                if (end > start)
                    findText = GetTextRange(start, end);
            }
            fd->SetFindText(findText);
        }

        // do not re-center dialog if it is already visible
        if (!fd->IsShown())
            fd->Show();
        fd->SetFocus();
        return false;    // <- caller shouldn't care about this
    }

    int start = GetSelectionEnd();
    if (findFlagsM.has(se::FROM_TOP))
    {
        start = 0;
        findFlagsM.remove(se::ALERT);    // remove flag after first find
    }

    int end = GetTextLength();
    int p = FindText(start, end, findTextM, findFlagsM.asStc());
    if (p == -1)
    {
        if (findFlagsM.has(se::WRAP))
            p = FindText(0, end, findTextM, findFlagsM.asStc());
        if (p == -1)
        {
            if (findFlagsM.has(se::ALERT))
                wxMessageBox(_("No more matches"), _("Search complete"), wxICON_INFORMATION|wxOK);
            return false;
        }
    }
    centerCaret(true);
    GotoPos(p);
    GotoPos(p + findTextM.Length());
    SetSelectionStart(p);
    SetSelectionEnd(p + findTextM.Length());
    centerCaret(false);
    return true;
}
예제 #4
0
void Separate(char *ValueList,float results[],unsigned short numValues) {
// parses a space- or tab- delimited string into an array of floats
    unsigned short i;
    unsigned short StartPos, EndPos;
	char *word;
    StartPos=FindText(ValueList,0);    // find start of first value
	for (i=0;i<numValues;i++) {
		EndPos=FindSpace(ValueList,StartPos);    // find end of value
		word=mid(ValueList, StartPos, (unsigned short)(EndPos-StartPos));
        results[i] = (float) atof(word);  // store value in array
		free(word);
        StartPos=FindText(ValueList,EndPos);   // find start of next value
	}
} // Separate()
예제 #5
0
파일: SearchDialog.c 프로젝트: Viriana/SISE
void SetUpSearch( 
  HWND hWnd, 
  int Replace)
  {  
   /*========================*/
   /* Call the common dialog */
   /* for Search or Replace. */
   /*========================*/
   
   fr.hwndOwner = hWnd;
   fr.Flags = FR_HIDEUPDOWN | FR_HIDEWHOLEWORD ;

   if (Replace)
     { SearchDlg = ReplaceText(&fr); }
   else
     { SearchDlg = FindText(&fr); }

   /*=====================*/
   /* Disable Menu Items. */
   /*=====================*/

   if (SearchDlg)
     {  
      HMENU hMenu = GetMenu(hMainFrame);
      
      EnableMenuItem(hMenu,ID_BUFFER_FIND,MF_GRAYED);
      EnableMenuItem(hMenu,ID_BUFFER_REPLACE,MF_GRAYED);
      
      FirstSearch = TRUE;
      SearchActive = TRUE;
     }
  }
예제 #6
0
void CEdit::FindSelectedWord( BOOL bForward )
{
	if ( m_Selection.IsEmpty() )
	{
		m_Selection.Extend( CSelection::eOutward, CSelection::eWord, FALSE, FALSE, FALSE );
	}

	if ( !m_Selection.IsEmpty() )
	{
		HGLOBAL hMem = GetSelectionText();
		if ( hMem )
		{
			LPTSTR pszText = ( LPTSTR ) GlobalLock( hMem );
			if ( pszText && *pszText )
			{
				SetFindText( pszText );
				FindText( bForward );
			}
			GlobalUnlock( hMem );
			GlobalFree( hMem );
		}
	}
	else
	{
		NotifyParentOfCmdFailure( CMDERR_EMPTYBUF );
	}

}
예제 #7
0
void	EdSearch_ShowFindDialog (HWND pmTextDisplayWindow, char *pmFindString)
{
    if (EdSearch_FindReplaceDialog != NULL)
    {
    	if ((stFindReplace.hwndOwner == pmTextDisplayWindow) && stIsFindDialog)
    	{
    	    // Bring the window to the front
    	    BringWindowToTop (EdSearch_FindReplaceDialog);
    	    return;
    	}
    	else
    	{
    	    // Close the current window
    	    DestroyWindow (EdSearch_FindReplaceDialog);
    	}
    }
    else
    {
    	if ((pmFindString != NULL) && (pmFindString [0] != 0))
    	{
    	    strcpy (stFindWhat, pmFindString);
    	}
    }
    stFindReplace.hwndOwner = pmTextDisplayWindow;
    stFindReplace.Flags &= 
        ~(FR_DIALOGTERM | FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL); 
    EdSearch_FindReplaceDialog = FindText (&stFindReplace);
    stIsFindDialog = TRUE;
} // EdSearch_ShowFindDialog
예제 #8
0
void CEditView::OnEditRepeat()
/****************************/
{
    if( !FindText( _afxEditState->strFind, _afxEditState->bNext,
                   _afxEditState->bCase ) ) {
        OnTextNotFound( _afxEditState->strFind );
    }
}
예제 #9
0
void CEditView::OnReplaceAll( LPCTSTR lpszFind, LPCTSTR lpszReplace, BOOL bCase )
/*******************************************************************************/
{
    _AFX_EDIT_STATE *pState = _afxEditState.GetData();
    ASSERT( pState != NULL );
    
    pState->strFind = lpszFind;
    pState->strReplace = lpszReplace;
    pState->bCase = bCase;
    
    if( !FindText( lpszFind, TRUE, bCase ) ) {
        OnTextNotFound( lpszFind );
    } else {
        ::SendMessage( m_hWnd, EM_REPLACESEL, TRUE, (LPARAM)lpszReplace );
        while( FindText( lpszFind, TRUE, bCase ) ) {
            ::SendMessage( m_hWnd, EM_REPLACESEL, TRUE, (LPARAM)lpszReplace );
        }
    }
}
예제 #10
0
파일: Find.c 프로젝트: SatishSara/zxlooong
void DoFindRepStuff(LPFINDREPLACE pfr)
{
  if (IsDlgButtonChecked(hwndMainDialog, ID_PRELOADEDFIND) == 1)
  {
    if (bDoFindDlg)
      pfr->hInstance = GetFindDlgHandle() ;
    else
      pfr->hInstance = GetReplaceDlgHandle() ;
  }

  if (bDoFindDlg)
  {
    if (IsDlgButtonChecked(hwndMainDialog, ID_FRNULLSTRUCT) == 1)
    {
        hwndFind = FindText((LPFINDREPLACE) NULL) ;
    }
    else
    {
        hwndFind = FindText(pfr) ;
    }
  }
  else
  {
    if (IsDlgButtonChecked(hwndMainDialog, ID_FRNULLSTRUCT) == 1)
    {
        hwndFind = ReplaceText((LPFINDREPLACE) NULL) ;
    }
    else
    {
        hwndFind = ReplaceText(pfr) ;
    }

  }


  wsprintf(szTemp, szLongFilter, CommDlgExtendedError()) ;
  SetDlgItemText(hwndMainDialog, ID_ERRORFT, szTemp) ;

  wsprintf(szTemp, szLongFilter, hwndFind) ;
  SetDlgItemText(hwndMainDialog, ID_RETURNFT, szTemp) ;
}
예제 #11
0
void CEditView::OnFindNext(LPCTSTR lpszFind, BOOL bNext, BOOL bCase)
{
	ASSERT_VALID(this);
	_AFX_EDIT_STATE* pEditState = _afxEditState;
	pEditState->strFind = lpszFind;
	pEditState->bCase = bCase;
	pEditState->bNext = bNext;

	if (!FindText(pEditState->strFind, bNext, bCase))
		OnTextNotFound(pEditState->strFind);
	ASSERT_VALID(this);
}
예제 #12
0
void CEditView::OnEditRepeat()
{
	ASSERT_VALID(this);
	_AFX_EDIT_STATE* pEditState = _afxEditState;
	if (!FindText(pEditState->strFind,
		pEditState->bNext,
		pEditState->bCase))
	{
		OnTextNotFound(pEditState->strFind);
	}
	ASSERT_VALID(this);
}
예제 #13
0
void CEditView::OnFindNext( LPCTSTR lpszFind, BOOL bNext, BOOL bCase )
/********************************************************************/
{
    _AFX_EDIT_STATE *pState = _afxEditState.GetData();
    ASSERT( pState != NULL );
    
    pState->strFind = lpszFind;
    pState->bNext = bNext;
    pState->bCase = bCase;
    
    if( !FindText( lpszFind, bNext, bCase ) ) {
        OnTextNotFound( lpszFind );
    }
}
예제 #14
0
파일: editor.cpp 프로젝트: 8l/objeck-lang
void Edit::OnFindReplaceDialog(wxFindDialogEvent& event)
{
  const wxEventType type = event.GetEventType();
  const wxString find_string = m_FindData.GetFindString();
  int found_start, found_end;

  if (type == wxEVT_FIND || type == wxEVT_FIND_NEXT) {
    // search
    if (FindText(found_start, found_end, type == wxEVT_FIND_NEXT)) {
      SetSelection(found_start, found_end);
    }
    else {
      wxMessageDialog dialog(this, wxT("Cannot find the text \"" + find_string + "\" from current position"), wxT("Find"));
      dialog.ShowModal();
    }
  }
  else if (type == wxEVT_FIND_REPLACE) {
    ReplaceText(find_string);
  }
  else if (type == wxEVT_FIND_REPLACE_ALL) {
    const wxString replace_string = m_FindData.GetReplaceString();
    int start_index = 0;
    bool found = true;
    int found_count = 0;
    do {
      // set search area
      SetTargetStart(start_index); SetTargetEnd(GetLastPosition());

      // search and replace
      found_start = SearchInTarget(find_string);
      if (found_start > -1) {
        found_end = found_start + find_string.size();
        SetTargetStart(found_start);
        SetTargetEnd(found_end);
        ReplaceTarget(replace_string);
        start_index = found_start + replace_string.size();
        found_count++;
      }
      else {
        found = false;
      }
    }
    while (found);

    const wxString message = wxString::Format(wxT("%d occurrence(s) of \"%s\" were replaced with \"%s\"."), 
      found_count, find_string, replace_string);
    wxMessageDialog replace_dialog(this, message, wxT("Replaced Text"));
    replace_dialog.ShowModal();
  }
}
예제 #15
0
void CEditView::OnReplaceSel( LPCTSTR lpszFind, BOOL bNext, BOOL bCase,
                              LPCTSTR lpszReplace )
/*************************************************/
{
    _AFX_EDIT_STATE *pState = _afxEditState.GetData();
    ASSERT( pState != NULL );
    
    pState->strFind = lpszFind;
    pState->bNext = bNext;
    pState->bCase = bCase;
    pState->strReplace = lpszReplace;
    
    CString strSelection;
    GetSelectedText( strSelection );
    if( (bCase && strSelection.Compare( lpszFind ) != 0) ||
        (!bCase && strSelection.Compare( lpszFind ) != 0) ) {
        if( !FindText( lpszFind, bNext, bCase ) ) {
            OnTextNotFound( lpszFind );
            return;
        }
    }
    ::SendMessage( m_hWnd, EM_REPLACESEL, TRUE, (LPARAM)lpszReplace );
    FindText( lpszFind, bNext, bCase );
}
예제 #16
0
파일: dialog.c 프로젝트: howard5888/wineT
VOID DIALOG_Search(VOID)
{
        ZeroMemory(&Globals.find, sizeof(Globals.find));
        Globals.find.lStructSize      = sizeof(Globals.find);
        Globals.find.hwndOwner        = Globals.hMainWnd;
        Globals.find.hInstance        = Globals.hInstance;
        Globals.find.lpstrFindWhat    = Globals.szFindText;
        Globals.find.wFindWhatLen     = SIZEOF(Globals.szFindText);
        Globals.find.Flags            = FR_DOWN;

        /* We only need to create the modal FindReplace dialog which will */
        /* notify us of incoming events using hMainWnd Window Messages    */

        Globals.hFindReplaceDlg = FindText(&Globals.find);
        assert(Globals.hFindReplaceDlg !=0);
}
예제 #17
0
void finddialog(textbox t)
{
    static FINDREPLACE fr;
    static char szFindWhat[80];

    fr.lStructSize = sizeof(fr);
    fr.hwndOwner = t->handle;
    fr.lpstrFindWhat = szFindWhat;
    fr.wFindWhatLen = 80;
    fr.Flags = FR_DOWN;
    fr.lCustData        = 0 ;
    fr.lpfnHook         = NULL ;
    fr.lpTemplateName   = NULL ;

    hModelessDlg = FindText(&fr);
}
예제 #18
0
void CEditView::OnReplaceSel(LPCTSTR lpszFind, BOOL bNext, BOOL bCase,
	LPCTSTR lpszReplace)
{
	ASSERT_VALID(this);
	_AFX_EDIT_STATE* pEditState = _afxEditState;
	pEditState->strFind = lpszFind;
	pEditState->strReplace = lpszReplace;
	pEditState->bCase = bCase;
	pEditState->bNext = bNext;

	if (!InitializeReplace())
		return;

	GetEditCtrl().ReplaceSel(pEditState->strReplace);
	FindText(pEditState->strFind, bNext, bCase);
	ASSERT_VALID(this);
}
예제 #19
0
파일: editor.cpp 프로젝트: 8l/objeck-lang
void Edit::OnFindReplace(wxCommandEvent &event) {
  const wxString find_string = m_FindData.GetFindString();
  int found_start, found_end;

  if (event.GetId() == myID_FINDNEXT) {
    // search
    if (FindText(found_start, found_end, true)) {
      SetSelection(found_start, found_end);
    }
    else {
      wxMessageDialog dialog(this, wxT("Cannot find the text \"" + find_string + "\" from current position"), wxT("Find"));
      dialog.ShowModal();
    }
  }
  if (event.GetId() == myID_REPLACENEXT) {
    ReplaceText(find_string);
  }
  else {
    if (m_findReplace) {
      delete m_findReplace;
      m_findReplace = NULL;
    }

    const int select_start = GetSelectionStart();
    const int select_end = GetSelectionEnd();
    wxString find_text;
    if (select_start > -1 && select_end > select_start) {
      find_text = GetSelectedText();
    }

    if (event.GetId() == myID_DLG_FIND_TEXT) {
      if (find_text.size() > 0) {
        m_FindData.SetFindString(find_text);
      }
      m_findReplace = new wxFindReplaceDialog(this, &m_FindData, wxT("Find"));
    }
    else {
      if (find_text.size() > 0) {
        m_FindData.SetFindString(find_text);
      }
      m_findReplace = new wxFindReplaceDialog(this, &m_FindData, wxT("Find & Replace"), wxFR_REPLACEDIALOG);
    }
    m_findReplace->Show();
  }
}
예제 #20
0
void CEdit::Replace()
{
	if ( m_Buffer.GetLineCount() && !m_Selection.IsEmpty() )
	{
		if ( g_FindReplaceData.m_pszFindText )
		{
			if ( g_FindReplaceData.m_pszReplaceText )
			{
				FindReplaceSelection();
			}
			else
			{
				DeleteSelection( FALSE, FALSE );
			}
		}
	}
	FindText( TRUE );
}
예제 #21
0
bool SearchableEditor::replace(bool force)
{
    int start = GetSelectionStart();
    int end = GetSelectionEnd();
    if (start == end || FindText(start, end, findTextM, findFlagsM.asStc()) == -1)
    {
        if (!find(false))
            return false;
        if (!force)
            return false;
    }

    // we have selection here
    start = GetSelectionStart();
    ReplaceSelection(replaceTextM);
    SetSelectionEnd(start + replaceTextM.Length());        // position at end of replaced text
    find(false);
    return true;
}
예제 #22
0
파일: TabUnits.cpp 프로젝트: GotoHack/IDR
//---------------------------------------------------------------------------
void __fastcall TFMain_11011981::miSearchUnitClick(TObject *Sender)
{
    WhereSearch = SEARCH_UNITS;

    FindDlg_11011981->cbText->Clear();
    for (int n = 0; n < UnitsSearchList->Count; n++)
        FindDlg_11011981->cbText->AddItem(UnitsSearchList->Strings[n], 0);

    if (FindDlg_11011981->ShowModal() == mrOk && FindDlg_11011981->cbText->Text != "")
    {
        if (lbUnits->ItemIndex == -1)
            UnitsSearchFrom = 0;
        else
            UnitsSearchFrom = lbUnits->ItemIndex;

        UnitsSearchText = FindDlg_11011981->cbText->Text;
        if (UnitsSearchList->IndexOf(UnitsSearchText) == -1) UnitsSearchList->Add(UnitsSearchText);
        FindText(UnitsSearchText);
    }
}
void CMyRichEditView::OnReplaceAll(LPCTSTR lpszFind, LPCTSTR lpszReplace, 
   BOOL bCase, BOOL bWord)
{
   CWaitCursor wait;
   // no selection or different than what we are looking for
   if (!FindText(lpszFind, bCase, bWord))
   {
      OnTextNotFound(lpszFind);
      return;
   }

   GetRichEditCtrl().HideSelection(TRUE, FALSE);
   m_nNumReplaced = 0;
   do
   {
      GetRichEditCtrl().ReplaceSel(lpszReplace);
      m_nNumReplaced++;  // Record the number of replacements

   } while (FindTextSimple(lpszFind));
   GetRichEditCtrl().HideSelection(FALSE, FALSE);
}
예제 #24
0
void CEditView::OnReplaceAll(LPCTSTR lpszFind, LPCTSTR lpszReplace, BOOL bCase)
{
	ASSERT_VALID(this);
	_AFX_EDIT_STATE* pEditState = _afxEditState;
	pEditState->strFind = lpszFind;
	pEditState->strReplace = lpszReplace;
	pEditState->bCase = bCase;
	pEditState->bNext = TRUE;

	if (!InitializeReplace() &&
		!SameAsSelected(pEditState->strFind, pEditState->bCase))
	{
		// initial find was not successful
		return;
	}

	do
	{
		GetEditCtrl().ReplaceSel(pEditState->strReplace);
	} while (FindText(pEditState->strFind, 1, bCase));

	ASSERT_VALID(this);
}
예제 #25
0
bool CScriptEditView::DoFindText( bool bNext )
{
	DWORD dwFlags = FR_DOWN;
	if( m_fro.bMatchCase )
		dwFlags |= FR_MATCHCASE;
	if( m_fro.bWholeWord )
		dwFlags |= FR_WHOLEWORD;

	long nStart, nEnd;
	GetSel( nStart, nEnd );

	FINDTEXTEX ft;
	ft.chrg.cpMin = bNext ? nEnd : nStart ;
	ft.chrg.cpMax = -1;
	ft.lpstrText = m_fro.StrToFind;

	if( FindText(dwFlags, ft) == -1 )
		return false;

	SetSel( ft.chrgText );

	return true;
}
예제 #26
0
파일: fr.c 프로젝트: amacal/ed
/** Function: Rufe Suchen-Ersetzen-Dialogbox auf **/
HWND fr_dlg(HWND hWnd, BOOL replDlg)
  {
  // Der fr_dlg ist nur eine Huelse und kehrt sofort zum Aufrufer zurueck; werden die Buttons betaetigt,
  // werden fr_msg-Nachrichten erzeugt, die die die eigentlichen Arbeitsfunktionen fr_find*() ansteuern.
  // Nachfolgende Aenderungen von Suchoptionen (matchCase etc.) in fr_dlgStruc werden ueber den Dialog sofort an
  // die Variable fr_dlgStruc weitergegeben, sodass die Arbeitsfunktionen immer den aktuellen Zustand haben.
  fr_findCt = fr_replCt = 0;
  #ifdef BUILD_FR_PR
  fr_preset(GetDlgItem(hWnd, IDW_WIN_EDIT)); // fr_FindText mit evt. Markierung vorbesetzen
  #endif
  ZeroMemory(&fr_dlgStruc, sizeof(FINDREPLACE));
  fr_dlgStruc.lStructSize = sizeof(FINDREPLACE);
  fr_dlgStruc.hwndOwner = hWnd; // Bestimmt, an welches Fenster Nachrichten gesendet werden
  fr_dlgStruc.Flags = FR_DOWN | FR_NOUPDOWN; // DOWN voreinstellen und fixieren
  fr_dlgStruc.lpstrFindWhat = fr_findStr;
  fr_dlgStruc.wFindWhatLen = MAX_STRING_LEN;
  if (replDlg) {
    fr_dlgStruc.lpstrReplaceWith = fr_replStr; fr_dlgStruc.wReplaceWithLen  = MAX_STRING_LEN;
    return ReplaceText(&fr_dlgStruc);
    }
  else
    return FindText(&fr_dlgStruc); // Hier wird Dialog aufgerufen; Find- und ReplaceText warten Benutzereingaben
    // in Suchfelder NICHT ab, sondern kehren sofort unter Rueckgabe von hFindDlg zurueck (moduslos).
  }
예제 #27
0
LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 
{
	HWND hWnd;
	static FINDREPLACE find;
	static char findbuf[256];
	static unsigned char *file;
	static HWND hTool, hClip, hStatus;
	static RECT rOld;
	CHARFORMAT2 chars;

	if (message == WM_FINDMSGSTRING)
	{
		FINDREPLACE *fr = (FINDREPLACE *)lParam;

		if (fr->Flags & FR_FINDNEXT)
		{
			HWND hRich = GetDlgItem(hDlg, IDC_TEXT);
			DWORD flags=0;
			FINDTEXTEX ft;
			CHARRANGE chrg;

			if (fr->Flags & FR_DOWN)
				flags |= FR_DOWN;
			if (fr->Flags & FR_MATCHCASE)
				flags |= FR_MATCHCASE;
			if (fr->Flags & FR_WHOLEWORD)
				flags |= FR_WHOLEWORD;
			ft.lpstrText = fr->lpstrFindWhat;
			SendMessage(hRich, EM_EXGETSEL, 0, (LPARAM)&chrg);
			if (flags & FR_DOWN)
			{
				ft.chrg.cpMin = chrg.cpMax;
				ft.chrg.cpMax = -1;
			}
			else
			{
				ft.chrg.cpMin = chrg.cpMin;
				ft.chrg.cpMax = -1;
			}
			if (SendMessage(hRich, EM_FINDTEXTEX, flags, (LPARAM)&ft) == -1)
				MessageBox(NULL, "UnrealIRCd has finished searching the document",
					"Find", MB_ICONINFORMATION|MB_OK);
			else
			{
				SendMessage(hRich, EM_EXSETSEL, 0, (LPARAM)&(ft.chrgText));
				SendMessage(hRich, EM_SCROLLCARET, 0, 0);
				SetFocus(hRich);
			}
		}
		return TRUE;
	}
	switch (message) 
	{
		case WM_INITDIALOG: 
		{
			int fd,len;
			char *buffer, *string;
			EDITSTREAM edit;
			StreamIO *stream = MyMallocEx(sizeof(StreamIO));
			unsigned char szText[256];
			struct stat sb;
			HWND hWnd = GetDlgItem(hDlg, IDC_TEXT), hTip;
			file = (unsigned char *)lParam;
			if (file)
				wsprintf(szText, "UnrealIRCd Editor - %s", file);
			else 
				strcpy(szText, "UnrealIRCd Editor - New File");
			SetWindowText(hDlg, szText);
			lpfnOldWndProc = (FARPROC)SetWindowLong(hWnd, GWL_WNDPROC, (DWORD)RESubClassFunc);
			hTool = DrawToolbar(hInst, hDlg);
			hStatus = DrawStatusbar(hInst, hDlg, IDC_STATUS);
			SendMessage(hWnd, EM_SETEVENTMASK, 0, (LPARAM)ENM_SELCHANGE);
			chars.cbSize = sizeof(CHARFORMAT2);
			chars.dwMask = CFM_FACE;
			strcpy(chars.szFaceName,"Fixedsys");
			SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_ALL, (LPARAM)&chars);
			if ((fd = open(file, _O_RDONLY|_O_BINARY)) != -1) 
			{
				fstat(fd,&sb);
				/* Only allocate the amount we need */
				buffer = MyMallocEx(sb.st_size+1);
				len = read(fd, buffer, sb.st_size);
				buffer[len] = 0;
				len = CountRTFSize(buffer)+1;
				string = MyMallocEx(len);
				IRCToRTF(buffer,string);
				RTFBuf = string;
				len--;
				stream->size = &len;
				stream->buffer = &RTFBuf;
				edit.dwCookie = (UINT)stream;
				edit.pfnCallback = SplitIt;
				SendMessage(hWnd, EM_EXLIMITTEXT, 0, (LPARAM)0x7FFFFFFF);
				SendMessage(hWnd, EM_STREAMIN, (WPARAM)SF_RTF|SFF_PLAINRTF, (LPARAM)&edit);
				SendMessage(hWnd, EM_SETMODIFY, (WPARAM)FALSE, 0);
				SendMessage(hWnd, EM_EMPTYUNDOBUFFER, 0, 0);
				close(fd);
				RTFBuf = NULL;
				free(buffer);
				free(string);
				free(stream);
				hClip = SetClipboardViewer(hDlg);
				if (SendMessage(hWnd, EM_CANPASTE, 0, 0)) 
					SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_PASTE, (LPARAM)MAKELONG(TRUE,0));
				else
					SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_PASTE, (LPARAM)MAKELONG(FALSE,0));
				SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_UNDO, (LPARAM)MAKELONG(FALSE,0));
				wsprintf(szText, "Line: 1");
				SetWindowText(hStatus, szText);
			}
			return TRUE;
		}
		case WM_WINDOWPOSCHANGING:
		{
			GetClientRect(hDlg, &rOld);
			return FALSE;
		}
		case WM_SIZE:
		{
			DWORD new_width, new_height;
			HWND hRich;
			RECT rOldRich;
			DWORD old_width, old_height;
			DWORD old_rich_width, old_rich_height;
			if (hDlg == hFind)
				return FALSE;
			new_width =  LOWORD(lParam);
			new_height = HIWORD(lParam);
			hRich  = GetDlgItem(hDlg, IDC_TEXT);
			SendMessage(hStatus, WM_SIZE, 0, 0);
			SendMessage(hTool, TB_AUTOSIZE, 0, 0);
			old_width = rOld.right-rOld.left;
			old_height = rOld.bottom-rOld.top;
			new_width = new_width - old_width;
			new_height = new_height - old_height;
			GetWindowRect(hRich, &rOldRich);
			old_rich_width = rOldRich.right-rOldRich.left;
			old_rich_height = rOldRich.bottom-rOldRich.top;
			SetWindowPos(hRich, NULL, 0, 0, old_rich_width+new_width, 
				old_rich_height+new_height,
				SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOZORDER);
			bzero(&rOld, sizeof(RECT));
			return TRUE;
		} 

		case WM_NOTIFY:
			switch (((NMHDR *)lParam)->code) 
			{
				case EN_SELCHANGE: 
				{
					HWND hWnd = GetDlgItem(hDlg, IDC_TEXT);
					DWORD start, end, currline;
					static DWORD prevline = 0;
					unsigned char buffer[512];
					chars.cbSize = sizeof(CHARFORMAT2);
					SendMessage(hWnd, EM_GETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&chars);
					if (chars.dwMask & CFM_BOLD && chars.dwEffects & CFE_BOLD)
						SendMessage(hTool, TB_CHECKBUTTON, (WPARAM)IDC_BOLD, (LPARAM)MAKELONG(TRUE,0));
					else
						SendMessage(hTool, TB_CHECKBUTTON, (WPARAM)IDC_BOLD, (LPARAM)MAKELONG(FALSE,0));
					if (chars.dwMask & CFM_UNDERLINE && chars.dwEffects & CFE_UNDERLINE)
						SendMessage(hTool, TB_CHECKBUTTON, (WPARAM)IDC_UNDERLINE, (LPARAM)MAKELONG(TRUE,0));
					else
						SendMessage(hTool, TB_CHECKBUTTON, (WPARAM)IDC_UNDERLINE, (LPARAM)MAKELONG(FALSE,0));
					SendMessage(hWnd, EM_GETSEL,(WPARAM)&start, (LPARAM)&end);
					if (start == end) 
					{
						SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_COPY, (LPARAM)MAKELONG(FALSE,0));
						SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_CUT, (LPARAM)MAKELONG(FALSE,0));
					}
					else 
					{
						SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_COPY, (LPARAM)MAKELONG(TRUE,0));
						SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_CUT, (LPARAM)MAKELONG(TRUE,0));
					}
					if (SendMessage(hWnd, EM_CANUNDO, 0, 0)) 
						SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_UNDO, (LPARAM)MAKELONG(TRUE,0));
					else
						SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_UNDO, (LPARAM)MAKELONG(FALSE,0));
					if (SendMessage(hWnd, EM_CANREDO, 0, 0)) 
						SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_REDO, (LPARAM)MAKELONG(TRUE,0));
					else
						SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_REDO, (LPARAM)MAKELONG(FALSE,0));
					currline = SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, 0);
					currline++;
					if (currline != prevline) 
					{
						wsprintf(buffer, "Line: %d", currline);
						SetWindowText(hStatus, buffer);
						prevline = currline;
					}
				return TRUE;
			}
			case TTN_GETDISPINFO: 
			{
				LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT) lParam;
				lpttt->hinst = NULL;
				switch (lpttt->hdr.idFrom) 
				{
					case IDM_NEW:
						strcpy(lpttt->szText, "New");
						break;
					case IDM_SAVE:
						strcpy(lpttt->szText, "Save");
						break;
					case IDM_CUT:
						strcpy(lpttt->szText, "Cut");
						break;
					case IDM_COPY:
						strcpy(lpttt->szText, "Copy");
						break;
					case IDM_PASTE:
						strcpy(lpttt->szText, "Paste");
						break;
					case IDM_UNDO:
						strcpy(lpttt->szText, "Undo");
						break;
					case IDM_REDO:
						strcpy(lpttt->szText, "Redo");
						break;
					case IDC_BOLD:
						strcpy(lpttt->szText, "Bold");
						break;
					case IDC_UNDERLINE:
						strcpy(lpttt->szText, "Underline");
						break;
					case IDC_COLOR:
						strcpy(lpttt->szText, "Text Color");
						break;
					case IDC_BGCOLOR:
						strcpy(lpttt->szText, "Background Color");
						break;
					case IDC_GOTO:
						strcpy(lpttt->szText, "Goto");
						break;
					case IDC_FIND:
						strcpy(lpttt->szText, "Find");
						break;
				}
				return TRUE;
			}
			case NM_DBLCLK:
				DialogBox(hInst, "GOTO", hDlg, (DLGPROC)GotoDLG);
				return (TRUE);
		}
				
				return (TRUE);
		case WM_COMMAND:
			if (LOWORD(wParam) == IDC_BOLD) 
			{
				hWnd = GetDlgItem(hDlg, IDC_TEXT);
				if (SendMessage(hTool, TB_ISBUTTONCHECKED, (WPARAM)IDC_BOLD, (LPARAM)0) != 0) 
				{
					chars.cbSize = sizeof(CHARFORMAT2);
					chars.dwMask = CFM_BOLD;
					chars.dwEffects = CFE_BOLD;
					SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&chars);
					SendMessage(hWnd, EM_HIDESELECTION, 0, 0);
					SetFocus(hWnd);
				}
				else 
				{
					chars.cbSize = sizeof(CHARFORMAT2);
					chars.dwMask = CFM_BOLD;
					chars.dwEffects = 0;
					SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&chars);
					SendMessage(hWnd, EM_HIDESELECTION, 0, 0);
					SetFocus(hWnd);
				}
				return TRUE;
			}
			else if (LOWORD(wParam) == IDC_UNDERLINE) 
			{
				hWnd = GetDlgItem(hDlg, IDC_TEXT);
				if (SendMessage(hTool, TB_ISBUTTONCHECKED, (WPARAM)IDC_UNDERLINE, (LPARAM)0) != 0) 
				{
					chars.cbSize = sizeof(CHARFORMAT2);
					chars.dwMask = CFM_UNDERLINETYPE;
					chars.bUnderlineType = CFU_UNDERLINE;
					SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&chars);
					SendMessage(hWnd, EM_HIDESELECTION, 0, 0);
					SetFocus(hWnd);
				}
				else 
				{
					chars.cbSize = sizeof(CHARFORMAT2);
					chars.dwMask = CFM_UNDERLINETYPE;
					chars.bUnderlineType = CFU_UNDERLINENONE;
					SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&chars);
					SendMessage(hWnd, EM_HIDESELECTION, 0, 0);
					SetFocus(hWnd);
				}
				return TRUE;
			}
			if (LOWORD(wParam) == IDC_COLOR) 
			{
				DialogBoxParam(hInst, "Color", hDlg, (DLGPROC)ColorDLG, (LPARAM)WM_USER+10);
				return 0;
			}
			if (LOWORD(wParam) == IDC_BGCOLOR)
			{
				DialogBoxParam(hInst, "Color", hDlg, (DLGPROC)ColorDLG, (LPARAM)WM_USER+11);
				return 0;
			}
			if (LOWORD(wParam) == IDC_GOTO)
			{
				DialogBox(hInst, "GOTO", hDlg, (DLGPROC)GotoDLG);
				return 0;
			}
			if (LOWORD(wParam) == IDC_FIND)
			{
				static FINDREPLACE fr;
				bzero(&fr, sizeof(FINDREPLACE));
				fr.lStructSize = sizeof(FINDREPLACE);
				fr.hwndOwner = hDlg;
				fr.lpstrFindWhat = findbuf;
				fr.wFindWhatLen = 255;
				hFind = FindText(&fr);
				return 0;
			}
				
			hWnd = GetDlgItem(hDlg, IDC_TEXT);
			if (LOWORD(wParam) == IDM_COPY) 
			{
				SendMessage(hWnd, WM_COPY, 0, 0);
				return 0;
			}
			if (LOWORD(wParam) == IDM_SELECTALL) 
			{
				SendMessage(hWnd, EM_SETSEL, 0, -1);
				return 0;
			}
			if (LOWORD(wParam) == IDM_PASTE) 
			{
				SendMessage(hWnd, WM_PASTE, 0, 0);
				return 0;
			}
			if (LOWORD(wParam) == IDM_CUT) 
			{
				SendMessage(hWnd, WM_CUT, 0, 0);
				return 0;
			}
			if (LOWORD(wParam) == IDM_UNDO) 
			{
				SendMessage(hWnd, EM_UNDO, 0, 0);
				return 0;
			}
			if (LOWORD(wParam) == IDM_REDO) 
			{
				SendMessage(hWnd, EM_REDO, 0, 0);
				return 0;
			}
			if (LOWORD(wParam) == IDM_DELETE) 
			{
				SendMessage(hWnd, WM_CLEAR, 0, 0);
				return 0;
			}
			if (LOWORD(wParam) == IDM_SAVE) 
			{
				int fd;
				EDITSTREAM edit;
				OPENFILENAME lpopen;
				if (!file) 
				{
					unsigned char path[MAX_PATH];
					path[0] = '\0';
					bzero(&lpopen, sizeof(OPENFILENAME));
					lpopen.lStructSize = sizeof(OPENFILENAME);
					lpopen.hwndOwner = hDlg;
					lpopen.lpstrFilter = NULL;
					lpopen.lpstrCustomFilter = NULL;
					lpopen.nFilterIndex = 0;
					lpopen.lpstrFile = path;
					lpopen.nMaxFile = MAX_PATH;
					lpopen.lpstrFileTitle = NULL;
					lpopen.lpstrInitialDir = CONFDIR;
					lpopen.lpstrTitle = NULL;
					lpopen.Flags = (OFN_ENABLESIZING|OFN_NONETWORKBUTTON|
							OFN_OVERWRITEPROMPT);
					if (GetSaveFileName(&lpopen))
						file = path;
					else
						break;
				}
				fd = open(file, _O_TRUNC|_O_CREAT|_O_WRONLY|_O_BINARY,_S_IWRITE);
				edit.dwCookie = 0;
				edit.pfnCallback = BufferIt;
				SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_STREAMOUT, (WPARAM)SF_RTF|SFF_PLAINRTF, (LPARAM)&edit);
				RTFToIRC(fd, RTFBuf, strlen(RTFBuf));
				free(RTFBuf);
				RTFBuf = NULL;
				SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_SETMODIFY, (WPARAM)FALSE, 0);
	
				return 0;
			}
			if (LOWORD(wParam) == IDM_NEW) 
			{
				unsigned char text[1024];
				BOOL newfile = FALSE;
				int ans;
				if (SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_GETMODIFY, 0, 0) != 0) 
				{
					sprintf(text, "The text in the %s file has changed.\r\n\r\nDo you want to save the changes?", file ? file : "new");
					ans = MessageBox(hDlg, text, "UnrealIRCd", MB_YESNOCANCEL|MB_ICONWARNING);
					if (ans == IDNO)
						newfile = TRUE;
					if (ans == IDCANCEL)
						return TRUE;
					if (ans == IDYES) 
					{
						SendMessage(hDlg, WM_COMMAND, MAKEWPARAM(IDM_SAVE,0), 0);
						newfile = TRUE;
					}
				}
				else
					newfile = TRUE;
				if (newfile == TRUE) 
				{
					unsigned char szText[256];
					file = NULL;
					strcpy(szText, "UnrealIRCd Editor - New File");
					SetWindowText(hDlg, szText);
					SetWindowText(GetDlgItem(hDlg, IDC_TEXT), NULL);
				}
				break;
			}
			break;
		case WM_USER+10: 
		{
			HWND hWnd = GetDlgItem(hDlg, IDC_TEXT);
			EndDialog((HWND)lParam, TRUE);
			chars.cbSize = sizeof(CHARFORMAT2);
			chars.dwMask = CFM_COLOR;
			chars.crTextColor = (COLORREF)wParam;
			SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&chars);
			SendMessage(hWnd, EM_HIDESELECTION, 0, 0);
			SetFocus(hWnd);
			break;
		}
		case WM_USER+11: 
		{
			HWND hWnd = GetDlgItem(hDlg, IDC_TEXT);
			EndDialog((HWND)lParam, TRUE);
			chars.cbSize = sizeof(CHARFORMAT2);
			chars.dwMask = CFM_BACKCOLOR;
			chars.crBackColor = (COLORREF)wParam;
			SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&chars);
			SendMessage(hWnd, EM_HIDESELECTION, 0, 0);
			SetFocus(hWnd);
			break;
		}
		case WM_CHANGECBCHAIN:
			if ((HWND)wParam == hClip)
				hClip = (HWND)lParam;
			else
				SendMessage(hClip, WM_CHANGECBCHAIN, wParam, lParam);
			break;
		case WM_DRAWCLIPBOARD:
			if (SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_CANPASTE, 0, 0)) 
				SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_PASTE, (LPARAM)MAKELONG(TRUE,0));
			else
				SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_PASTE, (LPARAM)MAKELONG(FALSE,0));
			SendMessage(hClip, WM_DRAWCLIPBOARD, wParam, lParam);
			break;
		case WM_CLOSE: 
		{
			unsigned char text[256];
			int ans;
			if (SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_GETMODIFY, 0, 0) != 0) 
			{
				sprintf(text, "The text in the %s file has changed.\r\n\r\nDo you want to save the changes?", file ? file : "new");
				ans = MessageBox(hDlg, text, "UnrealIRCd", MB_YESNOCANCEL|MB_ICONWARNING);
				if (ans == IDNO)
					EndDialog(hDlg, TRUE);
				if (ans == IDCANCEL)
					return TRUE;
				if (ans == IDYES) 
				{
					SendMessage(hDlg, WM_COMMAND, MAKEWPARAM(IDM_SAVE,0), 0);
					EndDialog(hDlg, TRUE);
				}
			}
			else
				EndDialog(hDlg, TRUE);
			break;
		}
		case WM_DESTROY:
			ChangeClipboardChain(hDlg, hClip);
			break;
	}

	return FALSE;
}
예제 #28
0
bool FindReplace::FindNext()
{
    return FindText( Searchable::Direction_Down );
}
예제 #29
0
BOOL UFindReplaceDialog::go( LPCTSTR lpText )
{
    lstrcpy(m_buffer, lpText);
    m_hDlg = FindText(&m_fr);
    return FALSE;
}
예제 #30
0
bool FindReplace::FindPrevious()
{
    return FindText( Searchable::Direction_Up );
}