DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2221
Version: 1.3-feature


Support for 64-bit applications on Mac OS X requires the use of Cocoa
because much of Carbon is not available to 64-bit applications. This, in
turn, requires the use of objective-c, or objective-c++. I present here a
modified FLTK-1.3.x-r6858 that can be used to build Cocoa-based FLTK
applications which can be compiled either in 32-bit or 64-bit modes.

Here is a list of statements that describe this contribution:
- Only MAC-specific code has been touched, so WIN32 and X11 FLTK platforms
are unchanged and unconcerned.
- The FLTK API is unchanged, so existing applications can be recompiled
without source-level change in 64-bit mode.
- All changes have been bracketted by #ifdef _APPLE_COCOA__ / #endif. This
allows this codebase to produce a traditional carbon fltk using a
traditional config.h file. The changes are visible if and only if 
#define __APPLE_COCOA__
is added to config.h
- The code presented here is almost complete in the sense that all of FLTK
works (see below for details) in both 32-bit and 64-bit modes, except for
GL- and cairo-related stuff I did not consider at all. Because this stuff
is unchanged, it will work as before under 32-bit but may not compile
under 64-bit mode.
- FLTK's logic of where to clip and when to draw is unchanged; only how
things are drawn change from Carbon to Cocoa. This statement is of course
closely related to the fact that none of the non MAC-specific code was
modified.
- All objective-c code has been put in a single file, FL_cocoa.m, that
replaces Fl_mac.cxx when Fl.cxx is compiled and __APPLE_COCOA__ is
defined. So a single file, Fl.cxx, must be compiled in objective-c++. This
is achieved under Xcode by setting this file to the type
sourcecode.cpp.objcpp. In a make context, the  same is achieved with the
-x objective-c++ gcc option.
- A single .H file was touched, mac.H, where, as said above, changes are
active only if __APPLE_COCOA__ is defined in config.h
- Modified files of the src directory are those dated October 3, 2009 or
after; there are 17 such files. Older files have not been modified.
- Text/fonts: FLTK uses ATSUI which, for some reason I don't grasp, is not
available to 64-bit applications. So the new code uses "Core Text" for UTF
text, but core text is not available before MAC OS 10.5. So "Core Text"
calls are bracketted by
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 / #endif.
Consequently, the 64-bit mode of the new code is not available before
10.5, which is not a problem because GUI-based 64-bit applications did not
start before 10.5. In 32-bit mode, ATSUI is used if an SDK older than 10.5
is used, and Core Text is used with SDK's 10.5 or above.
- UTF support is present with correct display of chinese, russian, greek,
arabic and hebrew text.
- rotated text works.
- right-to-left text output should work but has not been tested.
- The new code compiles in ppc mode for SDKs 10.3, 10.4, 10.5, in i386
mode for 10.4 and above, in x86_64 for 10.5 and above.
- The new code has been tested in 10.5 and 10.6 (which presented some
unexpected surprises) and runs correctly in both cases in 32-bit and
64-bit modes.
- text input: ASCII and non-ASCII keys (I use a French keyboard) are
correctly input (better than with traditional FLTK-1.3). Character
composition does not work, though.
- Fl::add_fd and Fl::add_timeout work, unchanged.
- fl_read_image, that reads a piece of a window, work and allow
fl_overlay_rect to work.
- fl_open_callback works.
- drop of text and filenames and drag of text work.
- Fl_Scroll works using a Cocoa equivalent of CopyBits
- Fl_Open_display now creates a standard "Application menu" with the
About, Hide, Quit commands.
- menu shortcuts work.
- I have added a function (MACsetAboutMenu) that accepts a callback called
by the "About myprog" item of the Application menu.
- Fl_Sys_Menu_Bar.cxx allows to create FLTK menus in the menu bar of the
top of the screen and to attach standard FLTK callbacks to them.
- Cursors: only predefined Cocoa cursors have been used. This allows to
implement much of the FLTK-defined cursors, but one conspicuous absence is
the watch cursor. Missing cursors are all replaced by the default arrow
cursor.
- Modal and non_modal windows work.
- mouse wheel works.
- Carbon regions are not supported by 64-bit applications, so regions have
been replaced by a custom structure:
typedef struct flrects {
        int count;
        CGRect *rects;
} *Fl_Region;
and two support functions were written:
Fl_Region MacRectRegionIntersect(Fl_Region current, int x,int y,int w, int
h)
to intersect a region and a rectangle
and 
Fl_Region MacRegionMinusRect(Fl_Region r, int x,int y,int w,int h)
to remove a rectangle from a region.

I contribute a ZIP archive available at 
http://pbil.univ-lyon1.fr/members/mgouy/data/fltk-1.3-cocoa.zip
containing an Xcode project, fltkCOCOA.xcodeproj located in the fltk-xcode
directory of the archive, with the modified code and several targets:
- fltkCOCOA: builds the 32-bit i386 libfltkCOCOA.a using the 10.4 SDK.
- fltCOCOA64: builds the 64-bit x86_64 libfltkCOCOA64.a using the 10.5
SDK.
- fluid: builds the fluid application (unbundled to allow for arguments)
as an example of a 32-bit cocoa fltk application
- scroll64: builds the scroll.cxx demo application as an example of a
64-bit bundled fltk application.
- libjpeg and libpng: build support 32-bit libraries
- libjpeg64 and libpng64: build support 64-bit libraries

I imagine 64-bit support could be valuable today for example to
image-processing FLTK applications. All of this results from much hard,
but fun, work. I wish the FLTK team will agree to evaluate this
contribution, and hopefully, integrate it in FLTK 1.3


Link: http://www.fltk.org/str.php?L2221
Version: 1.3-feature

_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to