1 // ResultDialog.cpp : implementation file
6 #include "ResultDialog.h"
8 #include "OCCDemoDoc.h"
13 static char THIS_FILE[] = __FILE__;
16 // minimum distance between buttons, button and dialog border
19 /////////////////////////////////////////////////////////////////////////////
20 // CResultDialog dialog
23 CResultDialog::CResultDialog(CWnd* pParent /*=NULL*/)
24 : CDialog(CResultDialog::IDD, pParent)
26 //{{AFX_DATA_INIT(CResultDialog)
27 // NOTE: the ClassWizard will add member initialization here
31 void CResultDialog::Empty()
33 CRichEditCtrl *pEd = (CRichEditCtrl *) GetDlgItem (IDC_RICHEDIT_ResultDialog);
37 void CResultDialog::SetText(LPCSTR aText)
39 CRichEditCtrl *pEd = (CRichEditCtrl *) GetDlgItem (IDC_RICHEDIT_ResultDialog);
41 pEd->SetWindowText(aCStr);
44 void CResultDialog::SetTitle(LPCSTR aTitle)
46 CString aCStr(aTitle);
50 void CResultDialog::DoDataExchange(CDataExchange* pDX)
52 CDialog::DoDataExchange(pDX);
53 //{{AFX_DATA_MAP(CResultDialog)
54 // NOTE: the ClassWizard will add DDX and DDV calls here
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)
67 /////////////////////////////////////////////////////////////////////////////
68 // CResultDialog message handlers
70 void CResultDialog::OnCopySelectionToClipboard()
72 CRichEditCtrl *pEd = (CRichEditCtrl *) GetDlgItem (IDC_RICHEDIT_ResultDialog);
76 void CResultDialog::OnCopyAllToClipboard()
78 CRichEditCtrl *pEd = (CRichEditCtrl *) GetDlgItem (IDC_RICHEDIT_ResultDialog);
79 long nStartChar, nEndChar;
80 pEd->GetSel (nStartChar, nEndChar);
83 pEd->SetSel (nStartChar, nEndChar);
86 void CResultDialog::OnCancel()
88 CMainFrame* cFrame = (CMainFrame*) AfxGetApp()->GetMainWnd();
89 COCCDemoDoc* aDoc = (COCCDemoDoc*) cFrame->GetActiveDocument();
90 aDoc->IsShowResult() = FALSE;
95 void CResultDialog::Initialize()
97 // Set Fixed Width Font for rich edit control
98 CRichEditCtrl *pEd = (CRichEditCtrl *) GetDlgItem (IDC_RICHEDIT_ResultDialog);
99 CFont aFixedWidthFont;
100 VERIFY(aFixedWidthFont.CreateFont(
105 FW_NORMAL, // nWeight
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);
117 // save button's width and height, so they are calculated only once
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
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)
132 // call the base class handler
133 CDialog::OnSize(nType, cx, cy);
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);
144 if (pEd != NULL) // it is NULL when dialog is being created and OnSize is called
146 int butY = cy-bh-d; // y coordinate of buttons' top left corner
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);
157 LRESULT CResultDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
159 if (message != WM_SIZING)
160 return CDialog::WindowProc(message, wParam, lParam);
162 LPRECT pRect = (LPRECT) lParam;
163 int cx = pRect->right - pRect->left;
164 int cy = pRect->bottom - pRect->top;
166 int minCx = 3*bw+5*d;
167 int minCy = 2*d+bh+200;
169 if (cx < minCx || cy < minCy)
174 pRect->bottom = pRect->top + minCy;
177 pRect->top = pRect->bottom - minCy;
180 pRect->left = pRect->right - minCx;
183 pRect->right = pRect->left + minCx;
186 if (cx < minCx) pRect->left = pRect->right - minCx;
187 if (cy < minCy) pRect->top = pRect->bottom - minCy;
189 case WMSZ_BOTTOMRIGHT:
190 if (cx < minCx) pRect->right = pRect->left + minCx;
191 if (cy < minCy) pRect->bottom = pRect->top + minCy;
194 if (cx < minCx) pRect->right = pRect->left + minCx;
195 if (cy < minCy) pRect->top = pRect->bottom - minCy;
197 case WMSZ_BOTTOMLEFT:
198 if (cx < minCx) pRect->left = pRect->right - minCx;
199 if (cy < minCy) pRect->bottom = pRect->top + minCy;
204 return CDialog::WindowProc(message, wParam, lParam);