WxMac BadgeLabels

From WxWiki
Jump to: navigation, search

wxMac: Displaying Badge Labels on the dock icon

This is a small piece of code demonstrating how to display a badge label on Mac OS X at the dock icon like Mail does, when new messages arrive.

BadgeLabel.mm:

#import <Cocoa/Cocoa.h>

void wxSetBadgeLabel(wxString label) {

#if wxUSE_UNICODE
    NSString *temp = [NSString stringWithUTF8String:label.mb_str(wxConvUTF8)];
#else
    NSString *temp = [NSString stringWithCString:label.c_str() length:label.Len()];
#endif
    NSDockTile *dockTile = [[NSApplication sharedApplication] dockTile];
    [dockTile setBadgeLabel:temp];
}

//removing the badge label
void wxRemoveBadgeLabel() {
    NSDockTile *dockTile = [[NSApplication sharedApplication] dockTile];
    [dockTile setBadgeLabel:nil];
}

BadgeLabel.h:

#ifndef __BADGE_LABEL_h__
#define __BADGE_LABEL_h__

#ifndef WX_PRECOMP
#include <wx/wx.h>
#else
#include <wx/wxprec.h>
#endif

extern void wxRemoveBadgeLabel();
extern void wxSetBadgeLabel(wxString label);

#endif