~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/embedding/qa/testembed/components/Dialogs.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: Mozilla-sample-code 1.0
 
4
 *
 
5
 * Copyright (c) 2002 Netscape Communications Corporation and
 
6
 * other contributors
 
7
 *
 
8
 * Permission is hereby granted, free of charge, to any person obtaining a
 
9
 * copy of this Mozilla sample software and associated documentation files
 
10
 * (the "Software"), to deal in the Software without restriction, including
 
11
 * without limitation the rights to use, copy, modify, merge, publish,
 
12
 * distribute, sublicense, and/or sell copies of the Software, and to permit
 
13
 * persons to whom the Software is furnished to do so, subject to the
 
14
 * following conditions:
 
15
 *
 
16
 * The above copyright notice and this permission notice shall be included
 
17
 * in all copies or substantial portions of the Software.
 
18
 *
 
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
20
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 
22
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
24
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
25
 * DEALINGS IN THE SOFTWARE.
 
26
 *
 
27
 * Contributor(s):
 
28
 *   Chak Nanga <chak@netscape.com> 
 
29
 *
 
30
 * ***** END LICENSE BLOCK ***** */
 
31
 
 
32
#include "stdafx.h"
 
33
#include "Dialogs.h"
 
34
 
 
35
// File overview....
 
36
//
 
37
// Contains dialog box code to support Alerts, Prompts such as
 
38
// password prompt and username/password prompts
 
39
//
 
40
 
 
41
//--------------------------------------------------------------------------//
 
42
//                              CPromptDialog Stuff
 
43
//--------------------------------------------------------------------------//
 
44
 
 
45
CPromptDialog::CPromptDialog(CWnd* pParent, const char* pTitle, const char* pText,
 
46
                             const char* pInitPromptText,
 
47
                             BOOL bHasCheck, const char* pCheckText, int initCheckVal)
 
48
    : CDialog(CPromptDialog::IDD, pParent),
 
49
    m_bHasCheckBox(bHasCheck)
 
50
{   
 
51
    if(pTitle)
 
52
        m_csDialogTitle = pTitle;
 
53
    if(pText)
 
54
        m_csPromptText = pText;
 
55
    if(pInitPromptText)
 
56
        m_csPromptAnswer = pInitPromptText;
 
57
    if(pCheckText)
 
58
        m_csCheckBoxText = pCheckText; 
 
59
}
 
60
 
 
61
void CPromptDialog::DoDataExchange(CDataExchange* pDX)
 
62
{
 
63
    CDialog::DoDataExchange(pDX);
 
64
    //{{AFX_DATA_MAP(CPromptDialog)
 
65
    DDX_Text(pDX, IDC_PROMPT_ANSWER, m_csPromptAnswer);
 
66
    DDX_Check(pDX, IDC_CHECK_SAVE_PASSWORD, m_bCheckBoxValue);
 
67
    //}}AFX_DATA_MAP
 
68
}
 
69
 
 
70
BEGIN_MESSAGE_MAP(CPromptDialog, CDialog)
 
71
    //{{AFX_MSG_MAP(CPromptDialog)
 
72
        // NOTE: the ClassWizard will add message map macros here
 
73
    //}}AFX_MSG_MAP
 
74
END_MESSAGE_MAP()
 
75
 
 
76
int CPromptDialog::OnInitDialog()
 
77
{   
 
78
    SetWindowText(m_csDialogTitle);
 
79
  
 
80
    CWnd *pWnd = GetDlgItem(IDC_PROMPT_TEXT);
 
81
    if(pWnd)
 
82
        pWnd->SetWindowText(m_csPromptText);
 
83
 
 
84
    CButton *pChk = (CButton *)GetDlgItem(IDC_CHECK_SAVE_PASSWORD);
 
85
    if(pChk)
 
86
    {
 
87
        if (m_bHasCheckBox)
 
88
        {
 
89
            if(!m_csCheckBoxText.IsEmpty())
 
90
                pChk->SetWindowText(m_csCheckBoxText);
 
91
            pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED);
 
92
        }
 
93
        else
 
94
        {
 
95
            // Hide the check box control if there's no label text
 
96
            // This will be the case when we're not using single sign-on
 
97
            pChk->ShowWindow(SW_HIDE); 
 
98
        }
 
99
    }
 
