Update OpenVMS makefile
[wxWidgets.git] / src / osx / cocoa / aboutdlg.mm
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name:        src/osx/cocoa/aboutdlg.mm
3 // Purpose:     native wxAboutBox() implementation for wxMac
4 // Author:      Vadim Zeitlin
5 // Created:     2006-10-08
6 // Copyright:   (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
7 // Licence:     wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ============================================================================
11 // declarations
12 // ============================================================================
13
14 // ----------------------------------------------------------------------------
15 // headers
16 // ----------------------------------------------------------------------------
17
18 // for compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
20
21 #if wxUSE_ABOUTDLG
22
23 #ifndef WX_PRECOMP
24 #endif //WX_PRECOMP
25
26 #include "wx/aboutdlg.h"
27 #include "wx/generic/aboutdlgg.h"
28
29 #include "wx/osx/private.h"
30
31 // see http://developer.apple.com/mac/library/technotes/tn2006/tn2179.html for
32 // information about the various keys used here
33
34 // helper class for HIAboutBox options
35 class AboutBoxOptions : public wxCFRef<CFMutableDictionaryRef>
36 {
37 public:
38     AboutBoxOptions() : wxCFRef<CFMutableDictionaryRef>
39                         (
40                           CFDictionaryCreateMutable
41                           (
42                            kCFAllocatorDefault,
43                            4, // there are at most 4 values
44                            &kCFTypeDictionaryKeyCallBacks,
45                            &kCFTypeDictionaryValueCallBacks
46                           )
47                         )
48     {
49     }
50
51     void Set(CFStringRef key, const wxString& value)
52     {
53         CFDictionarySetValue(*this, key, wxCFStringRef(value));
54     }
55
56     void SetAttributedString( CFStringRef key, const wxString& value )
57     {
58           wxCFRef<CFAttributedStringRef> attrString(
59             CFAttributedStringCreate(kCFAllocatorDefault, wxCFStringRef(value), NULL) );
60         CFDictionarySetValue(*this, key, attrString);
61     }
62 };
63
64 // ============================================================================
65 // implementation
66 // ============================================================================
67
68 void wxAboutBox(const wxAboutDialogInfo& info, wxWindow *parent)
69 {
70     // Mac native about box currently can show only name, version, copyright
71     // and description fields and we also shoehorn the credits text into the
72     // description but if we have anything else we must use the generic version
73
74     if ( info.IsSimple() )
75     {
76         AboutBoxOptions opts;
77
78         opts.Set(CFSTR("ApplicationName"), info.GetName());
79
80         if ( info.HasVersion() )
81         {
82             opts.Set(CFSTR("Version"),info.GetVersion());
83             if ( info.GetLongVersion() != (_("Version ")+info.GetVersion()))
84                 opts.Set(CFSTR("ApplicationVersion"),info.GetLongVersion());
85         }
86
87         if ( info.HasCopyright() )
88             opts.Set(CFSTR("Copyright"), info.GetCopyrightToDisplay());
89
90         opts.SetAttributedString(CFSTR("Credits"), info.GetDescriptionAndCredits());
91
92         [[NSApplication sharedApplication] orderFrontStandardAboutPanelWithOptions:((NSDictionary*)(CFDictionaryRef) opts)];
93     }
94     else // simple "native" version is not enough
95     {
96         // we need to use the full-blown generic version
97         wxGenericAboutBox(info, parent);
98     }
99 }
100
101 #endif // wxUSE_ABOUTDLG