summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2010-08-26 12:29:37 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2010-08-26 12:29:37 +0200
commit41336db4593f4ef94e6eec6c7a78f278f1125f87 (patch)
tree98f2d08d239ba05fed8b6071f0318277cc0b050c
parent96803f0f05413ce642aecdd1fa016a12ecb92ff0 (diff)
downloadfpGUI-41336db4593f4ef94e6eec6c7a78f278f1125f87.tar.xz
GDI: Correctly implement clipboard support under Windows.
This includes unicode text support.
-rw-r--r--src/corelib/fpg_base.pas3
-rw-r--r--src/corelib/gdi/fpg_gdi.pas49
2 files changed, 32 insertions, 20 deletions
diff --git a/src/corelib/fpg_base.pas b/src/corelib/fpg_base.pas
index b9bc394b..dab57e0c 100644
--- a/src/corelib/fpg_base.pas
+++ b/src/corelib/fpg_base.pas
@@ -531,7 +531,7 @@ type
procedure DoSetText(const AValue: TfpgString); virtual; abstract;
procedure InitClipboard; virtual; abstract;
public
- constructor Create;
+ constructor Create; virtual;
property Text: TfpgString read DoGetText write DoSetText;
end;
@@ -2296,6 +2296,7 @@ end;
constructor TfpgClipboardBase.Create;
begin
+ inherited Create;
InitClipboard;
end;
diff --git a/src/corelib/gdi/fpg_gdi.pas b/src/corelib/gdi/fpg_gdi.pas
index e242bfb6..ccf460e2 100644
--- a/src/corelib/gdi/fpg_gdi.pas
+++ b/src/corelib/gdi/fpg_gdi.pas
@@ -2350,36 +2350,47 @@ begin
end;
procedure TfpgGDIClipboard.DoSetText(const AValue: TfpgString);
+var
+ mem: THandle;
+ po2: PWideChar;
+ str: PWideChar;
begin
FClipboardText := AValue;
- if OpenClipboard(FClipboardWndHandle) then
+ if OpenClipboard(0) then
begin
- EmptyClipboard;
- SetClipboardData(CF_TEXT, 0);
+ str := PWideChar(Utf8Decode(AValue));
+ if EmptyClipboard then
+ begin
+ // Allocate a global memory object for the text.
+ mem:= globalalloc(GMEM_MOVEABLE or GMEM_DDESHARE, (length(AValue)+1)*2);
+ if mem <> 0 then
+ begin
+ po2:= globallock(mem);
+ if po2 <> nil then
+ begin
+ move(str^, po2^, (length(AValue)+1)*2);
+ globalunlock(mem);
+ if SetClipboardData(CF_UNICODETEXT,longword(mem)) <> 0 then
+ begin
+ //writeln('Successfully copied to clipboard');
+ end;
+ end
+ else
+ begin
+ globalfree(mem);
+ end;
+ end;
+ end;
CloseClipboard;
end;
end;
procedure TfpgGDIClipboard.InitClipboard;
begin
- {$WARNING This does not work! 'FPGUI' window class was not registered,
- so CreateWindowEx always returns 0}
- FClipboardWndHandle := Windows.CreateWindowEx(
- 0, // extended window style
- 'FPGUI', // registered class name
- nil, // window name
- 0, // window style
- 0, // horizontal position of window
- 0, // vertical position of window
- 10, // window width
- 10, // window height
- 0, // handle to parent or owner window
- 0, // menu handle or child identifier
- MainInstance, // handle to application instance
- nil // window-creation data
- );
+ // nothing to do here
end;
+
{ TfpgGDIFileList }
function TfpgGDIFileList.EncodeAttributesString(attrs: longword