2009-12-07 01:21:55 +03:00
|
|
|
//
|
2011-03-29 15:19:51 +04:00
|
|
|
// "$Id$"
|
2009-12-07 01:21:55 +03:00
|
|
|
//
|
2010-02-15 23:35:58 +03:00
|
|
|
// MacOS-Cocoa specific code for the Fast Light Tool Kit (FLTK).
|
2009-12-07 01:21:55 +03:00
|
|
|
//
|
2014-10-14 15:53:51 +04:00
|
|
|
// Copyright 1998-2014 by Bill Spitzak and others.
|
2009-12-07 01:21:55 +03:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/COPYING.php
|
2009-12-07 01:21:55 +03:00
|
|
|
//
|
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
|
|
|
//
|
|
|
|
|
|
|
|
//// From the inner edge of a MetroWerks CodeWarrior CD:
|
|
|
|
// (without permission)
|
|
|
|
//
|
|
|
|
// "Three Compiles for 68Ks under the sky,
|
|
|
|
// Seven Compiles for PPCs in their fragments of code,
|
|
|
|
// Nine Compiles for Mortal Carbon doomed to die,
|
|
|
|
// One Compile for Mach-O Cocoa on its Mach-O throne,
|
|
|
|
// in the Land of MacOS X where the Drop-Shadows lie.
|
|
|
|
//
|
|
|
|
// One Compile to link them all, One Compile to merge them,
|
|
|
|
// One Compile to copy them all and in the bundle bind them,
|
|
|
|
// in the Land of MacOS X where the Drop-Shadows lie."
|
|
|
|
|
2010-12-19 20:57:19 +03:00
|
|
|
#ifdef __APPLE__
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
#define CONSOLIDATE_MOTION 0
|
|
|
|
extern "C" {
|
|
|
|
#include <pthread.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/x.H>
|
|
|
|
#include <FL/Fl_Window.H>
|
|
|
|
#include <FL/Fl_Tooltip.H>
|
2010-03-15 18:57:48 +03:00
|
|
|
#include <FL/Fl_Printer.H>
|
2009-12-13 15:03:26 +03:00
|
|
|
#include <FL/Fl_Input_.H>
|
2010-11-29 17:12:57 +03:00
|
|
|
#include <FL/Fl_Text_Display.H>
|
2014-11-08 21:14:31 +03:00
|
|
|
#include <FL/Fl_Copy_Surface.H>
|
2009-12-07 01:21:55 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "flstring.h"
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdarg.h>
|
2012-06-16 12:49:52 +04:00
|
|
|
#include <math.h>
|
2013-01-29 01:05:29 +04:00
|
|
|
#include <limits.h>
|
2014-09-13 20:49:47 +04:00
|
|
|
#include <dlfcn.h>
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
2009-12-07 22:15:37 +03:00
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
#ifndef NSINTEGER_DEFINED // appears with 10.5 in NSObjCRuntime.h
|
2009-12-09 02:15:30 +03:00
|
|
|
#if defined(__LP64__) && __LP64__
|
2009-12-07 01:21:55 +03:00
|
|
|
typedef long NSInteger;
|
|
|
|
typedef unsigned long NSUInteger;
|
2009-12-09 02:15:30 +03:00
|
|
|
#else
|
2011-01-03 19:50:34 +03:00
|
|
|
typedef long NSInteger;
|
2009-12-09 02:15:30 +03:00
|
|
|
typedef unsigned int NSUInteger;
|
|
|
|
#endif
|
2009-12-07 01:21:55 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// #define DEBUG_SELECT // UNCOMMENT FOR SELECT()/THREAD DEBUGGING
|
|
|
|
#ifdef DEBUG_SELECT
|
|
|
|
#include <stdio.h> // testing
|
|
|
|
#define DEBUGMSG(msg) if ( msg ) fprintf(stderr, msg);
|
|
|
|
#define DEBUGPERRORMSG(msg) if ( msg ) perror(msg)
|
|
|
|
#define DEBUGTEXT(txt) txt
|
|
|
|
#else
|
|
|
|
#define DEBUGMSG(msg)
|
|
|
|
#define DEBUGPERRORMSG(msg)
|
|
|
|
#define DEBUGTEXT(txt) NULL
|
|
|
|
#endif /*DEBUG_SELECT*/
|
|
|
|
|
|
|
|
// external functions
|
|
|
|
extern void fl_fix_focus();
|
2012-03-10 12:45:44 +04:00
|
|
|
extern unsigned short *fl_compute_macKeyLookUp();
|
2014-09-15 13:17:56 +04:00
|
|
|
extern int fl_send_system_handlers(void *e);
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
// forward definition of functions in this file
|
|
|
|
// converting cr lf converter function
|
|
|
|
static void convert_crlf(char * string, size_t len);
|
|
|
|
static void createAppleMenu(void);
|
|
|
|
static void cocoaMouseHandler(NSEvent *theEvent);
|
2012-09-27 16:49:39 +04:00
|
|
|
static int calc_mac_os_version();
|
2013-09-11 16:54:40 +04:00
|
|
|
static void clipboard_check(void);
|
2013-12-10 16:07:09 +04:00
|
|
|
static NSString *calc_utf8_format(void);
|
2014-06-15 22:45:32 +04:00
|
|
|
static unsigned make_current_counts = 0; // if > 0, then Fl_Window::make_current() can be called only once
|
|
|
|
static Fl_X *fl_x_to_redraw = NULL; // set by Fl_X::flush() to the Fl_X object of the window to be redrawn
|
2014-11-11 19:08:09 +03:00
|
|
|
static NSBitmapImageRep* rect_to_NSBitmapImageRep(Fl_Window *win, int x, int y, int w, int h);
|
2009-12-07 01:21:55 +03:00
|
|
|
|
2013-04-15 15:00:24 +04:00
|
|
|
Fl_Display_Device *Fl_Display_Device::_display = new Fl_Display_Device(new Fl_Quartz_Graphics_Driver); // the platform display
|
2010-03-14 21:07:24 +03:00
|
|
|
|
2009-12-07 01:21:55 +03:00
|
|
|
// public variables
|
|
|
|
CGContextRef fl_gc = 0;
|
2009-12-09 02:15:30 +03:00
|
|
|
void *fl_capture = 0; // (NSWindow*) we need this to compensate for a missing(?) mouse capture
|
|
|
|
bool fl_show_iconic; // true if called from iconize() - shows the next created window in collapsed state
|
2010-11-29 18:59:53 +03:00
|
|
|
//int fl_disable_transient_for; // secret method of removing TRANSIENT_FOR
|
2009-12-07 01:21:55 +03:00
|
|
|
Window fl_window;
|
|
|
|
Fl_Window *Fl_Window::current_;
|
2012-09-27 16:49:39 +04:00
|
|
|
int fl_mac_os_version = calc_mac_os_version(); // the version number of the running Mac OS X (e.g., 100604 for 10.6.4)
|
2013-10-29 16:46:51 +04:00
|
|
|
Fl_Fontdesc* fl_fonts = Fl_X::calc_fl_fonts();
|
2013-12-10 16:07:09 +04:00
|
|
|
static NSString *utf8_format = calc_utf8_format();
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
// forward declarations of variables in this file
|
|
|
|
static int got_events = 0;
|
|
|
|
static Fl_Window* resize_from_system;
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
static int main_screen_height; // height of menubar-containing screen used to convert between Cocoa and FLTK global screen coordinates
|
2014-03-22 21:09:07 +04:00
|
|
|
// through_drawRect = YES means the drawRect: message was sent to the view,
|
|
|
|
// thus the graphics context was prepared by the system
|
|
|
|
static BOOL through_drawRect = NO;
|
2014-09-15 13:44:35 +04:00
|
|
|
static int im_enabled = -1;
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
#if CONSOLIDATE_MOTION
|
|
|
|
static Fl_Window* send_motion;
|
|
|
|
extern Fl_Window* fl_xmousewin;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
enum { FLTKTimerEvent = 1, FLTKDataReadyEvent };
|
|
|
|
|
2014-09-15 13:44:35 +04:00
|
|
|
// Carbon functions and definitions
|
|
|
|
|
|
|
|
typedef void *TSMDocumentID;
|
|
|
|
|
|
|
|
extern "C" enum {
|
|
|
|
kTSMDocumentEnabledInputSourcesPropertyTag = 'enis' // from Carbon/TextServices.h
|
|
|
|
};
|
|
|
|
|
|
|
|
// Undocumented voodoo. Taken from Mozilla.
|
|
|
|
static const int smEnableRomanKybdsOnly = -23;
|
|
|
|
|
|
|
|
typedef TSMDocumentID (*TSMGetActiveDocument_type)(void);
|
|
|
|
static TSMGetActiveDocument_type TSMGetActiveDocument;
|
|
|
|
typedef OSStatus (*TSMSetDocumentProperty_type)(TSMDocumentID, OSType, UInt32, void*);
|
|
|
|
static TSMSetDocumentProperty_type TSMSetDocumentProperty;
|
|
|
|
typedef OSStatus (*TSMRemoveDocumentProperty_type)(TSMDocumentID, OSType);
|
|
|
|
static TSMRemoveDocumentProperty_type TSMRemoveDocumentProperty;
|
|
|
|
typedef CFArrayRef (*TISCreateASCIICapableInputSourceList_type)(void);
|
|
|
|
static TISCreateASCIICapableInputSourceList_type TISCreateASCIICapableInputSourceList;
|
|
|
|
|
|
|
|
typedef void (*KeyScript_type)(short);
|
|
|
|
static KeyScript_type KeyScript;
|
|
|
|
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
/* fltk-utf8 placekeepers */
|
|
|
|
void fl_reset_spot()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void fl_set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void fl_set_status(int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2009-12-07 01:21:55 +03:00
|
|
|
* Mac keyboard lookup table
|
|
|
|
*/
|
2012-03-10 12:45:44 +04:00
|
|
|
static unsigned short* macKeyLookUp = fl_compute_macKeyLookUp();
|
2009-12-07 01:21:55 +03:00
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2009-12-07 01:21:55 +03:00
|
|
|
* convert the current mouse chord into the FLTK modifier state
|
|
|
|
*/
|
|
|
|
static unsigned int mods_to_e_state( NSUInteger mods )
|
|
|
|
{
|
|
|
|
long state = 0;
|
|
|
|
if ( mods & NSCommandKeyMask ) state |= FL_META;
|
|
|
|
if ( mods & NSAlternateKeyMask ) state |= FL_ALT;
|
|
|
|
if ( mods & NSControlKeyMask ) state |= FL_CTRL;
|
|
|
|
if ( mods & NSShiftKeyMask ) state |= FL_SHIFT;
|
|
|
|
if ( mods & NSAlphaShiftKeyMask ) state |= FL_CAPS_LOCK;
|
|
|
|
unsigned int ret = ( Fl::e_state & 0xff000000 ) | state;
|
|
|
|
Fl::e_state = ret;
|
|
|
|
//printf( "State 0x%08x (%04x)\n", Fl::e_state, mods );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// these pointers are set by the Fl::lock() function:
|
|
|
|
static void nothing() {}
|
|
|
|
void (*fl_lock_function)() = nothing;
|
|
|
|
void (*fl_unlock_function)() = nothing;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Select interface -- how it's implemented:
|
|
|
|
// When the user app configures one or more file descriptors to monitor
|
|
|
|
// with Fl::add_fd(), we start a separate thread to select() the data,
|
|
|
|
// sending a custom OSX 'FLTK data ready event' to the parent thread's
|
|
|
|
// RunApplicationLoop(), so that it triggers the data ready callbacks
|
|
|
|
// in the parent thread. -erco 04/04/04
|
|
|
|
//
|
|
|
|
#define POLLIN 1
|
|
|
|
#define POLLOUT 4
|
|
|
|
#define POLLERR 8
|
|
|
|
|
|
|
|
// Class to handle select() 'data ready'
|
|
|
|
class DataReady
|
|
|
|
{
|
|
|
|
struct FD
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
short events;
|
|
|
|
void (*cb)(int, void*);
|
|
|
|
void* arg;
|
|
|
|
};
|
|
|
|
int nfds, fd_array_size;
|
|
|
|
FD *fds;
|
|
|
|
pthread_t tid; // select()'s thread id
|
|
|
|
|
|
|
|
// Data that needs to be locked (all start with '_')
|
|
|
|
pthread_mutex_t _datalock; // data lock
|
|
|
|
fd_set _fdsets[3]; // r/w/x sets user wants to monitor
|
|
|
|
int _maxfd; // max fd count to monitor
|
|
|
|
int _cancelpipe[2]; // pipe used to help cancel thread
|
|
|
|
|
|
|
|
public:
|
|
|
|
DataReady()
|
|
|
|
{
|
|
|
|
nfds = 0;
|
|
|
|
fd_array_size = 0;
|
|
|
|
fds = 0;
|
|
|
|
tid = 0;
|
|
|
|
|
|
|
|
pthread_mutex_init(&_datalock, NULL);
|
|
|
|
FD_ZERO(&_fdsets[0]); FD_ZERO(&_fdsets[1]); FD_ZERO(&_fdsets[2]);
|
|
|
|
_cancelpipe[0] = _cancelpipe[1] = 0;
|
2011-05-31 15:20:52 +04:00
|
|
|
_maxfd = -1;
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
~DataReady()
|
|
|
|
{
|
|
|
|
CancelThread(DEBUGTEXT("DESTRUCTOR\n"));
|
|
|
|
if (fds) { free(fds); fds = 0; }
|
|
|
|
nfds = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Locks
|
|
|
|
// The convention for locks: volatile vars start with '_',
|
|
|
|
// and must be locked before use. Locked code is prefixed
|
|
|
|
// with /*LOCK*/ to make painfully obvious esp. in debuggers. -erco
|
|
|
|
//
|
|
|
|
void DataLock() { pthread_mutex_lock(&_datalock); }
|
|
|
|
void DataUnlock() { pthread_mutex_unlock(&_datalock); }
|
|
|
|
|
|
|
|
// Accessors
|
|
|
|
int IsThreadRunning() { return(tid ? 1 : 0); }
|
|
|
|
int GetNfds() { return(nfds); }
|
|
|
|
int GetCancelPipe(int ix) { return(_cancelpipe[ix]); }
|
|
|
|
fd_set GetFdset(int ix) { return(_fdsets[ix]); }
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
void AddFD(int n, int events, void (*cb)(int, void*), void *v);
|
|
|
|
void RemoveFD(int n, int events);
|
|
|
|
int CheckData(fd_set& r, fd_set& w, fd_set& x);
|
|
|
|
void HandleData(fd_set& r, fd_set& w, fd_set& x);
|
|
|
|
static void* DataReadyThread(void *self);
|
2010-03-26 19:04:06 +03:00
|
|
|
void StartThread(void);
|
2009-12-07 01:21:55 +03:00
|
|
|
void CancelThread(const char *reason);
|
|
|
|
};
|
|
|
|
|
|
|
|
static DataReady dataready;
|
|
|
|
|
|
|
|
void DataReady::AddFD(int n, int events, void (*cb)(int, void*), void *v)
|
|
|
|
{
|
|
|
|
RemoveFD(n, events);
|
|
|
|
int i = nfds++;
|
|
|
|
if (i >= fd_array_size)
|
|
|
|
{
|
2011-03-01 15:37:34 +03:00
|
|
|
fl_open_display(); // necessary for NSApp to be defined and the event loop to work
|
2009-12-07 01:21:55 +03:00
|
|
|
FD *temp;
|
|
|
|
fd_array_size = 2*fd_array_size+1;
|
|
|
|
if (!fds) { temp = (FD*)malloc(fd_array_size*sizeof(FD)); }
|
|
|
|
else { temp = (FD*)realloc(fds, fd_array_size*sizeof(FD)); }
|
|
|
|
if (!temp) return;
|
|
|
|
fds = temp;
|
|
|
|
}
|
|
|
|
fds[i].cb = cb;
|
|
|
|
fds[i].arg = v;
|
|
|
|
fds[i].fd = n;
|
|
|
|
fds[i].events = events;
|
|
|
|
DataLock();
|
|
|
|
/*LOCK*/ if (events & POLLIN) FD_SET(n, &_fdsets[0]);
|
|
|
|
/*LOCK*/ if (events & POLLOUT) FD_SET(n, &_fdsets[1]);
|
|
|
|
/*LOCK*/ if (events & POLLERR) FD_SET(n, &_fdsets[2]);
|
|
|
|
/*LOCK*/ if (n > _maxfd) _maxfd = n;
|
|
|
|
DataUnlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove an FD from the array
|
|
|
|
void DataReady::RemoveFD(int n, int events)
|
|
|
|
{
|
|
|
|
int i,j;
|
2011-05-31 15:20:52 +04:00
|
|
|
_maxfd = -1; // recalculate maxfd on the fly
|
2010-01-14 02:13:59 +03:00
|
|
|
for (i=j=0; i<nfds; i++) {
|
|
|
|
if (fds[i].fd == n) {
|
2009-12-07 01:21:55 +03:00
|
|
|
int e = fds[i].events & ~events;
|
|
|
|
if (!e) continue; // if no events left, delete this fd
|
|
|
|
fds[i].events = e;
|
|
|
|
}
|
2011-05-31 15:20:52 +04:00
|
|
|
if (fds[i].fd > _maxfd) _maxfd = fds[i].fd;
|
2009-12-07 01:21:55 +03:00
|
|
|
// move it down in the array if necessary:
|
2010-01-14 02:13:59 +03:00
|
|
|
if (j<i) {
|
|
|
|
fds[j] = fds[i];
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
nfds = j;
|
|
|
|
DataLock();
|
|
|
|
/*LOCK*/ if (events & POLLIN) FD_CLR(n, &_fdsets[0]);
|
|
|
|
/*LOCK*/ if (events & POLLOUT) FD_CLR(n, &_fdsets[1]);
|
|
|
|
/*LOCK*/ if (events & POLLERR) FD_CLR(n, &_fdsets[2]);
|
|
|
|
DataUnlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK IF USER DATA READY, RETURNS r/w/x INDICATING WHICH IF ANY
|
|
|
|
int DataReady::CheckData(fd_set& r, fd_set& w, fd_set& x)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
DataLock();
|
|
|
|
/*LOCK*/ timeval t = { 0, 1 }; // quick check
|
|
|
|
/*LOCK*/ r = _fdsets[0], w = _fdsets[1], x = _fdsets[2];
|
|
|
|
/*LOCK*/ ret = ::select(_maxfd+1, &r, &w, &x, &t);
|
|
|
|
DataUnlock();
|
2010-01-14 02:13:59 +03:00
|
|
|
if ( ret == -1 ) {
|
|
|
|
DEBUGPERRORMSG("CheckData(): select()");
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
// HANDLE DATA READY CALLBACKS
|
|
|
|
void DataReady::HandleData(fd_set& r, fd_set& w, fd_set& x)
|
|
|
|
{
|
2010-01-14 02:13:59 +03:00
|
|
|
for (int i=0; i<nfds; i++) {
|
2009-12-07 01:21:55 +03:00
|
|
|
int f = fds[i].fd;
|
|
|
|
short revents = 0;
|
|
|
|
if (FD_ISSET(f, &r)) revents |= POLLIN;
|
|
|
|
if (FD_ISSET(f, &w)) revents |= POLLOUT;
|
|
|
|
if (FD_ISSET(f, &x)) revents |= POLLERR;
|
2010-01-14 02:13:59 +03:00
|
|
|
if (fds[i].events & revents) {
|
2009-12-07 01:21:55 +03:00
|
|
|
DEBUGMSG("DOING CALLBACK: ");
|
|
|
|
fds[i].cb(f, fds[i].arg);
|
|
|
|
DEBUGMSG("DONE\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DATA READY THREAD
|
|
|
|
// This thread watches for changes in user's file descriptors.
|
|
|
|
// Sends a 'data ready event' to the main thread if any change.
|
|
|
|
//
|
|
|
|
void* DataReady::DataReadyThread(void *o)
|
|
|
|
{
|
|
|
|
DataReady *self = (DataReady*)o;
|
2010-01-14 02:13:59 +03:00
|
|
|
while ( 1 ) { // loop until thread cancel or error
|
2009-12-07 01:21:55 +03:00
|
|
|
// Thread safe local copies of data before each select()
|
|
|
|
self->DataLock();
|
|
|
|
/*LOCK*/ int maxfd = self->_maxfd;
|
|
|
|
/*LOCK*/ fd_set r = self->GetFdset(0);
|
|
|
|
/*LOCK*/ fd_set w = self->GetFdset(1);
|
|
|
|
/*LOCK*/ fd_set x = self->GetFdset(2);
|
|
|
|
/*LOCK*/ int cancelpipe = self->GetCancelPipe(0);
|
|
|
|
/*LOCK*/ if ( cancelpipe > maxfd ) maxfd = cancelpipe;
|
|
|
|
/*LOCK*/ FD_SET(cancelpipe, &r); // add cancelpipe to fd's to watch
|
|
|
|
/*LOCK*/ FD_SET(cancelpipe, &x);
|
|
|
|
self->DataUnlock();
|
|
|
|
// timeval t = { 1000, 0 }; // 1000 seconds;
|
|
|
|
timeval t = { 2, 0 }; // HACK: 2 secs prevents 'hanging' problem
|
|
|
|
int ret = ::select(maxfd+1, &r, &w, &x, &t);
|
|
|
|
pthread_testcancel(); // OSX 10.0.4 and older: needed for parent to cancel
|
2010-01-14 02:13:59 +03:00
|
|
|
switch ( ret ) {
|
2009-12-07 01:21:55 +03:00
|
|
|
case 0: // NO DATA
|
|
|
|
continue;
|
|
|
|
case -1: // ERROR
|
|
|
|
{
|
|
|
|
DEBUGPERRORMSG("CHILD THREAD: select() failed");
|
|
|
|
return(NULL); // error? exit thread
|
|
|
|
}
|
|
|
|
default: // DATA READY
|
|
|
|
{
|
|
|
|
if (FD_ISSET(cancelpipe, &r) || FD_ISSET(cancelpipe, &x)) // cancel?
|
2010-01-14 02:13:59 +03:00
|
|
|
{ return(NULL); } // just exit
|
2009-12-07 01:21:55 +03:00
|
|
|
DEBUGMSG("CHILD THREAD: DATA IS READY\n");
|
2014-11-06 18:35:32 +03:00
|
|
|
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
|
|
|
|
NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined
|
|
|
|
location:NSMakePoint(0,0)
|
|
|
|
modifierFlags:0
|
2009-12-07 01:21:55 +03:00
|
|
|
timestamp:0
|
2014-11-06 18:35:32 +03:00
|
|
|
windowNumber:0 context:NULL subtype:FLTKDataReadyEvent data1:0 data2:0];
|
2009-12-07 01:21:55 +03:00
|
|
|
[NSApp postEvent:event atStart:NO];
|
2014-11-06 18:35:32 +03:00
|
|
|
[localPool release];
|
2009-12-07 01:21:55 +03:00
|
|
|
return(NULL); // done with thread
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// START 'DATA READY' THREAD RUNNING, CREATE INTER-THREAD PIPE
|
2010-03-26 19:04:06 +03:00
|
|
|
void DataReady::StartThread(void)
|
2009-12-07 01:21:55 +03:00
|
|
|
{
|
|
|
|
CancelThread(DEBUGTEXT("STARTING NEW THREAD\n"));
|
|
|
|
DataLock();
|
|
|
|
/*LOCK*/ pipe(_cancelpipe); // pipe for sending cancel msg to thread
|
|
|
|
DataUnlock();
|
|
|
|
DEBUGMSG("*** START THREAD\n");
|
|
|
|
pthread_create(&tid, NULL, DataReadyThread, (void*)this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// CANCEL 'DATA READY' THREAD, CLOSE PIPE
|
|
|
|
void DataReady::CancelThread(const char *reason)
|
|
|
|
{
|
2010-01-14 02:13:59 +03:00
|
|
|
if ( tid ) {
|
2009-12-07 01:21:55 +03:00
|
|
|
DEBUGMSG("*** CANCEL THREAD: ");
|
|
|
|
DEBUGMSG(reason);
|
2010-01-14 02:13:59 +03:00
|
|
|
if ( pthread_cancel(tid) == 0 ) { // cancel first
|
2009-12-07 01:21:55 +03:00
|
|
|
DataLock();
|
|
|
|
/*LOCK*/ write(_cancelpipe[1], "x", 1); // wake thread from select
|
|
|
|
DataUnlock();
|
|
|
|
pthread_join(tid, NULL); // wait for thread to finish
|
|
|
|
}
|
|
|
|
tid = 0;
|
|
|
|
DEBUGMSG("(JOINED) OK\n");
|
|
|
|
}
|
|
|
|
// Close pipe if open
|
|
|
|
DataLock();
|
|
|
|
/*LOCK*/ if ( _cancelpipe[0] ) { close(_cancelpipe[0]); _cancelpipe[0] = 0; }
|
|
|
|
/*LOCK*/ if ( _cancelpipe[1] ) { close(_cancelpipe[1]); _cancelpipe[1] = 0; }
|
|
|
|
DataUnlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fl::add_fd( int n, int events, void (*cb)(int, void*), void *v )
|
2010-01-14 02:13:59 +03:00
|
|
|
{
|
|
|
|
dataready.AddFD(n, events, cb, v);
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
void Fl::add_fd(int fd, void (*cb)(int, void*), void* v)
|
2010-01-14 02:13:59 +03:00
|
|
|
{
|
|
|
|
dataready.AddFD(fd, POLLIN, cb, v);
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
void Fl::remove_fd(int n, int events)
|
2010-01-14 02:13:59 +03:00
|
|
|
{
|
|
|
|
dataready.RemoveFD(n, events);
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
void Fl::remove_fd(int n)
|
2010-01-14 02:13:59 +03:00
|
|
|
{
|
|
|
|
dataready.RemoveFD(n, -1);
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2012-06-16 12:49:52 +04:00
|
|
|
* Check if there is actually a message pending
|
2009-12-07 01:21:55 +03:00
|
|
|
*/
|
|
|
|
int fl_ready()
|
|
|
|
{
|
2010-01-14 02:13:59 +03:00
|
|
|
NSEvent *retval = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:0]
|
|
|
|
inMode:NSDefaultRunLoopMode dequeue:NO];
|
|
|
|
return retval != nil;
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void processFLTKEvent(void) {
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2009-12-21 21:43:13 +03:00
|
|
|
dataready.CancelThread(DEBUGTEXT("DATA READY EVENT\n"));
|
|
|
|
|
|
|
|
// CHILD THREAD TELLS US DATA READY
|
|
|
|
// Check to see what's ready, and invoke user's cb's
|
|
|
|
//
|
|
|
|
fd_set r,w,x;
|
2010-01-14 02:13:59 +03:00
|
|
|
switch(dataready.CheckData(r,w,x)) {
|
2009-12-21 21:43:13 +03:00
|
|
|
case 0: // NO DATA
|
|
|
|
break;
|
|
|
|
case -1: // ERROR
|
|
|
|
break;
|
|
|
|
default: // DATA READY
|
|
|
|
dataready.HandleData(r,w,x);
|
|
|
|
break;
|
|
|
|
}
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2009-12-21 21:43:13 +03:00
|
|
|
return;
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2009-12-07 01:21:55 +03:00
|
|
|
* break the current event loop
|
|
|
|
*/
|
|
|
|
static void breakMacEventLoop()
|
2013-11-13 19:49:48 +04:00
|
|
|
{
|
2014-11-06 18:35:32 +03:00
|
|
|
NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined location:NSMakePoint(0,0)
|
|
|
|
modifierFlags:0 timestamp:0
|
|
|
|
windowNumber:0 context:NULL subtype:FLTKTimerEvent data1:0 data2:0];
|
2009-12-07 01:21:55 +03:00
|
|
|
[NSApp postEvent:event atStart:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// MacOS X timers
|
|
|
|
//
|
|
|
|
|
|
|
|
struct MacTimeout {
|
|
|
|
Fl_Timeout_Handler callback;
|
|
|
|
void* data;
|
2010-05-27 00:04:00 +04:00
|
|
|
CFRunLoopTimerRef timer;
|
2009-12-07 01:21:55 +03:00
|
|
|
char pending;
|
2012-06-15 19:08:17 +04:00
|
|
|
CFAbsoluteTime next_timeout; // scheduled time for this timer
|
2009-12-07 01:21:55 +03:00
|
|
|
};
|
|
|
|
static MacTimeout* mac_timers;
|
|
|
|
static int mac_timer_alloc;
|
|
|
|
static int mac_timer_used;
|
2012-06-15 19:08:17 +04:00
|
|
|
static MacTimeout* current_timer; // the timer that triggered its callback function, or NULL
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
static void realloc_timers()
|
|
|
|
{
|
|
|
|
if (mac_timer_alloc == 0) {
|
|
|
|
mac_timer_alloc = 8;
|
2011-03-01 15:37:34 +03:00
|
|
|
fl_open_display(); // needed because the timer creates an event
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
mac_timer_alloc *= 2;
|
|
|
|
MacTimeout* new_timers = new MacTimeout[mac_timer_alloc];
|
|
|
|
memset(new_timers, 0, sizeof(MacTimeout)*mac_timer_alloc);
|
|
|
|
memcpy(new_timers, mac_timers, sizeof(MacTimeout) * mac_timer_used);
|
|
|
|
MacTimeout* delete_me = mac_timers;
|
|
|
|
mac_timers = new_timers;
|
|
|
|
delete [] delete_me;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_timer(MacTimeout& t)
|
|
|
|
{
|
|
|
|
if (t.timer) {
|
2010-05-27 11:06:43 +04:00
|
|
|
CFRunLoopRemoveTimer(CFRunLoopGetCurrent(),
|
|
|
|
t.timer,
|
|
|
|
kCFRunLoopDefaultMode);
|
2010-05-27 00:04:00 +04:00
|
|
|
CFRelease(t.timer);
|
2009-12-07 01:21:55 +03:00
|
|
|
memset(&t, 0, sizeof(MacTimeout));
|
2012-06-16 12:49:52 +04:00
|
|
|
if (&t == current_timer) current_timer = NULL;
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-27 00:04:00 +04:00
|
|
|
static void do_timer(CFRunLoopTimerRef timer, void* data)
|
2009-12-07 01:21:55 +03:00
|
|
|
{
|
2013-11-13 19:49:48 +04:00
|
|
|
fl_lock_function();
|
2012-06-16 12:49:52 +04:00
|
|
|
current_timer = (MacTimeout*)data;
|
|
|
|
current_timer->pending = 0;
|
|
|
|
(current_timer->callback)(current_timer->data);
|
|
|
|
if (current_timer && current_timer->pending == 0)
|
|
|
|
delete_timer(*current_timer);
|
|
|
|
current_timer = NULL;
|
|
|
|
|
|
|
|
breakMacEventLoop();
|
2013-11-13 19:49:48 +04:00
|
|
|
fl_unlock_function();
|
2012-06-16 12:49:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Fl::add_timeout(double time, Fl_Timeout_Handler cb, void* data)
|
|
|
|
{
|
|
|
|
// check, if this timer slot exists already
|
|
|
|
for (int i = 0; i < mac_timer_used; ++i) {
|
2009-12-07 01:21:55 +03:00
|
|
|
MacTimeout& t = mac_timers[i];
|
2012-06-16 12:49:52 +04:00
|
|
|
// if so, simply change the fire interval
|
|
|
|
if (t.callback == cb && t.data == data) {
|
|
|
|
t.next_timeout = CFAbsoluteTimeGetCurrent() + time;
|
|
|
|
CFRunLoopTimerSetNextFireDate(t.timer, t.next_timeout );
|
|
|
|
t.pending = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// no existing timer to use. Create a new one:
|
|
|
|
int timer_id = -1;
|
|
|
|
// find an empty slot in the timer array
|
|
|
|
for (int i = 0; i < mac_timer_used; ++i) {
|
|
|
|
if ( !mac_timers[i].timer ) {
|
|
|
|
timer_id = i;
|
2009-12-07 01:21:55 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-06-16 12:49:52 +04:00
|
|
|
// if there was no empty slot, append a new timer
|
|
|
|
if (timer_id == -1) {
|
|
|
|
// make space if needed
|
|
|
|
if (mac_timer_used == mac_timer_alloc) {
|
|
|
|
realloc_timers();
|
|
|
|
}
|
|
|
|
timer_id = mac_timer_used++;
|
|
|
|
}
|
|
|
|
// now install a brand new timer
|
|
|
|
MacTimeout& t = mac_timers[timer_id];
|
|
|
|
CFRunLoopTimerContext context = {0, &t, NULL,NULL,NULL};
|
|
|
|
CFRunLoopTimerRef timerRef = CFRunLoopTimerCreate(kCFAllocatorDefault,
|
|
|
|
CFAbsoluteTimeGetCurrent() + time,
|
|
|
|
1E30,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
do_timer,
|
|
|
|
&context
|
|
|
|
);
|
|
|
|
if (timerRef) {
|
|
|
|
CFRunLoopAddTimer(CFRunLoopGetCurrent(),
|
|
|
|
timerRef,
|
|
|
|
kCFRunLoopDefaultMode);
|
|
|
|
t.callback = cb;
|
|
|
|
t.data = data;
|
|
|
|
t.timer = timerRef;
|
|
|
|
t.pending = 1;
|
|
|
|
t.next_timeout = CFRunLoopTimerGetNextFireDate(timerRef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fl::repeat_timeout(double time, Fl_Timeout_Handler cb, void* data)
|
|
|
|
{
|
|
|
|
if (current_timer) {
|
|
|
|
// k = how many times 'time' seconds after the last scheduled timeout until the future
|
|
|
|
double k = ceil( (CFAbsoluteTimeGetCurrent() - current_timer->next_timeout) / time);
|
|
|
|
if (k < 1) k = 1;
|
|
|
|
current_timer->next_timeout += k * time;
|
|
|
|
CFRunLoopTimerSetNextFireDate(current_timer->timer, current_timer->next_timeout );
|
|
|
|
current_timer->callback = cb;
|
|
|
|
current_timer->data = data;
|
|
|
|
current_timer->pending = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
add_timeout(time, cb, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Fl::has_timeout(Fl_Timeout_Handler cb, void* data)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < mac_timer_used; ++i) {
|
|
|
|
MacTimeout& t = mac_timers[i];
|
|
|
|
if (t.callback == cb && t.data == data && t.pending) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fl::remove_timeout(Fl_Timeout_Handler cb, void* data)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < mac_timer_used; ++i) {
|
|
|
|
MacTimeout& t = mac_timers[i];
|
|
|
|
if (t.callback == cb && ( t.data == data || data == NULL)) {
|
|
|
|
delete_timer(t);
|
|
|
|
}
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@interface FLWindow : NSWindow {
|
|
|
|
Fl_Window *w;
|
|
|
|
}
|
2009-12-21 21:43:13 +03:00
|
|
|
- (FLWindow*)initWithFl_W:(Fl_Window *)flw
|
|
|
|
contentRect:(NSRect)rect
|
2011-04-27 15:21:57 +04:00
|
|
|
styleMask:(NSUInteger)windowStyle;
|
2009-12-07 01:21:55 +03:00
|
|
|
- (Fl_Window *)getFl_Window;
|
2014-09-13 20:49:47 +04:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
|
|
|
- (NSPoint)convertBaseToScreen:(NSPoint)aPoint;
|
|
|
|
#endif
|
2009-12-07 01:21:55 +03:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation FLWindow
|
2014-09-13 20:49:47 +04:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
|
|
|
- (NSPoint)convertBaseToScreen:(NSPoint)aPoint
|
|
|
|
{
|
|
|
|
if (fl_mac_os_version >= 100700) {
|
|
|
|
NSRect r = [self convertRectToScreen:NSMakeRect(aPoint.x, aPoint.y, 0, 0)];
|
|
|
|
return r.origin;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// replaces return [super convertBaseToScreen:aPoint] that may trigger a compiler warning
|
|
|
|
typedef NSPoint (*convertIMP)(id, SEL, NSPoint);
|
|
|
|
convertIMP addr = (convertIMP)[NSWindow instanceMethodForSelector:@selector(convertBaseToScreen:)];
|
|
|
|
return addr(self, @selector(convertBaseToScreen:), aPoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-12-21 21:43:13 +03:00
|
|
|
- (FLWindow*)initWithFl_W:(Fl_Window *)flw
|
|
|
|
contentRect:(NSRect)rect
|
|
|
|
styleMask:(NSUInteger)windowStyle
|
|
|
|
{
|
2011-11-14 19:15:03 +04:00
|
|
|
self = [super initWithContentRect:rect styleMask:windowStyle backing:NSBackingStoreBuffered defer:NO];
|
2010-01-14 02:13:59 +03:00
|
|
|
if (self) {
|
2009-12-21 21:43:13 +03:00
|
|
|
w = flw;
|
2013-05-08 17:11:56 +04:00
|
|
|
if (fl_mac_os_version >= 100700) {
|
|
|
|
// replaces [self setRestorable:NO] that may trigger a compiler warning
|
|
|
|
typedef void (*setIMP)(id, SEL, BOOL);
|
|
|
|
setIMP addr = (setIMP)[self methodForSelector:@selector(setRestorable:)];
|
|
|
|
addr(self, @selector(setRestorable:), NO);
|
|
|
|
}
|
2010-01-14 02:13:59 +03:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
- (Fl_Window *)getFl_Window;
|
|
|
|
{
|
|
|
|
return w;
|
|
|
|
}
|
2012-04-28 04:42:31 +04:00
|
|
|
|
2012-03-22 17:58:38 +04:00
|
|
|
- (BOOL)canBecomeKeyWindow
|
|
|
|
{
|
2012-04-28 04:42:31 +04:00
|
|
|
if (Fl::modal_ && (Fl::modal_ != w))
|
|
|
|
return NO; // prevent the caption to be redrawn as active on click
|
|
|
|
// when another modal window is currently the key win
|
2014-11-11 19:08:09 +03:00
|
|
|
return !(w->tooltip_window() || w->menu_window() || w->parent());
|
2012-04-28 04:42:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)canBecomeMainWindow
|
|
|
|
{
|
|
|
|
if (Fl::modal_ && (Fl::modal_ != w))
|
|
|
|
return NO; // prevent the caption to be redrawn as active on click
|
|
|
|
// when another modal window is currently the key win
|
|
|
|
|
2014-11-11 19:08:09 +03:00
|
|
|
return !(w->tooltip_window() || w->menu_window() || w->parent());
|
2012-03-22 17:58:38 +04:00
|
|
|
}
|
2012-04-28 04:42:31 +04:00
|
|
|
|
2009-12-07 01:21:55 +03:00
|
|
|
@end
|
|
|
|
|
2011-03-30 00:26:51 +04:00
|
|
|
@interface FLApplication : NSObject
|
|
|
|
{
|
|
|
|
}
|
|
|
|
+ (void)sendEvent:(NSEvent *)theEvent;
|
|
|
|
@end
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2009-12-07 01:21:55 +03:00
|
|
|
* This function is the central event handler.
|
|
|
|
* It reads events from the event queue using the given maximum time
|
|
|
|
* Funny enough, it returns the same time that it got as the argument.
|
|
|
|
*/
|
|
|
|
static double do_queued_events( double time = 0.0 )
|
|
|
|
{
|
|
|
|
got_events = 0;
|
|
|
|
|
|
|
|
// Check for re-entrant condition
|
2010-01-14 02:13:59 +03:00
|
|
|
if ( dataready.IsThreadRunning() ) {
|
|
|
|
dataready.CancelThread(DEBUGTEXT("AVOID REENTRY\n"));
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
// Start thread to watch for data ready
|
2010-01-14 02:13:59 +03:00
|
|
|
if ( dataready.GetNfds() ) {
|
2010-03-26 19:04:06 +03:00
|
|
|
dataready.StartThread();
|
2010-01-14 02:13:59 +03:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
fl_unlock_function();
|
|
|
|
NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask
|
2009-12-09 02:15:30 +03:00
|
|
|
untilDate:[NSDate dateWithTimeIntervalSinceNow:time]
|
|
|
|
inMode:NSDefaultRunLoopMode dequeue:YES];
|
2010-01-14 02:13:59 +03:00
|
|
|
if (event != nil) {
|
2011-02-28 20:48:55 +03:00
|
|
|
got_events = 1;
|
2011-03-30 00:26:51 +04:00
|
|
|
[FLApplication sendEvent:event]; // will then call [NSApplication sendevent:]
|
2010-01-14 02:13:59 +03:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
fl_lock_function();
|
|
|
|
|
|
|
|
#if CONSOLIDATE_MOTION
|
|
|
|
if (send_motion && send_motion == fl_xmousewin) {
|
|
|
|
send_motion = 0;
|
|
|
|
Fl::handle(FL_MOVE, fl_xmousewin);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
2014-03-22 21:09:07 +04:00
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2009-12-07 01:21:55 +03:00
|
|
|
* This public function handles all events. It wait a maximum of
|
|
|
|
* 'time' seconds for an event. This version returns 1 if events
|
|
|
|
* other than the timeout timer were processed.
|
|
|
|
*
|
|
|
|
* \todo there is no socket handling in this code whatsoever
|
|
|
|
*/
|
|
|
|
int fl_wait( double time )
|
|
|
|
{
|
|
|
|
do_queued_events( time );
|
|
|
|
return (got_events);
|
|
|
|
}
|
|
|
|
|
2014-01-18 20:28:59 +04:00
|
|
|
double fl_mac_flush_and_wait(double time_to_wait) {
|
|
|
|
static int in_idle = 0;
|
2010-12-17 13:43:41 +03:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2014-01-18 20:28:59 +04:00
|
|
|
if (Fl::idle) {
|
|
|
|
if (!in_idle) {
|
|
|
|
in_idle = 1;
|
|
|
|
Fl::idle();
|
|
|
|
in_idle = 0;
|
|
|
|
}
|
|
|
|
// the idle function may turn off idle, we can then wait:
|
|
|
|
if (Fl::idle) time_to_wait = 0.0;
|
|
|
|
}
|
2010-12-17 13:43:41 +03:00
|
|
|
Fl::flush();
|
|
|
|
if (Fl::idle && !in_idle) // 'idle' may have been set within flush()
|
|
|
|
time_to_wait = 0.0;
|
|
|
|
double retval = fl_wait(time_to_wait);
|
2014-03-22 21:09:07 +04:00
|
|
|
if (fl_gc) {
|
2014-11-19 19:23:36 +03:00
|
|
|
Fl_X::q_release_context();
|
|
|
|
}
|
2010-12-17 13:43:41 +03:00
|
|
|
[pool release];
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
|
2014-06-16 14:59:46 +04:00
|
|
|
static NSInteger max_normal_window_level(void)
|
|
|
|
{
|
|
|
|
Fl_X *x;
|
|
|
|
NSInteger max_level;
|
|
|
|
|
|
|
|
max_level = 0;
|
|
|
|
|
|
|
|
for (x = Fl_X::first;x;x = x->next) {
|
|
|
|
NSInteger level;
|
|
|
|
FLWindow *cw = x->xid;
|
|
|
|
Fl_Window *win = x->w;
|
|
|
|
if (!win || !cw || ![cw isVisible])
|
|
|
|
continue;
|
|
|
|
if (win->modal() || win->non_modal())
|
|
|
|
continue;
|
|
|
|
level = [cw level];
|
|
|
|
if (level >= max_level)
|
|
|
|
max_level = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
return max_level;
|
|
|
|
}
|
|
|
|
|
|
|
|
// appropriate window level for modal windows
|
|
|
|
static NSInteger modal_window_level(void)
|
|
|
|
{
|
|
|
|
NSInteger level;
|
|
|
|
|
|
|
|
level = max_normal_window_level();
|
|
|
|
if (level < NSModalPanelWindowLevel)
|
|
|
|
return NSModalPanelWindowLevel;
|
|
|
|
|
|
|
|
// Need some room for non-modal windows
|
|
|
|
level += 2;
|
|
|
|
|
|
|
|
// We cannot exceed this
|
|
|
|
if (level > CGShieldingWindowLevel())
|
|
|
|
return CGShieldingWindowLevel();
|
|
|
|
|
|
|
|
return level;
|
|
|
|
}
|
|
|
|
|
|
|
|
// appropriate window level for non-modal windows
|
|
|
|
static NSInteger non_modal_window_level(void)
|
|
|
|
{
|
|
|
|
NSInteger level;
|
|
|
|
|
|
|
|
level = max_normal_window_level();
|
|
|
|
if (level < NSFloatingWindowLevel)
|
|
|
|
return NSFloatingWindowLevel;
|
|
|
|
|
|
|
|
level += 1;
|
|
|
|
|
|
|
|
if (level > CGShieldingWindowLevel())
|
|
|
|
return CGShieldingWindowLevel();
|
|
|
|
|
|
|
|
return level;
|
|
|
|
}
|
|
|
|
|
|
|
|
// makes sure modal and non-modal windows stay on top
|
|
|
|
static void fixup_window_levels(void)
|
|
|
|
{
|
|
|
|
NSInteger modal_level, non_modal_level;
|
|
|
|
|
|
|
|
Fl_X *x;
|
|
|
|
FLWindow *prev_modal, *prev_non_modal;
|
|
|
|
|
|
|
|
modal_level = modal_window_level();
|
|
|
|
non_modal_level = non_modal_window_level();
|
|
|
|
|
|
|
|
prev_modal = NULL;
|
|
|
|
prev_non_modal = NULL;
|
|
|
|
|
|
|
|
for (x = Fl_X::first;x;x = x->next) {
|
|
|
|
FLWindow *cw = x->xid;
|
|
|
|
Fl_Window *win = x->w;
|
|
|
|
if (!win || !cw || ![cw isVisible])
|
|
|
|
continue;
|
|
|
|
if (win->modal()) {
|
|
|
|
if ([cw level] != modal_level) {
|
|
|
|
[cw setLevel:modal_level];
|
|
|
|
// changing level puts then in front, so make sure the
|
|
|
|
// stacking isn't messed up
|
|
|
|
if (prev_modal != NULL)
|
|
|
|
[cw orderWindow:NSWindowBelow
|
|
|
|
relativeTo:[prev_modal windowNumber]];
|
|
|
|
}
|
|
|
|
prev_modal = cw;
|
|
|
|
} else if (win->non_modal()) {
|
|
|
|
if ([cw level] != non_modal_level) {
|
|
|
|
[cw setLevel:non_modal_level];
|
|
|
|
if (prev_non_modal != NULL)
|
|
|
|
[cw orderWindow:NSWindowBelow
|
|
|
|
relativeTo:[prev_non_modal windowNumber]];
|
|
|
|
}
|
|
|
|
prev_non_modal = cw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-01 20:41:32 +03:00
|
|
|
// updates Fl::e_x, Fl::e_y, Fl::e_x_root, and Fl::e_y_root
|
|
|
|
static void update_e_xy_and_e_xy_root(NSWindow *nsw)
|
|
|
|
{
|
|
|
|
NSPoint pt;
|
|
|
|
pt = [nsw mouseLocationOutsideOfEventStream];
|
2010-11-15 07:34:58 +03:00
|
|
|
Fl::e_x = int(pt.x);
|
|
|
|
Fl::e_y = int([[nsw contentView] frame].size.height - pt.y);
|
2010-02-01 20:41:32 +03:00
|
|
|
pt = [NSEvent mouseLocation];
|
2010-11-15 07:34:58 +03:00
|
|
|
Fl::e_x_root = int(pt.x);
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
Fl::e_y_root = int(main_screen_height - pt.y);
|
2010-02-01 20:41:32 +03:00
|
|
|
}
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2009-12-07 01:21:55 +03:00
|
|
|
* Cocoa Mousewheel handler
|
|
|
|
*/
|
2010-12-19 01:31:01 +03:00
|
|
|
static void cocoaMouseWheelHandler(NSEvent *theEvent)
|
2009-12-07 01:21:55 +03:00
|
|
|
{
|
|
|
|
// Handle the new "MightyMouse" mouse wheel events. Please, someone explain
|
|
|
|
// to me why Apple changed the API on this even though the current API
|
|
|
|
// supports two wheels just fine. Matthias,
|
|
|
|
fl_lock_function();
|
|
|
|
|
|
|
|
Fl_Window *window = (Fl_Window*)[(FLWindow*)[theEvent window] getFl_Window];
|
2010-01-14 02:13:59 +03:00
|
|
|
if ( !window->shown() ) {
|
2009-12-07 01:21:55 +03:00
|
|
|
fl_unlock_function();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Fl::first_window(window);
|
|
|
|
|
2010-03-04 20:17:04 +03:00
|
|
|
// Under OSX, single mousewheel increments are 0.1,
|
|
|
|
// so make sure they show up as at least 1..
|
|
|
|
//
|
|
|
|
float dx = [theEvent deltaX]; if ( fabs(dx) < 1.0 ) dx = (dx > 0) ? 1.0 : -1.0;
|
|
|
|
float dy = [theEvent deltaY]; if ( fabs(dy) < 1.0 ) dy = (dy > 0) ? 1.0 : -1.0;
|
2010-01-14 02:13:59 +03:00
|
|
|
if ([theEvent deltaX] != 0) {
|
2010-03-04 20:17:04 +03:00
|
|
|
Fl::e_dx = (int)-dx;
|
2009-12-07 01:21:55 +03:00
|
|
|
Fl::e_dy = 0;
|
|
|
|
if ( Fl::e_dx) Fl::handle( FL_MOUSEWHEEL, window );
|
2010-01-14 02:13:59 +03:00
|
|
|
} else if ([theEvent deltaY] != 0) {
|
2009-12-07 01:21:55 +03:00
|
|
|
Fl::e_dx = 0;
|
2010-03-04 20:17:04 +03:00
|
|
|
Fl::e_dy = (int)-dy;
|
2009-12-07 01:21:55 +03:00
|
|
|
if ( Fl::e_dy) Fl::handle( FL_MOUSEWHEEL, window );
|
|
|
|
} else {
|
|
|
|
fl_unlock_function();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fl_unlock_function();
|
|
|
|
|
|
|
|
// return noErr;
|
|
|
|
}
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2009-12-07 01:21:55 +03:00
|
|
|
* Cocoa Mouse Button Handler
|
|
|
|
*/
|
|
|
|
static void cocoaMouseHandler(NSEvent *theEvent)
|
|
|
|
{
|
|
|
|
static int keysym[] = { 0, FL_Button+1, FL_Button+3, FL_Button+2 };
|
|
|
|
static int px, py;
|
|
|
|
static char suppressed = 0;
|
|
|
|
|
|
|
|
fl_lock_function();
|
|
|
|
|
|
|
|
Fl_Window *window = (Fl_Window*)[(FLWindow*)[theEvent window] getFl_Window];
|
2010-01-14 02:13:59 +03:00
|
|
|
if ( !window->shown() ) {
|
2009-12-07 01:21:55 +03:00
|
|
|
fl_unlock_function();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Fl_Window *first = Fl::first_window();
|
2010-01-14 02:13:59 +03:00
|
|
|
if (first != window && !(first->modal() || first->non_modal())) Fl::first_window(window);
|
2009-12-07 01:21:55 +03:00
|
|
|
NSPoint pos = [theEvent locationInWindow];
|
|
|
|
pos.y = window->h() - pos.y;
|
|
|
|
NSInteger btn = [theEvent buttonNumber] + 1;
|
|
|
|
NSUInteger mods = [theEvent modifierFlags];
|
|
|
|
int sendEvent = 0;
|
|
|
|
|
2010-01-24 13:27:21 +03:00
|
|
|
NSEventType etype = [theEvent type];
|
|
|
|
if (etype == NSLeftMouseDown || etype == NSRightMouseDown || etype == NSOtherMouseDown) {
|
|
|
|
if (btn == 1) Fl::e_state |= FL_BUTTON1;
|
|
|
|
else if (btn == 3) Fl::e_state |= FL_BUTTON2;
|
|
|
|
else if (btn == 2) Fl::e_state |= FL_BUTTON3;
|
|
|
|
}
|
|
|
|
else if (etype == NSLeftMouseUp || etype == NSRightMouseUp || etype == NSOtherMouseUp) {
|
|
|
|
if (btn == 1) Fl::e_state &= ~FL_BUTTON1;
|
|
|
|
else if (btn == 3) Fl::e_state &= ~FL_BUTTON2;
|
|
|
|
else if (btn == 2) Fl::e_state &= ~FL_BUTTON3;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( etype ) {
|
2010-01-14 02:13:59 +03:00
|
|
|
case NSLeftMouseDown:
|
|
|
|
case NSRightMouseDown:
|
|
|
|
case NSOtherMouseDown:
|
2009-12-07 01:21:55 +03:00
|
|
|
suppressed = 0;
|
|
|
|
sendEvent = FL_PUSH;
|
|
|
|
Fl::e_is_click = 1;
|
2010-01-14 02:13:59 +03:00
|
|
|
px = (int)pos.x; py = (int)pos.y;
|
2010-11-08 11:10:48 +03:00
|
|
|
if ([theEvent clickCount] > 1)
|
2009-12-07 01:21:55 +03:00
|
|
|
Fl::e_clicks++;
|
|
|
|
else
|
|
|
|
Fl::e_clicks = 0;
|
|
|
|
// fall through
|
2010-01-14 02:13:59 +03:00
|
|
|
case NSLeftMouseUp:
|
|
|
|
case NSRightMouseUp:
|
|
|
|
case NSOtherMouseUp:
|
2009-12-07 01:21:55 +03:00
|
|
|
if (suppressed) {
|
|
|
|
suppressed = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ( !window ) break;
|
|
|
|
if ( !sendEvent ) {
|
|
|
|
sendEvent = FL_RELEASE;
|
|
|
|
}
|
|
|
|
Fl::e_keysym = keysym[ btn ];
|
|
|
|
// fall through
|
2010-01-14 02:13:59 +03:00
|
|
|
case NSMouseMoved:
|
2009-12-07 01:21:55 +03:00
|
|
|
suppressed = 0;
|
|
|
|
if ( !sendEvent ) {
|
|
|
|
sendEvent = FL_MOVE;
|
|
|
|
}
|
|
|
|
// fall through
|
2010-01-14 02:13:59 +03:00
|
|
|
case NSLeftMouseDragged:
|
|
|
|
case NSRightMouseDragged:
|
|
|
|
case NSOtherMouseDragged: {
|
2009-12-07 01:21:55 +03:00
|
|
|
if (suppressed) break;
|
|
|
|
if ( !sendEvent ) {
|
|
|
|
sendEvent = FL_MOVE; // Fl::handle will convert into FL_DRAG
|
2010-01-14 02:13:59 +03:00
|
|
|
if (fabs(pos.x-px)>5 || fabs(pos.y-py)>5)
|
2009-12-07 01:21:55 +03:00
|
|
|
Fl::e_is_click = 0;
|
|
|
|
}
|
|
|
|
mods_to_e_state( mods );
|
2010-02-01 20:41:32 +03:00
|
|
|
update_e_xy_and_e_xy_root([theEvent window]);
|
2009-12-07 01:21:55 +03:00
|
|
|
Fl::handle( sendEvent, window );
|
2010-01-14 02:13:59 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fl_unlock_function();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-17 21:40:53 +04:00
|
|
|
@interface FLTextView : NSTextView // this subclass is only needed under OS X < 10.6
|
2009-12-07 01:21:55 +03:00
|
|
|
{
|
2013-01-17 21:40:53 +04:00
|
|
|
BOOL isActive;
|
2010-11-06 18:06:25 +03:00
|
|
|
}
|
2014-11-06 18:35:32 +03:00
|
|
|
+ (void)initialize;
|
|
|
|
+ (FLTextView*)singleInstance;
|
2013-01-17 21:40:53 +04:00
|
|
|
- (void)insertText:(id)aString;
|
|
|
|
- (void)doCommandBySelector:(SEL)aSelector;
|
|
|
|
- (void)setActive:(BOOL)a;
|
2010-11-06 18:06:25 +03:00
|
|
|
@end
|
2014-11-06 18:35:32 +03:00
|
|
|
static FLTextView *fltextview_instance = nil;
|
2010-11-06 18:06:25 +03:00
|
|
|
@implementation FLTextView
|
2014-11-06 18:35:32 +03:00
|
|
|
+ (void)initialize {
|
|
|
|
NSRect rect={{0,0},{20,20}};
|
|
|
|
fltextview_instance = [[FLTextView alloc] initWithFrame:rect];
|
|
|
|
}
|
|
|
|
+ (FLTextView*)singleInstance {
|
|
|
|
return fltextview_instance;
|
|
|
|
}
|
2010-11-06 18:06:25 +03:00
|
|
|
- (void)insertText:(id)aString
|
|
|
|
{
|
2013-01-17 21:40:53 +04:00
|
|
|
if (isActive) [[[NSApp keyWindow] contentView] insertText:aString];
|
2010-11-06 18:06:25 +03:00
|
|
|
}
|
|
|
|
- (void)doCommandBySelector:(SEL)aSelector
|
|
|
|
{
|
2011-04-27 15:21:57 +04:00
|
|
|
[[[NSApp keyWindow] contentView] doCommandBySelector:aSelector];
|
2010-11-06 18:06:25 +03:00
|
|
|
}
|
2013-01-17 21:40:53 +04:00
|
|
|
- (void)setActive:(BOOL)a
|
2009-12-07 01:21:55 +03:00
|
|
|
{
|
2013-01-17 21:40:53 +04:00
|
|
|
isActive = a;
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2013-01-17 21:40:53 +04:00
|
|
|
@end
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
|
2013-01-07 19:56:14 +04:00
|
|
|
@interface FLWindowDelegate : NSObject
|
2009-12-09 02:15:30 +03:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
|
2013-01-07 19:56:14 +04:00
|
|
|
<NSWindowDelegate>
|
2009-12-09 02:15:30 +03:00
|
|
|
#endif
|
2014-11-06 18:35:32 +03:00
|
|
|
+ (void)initialize;
|
|
|
|
+ (FLWindowDelegate*)singleInstance;
|
2009-12-07 01:21:55 +03:00
|
|
|
- (void)windowDidMove:(NSNotification *)notif;
|
|
|
|
- (void)windowDidResize:(NSNotification *)notif;
|
2011-03-24 15:58:32 +03:00
|
|
|
- (void)windowDidResignKey:(NSNotification *)notif;
|
2009-12-07 01:21:55 +03:00
|
|
|
- (void)windowDidBecomeKey:(NSNotification *)notif;
|
|
|
|
- (void)windowDidBecomeMain:(NSNotification *)notif;
|
2014-11-11 19:08:09 +03:00
|
|
|
- (void)windowWillMiniaturize:(NSNotification *)notif;
|
2009-12-07 01:21:55 +03:00
|
|
|
- (void)windowDidDeminiaturize:(NSNotification *)notif;
|
|
|
|
- (void)windowDidMiniaturize:(NSNotification *)notif;
|
2011-11-23 13:19:39 +04:00
|
|
|
- (BOOL)windowShouldClose:(id)fl;
|
2013-01-07 19:56:14 +04:00
|
|
|
- (void)anyWindowWillClose:(NSNotification *)notif;
|
2009-12-07 01:21:55 +03:00
|
|
|
@end
|
2014-11-06 18:35:32 +03:00
|
|
|
|
2014-11-11 19:08:09 +03:00
|
|
|
/* recursively set Cocoa's position and size of subwindows from their FLTK coords
|
|
|
|
*/
|
|
|
|
static void position_subwindows(Fl_Window *parent, BOOL is_a_move)
|
|
|
|
{
|
|
|
|
FLWindow *xid = fl_xid(parent);
|
|
|
|
NSArray *children = [xid childWindows]; // 10.2
|
|
|
|
NSEnumerator *enumerator = [children objectEnumerator];
|
|
|
|
id child;
|
|
|
|
NSRect pframe = [xid frame];
|
|
|
|
while ((child = [enumerator nextObject]) != nil) {
|
|
|
|
NSRect rchild;
|
|
|
|
Fl_Window *sub = [child getFl_Window];
|
2014-12-17 12:04:01 +03:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
Fl_X *subx = Fl_X::i(sub);
|
|
|
|
bool previous = subx->mapped_to_retina();
|
|
|
|
subx->mapped_to_retina( Fl_X::i(parent)->mapped_to_retina() );
|
|
|
|
if (previous != subx->mapped_to_retina()) subx->changed_resolution(true);
|
2014-12-17 12:04:01 +03:00
|
|
|
#endif
|
2014-11-11 19:08:09 +03:00
|
|
|
rchild.origin = NSMakePoint(pframe.origin.x + sub->x(), pframe.origin.y + parent->h() - (sub->h() + sub->y()));
|
|
|
|
rchild.size = NSMakeSize(sub->w(), sub->h());
|
|
|
|
[child setFrame:rchild display:YES];
|
|
|
|
position_subwindows(sub, is_a_move);
|
|
|
|
if (is_a_move && fl_mac_os_version < 100700) { // after move, redraw parent and children of GL windows
|
|
|
|
if (parent->as_gl_window()) [child display];
|
|
|
|
if (sub->as_gl_window()) [xid display];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make subwindows re-appear after appl unhide or window deminiaturize
|
|
|
|
(not necessary with 10.5 and above)
|
|
|
|
*/
|
|
|
|
static void orderfront_subwindows(FLWindow *xid)
|
|
|
|
{
|
|
|
|
NSArray *children = [xid childWindows]; // 10.2
|
|
|
|
NSEnumerator *enumerator = [children objectEnumerator];
|
|
|
|
id child;
|
|
|
|
while ((child = [enumerator nextObject]) != nil) { // this undo-redo seems necessary under 10.3
|
|
|
|
[xid removeChildWindow:child];
|
|
|
|
[xid addChildWindow:child ordered:NSWindowAbove];
|
|
|
|
[child orderWindow:NSWindowAbove relativeTo:[xid windowNumber]];
|
|
|
|
orderfront_subwindows(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-17 12:04:01 +03:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
|
|
|
//determines whether the (top-level) window is mapped to a retina display
|
2014-12-12 01:25:31 +03:00
|
|
|
static void compute_mapped_to_retina(Fl_Window *window)
|
|
|
|
{
|
|
|
|
if (fl_mac_os_version >= 100700) { // determine whether window is now mapped to a retina display
|
2014-12-17 12:04:01 +03:00
|
|
|
Fl_X *flx = Fl_X::i(window);
|
|
|
|
bool previous = flx->mapped_to_retina();
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
NSSize s = [[flx->xid contentView] convertSizeToBacking:NSMakeSize(10, 10)];
|
2014-12-17 12:04:01 +03:00
|
|
|
flx->mapped_to_retina( int(s.width + 0.5) > 10 );
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
if (previous != flx->mapped_to_retina()) flx->changed_resolution(true);
|
2014-12-12 01:25:31 +03:00
|
|
|
// window needs redrawn when moving from low res to retina
|
2014-12-17 12:04:01 +03:00
|
|
|
if ((!previous) && flx->mapped_to_retina()) {
|
|
|
|
window->redraw();
|
|
|
|
}
|
2014-12-12 01:25:31 +03:00
|
|
|
}
|
2014-12-17 12:04:01 +03:00
|
|
|
}
|
|
|
|
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
#if FLTK_ABI_VERSION >= 10304
|
|
|
|
static const unsigned mapped_mask = 1;
|
|
|
|
static const unsigned changed_mask = 2;
|
|
|
|
#else
|
|
|
|
static const unsigned long mapped_mask = 1; // sizeof(unsigned long) = sizeof(Fl_X*)
|
|
|
|
static const unsigned long changed_mask = 2;
|
|
|
|
#endif
|
|
|
|
|
2014-12-17 12:04:01 +03:00
|
|
|
bool Fl_X::mapped_to_retina() {
|
|
|
|
#if FLTK_ABI_VERSION >= 10304
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
return mapped_to_retina_ & mapped_mask;
|
2014-12-17 12:04:01 +03:00
|
|
|
#else
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
return (unsigned long)xidChildren & mapped_mask;
|
2014-12-17 12:04:01 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fl_X::mapped_to_retina(bool b) {
|
|
|
|
#if FLTK_ABI_VERSION >= 10304
|
2014-12-21 21:03:03 +03:00
|
|
|
if (b) mapped_to_retina_ |= mapped_mask;
|
|
|
|
else mapped_to_retina_ &= ~mapped_mask;
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
#else
|
|
|
|
if (b) xidChildren = (Fl_X*)((unsigned long)xidChildren | mapped_mask);
|
|
|
|
else xidChildren = (Fl_X*)((unsigned long)xidChildren & ~mapped_mask);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Fl_X::changed_resolution() {
|
|
|
|
#if FLTK_ABI_VERSION >= 10304
|
|
|
|
return mapped_to_retina_ & changed_mask;
|
2014-12-17 12:04:01 +03:00
|
|
|
#else
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
return (unsigned long)xidChildren & changed_mask;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fl_X::changed_resolution(bool b) {
|
|
|
|
#if FLTK_ABI_VERSION >= 10304
|
|
|
|
if (b) mapped_to_retina_ |= changed_mask;
|
|
|
|
else mapped_to_retina_ &= ~changed_mask;
|
|
|
|
#else
|
|
|
|
if (b) xidChildren = (Fl_X*)((unsigned long)xidChildren | changed_mask);
|
|
|
|
else xidChildren = (Fl_X*)((unsigned long)xidChildren & ~changed_mask);
|
2014-12-12 01:25:31 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-12-17 12:04:01 +03:00
|
|
|
#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
|
|
|
|
2014-11-06 18:35:32 +03:00
|
|
|
@interface FLWindowDelegateBefore10_6 : FLWindowDelegate
|
|
|
|
- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)client;
|
|
|
|
@end
|
|
|
|
@implementation FLWindowDelegateBefore10_6
|
|
|
|
- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)client
|
|
|
|
{
|
|
|
|
return [FLTextView singleInstance];
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2014-11-11 19:08:09 +03:00
|
|
|
@interface FLWindowDelegateBefore10_5 : FLWindowDelegateBefore10_6
|
|
|
|
-(void)windowDidDeminiaturize:(NSNotification *)notif;
|
|
|
|
-(void)windowWillMiniaturize:(NSNotification *)notif;
|
|
|
|
@end
|
|
|
|
@implementation FLWindowDelegateBefore10_5
|
|
|
|
-(void)windowDidDeminiaturize:(NSNotification *)notif
|
|
|
|
{
|
|
|
|
[super windowDidDeminiaturize:notif];
|
|
|
|
fl_lock_function();
|
|
|
|
orderfront_subwindows([notif object]);
|
|
|
|
fl_unlock_function();
|
|
|
|
}
|
|
|
|
-(void)windowWillMiniaturize:(NSNotification *)notif
|
|
|
|
{
|
|
|
|
[super windowWillMiniaturize:notif];
|
|
|
|
NSArray *children = [(NSWindow*)[notif object] childWindows]; // 10.2
|
|
|
|
NSEnumerator *enumerator = [children objectEnumerator];
|
|
|
|
id child;
|
|
|
|
while ((child = [enumerator nextObject]) != nil) [child orderOut:self];
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2014-11-06 18:35:32 +03:00
|
|
|
static FLWindowDelegate *flwindowdelegate_instance = nil;
|
2013-01-07 19:56:14 +04:00
|
|
|
@implementation FLWindowDelegate
|
2014-11-06 18:35:32 +03:00
|
|
|
+ (void)initialize
|
2013-01-07 19:56:14 +04:00
|
|
|
{
|
2014-11-06 18:35:32 +03:00
|
|
|
if (self == [FLWindowDelegate self]) {
|
2014-11-11 19:08:09 +03:00
|
|
|
if (fl_mac_os_version < 100500) flwindowdelegate_instance = [FLWindowDelegateBefore10_5 alloc];
|
|
|
|
else if (fl_mac_os_version < 100600) flwindowdelegate_instance = [FLWindowDelegateBefore10_6 alloc];
|
2014-11-06 18:35:32 +03:00
|
|
|
else flwindowdelegate_instance = [FLWindowDelegate alloc];
|
|
|
|
flwindowdelegate_instance = [flwindowdelegate_instance init];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+ (FLWindowDelegate*)singleInstance {
|
|
|
|
return flwindowdelegate_instance;
|
2013-01-07 19:56:14 +04:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
- (void)windowDidMove:(NSNotification *)notif
|
|
|
|
{
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
FLWindow *nsw = (FLWindow*)[notif object];
|
|
|
|
Fl_Window *window = [nsw getFl_Window];
|
2014-11-11 19:08:09 +03:00
|
|
|
if (!window->parent()) {
|
|
|
|
NSPoint pt2;
|
|
|
|
pt2 = [nsw convertBaseToScreen:NSMakePoint(0, [[nsw contentView] frame].size.height)];
|
|
|
|
update_e_xy_and_e_xy_root(nsw);
|
|
|
|
resize_from_system = NULL;
|
|
|
|
window->position((int)pt2.x, (int)(main_screen_height - pt2.y));
|
2014-12-18 20:32:08 +03:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
2014-12-12 01:25:31 +03:00
|
|
|
compute_mapped_to_retina(window);
|
2014-12-18 20:32:08 +03:00
|
|
|
#endif
|
2014-12-11 23:09:55 +03:00
|
|
|
position_subwindows(window, YES);
|
2014-11-11 19:08:09 +03:00
|
|
|
}
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
- (void)windowDidResize:(NSNotification *)notif
|
|
|
|
{
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
FLWindow *nsw = (FLWindow*)[notif object];
|
|
|
|
Fl_Window *window = [nsw getFl_Window];
|
2014-11-11 19:08:09 +03:00
|
|
|
NSRect r; NSPoint pt2;
|
|
|
|
if (!window->parent()) {
|
|
|
|
r = [[nsw contentView] frame];
|
|
|
|
pt2 = [nsw convertBaseToScreen:NSMakePoint(0, [[nsw contentView] frame].size.height)];
|
|
|
|
pt2.y = main_screen_height - pt2.y;
|
|
|
|
resize_from_system = window;
|
|
|
|
update_e_xy_and_e_xy_root(nsw);
|
|
|
|
window->resize((int)pt2.x, (int)pt2.y, (int)r.size.width, (int)r.size.height);
|
|
|
|
position_subwindows(window, NO);
|
|
|
|
}
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2011-03-24 15:58:32 +03:00
|
|
|
- (void)windowDidResignKey:(NSNotification *)notif
|
|
|
|
{
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2011-03-24 15:58:32 +03:00
|
|
|
FLWindow *nsw = (FLWindow*)[notif object];
|
|
|
|
Fl_Window *window = [nsw getFl_Window];
|
2012-03-23 20:47:53 +04:00
|
|
|
/* Fullscreen windows obscure all other windows so we need to return
|
2013-01-07 19:56:14 +04:00
|
|
|
to a "normal" level when the user switches to another window */
|
2014-06-16 14:59:46 +04:00
|
|
|
if (window->fullscreen_active()) {
|
2012-03-23 20:47:53 +04:00
|
|
|
[nsw setLevel:NSNormalWindowLevel];
|
2014-06-16 14:59:46 +04:00
|
|
|
fixup_window_levels();
|
|
|
|
}
|
2011-03-24 15:58:32 +03:00
|
|
|
Fl::handle( FL_UNFOCUS, window);
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2011-03-24 15:58:32 +03:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
- (void)windowDidBecomeKey:(NSNotification *)notif
|
|
|
|
{
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
FLWindow *nsw = (FLWindow*)[notif object];
|
2011-04-18 12:18:16 +04:00
|
|
|
Fl_Window *w = [nsw getFl_Window];
|
2012-03-23 20:47:53 +04:00
|
|
|
/* Restore previous fullscreen level */
|
2014-06-16 14:59:46 +04:00
|
|
|
if (w->fullscreen_active()) {
|
2012-03-23 20:47:53 +04:00
|
|
|
[nsw setLevel:NSStatusWindowLevel];
|
2014-06-16 14:59:46 +04:00
|
|
|
fixup_window_levels();
|
|
|
|
}
|
2014-11-11 19:08:09 +03:00
|
|
|
Fl::handle( FL_FOCUS, w);
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
- (void)windowDidBecomeMain:(NSNotification *)notif
|
|
|
|
{
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
FLWindow *nsw = (FLWindow*)[notif object];
|
|
|
|
Fl_Window *window = [nsw getFl_Window];
|
|
|
|
Fl::first_window(window);
|
2010-02-01 20:41:32 +03:00
|
|
|
update_e_xy_and_e_xy_root(nsw);
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
- (void)windowDidDeminiaturize:(NSNotification *)notif
|
|
|
|
{
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
FLWindow *nsw = (FLWindow*)[notif object];
|
|
|
|
Fl_Window *window = [nsw getFl_Window];
|
2011-04-13 13:03:19 +04:00
|
|
|
Fl::handle(FL_SHOW, window);
|
2010-02-01 20:41:32 +03:00
|
|
|
update_e_xy_and_e_xy_root(nsw);
|
2014-12-19 07:53:01 +03:00
|
|
|
Fl::flush(); // process redraws set by FL_SHOW
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2014-11-11 19:08:09 +03:00
|
|
|
- (void)windowWillMiniaturize:(NSNotification *)notif
|
|
|
|
{
|
|
|
|
// subwindows are not captured in system-built miniature window image
|
|
|
|
fl_lock_function();
|
|
|
|
FLWindow *nsw = (FLWindow*)[notif object];
|
|
|
|
if ([nsw childWindows]) {
|
|
|
|
// capture the window and its subwindows and use as miniature window image
|
|
|
|
Fl_Window *window = [nsw getFl_Window];
|
|
|
|
NSBitmapImageRep *bitmap = rect_to_NSBitmapImageRep(window, 0, 0, window->w(), window->h());
|
|
|
|
NSImage *img = [[[NSImage alloc] initWithSize:NSMakeSize([bitmap pixelsWide], [bitmap pixelsHigh])] autorelease];
|
|
|
|
[img addRepresentation:bitmap];
|
|
|
|
[bitmap release];
|
|
|
|
[nsw setMiniwindowImage:img];
|
|
|
|
}
|
|
|
|
fl_unlock_function();
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
- (void)windowDidMiniaturize:(NSNotification *)notif
|
|
|
|
{
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
FLWindow *nsw = (FLWindow*)[notif object];
|
|
|
|
Fl_Window *window = [nsw getFl_Window];
|
2011-04-13 13:03:19 +04:00
|
|
|
Fl::handle(FL_HIDE, window);
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2011-11-23 13:19:39 +04:00
|
|
|
- (BOOL)windowShouldClose:(id)fl
|
|
|
|
{
|
|
|
|
fl_lock_function();
|
|
|
|
Fl::handle( FL_CLOSE, [(FLWindow *)fl getFl_Window] ); // this might or might not close the window
|
|
|
|
fl_unlock_function();
|
|
|
|
// the system doesn't need to send [fl close] because FLTK does it when needed
|
|
|
|
return NO;
|
|
|
|
}
|
2011-10-30 21:23:42 +04:00
|
|
|
- (void)anyWindowWillClose:(NSNotification *)notif
|
2009-12-07 01:21:55 +03:00
|
|
|
{
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2011-10-27 23:41:54 +04:00
|
|
|
if ([[notif object] isKeyWindow]) {
|
|
|
|
// If the closing window is the key window,
|
|
|
|
// find a bordered top-level window to become the new key window
|
|
|
|
Fl_Window *w = Fl::first_window();
|
|
|
|
while (w && (w->parent() || !w->border() || !w->visible())) {
|
|
|
|
w = Fl::next_window(w);
|
2013-01-07 19:56:14 +04:00
|
|
|
}
|
2011-10-27 23:41:54 +04:00
|
|
|
if (w) {
|
2011-11-12 17:06:54 +04:00
|
|
|
[Fl_X::i(w)->xid makeKeyWindow];
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
}
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2013-01-07 19:56:14 +04:00
|
|
|
@end
|
|
|
|
|
|
|
|
@interface FLAppDelegate : NSObject
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
|
|
|
|
<NSApplicationDelegate>
|
|
|
|
#endif
|
|
|
|
{
|
2013-04-15 15:00:24 +04:00
|
|
|
void (*open_cb)(const char*);
|
2014-11-19 21:20:41 +03:00
|
|
|
@public
|
2014-09-15 13:44:35 +04:00
|
|
|
TSMDocumentID currentDoc;
|
2013-01-07 19:56:14 +04:00
|
|
|
}
|
|
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender;
|
|
|
|
- (void)applicationDidBecomeActive:(NSNotification *)notify;
|
|
|
|
- (void)applicationDidChangeScreenParameters:(NSNotification *)aNotification;
|
2014-09-15 13:44:35 +04:00
|
|
|
- (void)applicationDidUpdate:(NSNotification *)aNotification;
|
2013-01-07 19:56:14 +04:00
|
|
|
- (void)applicationWillResignActive:(NSNotification *)notify;
|
|
|
|
- (void)applicationWillHide:(NSNotification *)notify;
|
|
|
|
- (void)applicationWillUnhide:(NSNotification *)notify;
|
|
|
|
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
|
2013-04-15 15:00:24 +04:00
|
|
|
- (void)open_cb:(void (*)(const char*))cb;
|
2013-01-07 19:56:14 +04:00
|
|
|
@end
|
|
|
|
@implementation FLAppDelegate
|
2009-12-07 01:21:55 +03:00
|
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender
|
|
|
|
{
|
|
|
|
fl_lock_function();
|
|
|
|
NSApplicationTerminateReply reply = NSTerminateNow;
|
|
|
|
while ( Fl_X::first ) {
|
2014-11-16 00:59:41 +03:00
|
|
|
Fl_Window *win = Fl::first_window();
|
|
|
|
if (win->parent()) win = win->top_window();
|
|
|
|
Fl_Widget_Tracker wt(win); // track the window object
|
|
|
|
Fl::handle(FL_CLOSE, win);
|
|
|
|
if (wt.exists() && win->shown()) { // the user didn't close win
|
|
|
|
reply = NSTerminateCancel; // so we return to the main program now
|
2009-12-07 01:21:55 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fl_unlock_function();
|
|
|
|
return reply;
|
|
|
|
}
|
2010-02-19 23:21:20 +03:00
|
|
|
- (void)applicationDidBecomeActive:(NSNotification *)notify
|
|
|
|
{
|
2013-09-11 16:54:40 +04:00
|
|
|
fl_lock_function();
|
|
|
|
|
|
|
|
// update clipboard status
|
|
|
|
clipboard_check();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cocoa organizes the Z depth of windows on a global priority. FLTK however
|
|
|
|
* expects the window manager to organize Z level by application. The trickery
|
|
|
|
* below will change Z order during activation and deactivation.
|
|
|
|
*/
|
2014-06-16 14:59:46 +04:00
|
|
|
fixup_window_levels();
|
|
|
|
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2010-02-19 23:21:20 +03:00
|
|
|
}
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
- (void)applicationDidChangeScreenParameters:(NSNotification *)unused
|
|
|
|
{ // react to changes in screen numbers and positions
|
2013-09-04 13:30:18 +04:00
|
|
|
fl_lock_function();
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
main_screen_height = [[[NSScreen screens] objectAtIndex:0] frame].size.height;
|
2011-09-30 17:09:06 +04:00
|
|
|
Fl::call_screen_init();
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
// FLTK windows have already been notified they were moved,
|
|
|
|
// but they had the old main_screen_height, so they must be notified again.
|
|
|
|
NSArray *windows = [NSApp windows];
|
|
|
|
int count = [windows count];
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
NSWindow *win = [windows objectAtIndex:i];
|
|
|
|
if ([win isKindOfClass:[FLWindow class]]) {
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidMoveNotification object:win];
|
|
|
|
}
|
|
|
|
}
|
2011-09-30 12:03:22 +04:00
|
|
|
Fl::handle(FL_SCREEN_CONFIGURATION_CHANGED, NULL);
|
2013-09-04 13:30:18 +04:00
|
|
|
fl_unlock_function();
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
}
|
2014-09-15 13:44:35 +04:00
|
|
|
- (void)applicationDidUpdate:(NSNotification *)aNotification
|
|
|
|
{
|
2014-11-19 21:20:41 +03:00
|
|
|
if (im_enabled != -1) {
|
2014-09-15 13:44:35 +04:00
|
|
|
TSMDocumentID newDoc;
|
|
|
|
// It is extremely unclear when Cocoa decides to create/update
|
|
|
|
// the input context, but debugging reveals that it is done
|
|
|
|
// by NSApplication:updateWindows. So check if the input context
|
|
|
|
// has shifted after each such run so that we can update our
|
|
|
|
// input methods status.
|
|
|
|
newDoc = TSMGetActiveDocument();
|
|
|
|
if (newDoc != currentDoc) {
|
2014-11-19 21:20:41 +03:00
|
|
|
TSMDocumentID doc;
|
|
|
|
|
|
|
|
doc = TSMGetActiveDocument();
|
|
|
|
|
|
|
|
if (im_enabled)
|
|
|
|
TSMRemoveDocumentProperty(doc, kTSMDocumentEnabledInputSourcesPropertyTag);
|
|
|
|
else {
|
|
|
|
CFArrayRef inputSources;
|
|
|
|
|
|
|
|
inputSources = TISCreateASCIICapableInputSourceList();
|
|
|
|
TSMSetDocumentProperty(doc, kTSMDocumentEnabledInputSourcesPropertyTag,
|
|
|
|
sizeof(CFArrayRef), &inputSources);
|
|
|
|
CFRelease(inputSources);
|
|
|
|
}
|
|
|
|
currentDoc = newDoc;
|
2014-09-15 13:44:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-02-19 23:21:20 +03:00
|
|
|
- (void)applicationWillResignActive:(NSNotification *)notify
|
|
|
|
{
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2010-02-19 23:21:20 +03:00
|
|
|
Fl_X *x;
|
|
|
|
FLWindow *top = 0;
|
|
|
|
// sort in all regular windows
|
|
|
|
for (x = Fl_X::first;x;x = x->next) {
|
2011-11-12 17:06:54 +04:00
|
|
|
FLWindow *cw = x->xid;
|
2010-02-19 23:21:20 +03:00
|
|
|
Fl_Window *win = x->w;
|
|
|
|
if (win && cw) {
|
|
|
|
if (win->modal()) {
|
|
|
|
} else if (win->non_modal()) {
|
|
|
|
} else {
|
|
|
|
if (!top) top = cw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// now sort in all modals
|
|
|
|
for (x = Fl_X::first;x;x = x->next) {
|
2011-11-12 17:06:54 +04:00
|
|
|
FLWindow *cw = x->xid;
|
2010-02-19 23:21:20 +03:00
|
|
|
Fl_Window *win = x->w;
|
2011-09-13 17:03:07 +04:00
|
|
|
if (win && cw && [cw isVisible]) {
|
2010-02-19 23:21:20 +03:00
|
|
|
if (win->modal()) {
|
|
|
|
[cw setLevel:NSNormalWindowLevel];
|
|
|
|
if (top) [cw orderWindow:NSWindowAbove relativeTo:[top windowNumber]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// finally all non-modals
|
|
|
|
for (x = Fl_X::first;x;x = x->next) {
|
2011-11-12 17:06:54 +04:00
|
|
|
FLWindow *cw = x->xid;
|
2010-02-19 23:21:20 +03:00
|
|
|
Fl_Window *win = x->w;
|
2011-09-13 17:03:07 +04:00
|
|
|
if (win && cw && [cw isVisible]) {
|
2011-04-05 16:41:32 +04:00
|
|
|
if (win->non_modal()) {
|
2010-02-19 23:21:20 +03:00
|
|
|
[cw setLevel:NSNormalWindowLevel];
|
|
|
|
if (top) [cw orderWindow:NSWindowAbove relativeTo:[top windowNumber]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2010-02-19 23:21:20 +03:00
|
|
|
}
|
2011-03-25 15:02:31 +03:00
|
|
|
- (void)applicationWillHide:(NSNotification *)notify
|
|
|
|
{
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2011-03-25 15:02:31 +03:00
|
|
|
Fl_X *x;
|
|
|
|
for (x = Fl_X::first;x;x = x->next) {
|
|
|
|
Fl_Window *window = x->w;
|
|
|
|
if ( !window->parent() ) Fl::handle( FL_HIDE, window);
|
|
|
|
}
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2011-03-25 15:02:31 +03:00
|
|
|
}
|
|
|
|
- (void)applicationWillUnhide:(NSNotification *)notify
|
|
|
|
{
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2014-11-06 18:35:32 +03:00
|
|
|
for (Fl_X *x = Fl_X::first;x;x = x->next) {
|
2011-04-18 12:18:16 +04:00
|
|
|
Fl_Window *w = x->w;
|
2012-06-13 14:46:53 +04:00
|
|
|
if ( !w->parent() && ![x->xid isMiniaturized]) {
|
2014-11-06 18:35:32 +03:00
|
|
|
Fl::handle(FL_SHOW, w);
|
2011-03-25 15:02:31 +03:00
|
|
|
}
|
|
|
|
}
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2011-03-25 15:02:31 +03:00
|
|
|
}
|
2011-07-19 17:26:52 +04:00
|
|
|
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
|
|
|
{
|
2013-12-09 16:12:26 +04:00
|
|
|
// without the next statement, the opening of the 1st window is delayed by several seconds
|
|
|
|
// under Mac OS ≥ 10.8 when a file is dragged on the application icon
|
|
|
|
[[theApplication mainWindow] orderFront:self];
|
2011-07-19 17:26:52 +04:00
|
|
|
if (open_cb) {
|
|
|
|
fl_lock_function();
|
|
|
|
(*open_cb)([filename UTF8String]);
|
|
|
|
fl_unlock_function();
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
2013-04-15 15:00:24 +04:00
|
|
|
- (void)open_cb:(void (*)(const char*))cb
|
|
|
|
{
|
|
|
|
open_cb = cb;
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
@end
|
|
|
|
|
2014-11-11 19:08:09 +03:00
|
|
|
@interface FLAppDelegateBefore10_5 : FLAppDelegate
|
|
|
|
- (void)applicationDidUnhide:(NSNotification *)notify;
|
2014-11-17 19:08:23 +03:00
|
|
|
- (void)applicationDidUpdate:(NSNotification *)aNotification;
|
2014-11-11 19:08:09 +03:00
|
|
|
@end
|
|
|
|
@implementation FLAppDelegateBefore10_5
|
|
|
|
- (void)applicationDidUnhide:(NSNotification *)notify
|
|
|
|
{ // before 10.5, subwindows are lost when application is unhidden
|
|
|
|
fl_lock_function();
|
|
|
|
for (Fl_X *x = Fl_X::first; x; x = x->next) {
|
|
|
|
if (![x->xid parentWindow]) {
|
|
|
|
orderfront_subwindows(x->xid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fl_unlock_function();
|
|
|
|
}
|
2014-11-17 19:08:23 +03:00
|
|
|
- (void)applicationDidUpdate:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
}
|
2014-11-11 19:08:09 +03:00
|
|
|
@end
|
|
|
|
|
2013-04-15 15:00:24 +04:00
|
|
|
/*
|
|
|
|
* Install an open documents event handler...
|
|
|
|
*/
|
|
|
|
void fl_open_callback(void (*cb)(const char *)) {
|
|
|
|
fl_open_display();
|
2014-09-13 20:49:47 +04:00
|
|
|
[(FLAppDelegate*)[NSApp delegate] open_cb:cb];
|
2013-04-15 15:00:24 +04:00
|
|
|
}
|
|
|
|
|
2010-02-16 10:27:55 +03:00
|
|
|
@implementation FLApplication
|
2011-03-30 00:26:51 +04:00
|
|
|
+ (void)sendEvent:(NSEvent *)theEvent
|
2010-02-16 10:27:55 +03:00
|
|
|
{
|
2014-09-15 13:17:56 +04:00
|
|
|
if (fl_send_system_handlers(theEvent))
|
|
|
|
return;
|
|
|
|
|
2010-12-12 11:37:21 +03:00
|
|
|
NSEventType type = [theEvent type];
|
|
|
|
if (type == NSLeftMouseDown) {
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2010-12-12 11:37:21 +03:00
|
|
|
Fl_Window *grab = Fl::grab();
|
2011-02-24 19:58:00 +03:00
|
|
|
if (grab) {
|
|
|
|
FLWindow *win = (FLWindow *)[theEvent window];
|
|
|
|
if ( [win isKindOfClass:[FLWindow class]] && grab != [win getFl_Window]) {
|
|
|
|
// a click event out of a menu window, so we should close this menu
|
|
|
|
// done here to catch also clicks on window title bar/resize box
|
|
|
|
cocoaMouseHandler(theEvent);
|
|
|
|
}
|
2010-12-12 11:37:21 +03:00
|
|
|
}
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2010-12-12 11:37:21 +03:00
|
|
|
} else if (type == NSApplicationDefined) {
|
|
|
|
if ([theEvent subtype] == FLTKDataReadyEvent) {
|
|
|
|
processFLTKEvent();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else if (type == NSKeyUp) {
|
|
|
|
// The default sendEvent turns key downs into performKeyEquivalent when
|
|
|
|
// modifiers are down, but swallows the key up if the modifiers include
|
|
|
|
// command. This one makes all modifiers consistent by always sending key ups.
|
|
|
|
// FLView treats performKeyEquivalent to keyDown, but performKeyEquivalent is
|
|
|
|
// still needed for the system menu.
|
2011-03-30 00:26:51 +04:00
|
|
|
[[NSApp keyWindow] sendEvent:theEvent];
|
2010-12-12 11:37:21 +03:00
|
|
|
return;
|
|
|
|
}
|
2011-03-30 00:26:51 +04:00
|
|
|
[NSApp sendEvent:theEvent];
|
2010-02-16 10:27:55 +03:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2013-09-05 13:12:35 +04:00
|
|
|
/* Prototype of undocumented function needed to support Mac OS 10.2 or earlier
|
|
|
|
extern "C" {
|
|
|
|
OSErr CPSEnableForegroundOperation(ProcessSerialNumber*, UInt32, UInt32, UInt32, UInt32);
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
}
|
2013-09-05 13:12:35 +04:00
|
|
|
*/
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
void fl_open_display() {
|
|
|
|
static char beenHereDoneThat = 0;
|
2010-01-14 02:13:59 +03:00
|
|
|
if ( !beenHereDoneThat ) {
|
2009-12-07 01:21:55 +03:00
|
|
|
beenHereDoneThat = 1;
|
2012-03-10 01:35:45 +04:00
|
|
|
|
2011-04-01 12:32:57 +04:00
|
|
|
BOOL need_new_nsapp = (NSApp == nil);
|
|
|
|
if (need_new_nsapp) [NSApplication sharedApplication];
|
2010-12-19 14:30:01 +03:00
|
|
|
NSAutoreleasePool *localPool;
|
|
|
|
localPool = [[NSAutoreleasePool alloc] init]; // never released
|
2014-11-11 19:08:09 +03:00
|
|
|
FLAppDelegate *delegate = (fl_mac_os_version < 100500 ? [FLAppDelegateBefore10_5 alloc] : [FLAppDelegate alloc]);
|
|
|
|
[(NSApplication*)NSApp setDelegate:[delegate init]];
|
2011-04-01 12:32:57 +04:00
|
|
|
if (need_new_nsapp) [NSApp finishLaunching];
|
|
|
|
|
2010-03-30 22:14:57 +04:00
|
|
|
// empty the event queue but keep system events for drag&drop of files at launch
|
2010-03-26 19:04:06 +03:00
|
|
|
NSEvent *ign_event;
|
2010-03-30 22:14:57 +04:00
|
|
|
do ign_event = [NSApp nextEventMatchingMask:(NSAnyEventMask & ~NSSystemDefinedMask)
|
2010-03-26 19:04:06 +03:00
|
|
|
untilDate:[NSDate dateWithTimeIntervalSinceNow:0]
|
|
|
|
inMode:NSDefaultRunLoopMode
|
|
|
|
dequeue:YES];
|
|
|
|
while (ign_event);
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
// bring the application into foreground without a 'CARB' resource
|
2014-09-08 00:30:46 +04:00
|
|
|
bool i_am_in_front;
|
|
|
|
ProcessSerialNumber cur_psn = { 0, kCurrentProcess };
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
|
|
|
|
if (fl_mac_os_version >= 100600) {
|
|
|
|
i_am_in_front = [[NSRunningApplication currentApplication] isActive];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
Boolean same_psn;
|
|
|
|
ProcessSerialNumber front_psn;
|
2014-09-13 20:49:47 +04:00
|
|
|
//avoid compilation warnings triggered by GetFrontProcess() and SameProcess()
|
|
|
|
void* h = dlopen(NULL, RTLD_LAZY);
|
|
|
|
typedef OSErr (*GetFrontProcess_type)(ProcessSerialNumber*);
|
|
|
|
GetFrontProcess_type GetFrontProcess_ = (GetFrontProcess_type)dlsym(h, "GetFrontProcess");
|
|
|
|
typedef OSErr (*SameProcess_type)(ProcessSerialNumber*, ProcessSerialNumber*, Boolean*);
|
|
|
|
SameProcess_type SameProcess_ = (SameProcess_type)dlsym(h, "SameProcess");
|
|
|
|
i_am_in_front = (!GetFrontProcess_( &front_psn ) &&
|
|
|
|
!SameProcess_( &front_psn, &cur_psn, &same_psn ) && same_psn );
|
2014-09-08 00:30:46 +04:00
|
|
|
}
|
|
|
|
if (!i_am_in_front) {
|
2009-12-07 01:21:55 +03:00
|
|
|
// only transform the application type for unbundled apps
|
2012-09-26 18:34:02 +04:00
|
|
|
NSBundle *bundle = [NSBundle mainBundle];
|
|
|
|
if (bundle) {
|
2014-09-08 00:30:46 +04:00
|
|
|
NSString *exe = [[bundle executablePath] stringByStandardizingPath];
|
|
|
|
NSString *bpath = [bundle bundlePath];
|
|
|
|
NSString *exe_dir = [exe stringByDeletingLastPathComponent];
|
|
|
|
if ([bpath isEqualToString:exe] || [bpath isEqualToString:exe_dir]) bundle = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !bundle ) {
|
|
|
|
TransformProcessType(&cur_psn, kProcessTransformToForegroundApplication); // needs Mac OS 10.3
|
|
|
|
/* support of Mac OS 10.2 or earlier used this undocumented call instead
|
|
|
|
err = CPSEnableForegroundOperation(&cur_psn, 0x03, 0x3C, 0x2C, 0x1103);
|
|
|
|
*/
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2014-11-11 19:08:09 +03:00
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2011-03-31 02:15:17 +04:00
|
|
|
if (![NSApp servicesMenu]) createAppleMenu();
|
2011-10-12 16:38:32 +04:00
|
|
|
main_screen_height = [[[NSScreen screens] objectAtIndex:0] frame].size.height;
|
2014-11-06 18:35:32 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:[FLWindowDelegate singleInstance]
|
2011-10-30 21:23:42 +04:00
|
|
|
selector:@selector(anyWindowWillClose:)
|
|
|
|
name:NSWindowWillCloseNotification
|
|
|
|
object:nil];
|
2012-06-12 19:36:33 +04:00
|
|
|
// necessary for secondary pthreads to be allowed to use cocoa,
|
|
|
|
// especially to create an NSAutoreleasePool.
|
|
|
|
[NSThread detachNewThreadSelector:nil toTarget:nil withObject:nil];
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2009-12-07 01:21:55 +03:00
|
|
|
* get rid of allocated resources
|
|
|
|
*/
|
2010-01-14 02:13:59 +03:00
|
|
|
void fl_close_display() {
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
2014-09-15 13:44:35 +04:00
|
|
|
// Force a "Roman" or "ASCII" keyboard, which both the Mozilla and
|
|
|
|
// Safari people seem to think implies turning off advanced IME stuff
|
|
|
|
// (see nsTSMManager::SyncKeyScript in Mozilla and enableSecureTextInput
|
|
|
|
// in Safari/Webcore). Should be good enough for us then...
|
|
|
|
|
2014-11-19 21:20:41 +03:00
|
|
|
static int input_method_startup()
|
|
|
|
{
|
|
|
|
static int retval = -1; // -1: not initialized, 0: not usable, 1: ready for use
|
|
|
|
if (retval == -1) {
|
|
|
|
fl_open_display();
|
|
|
|
if (fl_mac_os_version >= 100500) {
|
|
|
|
TSMGetActiveDocument = (TSMGetActiveDocument_type)Fl_X::get_carbon_function("TSMGetActiveDocument");
|
|
|
|
TSMSetDocumentProperty = (TSMSetDocumentProperty_type)Fl_X::get_carbon_function("TSMSetDocumentProperty");
|
|
|
|
TSMRemoveDocumentProperty = (TSMRemoveDocumentProperty_type)Fl_X::get_carbon_function("TSMRemoveDocumentProperty");
|
|
|
|
TISCreateASCIICapableInputSourceList = (TISCreateASCIICapableInputSourceList_type)Fl_X::get_carbon_function("TISCreateASCIICapableInputSourceList");
|
|
|
|
retval = (TSMGetActiveDocument && TSMSetDocumentProperty && TSMRemoveDocumentProperty && TISCreateASCIICapableInputSourceList ? 1 : 0);
|
|
|
|
} else {
|
|
|
|
KeyScript = (KeyScript_type)Fl_X::get_carbon_function("KeyScript");
|
|
|
|
retval = (KeyScript? 1 : 0);
|
2014-09-15 13:44:35 +04:00
|
|
|
}
|
|
|
|
}
|
2014-11-19 21:20:41 +03:00
|
|
|
return retval;
|
2014-09-15 13:44:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Fl::enable_im() {
|
2014-11-19 21:20:41 +03:00
|
|
|
if (!input_method_startup()) return;
|
2014-09-15 13:44:35 +04:00
|
|
|
|
|
|
|
im_enabled = 1;
|
|
|
|
|
2014-11-19 21:20:41 +03:00
|
|
|
if (fl_mac_os_version >= 100500) {
|
|
|
|
((FLAppDelegate*)[NSApp delegate])->currentDoc = NULL;
|
|
|
|
[NSApp updateWindows]; // triggers [FLAppDelegate applicationDidUpdate]
|
|
|
|
}
|
2014-09-15 13:44:35 +04:00
|
|
|
else
|
2014-11-19 21:20:41 +03:00
|
|
|
KeyScript(smKeyEnableKybds);
|
2014-09-15 13:44:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Fl::disable_im() {
|
2014-11-19 21:20:41 +03:00
|
|
|
if (!input_method_startup()) return;
|
2014-09-15 13:44:35 +04:00
|
|
|
|
|
|
|
im_enabled = 0;
|
|
|
|
|
2014-11-19 21:20:41 +03:00
|
|
|
if (fl_mac_os_version >= 100500) {
|
|
|
|
((FLAppDelegate*)[NSApp delegate])->currentDoc = NULL;
|
|
|
|
[NSApp updateWindows]; // triggers [FLAppDelegate applicationDidUpdate]
|
|
|
|
}
|
2014-09-15 13:44:35 +04:00
|
|
|
else
|
2014-11-19 21:20:41 +03:00
|
|
|
KeyScript(smEnableRomanKybdsOnly);
|
2014-09-15 13:44:35 +04:00
|
|
|
}
|
|
|
|
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
// Gets the border sizes and the titlebar size
|
|
|
|
static void get_window_frame_sizes(int &bx, int &by, int &bt) {
|
2011-04-16 01:38:05 +04:00
|
|
|
static bool first = true;
|
|
|
|
static int top, left, bottom;
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
if (NSApp == nil) fl_open_display();
|
|
|
|
NSRect inside = { {20,20}, {100,100} };
|
|
|
|
NSRect outside = [NSWindow frameRectForContentRect:inside styleMask:NSTitledWindowMask];
|
|
|
|
left = int(outside.origin.x - inside.origin.x);
|
|
|
|
bottom = int(outside.origin.y - inside.origin.y);
|
|
|
|
top = int(outside.size.height - inside.size.height) - bottom;
|
|
|
|
}
|
|
|
|
bx = left;
|
|
|
|
by = bottom;
|
|
|
|
bt = top;
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
* smallest x coordinate in screen space of work area of menubar-containing display
|
2009-12-07 01:21:55 +03:00
|
|
|
*/
|
|
|
|
int Fl::x() {
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
return int([[[NSScreen screens] objectAtIndex:0] visibleFrame].origin.x);
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
* smallest y coordinate in screen space of work area of menubar-containing display
|
2009-12-07 01:21:55 +03:00
|
|
|
*/
|
|
|
|
int Fl::y() {
|
2012-06-14 16:41:19 +04:00
|
|
|
fl_open_display();
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
NSRect visible = [[[NSScreen screens] objectAtIndex:0] visibleFrame];
|
|
|
|
return int(main_screen_height - (visible.origin.y + visible.size.height));
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
* width of work area of menubar-containing display
|
2009-12-07 01:21:55 +03:00
|
|
|
*/
|
|
|
|
int Fl::w() {
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
return int([[[NSScreen screens] objectAtIndex:0] visibleFrame].size.width);
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
* height of work area of menubar-containing display
|
2009-12-07 01:21:55 +03:00
|
|
|
*/
|
|
|
|
int Fl::h() {
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
return int([[[NSScreen screens] objectAtIndex:0] visibleFrame].size.height);
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
// computes the work area of the nth screen (screen #0 has the menubar)
|
|
|
|
void Fl_X::screen_work_area(int &X, int &Y, int &W, int &H, int n)
|
|
|
|
{
|
2012-06-14 16:41:19 +04:00
|
|
|
fl_open_display();
|
|
|
|
NSRect r = [[[NSScreen screens] objectAtIndex:n] visibleFrame];
|
|
|
|
X = int(r.origin.x);
|
|
|
|
Y = main_screen_height - int(r.origin.y + r.size.height);
|
|
|
|
W = int(r.size.width);
|
|
|
|
H = int(r.size.height);
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2009-12-07 01:21:55 +03:00
|
|
|
* get the current mouse pointer world coordinates
|
|
|
|
*/
|
|
|
|
void Fl::get_mouse(int &x, int &y)
|
|
|
|
{
|
|
|
|
fl_open_display();
|
|
|
|
NSPoint pt = [NSEvent mouseLocation];
|
2010-11-15 07:34:58 +03:00
|
|
|
x = int(pt.x);
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
y = int(main_screen_height - pt.y);
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2014-12-19 07:53:01 +03:00
|
|
|
* Gets called when a window is created or resized
|
2009-12-07 01:21:55 +03:00
|
|
|
*/
|
|
|
|
static void handleUpdateEvent( Fl_Window *window )
|
|
|
|
{
|
|
|
|
if ( !window ) return;
|
|
|
|
Fl_X *i = Fl_X::i( window );
|
|
|
|
i->wait_for_expose = 0;
|
2009-12-13 20:34:19 +03:00
|
|
|
|
2009-12-07 01:21:55 +03:00
|
|
|
if ( i->region ) {
|
2009-12-12 21:18:54 +03:00
|
|
|
XDestroyRegion(i->region);
|
2009-12-07 01:21:55 +03:00
|
|
|
i->region = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
window->clear_damage(FL_DAMAGE_ALL);
|
|
|
|
i->flush();
|
|
|
|
window->clear_damage();
|
|
|
|
}
|
|
|
|
|
2010-11-06 18:06:25 +03:00
|
|
|
|
2009-12-07 01:21:55 +03:00
|
|
|
int Fl_X::fake_X_wm(const Fl_Window* w,int &X,int &Y, int &bt,int &bx, int &by) {
|
|
|
|
int W, H, xoff, yoff, dx, dy;
|
|
|
|
int ret = bx = by = bt = 0;
|
|
|
|
if (w->border() && !w->parent()) {
|
|
|
|
if (w->maxw != w->minw || w->maxh != w->minh) {
|
|
|
|
ret = 2;
|
|
|
|
} else {
|
|
|
|
ret = 1;
|
|
|
|
}
|
2011-04-19 12:22:05 +04:00
|
|
|
get_window_frame_sizes(bx, by, bt);
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2010-01-14 02:13:59 +03:00
|
|
|
// The coordinates of the whole window, including non-client area
|
2009-12-07 01:21:55 +03:00
|
|
|
xoff = bx;
|
|
|
|
yoff = by + bt;
|
|
|
|
dx = 2*bx;
|
|
|
|
dy = 2*by + bt;
|
|
|
|
X = w->x()-xoff;
|
|
|
|
Y = w->y()-yoff;
|
|
|
|
W = w->w()+dx;
|
|
|
|
H = w->h()+dy;
|
|
|
|
|
2014-11-11 19:08:09 +03:00
|
|
|
if (w->parent()) return 0;
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
// Proceed to positioning the window fully inside the screen, if possible
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
// let's get a little elaborate here. Mac OS X puts a lot of stuff on the desk
|
|
|
|
// that we want to avoid when positioning our window, namely the Dock and the
|
|
|
|
// top menu bar (and even more stuff in 10.4 Tiger). So we will go through the
|
|
|
|
// list of all available screens and find the one that this window is most
|
|
|
|
// likely to go to, and then reposition it to fit withing the 'good' area.
|
|
|
|
// Rect r;
|
|
|
|
// find the screen, that the center of this window will fall into
|
|
|
|
int R = X+W, B = Y+H; // right and bottom
|
|
|
|
int cx = (X+R)/2, cy = (Y+B)/2; // center of window;
|
|
|
|
NSScreen *gd = NULL;
|
|
|
|
NSArray *a = [NSScreen screens]; int count = (int)[a count]; NSRect r; int i;
|
|
|
|
for( i = 0; i < count; i++) {
|
|
|
|
r = [[a objectAtIndex:i] frame];
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
r.origin.y = main_screen_height - (r.origin.y + r.size.height); // use FLTK's multiscreen coordinates
|
2010-11-15 07:34:58 +03:00
|
|
|
if ( cx >= r.origin.x && cx <= r.origin.x + r.size.width
|
|
|
|
&& cy >= r.origin.y && cy <= r.origin.y + r.size.height)
|
2009-12-07 01:21:55 +03:00
|
|
|
break;
|
|
|
|
}
|
2010-01-14 02:13:59 +03:00
|
|
|
if (i < count) gd = [a objectAtIndex:i];
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
// if the center doesn't fall on a screen, try the top left
|
|
|
|
if (!gd) {
|
|
|
|
for( i = 0; i < count; i++) {
|
|
|
|
r = [[a objectAtIndex:i] frame];
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
r.origin.y = main_screen_height - (r.origin.y + r.size.height); // use FLTK's multiscreen coordinates
|
2009-12-07 01:21:55 +03:00
|
|
|
if ( X >= r.origin.x && X <= r.origin.x + r.size.width
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
&& Y >= r.origin.y && Y <= r.origin.y + r.size.height)
|
2009-12-07 01:21:55 +03:00
|
|
|
break;
|
|
|
|
}
|
2010-01-14 02:13:59 +03:00
|
|
|
if (i < count) gd = [a objectAtIndex:i];
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
// if that doesn't fall on a screen, try the top right
|
|
|
|
if (!gd) {
|
|
|
|
for( i = 0; i < count; i++) {
|
|
|
|
r = [[a objectAtIndex:i] frame];
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
r.origin.y = main_screen_height - (r.origin.y + r.size.height); // use FLTK's multiscreen coordinates
|
2009-12-07 01:21:55 +03:00
|
|
|
if ( R >= r.origin.x && R <= r.origin.x + r.size.width
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
&& Y >= r.origin.y && Y <= r.origin.y + r.size.height)
|
2009-12-07 01:21:55 +03:00
|
|
|
break;
|
|
|
|
}
|
2010-01-14 02:13:59 +03:00
|
|
|
if (i < count) gd = [a objectAtIndex:i];
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
// if that doesn't fall on a screen, try the bottom left
|
|
|
|
if (!gd) {
|
|
|
|
for( i = 0; i < count; i++) {
|
|
|
|
r = [[a objectAtIndex:i] frame];
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
r.origin.y = main_screen_height - (r.origin.y + r.size.height); // use FLTK's multiscreen coordinates
|
2009-12-07 01:21:55 +03:00
|
|
|
if ( X >= r.origin.x && X <= r.origin.x + r.size.width
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
&& Y+H >= r.origin.y && Y+H <= r.origin.y + r.size.height)
|
2009-12-07 01:21:55 +03:00
|
|
|
break;
|
|
|
|
}
|
2010-01-14 02:13:59 +03:00
|
|
|
if (i < count) gd = [a objectAtIndex:i];
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
// last resort, try the bottom right
|
|
|
|
if (!gd) {
|
|
|
|
for( i = 0; i < count; i++) {
|
|
|
|
r = [[a objectAtIndex:i] frame];
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
r.origin.y = main_screen_height - (r.origin.y + r.size.height); // use FLTK's multiscreen coordinates
|
2009-12-07 01:21:55 +03:00
|
|
|
if ( R >= r.origin.x && R <= r.origin.x + r.size.width
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
&& Y+H >= r.origin.y && Y+H <= r.origin.y + r.size.height)
|
2009-12-07 01:21:55 +03:00
|
|
|
break;
|
|
|
|
}
|
2010-01-14 02:13:59 +03:00
|
|
|
if (i < count) gd = [a objectAtIndex:i];
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
// if we still have not found a screen, we will use the main
|
|
|
|
// screen, the one that has the application menu bar.
|
|
|
|
if (!gd) gd = [a objectAtIndex:0];
|
|
|
|
if (gd) {
|
|
|
|
r = [gd visibleFrame];
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
r.origin.y = main_screen_height - (r.origin.y + r.size.height); // use FLTK's multiscreen coordinates
|
2010-11-15 07:34:58 +03:00
|
|
|
if ( R > r.origin.x + r.size.width ) X -= int(R - (r.origin.x + r.size.width));
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
if ( B > r.size.height + r.origin.y ) Y -= int(B - (r.size.height + r.origin.y));
|
2010-11-15 07:34:58 +03:00
|
|
|
if ( X < r.origin.x ) X = int(r.origin.x);
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
if ( Y < r.origin.y ) Y = int(r.origin.y);
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
// Return the client area's top left corner in (X,Y)
|
2009-12-07 01:21:55 +03:00
|
|
|
X+=xoff;
|
|
|
|
Y+=yoff;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Fl_Window *fl_dnd_target_window = 0;
|
|
|
|
|
2011-05-15 16:34:31 +04:00
|
|
|
static void q_set_window_title(NSWindow *nsw, const char * name, const char *mininame) {
|
2011-04-19 16:37:20 +04:00
|
|
|
CFStringRef title = CFStringCreateWithCString(NULL, (name ? name : ""), kCFStringEncodingUTF8);
|
|
|
|
if(!title) { // fallback when name contains malformed UTF-8
|
|
|
|
int l = strlen(name);
|
|
|
|
unsigned short* utf16 = new unsigned short[l + 1];
|
|
|
|
l = fl_utf8toUtf16(name, l, utf16, l + 1);
|
|
|
|
title = CFStringCreateWithCharacters(NULL, utf16, l);
|
|
|
|
delete[] utf16;
|
|
|
|
}
|
|
|
|
[nsw setTitle:(NSString*)title];
|
|
|
|
CFRelease(title);
|
2011-05-15 16:34:31 +04:00
|
|
|
if (mininame && strlen(mininame)) {
|
|
|
|
CFStringRef minititle = CFStringCreateWithCString(NULL, mininame, kCFStringEncodingUTF8);
|
|
|
|
if (minititle) {
|
|
|
|
[nsw setMiniwindowTitle:(NSString*)minititle];
|
|
|
|
CFRelease(minititle);
|
|
|
|
}
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
2013-01-17 21:40:53 +04:00
|
|
|
/** How FLTK handles Mac OS text input
|
|
|
|
|
|
|
|
Let myview be the instance of the FLView class that has the keyboard focus. FLView is an FLTK-defined NSView subclass
|
|
|
|
that implements the NSTextInputClient protocol to properly handle text input. It also implements the old NSTextInput
|
|
|
|
protocol to run with OS <= 10.4. The few NSTextInput protocol methods that differ in signature from the NSTextInputClient
|
|
|
|
protocol transmit the received message to the corresponding NSTextInputClient method.
|
2014-11-30 15:34:21 +03:00
|
|
|
If OS < 10.6, the FLView class implements differently its fl_handle_keydown_event method.
|
2013-01-17 21:40:53 +04:00
|
|
|
|
|
|
|
Keyboard input sends keyDown: and performKeyEquivalent: messages to myview. The latter occurs for keys such as
|
|
|
|
ForwardDelete, arrows and F1, and when the Ctrl or Cmd modifiers are used. Other key presses send keyDown: messages.
|
2014-11-06 18:35:32 +03:00
|
|
|
The keyDown: method calls [myview fl_handle_keydown_event:theEvent] (equivalent to [[myview inputContext] handleEvent:theEvent])
|
|
|
|
that triggers system processing of keyboard events.
|
|
|
|
The performKeyEquivalent: method directly calls Fl::handle(FL_KEYBOARD, focus-window)
|
|
|
|
when the Ctrl or Cmd modifiers are used. If not, it also calls [myview fl_handle_keydown_event:theEvent].
|
|
|
|
The performKeyEquivalent: method returns YES when the keystroke has been handled and NO otherwise, which allows
|
2013-01-19 13:49:33 +04:00
|
|
|
shortcuts of the system menu to be processed. Three sorts of messages are then sent back by the system to myview:
|
|
|
|
doCommandBySelector:, setMarkedText: and insertText:. All 3 messages eventually produce Fl::handle(FL_KEYBOARD, win) calls.
|
|
|
|
The doCommandBySelector: message allows to process events such as new-line, forward and backward delete, arrows,
|
|
|
|
escape, tab, F1. The message setMarkedText: is sent when marked text, that is, temporary text that gets replaced later
|
2013-09-06 13:24:28 +04:00
|
|
|
by some other text, is inserted. This happens when a dead key is pressed, and also
|
2013-01-19 13:49:33 +04:00
|
|
|
when entering complex scripts (e.g., Chinese). Fl_X::next_marked_length gives the byte
|
2013-01-17 21:40:53 +04:00
|
|
|
length of marked text before the FL_KEYBOARD event is processed. Fl::compose_state gives this length after this processing.
|
|
|
|
Message insertText: is sent to enter text in the focused widget. If there's marked text, Fl::compose_state is > 0, and this
|
|
|
|
marked text gets replaced by the inserted text. If there's no marked text, the new text is inserted at the insertion point.
|
2013-05-29 13:12:38 +04:00
|
|
|
When the character palette is used to enter text, the system sends an insertText: message to myview.
|
|
|
|
The in_key_event field of the FLView class allows to differentiate keyboard from palette inputs.
|
2013-01-17 21:40:53 +04:00
|
|
|
|
2013-02-02 19:46:00 +04:00
|
|
|
During processing of the handleEvent message, inserted and marked strings are concatenated in a single string
|
|
|
|
inserted in a single FL_KEYBOARD event after return from handleEvent. The need_handle member variable of FLView allows
|
|
|
|
to determine when setMarkedText or insertText strings have been sent during handleEvent processing and must trigger
|
|
|
|
an FL_KEYBOARD event. Concatenating two insertText operations or an insertText followed by a setMarkedText is possible.
|
|
|
|
In contrast, setMarkedText followed by insertText or by another setMarkedText isn't correct if concatenated in a single
|
|
|
|
string. Thus, in such case, the setMarkedText and the next operation produce each an FL_KEYBOARD event.
|
|
|
|
|
2013-01-17 21:40:53 +04:00
|
|
|
OS >= 10.7 contains a feature where pressing and holding certain keys opens a menu window that shows a list
|
|
|
|
of possible accented variants of this key. The selectedRange field of the FLView class and the selectedRange, insertText:
|
|
|
|
and setMarkedText: methods of the NSTextInputClient protocol are used to support this feature.
|
|
|
|
The notion of selected text (!= marked text) is monitored by the selectedRange field.
|
|
|
|
The -(NSRange)[FLView selectedRange] method is used to control whether an FLTK widget opens accented character windows
|
|
|
|
by returning .location = NSNotFound to disable that, or returning the value of the selectedRange field to enable the feature.
|
|
|
|
When selectedRange.location >= 0, the value of selectedRange.length is meaningful. 0 means no text is currently selected,
|
|
|
|
> 0 means this number of characters before the insertion point are selected. The insertText: method does
|
|
|
|
selectedRange = NSMakeRange(100, 0); to indicate no text is selected. The setMarkedText: method does
|
|
|
|
selectedRange = NSMakeRange(100, newSelection.length); to indicate that this length of text is selected.
|
|
|
|
|
2014-11-06 18:35:32 +03:00
|
|
|
With OS <= 10.5, the fl_handle_keydown_event: method is implemented differently because neither the
|
2014-11-30 15:34:21 +03:00
|
|
|
inputContext nor the handleEvent: methods are available.
|
|
|
|
It becomes [[FLTextInputContext singleInstance] handleEvent:event].
|
2014-11-06 18:35:32 +03:00
|
|
|
Method +[FLTextInputContext singleInstance] returns an instance of class FLTextInputContext that possesses
|
|
|
|
a handleEvent: method. The class FLTextView implements the so-called view's "field editor". This editor is an instance
|
|
|
|
of the FLTextView class allocated by the -(id)[FLWindowDelegate windowWillReturnFieldEditor: toObject:] method.
|
2013-01-17 21:40:53 +04:00
|
|
|
The -(BOOL)[FLTextInputContext handleEvent:] method emulates the missing 10.6 -(BOOL)[NSTextInputContext handleEvent:]
|
|
|
|
by sending the interpretKeyEvents: message to the FLTextView object. The system sends back doCommandBySelector: and
|
|
|
|
insertText: messages to the FLTextView object that are transmitted unchanged to myview to be processed as with OS >= 10.6.
|
|
|
|
The system also sends setMarkedText: messages directly to myview.
|
2013-02-02 19:46:00 +04:00
|
|
|
|
2013-01-17 21:40:53 +04:00
|
|
|
There is furthermore an oddity of dead key processing with OS <= 10.5. It occurs when a dead key followed by a non-accented
|
|
|
|
key are pressed. Say, for example, that keys '^' followed by 'p' are pressed on a French or German keyboard. Resulting
|
|
|
|
messages are: [myview setMarkedText:@"^"], [myview insertText:@"^"], [myview insertText:@"p"], [FLTextView insertText:@"^p"].
|
|
|
|
The 2nd '^' replaces the marked 1st one, followed by p^p. The resulting text in the widget is "^p^p" instead of the
|
|
|
|
desired "^p". To avoid that, the FLTextView object is deactivated by the insertText: message and reactivated after
|
|
|
|
the handleEvent: message has been processed.
|
|
|
|
|
|
|
|
NSEvent's during a character composition sequence:
|
|
|
|
- keyDown with deadkey -> [[theEvent characters] length] is 0
|
|
|
|
- keyUp -> [theEvent characters] contains the deadkey
|
|
|
|
- keyDown with next key -> [theEvent characters] contains the composed character
|
|
|
|
- keyUp -> [theEvent characters] contains the standard character
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void cocoaKeyboardHandler(NSEvent *theEvent)
|
|
|
|
{
|
|
|
|
NSUInteger mods;
|
|
|
|
// get the modifiers
|
|
|
|
mods = [theEvent modifierFlags];
|
|
|
|
// get the key code
|
|
|
|
UInt32 keyCode = 0, maskedKeyCode = 0;
|
|
|
|
unsigned short sym = 0;
|
|
|
|
keyCode = [theEvent keyCode];
|
|
|
|
// extended keyboards can also send sequences on key-up to generate Kanji etc. codes.
|
|
|
|
// Some observed prefixes are 0x81 to 0x83, followed by an 8 bit keycode.
|
|
|
|
// In this mode, there seem to be no key-down codes
|
|
|
|
// printf("%08x %08x %08x\n", keyCode, mods, key);
|
|
|
|
maskedKeyCode = keyCode & 0x7f;
|
|
|
|
mods_to_e_state( mods ); // process modifier keys
|
|
|
|
sym = macKeyLookUp[maskedKeyCode];
|
|
|
|
if (sym < 0xff00) { // a "simple" key
|
|
|
|
// find the result of this key without modifier
|
|
|
|
NSString *sim = [theEvent charactersIgnoringModifiers];
|
|
|
|
UniChar one;
|
|
|
|
CFStringGetCharacters((CFStringRef)sim, CFRangeMake(0, 1), &one);
|
|
|
|
// charactersIgnoringModifiers doesn't ignore shift, remove it when it's on
|
|
|
|
if(one >= 'A' && one <= 'Z') one += 32;
|
|
|
|
if (one > 0 && one <= 0x7f && (sym<'0' || sym>'9') ) sym = one;
|
|
|
|
}
|
|
|
|
Fl::e_keysym = Fl::e_original_keysym = sym;
|
|
|
|
/*NSLog(@"cocoaKeyboardHandler: keycode=%08x keysym=%08x mods=%08x symbol=%@ (%@)",
|
|
|
|
keyCode, sym, mods, [theEvent characters], [theEvent charactersIgnoringModifiers]);*/
|
|
|
|
// If there is text associated with this key, it will be filled in later.
|
|
|
|
Fl::e_length = 0;
|
|
|
|
Fl::e_text = (char*)"";
|
|
|
|
}
|
|
|
|
|
2014-11-06 18:35:32 +03:00
|
|
|
@interface FLTextInputContext : NSObject // "emulates" NSTextInputContext before OS 10.6
|
|
|
|
+ (void)initialize;
|
|
|
|
+ (FLTextInputContext*)singleInstance;
|
2013-01-17 21:40:53 +04:00
|
|
|
-(BOOL)handleEvent:(NSEvent*)theEvent;
|
|
|
|
@end
|
2014-11-06 18:35:32 +03:00
|
|
|
static FLTextInputContext* fltextinputcontext_instance = nil;
|
2013-01-17 21:40:53 +04:00
|
|
|
@implementation FLTextInputContext
|
2014-11-06 18:35:32 +03:00
|
|
|
+ (void)initialize {
|
|
|
|
fltextinputcontext_instance = [[FLTextInputContext alloc] init];
|
|
|
|
}
|
|
|
|
+ (FLTextInputContext*)singleInstance {
|
|
|
|
return fltextinputcontext_instance;
|
|
|
|
}
|
2013-01-17 21:40:53 +04:00
|
|
|
-(BOOL)handleEvent:(NSEvent*)theEvent {
|
2014-11-06 18:35:32 +03:00
|
|
|
FLTextView *edit = [FLTextView singleInstance];
|
|
|
|
[edit setActive:YES];
|
|
|
|
[edit interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
|
|
|
|
[edit setActive:YES];
|
2013-01-17 21:40:53 +04:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
@end
|
2009-12-07 01:21:55 +03:00
|
|
|
|
2013-01-13 19:25:37 +04:00
|
|
|
@interface FLView : NSView <NSTextInput
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
|
|
|
, NSTextInputClient
|
|
|
|
#endif
|
|
|
|
> {
|
2013-02-02 19:46:00 +04:00
|
|
|
BOOL in_key_event; // YES means keypress is being processed by handleEvent
|
|
|
|
BOOL need_handle; // YES means Fl::handle(FL_KEYBOARD,) is needed after handleEvent processing
|
2012-12-14 12:36:13 +04:00
|
|
|
NSInteger identifier;
|
2013-01-13 19:25:37 +04:00
|
|
|
NSRange selectedRange;
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2011-04-27 15:21:57 +04:00
|
|
|
+ (void)prepareEtext:(NSString*)aString;
|
2013-02-02 19:46:00 +04:00
|
|
|
+ (void)concatEtext:(NSString*)aString;
|
2014-11-30 15:34:21 +03:00
|
|
|
- (id)initWithFrame:(NSRect)frameRect;
|
2009-12-07 01:21:55 +03:00
|
|
|
- (void)drawRect:(NSRect)rect;
|
|
|
|
- (BOOL)acceptsFirstResponder;
|
|
|
|
- (BOOL)acceptsFirstMouse:(NSEvent*)theEvent;
|
2014-06-16 15:17:57 +04:00
|
|
|
- (void)resetCursorRects;
|
2010-01-14 02:13:59 +03:00
|
|
|
- (BOOL)performKeyEquivalent:(NSEvent*)theEvent;
|
2009-12-07 01:21:55 +03:00
|
|
|
- (void)mouseUp:(NSEvent *)theEvent;
|
|
|
|
- (void)rightMouseUp:(NSEvent *)theEvent;
|
|
|
|
- (void)otherMouseUp:(NSEvent *)theEvent;
|
|
|
|
- (void)mouseDown:(NSEvent *)theEvent;
|
|
|
|
- (void)rightMouseDown:(NSEvent *)theEvent;
|
|
|
|
- (void)otherMouseDown:(NSEvent *)theEvent;
|
2010-12-02 02:12:06 +03:00
|
|
|
- (void)mouseMoved:(NSEvent *)theEvent;
|
2009-12-07 01:21:55 +03:00
|
|
|
- (void)mouseDragged:(NSEvent *)theEvent;
|
2010-03-04 20:17:04 +03:00
|
|
|
- (void)rightMouseDragged:(NSEvent *)theEvent;
|
|
|
|
- (void)otherMouseDragged:(NSEvent *)theEvent;
|
2009-12-07 01:21:55 +03:00
|
|
|
- (void)scrollWheel:(NSEvent *)theEvent;
|
|
|
|
- (void)keyDown:(NSEvent *)theEvent;
|
|
|
|
- (void)keyUp:(NSEvent *)theEvent;
|
2010-01-24 13:27:21 +03:00
|
|
|
- (void)flagsChanged:(NSEvent *)theEvent;
|
2009-12-07 01:21:55 +03:00
|
|
|
- (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender;
|
|
|
|
- (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender;
|
|
|
|
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
|
|
|
|
- (void)draggingExited:(id < NSDraggingInfo >)sender;
|
|
|
|
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal;
|
2014-11-06 18:35:32 +03:00
|
|
|
- (BOOL)fl_handle_keydown_event:(NSEvent*)event;
|
2013-01-17 21:40:53 +04:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
|
|
|
|
- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange;
|
|
|
|
- (void)setMarkedText:(id)aString selectedRange:(NSRange)newSelection replacementRange:(NSRange)replacementRange;
|
|
|
|
- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange;
|
|
|
|
- (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange;
|
|
|
|
- (NSInteger)windowLevel;
|
|
|
|
#endif
|
2009-12-07 01:21:55 +03:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation FLView
|
2014-11-30 15:34:21 +03:00
|
|
|
- (id)initWithFrame:(NSRect)frameRect
|
2011-04-27 15:21:57 +04:00
|
|
|
{
|
2012-12-14 12:36:13 +04:00
|
|
|
static NSInteger counter = 0;
|
2014-11-30 15:34:21 +03:00
|
|
|
self = [super initWithFrame:frameRect];
|
2011-04-27 15:21:57 +04:00
|
|
|
if (self) {
|
2012-12-15 01:29:45 +04:00
|
|
|
in_key_event = NO;
|
2012-12-14 12:36:13 +04:00
|
|
|
identifier = ++counter;
|
2011-04-27 15:21:57 +04:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
- (void)drawRect:(NSRect)rect
|
|
|
|
{
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
FLWindow *cw = (FLWindow*)[self window];
|
|
|
|
Fl_Window *w = [cw getFl_Window];
|
2014-12-19 07:53:01 +03:00
|
|
|
if (w->visible()) {
|
|
|
|
through_drawRect = YES;
|
|
|
|
if (fl_x_to_redraw) fl_x_to_redraw->flush();
|
|
|
|
else handleUpdateEvent(w);
|
|
|
|
through_drawRect = NO;
|
|
|
|
}
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)acceptsFirstResponder
|
|
|
|
{
|
2014-11-30 15:34:21 +03:00
|
|
|
return [[self window] parentWindow] ? NO : YES; // 10.2
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
- (BOOL)performKeyEquivalent:(NSEvent*)theEvent
|
|
|
|
{
|
2011-04-27 15:21:57 +04:00
|
|
|
//NSLog(@"performKeyEquivalent:");
|
2012-12-15 01:29:45 +04:00
|
|
|
fl_lock_function();
|
|
|
|
cocoaKeyboardHandler(theEvent);
|
2013-01-19 13:49:33 +04:00
|
|
|
BOOL handled;
|
2013-01-18 21:12:39 +04:00
|
|
|
NSUInteger mods = [theEvent modifierFlags];
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
Fl_Window *w = [(FLWindow*)[theEvent window] getFl_Window];
|
|
|
|
if ( (mods & NSControlKeyMask) || (mods & NSCommandKeyMask) || (w->as_gl_window() && Fl::focus() == w)) {
|
2013-01-19 13:49:33 +04:00
|
|
|
NSString *s = [theEvent characters];
|
|
|
|
if ( (mods & NSShiftKeyMask) && (mods & NSCommandKeyMask) ) {
|
|
|
|
s = [s uppercaseString]; // US keyboards return lowercase letter in s if cmd-shift-key is hit
|
|
|
|
}
|
|
|
|
[FLView prepareEtext:s];
|
2013-12-20 22:29:02 +04:00
|
|
|
Fl::compose_state = 0;
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
handled = Fl::handle(FL_KEYBOARD, w);
|
2013-01-19 13:49:33 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
in_key_event = YES;
|
2013-02-02 19:46:00 +04:00
|
|
|
need_handle = NO;
|
2014-11-06 18:35:32 +03:00
|
|
|
handled = [self fl_handle_keydown_event:theEvent];
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
if (need_handle) handled = Fl::handle(FL_KEYBOARD, w);
|
2013-01-19 13:49:33 +04:00
|
|
|
in_key_event = NO;
|
|
|
|
}
|
2012-12-15 01:29:45 +04:00
|
|
|
fl_unlock_function();
|
2013-01-18 21:12:39 +04:00
|
|
|
return handled;
|
2010-01-14 02:13:59 +03:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
- (BOOL)acceptsFirstMouse:(NSEvent*)theEvent
|
|
|
|
{
|
|
|
|
Fl_Window *w = [(FLWindow*)[theEvent window] getFl_Window];
|
|
|
|
Fl_Window *first = Fl::first_window();
|
|
|
|
return (first == w || !first->modal());
|
|
|
|
}
|
2014-06-16 15:17:57 +04:00
|
|
|
- (void)resetCursorRects {
|
|
|
|
Fl_Window *w = [(FLWindow*)[self window] getFl_Window];
|
|
|
|
Fl_X *i = Fl_X::i(w);
|
2014-09-09 15:02:33 +04:00
|
|
|
if (!i) return; // fix for STR #3128
|
2014-06-16 15:17:57 +04:00
|
|
|
// We have to have at least one cursor rect for invalidateCursorRectsForView
|
|
|
|
// to work, hence the "else" clause.
|
|
|
|
if (i->cursor)
|
|
|
|
[self addCursorRect:[self visibleRect] cursor:(NSCursor*)i->cursor];
|
|
|
|
else
|
|
|
|
[self addCursorRect:[self visibleRect] cursor:[NSCursor arrowCursor]];
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
- (void)mouseUp:(NSEvent *)theEvent {
|
|
|
|
cocoaMouseHandler(theEvent);
|
|
|
|
}
|
|
|
|
- (void)rightMouseUp:(NSEvent *)theEvent {
|
|
|
|
cocoaMouseHandler(theEvent);
|
|
|
|
}
|
|
|
|
- (void)otherMouseUp:(NSEvent *)theEvent {
|
|
|
|
cocoaMouseHandler(theEvent);
|
|
|
|
}
|
|
|
|
- (void)mouseDown:(NSEvent *)theEvent {
|
|
|
|
cocoaMouseHandler(theEvent);
|
|
|
|
}
|
|
|
|
- (void)rightMouseDown:(NSEvent *)theEvent {
|
|
|
|
cocoaMouseHandler(theEvent);
|
|
|
|
}
|
|
|
|
- (void)otherMouseDown:(NSEvent *)theEvent {
|
|
|
|
cocoaMouseHandler(theEvent);
|
|
|
|
}
|
|
|
|
- (void)mouseMoved:(NSEvent *)theEvent {
|
|
|
|
cocoaMouseHandler(theEvent);
|
|
|
|
}
|
|
|
|
- (void)mouseDragged:(NSEvent *)theEvent {
|
|
|
|
cocoaMouseHandler(theEvent);
|
|
|
|
}
|
2010-03-04 20:17:04 +03:00
|
|
|
- (void)rightMouseDragged:(NSEvent *)theEvent {
|
|
|
|
cocoaMouseHandler(theEvent);
|
|
|
|
}
|
|
|
|
- (void)otherMouseDragged:(NSEvent *)theEvent {
|
|
|
|
cocoaMouseHandler(theEvent);
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
- (void)scrollWheel:(NSEvent *)theEvent {
|
|
|
|
cocoaMouseWheelHandler(theEvent);
|
|
|
|
}
|
2012-12-15 01:29:45 +04:00
|
|
|
- (void)keyDown:(NSEvent *)theEvent {
|
2013-01-17 21:40:53 +04:00
|
|
|
//NSLog(@"keyDown:%@",[theEvent characters]);
|
2011-04-27 15:21:57 +04:00
|
|
|
fl_lock_function();
|
2012-12-15 01:29:45 +04:00
|
|
|
Fl_Window *window = [(FLWindow*)[theEvent window] getFl_Window];
|
2011-04-27 15:21:57 +04:00
|
|
|
Fl::first_window(window);
|
|
|
|
cocoaKeyboardHandler(theEvent);
|
2012-12-15 18:19:42 +04:00
|
|
|
in_key_event = YES;
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
if (window->as_gl_window() && Fl::focus() == window ) { // ignore text input methods for GL windows
|
|
|
|
need_handle = YES;
|
|
|
|
[FLView prepareEtext:[theEvent characters]];
|
|
|
|
} else {
|
|
|
|
need_handle = NO;
|
|
|
|
[self fl_handle_keydown_event:theEvent];
|
|
|
|
}
|
2013-02-02 19:46:00 +04:00
|
|
|
if (need_handle) Fl::handle(FL_KEYBOARD, window);
|
2012-12-15 18:19:42 +04:00
|
|
|
in_key_event = NO;
|
2011-04-27 15:21:57 +04:00
|
|
|
fl_unlock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
- (void)keyUp:(NSEvent *)theEvent {
|
2013-01-17 21:40:53 +04:00
|
|
|
//NSLog(@"keyUp:%@",[theEvent characters]);
|
2011-04-27 15:21:57 +04:00
|
|
|
fl_lock_function();
|
|
|
|
Fl_Window *window = (Fl_Window*)[(FLWindow*)[theEvent window] getFl_Window];
|
|
|
|
Fl::first_window(window);
|
2009-12-07 01:21:55 +03:00
|
|
|
cocoaKeyboardHandler(theEvent);
|
2011-06-03 13:12:07 +04:00
|
|
|
NSString *s = [theEvent characters];
|
|
|
|
if ([s length] >= 1) [FLView prepareEtext:[s substringToIndex:1]];
|
2011-04-27 15:21:57 +04:00
|
|
|
Fl::handle(FL_KEYUP,window);
|
|
|
|
fl_unlock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2010-01-24 13:27:21 +03:00
|
|
|
- (void)flagsChanged:(NSEvent *)theEvent {
|
2011-04-27 15:21:57 +04:00
|
|
|
//NSLog(@"flagsChanged: ");
|
2010-01-24 13:27:21 +03:00
|
|
|
fl_lock_function();
|
2010-03-26 19:04:06 +03:00
|
|
|
static UInt32 prevMods = 0;
|
2010-01-24 13:27:21 +03:00
|
|
|
NSUInteger mods = [theEvent modifierFlags];
|
|
|
|
Fl_Window *window = (Fl_Window*)[(FLWindow*)[theEvent window] getFl_Window];
|
|
|
|
UInt32 tMods = prevMods ^ mods;
|
|
|
|
int sendEvent = 0;
|
|
|
|
if ( tMods )
|
|
|
|
{
|
2011-03-31 02:15:17 +04:00
|
|
|
unsigned short keycode = [theEvent keyCode];
|
2011-06-16 15:13:59 +04:00
|
|
|
Fl::e_keysym = Fl::e_original_keysym = macKeyLookUp[keycode & 0x7f];
|
2010-01-24 13:27:21 +03:00
|
|
|
if ( Fl::e_keysym )
|
|
|
|
sendEvent = ( prevMods<mods ) ? FL_KEYBOARD : FL_KEYUP;
|
|
|
|
Fl::e_length = 0;
|
2010-02-21 00:14:47 +03:00
|
|
|
Fl::e_text = (char*)"";
|
2010-01-24 13:27:21 +03:00
|
|
|
prevMods = mods;
|
|
|
|
}
|
|
|
|
mods_to_e_state( mods );
|
|
|
|
if (sendEvent) Fl::handle(sendEvent,window);
|
|
|
|
fl_unlock_function();
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
- (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender
|
|
|
|
{
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
Fl_Window *target = [(FLWindow*)[self window] getFl_Window];
|
2010-02-01 20:41:32 +03:00
|
|
|
update_e_xy_and_e_xy_root([self window]);
|
2009-12-07 01:21:55 +03:00
|
|
|
fl_dnd_target_window = target;
|
2009-12-13 20:34:19 +03:00
|
|
|
int ret = Fl::handle( FL_DND_ENTER, target );
|
|
|
|
breakMacEventLoop();
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2011-09-30 13:38:35 +04:00
|
|
|
Fl::flush();
|
2009-12-13 20:34:19 +03:00
|
|
|
return ret ? NSDragOperationCopy : NSDragOperationNone;
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
- (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender
|
|
|
|
{
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
Fl_Window *target = [(FLWindow*)[self window] getFl_Window];
|
2010-02-01 20:41:32 +03:00
|
|
|
update_e_xy_and_e_xy_root([self window]);
|
2009-12-07 01:21:55 +03:00
|
|
|
fl_dnd_target_window = target;
|
2009-12-13 20:34:19 +03:00
|
|
|
int ret = Fl::handle( FL_DND_DRAG, target );
|
|
|
|
breakMacEventLoop();
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2011-09-30 13:38:35 +04:00
|
|
|
// if the DND started in the same application, Fl::dnd() will not return until
|
|
|
|
// the the DND operation is finished. The call below causes the drop indicator
|
|
|
|
// to be draw correctly (a full event handling would be better...)
|
|
|
|
Fl::flush();
|
2009-12-13 20:34:19 +03:00
|
|
|
return ret ? NSDragOperationCopy : NSDragOperationNone;
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
|
|
|
|
{
|
|
|
|
static char *DragData = NULL;
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
Fl_Window *target = [(FLWindow*)[self window] getFl_Window];
|
2009-12-13 20:34:19 +03:00
|
|
|
if ( !Fl::handle( FL_DND_RELEASE, target ) ) {
|
|
|
|
breakMacEventLoop();
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2009-12-13 20:34:19 +03:00
|
|
|
return NO;
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
NSPasteboard *pboard;
|
2010-01-14 02:13:59 +03:00
|
|
|
// NSDragOperation sourceDragMask;
|
|
|
|
// sourceDragMask = [sender draggingSourceOperationMask];
|
2009-12-07 01:21:55 +03:00
|
|
|
pboard = [sender draggingPasteboard];
|
2010-02-01 20:41:32 +03:00
|
|
|
update_e_xy_and_e_xy_root([self window]);
|
2010-01-14 02:13:59 +03:00
|
|
|
if (DragData) { free(DragData); DragData = NULL; }
|
2009-12-07 01:21:55 +03:00
|
|
|
if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
|
2010-01-14 02:13:59 +03:00
|
|
|
CFArrayRef files = (CFArrayRef)[pboard propertyListForType:NSFilenamesPboardType];
|
|
|
|
CFStringRef all = CFStringCreateByCombiningStrings(NULL, files, CFSTR("\n"));
|
|
|
|
int l = CFStringGetMaximumSizeForEncoding(CFStringGetLength(all), kCFStringEncodingUTF8);
|
|
|
|
DragData = (char *)malloc(l + 1);
|
|
|
|
CFStringGetCString(all, DragData, l + 1, kCFStringEncodingUTF8);
|
|
|
|
CFRelease(all);
|
|
|
|
}
|
2013-12-10 16:07:09 +04:00
|
|
|
else if ( [[pboard types] containsObject:utf8_format] ) {
|
|
|
|
NSData *data = [pboard dataForType:utf8_format];
|
2010-01-14 02:13:59 +03:00
|
|
|
DragData = (char *)malloc([data length] + 1);
|
|
|
|
[data getBytes:DragData];
|
|
|
|
DragData[[data length]] = 0;
|
|
|
|
convert_crlf(DragData, strlen(DragData));
|
|
|
|
}
|
2009-12-13 20:34:19 +03:00
|
|
|
else {
|
|
|
|
breakMacEventLoop();
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2009-12-13 20:34:19 +03:00
|
|
|
return NO;
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
Fl::e_text = DragData;
|
|
|
|
Fl::e_length = strlen(DragData);
|
|
|
|
int old_event = Fl::e_number;
|
|
|
|
Fl::belowmouse()->handle(Fl::e_number = FL_PASTE);
|
|
|
|
Fl::e_number = old_event;
|
2010-01-14 02:13:59 +03:00
|
|
|
if (DragData) { free(DragData); DragData = NULL; }
|
2009-12-07 01:21:55 +03:00
|
|
|
Fl::e_text = NULL;
|
|
|
|
Fl::e_length = 0;
|
|
|
|
fl_dnd_target_window = NULL;
|
2009-12-13 20:34:19 +03:00
|
|
|
breakMacEventLoop();
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
- (void)draggingExited:(id < NSDraggingInfo >)sender
|
|
|
|
{
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2010-01-14 02:13:59 +03:00
|
|
|
if ( fl_dnd_target_window ) {
|
2009-12-13 20:34:19 +03:00
|
|
|
Fl::handle( FL_DND_LEAVE, fl_dnd_target_window );
|
|
|
|
fl_dnd_target_window = 0;
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal
|
|
|
|
{
|
|
|
|
return NSDragOperationGeneric;
|
|
|
|
}
|
2011-01-03 19:50:34 +03:00
|
|
|
|
2014-11-30 15:34:21 +03:00
|
|
|
- (BOOL)fl_handle_keydown_event:(NSEvent*)event {
|
|
|
|
return fl_mac_os_version >= 100600 ?
|
|
|
|
[[self performSelector:@selector(inputContext)] handleEvent:event]
|
|
|
|
:
|
|
|
|
[[FLTextInputContext singleInstance] handleEvent:event];
|
2013-01-17 21:40:53 +04:00
|
|
|
}
|
|
|
|
|
2011-04-27 15:21:57 +04:00
|
|
|
+ (void)prepareEtext:(NSString*)aString {
|
|
|
|
// fills Fl::e_text with UTF-8 encoded aString using an adequate memory allocation
|
|
|
|
static char *received_utf8 = NULL;
|
|
|
|
static int lreceived = 0;
|
|
|
|
char *p = (char*)[aString UTF8String];
|
|
|
|
int l = strlen(p);
|
|
|
|
if (l > 0) {
|
|
|
|
if (lreceived == 0) {
|
|
|
|
received_utf8 = (char*)malloc(l + 1);
|
|
|
|
lreceived = l;
|
|
|
|
}
|
|
|
|
else if (l > lreceived) {
|
|
|
|
received_utf8 = (char*)realloc(received_utf8, l + 1);
|
|
|
|
lreceived = l;
|
|
|
|
}
|
|
|
|
strcpy(received_utf8, p);
|
|
|
|
Fl::e_text = received_utf8;
|
|
|
|
}
|
|
|
|
Fl::e_length = l;
|
|
|
|
}
|
|
|
|
|
2013-02-02 19:46:00 +04:00
|
|
|
+ (void)concatEtext:(NSString*)aString {
|
|
|
|
// extends Fl::e_text with aString
|
|
|
|
NSString *newstring = [[NSString stringWithUTF8String:Fl::e_text] stringByAppendingString:aString];
|
|
|
|
[FLView prepareEtext:newstring];
|
|
|
|
}
|
|
|
|
|
2011-01-03 19:50:34 +03:00
|
|
|
- (void)doCommandBySelector:(SEL)aSelector {
|
2013-02-09 17:54:58 +04:00
|
|
|
NSString *s = [[NSApp currentEvent] characters];
|
|
|
|
//NSLog(@"doCommandBySelector:%s text='%@'",sel_getName(aSelector), s);
|
|
|
|
s = [s substringFromIndex:[s length] - 1];
|
|
|
|
[FLView prepareEtext:s]; // use the last character of the event; necessary for deadkey + Tab
|
2013-01-17 21:40:53 +04:00
|
|
|
Fl_Window *target = [(FLWindow*)[self window] getFl_Window];
|
|
|
|
Fl::handle(FL_KEYBOARD, target);
|
2011-01-03 19:50:34 +03:00
|
|
|
}
|
2013-01-17 21:40:53 +04:00
|
|
|
|
2011-01-03 19:50:34 +03:00
|
|
|
- (void)insertText:(id)aString {
|
2013-01-13 19:25:37 +04:00
|
|
|
[self insertText:aString replacementRange:NSMakeRange(NSNotFound, 0)];
|
|
|
|
}
|
2013-01-17 21:40:53 +04:00
|
|
|
|
2013-01-13 19:25:37 +04:00
|
|
|
- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange {
|
2011-01-03 19:50:34 +03:00
|
|
|
NSString *received;
|
|
|
|
if ([aString isKindOfClass:[NSAttributedString class]]) {
|
|
|
|
received = [(NSAttributedString*)aString string];
|
|
|
|
} else {
|
|
|
|
received = (NSString*)aString;
|
|
|
|
}
|
2013-02-09 17:54:58 +04:00
|
|
|
/*NSLog(@"insertText='%@' l=%d Fl::compose_state=%d range=%d,%d",
|
2013-02-08 15:58:19 +04:00
|
|
|
received,strlen([received UTF8String]),Fl::compose_state,replacementRange.location,replacementRange.length);*/
|
2012-12-14 12:36:13 +04:00
|
|
|
fl_lock_function();
|
2013-01-13 19:25:37 +04:00
|
|
|
Fl_Window *target = [(FLWindow*)[self window] getFl_Window];
|
|
|
|
while (replacementRange.length--) { // delete replacementRange.length characters before insertion point
|
|
|
|
int saved_keysym = Fl::e_keysym;
|
|
|
|
Fl::e_keysym = FL_BackSpace;
|
|
|
|
Fl::handle(FL_KEYBOARD, target);
|
|
|
|
Fl::e_keysym = saved_keysym;
|
|
|
|
}
|
2013-02-02 19:46:00 +04:00
|
|
|
if (in_key_event && Fl_X::next_marked_length && Fl::e_length) {
|
|
|
|
// if setMarkedText + insertText is sent during handleEvent, text cannot be concatenated in single FL_KEYBOARD event
|
|
|
|
Fl::handle(FL_KEYBOARD, target);
|
|
|
|
Fl::e_length = 0;
|
|
|
|
}
|
|
|
|
if (in_key_event && Fl::e_length) [FLView concatEtext:received];
|
|
|
|
else [FLView prepareEtext:received];
|
2012-12-24 15:45:07 +04:00
|
|
|
Fl_X::next_marked_length = 0;
|
2013-05-29 13:12:38 +04:00
|
|
|
// We can get called outside of key events (e.g., from the character palette, from CJK text input).
|
|
|
|
BOOL palette = !(in_key_event || Fl::compose_state);
|
|
|
|
if (palette) Fl::e_keysym = 0;
|
2013-02-09 17:54:58 +04:00
|
|
|
// YES if key has text attached
|
|
|
|
BOOL has_text_key = Fl::e_keysym <= '~' || Fl::e_keysym == FL_Iso_Key ||
|
|
|
|
(Fl::e_keysym >= FL_KP && Fl::e_keysym <= FL_KP_Last && Fl::e_keysym != FL_KP_Enter);
|
|
|
|
// insertText sent during handleEvent of a key without text cannot be processed in a single FL_KEYBOARD event.
|
|
|
|
// Occurs with deadkey followed by non-text key
|
|
|
|
if (!in_key_event || !has_text_key) {
|
2013-05-29 13:12:38 +04:00
|
|
|
Fl::handle(FL_KEYBOARD, target);
|
2013-02-09 17:54:58 +04:00
|
|
|
Fl::e_length = 0;
|
|
|
|
}
|
2013-02-02 19:46:00 +04:00
|
|
|
else need_handle = YES;
|
2013-01-13 19:25:37 +04:00
|
|
|
selectedRange = NSMakeRange(100, 0); // 100 is an arbitrary value
|
2012-12-14 12:36:13 +04:00
|
|
|
// for some reason, with the palette, the window does not redraw until the next mouse move or button push
|
|
|
|
// sending a 'redraw()' or 'awake()' does not solve the issue!
|
2013-05-29 13:12:38 +04:00
|
|
|
if (palette) Fl::flush();
|
2014-11-30 15:34:21 +03:00
|
|
|
if (fl_mac_os_version < 100600) [[FLTextView singleInstance] setActive:NO];
|
2012-12-14 12:36:13 +04:00
|
|
|
fl_unlock_function();
|
2011-01-03 19:50:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setMarkedText:(id)aString selectedRange:(NSRange)newSelection {
|
2013-01-13 19:25:37 +04:00
|
|
|
[self setMarkedText:aString selectedRange:newSelection replacementRange:NSMakeRange(NSNotFound, 0)];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setMarkedText:(id)aString selectedRange:(NSRange)newSelection replacementRange:(NSRange)replacementRange {
|
2011-04-27 15:21:57 +04:00
|
|
|
NSString *received;
|
|
|
|
if ([aString isKindOfClass:[NSAttributedString class]]) {
|
|
|
|
received = [(NSAttributedString*)aString string];
|
|
|
|
} else {
|
|
|
|
received = (NSString*)aString;
|
|
|
|
}
|
2012-12-14 12:36:13 +04:00
|
|
|
fl_lock_function();
|
2013-02-08 15:58:19 +04:00
|
|
|
/*NSLog(@"setMarkedText:%@ l=%d newSelection=%d,%d Fl::compose_state=%d replacement=%d,%d",
|
|
|
|
received, strlen([received UTF8String]), newSelection.location, newSelection.length, Fl::compose_state,
|
2013-01-13 19:25:37 +04:00
|
|
|
replacementRange.location, replacementRange.length);*/
|
2012-12-14 12:36:13 +04:00
|
|
|
Fl_Window *target = [(FLWindow*)[self window] getFl_Window];
|
2013-01-13 19:25:37 +04:00
|
|
|
while (replacementRange.length--) { // delete replacementRange.length characters before insertion point
|
|
|
|
Fl::e_keysym = FL_BackSpace;
|
|
|
|
Fl::compose_state = 0;
|
|
|
|
Fl_X::next_marked_length = 0;
|
|
|
|
Fl::handle(FL_KEYBOARD, target);
|
|
|
|
Fl::e_keysym = 'a'; // pretend a letter key was hit
|
|
|
|
}
|
2013-02-02 19:46:00 +04:00
|
|
|
if (in_key_event && Fl_X::next_marked_length && Fl::e_length) {
|
|
|
|
// if setMarkedText + setMarkedText is sent during handleEvent, text cannot be concatenated in single FL_KEYBOARD event
|
|
|
|
Fl::handle(FL_KEYBOARD, target);
|
|
|
|
Fl::e_length = 0;
|
|
|
|
}
|
|
|
|
if (in_key_event && Fl::e_length) [FLView concatEtext:received];
|
|
|
|
else [FLView prepareEtext:received];
|
|
|
|
Fl_X::next_marked_length = strlen([received UTF8String]);
|
|
|
|
if (!in_key_event) Fl::handle( FL_KEYBOARD, target);
|
|
|
|
else need_handle = YES;
|
2013-01-13 19:25:37 +04:00
|
|
|
selectedRange = NSMakeRange(100, newSelection.length);
|
2012-12-14 12:36:13 +04:00
|
|
|
fl_unlock_function();
|
2011-01-03 19:50:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)unmarkText {
|
2011-04-27 15:21:57 +04:00
|
|
|
fl_lock_function();
|
2012-12-24 15:45:07 +04:00
|
|
|
Fl::reset_marked_text();
|
2011-04-27 15:21:57 +04:00
|
|
|
fl_unlock_function();
|
2011-01-03 19:50:34 +03:00
|
|
|
//NSLog(@"unmarkText");
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRange)selectedRange {
|
2013-01-13 19:25:37 +04:00
|
|
|
Fl_Widget *w = Fl::focus();
|
|
|
|
if (w && w->use_accents_menu()) return selectedRange;
|
2011-01-03 19:50:34 +03:00
|
|
|
return NSMakeRange(NSNotFound, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRange)markedRange {
|
2013-02-08 15:58:19 +04:00
|
|
|
//NSLog(@"markedRange=%d %d", Fl::compose_state > 0?0:NSNotFound, Fl::compose_state);
|
|
|
|
return NSMakeRange(Fl::compose_state > 0?0:NSNotFound, Fl::compose_state);
|
2011-01-03 19:50:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)hasMarkedText {
|
2013-02-08 15:58:19 +04:00
|
|
|
//NSLog(@"hasMarkedText %s", Fl::compose_state > 0?"YES":"NO");
|
|
|
|
return (Fl::compose_state > 0);
|
2011-01-03 19:50:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSAttributedString *)attributedSubstringFromRange:(NSRange)aRange {
|
2013-01-13 19:25:37 +04:00
|
|
|
return [self attributedSubstringForProposedRange:aRange actualRange:NULL];
|
|
|
|
}
|
|
|
|
- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange {
|
2011-01-03 19:50:34 +03:00
|
|
|
//NSLog(@"attributedSubstringFromRange: %d %d",aRange.location,aRange.length);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *)validAttributesForMarkedText {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)firstRectForCharacterRange:(NSRange)aRange {
|
2013-01-13 19:25:37 +04:00
|
|
|
return [self firstRectForCharacterRange:aRange actualRange:NULL];
|
|
|
|
}
|
|
|
|
- (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange {
|
|
|
|
//NSLog(@"firstRectForCharacterRange %d %d actualRange=%p",aRange.location, aRange.length,actualRange);
|
2011-01-09 19:07:13 +03:00
|
|
|
NSRect glyphRect;
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_lock_function();
|
2011-01-09 19:07:13 +03:00
|
|
|
Fl_Widget *focus = Fl::focus();
|
2012-12-14 12:36:13 +04:00
|
|
|
Fl_Window *wfocus = [(FLWindow*)[self window] getFl_Window];
|
|
|
|
if (!focus) focus = wfocus;
|
2011-01-09 19:07:13 +03:00
|
|
|
glyphRect.size.width = 0;
|
2011-01-03 19:50:34 +03:00
|
|
|
|
2013-01-13 19:25:37 +04:00
|
|
|
int x, y, height;
|
|
|
|
if (Fl_X::insertion_point_location(&x, &y, &height)) {
|
2011-01-09 19:07:13 +03:00
|
|
|
glyphRect.origin.x = (CGFloat)x;
|
2012-12-24 15:45:07 +04:00
|
|
|
glyphRect.origin.y = (CGFloat)y;
|
2011-01-09 19:07:13 +03:00
|
|
|
} else {
|
2012-12-20 19:12:32 +04:00
|
|
|
if (focus->as_window()) {
|
|
|
|
glyphRect.origin.x = 0;
|
|
|
|
glyphRect.origin.y = focus->h();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glyphRect.origin.x = focus->x();
|
|
|
|
glyphRect.origin.y = focus->y() + focus->h();
|
|
|
|
}
|
2013-01-13 19:25:37 +04:00
|
|
|
height = 12;
|
2011-01-09 19:07:13 +03:00
|
|
|
}
|
2013-01-13 19:25:37 +04:00
|
|
|
glyphRect.size.height = height;
|
2012-12-20 20:00:04 +04:00
|
|
|
Fl_Window *win = focus->as_window();
|
|
|
|
if (!win) win = focus->window();
|
2012-12-20 19:12:32 +04:00
|
|
|
while (win != NULL && win != wfocus) {
|
2012-12-20 20:00:04 +04:00
|
|
|
glyphRect.origin.x += win->x();
|
2012-12-20 19:12:32 +04:00
|
|
|
glyphRect.origin.y += win->y();
|
|
|
|
win = win->window();
|
|
|
|
}
|
2011-01-03 19:50:34 +03:00
|
|
|
// Convert the rect to screen coordinates
|
2011-01-09 19:07:13 +03:00
|
|
|
glyphRect.origin.y = wfocus->h() - glyphRect.origin.y;
|
2014-09-13 20:49:47 +04:00
|
|
|
glyphRect.origin = [(FLWindow*)[self window] convertBaseToScreen:glyphRect.origin];
|
2013-01-13 19:25:37 +04:00
|
|
|
if (actualRange) *actualRange = aRange;
|
2011-04-11 23:52:41 +04:00
|
|
|
fl_unlock_function();
|
2011-01-03 19:50:34 +03:00
|
|
|
return glyphRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSUInteger)characterIndexForPoint:(NSPoint)aPoint {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-14 13:07:34 +04:00
|
|
|
- (NSInteger)windowLevel {
|
|
|
|
return [[self window] level];
|
|
|
|
}
|
|
|
|
|
2011-01-03 19:50:34 +03:00
|
|
|
- (NSInteger)conversationIdentifier {
|
2012-12-14 12:36:13 +04:00
|
|
|
return identifier;
|
2011-01-03 19:50:34 +03:00
|
|
|
}
|
2014-11-06 18:35:32 +03:00
|
|
|
@end
|
|
|
|
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
|
|
|
|
// For Fl_Gl_Window on retina display, returns 2, otherwise 1
|
|
|
|
int Fl_X::resolution_scaling_factor(Fl_Window* win)
|
|
|
|
{
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
|
|
|
return (win->as_gl_window() && Fl::use_high_res_GL() && win->i->mapped_to_retina()) ? 2 : 1;
|
|
|
|
#else
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NSOpenGLPixelFormat* Fl_X::mode_to_NSOpenGLPixelFormat(int m, const int *alistp)
|
|
|
|
{
|
|
|
|
NSOpenGLPixelFormatAttribute attribs[32];
|
|
|
|
int n = 0;
|
|
|
|
// AGL-style code remains commented out for comparison
|
|
|
|
if (!alistp) {
|
|
|
|
if (m & FL_INDEX) {
|
|
|
|
//list[n++] = AGL_BUFFER_SIZE; list[n++] = 8;
|
|
|
|
} else {
|
|
|
|
//list[n++] = AGL_RGBA;
|
|
|
|
//list[n++] = AGL_GREEN_SIZE;
|
|
|
|
//list[n++] = (m & FL_RGB8) ? 8 : 1;
|
|
|
|
attribs[n++] = NSOpenGLPFAColorSize;
|
|
|
|
attribs[n++] = (m & FL_RGB8) ? 32 : 1;
|
|
|
|
if (m & FL_ALPHA) {
|
|
|
|
//list[n++] = AGL_ALPHA_SIZE;
|
|
|
|
attribs[n++] = NSOpenGLPFAAlphaSize;
|
|
|
|
attribs[n++] = (m & FL_RGB8) ? 8 : 1;
|
|
|
|
}
|
|
|
|
if (m & FL_ACCUM) {
|
|
|
|
//list[n++] = AGL_ACCUM_GREEN_SIZE; list[n++] = 1;
|
|
|
|
attribs[n++] = NSOpenGLPFAAccumSize;
|
|
|
|
attribs[n++] = 1;
|
|
|
|
if (m & FL_ALPHA) {
|
|
|
|
//list[n++] = AGL_ACCUM_ALPHA_SIZE; list[n++] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m & FL_DOUBLE) {
|
|
|
|
//list[n++] = AGL_DOUBLEBUFFER;
|
|
|
|
attribs[n++] = NSOpenGLPFADoubleBuffer;
|
|
|
|
}
|
|
|
|
if (m & FL_DEPTH) {
|
|
|
|
//list[n++] = AGL_DEPTH_SIZE; list[n++] = 24;
|
|
|
|
attribs[n++] = NSOpenGLPFADepthSize;
|
|
|
|
attribs[n++] = 24;
|
|
|
|
}
|
|
|
|
if (m & FL_STENCIL) {
|
|
|
|
//list[n++] = AGL_STENCIL_SIZE; list[n++] = 1;
|
|
|
|
attribs[n++] = NSOpenGLPFAStencilSize;
|
|
|
|
attribs[n++] = 1;
|
|
|
|
}
|
|
|
|
if (m & FL_STEREO) {
|
|
|
|
//list[n++] = AGL_STEREO;
|
|
|
|
attribs[n++] = NSOpenGLPFAStereo;
|
|
|
|
}
|
|
|
|
if (m & FL_MULTISAMPLE) {
|
|
|
|
attribs[n++] = NSOpenGLPFAMultisample,
|
|
|
|
attribs[n++] = NSOpenGLPFASampleBuffers; attribs[n++] = 1;
|
|
|
|
attribs[n++] = NSOpenGLPFASamples; attribs[n++] = 4;
|
|
|
|
}
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
|
|
|
if (fl_mac_os_version >= 100700) {
|
|
|
|
attribs[n++] = NSOpenGLPFAOpenGLProfile;
|
|
|
|
attribs[n++] = NSOpenGLProfileVersionLegacy;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
while (alistp[n] && n < 30) {
|
|
|
|
attribs[n] = alistp[n];
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
attribs[n] = 0;
|
|
|
|
NSOpenGLPixelFormat *pixform = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
|
|
|
|
/*GLint color,alpha,accum,depth;
|
|
|
|
[pixform getValues:&color forAttribute:NSOpenGLPFAColorSize forVirtualScreen:0];
|
|
|
|
[pixform getValues:&alpha forAttribute:NSOpenGLPFAAlphaSize forVirtualScreen:0];
|
|
|
|
[pixform getValues:&accum forAttribute:NSOpenGLPFAAccumSize forVirtualScreen:0];
|
|
|
|
[pixform getValues:&depth forAttribute:NSOpenGLPFADepthSize forVirtualScreen:0];
|
|
|
|
NSLog(@"color=%d alpha=%d accum=%d depth=%d",color,alpha,accum,depth);*/
|
|
|
|
return pixform;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSOpenGLContext* gl_create_context_for_window(NSOpenGLPixelFormat *pixelformat,
|
|
|
|
NSOpenGLContext *shared_ctx, Fl_Window *window)
|
|
|
|
{
|
|
|
|
NSOpenGLContext *context = [[NSOpenGLContext alloc] initWithFormat:pixelformat shareContext:shared_ctx];
|
|
|
|
if (context) [context setView:[fl_xid(window) contentView]];
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_context_update(NSOpenGLContext* ctxt)
|
|
|
|
{
|
|
|
|
[ctxt update];
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_context_flushbuffer(NSOpenGLContext* ctxt)
|
|
|
|
{
|
|
|
|
[ctxt flushBuffer];
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_context_release(NSOpenGLContext* ctxt)
|
|
|
|
{
|
|
|
|
[ctxt release];
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_cleardrawable(void)
|
|
|
|
{
|
|
|
|
[[NSOpenGLContext currentContext] clearDrawable];
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_context_makecurrent(NSOpenGLContext* ctxt)
|
|
|
|
{
|
|
|
|
[ctxt makeCurrentContext];
|
|
|
|
}
|
|
|
|
|
2012-03-23 20:47:53 +04:00
|
|
|
void Fl_Window::fullscreen_x() {
|
|
|
|
_set_fullscreen();
|
|
|
|
/* On OS X < 10.6, it is necessary to recreate the window. This is done
|
|
|
|
with hide+show. */
|
|
|
|
hide();
|
|
|
|
show();
|
|
|
|
Fl::handle(FL_FULLSCREEN, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fl_Window::fullscreen_off_x(int X, int Y, int W, int H) {
|
|
|
|
_clear_fullscreen();
|
|
|
|
hide();
|
|
|
|
resize(X, Y, W, H);
|
|
|
|
show();
|
|
|
|
Fl::handle(FL_FULLSCREEN, this);
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
|
2014-03-22 21:09:07 +04:00
|
|
|
/*
|
|
|
|
* Initialize the given port for redraw and call the window's flush() to actually draw the content
|
|
|
|
*/
|
|
|
|
void Fl_X::flush()
|
|
|
|
{
|
2015-01-04 17:41:50 +03:00
|
|
|
if (w->as_gl_window()) {
|
|
|
|
w->flush();
|
|
|
|
return;
|
|
|
|
} else if (through_drawRect) {
|
|
|
|
make_current_counts = 1;
|
|
|
|
w->flush();
|
|
|
|
make_current_counts = 0;
|
|
|
|
Fl_X::q_release_context();
|
2014-03-22 21:09:07 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// have Cocoa immediately redraw the window's view
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
FLView *view = (FLView*)[xid contentView];
|
2014-06-15 22:45:32 +04:00
|
|
|
fl_x_to_redraw = this;
|
2014-03-22 21:09:07 +04:00
|
|
|
[view setNeedsDisplay:YES];
|
|
|
|
// will send the drawRect: message to the window's view after having prepared the adequate NSGraphicsContext
|
|
|
|
[view displayIfNeededIgnoringOpacity];
|
2014-06-15 22:45:32 +04:00
|
|
|
fl_x_to_redraw = NULL;
|
2014-03-22 21:09:07 +04:00
|
|
|
}
|
|
|
|
|
2014-11-11 19:08:09 +03:00
|
|
|
|
|
|
|
static void set_subwindow_frame(Fl_Window *w) { // maps a subwindow at its correct position/size
|
|
|
|
FLWindow *xid = fl_xid(w);
|
|
|
|
Fl_Window *parent = w->window();
|
|
|
|
FLWindow *pxid = fl_xid(parent);
|
|
|
|
if (!pxid) return;
|
|
|
|
NSRect rp = [pxid frame];
|
|
|
|
// subwindow coordinates are in screen units from bottom just like all windows
|
|
|
|
rp.origin = NSMakePoint(rp.origin.x + w->x(), rp.origin.y + parent->h() - w->y() - w->h());
|
|
|
|
rp.size = NSMakeSize(w->w(), w->h());
|
2014-11-13 16:57:27 +03:00
|
|
|
if (!NSEqualRects(rp, [xid frame])) {
|
|
|
|
[xid setFrame:rp display:YES];
|
2014-11-13 18:33:33 +03:00
|
|
|
}
|
|
|
|
if (![xid parentWindow]) {
|
2014-11-13 16:57:27 +03:00
|
|
|
[pxid addChildWindow:xid ordered:NSWindowAbove]; // needs OS X 10.2
|
|
|
|
[xid orderWindow:NSWindowAbove relativeTo:[pxid windowNumber]]; // necessary under 10.3
|
|
|
|
}
|
2014-11-11 19:08:09 +03:00
|
|
|
}
|
2014-03-22 21:09:07 +04:00
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2009-12-07 01:21:55 +03:00
|
|
|
* go ahead, create that (sub)window
|
|
|
|
*/
|
|
|
|
void Fl_X::make(Fl_Window* w)
|
|
|
|
{
|
|
|
|
Fl_Group::current(0);
|
|
|
|
fl_open_display();
|
2009-12-13 15:03:26 +03:00
|
|
|
NSInteger winlevel = NSNormalWindowLevel;
|
|
|
|
NSUInteger winstyle;
|
2014-11-11 19:08:09 +03:00
|
|
|
if (w->parent()) {
|
|
|
|
w->border(0);
|
|
|
|
fl_show_iconic = 0;
|
|
|
|
}
|
2010-01-14 02:13:59 +03:00
|
|
|
if (w->border()) winstyle = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask;
|
2009-12-13 15:03:26 +03:00
|
|
|
else winstyle = NSBorderlessWindowMask;
|
2009-12-07 01:21:55 +03:00
|
|
|
int xp = w->x();
|
|
|
|
int yp = w->y();
|
|
|
|
int wp = w->w();
|
|
|
|
int hp = w->h();
|
|
|
|
if (w->size_range_set) {
|
2010-01-14 02:13:59 +03:00
|
|
|
if ( w->minh != w->maxh || w->minw != w->maxw) {
|
2014-06-26 23:31:38 +04:00
|
|
|
if (w->border()) winstyle |= NSResizableWindowMask;
|
2010-01-14 02:13:59 +03:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
} else {
|
2010-04-18 10:57:37 +04:00
|
|
|
if (w->resizable()) {
|
2009-12-07 01:21:55 +03:00
|
|
|
Fl_Widget *o = w->resizable();
|
|
|
|
int minw = o->w(); if (minw > 100) minw = 100;
|
|
|
|
int minh = o->h(); if (minh > 100) minh = 100;
|
|
|
|
w->size_range(w->w() - o->w() + minw, w->h() - o->h() + minh, 0, 0);
|
2014-11-11 19:08:09 +03:00
|
|
|
if (w->border()) winstyle |= NSResizableWindowMask;
|
2009-12-07 01:21:55 +03:00
|
|
|
} else {
|
|
|
|
w->size_range(w->w(), w->h(), w->w(), w->h());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int xwm = xp, ywm = yp, bt, bx, by;
|
|
|
|
|
|
|
|
if (!fake_X_wm(w, xwm, ywm, bt, bx, by)) {
|
|
|
|
// menu windows and tooltips
|
2011-04-18 12:18:16 +04:00
|
|
|
if (w->modal()||w->tooltip_window()) {
|
2014-06-16 14:59:46 +04:00
|
|
|
winlevel = modal_window_level();
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2014-11-11 19:08:09 +03:00
|
|
|
}
|
2014-06-26 23:31:38 +04:00
|
|
|
if (w->modal()) {
|
2010-04-18 10:57:37 +04:00
|
|
|
winstyle &= ~NSMiniaturizableWindowMask;
|
2014-06-16 14:59:46 +04:00
|
|
|
winlevel = modal_window_level();
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
else if (w->non_modal()) {
|
2014-06-16 14:59:46 +04:00
|
|
|
winlevel = non_modal_window_level();
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (by+bt) {
|
|
|
|
wp += 2*bx;
|
|
|
|
hp += 2*by+bt;
|
|
|
|
}
|
2011-11-29 18:41:33 +04:00
|
|
|
if (w->force_position()) {
|
2009-12-07 01:21:55 +03:00
|
|
|
if (!Fl::grab()) {
|
|
|
|
xp = xwm; yp = ywm;
|
|
|
|
w->x(xp);w->y(yp);
|
|
|
|
}
|
|
|
|
xp -= bx;
|
|
|
|
yp -= by+bt;
|
|
|
|
}
|
2014-11-11 19:08:09 +03:00
|
|
|
|
2009-12-07 01:21:55 +03:00
|
|
|
Fl_X* x = new Fl_X;
|
|
|
|
x->other_xid = 0; // room for doublebuffering image map. On OS X this is only used by overlay windows
|
|
|
|
x->region = 0;
|
2014-12-17 12:04:01 +03:00
|
|
|
x->subRect(0);
|
2014-06-16 15:17:57 +04:00
|
|
|
x->cursor = NULL;
|
2009-12-07 01:21:55 +03:00
|
|
|
x->gc = 0;
|
2014-12-18 20:32:08 +03:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
2014-12-17 12:04:01 +03:00
|
|
|
if (w->parent()) x->mapped_to_retina( w->top_window()->i->mapped_to_retina() );
|
|
|
|
else x->mapped_to_retina(false);
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
x->changed_resolution(false);
|
2014-12-18 20:32:08 +03:00
|
|
|
#endif
|
2014-12-11 23:09:55 +03:00
|
|
|
|
2009-12-07 01:21:55 +03:00
|
|
|
NSRect crect;
|
2012-04-24 00:12:06 +04:00
|
|
|
if (w->fullscreen_active()) {
|
2014-06-11 13:10:53 +04:00
|
|
|
int top, bottom, left, right;
|
|
|
|
int sx, sy, sw, sh, X, Y, W, H;
|
|
|
|
|
|
|
|
top = w->fullscreen_screen_top;
|
|
|
|
bottom = w->fullscreen_screen_bottom;
|
|
|
|
left = w->fullscreen_screen_left;
|
|
|
|
right = w->fullscreen_screen_right;
|
|
|
|
|
|
|
|
if ((top < 0) || (bottom < 0) || (left < 0) || (right < 0)) {
|
|
|
|
top = Fl::screen_num(w->x(), w->y(), w->w(), w->h());
|
|
|
|
bottom = top;
|
|
|
|
left = top;
|
|
|
|
right = top;
|
|
|
|
}
|
|
|
|
|
|
|
|
Fl::screen_xywh(sx, sy, sw, sh, top);
|
|
|
|
Y = sy;
|
|
|
|
Fl::screen_xywh(sx, sy, sw, sh, bottom);
|
|
|
|
H = sy + sh - Y;
|
|
|
|
Fl::screen_xywh(sx, sy, sw, sh, left);
|
|
|
|
X = sx;
|
|
|
|
Fl::screen_xywh(sx, sy, sw, sh, right);
|
|
|
|
W = sx + sw - X;
|
|
|
|
|
|
|
|
w->resize(X, Y, W, H);
|
|
|
|
|
2012-03-23 20:47:53 +04:00
|
|
|
winstyle = NSBorderlessWindowMask;
|
|
|
|
winlevel = NSStatusWindowLevel;
|
|
|
|
}
|
2014-11-11 19:08:09 +03:00
|
|
|
crect.origin.x = w->x(); // correct origin set later for subwindows
|
Fix STR#2695 & 2697: correct computation of work areas with multiple screens.
This introduces 3 new functions
static void Fl::screen_work_area(X,Y,W,H)
static void Fl::screen_work_area(X,Y,W,H,mx,my)
static void Fl::screen_work_area(X,Y,W,H,screen_no)
that compute screen work areas and are used by FLTK to position menu windows.
The Fl::x(),y(),w(),h() functions are made consistent across platforms: they return
the origin/size of the work area of the main screen (as far as possible, see below).
On the Mac OS platform, all screen functions reflect changes in screen number and
positions without requiring the application to restart.
On the X11 platform, I did not find an API to compute the main screen work area
in all conditions. What's used does compute the correct work area when there's
a single screen, but not when there are several, because it returns an area that
encompasses all screens. The implemented workaround is that Fl::x(),y(),w(),h()
and Fl::screen_work_area(X,Y,W,H,0) return the exact work area when there's
a single screen, and return the full screen area when there are several.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2011-09-29 20:04:24 +04:00
|
|
|
crect.origin.y = main_screen_height - (w->y() + w->h());
|
2009-12-07 01:21:55 +03:00
|
|
|
crect.size.width=w->w();
|
|
|
|
crect.size.height=w->h();
|
2009-12-21 21:43:13 +03:00
|
|
|
FLWindow *cw = [[FLWindow alloc] initWithFl_W:w
|
|
|
|
contentRect:crect
|
2011-04-27 15:21:57 +04:00
|
|
|
styleMask:winstyle];
|
2011-11-14 19:15:03 +04:00
|
|
|
[cw setFrameOrigin:crect.origin];
|
2014-11-30 15:34:21 +03:00
|
|
|
if (!w->parent()) {
|
|
|
|
[cw setHasShadow:YES];
|
|
|
|
[cw setAcceptsMouseMovedEvents:YES];
|
|
|
|
}
|
2014-09-21 18:10:36 +04:00
|
|
|
if (w->shape_data_) {
|
2014-08-27 15:55:57 +04:00
|
|
|
[cw setOpaque:NO]; // shaped windows must be non opaque
|
|
|
|
[cw setBackgroundColor:[NSColor clearColor]]; // and with transparent background color
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
x->xid = cw;
|
2011-11-14 21:10:28 +04:00
|
|
|
x->w = w; w->i = x;
|
|
|
|
x->wait_for_expose = 1;
|
2014-11-11 19:08:09 +03:00
|
|
|
if (!w->parent()) {
|
|
|
|
x->next = Fl_X::first;
|
|
|
|
Fl_X::first = x;
|
|
|
|
} else if (Fl_X::first) {
|
|
|
|
x->next = Fl_X::first->next;
|
|
|
|
Fl_X::first->next = x;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
x->next = NULL;
|
|
|
|
Fl_X::first = x;
|
|
|
|
}
|
2014-11-30 15:34:21 +03:00
|
|
|
FLView *myview = [[FLView alloc] initWithFrame:crect];
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
|
|
|
if (w->as_gl_window() && fl_mac_os_version >= 100700 && Fl::use_high_res_GL()) {
|
|
|
|
[myview setWantsBestResolutionOpenGLSurface:YES];
|
|
|
|
}
|
|
|
|
#endif
|
2009-12-07 01:21:55 +03:00
|
|
|
[cw setContentView:myview];
|
2013-12-01 01:50:00 +04:00
|
|
|
[myview release];
|
2009-12-07 01:21:55 +03:00
|
|
|
[cw setLevel:winlevel];
|
|
|
|
|
2011-05-15 16:34:31 +04:00
|
|
|
q_set_window_title(cw, w->label(), w->iconlabel());
|
2011-11-29 18:41:33 +04:00
|
|
|
if (!w->force_position()) {
|
2009-12-07 01:21:55 +03:00
|
|
|
if (w->modal()) {
|
|
|
|
[cw center];
|
|
|
|
} else if (w->non_modal()) {
|
|
|
|
[cw center];
|
|
|
|
} else {
|
|
|
|
static NSPoint delta = NSZeroPoint;
|
|
|
|
delta = [cw cascadeTopLeftFromPoint:delta];
|
|
|
|
}
|
|
|
|
}
|
2010-12-11 16:33:29 +03:00
|
|
|
if(w->menu_window()) { // make menu windows slightly transparent
|
|
|
|
[cw setAlphaValue:0.97];
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
// Install DnD handlers
|
2013-12-10 16:07:09 +04:00
|
|
|
[myview registerForDraggedTypes:[NSArray arrayWithObjects:utf8_format, NSFilenamesPboardType, nil]];
|
2014-11-11 19:08:09 +03:00
|
|
|
|
2009-12-07 01:21:55 +03:00
|
|
|
if (w->size_range_set) w->size_range_();
|
|
|
|
|
2011-04-18 12:18:16 +04:00
|
|
|
if ( w->border() || (!w->modal() && !w->tooltip_window()) ) {
|
2009-12-07 01:21:55 +03:00
|
|
|
Fl_Tooltip::enter(0);
|
|
|
|
}
|
2012-04-28 04:42:31 +04:00
|
|
|
|
|
|
|
if (w->modal()) Fl::modal_ = w;
|
|
|
|
|
2011-05-11 22:31:28 +04:00
|
|
|
w->set_visible();
|
2011-04-18 12:18:16 +04:00
|
|
|
if ( w->border() || (!w->modal() && !w->tooltip_window()) ) Fl::handle(FL_FOCUS, w);
|
2014-11-11 19:08:09 +03:00
|
|
|
if (!w->parent()) Fl::first_window(w);
|
2014-11-06 18:35:32 +03:00
|
|
|
[cw setDelegate:[FLWindowDelegate singleInstance]];
|
2014-11-30 15:34:21 +03:00
|
|
|
if (fl_show_iconic) {
|
|
|
|
fl_show_iconic = 0;
|
|
|
|
[cw miniaturize:nil];
|
|
|
|
} else if (w->parent()) {
|
|
|
|
[cw setIgnoresMouseEvents:YES]; // needs OS X 10.2
|
|
|
|
// next 2 statements so a subwindow doesn't leak out of its parent window
|
|
|
|
[cw setOpaque:NO];
|
|
|
|
[cw setBackgroundColor:[NSColor clearColor]]; // transparent background color
|
|
|
|
CGRect prect = CGRectMake(0, 0, w->window()->w(), w->window()->h());
|
|
|
|
CGRect srect = CGRectMake(w->x(), w->y(), w->w(), w->h());
|
|
|
|
if (!CGRectContainsRect(prect, srect)) { // if subwindow extends outside its parent window
|
|
|
|
CGRect clip = CGRectIntersection(prect, srect);
|
|
|
|
clip = CGRectOffset(clip, -w->x(), -w->y());
|
|
|
|
clip = fl_cgrectmake_cocoa(clip.origin.x, clip.origin.y, clip.size.width, clip.size.height);
|
2014-12-17 12:04:01 +03:00
|
|
|
x->subRect(new CGRect(clip));
|
2014-11-11 19:08:09 +03:00
|
|
|
}
|
2014-11-30 15:34:21 +03:00
|
|
|
set_subwindow_frame(w);
|
|
|
|
// needed if top window was first displayed miniaturized
|
|
|
|
FLWindow *pxid = fl_xid(w->top_window());
|
|
|
|
[pxid makeFirstResponder:[pxid contentView]];
|
|
|
|
} else {
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
|
|
|
compute_mapped_to_retina(w);
|
|
|
|
x->changed_resolution(false);
|
|
|
|
#endif
|
2014-11-30 15:34:21 +03:00
|
|
|
[cw makeKeyAndOrderFront:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!w->parent()) {
|
|
|
|
crect = [[cw contentView] frame];
|
|
|
|
w->w(int(crect.size.width));
|
|
|
|
w->h(int(crect.size.height));
|
|
|
|
crect = [cw frame];
|
|
|
|
w->x(int(crect.origin.x));
|
|
|
|
w->y(int(main_screen_height - (crect.origin.y + w->h())));
|
2014-12-18 20:32:08 +03:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
2014-12-12 01:25:31 +03:00
|
|
|
compute_mapped_to_retina(w);
|
2014-12-18 20:32:08 +03:00
|
|
|
#endif
|
2014-11-30 15:34:21 +03:00
|
|
|
}
|
|
|
|
|
2009-12-07 01:21:55 +03:00
|
|
|
int old_event = Fl::e_number;
|
|
|
|
w->handle(Fl::e_number = FL_SHOW);
|
|
|
|
Fl::e_number = old_event;
|
|
|
|
|
2012-04-28 04:42:31 +04:00
|
|
|
// if (w->modal()) { Fl::modal_ = w; fl_fix_focus(); }
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2009-12-07 01:21:55 +03:00
|
|
|
* Tell the OS what window sizes we want to allow
|
|
|
|
*/
|
|
|
|
void Fl_Window::size_range_() {
|
|
|
|
int bx, by, bt;
|
|
|
|
get_window_frame_sizes(bx, by, bt);
|
|
|
|
size_range_set = 1;
|
|
|
|
NSSize minSize = { minw, minh + bt };
|
|
|
|
NSSize maxSize = { maxw?maxw:32000, maxh?maxh + bt:32000 };
|
|
|
|
if (i && i->xid) {
|
2011-11-12 17:06:54 +04:00
|
|
|
[i->xid setMinSize:minSize];
|
|
|
|
[i->xid setMaxSize:maxSize];
|
2010-01-14 02:13:59 +03:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2009-12-07 01:21:55 +03:00
|
|
|
* returns pointer to the filename, or null if name ends with ':'
|
|
|
|
*/
|
|
|
|
const char *fl_filename_name( const char *name )
|
|
|
|
{
|
|
|
|
const char *p, *q;
|
|
|
|
if (!name) return (0);
|
2010-01-14 02:13:59 +03:00
|
|
|
for ( p = q = name ; *p ; ) {
|
|
|
|
if ( ( p[0] == ':' ) && ( p[1] == ':' ) ) {
|
2009-12-07 01:21:55 +03:00
|
|
|
q = p+2;
|
|
|
|
p++;
|
|
|
|
}
|
2010-01-14 02:13:59 +03:00
|
|
|
else if (p[0] == '/') {
|
2009-12-07 01:21:55 +03:00
|
|
|
q = p + 1;
|
2010-01-14 02:13:59 +03:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
return q;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2011-05-15 13:42:36 +04:00
|
|
|
* set the window title bar name
|
2009-12-07 01:21:55 +03:00
|
|
|
*/
|
2011-05-15 13:42:36 +04:00
|
|
|
void Fl_Window::label(const char *name, const char *mininame) {
|
2009-12-07 01:21:55 +03:00
|
|
|
Fl_Widget::label(name);
|
2011-05-15 13:42:36 +04:00
|
|
|
iconlabel_ = mininame;
|
2009-12-07 01:21:55 +03:00
|
|
|
if (shown() || i) {
|
2011-11-12 17:06:54 +04:00
|
|
|
q_set_window_title(i->xid, name, mininame);
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2009-12-07 01:21:55 +03:00
|
|
|
* make a window visible
|
|
|
|
*/
|
|
|
|
void Fl_Window::show() {
|
|
|
|
image(Fl::scheme_bg_);
|
|
|
|
if (Fl::scheme_bg_) {
|
|
|
|
labeltype(FL_NORMAL_LABEL);
|
|
|
|
align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
|
|
|
|
} else {
|
|
|
|
labeltype(FL_NO_LABEL);
|
|
|
|
}
|
|
|
|
Fl_Tooltip::exit(this);
|
2014-12-11 23:34:47 +03:00
|
|
|
Fl_X *top = NULL;
|
|
|
|
if (parent()) top = top_window()->i;
|
|
|
|
if (!shown() && (!parent() || (top && ![top->xid isMiniaturized]))) {
|
2009-12-07 01:21:55 +03:00
|
|
|
Fl_X::make(this);
|
|
|
|
} else {
|
2010-01-14 02:13:59 +03:00
|
|
|
if ( !parent() ) {
|
2011-11-12 17:06:54 +04:00
|
|
|
if ([i->xid isMiniaturized]) {
|
2014-11-06 18:35:32 +03:00
|
|
|
i->w->redraw();
|
|
|
|
[i->xid deminiaturize:nil];
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2010-01-14 02:13:59 +03:00
|
|
|
if (!fl_capture) {
|
2014-11-06 18:35:32 +03:00
|
|
|
[i->xid makeKeyAndOrderFront:nil];
|
2010-01-14 02:13:59 +03:00
|
|
|
}
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2009-12-07 01:21:55 +03:00
|
|
|
* resize a window
|
|
|
|
*/
|
|
|
|
void Fl_Window::resize(int X,int Y,int W,int H) {
|
|
|
|
if (W<=0) W = 1; // OS X does not like zero width windows
|
|
|
|
if (H<=0) H = 1;
|
|
|
|
int is_a_resize = (W != w() || H != h());
|
|
|
|
// printf("Fl_Window::resize(X=%d, Y=%d, W=%d, H=%d), is_a_resize=%d, resize_from_system=%p, this=%p\n",
|
|
|
|
// X, Y, W, H, is_a_resize, resize_from_system, this);
|
|
|
|
if (X != x() || Y != y()) set_flag(FORCE_POSITION);
|
2011-11-29 15:50:18 +04:00
|
|
|
else if (!is_a_resize) {
|
|
|
|
resize_from_system = 0;
|
|
|
|
return;
|
|
|
|
}
|
2014-11-11 19:08:09 +03:00
|
|
|
if ( (resize_from_system!=this) && shown()) {
|
2009-12-07 01:21:55 +03:00
|
|
|
if (is_a_resize) {
|
|
|
|
if (resizable()) {
|
|
|
|
if (W<minw) minw = W; // user request for resize takes priority
|
2011-04-05 21:16:35 +04:00
|
|
|
if (maxw && W>maxw) maxw = W; // over a previously set size_range
|
2009-12-07 01:21:55 +03:00
|
|
|
if (H<minh) minh = H;
|
2011-04-05 21:16:35 +04:00
|
|
|
if (maxh && H>maxh) maxh = H;
|
2009-12-07 01:21:55 +03:00
|
|
|
size_range(minw, minh, maxw, maxh);
|
|
|
|
} else {
|
|
|
|
size_range(W, H, W, H);
|
|
|
|
}
|
2014-11-11 19:08:09 +03:00
|
|
|
Fl_Group::resize(X,Y,W,H);
|
2014-11-13 18:33:33 +03:00
|
|
|
if ([i->xid parentWindow]) set_subwindow_frame(this);
|
2014-11-11 19:08:09 +03:00
|
|
|
|
2009-12-07 01:21:55 +03:00
|
|
|
} else {
|
2014-11-30 15:34:21 +03:00
|
|
|
x(X); y(Y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
resize_from_system = 0;
|
|
|
|
if (is_a_resize) {
|
|
|
|
Fl_Group::resize(X,Y,W,H);
|
|
|
|
if (shown()) {
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
x(X); y(Y);
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (is_a_resize) {
|
2014-11-30 15:34:21 +03:00
|
|
|
// make sure that subwindows of this window don't leak out of their parent window
|
|
|
|
NSArray *children = [fl_xid(this) childWindows]; // 10.2
|
|
|
|
NSEnumerator *enumerator = [children objectEnumerator];
|
|
|
|
id child;
|
|
|
|
while ((child = [enumerator nextObject]) != nil) {
|
|
|
|
[[(FLWindow*)child contentView] setNeedsDisplay:YES];
|
|
|
|
Fl_Window *childw = [child getFl_Window];
|
|
|
|
CGRect prect = CGRectMake(0, 0, w(), h());
|
|
|
|
CGRect srect = CGRectMake(childw->x(), childw->y(), childw->w(), childw->h());
|
2014-12-17 12:04:01 +03:00
|
|
|
delete Fl_X::i(childw)->subRect();
|
|
|
|
CGRect *pclip = NULL;
|
2014-11-30 15:34:21 +03:00
|
|
|
if (!CGRectContainsRect(prect, srect)) { // if subwindow extends outside its parent window
|
|
|
|
CGRect clip = CGRectIntersection(prect, srect);
|
|
|
|
clip = CGRectOffset(clip, -childw->x(), -childw->y());
|
|
|
|
clip = fl_cgrectmake_cocoa(clip.origin.x, clip.origin.y, clip.size.width, clip.size.height);
|
2014-12-17 12:04:01 +03:00
|
|
|
pclip = new CGRect(clip);
|
2014-11-30 15:34:21 +03:00
|
|
|
}
|
2014-12-17 12:04:01 +03:00
|
|
|
Fl_X::i(childw)->subRect(pclip);
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2009-12-07 01:21:55 +03:00
|
|
|
* make all drawing go into this window (called by subclass flush() impl.)
|
2014-03-22 21:09:07 +04:00
|
|
|
|
|
|
|
This can be called in 3 different instances:
|
|
|
|
|
2014-12-19 07:53:01 +03:00
|
|
|
1) When a window is created or resized.
|
2014-03-22 21:09:07 +04:00
|
|
|
The system sends the drawRect: message to the window's view after having prepared the current graphics context
|
|
|
|
to draw to this view. Variable through_drawRect is YES, and fl_x_to_redraw is NULL. Processing of drawRect: calls
|
|
|
|
handleUpdateEvent() that calls Fl_X::flush() for the window and its subwindows. Fl_X::flush() calls
|
|
|
|
Fl_Window::flush() that calls Fl_Window::make_current() that only needs to identify the graphics port of the
|
|
|
|
current graphics context. The window's draw() function is then executed.
|
|
|
|
|
|
|
|
2) At each round of the FLTK event loop.
|
|
|
|
Fl::flush() is called, that calls Fl_X::flush() on each window that needs drawing. Fl_X::flush() sets
|
|
|
|
fl_x_to_redraw to this and sends the displayIfNeededIgnoringOpacity message to the window's view.
|
|
|
|
This message makes the system prepare the current graphics context adequately for drawing to this view, and
|
|
|
|
send it the drawRect: message which sets through_drawRect to YES. Processing of the drawRect: message calls
|
|
|
|
Fl_X::flush() for the window which proceeds as in 1) above.
|
|
|
|
|
|
|
|
3) An FLTK application can call Fl_Window::make_current() at any time before it draws to a window.
|
|
|
|
This occurs for instance in the idle callback function of the mandelbrot test program. Variable through_drawRect is NO,
|
|
|
|
so Fl_Window::make_current() creates a new graphics context adequate for the window.
|
|
|
|
Subsequent drawing requests go to this window. CAUTION: it's not possible to call Fl::wait(), Fl::check()
|
|
|
|
nor Fl::ready() while in the draw() function of a widget. Use an idle callback instead.
|
|
|
|
|
2009-12-07 01:21:55 +03:00
|
|
|
*/
|
|
|
|
void Fl_Window::make_current()
|
|
|
|
{
|
2014-06-15 22:45:32 +04:00
|
|
|
if (make_current_counts > 1) return;
|
|
|
|
if (make_current_counts) make_current_counts++;
|
2009-12-07 01:21:55 +03:00
|
|
|
Fl_X::q_release_context();
|
|
|
|
fl_window = i->xid;
|
2014-12-18 20:32:08 +03:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
2014-12-17 12:04:01 +03:00
|
|
|
Fl_X::set_high_resolution( i->mapped_to_retina() );
|
2014-12-18 20:32:08 +03:00
|
|
|
#endif
|
2009-12-07 01:21:55 +03:00
|
|
|
current_ = this;
|
|
|
|
|
2014-11-11 19:08:09 +03:00
|
|
|
NSGraphicsContext *nsgc = through_drawRect ? [NSGraphicsContext currentContext] :
|
2014-03-22 21:09:07 +04:00
|
|
|
[NSGraphicsContext graphicsContextWithWindow:fl_window];
|
|
|
|
i->gc = (CGContextRef)[nsgc graphicsPort];
|
2009-12-07 01:21:55 +03:00
|
|
|
fl_gc = i->gc;
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
// antialiasing must be deactivated because it applies to rectangles too
|
|
|
|
// and escapes even clipping!!!
|
|
|
|
// it gets activated when needed (e.g., draw text)
|
2010-02-02 20:13:55 +03:00
|
|
|
CGContextSetShouldAntialias(fl_gc, false);
|
2011-11-12 17:06:54 +04:00
|
|
|
CGFloat hgt = [[fl_window contentView] frame].size.height;
|
2010-02-02 20:13:55 +03:00
|
|
|
CGContextTranslateCTM(fl_gc, 0.5, hgt-0.5f);
|
|
|
|
CGContextScaleCTM(fl_gc, 1.0f, -1.0f); // now 0,0 is top-left point of the window
|
2014-11-11 19:08:09 +03:00
|
|
|
// for subwindows, limit drawing to inside of parent window
|
2014-12-17 12:04:01 +03:00
|
|
|
if (i->subRect()) CGContextClipToRect(fl_gc, *(i->subRect()));
|
2014-11-11 19:08:09 +03:00
|
|
|
|
|
|
|
// this is the context with origin at top left of (sub)window
|
|
|
|
CGContextSaveGState(fl_gc);
|
2011-01-06 13:24:58 +03:00
|
|
|
#if defined(FLTK_USE_CAIRO)
|
2009-12-07 01:21:55 +03:00
|
|
|
if (Fl::cairo_autolink_context()) Fl::cairo_make_current(this); // capture gc changes automatically to update the cairo context adequately
|
|
|
|
#endif
|
|
|
|
fl_clip_region( 0 );
|
|
|
|
|
2011-01-06 13:24:58 +03:00
|
|
|
#if defined(FLTK_USE_CAIRO)
|
2009-12-07 01:21:55 +03:00
|
|
|
// update the cairo_t context
|
|
|
|
if (Fl::cairo_autolink_context()) Fl::cairo_make_current(this);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper function to manage the current CGContext fl_gc
|
|
|
|
extern void fl_quartz_restore_line_style_();
|
|
|
|
|
|
|
|
// FLTK has only one global graphics state. This function copies the FLTK state into the
|
|
|
|
// current Quartz context
|
|
|
|
void Fl_X::q_fill_context() {
|
|
|
|
if (!fl_gc) return;
|
2010-02-02 20:13:55 +03:00
|
|
|
if ( ! fl_window) { // a bitmap context
|
|
|
|
size_t hgt = CGBitmapContextGetHeight(fl_gc);
|
|
|
|
CGContextTranslateCTM(fl_gc, 0.5, hgt-0.5f);
|
|
|
|
CGContextScaleCTM(fl_gc, 1.0f, -1.0f); // now 0,0 is top-left point of the context
|
|
|
|
}
|
2011-02-06 15:32:23 +03:00
|
|
|
fl_color(fl_graphics_driver->color());
|
2009-12-07 01:21:55 +03:00
|
|
|
fl_quartz_restore_line_style_();
|
|
|
|
}
|
|
|
|
|
|
|
|
// The only way to reset clipping to its original state is to pop the current graphics
|
|
|
|
// state and restore the global state.
|
|
|
|
void Fl_X::q_clear_clipping() {
|
|
|
|
if (!fl_gc) return;
|
|
|
|
CGContextRestoreGState(fl_gc);
|
|
|
|
CGContextSaveGState(fl_gc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Give the Quartz context back to the system
|
|
|
|
void Fl_X::q_release_context(Fl_X *x) {
|
|
|
|
if (x && x->gc!=fl_gc) return;
|
|
|
|
if (!fl_gc) return;
|
2014-01-19 14:00:37 +04:00
|
|
|
CGContextRestoreGState(fl_gc); // KEEP IT: matches the CGContextSaveGState of make_current
|
2014-11-19 19:23:36 +03:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
|
|
|
Fl_X::set_high_resolution(false);
|
|
|
|
#endif
|
2014-01-19 14:00:37 +04:00
|
|
|
CGContextFlush(fl_gc);
|
2009-12-07 01:21:55 +03:00
|
|
|
fl_gc = 0;
|
2011-01-06 13:24:58 +03:00
|
|
|
#if defined(FLTK_USE_CAIRO)
|
2009-12-07 01:21:55 +03:00
|
|
|
if (Fl::cairo_autolink_context()) Fl::cairo_make_current((Fl_Window*) 0); // capture gc changes automatically to update the cairo context adequately
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-02-21 21:40:15 +03:00
|
|
|
void Fl_X::q_begin_image(CGRect &rect, int cx, int cy, int w, int h) {
|
|
|
|
CGContextSaveGState(fl_gc);
|
|
|
|
CGRect r2 = rect;
|
|
|
|
r2.origin.x -= 0.5f;
|
|
|
|
r2.origin.y -= 0.5f;
|
|
|
|
CGContextClipToRect(fl_gc, r2);
|
|
|
|
// move graphics context to origin of vertically reversed image
|
|
|
|
CGContextTranslateCTM(fl_gc, rect.origin.x - cx - 0.5, rect.origin.y - cy + h - 0.5);
|
|
|
|
CGContextScaleCTM(fl_gc, 1, -1);
|
|
|
|
rect.origin.x = rect.origin.y = 0;
|
|
|
|
rect.size.width = w;
|
|
|
|
rect.size.height = h;
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
void Fl_X::q_end_image() {
|
|
|
|
CGContextRestoreGState(fl_gc);
|
|
|
|
}
|
|
|
|
|
2014-11-19 19:23:36 +03:00
|
|
|
void Fl_X::set_high_resolution(bool new_val)
|
|
|
|
{
|
|
|
|
Fl_Display_Device::high_res_window_ = new_val;
|
|
|
|
}
|
|
|
|
|
2014-11-08 21:14:31 +03:00
|
|
|
void Fl_Copy_Surface::complete_copy_pdf_and_tiff()
|
|
|
|
{
|
|
|
|
CGContextRestoreGState(gc);
|
|
|
|
CGContextEndPage(gc);
|
|
|
|
CGContextRelease(gc);
|
|
|
|
NSPasteboard *clip = [NSPasteboard generalPasteboard];
|
|
|
|
[clip declareTypes:[NSArray arrayWithObjects:@"com.adobe.pdf", @"public.tiff", nil] owner:nil];
|
|
|
|
[clip setData:(NSData*)pdfdata forType:@"com.adobe.pdf"];
|
|
|
|
//second, transform this PDF to a bitmap image and put it as tiff in clipboard
|
|
|
|
NSPDFImageRep *vectorial = [[NSPDFImageRep alloc] initWithData:(NSData*)pdfdata];
|
|
|
|
CFRelease(pdfdata);
|
|
|
|
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
|
|
|
|
pixelsWide:width
|
|
|
|
pixelsHigh:height
|
|
|
|
bitsPerSample:8
|
|
|
|
samplesPerPixel:3
|
|
|
|
hasAlpha:NO
|
|
|
|
isPlanar:NO
|
|
|
|
colorSpaceName:NSDeviceRGBColorSpace
|
|
|
|
bytesPerRow:width*4
|
|
|
|
bitsPerPixel:32];
|
|
|
|
memset([bitmap bitmapData], -1, [bitmap bytesPerRow] * [bitmap pixelsHigh]);
|
|
|
|
NSDictionary *dict = [NSDictionary dictionaryWithObject:bitmap
|
|
|
|
forKey:NSGraphicsContextDestinationAttributeName];
|
|
|
|
NSGraphicsContext *oldgc = [NSGraphicsContext currentContext];
|
|
|
|
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithAttributes:dict]];
|
|
|
|
[vectorial draw];
|
|
|
|
[vectorial release];
|
|
|
|
[NSGraphicsContext setCurrentContext:oldgc];
|
|
|
|
[clip setData:[bitmap TIFFRepresentation] forType:@"public.tiff"];
|
|
|
|
[bitmap release];
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
// Copy & Paste fltk implementation.
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static void convert_crlf(char * s, size_t len)
|
|
|
|
{
|
|
|
|
// turn all \r characters into \n:
|
|
|
|
for (size_t x = 0; x < len; x++) if (s[x] == '\r') s[x] = '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
// fltk 1.3 clipboard support constant definitions:
|
2013-09-24 20:25:29 +04:00
|
|
|
static NSString *calc_utf8_format(void)
|
2013-09-23 23:00:15 +04:00
|
|
|
{
|
2013-12-10 16:07:09 +04:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
|
|
|
|
#define NSPasteboardTypeString @"public.utf8-plain-text"
|
|
|
|
#endif
|
|
|
|
if (fl_mac_os_version >= 100600) return NSPasteboardTypeString;
|
2013-09-23 23:00:15 +04:00
|
|
|
return NSStringPboardType;
|
|
|
|
}
|
|
|
|
|
2009-12-07 01:21:55 +03:00
|
|
|
// clipboard variables definitions :
|
2014-03-22 21:09:07 +04:00
|
|
|
char *fl_selection_buffer[2] = {NULL, NULL};
|
|
|
|
int fl_selection_length[2] = {0, 0};
|
2009-12-07 01:21:55 +03:00
|
|
|
static int fl_selection_buffer_length[2];
|
|
|
|
|
2013-09-11 16:54:40 +04:00
|
|
|
extern void fl_trigger_clipboard_notify(int source);
|
|
|
|
|
|
|
|
void fl_clipboard_notify_change() {
|
|
|
|
// No need to do anything here...
|
|
|
|
}
|
|
|
|
|
|
|
|
static void clipboard_check(void)
|
|
|
|
{
|
2014-11-07 20:08:13 +03:00
|
|
|
static NSInteger oldcount = -1;
|
|
|
|
NSInteger newcount = [[NSPasteboard generalPasteboard] changeCount];
|
|
|
|
if (newcount == oldcount) return;
|
|
|
|
oldcount = newcount;
|
2013-09-11 16:54:40 +04:00
|
|
|
fl_trigger_clipboard_notify(1);
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
/*
|
2009-12-07 01:21:55 +03:00
|
|
|
* create a selection
|
|
|
|
* stuff: pointer to selected data
|
2013-09-23 19:01:54 +04:00
|
|
|
* len: size of selected data
|
2014-05-23 20:47:21 +04:00
|
|
|
* type: always "plain/text" for now
|
2009-12-07 01:21:55 +03:00
|
|
|
*/
|
2014-05-23 20:47:21 +04:00
|
|
|
void Fl::copy(const char *stuff, int len, int clipboard, const char *type) {
|
2009-12-07 01:21:55 +03:00
|
|
|
if (!stuff || len<0) return;
|
|
|
|
if (len+1 > fl_selection_buffer_length[clipboard]) {
|
|
|
|
delete[] fl_selection_buffer[clipboard];
|
|
|
|
fl_selection_buffer[clipboard] = new char[len+100];
|
|
|
|
fl_selection_buffer_length[clipboard] = len+100;
|
|
|
|
}
|
|
|
|
memcpy(fl_selection_buffer[clipboard], stuff, len);
|
|
|
|
fl_selection_buffer[clipboard][len] = 0; // needed for direct paste
|
|
|
|
fl_selection_length[clipboard] = len;
|
|
|
|
if (clipboard) {
|
|
|
|
CFDataRef text = CFDataCreate(kCFAllocatorDefault, (UInt8*)fl_selection_buffer[1], len);
|
|
|
|
if (text==NULL) return; // there was a pb creating the object, abort.
|
2013-09-12 16:21:57 +04:00
|
|
|
NSPasteboard *clip = [NSPasteboard generalPasteboard];
|
|
|
|
[clip declareTypes:[NSArray arrayWithObject:utf8_format] owner:nil];
|
|
|
|
[clip setData:(NSData*)text forType:utf8_format];
|
2009-12-07 01:21:55 +03:00
|
|
|
CFRelease(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 20:47:21 +04:00
|
|
|
static int get_plain_text_from_clipboard(char **buffer, int previous_length)
|
|
|
|
{
|
|
|
|
NSInteger length = 0;
|
|
|
|
NSPasteboard *clip = [NSPasteboard generalPasteboard];
|
|
|
|
NSString *found = [clip availableTypeFromArray:[NSArray arrayWithObjects:utf8_format, @"public.utf16-plain-text", @"com.apple.traditional-mac-plain-text", nil]];
|
|
|
|
if (found) {
|
|
|
|
NSData *data = [clip dataForType:found];
|
|
|
|
if (data) {
|
|
|
|
NSInteger len;
|
|
|
|
char *aux_c = NULL;
|
|
|
|
if (![found isEqualToString:utf8_format]) {
|
|
|
|
NSString *auxstring;
|
|
|
|
auxstring = (NSString *)CFStringCreateWithBytes(NULL,
|
|
|
|
(const UInt8*)[data bytes],
|
|
|
|
[data length],
|
|
|
|
[found isEqualToString:@"public.utf16-plain-text"] ? kCFStringEncodingUnicode : kCFStringEncodingMacRoman,
|
|
|
|
false);
|
|
|
|
aux_c = strdup([auxstring UTF8String]);
|
|
|
|
[auxstring release];
|
|
|
|
len = strlen(aux_c) + 1;
|
|
|
|
}
|
|
|
|
else len = [data length] + 1;
|
|
|
|
if ( len >= previous_length ) {
|
|
|
|
length = len;
|
|
|
|
delete[] *buffer;
|
|
|
|
*buffer = new char[len];
|
|
|
|
}
|
|
|
|
if (![found isEqualToString:utf8_format]) {
|
|
|
|
strcpy(*buffer, aux_c);
|
|
|
|
free(aux_c);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
[data getBytes:*buffer];
|
|
|
|
}
|
|
|
|
(*buffer)[len - 1] = 0;
|
|
|
|
length = len - 1;
|
|
|
|
convert_crlf(*buffer, len - 1); // turn all \r characters into \n:
|
|
|
|
Fl::e_clipboard_type = Fl::clipboard_plain_text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Fl_Image* get_image_from_clipboard()
|
|
|
|
{
|
|
|
|
Fl_RGB_Image *image = NULL;
|
|
|
|
uchar *imagedata;
|
|
|
|
NSBitmapImageRep *bitmap;
|
|
|
|
NSPasteboard *clip = [NSPasteboard generalPasteboard];
|
|
|
|
NSArray *present = [clip types]; // types in pasteboard in order of decreasing preference
|
|
|
|
NSArray *possible = [NSArray arrayWithObjects:@"com.adobe.pdf", @"public.tiff", @"com.apple.pict", nil];
|
|
|
|
NSString *found = nil;
|
|
|
|
NSUInteger rank;
|
|
|
|
for (rank = 0; rank < [present count]; rank++) { // find first of possible types present in pasteboard
|
|
|
|
for (NSUInteger i = 0; i < [possible count]; i++) {
|
|
|
|
if ([[present objectAtIndex:rank] isEqualToString:[possible objectAtIndex:i]]) {
|
|
|
|
found = [present objectAtIndex:rank];
|
|
|
|
goto after_loop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
after_loop:
|
|
|
|
if (found) {
|
|
|
|
NSData *data = [clip dataForType:found];
|
|
|
|
if (data) {
|
|
|
|
if ([found isEqualToString:@"public.tiff"]) {
|
|
|
|
bitmap = [NSBitmapImageRep imageRepWithData:data];
|
|
|
|
int bpp = [bitmap bytesPerPlane];
|
|
|
|
int bpr = [bitmap bytesPerRow];
|
|
|
|
int depth = [bitmap samplesPerPixel], w = bpr/depth, h = bpp/bpr;
|
|
|
|
imagedata = new uchar[w * h * depth];
|
|
|
|
memcpy(imagedata, [bitmap bitmapData], w * h * depth);
|
|
|
|
image = new Fl_RGB_Image(imagedata, w, h, depth);
|
|
|
|
image->alloc_array = 1;
|
|
|
|
}
|
|
|
|
else if ([found isEqualToString:@"com.adobe.pdf"] || [found isEqualToString:@"com.apple.pict"]) {
|
|
|
|
NSRect rect;
|
|
|
|
NSImageRep *vectorial;
|
|
|
|
NSAffineTransform *dilate = [NSAffineTransform transform];
|
|
|
|
if ([found isEqualToString:@"com.adobe.pdf"] ) {
|
|
|
|
vectorial = [NSPDFImageRep imageRepWithData:data];
|
|
|
|
rect = [(NSPDFImageRep*)vectorial bounds]; // in points = 1/72 inch
|
|
|
|
Fl_Window *win = Fl::first_window();
|
|
|
|
int screen_num = win ? Fl::screen_num(win->x(), win->y(), win->w(), win->h()) : 0;
|
|
|
|
float hr, vr;
|
|
|
|
Fl::screen_dpi(hr, vr, screen_num); // 1 inch = hr pixels = 72 points -> hr/72 pixel/point
|
|
|
|
CGFloat scale = hr/72;
|
|
|
|
[dilate scaleBy:scale];
|
|
|
|
rect.size.width *= scale;
|
|
|
|
rect.size.height *= scale;
|
|
|
|
rect = NSIntegralRect(rect);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
vectorial = [NSPICTImageRep imageRepWithData:data];
|
|
|
|
rect = [(NSPICTImageRep*)vectorial boundingBox]; // in pixel, no scaling required
|
|
|
|
}
|
|
|
|
imagedata = new uchar[(int)(rect.size.width * rect.size.height) * 4];
|
|
|
|
memset(imagedata, -1, (int)(rect.size.width * rect.size.height) * 4);
|
|
|
|
bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&imagedata
|
|
|
|
pixelsWide:rect.size.width
|
|
|
|
pixelsHigh:rect.size.height
|
|
|
|
bitsPerSample:8
|
|
|
|
samplesPerPixel:3
|
|
|
|
hasAlpha:NO
|
|
|
|
isPlanar:NO
|
|
|
|
colorSpaceName:NSDeviceRGBColorSpace
|
|
|
|
bytesPerRow:rect.size.width*4
|
|
|
|
bitsPerPixel:32];
|
|
|
|
NSDictionary *dict = [NSDictionary dictionaryWithObject:bitmap
|
|
|
|
forKey:NSGraphicsContextDestinationAttributeName];
|
|
|
|
NSGraphicsContext *oldgc = [NSGraphicsContext currentContext];
|
|
|
|
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithAttributes:dict]];
|
|
|
|
[dilate concat];
|
|
|
|
[vectorial draw];
|
|
|
|
[NSGraphicsContext setCurrentContext:oldgc];
|
|
|
|
[bitmap release];
|
|
|
|
image = new Fl_RGB_Image(imagedata, rect.size.width, rect.size.height, 4);
|
|
|
|
image->alloc_array = 1;
|
|
|
|
}
|
|
|
|
Fl::e_clipboard_type = Fl::clipboard_image;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return image;
|
|
|
|
}
|
2014-03-22 21:09:07 +04:00
|
|
|
|
2009-12-07 01:21:55 +03:00
|
|
|
// Call this when a "paste" operation happens:
|
2014-05-23 20:47:21 +04:00
|
|
|
void Fl::paste(Fl_Widget &receiver, int clipboard, const char *type) {
|
|
|
|
if (type[0] == 0) type = Fl::clipboard_plain_text;
|
2009-12-07 01:21:55 +03:00
|
|
|
if (clipboard) {
|
2014-05-23 20:47:21 +04:00
|
|
|
Fl::e_clipboard_type = "";
|
|
|
|
if (strcmp(type, Fl::clipboard_plain_text) == 0) {
|
|
|
|
fl_selection_length[1] = get_plain_text_from_clipboard( &fl_selection_buffer[1], fl_selection_length[1]);
|
|
|
|
}
|
|
|
|
else if (strcmp(type, Fl::clipboard_image) == 0) {
|
|
|
|
Fl::e_clipboard_data = get_image_from_clipboard( );
|
|
|
|
if (Fl::e_clipboard_data) {
|
|
|
|
int done = receiver.handle(FL_PASTE);
|
|
|
|
Fl::e_clipboard_type = "";
|
|
|
|
if (done == 0) {
|
|
|
|
delete (Fl_Image*)Fl::e_clipboard_data;
|
|
|
|
Fl::e_clipboard_data = NULL;
|
2014-03-22 21:09:07 +04:00
|
|
|
}
|
2010-01-14 02:13:59 +03:00
|
|
|
}
|
2014-05-23 20:47:21 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fl_selection_length[1] = 0;
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
Fl::e_text = fl_selection_buffer[clipboard];
|
|
|
|
Fl::e_length = fl_selection_length[clipboard];
|
2014-05-23 20:47:21 +04:00
|
|
|
if (!Fl::e_length) Fl::e_text = (char *)"";
|
2009-12-07 01:21:55 +03:00
|
|
|
receiver.handle(FL_PASTE);
|
|
|
|
}
|
|
|
|
|
2014-05-23 20:47:21 +04:00
|
|
|
int Fl::clipboard_contains(const char *type) {
|
|
|
|
NSString *found = nil;
|
|
|
|
if (strcmp(type, Fl::clipboard_plain_text) == 0) {
|
|
|
|
found = [[NSPasteboard generalPasteboard] availableTypeFromArray:[NSArray arrayWithObjects:utf8_format, @"public.utf16-plain-text", @"com.apple.traditional-mac-plain-text", nil]];
|
|
|
|
}
|
|
|
|
else if (strcmp(type, Fl::clipboard_image) == 0) {
|
|
|
|
found = [[NSPasteboard generalPasteboard] availableTypeFromArray:[NSArray arrayWithObjects:@"public.tiff", @"com.adobe.pdf", @"com.apple.pict", nil]];
|
|
|
|
}
|
|
|
|
return found != nil;
|
|
|
|
}
|
|
|
|
|
2010-12-19 01:31:01 +03:00
|
|
|
void Fl_X::destroy() {
|
2014-11-11 19:08:09 +03:00
|
|
|
if (xid) {
|
2011-11-12 17:06:54 +04:00
|
|
|
[xid close];
|
2010-01-14 02:13:59 +03:00
|
|
|
}
|
2014-12-17 12:04:01 +03:00
|
|
|
delete subRect();
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
2010-12-19 01:31:01 +03:00
|
|
|
void Fl_X::map() {
|
2014-11-11 19:08:09 +03:00
|
|
|
if (w && xid && ![xid parentWindow]) { // 10.2
|
|
|
|
// after a subwindow has been unmapped, it has lost its parent window and its frame may be wrong
|
|
|
|
set_subwindow_frame(w);
|
2010-01-14 02:13:59 +03:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
//+ link to window list
|
|
|
|
if (w && w->parent()) {
|
2014-11-30 15:34:21 +03:00
|
|
|
w->redraw(); // possibly not necessary
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2014-06-16 15:17:57 +04:00
|
|
|
if (cursor) {
|
|
|
|
[(NSCursor*)cursor release];
|
|
|
|
cursor = NULL;
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
2010-12-19 01:31:01 +03:00
|
|
|
void Fl_X::unmap() {
|
2014-11-11 19:08:09 +03:00
|
|
|
if (w && xid) {
|
|
|
|
if (w->parent()) [[xid parentWindow] removeChildWindow:xid]; // necessary with at least 10.5
|
2011-11-12 17:06:54 +04:00
|
|
|
[xid orderOut:nil];
|
2010-01-14 02:13:59 +03:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
2010-12-19 01:31:01 +03:00
|
|
|
// intersects current and x,y,w,h rectangle and returns result as a new Fl_Region
|
|
|
|
Fl_Region Fl_X::intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h)
|
2009-12-07 01:21:55 +03:00
|
|
|
{
|
2010-01-14 02:13:59 +03:00
|
|
|
if (current == NULL) return XRectangleRegion(x,y,w,h);
|
2010-03-14 21:07:24 +03:00
|
|
|
CGRect r = fl_cgrectmake_cocoa(x, y, w, h);
|
2009-12-07 01:21:55 +03:00
|
|
|
Fl_Region outr = (Fl_Region)malloc(sizeof(*outr));
|
|
|
|
outr->count = current->count;
|
|
|
|
outr->rects =(CGRect*)malloc(outr->count * sizeof(CGRect));
|
|
|
|
int j = 0;
|
|
|
|
for(int i = 0; i < current->count; i++) {
|
2010-01-14 02:13:59 +03:00
|
|
|
CGRect test = CGRectIntersection(current->rects[i], r);
|
|
|
|
if (!CGRectIsEmpty(test)) outr->rects[j++] = test;
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2010-01-14 02:13:59 +03:00
|
|
|
if (j) {
|
|
|
|
outr->count = j;
|
|
|
|
outr->rects = (CGRect*)realloc(outr->rects, outr->count * sizeof(CGRect));
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
else {
|
2010-01-14 02:13:59 +03:00
|
|
|
XDestroyRegion(outr);
|
|
|
|
outr = XRectangleRegion(0,0,0,0);
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
return outr;
|
|
|
|
}
|
|
|
|
|
2010-12-19 01:31:01 +03:00
|
|
|
void Fl_X::collapse() {
|
2011-11-12 17:06:54 +04:00
|
|
|
[xid miniaturize:nil];
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static NSImage *CGBitmapContextToNSImage(CGContextRef c)
|
2010-01-14 02:13:59 +03:00
|
|
|
// the returned NSImage is autoreleased
|
2009-12-07 01:21:55 +03:00
|
|
|
{
|
2013-04-30 12:56:28 +04:00
|
|
|
NSImage* image;
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
|
|
|
|
if (fl_mac_os_version >= 100600) {
|
|
|
|
CGImageRef cgimg = CGBitmapContextCreateImage(c); // requires 10.4
|
|
|
|
image = [[NSImage alloc] initWithCGImage:cgimg size:NSZeroSize]; // requires 10.6
|
|
|
|
CFRelease(cgimg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2014-11-11 19:08:09 +03:00
|
|
|
NSBitmapImageRep *imagerep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
|
2014-03-22 21:09:07 +04:00
|
|
|
pixelsWide:CGBitmapContextGetWidth(c)
|
|
|
|
pixelsHigh:CGBitmapContextGetHeight(c)
|
|
|
|
bitsPerSample:8
|
|
|
|
samplesPerPixel:4
|
|
|
|
hasAlpha:YES
|
|
|
|
isPlanar:NO
|
|
|
|
colorSpaceName:NSDeviceRGBColorSpace
|
|
|
|
bytesPerRow:CGBitmapContextGetBytesPerRow(c)
|
|
|
|
bitsPerPixel:CGBitmapContextGetBitsPerPixel(c)];
|
2014-11-11 19:08:09 +03:00
|
|
|
memcpy([imagerep bitmapData], CGBitmapContextGetData(c), [imagerep bytesPerRow] * [imagerep pixelsHigh]);
|
|
|
|
image = [[NSImage alloc] initWithSize:NSMakeSize([imagerep pixelsWide], [imagerep pixelsHigh])];
|
|
|
|
[image addRepresentation:imagerep];
|
2014-03-22 21:09:07 +04:00
|
|
|
[imagerep release];
|
2013-04-30 12:56:28 +04:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
return [image autorelease];
|
|
|
|
}
|
|
|
|
|
2014-06-16 15:17:57 +04:00
|
|
|
int Fl_X::set_cursor(Fl_Cursor c)
|
2009-12-07 01:21:55 +03:00
|
|
|
{
|
2014-06-16 15:17:57 +04:00
|
|
|
if (cursor) {
|
|
|
|
[(NSCursor*)cursor release];
|
|
|
|
cursor = NULL;
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (c) {
|
2014-06-16 15:17:57 +04:00
|
|
|
case FL_CURSOR_ARROW: cursor = [NSCursor arrowCursor]; break;
|
|
|
|
case FL_CURSOR_CROSS: cursor = [NSCursor crosshairCursor]; break;
|
|
|
|
case FL_CURSOR_INSERT: cursor = [NSCursor IBeamCursor]; break;
|
|
|
|
case FL_CURSOR_HAND: cursor = [NSCursor pointingHandCursor]; break;
|
|
|
|
case FL_CURSOR_MOVE: cursor = [NSCursor openHandCursor]; break;
|
|
|
|
case FL_CURSOR_NS: cursor = [NSCursor resizeUpDownCursor]; break;
|
|
|
|
case FL_CURSOR_WE: cursor = [NSCursor resizeLeftRightCursor]; break;
|
|
|
|
case FL_CURSOR_N: cursor = [NSCursor resizeUpCursor]; break;
|
|
|
|
case FL_CURSOR_E: cursor = [NSCursor resizeRightCursor]; break;
|
|
|
|
case FL_CURSOR_W: cursor = [NSCursor resizeLeftCursor]; break;
|
|
|
|
case FL_CURSOR_S: cursor = [NSCursor resizeDownCursor]; break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
[(NSCursor*)cursor retain];
|
|
|
|
|
|
|
|
[(NSWindow*)xid invalidateCursorRectsForView:[(NSWindow*)xid contentView]];
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
|
|
|
|
if (cursor) {
|
|
|
|
[(NSCursor*)cursor release];
|
|
|
|
cursor = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((hotx < 0) || (hotx >= image->w()))
|
|
|
|
return 0;
|
|
|
|
if ((hoty < 0) || (hoty >= image->h()))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// OS X >= 10.6 can create a NSImage from a CGImage, but we need to
|
|
|
|
// support older versions, hence this pesky handling.
|
|
|
|
|
|
|
|
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc]
|
|
|
|
initWithBitmapDataPlanes:NULL
|
|
|
|
pixelsWide:image->w()
|
|
|
|
pixelsHigh:image->h()
|
|
|
|
bitsPerSample:8
|
|
|
|
samplesPerPixel:image->d()
|
|
|
|
hasAlpha:!(image->d() & 1)
|
|
|
|
isPlanar:NO
|
|
|
|
colorSpaceName:(image->d()<=2) ? NSDeviceWhiteColorSpace : NSDeviceRGBColorSpace
|
|
|
|
bytesPerRow:(image->w() * image->d())
|
|
|
|
bitsPerPixel:(image->d()*8)];
|
|
|
|
|
|
|
|
// Alpha needs to be premultiplied for this format
|
|
|
|
|
|
|
|
const uchar *i = (const uchar*)*image->data();
|
|
|
|
unsigned char *o = [bitmap bitmapData];
|
|
|
|
for (int y = 0;y < image->h();y++) {
|
2014-06-17 15:13:55 +04:00
|
|
|
if (!(image->d() & 1)) {
|
2014-06-16 15:17:57 +04:00
|
|
|
for (int x = 0;x < image->w();x++) {
|
|
|
|
unsigned int alpha;
|
|
|
|
if (image->d() == 4) {
|
|
|
|
alpha = i[3];
|
|
|
|
*o++ = (unsigned char)((unsigned int)*i++ * alpha / 255);
|
|
|
|
*o++ = (unsigned char)((unsigned int)*i++ * alpha / 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
alpha = i[1];
|
|
|
|
*o++ = (unsigned char)((unsigned int)*i++ * alpha / 255);
|
|
|
|
*o++ = alpha;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No alpha, so we can just copy everything directly.
|
|
|
|
int len = image->w() * image->d();
|
|
|
|
memcpy(o, i, len);
|
|
|
|
o += len;
|
|
|
|
i += len;
|
|
|
|
}
|
|
|
|
i += image->ld();
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2014-06-16 15:17:57 +04:00
|
|
|
|
|
|
|
NSImage *nsimage = [[NSImage alloc]
|
|
|
|
initWithSize:NSMakeSize(image->w(), image->h())];
|
|
|
|
|
|
|
|
[nsimage addRepresentation:bitmap];
|
|
|
|
|
|
|
|
cursor = [[NSCursor alloc]
|
|
|
|
initWithImage:nsimage
|
|
|
|
hotSpot:NSMakePoint(hotx, hoty)];
|
|
|
|
|
|
|
|
[(NSWindow*)xid invalidateCursorRectsForView:[(NSWindow*)xid contentView]];
|
|
|
|
|
|
|
|
[bitmap release];
|
|
|
|
[nsimage release];
|
|
|
|
|
|
|
|
return 1;
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
2009-12-09 02:15:30 +03:00
|
|
|
@interface FLaboutItemTarget : NSObject
|
|
|
|
{
|
|
|
|
}
|
2014-11-15 17:55:15 +03:00
|
|
|
- (BOOL)validateMenuItem:(NSMenuItem *)item;
|
2009-12-09 02:15:30 +03:00
|
|
|
- (void)showPanel;
|
2010-03-14 21:07:24 +03:00
|
|
|
- (void)printPanel;
|
2014-11-15 17:55:15 +03:00
|
|
|
- (void)terminate:(id)sender;
|
2009-12-09 02:15:30 +03:00
|
|
|
@end
|
|
|
|
@implementation FLaboutItemTarget
|
2014-11-15 17:55:15 +03:00
|
|
|
- (BOOL)validateMenuItem:(NSMenuItem *)item
|
|
|
|
{ // invalidate the Quit item of the application menu when running modal
|
|
|
|
if (!Fl::modal() || [item action] != @selector(terminate:)) return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
2009-12-09 02:15:30 +03:00
|
|
|
- (void)showPanel
|
|
|
|
{
|
2009-12-12 21:26:12 +03:00
|
|
|
NSDictionary *options;
|
|
|
|
options = [NSDictionary dictionaryWithObjectsAndKeys:
|
2011-07-11 18:53:07 +04:00
|
|
|
[[[NSAttributedString alloc]
|
|
|
|
initWithString:[NSString stringWithFormat:@" GUI with FLTK %d.%d",
|
|
|
|
FL_MAJOR_VERSION, FL_MINOR_VERSION ]] autorelease], @"Credits",
|
2009-12-12 21:26:12 +03:00
|
|
|
nil];
|
2011-07-11 18:53:07 +04:00
|
|
|
[NSApp orderFrontStandardAboutPanelWithOptions:options];
|
2011-10-26 16:42:41 +04:00
|
|
|
}
|
2011-02-24 19:58:00 +03:00
|
|
|
//#include <FL/Fl_PostScript.H>
|
2010-03-14 21:07:24 +03:00
|
|
|
- (void)printPanel
|
2014-03-22 21:09:07 +04:00
|
|
|
{
|
2010-03-14 21:07:24 +03:00
|
|
|
Fl_Printer printer;
|
2010-05-27 21:20:18 +04:00
|
|
|
//Fl_PostScript_File_Device printer;
|
2011-04-16 01:38:05 +04:00
|
|
|
int w, h, ww, wh;
|
2010-03-14 21:07:24 +03:00
|
|
|
Fl_Window *win = Fl::first_window();
|
|
|
|
if(!win) return;
|
2014-11-11 19:08:09 +03:00
|
|
|
if (win->parent()) win = win->top_window();
|
2010-03-14 21:07:24 +03:00
|
|
|
if( printer.start_job(1) ) return;
|
|
|
|
if( printer.start_page() ) return;
|
2011-07-11 17:52:16 +04:00
|
|
|
fl_lock_function();
|
2010-03-14 21:07:24 +03:00
|
|
|
// scale the printer device so that the window fits on the page
|
|
|
|
float scale = 1;
|
|
|
|
printer.printable_rect(&w, &h);
|
2011-04-16 01:38:05 +04:00
|
|
|
ww = win->decorated_w();
|
|
|
|
wh = win->decorated_h();
|
|
|
|
if (ww>w || wh>h) {
|
2010-03-14 21:07:24 +03:00
|
|
|
scale = (float)w/win->w();
|
2011-04-05 20:20:02 +04:00
|
|
|
if ((float)h/wh < scale) scale = (float)h/wh;
|
2011-02-04 12:17:45 +03:00
|
|
|
printer.scale(scale);
|
2011-09-08 12:09:20 +04:00
|
|
|
printer.printable_rect(&w, &h);
|
2010-03-14 21:07:24 +03:00
|
|
|
}
|
2011-02-02 00:31:57 +03:00
|
|
|
//#define ROTATE 1
|
2010-03-14 21:07:24 +03:00
|
|
|
#ifdef ROTATE
|
|
|
|
printer.scale(scale * 0.8, scale * 0.8);
|
|
|
|
printer.printable_rect(&w, &h);
|
|
|
|
printer.origin(w/2, h/2 );
|
|
|
|
printer.rotate(20.);
|
|
|
|
#else
|
2011-09-08 12:09:20 +04:00
|
|
|
printer.origin(w/2, h/2);
|
2010-03-14 21:07:24 +03:00
|
|
|
#endif
|
2011-09-08 12:09:20 +04:00
|
|
|
printer.print_window(win, -ww/2, -wh/2);
|
2014-11-19 19:23:36 +03:00
|
|
|
//printer.print_window_part(win,0,0,win->w(),win->h(), -ww/2, -wh/2);
|
2010-03-14 21:07:24 +03:00
|
|
|
printer.end_page();
|
|
|
|
printer.end_job();
|
2011-07-11 17:52:16 +04:00
|
|
|
fl_unlock_function();
|
2010-03-14 21:07:24 +03:00
|
|
|
}
|
2014-11-15 17:55:15 +03:00
|
|
|
- (void)terminate:(id)sender
|
|
|
|
{
|
|
|
|
[NSApp terminate:sender];
|
|
|
|
}
|
2009-12-09 02:15:30 +03:00
|
|
|
@end
|
|
|
|
|
2009-12-07 01:21:55 +03:00
|
|
|
static void createAppleMenu(void)
|
|
|
|
{
|
|
|
|
static BOOL donethat = NO;
|
2010-01-14 02:13:59 +03:00
|
|
|
if (donethat) return;
|
2009-12-07 01:21:55 +03:00
|
|
|
donethat = YES;
|
2013-01-19 13:49:33 +04:00
|
|
|
NSMenu *mainmenu, *services = nil, *appleMenu;
|
2009-12-07 01:21:55 +03:00
|
|
|
NSMenuItem *menuItem;
|
|
|
|
NSString *title;
|
2013-01-25 20:28:49 +04:00
|
|
|
|
|
|
|
SEL infodictSEL = (fl_mac_os_version >= 100200 ? @selector(localizedInfoDictionary) : @selector(infoDictionary));
|
|
|
|
NSString *nsappname = [[[NSBundle mainBundle] performSelector:infodictSEL] objectForKey:@"CFBundleName"];
|
2011-06-16 16:35:32 +04:00
|
|
|
if (nsappname == nil)
|
|
|
|
nsappname = [[NSProcessInfo processInfo] processName];
|
2009-12-07 01:21:55 +03:00
|
|
|
appleMenu = [[NSMenu alloc] initWithTitle:@""];
|
|
|
|
/* Add menu items */
|
2013-01-25 20:28:49 +04:00
|
|
|
title = [NSString stringWithFormat:NSLocalizedString([NSString stringWithUTF8String:Fl_Mac_App_Menu::about],nil), nsappname];
|
2010-03-14 21:07:24 +03:00
|
|
|
menuItem = [appleMenu addItemWithTitle:title action:@selector(showPanel) keyEquivalent:@""];
|
2009-12-09 02:15:30 +03:00
|
|
|
FLaboutItemTarget *about = [[FLaboutItemTarget alloc] init];
|
2010-03-14 21:07:24 +03:00
|
|
|
[menuItem setTarget:about];
|
2009-12-07 01:21:55 +03:00
|
|
|
[appleMenu addItem:[NSMenuItem separatorItem]];
|
2010-11-25 21:21:21 +03:00
|
|
|
// Print front window
|
2013-01-25 20:28:49 +04:00
|
|
|
title = NSLocalizedString([NSString stringWithUTF8String:Fl_Mac_App_Menu::print], nil);
|
|
|
|
if ([title length] > 0) {
|
2011-02-02 00:31:57 +03:00
|
|
|
menuItem = [appleMenu
|
2013-01-25 20:28:49 +04:00
|
|
|
addItemWithTitle:title
|
2011-02-02 00:31:57 +03:00
|
|
|
action:@selector(printPanel)
|
|
|
|
keyEquivalent:@""];
|
|
|
|
[menuItem setTarget:about];
|
|
|
|
[menuItem setEnabled:YES];
|
|
|
|
[appleMenu addItem:[NSMenuItem separatorItem]];
|
|
|
|
}
|
2013-01-19 13:49:33 +04:00
|
|
|
if (fl_mac_os_version >= 100400) { // services+hide+quit already in menu in OS 10.3
|
|
|
|
// Services Menu
|
|
|
|
services = [[NSMenu alloc] init];
|
|
|
|
menuItem = [appleMenu
|
2013-01-25 20:28:49 +04:00
|
|
|
addItemWithTitle:NSLocalizedString([NSString stringWithUTF8String:Fl_Mac_App_Menu::services], nil)
|
2013-01-19 13:49:33 +04:00
|
|
|
action:nil
|
|
|
|
keyEquivalent:@""];
|
|
|
|
[appleMenu setSubmenu:services forItem:menuItem];
|
|
|
|
[appleMenu addItem:[NSMenuItem separatorItem]];
|
|
|
|
// Hide AppName
|
2013-01-25 20:28:49 +04:00
|
|
|
title = [NSString stringWithFormat:NSLocalizedString([NSString stringWithUTF8String:Fl_Mac_App_Menu::hide],nil), nsappname];
|
2013-01-19 13:49:33 +04:00
|
|
|
[appleMenu addItemWithTitle:title
|
|
|
|
action:@selector(hide:)
|
|
|
|
keyEquivalent:@"h"];
|
|
|
|
// Hide Others
|
|
|
|
menuItem = [appleMenu
|
2013-01-25 20:28:49 +04:00
|
|
|
addItemWithTitle:NSLocalizedString([NSString stringWithUTF8String:Fl_Mac_App_Menu::hide_others] , nil)
|
2013-01-19 13:49:33 +04:00
|
|
|
action:@selector(hideOtherApplications:)
|
2011-02-02 00:31:57 +03:00
|
|
|
keyEquivalent:@"h"];
|
2013-01-19 13:49:33 +04:00
|
|
|
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
|
|
|
|
// Show All
|
2013-01-25 20:28:49 +04:00
|
|
|
[appleMenu addItemWithTitle:NSLocalizedString([NSString stringWithUTF8String:Fl_Mac_App_Menu::show] , nil)
|
2013-01-19 13:49:33 +04:00
|
|
|
action:@selector(unhideAllApplications:) keyEquivalent:@""];
|
|
|
|
[appleMenu addItem:[NSMenuItem separatorItem]];
|
|
|
|
// Quit AppName
|
2013-01-25 20:28:49 +04:00
|
|
|
title = [NSString stringWithFormat:NSLocalizedString([NSString stringWithUTF8String:Fl_Mac_App_Menu::quit] , nil),
|
|
|
|
nsappname];
|
2014-11-15 17:55:15 +03:00
|
|
|
menuItem = [appleMenu addItemWithTitle:title
|
|
|
|
action:@selector(terminate:)
|
|
|
|
keyEquivalent:@"q"];
|
|
|
|
[menuItem setTarget:about];
|
2013-01-19 13:49:33 +04:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
/* Put menu into the menubar */
|
|
|
|
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
|
|
|
|
[menuItem setSubmenu:appleMenu];
|
|
|
|
mainmenu = [[NSMenu alloc] initWithTitle:@""];
|
|
|
|
[mainmenu addItem:menuItem];
|
2011-03-04 19:48:10 +03:00
|
|
|
if (fl_mac_os_version < 100600) {
|
2009-12-07 01:21:55 +03:00
|
|
|
// [NSApp setAppleMenu:appleMenu];
|
|
|
|
// to avoid compiler warning raised by use of undocumented setAppleMenu :
|
2010-11-06 18:06:25 +03:00
|
|
|
[NSApp performSelector:@selector(setAppleMenu:) withObject:appleMenu];
|
2009-12-13 15:03:26 +03:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
[NSApp setMainMenu:mainmenu];
|
2013-01-19 13:49:33 +04:00
|
|
|
if (services) {
|
|
|
|
[NSApp setServicesMenu:services];
|
|
|
|
[services release];
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
[mainmenu release];
|
|
|
|
[appleMenu release];
|
|
|
|
[menuItem release];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-19 01:31:01 +03:00
|
|
|
void Fl_X::set_key_window()
|
2009-12-07 01:21:55 +03:00
|
|
|
{
|
2011-11-12 17:06:54 +04:00
|
|
|
[xid makeKeyWindow];
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
2009-12-13 15:03:26 +03:00
|
|
|
static NSImage *imageFromText(const char *text, int *pwidth, int *pheight)
|
2009-12-07 01:21:55 +03:00
|
|
|
{
|
2009-12-13 15:03:26 +03:00
|
|
|
const char *p, *q;
|
|
|
|
int width = 0, height, w2, ltext = strlen(text);
|
2009-12-07 01:21:55 +03:00
|
|
|
fl_font(FL_HELVETICA, 10);
|
2009-12-13 15:03:26 +03:00
|
|
|
p = text;
|
2009-12-07 01:21:55 +03:00
|
|
|
int nl = 0;
|
2013-04-19 13:20:56 +04:00
|
|
|
while(nl < 100 && (q=strchr(p, '\n')) != NULL) {
|
2009-12-07 01:21:55 +03:00
|
|
|
nl++;
|
2010-11-15 07:34:58 +03:00
|
|
|
w2 = int(fl_width(p, q - p));
|
2010-01-14 02:13:59 +03:00
|
|
|
if (w2 > width) width = w2;
|
2009-12-07 01:21:55 +03:00
|
|
|
p = q + 1;
|
2009-12-13 15:03:26 +03:00
|
|
|
}
|
2010-01-14 02:13:59 +03:00
|
|
|
if (text[ ltext - 1] != '\n') {
|
2009-12-07 01:21:55 +03:00
|
|
|
nl++;
|
2010-11-15 07:34:58 +03:00
|
|
|
w2 = int(fl_width(p));
|
2010-01-14 02:13:59 +03:00
|
|
|
if (w2 > width) width = w2;
|
2009-12-13 15:03:26 +03:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
height = nl * fl_height() + 3;
|
|
|
|
width += 6;
|
2012-03-12 15:55:50 +04:00
|
|
|
Fl_Offscreen off = Fl_Quartz_Graphics_Driver::create_offscreen_with_alpha(width, height);
|
2009-12-07 01:21:55 +03:00
|
|
|
fl_begin_offscreen(off);
|
|
|
|
CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
|
|
|
|
fl_rectf(0,0,width,height);
|
|
|
|
fl_color(FL_BLACK);
|
2009-12-13 15:03:26 +03:00
|
|
|
p = text;
|
2009-12-07 01:21:55 +03:00
|
|
|
int y = fl_height();
|
|
|
|
while(TRUE) {
|
|
|
|
q = strchr(p, '\n');
|
2010-01-14 02:13:59 +03:00
|
|
|
if (q) {
|
|
|
|
fl_draw(p, q - p, 3, y);
|
|
|
|
} else {
|
2009-12-07 01:21:55 +03:00
|
|
|
fl_draw(p, 3, y);
|
|
|
|
break;
|
2009-12-13 15:03:26 +03:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
y += fl_height();
|
|
|
|
p = q + 1;
|
2009-12-13 15:03:26 +03:00
|
|
|
}
|
|
|
|
fl_end_offscreen();
|
|
|
|
NSImage* image = CGBitmapContextToNSImage( (CGContextRef)off );
|
|
|
|
fl_delete_offscreen( off );
|
|
|
|
*pwidth = width;
|
|
|
|
*pheight = height;
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NSImage *defaultDragImage(int *pwidth, int *pheight)
|
|
|
|
{
|
2013-04-19 13:20:56 +04:00
|
|
|
const int version_threshold = 100700;
|
2013-04-18 20:15:59 +04:00
|
|
|
int width, height;
|
|
|
|
if (fl_mac_os_version >= version_threshold) {
|
|
|
|
width = 50; height = 40;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
width = 16; height = 16;
|
|
|
|
}
|
2012-03-12 15:55:50 +04:00
|
|
|
Fl_Offscreen off = Fl_Quartz_Graphics_Driver::create_offscreen_with_alpha(width, height);
|
2009-12-13 15:03:26 +03:00
|
|
|
fl_begin_offscreen(off);
|
2013-04-18 20:15:59 +04:00
|
|
|
if (fl_mac_os_version >= version_threshold) {
|
|
|
|
fl_font(FL_HELVETICA, 20);
|
|
|
|
fl_color(FL_BLACK);
|
|
|
|
char str[4];
|
2013-04-19 13:20:56 +04:00
|
|
|
int l = fl_utf8encode(0x1F69A, str); // the "Delivery truck" Unicode character from "Apple Color Emoji" font
|
2013-04-18 20:15:59 +04:00
|
|
|
fl_draw(str, l, 1, 16);
|
|
|
|
}
|
|
|
|
else { // draw two squares
|
|
|
|
CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
|
|
|
|
fl_rectf(0,0,width,height);
|
|
|
|
CGContextSetRGBStrokeColor( (CGContextRef)off, 0,0,0,0.6);
|
|
|
|
fl_rect(0,0,width,height);
|
|
|
|
fl_rect(2,2,width-4,height-4);
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
fl_end_offscreen();
|
|
|
|
NSImage* image = CGBitmapContextToNSImage( (CGContextRef)off );
|
|
|
|
fl_delete_offscreen( off );
|
2009-12-13 15:03:26 +03:00
|
|
|
*pwidth = width;
|
|
|
|
*pheight = height;
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2010-12-19 01:31:01 +03:00
|
|
|
int Fl::dnd(void)
|
2009-12-13 15:03:26 +03:00
|
|
|
{
|
|
|
|
CFDataRef text = CFDataCreate(kCFAllocatorDefault, (UInt8*)fl_selection_buffer[0], fl_selection_length[0]);
|
|
|
|
if (text==NULL) return false;
|
|
|
|
NSAutoreleasePool *localPool;
|
|
|
|
localPool = [[NSAutoreleasePool alloc] init];
|
|
|
|
NSPasteboard *mypasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
|
2013-09-12 16:21:57 +04:00
|
|
|
[mypasteboard declareTypes:[NSArray arrayWithObject:utf8_format] owner:nil];
|
|
|
|
[mypasteboard setData:(NSData*)text forType:utf8_format];
|
2009-12-13 15:03:26 +03:00
|
|
|
CFRelease(text);
|
|
|
|
Fl_Widget *w = Fl::pushed();
|
2013-04-30 12:56:28 +04:00
|
|
|
Fl_Window *win = w->top_window();
|
2011-11-12 17:06:54 +04:00
|
|
|
NSView *myview = [Fl_X::i(win)->xid contentView];
|
2009-12-13 15:03:26 +03:00
|
|
|
NSEvent *theEvent = [NSApp currentEvent];
|
|
|
|
|
|
|
|
int width, height;
|
|
|
|
NSImage *image;
|
2010-11-29 17:12:57 +03:00
|
|
|
if ( dynamic_cast<Fl_Input_*>(w) != NULL || dynamic_cast<Fl_Text_Display*>(w) != NULL) {
|
2009-12-13 15:03:26 +03:00
|
|
|
fl_selection_buffer[0][ fl_selection_length[0] ] = 0;
|
|
|
|
image = imageFromText(fl_selection_buffer[0], &width, &height);
|
2010-01-14 02:13:59 +03:00
|
|
|
} else {
|
2009-12-13 15:03:26 +03:00
|
|
|
image = defaultDragImage(&width, &height);
|
2010-01-14 02:13:59 +03:00
|
|
|
}
|
2009-12-13 15:03:26 +03:00
|
|
|
|
2009-12-07 01:21:55 +03:00
|
|
|
static NSSize offset={0,0};
|
|
|
|
NSPoint pt = [theEvent locationInWindow];
|
|
|
|
pt.x -= width/2;
|
|
|
|
pt.y -= height/2;
|
|
|
|
[myview dragImage:image at:pt offset:offset
|
|
|
|
event:theEvent pasteboard:mypasteboard
|
|
|
|
source:myview slideBack:YES];
|
2010-01-14 02:13:59 +03:00
|
|
|
if ( w ) {
|
2009-12-07 01:21:55 +03:00
|
|
|
int old_event = Fl::e_number;
|
|
|
|
w->handle(Fl::e_number = FL_RELEASE);
|
|
|
|
Fl::e_number = old_event;
|
|
|
|
Fl::pushed( 0 );
|
|
|
|
}
|
|
|
|
[localPool release];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-12 20:12:11 +03:00
|
|
|
// rescales an NSBitmapImageRep
|
|
|
|
static NSBitmapImageRep *scale_nsbitmapimagerep(NSBitmapImageRep *img, float scale)
|
|
|
|
{
|
|
|
|
int w = [img pixelsWide];
|
|
|
|
int h = [img pixelsHigh];
|
|
|
|
int scaled_w = int(scale * w + 0.5);
|
|
|
|
int scaled_h = int(scale * h + 0.5);
|
|
|
|
NSBitmapImageRep *scaled = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
|
|
|
|
pixelsWide:scaled_w
|
|
|
|
pixelsHigh:scaled_h
|
|
|
|
bitsPerSample:8
|
|
|
|
samplesPerPixel:4
|
|
|
|
hasAlpha:YES
|
|
|
|
isPlanar:NO
|
|
|
|
colorSpaceName:NSDeviceRGBColorSpace
|
|
|
|
bytesPerRow:scaled_w*4
|
|
|
|
bitsPerPixel:32];
|
|
|
|
NSDictionary *dict = [NSDictionary dictionaryWithObject:scaled
|
|
|
|
forKey:NSGraphicsContextDestinationAttributeName];
|
|
|
|
NSGraphicsContext *oldgc = [NSGraphicsContext currentContext];
|
|
|
|
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithAttributes:dict]];
|
|
|
|
[[NSColor clearColor] set];
|
|
|
|
NSRect r = NSMakeRect(0, 0, scaled_w, scaled_h);
|
|
|
|
NSRectFill(r);
|
|
|
|
[img drawInRect:r];
|
|
|
|
[NSGraphicsContext setCurrentContext:oldgc];
|
|
|
|
[img release];
|
|
|
|
return scaled;
|
|
|
|
}
|
|
|
|
|
2014-11-06 19:48:57 +03:00
|
|
|
static void write_bitmap_inside(NSBitmapImageRep *to, int to_width, NSBitmapImageRep *from,
|
|
|
|
int to_x, int to_y)
|
|
|
|
/* Copies in bitmap "to" the bitmap "from" with its top-left angle at coordinates to_x, to_y
|
|
|
|
On retina displays both bitmaps have double width and height
|
|
|
|
to_width is the width in screen units of "to". On retina, its pixel width is twice that.
|
|
|
|
*/
|
2009-12-07 01:21:55 +03:00
|
|
|
{
|
2014-11-06 19:48:57 +03:00
|
|
|
int to_w = (int)[to pixelsWide]; // pixel width of "to"
|
|
|
|
int from_w = (int)[from pixelsWide]; // pixel width of "from"
|
|
|
|
int from_h = [from pixelsHigh]; // pixel height of "from"
|
|
|
|
int to_depth = [to samplesPerPixel], from_depth = [from samplesPerPixel];
|
|
|
|
int depth = 0;
|
|
|
|
if (to_depth > from_depth) depth = from_depth;
|
|
|
|
else if (from_depth > to_depth) depth = to_depth;
|
|
|
|
float factor = to_w / (float)to_width; // scaling factor is 1 for classic displays and 2 for retina
|
|
|
|
to_x = factor*to_x; // transform offset from screen unit to pixels
|
|
|
|
to_y = factor*to_y;
|
|
|
|
// perform the copy
|
|
|
|
uchar *tobytes = [to bitmapData] + to_y * to_w * to_depth + to_x * to_depth;
|
|
|
|
uchar *frombytes = [from bitmapData];
|
|
|
|
for (int i = 0; i < from_h; i++) {
|
|
|
|
if (depth == 0) memcpy(tobytes, frombytes, from_w * from_depth);
|
|
|
|
else {
|
|
|
|
for (int j = 0; j < from_w; j++) {
|
|
|
|
memcpy(tobytes + j * to_depth, frombytes + j * from_depth, depth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tobytes += to_w * to_depth;
|
|
|
|
frombytes += from_w * from_depth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-12 20:12:11 +03:00
|
|
|
static NSBitmapImageRep* GL_rect_to_nsbitmap(Fl_Window *win, int x, int y, int w, int h)
|
|
|
|
// captures a rectangle from a GL window and returns it as an allocated NSBitmapImageRep
|
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2014-12-20 10:19:23 +03:00
|
|
|
// the capture has high res on retina
|
2014-11-06 19:48:57 +03:00
|
|
|
{
|
|
|
|
Fl_Plugin_Manager pm("fltk:device");
|
|
|
|
Fl_Device_Plugin *pi = (Fl_Device_Plugin*)pm.plugin("opengl.device.fltk.org");
|
2014-12-12 20:12:11 +03:00
|
|
|
if (!pi) return nil;
|
2014-11-06 19:48:57 +03:00
|
|
|
Fl_RGB_Image *img = pi->rectangle_capture(win, x, y, w, h);
|
2014-12-12 20:12:11 +03:00
|
|
|
Fl_Offscreen offscreen = fl_create_offscreen(img->w(), img->h());
|
2014-11-06 19:48:57 +03:00
|
|
|
fl_begin_offscreen(offscreen);
|
2014-12-12 20:12:11 +03:00
|
|
|
CGRect rect = CGRectMake(0, 0, img->w(), img->h());
|
|
|
|
Fl_X::q_begin_image(rect, 0, 0, img->w(), img->h()); // flip the image
|
|
|
|
img->draw(0, 0);
|
2014-11-06 19:48:57 +03:00
|
|
|
Fl_X::q_end_image();
|
|
|
|
fl_end_offscreen();
|
2014-12-12 20:12:11 +03:00
|
|
|
NSBitmapImageRep* bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:img->w() pixelsHigh:img->h() bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:4*img->w() bitsPerPixel:32];
|
2014-11-06 19:48:57 +03:00
|
|
|
memcpy([bitmap bitmapData], CGBitmapContextGetData(offscreen), CGBitmapContextGetBytesPerRow(offscreen)*CGBitmapContextGetHeight(offscreen));
|
|
|
|
fl_delete_offscreen(offscreen);
|
2014-12-12 20:12:11 +03:00
|
|
|
delete img;
|
2014-11-06 19:48:57 +03:00
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NSBitmapImageRep* rect_to_NSBitmapImageRep(Fl_Window *win, int x, int y, int w, int h)
|
|
|
|
/* Captures a rectangle from a mapped window.
|
|
|
|
On retina displays, the resulting bitmap has 2 pixels per screen unit.
|
|
|
|
The returned value is to be released after use
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
NSBitmapImageRep *bitmap = nil;
|
|
|
|
NSRect rect;
|
|
|
|
if (win->as_gl_window() && y >= 0) {
|
|
|
|
bitmap = GL_rect_to_nsbitmap(win, x, y, w, h);
|
|
|
|
} else {
|
|
|
|
NSView *winview = nil;
|
|
|
|
if ( through_drawRect && Fl_Window::current() == win ) {
|
2014-11-19 19:23:36 +03:00
|
|
|
rect = NSMakeRect(x - 0.5, y - 0.5, w, h);
|
2014-03-22 21:09:07 +04:00
|
|
|
}
|
2014-11-06 19:48:57 +03:00
|
|
|
else {
|
|
|
|
rect = NSMakeRect(x, win->h()-(y+h), w, h);
|
|
|
|
// lock focus to win's view
|
|
|
|
winview = [fl_xid(win) contentView];
|
|
|
|
[winview lockFocus];
|
2014-03-22 21:09:07 +04:00
|
|
|
}
|
2014-11-06 19:48:57 +03:00
|
|
|
// The image depth is 3 until 10.5 and 4 with 10.6 and above
|
|
|
|
bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:rect];
|
|
|
|
if ( !( through_drawRect && Fl_Window::current() == win) ) [winview unlockFocus];
|
|
|
|
if (!bitmap) return nil;
|
|
|
|
}
|
|
|
|
|
2014-11-11 19:08:09 +03:00
|
|
|
// capture also subwindows
|
|
|
|
NSArray *children = [fl_xid(win) childWindows]; // 10.2
|
|
|
|
NSEnumerator *enumerator = [children objectEnumerator];
|
|
|
|
id child;
|
|
|
|
while ((child = [enumerator nextObject]) != nil) {
|
|
|
|
Fl_Window *sub = [(FLWindow*)child getFl_Window];
|
2014-11-06 19:48:57 +03:00
|
|
|
CGRect rsub = CGRectMake(sub->x(), win->h() -(sub->y()+sub->h()), sub->w(), sub->h());
|
|
|
|
CGRect clip = CGRectMake(x, win->h()-(y+h), w, h);
|
|
|
|
clip = CGRectIntersection(rsub, clip);
|
|
|
|
if (CGRectIsNull(clip)) continue;
|
|
|
|
NSBitmapImageRep *childbitmap = rect_to_NSBitmapImageRep(sub, clip.origin.x - sub->x(),
|
2014-12-12 20:12:11 +03:00
|
|
|
win->h() - clip.origin.y - sub->y() - clip.size.height, clip.size.width, clip.size.height);
|
|
|
|
if (childbitmap) {
|
|
|
|
// if bitmap is high res and childbitmap is not, childbitmap must be rescaled
|
|
|
|
if ([bitmap pixelsWide] > w && [childbitmap pixelsWide] == clip.size.width) childbitmap = scale_nsbitmapimagerep(childbitmap, 2);
|
|
|
|
write_bitmap_inside(bitmap, w, childbitmap,
|
|
|
|
clip.origin.x - x, win->h() - clip.origin.y - clip.size.height - y );
|
|
|
|
}
|
2014-11-06 19:48:57 +03:00
|
|
|
[childbitmap release];
|
|
|
|
}
|
2014-01-19 14:00:37 +04:00
|
|
|
return bitmap;
|
2012-09-17 13:00:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char *Fl_X::bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel)
|
2012-11-17 18:57:55 +04:00
|
|
|
/* Returns a capture of a rectangle of a mapped window as a pre-multiplied RGBA array of bytes.
|
|
|
|
Alpha values are always 1 (except for the angles of a window title bar)
|
2014-11-11 19:08:09 +03:00
|
|
|
so pre-multiplication can be ignored.
|
|
|
|
*bytesPerPixel is set to the value 3 or 4 upon return.
|
2012-11-15 16:28:29 +04:00
|
|
|
delete[] the returned pointer after use
|
|
|
|
*/
|
2012-09-17 13:00:22 +04:00
|
|
|
{
|
|
|
|
NSBitmapImageRep *bitmap = rect_to_NSBitmapImageRep(win, x, y, w, h);
|
2014-01-23 00:39:21 +04:00
|
|
|
if (bitmap == nil) return NULL;
|
2009-12-07 01:21:55 +03:00
|
|
|
*bytesPerPixel = [bitmap bitsPerPixel]/8;
|
2010-01-24 13:27:21 +03:00
|
|
|
int bpp = (int)[bitmap bytesPerPlane];
|
|
|
|
int bpr = (int)[bitmap bytesPerRow];
|
2014-10-11 17:43:06 +04:00
|
|
|
int hh = bpp/bpr; // sometimes hh = h-1 for unclear reason, and hh = 2*h with retina
|
|
|
|
int ww = bpr/(*bytesPerPixel); // sometimes ww = w-1, and ww = 2*w with retina
|
|
|
|
unsigned char *data;
|
|
|
|
if (ww > w) { // with a retina display
|
|
|
|
Fl_RGB_Image *rgb = new Fl_RGB_Image([bitmap bitmapData], ww, hh, 4);
|
2014-10-14 15:53:51 +04:00
|
|
|
Fl_RGB_Scaling save_scaling = Fl_Image::RGB_scaling();
|
|
|
|
Fl_Image::RGB_scaling(FL_RGB_SCALING_BILINEAR);
|
2014-10-11 17:43:06 +04:00
|
|
|
Fl_RGB_Image *rgb2 = (Fl_RGB_Image*)rgb->copy(w, h);
|
2014-10-14 15:53:51 +04:00
|
|
|
Fl_Image::RGB_scaling(save_scaling);
|
2014-10-11 17:43:06 +04:00
|
|
|
delete rgb;
|
|
|
|
rgb2->alloc_array = 0;
|
|
|
|
data = (uchar*)rgb2->array;
|
|
|
|
delete rgb2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data = new unsigned char[w * h * *bytesPerPixel];
|
|
|
|
if (w == ww) {
|
|
|
|
memcpy(data, [bitmap bitmapData], w * hh * *bytesPerPixel);
|
|
|
|
} else {
|
|
|
|
unsigned char *p = [bitmap bitmapData];
|
|
|
|
unsigned char *q = data;
|
|
|
|
for(int i = 0;i < hh; i++) {
|
|
|
|
memcpy(q, p, *bytesPerPixel * ww);
|
|
|
|
p += bpr;
|
|
|
|
q += w * *bytesPerPixel;
|
2010-01-24 13:27:21 +03:00
|
|
|
}
|
2014-10-11 17:43:06 +04:00
|
|
|
}
|
2010-01-24 13:27:21 +03:00
|
|
|
}
|
2014-11-06 19:48:57 +03:00
|
|
|
[bitmap release];
|
2009-12-07 01:21:55 +03:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2014-11-06 19:48:57 +03:00
|
|
|
static void nsbitmapProviderReleaseData (void *info, const void *data, size_t size)
|
2009-12-07 01:21:55 +03:00
|
|
|
{
|
2014-11-06 19:48:57 +03:00
|
|
|
[(NSBitmapImageRep*)info release];
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
|
|
|
|
2010-12-19 01:31:01 +03:00
|
|
|
CGImageRef Fl_X::CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h)
|
2014-11-06 19:48:57 +03:00
|
|
|
/* Returns a capture of a rectangle of a mapped window as a CGImage.
|
|
|
|
With retina displays, the returned image has twice the width and height.
|
|
|
|
CFRelease the returned CGImageRef after use
|
|
|
|
*/
|
2009-12-07 01:21:55 +03:00
|
|
|
{
|
|
|
|
CGImageRef img;
|
2014-11-06 19:48:57 +03:00
|
|
|
NSBitmapImageRep *bitmap = rect_to_NSBitmapImageRep(win, x, y, w, h);
|
2013-01-20 20:54:23 +04:00
|
|
|
if (fl_mac_os_version >= 100500) {
|
2013-01-17 21:40:53 +04:00
|
|
|
img = (CGImageRef)[bitmap performSelector:@selector(CGImage)]; // requires Mac OS 10.5
|
2012-09-17 13:00:22 +04:00
|
|
|
CGImageRetain(img);
|
2014-11-06 19:48:57 +03:00
|
|
|
[bitmap release];
|
|
|
|
} else {
|
|
|
|
CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB();
|
|
|
|
CGDataProviderRef provider = CGDataProviderCreateWithData(bitmap, [bitmap bitmapData],
|
|
|
|
[bitmap bytesPerRow]*[bitmap pixelsHigh],
|
|
|
|
nsbitmapProviderReleaseData);
|
|
|
|
img = CGImageCreate([bitmap pixelsWide], [bitmap pixelsHigh], 8, [bitmap bitsPerPixel], [bitmap bytesPerRow],
|
|
|
|
cspace,
|
|
|
|
[bitmap bitsPerPixel] == 32 ? kCGImageAlphaPremultipliedLast : kCGImageAlphaNone,
|
|
|
|
provider, NULL, false, kCGRenderingIntentDefault);
|
|
|
|
CGColorSpaceRelease(cspace);
|
2012-09-17 13:00:22 +04:00
|
|
|
CGDataProviderRelease(provider);
|
2014-11-06 19:48:57 +03:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
return img;
|
|
|
|
}
|
|
|
|
|
2010-12-19 01:31:01 +03:00
|
|
|
WindowRef Fl_X::window_ref()
|
2009-12-07 01:21:55 +03:00
|
|
|
{
|
2011-11-12 17:06:54 +04:00
|
|
|
return (WindowRef)[xid windowRef];
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2010-03-14 21:07:24 +03:00
|
|
|
|
|
|
|
// so a CGRect matches exactly what is denoted x,y,w,h for clipping purposes
|
|
|
|
CGRect fl_cgrectmake_cocoa(int x, int y, int w, int h) {
|
2014-10-28 16:44:09 +03:00
|
|
|
return CGRectMake(x - 0.5, y - 0.5, w, h);
|
2010-03-14 21:07:24 +03:00
|
|
|
}
|
|
|
|
|
2010-12-23 17:24:29 +03:00
|
|
|
Window fl_xid(const Fl_Window* w)
|
|
|
|
{
|
2011-05-22 01:31:35 +04:00
|
|
|
Fl_X *temp = Fl_X::i(w);
|
|
|
|
return temp ? temp->xid : 0;
|
2010-12-23 17:24:29 +03:00
|
|
|
}
|
|
|
|
|
2011-04-16 01:38:05 +04:00
|
|
|
int Fl_Window::decorated_w()
|
|
|
|
{
|
2011-05-30 16:33:51 +04:00
|
|
|
if (!shown() || parent() || !border() || !visible()) return w();
|
2011-04-16 01:38:05 +04:00
|
|
|
int bx, by, bt;
|
|
|
|
get_window_frame_sizes(bx, by, bt);
|
|
|
|
return w() + 2 * bx;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Fl_Window::decorated_h()
|
|
|
|
{
|
2011-05-30 16:33:51 +04:00
|
|
|
if (!shown() || parent() || !border() || !visible()) return h();
|
2011-04-16 01:38:05 +04:00
|
|
|
int bx, by, bt;
|
|
|
|
get_window_frame_sizes(bx, by, bt);
|
|
|
|
return h() + bt + by;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fl_Paged_Device::print_window(Fl_Window *win, int x_offset, int y_offset)
|
|
|
|
{
|
2011-05-30 16:33:51 +04:00
|
|
|
if (!win->shown() || win->parent() || !win->border() || !win->visible()) {
|
2011-04-16 01:38:05 +04:00
|
|
|
this->print_widget(win, x_offset, y_offset);
|
|
|
|
return;
|
|
|
|
}
|
2013-10-23 18:39:14 +04:00
|
|
|
int bx, by, bt, bpp;
|
2011-04-16 01:38:05 +04:00
|
|
|
get_window_frame_sizes(bx, by, bt);
|
2015-01-13 19:36:04 +03:00
|
|
|
BOOL to_quartz = (this->driver()->class_name() == Fl_Quartz_Graphics_Driver::class_id);
|
2015-01-14 16:29:05 +03:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
|
|
|
|
// a compilation warning appears with SDK 10.5, so we require SDK 10.6 instead
|
2015-01-13 19:36:04 +03:00
|
|
|
if (fl_mac_os_version >= 101000) {
|
|
|
|
CALayer *layer = [[[fl_xid(win) standardWindowButton:NSWindowCloseButton] superview] layer]; // 10.5
|
|
|
|
if (layer) { // if program is linked with 10.10, title bar uses a layer
|
|
|
|
if (to_quartz) { // to Quartz printer
|
|
|
|
CGContextSaveGState(fl_gc);
|
|
|
|
CGContextTranslateCTM(fl_gc, x_offset - 0.5, y_offset + bt - 0.5);
|
|
|
|
CGContextScaleCTM(fl_gc, 1, -1);
|
|
|
|
[layer renderInContext:fl_gc]; // 10.5 // print all title bar
|
|
|
|
CGContextRestoreGState(fl_gc);
|
|
|
|
}
|
|
|
|
else { // to PostScript
|
|
|
|
CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB ();
|
|
|
|
CGContextRef gc = CGBitmapContextCreate(NULL, win->w(), bt, 8, 0, cspace, kCGImageAlphaPremultipliedLast);
|
|
|
|
CGColorSpaceRelease(cspace);
|
|
|
|
[layer renderInContext:gc]; // 10.5 // draw all title bar to bitmap
|
|
|
|
Fl_RGB_Image *image = new Fl_RGB_Image((const uchar*)CGBitmapContextGetData(gc), win->w(), bt, 4); // 10.2
|
|
|
|
image->draw(x_offset, y_offset); // draw title bar to PostScript
|
|
|
|
delete image;
|
|
|
|
CGContextRelease(gc);
|
|
|
|
}
|
|
|
|
this->print_widget(win, x_offset, y_offset + bt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2011-04-16 01:38:05 +04:00
|
|
|
Fl_Display_Device::display_device()->set_current(); // send win to front and make it current
|
2013-12-08 20:16:24 +04:00
|
|
|
const char *title = win->label();
|
|
|
|
win->label(""); // temporarily set a void window title
|
2011-04-16 01:38:05 +04:00
|
|
|
win->show();
|
|
|
|
fl_gc = NULL;
|
|
|
|
Fl::check();
|
2013-12-08 20:16:24 +04:00
|
|
|
// capture the window title bar with no title
|
2014-10-11 18:33:43 +04:00
|
|
|
CGImageRef img = NULL;
|
|
|
|
unsigned char *bitmap = NULL;
|
|
|
|
if (to_quartz)
|
|
|
|
img = Fl_X::CGImage_from_window_rect(win, 0, -bt, win->w(), bt);
|
|
|
|
else
|
|
|
|
bitmap = Fl_X::bitmap_from_window_rect(win, 0, -bt, win->w(), bt, &bpp);
|
2013-12-08 20:16:24 +04:00
|
|
|
win->label(title); // put back the window title
|
2013-10-23 18:39:14 +04:00
|
|
|
this->set_current(); // back to the Fl_Paged_Device
|
2014-10-23 13:04:30 +04:00
|
|
|
if (img && to_quartz) { // print the title bar
|
2014-10-11 18:33:43 +04:00
|
|
|
CGRect rect = { { x_offset, y_offset }, { win->w(), bt } };
|
|
|
|
Fl_X::q_begin_image(rect, 0, 0, win->w(), bt);
|
|
|
|
CGContextDrawImage(fl_gc, rect, img);
|
|
|
|
Fl_X::q_end_image();
|
|
|
|
CFRelease(img);
|
|
|
|
}
|
|
|
|
else if(!to_quartz) {
|
|
|
|
Fl_RGB_Image *rgb = new Fl_RGB_Image(bitmap, win->w(), bt, bpp);
|
|
|
|
rgb->draw(x_offset, y_offset);
|
|
|
|
delete rgb;
|
|
|
|
delete[] bitmap;
|
|
|
|
}
|
2013-12-08 20:16:24 +04:00
|
|
|
if (title) { // print the window title
|
2014-10-23 13:04:30 +04:00
|
|
|
const int skip = 65; // approx width of the zone of the 3 window control buttons
|
2014-04-27 19:48:18 +04:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
2014-10-11 18:33:43 +04:00
|
|
|
if (fl_mac_os_version >= 100400 && to_quartz) { // use Cocoa string drawing with exact title bar font
|
2014-10-23 13:04:30 +04:00
|
|
|
// the exact font is LucidaGrande 13 pts (and HelveticaNeueDeskInterface-Regular with 10.10)
|
2014-01-21 18:04:43 +04:00
|
|
|
NSGraphicsContext *current = [NSGraphicsContext currentContext];
|
|
|
|
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:fl_gc flipped:YES]];//10.4
|
|
|
|
NSDictionary *attr = [NSDictionary dictionaryWithObject:[NSFont titleBarFontOfSize:0]
|
|
|
|
forKey:NSFontAttributeName];
|
2014-01-30 11:10:37 +04:00
|
|
|
NSString *title_s = [fl_xid(win) title];
|
2014-01-21 18:04:43 +04:00
|
|
|
NSSize size = [title_s sizeWithAttributes:attr];
|
|
|
|
int x = x_offset + win->w()/2 - size.width/2;
|
|
|
|
if (x < x_offset+skip) x = x_offset+skip;
|
|
|
|
NSRect r = {{x, y_offset+bt/2+4}, {win->w() - skip, bt}};
|
|
|
|
[[NSGraphicsContext currentContext] setShouldAntialias:YES];
|
2014-04-27 18:14:23 +04:00
|
|
|
[title_s drawWithRect:r options:(NSStringDrawingOptions)0 attributes:attr]; // 10.4
|
2014-01-21 18:04:43 +04:00
|
|
|
[[NSGraphicsContext currentContext] setShouldAntialias:NO];
|
|
|
|
[NSGraphicsContext setCurrentContext:current];
|
2014-05-23 20:47:21 +04:00
|
|
|
}
|
|
|
|
else
|
2014-04-27 19:48:18 +04:00
|
|
|
#endif
|
2014-05-23 20:47:21 +04:00
|
|
|
{
|
2014-10-23 13:04:30 +04:00
|
|
|
fl_font(FL_HELVETICA, 14);
|
2014-01-21 18:04:43 +04:00
|
|
|
fl_color(FL_BLACK);
|
|
|
|
int x = x_offset + win->w()/2 - fl_width(title)/2;
|
|
|
|
if (x < x_offset+skip) x = x_offset+skip;
|
|
|
|
fl_push_clip(x_offset, y_offset, win->w(), bt);
|
|
|
|
fl_draw(title, x, y_offset+bt/2+4);
|
|
|
|
fl_pop_clip();
|
2014-05-23 20:47:21 +04:00
|
|
|
}
|
2014-03-22 21:09:07 +04:00
|
|
|
}
|
2011-04-16 01:38:05 +04:00
|
|
|
this->print_widget(win, x_offset, y_offset + bt); // print the window inner part
|
|
|
|
}
|
|
|
|
|
2011-01-03 19:50:34 +03:00
|
|
|
|
|
|
|
/* Returns the address of a Carbon function after dynamically loading the Carbon library if needed.
|
|
|
|
Supports old Mac OS X versions that may use a couple of Carbon calls:
|
|
|
|
GetKeys used by OS X 10.3 or before (in Fl::get_key())
|
|
|
|
PMSessionPageSetupDialog and PMSessionPrintDialog used by 10.4 or before (in Fl_Printer::start_job())
|
|
|
|
GetWindowPort used by 10.4 or before (in Fl_Gl_Choice.cxx)
|
|
|
|
*/
|
|
|
|
void *Fl_X::get_carbon_function(const char *function_name) {
|
|
|
|
static void *carbon = NULL;
|
|
|
|
void *f = NULL;
|
|
|
|
if (!carbon) {
|
|
|
|
carbon = dlopen("/System/Library/Frameworks/Carbon.framework/Carbon", RTLD_LAZY);
|
|
|
|
}
|
|
|
|
if (carbon) {
|
|
|
|
f = dlsym(carbon, function_name);
|
|
|
|
}
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2012-09-27 16:49:39 +04:00
|
|
|
/* Returns the version of the running Mac OS as an int such as 100802 for 10.8.2
|
|
|
|
*/
|
|
|
|
static int calc_mac_os_version() {
|
|
|
|
int M, m, b = 0;
|
2012-09-28 12:07:47 +04:00
|
|
|
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
|
2014-09-13 18:29:53 +04:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10
|
2014-09-13 18:18:34 +04:00
|
|
|
if ([NSProcessInfo instancesRespondToSelector:@selector(operatingSystemVersion)]) {
|
|
|
|
NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
|
|
|
|
M = version.majorVersion;
|
|
|
|
m = version.minorVersion;
|
|
|
|
b = version.patchVersion;
|
|
|
|
}
|
2014-09-13 18:29:53 +04:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2014-09-13 18:18:34 +04:00
|
|
|
NSDictionary * sv = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
|
|
|
|
const char *s = [[sv objectForKey:@"ProductVersion"] UTF8String];
|
|
|
|
sscanf(s, "%d.%d.%d", &M, &m, &b);
|
|
|
|
}
|
2012-09-28 12:07:47 +04:00
|
|
|
[localPool release];
|
2012-09-27 16:49:39 +04:00
|
|
|
return M*10000 + m*100 + b;
|
|
|
|
}
|
|
|
|
|
2010-12-19 20:57:19 +03:00
|
|
|
#endif // __APPLE__
|
2009-12-07 01:21:55 +03:00
|
|
|
|
|
|
|
//
|
2011-03-29 15:19:51 +04:00
|
|
|
// End of "$Id$".
|
2009-12-07 01:21:55 +03:00
|
|
|
//
|