Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Private Member Functions | Private Attributes
EmbedPrompter Class Reference

#include <EmbedPrompter.h>

Collaboration diagram for EmbedPrompter:
Collaboration graph

List of all members.

Public Types

enum  PromptType {

Public Member Functions

 EmbedPrompter ()
 ~EmbedPrompter ()
nsresult Create (PromptType aType, GtkWindow *aParentWindow)
void SetTitle (const PRUnichar *aTitle)
void SetTextValue (const PRUnichar *aTextValue)
void SetCheckMessage (const PRUnichar *aCheckMessage)
void SetCheckValue (const PRBool aValue)
void SetMessageText (const PRUnichar *aMessageText)
void SetUser (const PRUnichar *aUser)
void SetPassword (const PRUnichar *aPass)
void SetButtons (const PRUnichar *aButton0Label, const PRUnichar *aButton1Label, const PRUnichar *aButton2Label)
void SetItems (const PRUnichar **aItemArray, PRUint32 aCount)
void GetCheckValue (PRBool *aValue)
void GetConfirmValue (PRBool *aConfirmValue)
void GetTextValue (PRUnichar **aTextValue)
void GetUser (PRUnichar **aUser)
void GetPassword (PRUnichar **aPass)
void GetButtonPressed (PRInt32 *aButton)
void GetSelectedItem (PRInt32 *aIndex)
void Run (void)

Private Member Functions

void SaveDialogValues ()

Private Attributes

nsCString mTitle
nsCString mMessageText
nsCString mTextValue
nsCString mCheckMessage
PRBool mCheckValue
nsCString mUser
nsCString mPass
nsCString mButtonLabels [EMBED_MAX_BUTTONS]
PRUint32 mItemCount
PRInt32 mButtonPressed
PRBool mConfirmResult
PRInt32 mSelectedItem
GtkWidget * mWindow
GtkWidget * mUserField
GtkWidget * mPassField
GtkWidget * mTextField
GtkWidget * mOptionMenu
GtkWidget * mCheckBox

Detailed Description

Definition at line 46 of file EmbedPrompter.h.

Member Enumeration Documentation


Definition at line 53 of file EmbedPrompter.h.

Constructor & Destructor Documentation

Definition at line 94 of file EmbedPrompter.cpp.

