Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa_test / FormFiller_Test / JS_ResponseDlg.cpp
1 // JS_ResponseDlg.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "readervc.h"\r
6 #include "JS_ResponseDlg.h"\r
7 \r
8 #ifdef _DEBUG\r
9 #define new DEBUG_NEW\r
10 #undef THIS_FILE\r
11 static char THIS_FILE[] = __FILE__;\r
12 #endif\r
13 \r
14 /////////////////////////////////////////////////////////////////////////////\r
15 // CJS_ResponseDlg dialog\r
16 \r
17 \r
18 CJS_ResponseDlg::CJS_ResponseDlg(CWnd* pParent /*=NULL*/)\r
19         : CDialog(CJS_ResponseDlg::IDD, pParent)\r
20 {\r
21         //{{AFX_DATA_INIT(CJS_ResponseDlg)\r
22                 // NOTE: the ClassWizard will add member initialization here\r
23         //}}AFX_DATA_INIT\r
24         m_swTitle =(FPDF_WIDESTRING) L"";\r
25         m_swQuestion =(FPDF_WIDESTRING) L"";\r
26         m_swLabel =(FPDF_WIDESTRING) L"";\r
27         m_swDefault =(FPDF_WIDESTRING) L"";\r
28         m_swResponse =L"";\r
29         m_bIsVisible = false;\r
30         m_pResponseEdit = NULL;\r
31 }\r
32 \r
33 \r
34 void CJS_ResponseDlg::DoDataExchange(CDataExchange* pDX)\r
35 {\r
36         CDialog::DoDataExchange(pDX);\r
37         //{{AFX_DATA_MAP(CJS_ResponseDlg)\r
38                 // NOTE: the ClassWizard will add DDX and DDV calls here\r
39         //}}AFX_DATA_MAP\r
40 }\r
41 \r
42 \r
43 BEGIN_MESSAGE_MAP(CJS_ResponseDlg, CDialog)\r
44         //{{AFX_MSG_MAP(CJS_ResponseDlg)\r
45                 // NOTE: the ClassWizard will add message map macros here\r
46                 ON_BN_CLICKED(ID_JS_OK, OnResOk)\r
47                 ON_BN_CLICKED(ID_JS_CANCEL, OnResCancel)\r
48         //}}AFX_MSG_MAP\r
49 END_MESSAGE_MAP()\r
50 \r
51 /////////////////////////////////////////////////////////////////////////////\r
52 // CJS_ResponseDlg message handlers\r
53 BOOL CJS_ResponseDlg::OnInitDialog()\r
54 {\r
55         CDialog::OnInitDialog();\r
56 \r
57         ::SetWindowTextW(this->GetSafeHwnd(), (LPCWSTR)m_swTitle);\r
58 \r
59         CStatic* pQuestion = (CStatic*)GetDlgItem(IDC_JS_QUESTION);\r
60         ::SetWindowTextW(pQuestion->GetSafeHwnd(), (LPCWSTR)m_swQuestion);\r
61 \r
62         CStatic* pLabel = (CStatic*)GetDlgItem(IDC_JS_ANSWER);\r
63 \r
64         CRect DialogRect;\r
65         CRect LabelRect;\r
66         RECT rect;\r
67         GetWindowRect(&DialogRect);\r
68         pLabel->GetWindowRect(&LabelRect);      \r
69 \r
70         if(m_swLabel == (FPDF_WIDESTRING)L"")\r
71         {       \r
72                 rect.left = DialogRect.left + 20;\r
73                 pLabel->ShowWindow(SW_HIDE);\r
74         }\r
75         else\r
76         {\r
77                 rect.left = LabelRect.right + 1;\r
78                 ::SetWindowTextW(pLabel->GetSafeHwnd(), (LPCWSTR)m_swLabel);\r
79         }\r
80 \r
81         rect.top = LabelRect.top - 3;\r
82         rect.right = DialogRect.right - 20;\r
83         rect.bottom = LabelRect.bottom + 2;\r
84         ScreenToClient(&rect);\r
85         m_pResponseEdit = new CEdit();\r
86 \r
87         if(m_bIsVisible)\r
88                 m_pResponseEdit->Create(ES_AUTOVSCROLL | ES_NOHIDESEL | ES_PASSWORD | WS_BORDER, rect, this, IDC_JS_EDIT);\r
89         else\r
90                 m_pResponseEdit->Create(ES_AUTOVSCROLL | ES_NOHIDESEL | WS_BORDER, rect, this, IDC_JS_EDIT);\r
91         \r
92         ::SetWindowTextW(m_pResponseEdit->GetSafeHwnd(), (LPCWSTR)m_swDefault);\r
93         m_pResponseEdit->ShowWindow(SW_SHOW);\r
94 \r
95         return TRUE;\r
96 }\r
97 \r
98 void CJS_ResponseDlg::OnResOk()\r
99 {\r
100         m_swResponse = (wchar_t*)malloc(sizeof(wchar_t) * 250);\r
101         ::GetWindowTextW(m_pResponseEdit->GetSafeHwnd(), m_swResponse, 250);\r
102 \r
103         if(m_pResponseEdit)\r
104         {\r
105                 m_pResponseEdit->DestroyWindow();\r
106                 delete m_pResponseEdit;\r
107                 m_pResponseEdit = NULL;\r
108         }\r
109         CDialog::OnOK();\r
110 }\r
111 \r
112 void CJS_ResponseDlg::OnResCancel()\r
113 {\r
114         if(m_pResponseEdit)\r
115         {\r
116                 m_pResponseEdit->DestroyWindow();\r
117                 delete m_pResponseEdit;\r
118                 m_pResponseEdit = NULL;\r
119         }\r
120         \r
121         CDialog::OnCancel();\r
122 }\r
123 \r
124 void CJS_ResponseDlg::SetTitle(FPDF_WIDESTRING swTitle)\r
125 {\r
126         m_swTitle = swTitle;\r
127 }\r
128 \r
129 void CJS_ResponseDlg::SetQuestion(FPDF_WIDESTRING swQuestion)\r
130 {\r
131         m_swQuestion = swQuestion;\r
132 }\r
133 \r
134 void CJS_ResponseDlg::SetLabel(FPDF_WIDESTRING swLabel)\r
135 {\r
136         m_swLabel = swLabel;\r
137 }\r
138 \r
139 void CJS_ResponseDlg::SetDefault(FPDF_WIDESTRING swDefault)\r
140 {\r
141         m_swDefault = swDefault;\r
142 }\r
143 \r
144 FPDF_WIDESTRING CJS_ResponseDlg::GetResponse()\r
145 {\r
146         return (FPDF_WIDESTRING)m_swResponse;\r
147 }\r
148 \r
149 void CJS_ResponseDlg::SetIsVisible(FPDF_BOOL bPassword)\r
150 {\r
151         m_bIsVisible = bPassword;\r
152 }\r