Menu

#197 Timer support for nsDialogs

closed-accepted
Plugin (47)
5
2014-08-28
2008-09-29
No

Inspired by this thread: http://forums.winamp.com/showthread.php?s=&threadid=296985

I added timer support for nsDialogs. Patch adds two new functions to nsDialogs (CreateTimer and DestroyTimer).

nsDialogs::CreateTimer time_in_milliseconds function_address
On sucess it will push timer id and on failure "error" to the the stack. Timer id be also waiting on the stack when the callback function is called.

nsDialogs::DestroyTimer timer_id
Simply kills the timer specified by the timer id. Doesn't push anytin in the stack.

---
WM_TIMER notification fo DialogProc
---

case WM_TIMER:
{
struct nsControl* ctl = &g_dialog.controls[wParam - 100];

if (ctl == NULL)
break;

if (!ctl->callbacks.onClick)
break;

pushint((int) wParam);
g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onClick - 1, 0);
break;
}

---
CreateTimer and DestroyTimer functions
---

void __declspec(dllexport) CreateTimer(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
{
nsFunction callback;
UINT time;
size_t id;

// get info from stack

time = popint();

if (!time)
{
popint(); // remove callback from stack
pushstring("error");
return;
}

callback = (nsFunction) popint();

if (!callback)
{
pushstring("error");
return;
}

// create item descriptor

id = g_dialog.controlCount;
g_dialog.controlCount++;
g_dialog.controls = (struct nsControl*) HeapReAlloc(
GetProcessHeap(),
HEAP_ZERO_MEMORY,
g_dialog.controls,
g_dialog.controlCount * sizeof(struct nsControl));

g_dialog.controls[id].type = NSCTL_UNKNOWN;

// create timer

SetTimer(
g_dialog.hwDialog,
(100 + id),
time,
NULL);

g_dialog.controls[id].window = NULL;
g_dialog.controls[id].callbacks.onClick = callback;

// push back result

pushint(100 + id);
}

void __declspec(dllexport) DestroyTimer(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
{
UINT id;

// get timer id from stack

id = popint();

// kill timer

KillTimer(g_dialog.hwDialog, id);
}

Discussion

  • Pasi Ruokola

    Pasi Ruokola - 2008-09-29

    Patched nsDialogs.c and example script

     
  • Amir Szekely

    Amir Szekely - 2008-11-29

    Thanks for the patch. I love the idea. But I think the interface could be improved. There's no real need for the user to remember two variables. Just the function address is enough and can be used as an id. Also, I prefer KillTimer over DestroyTimer as it's confusing for Windows developers and I've already found myself confused a few times. Besides that, a few macros in nsDialogs.nsh can't hurt and documentation updates as well. I've done all that and attached it. Let me know what you think.

     
  • Amir Szekely

    Amir Szekely - 2008-11-29
    • assigned_to: nobody --> kichik
    • status: open --> open-accepted
     
  • Amir Szekely

    Amir Szekely - 2008-11-29

    I've went ahead and committed the changes to SVN. Check it out there.

     
  • Amir Szekely

    Amir Szekely - 2008-11-29
    • status: open-accepted --> pending-accepted
     
  • Pasi Ruokola

    Pasi Ruokola - 2008-11-30

    It's definitely better.

    I never thought of using function address as id too, but I like it. Also using the TimerProc instead of WM_TIMER is much better. I also agree about the DestroyTimer and the only reason I used it was that KillTimer was taken. :)

     
  • Pasi Ruokola

    Pasi Ruokola - 2008-11-30
    • status: pending-accepted --> open-accepted
     
  • Amir Szekely

    Amir Szekely - 2008-11-30
    • status: open-accepted --> closed-accepted
     

Log in to post a comment.