]> git.saurik.com Git - wxWidgets.git/blame - demos/dbbrowse/pgmctrl.cpp
fixed wxFileDataObject in Unicode build
[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//----------------------------------------------------------------------------------------
daf06bb8 46static inline const wxChar *bool2String(bool b)
b5ffecfc 47{
daf06bb8 48 return b ? _T("") : _T("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{
daf06bb8 73 const int image_size = 16;
645889ad 74 // Make an image list containing small icons
daf06bb8 75 p_imageListNormal = new wxImageList(image_size, image_size, TRUE);
645889ad 76 // should correspond to TreeIc_xxx enum
daf06bb8
JS
77 p_imageListNormal->Add(wxBitmap(wxBitmap(wxICON(aLogo)).ConvertToImage().Rescale(image_size, image_size)));
78 p_imageListNormal->Add(wxBitmap(wxBitmap(wxICON(DsnClosed)).ConvertToImage().Rescale(image_size, image_size)));
79 p_imageListNormal->Add(wxBitmap(wxBitmap(wxICON(DsnOpen)).ConvertToImage().Rescale(image_size, image_size)));
80 p_imageListNormal->Add(wxBitmap(wxBitmap(wxICON(DocClosed)).ConvertToImage().Rescale(image_size, image_size)));
81 p_imageListNormal->Add(wxBitmap(wxBitmap(wxICON(DocOpen)).ConvertToImage().Rescale(image_size, image_size)));
82 p_imageListNormal->Add(wxBitmap(wxBitmap(wxICON(FolderClosed)).ConvertToImage().Rescale(image_size, image_size)));
83 p_imageListNormal->Add(wxBitmap(wxBitmap(wxICON(FolderOpen)).ConvertToImage().Rescale(image_size, image_size)));
645889ad 84 SetImageList(p_imageListNormal);
b5ffecfc 85}
645889ad 86
c92b0f9a 87//----------------------------------------------------------------------------------------
b5ffecfc
GT
88PgmCtrl::~PgmCtrl()
89{
645889ad
GT
90 delete p_imageListNormal;
91 delete popupMenu1;
b5ffecfc 92}
645889ad 93
c92b0f9a 94//----------------------------------------------------------------------------------------
b5ffecfc 95#undef TREE_EVENT_HANDLER
645889ad 96
c92b0f9a 97//----------------------------------------------------------------------------------------
b5ffecfc
GT
98int PgmCtrl::OnPopulate()
99{
645889ad
GT
100 SetFont(* pDoc->ft_Doc);
101 wxTreeItemId Root, Folder, Docu;
102 //---------------------------------------------------------------------------------------
103 int i;
104 double dTmp = 1234567.89;
105 Temp0.Printf(_("%s Functions"),p_ProgramCfg->GetAppName().c_str());
daf06bb8 106 Root = AddRoot(Temp0,TreeIc_Logo,TreeIc_Logo, new TreeData(_T("Root")));
645889ad 107 //---------------------------------------------------------------------------------------
daf06bb8
JS
108 Folder = AppendItem(Root, _("Program settings") ,TreeIc_FolderClosed, TreeIc_FolderOpen, new TreeData(_T("Settings")));
109 p_ProgramCfg->Read(_T("/Local/langid"),&Temp0); p_ProgramCfg->Read(_T("/Local/language"),&Temp2);
645889ad 110 Temp1.Printf(_("locale (%s) ; Language (%s) ; Number(%2.2f)"),Temp0.c_str(), Temp2.c_str(), dTmp); Temp0.Empty(); Temp2.Empty();
daf06bb8
JS
111 Docu = AppendItem(Folder, Temp1,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData(_T("Setting Language")));
112 p_ProgramCfg->Read(_T("/Paths/Work"),&Temp0); Temp1.Printf(_("Work Path : %s"),Temp0.c_str()); Temp0.Empty();
113 Docu = AppendItem(Folder,Temp1,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData(_T("Path Work")));
114 Docu = AppendItem(Folder, _("Change the language to English") ,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData(_T("Language English")));
115 Docu = AppendItem(Folder, _("Change the language to German") ,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData(_T("Language German")));
116 Docu = AppendItem(Folder, _("Delete all wxConfigBase Entry's"),TreeIc_DocClosed,TreeIc_DocOpen,new TreeData(_T("wxConfigBase Delete")));
117 Folder = AppendItem(Root, _T("ODBC DSN"),TreeIc_FolderClosed,TreeIc_FolderOpen,new TreeData(_T("ODBC-DSN")));
645889ad
GT
118 for (i=0;i<pDoc->i_DSN;i++)
119 {
daf06bb8 120 Temp0.Printf(_T("ODBC-%s"),(pDoc->p_DSN+i)->Dsn.c_str());
645889ad
GT
121 Docu = AppendItem(Folder,(pDoc->p_DSN+i)->Dsn ,TreeIc_DsnClosed,TreeIc_DsnOpen, new TreeData(Temp0));
122 }
123 //---------------------------------------------------------------------------------------
124 popupMenu1 = NULL;
daf06bb8 125 popupMenu1 = new wxMenu(_T(""));
645889ad
GT
126 popupMenu1->Append(PGMCTRL_ODBC_USER, _("Set Username and Password"));
127 // popupMenu1->AppendSeparator();
128 //---------------------------------------------------------------------------------------
129 Expand(Root);
130 Expand(Folder);
131 //---------------------------------------------------------------------------------------
132 return 0;
b5ffecfc 133}
645889ad 134
c92b0f9a 135//----------------------------------------------------------------------------------------
669f7a11 136void PgmCtrl::OnSelChanged(wxMouseEvent& WXUNUSED(event))
b5ffecfc 137{
645889ad
GT
138 int i;
139 Temp0.Empty(); Temp1.Empty();
140 pDoc->p_MainFrame->SetStatusText(Temp0,0);
141 // Get the Information that we need
142 wxTreeItemId itemId = GetSelection();
143 TreeData *item = (TreeData *)GetItemData(itemId);
144 if (item != NULL )
b5ffecfc 145 {
645889ad 146 int Treffer = 0;
daf06bb8 147 Temp1.Printf(_T("%s"),item->m_desc.c_str());
645889ad 148 //--------------------------------------------------------------------------------------
daf06bb8 149 if (Temp1 == _T("Language English"))
645889ad 150 {
daf06bb8
JS
151 Temp0 = _T("std");
152 p_ProgramCfg->Write(_T("/Local/langid"),Temp0);
645889ad
GT
153 Temp0 = _("-I-> After a programm restart, the language will be changed to English.");
154 wxMessageBox(Temp0);
155 }
daf06bb8 156 if (Temp1 == _T("Language German"))
645889ad 157 {
daf06bb8
JS
158 Temp0 = _T("de");
159 p_ProgramCfg->Write(_T("/Local/langid"),Temp0);
645889ad
GT
160 Temp0 = _("-I-> After a programm restart, the language will be changed to German.");
161 wxMessageBox(Temp0);
162 }
163 //--------------------------------------------------------------------------------------
daf06bb8 164 if (Temp1 == _T("wxConfigBase Delete"))
645889ad
GT
165 {
166 if (p_ProgramCfg->DeleteAll()) // Default Diretory for wxFileSelector
167 Temp0 = _("-I-> wxConfigBase.p_ProgramCfg->DeleteAll() was succesfull.");
168 else
169 Temp0 = _("-E-> wxConfigBase.p_ProgramCfg->DeleteAll() was not succesfull !");
170 wxBell(); // Ding_a_Ling
171 Treffer++;
172 }
173 //--------------------------------------------------------------------------------------
daf06bb8 174 if (Temp1.Contains(_T("ODBC-")))
645889ad
GT
175 {
176 Temp1 = Temp1.Mid(5,wxSTRING_MAXLEN);
177 for (i=0;i<pDoc->i_DSN;i++)
178 {
179 if (Temp1 == (pDoc->p_DSN+i)->Dsn)
180 {
181 pDoc->OnChosenDSN(i);
182 }
183 }
184 Treffer++;
185 }
186 //--------------------------------------------------------------------------------------
187 if (Treffer == 0)
188 {
189 //-------------------------------------------------------------------------------------
daf06bb8 190 Temp0.Printf(_("Item '%s': %sselected, %sexpanded, %sbold, %u children (%u immediately under this item)."),
645889ad
GT
191 item->m_desc.c_str(),
192 bool2String(IsSelected(itemId)),
193 bool2String(IsExpanded(itemId)),
194 bool2String(IsBold(itemId)),
195 GetChildrenCount(itemId),
196 GetChildrenCount(itemId));
daf06bb8
JS
197 LogBuf.Printf(_T("-I-> PgmCtrl::OnSelChanged - %s"),Temp0.c_str());
198 wxLogMessage( _T("%s"), LogBuf.c_str() );
645889ad
GT
199 //-------------------------------------------------------------------------------------
200 }
b5ce269b 201 }
b5ffecfc 202}
645889ad 203
c92b0f9a 204//----------------------------------------------------------------------------------------
b5ffecfc
GT
205void PgmCtrl::OnRightSelect(wxTreeEvent& WXUNUSED(event))
206{
645889ad
GT
207 int i;
208 Temp0.Empty();
209 // Get the Information that we need
210 wxTreeItemId itemId = GetSelection();
211 DBTreeData *item = (DBTreeData *)GetItemData(itemId);
212 SaveDSN.Empty();
213 if ( item != NULL )
b5ffecfc 214 {
645889ad 215 int Treffer = 0;
daf06bb8 216 Temp1.Printf(_T("%s"),item->m_desc.c_str());
645889ad 217 //--------------------------------------------------------------------------------------
daf06bb8 218 if (Temp1.Contains(_T("ODBC-")))
645889ad
GT
219 {
220 Temp1 = Temp1.Mid(5,wxSTRING_MAXLEN);
221 for (i=0;i<pDoc->i_DSN;i++)
222 {
223 if (Temp1 == (pDoc->p_DSN+i)->Dsn)
224 {
225 SaveDSN = Temp1;
226 PopupMenu(popupMenu1,TreePos.x,TreePos.y);
227 }
228 }
229 Treffer++;
230 }
231 //--------------------------------------------------------------------------------------
232 if (Treffer == 0)
233 {
234 /*
235 Temp0.Printf(_("Item '%s': %sselected, %sexpanded, %sbold,"
236 "%u children (%u immediately under this item)."),
237 item->m_desc.c_str(),
238 bool2String(IsSelected(itemId)),
239 bool2String(IsExpanded(itemId)),
240 bool2String(IsBold(itemId)),
241 GetChildrenCount(itemId),
242 GetChildrenCount(itemId));
243 LogBuf.Printf("-I-> DBTree::OnSelChanged - %s",Temp0.c_str());
244 wxLogMessage( "%s", LogBuf.c_str() );
245 */
246 }
247 //--------------------------------------------------------------------------------------
c92b0f9a 248 }
ca7408bd 249} // void PgmCtrl::OnRightSelect(wxTreeEvent& WXUNUSED(event))
645889ad 250
c92b0f9a 251//----------------------------------------------------------------------------------------
b5ffecfc
GT
252void PgmCtrl::OnMouseMove(wxMouseEvent &event)
253{
645889ad 254 TreePos = event.GetPosition();
b5ffecfc 255}
645889ad 256
c92b0f9a 257//----------------------------------------------------------------------------------------
669f7a11 258void PgmCtrl::OnUserPassword(wxCommandEvent& WXUNUSED(event))
b5ffecfc 259{
645889ad
GT
260 // wxMessageBox(SaveDSN);
261 int i;
262 //--------------------------------------------
daf06bb8 263 DlgUser *p_Dlg = new DlgUser(this,pDoc,_T(""));
645889ad
GT
264 //-------------------------------------------
265 for (i=0;i<pDoc->i_DSN;i++)
266 {
267 wxYield();
268 if (SaveDSN == (pDoc->p_DSN+i)->Dsn)
269 {
270 p_Dlg->pDoc = pDoc;
271 p_Dlg->s_DSN = (pDoc->p_DSN+i)->Dsn;
272 p_Dlg->s_User = (pDoc->p_DSN+i)->Usr;
273 p_Dlg->s_Password = (pDoc->p_DSN+i)->Pas;
274 p_Dlg->OnInit();
275 p_Dlg->Fit();
276 //--------------------
277 // 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);
278 // wxMessageBox(Temp0);
279 bool OK = FALSE;
280 if (p_Dlg->ShowModal() == wxID_OK)
281 {
282 (pDoc->p_DSN+i)->Usr = p_Dlg->s_User;
283 (pDoc->p_DSN+i)->Pas = p_Dlg->s_Password;
284 (pDoc->db_Br+i)->UserName = (pDoc->p_DSN+i)->Usr;
285 (pDoc->db_Br+i)->Password = (pDoc->p_DSN+i)->Pas;
286 OK = TRUE;
287 }
288 delete p_Dlg;
289 if (!OK)
290 return;
291 //--------------------
292 break; // We have what we want, leave
293 }
294 }
295 //-------------------------------------------
296 SaveDSN.Empty();
b5ffecfc 297}
c92b0f9a 298//----------------------------------------------------------------------------------------