100
 
 
101
    CEdit *pEdit = (CEdit *)GetDlgItem(IDC_PROMPT_ANSWER);
 
102
    if(pEdit) 
 
103
    {
 
104
        pEdit->SetWindowText(m_csPromptAnswer);
 
105
        pEdit->SetFocus();
 
106
        pEdit->SetSel(0, -1);
 
107
 
 
108
        return 0; // Returning "0" since we're explicitly setting focus
 
109
    }
 
110
 
 
111
    return TRUE;
 
112
}
 
113
 
 
114
//--------------------------------------------------------------------------//
 
115
//                              CPromptPasswordDialog Stuff
 
116
//--------------------------------------------------------------------------//
 
117
 
 
118
CPromptPasswordDialog::CPromptPasswordDialog(CWnd* pParent, const char* pTitle, const char* pText,
 
119
                                             const char* pInitPasswordText,
 
120
                                             BOOL bHasCheck, const char* pCheckText, int initCheckVal)
 
121
    : CDialog(CPromptPasswordDialog::IDD, pParent),
 
122
    m_bHasCheckBox(bHasCheck), m_bCheckBoxValue(initCheckVal)
 
123
{   
 
124
        if(pTitle)
 
125
                m_csDialogTitle = pTitle;
 
126
        if(pText)
 
127
                m_csPromptText = pText;
 
128
        if(pInitPasswordText)
 
129
            m_csPassword = pInitPasswordText;
 
130
        if(pCheckText)
 
131
                m_csCheckBoxText = pCheckText;
 
132
}
 
133
 
 
134
void CPromptPasswordDialog::DoDataExchange(CDataExchange* pDX)
 
135
{
 
136
    CDialog::DoDataExchange(pDX);
 
137
    //{{AFX_DATA_MAP(CPromptPasswordDialog)
 
138
    DDX_Text(pDX, IDC_PASSWORD, m_csPassword);
 
139
    DDX_Check(pDX, IDC_CHECK_SAVE_PASSWORD, m_bCheckBoxValue);
 
140
    //}}AFX_DATA_MAP
 
141
}
 
142
 
 
143
BEGIN_MESSAGE_MAP(CPromptPasswordDialog, CDialog)
 
144
    //{{AFX_MSG_MAP(CPromptPasswordDialog)
 
145
        // NOTE: the ClassWizard will add message map macros here
 
146
    //}}AFX_MSG_MAP
 
147
END_MESSAGE_MAP()
 
148
 
 
149
int CPromptPasswordDialog::OnInitDialog()
 
150
{   
 
151
    SetWindowText(m_csDialogTitle);
 
152
  
 
153
    CWnd *pWnd = GetDlgItem(IDC_PROMPT_TEXT);
 
154
    if(pWnd)
 
155
        pWnd->SetWindowText(m_csPromptText);
 
156
 
 
157
    CButton *pChk = (CButton *)GetDlgItem(IDC_CHECK_SAVE_PASSWORD);
 
158
    if(pChk)
 
159
    {
 
160
        if (m_bHasCheckBox)
 
161
        {
 
162
            if(!m_csCheckBoxText.IsEmpty())
 
163
                pChk->SetWindowText(m_csCheckBoxText);
 
164
            pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED);
 
165
        }
 
166
        else
 
167
        {
 
168
            // Hide the check box control if there's no label text
 
169
            // This will be the case when we're not using single sign-on
 
170
            pChk->ShowWindow(SW_HIDE); 
 
171
        }
 
172
    }
 
