Module: wine
Branch: master
Commit: 016b7c53dc173389950af2047efd343cfd36666b
URL: http://source.winehq.org/git/wine.git/?a=commit;h=016b7c53dc173389950af2047…
Author: Huw Davies <huw(a)codeweavers.com>
Date: Wed Jun 22 15:22:48 2011 +0100
comdlg32: When changing printers, only preserve the paper/bin settings if the new printer has the original setting available.
---
dlls/comdlg32/printdlg.c | 101 +++++++++++++++++++++++++---------------------
1 files changed, 55 insertions(+), 46 deletions(-)
diff --git a/dlls/comdlg32/printdlg.c b/dlls/comdlg32/printdlg.c
index d692e7d..4d8b0c8 100644
--- a/dlls/comdlg32/printdlg.c
+++ b/dlls/comdlg32/printdlg.c
@@ -616,8 +616,8 @@ static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
int NrOfEntries;
char* Names;
WORD* Words;
- DWORD Sel;
- WORD oldWord = 0;
+ DWORD Sel, old_Sel;
+ WORD oldWord = 0, newWord = 0; /* DMPAPER_ and DMBIN_ start at 1 */
int NamesSize;
int fwCapability_Names;
int fwCapability_Words;
@@ -633,26 +633,14 @@ static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
*/
oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
Sel, 0);
- if (dm) {
- if (nIDComboBox == cmb2)
- dm->u1.s1.dmPaperSize = oldWord;
- else
- dm->u1.s1.dmDefaultSource = oldWord;
- }
- }
- else {
- /* we enter here only when the Print setup dialog is initially
- * opened. In this case the settings are restored from when
- * the dialog was last closed.
- */
- if (dm) {
- if (nIDComboBox == cmb2)
- oldWord = dm->u1.s1.dmPaperSize;
- else
- oldWord = dm->u1.s1.dmDefaultSource;
- }
+ if(oldWord >= DMPAPER_USER) /* DMPAPER_USER == DMBIN_USER */
+ oldWord = 0; /* There's no point in trying to keep custom
+ paper / bin sizes across printers */
}
+ if (dm)
+ newWord = (nIDComboBox == cmb2) ? dm->u1.s1.dmPaperSize : dm->u1.s1.dmDefaultSource;
+
if (nIDComboBox == cmb2) {
NamesSize = 64;
fwCapability_Names = DC_PAPERNAMES;
@@ -695,16 +683,32 @@ static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
Words[i]);
}
- /* Look for old selection - can't do this is previous loop since
- item order will change as more items are added */
+ /* Look for old selection or the new default.
+ Can't do this is previous loop since item order will change as more items are added */
Sel = 0;
+ old_Sel = NrOfEntries;
for (i = 0; i < NrOfEntries; i++) {
if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
oldWord) {
- Sel = i;
+ old_Sel = i;
break;
}
+ if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) == newWord)
+ Sel = i;
+ }
+
+ if(old_Sel < NrOfEntries)
+ {
+ if (dm)
+ {
+ if(nIDComboBox == cmb2)
+ dm->u1.s1.dmPaperSize = oldWord;
+ else
+ dm->u1.s1.dmDefaultSource = oldWord;
+ }
+ Sel = old_Sel;
}
+
SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
HeapFree(GetProcessHeap(),0,Words);
@@ -722,8 +726,8 @@ static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
int NrOfEntries;
WCHAR* Names;
WORD* Words;
- DWORD Sel;
- WORD oldWord = 0;
+ DWORD Sel, old_Sel;
+ WORD oldWord = 0, newWord = 0; /* DMPAPER_ and DMBIN_ start at 1 */
int NamesSize;
int fwCapability_Names;
int fwCapability_Words;
@@ -739,26 +743,15 @@ static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
*/
oldWord = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA,
Sel, 0);
- if (dm) {
- if (nIDComboBox == cmb2)
- dm->u1.s1.dmPaperSize = oldWord;
- else
- dm->u1.s1.dmDefaultSource = oldWord;
- }
- }
- else {
- /* we enter here only when the Print setup dialog is initially
- * opened. In this case the settings are restored from when
- * the dialog was last closed.
- */
- if (dm) {
- if (nIDComboBox == cmb2)
- oldWord = dm->u1.s1.dmPaperSize;
- else
- oldWord = dm->u1.s1.dmDefaultSource;
- }
+
+ if(oldWord >= DMPAPER_USER) /* DMPAPER_USER == DMBIN_USER */
+ oldWord = 0; /* There's no point in trying to keep custom
+ paper / bin sizes across printers */
}
+ if (dm)
+ newWord = (nIDComboBox == cmb2) ? dm->u1.s1.dmPaperSize : dm->u1.s1.dmDefaultSource;
+
if (nIDComboBox == cmb2) {
NamesSize = 64;
fwCapability_Names = DC_PAPERNAMES;
@@ -801,16 +794,32 @@ static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
Words[i]);
}
- /* Look for old selection - can't do this is previous loop since
- item order will change as more items are added */
+ /* Look for old selection or the new default.
+ Can't do this is previous loop since item order will change as more items are added */
Sel = 0;
+ old_Sel = NrOfEntries;
for (i = 0; i < NrOfEntries; i++) {
if(SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
oldWord) {
- Sel = i;
+ old_Sel = i;
break;
}
+ if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) == newWord)
+ Sel = i;
+ }
+
+ if(old_Sel < NrOfEntries)
+ {
+ if (dm)
+ {
+ if(nIDComboBox == cmb2)
+ dm->u1.s1.dmPaperSize = oldWord;
+ else
+ dm->u1.s1.dmDefaultSource = oldWord;
+ }
+ Sel = old_Sel;
}
+
SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
HeapFree(GetProcessHeap(),0,Words);