2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
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.
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.
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 $ */
22 #include "gnashconfig.h"
30 extern int getopt(int, char *const *, const char *);
36 #include "movie_root.h"
37 #include "RunResources.h"
41 #include <Carbon/Carbon.h>
47 /* Main window widget */
48 WindowRef myWindow
= NULL
;
50 pascal OSStatus
DoWindowClose (EventHandlerCallRef nextHandler
,
54 QuitApplicationEventLoop();
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
),
74 RemoveEventLoopTimer(*_advance_timer
);
81 double interval
= _interval
/ 1000.0;
84 OSStatus ret
= InstallEventLoopTimer (GetMainEventLoop(), 0, interval
,
85 DoAdvanceMovie
, this, _advance_timer
);
90 RepositionWindow(myWindow
, NULL
, kWindowCascadeOnMainScreen
);
91 SelectWindow(myWindow
);
93 SetWindowModified(myWindow
, false);
94 RunApplicationEventLoop();
98 void AquaGui::renderBuffer()
103 GetWindowPortBounds (myWindow
, &rectPort
);
104 InvalWindowRect (myWindow
, &rectPort
); // force redrow
107 bool AquaGui::init(int argc
, char **argv
[]) /* Self-explainatory */
112 Str255 text
= " OS X version lower than 10.4 is not supported!", tmp
= "";
115 err
= Gestalt(gestaltSystemVersion
, &response
);
116 Boolean ok
= ((err
== noErr
) && (response
>= 0x00001040));
120 StandardAlert(kAlertStopAlert
, text
, tmp
, NULL
, NULL
);
124 _glue
.init(argc
, argv
);
126 _renderer
.reset(_glue
.createRenderHandler());
127 if(!_renderer
)return false;
129 _runResources
.setRenderer(boost::shared_ptr
<Renderer
>(_renderer
));
134 void AquaGui::setTimeout(unsigned int timeout
)
139 void AquaGui::key_event(int key
, bool down
)
143 void AquaGui::setCursor(gnash_cursor_type newcursor
)
147 case gnash::CURSOR_HAND
:
148 SetThemeCursor(kThemePointingHandCursor
);
150 case gnash::CURSOR_INPUT
:
151 SetThemeCursor(kThemeCrossCursor
);
154 SetThemeCursor(kThemeArrowCursor
);
159 bool AquaGui::createWindow(const char* title
, int width
, int height
,
160 int xPosition
, int yPosition
)
162 CFStringRef windowTitle
= NULL
;
164 Rect theBounds
= {0, 0, 0, 0};
166 EventTypeSpec eventType
; // Specifier for event type
167 EventHandlerUPP handlerUPP
; // Pointer to event handler routine
172 SetRect(&theBounds
, 0, 0, width
, height
);
173 OSStatus status
= CreateNewWindow ( kDocumentWindowClass
,
174 kWindowStandardDocumentAttributes
175 | kWindowStandardHandlerAttribute
,
179 windowTitle
= CFStringCreateWithCString(NULL
, title
, NULL
);
180 result
= SetWindowTitleWithCFString(myWindow
, windowTitle
);
181 if(windowTitle
!= NULL
)CFRelease(windowTitle
);
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
191 assert(_glue
.prepDrawingArea(_width
, _height
, GetWindowPort(myWindow
)));
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
);
208 InsertMenuItemTextWithCFString(rApplicationMenu
, CFSTR("About Gnash"), (short) 0, 0, kHICommandAbout
);
213 bool AquaGui::setupEvents()