#include "WndContact.h"
#include "vdricqosd.h"
#include "icqhook.h"
#include "WndMessagelist.h"
#include "WndStatusbar.h"
#include "vdricqTools.h"
#include "NumberList.h"
#include "vdricqsetup.h"


// ----------- cContactWnd --------------------------------------------------------------

cContactWnd::cContactWnd(int iLeft, int iTop, int iWidth, int iHeight, int iBpP, cOsd *pOsd, 
                         cVdrIcqOsd *pVdrIcqOsd, SimpleClient *pIcqClient, cStatusbarWnd *pStatusbarWnd)
{
  tArea Area    = { iLeft, iTop, iLeft + iWidth - 1, iTop + iHeight - 1, iBpP };
  m_Area        = Area;
  m_pOsd        = pOsd;
  m_pVdrIcqOsd  = pVdrIcqOsd;
  m_pIcqClient  = pIcqClient;
  m_pStatusbarWnd = pStatusbarWnd;
  m_pContactList  = NULL;
  m_iSelectedUIN  = 1;
  m_iSelectedPos  = 0;
  m_eActiveMenu   = cwmDefault;
  m_bOnlineGroupSchow     = true;
  m_bOfflineGroupSchow    = true;
  m_bAwaitingGroupSchow   = true;
  m_bIgnorelistGroupSchow  = false;
  m_bSearchmenuEnable     = false;
  m_pSerchField1          = NULL;
  m_pSerchField2          = NULL;
  m_pSerchField3          = NULL;
  m_bWaitForSerchResult   = false;
  m_pSerchResultCotactList    = NULL;
  m_iSelectedSerchResult      = 0;
  m_iFirsSearchResultListPos  = 0;
  m_iLastSearchResultListPos  = 0;
  m_pAuthField                = NULL;
}

cContactWnd::~cContactWnd()
{
  delete m_pAuthField;
  delete m_pSerchField1;
  delete m_pSerchField2;
  delete m_pSerchField3;
  delete m_pSerchResultCotactList;
}

tArea cContactWnd::GetArea(void)
{
  return m_Area;
}

void cContactWnd::SetContactList(ICQ2000::ContactList *pContactList)
{
  m_pContactList = pContactList;

  m_OnlineContactList.clear();
  m_OfflineContactList.clear();

  ICQ2000::ContactList::iterator curr = m_pContactList->begin();
  while (curr != m_pContactList->end())
  {
    string sAlias = (*curr)->getNameAlias();

    ICQ2000::ContactRef MyContact = m_pIcqClient->GetSelfContact();
    if ((*curr)->getUIN() != MyContact->getUIN())
    {
      cNumberList *pIgnoreList = m_pIcqClient->GetIgnoreList();
      if ((pIgnoreList) && (pIgnoreList->inList((*curr)->getUIN())))
      {
        // user in ignorelist
      }
      else if (((*curr)->getStatus() == ICQ2000::STATUS_ONLINE) || ((*curr)->getStatus() == ICQ2000::STATUS_AWAY))
      {
        std::list<unsigned int>::iterator curr2 = m_OnlineContactList.begin();
        while((curr2 != m_OnlineContactList.end()) && 
              (sAlias.compare(m_pContactList->lookup_uin(*curr2)->getNameAlias()) > 0))
        {
          ++curr2;
        }
        m_OnlineContactList.insert(curr2, (*curr)->getUIN());
      }
      else
      {
        std::list<unsigned int>::iterator curr2 = m_OfflineContactList.begin();
        while((curr2 != m_OfflineContactList.end()) && 
              (sAlias.compare(m_pContactList->lookup_uin(*curr2)->getNameAlias()) > 0))
        {
          ++curr2;
        }
        m_OfflineContactList.insert(curr2, (*curr)->getUIN());
      }
    }

    ++curr;
  }

  Draw();
}


