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