[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13964] trunk/blender: Added Copy and Paste functions to GHOST.

Ricki Myers antihc3 at gmail.com
Tue Mar 4 01:41:30 CET 2008


Revision: 13964
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13964
Author:   themyers
Date:     2008-03-04 01:41:30 +0100 (Tue, 04 Mar 2008)

Log Message:
-----------
Added Copy and Paste functions to GHOST.
- Moved WIN32 code to ghost and added code for other systems.
- Added functions getClipboard(flag), and putClipboard(buffer, flag)
    -Flag is used on X11 to request selection buffer or clipboard.
    -If any other system uses flag = 1 the function returns doing nothing.
- Changed ctrl +c/v and shift+ctrl + c/v to do the same thing (use the clipboard).
- Changed the menu items (copy, paste) to use the clipboard.

Modified Paths:
--------------
    trunk/blender/intern/ghost/GHOST_C-api.h
    trunk/blender/intern/ghost/GHOST_ISystem.h
    trunk/blender/intern/ghost/intern/GHOST_C-api.cpp
    trunk/blender/intern/ghost/intern/GHOST_System.h
    trunk/blender/intern/ghost/intern/GHOST_SystemCarbon.cpp
    trunk/blender/intern/ghost/intern/GHOST_SystemCarbon.h
    trunk/blender/intern/ghost/intern/GHOST_SystemWin32.cpp
    trunk/blender/intern/ghost/intern/GHOST_SystemWin32.h
    trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp
    trunk/blender/intern/ghost/intern/GHOST_SystemX11.h
    trunk/blender/intern/ghost/intern/GHOST_WindowX11.cpp
    trunk/blender/source/blender/blenkernel/BKE_text.h
    trunk/blender/source/blender/src/drawtext.c
    trunk/blender/source/blender/src/header_text.c

Modified: trunk/blender/intern/ghost/GHOST_C-api.h
===================================================================
--- trunk/blender/intern/ghost/GHOST_C-api.h	2008-03-03 21:43:31 UTC (rev 13963)
+++ trunk/blender/intern/ghost/GHOST_C-api.h	2008-03-04 00:41:30 UTC (rev 13964)
@@ -758,6 +758,18 @@
  */
 extern GHOST_TSuccess GHOST_ClipRectangle(GHOST_RectangleHandle rectanglehandle,
 										  GHOST_RectangleHandle anotherrectanglehandle);
+
+/**
+ * Return the data from the clipboad
+ * @return clipboard data
+ */
+extern GHOST_TUns8* getClipboard(int flag);
+
+/**
+ * Put data to the Clipboard
+ */
+extern void putClipboard(GHOST_TInt8 *buffer, int flag);
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/blender/intern/ghost/GHOST_ISystem.h
===================================================================
--- trunk/blender/intern/ghost/GHOST_ISystem.h	2008-03-03 21:43:31 UTC (rev 13963)
+++ trunk/blender/intern/ghost/GHOST_ISystem.h	2008-03-04 00:41:30 UTC (rev 13964)
@@ -336,6 +336,18 @@
 	 */
 	virtual GHOST_TSuccess getButtonState(GHOST_TButtonMask mask, bool& isDown) const = 0;
 
+	/**
+	 * Returns the selection buffer
+	 * @return Returns "unsinged char" from X11 XA_CUT_BUFFER0 buffer
+	 *
+	 */
+	 virtual GHOST_TUns8* getClipboard(int flag) const = 0;
+
+	/**
+	 * Put data to the Clipboard
+	 */
+	virtual void putClipboard(GHOST_TInt8 *buffer, int flag) const = 0;
+
 protected:
 	/**
 	 * Initialize the system.

Modified: trunk/blender/intern/ghost/intern/GHOST_C-api.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_C-api.cpp	2008-03-03 21:43:31 UTC (rev 13963)
+++ trunk/blender/intern/ghost/intern/GHOST_C-api.cpp	2008-03-04 00:41:30 UTC (rev 13964)
@@ -802,3 +802,16 @@
 
 	return result;
 }
+
+GHOST_TUns8* getClipboard(int flag)
+{
+	GHOST_ISystem* system = GHOST_ISystem::getSystem();
+	return system->getClipboard(flag);
+}
+
+void putClipboard(GHOST_TInt8 *buffer, int flag)
+{
+	GHOST_ISystem* system = GHOST_ISystem::getSystem();
+	system->putClipboard(buffer, flag);
+}
+

Modified: trunk/blender/intern/ghost/intern/GHOST_System.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_System.h	2008-03-03 21:43:31 UTC (rev 13963)
+++ trunk/blender/intern/ghost/intern/GHOST_System.h	2008-03-04 00:41:30 UTC (rev 13964)
@@ -257,6 +257,21 @@
 	 */
 	virtual GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const = 0;
 
