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