Skip to content

Commit

Permalink
Merge pull request #1 from notsecure/master
Browse files Browse the repository at this point in the history
Updating
  • Loading branch information
CowInAPie committed Aug 5, 2014
2 parents 98a04fc + c51029e commit 639b625
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 12 deletions.
24 changes: 18 additions & 6 deletions tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,17 @@ static void callback_file_control(Tox *tox, int32_t fid, uint8_t receive_send, u
fclose(ft->data);
postmessage(FRIEND_FILE_IN_DONE, fid, filenumber, ft->path);
}

tox_file_send_control(tox, fid, 1, filenumber, TOX_FILECONTROL_FINISHED, NULL, 0);

} else {
if(ft->status == FT_NONE) {
if(!ft->inline_png) {
fclose(ft->data);
free(ft->buffer);
}
postmessage(FRIEND_FILE_OUT_DONE, fid, filenumber, ft->path);
}
}
break;
}
Expand Down Expand Up @@ -520,16 +531,11 @@ void tox_thread(void *args)
}
if(ft->finish) {
tox_file_send_control(tox, ft->fid, 0, ft->filenumber, TOX_FILECONTROL_FINISHED, NULL, 0);
if(!ft->inline_png) {
fclose(ft->data);
free(ft->buffer);
}

memmove(p, p + 1, ((void*)file_tend - (void*)(p + 1)));
p--;
file_tend--;
ft->status = FT_NONE;
postmessage(FRIEND_FILE_OUT_DONE, ft->fid, ft->filenumber, ft->data);
break;
}

