]> git.saurik.com Git - wxWidgets.git/blame - demos/dbbrowse/pgmctrl.cpp
corrected DSW dependencies
[wxWidgets.git] / demos / dbbrowse / pgmctrl.cpp
CommitLineData
c92b0f9a 1//----------------------------------------------------------------------------------------
645889ad 2// Name: pgmctrl.cpp
b5ffecfc
GT
3// Purpose: Programm Control with a Tree
4// Author: Mark Johnson
5// Modified by: 19990806.mj10777
6// Created: 19991010
c09d434d 7// RCS-ID: $Id$
829c421b 8// Copyright: (c) Mark Johnson, Berlin Germany
b5ffecfc 9// Licence: wxWindows license
c92b0f9a
MJ
10//----------------------------------------------------------------------------------------
11//-- all #ifdefs that the whole Project needs. -------------------------------------------
12//----------------------------------------------------------------------------------------
b5ffecfc 13#ifdef __GNUG__
b5ce269b
BJ
14#pragma implementation
15#pragma interface
b5ffecfc 16#endif
c92b0f9a 17//----------------------------------------------------------------------------------------
b5ffecfc
GT
18// For compilers that support precompilation, includes "wx/wx.h".
19#include "wx/wxprec.h"
c92b0f9a 20//----------------------------------------------------------------------------------------
b5ffecfc 21#ifdef __BORLANDC__
b5ce269b 22#pragma hdrstop
b5ffecfc 23#endif
c92b0f9a 24//----------------------------------------------------------------------------------------
b5ffecfc 25#ifndef WX_PRECOMP
b5ce269b 26#include "wx/wx.h"
b5ffecfc 27#endif
c92b0f9a 28//----------------------------------------------------------------------------------------
b5ffecfc 29#ifndef __WXMSW__
b5ce269b
BJ
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"
b5ffecfc 37#endif
c92b0f9a
MJ
38//----------------------------------------------------------------------------------------
39//-- all #includes that every .cpp needs --- 19990807.mj10777 ----------------
40//----------------------------------------------------------------------------------------
b5ffecfc 41#include "std.h" // sorgsam Pflegen !
645889ad 42
c92b0f9a
MJ
43//----------------------------------------------------------------------------------------
44//-- Global functions --------------------------------------------------------------------
45//----------------------------------------------------------------------------------------
b5ffecfc
GT
46static inline const char *bool2String(bool b)
47{
645889ad 48 return b ? "" : "not ";
b5ffecfc 49}
645889ad 50
c92b0f9a 51//----------------------------------------------------------------------------------------
b5ffecfc 52BEGIN_EVENT_TABLE(PgmCtrl, wxTreeCtrl)
645889ad
GT
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)
c92b0f9a 57END_EVENT_TABLE()
645889ad 58
c92b0f9a
MJ
59//----------------------------------------------------------------------------------------
60// PgmCtrl implementation
61//----------------------------------------------------------------------------------------
62IMPLEMENT_DYNAMIC_CLASS(PgmCtrl, wxTreeCtrl)
645889ad 63
c92b0f9a
MJ
64//----------------------------------------------------------------------------------------
65PgmCtrl::PgmCtrl(wxWindow *parent) : wxTreeCtrl(parent)
b5ffecfc
GT
66{
67}
645889ad 68
c92b0f9a 69//----------------------------------------------------------------------------------------
b5ffecfc 70PgmCtrl::PgmCtrl(wxWindow *parent, const wxWindowID id,const wxPoint& pos, const wxSize& size, long style)
645889ad 71: wxTreeCtrl(parent, id, pos, size, style)
b5ffecfc 72{
645889ad
GT
73 // Make an image list containing small icons
74 p_imageListNormal = new wxImageList(16, 16, TRUE);
75 // should correspond to TreeIc_xxx enum
b5ffecfc 76#if defined(__WXMSW__) && defined(__WIN16__)
645889ad
GT
77 // This is required in 16-bit Windows mode only because we can't load a specific (16x16)
78 // icon image, so it comes out stretched
79 p_imageListNormal->Add(wxBitmap("bitmap1", wxBITMAP_TYPE_BMP_RESOURCE));
80 p_imageListNormal->Add(wxBitmap("bitmap2", wxBITMAP_TYPE_BMP_RESOURCE));
b5ffecfc 81#else
645889ad
GT
82 p_imageListNormal->Add(wxICON(aLogo));
83 p_imageListNormal->Add(wxICON(DsnClosed));
84 p_imageListNormal->Add(wxICON(DsnOpen));
85 p_imageListNormal->Add(wxICON(DocClosed));
86 p_imageListNormal->Add(wxICON(DocOpen));
87 p_imageListNormal->Add(wxICON(FolderClosed));
88 p_imageListNormal->Add(wxICON(FolderOpen));
b5ffecfc 89#endif
645889ad 90 SetImageList(p_imageListNormal);
b5ffecfc 91}
645889ad 92
c92b0f9a 93//----------------------------------------------------------------------------------------
b5ffecfc
GT
94PgmCtrl::~PgmCtrl()
95{
645889ad
GT
96 delete p_imageListNormal;
97 delete popupMenu1;
b5ffecfc 98}
645889ad 99
c92b0f9a 100//----------------------------------------------------------------------------------------
b5ffecfc 101#undef TREE_EVENT_HANDLER
645889ad 102
c92b0f9a 103//----------------------------------------------------------------------------------------
b5ffecfc
GT
104int PgmCtrl::OnPopulate()
105{
645889ad
GT
106 SetFont(* pDoc->ft_Doc);
107 wxTreeItemId Root, Folder, Docu;
108 //---------------------------------------------------------------------------------------
109 int i;
110 double dTmp = 1234567.89;
111 Temp0.Printf(_("%s Functions"),p_ProgramCfg->GetAppName().c_str());
112 Root = AddRoot(Temp0,TreeIc_Logo,TreeIc_Logo, new TreeData("Root"));
113 //---------------------------------------------------------------------------------------
114 Folder = AppendItem(Root, _("Program settings") ,TreeIc_FolderClosed, TreeIc_FolderOpen, new TreeData("Settings"));
115 p_ProgramCfg->Read("/Local/langid",&Temp0); p_ProgramCfg->Read("/Local/language",&Temp2);
116 Temp1.Printf(_("locale (%s) ; Language (%s) ; Number(%2.2f)"),Temp0.c_str(), Temp2.c_str(), dTmp); Temp0.Empty(); Temp2.Empty();
117 Docu = AppendItem(Folder, Temp1,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("Setting Language"));
118 p_ProgramCfg->Read("/Paths/Work",&Temp0); Temp1.Printf(_("Work Path : %s"),Temp0.c_str()); Temp0.Empty();
119 Docu = AppendItem(Folder,Temp1,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("Path Work"));
120 Docu = AppendItem(Folder, _("Change the language to English") ,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("Language English"));
121 Docu = AppendItem(Folder, _("Change the language to German") ,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("Language German"));
122 Docu = AppendItem(Folder, _("Delete all wxConfigBase Entry's"),TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("wxConfigBase Delete"));
123 Folder = AppendItem(Root, "ODBC DSN",TreeIc_FolderClosed,TreeIc_FolderOpen,new TreeData("ODBC-DSN"));
124 for (i=0;i<pDoc->i_DSN;i++)
125 {
126 Temp0.Printf("ODBC-%s",(pDoc->p_DSN+i)->Dsn.c_str());
127 Docu = AppendItem(Folder,(pDoc->p_DSN+i)->Dsn ,TreeIc_DsnClosed,TreeIc_DsnOpen, new TreeData(Temp0));
128 }
129 //---------------------------------------------------------------------------------------
130 popupMenu1 = NULL;
131 popupMenu1 = new wxMenu("");
132 popupMenu1->Append(PGMCTRL_ODBC_USER, _("Set Username and Password"));
133 // popupMenu1->AppendSeparator();
134 //---------------------------------------------------------------------------------------
135 Expand(Root);
136 Expand(Folder);
137 //---------------------------------------------------------------------------------------
138 return 0;
b5ffecfc 139}
645889ad 140
c92b0f9a 141//----------------------------------------------------------------------------------------
669f7a11 142void PgmCtrl::OnSelChanged(wxMouseEvent& WXUNUSED(event))
b5ffecfc 143{
645889ad
GT
144 int i;
145 Temp0.Empty(); Temp1.Empty();
146 pDoc->p_MainFrame->SetStatusText(Temp0,0);
147 // Get the Information that we need
148 wxTreeItemId itemId = GetSelection();
149 TreeData *item = (TreeData *)GetItemData(itemId);
150 if (item != NULL )
b5ffecfc 151 {
645889ad
GT
152 int Treffer = 0;
153 Temp1.Printf("%s",item->m_desc.c_str());
154 //--------------------------------------------------------------------------------------
155 if (Temp1 == "Language English")
156 {
157 Temp0 = "std";
158 p_ProgramCfg->Write("/Local/langid",Temp0);
159 Temp0 = _("-I-> After a programm restart, the language will be changed to English.");
160 wxMessageBox(Temp0);
161 }
162 if (Temp1 == "Language German")
163 {
164 Temp0 = "de";
165 p_ProgramCfg->Write("/Local/langid",Temp0);
166 Temp0 = _("-I-> After a programm restart, the language will be changed to German.");
167 wxMessageBox(Temp0);
168 }
169 //--------------------------------------------------------------------------------------
170 if (Temp1 == "wxConfigBase Delete")
171 {
172 if (p_ProgramCfg->DeleteAll()) // Default Diretory for wxFileSelector
173 Temp0 = _("-I-> wxConfigBase.p_ProgramCfg->DeleteAll() was succesfull.");
174 else
175 Temp0 = _("-E-> wxConfigBase.p_ProgramCfg->DeleteAll() was not succesfull !");
176 wxBell(); // Ding_a_Ling
177 Treffer++;
178 }
179 //--------------------------------------------------------------------------------------
180 if (Temp1.Contains("ODBC-"))
181 {
182 Temp1 = Temp1.Mid(5,wxSTRING_MAXLEN);
183 for (i=0;i<pDoc->i_DSN;i++)
184 {
185 if (Temp1 == (pDoc->p_DSN+i)->Dsn)
186 {
187 pDoc->OnChosenDSN(i);
188 }
189 }
190 Treffer++;
191 }
192 //--------------------------------------------------------------------------------------
193 if (Treffer == 0)
194 {
195 //-------------------------------------------------------------------------------------
196 Temp0.Printf(_("Item '%s': %sselected, %sexpanded, %sbold,"
197 "%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("-I-> PgmCtrl::OnSelChanged - %s",Temp0.c_str());
205 wxLogMessage( "%s", LogBuf.c_str() );
206 //-------------------------------------------------------------------------------------
207 }
b5ce269b 208 }
b5ffecfc 209}
645889ad 210
c92b0f9a 211//----------------------------------------------------------------------------------------
b5ffecfc
GT
212void PgmCtrl::OnRightSelect(wxTreeEvent& WXUNUSED(event))
213{
645889ad
GT
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 )
b5ffecfc 221 {
645889ad
GT
222 int Treffer = 0;
223 Temp1.Printf("%s",item->m_desc.c_str());
224 //--------------------------------------------------------------------------------------
225 if (Temp1.Contains("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 //--------------------------------------------------------------------------------------
c92b0f9a 255 }
ca7408bd 256} // void PgmCtrl::OnRightSelect(wxTreeEvent& WXUNUSED(event))
645889ad 257
c92b0f9a 258//----------------------------------------------------------------------------------------
b5ffecfc
GT
259void PgmCtrl::OnMouseMove(wxMouseEvent &event)
260{
645889ad 261 TreePos = event.GetPosition();
b5ffecfc 262}
645889ad 263
c92b0f9a 264//----------------------------------------------------------------------------------------
669f7a11 265void PgmCtrl::OnUserPassword(wxCommandEvent& WXUNUSED(event))
b5ffecfc 266{
645889ad
GT
267 // wxMessageBox(SaveDSN);
268 int i;
269 //--------------------------------------------
270 DlgUser *p_Dlg = new DlgUser(this,pDoc,"");
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();
b5ffecfc 304}
c92b0f9a 305//----------------------------------------------------------------------------------------