eOSState cContactWnd::ProcessKey(eKeys Key)
{
  if (m_pAuthField != NULL)
    return ProcessKeyAuthDialog(Key);

  if (m_bSearchmenuEnable)
    return ProcessKeySearch(Key);

  std::list<unsigned int>::iterator pos;
  cNumberList::iterator posAwait;
  cNumberList::iterator posIgnor;
  cNumberList *pWaitList = m_pIcqClient->GetWaitList();
  cNumberList *pIgnoreList = m_pIcqClient->GetIgnoreList();
  switch (Key) 
  {
  case kUp|k_Repeat:
  case kUp:
    if (m_iSelectedUIN == 1)
    {
      m_iSelectedPos = 0;
    }
    else if (m_iSelectedUIN == 2) 
    {
      if ((m_OnlineContactList.size() > 0) && (m_bOnlineGroupSchow))
      {
        pos = m_OnlineContactList.end();
        pos--;
        m_iSelectedUIN = *pos;
      }
      else
      {
        m_iSelectedUIN = 1;
        m_iSelectedPos = 0;
      }
    }
    else if (m_iSelectedUIN == 3) 
    {
      if ((m_OfflineContactList.size() > 0) && (m_bOfflineGroupSchow))
      {
        pos = m_OfflineContactList.end();
        pos--;
        m_iSelectedUIN = *pos;
      }
      else
      {
        m_iSelectedUIN = 2;
        m_iSelectedPos = 0;
      }
    }
    else if (m_iSelectedUIN == 4) 
    {
      if (pWaitList->size() > 0)
      {
        if (m_bAwaitingGroupSchow)
        {
          posAwait = pWaitList->end();
          posAwait--;
          m_iSelectedUIN = (*posAwait)->getUIN();
        }
        else
        {
          m_iSelectedUIN = 3;
          m_iSelectedPos = 0;
        }
      }
      else
      {
        m_iSelectedUIN = 2;
        m_iSelectedPos = 0;
      }
    }
    else if ((pos = FindListpos(&m_OnlineContactList, m_iSelectedUIN)) != m_OnlineContactList.end())
    {
      if (pos == m_OnlineContactList.begin())
      {
         m_iSelectedUIN = 1;
      }
      else
      {
        pos--;
        m_iSelectedUIN = *pos;
      }
    }
    else if ((pos = FindListpos(&m_OfflineContactList, m_iSelectedUIN)) != m_OfflineContactList.end())
    {
      if (pos == m_OfflineContactList.begin())
      {
         m_iSelectedUIN = 2;
      }
      else
      {
        pos--;
        m_iSelectedUIN = *pos;
      }
    }
    else if ((posAwait = pWaitList->find(m_iSelectedUIN)) != pWaitList->end())
    {
      if (posAwait == pWaitList->begin())
      {
         m_iSelectedUIN = 3;
      }
      else
      {
        posAwait--;
        m_iSelectedUIN = (*posAwait)->getUIN();
      }
    }
    else if ((posIgnor = pIgnoreList->find(m_iSelectedUIN)) != pIgnoreList->end())
    {
      if (posIgnor == pIgnoreList->begin())
      {
         m_iSelectedUIN = 4;
      }
      else
      {
        posIgnor--;
        m_iSelectedUIN = (*posIgnor)->getUIN();
      }
    }
    else
    {
      m_iSelectedUIN = 1;
      m_iSelectedPos = 0;
    }
    break;

  case kDown|k_Repeat:
  case kDown:
    if (m_iSelectedUIN == 1)
    {
      if ((m_OnlineContactList.size() > 0) && (m_bOnlineGroupSchow))
      {
        pos = m_OnlineContactList.begin();
        m_iSelectedUIN = *pos;
      }
      else
      {
        m_iSelectedUIN = 2;
      }
    }
    else if (m_iSelectedUIN == 2)
    {
      if ((m_OfflineContactList.size() > 0) && (m_bOfflineGroupSchow))
      {
        pos = m_OfflineContactList.begin();
        m_iSelectedUIN = *pos;
      }
      else if (pWaitList->size() > 0)
      {
        m_iSelectedUIN = 3;
      }
      else if (pIgnoreList->size() > 0)
      {
        m_iSelectedUIN = 4;
      }
    }
    else if (m_iSelectedUIN == 3)
    {
      if ((pWaitList->size() > 0) && (m_bAwaitingGroupSchow))
      {
        posAwait = pWaitList->begin();
        m_iSelectedUIN = (*posAwait)->getUIN();
      }
      else if (pIgnoreList->size() > 0)
      {
        m_iSelectedUIN = 4;
      }
    }
    else if (m_iSelectedUIN == 4)
    {
      if ((pIgnoreList->size() > 0) && (m_bIgnorelistGroupSchow))
      {
        posIgnor = pIgnoreList->begin();
        m_iSelectedUIN = (*posIgnor)->getUIN();
      }
    }
    else if ((pos = FindListpos(&m_OnlineContactList, m_iSelectedUIN)) != m_OnlineContactList.end())
    {
      pos++;
      if (pos != m_OnlineContactList.end())
      {
         m_iSelectedUIN = *pos;
      }
      else
      {
        m_iSelectedUIN = 2;
      }
    }
    else if ((pos = FindListpos(&m_OfflineContactList, m_iSelectedUIN)) != m_OfflineContactList.end())
    {
      pos++;
      if (pos != m_OfflineContactList.end())
      {
        m_iSelectedUIN = *pos;
      }
      else if (pWaitList->size() > 0)
      {
        m_iSelectedUIN = 3;
      }
      else if (pIgnoreList->size() > 0)
      {
        m_iSelectedUIN = 4;
      }
    }
    else if ((posAwait = pWaitList->find(m_iSelectedUIN)) != pWaitList->end())
    {
      posAwait++;
      if (posAwait != pWaitList->end())
      {
        m_iSelectedUIN = (*posAwait)->getUIN();
      }
      else if (pIgnoreList->size() > 0)
      {
        m_iSelectedUIN = 4;
      }
    }
    else if ((posIgnor = pIgnoreList->find(m_iSelectedUIN)) != pIgnoreList->end())
    {
      posIgnor++;
      if (posIgnor != pIgnoreList->end())
      {
        m_iSelectedUIN = (*posIgnor)->getUIN();
      }
    }
    else
    {
      m_iSelectedUIN = 1;
      m_iSelectedPos = 0;
    }
    break;

  case kOk:
    if (m_iSelectedUIN > 10)
    {
      m_pIcqClient->SetActiveContact(m_pContactList->lookup_uin(m_iSelectedUIN));
      m_pStatusbarWnd->ShowDefaultButtons();
      return osContinue;    
    }
    break;

  case kRed:
    if ((m_eActiveMenu == cwmOnlineContact) || (m_eActiveMenu == cwmOfflineContact) || 
        (m_eActiveMenu == cwmAwaitingContact) || (m_eActiveMenu == cwmIgnorelistContact))
    {
      int iOldCounter = m_pIcqClient->getDetailInfoUpdateCounter();
      m_pStatusbarWnd->Message(mtInfo, tr("Waiting for contactdetails"), 20);
      
      if (m_eActiveMenu == cwmAwaitingContact)
      {
        m_pIcqClient->GetClient()->fetchDetailContactInfo(pWaitList->getContact(m_iSelectedUIN));
      }
      else if (m_eActiveMenu == cwmIgnorelistContact)
      {
        m_pIcqClient->GetClient()->fetchDetailContactInfo(pIgnoreList->getContact(m_iSelectedUIN));
      }
      else
      {
        m_pIcqClient->GetClient()->fetchDetailContactInfo(m_pContactList->lookup_uin(m_iSelectedUIN));
      }
      
      for(int i = 0; (i < 15) && (iOldCounter == m_pIcqClient->getDetailInfoUpdateCounter()); i++)
        usleep(100000);
 
      if (m_eActiveMenu == cwmAwaitingContact)
        m_pVdrIcqOsd->GetMessagelistWnd()->ShowContactDetails(pWaitList->getContact(m_iSelectedUIN));
      else if (m_eActiveMenu == cwmIgnorelistContact)
        m_pVdrIcqOsd->GetMessagelistWnd()->ShowContactDetails(pIgnoreList->getContact(m_iSelectedUIN));
      else
        m_pVdrIcqOsd->GetMessagelistWnd()->ShowContactDetails(m_pContactList->lookup_uin(m_iSelectedUIN));

      m_pStatusbarWnd->Message(mtInfo, NULL);
      return osContinue;
    }
    else if (m_eActiveMenu == cwmOnline)
    {
      m_bOnlineGroupSchow = !m_bOnlineGroupSchow;
    }
    else if (m_eActiveMenu == cwmOffline)
    {
      m_bOfflineGroupSchow = !m_bOfflineGroupSchow;
    }
    else if (m_eActiveMenu == cwmAwaiting)
    {
      m_bAwaitingGroupSchow = !m_bAwaitingGroupSchow;
    }
    else if (m_eActiveMenu == cwmIgnorelist)
    {
      m_bIgnorelistGroupSchow = !m_bIgnorelistGroupSchow;
    }
    
    
    break;
  
  case kGreen:
    if ((m_eActiveMenu == cwmOnlineContact) || (m_eActiveMenu == cwmOfflineContact))
    {
      m_pStatusbarWnd->Message(mtWarning, "Function does not implement");
      return osContinue;
    }
    else if (m_eActiveMenu == cwmIgnorelistContact)
    {
      ICQ2000::ContactRef c = pIgnoreList->getContact(m_iSelectedUIN);
      m_pIcqClient->GetClient()->addContact(c);
      pIgnoreList->removeContact(m_iSelectedUIN);
      pIgnoreList->saveList();
    }
    else if ((m_eActiveMenu == cwmOnline) || (m_eActiveMenu == cwmOffline) || 
             (m_eActiveMenu == cwmAwaiting) || (m_eActiveMenu == cwmIgnorelist))
    {
      m_bSearchmenuEnable  = true;
      m_eSearchDialog      = ssdNone;
      SetHelpKeys();
    }
    break;

  case kYellow:
    if ((m_eActiveMenu == cwmOnlineContact) || (m_eActiveMenu == cwmOfflineContact))
    { // Contact to ignorlist
      ICQ2000::ContactRef c = m_pIcqClient->GetClient()->getContact(m_iSelectedUIN);
      pIgnoreList->insert(pIgnoreList->end(), c);
      pIgnoreList->saveList();
      m_pIcqClient->GetClient()->removeContact(m_iSelectedUIN);
      m_iSelectedUIN = 0;
      if (m_iSelectedPos > 0)
        m_iSelectedPos = 0;
    }
    else if (m_eActiveMenu == cwmAwaitingContact)
    { // show Autorisation Dialog / resend Authorisation
      m_SelectedSerchResultContact = pWaitList->getContact(m_iSelectedUIN);
      ShowAuthDialog();
    }
    break;

  case kBlue:
    if (((m_eActiveMenu == cwmOnlineContact) || (m_eActiveMenu == cwmOfflineContact) || 
         (m_eActiveMenu == cwmAwaitingContact) || (m_eActiveMenu == cwmIgnorelistContact)) && 
        (m_pStatusbarWnd->Confirm("Remove User ?")))
    {
      dsyslog("vdricq: Remove User from Contactlist: %d", m_iSelectedUIN);
      if (m_eActiveMenu == cwmAwaitingContact)
      {
        pWaitList->removeContact(m_iSelectedUIN);
        pWaitList->saveList();
      }
      else if (m_eActiveMenu == cwmIgnorelistContact)
      {
        pIgnoreList->removeContact(m_iSelectedUIN);
        pIgnoreList->saveList();
      }
      else
      {
        m_pIcqClient->GetClient()->removeContact(m_iSelectedUIN);
        m_pIcqClient->GetClient()->uploadSelfDetails();
      }
      m_iSelectedUIN = 0;
      if (m_iSelectedPos > 0)
        m_iSelectedPos = 0;
      SetContactList(m_pContactList);
      return osContinue;
    }
    else if ((m_eActiveMenu == cwmOnline) || (m_eActiveMenu == cwmOffline) || 
             (m_eActiveMenu == cwmAwaiting) || (m_eActiveMenu == cwmIgnorelist))
    {
      m_pIcqClient->GetClient()->fetchServerBasedContactList();
    }
    break;

  case kBack:
    if (m_pAuthField)
    {
      delete m_pAuthField;
      m_pAuthField = NULL;
      m_pVdrIcqOsd->GetMessagelistWnd()->Draw();
      SetHelpKeys();
    }
    else
    {
      m_pStatusbarWnd->ShowDefaultButtons();
    }
    return osContinue;
    break;

  default:
    break;
  }

  Draw();

  return osContinue;
}

