Difference between revisions of "AquaPortCocoa/Changelog"

From Apache OpenOffice Wiki
Jump to: navigation, search
(vcl)
(vcl)
Line 58: Line 58:
 
- timers issues :  In OpenOffice.org timers are (unfortunaly) everywhere, and a new implementation is needed
 
- timers issues :  In OpenOffice.org timers are (unfortunaly) everywhere, and a new implementation is needed
  
- strings : NSStrings will replace CFStrings (comment fheckl: NSString* s1 = (NSString*)s2, where s2 is a CFString; Apple calls this toll-free bridging)
+
- strings : NSStrings will replace CFStrings  
 +
<pre>Note from fheckl:  
 +
CFStringRef s1 = CFSTR("something");
 +
NSString* s2 = (NSString*)s1;
 +
Apple calls this toll-free bridging :)
 +
</pre>
  
 
- datas: important system datas are available via SalData class. The old design must be adapted for Cocoa change
 
- datas: important system datas are available via SalData class. The old design must be adapted for Cocoa change

Revision as of 23:38, 15 August 2007

Comments in the changes ( aquavcl03 cws )

What follows are dev notes relative to Cocoa migration in Open Office.org code ( Aqua version for Mac OS X )

Changes can be divided into several parts. The initial try (not sure it is the best) will describes changes modules by modules

solenv

All changes in this part are made for fix building issues.

In order to use Cocoa framework, objective-C and objective-C++ flags must be passed to the compiler at build time.

Follow some severe build breakers, fixed with the changes described below. Of course, until aquavcl03 reaches an alpha states, we cannot consider the changes below as definitive.

Initial solenv changes were made in AquaPortCocoa

unxmacx.mk-1.18vs.1.18.36.1

Initial changes

unxmacx.mk-1.18.36.1vs.1.18.36.2

Remove CFLAGSCXX+=$(OBJCXXFLAGS) from unxmacx.mk and put them into vcl dedicated makefile instead. The reason is :

when in solenv -> all modules are concerned, and they are breakers

when in vcl only -> no build issue

Drawback: new modified modules using Objective-C++ flags, must be modified separately. We have not enough experience to decide wich exact strategy use yet.

vcl

We'll try to describe and justify every change in vcl. First were build issues, and they will be described first.

An important part about design should complete asap. Like for Carbon implementation, all the modifications are located in vcl/aqua.

  • vcl/aqua/util or vcl/aqua/prj for everything about building vcl
  • vcl/aqua/inc for interface definition
  • vcl/aqua/source for implementation in :

- app ( everything thread, eventloop, application)

- gdi ( everything AquaSalGraphics )

- window ( everything frame, window(s) )


The most important changes will be about :

- frames /Windowing : CarbonViewRefs wil be replaced by NSViews, same issue for windows

- events : new event management

- threading issues: a new implementation is mandatory

- timers issues : In OpenOffice.org timers are (unfortunaly) everywhere, and a new implementation is needed

- strings : NSStrings will replace CFStrings

Note from fheckl: 
CFStringRef s1 = CFSTR("something");
NSString* s2 = (NSString*)s1;
Apple calls this toll-free bridging :)

- datas: important system datas are available via SalData class. The old design must be adapted for Cocoa change


TODO : replace Carbon menus with Cocoa menus, create .nib entry and links, new Drag and drop implementation ( Cocoa only)

Build

makefile2.pmk-1.3vs.1.3.638.1

Add objective-C++ flags in a dedicated makefile : makefile2.pmk ( all makefiles in vcl/aqua/source include it )

Events

aquavcltypes.h-1.2 vs. 1.2.4.1.html

#include <premac.h>
#include <Carbon/Carbon.h>
+#import <Cocoa/Cocoa.h>
+#import <AppKit/NSEvent.h>
#include <postmac.h>

-> #import replaces #include, and add only once every needed header file.


NSEvent.h does contain all event types.

