Browse Source

Add macros function logmsg, popupmenu and fix getpref localized

Add jsbridge ShowMenu
master
boisso 7 years ago
parent
commit
9aea4d8238
  1. 12
      k-meleon/JSBridge/jscomp.cpp
  2. 11
      k-meleon/JSBridge/jsplugin.cpp
  3. 1
      k-meleon/JSBridge/nsIJSBridge.idl
  4. 24
      k-meleon/Plugins.cpp
  5. 4
      k-meleon/kmeleon_plugin.h
  6. 32
      k-meleon/macros2/functions.h
  7. 6
      k-meleon/macros2/object.h
  8. 2
      k-meleon/macros2/parser.h

12
k-meleon/JSBridge/jscomp.cpp

@ -62,6 +62,12 @@ bool CCmdList::Run(HWND hwnd, UINT command, UINT mode) {
browser->GetContentDOMWindow(getter_AddRefs(dom));
auto iter = cmdMap.find(command);
if (iter != cmdMap.end() && iter->second) {
if ((GetKeyState(VK_CONTROL) & 0x8000))
mode |= 256;
if ((GetKeyState(VK_SHIFT) & 0x8000))
mode |= 512;
if ((GetKeyState(VK_MENU) & 0x8000))
mode |= 1024;
iter->second->OnCommand(dom, mode, nullptr);
return true;
}
@ -434,6 +440,12 @@ NS_IMETHODIMP CJSBridge::LoadPlugin(const char* path)
return NS_OK;
}
NS_IMETHODIMP CJSBridge::ShowMenu(const char* name, bool sendCommand, int32_t *_retval)
{
*_retval = kPlugin.kFuncs->ShowMenu(NULL, name, sendCommand);
return NS_OK;
}
bool notifyOpenWindow(nsIObserver *aListener, void* aData)
{
kmIWindow* winData = static_cast<kmIWindow*>(aData);

11
k-meleon/JSBridge/jsplugin.cpp

@ -176,8 +176,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
switch (message) {
case WM_COMMAND:
if (cmdList && cmdList->Run(hWnd, LOWORD(wParam), lParam)) return 0;
}
if (cmdList && cmdList->Run(hWnd, LOWORD(wParam), 0)) return 0;
break;
case TB_MBUTTONDOWN:
if (cmdList && cmdList->Run(hWnd, LOWORD(wParam), 2)) return 0;
break;
/*case TB_RBUTTONDOWN:
if (cmdList && cmdList->Run(hWnd, LOWORD(wParam), 2)) return 0;
break;*/
}
return CallWindowProc(KMeleonWndProc, hWnd, message, wParam, lParam);
}

1
k-meleon/JSBridge/nsIJSBridge.idl

@ -84,5 +84,6 @@ interface nsIJSBridge : nsISupports
void RemoveListener(in nsIObserver listener);
void LoadPlugin(in string path);
long ShowMenu(in string name, [optional] in bool sendCommand);
};

24
k-meleon/Plugins.cpp