    if (mItemList)
        delete[] mItemList;

Member Function Documentation

nsresult EmbedPrompter::Create ( PromptType  aType,
GtkWindow *  aParentWindow 

Definition at line 101 of file EmbedPrompter.cpp.

    mWindow = gtk_dialog_new_with_buttons(mTitle.get(), aParentWindow,

    // only add the dialog to the window group if the parent already has a window group,
    // so as not to break app's expectations about modal dialogs.
    if (aParentWindow && aParentWindow->group) {
        gtk_window_group_add_window (aParentWindow->group, GTK_WINDOW (mWindow));

    // gtk will resize this for us as necessary
    gtk_window_set_default_size(GTK_WINDOW(mWindow), 100, 50);

    // this HBox will contain the icon, and a vbox which contains the
    // dialog text and other widgets.
    GtkWidget* dialogHBox = gtk_hbox_new(FALSE, 12);

    // Set up dialog properties according to the GNOME HIG
    // (

    gtk_container_set_border_width(GTK_CONTAINER(mWindow), 6);
    gtk_dialog_set_has_separator(GTK_DIALOG(mWindow), FALSE);
    gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(mWindow)->vbox), 12);
    gtk_container_set_border_width(GTK_CONTAINER(dialogHBox), 6);

    // This is the VBox which will contain the label and other controls.
    GtkWidget* contentsVBox = gtk_vbox_new(FALSE, 12);

    // get the stock icon for this dialog and put it in the box
    const gchar* iconDesc = DialogTable[aType].icon;
    GtkWidget* icon = gtk_image_new_from_stock(iconDesc, GTK_ICON_SIZE_DIALOG);
    gtk_misc_set_alignment(GTK_MISC(icon), 0.5, 0.0);
    gtk_box_pack_start(GTK_BOX(dialogHBox), icon, FALSE, FALSE, 0);

    // now pack the label into the vbox
    GtkWidget* label = gtk_label_new(mMessageText.get());
    gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
    gtk_label_set_selectable(GTK_LABEL(label), TRUE);
    gtk_box_pack_start(GTK_BOX(contentsVBox), label, FALSE, FALSE, 0);

    int widgetFlags = DialogTable[aType].flags;

    if (widgetFlags & (INCLUDE_USERNAME | INCLUDE_PASSWORD)) {

        // If we're creating a username and/or password field, make an hbox
        // which will contain two vboxes, one for the labels and one for the
        // text fields.  This will let us line up the textfields.

        GtkWidget* userPassHBox = gtk_hbox_new(FALSE, 12);
        GtkWidget* userPassLabels = gtk_vbox_new(TRUE, 6);
        GtkWidget* userPassFields = gtk_vbox_new(TRUE, 6);

        if (widgetFlags & INCLUDE_USERNAME) {
            GtkWidget* userLabel = gtk_label_new("User Name:");
            gtk_box_pack_start(GTK_BOX(userPassLabels), userLabel, FALSE,
                               FALSE, 0);

            mUserField = gtk_entry_new();

            if (!mUser.IsEmpty())
                gtk_entry_set_text(GTK_ENTRY(mUserField), mUser.get());

            gtk_entry_set_activates_default(GTK_ENTRY(mUserField), TRUE);

            gtk_box_pack_start(GTK_BOX(userPassFields), mUserField, FALSE,
                               FALSE, 0);
        if (widgetFlags & INCLUDE_PASSWORD) {
            GtkWidget* passLabel = gtk_label_new("Password:");
            gtk_box_pack_start(GTK_BOX(userPassLabels), passLabel, FALSE,
                               FALSE, 0);

            mPassField = gtk_entry_new();

            if (!mPass.IsEmpty())
                gtk_entry_set_text(GTK_ENTRY(mPassField), mPass.get());

            gtk_entry_set_visibility(GTK_ENTRY(mPassField), FALSE);
            gtk_entry_set_activates_default(GTK_ENTRY(mPassField), TRUE);

            gtk_box_pack_start(GTK_BOX(userPassFields), mPassField, FALSE,
                               FALSE, 0);

        gtk_box_pack_start(GTK_BOX(userPassHBox), userPassLabels, FALSE,
                           FALSE, 0);
        gtk_box_pack_start(GTK_BOX(userPassHBox), userPassFields, FALSE,
                           FALSE, 0);
        gtk_box_pack_start(GTK_BOX(contentsVBox), userPassHBox, FALSE, FALSE, 0);

    if (aType == TYPE_PROMPT) {
        mTextField = gtk_entry_new();

        if (!mTextValue.IsEmpty())
            gtk_entry_set_text(GTK_ENTRY(mTextField), mTextValue.get());

        gtk_entry_set_activates_default(GTK_ENTRY(mTextField), TRUE);

        gtk_box_pack_start(GTK_BOX(contentsVBox), mTextField, FALSE, FALSE, 0);

    // Add a checkbox
    if ((widgetFlags & INCLUDE_CHECKBOX) && !mCheckMessage.IsEmpty()) {
        mCheckBox = gtk_check_button_new_with_label(mCheckMessage.get());


        gtk_box_pack_start(GTK_BOX(contentsVBox), mCheckBox, FALSE, FALSE, 0);

    // Add a dropdown menu
    if (aType == TYPE_SELECT) {
        // Build up a GtkMenu containing the items
        GtkWidget* menu = gtk_menu_new();
        for (PRUint32 i = 0; i < mItemCount; ++i) {
            GtkWidget* item = gtk_menu_item_new_with_label(mItemList[i].get());
            gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);

        // Now create an OptionMenu and set this as the menu
        mOptionMenu = gtk_option_menu_new();

        gtk_option_menu_set_menu(GTK_OPTION_MENU(mOptionMenu), menu);
        gtk_box_pack_start(GTK_BOX(contentsVBox), mOptionMenu, FALSE, FALSE, 0);

    if (aType == TYPE_UNIVERSAL) {
        // Create buttons based on the flags passed in.
        for (int i = EMBED_MAX_BUTTONS; i >= 0; --i) {
            if (!mButtonLabels[i].IsEmpty())
                                      mButtonLabels[i].get(), i);
        gtk_dialog_set_default_response(GTK_DIALOG(mWindow), 0);
    } else {
        // Create standard ok and cancel buttons
        if (widgetFlags & INCLUDE_CANCEL)
            gtk_dialog_add_button(GTK_DIALOG(mWindow), GTK_STOCK_CANCEL,

        GtkWidget* okButton = gtk_dialog_add_button(GTK_DIALOG(mWindow),

    // Pack the contentsVBox into the dialogHBox and the dialog.
    gtk_box_pack_start(GTK_BOX(dialogHBox), contentsVBox, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mWindow)->vbox), dialogHBox, FALSE,
                       FALSE, 0);

    return NS_OK;

Here is the call graph for this function:

Definition at line 364 of file EmbedPrompter.cpp.

    *aButton = mButtonPressed;

Definition at line 328 of file EmbedPrompter.cpp.

Definition at line 334 of file EmbedPrompter.cpp.

    *aConfirmValue = mConfirmResult;

Definition at line 352 of file EmbedPrompter.cpp.

    *aPass = UTF8ToNewUnicode(mPass);

Here is the call graph for this function:

Definition at line 358 of file EmbedPrompter.cpp.

    *aIndex = mSelectedItem;

Definition at line 340 of file EmbedPrompter.cpp.

    *aTextValue = UTF8ToNewUnicode(mTextValue);

Here is the call graph for this function:

Definition at line 346 of file EmbedPrompter.cpp.

    *aUser = UTF8ToNewUnicode(mUser);

Here is the call graph for this function:

Definition at line 370 of file EmbedPrompter.cpp.

    gint response = gtk_dialog_run(GTK_DIALOG(mWindow));
    switch (response) {
        mConfirmResult = PR_FALSE;
        mConfirmResult = PR_TRUE;
        mButtonPressed = response;


Here is the call graph for this function:

Definition at line 393 of file EmbedPrompter.cpp.

    if (mUserField)

    if (mPassField)

    if (mCheckBox)
        mCheckValue = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mCheckBox));

    if (mTextField)

    if (mOptionMenu)
        mSelectedItem = gtk_option_menu_get_history(GTK_OPTION_MENU(mOptionMenu));

Here is the caller graph for this function:

void EmbedPrompter::SetButtons ( const PRUnichar aButton0Label,
const PRUnichar aButton1Label,
const PRUnichar aButton2Label 

Definition at line 318 of file EmbedPrompter.cpp.

    CopyUTF16toUTF8(aButton0Label, mButtonLabels[0]);
    CopyUTF16toUTF8(aButton1Label, mButtonLabels[1]);
    CopyUTF16toUTF8(aButton2Label, mButtonLabels[2]);

Here is the call graph for this function:

Definition at line 276 of file EmbedPrompter.cpp.

Here is the call graph for this function:

Definition at line 300 of file EmbedPrompter.cpp.

void EmbedPrompter::SetItems ( const PRUnichar **  aItemArray,
PRUint32  aCount 

Definition at line 306 of file EmbedPrompter.cpp.

    if (mItemList)
        delete[] mItemList;

    mItemCount = aCount;
    mItemList = new nsCString[aCount];
    for (PRUint32 i = 0; i < aCount; ++i)
        CopyUTF16toUTF8(aItemArray[i], mItemList[i]);

Here is the call graph for this function:

Definition at line 282 of file EmbedPrompter.cpp.

    CopyUTF16toUTF8(aMessageText, mMessageText);

Here is the call graph for this function:

Definition at line 294 of file EmbedPrompter.cpp.

    CopyUTF16toUTF8(aPass, mPass);

Here is the call graph for this function:

Definition at line 270 of file EmbedPrompter.cpp.

    CopyUTF16toUTF8(aTextValue, mTextValue);

Here is the call graph for this function:

Definition at line 264 of file EmbedPrompter.cpp.

    CopyUTF16toUTF8(aTitle, mTitle);

Here is the call graph for this function:

Definition at line 288 of file EmbedPrompter.cpp.

    CopyUTF16toUTF8(aUser, mUser);

Here is the call graph for this function:

Member Data Documentation

Definition at line 99 of file EmbedPrompter.h.

Definition at line 103 of file EmbedPrompter.h.

GtkWidget* EmbedPrompter::mCheckBox [private]

Definition at line 112 of file EmbedPrompter.h.

Definition at line 95 of file EmbedPrompter.h.

Definition at line 96 of file EmbedPrompter.h.

Definition at line 104 of file EmbedPrompter.h.

Definition at line 101 of file EmbedPrompter.h.

Definition at line 100 of file EmbedPrompter.h.

Definition at line 93 of file EmbedPrompter.h.

GtkWidget* EmbedPrompter::mOptionMenu [private]

Definition at line 111 of file EmbedPrompter.h.

Definition at line 98 of file EmbedPrompter.h.

GtkWidget* EmbedPrompter::mPassField [private]

Definition at line 109 of file EmbedPrompter.h.

Definition at line 105 of file EmbedPrompter.h.

GtkWidget* EmbedPrompter::mTextField [private]

Definition at line 110 of file EmbedPrompter.h.

Definition at line 94 of file EmbedPrompter.h.

Definition at line 92 of file EmbedPrompter.h.

Definition at line 97 of file EmbedPrompter.h.

GtkWidget* EmbedPrompter::mUserField [private]

Definition at line 108 of file EmbedPrompter.h.

GtkWidget* EmbedPrompter::mWindow [private]

Definition at line 107 of file EmbedPrompter.h.

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