1 //////////////////////////////////////////////////////////////////////////
3 #include "FirstUiBuilder.h"
4 #include "DiffDialogBox.h"
5 #include "UIBaseObject.h"
6 #include "UILowerString.h"
8 //////////////////////////////////////////////////////////////////////////
15 namespace DiffDialogBoxNamespace
17 std::string s_diffStringBuffer
;
20 using namespace DiffDialogBoxNamespace
;
22 //////////////////////////////////////////////////////////////////////////
24 bool DiffDialogBox::DiffObjects(HWND hwndParent
, UIBaseObject
const & lhs
, UIBaseObject
const & rhs
)
26 // Do the Diff inline.
27 s_diffStringBuffer
= lhs
.GetFullPath();
28 s_diffStringBuffer
+= " and ";
29 s_diffStringBuffer
+= rhs
.GetFullPath();
31 // Get properties on the left.
32 UIBaseObject::UIPropertyNameVector allProperties
;
33 lhs
.GetPropertyNames(allProperties
, false);
35 // Get properties on the right.
36 rhs
.GetPropertyNames(allProperties
, false);
39 std::sort(allProperties
.begin(), allProperties
.end());
40 allProperties
.erase(std::unique(allProperties
.begin(), allProperties
.end()), allProperties
.end());
43 // Diff if both objects have it and add to diff text.
44 bool hasDifferences
= false;
45 for (UIBaseObject::UIPropertyNameVector::const_iterator itPropertyName
= allProperties
.begin(); itPropertyName
!= allProperties
.end(); ++itPropertyName
)
49 UILowerString
const & property
= *itPropertyName
;
51 if (property
== UIBaseObject::PropertyName::Name
)
56 lhs
.GetProperty(property
, lhsValue
);
57 rhs
.GetProperty(property
, rhsValue
);
59 UILowerString
lhsLowerValue(UIUnicode::wideToNarrow(lhsValue
));
60 UILowerString
rhsLowerValue(UIUnicode::wideToNarrow(rhsValue
));
63 if (lhsLowerValue
!= rhsLowerValue
)
67 s_diffStringBuffer
+= allProperties
.size() == 1 ? " has the following difference:\r\n\r\n" :
68 " have the following differences:\r\n\r\n";
69 hasDifferences
= true;
72 s_diffStringBuffer
+= "[";
73 s_diffStringBuffer
+= property
.c_str();
74 s_diffStringBuffer
+= "]\t";
75 s_diffStringBuffer
+= lhsLowerValue
.empty() ? "[EMPTY]" : lhsLowerValue
.c_str();
76 s_diffStringBuffer
+= " <=> ";
77 s_diffStringBuffer
+= rhsLowerValue
.empty() ? "[EMPTY]" : rhsLowerValue
.c_str();
78 s_diffStringBuffer
+= "\r\n";
84 s_diffStringBuffer
+= " are not different.";
88 if (DialogBox(GetModuleHandle(0), MAKEINTRESOURCE(IDD_DIFF_WINDOW
), hwndParent
, DialogProc
))
98 //////////////////////////////////////////////////////////////////////////
100 BOOL CALLBACK
DiffDialogBox::DialogProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
108 const int height
= HIWORD(GetDialogBaseUnits());
109 HWND hControl
= GetDlgItem(hwndDlg
, IDC_VALUE
);
111 HFONT fixedFont
= CreateFont(height
* 3 / 4, 0,
121 SendMessage(hControl
, WM_SETFONT
, reinterpret_cast<WPARAM
>(fixedFont
), 1);
123 SetDlgItemText(hwndDlg
, IDC_DIFF_EDIT
, s_diffStringBuffer
.c_str());
128 // Equivalent to pressing cancel
129 EndDialog(hwndDlg
, 0);
133 if(LOWORD(wParam
) == IDOK
)
135 EndDialog(hwndDlg
, 1);
137 else if(LOWORD(wParam
) == IDCANCEL
)
139 EndDialog(hwndDlg
, 0);