/*
* -----
* Screenshot Sender - ss_events.js
* -----
* Screenshot Sender Events
* -----
*/
function LoadEventsSubclassWindow() {
_debug.getfuncname(arguments);
var oWindow = OpenWindow('ScreenshotSender_Subclass', WNDOPT_INVISIBLE | WNDOPT_NOACTIVATE, true);
RegisterWindowHooks(oWindow, [
WM_CONTACTSIGNIN,
WM_CONTACTSIGNOUT,
WM_CONTACTSTATUSCHANGE,
WM_CHATWNDOPEN,
WM_CHATWNDCLOSED,
WM_SCREENSHOTADDED,
WM_IDLEUPLOAD
]);
}
function BroadcastEvent(nEvent, wParam, lParam) {
_debug.getfuncname(arguments);
if (typeof wParam === TYPE_UNDEFINED) wParam = 0;
if (typeof lParam === TYPE_UNDEFINED) lParam = 0;
_win32.PostMessageW(_win32._const._HWND_BROADCAST, nEvent, wParam, lParam);
}
function OnEvent_MyStatusChange(nStatus) {
if (nStatus === STATUS_IDLE) {
BroadcastEvent(WM_IDLEUPLOAD);
}
}
function OnEvent_ContactStatusChange(sEmail, nStatus) {
BroadcastEvent(WM_CONTACTSTATUSCHANGE, sEmail, nStatus);
}
function OnEvent_ContactSignIn(sEmail) {
BroadcastEvent(WM_CONTACTSIGNIN, sEmail);
}
function OnEvent_ContactSignout(sEmail) {
BroadcastEvent(WM_CONTACTSIGNOUT, sEmail);
}
function OnEvent_ContactBlocked(sEmail) {
BroadcastEvent(WM_CONTACTSIGNOUT, sEmail);
}
function OnEvent_ContactUnblocked(sEmail) {
BroadcastEvent(WM_CONTACTSIGNIN, sEmail);
}
function OnEvent_ChatWndCreated(oChatWnd) {
for (var o = new Enumerator(oChatWnd.Contacts); !o.atEnd(); o.moveNext()) {
BroadcastEvent(WM_CHATWNDOPEN, o.item().Email);
}
}
function OnEvent_ChatWndDestroyed(oChatWnd) {
for (var o = new Enumerator(oChatWnd.Contacts); !o.atEnd(); o.moveNext()) {
BroadcastEvent(WM_CHATWNDCLOSED, o.item().Email);
}
}
function OnScreenshotSender_SubclassEvent_MessageNotification(pPlusWnd, nMessage, wParam, lParam) {
_debug.getfuncname(arguments);
// Get the string from the wParam pointer
if (wParam !== 0) {
var wParamPtr = Interop.Allocate(512);
_win32.RtlMoveMemory(wParamPtr, wParam, 512);
wParam = wParamPtr.ReadString(0);
wParamPtr.Size = 0;
}
var bAddContact = false;
switch (nMessage) {
case WM_IDLEUPLOAD :
Ftp_InitiateFileTransferOnIdle();
break;
case WM_SCREENSHOTADDED :
RefreshScreenshotViewerList();
break;
case WM_CHATWNDOPEN :
bAddContact = true;
case WM_CHATWNDCLOSED :
if (typeof objWindows['ContactSelector'] !== TYPE_UNDEFINED) {
var t = objWindows['ContactSelector'];
if (t.Button_IsChecked('chkShowConversationContacts')) {
var o = Messenger.MyContacts.GetContact(wParam);
var nIndex = ItemExistsInLstView(o.Email, t, 'LvContacts', 1);
if (bAddContact === true) {
if (nIndex === false) {
nIndex = t.LstView_AddItem('LvContacts', RemovePlusCodes(o.Name));
t.LstView_SetItemText('LvContacts', nIndex, 1, o.Email);
t.LstView_SetItemIcon('LvContacts', nIndex, oStatus[o.Status], true);
}
} else {
if (nIndex !== false) {
t.LstView_RemoveItem('LvContacts', nIndex);
}
}
}
}
break;
case WM_CONTACTSIGNIN :
if (typeof objWindows['ContactSelector'] !== TYPE_UNDEFINED) {
var t = objWindows['ContactSelector'];
if (t.Button_IsChecked('chkShowConversationContacts') === false) {
var oContact = Messenger.MyContacts.GetContact(wParam);
var nIndex = ItemExistsInLstView(oContact.Email, t, 'LvContacts', 1);
if (nIndex === false) {
nIndex = t.LstView_AddItem('LvContacts', RemovePlusCodes(Contact.Name));
}
t.LstView_SetItemText('LvContacts', nIndex, 1, wParam);
t.LstView_SetItemIcon('LvContacts', nIndex, oStatus[oContact.Status], true);
} else OnContactSelectorEvent_CtrlClicked(t, 'chkShowConversationContacts');
}
break;
case WM_CONTACTSTATUSCHANGE :
var t = objWindows['ContactSelector'];
var oContact = Messenger.MyContacts.GetContact(wParam);
var nIndex = ItemExistsInLstView(oContact.Email, t, 'LvContacts', 1);
if (nIndex !== false) {
t.LstView_SetItemText('LvContacts', nIndex, 1, wParam);
t.LstView_SetItemIcon('LvContacts', nIndex, oStatus[oContact.Status ], true);
}
break;
case WM_CONTACTSIGNOUT :
objWindows['ContactSelector'].LstView_RemoveItem('LvContacts', ItemExistsInLstView(wParam, objWindows['ContactSelector'], 'LvContacts', 1));
break;
}
}
function ItemExistsInLstView(sItem, pPlusWnd, sLstViewName, iColumn) {
_debug.getfuncname(arguments);
// Note: may want to use reverse loop here?
// Pro: faster, Con: matching will be done in reverse (first item tested last)
for (var i=0, len=pPlusWnd.LstView_GetCount(sLstViewName); i<len; ++i) {
if (pPlusWnd.LstView_GetItemText(sLstViewName, i, iColumn) === sItem) {
return i;
}
}
return false;
}
function LstViewColumnToArray(pPlusWnd, sLstViewName, iColumn) {
_debug.getfuncname(arguments);
var tArray = [], i = pPlusWnd.LstView_GetCount(sLstViewName);
// Super fast reverse array populating!
while (i--) {
tArray[i] = pPlusWnd.LstView_GetItemText(sLstViewName, i, iColumn);
}
return tArray;
}