173
 
 
174
    CEdit *pEdit = (CEdit *)GetDlgItem(IDC_PASSWORD);
 
175
    if(pEdit) 
 
176
    {
 
177
        pEdit->SetFocus();
 
178
 
 
179
        return 0; // Returning "0" since we're explicitly setting focus
 
180
    }
 
181
 
 
182
    return TRUE;
 
183
}
 
184
 
 
185
//--------------------------------------------------------------------------//
 
186
//                              CPromptUsernamePasswordDialog Stuff
 
187
//--------------------------------------------------------------------------//
 
188
 
 
189
CPromptUsernamePasswordDialog::CPromptUsernamePasswordDialog(CWnd* pParent, const char* pTitle, const char* pText,
 
190
                                  const char* pInitUsername, const char* pInitPassword, 
 
191
                                          BOOL bHasCheck, const char* pCheckText, int initCheckVal)
 
192
    : CDialog(CPromptUsernamePasswordDialog::IDD, pParent),
 
193
    m_bHasCheckBox(bHasCheck), m_bCheckBoxValue(initCheckVal)
 
194
{
 
195
    if(pTitle)
 
196
        m_csDialogTitle = pTitle;
 
197
    if(pText)
 
198
        m_csPromptText = pText;
 
199
    if(pInitUsername)
 
200
        m_csUserName = pInitUsername;
 
201
    if(pInitPassword)
 
202
        m_csPassword = pInitPassword;
 
203
    if(pCheckText)
 
204
        m_csCheckBoxText = pCheckText;
 
205
}
 
206
 
 
207
void CPromptUsernamePasswordDialog::DoDataExchange(CDataExchange* pDX)
 
208
{
 
209
    CDialog::DoDataExchange(pDX);
 
210
    //{{AFX_DATA_MAP(CPromptUsernamePasswordDialog)
 
211
    DDX_Text(pDX, IDC_USERNAME, m_csUserName);
 
212
    DDX_Text(pDX, IDC_PASSWORD, m_csPassword);
 
213
    DDX_Check(pDX, IDC_CHECK_SAVE_PASSWORD, m_bCheckBoxValue);
 
214
    //}}AFX_DATA_MAP
 
215
}
 
216
 
 
217
BEGIN_MESSAGE_MAP(CPromptUsernamePasswordDialog, CDialog)
 
218
    //{{AFX_MSG_MAP(CPromptUsernamePasswordDialog)
 
219
        // NOTE: the ClassWizard will add message map macros here
 
220
    //}}AFX_MSG_MAP
 
221
END_MESSAGE_MAP()
 
222
 
 
223
int CPromptUsernamePasswordDialog::OnInitDialog()
 
224
{   
 
225
        SetWindowText(m_csDialogTitle);
 
226
  
 
227
    CWnd *pWnd = GetDlgItem(IDC_PROMPT_TEXT);
 
228
    if(pWnd)
 
229
        pWnd->SetWindowText(m_csPromptText);
 
230
 
 
231
    CButton *pChk = (CButton *)GetDlgItem(IDC_CHECK_SAVE_PASSWORD);
 
232
    if(pChk)
 
233
    {
 
234
        if(m_bHasCheckBox)
 
235
        {
 
236
            if (!m_csCheckBoxText.IsEmpty())
 
237
                pChk->SetWindowText(m_csCheckBoxText);
 
238
            pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED);
 
239
        }
 
240
        else
 
241
        {
 
242
            pChk->ShowWindow(SW_HIDE);
 
243
        }
 
244
    }
 
245
 
 
246
    CEdit *pEdit = (CEdit *)GetDlgItem(IDC_PASSWORD);
 
247
    if(pEdit) 
 
248
    {
 
249
        pEdit->SetWindowText(m_csPassword);
 
250
    }
 
251
 
 
252
    pEdit = (CEdit *)GetDlgItem(IDC_USERNAME);
 
253
    if(pEdit) 
 
