Ejemplo n.º 1
0
WStringVector PME::GetStringVectorW ( )
{
	WStringVector oStringVector;

	for ( int nCurrentMatch = 0;
		  nCurrentMatch < nMatches;
		  nCurrentMatch++ ) {

			  oStringVector.insert( oStringVector.end ( ), Text::utf8ToWide( (*this)[nCurrentMatch] ) );
		  }

	return oStringVector;
}
Ejemplo n.º 2
0
void ChatView::mucNickComplete() {
    //step 1 - verify if this chat is muc-chat
    MucGroup::ref roomGrp;
    roomGrp=boost::dynamic_pointer_cast<MucGroup> (rc->roster->findGroup(contact->jid.getBareJid()));
    if (!roomGrp) return;
    if (roomGrp->room!=contact) return;

    //step 2 - extracting data for autocomplete
    wchar_t buf[1024];
    int len=SendMessage(editWnd, WM_GETTEXT, 1024, (LPARAM) buf);
    size_t mbegin;
    size_t mend;
    SendMessage(editWnd, EM_GETSEL, (WPARAM)&mbegin, (LPARAM)&mend);

    //step 3 - search nick begin and end
    size_t nbegin=mbegin;
    while (nbegin>0) {
        nbegin--;
        if (iswspace(buf[nbegin])) { nbegin++; break; }
    }

    size_t nend=mend;
    while (nend>mbegin) {
        nend--;
        if (buf[nend]==':') continue;
        if (!iswspace(buf[nend])) { nend++; break; }
    }

    //now: [nbegin..mbegin) - constant part (case may be altered)
    size_t clen=mbegin-nbegin;
    //     [mbegin..mend) - may be fully rewritten, selection will be kept
    //     [nend..mend) = ':' + whitespaces
    size_t nlen=nend-nbegin;


    //step 4 - pull and filter nicknames
    WStringVector nicks;
    {
        Roster::ContactListRef participants=rc->roster->getGroupContacts(roomGrp);

        for (Roster::ContactList::iterator i=participants->begin(); i!=participants->end(); i++) {
            std::wstring &ws=utf8::utf8_wchar( (*i)->jid.getResource() );

            if (ws.length()<clen) continue;
            if (clen>0) if (_wcsnicmp(buf+nbegin, ws.c_str(), clen)!=0) continue;

            nicks.push_back(ws);
        }
    }
    if (nicks.empty()) return;

    //step 5 - sorting
    stable_sort(nicks.begin(), nicks.end(), nickCompare);

    //step 6 - search for nick instance
    int loop=nicks.size();
    WStringVector::iterator i=nicks.begin();

    while (loop) {
        std::wstring &s=(*i);

        i++; 
        if (i==nicks.end()) 
            i=nicks.begin();
        loop--;

        if (s.length()==nlen) {
            if (_wcsnicmp(buf+nbegin, s.c_str(), nlen)==0) break;
        } 
    }


    std::wstring &s=(*i);
    s+=L": ";
    SendMessage(editWnd, EM_SETSEL, nbegin, mend);
    SendMessage(editWnd, EM_REPLACESEL, TRUE, (LPARAM)s.c_str());
    SendMessage(editWnd, EM_SETSEL, mbegin, nbegin+s.length());
}