]> git.saurik.com Git - wxWidgets.git/blob - demos/dbbrowse/pgmctrl.cpp
documented wxSpinCtrl
[wxWidgets.git] / demos / dbbrowse / pgmctrl.cpp
1 //----------------------------------------------------------------------------------------
2 // Name: pgmctrl.h
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, mj10777@gmx.net
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 //-- Global functions --------------------------------------------------------------------
44 //----------------------------------------------------------------------------------------
45 static inline const char *bool2String(bool b)
46 {
47 return b ? "" : "not ";
48 }
49 //----------------------------------------------------------------------------------------
50 BEGIN_EVENT_TABLE(PgmCtrl, wxTreeCtrl)
51 EVT_MOTION (PgmCtrl::OnMouseMove)
52 EVT_LEFT_DCLICK(PgmCtrl::OnSelChanged)
53 EVT_TREE_ITEM_RIGHT_CLICK(TREE_CTRL_PGM,PgmCtrl::OnRightSelect)
54 EVT_MENU(PGMCTRL_ODBC_USER,PgmCtrl::OnUserPassword)
55 END_EVENT_TABLE()
56 //----------------------------------------------------------------------------------------
57 // PgmCtrl implementation
58 //----------------------------------------------------------------------------------------
59 IMPLEMENT_DYNAMIC_CLASS(PgmCtrl, wxTreeCtrl)
60 //----------------------------------------------------------------------------------------
61 PgmCtrl::PgmCtrl(wxWindow *parent) : wxTreeCtrl(parent)
62 {
63 }
64 //----------------------------------------------------------------------------------------
65 PgmCtrl::PgmCtrl(wxWindow *parent, const wxWindowID id,const wxPoint& pos, const wxSize& size, long style)
66 : wxTreeCtrl(parent, id, pos, size, style)
67 {
68 // Make an image list containing small icons
69 p_imageListNormal = new wxImageList(16, 16, TRUE);
70 // should correspond to TreeIc_xxx enum
71 #if defined(__WXMSW__) && defined(__WIN16__)
72 // This is required in 16-bit Windows mode only because we can't load a specific (16x16)
73 // icon image, so it comes out stretched
74 p_imageListNormal->Add(wxBitmap("bitmap1", wxBITMAP_TYPE_BMP_RESOURCE));
75 p_imageListNormal->Add(wxBitmap("bitmap2", wxBITMAP_TYPE_BMP_RESOURCE));
76 #else
77 p_imageListNormal->Add(wxICON(aLogo));
78 p_imageListNormal->Add(wxICON(DsnClosed));
79 p_imageListNormal->Add(wxICON(DsnOpen));
80 p_imageListNormal->Add(wxICON(DocClosed));
81 p_imageListNormal->Add(wxICON(DocOpen));
82 p_imageListNormal->Add(wxICON(FolderClosed));
83 p_imageListNormal->Add(wxICON(FolderOpen));
84 #endif
85 SetImageList(p_imageListNormal);
86 }
87 //----------------------------------------------------------------------------------------
88 PgmCtrl::~PgmCtrl()
89 {
90 delete p_imageListNormal;
91 }
92 //----------------------------------------------------------------------------------------
93 #undef TREE_EVENT_HANDLER
94 //----------------------------------------------------------------------------------------
95 int PgmCtrl::OnPopulate()
96 {
97 SetFont(* pDoc->ft_Doc);
98 wxTreeItemId Root, Folder, Docu;
99 //---------------------------------------------------------------------------------------
100 int i;
101 double dTmp = 1234567.89;
102 Temp0.Printf(_("%s Functions"),p_ProgramCfg->GetAppName().c_str());
103 Root = AddRoot(Temp0,TreeIc_Logo,TreeIc_Logo, new TreeData("Root"));
104 //---------------------------------------------------------------------------------------
105 Folder = AppendItem(Root, _("Program settings") ,TreeIc_FolderClosed, TreeIc_FolderOpen, new TreeData("Settings"));
106 p_ProgramCfg->Read("/Local/langid",&Temp0); p_ProgramCfg->Read("/Local/language",&Temp2);
107 Temp1.Printf(_("locale (%s) ; Language (%s) ; Number(%2.2f)"),Temp0.c_str(), Temp2.c_str(), dTmp); Temp0.Empty(); Temp2.Empty();
108 Docu = AppendItem(Folder, Temp1,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("Setting Language"));
109 p_ProgramCfg->Read("/Paths/Work",&Temp0); Temp1.Printf(_("Work Path : %s"),Temp0.c_str()); Temp0.Empty();
110 Docu = AppendItem(Folder,Temp1,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("Path Work"));
111 Docu = AppendItem(Folder, _("Change the language to English") ,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("Language English"));
112 Docu = AppendItem(Folder, _("Change the language to German") ,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("Language German"));
113 Docu = AppendItem(Folder, _("Delete all wxConfigBase Entry's"),TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("wxConfigBase Delete"));
114 Folder = AppendItem(Root, "ODBC DSN",TreeIc_FolderClosed,TreeIc_FolderOpen,new TreeData("ODBC-DSN"));
115 for (i=0;i<pDoc->i_DSN;i++)
116 {
117 Temp0.Printf("ODBC-%s",(pDoc->p_DSN+i)->Dsn.c_str());
118 Docu = AppendItem(Folder,(pDoc->p_DSN+i)->Dsn ,TreeIc_DsnClosed,TreeIc_DsnOpen, new TreeData(Temp0));
119 }
120 //---------------------------------------------------------------------------------------
121 popupMenu1 = NULL;
122 popupMenu1 = new wxMenu("");
123 popupMenu1->Append(PGMCTRL_ODBC_USER, _("Set Username and Password"));
124 // popupMenu1->AppendSeparator();
125 //---------------------------------------------------------------------------------------
126 Expand(Root);
127 Expand(Folder);
128 //---------------------------------------------------------------------------------------
129 return 0;
130 }
131 //----------------------------------------------------------------------------------------
132 void PgmCtrl::OnSelChanged(wxTreeEvent& WXUNUSED(event))
133 {
134 int i;
135 Temp0.Empty(); Temp1.Empty();
136 pDoc->p_MainFrame->SetStatusText(Temp0,0);
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("%s",item->m_desc.c_str());
144 //--------------------------------------------------------------------------------------
145 if (Temp1 == "Language English")
146 {
147 Temp0 = "std";
148 p_ProgramCfg->Write("/Local/langid",Temp0);
149 Temp0 = _("-I-> After a programm restart, the language will be changed to English.");
150 wxMessageBox(Temp0);
151 }
152 if (Temp1 == "Language German")
153 {
154 Temp0 = "de";
155 p_ProgramCfg->Write("/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 == "wxConfigBase Delete")
161 {
162 if (p_ProgramCfg->DeleteAll()) // Default Diretory for wxFileSelector
163 Temp0 = _("-I-> wxConfigBase.p_ProgramCfg->DeleteAll() was succesfull.");
164 else
165 Temp0 = _("-E-> wxConfigBase.p_ProgramCfg->DeleteAll() was not succesfull !");
166 wxBell(); // Ding_a_Ling
167 Treffer++;
168 }
169 //--------------------------------------------------------------------------------------
170 if (Temp1.Contains("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,"
187 "%u children (%u immediately under this item)."),
188 item->m_desc.c_str(),
189 bool2String(IsSelected(itemId)),
190 bool2String(IsExpanded(itemId)),
191 bool2String(IsBold(itemId)),
192 GetChildrenCount(itemId),
193 GetChildrenCount(itemId));
194 LogBuf.Printf("-I-> PgmCtrl::OnSelChanged - %s",Temp0.c_str());
195 wxLogMessage( "%s", LogBuf.c_str() );
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("%s",item->m_desc.c_str());
213 //--------------------------------------------------------------------------------------
214 if (Temp1.Contains("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 }
246 //----------------------------------------------------------------------------------------
247 void PgmCtrl::OnMouseMove(wxMouseEvent &event)
248 {
249 TreePos = event.GetPosition();
250 }
251 //----------------------------------------------------------------------------------------
252 void PgmCtrl::OnUserPassword()
253 {
254 // wxMessageBox(SaveDSN);
255 int i;
256 //--------------------------------------------
257 DlgUser *p_Dlg = new DlgUser(this,pDoc,"");
258 //-------------------------------------------
259 for (i=0;i<pDoc->i_DSN;i++)
260 {
261 if (SaveDSN == (pDoc->p_DSN+i)->Dsn)
262 {
263 p_Dlg->pDoc = pDoc;
264 p_Dlg->s_DSN = (pDoc->p_DSN+i)->Dsn;
265 p_Dlg->s_User = (pDoc->p_DSN+i)->Usr;
266 p_Dlg->s_Password = (pDoc->p_DSN+i)->Pas;
267 p_Dlg->OnInit();
268 p_Dlg->Fit();
269 //--------------------
270 // 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);
271 // wxMessageBox(Temp0);
272 bool OK = FALSE;
273 if (p_Dlg->ShowModal() == wxID_OK)
274 {
275 (pDoc->p_DSN+i)->Usr = p_Dlg->s_User;
276 (pDoc->p_DSN+i)->Pas = p_Dlg->s_Password;
277 (pDoc->db_Br+i)->UserName = (pDoc->p_DSN+i)->Usr;
278 (pDoc->db_Br+i)->Password = (pDoc->p_DSN+i)->Pas;
279 OK = TRUE;
280 }
281 delete p_Dlg;
282 if (!OK) return;
283 //--------------------
284 break; // We have what we want, leave
285 }
286 }
287 //-------------------------------------------
288 SaveDSN.Empty();
289 }
290 //----------------------------------------------------------------------------------------