From fb8dcb05283b9ccfd130eeb0bdae24b6615d5ce8 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Thu, 21 Aug 2008 07:29:07 +0000 Subject: [PATCH] cocoa specific implementations git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55139 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/cocoa/aboutdlg.mm | 108 ++++++++++++++++++++++++++++++++++++++ src/osx/cocoa/dialog.mm | 62 ++++++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 src/osx/cocoa/aboutdlg.mm create mode 100644 src/osx/cocoa/dialog.mm diff --git a/src/osx/cocoa/aboutdlg.mm b/src/osx/cocoa/aboutdlg.mm new file mode 100644 index 0000000000..553094bf18 --- /dev/null +++ b/src/osx/cocoa/aboutdlg.mm @@ -0,0 +1,108 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: osx/cocoa/aboutdlg.cpp +// Purpose: native wxAboutBox() implementation for wxMac +// Author: Vadim Zeitlin +// Created: 2006-10-08 +// RCS-ID: $Id: aboutdlg.cpp 54820 2008-07-29 20:04:11Z SC $ +// Copyright: (c) 2006 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#if wxUSE_ABOUTDLG + +#ifndef WX_PRECOMP +#endif //WX_PRECOMP + +#include "wx/aboutdlg.h" +#include "wx/generic/aboutdlgg.h" + +#include "wx/osx/private.h" + +/* +@"Credits": An NSAttributedString displayed in the info area of the panel. If not specified, this method then looks for a file named “Credits.html”, “Credits.rtf”, and “Credits.rtfd”, in that order, in the bundle returned by the NSBundle class method mainBundle. The first file found is used. If none is found, the info area is left blank. +@"ApplicationName": An NSString object displayed as the application’s name. If not specified, this method then uses the value of CFBundleName (localizable). If neither is found, this method uses [[NSProcessInfo processInfo] processName]. +@"ApplicationIcon": An NSImage object displayed as the application’s icon. If not specified, this method then looks for an image named “NSApplicationIcon”, using [NSImage imageNamed:@"NSApplicationIcon"]. If neither is available, this method uses the generic application icon. +@"Version": An NSString object with the build version number of the application (“58.4”), displayed as “(v58.4)”. If not specified, obtain from the CFBundleVersion key in infoDictionary; if not specified, leave blank (the “(v)” is not displayed). +@"Copyright": An NSString object with a line of copyright information. If not specified, this method then looks for the value of NSHumanReadableCopyright in the localized version infoDictionary. If neither is available, this method leaves the space blank. +@"ApplicationVersion": An NSString object with the application version (“Mac OS X”, “3”, “WebObjects 4.5”, “AppleWorks 6”,...). If not specified, obtain from the CFBundleShortVersionString key in infoDictionary. If neither is available, the build version, if available, is printed alone, as “Version x.x”. +*/ + +// helper class for HIAboutBox options +class AboutBoxOptions : public wxCFRef +{ +public: + AboutBoxOptions() : wxCFRef + ( + CFDictionaryCreateMutable + ( + kCFAllocatorDefault, + 4, // there are at most 4 values + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks + ) + ) + { + } + + void Set(CFStringRef key, const wxString& value) + { + CFDictionarySetValue(*this, key, wxCFStringRef(value)); + } + + void SetAttributedString( CFStringRef key, const wxString& value ) + { + wxCFRef attrString( + CFAttributedStringCreate(kCFAllocatorDefault, wxCFStringRef(value), NULL) ); + CFDictionarySetValue(*this, key, attrString); + } +}; + +// ============================================================================ +// implementation +// ============================================================================ + +void wxAboutBox(const wxAboutDialogInfo& info) +{ + // Mac native about box currently can show only name, version, copyright + // and description fields and we also shoehorn the credits text into the + // description but if we have anything else we must use the generic version + + if ( info.IsSimple() ) + { + AboutBoxOptions opts; + + opts.Set(CFSTR("ApplicationName"), info.GetName()); + + if ( info.HasVersion() ) + { + opts.Set(CFSTR("Version"),info.GetVersion()); + opts.Set(CFSTR("ApplicationVersion"), + wxString::Format(_("Version %s"), info.GetVersion())); + } + + if ( info.HasCopyright() ) + opts.Set(CFSTR("Copyright"), info.GetCopyright()); + + opts.SetAttributedString(CFSTR("Credits"), info.GetDescriptionAndCredits()); + + [[NSApplication sharedApplication] orderFrontStandardAboutPanelWithOptions:((NSDictionary*)(CFDictionaryRef) opts)]; + } + else // simple "native" version is not enough + { + // we need to use the full-blown generic version + wxGenericAboutBox(info); + } +} + +#endif // wxUSE_ABOUTDLG diff --git a/src/osx/cocoa/dialog.mm b/src/osx/cocoa/dialog.mm new file mode 100644 index 0000000000..9d99165c63 --- /dev/null +++ b/src/osx/cocoa/dialog.mm @@ -0,0 +1,62 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/osx/cocoa/dialog.cpp +// Purpose: wxDialog class +// Author: Stefan Csomor +// Modified by: +// Created: 1998-01-01 +// RCS-ID: $Id: dialog.cpp 54820 2008-07-29 20:04:11Z SC $ +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" + +#include "wx/dialog.h" + +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/utils.h" + #include "wx/frame.h" + #include "wx/settings.h" +#endif // WX_PRECOMP + +#include "wx/osx/private.h" + +extern wxList wxModalDialogs; + +void wxDialog::DoShowModal() +{ + + SetFocus() ; +/* + WindowGroupRef windowGroup; + WindowGroupRef formerParentGroup; + bool resetGroupParent = false; + + if ( GetParent() == NULL ) + { + windowGroup = GetWindowGroup(windowRef) ; + formerParentGroup = GetWindowGroupParent( windowGroup ); + SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) ); + resetGroupParent = true; + } +*/ + + NSWindow* theWindow = GetWXWindow(); + + NSModalSession session = [NSApp beginModalSessionForWindow:theWindow]; + while (IsModal()) + { + if ([NSApp runModalSession:session] != NSRunContinuesResponse) + break; + // TODO should we do some idle processing ? + } + [NSApp endModalSession:session]; + +/* + if ( resetGroupParent ) + { + SetWindowGroupParent( windowGroup , formerParentGroup ); + } +*/ +} -- 2.45.2