@ -1397,7 +1397,8 @@ void GetBrowserviewRect(HWND mainWnd, RECT *rc)
view->GetWindowRect(rc);
}
HMENU GetMenu(char *menuName){
HMENU GetMenu(const char *menuName)
{
CMenu *menu;
USES_CONVERSION;
menu = theApp.menus.GetMenu(A2T(menuName));
@ -1405,6 +1406,21 @@ HMENU GetMenu(char *menuName){
return menu ? menu->m_hMenu : NULL;
}
UINT ShowMenu(HWND hWnd, const char *name, bool sendCommand)
{
HMENU menu = GetMenu(name);
if (!menu) return 0;
CBrowserFrame* frame = GetFrame(hWnd);
POINT pt;
GetCursorPos(&pt);
UINT flags = TPM_TOPALIGN | TPM_LEFTALIGN | TPM_NONOTIFY | TPM_LEFTBUTTON;
if (!sendCommand) flags |= TPM_RETURNCMD;
UINT id = TrackPopupMenuEx(menu, flags, pt.x, pt.y, frame->GetSafeHwnd(), NULL);
return id;
}
void SetForceCharset(const char *aCharset)
{
CBrowserWrapper* browser = GetWrapper();
@ -2061,7 +2077,8 @@ kmeleonFunctions kmelFuncsUTF8 = {
AddButton,
SetCmdIcon,
SetButtonIcon,
AddPermission
AddPermission,
ShowMenu
};
kmeleonFunctions kmelFuncs = {
@ -2137,7 +2154,8 @@ kmeleonFunctions kmelFuncs = {
AddButton,
SetCmdIcon,
SetButtonIcon,
AddPermission
AddPermission,
ShowMenu
};
BOOL CPlugins::TestLoad(LPCTSTR file, const char *description)

4
k-meleon/kmeleon_plugin.h

@ -257,7 +257,7 @@ typedef struct {
void (*GetBrowserviewRect) (HWND mainWnd, RECT *rc);
HMENU (*GetMenu) (char *menu);
HMENU (*GetMenu) (const char *menu);
void (*SetForceCharset)(const char *aCharset);
@ -386,7 +386,7 @@ typedef struct {
int (*SetCmdIcon)(const char* name, const char* icon, const LPRECT region, const char* hot, const LPRECT hotregion, const char* dead, const LPRECT deadregion);
int (*SetButtonIcon)(const char* toolbar, UINT id, const char* icon, const LPRECT region, const char* hot, const LPRECT hotregion, const char* dead, const LPRECT deadregion);
bool (*AddPermission)(const char* url, const char* type, const char* perm, bool sessionOnly);
UINT (*ShowMenu)(HWND hWnd, const char* name, bool sendCommand);
} kmeleonFunctions;
/*

32
k-meleon/macros2/functions.h

@ -376,10 +376,16 @@
MString pref = data->getstr(2);
if (preftype == PREF_UNISTRING) {
long len = kFuncs->GetPreference(PREF_LOCALIZED, pref, 0, L"");
long len = kFuncs->GetPreference(PREF_STRING, pref, 0, L"");
if (!len) return Value("");
char* cRetval = (char*)calloc(sizeof(char), len+1);
kFuncs->GetPreference(PREF_LOCALIZED, pref, cRetval, L"");
kFuncs->GetPreference(PREF_STRING, pref, cRetval, L"");
if (strncmp(cRetval, "chrome:",7) == 0) {
len = kFuncs->GetPreference(PREF_LOCALIZED, pref, 0, L"");
if (!len) return Value("");
cRetval = (char*)calloc(sizeof(char), len+1);
kFuncs->GetPreference(PREF_LOCALIZED, pref, cRetval, L"");
}
Value v(cRetval);
return v;
}
@ -1402,6 +1408,10 @@
return ret;
}*/
if (name == "VERSION") {
return kPlugin.kFuncs->GetKmeleonVersion();
}
if (name == "TextZoom") {
int zoom;
kPlugin.kFuncs->GetWindowVar(data->c.hWnd, Window_TextZoom, &zoom);
@ -1699,6 +1709,22 @@
!(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}
Value logmsg(FunctionData* data)
{
checkArgs(__FUNCTION__, data, 1, 2);
UINT flags = 5;
MString type = data->getstr(2);
if (type == "error") flags = 0;
else if (type == "warning") flags = 1;
return kPlugin.kFuncs->LogMessage("macro", data->getstr(1), data->stat->getFile(), data->stat->getLine(), flags);
}
Value popupmenu(FunctionData* data)
{
checkArgs(__FUNCTION__, data, 1, 2);
return kPlugin.kFuncs->ShowMenu(data->c.hWnd, data->getstr(1).c_str(), data->getint(2,1));
}
#ifndef MACROSFUNC_ADD
#define MACROSFUNC_ADD(entry) m->AddSymbol(#entry, ValueFunc((MacroFunction)&entry));
#endif
@ -1771,4 +1797,6 @@ void InitFunctions(Mac* m)
MACROSFUNC_ADD(renamefile);
MACROSFUNC_ADD(deletefile);
MACROSFUNC_ADD(appendfile);
MACROSFUNC_ADD(logmsg);
MACROSFUNC_ADD(popupmenu);
}

6
k-meleon/macros2/object.h

@ -259,9 +259,9 @@ typedef struct FunctionData
Statement* stat;
Value getarg(unsigned short i) {return i>0&&i<=nparam ? *(params+i-1) : Value();}
MString getstr(unsigned short i) {return i>0&&i<=nparam ? (params+i-1)->strval() : "";}
int getint(unsigned short i) {return i>0&&i<=nparam ? (params+i-1)->intval() : 0;}
int getbool(unsigned short i) {return i>0&&i<=nparam ? (params+i-1)->boolval() : 0;}
MString getstr(unsigned short i, const char* def = "") {return i>0&&i<=nparam ? (params+i-1)->strval() : def;}
int getint(unsigned short i, int def = 0) {return i>0&&i<=nparam ? (params+i-1)->intval() : def;}
int getbool(unsigned short i, int def = 0) {return i>0&&i<=nparam ? (params+i-1)->boolval() : def;}
} FunctionData;

2
k-meleon/macros2/parser.h

@ -94,7 +94,7 @@ typedef struct Program {
static char* reservedwords[] = { "while", "if", "else", "and", "or", "not", "menu", "menuchecked", "menugrayed", "macroinfo" };
#define MAXRESERVED sizeof(reservedwords) / sizeof(char*)
static char* windowvars[] = { "URL", "URLBAR", "SelectedText", "FrameURL", "LinkURL", "ImageURL", "CHARSET", "TextZoom", "TITLE", "WindowNumber", "TabNumber", "CommandLine", "SEARCHURL", "LANG" };
static char* windowvars[] = { "URL", "URLBAR", "SelectedText", "FrameURL", "LinkURL", "ImageURL", "CHARSET", "TextZoom", "TITLE", "WindowNumber", "TabNumber", "CommandLine", "SEARCHURL", "LANG", "VERSION" };
#define MAXWINDOWVARS sizeof(windowvars) / sizeof(char*)
static const int OpPriority[] = {0, 5, 5, 6, 6, 6, 4, 4, 4, 4, 4, 4, 2, 1, 3, 3};

Loading…
Cancel
Save