Browse Source

Plugin/Js cmd/toolbar implementation 1

import/tags/kmeleon75
boisso 8 years ago
parent
commit
409fd32ad7
  1. 17
      k-meleon/BrowserFrm.cpp
  2. 6
      k-meleon/BrowserFrm.h
  3. 78
      k-meleon/JSBridge/jscomp.cpp
  4. 40
      k-meleon/JSBridge/jscomp.h
  5. 4
      k-meleon/JSBridge/jsplugin.cpp
  6. 43
      k-meleon/JSBridge/nsIJSBridge.idl
  7. 6
      k-meleon/KMeleonConst.h
  8. 25
      k-meleon/KmCommand.cpp
  9. 13
      k-meleon/KmCommand.h
  10. 6
      k-meleon/KmImage.cpp
  11. 41
      k-meleon/KmSkin.cpp
  12. 10
      k-meleon/KmSkin.h
  13. 111
      k-meleon/KmToolbar.cpp
  14. 12
      k-meleon/KmToolbar.h
  15. 24
      k-meleon/Plugins.cpp
  16. 17
      k-meleon/ToolBarEx.cpp
  17. 3
      k-meleon/kmeleon_plugin.h
  18. 6
      k-meleon/macros2/functions.h
  19. 264
      k-meleon/macros2/macros.cpp

17
k-meleon/BrowserFrm.cpp

@ -448,7 +448,7 @@ int CBrowserFrame::InitLayout()
if (!IsDialog()) {
theApp.plugins.SendMessage("*", "* OnCreate", "DoRebar", (long)m_wndReBar.GetReBarCtrl().m_hWnd);
theApp.toolbars.InitWindows(&m_wndReBar);
theApp.toolbars.InitWindows(this);
}
m_wndReBar.RestoreBandSizes();
@ -1265,7 +1265,7 @@ BOOL CALLBACK EnumToolbar(HWND hwnd, LPARAM lParam)
}
// create a linked list of CToolBarEx controls, return the hwnd
HWND CBrowserFrame::CreateToolbar(UINT style) {
CToolBarEx* CBrowserFrame::CreateToolbar(UINT style) {
return m_tbList.Add(this, style);
}
@ -1696,16 +1696,17 @@ void CBrowserFrame::UpdateLoading(BOOL aLoading)
void CBrowserFrame::UpdateTitle(LPCTSTR aTitle)
{
CString appTitle;
appTitle.LoadString(AFX_IDS_APP_TITLE);
appTitle = theApp.preferences.GetString("kmeleon.display.title", appTitle);
CString title = aTitle;
if (title.IsEmpty())
title = GetActiveView()->GetBrowserGlue()->mLocation;
if (!appTitle.IsEmpty())
title += _T(" (") + appTitle + _T(")");
if (!IsDialog()) {
CString appTitle;
appTitle.LoadString(AFX_IDS_APP_TITLE);
appTitle = theApp.preferences.GetString("kmeleon.display.title", appTitle);
if (!appTitle.IsEmpty())
title += _T(" - ") + appTitle;
}
SetWindowText(title);
UpdateSHistoryMenu();

6
k-meleon/BrowserFrm.h

@ -171,7 +171,7 @@ public:
delete temp;
}
}
HWND Add(CWnd *wnd, UINT style)
CToolBarEx* Add(CWnd *wnd, UINT style)
{
CToolBarItem *newTB = new CToolBarItem(wnd, style);
@ -181,7 +181,7 @@ public:
m_tail->m_next = newTB;
m_tail = newTB;
}
return newTB->m_tb->m_hWnd;
return newTB->m_tb;
}
private:
CToolBarItem *m_head;
@ -258,7 +258,7 @@ public:
void CloseNothing(){}
INT_PTR DoModal();
HWND CreateToolbar(UINT style);
CToolBarEx* CreateToolbar(UINT style);
void SetBackImage ();

78
k-meleon/JSBridge/jscomp.cpp