Expand Down Expand Up @@ -765,13 +771,15 @@ static void tox_thread_message(Tox *tox, ToxAv *av, uint8_t msg, uint16_t param1
//paths with line breaks
uint8_t *name = data, *p = data, *s = name;
while(*p) {
_Bool end = 1;
while(*p) {
if(*p == '\n') {
*p = 0;
end = 0;
break;
}

if(*p == '/') {
if(*p == '/' || *p == '\\') {
s = p + 1;
}
p++;
Expand All @@ -784,6 +792,10 @@ static void tox_thread_message(Tox *tox, ToxAv *av, uint8_t msg, uint16_t param1
startft(tox, param1, name, s, p - s);
p++;
s = name = p;

if(end) {
break;
}
}
} else {
//windows path list
Expand Down
120 changes: 120 additions & 0 deletions win32/dnd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@

typedef struct {
IDropTarget dt;
LONG ref;
} my_IDropTarget;

ULONG __stdcall dnd_AddRef(IDropTarget *lpMyObj)
{
my_IDropTarget *p = (void*)lpMyObj;
return InterlockedIncrement(&p->ref);
}

ULONG __stdcall dnd_Release(IDropTarget *lpMyObj)
{
my_IDropTarget *p = (void*)lpMyObj;
LONG count = InterlockedDecrement(&p->ref);

if(!count) {
free(lpMyObj->lpVtbl);
free(lpMyObj);
}

return count;
}

HRESULT __stdcall dnd_QueryInterface(IDropTarget *lpMyObj, REFIID riid, LPVOID FAR * lppvObj)
{
*lppvObj = NULL;

// PRINT_GUID (riid);
if (IsEqualIID (riid, &IID_IUnknown) || IsEqualIID (riid, &IID_IDropTarget))
{
dnd_AddRef (lpMyObj);
*lppvObj = lpMyObj;
return S_OK;
}

return E_NOINTERFACE;
}

HRESULT __stdcall dnd_DragEnter(IDropTarget *lpMyObj, IDataObject * pDataObject, DWORD grfKeyState, POINTL pt, DWORD * pdwEffect)
{
*pdwEffect = DROPEFFECT_COPY;
return S_OK;
}

HRESULT __stdcall dnd_DragOver(IDropTarget *lpMyObj, DWORD grfKeyState, POINTL pt, DWORD * pdwEffect)
{
*pdwEffect = DROPEFFECT_COPY;
return S_OK;
}

HRESULT __stdcall dnd_DragLeave(IDropTarget *lpMyObj)
{
return S_OK;
}

HRESULT __stdcall dnd_Drop(IDropTarget *lpMyObj, IDataObject * pDataObject, DWORD grfKeyState, POINTL pt, DWORD * pdwEffect)
{
*pdwEffect = DROPEFFECT_COPY;
debug("droppped!\n");

if(sitem->item != ITEM_FRIEND) {
return S_OK;
}

FORMATETC format = {
.cfFormat = CF_HDROP,
.dwAspect = DVASPECT_CONTENT,
.lindex = -1,
.tymed = TYMED_HGLOBAL,
};
STGMEDIUM medium;

HRESULT r = pDataObject->lpVtbl->GetData(pDataObject, &format, &medium);
if(r == S_OK) {
HDROP h = medium.hGlobal;
int count = DragQueryFile(h, ~0, NULL, 0);
debug("%u files dropped\n", count);
int i;

char *paths = malloc(count * 256);
if(paths) {
char *p = paths;
for(i = 0; i != count; i++) {
p += DragQueryFile(h, i, p, 256);
*p++ = '\n';
}

tox_postmessage(TOX_SENDFILES, (FRIEND*)sitem->data - friend, 0xFFFF, paths);
}

ReleaseStgMedium(&medium);
} else {
debug("itz failed! %X\n", r);
}

return S_OK;
}

static void dnd_init(HWND hwnd)
{
my_IDropTarget *p;
p = malloc(sizeof(my_IDropTarget));
p->dt.lpVtbl = malloc(sizeof(*(p->dt.lpVtbl)));
p->ref = 0;

p->dt.lpVtbl->QueryInterface = dnd_QueryInterface;
p->dt.lpVtbl->AddRef = dnd_AddRef;
p->dt.lpVtbl->Release = dnd_Release;

p->dt.lpVtbl->DragEnter = dnd_DragEnter;
p->dt.lpVtbl->DragLeave = dnd_DragLeave;
p->dt.lpVtbl->DragOver = dnd_DragOver;
p->dt.lpVtbl->Drop = dnd_Drop;

CoLockObjectExternal((struct IUnknown*)p, TRUE, FALSE);

RegisterDragDrop(hwnd, (IDropTarget*)p);
}
6 changes: 6 additions & 0 deletions win32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,8 @@ static UTOX_SAVE* loadconfig(void)
return r;
}

#include "dnd.c"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR cmd, int nCmdShow)
{
/* if opened with argument, check if uTox is already open and pass the argument to the existing process */
Expand Down Expand Up @@ -1066,6 +1068,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR cmd, int n
.cbSize = sizeof(nid),
};


OleInitialize(NULL);
RegisterClassW(&wc);
RegisterClassW(&wc2);

Expand Down Expand Up @@ -1094,6 +1098,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR cmd, int n

SetBkMode(hdc, TRANSPARENT);

dnd_init(hwnd);

//wait for tox_thread init
while(!tox_thread_init) {
Sleep(1);
Expand Down
4 changes: 1 addition & 3 deletions xlib/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ static void saveprimary(void)
}
}

_Bool doevent(void)
_Bool doevent(XEvent event)
{
XEvent event;
XNextEvent(display, &event);
if(event.xany.window && event.xany.window != window) {
if(event.type == ClientMessage) {
XClientMessageEvent *ev = &event.xclient;
Expand Down
29 changes: 26 additions & 3 deletions xlib/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Pixmap drawbuf;
Picture renderpic;
Picture colorpic;

_Bool _redraw;

uint16_t drawwidth, drawheight;

XImage *screen_image;
Expand Down Expand Up @@ -599,7 +601,7 @@ void showkeyboard(_Bool show)

void redraw(void)
{
panel_draw(&panel_main, 0, 0, width, height);
_redraw = 1;
}

#include "event.c"
Expand Down Expand Up @@ -770,10 +772,31 @@ int main(int argc, char *argv[])
list_start();

/* draw */
redraw();
panel_draw(&panel_main, 0, 0, width, height);

/* event loop */
while(doevent());
while(1) {
/* block on the first event, then process all events */
XEvent event;

XNextEvent(display, &event);
if(!doevent(event)) {
break;
}

while(XPending(display)) {
XNextEvent(display, &event);
if(!doevent(event)) {
goto BREAK;
}
}

if(_redraw) {
panel_draw(&panel_main, 0, 0, width, height);
_redraw = 0;
}
}
BREAK:

toxaudio_postmessage(AUDIO_KILL, 0, 0, NULL);
toxvideo_postmessage(VIDEO_KILL, 0, 0, NULL);
Expand Down

0 comments on commit 639b625

Please sign in to comment.