Development :  K-Meleon Web Browser Forum
K-Meleon development related discussions. 
Prompts (with source)
Posted by: Brian Harris
Date: January 24, 2001 02:47AM

I've been doing some work on the prompts. With these changes you can access those pages that require username/passwords. hopefully it'll work for you smiling smiley

I can also upload a snapsot for those that can't get mozilla to compile, I just need webspace smiling smiley

--- Prompt.cpp ---

#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:tongue sticking out smileyrompt(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:tongue sticking out smileyromptUsernameAndPassword(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:tongue sticking out smileyromptPassword(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:confused smileyelect(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;
}

--- Prompt.h ---
#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__

--- KMeleon.rc ---
IDD_PROMPT DIALOG DISCARDABLE 0, 0, 264, 95
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "OK",IDOK,75,74,50,14
PUSHBUTTON "Cancel",IDCANCEL,131,74,50,14
EDITTEXT IDC_EDITBOX,7,44,250,14,ES_AUTOHSCROLL
LTEXT "Static",IDC_CAPTION,7,7,250,35
END

IDD_PROMPT_USERNAME_PASSWORD DIALOG DISCARDABLE 0, 0, 186, 102
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "OK",IDOK,43,81,50,14
PUSHBUTTON "Cancel",IDCANCEL,97,81,50,14
EDITTEXT IDC_EDIT_USERNAME,61,37,118,14,ES_AUTOHSCROLL
LTEXT "Username:",IDC_STATIC,7,40,54,8
EDITTEXT IDC_EDIT_PASSWORD,61,55,118,14,ES_AUTOHSCROLL
LTEXT "Password",IDC_STATIC,7,58,54,8
LTEXT "Static",IDC_CAPTION,7,7,172,26
END

--- resource.h ---
#define IDD_PROMPT 152
#define IDD_PROMPT_USERNAME_PASSWORD 153
#define IDC_EDITBOX 1003
#define IDC_EDIT_USERNAME 1005
#define IDC_EDIT_PASSWORD 1006

--- WebBrowserChrome.cpp ---
in between NS_INTERFACE_MAP_BEGIN(WebBrowserChrome) and NS_INTERFACE_MAP_END add this:
NS_INTERFACE_MAP_ENTRY(nsIPrompt) // defined in prompt.cpp/h

--- WebBrowserChrome.h ---
add #include "Prompt.h" at the top
replace public nsIPrompt with this:
public CPrompt // BC -- implements all nsIPrompt stufs


Options: ReplyQuote
RE: Prompts (with source)
Posted by: guido
Date: January 24, 2001 10:45AM

Can't you get freespace from Freedrive or somekind???

Guido



Options: ReplyQuote
RE: Prompts (with source)
Posted by: Sebastian Späth
Date: January 24, 2001 10:51PM

#define IDC_EDITBOX 1003 is already defined in resource.h BTW,
now if sourceforge finally could get my CVS access fixed, I'd try that out...

Options: ReplyQuote
RE: Prompts (with source)
Posted by: Sebastian Späth
Date: January 24, 2001 10:56PM

err, I meant 1003 is already used, doesn't this has to be changed? How much bigger does the .exe get BTW?

Options: ReplyQuote
RE: Prompts (with source)
Posted by: Brian Harris
Date: January 25, 2001 02:17AM

the 1003 already being used isn't really a problem because it's used in a different dialog, but if it bothers you, you can change it to whatever you want (it *is* a #define after all :p)

I don't know how much bigger it makes the exe, probably not much, the majority of the code was just moved out of WebBrowserChrome.cpp, then there's the resource for the dialog boxes...

Options: ReplyQuote
RE: Prompts (with source)
Posted by: Sebastian Späth
Date: January 26, 2001 10:39PM

Hi Brian, hope you get an e-mail with this message:
As you already proposed a nice looking patch. Would you be interested in becoming a Kmeleon developer, commiting this (and hopefully other) patch(es)?
If so, let me know: Sebastian@SSpaeth.de

Options: ReplyQuote


K-Meleon forum is powered by Phorum.