SystemTrayService::Handle SystemTrayServiceWindows::AddIcon(const RF_Draw::TrayIcon& Settings)
{
    // early exit if there are too many icons registered
    if(m_PImpl->m_IconData.Count() > MAX_WM_APP - WM_APP)
        return 0;

    RF_Mem::AutoPointer<NOTIFYICONDATA> notifyData(new NOTIFYICONDATA);

    RF_SysMem::Set(notifyData.Get(), 0, sizeof(NOTIFYICONDATA));
    notifyData->cbSize = sizeof(NOTIFYICONDATA);
    notifyData->hWnd = m_PImpl->m_HWND;
    notifyData->uVersion = NOTIFYICON_VERSION_4;
    notifyData->uFlags = NIF_GUID | NIF_MESSAGE;
    notifyData->uCallbackMessage = WM_APP + m_PImpl->m_IconData.Count();
    CoCreateGuid(&notifyData->guidItem);

    if(!Settings.Notification.IsEmpty())
    {
        notifyData->uFlags |= NIF_INFO | NIF_SHOWTIP;
        StringCchCopyA(notifyData->szInfo, ARRAYSIZE(notifyData->szInfo), Settings.Notification.c_str());
    }

    if(!Settings.Tooltip.IsEmpty())
    {
        notifyData->uFlags |= NIF_TIP;
        StringCchCopyA(notifyData->szTip, ARRAYSIZE(notifyData->szTip), Settings.Tooltip.c_str());
    }

    RF_IO::File icon;
    icon.SetLocation(Settings.Icon);
    if(icon.Exists())
    {
        RF_Type::String systemPath = Settings.Icon.GetComponents(RF_IO::UriComponents::Path);        
        int min = GetSystemMetrics(SM_CXSMICON);
        notifyData->hIcon = (HICON)LoadImage(NULL, systemPath.c_str(), IMAGE_ICON, 
                                             min, min, LR_LOADFROMFILE);
        if(notifyData->hIcon != 0)
        {
            notifyData->uFlags |= NIF_ICON;
        }
    }

    Handle handle = 0;
    SystemTrayService::Handle result = Shell_NotifyIcon(NIM_ADD, notifyData.Get());
    if(result)
    {
        handle = reinterpret_cast<Handle>(notifyData.Get());
        
        m_PImpl->m_IconData.Resize(m_PImpl->m_IconData.Count() + 1);
        auto& item = m_PImpl->m_IconData(m_PImpl->m_IconData.Count() - 1);
        m_PImpl->m_MessageLookup[notifyData->uCallbackMessage] = &item;
        m_PImpl->m_HandleLookup[handle] = &item;
        
        item.m_MenuHandle = m_PImpl->AddPopupMenu(Settings);
        item.m_NotificationData = notifyData;
    }

    return handle;
}
Ejemplo n.º 2
0
bool wxTaskBarIcon::RemoveIcon()
{
    if (!m_iconAdded)
        return false;

    m_iconAdded = false;

    NotifyIconData notifyData(GetHwndOf(m_win));

    bool ok = Shell_NotifyIcon(NIM_DELETE, &notifyData) != 0;
    if ( !ok )
    {
        wxLogLastError(wxT("Shell_NotifyIcon(NIM_DELETE)"));
    }

    return ok;
}
Ejemplo n.º 3
0
bool
wxTaskBarIcon::ShowBalloon(const wxString& title,
                           const wxString& text,
                           unsigned msec,
                           int flags)
{
    wxCHECK_MSG( m_iconAdded, false,
                    wxT("can't be used before the icon is created") );

    const HWND hwnd = GetHwndOf(m_win);

    // we need to enable version 5.0 behaviour to receive notifications about
    // the balloon disappearance
    NotifyIconData notifyData(hwnd);
    notifyData.uFlags = 0;
    notifyData.uVersion = 3 /* NOTIFYICON_VERSION for Windows 2000/XP */;

    if ( !Shell_NotifyIcon(NIM_SETVERSION, &notifyData) )
    {
        wxLogLastError(wxT("Shell_NotifyIcon(NIM_SETVERSION)"));
    }

    // do show the balloon now
    notifyData = NotifyIconData(hwnd);
    notifyData.uFlags |= NIF_INFO;
    notifyData.uTimeout = msec;
    wxStrlcpy(notifyData.szInfo, text.t_str(), WXSIZEOF(notifyData.szInfo));
    wxStrlcpy(notifyData.szInfoTitle, title.t_str(),
                WXSIZEOF(notifyData.szInfoTitle));

    if ( flags & wxICON_INFORMATION )
        notifyData.dwInfoFlags |= NIIF_INFO;
    else if ( flags & wxICON_WARNING )
        notifyData.dwInfoFlags |= NIIF_WARNING;
    else if ( flags & wxICON_ERROR )
        notifyData.dwInfoFlags |= NIIF_ERROR;

    bool ok = Shell_NotifyIcon(NIM_MODIFY, &notifyData) != 0;
    if ( !ok )
    {
        wxLogLastError(wxT("Shell_NotifyIcon(NIM_MODIFY)"));
    }

    return ok;
}
Ejemplo n.º 4
0
// Operations
bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip)
{
    // NB: we have to create the window lazily because of backward compatibility,
    //     old applications may create a wxTaskBarIcon instance before wxApp
    //     is initialized (as samples/taskbar used to do)
    if (!m_win)
    {
        m_win = new wxTaskBarIconWindow(this);
    }

    m_icon = icon;
    m_strTooltip = tooltip;

    NotifyIconData notifyData(GetHwndOf(m_win));

    if (icon.IsOk())
    {
        notifyData.uFlags |= NIF_ICON;
        notifyData.hIcon = GetHiconOf(icon);
    }

    // set NIF_TIP even for an empty tooltip: otherwise it would be impossible
    // to remove an existing tooltip using this function
    notifyData.uFlags |= NIF_TIP;
    if ( !tooltip.empty() )
    {
        wxStrlcpy(notifyData.szTip, tooltip.t_str(), WXSIZEOF(notifyData.szTip));
    }

    bool ok = Shell_NotifyIcon(m_iconAdded ? NIM_MODIFY
                                            : NIM_ADD, &notifyData) != 0;

    if ( !ok )
    {
        wxLogLastError(wxT("Shell_NotifyIcon(NIM_MODIFY/ADD)"));
    }

    if ( !m_iconAdded && ok )
        m_iconAdded = true;

    return ok;
}
Ejemplo n.º 5
0
bool gcTaskBarIcon::RemoveIcon()
{
#ifdef WIN32
	if (!m_iconAdded)
		return false;

	m_iconAdded = false;

	NotifyIconData notifyData(GetHwndOf(m_win));

	bool ok = wxShellNotifyIcon(NIM_DELETE, &notifyData) != 0;
	if ( !ok )
	{
		wxLogLastError(wxT("wxShellNotifyIcon(NIM_DELETE)"));
	}

	return ok;
#else
	return false;
#endif
}
Ejemplo n.º 6
0
bool StringSelectForm::handleEvent(EventType& event)
{
    int selection = noListSelection;
    switch (event.eType)
    {
        case lstSelectEvent:
            okButton_.hit();
            return true;
            
        case ctlSelectEvent: 
            if (okButton == event.data.ctlSelect.controlID)
                selection = choicesList_.selection();
            if (noListSelection != selection || cancelButton == event.data.ctlSelect.controlID)
            {
                closePopup();
                StringSelectNotifyData notifyData(selection);
                sendEvent(notifyEvent_, notifyData);
            }
            return true;
        
        case keyDownEvent:
        {
            int option = ExtendedList::optionScrollPagesWithLeftRight;
            if (application().runningOnTreo600())
                option = 0;
            if (choicesList_.handleKeyDownEvent(event, option | ExtendedList::optionFireListSelectOnCenter))
                return true;
            if (chrCarriageReturn == event.data.keyDown.chr || chrLineFeed == event.data.keyDown.chr)
            {
                okButton_.hit();
                return true;
            }
            // intentional fall-through
        }
        
        default:
            return MoriartyForm::handleEvent(event);
    }
}
Ejemplo n.º 7
0
// Operations
bool gcTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip)
{
#ifdef WIN32
	m_icon = icon;
	m_strTooltip = tooltip;

	NotifyIconData notifyData(GetHwndOf(m_win));

	if (icon.Ok())
	{
		notifyData.uFlags |= NIF_ICON;
		notifyData.hIcon = GetHiconOf(icon);
	}

	// set NIF_TIP even for an empty tooltip: otherwise it would be impossible
	// to remove an existing tooltip using this function
	notifyData.uFlags |= NIF_TIP;
	if ( !tooltip.empty() )
	{
		wxStrlcpy(notifyData.szTip, tooltip.wx_str(), WXSIZEOF(notifyData.szTip));
	}

	bool ok = wxShellNotifyIcon(m_iconAdded ? NIM_MODIFY
											: NIM_ADD, &notifyData) != 0;

	if ( !ok )
	{
		wxLogLastError(wxT("wxShellNotifyIcon(NIM_MODIFY/ADD)"));
	}

	if ( !m_iconAdded && ok )
		m_iconAdded = true;

	return ok;
#else
	return wxTaskBarIcon::SetIcon(icon, tooltip);
#endif
}
Ejemplo n.º 8
0
bool gcTaskBarIcon::ShowBalloon(const wxString& title, const wxString& text, unsigned msec, int flags)
{
#if defined(WIN32)
	wxCHECK_MSG( m_iconAdded, false,
					_T("can't be used before the icon is created") );

	const HWND hwnd = GetHwndOf(m_win);

	// we need to enable version 5.0 behaviour to receive notifications about
	// the balloon disappearance
	NotifyIconData notifyData(hwnd);
	notifyData.uFlags = 0;
	notifyData.uVersion = 3 /* NOTIFYICON_VERSION for Windows XP */;

	if ( !wxShellNotifyIcon(NIM_SETVERSION, &notifyData) )
	{
		wxLogLastError(wxT("wxShellNotifyIcon(NIM_SETVERSION)"));
	}

	// do show the balloon now
	notifyData = NotifyIconData(hwnd);
	notifyData.uFlags |= NIF_INFO;
	notifyData.uTimeout = msec;
	wxStrlcpy(notifyData.szInfo, text.wx_str(), WXSIZEOF(notifyData.szInfo));
	wxStrlcpy(notifyData.szInfoTitle, title.wx_str(),
				WXSIZEOF(notifyData.szInfoTitle));

	if ( flags & wxICON_INFORMATION )
		notifyData.dwInfoFlags |= NIIF_INFO;
	else if ( flags & wxICON_WARNING )
		notifyData.dwInfoFlags |= NIIF_WARNING;
	else if ( flags & wxICON_ERROR )
		notifyData.dwInfoFlags |= NIIF_ERROR;

	bool ok = wxShellNotifyIcon(NIM_MODIFY, &notifyData) != 0;
	if ( !ok )
	{
		wxLogLastError(wxT("wxShellNotifyIcon(NIM_MODIFY)"));

	}
	return ok;
#elif defined(NIX)
	const char* icon = NULL;
	
	if ( flags & wxICON_INFORMATION )
		icon = "dialog-information";
	else if ( flags & wxICON_WARNING )
		icon = "dialog-warning";
	else if ( flags & wxICON_ERROR )
		icon = "dialog-error";
	
	NotifyNotification* notification =
		notify_notification_new(
			title.c_str(),
			text.c_str(),
			icon);
	
	notify_notification_show(notification, NULL);
	
	return true;
#else
	return false;
#endif
}
Ejemplo n.º 9
0
/*private virtual */void ofxEasyCubeSAT::onNotifyData(ofxSATTime const& time)
{
    notifyData(time);
    return;
}