+	/**
+	 * Returns the selection buffer
+	 * @param flag		Only used on X11
+	 * @return 		Returns the clipboard data
+	 *
+	 */
+	 virtual GHOST_TUns8* getClipboard(int flag) const = 0;
+	  
+	  /**
+	   * Put data to the Clipboard
+	   * @param buffer	The buffer to copy to the clipboard
+	   * @param flag	The clipboard to copy too only used on X11
+	   */
+	  virtual void putClipboard(GHOST_TInt8 *buffer, int flag) const = 0;
+
 protected:
 	/**
 	 * Initialize the system.

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemCarbon.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemCarbon.cpp	2008-03-03 21:43:31 UTC (rev 13963)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemCarbon.cpp	2008-03-04 00:41:30 UTC (rev 13964)
@@ -1065,3 +1065,71 @@
 
     return err;
 }
+
+GHOST_TUns8* GHOST_SystemCarbon::getClipboard(int flag) const
+{
+	PasteboardRef inPasteboard;
+	PasteboardItemID itemID;
+	CFDataRef flavorData;
+	OSStatus err = noErr;
+	GHOST_TUns8 * temp_buff;
+	CFRange range;
+	
+	err = PasteboardCreate(kPasteboardClipboard, &inPasteboard);
+	if(err != noErr) { return NULL;}
+
+	err = PasteboardSynchronize( inPasteboard );
+	if(err != noErr) { return NULL;}
+
+	err = PasteboardGetItemIdentifier( inPasteboard, 1, &itemID );
+	if(err != noErr) { return NULL;}
+
+	err = PasteboardCopyItemFlavorData( inPasteboard, itemID, CFSTR("public.utf8-plain-text"), &flavorData);
+	if(err != noErr) { return NULL;}
+
+	range = CFRangeMake(0, CFDataGetLength(flavorData));
+	
+	temp_buff = (GHOST_TUns8*) malloc(range.length+1); 
+
+	CFDataGetBytes(flavorData, range, (UInt8*)temp_buff);
+	
+	temp_buff[range.length] = '\0';
+	
+	if(temp_buff) {
+		return temp_buff;
+	} else {
+		return NULL;
+	}
+}
+
+void GHOST_SystemCarbon::putClipboard(GHOST_TInt8 *buffer, int flag) const
+{
+	if(flag == 1) {return;} //If Flag is 1 means the selection and is used on X11
+	PasteboardRef inPasteboard;
+	CFDataRef textData = NULL;
+	OSStatus err = noErr; /*For error checking*/
+	
+	err = PasteboardCreate(kPasteboardClipboard, &inPasteboard);
+	if(err != noErr) { return;}
+	
+	err = PasteboardSynchronize( inPasteboard ); 
+	if(err != noErr) { return;}
+	
+	err = PasteboardClear( inPasteboard );
+	if(err != noErr) { return;}
+	
+	textData = CFDataCreate(kCFAllocatorDefault, (UInt8*)buffer, strlen(buffer));
+	
+	if (textData) {
+		err = PasteboardPutItemFlavor( inPasteboard, (PasteboardItemID)1, CFSTR("public.utf8-plain-text"), textData, 0);
+			if(err != noErr) { 
+				if(textData) { CFRelease(textData);}
+				return;
+			}
+	}
+	
+	if(textData) {
+		CFRelease(textData);
+	}
+}
+

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemCarbon.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemCarbon.h	2008-03-03 21:43:31 UTC (rev 13963)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemCarbon.h	2008-03-04 00:41:30 UTC (rev 13964)
@@ -168,6 +168,20 @@
 	 */
 	virtual GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const;
 
