c2b9868025133fec95b7c31c89669b6a3d7cf59e
[opencv] / apps / Hawk / WordColors.cpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                        Intel License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
22 //   * Redistribution's in binary form must reproduce the above copyright notice,
23 //     this list of conditions and the following disclaimer in the documentation
24 //     and/or other materials provided with the distribution.
25 //
26 //   * The name of Intel Corporation may not be used to endorse or promote products
27 //     derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 //M*/// WordColors.cpp : implementation file
41 //
42
43 #include "stdafx.h"
44 #include "hawk.h"
45 #include "stdafx.h"
46 #include "Hawk.h"
47 #include "MainFrm.h"
48
49 #include "HawkDoc.h"
50 #include "HawkView.h"
51 #include "GotoLine.h"
52 #include "WordColors.h"
53
54 #ifdef _DEBUG
55 #define new DEBUG_NEW
56 #undef THIS_FILE
57 static char THIS_FILE[] = __FILE__;
58 #endif
59
60 /////////////////////////////////////////////////////////////////////////////
61 // CWordColors dialog
62
63
64 CWordColors::CWordColors(CWnd* pParent /*=NULL*/)
65         : CDialog(CWordColors::IDD, pParent)
66 {
67         //{{AFX_DATA_INIT(CWordColors)
68                 // NOTE: the ClassWizard will add member initialization here
69         //}}AFX_DATA_INIT
70 }
71
72
73 void CWordColors::DoDataExchange(CDataExchange* pDX)
74 {
75         CDialog::DoDataExchange(pDX);
76         //{{AFX_DATA_MAP(CWordColors)
77         DDX_Control(pDX, IDC_SAMPLE, m_Sample);
78         DDX_Control(pDX, IDC_KEYWORDS, m_KeyWords);
79         //}}AFX_DATA_MAP
80 }
81
82
83 BEGIN_MESSAGE_MAP(CWordColors, CDialog)
84         //{{AFX_MSG_MAP(CWordColors)
85         ON_LBN_SELCHANGE(IDC_KEYWORDS, OnSelchangeKeywords)
86         ON_BN_CLICKED(IDC_FOREGROUND, OnForeground)
87         ON_WM_CTLCOLOR()
88         //}}AFX_MSG_MAP
89 END_MESSAGE_MAP()
90
91 /////////////////////////////////////////////////////////////////////////////
92 // CWordColors message handlers
93
94 BOOL CWordColors::OnInitDialog() 
95 {
96         CDialog::OnInitDialog();
97         
98         // TODO: Add extra initialization here
99     m_KeyWords.AddString("Selection Background");
100     m_KeyWords.AddString("Selection Foreground");
101     m_KeyWords.AddString("Background");
102     m_KeyWords.AddString("Normal");
103     m_KeyWords.AddString("Comment");
104     m_KeyWords.AddString("String");
105     m_KeyWords.AddString("KeyWord");
106     m_KeyWords.AddString("Number");
107
108     m_KeyWords.SetCurSel(0);
109     OnSelchangeKeywords();
110     m_Sample.SetWindowText("Sample Sample Sample Sample Sample Sample Sample Sample "
111                            "Sample Sample Sample Sample Sample Sample Sample Sample "
112                            "Sample Sample Sample Sample Sample Sample Sample Sample "
113                            "Sample Sample Sample Sample Sample Sample Sample Sample "
114                            "Sample Sample Sample Sample Sample Sample Sample Sample "
115                            "Sample Sample Sample Sample Sample Sample Sample Sample "
116                            "Sample Sample Sample Sample Sample Sample Sample Sample "
117                            "Sample Sample Sample Sample Sample Sample Sample Sample "
118                            "Sample Sample Sample Sample Sample Sample Sample Sample "
119                            "Sample Sample Sample Sample Sample Sample Sample Sample "
120                            "Sample Sample Sample Sample Sample Sample Sample Sample "
121                            "Sample Sample Sample Sample Sample Sample Sample Sample "
122                            "Sample Sample Sample Sample Sample Sample Sample Sample "
123                            "Sample Sample Sample Sample Sample Sample Sample Sample "
124                            "Sample Sample Sample Sample Sample Sample Sample Sample "
125                            "Sample Sample Sample Sample Sample Sample Sample Sample "
126                            "Sample Sample Sample Sample Sample Sample Sample Sample ");
127         
128         return TRUE;  // return TRUE unless you set the focus to a control
129                       // EXCEPTION: OCX Property Pages should return FALSE
130 }
131
132 ColorScheme CWordColors::DoModal(ColorScheme scheme)
133 {
134     m_Colors = scheme;
135     if(CDialog::DoModal() == IDOK)
136     {
137         m_Colors.bkBrush = (HBRUSH)CreateSolidBrush( m_Colors.background );
138
139         CHawkApp* app = (CHawkApp*)AfxGetApp();
140         app->WriteProfileInt("Configuration", "background", m_Colors.background);
141         app->WriteProfileInt("Configuration", "TOKEN_NORMAL", m_Colors.clr[TOKEN_NORMAL]);
142         app->WriteProfileInt("Configuration", "TOKEN_KEYWORD", m_Colors.clr[TOKEN_KEYWORD]);
143         app->WriteProfileInt("Configuration", "TOKEN_COMMENT", m_Colors.clr[TOKEN_COMMENT]);
144         app->WriteProfileInt("Configuration", "TOKEN_NUMBER", m_Colors.clr[TOKEN_NUMBER]);
145         app->WriteProfileInt("Configuration", "TOKEN_STRING", m_Colors.clr[TOKEN_STRING]);
146         app->WriteProfileInt("Configuration", "selbk", m_Colors.selbk);
147         app->WriteProfileInt("Configuration", "selfk", m_Colors.selfk);
148         return m_Colors;
149     }
150     else return scheme;
151 }
152
153 void CWordColors::OnSelchangeKeywords() 
154 {
155         // TODO: Add your control notification handler code here
156     switch(m_KeyWords.GetCurSel())
157     {
158     case 0:
159         m_Color = (COLORREF*)&m_Colors.selbk;
160         m_Background = m_Colors.selbk;
161         m_Foreground = m_Colors.selfk;
162         m_Entry = "selbk";
163         break;
164     case 1:
165         m_Color = (COLORREF*)&m_Colors.selfk;
166         m_Background = m_Colors.selbk;
167         m_Foreground = m_Colors.selfk;
168         m_Entry = "selfk";
169         break;
170     case 2:
171         m_Color = (COLORREF*)&m_Colors.background;
172         m_Background = m_Foreground = m_Colors.background;
173         m_Entry = "background";
174         break;
175     case 3:
176         m_Color = (COLORREF*)&m_Colors.clr[TOKEN_NORMAL];
177         m_Background = m_Colors.background;
178         m_Foreground = m_Colors.clr[0];
179         m_Entry = "TOKEN_NORMAL";
180         break;
181     case 4:
182         m_Color = (COLORREF*)&m_Colors.clr[TOKEN_COMMENT];
183         m_Background = m_Colors.background;
184         m_Foreground = m_Colors.clr[1];
185         m_Entry = "TOKEN_COMMENT";
186         break;
187     case 5:
188         m_Color = (COLORREF*)&m_Colors.clr[TOKEN_STRING];
189         m_Background = m_Colors.background;
190         m_Foreground = m_Colors.clr[2];
191         m_Entry = "TOKEN_STRING";
192         break;
193     case 6:
194         m_Color = (COLORREF*)&m_Colors.clr[TOKEN_KEYWORD];
195         m_Background = m_Colors.background;
196         m_Foreground = m_Colors.clr[3];
197         m_Entry = "TOKEN_KEYWORD";
198         break;
199     case 7:
200         m_Color = (COLORREF*)&m_Colors.clr[TOKEN_NUMBER];
201         m_Background = m_Colors.background;
202         m_Foreground = m_Colors.clr[4];
203         m_Entry = "TOKEN_NUMBER";
204         break;
205     }
206     m_Sample.RedrawWindow();
207 }
208
209 void CWordColors::OnForeground() 
210 {
211         // TODO: Add your control notification handler code here
212     static COLORREF colors[16];
213     CHOOSECOLOR cl = {sizeof(cl), AfxGetMainWnd()->m_hWnd, 0, *m_Color, colors,
214                       CC_RGBINIT, 0, 0, 0};
215     BOOL res = ChooseColor(&cl);
216     if(res) *m_Color = cl.rgbResult;
217     OnSelchangeKeywords();
218 }
219
220 HBRUSH CWordColors::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
221 {
222         HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
223         
224         // TODO: Change any attributes of the DC here
225     if(pWnd->m_hWnd == m_Sample.m_hWnd)
226     {
227         pDC->SetTextColor(m_Foreground);
228         pDC->SetBkColor(m_Background);
229     }
230         // TODO: Return a different brush if the default is not desired
231         return hbr;
232 }