eOSState cContactWnd::ProcessKeySearch(eKeys Key)
{
  if (m_pSerchResultCotactList)
    return ProcessKeySearchResult(Key);

  if ((m_eSearchDialog != ssdNone) && 
      (((m_pSerchField1) && (m_pSerchField1->IsFocused()) && 
        ((m_pSerchField1->Editing()) || ((Key != kRed) && (Key != kGreen) && (Key != kYellow) && (Key != kBlue)))) ||
       ((m_pSerchField2) && (m_pSerchField2->IsFocused()) &&
        ((m_pSerchField2->Editing()) || ((Key != kRed) && (Key != kGreen) && (Key != kYellow) && (Key != kBlue)))) ||
       ((m_pSerchField3) && (m_pSerchField3->IsFocused()) &&
        ((m_pSerchField3->Editing()) || ((Key != kRed) && (Key != kGreen) && (Key != kYellow) && (Key != kBlue))))))
  {
    eOSState state = osUnknown;
    if ((m_pSerchField1) && (m_pSerchField1->IsFocused()))
      state = m_pSerchField1->ProcessKey(Key);
    else if ((m_pSerchField2) && (m_pSerchField2->IsFocused()))
      state = m_pSerchField2->ProcessKey(Key);
    else if ((m_pSerchField3) && (m_pSerchField3->IsFocused()))
      state = m_pSerchField3->ProcessKey(Key);

    if (state != osUnknown)
      return state;
  }


  switch (Key) 
  {
  case kRed:
    if (m_eSearchDialog == ssdNone)
    {
      ShowSearchDialog(ssdByICQNumber);
    }
    else
    {
      switch(m_eSearchDialog)
      {
      case ssdByICQNumber:
        m_pIcqClient->GetClient()->searchForContacts(atoi(m_pSerchField1->GetText().c_str()));
        break;
      
      case ssdByEMail:
        m_pIcqClient->GetClient()->searchForContacts("", "", "", m_pSerchField1->GetText(),
					 ICQ2000::range_NoRange, ICQ2000::SEX_UNSPECIFIED, 0, "", "", 0, "", "", "", false);
        break;

      case ssdByName:
        m_pIcqClient->GetClient()->searchForContacts(m_pSerchField3->GetText(), m_pSerchField2->GetText(),
          m_pSerchField1->GetText());
        break;

      default:
        break;
      }

      m_pStatusbarWnd->Message(mtInfo, tr("Waiting for searchresults"), 20);
      m_bWaitForSerchResult = true;
    }
    break;

  case kGreen:
    if (m_eSearchDialog == ssdNone)
    {
      ShowSearchDialog(ssdByEMail);
    }
    else
    {
      if (m_pSerchField1)
        m_pSerchField1->SetFocused(true);
      if (m_pSerchField2)
        m_pSerchField2->SetFocused(false);
      if (m_pSerchField3)
        m_pSerchField3->SetFocused(false);
    }
    break;

  case kYellow:
    if (m_eSearchDialog == ssdNone)
    {
      ShowSearchDialog(ssdByName);
    }
    else
    {
      if (m_pSerchField1)
        m_pSerchField1->SetFocused(false);
      if (m_pSerchField2)
        m_pSerchField2->SetFocused(true);
      if (m_pSerchField3)
        m_pSerchField3->SetFocused(false);
    }
    break;

  case kBlue:
    if (m_eSearchDialog != ssdNone)
    {
      if (m_pSerchField1)
        m_pSerchField1->SetFocused(false);
      if (m_pSerchField2)
        m_pSerchField2->SetFocused(false);
      if (m_pSerchField3)
        m_pSerchField3->SetFocused(true);
    }
    break;

  case kBack:
    if (m_bSearchmenuEnable)
    {
      if (m_eSearchDialog != ssdNone)
      {
        m_eSearchDialog = ssdNone;
        delete m_pSerchField1;
        m_pSerchField1 = NULL;
        delete m_pSerchField2;
        m_pSerchField2 = NULL;
        delete m_pSerchField3;
        m_pSerchField3 = NULL;      
      }
      else
      {
        m_bSearchmenuEnable = false;
      }

      m_pVdrIcqOsd->GetMessagelistWnd()->Draw();
      SetHelpKeys();
    }

  default:
    break;
  }

  return osContinue;
}