e.g. :

	NSLeftMouseDown		= 1,
	NSLeftMouseUp		= 2,
	NSRightMouseDown	= 3,
	NSRightMouseUp		= 4,
	NSMouseMoved		= 5,
	NSLeftMouseDragged	= 6,
	NSRightMouseDragged	= 7,
	NSMouseEntered		= 8,
	NSMouseExited		= 9,
	NSKeyDown		= 10,
	NSKeyUp			= 11,

... etc

SalDatas

saldata.hxx-1.14 vs 1.14.4.1.html

- #include <Carbon/Carbon.h>                                                      
+ #include <Cocoa/Cocoa.h>

Remove every Carbon thing, and use Cocoa definitions instead

- class SalInstance;
+ class AquaSalInstance;

Define AquaSalInstance

 - /*                                                                                                                                                      
 -   * SalTimer related members                                                  
 -   */                                                                         
-   BOOL              mbInTimerProc;     // timer event is currently being dispatched
-    BOOL              mbTimerInstalled;  // timer is in the event loop            
-   ULONG             mnTimerMS;         // Current Time (in MS) of the Timer   
-   ULONG             mnTimerOrgMS;      // Current Original Time (in MS)       
-   EventLoopTimerRef mrTimerRef;                                               
-   EventLoopTimerUPP mrTimerUPP;

-> remove Carbon Timers

means : remove all Carbon timers members in SalData structure


TODO :

- check in the code if old code is remaining

Timers

1) saltimer.h-1.4vs.1.4.4.1

Added: prototype for handleStartTimerEvent(), as static void method in AquaSalTimer class.


2) saltimer.cxx-1.14vs.1.14.4.1

Conditionnal inclusions for saltimer.h, saldata.hxx and salframe.h have been removed

USEMAINTHREAD is not defined anymore (was true before the change),the boolean isNSAppThread() is tested instead in the new implementation.

Added:

implementations+initializations of static methods:

- pRunningTimer, as pointer on NSTimer object type ( NSTimer creates timer objects or, more simply, timers )

Note :  NSTimer is “toll-free bridged” with its Core Foundation counterpart, CFRunLoopTimer.
This means that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object.
Therefore, in a method where you see an NSTimer * parameter, you can pass a CFRunLoopTimerRef,
and in a function where you see a CFRunLoopTimerRef parameter, you can pass an NSTimer instance
(you cast one type to the other to suppress compiler warnings)

- bDispatchTimer, bTimerInDispatch as booleans

Added TimerCallbackCaller class, inherited from NSObject class.

ImplSalStartTimer(): new implementation, using only one parameter ( ULONG nMS).

The second parameter bMutex is not used anymore. Now, the test stands on the boolean isNSAppThread(), read in SalData structure (pSalData->mpFirstInstance).

To understand more, there are three ways to create a timer. Here, ImplSalStartTimer() uses scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: class methods automatically add the new timer to the current NSRunLoop object in the default mode (NSDefaultRunLoopMode).

Important : in the case pSalData->mpFirstInstance->isNSAppThread() is false, we have to post an event, to get in the main thread. // FIXME: find more infos

ImplSalStopTimer(): simply set bDispatchTimer to false stops the timer.

AquaSalTimer::AquaSalTimer(): removed previous implementation, using a pointer on SalData object.

(mbTimerInstalled, mnTimerMS, mnTimerOrgMS, mrTimerUPP have been removed )

New void AquaSalTimer::handleStartTimerEvent() implementation:

2) saltimer.cxx-1.14.4.1vs.1.14.4.2

Removed all AquaLog() entries

Modified setFireDate for pRunningTimer object: only setFireDate if [pRunningTimer timeInterval] == aTI.

If different, invalidate pRunningTimer, and retry.

Frame

salframe.h- 1.18 vs. 1.18.4.1

New classes for SalFrameWindow and SalFrameView using objective-C syntax + new variables (and associated types):

