~ubuntu-branches/ubuntu/saucy/sflphone/saucy

« back to all changes in this revision

Viewing changes to sflphone-common/libs/pjproject/pjsip-apps/src/pocketpj/PopUpWnd.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-12-24 16:33:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20101224163355-tkvvikqxbrbav6up
Tags: 0.9.11-1
* New upstream release
* Add new build dependencies on libwebkit-dev and libyaml-dev

* Bump Standards-Version up to 3.9.1
* Bump debhelper compatibility to 8
* Patch another typo in the upstream code (lintian notice)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
/////////////////////////////////////////////////////////////////////////////
17
17
// CPopUpWnd
18
18
 
19
 
CPopUpWnd::CPopUpWnd(CPocketPJDlg* pParent)
 
19
CPopUpWnd::CPopUpWnd (CPocketPJDlg* pParent)
20
20
{
21
 
    Create(pParent);
 
21
    Create (pParent);
22
22
}
23
23
 
24
24
CPopUpWnd::~CPopUpWnd()
26
26
    DestroyWindow();
27
27
}
28
28
 
29
 
BOOL CPopUpWnd::Create(CPocketPJDlg* pParent)
 
29
BOOL CPopUpWnd::Create (CPocketPJDlg* pParent)
30
30
{
31
31
    BOOL bSuccess;
32
32
 
33
33
    m_ParentWnd = pParent;
34
34
 
35
35
    // Register window class
36
 
    CString csClassName = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,
37
 
                                              0,
38
 
                                              CBrush(::GetSysColor(COLOR_BTNFACE)));
 
36
    CString csClassName = AfxRegisterWndClass (CS_HREDRAW|CS_VREDRAW,
 
37
                          0,
 
38
                          CBrush (::GetSysColor (COLOR_BTNFACE)));
39
39
 
40
40
    // Create popup window
41
 
    bSuccess = CreateEx(WS_EX_DLGMODALFRAME|WS_EX_TOPMOST, // Extended style
42
 
                        csClassName,                       // Classname
43
 
                        _T("PocketPJ"),                    // Title
44
 
                        WS_POPUP|WS_BORDER|WS_CAPTION,     // style
45
 
                        0,0,                               // position - updated soon.
46
 
                        1,1,                               // Size - updated soon
47
 
                        pParent->GetSafeHwnd(),            // handle to parent
48
 
                        0,                                 // No menu
49
 
                        NULL);    
50
 
    if (!bSuccess) 
51
 
        return FALSE;
52
 
 
53
 
    ShowWindow(SW_HIDE);
 
41
    bSuccess = CreateEx (WS_EX_DLGMODALFRAME|WS_EX_TOPMOST, // Extended style
 
42
                         csClassName,                       // Classname
 
43
                         _T ("PocketPJ"),                   // Title
 
44
                         WS_POPUP|WS_BORDER|WS_CAPTION,     // style
 
45
                         0,0,                               // position - updated soon.
 
46
                         1,1,                              // Size - updated soon
 
47
                         pParent->GetSafeHwnd(),            // handle to parent
 
48
                         0,                                 // No menu
 
49
                         NULL);
 
50
 
 
51
    if (!bSuccess)
 
52
        return FALSE;
 
53
 
 
54
    ShowWindow (SW_HIDE);
54
55
 
55
56
    // Now create the controls
56
 
    CRect TempRect(0,0,10,10);
 
57
    CRect TempRect (0,0,10,10);
57
58
 
58
59
    /* |SS_LEFTNOWORDWRAP */
59
 
    bSuccess = m_Title1.Create(_T("Title1"), WS_CHILD|WS_VISIBLE|SS_NOPREFIX,
60
 
                               TempRect, this, IDC_TITLE1);
61
 
    if (!bSuccess)
62
 
        return FALSE;
63
 
 
64
 
    bSuccess = m_Title2.Create(_T("Title2"), WS_CHILD|WS_VISIBLE|SS_NOPREFIX,
65
 
                               TempRect, this, IDC_TITLE2);
66
 
    if (!bSuccess)
67
 
        return FALSE;
68
 
 
69
 
    bSuccess = m_Title3.Create(_T("Title3"), WS_CHILD|WS_VISIBLE|SS_NOPREFIX,
70
 
                               TempRect, this, IDC_TITLE3);