eOSState cContactWnd::ProcessKeySearchResult(eKeys Key)
{
  switch(Key)
  {
  case kUp:
  case kUp|k_Repeat:
    if (m_iSelectedSerchResult > 0)
      m_iSelectedSerchResult--;
    
    if (m_iFirsSearchResultListPos > m_iSelectedSerchResult)
    {
      m_iFirsSearchResultListPos--;
      m_iLastSearchResultListPos--;
    }
    ShowSearchResults();
    break;

  case kDown:
  case kDown|k_Repeat:
    if (m_iSelectedSerchResult < (int)m_pSerchResultCotactList->size() - 1)
      m_iSelectedSerchResult++;
    
    if (m_iLastSearchResultListPos < m_iSelectedSerchResult)
    {
      m_iFirsSearchResultListPos++;
      m_iLastSearchResultListPos++;
    }
    ShowSearchResults();
    break;

  case kRed:
    if ((m_pContactList->exists(m_SelectedSerchResultContact->getUIN())) || 
        (m_pIcqClient->GetWaitList()->inList(m_SelectedSerchResultContact->getUIN())))
    {
      m_pStatusbarWnd->Message(mtInfo, tr("The User is already in your Contact list."));
      break;
    }
    if (m_SelectedSerchResultContact->getAuthReq())
    {
      ShowAuthDialog();
      break;
    }
    else
    {
      ICQ2000::UserAddEvent *pUserAddEvent = new ICQ2000::UserAddEvent(m_SelectedSerchResultContact);   
      m_pIcqClient->GetClient()->SendEvent(pUserAddEvent);
      m_pIcqClient->GetClient()->addContact(m_SelectedSerchResultContact);
    }
    break;
   
  case kBack:
    delete m_pSerchResultCotactList;
    m_pSerchResultCotactList = NULL;
    ShowSearchDialog(m_eSearchDialog);
    SetHelpKeys();
    break;

  default:
    break;
  }

  return osContinue;
}


eOSState cContactWnd::ProcessKeyAuthDialog(eKeys Key)
{
  if ((m_pAuthField) && (m_pAuthField->IsFocused()) && 
      ((m_pAuthField->Editing()) || ((Key != kRed) && (Key != kGreen) && (Key != kYellow) && (Key != kBlue))))
  {
    eOSState state = osUnknown;
    state = m_pAuthField->ProcessKey(Key);
    if (state != osUnknown)
      return state;
  }

  switch(Key)
  {
  case kRed:
    {
      ICQ2000::AuthReqEvent *pAuthReqEvent = new ICQ2000::AuthReqEvent(m_SelectedSerchResultContact, 
        m_pAuthField->GetText());   
      m_pIcqClient->GetClient()->SendEvent(pAuthReqEvent);
      cNumberList *pWaitList = m_pIcqClient->GetWaitList();
      if ((pWaitList) && (!pWaitList->inList(m_SelectedSerchResultContact->getUIN())))
      {
        pWaitList->insert(pWaitList->end(), m_SelectedSerchResultContact);
        pWaitList->saveList();
        Draw();
      }
    }
    // no break;
        
  case kBack:
    delete m_pAuthField;
    m_pAuthField = NULL;
    ShowSearchResults();
    SetHelpKeys();
    break;

  default:
    break;
  }

  return osContinue;
}


void cContactWnd::SetHelpKeys(void)
{
  if (m_pAuthField != NULL)
  {
    m_pStatusbarWnd->SetButtons(tr("Send"));
  }
  else if (m_pSerchResultCotactList)
  {
    if (m_SelectedSerchResultContact->getUIN() == m_pIcqClient->GetSelfContact()->getUIN())
      m_pStatusbarWnd->SetButtons(NULL);
    else
      m_pStatusbarWnd->SetButtons(tr("Add User"));
  }
  else if (m_bSearchmenuEnable)
  {
    m_bWaitForSerchResult = false;
    switch(m_eSearchDialog)
    {
    case ssdByICQNumber:
    case ssdByEMail:
      m_pStatusbarWnd->SetButtons(tr("Serach"));
      break;

    case ssdByName:
      m_pStatusbarWnd->SetButtons(tr("Serach"), tr("First Name"), tr("Last Name"), tr("Nickname"));
      break;

    default:
      m_pStatusbarWnd->SetButtons(tr("by ICQ Num."), tr("by eMail"), tr("by Name"), NULL);
      break;
    }
  }
  else if (m_iSelectedUIN > 10)
  {
    if (FindListpos(&m_OnlineContactList, m_iSelectedUIN) != m_OnlineContactList.end())
    {
      m_eActiveMenu = cwmOnlineContact;
      m_pStatusbarWnd->SetButtons(tr("Details"), NULL, tr("to Ignorlist"), tr("Delete"));
    }
    else if (FindListpos(&m_OfflineContactList, m_iSelectedUIN) != m_OfflineContactList.end())
    {
      m_eActiveMenu = cwmOfflineContact;
      m_pStatusbarWnd->SetButtons(tr("Details"), NULL, tr("to Ignorlist"), tr("Delete"));
    }
    else if (m_pIcqClient->GetWaitList()->inList(m_iSelectedUIN))
    {
      m_eActiveMenu = cwmAwaitingContact;
      m_pStatusbarWnd->SetButtons(tr("Details"), NULL, tr("resend Auth."), tr("Delete"));
    }
    else if (m_pIcqClient->GetIgnoreList()->inList(m_iSelectedUIN))
    {
      m_eActiveMenu = cwmIgnorelistContact;
      m_pStatusbarWnd->SetButtons(tr("Details"), tr("to Contactlist"), NULL, tr("Delete"));
    }
  }
  else if (m_iSelectedUIN == 1)
  {
    if (m_bOnlineGroupSchow)
      m_pStatusbarWnd->SetButtons(tr("Hidde Group"), tr("Search User"), NULL, tr("Get From Serv"));
    else
      m_pStatusbarWnd->SetButtons(tr("Schow Group"), tr("Search User"), NULL, tr("Get From Serv"));
    m_eActiveMenu = cwmOnline;
  }
  else if (m_iSelectedUIN == 2)
  {
    if (m_bOfflineGroupSchow)
      m_pStatusbarWnd->SetButtons(tr("Hidde Group"), tr("Search User"), NULL, tr("Get From Serv"));
    else
      m_pStatusbarWnd->SetButtons(tr("Schow Group"), tr("Search User"), NULL, tr("Get From Serv"));
    m_eActiveMenu = cwmOffline;
  }
  else if (m_iSelectedUIN == 3)
  {
    if (m_bAwaitingGroupSchow)
      m_pStatusbarWnd->SetButtons(tr("Hidde Group"), tr("Search User"), NULL, tr("Get From Serv"));
    else
      m_pStatusbarWnd->SetButtons(tr("Schow Group"), tr("Search User"), NULL, tr("Get From Serv"));
    m_eActiveMenu = cwmAwaiting;
  }
  else if (m_iSelectedUIN == 4)
  {
    if (m_bIgnorelistGroupSchow)
      m_pStatusbarWnd->SetButtons(tr("Hidde Group"), tr("Search User"), NULL, tr("Get From Serv"));
    else
      m_pStatusbarWnd->SetButtons(tr("Schow Group"), tr("Search User"), NULL, tr("Get From Serv"));
    m_eActiveMenu = cwmIgnorelist;
  }
  else
  {
    m_pStatusbarWnd->ShowDefaultButtons();
  }
}