254
    {
 
255
        pEdit->SetWindowText(m_csUserName);
 
256
        pEdit->SetSel(0, -1);
 
257
 
 
258
        pEdit->SetFocus();
 
259
 
 
260
        return 0; // Returning "0" since we're explicitly setting focus
 
261
    }
 
262
 
 
263
    return TRUE;
 
264
}
 
265
 
 
266
//--------------------------------------------------------------------------//
 
267
//                              CAlertCheckDialog Stuff
 
268
//--------------------------------------------------------------------------//
 
269
 
 
270
CAlertCheckDialog::CAlertCheckDialog(CWnd* pParent, const char* pTitle, const char* pText,
 
271
                             const char* pCheckText, int initCheckVal)
 
272
        : CDialog(CAlertCheckDialog::IDD, pParent)
 
273
{   
 
274
    if(pTitle)
 
275
        m_csDialogTitle = pTitle;
 
276
    if(pText)
 
277
        m_csMsgText = pText;
 
278
    if(pCheckText)
 
279
        m_csCheckBoxText = pCheckText; 
 
280
 
 
281
    m_bCheckBoxValue = initCheckVal;
 
282
}
 
283
 
 
284
void CAlertCheckDialog::DoDataExchange(CDataExchange* pDX)
 
285
{
 
286
    CDialog::DoDataExchange(pDX);
 
287
    //{{AFX_DATA_MAP(CAlertCheckDialog)
 
288
    DDX_Check(pDX, IDC_CHECKBOX, m_bCheckBoxValue);
 
289
    //}}AFX_DATA_MAP
 
290
}
 
291
 
 
292
BEGIN_MESSAGE_MAP(CAlertCheckDialog, CDialog)
 
293
    //{{AFX_MSG_MAP(CAlertCheckDialog)
 
294
        // NOTE: the ClassWizard will add message map macros here
 
295
    //}}AFX_MSG_MAP
 
296
END_MESSAGE_MAP()
 
297
 
 
298
int CAlertCheckDialog::OnInitDialog()
 
299
{
 
300
    SetWindowText(m_csDialogTitle);
 
301
 
 
302
    CWnd *pWnd = GetDlgItem(IDC_MSG_TEXT);
 
303
    if(pWnd)
 
304
        pWnd->SetWindowText(m_csMsgText);
 
305
 
 
306
    CButton *pChk = (CButton *)GetDlgItem(IDC_CHECKBOX);
 
307
    if(pChk)
 
308
    {
 
309
        pChk->SetWindowText(m_csCheckBoxText);
 
310
        pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED);
 
311
    }
 
312
 
 
313
    return TRUE;
 
314
}
 
315
 
 
316
//--------------------------------------------------------------------------//
 
317
//                              CConfirmCheckDialog Stuff
 
318
//--------------------------------------------------------------------------//
 
319
 
 
320
CConfirmCheckDialog::CConfirmCheckDialog(CWnd* pParent, const char* pTitle, const char* pText,
 
321
                            const char* pCheckText, int initCheckVal,
 
322
                            const char *pBtn1Text, const char *pBtn2Text, 
 
323
                            const char *pBtn3Text)
 
324
            : CDialog(CConfirmCheckDialog::IDD, pParent)
 
325
{   
 
326
    if(pTitle)
 
327
        m_csDialogTitle = pTitle;
 
328
    if(pText)
 
329
        m_csMsgText = pText;
 
330
    if(pCheckText)
 
331
        m_csCheckBoxText = pCheckText; 
 
332
 
 
333
    m_bCheckBoxValue = initCheckVal;
 
334
 
 
335
    if(pBtn1Text)
 
336
        m_csBtn1Text = pBtn1Text;
 
337
    if(pBtn2Text)
 
338
        m_csBtn2Text = pBtn2Text;
 
339
    if(pBtn3Text)
 
340
        m_csBtn3Text = pBtn3Text;
 
341
}
 
