massive checkin

import/tags/kmeleon03
binaryc 22 years ago
parent 9e2a515f66
commit a1f21bb2ad
  1. 66
      k-meleon/MenuParser.cpp
  2. 4
      k-meleon/MenuParser.h
  3. 53
      k-meleon/Plugins.cpp
  4. 5
      k-meleon/Plugins.h
  5. 181
      k-meleon/Preferences.cpp
  6. 56
      k-meleon/Preferences.h
  7. 14
      k-meleon/kmeleon_plugin.h

@ -25,18 +25,21 @@
#include "MenuParser.h"
CMenuParser::CMenuParser(){
menu = NULL;
}
CMenuParser::CMenuParser(CString &filename){
menu = NULL;
Load(filename);
}
CMenuParser::~CMenuParser(){
if (menu){
menu->DestroyMenu();
delete menu;
POSITION pos = menus.GetStartPosition();
CMenu *m;
CString s;
while (pos){
menus.GetNextAssoc( pos, s, m);
if (m){
m->DestroyMenu();
}
}
}
@ -65,10 +68,6 @@ void TranslateTabs(char *buffer){
}
int CMenuParser::Load(CString &filename){
if (menu)
delete menu;
menu = NULL;
TRY {
menuFile = new CFile(filename, CFile::modeRead);
}
@ -100,14 +99,18 @@ int CMenuParser::Load(CString &filename){
if (*p == '#'){
}
else if (strnicmp(p, _T("MenuDef"), 7) == 0){
p+=8;
currentMenuName = NULL;
menu = new CMenu();
menu->CreateMenu();
currentMenu = menu;
currentMenu = new CMenu();
if (strstr(p, _T("Popup"))){
currentMenu->CreatePopupMenu();
}else{
currentMenu->CreateMenu();
}
menus[p] = currentMenu;
}
else if (strnicmp(p, _T(":EndMenu"), 8) == 0){
// there shouldn't be anything after this!
break;
}
else if (strnicmp(p, _T("Popup "), 6) == 0){
if (currentMenuName || currentMenu){
@ -144,18 +147,10 @@ int CMenuParser::Load(CString &filename){
e++;
kmeleonPlugin * kPlugin = theApp.plugins.Load(e);
if (kPlugin) {
HMENU pluginMenu;
HGLOBAL menuData = kPlugin->GetMenu();
pluginMenu = LoadMenuIndirect(menuData);
if (!IsMenu(pluginMenu)){
ERROR_BOX_1( "Menu %s is not a menu?", p )
}else if (!pluginMenu){
ERROR_BOX_1( "Could not load menu %s", p )
if (kPlugin->DoMenu){
kPlugin->DoMenu(currentMenu->GetSafeHmenu(), p);
}else{
if (!currentMenu->AppendMenu(MF_POPUP | MF_STRING, (UINT)pluginMenu, p)){
ERROR_BOX_1( "Could create menu %s", e )
}
ERROR_BOX_1( "plugin %s has no menu", e);
}
}else{
ERROR_BOX_1( "Could not load plugin %s", e )
@ -166,11 +161,16 @@ int CMenuParser::Load(CString &filename){
// unknown command
}
else {
char *e = strrchr(p, '=');
if (e){
*e = 0;
e++;
currentMenu->AppendMenu(MF_STRING, atoi(e), p);
if (!currentMenu){
MessageBox(NULL, "Found Menu item with no menu!", "", 0);
}
else {
char *e = strrchr(p, '=');
if (e){
*e = 0;
e++;
currentMenu->AppendMenu(MF_STRING, atoi(e), p);
}
}
}
p = strtok(NULL, "\r\n");
@ -192,6 +192,10 @@ int CMenuParser::Load(CString &filename){
return 1;
}
CMenu *CMenuParser::GetMenu(){
CMenu *CMenuParser::GetMenu(char *menuName){
CMenu *menu;
if (!menus.Lookup(menuName, menu)){
return NULL;
}
return menu;
}

@ -25,7 +25,7 @@ class CMenuParser {
protected:
CFile *menuFile;
CMenu *menu;
CMap<CString, LPCSTR, CMenu *, CMenu *&> menus;
public:
CMenuParser();
@ -35,7 +35,7 @@ public:
Load(CString &filename);
CMenu *GetMenu();
CMenu *GetMenu(char * menuName);
};
#endif // __MENUPARSER_H__

@ -20,6 +20,11 @@
#include "StdAfx.h"
#include "KMeleon.h"
#include "nsEmbedAPI.h"
#include "MainFrm.h"
#include "Mozilla.h"
#include "Plugins.h"
#include "kmeleon_plugin.h"
@ -54,6 +59,42 @@ const char *FileNoPath(const char *filepath){
}
}
UINT currentID = 2000;
UINT GetCommandIDs(int num){
UINT freeID = currentID;
currentID += num;
return freeID;
}
int CPlugins::OnUpdate(UINT command){
if (command >= 2000 && command <= currentID){
return true;
}
return false;
}
// TODO: when a plugin calls GetCommandIDs, register it, then only send them those messages
void CPlugins::OnCommand(UINT command){
if (!OnUpdate(command)){
return;
}
POSITION pos = pluginList.GetStartPosition();
kmeleonPlugin * kPlugin;
CString s;
while (pos){
pluginList.GetNextAssoc( pos, s, kPlugin);
if (kPlugin && kPlugin->OnCommand){
kPlugin->OnCommand(command);
}
}
}
void NavigateTo(char *url, int newWindow){
CString CStringUrl(url);
CMainFrame *mainFrame = (CMainFrame *)theApp.m_pMainWnd->GetActiveWindow();
((CMozilla *)(mainFrame->GetActiveView()))->Navigate(&CStringUrl);
}
kmeleonPlugin * CPlugins::Load(const char *file){
kmeleonPlugin * kPlugin;
if (pluginList.Lookup(FileNoPath(file), kPlugin)){
@ -78,6 +119,9 @@ kmeleonPlugin * CPlugins::Load(const char *file){
kPlugin->hParentInstance = AfxGetInstanceHandle();
kPlugin->hDllInstance = plugin;
kPlugin->GetCommandIDs = GetCommandIDs;
kPlugin->NavigateTo = NavigateTo;
kPlugin->Init();
pluginList.SetAt(FileNoPath(file), kPlugin);
@ -102,15 +146,14 @@ int CPlugins::FindAndLoad(char *pattern = "*.dll"){
return i;
}
void CPlugins::OnCommand(UINT command){
void CPlugins::DoRebars(HWND rebarWnd){
POSITION pos = pluginList.GetStartPosition();
kmeleonPlugin * kPlugin;
CString s;
while (pos){
pluginList.GetNextAssoc( pos, s, kPlugin);
if (kPlugin && kPlugin->OnCommand){
kPlugin->OnCommand(command);
if (kPlugin && kPlugin->DoRebar){
kPlugin->DoRebar(rebarWnd);
}
}
}
}

@ -27,7 +27,7 @@
#include "Preferences.h"
class CPlugins {
friend CPreferencePage;
friend CPreferencePagePlugins;
protected:
CMap<CString, LPCSTR, kmeleonPlugin *, kmeleonPlugin *> pluginList;
@ -40,6 +40,9 @@ public:
kmeleonPlugin * Load(const char *pattern);
void OnCommand(UINT command);
int OnUpdate(UINT command);
void DoRebars(HWND rebarWnd);
};
#endif // __PLUGINS_H__

@ -24,44 +24,58 @@
extern CKMeleonApp theApp;
CPreferences::CPreferences(){
Init();
CPreferences::CPreferences() {
}
CPreferences::CPreferences(CWnd* pParent /*=NULL*/)
: CDialog(CPreferences::IDD, pParent)
{
Init();
CPreferences::~CPreferences() {
if (bAutoSave)
Save();
}
BOOL CPreferences::Create(CWnd *pParent){
return false;
}
CPreferences::Load() {
bAutoSave = true;
bToolbarBackground = theApp.GetProfileInt(_T("Display"), _T("BackgroundImageEnabled"), 1);
toolbarBackground = theApp.GetProfileString(_T("Display"), _T("BackgroundImage"));
void CPreferences::Init(){
bStartHome = theApp.GetProfileInt(_T("General"), _T("StartHome"), 1);
homePage = theApp.GetProfileString(_T("General"), _T("HomePage"), "http://www.kmeleon.org");
homePage = theApp.GetProfileString(_T("General"), _T("HomePage"), _T("http://www.kmeleon.org"));
toolbarBackground = theApp.GetProfileString(_T("Display"), _T("BackgroundImage"));
bToolbarBackground = theApp.GetProfileInt(_T("Display"), _T("BackgroundImageEnabled"), 1);
settingsDir = theApp.GetProfileString(_T("General"), _T("SettingsDir"));
}
CPreferences::Save() {
theApp.WriteProfileInt(_T("Display"), _T("BackgroundImageEnabled"), bToolbarBackground);
theApp.WriteProfileString(_T("Display"), _T("BackgroundImage"), toolbarBackground);
theApp.WriteProfileInt(_T("General"), _T("StartHome"), bStartHome);
theApp.WriteProfileString(_T("General"), _T("HomePage"), homePage);
theApp.WriteProfileString(_T("General"), _T("SettingsDir"), settingsDir);
}
CPreferencesDlg::CPreferencesDlg() : CDialog(IDD) {
page = NULL;
}
void CPreferences::DoDataExchange(CDataExchange* pDX){
BOOL CPreferencesDlg::Create(CWnd *pParent){
return false;
}
void CPreferencesDlg::DoDataExchange(CDataExchange* pDX){
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPreferences)
//{{AFX_DATA_MAP(CPreferencesDlg)
DDX_Control(pDX, IDC_LIST1, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPreferences, CDialog)
//{{AFX_MSG_MAP(CPreferences)
BEGIN_MESSAGE_MAP(CPreferencesDlg, CDialog)
//{{AFX_MSG_MAP(CPreferencesDlg)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnListSelect)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CPreferences::OnInitDialog(){
CPreferencesDlg::OnInitDialog(){
CDialog::OnInitDialog();
UpdateData(true);
@ -82,12 +96,12 @@ CPreferences::OnInitDialog(){
return TRUE; // return TRUE unless you set the focus to a control
}
CPreferences::~CPreferences(){
CPreferencesDlg::~CPreferencesDlg(){
if (page)
delete page;
}
int CPreferences::DoModal(){
int CPreferencesDlg::DoModal(){
int ret = CDialog::DoModal();
if (page){
@ -95,31 +109,25 @@ int CPreferences::DoModal(){
page = NULL;
}
theApp.WriteProfileInt(_T("Display"), _T("BackgroundImageEnabled"), bToolbarBackground);
theApp.WriteProfileString(_T("Display"), _T("BackgroundImage"), toolbarBackground);
theApp.WriteProfileInt(_T("General"), _T("StartHome"), bStartHome);
theApp.WriteProfileString(_T("General"), _T("HomePage"), homePage);
return ret;
}
void CPreferences::OnOK(){
void CPreferencesDlg::OnOK(){
page->UpdateData();
CDialog::OnOK();
}
void CPreferences::OnCancel(){
void CPreferencesDlg::OnCancel(){
CDialog::OnCancel();
}
void CPreferences::AddItem(char *text, UINT idd){
void CPreferencesDlg::AddItem(char *text, UINT idd){
int item = m_list.GetItemCount();
m_list.InsertItem(item, text, 0);
m_list.SetItemData(item, idd);
}
void CPreferences::OnListSelect(NMHDR* pNMHDR, LRESULT* pResult) {
void CPreferencesDlg::OnListSelect(NMHDR* pNMHDR, LRESULT* pResult) {
int item;
POSITION pos;
pos = m_list.GetFirstSelectedItemPosition();
@ -133,7 +141,7 @@ void CPreferences::OnListSelect(NMHDR* pNMHDR, LRESULT* pResult) {
ShowPage(idd);
}
void CPreferences::ShowPage(UINT idd){
void CPreferencesDlg::ShowPage(UINT idd){
if (page){
if (page->idd == idd){
return;
@ -141,7 +149,11 @@ void CPreferences::ShowPage(UINT idd){
page->UpdateData();
delete page;
}
page = new CPreferencePage;
if (idd == IDD_PREFERENCES_PLUGINS){
page = new CPreferencePagePlugins;
}else{
page = new CPreferencePage;
}
page->idd = idd;
@ -166,46 +178,21 @@ void CPreferences::ShowPage(UINT idd){
BOOL CPreferencePage::OnInitDialog(){
CDialog::OnInitDialog();
if (idd == IDD_PREFERENCES_PLUGINS){
CPreferences *parent = (CPreferences *)GetParent();
RECT rect;
parent->m_pluginList.SetParent(this);
parent->m_pluginList.GetClientRect(&rect);
parent->m_pluginList.InsertColumn(0, "Blah", LVCFMT_LEFT, rect.right);
POSITION pos = theApp.plugins.pluginList.GetStartPosition();
kmeleonPlugin * kPlugin;
CString s;
int i=0;
while (pos){
theApp.plugins.pluginList.GetNextAssoc( pos, s, kPlugin);
int item = parent->m_pluginList.GetItemCount();
parent->m_pluginList.InsertItem(item, kPlugin->description, 0);
}
parent->m_pluginList.SetItemState(0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
}
return FALSE; // return TRUE unless you set the focus to a control
}
void CPreferencePage::DoDataExchange(CDataExchange* pDX){
CPreferences *parent = (CPreferences *)GetParent();
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPreferencePage)
switch (idd){
case IDD_PREFERENCES_DISPLAY:
DDX_Text(pDX, IDC_EDIT_TOOLBAR_BACKGROUND, parent->toolbarBackground);
DDX_Check(pDX, IDC_CHECK_TOOLBAR_BACKGROUND, parent->bToolbarBackground);
DDX_Text(pDX, IDC_EDIT_TOOLBAR_BACKGROUND, theApp.preferences.toolbarBackground);
DDX_Check(pDX, IDC_CHECK_TOOLBAR_BACKGROUND, theApp.preferences.bToolbarBackground);
break;
case IDD_PREFERENCES_GENERAL:
DDX_Radio(pDX, IDC_RADIO_START_BLANK, parent->bStartHome);
DDX_Text(pDX, IDC_EDIT_HOMEPAGE, parent->homePage);
break;
case IDD_PREFERENCES_PLUGINS:
DDX_Control(pDX, IDC_LIST_PLUGINS, parent->m_pluginList);
DDX_Radio(pDX, IDC_RADIO_START_BLANK, theApp.preferences.bStartHome);
DDX_Text(pDX, IDC_EDIT_HOMEPAGE, theApp.preferences.homePage);
DDX_Text(pDX, IDC_EDIT_SETTINGS_DIR, theApp.preferences.settingsDir);
break;
}
//}}AFX_DATA_MAP
@ -214,36 +201,77 @@ void CPreferencePage::DoDataExchange(CDataExchange* pDX){
BEGIN_MESSAGE_MAP(CPreferencePage, CDialog)
//{{AFX_MSG_MAP(CPreferencePage)
ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnBrowse)
ON_BN_CLICKED(IDC_BUTTON_CONFIG, OnConfig)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CPreferencePage::OnBrowse() {
CPreferences *parent = (CPreferences *)GetParent();
CFileDialog fDlg(TRUE);
switch (idd){
case IDD_PREFERENCES_DISPLAY:
fDlg.m_ofn.lpstrFilter = "Bitmaps\0*.bmp\0";
fDlg.DoModal();
if (parent){
parent->toolbarBackground = fDlg.GetPathName();
UpdateData(FALSE);
}
theApp.preferences.toolbarBackground = fDlg.GetPathName();
UpdateData(FALSE);
break;
}
}
void CPreferencePage::OnConfig() {
CPreferences *parent = (CPreferences *)GetParent();
// these are here to cancel the effects of hitting enter/esc
void CPreferencePage::OnOK(){
}
void CPreferencePage::OnCancel(){
}
/**/
BOOL CPreferencePagePlugins::OnInitDialog(){
CDialog::OnInitDialog();
RECT rect;
m_pluginList.SetParent(this);
m_pluginList.GetClientRect(&rect);
m_pluginList.InsertColumn(0, "Blah", LVCFMT_LEFT, rect.right);
POSITION pos = theApp.plugins.pluginList.GetStartPosition();
kmeleonPlugin * kPlugin;
CString s;
int i=0;
while (pos){
theApp.plugins.pluginList.GetNextAssoc( pos, s, kPlugin);
int item = m_pluginList.GetItemCount();
m_pluginList.InsertItem(item, kPlugin->description, 0);
}
m_pluginList.SetItemState(0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
return FALSE; // return TRUE unless you set the focus to a control
}
void CPreferencePagePlugins::DoDataExchange(CDataExchange* pDX){
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPreferencePagePlugins)
DDX_Control(pDX, IDC_LIST_PLUGINS, m_pluginList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPreferencePagePlugins, CPreferencePage)
//{{AFX_MSG_MAP(CPreferencePagePlugins)
ON_BN_CLICKED(IDC_BUTTON_CONFIG, OnConfig)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CPreferencePagePlugins::OnConfig() {
int item;
POSITION pos;
pos = parent->m_pluginList.GetFirstSelectedItemPosition();
pos = m_pluginList.GetFirstSelectedItemPosition();
if (!pos){
return;
}
item = parent->m_pluginList.GetNextSelectedItem(pos);
item = m_pluginList.GetNextSelectedItem(pos);
kmeleonPlugin * kPlugin;
CString s;
@ -260,10 +288,3 @@ void CPreferencePage::OnConfig() {
item--;
}
}
// these are here to cancel the effects of hitting enter/esc
void CPreferencePage::OnOK(){
}
void CPreferencePage::OnCancel(){
}

@ -33,7 +33,6 @@ protected:
virtual BOOL OnInitDialog();
afx_msg void OnBrowse();
afx_msg void OnConfig();
virtual void OnOK();
virtual void OnCancel();
@ -41,28 +40,33 @@ protected:
DECLARE_MESSAGE_MAP()
};
class CPreferences : public CDialog{
class CPreferencePagePlugins : public CPreferencePage {
protected:
CListCtrl m_pluginList;
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual BOOL OnInitDialog();
afx_msg void OnConfig();
DECLARE_MESSAGE_MAP()
};
class CPreferencesDlg : public CDialog{
friend CPreferencePage;
protected:
//{{AFX_DATA(CPreferences)
enum { IDD = IDD_PREFERENCES };
CListCtrl m_list;
//}}AFX_DATA
CListCtrl m_pluginList;
CPreferencePage *page;
public:
// the filename
CString toolbarBackground;
int bToolbarBackground;
CString homePage;
int bStartHome;
CPreferences(CWnd* pParent /*=NULL*/);
CPreferences();
~CPreferences();
CPreferencesDlg();
~CPreferencesDlg();
int DoModal();
@ -88,8 +92,30 @@ protected:
void AddItem(char *text, UINT idd);
friend CPreferencePage;
};
class CPreferences {
public:
// -- data
CString toolbarBackground;
int bToolbarBackground;
CString homePage;
int bStartHome;
// this holds the menu.txt files
CString settingsDir;
// if true, will call Save on destruction
int bAutoSave;
// -- functions
CPreferences();
~CPreferences();
Save();
Load();
};
#endif

@ -26,13 +26,25 @@
#endif
typedef struct {
// Filled in by the plugin
int version;
char *description;
int (*Init)();
void (*Config)(HWND parent);
void (*Quit)();
HGLOBAL (*GetMenu)();
void (*DoMenu)(HMENU menu, char *param);
void (*OnCommand)(UINT command);
// return false to disable the item
//int (*CommandUpdate)(UINT command);
void (*DoRebar)(HWND rebarWnd);
// Filled in by k-meleon
// this function allocates <num> successive ids for the plugin, then returns the first one.
// use it to get an unused command id. this way plugins won't step on others toes.
UINT (*GetCommandIDs)(int num);
// if newWindow, open in a new window, otherwise use the current window
void (*NavigateTo)(char *url, int newWindow);
HINSTANCE hParentInstance;
HINSTANCE hDllInstance;
} kmeleonPlugin;

Loading…
Cancel
Save