Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Types | Static Protected Member Functions | Protected Attributes
PromptDlg Class Reference

List of all members.

Public Member Functions

 PromptDlg ()
virtual ~PromptDlg ()
nsresult ConfirmCheck (HWND hwndParent, const PRUnichar *dialogTitle, const PRUnichar *text, const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval)
nsresult ConfirmEx (HWND hwndParent, const PRUnichar *dialogTitle, const PRUnichar *text, PRUint32 buttonFlags, const PRUnichar *button0Title, const PRUnichar *button1Title, const PRUnichar *button2Title, const PRUnichar *checkMsg, PRBool *checkValue, PRInt32 *buttonPressed)
nsresult Prompt (HWND hwndParent, const PRUnichar *dialogTitle, const PRUnichar *text, PRUnichar **value, const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval)
nsresult PromptUsernameAndPassword (HWND hwndParent, const PRUnichar *dialogTitle, const PRUnichar *text, PRUnichar **username, PRUnichar **password, const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval)
nsresult PromptPassword (HWND hwndParent, const PRUnichar *dialogTitle, const PRUnichar *text, PRUnichar **password, const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval)

Protected Types

enum  { PROMPT_USERPASS, PROMPT_PASS, PROMPT_VALUE }

Static Protected Member Functions

static BOOL CALLBACK ConfirmProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
static BOOL CALLBACK PromptProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)

Protected Attributes

TCHARmTitle
TCHARmMessage
TCHARmCheckMessage
BOOL mCheckValue
TCHARmButtonTitles [3]
TCHARmUsername
TCHARmPassword
TCHARmValue
enum PromptDlg:: { ... }  mPromptMode

Detailed Description

Definition at line 51 of file PromptService.cpp.


Member Enumeration Documentation

anonymous enum [protected]
Enumerator:
PROMPT_USERPASS 
PROMPT_PASS 
PROMPT_VALUE 

Definition at line 107 of file PromptService.cpp.


Constructor & Destructor Documentation

PromptDlg::~PromptDlg ( ) [virtual]

Definition at line 130 of file PromptService.cpp.

{
    if (mTitle)
        free(mTitle);
    if (mMessage)
        free(mMessage);
    if (mCheckMessage)
        free(mCheckMessage);
    if (mUsername)
        free(mUsername);
    if (mPassword)
        free(mPassword);
    if (mValue)
        free(mValue);
    for (int i = 0; i < 3; i++)
    {
        if (mButtonTitles[i])
        {
            free(mButtonTitles[i]);
        }
    }
}

Member Function Documentation

nsresult PromptDlg::ConfirmCheck ( HWND  hwndParent,
const PRUnichar dialogTitle,
const PRUnichar text,
const PRUnichar checkMsg,
PRBool checkValue,
PRBool _retval 
)

Definition at line 153 of file PromptService.cpp.

{
    NS_ENSURE_ARG_POINTER(_retval);
    
    PRInt32 buttonPressed = 0;
    PRUint32 buttonFlags = nsIPromptService::BUTTON_TITLE_YES +
                          (nsIPromptService::BUTTON_TITLE_NO << 8);

    // Use the extended confirmation dialog with Yes & No buttons
    nsresult rv = ConfirmEx(hwndParent, dialogTitle, text,
        buttonFlags, NULL, NULL, NULL,
        checkMsg, checkValue, &buttonPressed);

    if (NS_SUCCEEDED(rv))
    {
        *_retval = (buttonPressed == 0) ? PR_TRUE : PR_FALSE;
    }

    return rv;
}

Here is the call graph for this function:

nsresult PromptDlg::ConfirmEx ( HWND  hwndParent,
const PRUnichar dialogTitle,
const PRUnichar text,
PRUint32  buttonFlags,
const PRUnichar button0Title,
const PRUnichar button1Title,
const PRUnichar button2Title,
const PRUnichar checkMsg,
PRBool checkValue,
PRInt32 buttonPressed 
)

Definition at line 179 of file PromptService.cpp.