+	/**
+	 * Returns Clipboard data
+	 * @param flag		Indicate which buffer to return
+	 * @return		Returns the selected buffer
+	 */
+	virtual GHOST_TUns8* GHOST_SystemCarbon::getClipboard(int flag) const;
+	
+	/**
+	 * Puts buffer to system clipboard
+	 * @param buffer	The buffer to be copied
+	 * @param flag		Indicates which buffer to copy too Only used on X11
+	 */
+	virtual void putClipboard(GHOST_TInt8 *buffer, int flag) const;
+
 protected:
 	/**
 	 * Initializes the system.

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemWin32.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemWin32.cpp	2008-03-03 21:43:31 UTC (rev 13963)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemWin32.cpp	2008-03-04 00:41:30 UTC (rev 13964)
@@ -873,3 +873,54 @@
 	}
 	return lResult;
 }
+
+GHOST_TUns8* GHOST_SystemWin32::getClipboard(int flag) const 
+{
+	char *buffer;
+	char *temp_buff;
+	
+	if ( OpenClipboard(NULL) ) {
+		HANDLE hData = GetClipboardData( CF_TEXT );
+		buffer = (char*)GlobalLock( hData );
+		
+		temp_buff = (char*) malloc(strlen(buffer)+1);
+		strcpy(temp_buff, buffer);
+		
+		GlobalUnlock( hData );
+		CloseClipboard();
+		
+		temp_buff[strlen(buffer)] = '\0';
+		if (buffer) {
+			return (GHOST_TUns8*)temp_buff;
+		} else {
+			return NULL;
+		}
+	} else {
+		return NULL;
+	}
+}
+
+void GHOST_SystemWin32::putClipboard(GHOST_TInt8 *buffer, int flag) const
+{
+	if(flag == 1) {return;} //If Flag is 1 means the selection and is used on X11
+	if (OpenClipboard(NULL)) {
+		HLOCAL clipbuffer;
+		char *data;
+		
+		if (buffer) {
+			EmptyClipboard();
+			
+			clipbuffer = LocalAlloc(LMEM_FIXED,((strlen(buffer)+1)));
+			data = (char*)GobalLock(clipbuffer);
+
+			strcpy(data, (char*)buffer);
+			data[strlen(buffer)] = '\0';
+			LocalUnlock(clipbuffer);
+			SetClipboardData(CF_TEXT,clipbuffer);
+		}
+		CloseClipboard();
+	} else {
+		return;
+	}
+}
+

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemWin32.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemWin32.h	2008-03-03 21:43:31 UTC (rev 13963)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemWin32.h	2008-03-04 00:41:30 UTC (rev 13964)
@@ -170,6 +170,20 @@
 	 */
 	virtual GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const;
 
+	/**
+	 * Returns unsinged char from CUT_BUFFER0
+	 * @param flag		Flag is not used on win32 on used on X11
+	 * @return		Returns the Clipboard
+	 */
+	virtual GHOST_TUns8* getClipboard(int flag) const;
+	
+	/**
+	 * Puts buffer to system clipboard
+	 * @param flag		Flag is not used on win32 on used on X11
+	 * @return		No return
+	 */
+	virtual void putClipboard(GHOST_TInt8 *buffer, int flag) const;
+	 
 protected:
 	/**
 	 * Initializes the system.

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp	2008-03-03 21:43:31 UTC (rev 13963)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp	2008-03-04 00:41:30 UTC (rev 13964)
@@ -95,6 +95,9 @@
 #include <unistd.h>
 
 #include <vector>
+//these are for copy and select copy
+static char *txt_cut_buffer= NULL;
+static char *txt_select_buffer= NULL;
 
 using namespace std;
 
@@ -336,7 +339,7 @@
 	if (!window) {
 		return;
 	}
-
+	
 	switch (xe->type) {
 		case Expose:
 		{
@@ -504,8 +507,57 @@
 		case MappingNotify:
 		case ReparentNotify:
 			break;
-
-      	default: {
+		case SelectionRequest:
+		{
+			XEvent nxe;
+			Atom target, string, compound_text, c_string;
+			XSelectionRequestEvent *xse = &xe->xselectionrequest;
+			
+			target = XInternAtom(m_display, "TARGETS", False);
+			string = XInternAtom(m_display, "STRING", False);
+			compound_text = XInternAtom(m_display, "COMPOUND_TEXT", False);
+			c_string = XInternAtom(m_display, "C_STRING", False);
+			
+			/* support obsolete clients */
+			if (xse->property == None) {
+				xse->property = xse->target;
+			}
+			
+			nxe.xselection.type = SelectionNotify;
+			nxe.xselection.requestor = xse->requestor;
+			nxe.xselection.property = xse->property;
+			nxe.xselection.display = xse->display;
+			nxe.xselection.selection = xse->selection;
+			nxe.xselection.target = xse->target;
+			nxe.xselection.time = xse->time;
+			
+			/*Check to see if the requestor is asking for String*/
+			if(xse->target == string || xse->target == compound_text || xse->target == c_string) {
+				if (xse->selection == XInternAtom(m_display, "PRIMARY", False)) {
+					XChangeProperty(m_display, xse->requestor, xse->property, xse->target, 8, PropModeReplace, (unsigned char*)txt_select_buffer, strlen(txt_select_buffer));
+				} else if (xse->selection == XInternAtom(m_display, "CLIPBOARD", False)) {
+					XChangeProperty(m_display, xse->requestor, xse->property, xse->target, 8, PropModeReplace, (unsigned char*)txt_cut_buffer, strlen(txt_cut_buffer));
+				}

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list