71
 
    if (!bSuccess)
72
 
        return FALSE;
73
 
 
74
 
    bSuccess = m_Btn1.Create(_T("Button1"), 
75
 
                             WS_CHILD|WS_VISIBLE|WS_TABSTOP| BS_PUSHBUTTON, 
76
 
                             TempRect, this, IDC_BTN1);
77
 
    if (!bSuccess)
78
 
        return FALSE;
79
 
 
80
 
    bSuccess = m_Btn2.Create(_T("Button2"), 
81
 
                             WS_CHILD|WS_VISIBLE|WS_TABSTOP| BS_PUSHBUTTON, 
82
 
                             TempRect, this, IDC_BTN2);
83
 
    if (!bSuccess)
84
 
        return FALSE;
85
 
 
86
 
    CFont *ft1 = new CFont, 
87
 
          *ft2 = new CFont, 
88
 
          *ft3 = new CFont;
 
60
    bSuccess = m_Title1.Create (_T ("Title1"), WS_CHILD|WS_VISIBLE|SS_NOPREFIX,
 
61
                                TempRect, this, IDC_TITLE1);
 
62
 
 
63
    if (!bSuccess)
 
64
        return FALSE;
 
65
 
 
66
    bSuccess = m_Title2.Create (_T ("Title2"), WS_CHILD|WS_VISIBLE|SS_NOPREFIX,
 
67
                                TempRect, this, IDC_TITLE2);
 
68
 
 
69
    if (!bSuccess)
 
70
        return FALSE;
 
71
 
 
72
    bSuccess = m_Title3.Create (_T ("Title3"), WS_CHILD|WS_VISIBLE|SS_NOPREFIX,
 
73
                                TempRect, this, IDC_TITLE3);
 
74
 
 
75
    if (!bSuccess)
 
76
        return FALSE;
 
77
 
 
78
    bSuccess = m_Btn1.Create (_T ("Button1"),
 
79
                              WS_CHILD|WS_VISIBLE|WS_TABSTOP| BS_PUSHBUTTON,
 
80
                              TempRect, this, IDC_BTN1);
 
81
 
 
82
    if (!bSuccess)
 
83
        return FALSE;
 
84
 
 
85
    bSuccess = m_Btn2.Create (_T ("Button2"),
 
86
                              WS_CHILD|WS_VISIBLE|WS_TABSTOP| BS_PUSHBUTTON,
 
87
                              TempRect, this, IDC_BTN2);
 
88
 
 
89
    if (!bSuccess)
 
90
        return FALSE;
 
91
 
 
92
    CFont *ft1 = new CFont,
 
93
    *ft2 = new CFont,
 
94
    *ft3 = new CFont;
89
95
 
90
96
 
91
97
    LOGFONT lf;
92
 
    memset(&lf, 0, sizeof(LOGFONT));
 
98
    memset (&lf, 0, sizeof (LOGFONT));
93
99
    lf.lfHeight = 12;
94
 
    lstrcpy(lf.lfFaceName, _T("Arial"));
95
 
    VERIFY(ft1->CreateFontIndirect(&lf));
96
 
    VERIFY(ft3->CreateFontIndirect(&lf));
 
100
    lstrcpy (lf.lfFaceName, _T ("Arial"));
 
101
    VERIFY (ft1->CreateFontIndirect (&lf));
 
102
    VERIFY (ft3->CreateFontIndirect (&lf));
97
103
 
98
104
    lf.lfHeight = 20;
99
 
    VERIFY(ft2->CreateFontIndirect(&lf));
 
105
    VERIFY (ft2->CreateFontIndirect (&lf));
100
106
 
101
 
    m_Title1.SetFont(ft1, TRUE);
102
 
    m_Title2.SetFont(ft2, TRUE);
103
 
    m_Title3.SetFont(ft3, TRUE);
 
107
    m_Title1.SetFont (ft1, TRUE);
 
108
    m_Title2.SetFont (ft2, TRUE);
 
109
    m_Title3.SetFont (ft3, TRUE);
104
110
 
105
111
 
106
112
    SetWindowSize();
113
119
    return TRUE;
114
120
}
115
121
 
116
 
void CPopUpWnd::SetContent(const CPopUpContent &content)
 
