dsrc isn't necessary for this repo
[client-tools.git] / src / external / 3rd / application / UiBuilder / AddPropertyDialogBox.cpp
blob7c63ca964a295ddf90e382f4b4e7c9eb6c240569
1 #include "FirstUiBuilder.h"
2 #include "AddPropertyDialogBox.h"
4 #include "resource.h"
5 #include "UITypes.h"
7 AddPropertyDialogBox::NarrowStringList gOldPropertyNames;
8 AddPropertyDialogBox::StringList gOldPropertyValues;
9 UINarrowString gNewPropertyName;
10 UIString gNewPropertyValue;
12 bool AddPropertyDialogBox::GetNewProperty( HWND hwndParent, UINarrowString &Name, UIString &Value )
14 if( DialogBox( GetModuleHandle(0), MAKEINTRESOURCE(IDD_ADDPROPERTY), hwndParent, DialogProc ) )
16 Name = gNewPropertyName;
17 Value = gNewPropertyValue;
18 return true;
20 else
22 return false;
26 BOOL CALLBACK AddPropertyDialogBox::DialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
28 UI_UNREF (lParam);
30 switch( uMsg )
32 case WM_INITDIALOG:
35 for( NarrowStringList::const_iterator i = gOldPropertyNames.begin(); i != gOldPropertyNames.end(); ++i )
36 SendDlgItemMessage( hwndDlg, IDC_PROPERTYNAME, CB_ADDSTRING, 0, (LPARAM)i->c_str() );
40 for( StringList::const_iterator i = gOldPropertyValues.begin(); i != gOldPropertyValues.end(); ++i )
41 SendDlgItemMessage( hwndDlg, IDC_PROPERTYVALUE, CB_ADDSTRING, 0, (LPARAM)i->c_str() );
43 return TRUE;
45 case WM_CLOSE:
46 // Equivalent to pressing cancel
47 EndDialog( hwndDlg, 0 );
48 return 0;
50 case WM_COMMAND:
51 if( LOWORD( wParam ) == IDOK )
53 long len = SendDlgItemMessage( hwndDlg, IDC_PROPERTYNAME, WM_GETTEXTLENGTH, 0, 0 );
54 char *TextBuffer = new char[len + 1];
55 GetDlgItemText( hwndDlg, IDC_PROPERTYNAME, TextBuffer, len + 1 );
56 gNewPropertyName = TextBuffer;
57 delete TextBuffer;
59 len = SendDlgItemMessage( hwndDlg, IDC_PROPERTYVALUE, WM_GETTEXTLENGTH, 0, 0 );
60 TextBuffer = new char[len + 1];
61 GetDlgItemText( hwndDlg, IDC_PROPERTYVALUE, TextBuffer, len + 1 );
62 gNewPropertyValue = UIUnicode::narrowToWide (TextBuffer);
63 delete TextBuffer;
65 if( gNewPropertyName.empty() )
66 EndDialog( hwndDlg, 0 );
67 else
69 gOldPropertyNames.push_front( gNewPropertyName );
70 gOldPropertyValues.push_front( gNewPropertyValue );
71 EndDialog( hwndDlg, 1 );
74 else if( LOWORD( wParam ) == IDCANCEL )
75 EndDialog( hwndDlg, 0 );
77 return 0;
79 default:
80 return 0;