@interface SalFrameWindow : NSWindow                                            
{                                                                               
    AquaSalFrame*       mpFrame;                                                
}                                                                               
-(id)initWithSalFrame: (AquaSalFrame*)pFrame;                                   
-(void)windowDidBecomeKey: (NSNotification*)pNotification;                      
-(void)windowDidResignKey: (NSNotification*)pNotification;                      
-(void)windowDidChangeScreen: (NSNotification*)pNotification;                   
-(void)windowDidMove: (NSNotification*)pNotification;                           
-(void)windowDidResize: (NSNotification*)pNotification;                         
-(void)windowDidMiniaturize: (NSNotification*)pNotification;                    
-(void)windowDidDeminiaturize: (NSNotification*)pNotification;                  
-(MacOSBOOL)windowShouldClose: (NSNotification*)pNotification;                  
@end                                                                                                                                                  
                                                                                
@interface SalFrameView : NSView                                                
{                                                                               
    AquaSalFrame*       mpFrame;                                                
}                                                                               
-(id)initWithSalFrame: (AquaSalFrame*)pFrame;                                   
-(MacOSBOOL)acceptsFirstResponder;                                              
-(MacOSBOOL)acceptsFirstMouse: (NSEvent *)pEvent;                               
-(MacOSBOOL)isOpaque;                                                           
-(void)drawRect: (NSRect)aRect;                                                 
-(void)mouseDown: (NSEvent*)pEvent;                                             
-(void)mouseDragged: (NSEvent*)pEvent;                                          
-(void)mouseUp: (NSEvent*)pEvent;                                               
-(void)mouseMoved: (NSEvent*)pEvent;                                            
-(void)mouseEntered: (NSEvent*)pEvent;                                          
-(void)mouseExited: (NSEvent*)pEvent;                                           
-(void)rightMouseDown: (NSEvent*)pEvent;                                        
-(void)rightMouseDragged: (NSEvent*)pEvent;                                     
-(void)rightMouseUp: (NSEvent*)pEvent;                                          
-(void)otherMouseDown: (NSEvent*)pEvent;                                        
-(void)otherMouseDragged: (NSEvent*)pEvent;                                     
-(void)otherMouseUp: (NSEvent*)pEvent;                                          
-(void)scrollWheel: (NSEvent*)pEvent;                                           
-(void)keyDown: (NSEvent*)pEvent;                                               
-(void)keyUp: (NSEvent*)pEvent;                                                 
-(void)flagsChanged: (NSEvent*)pEvent;                                          
-(void)sendMouseEventToFrame:(NSEvent*)pEvent button:(USHORT)nButton eventtype:(USHORT)nEvent;
@end

salframe.cxx-1.50vs.1.50.4.1.html

Remove overlay Event Handler ( TODO : reimplement a new one, if needed )

Remove static void ImplSalCalcFullScreenSize() // Note: useless ?


Implemented AquaSalFrame::AquaSalFrame()

members removed : mpInst / mnWidthn mnWeight, mpSalInstance, maTsmDocumentId, mpMenu

Removed : CreateNewSystemWindow(), InstallAndRegisterAllEventHandler(), DeinstallAndUnregisterAllEventHandler(), GetOptimalWindowSize()


Added :

void AquaSalFrame::initWindowAndView(): helps to initialize mirroring parameters, calculates style mask, and initiamize the frame + delegates to mpWindow // FIXME: desccribe better delegates


void AquaSalFrame::CocoaToVCL( NSRect& io_rRect, bool bRelativeToScreen )

void AquaSalFrame::CocoaToVCL( NSPoint& io_rPoint, bool bRelativeToScreen )

-> translates Cocoa rectangle [resp.] point coordinates into VCL one the Cocoa rectangle [resp.] point depending the fact the rectangle [resp.] the point is relative to screen or not


void AquaSalFrame::VCLToCocoa( NSRect& io_rRect, bool bRelativeToScreen )

void AquaSalFrame::VCLToCocoa( NSPoint& io_rPoint, bool bRelativeToScreen )

-> translate VCL rectangle [resp.] point into Cocoa area [resp.] point depending the fact the rectangle [resp.] the point is relative to screen or not