std::list<unsigned int>::iterator cContactWnd::FindListpos(std::list<unsigned int> *pList, unsigned int iUIN)
{
  std::list<unsigned int>::iterator curr;
  for (curr = pList->begin(); (iUIN != (*curr)) && (curr != pList->end()); ++curr);
  return curr;
}

void cContactWnd::ShowSearchDialog(EShowSearchDialog eSearchDialog)
{
  if (m_pOsd->GetBitmap(0) == NULL)
    return;
  
  { // start Mutex section
    cMutexLock lock(&cVdrIcqOsd::OsdMutex);

    if (m_eSearchDialog != eSearchDialog)
    {
      delete m_pSerchField1;
      m_pSerchField1 = NULL;
      delete m_pSerchField2;
      m_pSerchField2 = NULL;
      delete m_pSerchField3;
      m_pSerchField3 = NULL;
    }

    m_eSearchDialog = eSearchDialog;

    tArea Area1 = m_pVdrIcqOsd->GetMessagelistWnd()->GetArea1();
    tArea Area2 = m_pVdrIcqOsd->GetMessagelistWnd()->GetArea2();

    m_pOsd->DrawRectangle(Area1.x1, Area1.y1, Area2.x2, Area2.y2, clrBlue);
    m_pOsd->DrawRectangle(Area1.x1 + 2, Area1.y1 + 2, Area2.x2 - 2, Area2.y2 - 2, clrGray50);
    m_pOsd->DrawText(Area1.x1 + 10, Area1.y1 + 10, tr("Find an ICQ User"), clrWhite, clrGray50, font);

    switch(eSearchDialog)
    {
    case ssdByICQNumber:
      m_pOsd->DrawText(Area1.x1 + 10, Area1.y1 + 60, tr("Search by ICQ number"), clrWhite, clrGray50, font);
      if (m_pSerchField1 == NULL)
      {
        m_pSerchField1 = new cEditField(Area1.x1 + 260, Area1.y1 + 58, 150, LINEHEIGHT + 4, 
          9, this, m_pOsd, m_pStatusbarWnd);
        m_pSerchField1->SetFocused(true);
      }
      m_pSerchField1->SetStyle(clrBlue, clrRed, clrGray50, clrWhite, (cFont*)font);
      break;

    case ssdByEMail:
      m_pOsd->DrawText(Area1.x1 + 10, Area1.y1 + 60, tr("Search by eMail"), clrWhite, clrGray50, font);
      if (m_pSerchField1 == NULL)
      {
        m_pSerchField1 = new cEditField(Area1.x1 + 10, Area1.y1 + 100, 300, LINEHEIGHT + 4, 
          40, this, m_pOsd, m_pStatusbarWnd, VdrIcqSetup.TextInputmode);
        m_pSerchField1->SetFocused(true);
      }
      m_pSerchField1->SetStyle(clrBlue, clrRed, clrGray50, clrWhite, (cFont*)font);
      break;

    case ssdByName:
      m_pOsd->DrawText(Area1.x1 + 10, Area1.y1 + 60, tr("Search by First Name:"), clrWhite, clrGray50, font);
      if (m_pSerchField1 == NULL)
      {
        m_pSerchField1 = new cEditField(Area1.x1 + 260, Area1.y1 + 58, 160, LINEHEIGHT + 4, 
          30, this, m_pOsd, m_pStatusbarWnd, VdrIcqSetup.TextInputmode);
        m_pSerchField1->SetFocused(true);
      }
      m_pSerchField1->SetStyle(clrBlue, clrRed, clrGray50, clrWhite, (cFont*)font);

      m_pOsd->DrawText(Area1.x1 + 25, Area1.y1 + 110, tr("(and/or) Last Name:"), clrWhite, clrGray50, font);
      if (m_pSerchField2 == NULL)
      {
        m_pSerchField2 = new cEditField(Area1.x1 + 260, Area1.y1 + 108, 160, LINEHEIGHT + 4, 
          30, this, m_pOsd, m_pStatusbarWnd, VdrIcqSetup.TextInputmode);
      }
      m_pSerchField2->SetStyle(clrBlue, clrRed, clrGray50, clrWhite, (cFont*)font);

      m_pOsd->DrawText(Area1.x1 + 30, Area1.y1 + 160, tr("(and/or) Nickname:"), clrWhite, clrGray50, font);
      if (m_pSerchField3 == NULL)
      {
        m_pSerchField3 = new cEditField(Area1.x1 + 260, Area1.y1 + 158, 160, LINEHEIGHT + 4, 
          30, this, m_pOsd, m_pStatusbarWnd, VdrIcqSetup.TextInputmode);
      }
      m_pSerchField3->SetStyle(clrBlue, clrRed, clrGray50, clrWhite, (cFont*)font);
      break;

    case ssdNone:
    default:
      break;
    }

    m_pOsd->Flush();
  } // end Mutex section

  SetHelpKeys();
}

