Add a fetch-swfdec rule, cloning swfdec git repo or pulling it under testsuite/swfdec/src
[gnash.git] / gui / aqua / aqua.cpp
blob391212db3625b1f7ce0506062380537e962339c2
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
3 // Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (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
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 /* $Id: aqua.cpp,v 1.33 2008/05/26 22:13:33 ann Exp $ */
21 #ifdef HAVE_CONFIG_H
22 #include "gnashconfig.h"
23 #endif
25 extern "C"{
26 # ifdef HAVE_GETOPT_H
27 # include <getopt.h>
28 # endif
29 # ifndef __GNUC__
30 extern int getopt(int, char *const *, const char *);
31 # endif
34 #include "aquasup.h"
35 #include "log.h"
36 #include "movie_root.h"
37 #include "RunResources.h"
39 #include "Renderer.h"
41 #include <Carbon/Carbon.h>
43 using namespace std;
45 namespace gnash {
47 /* Main window widget */
48 WindowRef myWindow = NULL;
50 pascal OSStatus DoWindowClose (EventHandlerCallRef nextHandler,
51 EventRef theEvent,
52 void* userData)
54 QuitApplicationEventLoop();
55 return noErr;
58 void DoAdvanceMovie ( EventLoopTimerRef inTimer, void* data)
60 AquaGui* gui = static_cast<AquaGui*>(data);
61 Gui::advance_movie(gui);
65 AquaGui::AquaGui(unsigned long xid, float scale, bool loop, RunResources& r)
66 : Gui(xid, scale, loop, r),
67 _advance_timer(NULL)
71 AquaGui::~AquaGui()
73 if (_advance_timer) {
74 RemoveEventLoopTimer(*_advance_timer);
79 bool AquaGui::run()
81 double interval = _interval / 1000.0;
84 OSStatus ret = InstallEventLoopTimer (GetMainEventLoop(), 0, interval,
85 DoAdvanceMovie, this, _advance_timer);
86 if (ret != noErr) {
87 return false;
90 RepositionWindow(myWindow, NULL, kWindowCascadeOnMainScreen);
91 SelectWindow(myWindow);
92 ShowWindow(myWindow);
93 SetWindowModified(myWindow, false);
94 RunApplicationEventLoop();
95 return true;
98 void AquaGui::renderBuffer()
100 _glue.render();
102 Rect rectPort;
103 GetWindowPortBounds (myWindow, &rectPort);
104 InvalWindowRect (myWindow, &rectPort); // force redrow
107 bool AquaGui::init(int argc, char **argv[]) /* Self-explainatory */
110 OSErr err;
111 long response;
112 Str255 text = " OS X version lower than 10.4 is not supported!", tmp = "";
114 /* Version check */
115 err = Gestalt(gestaltSystemVersion, &response);
116 Boolean ok = ((err == noErr) && (response >= 0x00001040));
118 if (!ok)
120 StandardAlert(kAlertStopAlert, text, tmp, NULL, NULL);
121 ExitToShell();
124 _glue.init(argc, argv);
126 _renderer.reset(_glue.createRenderHandler());
127 if(!_renderer)return false;
129 _runResources.setRenderer(boost::shared_ptr<Renderer>(_renderer));
130 return true;
134 void AquaGui::setTimeout(unsigned int timeout)
136 _timeout = timeout;
139 void AquaGui::key_event(int key, bool down)
143 void AquaGui::setCursor(gnash_cursor_type newcursor)
146 switch(newcursor) {
147 case gnash::CURSOR_HAND:
148 SetThemeCursor(kThemePointingHandCursor);
149 break;
150 case gnash::CURSOR_INPUT:
151 SetThemeCursor(kThemeCrossCursor);
152 break;
153 default:
154 SetThemeCursor(kThemeArrowCursor);
159 bool AquaGui::createWindow(const char* title, int width, int height,
160 int xPosition, int yPosition)
162 CFStringRef windowTitle = NULL;
163 OSStatus result;
164 Rect theBounds = {0, 0, 0, 0};
166 EventTypeSpec eventType; // Specifier for event type
167 EventHandlerUPP handlerUPP; // Pointer to event handler routine
169 _width = width;
170 _height = height;
172 SetRect(&theBounds, 0, 0, width, height);
173 OSStatus status = CreateNewWindow ( kDocumentWindowClass,
174 kWindowStandardDocumentAttributes
175 | kWindowStandardHandlerAttribute,
176 &theBounds,
177 &myWindow);
179 windowTitle = CFStringCreateWithCString(NULL, title, NULL);
180 result = SetWindowTitleWithCFString(myWindow, windowTitle);
181 if(windowTitle != NULL)CFRelease(windowTitle);
183 createMenu();
185 eventType.eventClass = kEventClassWindow; // Set event class
186 eventType.eventKind = kEventWindowClose; // Set event kind
187 handlerUPP = NewEventHandlerUPP(DoWindowClose); // Point to handler
188 InstallWindowEventHandler (myWindow, handlerUPP, // Install handler
189 1, &eventType,
190 NULL, NULL);
191 assert(_glue.prepDrawingArea(_width, _height, GetWindowPort(myWindow)));
193 return true;
196 bool AquaGui::createMenu()
198 MenuRef rApplicationMenu;
199 MenuItemIndex outIndex[1];
202 /* Enable 'Prefereces...' */
203 EnableMenuCommand(NULL, kHICommandPreferences);
205 GetIndMenuItemWithCommandID(NULL, kHICommandPreferences, 1, &rApplicationMenu, outIndex);
207 /* Enable 'About' */
208 InsertMenuItemTextWithCFString(rApplicationMenu, CFSTR("About Gnash"), (short) 0, 0, kHICommandAbout);
210 return true;
213 bool AquaGui::setupEvents()
216 return true;
219 } // namespace gnash