Skip to content

Commit edbfa29

Browse files
committed
Symbian: Implement clipboard
1 parent 900d76d commit edbfa29

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

misc/symbian/ClassiCube.mmh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ LIBRARY apparc.lib
1616
LIBRARY eikcore.lib
1717
LIBRARY eikdlg.lib
1818
LIBRARY mediaclientaudiostream.lib
19+
LIBRARY estor.lib
20+
LIBRARY bafl.lib
1921

2022
LIBRARY libc.lib
2123
LIBRARY libm.lib

src/symbian/Window_Symbian.cpp

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <AknUtils.h>
1818
#include <eikstart.h>
1919
#include <aknmessagequerydialog.h>
20+
#include <baclipb.h>
21+
#include <s32ucmp.h>
2022
#include <classicube.rsg>
2123

2224
extern "C" {
@@ -801,6 +803,63 @@ static void ShowDialogL(const char* title, const char* msg) {
801803
dialog->RunLD();
802804
}
803805

806+
static void GetClipboardL(cc_string* value) {
807+
TUid uid = {268450333}; // KClipboardUidTypePlainText
808+
809+
CClipboard* cb = CClipboard::NewForReadingLC(CCoeEnv::Static()->FsSession());
810+
TStreamId stid = cb->StreamDictionary().At(uid);
811+
if (stid != KNullStreamId) {
812+
RStoreReadStream stream;
813+
stream.OpenLC(cb->Store(), stid);
814+
const TInt32 size = stream.ReadInt32L();
815+
HBufC* buf = HBufC::NewLC(size);
816+
buf->Des().SetLength(size);
817+
818+
TUnicodeExpander e;
819+
TMemoryUnicodeSink sink(&buf->Des()[0]);
820+
e.ExpandL(sink, stream, size);
821+
822+
String_AppendUtf16(value, buf->Ptr(), buf->Length() * 2);
823+
824+
stream.Close();
825+
CleanupStack::Pop();
826+
CleanupStack::PopAndDestroy(buf);
827+
}
828+
CleanupStack::PopAndDestroy(cb);
829+
}
830+
831+
static void SetClipboardL(const cc_string* value) {
832+
TUid uid = {268450333}; // KClipboardUidTypePlainText
833+
834+
HBufC* buf = HBufC::NewLC(value->length + 1);
835+
TPtr16 des = buf->Des();
836+
ConvertToUnicode(des, value);
837+
838+
CClipboard* cb = CClipboard::NewForWritingLC(CCoeEnv::Static()->FsSession());
839+
840+
RStoreWriteStream stream;
841+
TStreamId stid = stream.CreateLC(cb->Store());
842+
stream.WriteInt32L(buf->Length());
843+
844+
TUnicodeCompressor c;
845+
TMemoryUnicodeSource source(buf->Ptr());
846+
TInt bytes(0);
847+
TInt words(0);
848+
c.CompressL(stream, source, KMaxTInt, buf->Length(), &bytes, &words);
849+
850+
stream.WriteInt8L(0);
851+
852+
stream.CommitL();
853+
cb->StreamDictionary().AssignL(uid, stid);
854+
cb->CommitL();
855+
856+
stream.Close();
857+
CleanupStack::PopAndDestroy();
858+
CleanupStack::PopAndDestroy(cb);
859+
860+
CleanupStack::PopAndDestroy(buf);
861+
}
862+
804863
// Window implementation
805864

806865
void Window_PreInit(void) {
@@ -835,11 +894,11 @@ void Window_Destroy(void) { }
835894
void Window_SetTitle(const cc_string* title) { }
836895

837896
void Clipboard_GetText(cc_string* value) {
838-
// TODO
897+
TRAP_IGNORE(GetClipboardL(value));
839898
}
840899

841900
void Clipboard_SetText(const cc_string* value) {
842-
// TODO
901+
TRAP_IGNORE(SetClipboardL(value));
843902
}
844903

845904
int Window_GetWindowState(void) {

0 commit comments

Comments
 (0)