void cContactWnd::OnSerchResult(ICQ2000::SearchResultEvent *ev)
{
  if ((ev->isFinished()) && (m_bWaitForSerchResult))
  {
    delete m_pSerchResultCotactList;
    m_pSerchResultCotactList = new ICQ2000::ContactList(ev->getContactList());
    m_SelectedSerchResultContact = m_pIcqClient->GetSelfContact();

    m_pStatusbarWnd->Message(mtInfo, NULL);
    m_iSelectedSerchResult     = 0;
    m_iFirsSearchResultListPos = 0;
    m_iLastSearchResultListPos = 0;
    ShowSearchResults();
    SetHelpKeys();
  }
}

void cContactWnd::ShowSearchResults(void)
{
  if (m_pOsd->GetBitmap(0) == NULL)
    return;

  if (m_pSerchResultCotactList == NULL)
    return;

  cMutexLock lock(&cVdrIcqOsd::OsdMutex);

  tArea Area1 = m_pVdrIcqOsd->GetMessagelistWnd()->GetArea1();
  tArea Area2 = m_pVdrIcqOsd->GetMessagelistWnd()->GetArea2();
  
  m_pOsd->DrawRectangle(Area1.x1, Area1.y1, Area2.x2, Area2.y2, clrBlue);
  m_pOsd->DrawRectangle(Area1.x1 + 2, Area1.y1 + 2, Area2.x2 - 2, Area2.y2 - 2, clrGray50);
  m_pOsd->DrawText(Area1.x1 + 10, Area1.y1 + 10, tr("Searchresults"), clrWhite, clrGray50, font);
  
  int iXPos   = Area1.x1 + 5;
  int iYPos   = Area1.y1 + LINEHEIGHT + 10;
  int iWidth  = Area2.x2 - Area1.x1 - 10;
  int iHeight = SMLLINEHEIGHT + 4;
  int iZaehler = 0;
  ICQ2000::ContactList::iterator curr = m_pSerchResultCotactList->begin();
  
  while ((iZaehler < m_iFirsSearchResultListPos) && (curr != m_pSerchResultCotactList->end()))
  {
    ++curr;
    iZaehler++;
  }

  while ((curr != m_pSerchResultCotactList->end()) && (iYPos + iHeight < Area2.y2 - 2))
  {
    string sTemp;
    if (iZaehler == m_iSelectedSerchResult)
    {
      m_pOsd->DrawRectangle(iXPos, iYPos, iXPos + iWidth, iYPos + iHeight, clrRed);
      m_pOsd->DrawRectangle(iXPos + 1, iYPos + 1, iXPos + iWidth - 1, iYPos + iHeight - 1, clrGray50);
      m_SelectedSerchResultContact = (*curr);
    }
    
    m_pOsd->DrawText(iXPos + 2,   iYPos + 2, (*curr)->getStringUIN().c_str(), clrWhite, clrGray50, smlfont, 108);
    m_pOsd->DrawText(iXPos + 102, iYPos + 2, (*curr)->getAlias().c_str(),     clrWhite, clrGray50, smlfont, 98);
    m_pOsd->DrawText(iXPos + 192, iYPos + 2, (*curr)->getFirstName().c_str(), clrWhite, clrGray50, smlfont, 88);
    m_pOsd->DrawText(iXPos + 282, iYPos + 2, (*curr)->getLastName().c_str(),  clrWhite, clrGray50, smlfont, 88);
    
    sTemp = "";
    if ((*curr)->getHomepageInfo().sex == ICQ2000::SEX_MALE)
      sTemp = "M";
    else if ((*curr)->getHomepageInfo().sex == ICQ2000::SEX_FEMALE)
      sTemp = "F";
    

    if ((*curr)->getHomepageInfo().age > 0)
    {
      if (sTemp.size() > 0)
        sTemp += "-";
      sTemp += itoa((*curr)->getHomepageInfo().age);
    }
    else
    m_pOsd->DrawText(iXPos + 372, iYPos + 2, sTemp.c_str(),  clrWhite, clrGray50, smlfont);

    if ((*curr)->getAuthReq())
      sTemp = "Auth.";
    else
      sTemp = "Alw.";
    m_pOsd->DrawText(iXPos + 402, iYPos + 2, sTemp.c_str(),  clrWhite, clrGray50, smlfont);
  
    ++curr;
    iYPos += iHeight;
    iZaehler++;
  }

  m_iLastSearchResultListPos = iZaehler-1;
  m_pOsd->Flush();
}

void cContactWnd::ShowAuthDialog(void)
{
  if (m_pOsd->GetBitmap(0) == NULL)
    return;

  { // start Mutex section
    cMutexLock lock(&cVdrIcqOsd::OsdMutex);

    delete m_pAuthField;
    m_pAuthField = NULL;
    
    tArea Area1 = m_pVdrIcqOsd->GetMessagelistWnd()->GetArea1();
    tArea Area2 = m_pVdrIcqOsd->GetMessagelistWnd()->GetArea2();

    m_pOsd->DrawRectangle(Area1.x1, Area1.y1, Area2.x2, Area2.y2, clrBlue);
    m_pOsd->DrawRectangle(Area1.x1 + 2, Area1.y1 + 2, Area2.x2 - 2, Area2.y2 - 2, clrGray50);
    m_pOsd->DrawText(Area1.x1 + 10, Area1.y1 + 10, tr("The user can't be added to your Contact"), 
      clrWhite, clrGray50, font);
    m_pOsd->DrawText(Area1.x1 + 10, Area1.y1 + 10 + LINEHEIGHT, tr("List. The user must first authorize your"), 
      clrWhite, clrGray50, font);
    m_pOsd->DrawText(Area1.x1 + 10, Area1.y1 + 10 + LINEHEIGHT + LINEHEIGHT, tr("request."), 
      clrWhite, clrGray50, font);

    m_pAuthField = new cEditField(Area1.x1 + 10, Area1.y1 + 120, Area2.x2 - Area1.x1 - 20, LINEHEIGHT + 4,
      MAXTEXTLENGHT, this, m_pOsd, m_pStatusbarWnd, VdrIcqSetup.TextInputmode);
    char msg[120];
    ICQ2000::ContactRef MyContact = m_pIcqClient->GetSelfContact();
    sprintf(msg, tr("Please authorize my request and add me to your Contact List. %s ICQ#: %d"), 
      MyContact->getAlias().c_str(), MyContact->getUIN());
    m_pAuthField->SetStyle(clrBlue, clrRed, clrGray50, clrWhite, (cFont*)font);
    m_pAuthField->SetText(msg);
    m_pAuthField->SetFocused(true);

    m_pOsd->Flush();
  } // end Mutex section

  SetHelpKeys();
}

