Browse Source

Add getTabs, checked and enabled callback for button/menu

master
boisso 7 years ago
parent
commit
6b16be3da6
  1. 46
      k-meleon/JSBridge/jscomp.cpp
  2. 20
      k-meleon/JSBridge/jscomp.h
  3. 34
      k-meleon/JSBridge/jsplugin.cpp
  4. 5
      k-meleon/JSBridge/nsIJSBridge.idl

46
k-meleon/JSBridge/jscomp.cpp

@ -63,7 +63,7 @@ int CCmdList::GetState(int command) {
bool b;
if (eIter != eMap.end()) {
eIter->second->Run(nullptr, &b);
if (b) res |= 0x1;
if (!b) res |= 0x1;
}
if (cIter != cMap.end()) {
cIter->second->Run(nullptr, &b);
@ -397,6 +397,15 @@ NS_IMETHODIMP CJSBridge::SetAccel(const char * key, const char * command)
return NS_OK;
}
/*NS_IMETHODIMP CJSBridge::SetStatusBarText(kmIWindow *win, const char *text)
{
HWND hwnd = NULL;
if (win) win->GetHandle((void**)&hwnd);
kPlugin.kFuncs->SetStatusBarText(text);
return NS_OK;
}*/
NS_IMETHODIMP CJSBridge::CreateButton(const char * cmd, const char * menu, const char * tooltip, const char * label, kmIButton * *_retval)
{
CJSButton* button = new CJSButton();
@ -432,11 +441,34 @@ public:
NS_IMPL_ISUPPORTS (CWin, kmIWindow)
NS_IMETHODIMP CWin::GetHandle(void **aHandle) {
NS_IMETHODIMP CWin::GetHandle(void **aHandle)
{
*aHandle = hWnd;
return NS_OK;
}
NS_IMETHODIMP CWin::GetTabs(uint32_t *length, nsIWebBrowser * **list)
{
*list = nullptr;
*length = 0;
HWND hwnd = NULL;
GetHandle((void**)&hwnd);
int size = kPlugin.kFuncs->GetTabsList(hwnd, NULL, 0);
if (size == 0) return NS_OK;
HWND* hList = new HWND[size];
kPlugin.kFuncs->GetTabsList(hwnd, hList, size);
nsIWebBrowser** wins = static_cast<nsIWebBrowser**>(NS_Alloc(size*sizeof(nsIWebBrowser*)));
for (int i = 0;i<size;i++) {
wins[i] = nullptr;
kPlugin.kFuncs->GetMozillaWebBrowser(hList[i], &wins[i]);
}
delete [] hList;
if (length) *length = size;
*list = wins;
return NS_OK;
}
NS_IMETHODIMP CJSBridge::GetWindows(uint32_t *length, kmIWindow * **list)
{
*list = nullptr;
@ -460,6 +492,16 @@ NS_IMETHODIMP CJSBridge::GetWindows(uint32_t *length, kmIWindow * **list)
return NS_OK;
}
NS_IMETHODIMP CJSBridge::GetCurrentWindow(kmIWindow * *_retval)
{
CWin* win = new CWin();
win->hWnd = kPlugin.kFuncs->GetCurrent(NULL);
void *result;
win->QueryInterface(NS_GET_TEMPLATE_IID(kmIWindow), &result);
*_retval = static_cast<kmIWindow*>(result);
return NS_OK;
}
NS_IMETHODIMP CJSBridge::AddListener(nsIObserver* listener)
{
NS_ENSURE_ARG_POINTER(listener);

20
k-meleon/JSBridge/jscomp.h

@ -27,6 +27,26 @@ public:
}
bool Run(HWND hwnd, UINT command, UINT mode);
int GetState(int id);
kmICommandFunction* Get(int id) {
auto iter = cmdMap.find(id);
if (iter != cmdMap.end()) return iter->second;
return nullptr;
}
int GetChecked(int id) {
bool b;
auto cIter = cMap.find(id);
if (cIter == cMap.end()) return -1;
cIter->second->Run(nullptr, &b);
return b?1:0;
}
int GetEnabled(int id) {
bool b;
auto eIter = eMap.find(id);
if (eIter == eMap.end()) return -1;
eIter->second->Run(nullptr, &b);
return b?1:0;
}
};
typedef std::string string;

34
k-meleon/JSBridge/jsplugin.cpp

@ -194,6 +194,40 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case TB_MBUTTONDOWN:
if (cmdList && cmdList->Run(hWnd, LOWORD(wParam), 2)) return 0;
break;
case WM_INITMENUPOPUP: {
// Let MFC do its little update
LRESULT res = CallWindowProc(KMeleonWndProc, hWnd, message, wParam, lParam);
HMENU menu = (HMENU)wParam;
int count = GetMenuItemCount(menu);
for (int i=0;i<count;i++)
{
int id = GetMenuItemID(menu, i);
if (!id>0 || !cmdList->Get(id)) continue;
MENUITEMINFO mif;
mif.cbSize = sizeof(mif);
mif.fMask = MIIM_STATE;
GetMenuItemInfo(menu, i, TRUE, &mif);
int state = cmdList->GetChecked(id);
if (state != -1) {
mif.fState &= ~MF_CHECKED & ~MF_UNCHECKED;
mif.fState |= state ? MF_CHECKED : MF_UNCHECKED;
}
state = cmdList->GetEnabled(id);
if (state != -1) {
mif.fState &= ~MF_GRAYED & ~MF_ENABLED;
mif.fState |= state ? MF_ENABLED : MF_GRAYED;
}
::SetMenuItemInfo(menu, i, TRUE, &mif);
}
return res;
}
/*case TB_RBUTTONDOWN:
if (cmdList && cmdList->Run(hWnd, LOWORD(wParam), 2)) return 0;
break;*/

5
k-meleon/JSBridge/nsIJSBridge.idl

@ -19,6 +19,7 @@ interface kmICallback:nsISupports {
[scriptable,function, uuid(83910267-7670-4493-99c1-dd540a036ef5)]
interface kmIWindow:nsISupports {
readonly attribute voidPtr handle;
void getTabs([optional] out unsigned long length, [array, size_is(length), retval] out nsIWebBrowser list);
};
[scriptable, uuid(3d8ce8f0-5214-11db-b0de-0800200c9a65)]
@ -79,11 +80,13 @@ interface nsIJSBridge : nsISupports
[implicit_jscontext]
void SetButtonIcon(in string toolbar, in string command, in jsval icon);
void SetAccel(in string key, in string command);
//void SetStatusBarText(in kmIWindow win, in string text);
nsIWebBrowser Open(in string url, in unsigned short state);
nsIWebBrowser GetActiveBrowser();
kmIWindow GetCurrentWindow();
void GetWindows([optional] out unsigned long length, [array, size_is(length), retval] out kmIWindow list);
//void GetTabs([optional] in kmIWindow win, [optional] out unsigned long length, [array, size_is(length), retval] out nsIWebBrowser list);
void AddListener(in nsIObserver listener);
void RemoveListener(in nsIObserver listener);

Loading…
Cancel
Save