122
void CPopUpWnd::SetContent (const CPopUpContent &content)
117
123
{
118
 
    m_Title1.SetWindowText(content.m_Title1);
119
 
    m_Title2.SetWindowText(content.m_Title2);
120
 
    m_Title3.SetWindowText(content.m_Title3);
 
124
    m_Title1.SetWindowText (content.m_Title1);
 
125
    m_Title2.SetWindowText (content.m_Title2);
 
126
    m_Title3.SetWindowText (content.m_Title3);
121
127
 
122
128
    if (content.m_Btn1 != "") {
123
 
        m_Btn1.SetWindowText(content.m_Btn1);
124
 
        m_Btn1.ShowWindow(SW_SHOW);
 
129
        m_Btn1.SetWindowText (content.m_Btn1);
 
130
        m_Btn1.ShowWindow (SW_SHOW);
125
131
    } else {
126
 
        m_Btn1.ShowWindow(SW_HIDE);
 
132
        m_Btn1.ShowWindow (SW_HIDE);
127
133
    }
128
134
 
129
135
    if (content.m_Btn2 != "") {
130
 
        m_Btn2.SetWindowText(content.m_Btn2);
131
 
        m_Btn2.ShowWindow(SW_SHOW);
 
136
        m_Btn2.SetWindowText (content.m_Btn2);
 
137
        m_Btn2.ShowWindow (SW_SHOW);
132
138
    } else {
133
 
        m_Btn2.ShowWindow(SW_HIDE);
 
139
        m_Btn2.ShowWindow (SW_HIDE);
134
140
    }
135
141
 
136
142
    UpdateWindow();
137
 
    ShowWindow(SW_SHOW);
 
143
    ShowWindow (SW_SHOW);
138
144
}
139
145
 
140
 
void CPopUpWnd::SetWindowSize(int width, int height)
 
146
void CPopUpWnd::SetWindowSize (int width, int height)
141
147
{
142
148
    enum { H1 = 16, H2 = 40, H3 = 16, S = 5, G = 10, BW=60, BH=20, BG=40};
143
149
 
144
 
    CRect rootRect(0, 0, 320, 240);
 
150
    CRect rootRect (0, 0, 320, 240);
145
151
    int Y;
146
152
 
147
 
    MoveWindow((rootRect.Width() - width)/2, (rootRect.Height() - height)/2,
148
 
               width, height);
149
 
 
150
 
    m_Title1.MoveWindow(10, Y=S, width-20, H1);
151
 
    m_Title2.MoveWindow(10, Y+=H1+G, width-20, H2);
152
 
    m_Title3.MoveWindow(10, Y+=H2+G, width-20, H3);
153
 
 
154
 
    m_Btn1.MoveWindow((width-2*BW-BG)/2, Y+=H3+G, BW, BH);
155
 
    m_Btn2.MoveWindow((width-2*BW-BG)/2+BW+BG, Y, BW, BH);
 
153
    MoveWindow ( (rootRect.Width() - width) /2, (rootRect.Height() - height) /2,
 
154
                 width, height);
 
155
 
 
156
    m_Title1.MoveWindow (10, Y=S, width-20, H1);
 
157
    m_Title2.MoveWindow (10, Y+=H1+G, width-20, H2);
 
158
    m_Title3.MoveWindow (10, Y+=H2+G, width-20, H3);
 
159
 
 
160
    m_Btn1.MoveWindow ( (width-2*BW-BG) /2, Y+=H3+G, BW, BH);
 
161
    m_Btn2.MoveWindow ( (width-2*BW-BG) /2+BW+BG, Y, BW, BH);
156
162
}
157
163
 
158
 
void CPopUpWnd::Hide()  
159
 
160
 
    if (!::IsWindow(GetSafeHwnd())) 
 
164
void CPopUpWnd::Hide()
 
