dsrc isn't necessary for this repo
[client-tools.git] / src / external / 3rd / application / UiBuilder / SelectionSettings.cpp
blob0de22b94461f5fa6a9739172da61cea6c656e85a
1 #include "FirstUiBuilder.h"
3 #include "resource.h"
4 #include "uitypes.h"
6 #include <commctrl.h>
8 static HBRUSH gFillColorBrush = 0;
9 static HBRUSH gEdgeColorBrush = 0;
11 static UIColor gCurrentEdgeColor;
12 static UIColor gCurrentFillColor;
14 extern bool gDrawHighlightRect;
15 extern UIColor gHighlightOutlineColor;
16 extern UIColor gHighlightFillColor;
18 static void LoadData( HWND hwndDlg )
20 if( gDrawHighlightRect )
21 CheckDlgButton( hwndDlg, IDC_DRAWHIGHLIGHT, BST_CHECKED );
22 else
23 CheckDlgButton( hwndDlg, IDC_DRAWHIGHLIGHT, BST_UNCHECKED );
25 SendDlgItemMessage( hwndDlg, IDC_EDGEOPACITY_SLIDER, TBM_SETRANGE, FALSE, MAKELONG( 0, 255 ) );
26 SendDlgItemMessage( hwndDlg, IDC_EDGEOPACITY_SLIDER, TBM_SETPOS, TRUE, gHighlightOutlineColor.a );
28 SendDlgItemMessage( hwndDlg, IDC_FILLOPACITY_SLIDER, TBM_SETRANGE, FALSE, MAKELONG( 0, 255 ) );
29 SendDlgItemMessage( hwndDlg, IDC_FILLOPACITY_SLIDER, TBM_SETPOS, TRUE, gHighlightFillColor.a );
31 gCurrentEdgeColor = gHighlightOutlineColor;
32 gCurrentFillColor = gHighlightFillColor;
35 static void SaveData( HWND hwndDlg )
37 gHighlightOutlineColor = gCurrentEdgeColor;
38 gHighlightOutlineColor.a = (unsigned char)SendDlgItemMessage( hwndDlg, IDC_EDGEOPACITY_SLIDER, TBM_GETPOS, 0, 0 );
39 gHighlightFillColor = gCurrentFillColor;
40 gHighlightFillColor.a = (unsigned char)SendDlgItemMessage( hwndDlg, IDC_FILLOPACITY_SLIDER, TBM_GETPOS, 0, 0 );
41 gDrawHighlightRect = IsDlgButtonChecked( hwndDlg, IDC_DRAWHIGHLIGHT ) != 0;
44 static void ChangeEdgeColor( HWND hwndDlg )
46 CHOOSECOLOR cc = {sizeof(cc)};
47 COLORREF sc[16];
49 ZeroMemory( sc, sizeof( sc ) );
51 cc.hwndOwner = hwndDlg;
52 cc.rgbResult = RGB( gCurrentEdgeColor.r, gCurrentEdgeColor.g, gCurrentEdgeColor.b );
53 cc.Flags = CC_RGBINIT;
54 cc.lpCustColors = sc;
56 if( ChooseColor( &cc ) )
58 gCurrentEdgeColor.r = GetRValue( cc.rgbResult );
59 gCurrentEdgeColor.g = GetGValue( cc.rgbResult );
60 gCurrentEdgeColor.b = GetBValue( cc.rgbResult );
64 static void ChangeFillColor( HWND hwndDlg )
66 CHOOSECOLOR cc = {sizeof(cc)};
67 COLORREF sc[16];
69 ZeroMemory( sc, sizeof( sc ) );
71 cc.hwndOwner = hwndDlg;
72 cc.rgbResult = RGB( gCurrentFillColor.r, gCurrentFillColor.g, gCurrentFillColor.b );
73 cc.Flags = CC_RGBINIT;
74 cc.lpCustColors = sc;
76 if( ChooseColor( &cc ) )
78 gCurrentFillColor.r = GetRValue( cc.rgbResult );
79 gCurrentFillColor.g = GetGValue( cc.rgbResult );
80 gCurrentFillColor.b = GetBValue( cc.rgbResult );
84 static void Cleanup( void )
86 if( gFillColorBrush )
88 DeleteObject( gFillColorBrush );
89 gFillColorBrush = 0;
92 if( gEdgeColorBrush )
94 DeleteObject( gEdgeColorBrush );
95 gEdgeColorBrush = 0;
99 BOOL CALLBACK HighlightSettingsDlgProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
101 switch( uMsg )
103 case WM_INITDIALOG:
104 LoadData( hwndDlg );
105 return TRUE;
107 case WM_CLOSE:
108 // Equivalent to pressing cancel
109 EndDialog( hwndDlg, 0 );
110 Cleanup();
111 return 0;
113 case WM_COMMAND:
114 if( LOWORD( wParam ) == IDOK )
116 SaveData( hwndDlg );
117 EndDialog( hwndDlg, 0 );
118 Cleanup();
120 else if( LOWORD( wParam ) == IDCANCEL )
122 EndDialog( hwndDlg, 0 );
123 Cleanup();
125 else if( LOWORD( wParam ) == IDC_CHANGE_EDGECOLOR )
127 ChangeEdgeColor( hwndDlg );
128 InvalidateRect( GetDlgItem( hwndDlg, IDC_EDGECOLOR ), 0, TRUE );
130 else if( LOWORD( wParam ) == IDC_CHANGE_FILLCOLOR )
132 ChangeFillColor( hwndDlg );
133 InvalidateRect( GetDlgItem( hwndDlg, IDC_FILLCOLOR ), 0, TRUE );
135 return 0;
137 case WM_CTLCOLORSTATIC:
138 if( (HWND)lParam == GetDlgItem( hwndDlg, IDC_EDGECOLOR ) )
140 COLORREF col = RGB( gCurrentEdgeColor.r, gCurrentEdgeColor.g, gCurrentEdgeColor.b );
142 if( gEdgeColorBrush )
143 DeleteObject( gEdgeColorBrush );
145 gEdgeColorBrush = CreateSolidBrush( col );
146 SetTextColor( (HDC)wParam, col );
147 SetBkColor( (HDC)wParam, col );
149 return (BOOL)gEdgeColorBrush;
151 else if( (HWND)lParam == GetDlgItem( hwndDlg, IDC_FILLCOLOR ) )
153 COLORREF col = RGB( gCurrentFillColor.r, gCurrentFillColor.g, gCurrentFillColor.b );
155 if( gFillColorBrush )
156 DeleteObject( gFillColorBrush );
158 gFillColorBrush = CreateSolidBrush( col );
159 SetTextColor( (HDC)wParam, col );
160 SetBkColor( (HDC)wParam, col );
162 return (BOOL)gFillColorBrush;
164 return 0;
166 default:
167 return 0;