]> git.saurik.com Git - wxWidgets.git/blame - demos/dbbrowse/pgmctrl.cpp
silence a few (harmless) HP aCC warnings
[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 10//----------------------------------------------------------------------------------------
8907154c 11
b5ffecfc
GT
12// For compilers that support precompilation, includes "wx/wx.h".
13#include "wx/wxprec.h"
c92b0f9a 14//----------------------------------------------------------------------------------------
b5ffecfc 15#ifdef __BORLANDC__
b5ce269b 16#pragma hdrstop
b5ffecfc 17#endif
c92b0f9a 18//----------------------------------------------------------------------------------------
b5ffecfc 19#ifndef WX_PRECOMP
b5ce269b 20#include "wx/wx.h"
b5ffecfc 21#endif
c92b0f9a 22//----------------------------------------------------------------------------------------
b5ffecfc 23#ifndef __WXMSW__
b5ce269b
BJ
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"
b5ffecfc 31#endif
c92b0f9a
MJ
32//----------------------------------------------------------------------------------------
33//-- all #includes that every .cpp needs --- 19990807.mj10777 ----------------
34//----------------------------------------------------------------------------------------
b5ffecfc 35#include "std.h" // sorgsam Pflegen !
645889ad 36
c92b0f9a
MJ
37//----------------------------------------------------------------------------------------
38//-- Global functions --------------------------------------------------------------------
39//----------------------------------------------------------------------------------------
daf06bb8 40static inline const wxChar *bool2String(bool b)
b5ffecfc 41{
5d2ac6b8 42 return b ? wxEmptyString : _T("not ");
b5ffecfc 43}
645889ad 44
c92b0f9a 45//----------------------------------------------------------------------------------------
b5ffecfc 46BEGIN_EVENT_TABLE(PgmCtrl, wxTreeCtrl)
645889ad
GT
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)
c92b0f9a 51END_EVENT_TABLE()
645889ad 52
c92b0f9a
MJ
53//----------------------------------------------------------------------------------------
54// PgmCtrl implementation
55//----------------------------------------------------------------------------------------
56IMPLEMENT_DYNAMIC_CLASS(PgmCtrl, wxTreeCtrl)
645889ad 57
c92b0f9a
MJ
58//----------------------------------------------------------------------------------------
59PgmCtrl::PgmCtrl(wxWindow *parent) : wxTreeCtrl(parent)
b5ffecfc
GT
60{
61}
645889ad 62
c92b0f9a 63//----------------------------------------------------------------------------------------
b5ffecfc 64PgmCtrl::PgmCtrl(wxWindow *parent, const wxWindowID id,const wxPoint& pos, const wxSize& size, long style)
645889ad 65: wxTreeCtrl(parent, id, pos, size, style)
b5ffecfc 66{
daf06bb8 67 const int image_size = 16;
645889ad 68 // Make an image list containing small icons
5151c7af 69 p_imageListNormal = new wxImageList(image_size, image_size, true);
645889ad 70 // should correspond to TreeIc_xxx enum
daf06bb8
JS
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)));
645889ad 78 SetImageList(p_imageListNormal);
b5ffecfc 79}
645889ad 80
c92b0f9a 81//----------------------------------------------------------------------------------------
b5ffecfc
GT
82PgmCtrl::~PgmCtrl()
83{
645889ad 84 delete p_imageListNormal;
5d2ac6b8 85 delete popupMenu1;
b5ffecfc 86}
645889ad 87
c92b0f9a 88//----------------------------------------------------------------------------------------
b5ffecfc 89#undef TREE_EVENT_HANDLER
645889ad 90
c92b0f9a 91//----------------------------------------------------------------------------------------
b5ffecfc
GT
92int PgmCtrl::OnPopulate()
93{
645889ad
GT
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());
daf06bb8 100 Root = AddRoot(Temp0,TreeIc_Logo,TreeIc_Logo, new TreeData(_T("Root")));
645889ad 101 //---------------------------------------------------------------------------------------
daf06bb8
JS
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);
645889ad 104 Temp1.Printf(_("locale (%s) ; Language (%s) ; Number(%2.2f)"),Temp0.c_str(), Temp2.c_str(), dTmp); Temp0.Empty(); Temp2.Empty();
daf06bb8
JS
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")));
645889ad
GT
112 for (i=0;i<pDoc->i_DSN;i++)
113 {
daf06bb8 114 Temp0.Printf(_T("ODBC-%s"),(pDoc->p_DSN+i)->Dsn.c_str());
645889ad
GT
115 Docu = AppendItem(Folder,(pDoc->p_DSN+i)->Dsn ,TreeIc_DsnClosed,TreeIc_DsnOpen, new TreeData(Temp0));
116 }
117 //---------------------------------------------------------------------------------------
118 popupMenu1 = NULL;
5d2ac6b8 119 popupMenu1 = new wxMenu;
645889ad
GT
120 popupMenu1->Append(PGMCTRL_ODBC_USER, _("Set Username and Password"));
121 // popupMenu1->AppendSeparator();
122 //---------------------------------------------------------------------------------------
123 Expand(Root);
124 Expand(Folder);
125 //---------------------------------------------------------------------------------------
126 return 0;
b5ffecfc 127}
645889ad 128
c92b0f9a 129//----------------------------------------------------------------------------------------
669f7a11 130void PgmCtrl::OnSelChanged(wxMouseEvent& WXUNUSED(event))
b5ffecfc 131{
645889ad
GT
132 int i;
133 Temp0.Empty(); Temp1.Empty();
67a99992 134#if wxUSE_STATUSBAR
645889ad 135 pDoc->p_MainFrame->SetStatusText(Temp0,0);
67a99992 136#endif // wxUSE_STATUSBAR
645889ad
GT
137 // Get the Information that we need
138 wxTreeItemId itemId = GetSelection();
139 TreeData *item = (TreeData *)GetItemData(itemId);
140 if (item != NULL )
b5ffecfc 141 {
645889ad 142 int Treffer = 0;
daf06bb8 143 Temp1.Printf(_T("%s"),item->m_desc.c_str());
645889ad 144 //--------------------------------------------------------------------------------------
daf06bb8 145 if (Temp1 == _T("Language English"))
645889ad 146 {
daf06bb8
JS
147 Temp0 = _T("std");
148 p_ProgramCfg->Write(_T("/Local/langid"),Temp0);
645889ad
GT
149 Temp0 = _("-I-> After a programm restart, the language will be changed to English.");
150 wxMessageBox(Temp0);
151 }
daf06bb8 152 if (Temp1 == _T("Language German"))
645889ad 153 {
daf06bb8
JS
154 Temp0 = _T("de");
155 p_ProgramCfg->Write(_T("/Local/langid"),Temp0);
645889ad
GT
156 Temp0 = _("-I-> After a programm restart, the language will be changed to German.");
157 wxMessageBox(Temp0);
158 }
159 //--------------------------------------------------------------------------------------
daf06bb8 160 if (Temp1 == _T("wxConfigBase Delete"))
645889ad
GT
161 {
162 if (p_ProgramCfg->DeleteAll()) // Default Diretory for wxFileSelector
3103e8a9 163 Temp0 = _("-I-> wxConfigBase.p_ProgramCfg->DeleteAll() was successful.");
645889ad 164 else
3103e8a9 165 Temp0 = _("-E-> wxConfigBase.p_ProgramCfg->DeleteAll() was not successful !");
645889ad
GT
166 wxBell(); // Ding_a_Ling
167 Treffer++;
168 }
169 //--------------------------------------------------------------------------------------
daf06bb8 170 if (Temp1.Contains(_T("ODBC-")))
645889ad
GT
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 //-------------------------------------------------------------------------------------
daf06bb8 186 Temp0.Printf(_("Item '%s': %sselected, %sexpanded, %sbold, %u children (%u immediately under this item)."),
645889ad
GT
187 item->m_desc.c_str(),
188 bool2String(IsSelected(itemId)),
189 bool2String(IsExpanded(itemId)),
190 bool2String(IsBold(itemId)),
191 GetChildrenCount(itemId),
192 GetChildrenCount(itemId));
daf06bb8
JS
193 LogBuf.Printf(_T("-I-> PgmCtrl::OnSelChanged - %s"),Temp0.c_str());
194 wxLogMessage( _T("%s"), LogBuf.c_str() );
645889ad
GT
195 //-------------------------------------------------------------------------------------
196 }
b5ce269b 197 }
b5ffecfc 198}
645889ad 199
c92b0f9a 200//----------------------------------------------------------------------------------------
b5ffecfc
GT
201void PgmCtrl::OnRightSelect(wxTreeEvent& WXUNUSED(event))
202{
645889ad
GT
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 )
b5ffecfc 210 {
645889ad 211 int Treffer = 0;
daf06bb8 212 Temp1.Printf(_T("%s"),item->m_desc.c_str());
645889ad 213 //--------------------------------------------------------------------------------------
daf06bb8 214 if (Temp1.Contains(_T("ODBC-")))
645889ad
GT
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 //--------------------------------------------------------------------------------------
c92b0f9a 244 }
ca7408bd 245} // void PgmCtrl::OnRightSelect(wxTreeEvent& WXUNUSED(event))
645889ad 246
c92b0f9a 247//----------------------------------------------------------------------------------------
b5ffecfc
GT
248void PgmCtrl::OnMouseMove(wxMouseEvent &event)
249{
645889ad 250 TreePos = event.GetPosition();
b5ffecfc 251}
645889ad 252
c92b0f9a 253//----------------------------------------------------------------------------------------
669f7a11 254void PgmCtrl::OnUserPassword(wxCommandEvent& WXUNUSED(event))
b5ffecfc 255{
645889ad
GT
256 // wxMessageBox(SaveDSN);
257 int i;
258 //--------------------------------------------
5d2ac6b8 259 DlgUser *p_Dlg = new DlgUser(this,pDoc,wxEmptyString);
645889ad
GT
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);
5151c7af 275 bool OK = false;
645889ad
GT
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;
5151c7af 282 OK = true;
645889ad
GT
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();
b5ffecfc 293}
c92b0f9a 294//----------------------------------------------------------------------------------------