165
{
 
166
    if (!::IsWindow (GetSafeHwnd()))
161
167
        return;
162
168
 
163
 
    if (IsWindowVisible())
164
 
    {
165
 
        ShowWindow(SW_HIDE);
166
 
        ModifyStyle(WS_VISIBLE, 0);
 
169
    if (IsWindowVisible()) {
 
170
        ShowWindow (SW_HIDE);
 
171
        ModifyStyle (WS_VISIBLE, 0);
167
172
    }
168
173
}
169
174
 
170
 
void CPopUpWnd::Show()  
171
 
172
 
    if (!::IsWindow(GetSafeHwnd()))
 
175
void CPopUpWnd::Show()
 
176
{
 
177
    if (!::IsWindow (GetSafeHwnd()))
173
178
        return;
174
179
 
175
 
    ModifyStyle(0, WS_VISIBLE);
176
 
    ShowWindow(SW_SHOWNA);
177
 
    RedrawWindow(NULL,NULL,RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
 
180
    ModifyStyle (0, WS_VISIBLE);
 
181
    ShowWindow (SW_SHOWNA);
 
182
    RedrawWindow (NULL,NULL,RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
178
183
}
179
184
 
180
 
BEGIN_MESSAGE_MAP(CPopUpWnd, CWnd)
 
185
BEGIN_MESSAGE_MAP (CPopUpWnd, CWnd)
181
186
    //{{AFX_MSG_MAP(CPopUpWnd)
182
187
    ON_WM_ERASEBKGND()
183
 
        //}}AFX_MSG_MAP
184
 
    ON_BN_CLICKED(IDC_BTN1, OnCancel1)
185
 
    ON_BN_CLICKED(IDC_BTN2, OnCancel2)
 
188
    //}}AFX_MSG_MAP
 
189
    ON_BN_CLICKED (IDC_BTN1, OnCancel1)
 
190
    ON_BN_CLICKED (IDC_BTN2, OnCancel2)
186
191
END_MESSAGE_MAP()
187
192
 
188
193
 
189
194
/////////////////////////////////////////////////////////////////////////////
190
195
// CPopUpWnd message handlers
191
196
 
192
 
BOOL CPopUpWnd::OnEraseBkgnd(CDC* pDC) 
 
197
BOOL CPopUpWnd::OnEraseBkgnd (CDC* pDC)
193
198
{
194
199
    CBrush backBrush;
195
 
    backBrush.CreateSolidBrush(RGB(255,255,255));
196
 
    CBrush* pOldBrush = pDC->SelectObject(&backBrush);
 
200
    backBrush.CreateSolidBrush (RGB (255,255,255));
 
201
    CBrush* pOldBrush = pDC->SelectObject (&backBrush);
197
202
 
198
203
    CRect rect;
199
 
    pDC->GetClipBox(&rect);     // Erase the area needed
200
 
    pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
201
 
    pDC->SelectObject(pOldBrush);
 
204
    pDC->GetClipBox (&rect);    // Erase the area needed
 
205
    pDC->PatBlt (rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
 
206
    pDC->SelectObject (pOldBrush);
202
207
 
203
208
    return TRUE;
204
209
}
205
210
 
206
 
void CPopUpWnd::OnCancel1() 
207
 
{
208
 
    m_ParentWnd->OnPopUpButton(1);
209
 
}
210
 
 
211
 
 
212
 
void CPopUpWnd::OnCancel2() 
213
 
{
214
 
    m_ParentWnd->OnPopUpButton(2);
215
 
}
216
 
 
217
 
 
218
 
BOOL CPopUpWnd::DestroyWindow() 
 
211
void CPopUpWnd::OnCancel1()
 
212
{
 
213
    m_ParentWnd->OnPopUpButton (1);
 
214
}
 
215
 
 
216
 
 
217
void CPopUpWnd::OnCancel2()
 
218
{
 
219
    m_ParentWnd->OnPopUpButton (2);
 
220
}
 
221
 
 
222
 
 
223
BOOL CPopUpWnd::DestroyWindow()
219
224
{
220
225
    return CWnd::DestroyWindow();
221
226
}
223
228
void CPopUpWnd::PeekAndPump()
224
229
{
225
230
    MSG msg;
226
 
    while (::PeekMessage(&msg, NULL,0,0,PM_NOREMOVE)) 
227
 
    {
228
 
        if (!AfxGetApp()->PumpMessage()) 
229
 
        {
230
 
            ::PostQuitMessage(0);
 
231
 
 
232
    while (::PeekMessage (&msg, NULL,0,0,PM_NOREMOVE)) {
 
233
        if (!AfxGetApp()->PumpMessage()) {
 
234
            ::PostQuitMessage (0);
231
235
            return;
232
 
        } 
 
236
        }
233
237
    }
234
238
}
235
239