Modified :

void AquaSalFrame::SetTitle(const XubString& rTitle)

-> replace Carbon things using Cocoa things

( CFStringRef -> NSStrings, and CreateCFString -> CreateNSString)

Removed : CarbonViewRef, and Carbon AquaSalGraphics object type, replaced by Cocoa equivalent.

Removed : Carbon Event Queue management, e.g. PostEventToQueue() .. and Co stuff // FIXME : how does it work now ?

Removed assertion about wrWindow

Removed CreateMenu(), SetRootMenu() ..etc // FIXME : manage menus a day


Added : manage top window in a group

-> orderFront (This action method moves the receiver to the front of its level in the screen list, without changing either the key window or the main window.)

-> makeKeyAndOrderFront() (This action method moves the receiver to the front of the screen list, within its level, and makes it the key window.)

Removed : HideWindow


Replaced Carbon methods with Cocoa one :

CGSize -> NSSize


Removed : SetWindowResizeLimits() , replaced by setMaxSize (ew code:[mpWindow setMaxSize: aSize]; )

Replaced Get/SetWindowBounds with setContentSize

Removed ZoomWindow, CollapseWindow ( use isZoomed / isMiniaturized instead )


Replaced Rect aRectState with NSRect aStateRect

To be fixed:

replace by Cocoa calls all SetSystemUIMode() calls ;

use Cocoa pointers instead of use SetThemeCursor(aPointer[ePointerStyle]);

use Cocoa functions in AquaSalFrame::SetPointerPos()

new implementation of Carbon (??) NewTSMDocument() // FIXME : not sure


Modified:

AquaSalFrame::Flush() -> Sync() replaces Flush()

Rect parentContentRect; -> NSRect aParentContentRect;

In AquaSalFrame::ShowFullScreen() , replaced Carbon stuff with frameRectForContentRect

Removed : AquaSalFrame::DrawMenuBar() // FIXME: implement Cocoa way

Modified AquaSalFrame::GetWorkArea() -> Rect are now NSRect

Implemented SalFrameWindow and SalFrameView using objective-C syntax + corresponding members (and associated types) -> see interface in salframe.hxx

salframe.cxx-1.50.4.1vs.1.50.4.2

in AquaSalFrame::ShowFullScreen() , if mbShown true, pass SALEVENT_MOVERESIZE at event kind, and NULL for the event to CallCallback(), whatever value bFullScreen has.


salframe.cxx-1.50vs.1.50.4.1

in AquaSalFrame::initWindowAndView(), add NSTitledWindowMask as mnStyleMask ( or'ed with existing flags)

salgdi.h-1.31vs.1.31.4.1

Removed Carbon refs: CarbonViewRef , CarbonWindowRef, IsScreenCompatible()

Modified: add Cocoa implementations of SetWindowGraphics() and UpdateWindow()

salgdiutils.cxx-1.10vs.1.10.4.1

New AquaSalGraphics::SetWindowGraphics() implementation. pFrame alone replaces mrView, mrWindow, mbScreen ( FIXME : needed in the future ? )

Modified AquaSalGraphics::CheckContext() and AquaSalGraphics::RefreshRect() implementation (): use mpFrame only )

In RefreshRect(), added a workaround for antialiased rendering. The area outside the rect is not refreshed and causes "lines" and alien around an area containing gradients e.g. Add + 2 to the REct size helps.

Partial Cocoa implementation of AquaSalGraphics::UpdateWindow() // FIXME : work completed ?

SalInstance

salinst.h-1.12vs.1.12.4.1

Modifications in class SalYieldMutex

New class AquaSalInstance: added structure SalUserEvent

Removed TimerEvenHandler(), replaced by handleAppDefinedEvent()

New methods: PostUserEvent, isNSAppThread(), CreateNSString()

Added new members in AquaSalInstance:

void PostUserEvent()

bool isNSAppThread() const;

// event subtypes for NSApplicationDefined events

