]> git.saurik.com Git - wxWidgets.git/blob - demos/dbbrowse/pgmctrl.cpp
A clarification
[wxWidgets.git] / demos / dbbrowse / pgmctrl.cpp
1 //----------------------------------------------------------------------------------------
2 // Name: pgmctrl.cpp
3 // Purpose: Programm Control with a Tree
4 // Author: Mark Johnson
5 // Modified by: 19990806.mj10777
6 // Created: 19991010
7 // RCS-ID: $Id$
8 // Copyright: (c) Mark Johnson, Berlin Germany
9 // Licence: wxWindows license
10 //----------------------------------------------------------------------------------------
11 //-- all #ifdefs that the whole Project needs. -------------------------------------------
12 //----------------------------------------------------------------------------------------
13 #ifdef __GNUG__
14 #pragma implementation
15 #pragma interface
16 #endif
17 //----------------------------------------------------------------------------------------
18 // For compilers that support precompilation, includes "wx/wx.h".
19 #include "wx/wxprec.h"
20 //----------------------------------------------------------------------------------------
21 #ifdef __BORLANDC__
22 #pragma hdrstop
23 #endif
24 //----------------------------------------------------------------------------------------
25 #ifndef WX_PRECOMP
26 #include "wx/wx.h"
27 #endif
28 //----------------------------------------------------------------------------------------
29 #ifndef __WXMSW__
30 #include "bitmaps/d_closed.xpm"
31 #include "bitmaps/d_open.xpm"
32 #include "bitmaps/f_closed.xpm"
33 #include "bitmaps/f_open.xpm"
34 #include "bitmaps/logo.xpm"
35 #include "bitmaps/dsnclose.xpm"
36 #include "bitmaps/dsnopen.xpm"
37 #endif
38 //----------------------------------------------------------------------------------------
39 //-- all #includes that every .cpp needs --- 19990807.mj10777 ----------------
40 //----------------------------------------------------------------------------------------
41 #include "std.h" // sorgsam Pflegen !
42
43 //----------------------------------------------------------------------------------------
44 //-- Global functions --------------------------------------------------------------------
45 //----------------------------------------------------------------------------------------
46 static inline const wxChar *bool2String(bool b)
47 {
48 return b ? _T("") : _T("not ");
49 }
50
51 //----------------------------------------------------------------------------------------
52 BEGIN_EVENT_TABLE(PgmCtrl, wxTreeCtrl)
53 EVT_MOTION (PgmCtrl::OnMouseMove)
54 EVT_LEFT_DCLICK(PgmCtrl::OnSelChanged)
55 EVT_TREE_ITEM_RIGHT_CLICK(TREE_CTRL_PGM,PgmCtrl::OnRightSelect)
56 EVT_MENU(PGMCTRL_ODBC_USER,PgmCtrl::OnUserPassword)
57 END_EVENT_TABLE()
58
59 //----------------------------------------------------------------------------------------
60 // PgmCtrl implementation
61 //----------------------------------------------------------------------------------------
62 IMPLEMENT_DYNAMIC_CLASS(PgmCtrl, wxTreeCtrl)
63
64 //----------------------------------------------------------------------------------------
65 PgmCtrl::PgmCtrl(wxWindow *parent) : wxTreeCtrl(parent)
66 {
67 }
68
69 //----------------------------------------------------------------------------------------
70 PgmCtrl::PgmCtrl(wxWindow *parent, const wxWindowID id,const wxPoint& pos, const wxSize& size, long style)
71 : wxTreeCtrl(parent, id, pos, size, style)
72 {
73 const int image_size = 16;
74 // Make an image list containing small icons
75 p_imageListNormal = new wxImageList(image_size, image_size, TRUE);
76 // should correspond to TreeIc_xxx enum
77 #if defined(__WXMSW__) && defined(__WIN16__)
78 // This is required in 16-bit Windows mode only because we can't load a specific (16x16)
79 // icon image, so it comes out stretched
80 p_imageListNormal->Add(wxBitmap(wxBitmap("bitmap1", wxBITMAP_TYPE_BMP_RESOURCE).ConvertToImage().Rescale(image_size, image_size)));
81 p_imageListNormal->Add(wxBitmap(wxBitmap("bitmap2", wxBITMAP_TYPE_BMP_RESOURCE).ConvertToImage().Rescale(image_size, image_size)));
82 #else
83 p_imageListNormal->Add(wxBitmap(wxBitmap(wxICON(aLogo)).ConvertToImage().Rescale(image_size, image_size)));
84 p_imageListNormal->Add(wxBitmap(wxBitmap(wxICON(DsnClosed)).ConvertToImage().Rescale(image_size, image_size)));
85 p_imageListNormal->Add(wxBitmap(wxBitmap(wxICON(DsnOpen)).ConvertToImage().Rescale(image_size, image_size)));
86 p_imageListNormal->Add(wxBitmap(wxBitmap(wxICON(DocClosed)).ConvertToImage().Rescale(image_size, image_size)));
87 p_imageListNormal->Add(wxBitmap(wxBitmap(wxICON(DocOpen)).ConvertToImage().Rescale(image_size, image_size)));
88 p_imageListNormal->Add(wxBitmap(wxBitmap(wxICON(FolderClosed)).ConvertToImage().Rescale(image_size, image_size)));
89 p_imageListNormal->Add(wxBitmap(wxBitmap(wxICON(FolderOpen)).ConvertToImage().Rescale(image_size, image_size)));
90 #endif
91 SetImageList(p_imageListNormal);
92 }
93
94 //----------------------------------------------------------------------------------------
95 PgmCtrl::~PgmCtrl()
96 {
97 delete p_imageListNormal;
98 delete popupMenu1;
99 }
100
101 //----------------------------------------------------------------------------------------
102 #undef TREE_EVENT_HANDLER
103
104 //----------------------------------------------------------------------------------------
105 int PgmCtrl::OnPopulate()
106 {
107 SetFont(* pDoc->ft_Doc);
108 wxTreeItemId Root, Folder, Docu;
109 //---------------------------------------------------------------------------------------
110 int i;
111 double dTmp = 1234567.89;
112 Temp0.Printf(_("%s Functions"),p_ProgramCfg->GetAppName().c_str());
113 Root = AddRoot(Temp0,TreeIc_Logo,TreeIc_Logo, new TreeData(_T("Root")));
114 //---------------------------------------------------------------------------------------
115 Folder = AppendItem(Root, _("Program settings") ,TreeIc_FolderClosed, TreeIc_FolderOpen, new TreeData(_T("Settings")));
116 p_ProgramCfg->Read(_T("/Local/langid"),&Temp0); p_ProgramCfg->Read(_T("/Local/language"),&Temp2);
117 Temp1.Printf(_("locale (%s) ; Language (%s) ; Number(%2.2f)"),Temp0.c_str(), Temp2.c_str(), dTmp); Temp0.Empty(); Temp2.Empty();
118 Docu = AppendItem(Folder, Temp1,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData(_T("Setting Language")));
119 p_ProgramCfg->Read(_T("/Paths/Work"),&Temp0); Temp1.Printf(_("Work Path : %s"),Temp0.c_str()); Temp0.Empty();
120 Docu = AppendItem(Folder,Temp1,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData(_T("Path Work")));
121 Docu = AppendItem(Folder, _("Change the language to English") ,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData(_T("Language English")));
122 Docu = AppendItem(Folder, _("Change the language to German") ,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData(_T("Language German")));
123 Docu = AppendItem(Folder, _("Delete all wxConfigBase Entry's"),TreeIc_DocClosed,TreeIc_DocOpen,new TreeData(_T("wxConfigBase Delete")));
124 Folder = AppendItem(Root, _T("ODBC DSN"),TreeIc_FolderClosed,TreeIc_FolderOpen,new TreeData(_T("ODBC-DSN")));
125 for (i=0;i<pDoc->i_DSN;i++)
126 {
127 Temp0.Printf(_T("ODBC-%s"),(pDoc->p_DSN+i)->Dsn.c_str());
128 Docu = AppendItem(Folder,(pDoc->p_DSN+i)->Dsn ,TreeIc_DsnClosed,TreeIc_DsnOpen, new TreeData(Temp0));
129 }
130 //---------------------------------------------------------------------------------------
131 popupMenu1 = NULL;
132 popupMenu1 = new wxMenu(_T(""));
133 popupMenu1->Append(PGMCTRL_ODBC_USER, _("Set Username and Password"));
134 // popupMenu1->AppendSeparator();
135 //---------------------------------------------------------------------------------------
136 Expand(Root);
137 Expand(Folder);
138 //---------------------------------------------------------------------------------------
139 return 0;
140 }
141
142 //----------------------------------------------------------------------------------------
143 void PgmCtrl::OnSelChanged(wxMouseEvent& WXUNUSED(event))
144 {
145 int i;
146 Temp0.Empty(); Temp1.Empty();
147 pDoc->p_MainFrame->SetStatusText(Temp0,0);
148 // Get the Information that we need
149 wxTreeItemId itemId = GetSelection();
150 TreeData *item = (TreeData *)GetItemData(itemId);
151 if (item != NULL )
152 {
153 int Treffer = 0;
154 Temp1.Printf(_T("%s"),item->m_desc.c_str());
155 //--------------------------------------------------------------------------------------
156 if (Temp1 == _T("Language English"))
157 {
158 Temp0 = _T("std");
159 p_ProgramCfg->Write(_T("/Local/langid"),Temp0);
160 Temp0 = _("-I-> After a programm restart, the language will be changed to English.");
161 wxMessageBox(Temp0);
162 }
163 if (Temp1 == _T("Language German"))
164 {
165 Temp0 = _T("de");
166 p_ProgramCfg->Write(_T("/Local/langid"),Temp0);
167 Temp0 = _("-I-> After a programm restart, the language will be changed to German.");
168 wxMessageBox(Temp0);
169 }
170 //--------------------------------------------------------------------------------------
171 if (Temp1 == _T("wxConfigBase Delete"))
172 {
173 if (p_ProgramCfg->DeleteAll()) // Default Diretory for wxFileSelector
174 Temp0 = _("-I-> wxConfigBase.p_ProgramCfg->DeleteAll() was succesfull.");
175 else
176 Temp0 = _("-E-> wxConfigBase.p_ProgramCfg->DeleteAll() was not succesfull !");
177 wxBell(); // Ding_a_Ling
178 Treffer++;
179 }
180 //--------------------------------------------------------------------------------------
181 if (Temp1.Contains(_T("ODBC-")))
182 {
183 Temp1 = Temp1.Mid(5,wxSTRING_MAXLEN);
184 for (i=0;i<pDoc->i_DSN;i++)
185 {
186 if (Temp1 == (pDoc->p_DSN+i)->Dsn)
187 {
188 pDoc->OnChosenDSN(i);
189 }
190 }
191 Treffer++;
192 }
193 //--------------------------------------------------------------------------------------
194 if (Treffer == 0)
195 {
196 //-------------------------------------------------------------------------------------
197 Temp0.Printf(_("Item '%s': %sselected, %sexpanded, %sbold, %u children (%u immediately under this item)."),
198 item->m_desc.c_str(),
199 bool2String(IsSelected(itemId)),
200 bool2String(IsExpanded(itemId)),
201 bool2String(IsBold(itemId)),
202 GetChildrenCount(itemId),
203 GetChildrenCount(itemId));
204 LogBuf.Printf(_T("-I-> PgmCtrl::OnSelChanged - %s"),Temp0.c_str());
205 wxLogMessage( _T("%s"), LogBuf.c_str() );
206 //-------------------------------------------------------------------------------------
207 }
208 }
209 }
210
211 //----------------------------------------------------------------------------------------
212 void PgmCtrl::OnRightSelect(wxTreeEvent& WXUNUSED(event))
213 {
214 int i;
215 Temp0.Empty();
216 // Get the Information that we need
217 wxTreeItemId itemId = GetSelection();
218 DBTreeData *item = (DBTreeData *)GetItemData(itemId);
219 SaveDSN.Empty();
220 if ( item != NULL )
221 {
222 int Treffer = 0;
223 Temp1.Printf(_T("%s"),item->m_desc.c_str());
224 //--------------------------------------------------------------------------------------
225 if (Temp1.Contains(_T("ODBC-")))
226 {
227 Temp1 = Temp1.Mid(5,wxSTRING_MAXLEN);
228 for (i=0;i<pDoc->i_DSN;i++)
229 {
230 if (Temp1 == (pDoc->p_DSN+i)->Dsn)
231 {
232 SaveDSN = Temp1;
233 PopupMenu(popupMenu1,TreePos.x,TreePos.y);
234 }
235 }
236 Treffer++;
237 }
238 //--------------------------------------------------------------------------------------
239 if (Treffer == 0)
240 {
241 /*
242 Temp0.Printf(_("Item '%s': %sselected, %sexpanded, %sbold,"
243 "%u children (%u immediately under this item)."),
244 item->m_desc.c_str(),
245 bool2String(IsSelected(itemId)),
246 bool2String(IsExpanded(itemId)),
247 bool2String(IsBold(itemId)),
248 GetChildrenCount(itemId),
249 GetChildrenCount(itemId));
250 LogBuf.Printf("-I-> DBTree::OnSelChanged - %s",Temp0.c_str());
251 wxLogMessage( "%s", LogBuf.c_str() );
252 */
253 }
254 //--------------------------------------------------------------------------------------
255 }
256 } // void PgmCtrl::OnRightSelect(wxTreeEvent& WXUNUSED(event))
257
258 //----------------------------------------------------------------------------------------
259 void PgmCtrl::OnMouseMove(wxMouseEvent &event)
260 {
261 TreePos = event.GetPosition();
262 }
263
264 //----------------------------------------------------------------------------------------
265 void PgmCtrl::OnUserPassword(wxCommandEvent& WXUNUSED(event))
266 {
267 // wxMessageBox(SaveDSN);
268 int i;
269 //--------------------------------------------
270 DlgUser *p_Dlg = new DlgUser(this,pDoc,_T(""));
271 //-------------------------------------------
272 for (i=0;i<pDoc->i_DSN;i++)
273 {
274 wxYield();
275 if (SaveDSN == (pDoc->p_DSN+i)->Dsn)
276 {
277 p_Dlg->pDoc = pDoc;
278 p_Dlg->s_DSN = (pDoc->p_DSN+i)->Dsn;
279 p_Dlg->s_User = (pDoc->p_DSN+i)->Usr;
280 p_Dlg->s_Password = (pDoc->p_DSN+i)->Pas;
281 p_Dlg->OnInit();
282 p_Dlg->Fit();
283 //--------------------
284 // Temp0.Printf("i(%d) ; s_DSN(%s) ; s_User(%s) ; s_Password(%s)",i,p_Dlg.s_DSN,p_Dlg.s_User,p_Dlg.s_Password);
285 // wxMessageBox(Temp0);
286 bool OK = FALSE;
287 if (p_Dlg->ShowModal() == wxID_OK)
288 {
289 (pDoc->p_DSN+i)->Usr = p_Dlg->s_User;
290 (pDoc->p_DSN+i)->Pas = p_Dlg->s_Password;
291 (pDoc->db_Br+i)->UserName = (pDoc->p_DSN+i)->Usr;
292 (pDoc->db_Br+i)->Password = (pDoc->p_DSN+i)->Pas;
293 OK = TRUE;
294 }
295 delete p_Dlg;
296 if (!OK)
297 return;
298 //--------------------
299 break; // We have what we want, leave
300 }
301 }
302 //-------------------------------------------
303 SaveDSN.Empty();
304 }
305 //----------------------------------------------------------------------------------------