adding for binaryc untested files:

plugins, menuparser, authentication menus, preferences
import/tags/kmeleon03
spaetz 22 years ago
parent 66a2839b33
commit 5f6f59b4a6
  1. 197
      k-meleon/MenuParser.cpp
  2. 41
      k-meleon/MenuParser.h
  3. 116
      k-meleon/Plugins.cpp
  4. 45
      k-meleon/Plugins.h
  5. 269
      k-meleon/Preferences.cpp
  6. 95
      k-meleon/Preferences.h
  7. 255
      k-meleon/Prompt.cpp
  8. 95
      k-meleon/Prompt.h

@ -0,0 +1,197 @@
/*
* Copyright (C) 2000 Brian Harris
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "StdAfx.h"
#include <afxtempl.h>
#include "Kmeleon.h"
#include "Plugins.h"
#include "MenuParser.h"
CMenuParser::CMenuParser(){
menu = NULL;
}
CMenuParser::CMenuParser(CString &filename){
menu = NULL;
Load(filename);
}
CMenuParser::~CMenuParser(){
if (menu){
menu->DestroyMenu();
delete menu;
}
}
void TranslateTabs(char *buffer){
char *p;
for (p=buffer; *p; p++){
if (*p == '\\'){
if (*(p+1) == 't'){
*p = ' ';
*(p+1) = '\t';
}
}
}
}
#define ERROR_BOX_1(msg, var1) \
{ char err[255]; \
sprintf(err, msg, var1); \
MessageBox(NULL, err, "Error", 0); \
}
#define ERROR_BOX_2(msg, var1, var2) \
{ char err[255]; \
sprintf(err, msg, var1, var2); \
MessageBox(NULL, err, "Error", 0); \
}
int CMenuParser::Load(CString &filename){
if (menu)
delete menu;
menu = NULL;
TRY {
menuFile = new CFile(filename, CFile::modeRead);
}
CATCH (CFileException, e) {
menuFile = NULL;
return 0;
}
END_CATCH
long length = menuFile->GetLength();
char *buffer = new char[length + 1];
menuFile->Read(buffer, length);
// force the terminating 0
buffer[length] = 0;
menuFile->Close();
delete menuFile;
menuFile = NULL;
TranslateTabs(buffer);
CMap<CString, LPCSTR, CMenu *, CMenu *&> menuMap;
char *currentMenuName = NULL;
CMenu *currentMenu = NULL;
char *p = strtok(buffer, "\r\n");
while (p){
if (*p == '#'){
}
else if (strnicmp(p, _T("MenuDef"), 7) == 0){
currentMenuName = NULL;
menu = new CMenu();
menu->CreateMenu();
currentMenu = menu;
}
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){
MessageBox(NULL, "Found Popup before :EndPopup", "", 0);
}
else{
p += 6; // jump past "Popup "
currentMenuName = p;
currentMenu = new CMenu();
currentMenu->CreatePopupMenu();
}
}
else if (strnicmp(p, _T(":EndPopup"), 9) == 0){
menuMap[CString(currentMenuName)] = currentMenu;
currentMenu = NULL;
currentMenuName = NULL;
}
else if (strnicmp(p, _T(":Popup "), 6) == 0){
p += 7;
CMenu *popup = NULL;
menuMap.Lookup(CString(p), popup);
if (popup){
currentMenu->AppendMenu(MF_POPUP | MF_STRING, (UINT)popup->m_hMenu, p);
}
}
else if (strnicmp(p, _T(":Seperator"), 10) == 0){
currentMenu->AppendMenu(MF_SEPARATOR);
}
else if (strnicmp(p, _T(":Plugin "), 8) == 0){
p+=8;
char *e = strrchr(p, '=');
if (e){
*e = 0;
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 )
}else{
if (!currentMenu->AppendMenu(MF_POPUP | MF_STRING, (UINT)pluginMenu, p)){
ERROR_BOX_1( "Could create menu %s", e )
}
}
}else{
ERROR_BOX_1( "Could not load plugin %s", e )
}
}
}
else if (*p == ':'){
// unknown command
}
else {
char *e = strrchr(p, '=');
if (e){
*e = 0;
e++;
currentMenu->AppendMenu(MF_STRING, atoi(e), p);
}
}
p = strtok(NULL, "\r\n");
};
POSITION pos = menuMap.GetStartPosition();
CMenu *m;
CString s;
while (pos){
menuMap.GetNextAssoc( pos, s, m);
if (m){
m->Detach();
m->DestroyMenu();
}
}
delete [] buffer;
return 1;
}
CMenu *CMenuParser::GetMenu(){
return menu;
}

@ -0,0 +1,41 @@
/*
* Copyright (C) 2000 Brian Harris
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __MENUPARSER_H__
#define __MENUPARSER_H__
#include "StdAfx.h"
class CMenuParser {
protected:
CFile *menuFile;
CMenu *menu;
public:
CMenuParser();
CMenuParser(CString &filename);
~CMenuParser();
Load(CString &filename);
CMenu *GetMenu();
};
#endif // __MENUPARSER_H__

@ -0,0 +1,116 @@
/*
* Copyright (C) 2000 Brian Harris
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// this handles plugin loading/unloading
#include "StdAfx.h"
#include "Plugins.h"
#include "kmeleon_plugin.h"
CPlugins::CPlugins(){
}
CPlugins::~CPlugins(){
POSITION pos = pluginList.GetStartPosition();
kmeleonPlugin * kPlugin;
CString s;
while (pos){
pluginList.GetNextAssoc( pos, s, kPlugin);
if (kPlugin){
kPlugin->Quit();
FreeLibrary(kPlugin->hDllInstance);
}
}
}
// returns a pointer to the char after the last \ or /
const char *FileNoPath(const char *filepath){
char *p1 = strrchr(filepath, '\\');
char *p2 = strrchr(filepath, '/');
if (p1 > p2){
return p1 + 1;
}
else if (p2 > p1){
return p2 + 1;
}
else{
return filepath;
}
}
kmeleonPlugin * CPlugins::Load(const char *file){
kmeleonPlugin * kPlugin;
if (pluginList.Lookup(FileNoPath(file), kPlugin)){
return kPlugin; // it's already loaded
}
HINSTANCE plugin = LoadLibrary(file);
KmeleonPluginGetter kpg = (KmeleonPluginGetter)GetProcAddress(plugin, "GetKmeleonPlugin");
if (!kpg){
FreeLibrary(plugin);
return 0;
}
kPlugin = kpg();
if (!kPlugin){
FreeLibrary(plugin);
return 0;
}
kPlugin->hParentInstance = AfxGetInstanceHandle();
kPlugin->hDllInstance = plugin;
kPlugin->Init();
pluginList.SetAt(FileNoPath(file), kPlugin);
return kPlugin;
}
int CPlugins::FindAndLoad(char *pattern = "*.dll"){
CString filepath;
CFileFind finder;
BOOL bWorking = finder.FindFile(pattern);
int i = 0;
while (bWorking)
{
bWorking = finder.FindNextFile();
filepath = finder.GetFilePath();
if ( Load(filepath) ){
i++;
}
}
return i;
}
void CPlugins::OnCommand(UINT command){
POSITION pos = pluginList.GetStartPosition();
kmeleonPlugin * kPlugin;
CString s;
while (pos){
pluginList.GetNextAssoc( pos, s, kPlugin);
if (kPlugin && kPlugin->OnCommand){
kPlugin->OnCommand(command);
}
}
}

@ -0,0 +1,45 @@
/*
* Copyright (C) 2000 Brian Harris
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// this handles plugin loading/unloading
#ifndef __PLUGINS_H__
#define __PLUGINS_H__
#include "StdAfx.h"
#include "kmeleon_plugin.h"
#include "Preferences.h"
class CPlugins {
friend CPreferencePage;
protected:
CMap<CString, LPCSTR, kmeleonPlugin *, kmeleonPlugin *> pluginList;
public:
CPlugins();
~CPlugins();
int FindAndLoad(char *pattern);
kmeleonPlugin * Load(const char *pattern);
void OnCommand(UINT command);
};
#endif // __PLUGINS_H__

@ -0,0 +1,269 @@
/*
* Copyright (C) 2000 Brian Harris
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Holds various prefernces for k-meleon. also controls the dialog box
#include "StdAfx.h"
#include "KMeleon.h"
#include "Preferences.h"
extern CKMeleonApp theApp;
CPreferences::CPreferences(){
Init();
}
CPreferences::CPreferences(CWnd* pParent /*=NULL*/)
: CDialog(CPreferences::IDD, pParent)
{
Init();
}
BOOL CPreferences::Create(CWnd *pParent){
return false;
}
void CPreferences::Init(){
bStartHome = theApp.GetProfileInt(_T("General"), _T("StartHome"), 1);
homePage = theApp.GetProfileString(_T("General"), _T("HomePage"), "http://www.kmeleon.org");
toolbarBackground = theApp.GetProfileString(_T("Display"), _T("BackgroundImage"));
bToolbarBackground = theApp.GetProfileInt(_T("Display"), _T("BackgroundImageEnabled"), 1);
page = NULL;
}
void CPreferences::DoDataExchange(CDataExchange* pDX){
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPreferences)
DDX_Control(pDX, IDC_LIST1, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPreferences, CDialog)
//{{AFX_MSG_MAP(CPreferences)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnListSelect)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CPreferences::OnInitDialog(){
CDialog::OnInitDialog();
UpdateData(true);
RECT rect;
m_list.SetParent(this);
m_list.GetClientRect(&rect);
m_list.InsertColumn(0, "Blah", LVCFMT_LEFT, rect.right);
AddItem("General", IDD_PREFERENCES_GENERAL);
AddItem("Display", IDD_PREFERENCES_DISPLAY);
AddItem("Proxy", IDD_PREFERENCES_PROXY);
AddItem("Plugins", IDD_PREFERENCES_PLUGINS);
m_list.SetItemState(0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
return TRUE; // return TRUE unless you set the focus to a control
}
CPreferences::~CPreferences(){
if (page)
delete page;
}
int CPreferences::DoModal(){
int ret = CDialog::DoModal();
if (page){
delete page;
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(){
page->UpdateData();
CDialog::OnOK();
}
void CPreferences::OnCancel(){
CDialog::OnCancel();
}
void CPreferences::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) {
int item;
POSITION pos;
pos = m_list.GetFirstSelectedItemPosition();
if (!pos){
return;
}
item = m_list.GetNextSelectedItem(pos);
UINT idd = m_list.GetItemData(item);
ShowPage(idd);
}
void CPreferences::ShowPage(UINT idd){
if (page){
if (page->idd == idd){
return;
}
page->UpdateData();
delete page;
}
page = new CPreferencePage;
page->idd = idd;
page->Create(idd, this);
page->SetParent(this);
RECT rect;
CWnd *container = GetDlgItem(IDC_CONTAINER);
container->GetClientRect(&rect);
container->ClientToScreen(&rect);
ScreenToClient(&rect);
page->MoveWindow(&rect);
page->ShowWindow(SW_SHOW);
}
/**/
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);
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);
break;
}
//}}AFX_DATA_MAP
}
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);
}
break;
}
}
void CPreferencePage::OnConfig() {
CPreferences *parent = (CPreferences *)GetParent();
int item;
POSITION pos;
pos = parent->m_pluginList.GetFirstSelectedItemPosition();
if (!pos){
return;
}
item = parent->m_pluginList.GetNextSelectedItem(pos);
kmeleonPlugin * kPlugin;
CString s;
pos = theApp.plugins.pluginList.GetStartPosition();
while (pos){
theApp.plugins.pluginList.GetNextAssoc( pos, s, kPlugin);
if (item == 0){
if (kPlugin->Config){
kPlugin->Config(this->m_hWnd);
}
break;
}
item--;
}
}
// these are here to cancel the effects of hitting enter/esc
void CPreferencePage::OnOK(){
}
void CPreferencePage::OnCancel(){
}

