0031939: Coding - correction of spelling errors in comments [part 2]
[occt.git] / samples / mfc / standard / 10_Convert / src / WNT / ResultDialog.cpp
1 // ResultDialog.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "OCCDemo.h"
6 #include "ResultDialog.h"
7 #include "MainFrm.h"
8 #include "OCCDemoDoc.h"
9
10 #ifdef _DEBUG
11 #define new DEBUG_NEW
12 #undef THIS_FILE
13 static char THIS_FILE[] = __FILE__;
14 #endif
15
16 // minimum distance between buttons, button and dialog border
17 #define d 5
18
19 /////////////////////////////////////////////////////////////////////////////
20 // CResultDialog dialog
21
22
23 CResultDialog::CResultDialog(CWnd* pParent /*=NULL*/)
24         : CDialog(CResultDialog::IDD, pParent)
25 {
26         //{{AFX_DATA_INIT(CResultDialog)
27                 // NOTE: the ClassWizard will add member initialization here
28         //}}AFX_DATA_INIT
29 }
30
31 void CResultDialog::Empty()
32 {
33   CRichEditCtrl *pEd = (CRichEditCtrl *) GetDlgItem (IDC_RICHEDIT_ResultDialog);
34   pEd->Clear();
35 }
36
37 void CResultDialog::SetText(LPCSTR aText)
38 {
39   CRichEditCtrl *pEd = (CRichEditCtrl *) GetDlgItem (IDC_RICHEDIT_ResultDialog);
40         CString aCStr(aText);
41   pEd->SetWindowText(aCStr);
42 }
43
44 void CResultDialog::SetTitle(LPCSTR aTitle)
45 {
46   CString aCStr(aTitle);
47   SetWindowText(aCStr);
48 }
49
50 void CResultDialog::DoDataExchange(CDataExchange* pDX)
51 {
52         CDialog::DoDataExchange(pDX);
53         //{{AFX_DATA_MAP(CResultDialog)
54                 // NOTE: the ClassWizard will add DDX and DDV calls here
55         //}}AFX_DATA_MAP
56 }
57
58
59 BEGIN_MESSAGE_MAP(CResultDialog, CDialog)
60         //{{AFX_MSG_MAP(CResultDialog)
61         ON_BN_CLICKED(IDC_CopySelectionToClipboard, OnCopySelectionToClipboard)
62         ON_BN_CLICKED(IDC_CopyAllToClipboard, OnCopyAllToClipboard)
63         ON_WM_SIZE()
64         //}}AFX_MSG_MAP
65 END_MESSAGE_MAP()
66
67 /////////////////////////////////////////////////////////////////////////////
68 // CResultDialog message handlers
69
70 void CResultDialog::OnCopySelectionToClipboard() 
71 {
72         CRichEditCtrl *pEd = (CRichEditCtrl *) GetDlgItem (IDC_RICHEDIT_ResultDialog);
73         pEd->Copy( );
74 }
75
76 void CResultDialog::OnCopyAllToClipboard() 
77 {
78   CRichEditCtrl *pEd = (CRichEditCtrl *) GetDlgItem (IDC_RICHEDIT_ResultDialog);
79   long nStartChar, nEndChar;
80   pEd->GetSel (nStartChar, nEndChar);
81   pEd->SetSel (0, -1);
82   pEd->Copy();
83   pEd->SetSel (nStartChar, nEndChar);
84 }
85
86 void CResultDialog::OnCancel() 
87 {
88   CMainFrame* cFrame = (CMainFrame*) AfxGetApp()->GetMainWnd();
89   COCCDemoDoc* aDoc = (COCCDemoDoc*) cFrame->GetActiveDocument();
90   aDoc->IsShowResult() = FALSE;
91         
92         CDialog::OnCancel();
93 }
94
95 void CResultDialog::Initialize()
96 {
97   // Set Fixed Width Font for rich edit control
98   CRichEditCtrl *pEd = (CRichEditCtrl *) GetDlgItem (IDC_RICHEDIT_ResultDialog);
99   CFont aFixedWidthFont;
100   VERIFY(aFixedWidthFont.CreateFont(   
101     15,                        // nHeight
102     5,                         // nWidth
103     0,                         // nEscapement
104     0,                         // nOrientation
105     FW_NORMAL,                 // nWeight   
106     FALSE,                     // bItalic
107     FALSE,                     // bUnderline
108     0,                         // cStrikeOut
109     ANSI_CHARSET,              // nCharSet
110     OUT_DEFAULT_PRECIS,        // nOutPrecision
111     CLIP_DEFAULT_PRECIS,       // nClipPrecision
112     DEFAULT_QUALITY,           // nQuality
113     FF_MODERN,                 // Fix width fonts are FF_MODERN
114     L"Courier New"));          // lpszFacename
115   pEd->SetFont(&aFixedWidthFont, false);
116
117   // save button's width and height, so they are calculated only once
118   RECT rect;
119   CWnd *pBCopy = (CWnd *) GetDlgItem (IDC_CopySelectionToClipboard);
120   pBCopy->GetWindowRect(&rect);
121   bw = rect.right - rect.left; // a button's width (they are all equal)
122   bh = rect.bottom - rect.top; // a button's height
123 }
124
125
126 // OnSize is a message handler of WM_SIZE message,
127 // it is reimplemented in order to reposition the buttons
128 // (keep them always in the bottom part of the dialog)
129 // and resize the rich edit controls as user resized THIS dialog.
130 void CResultDialog::OnSize(UINT nType, int cx, int cy) 
131
132   // call the base class handler
133   CDialog::OnSize(nType, cx, cy);
134   
135   //resizes internal GUI controls (rich edit control and 3 buttons)
136   //according to given values of this dialog width (cx) and height (cy).
137   //the method is called from OnSize message handler and 
138   //from InitInstance of OCCDemo to do initial resize
139   CWnd *pEd = (CWnd *) GetDlgItem (IDC_RICHEDIT_ResultDialog);
140   CWnd *pBCopy = (CWnd *) GetDlgItem (IDC_CopySelectionToClipboard);
141   CWnd *pBCopyAll = (CWnd *) GetDlgItem (IDC_CopyAllToClipboard);
142   CWnd *pBClose = (CWnd *) GetDlgItem (IDCANCEL);
143
144   if (pEd != NULL) // it is NULL when dialog is being created and OnSize is called
145   {
146     int butY = cy-bh-d; // y coordinate of buttons' top left corner
147
148     pEd->SetWindowPos(&wndTop, 0, 0, cx, butY-4*d, SWP_NOMOVE);
149     pBCopy->SetWindowPos(&wndTop, d, butY, 0, 0, SWP_NOSIZE); 
150     pBCopyAll->SetWindowPos(&wndTop, d+bw+d, butY, 0, 0, SWP_NOSIZE);
151     pBClose->SetWindowPos(&wndTop, cx-bw-d, butY, 0, 0, SWP_NOSIZE);
152   }
153
154   RedrawWindow();
155 }
156
157 LRESULT CResultDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
158 {
159   if (message != WM_SIZING)
160     return CDialog::WindowProc(message, wParam, lParam);
161
162   LPRECT pRect = (LPRECT) lParam;
163   int cx = pRect->right - pRect->left;
164   int cy = pRect->bottom - pRect->top;
165
166   int minCx = 3*bw+5*d;
167   int minCy = 2*d+bh+200;
168
169   if (cx < minCx || cy < minCy)
170   {
171     switch (wParam)
172     {
173     case WMSZ_BOTTOM:
174       pRect->bottom = pRect->top + minCy;
175       break;
176     case WMSZ_TOP:
177       pRect->top = pRect->bottom - minCy;
178       break;
179     case WMSZ_LEFT:
180       pRect->left = pRect->right - minCx;
181       break;
182     case WMSZ_RIGHT:
183       pRect->right = pRect->left + minCx;
184       break;
185     case WMSZ_TOPLEFT:
186       if (cx < minCx) pRect->left = pRect->right - minCx;
187       if (cy < minCy) pRect->top = pRect->bottom - minCy;
188       break;
189     case WMSZ_BOTTOMRIGHT:
190       if (cx < minCx) pRect->right = pRect->left + minCx;
191       if (cy < minCy) pRect->bottom = pRect->top + minCy;
192       break;
193     case WMSZ_TOPRIGHT:
194       if (cx < minCx) pRect->right = pRect->left + minCx;
195       if (cy < minCy) pRect->top = pRect->bottom - minCy;
196       break;
197     case WMSZ_BOTTOMLEFT:
198       if (cx < minCx) pRect->left = pRect->right - minCx;
199       if (cy < minCy) pRect->bottom = pRect->top + minCy;
200       break;
201     }
202   }
203
204   return CDialog::WindowProc(message, wParam, lParam);
205 }
206