342
 
 
343
void CConfirmCheckDialog::DoDataExchange(CDataExchange* pDX)
 
344
{
 
345
    CDialog::DoDataExchange(pDX);
 
346
    //{{AFX_DATA_MAP(CConfirmCheckDialog)
 
347
    DDX_Check(pDX, IDC_CHECKBOX, m_bCheckBoxValue);
 
348
    //}}AFX_DATA_MAP
 
349
}
 
350
 
 
351
BEGIN_MESSAGE_MAP(CConfirmCheckDialog, CDialog)
 
352
    //{{AFX_MSG_MAP(CConfirmCheckDialog)
 
353
    ON_BN_CLICKED(IDC_BTN1, OnBtn1Clicked)
 
354
    ON_BN_CLICKED(IDC_BTN2, OnBtn2Clicked)
 
355
    ON_BN_CLICKED(IDC_BTN3, OnBtn3Clicked)
 
356
    //}}AFX_MSG_MAP
 
357
END_MESSAGE_MAP()
 
358
 
 
359
int CConfirmCheckDialog::OnInitDialog()
 
360
{   
 
361
        SetWindowText(m_csDialogTitle);
 
362
  
 
363
    CWnd *pWnd = GetDlgItem(IDC_MSG_TEXT);
 
364
    if(pWnd)
 
365
        pWnd->SetWindowText(m_csMsgText);
 
366
 
 
367
    CButton *pChk = (CButton *)GetDlgItem(IDC_CHECKBOX);
 
368
    if(pChk)
 
369
    {
 
370
        if(m_csCheckBoxText.IsEmpty())
 
371
        {
 
372
            pChk->ShowWindow(SW_HIDE);
 
373
        }
 
374
        else
 
375
        {
 
376
            pChk->SetWindowText(m_csCheckBoxText);
 
377
            pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED);
 
378
        }
 
379
    }
 
380
 
 
381
    CButton *pBtn1 = (CButton *)GetDlgItem(IDC_BTN1);
 
382
    if(pBtn1)
 
383
    {
 
384
        if(m_csBtn1Text.IsEmpty())
 
385
            pBtn1->ShowWindow(SW_HIDE);
 
386
        else
 
387
            pBtn1->SetWindowText(m_csBtn1Text);
 
388
    }
 
389
 
 
390
    CButton *pBtn2 = (CButton *)GetDlgItem(IDC_BTN2);
 
391
    if(pBtn2)
 
392
    {
 
393
        if(m_csBtn2Text.IsEmpty())
 
394
            pBtn2->ShowWindow(SW_HIDE);
 
395
        else
 
396
            pBtn2->SetWindowText(m_csBtn2Text);
 
397
    }
 
398
 
 
399
    CButton *pBtn3 = (CButton *)GetDlgItem(IDC_BTN3);
 
400
    if(pBtn3)
 
401
    {
 
402
        if(m_csBtn3Text.IsEmpty())
 
403
            pBtn3->ShowWindow(SW_HIDE);
 
404
        else
 
405
            pBtn3->SetWindowText(m_csBtn3Text);
 
406
    }
 
407
 
 
408
    return TRUE;
 
409
}
 
410
 
 
411
void CConfirmCheckDialog::OnBtn1Clicked()
 
412
{
 
413
    UpdateData();
 
414
 
 
415
    EndDialog(0); // where 0 indicates that the btn pressed was at index 0
 
416
}
 
417
 
 
418
void CConfirmCheckDialog::OnBtn2Clicked()
 
419
{
 
420
    UpdateData();
 
421
 
 
422
    EndDialog(1); // where 1 indicates that the btn pressed was at index 1
 
423
}
 
424
 
 
425
void CConfirmCheckDialog::OnBtn3Clicked()
 
426
{
 
427
    UpdateData();
 
428
 
 
429
    EndDialog(2); // where 2 indicates that the btn pressed was at index 2
 
430
}