void cContactWnd::Draw(void)
{
  if (m_pOsd->GetBitmap(4) == NULL)
    return;

  { // start Mutex section
    cMutexLock lock(&cVdrIcqOsd::OsdMutex);
    m_pOsd->GetBitmap(4)->Reset();

    // Rahmen zeichnen
    if (m_pVdrIcqOsd->GetSelectedWindow() == swContact)
    {
      m_pOsd->DrawRectangle(m_Area.x1, m_Area.y1, m_Area.x2, m_Area.y2, clrRed);
    }
    else
    {
      m_pOsd->DrawRectangle(m_Area.x1, m_Area.y1, m_Area.x2, m_Area.y2, clrBlue);
    }
    m_pOsd->DrawRectangle(m_Area.x1 + 2, m_Area.y1 + 2, m_Area.x2 - 2, m_Area.y2 - 2, clrGray50);

    if (m_pContactList == NULL)
    {
      return;
    }
     

    cNumberList *pWaitList = m_pIcqClient->GetWaitList();
    cNumberList *pIgnoreList = m_pIcqClient->GetIgnoreList();
    if ((m_iSelectedUIN > 10) && (!m_pContactList->exists(m_iSelectedUIN)) && 
        (!pWaitList->inList(m_iSelectedUIN)) && (!pIgnoreList->inList(m_iSelectedUIN)))
      m_iSelectedUIN = 0;
   
    if (m_iSelectedPos >= m_pContactList->size())
      m_iSelectedPos = m_pContactList->size() - 1;

    ICQ2000::ContactRef Contact = m_pIcqClient->GetActiveContact();

    // Zeile über Onlie-User "+ Online" mit Auswahlrahmen zeichnen
    int iXPos = m_Area.x1 + 8;
    int iYPos = m_Area.y1 + 8;
    if ((m_iSelectedUIN == 1) && (m_pVdrIcqOsd->GetSelectedWindow() == swContact))
    { 
      m_pOsd->DrawRectangle(m_Area.x1 + 2, iYPos - 1, m_Area.x2 - 2, iYPos + smlfont->Height(),     clrRed);
      m_pOsd->DrawRectangle(m_Area.x1 + 2, iYPos,     m_Area.x2 - 2, iYPos + smlfont->Height() - 1, clrGray50);
    } 
    m_pOsd->DrawRectangle(iXPos,     iYPos + 8,  iXPos + 10, iYPos + 18, clrWhite);
    m_pOsd->DrawRectangle(iXPos + 1, iYPos + 9,  iXPos + 9,  iYPos + 17, clrGray50);
    m_pOsd->DrawRectangle(iXPos + 2, iYPos + 13, iXPos + 8,  iYPos + 13, clrWhite);
    if (!m_bOnlineGroupSchow)
      m_pOsd->DrawRectangle(iXPos + 5, iYPos + 10, iXPos + 5,  iYPos + 16, clrWhite);
    m_pOsd->DrawText(iXPos + 13, iYPos, "Online", clrWhite, clrGray50, smlfont);

    iXPos = m_Area.x1 + 12;
    iYPos += smlfont->Height() + 1;

    unsigned int iPos = 0;
    if (m_bOnlineGroupSchow)
    { // User die sich in der Online-Liste befinden mit Auswahlrahmen zeichnen
      std::list<unsigned int>::iterator curr = m_OnlineContactList.begin();
      while (curr != m_OnlineContactList.end())
      {
        if (((m_iSelectedUIN == (*curr)) || ((m_iSelectedUIN == 0) && (iPos == m_iSelectedPos))) &&
            (m_pVdrIcqOsd->GetSelectedWindow() == swContact))
        {
          m_iSelectedUIN == *curr;
          m_pOsd->DrawRectangle(m_Area.x1 + 2, iYPos - 1, m_Area.x2 - 2,     iYPos + smlfont->Height(),     clrRed);
          m_pOsd->DrawRectangle(m_Area.x1 + 2, iYPos,     m_Area.x2 - 2, iYPos + smlfont->Height() - 1, clrGray50);
        }
        ICQ2000::ContactRef c = m_pContactList->lookup_uin(*curr);
        string sAlias = c->getNameAlias();
        m_pOsd->DrawBitmap(iXPos - 6, iYPos + 4, *m_pVdrIcqOsd->GetStatusBitmap(c->getStatus()), clrGray50, clrGray50);
        if ((*curr) == Contact->getUIN())
        {
          m_pOsd->DrawText(iXPos + 11, iYPos, sAlias.c_str(), clrGray50, clrWhite, smlfont);
        }
        else
        {
          m_pOsd->DrawText(iXPos + 11, iYPos, sAlias.c_str(), clrWhite, clrGray50, smlfont);
        }
        iYPos += smlfont->Height() + 1;
        ++curr;
        iPos++;
      }
    }

    // Zeile über Offline-User "+ Offline" mit Auswahlrahmen zeichnen
    iXPos = m_Area.x1 + 8;
    iYPos += 10;
    if ((m_iSelectedUIN == 2) && (m_pVdrIcqOsd->GetSelectedWindow() == swContact))
    {
      m_pOsd->DrawRectangle(m_Area.x1 + 2, iYPos - 1, m_Area.x2 - 2, iYPos + smlfont->Height(),     clrRed);
      m_pOsd->DrawRectangle(m_Area.x1 + 2, iYPos,     m_Area.x2 - 2, iYPos + smlfont->Height() - 1, clrGray50);
    }
    m_pOsd->DrawRectangle(iXPos,     iYPos + 8,  iXPos + 10, iYPos + 18, clrWhite);
    m_pOsd->DrawRectangle(iXPos + 1, iYPos + 9,  iXPos + 9,  iYPos + 17, clrGray50);
    m_pOsd->DrawRectangle(iXPos + 2, iYPos + 13, iXPos + 8,  iYPos + 13, clrWhite);
    if (!m_bOfflineGroupSchow)
      m_pOsd->DrawRectangle(iXPos + 5, iYPos + 10, iXPos + 5,  iYPos + 16, clrWhite);
    m_pOsd->DrawText(iXPos + 13, iYPos, "Offline", clrWhite, clrGray50, smlfont);

    iXPos = m_Area.x1 + 12;
    iYPos += smlfont->Height() + 1;

    if (m_bOfflineGroupSchow)
    { // User die sich in der Offline-Liste befinden mit Auswahlrahmen zeichnen
      std::list<unsigned int>::iterator curr = m_OfflineContactList.begin();
      while (curr != m_OfflineContactList.end())
      {
        if (((m_iSelectedUIN == (*curr)) || ((m_iSelectedUIN == 0) && (iPos == m_iSelectedPos))) &&
            (m_pVdrIcqOsd->GetSelectedWindow() == swContact))
        {
          m_iSelectedUIN == *curr;
          m_pOsd->DrawRectangle(m_Area.x1 + 2, iYPos - 1, m_Area.x2 - 2, iYPos + smlfont->Height(),     clrRed);
          m_pOsd->DrawRectangle(m_Area.x1 + 2, iYPos,     m_Area.x2 - 2, iYPos + smlfont->Height() - 1, clrGray50);
        }
        ICQ2000::ContactRef c = m_pContactList->lookup_uin(*curr);
        string sAlias = c->getNameAlias();
        m_pOsd->DrawBitmap(iXPos - 6, iYPos + 4, *m_pVdrIcqOsd->GetStatusBitmap(c->getStatus()), clrGray50, clrGray50);
        if ((*curr) == Contact->getUIN())
        {
          m_pOsd->DrawText(iXPos + 11, iYPos, sAlias.c_str(), clrGray50, clrWhite, smlfont);
        }
        else
        {
          m_pOsd->DrawText(iXPos + 11, iYPos, sAlias.c_str(), clrWhite, clrGray50, smlfont);
        }
        iYPos += smlfont->Height() + 1;
        ++curr;
      }
    }

    // Zeile über Awaiting-User "+ Awaiting" mit Auswahlrahmen zeichnen
    if ((pWaitList) && (pWaitList->size() > 0))
    {
      iXPos = m_Area.x1 + 8;
      iYPos += 10;
      if ((m_iSelectedUIN == 3) && (m_pVdrIcqOsd->GetSelectedWindow() == swContact))
      {
        m_pOsd->DrawRectangle(m_Area.x1 + 2, iYPos - 1, m_Area.x2 - 2, iYPos + smlfont->Height(),     clrRed);
        m_pOsd->DrawRectangle(m_Area.x1 + 2, iYPos,     m_Area.x2 - 2, iYPos + smlfont->Height() - 1, clrGray50);
      }
      m_pOsd->DrawRectangle(iXPos,     iYPos + 8,  iXPos + 10, iYPos + 18, clrWhite);
      m_pOsd->DrawRectangle(iXPos + 1, iYPos + 9,  iXPos + 9,  iYPos + 17, clrGray50);
      m_pOsd->DrawRectangle(iXPos + 2, iYPos + 13, iXPos + 8,  iYPos + 13, clrWhite);
   
      if (!m_bAwaitingGroupSchow)
        m_pOsd->DrawRectangle(iXPos + 5, iYPos + 10, iXPos + 5,  iYPos + 16, clrWhite);
      m_pOsd->DrawText(iXPos + 13, iYPos, "Awaiting", clrWhite, clrGray50, smlfont);

      iXPos = m_Area.x1 + 12;
      iYPos += smlfont->Height() + 1;
      if (m_bAwaitingGroupSchow)
      { // User die sich in der Awaiting-Liste befinden mit Auswahlrahmen zeichnen
        cNumberList::iterator curr = pWaitList->begin();
        while (curr != pWaitList->end())
        {
          if (((m_iSelectedUIN == (*curr)->getUIN()) || ((m_iSelectedUIN == 0) && (iPos == m_iSelectedPos))) &&
              (m_pVdrIcqOsd->GetSelectedWindow() == swContact))
          {
            m_iSelectedUIN == (*curr)->getUIN();
            m_pOsd->DrawRectangle(m_Area.x1 + 2, iYPos - 1, m_Area.x2 - 2, iYPos + smlfont->Height(),     clrRed);
            m_pOsd->DrawRectangle(m_Area.x1 + 2, iYPos,     m_Area.x2 - 2, iYPos + smlfont->Height() - 1, clrGray50);
          }
          m_pOsd->DrawText(iXPos, iYPos, (*curr)->getAlias().c_str(), clrWhite, clrGray50, smlfont);
          iYPos += smlfont->Height() + 1;
          ++curr;
        }
      }
    }

    // Zeile über Ignorierte-User "+ Ignorelist" mit Auswahlrahmen zeichnen
    if ((pIgnoreList) && (pIgnoreList->size() > 0))
    {
      iXPos = m_Area.x1 + 8;
      iYPos += 10;
      if ((m_iSelectedUIN == 4) && (m_pVdrIcqOsd->GetSelectedWindow() == swContact))
      {
        m_pOsd->DrawRectangle(m_Area.x1 + 2, iYPos - 1, m_Area.x2 - 2, iYPos + smlfont->Height(),     clrRed);
        m_pOsd->DrawRectangle(m_Area.x1 + 2, iYPos,     m_Area.x2 - 2, iYPos + smlfont->Height() - 1, clrGray50);
      }
      m_pOsd->DrawRectangle(iXPos,     iYPos + 8,  iXPos + 10, iYPos + 18, clrWhite);
      m_pOsd->DrawRectangle(iXPos + 1, iYPos + 9,  iXPos + 9,  iYPos + 17, clrGray50);
      m_pOsd->DrawRectangle(iXPos + 2, iYPos + 13, iXPos + 8,  iYPos + 13, clrWhite);
   
      if (!m_bIgnorelistGroupSchow)
        m_pOsd->DrawRectangle(iXPos + 5, iYPos + 10, iXPos + 5,  iYPos + 16, clrWhite);
      m_pOsd->DrawText(iXPos + 13, iYPos, "Ignorelist", clrWhite, clrGray50, smlfont);

      iXPos = m_Area.x1 + 12;
      iYPos += smlfont->Height() + 1;
      if (m_bIgnorelistGroupSchow)
      { // User die sich in der Awaiting-Liste befinden mit Auswahlrahmen zeichnen
        cNumberList::iterator curr = pIgnoreList->begin();
        while (curr != pIgnoreList->end())
        {
          if (((m_iSelectedUIN == (*curr)->getUIN()) || ((m_iSelectedUIN == 0) && (iPos == m_iSelectedPos))) &&
              (m_pVdrIcqOsd->GetSelectedWindow() == swContact))
          {
            m_iSelectedUIN == (*curr)->getUIN();
            m_pOsd->DrawRectangle(m_Area.x1 + 2, iYPos - 1, m_Area.x2 - 2, iYPos + smlfont->Height(),     clrRed);
            m_pOsd->DrawRectangle(m_Area.x1 + 2, iYPos,     m_Area.x2 - 2, iYPos + smlfont->Height() - 1, clrGray50);
          }
          m_pOsd->DrawText(iXPos, iYPos, (*curr)->getAlias().c_str(), clrWhite, clrGray50, smlfont);
          iYPos += smlfont->Height() + 1;
          ++curr;
        }
      }
    }

    m_pOsd->Flush();
  } // end Mutex section

  if (m_pVdrIcqOsd->GetSelectedWindow() == swContact)
    SetHelpKeys();
}