{
    NS_ENSURE_ARG_POINTER(dialogTitle);
    NS_ENSURE_ARG_POINTER(text);
    NS_ENSURE_ARG_POINTER(buttonPressed);

    HINSTANCE hInstResource = _Module.m_hInstResource;

    USES_CONVERSION;

    // Duplicate all strings, turning them into TCHARs

    mTitle = _tcsdup(W2T(dialogTitle));
    mMessage = _tcsdup(W2T(text));
    if (checkMsg)
    {
        NS_ENSURE_ARG_POINTER(checkValue);
        mCheckMessage = _tcsdup(W2T(checkMsg));
        mCheckValue = (*checkValue == PR_TRUE) ? TRUE : FALSE;
    }

    // Turn the button flags into strings. The nsIPromptService flags
    // are scary bit shifted values which explains the masks and bit
    // shifting happening in this loop.

    for (int i = 0; i < 3; i++)
    {
        PRUint32 titleId = buttonFlags & 255;
        TCHAR **title = &mButtonTitles[i];
        switch (titleId)
        {
        case nsIPromptService::BUTTON_TITLE_OK:
        case nsIPromptService::BUTTON_TITLE_CANCEL:
        case nsIPromptService::BUTTON_TITLE_YES:
        case nsIPromptService::BUTTON_TITLE_NO:
        case nsIPromptService::BUTTON_TITLE_SAVE:
        case nsIPromptService::BUTTON_TITLE_DONT_SAVE:
        case nsIPromptService::BUTTON_TITLE_REVERT:
        {
            const int kTitleSize = 256;
            int stringId = IDS_CONFIRMEX_OK + titleId - nsIPromptService::BUTTON_TITLE_OK;
            *title = (TCHAR *) malloc(sizeof(TCHAR) * kTitleSize);
            ::LoadString(hInstResource, stringId, *title, kTitleSize - 1);
            break;
        }
        case nsIPromptService::BUTTON_TITLE_IS_STRING:
        {
            const PRUnichar *srcTitle =
                (i == 0) ? button0Title : 
                (i == 1) ? button1Title : button2Title;
            if (srcTitle)
            {
                *title = _tcsdup(W2T(srcTitle));
            }
            break;
        }
        default:
            // ANYTHING ELSE GETS IGNORED
            break;
        }
        buttonFlags >>= 8;
    }

    // Must have at least one button the user can click on!
    NS_ENSURE_ARG_POINTER(mButtonTitles[0]);

    INT result = DialogBoxParam(hInstResource,
        MAKEINTRESOURCE(IDD_CONFIRMEX), hwndParent, ConfirmProc, (LPARAM) this);

    if (checkValue)
        *checkValue = mCheckValue;

    if (buttonPressed)
        *buttonPressed = result;

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL CALLBACK PromptDlg::ConfirmProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
) [static, protected]

Definition at line 569 of file PromptService.cpp.

{
    PromptDlg *pThis = (PromptDlg *) GetWindowLong(hwndDlg, DWL_USER);
    int i;

    switch (uMsg)
    {
    case WM_INITDIALOG:

        // Initialise pThis
        SetWindowLong(hwndDlg, DWL_USER, lParam);
        pThis = (PromptDlg *) lParam;

        // Set dialog title & message text
        SetWindowText(hwndDlg, pThis->mTitle);
        SetDlgItemText(hwndDlg, IDC_MESSAGE, pThis->mMessage);

        // Set check message text
        if (pThis->mCheckMessage)
        {
            SetDlgItemText(hwndDlg, IDC_CHECKMSG, pThis->mCheckMessage);
            CheckDlgButton(hwndDlg, IDC_CHECKMSG, pThis->mCheckValue ? BST_CHECKED : BST_UNCHECKED); 
        }
        else
        {
            ShowWindow(GetDlgItem(hwndDlg, IDC_CHECKMSG), SW_HIDE);
        }

        // Set the button text or hide them
        for (i = 0; i < 3; i++)
        {
            int id = IDC_BUTTON0 + i;
            if (pThis->mButtonTitles[i])
            {
                SetDlgItemText(hwndDlg, id, pThis->mButtonTitles[i]);
            }
            else
            {
                ShowWindow(GetDlgItem(hwndDlg, id), SW_HIDE);
            }
        }
        return TRUE;

    case WM_COMMAND:
        if (HIWORD(wParam) == BN_CLICKED)
        {
            int id = LOWORD(wParam);
            if (id == IDC_BUTTON0 ||
                id == IDC_BUTTON1 ||
                id == IDC_BUTTON2)
            {
                if (pThis->mCheckMessage)
                {
                    pThis->mCheckValue =
                        (IsDlgButtonChecked(hwndDlg, IDC_CHECKMSG) == BST_CHECKED) ?
                            TRUE : FALSE;
                }
                EndDialog(hwndDlg, id - IDC_BUTTON0);
            }
        }
        return FALSE;
    }

    return FALSE;
}

Here is the caller graph for this function:

nsresult PromptDlg::Prompt ( HWND  hwndParent,
const PRUnichar dialogTitle,
const PRUnichar text,
PRUnichar **  value,
const PRUnichar checkMsg,
PRBool checkValue,
PRBool _retval 
)

Definition at line 267 of file PromptService.cpp.

