MacOS: implemented cut/copy/past.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1895 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Matthias Melcher
2001-12-22 09:30:07 +00:00
parent d0bdfe300d
commit c868f3d886
3 changed files with 61 additions and 100 deletions
+1
View File
@@ -1,5 +1,6 @@
CHANGES IN FLTK 1.1.0b8 CHANGES IN FLTK 1.1.0b8
- MacOS: implemented cut/copy/paste.
- MacOS: improved keyboard handling, fixed keyboard - MacOS: improved keyboard handling, fixed keyboard
focus handling, fixed get_key, modified 'keyboard' focus handling, fixed get_key, modified 'keyboard'
demo to show second mouse wheel and additional keys demo to show second mouse wheel and additional keys
-1
View File
@@ -89,7 +89,6 @@ KNOWN MacFLTK BUGS
- File handles (Fl::add_fd) are not implemented. - File handles (Fl::add_fd) are not implemented.
- Line styles are not fully implemented. - Line styles are not fully implemented.
- Cut, copy, and paste are not implemented.
- Sub-sub-subwindow not tested. - Sub-sub-subwindow not tested.
- Image transparency is not implemented. - Image transparency is not implemented.
- The 'shiny' demo needs work (flush/aglFlush). - The 'shiny' demo needs work (flush/aglFlush).
+60 -99
View File
@@ -1,5 +1,5 @@
// //
// "$Id: Fl_cutpaste_mac.cxx,v 1.1.2.1 2001/11/27 17:44:06 easysw Exp $" // "$Id: Fl_cutpaste_mac.cxx,v 1.1.2.2 2001/12/22 09:30:07 matthiaswm Exp $"
// //
// MacOS cut/paste code for the Fast Light Tool Kit (FLTK). // MacOS cut/paste code for the Fast Light Tool Kit (FLTK).
// //
@@ -29,120 +29,81 @@
#include <FL/mac.H> #include <FL/mac.H>
#include <FL/Fl_Window.H> #include <FL/Fl_Window.H>
#include <string.h> #include <string.h>
/*
static char *selection_buffer; static char *selection_buffer = 0L;
static int selection_length; static int selection_length = 0;
static int selection_buffer_length; static int selection_buffer_length = 0;
static char beenhere;
static ScrapRef myScrap = 0;
extern Fl_Widget *fl_selection_requestor; // widget doing request_paste() extern Fl_Widget *fl_selection_requestor; // widget doing request_paste()
static int selection_xevent_handler(int) { /**
* call this to retrieve the current slection
switch (fl_xevent->type) { * receiver: widget receiving the selection
* Fl::e_text: pointer to selection
case SelectionNotify: { * Fl::e_length: size of election
if (!fl_selection_requestor) return 0; */
static char *pastebuffer; void Fl::paste( Fl_Widget &receiver )
if (pastebuffer) {XFree(pastebuffer); pastebuffer = 0;} {
if (fl_xevent->xselection.property != 0) { ScrapRef scrap = 0;
Atom a; int f; unsigned long n,b; OSStatus ret = GetCurrentScrap( &scrap );
if (!XGetWindowProperty(fl_display, if ( ( scrap != myScrap ) && ( ret == noErr ) )
fl_xevent->xselection.requestor, {
fl_xevent->xselection.property, Size len;
0,100000,1,0,&a,&f,&n,&b, ret = GetScrapFlavorSize( scrap, kScrapFlavorTypeText, &len );
(unsigned char**)&pastebuffer)) { if ( ret != noErr ) return;
Fl::e_text = pastebuffer; if ( len > selection_buffer_length )
Fl::e_length = int(n); {
fl_selection_requestor->handle(FL_PASTE); selection_buffer_length = len + 32;
} delete[] selection_buffer;
}} selection_buffer = new char[len];
return 1; selection_buffer_length = len;
case SelectionClear:
Fl::selection_owner(0);
return 1;
case SelectionRequest: {
XSelectionEvent e;
e.type = SelectionNotify;
e.display = fl_display;
e.requestor = fl_xevent->xselectionrequest.requestor;
e.selection = fl_xevent->xselectionrequest.selection;
e.target = fl_xevent->xselectionrequest.target;
e.time = fl_xevent->xselectionrequest.time;
if (fl_xevent->xselectionrequest.target != XA_STRING || !selection_length) {
e.property = 0;
} else {
e.property = fl_xevent->xselectionrequest.property;
} }
if (e.property) { GetScrapFlavorData( scrap, kScrapFlavorTypeText, &len, selection_buffer );
XChangeProperty(fl_display, e.requestor, e.property, selection_length = len;
XA_STRING, 8, 0, (unsigned char *)selection_buffer,
selection_length);
}
XSendEvent(fl_display, e.requestor, 0, 0, (XEvent *)&e);}
return 1;
default:
return 0;
} }
for ( char *s = selection_buffer+selection_length; s >= selection_buffer; s-- ) // this will fail on PC line endings (CR+LF)
if ( *s == 0x0d ) *s = 0x0a;
Fl::e_text = selection_buffer;
Fl::e_length = selection_length;
receiver.handle( FL_PASTE );
return;
} }
*/
////////////////////////////////////////////////////////////////
// Call this when a "paste" operation happens:
void Fl::paste(Fl_Widget &/*receiver*/) { /**
/* //++ * create a selection
if (selection_owner()) { * owner: widget that created the selection
// We already have it, do it quickly without window server. * stuff: pointer to selected data
// Notice that the text is clobbered if set_selection is * size of selected data
// called in response to FL_PASTE! */
Fl::e_text = selection_buffer; void Fl::selection( Fl_Widget &owner, const char *stuff, int len ) {
Fl::e_length = selection_length; if ( !stuff || len<0 )
receiver.handle(FL_PASTE);
return; return;
} if ( len+1 > selection_buffer_length ) {
// otherwise get the window server to return it:
fl_selection_requestor = &receiver;
XConvertSelection(fl_display, XA_PRIMARY, XA_STRING, XA_PRIMARY,
fl_xid(Fl::first_window()), fl_event_time);
if (!beenhere) {
Fl::add_handler(selection_xevent_handler);
beenhere = 1;
}
*/
}
////////////////////////////////////////////////////////////////
// call this when you create a selection:
void Fl::selection(Fl_Widget &/*owner*/, const char */*stuff*/, int /*len*/) {
/* //++
if (!stuff || len<0) return;
if (len+1 > selection_buffer_length) {
delete[] selection_buffer; delete[] selection_buffer;
selection_buffer = new char[len+100]; selection_buffer = new char[len+100];
selection_buffer_length = len+100; selection_buffer_length = len+100;
} }
memcpy(selection_buffer, stuff, len); memcpy( selection_buffer, stuff, len );
selection_buffer[len] = 0; // needed for direct paste for ( char *s = selection_buffer+len; s >= selection_buffer; s-- ) // this will fail on PC line endings (CR+LF)
if ( *s == 0x0a ) *s = 0x0d;
selection_buffer[len] = 0;
selection_length = len; selection_length = len;
selection_owner(&owner); selection_owner( &owner );
static Window selxid; // window X thinks selection belongs to
if (!selxid) selxid = ClearCurrentScrap();
XCreateSimpleWindow(fl_display, OSStatus ret = GetCurrentScrap( &myScrap );
RootWindow(fl_display, fl_screen), if ( ret != noErr )
0,0,1,1,0,0,0); {
XSetSelectionOwner(fl_display, XA_PRIMARY, selxid, fl_event_time); myScrap = 0;
if (!beenhere) { return;
Fl::add_handler(selection_xevent_handler);
beenhere = 1;
} }
*/ PutScrapFlavor( myScrap, kScrapFlavorTypeText, 0, selection_length, selection_buffer );
} }
// //
// End of "$Id: Fl_cutpaste_mac.cxx,v 1.1.2.1 2001/11/27 17:44:06 easysw Exp $". // End of "$Id: Fl_cutpaste_mac.cxx,v 1.1.2.2 2001/12/22 09:30:07 matthiaswm Exp $".
// //