@ -0,0 +1,95 @@
/*
* Copyright (C) 2000 Brian Harris
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Holds various prefernces for k-meleon. also controls the dialog box
#ifndef __PREFERENCES_H__
#define __PREFERENCES_H__
#include "StdAfx.h"
#include "resource.h"
class CPreferencePage : public CDialog {
public:
UINT idd;
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual BOOL OnInitDialog();
afx_msg void OnBrowse();
afx_msg void OnConfig();
virtual void OnOK();
virtual void OnCancel();
DECLARE_MESSAGE_MAP()
};
class CPreferences : public CDialog{
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();
int DoModal();
BOOL Create(CWnd *pParent);
protected:
//{{AFX_VIRTUAL(CPreferences)
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
//}}AFX_VIRTUAL
//{{AFX_MSG(CPreferences)
virtual BOOL OnInitDialog();
afx_msg void OnListSelect(NMHDR* pNMHDR, LRESULT* pResult);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
virtual void OnOK();
virtual void OnCancel();
void Init();
void ShowPage(UINT idd);
void AddItem(char *text, UINT idd);
friend CPreferencePage;
};
#endif

@ -0,0 +1,255 @@
/*
* Copyright (C) 2000 Brian Harris
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "stdafx.h"
#include "MainFrm.h"
#include "nsIGenericFactory.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsIURI.h"
#include "nsIWebProgress.h"
#include "nsIDocShellTreeItem.h"
#include "nsIRequest.h"
#include "nsIChannel.h"
#include "nsCWebBrowser.h"
#include "nsWidgetsCID.h"
#include "Prompt.h"
#include "resource.h"
NS_IMPL_ISUPPORTS1(CPrompt, nsIPrompt)
CPrompt::CPrompt(){
NS_INIT_ISUPPORTS();
}
CPrompt::~CPrompt(){
}
NS_IMETHODIMP CPrompt::Alert(const PRUnichar *dialogTitle, const PRUnichar *text)
{
nsString title(dialogTitle);
nsString txt(text);
char *strTitle=title.ToNewCString();
char *strTxt=txt.ToNewCString();
MessageBox(NULL,strTxt,strTitle,MB_ICONWARNING);
Recycle(strTxt);
Recycle(strTitle);
return NS_OK;
}
NS_IMETHODIMP CPrompt::AlertCheck(const PRUnichar *dialogTitle, const PRUnichar *text, const PRUnichar *checkMsg, PRBool *checkValue)
{
MessageBox(NULL,"AlertCheck called","hu?",0);
return NS_OK;
}
NS_IMETHODIMP CPrompt::Confirm(const PRUnichar *dialogTitle, const PRUnichar *text, PRBool *_retval)
{
nsString title(dialogTitle);
nsString txt(text);
char *strTitle=title.ToNewCString();
char *strTxt=txt.ToNewCString();
*_retval=(MessageBox(NULL,strTxt,strTitle,MB_OKCANCEL|MB_ICONQUESTION)==IDOK);
Recycle(strTxt);
Recycle(strTitle);
return NS_OK;
}
NS_IMETHODIMP CPrompt::ConfirmCheck(const PRUnichar *dialogTitle, const PRUnichar *text, const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval)
{
return NS_OK;
}
typedef struct {
// global
const PRUnichar *dialogTitle;
const PRUnichar *text;
const PRUnichar *passwordRealm;
PRUint32 savePassword;
// only Prompt
const PRUnichar *defaultText;
PRUnichar **result;
// only Prompt Username/Password
PRUnichar **user;
PRUnichar **pwd;
} prompt_info;
BOOL CALLBACK PromptFunc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
static prompt_info *pi;
switch (uMsg){
case WM_INITDIALOG:
{
pi = (prompt_info *)lParam;
nsString title(pi->dialogTitle);
nsString txt(pi->text);
char *strTitle=title.ToNewCString();
char *strTxt=txt.ToNewCString();
if (strTitle[0]){
SetWindowText(hwndDlg, strTitle);
}else{
SetWindowText(hwndDlg, "Popup! Huzzah!");
}
SetDlgItemText(hwndDlg, IDC_CAPTION, strTxt);
Recycle(strTxt);
Recycle(strTitle);
if (pi->pwd && !pi->user){
HWND userBox = GetDlgItem(hwndDlg, IDC_EDIT_USERNAME);
LONG style = GetWindowLong(userBox, GWL_STYLE);
SetWindowLong(userBox, GWL_STYLE, style | WS_DISABLED);
}
}
// true = did not call SetFocus
return true;
case WM_COMMAND:
switch(wParam){
case IDOK:
{
char result[1024];
if (pi->result){
GetDlgItemText(hwndDlg, IDC_EDITBOX, result, 1023);
nsString nsResult;
nsResult.AssignWithConversion(result);
*pi->result = nsResult.ToNewUnicode();
}
if (pi->user){
GetDlgItemText(hwndDlg, IDC_EDIT_USERNAME, result, 1023);
nsString nsResult;
nsResult.AssignWithConversion(result);
*pi->user = nsResult.ToNewUnicode();
}
if (pi->pwd){
GetDlgItemText(hwndDlg, IDC_EDIT_PASSWORD, result, 1023);
nsString nsResult;
nsResult.AssignWithConversion(result);
*pi->pwd = nsResult.ToNewUnicode();
}
EndDialog(hwndDlg, true);
}
break;
case IDCANCEL:
EndDialog(hwndDlg, false);
break;
}
default:
// false = did not process
return false;
}
// true = processed message
return true;
}
NS_IMETHODIMP CPrompt::Prompt(const PRUnichar *dialogTitle, const PRUnichar *text, const PRUnichar *passwordRealm, PRUint32 savePassword, const PRUnichar *defaultText, PRUnichar **result, PRBool *_retval)
{
prompt_info pi;
pi.defaultText = defaultText;
pi.dialogTitle = dialogTitle;
pi.passwordRealm = passwordRealm;
pi.result = result;
pi.savePassword = savePassword;
pi.text = text;
pi.user = NULL;
pi.pwd = NULL;
*_retval = DialogBoxParam(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDD_PROMPT), AfxGetMainWnd()->GetSafeHwnd(), PromptFunc, (LPARAM)&pi);
return NS_OK;
}
NS_IMETHODIMP CPrompt::PromptUsernameAndPassword(const PRUnichar *dialogTitle, const PRUnichar *text, const PRUnichar *passwordRealm, PRUint32 savePassword, PRUnichar **user, PRUnichar **pwd, PRBool *_retval)
{
prompt_info pi;
pi.dialogTitle = dialogTitle;
pi.passwordRealm = passwordRealm;
pi.savePassword = savePassword;
pi.text = text;
pi.user = user;
pi.pwd = pwd;
pi.result = NULL;
pi.defaultText = NULL;
*_retval = DialogBoxParam(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDD_PROMPT_USERNAME_PASSWORD), AfxGetMainWnd()->GetSafeHwnd(), PromptFunc, (LPARAM)&pi);
return NS_OK;
}
NS_IMETHODIMP CPrompt::PromptPassword(const PRUnichar *dialogTitle, const PRUnichar *text, const PRUnichar *passwordRealm, PRUint32 savePassword, PRUnichar **pwd, PRBool *_retval)
{
prompt_info pi;
pi.dialogTitle = dialogTitle;
pi.passwordRealm = passwordRealm;
pi.savePassword = savePassword;
pi.text = text;
pi.pwd = pwd;
pi.user = NULL;
pi.result = NULL;
pi.defaultText = NULL;
*_retval = DialogBoxParam(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDD_PROMPT_USERNAME_PASSWORD), AfxGetMainWnd()->GetSafeHwnd(), PromptFunc, (LPARAM)&pi);
return NS_OK;
}
NS_IMETHODIMP CPrompt::Select(const PRUnichar *dialogTitle, const PRUnichar *text, PRUint32 count, const PRUnichar **selectList, PRInt32 *outSelection, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP CPrompt::UniversalDialog(const PRUnichar *titleMessage, const PRUnichar *dialogTitle, const PRUnichar *text, const PRUnichar *checkboxMsg, const PRUnichar *button0Text, const PRUnichar *button1Text, const PRUnichar *button2Text, const PRUnichar *button3Text, const PRUnichar *editfield1Msg, const PRUnichar *editfield2Msg, PRUnichar **editfield1Value, PRUnichar **editfield2Value, const PRUnichar *iconURL, PRBool *checkboxState, PRInt32 numberButtons, PRInt32 numberEditfields, PRInt32 editField1Password, PRInt32 *buttonPressed)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

@ -0,0 +1,95 @@
/*
* Copyright (C) 2000 Brian Harris
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __PROMPT_H__
#define __PROMPT_H__
#include "nsCOMPtr.h"
#include "nsIGenericFactory.h"
#include "nsString.h"
#include "nsIPrompt.h"
class CPrompt : public nsIPrompt {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPROMPT
CPrompt();
virtual ~CPrompt();
/**
* Puts up an alert dialog with an OK button.
*/
/* void alert (in wstring dialogTitle, in wstring text); */
/**
* Puts up an alert dialog with an OK button.
*/
/* void alertCheck (in wstring dialogTitle, in wstring text, in wstring checkMsg, out boolean checkValue); */
/**
* Puts up a dialog with OK and Cancel buttons.
* @return true for OK, false for Cancel
*/
/* boolean confirm (in wstring dialogTitle, in wstring text); */
/**
* Puts up a dialog with OK and Cancel buttons, and
* a message with a single checkbox.
* @return true for OK, false for Cancel
*/
/* boolean confirmCheck (in wstring dialogTitle, in wstring text, in wstring checkMsg, out boolean checkValue); */
/**
* Values for the savePassword parameter to prompt, promptPassword and
* promptUsernameAndPassword.
*/
/**
* Puts up a text input dialog with OK and Cancel buttons.
* @return true for OK, false for Cancel
*/
/* boolean prompt (in wstring dialogTitle, in wstring text, in wstring passwordRealm, in PRUint32 savePassword, in wstring defaultText, out wstring result); */
/**
* Puts up a username/password dialog with OK and Cancel buttons.
* @return true for OK, false for Cancel
*/
/* boolean promptUsernameAndPassword (in wstring dialogTitle, in wstring text, in wstring passwordRealm, in PRUint32 savePassword, out wstring user, out wstring pwd); */
/**
* Puts up a password dialog with OK and Cancel buttons.
* @return true for OK, false for Cancel
*/
/* boolean promptPassword (in wstring dialogTitle, in wstring text, in wstring passwordRealm, in PRUint32 savePassword, out wstring pwd); */
/**
* Puts up a dialog box which has a list box of strings
*/
/* boolean select (in wstring dialogTitle, in wstring text, in PRUint32 count, [array, size_is (count)] in wstring selectList, out long outSelection); */
/**
* Put up a universal dialog
*/
/* void universalDialog (in wstring titleMessage, in wstring dialogTitle, in wstring text, in wstring checkboxMsg, in wstring button0Text, in wstring button1Text, in wstring button2Text, in wstring button3Text, in wstring editfield1Msg, in wstring editfield2Msg, inout wstring editfield1Value, inout wstring editfield2Value, in wstring iconURL, inout boolean checkboxState, in PRInt32 numberButtons, in PRInt32 numberEditfields, in PRInt32 editField1Password, out PRInt32 buttonPressed); */
};
#endif //__PROMPT_H__
Loading…
Cancel
Save