static const short AppEndLoopEvent = 1;

static const short AppStartTimerEvent = 10;

+ added a new helper: CreateNSString( const rtl::OUString& )

salinst.cxx-1.37vs.1.37.4.1

Declaration + Implementation of VCL_NSApplication (VCL_NSApplication inherits of NSApplication): this is the real NS application, and a key must be added in the Info.plist to make it start properly.

Part to be added (before CFBundleExecutable key) in the Info.plist:

<key>NSPrincipalClass</key>
<string>VCL_NSApplication</string>

Removed SetFilterCallback() implementation.

Code cleanup in ImplSalYieldMutexRelease()

Implementation of CocoaThreadEnabler class (inherits of NSObject ). Additional note: Instanciated object of this class does nothing: this is just to start an NSThread and therefore put Cococa into multithread mode


Modified : CreateSalInstance()

Inside have been removed eventLoopTimer, and InstallEventLoopTimer() replaced by all operation allowing VCL_NSApplication initialization.

// FIXME: needs some rework, because does not work as expected.

AquaSalInstance() Ctor:

- removed mpFilterCallback, mpFilterInst - added : maMainThread, mpAutoreleasePool, maUserEventListMutex

Removed:

void AquaSalInstance::TimerEventHandler(),

void AquaSalInstance::StartForceDispatchingPaintEvents()

void AquaSalInstance::StopForceDispatchingPaintEvents()


Added:

void AquaSalInstance::PostUserEvent()

bool AquaSalInstance::isNSAppThread()

void AquaSalInstance::handleAppDefinedEvent()

New implementation of void AquaSalInstance::Yield(). // FIXME: does not work well. Needs rework;

Important comments about AquaSalInstance::Yield() changes:

/*                                                                      
the first try for Yield was like this:

NSDate* pDate = bWait ? [NSDate distantFuture] : [NSDate distantPast];  
NSEvent* pEvent = nil;
do
{
  pEvent = [NSApp nextEventMatchingMask: NSAnyEventMask untilDate: pDate inMode: NSDefaultRunLoopMode
  dequeue: YES];
  if( pEvent )
    [NSApp sendEvent: pEvent];
}while( bHandleAllCurrentEvents && pEvent );                           
[NSApp updateWindows];                                                  

However this caused strange hanging with the desktop quasi locked. It seems that NSApplication:run does something extra we don't know about. The (temporary?) solution ist to use the actual run message and stop.it after dispatching an event                                                    
drawback:                                                               
                                                                                
- unknown overhead in NSApplication:run (which in normal Cocoa applications is called once and not left until program termination)
- currently this effects forcing bHandleAllCurrentEvents to false, we only dispatch one event.
Added comment: posting an event to the end of the queue before calling [NSApp run] to dispatch all events up to then works,
but has significant runtime issues; it seems to spend lots of time in -postEvent:atStart: locking and unlocking spinlocks.
This is not a viable option. Unfortunately there is alos no method to get the number of current events or the last event.

*/

Modified AquaSalInstance::CreateFrame(): removed try/catch pair

Added CreateNSString() helper.

salinst.cxx-1.37.4.1vs.1.37.4.2

Removed conditionnal inclusions for saldata.hxx, salinst.h, salframe.h, salobj.h, salsys.h, salvd.h, tools/fsys.hxx, vcl/salimestatus.hxx + add rtl/ustrbuf.hxx ( for rtl::OUString )

Implemented rtl::OUString GetOUString()

TO BE CONTINUED

vcldemo

In aquavcl01 cws, the toy we used for experiences and debug was svdem. This time, a new one has been created. It's name is vcldemo.

The progressive changes implemented will be described in this part.

initial try

Draw antialiased lines + red rectangles when clicking somewhere with left mouse button

makefile.mk-1.19vs.1.19.4.1

Build vcldemo instead of svdem at build time.

vcldemo.cxx-1.3vs.1.3.4.1

Added : draw a simple string, using times fonts

Personal tools