@ -1,4 +1,5 @@
#define WIN32_LEAN_AND_MEAN
#include <mozilla/Char16.h>
#include <windows.h>
#include <string.h>
#include <stdlib.h>
@ -10,11 +11,41 @@
#include "jscomp.h"
#include "..\kmeleon_plugin.h"
#include "nsComponentManagerUtils.h"
#include "nsMemory.h"
extern kmeleonPlugin kPlugin;
extern CCmdList* cmdList;
NS_IMETHODIMP CJSBridge::SetMenuCallback(const char *menu, const char *label, nsICommandFunction *command, const char *before)
NS_IMPL_ISUPPORTS (CJSCommand, kmICommand)
NS_IMETHODIMP CJSCommand::GetName(char * *aName)
{
*aName = (char*)nsMemory::Clone(name.BeginReading(), name.Length()+1);
return NS_OK;
}
NS_IMETHODIMP CJSCommand::GetDesc(char * *aDesc)
{
*aDesc = (char*)nsMemory::Clone(desc.BeginReading(), desc.Length()+1);
return NS_OK;
}
NS_IMETHODIMP CJSCommand::GetCommand(kmICommandFunction * *aCommand)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute string image; */
NS_IMETHODIMP CJSCommand::GetImage(char * *aImage)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP CJSCommand::SetImage(const char * aImage)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMPL_ISUPPORTS (CJSBridge, nsIJSBridge)
NS_IMETHODIMP CJSBridge::SetMenuCallback(const char *menu, const char *label, kmICommandFunction *command, const char *before)
{
kmeleonMenuItem item;
item.label = label;
@ -109,9 +140,50 @@ NS_IMETHODIMP CJSBridge::SendMessage(const char *to, const char *from, const cha
}
/* void GetCmdList (out unsigned long length, [array, size_is (length), retval] out kICmdList list); */
NS_IMETHODIMP CJSBridge::GetCmdList(PRUint32 *length, kICmdList ***list)
NS_IMETHODIMP CJSBridge::GetCmdList(PRUint32 *length, kmICommand ***list)
{
return NS_ERROR_NOT_IMPLEMENTED;
unsigned size = kPlugin.kFuncs->GetCmdList(nullptr, 0);
kmeleonCommand* kcs = new kmeleonCommand[size];
size = kPlugin.kFuncs->GetCmdList(kcs, size);
size = 1;
kmICommand** cmds = static_cast<kmICommand**>(NS_Alloc(size*sizeof(kmICommand*)));
for (unsigned i = 0;i<size;i++) {
CJSCommand* cmd = new CJSCommand();
cmd->name = kcs[i].cmd;
cmd->desc = kcs[i].desc;
void *result;
cmd->QueryInterface(NS_GET_TEMPLATE_IID(kmICommand), &result);
cmds[i] = static_cast<kmICommand*>(result);
}
delete [] kcs;
if (length) *length = size;
*list = cmds;
return NS_OK;
}
NS_IMETHODIMP CJSBridge::RegisterCmd(const char * name, const char * desc,
kmICommandFunction *command, const char* icon,
kmICallback *enabled, kmICallback *checked, int32_t *_retval)
{
UINT id = kPlugin.kFuncs->RegisterCmd(name, desc, icon);
cmdList->Add(id, command);
return NS_OK;
}
NS_IMETHODIMP CJSBridge::AddButton(const char * name, const char *command, const char* menu)
{
kmeleonButton b = {0};
b.action = command;
b.menu = menu;
b.enabled = true;
kPlugin.kFuncs->AddButton(name, &b);
return NS_OK;
}
NS_IMETHODIMP CJSBridge::RemoveButton(const char * name, const char *command)
{
kPlugin.kFuncs->RemoveButton(name, command);
return NS_OK;
}
NS_IMETHODIMP CJSBridge::Open(const char * url, uint16_t state, nsIWebBrowser * *_retval)

40
k-meleon/JSBridge/jscomp.h

@ -5,6 +5,7 @@
#include <nsCOMPtr.h>
#include <nsISupports.h>
#include "nsIJSBridge.h"
#include "nsEmbedString.h"
#include <map>
#define JSBRIDGE_CID { 0x842170a0, 0x5210, 0x11db, { 0xb0, 0xde, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66}}
@ -12,21 +13,52 @@ static NS_DEFINE_CID(kJSBridgeCID, JSBRIDGE_CID);
class CCmdList {
private:
std::map<UINT, nsCOMPtr<nsICommandFunction>> cmdMap;
std::map<UINT, nsCOMPtr<kmICommandFunction>> cmdMap;
public:
void Add(UINT id, nsICommandFunction* command) {
cmdMap.insert(std::pair<UINT,nsICommandFunction*>(id, command));
void Add(UINT id, kmICommandFunction* command) {
cmdMap.insert(std::pair<UINT,kmICommandFunction*>(id, command));
}
bool Run(UINT command, UINT mode) {
auto iter = cmdMap.find(command);
if (iter != cmdMap.end() && iter->second) {
iter->second->OnCommand(mode);
iter->second->OnCommand(mode, nullptr);
return true;
}
return false;
}
};
typedef std::string string;
class CJSCommand: public kmICommand
{
public:
NS_DECL_ISUPPORTS
NS_DECL_KMICOMMAND
CJSCommand() {};
virtual ~CJSCommand() {};
nsCString name;
nsCString desc;
};
class CJSButton : public kmIButton
{
public:
NS_DECL_ISUPPORTS
NS_DECL_KMIBUTTON
CJSButton() {};
virtual ~CJSButton() {};
string cmd;
string label;
string menu;
string tooltip;
int id;
};
class CJSBridge : public nsIJSBridge
{
public:

4
k-meleon/JSBridge/jsplugin.cpp

@ -1,4 +1,5 @@
#define WIN32_LEAN_AND_MEAN
#include <mozilla/Char16.h>
#include <windows.h>
#include <stdio.h>
@ -28,7 +29,6 @@ kmeleonPlugin kPlugin = {
CCmdList* cmdList;
NS_IMPL_ISUPPORTS(CJSBridge, nsIJSBridge);
NS_GENERIC_FACTORY_CONSTRUCTOR(CJSBridge)
/*
static const mozilla::Module::CIDEntry kBrowserCIDs[] = {
@ -144,7 +144,7 @@ BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReser
return TRUE;
}
extern std::map<UINT, nsCOMPtr<nsICommandFunction>> cmdMap;
extern std::map<UINT, nsCOMPtr<kmICommandFunction>> cmdMap;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

43
k-meleon/JSBridge/nsIJSBridge.idl

@ -4,22 +4,34 @@
interface nsISimpleEnumerator;
interface nsIArray;
[scriptable, uuid(3d8ce8f0-5214-11db-b0de-0800200c9a66)]
[scriptable,function, uuid(83910267-7670-4493-99c1-dd540a036ef3)]
interface kmICommandFunction:nsISupports {
void onCommand(in unsigned long mode, [optional] in string arg);
};
interface kICmdList : nsISupports
[scriptable,function, uuid(83910267-7670-4493-99c1-dd540a036ef4)]
interface kmICallback:nsISupports {
void run();
};
[scriptable, uuid(3d8ce8f0-5214-11db-b0de-0800200c9a65)]
interface kmICommand : nsISupports
{
readonly attribute unsigned long id;
readonly attribute string cmd;
readonly attribute string desc;
readonly attribute string name;
readonly attribute string desc;
readonly attribute kmICommandFunction command;
attribute string image;
};
[scriptable,function, uuid(83910267-7670-4493-99c1-dd540a036ef3)]
interface nsICommandFunction:nsISupports {
void onCommand(in unsigned long mode);
[scriptable, uuid(3d8ce8f0-5214-11db-b0de-0800200c9a67)]
interface kmIButton : nsISupports
{
attribute string image;
attribute bool checked;
attribute bool disabled;
};
[scriptable, uuid(83910267-7670-4493-99c1-dd540a036ef2)]
interface nsIJSBridge : nsISupports
{
const unsigned short MENU_COMMAND = 1;
@ -35,14 +47,21 @@ interface nsIJSBridge : nsISupports
const unsigned short OPEN_BACKGROUNDTAB = 4;
const unsigned short OPEN_CLONE = 16;
void SetMenuCallback(in string menu, in string label, in nsICommandFunction command, [optional] in string before);
void SetMenuCallback(in string menu, in string label, in kmICommandFunction command, [optional] in string before);
void SetMenu(in string menu,in unsigned short type, in string label, in string command, [optional] in string before);
void RebuildMenu(in string menu);
//void AddButton(in string toolbar, in kmIButton button);
void AddButton(in string toolbar, in string command, [optional] in string menu);
void RemoveButton(in string toolbar, in string command);
void id(in nsIDOMWindow window, in string id);
long SendMessage(in string plugin, in string to, in string from, in string data1);
void GetCmdList(out unsigned long length, [array, size_is(length), retval] out kICmdList list);
void GetCmdList([optional] out unsigned long length, [array, size_is(length), retval] out kmICommand list);
long RegisterCmd(in string name, in string desc,
in kmICommandFunction command, [optional] in string icon,
[optional] in kmICallback enabled, [optional] in kmICallback checked);
nsIWebBrowser Open(in string url, in unsigned short state);
nsIWebBrowser GetActiveBrowser();

6
k-meleon/KMeleonConst.h

@ -17,10 +17,10 @@
*/
#define KMELEON_VERSION 0x02010000
#define KMELEON_VERSION 0x02010001
#define MOZILLA_BUILDID 20140105
#define KMELEON_BUILDID 7400
#define KMELEON_UVERSION 74.0
#define KMELEON_BUILDID 7500
#define KMELEON_UVERSION 75.0
#define KMELEON_UUID {944df56f-c0ec-4d7b-94b6-f625c8cc96ea}
#define WM_DEFERSHOW WM_USER + 200

25
k-meleon/KmCommand.cpp

@ -21,6 +21,15 @@
#include "KmCommand.h"
#include "kmeleon_plugin.h"
UINT KmCmdService::RegisterCommand(LPCTSTR name, LPCTSTR desc, LPCTSTR icon)
{
UINT id = AllocateId();
mCommandList[name] = KmCommand(id, desc);
if (icon && theApp.skin.mImages)
theApp.skin.mImages->AddIcon(icon, 0, 0, id);
return id;
}
CString KmCmdService::GetDescription(LPCTSTR command)
{
KmCommand kcommand;
@ -33,6 +42,9 @@ CString KmCmdService::GetDescription(LPCTSTR command)
str.LoadString(id);
return str;
}
if (kcommand.GetDesc().GetLength())
return kcommand.GetDesc();
USES_CONVERSION;
char *desc = NULL;
@ -59,17 +71,18 @@ UINT KmCmdService::GetList(kmeleonCommand* cmdList, UINT size, BOOL def)
char* aCmd = strdup(T2CA(pCurVal->key));
strncpy(cmdList[i].cmd, aCmd, sizeof(cmdList[i].cmd));
cmdList[i].cmd[sizeof(cmdList[i].cmd)-1] = 0;
if (!IsPluginCommand(pCurVal->value.id)) {
CString str;
str.LoadString(pCurVal->value.id);
//if (!IsPluginCommand(pCurVal->value.id)) {
CString str = pCurVal->value.GetDesc();
if (!str.GetLength())
str.LoadString(pCurVal->value.id);
strncpy(cmdList[i].desc, T2CA(str), sizeof(cmdList[i].desc));
cmdList[i].desc[sizeof(cmdList[i].desc)-1] = 0;
}
/*}
else {
char *plugin, *parameter;
if (ParseCommand(aCmd, &plugin, &parameter))
theApp.plugins.SendMessage(plugin, "*", "GetCmds", (long)parameter, (long)&cmdList[i]);
}
}*/
free(aCmd);
ASSERT(i<=num);
if (++i > num) break;
@ -96,7 +109,7 @@ UINT KmCmdService::GetId(LPCTSTR command)
return kcommand.id;
if (command[0] == _T('@')) { //Menu
return RegisterCommand(NULL, command);
return RegisterCommand(command);
}
char *plugin, *parameter;

13
k-meleon/KmCommand.h

@ -32,11 +32,15 @@ class CMfcEmbedApp;
struct KmCommand
{
UINT id;
CString desc;
KmCommand() : id(0) {}
KmCommand(UINT aId) : id(aId) {}
KmCommand(UINT aId, LPCTSTR aDesc) : id(aId), desc(aDesc) {}
BOOL IsPlugin();
CString GetDesc();
CString GetDesc() {
return desc;
}
};
class KmCmdService
@ -105,12 +109,7 @@ public:
mCommandList.RemoveKey(command);
}
UINT RegisterCommand(LPCTSTR plugin, LPCTSTR command, unsigned nbArgs = 0)
{
UINT id = AllocateId();
mCommandList[command] = KmCommand(id);
return id;
}
UINT RegisterCommand(LPCTSTR name, LPCTSTR desc = 0, LPCTSTR icon = 0);
BOOL ParseCommand(char *pszCommand, char** plugin, char **parameter)
{

6
k-meleon/KmImage.cpp

@ -66,8 +66,8 @@ NS_IMETHODIMP nsImageObserver::Notify(imgIRequest *aProxy, int32_t aType, const
mObserver->ImageLoaded(CreateDIB(aProxy));
aProxy->CancelAndForgetObserver(NS_OK);
//mRequest = nullptr;
if (mNeedRelease) NS_RELEASE_THIS();
delete mObserver;
if (mNeedRelease) NS_RELEASE_THIS();
// Can't release here anymore else gecko crash
/*nsCOMPtr<nsIThreadManager> tm = do_GetService("@mozilla.org/thread-manager;1");
if (!tm) return NS_OK;
@ -229,7 +229,9 @@ HBITMAP nsImageObserver::CreateDIB(imgIRequest *aRequest)
#ifdef _DEBUG
// There is a problem with the linking in debug
return NULL;
// Use a dummy image instead
return (HBITMAP)::LoadImage(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_TOOLBAR_CLOSE), IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT);
//return NULL;
#endif
// Get the image data

41
k-meleon/KmSkin.cpp

@ -324,4 +324,45 @@ bool KmSkin::Init(LPCTSTR skinName)
return false;
mSkinName = skinName;
return true;
}
class iconSkinObserver: public IImageObserver {
UINT mID;
public:
iconSkinObserver(UINT id): mID (id) {}
~iconSkinObserver() {}
void ImageLoaded(HBITMAP hBitmap)
{
if (!hBitmap) return;
UINT w = theApp.skin.GetUserWidth();
UINT h = theApp.skin.GetUserHeight();
KmImage img;
img.LoadFromBitmap(hBitmap);
img.Resize(w, h);
theApp.skin.mImages->AddIcon(img, mID);
DeleteObject(hBitmap);
}
protected:
KmButton* mButton;
};
#include "MozUtils.h"
int KmIconList::AddIcon(LPCTSTR coldImgPath, LPCTSTR hotImgPath, LPCTSTR deadImgPath, UINT id)
{
if (CString(coldImgPath).Left(6).Compare(L"chrome") == 0) {
iconSkinObserver* io = new iconSkinObserver(id);
nsCOMPtr<nsIURI> uri;
NewURI(getter_AddRefs(uri), CStringToNSString(coldImgPath));
if (!nsImageObserver::LoadImage(io, uri)) {
delete io;
return -1;
}
} else {
}
}

10
k-meleon/KmSkin.h

@ -54,18 +54,18 @@ public:
int height = ::GetSystemMetrics(SM_CYSMICON);
if (width != w || height != h) {
mHasDifferentSize = true;
mSized.Create(width, height, ILC_MASK|ILC_COLOR32, 0, 10);
mSized.Create(width, height, ILC_COLOR32, 0, 10);
} else
mHasDifferentSize = false;
mHot.Create(w, h, ILC_MASK|ILC_COLOR32, 0, 10);
mCold.Create(w, h, ILC_MASK|ILC_COLOR32, 0, 10);
mDead.Create(w, h, ILC_MASK|ILC_COLOR32, 0, 10);
mHot.Create(w, h, ILC_COLOR32, 0, 10);
mCold.Create(w, h, ILC_COLOR32, 0, 10);
mDead.Create(w, h, ILC_COLOR32, 0, 10);
}
int AddIcons(KmImage& img, UINT w, UINT h);
int AddIcon(KmImage& img, UINT id = 0);
int AddIcon(KmImage& img, KmImage& hotImg, KmImage& deadImg, UINT id = 0);
int AddIcon(LPCTSTR hotImgPath, LPCTSTR coldImgPath, LPCTSTR deadImgPath, UINT id = 0);
int AddIcon(LPCTSTR coldImgPath, LPCTSTR hotImgPath, LPCTSTR deadImgPath, UINT id = 0);
HIMAGELIST GetIconList() {
return mHasDifferentSize ? mSized.GetSafeHandle() : mCold.GetSafeHandle();

111
k-meleon/KmToolbar.cpp

@ -70,16 +70,42 @@ protected:
KmButton* mButton;
};
bool KmToolbar::RemoveItem(UINT id)
{
bool res = false;
POSITION pos = mButtons.GetHeadPosition();
while (pos) {
KmButton* kbutton = mButtons.GetNext(pos);
if (kbutton->mID == id) {
mButtons.RemoveAt(pos);
res = true;
break;
}
}
pos = mToolbars.GetHeadPosition();
while (pos) {
CToolBarEx* toolbar = mToolbars.GetNext(pos);
for (int i=0;i<toolbar->GetCount();i++) {
UINT bid, style;
int iimage;
toolbar->GetButtonInfo(i, bid, style, iimage);
if (id == bid) toolbar->GetToolBarCtrl().DeleteButton(i);
}
}
return res;
}
void KmToolbar::AddItem(KmButton& button, int before, UINT w, UINT h)
{
KmButton* pbutton = new KmButton();
*pbutton = button;
if (pbutton->mAction.GetLength())
if (pbutton->mAction.GetLength()) {
pbutton->mID = theApp.commands.GetId(pbutton->mAction);
if (!pbutton->mID && pbutton->mName.GetLength())
return;
if (!pbutton->mID) return;
}
pbutton->mImageIndex = theApp.skin.GetIconIndex(pbutton->mID);
if (pbutton->mImageIndex == I_IMAGENONE && button.mColdImage) {
if (pbutton->mImageIndex == I_IMAGENONE && button.mColdImage.GetLength()) {
if (button.mColdImage.Left(6).Compare(L"chrome") == 0) {
@ -148,9 +174,45 @@ void KmToolbar::AddItem(KmButton& button, int before, UINT w, UINT h)
}
}
mButtons.AddTail(pbutton);
POSITION pos = mToolbars.GetHeadPosition();
while (pos) {
CToolBarEx* toolbar = mToolbars.GetNext(pos);
TBBUTTON b = InitButton(pbutton, toolbar);
toolbar->GetToolBarCtrl().InsertButton(-1, &b);
}
}
bool KmToolbar::Init(CToolBar* hToolbar)
TBBUTTON KmToolbar::InitButton(KmButton* kbutton, CToolBarEx* hToolbar)
{
TBBUTTON res;
if (kbutton->mID || kbutton->mName.GetLength()>0) {
res.iString = -1;
if (kbutton->mLabel.GetLength() > 0) {
CString strTemp(theApp.lang.Translate(kbutton->mLabel), lstrlen(kbutton->mLabel)+1);
res.iString = (INT_PTR)hToolbar->GetToolBarCtrl().SendMessage(TB_ADDSTRING, 0, (LPARAM)strTemp.GetBuffer());
}
res.iBitmap = kbutton->mImageIndex;
res.idCommand = kbutton->mID;
//res.iString = kbutton->mLabel.GetLength() ? (INT_PTR)(LPCTSTR)kbutton->mLabel : 0;
res.dwData = (DWORD_PTR)&kbutton;
res.fsState = TBSTATE_ENABLED;
res.fsStyle = BTNS_BUTTON;
res.bReserved[0] = 0;
} else {
// Separator
res.iBitmap = 0;
res.idCommand = 0;
res.iString = 0;
res.dwData = 0;
res.fsState = TBSTATE_ENABLED;
res.fsStyle = BTNS_SEP;
res.bReserved[0] = 0;
}
return res;
}
bool KmToolbar::Init(CToolBarEx* hToolbar)
{
if (!GetButtonCount()) return NULL;
TBBUTTON* hButtons = new TBBUTTON[GetButtonCount()];
@ -159,37 +221,15 @@ bool KmToolbar::Init(CToolBar* hToolbar)
int i = 0, j = 0;
while (pos) {
KmButton* kbutton = mButtons.GetNext(pos);
if (kbutton->mName.GetLength()>0) {
hButtons[i].iString = -1;
if (kbutton->mLabel.GetLength() > 0) {
CString strTemp(theApp.lang.Translate(kbutton->mLabel), lstrlen(kbutton->mLabel)+1);
hButtons[i].iString = (INT_PTR)hToolbar->GetToolBarCtrl().SendMessage(TB_ADDSTRING, 0, (LPARAM)strTemp.GetBuffer());
hasString = true;
}
hButtons[i].iBitmap = kbutton->mImageIndex;
hButtons[i].idCommand = kbutton->mID;
//hButtons[i].iString = kbutton->mLabel.GetLength() ? (INT_PTR)(LPCTSTR)kbutton->mLabel : 0;
hButtons[i].dwData = (DWORD_PTR)&kbutton;
hButtons[i].fsState = TBSTATE_ENABLED;
hButtons[i].fsStyle = BTNS_BUTTON;
hButtons[i].bReserved[0] = 0;
} else {
// Separator
hButtons[i].iBitmap = 0;
hButtons[i].idCommand = 0;
hButtons[i].iString = 0;
hButtons[i].dwData = 0;
hButtons[i].fsState = TBSTATE_ENABLED;
hButtons[i].fsStyle = BTNS_SEP;
hButtons[i].bReserved[0] = 0;
}
hButtons[i] = InitButton(kbutton, hToolbar);
if (hButtons[i].iString != -1) hasString = true;
i++;
}
if (hasString)
hToolbar->ModifyStyle(0, TBSTYLE_LIST);
hToolbar->GetToolBarCtrl().AddButtons(GetButtonCount(), hButtons);
delete hButtons;
CSize btnSize, btnImgSize(0,0);
if (mCold.m_hImageList) {
@ -211,21 +251,24 @@ bool KmToolbar::Init(CToolBar* hToolbar)
btnSize.SetSize(LOWORD(dwBtnSize), HIWORD(dwBtnSize));
}
hToolbar->SetSizes(btnSize, btnImgSize);
mToolbars.AddTail(hToolbar);
return true;
}
bool KmToolbarService::InitWindows(CReBarEx* rebar)
bool KmToolbarService::InitWindows(CBrowserFrame* frame)
{
CString s;
CReBarEx* rebar = &frame->m_wndReBar;
KmToolbar *ktoolbar;
POSITION pos = mToolbars.GetStartPosition();
while (pos) {
mToolbars.GetNextAssoc( pos, s, ktoolbar);
CToolBarEx* hToolbar = new CToolBarEx();
//CToolBarEx* hToolbar = new CToolBarEx();
int style = CCS_NODIVIDER | CCS_NOPARENTALIGN | CCS_NORESIZE | TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | TBSTYLE_TOOLTIPS;
int sstyle = WS_CHILD|WS_VISIBLE| (style&CCS_BOTTOM ? CBRS_ALIGN_BOTTOM : CBRS_ALIGN_TOP);
hToolbar->CreateEx(rebar->GetParentFrame(), style, sstyle);
//int sstyle = WS_CHILD|WS_VISIBLE| (style&CCS_BOTTOM ? CBRS_ALIGN_BOTTOM : CBRS_ALIGN_TOP);
//hToolbar->CreateEx(rebar->GetParentFrame(), style, sstyle);
CToolBarEx* hToolbar = frame->CreateToolbar(style);
SetProp(hToolbar->GetSafeHwnd(), _T("kmToolbar"), (HANDLE)ktoolbar);
ktoolbar->Init(hToolbar);

12
k-meleon/KmToolbar.h

@ -18,7 +18,8 @@
#pragma once
class CReBarEx;
class CBrowserFrame;
class CToolBarEx;
class KmImage;
class KmButton
@ -53,6 +54,7 @@ public:
};
void AddItem(KmButton& button, int before = -1, UINT w = 0, UINT h = 0);
bool RemoveItem(UINT id);
UINT GetButtonCount()
{
@ -69,8 +71,8 @@ public:
return nullptr;
}
bool Init(CToolBar* wToolbar);
bool Init(CToolBarEx* wToolbar);
#define DIB_WIDTHBYTES(bits) ((((bits) + 31)>>5)<<2)
bool LoadImage(LPCTSTR skinImg, KmImage& img, UINT w = 0, UINT h = 0);
@ -81,7 +83,9 @@ public:
int mWidth, mHeight;
protected:
TBBUTTON InitButton(KmButton* kbutton, CToolBarEx* hToolbar);
CList<KmButton*, KmButton*> mButtons;
CList<CToolBarEx*, CToolBarEx*> mToolbars;
};
class KmToolbarService {
@ -123,7 +127,7 @@ public:
}
bool Init();
bool InitWindows(CReBarEx* rebar);
bool InitWindows(CBrowserFrame* frame);
BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
UINT GetDefaultWidth() { return mDefWidth; }
UINT GetDefaultHeight() { return mDefHeight; }

24
k-meleon/Plugins.cpp

@ -672,7 +672,7 @@ HWND CreateToolbar(HWND hWnd, UINT style) {
CBrowserFrame *frame = GetFrame(hWnd);
if (!frame) return NULL;
return frame->CreateToolbar(style);
return frame->CreateToolbar(style)->m_hWnd;
}
int GetID(const char *strID) {
@ -1726,10 +1726,10 @@ void ReleaseCmdID(UINT id)
theApp.commands.ReleaseId(id);
}
UINT RegisterCmd(const char* cmd, const char* plugin, unsigned nbArgs)
UINT RegisterCmd(const char* name, const char* desc, const char* icon)
{
USES_CONVERSION;
return theApp.commands.RegisterCommand(A2CT(plugin), A2CT(cmd), nbArgs);
return theApp.commands.RegisterCommand(A2CT(name), A2CT(desc), A2CT(icon));
}
void UnregisterCmd(const char* cmd, const char* plugin)
@ -1741,12 +1741,12 @@ void UnregisterCmd(const char* cmd, const char* plugin)
unsigned GetCmdList(kmeleonCommand* cmdList, unsigned size)
{
int num = theApp.plugins.SendMessage("*", "Urlbar", "GetCmds", 0, 0);
num += theApp.commands.GetDefCount();
num += theApp.commands.GetCount();
if (!cmdList)
return num;
num = theApp.commands.GetList(cmdList, size, TRUE);
num = theApp.commands.GetList(cmdList, size);
CPluginList *pluginList = theApp.plugins.GetPlugins();
POSITION pos = pluginList->GetStartPosition();
kmeleonPlugin * kPlugin;
@ -1781,6 +1781,14 @@ bool AddToolbar(const char* name, UINT w, UINT h)
return theApp.toolbars.CreateToolbar(A2CT(name), w, h) ? true : false;
}
bool RemoveButton(const char* name, const char* command)
{
USES_CONVERSION;
KmToolbar* t = theApp.toolbars.GetKToolbar(A2CT(name));
if (!t) return false;
return t->RemoveItem(theApp.commands.GetId(command));
}
bool AddButton(const char* name, kmeleonButton* b)
{
USES_CONVERSION;
@ -1941,7 +1949,8 @@ kmeleonFunctions kmelFuncsUTF8 = {
GetCmdIconList,
GetCmdIcon,
FindSkinFile,
GotoHistoryIndex
GotoHistoryIndex,
RemoveButton
};
kmeleonFunctions kmelFuncs = {
@ -2012,7 +2021,8 @@ kmeleonFunctions kmelFuncs = {
GetCmdIconList,
GetCmdIcon,
FindSkinFile,
GotoHistoryIndex
GotoHistoryIndex,
RemoveButton
};
BOOL CPlugins::TestLoad(LPCTSTR file, const char *description)

17
k-meleon/ToolBarEx.cpp

@ -241,15 +241,18 @@ BOOL CToolBarEx::OnTbnGetDispInfo(UINT, NMHDR * pNotifyStruct, LRESULT* pResult)
if (button->mTooltip.GetLength()) {
pTTT->lpszText = (LPTSTR)theApp.lang.Translate(button->mTooltip);
}
else {
else if (text.LoadString(pNotifyStruct->idFrom)) {
if (button->mMenuName) {
if (!text.LoadString(pNotifyStruct->idFrom))
return FALSE;
text += L"\n";
text.AppendFormat(IDS_MORE_OPTIONS);
pTTT->lpszText = text.GetBuffer();
} else
pTTT->lpszText = MAKEINTRESOURCE(pNotifyStruct->idFrom);
text.AppendFormat(IDS_MORE_OPTIONS);
}
pTTT->lpszText = text.GetBuffer();
}
else {
KmCommand cmd;
text = theApp.commands.GetDescription(button->mAction);
if (!text.GetLength()) return FALSE;
pTTT->lpszText = text.GetBuffer();
}
return TRUE;

3
k-meleon/kmeleon_plugin.h

@ -352,7 +352,7 @@ typedef struct {
int (*GetTabsList) (HWND hWnd, HWND* list, unsigned size);
UINT (*GetIconIdx) (const char* host);
void (*ReleaseCmdId) (UINT id);
UINT (*RegisterCmd) (const char* name, const char* plugin, unsigned nbArgs); // Do not use yet
UINT (*RegisterCmd) (const char* name, const char* desc, const char* arg); // Do not use yet
void (*UnregisterCmd) (const char* name, const char* plugin);
unsigned (*GetCmdList) (kmeleonCommand*, unsigned size);
BOOL (*LoadCSS) (const char* path, BOOL load);
@ -374,6 +374,7 @@ typedef struct {
int (*GetCmdIcon)(UINT id);
bool (*FindSkinFile)(const wchar_t* name, wchar_t* result, unsigned size);
void (*GotoHistoryIndex)(HWND hWnd, UINT index);
bool (*RemoveButton)(const char* name, const char* command);
} kmeleonFunctions;

6
k-meleon/macros2/functions.h

@ -1405,7 +1405,7 @@
// toolbar, name, command, menu, label, tooltip, cold, hot, dead, w, h
Value addbutton(FunctionData* data)
{
checkArgs(__FUNCTION__, data, 1,3);
checkArgs(__FUNCTION__, data, 3,11);
MString name = data->getstr(2);
MString label = data->getstr(5);
@ -1439,7 +1439,7 @@
Value enablebutton(FunctionData* data)
{
checkArgs(__FUNCTION__, data, 2);
checkArgs(__FUNCTION__, data, 3);
kmeleonButton b = {0};
b.enabled = data->getbool(3);
b.checked = -1;
@ -1448,7 +1448,7 @@
Value checkbutton(FunctionData* data)
{
checkArgs(__FUNCTION__, data, 2);
checkArgs(__FUNCTION__, data, 3);
kmeleonButton b = {0};
b.enabled = -1;
b.checked = data->getbool(2);

264
k-meleon/macros2/macros.cpp

@ -24,6 +24,7 @@
#include <shellapi.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <malloc.h>
#define PLUGIN_NAME "Macro Extension Plugin"
@ -354,100 +355,6 @@ public:
}
};
long DoMessage(const char *to, const char *from, const char *subject, long data1, long data2)
{
if (to[0] == '*' || stricmp(to, kPlugin.dllname) == 0) {
if (stricmp(subject, "Load") == 0) {
Load();
}
else if (stricmp(subject, "Init") == 0) {
ExecuteMacro(NULL, "OnInit", false);
}
else if (stricmp(subject, "Setup") == 0) {
ExecuteMacro(NULL, "OnSetup", false);
}
else if (stricmp(subject, "UserSetup") == 0) {
ExecuteMacro(NULL, "OnUserSetup", false);
}
else if (stricmp(subject, "Create") == 0) {
Create((HWND)data1);
}
else if (stricmp(subject, "CreateTab") == 0) {
ExecuteMacro((HWND)data1, "OnOpenTab", false);
}
else if (stricmp(subject, "DestroyTab") == 0) {
ExecuteMacro((HWND)data1, "OnCloseTab", false);
}
else if (stricmp(subject, "Close") == 0) {
Close((HWND)data1);
}
else if (stricmp(subject, "Config") == 0) {
Config((HWND)data1);
}
else if (stricmp(subject, "Quit") == 0) {
Quit();
}
else if (stricmp(subject, "DoMenu") == 0) {
DoMenu((HMENU)data1, (char *)data2);
}
else if (stricmp(subject, "DoRebar") == 0) {
DoRebar((HWND)data1);
}
else if (stricmp(subject, "DoAccel") == 0) {
*(int *)data2 = DoAccel((char *)data1);
}
else if (stricmp(subject, "GetConfigFiles") == 0) {
*(int *)data2 = GetConfigFiles((configFileType**)data1);
}
else if (stricmp(subject, "GetCmds") == 0) {
return GetCmds((kmeleonCommand*)data1, data2);
}
else if (stricmp(subject, "RunMacro") == 0) {
Parser parser;
int debug = 0;
kPlugin.kFuncs->GetPreference(PREF_BOOL, "kmeleon.plugins.macros.debug", &debug, &debug);
MacroNode* node = M->root.GetLast();
if (!parser._init(M, strdup((char*)data1), debug))
return 0;
parser.parse();
Context c = {NULL};
// Ugly hack to run new code
MacroNode* child = M->root.child;
M->root.child = node->next;
Evaluator e(M, c);
e.Evaluate(&M->root);
M->root.child = child;
}
else return 0;
return 1;
}
return 0;
}
std::string ExecuteMacro (HWND hWnd, std::string name, bool haha)
{
Value* val = M->FindSymbol(name);
if (!val || !val->ismacro())
return "";
ValueMacro* macro = (ValueMacro*)val;
if (!macro->md) {
return "";
}
Context context;
context.hWnd = hWnd;
Evaluator eval(M, context);
eval.Evaluate(macro->md);
return "";
}
class ArgList {
@ -537,6 +444,168 @@ public:
}
}* arglist;
int GetMacroState(int id)
{
char *macroname, *param;
if (!arglist->getfromid(id, &macroname, &param))
return -1;
Value* macro = M->FindSymbol(macroname);
if (!macro || !macro->ismacro() ||
(!macro->md->menuChecked && ! macro->md->menuGrayed))
return -1;
Value *v = M->FindSymbol("$ARG");
assert(v);
*v = Value(param);
int res = 0;
Context c = {NULL};
if (macro->md->menuChecked) {
Evaluator e(M, c);
if (e.EvalExpr(macro->md->menuChecked).boolval())
res |= 0x2;
}
if (macro->md->menuGrayed) {
Evaluator e(M, c);
if (e.EvalExpr(macro->md->menuGrayed).boolval())
res |= 0x1;
}
return res;
}
const char* GetCmd(long id) {
static MString str;
char *macroname, *param;
if (!arglist->getfromid(id, &macroname, &param))
return nullptr;
Value* macro = M->FindSymbol(macroname);
if (!macro || !macro->ismacro() || !macro->md->macroInfo)
return nullptr;
Context c = {0};
Evaluator e(M, c);
Value *v = M->FindSymbol("$ARG");
*v = Value(param);
str = e.EvalExpr(macro->md->macroInfo).strval();
return str.c_str();
}
long DoMessage(const char *to, const char *from, const char *subject, long data1, long data2)
{
if (to[0] == '*' || stricmp(to, kPlugin.dllname) == 0) {
if (strcmp(subject, "GetState") == 0) {
unsigned res = GetMacroState(data1);
if (res == -1) return 0;
*((unsigned*)data2) = res;
return 1;
}
else if (strcmp(subject, "Load") == 0) {
Load();
}
else if (strcmp(subject, "Init") == 0) {
ExecuteMacro(NULL, "OnInit", false);
}
else if (strcmp(subject, "Setup") == 0) {
ExecuteMacro(NULL, "OnSetup", false);
}
else if (strcmp(subject, "UserSetup") == 0) {
ExecuteMacro(NULL, "OnUserSetup", false);
}
else if (strcmp(subject, "Create") == 0) {
Create((HWND)data1);
}
else if (strcmp(subject, "CreateTab") == 0) {
ExecuteMacro((HWND)data1, "OnOpenTab", false);
}
else if (strcmp(subject, "DestroyTab") == 0) {
ExecuteMacro((HWND)data1, "OnCloseTab", false);
}
else if (strcmp(subject, "Close") == 0) {
Close((HWND)data1);
}
else if (strcmp(subject, "Config") == 0) {
Config((HWND)data1);
}
else if (strcmp(subject, "Quit") == 0) {
Quit();
}
else if (strcmp(subject, "DoMenu") == 0) {
DoMenu((HMENU)data1, (char *)data2);
}
else if (strcmp(subject, "DoRebar") == 0) {
DoRebar((HWND)data1);
}
else if (strcmp(subject, "DoAccel") == 0) {
*(int *)data2 = DoAccel((char *)data1);
}
else if (strcmp(subject, "GetConfigFiles") == 0) {
*(int *)data2 = GetConfigFiles((configFileType**)data1);
}
else if (strcmp(subject, "GetCmds") == 0) {
return GetCmds((kmeleonCommand*)data1, data2);
}
else if (strcmp(subject, "GetCmd") == 0) {
data2 = (long)(void*)GetCmd((long)data1);
return 1;
}
else if (strcmp(subject, "RunMacro") == 0) {
Parser parser;
int debug = 0;
kPlugin.kFuncs->GetPreference(PREF_BOOL, "kmeleon.plugins.macros.debug", &debug, &debug);
MacroNode* node = M->root.GetLast();
if (!parser._init(M, strdup((char*)data1), debug))
return 0;
parser.parse();
Context c = {NULL};
// Ugly hack to run new code
MacroNode* child = M->root.child;
M->root.child = node->next;
Evaluator e(M, c);
e.Evaluate(&M->root);
M->root.child = child;
}
else return 0;
return 1;
}
return 0;
}
std::string ExecuteMacro (HWND hWnd, std::string name, bool haha)
{
if (!M) return "";
Value* val = M->FindSymbol(name);
if (!val || !val->ismacro())
return "";
ValueMacro* macro = (ValueMacro*)val;
if (!macro->md) {
return "";
}
Context context;
context.hWnd = hWnd;
Evaluator eval(M, context);
eval.Evaluate(macro->md);
return "";
}
typedef struct MacroFileDesc {
MString name;
MString desc;
bool user;
} MacroFileDesc;
std::vector<MacroFileDesc> *macroFileList;
bool LoadDir(const TCHAR* macrosDir)
{
TCHAR szMacroFile[MAX_PATH];
@ -610,6 +679,7 @@ BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
int Load() {
kFuncs = kPlugin.kFuncs;
arglist = new ArgList;
macroFileList = new std::vector<MacroFileDesc>;
M = new Mac();
M->AddSymbol("$ARG", Value());
InitFunctions(M);
@ -705,11 +775,11 @@ int GetCmds(kmeleonCommand* cmdList, long size)
cmdList->id = arglist->getfromname(iter->first.c_str(), "");
count++;
cmdList++;
if (--size == 0) break;
}
return count;
}
void Close(HWND hWnd) {
@ -722,8 +792,10 @@ void CloseFrame(HWND hWnd, LONG windows) {
void Quit() {
ExecuteMacro(NULL, "OnQuit", false);
delete arglist;
delete macroFileList;
delete arglist;
delete M;
M = nullptr;
}
void DoMenu(HMENU menu, char *param) {

Loading…
Cancel
Save