{
    NS_ENSURE_ARG_POINTER(text);
    NS_ENSURE_ARG_POINTER(_retval);

    HINSTANCE hInstResource = _Module.m_hInstResource;

    USES_CONVERSION;

    // Duplicate all strings, turning them into TCHARs

    if (dialogTitle)
        mTitle = _tcsdup(W2T(dialogTitle));
    mMessage = _tcsdup(W2T(text));
    if (checkMsg)
    {
        NS_ENSURE_ARG_POINTER(checkValue);
        mCheckMessage = _tcsdup(W2T(checkMsg));
        mCheckValue = (*checkValue == PR_TRUE) ? TRUE : FALSE;
    }
    if (value)
    {
        mValue = _tcsdup(W2T(*value));
    }

    mPromptMode = PROMPT_VALUE;
    INT result = DialogBoxParam(hInstResource,
        MAKEINTRESOURCE(IDD_PROMPT), hwndParent, PromptProc, (LPARAM) this);

    if (result == IDOK)
    {
        if (value)
        {
            if (*value)
                nsMemory::Free(*value);
            nsAutoString v(T2W(mValue));
            *value = ToNewUnicode(v);
        }

        if (checkValue)
            *checkValue = mCheckValue;

        *_retval = TRUE;
    }
    else
    {
        *_retval = FALSE;
    }

    return NS_OK;
}

Here is the call graph for this function:

nsresult PromptDlg::PromptPassword ( HWND  hwndParent,
const PRUnichar dialogTitle,
const PRUnichar text,
PRUnichar **  password,
const PRUnichar checkMsg,
PRBool checkValue,
PRBool _retval 
)

Definition at line 392 of file PromptService.cpp.

{
    NS_ENSURE_ARG_POINTER(text);
    NS_ENSURE_ARG_POINTER(_retval);

    HINSTANCE hInstResource = _Module.m_hInstResource;

    USES_CONVERSION;

    // Duplicate all strings, turning them into TCHARs

    if (dialogTitle)
        mTitle = _tcsdup(W2T(dialogTitle));
    mMessage = _tcsdup(W2T(text));
    if (checkMsg)
    {
        NS_ENSURE_ARG_POINTER(checkValue);
        mCheckMessage = _tcsdup(W2T(checkMsg));
        mCheckValue = (*checkValue == PR_TRUE) ? TRUE : FALSE;
    }
    if (password)
    {
        mPassword = _tcsdup(W2T(*password));
    }

    mPromptMode = PROMPT_PASS;
    INT result = DialogBoxParam(hInstResource,
        MAKEINTRESOURCE(IDD_PROMPTUSERPASS), hwndParent, PromptProc, (LPARAM) this);

    if (result == IDOK)
    {
        if (password)
        {
            if (*password)
                nsMemory::Free(*password);
            nsAutoString pass(T2W(mPassword));
            *password = ToNewUnicode(pass);
        }

        if (checkValue)
            *checkValue = mCheckValue;

        *_retval = TRUE;
    }
    else
    {
        *_retval = FALSE;
    }

    return NS_OK;
}

Here is the call graph for this function:

BOOL CALLBACK PromptDlg::PromptProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
) [static, protected]

Definition at line 451 of file PromptService.cpp.

