00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "precomp.h"
00028 #include "globals.h"
00029 #include "CCLicensePropPage.h"
00030
00031 #include "CCLicenseWizard.h"
00032
00033 #include "PngImage.h"
00034 #include "CCPrintLicenseInfo.h"
00035 #include "CCLicenseLocationDlg.h"
00036
00043 BOOL CCLicensePropPage::PageProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
00044 {
00045
00046 switch (uMsg)
00047 {
00048 case WM_INITDIALOG:
00049
00050 {
00051
00052 for (int i=0;i<LLNone;i++)
00053 {
00054 AddDlgComboString(IDC_LOCATION, i + IDS_LICENSELOCATION_TOP, i);
00055 AddDlgComboString(IDC_LOCATION_OTHER, i + IDS_LICENSELOCATION_TOP, i);
00056 }
00057 }
00058
00059 InitControls();
00060
00061
00062 SetFocus(GetDlgItem(IDC_LOCATION));
00063 return FALSE;
00064
00065 case WM_COMMAND:
00066 switch(HIWORD(wParam))
00067 {
00068 case BN_CLICKED:
00069
00070 switch(LOWORD(wParam))
00071 {
00072 case IDC_SELECT_LICENSE:
00073
00074 {
00075
00076 LicenseInfoLoader info(m_license);
00077 CCLicenseWizard wiz;
00078 if (wiz.DoModal(m_hDlg, m_pHelper, &info))
00079 {
00080
00081 if (!info.LoadLicenseData(m_hDlg))
00082 break;
00083
00084
00085 m_license = info;
00086 UpdateControls();
00087 SetChanged();
00088 }
00089 }
00090 break;
00091 case IDC_LICENSE_PROPERTIES:
00092
00093 m_bSetProperties = GetDlgItemCheck(IDC_LICENSE_PROPERTIES);
00094 SetChanged();
00095 break;
00096 case IDC_STAMP:
00097
00098 if (GetDlgItemCheck(IDC_STAMP))
00099 {
00100
00101 LONG_PTR nData = GetDlgComboSelData(IDC_LOCATION);
00102 if (nData == -1)
00103 m_location.eFirstPage = LLBottom;
00104 else
00105 m_location.eFirstPage = (LicenseLocation)nData;
00106 }
00107 else
00108
00109 m_location.eFirstPage = LLNone;
00110
00111 UpdateLicenseLocationControls();
00112 SetChanged();
00113 break;
00114 case IDC_LOCATION:
00115
00116 m_location.eFirstPage = (LicenseLocation)GetDlgComboSelData(IDC_LOCATION);
00117
00118 UpdateLicenseLocationControls();
00119 SetChanged();
00120 break;
00121 case IDC_STAMP_ALL:
00122
00123 if (GetDlgItemCheck(IDC_STAMP_ALL))
00124 {
00125
00126 int nSel = GetCheckedRadioBtn(IDC_LOCATION_SAME, IDC_LOCATION_DIFFERENT);
00127 if (nSel != 1)
00128 m_location.eOtherPages = LLOther;
00129 else
00130 {
00131 LONG_PTR nData = GetDlgComboSelData(IDC_LOCATION_OTHER);
00132 if (nData == -1)
00133 m_location.eOtherPages = LLBottom;
00134 else
00135 m_location.eOtherPages = (LicenseLocation)nData;
00136 }
00137 }
00138 else
00139 m_location.eOtherPages = LLNone;
00140
00141 UpdateLicenseLocationControls();
00142 SetChanged();
00143 break;
00144 case IDC_LOCATION_SAME:
00145 case IDC_LOCATION_DIFFERENT:
00146
00147 if (GetCheckedRadioBtn(IDC_LOCATION_SAME, IDC_LOCATION_DIFFERENT) == 1)
00148 {
00149 LONG_PTR nData = GetDlgComboSelData(IDC_LOCATION_OTHER);
00150 if (nData == -1)
00151 m_location.eOtherPages = LLBottom;
00152 else
00153 m_location.eOtherPages = (LicenseLocation)nData;
00154 }
00155 else
00156 {
00157 m_location.eOtherPages = LLOther;
00158 }
00159
00160 UpdateLicenseLocationControls();
00161 SetChanged();
00162 break;
00163 case IDC_LOCATION_USER:
00164 case IDC_LOCATION_OTHER_USER:
00165 {
00166
00167 SIZE szLicense = GetLicenseSize();
00168 int nMulti = m_pPublicDM->dmPrintQuality > 0 ? m_pPublicDM->dmPrintQuality / 72 : 1;
00169 szLicense.cx /= (nMulti/4);
00170 szLicense.cy /= (nMulti/4);
00171 POINT ptLocation = m_location.LocationForPage(LOWORD(wParam) == IDC_LOCATION_USER, GetPageSize(), szLicense);
00172
00173
00174 RECT rect;
00175 ::SetRect(&rect, ptLocation.x, ptLocation.y, ptLocation.x + szLicense.cx, ptLocation.y + szLicense.cy);
00176
00177 CCLicenseLocationDlg dlg(GetPageSize(), rect);
00178 if (dlg.DoModal(m_hDlg) == IDOK)
00179 {
00180
00181 if (LOWORD(wParam) == IDC_LOCATION_USER)
00182 {
00183 m_location.ptFirstPage = dlg.GetLocation();
00184 }
00185 else
00186 {
00187 m_location.ptOtherPages = dlg.GetLocation();
00188 }
00189 SetChanged();
00190 }
00191 }
00192 break;
00193 }
00194 break;
00195
00196 case CBN_SELCHANGE:
00197
00198 switch (LOWORD(wParam))
00199 {
00200 case IDC_LOCATION:
00201
00202
00203
00204 m_location.eFirstPage = (LicenseLocation)GetDlgComboSelData(IDC_LOCATION);
00205
00206 UpdateLicenseLocationControls();
00207 SetChanged();
00208 break;
00209 case IDC_LOCATION_OTHER:
00210
00211
00212
00213 m_location.eOtherPages = (LicenseLocation)GetDlgComboSelData(IDC_LOCATION_OTHER);
00214
00215 UpdateLicenseLocationControls();
00216 SetChanged();
00217 break;
00218 }
00219 break;
00220
00221 default:
00222
00223 return FALSE;
00224 }
00225
00226 return TRUE;
00227
00228 case WM_NOTIFY:
00229 {
00230
00231 switch (((LPNMHDR)lParam)->code)
00232 {
00233 case PSN_SETACTIVE:
00234
00235 InitControls();
00236 break;
00237
00238 case PSN_KILLACTIVE:
00239
00240 m_pDevMode->location = m_location;
00241 m_pDevMode->info = m_license;
00242 m_pDevMode->bSetProperties = m_bSetProperties;
00243 return TRUE;
00244
00245 case PSN_APPLY:
00246
00247 m_pDevMode->location = m_location;
00248 m_pDevMode->info = m_license;
00249 m_pDevMode->bSetProperties = m_bSetProperties;
00250
00251 (*m_pfnComPropSheet)(m_hComPropSheet, CPSFUNC_SET_RESULT, (LPARAM)m_hPage, CPSUI_OK);
00252 return TRUE;
00253
00254 case PSN_RESET:
00255
00256 InitControls();
00257 break;
00258 }
00259 }
00260 break;
00261 }
00262
00263
00264 return FALSE;
00265 }
00266
00270 void CCLicensePropPage::UpdateLicenseControls()
00271 {
00272
00273 SetDlgItemText(IDC_LICENSE, m_license.GetLicenseName().c_str());
00274
00275 if (m_hBmp != NULL)
00276 {
00277 DeleteObject(m_hBmp);
00278 m_hBmp = NULL;
00279 }
00280
00281
00282 UINT uID = m_license.GetLicenseImageID();
00283 if (uID != 0)
00284 {
00285
00286 PngImage png;
00287 if (png.LoadFromResource(uID, true, ghInstance))
00288 {
00289 HDC hDC = ::GetDC(GetDlgItem(IDC_LICENSE_IMAGE));
00290 m_hBmp = png.ToBitmap(hDC);
00291 ::ReleaseDC(GetDlgItem(IDC_LICENSE_IMAGE), hDC);
00292 }
00293 }
00294
00295
00296 ::SendMessage(GetDlgItem(IDC_LICENSE_IMAGE), STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)m_hBmp);
00297 }
00298
00302 void CCLicensePropPage::UpdateLicenseLocationControls()
00303 {
00304 if ((m_license.m_eLicense == LicenseInfo::LTNone) || (m_license.m_eLicense == LicenseInfo::LTUnknown))
00305 {
00306
00307 EnableDlgItem(IDC_LICENSE_PROPERTIES, FALSE);
00308 EnableDlgItem(IDC_STAMP, FALSE);
00309 EnableDlgItem(IDC_LOCATION, FALSE);
00310 EnableDlgItem(IDC_STAMP_ALL, FALSE);
00311 EnableDlgItem(IDC_LOCATION_SAME, FALSE);
00312 EnableDlgItem(IDC_LOCATION_DIFFERENT, FALSE);
00313 EnableDlgItem(IDC_LOCATION_OTHER, FALSE);
00314 return;
00315 }
00316
00317
00318 SetDlgItemCheck(IDC_LICENSE_PROPERTIES, m_bSetProperties);
00319 EnableDlgItem(IDC_LICENSE_PROPERTIES, TRUE);
00320
00321
00322 BOOL bStamp = (m_location.eFirstPage != LLNone), bAllPages = FALSE, bDifferentLocation = FALSE;
00323 SetDlgItemCheck(IDC_STAMP, bStamp);
00324 EnableDlgItem(IDC_STAMP, TRUE);
00325
00326 if (bStamp)
00327 {
00328
00329 SetDlgComboSel(IDC_LOCATION, m_location.eFirstPage);
00330 bAllPages = (m_location.eOtherPages != LLNone);
00331 SetDlgItemCheck(IDC_STAMP_ALL, bAllPages);
00332 if (bAllPages)
00333 {
00334
00335 bDifferentLocation = (m_location.eOtherPages != LLOther);
00336 SetDlgItemCheck(bDifferentLocation ? IDC_LOCATION_DIFFERENT : IDC_LOCATION_SAME, TRUE);
00337 if (bDifferentLocation)
00338 SetDlgComboSel(IDC_LOCATION_OTHER, (int)m_location.eOtherPages);
00339
00340 }
00341 }
00342
00343
00344 EnableDlgItem(IDC_LOCATION, bStamp);
00345 EnableDlgItem(IDC_LOCATION_USER, bStamp && (GetDlgComboSel(IDC_LOCATION) == LLUserDefined));
00346 EnableDlgItem(IDC_STAMP_ALL, bStamp);
00347 EnableDlgItem(IDC_LOCATION_SAME, bStamp && bAllPages);
00348 EnableDlgItem(IDC_LOCATION_DIFFERENT, bStamp && bAllPages);
00349 EnableDlgItem(IDC_LOCATION_OTHER, bStamp && bAllPages && bDifferentLocation);
00350 EnableDlgItem(IDC_LOCATION_OTHER_USER, bStamp && bAllPages && bDifferentLocation && (GetDlgComboSel(IDC_LOCATION_OTHER) == LLUserDefined));
00351 }
00352
00356 void CCLicensePropPage::InitControls()
00357 {
00358
00359 ::SetWindowLong(GetDlgItem(IDC_LICENSE_IMAGE), GWL_STYLE, (::GetWindowLong(GetDlgItem(IDC_LICENSE_IMAGE), GWL_STYLE)&~SS_TYPEMASK)|SS_BITMAP);
00360
00361
00362 m_license = m_pDevMode->info;
00363 m_location = m_pDevMode->location;
00364 m_bSetProperties = m_pDevMode->bSetProperties;
00365
00366
00367 UpdateControls();
00368 }
00369
00373 SIZE CCLicensePropPage::GetPageSize()
00374 {
00375 SIZE szPage;
00376
00377
00378 if (m_pPublicDM->dmOrientation == DMORIENT_PORTRAIT)
00379 {
00380
00381 szPage.cx = m_pPublicDM->dmPaperWidth;
00382 szPage.cy = m_pPublicDM->dmPaperLength;
00383 }
00384 else
00385 {
00386
00387 szPage.cx = m_pPublicDM->dmPaperLength;
00388 szPage.cy = m_pPublicDM->dmPaperWidth;
00389 }
00390 return szPage;
00391 }
00392
00396 SIZE CCLicensePropPage::GetLicenseSize()
00397 {
00398
00399 int nMulti = m_pPublicDM->dmPrintQuality > 0 ? m_pPublicDM->dmPrintQuality / 72 : 1;
00400 SIZE szLicenseSize;
00401
00402
00403 szLicenseSize.cx = 88 * nMulti;
00404 szLicenseSize.cy = 31 * nMulti;
00405
00406
00407 return szLicenseSize;
00408 }