Patch: [#22524] Update Windows Recent Documents on Open/Save
[blender.git] / intern / ghost / intern / GHOST_DisplayManagerCocoa.mm
1 /**
2  * $Id$
3  * ***** BEGIN GPL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20  * All rights reserved.
21  *
22  * The Original Code is: all of this file.
23  *
24  * Contributor(s):      Maarten Gribnau 09/2001
25                                         Damien Plisson  10/2009
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #include <Cocoa/Cocoa.h>
31
32 #include "GHOST_DisplayManagerCocoa.h"
33 #include "GHOST_Debug.h"
34
35 // We do not support multiple monitors at the moment
36
37
38 GHOST_DisplayManagerCocoa::GHOST_DisplayManagerCocoa(void)
39 {
40 }
41
42
43 GHOST_TSuccess GHOST_DisplayManagerCocoa::getNumDisplays(GHOST_TUns8& numDisplays) const
44 {
45         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
46         
47         numDisplays = (GHOST_TUns8) [[NSScreen screens] count];
48         
49         [pool drain];
50         return GHOST_kSuccess;
51 }
52
53
54 GHOST_TSuccess GHOST_DisplayManagerCocoa::getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const
55 {
56         GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::getNumDisplaySettings(): only main display is supported");
57         
58         numSettings = (GHOST_TInt32)3; //Width, Height, BitsPerPixel
59         
60         return GHOST_kSuccess;
61 }
62
63
64 GHOST_TSuccess GHOST_DisplayManagerCocoa::getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting) const
65 {
66         //Note that only current display setting is available
67         NSScreen *askedDisplay;
68         
69         GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::getDisplaySetting(): only main display is supported");
70         
71         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
72         
73         if (display == kMainDisplay) //Screen #0 may not be the main one
74                 askedDisplay = [NSScreen mainScreen];
75         else
76                 askedDisplay = [[NSScreen screens] objectAtIndex:display];
77         
78         if(askedDisplay == nil) {
79                 [pool drain];
80                 return GHOST_kFailure;
81         }
82         
83         NSRect frame = [askedDisplay visibleFrame];
84         setting.xPixels = frame.size.width;
85         setting.yPixels = frame.size.height;
86         
87         setting.bpp = NSBitsPerPixelFromDepth([askedDisplay depth]);
88         
89         setting.frequency = 0; //No more CRT display...
90                                 
91 #ifdef GHOST_DEBUG
92         printf("display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);
93 #endif // GHOST_DEBUG
94
95         [pool drain];
96         return GHOST_kSuccess;
97 }
98
99
100 GHOST_TSuccess GHOST_DisplayManagerCocoa::getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const
101 {
102         NSScreen *askedDisplay;
103         
104         GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::getCurrentDisplaySetting(): only main display is supported");
105     
106         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];     
107
108         if (display == kMainDisplay) //Screen #0 may not be the main one
109                 askedDisplay = [NSScreen mainScreen];
110         else
111                 askedDisplay = [[NSScreen screens] objectAtIndex:display];
112         
113         if(askedDisplay == nil) {
114                 [pool drain];
115                 return GHOST_kFailure;
116         }
117         
118         NSRect frame = [askedDisplay visibleFrame];
119         setting.xPixels = frame.size.width;
120         setting.yPixels = frame.size.height;
121         
122         setting.bpp = NSBitsPerPixelFromDepth([askedDisplay depth]);
123         
124         setting.frequency = 0; //No more CRT display...
125
126 #ifdef GHOST_DEBUG
127         printf("current display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);
128 #endif // GHOST_DEBUG
129
130         [pool drain];
131         return GHOST_kSuccess;
132 }
133
134
135 GHOST_TSuccess GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting)
136 {
137         GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(): only main display is supported");
138
139 #ifdef GHOST_DEBUG
140         printf("GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(): requested settings:\n");
141         printf("  setting.xPixels=%d\n", setting.xPixels);
142         printf("  setting.yPixels=%d\n", setting.yPixels);
143         printf("  setting.bpp=%d\n", setting.bpp);
144         printf("  setting.frequency=%d\n", setting.frequency);
145 #endif // GHOST_DEBUG
146
147         //Display configuration is no more available in 10.6
148         
149 /*      CFDictionaryRef displayModeValues = ::CGDisplayBestModeForParametersAndRefreshRate(
150                 m_displayIDs[display],
151                 (size_t)setting.bpp,
152                 (size_t)setting.xPixels,
153                 (size_t)setting.yPixels,
154                 (CGRefreshRate)setting.frequency,
155                 NULL);*/
156
157 #ifdef GHOST_DEBUG
158 /*      printf("GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(): switching to:\n");
159         printf("  setting.xPixels=%d\n", getValue(displayModeValues, kCGDisplayWidth));
160         printf("  setting.yPixels=%d\n", getValue(displayModeValues, kCGDisplayHeight));
161         printf("  setting.bpp=%d\n", getValue(displayModeValues, kCGDisplayBitsPerPixel));
162         printf("  setting.frequency=%d\n", getValue(displayModeValues, kCGDisplayRefreshRate)); */
163 #endif // GHOST_DEBUG
164
165         //CGDisplayErr err = ::CGDisplaySwitchToMode(m_displayIDs[display], displayModeValues);
166         
167         return /*err == CGDisplayNoErr ? GHOST_kSuccess :*/ GHOST_kFailure;
168 }