{
    PromptDlg *pThis = (PromptDlg *) GetWindowLong(hwndDlg, DWL_USER);
    switch (uMsg)
    {
    case WM_INITDIALOG:
        // Initialise pThis
        SetWindowLong(hwndDlg, DWL_USER, lParam);
        pThis = (PromptDlg *) lParam;

        // Set dialog title & message text
        if (pThis->mTitle)
            SetWindowText(hwndDlg, pThis->mTitle);

        SetDlgItemText(hwndDlg, IDC_MESSAGE, pThis->mMessage);

        // Set check message text
        if (pThis->mCheckMessage)
        {
            SetDlgItemText(hwndDlg, IDC_CHECKMSG, pThis->mCheckMessage);
            CheckDlgButton(hwndDlg, IDC_CHECKMSG, pThis->mCheckValue ? BST_CHECKED : BST_UNCHECKED); 
        }
        else
        {
            ShowWindow(GetDlgItem(hwndDlg, IDC_CHECKMSG), SW_HIDE);
        }

        switch (pThis->mPromptMode)
        {
        case PROMPT_PASS:
            EnableWindow(GetDlgItem(hwndDlg, IDC_USERNAME), FALSE);
            if (pThis->mPassword)
            {
                SetDlgItemText(hwndDlg, IDC_PASSWORD, pThis->mPassword);
            }
            break;
        case PROMPT_USERPASS:
            if (pThis->mUsername)
            {
                SetDlgItemText(hwndDlg, IDC_USERNAME, pThis->mUsername);
            }
            if (pThis->mPassword)
            {
                SetDlgItemText(hwndDlg, IDC_PASSWORD, pThis->mPassword);
            }
            break;
        case PROMPT_VALUE:
            if (pThis->mValue)
            {
                SetDlgItemText(hwndDlg, IDC_VALUE, pThis->mValue);
            }
            break;
        }

        return TRUE;

    case WM_COMMAND:
        if (HIWORD(wParam) == BN_CLICKED)
        {
            int id = LOWORD(wParam);
            if (id == IDOK)
            {
                if (pThis->mCheckMessage)
                {
                    pThis->mCheckValue =
                        (IsDlgButtonChecked(hwndDlg, IDC_CHECKMSG) == BST_CHECKED) ?
                            TRUE : FALSE;
                }

                const int bufferSize = 256;
                TCHAR buffer[bufferSize];

                switch (pThis->mPromptMode)
                {
                case PROMPT_USERPASS:
                    if (pThis->mUsername)
                    {
                        free(pThis->mUsername);
                    }
                    memset(buffer, 0, sizeof(buffer));
                    GetDlgItemText(hwndDlg, IDC_USERNAME, buffer, bufferSize);
                    pThis->mUsername = _tcsdup(buffer);

                    // DROP THROUGH !!!!

                case PROMPT_PASS:
                    if (pThis->mPassword)
                    {
                        free(pThis->mPassword);
                    }
                    memset(buffer, 0, sizeof(buffer));
                    GetDlgItemText(hwndDlg, IDC_PASSWORD, buffer, bufferSize);
                    pThis->mPassword = _tcsdup(buffer);
                    break;

                case PROMPT_VALUE:
                    if (pThis->mValue)
                    {
                        free(pThis->mValue);
                    }
                    memset(buffer, 0, sizeof(buffer));
                    GetDlgItemText(hwndDlg, IDC_VALUE, buffer, bufferSize);
                    pThis->mValue = _tcsdup(buffer);
                    break;
                }
                EndDialog(hwndDlg, IDOK);
            }
            else if (id == IDCANCEL)
            {
                EndDialog(hwndDlg, IDCANCEL);
            }
        }
        return TRUE;
    }
    return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult PromptDlg::PromptUsernameAndPassword ( HWND  hwndParent,
const PRUnichar dialogTitle,
const PRUnichar text,
PRUnichar **  username,
PRUnichar **  password,
const PRUnichar checkMsg,
PRBool checkValue,
PRBool _retval 
)

Definition at line 323 of file PromptService.cpp.

{
    NS_ENSURE_ARG_POINTER(text);
    NS_ENSURE_ARG_POINTER(_retval);

    HINSTANCE hInstResource = _Module.m_hInstResource;

    USES_CONVERSION;

    // Duplicate all strings, turning them into TCHARs

    if (dialogTitle)
        mTitle = _tcsdup(W2T(dialogTitle));
    mMessage = _tcsdup(W2T(text));
    if (checkMsg)
    {
        NS_ENSURE_ARG_POINTER(checkValue);
        mCheckMessage = _tcsdup(W2T(checkMsg));
        mCheckValue = (*checkValue == PR_TRUE) ? TRUE : FALSE;
    }
    if (username)
    {
        mUsername = _tcsdup(W2T(*username));
    }
    if (password)
    {
        mPassword = _tcsdup(W2T(*password));
    }

    mPromptMode = PROMPT_USERPASS;
    INT result = DialogBoxParam(hInstResource,
        MAKEINTRESOURCE(IDD_PROMPTUSERPASS), hwndParent, PromptProc, (LPARAM) this);

    if (result == IDOK)
    {
        if (username)
        {
            if (*username)
                nsMemory::Free(*username);
            nsAutoString user(T2W(mUsername));
            *username = ToNewUnicode(user);
        }
        if (password)
        {
            if (*password)
                nsMemory::Free(*password);
            nsAutoString pass(T2W(mPassword));
            *password = ToNewUnicode(pass);
        }

        if (checkValue)
            *checkValue = mCheckValue;

        *_retval = TRUE;
    }
    else
    {
        *_retval = FALSE;
    }

    return NS_OK;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 102 of file PromptService.cpp.

Definition at line 100 of file PromptService.cpp.

Definition at line 101 of file PromptService.cpp.

TCHAR* PromptDlg::mMessage [protected]

Definition at line 99 of file PromptService.cpp.

Definition at line 104 of file PromptService.cpp.

enum { ... } PromptDlg::mPromptMode [protected]
TCHAR* PromptDlg::mTitle [protected]

Definition at line 98 of file PromptService.cpp.

Definition at line 103 of file PromptService.cpp.

TCHAR* PromptDlg::mValue [protected]

Definition at line 105 of file PromptService.cpp.


The documentation for this class was generated from the following file: