]>
Commit | Line | Data |
---|---|---|
b5ffecfc GT |
1 | //--------------------------------------------------------------------------- |
2 | // Name: pgmctrl.h | |
3 | // Purpose: Programm Control with a Tree | |
4 | // Author: Mark Johnson | |
5 | // Modified by: 19990806.mj10777 | |
6 | // Created: 19991010 | |
c09d434d | 7 | // RCS-ID: $Id$ |
b5ffecfc GT |
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__ | |
b5ce269b BJ |
14 | #pragma implementation |
15 | #pragma interface | |
b5ffecfc GT |
16 | #endif |
17 | //--------------------------------------------------------------------------- | |
18 | // For compilers that support precompilation, includes "wx/wx.h". | |
19 | #include "wx/wxprec.h" | |
20 | //--------------------------------------------------------------------------- | |
21 | #ifdef __BORLANDC__ | |
b5ce269b | 22 | #pragma hdrstop |
b5ffecfc GT |
23 | #endif |
24 | //--------------------------------------------------------------------------- | |
25 | #ifndef WX_PRECOMP | |
b5ce269b | 26 | #include "wx/wx.h" |
b5ffecfc GT |
27 | #endif |
28 | //--------------------------------------------------------------------------- | |
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 GT |
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 | { | |
b5ce269b | 47 | return b ? "" : "not "; |
b5ffecfc GT |
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) | |
b5ce269b BJ |
55 | END_EVENT_TABLE() |
56 | //--------------------------------------------------------------------------- | |
57 | // PgmCtrl implementation | |
58 | //--------------------------------------------------------------------------- | |
59 | IMPLEMENT_DYNAMIC_CLASS(PgmCtrl, wxTreeCtrl) | |
60 | //--------------------------------------------------------------------------- | |
61 | PgmCtrl::PgmCtrl(wxWindow *parent) : wxTreeCtrl(parent) | |
b5ffecfc GT |
62 | { |
63 | } | |
64 | PgmCtrl::PgmCtrl(wxWindow *parent, const wxWindowID id,const wxPoint& pos, const wxSize& size, long style) | |
b5ce269b | 65 | : wxTreeCtrl(parent, id, pos, size, style) |
b5ffecfc | 66 | { |
b5ce269b BJ |
67 | wxFont* ft_Temp = new wxFont(10,wxSWISS,wxNORMAL,wxBOLD,FALSE,"Comic Sans MS"); |
68 | SetFont(* ft_Temp); | |
69 | ||
70 | // Make an image list containing small icons | |
71 | p_imageListNormal = new wxImageList(16, 16, TRUE); | |
72 | ||
73 | // should correspond to TreeIc_xxx enum | |
b5ffecfc | 74 | #if defined(__WXMSW__) && defined(__WIN16__) |
b5ce269b BJ |
75 | // This is required in 16-bit Windows mode only because we can't load a specific (16x16) |
76 | // icon image, so it comes out stretched | |
77 | p_imageListNormal->Add(wxBitmap("bitmap1", wxBITMAP_TYPE_BMP_RESOURCE)); | |
78 | p_imageListNormal->Add(wxBitmap("bitmap2", wxBITMAP_TYPE_BMP_RESOURCE)); | |
b5ffecfc | 79 | #else |
b5ce269b BJ |
80 | p_imageListNormal->Add(wxICON(Logo)); |
81 | p_imageListNormal->Add(wxICON(DsnClosed)); | |
82 | p_imageListNormal->Add(wxICON(DsnOpen)); | |
83 | p_imageListNormal->Add(wxICON(DocClosed)); | |
84 | p_imageListNormal->Add(wxICON(DocOpen)); | |
85 | p_imageListNormal->Add(wxICON(FolderClosed)); | |
86 | p_imageListNormal->Add(wxICON(FolderOpen)); | |
b5ffecfc | 87 | #endif |
b5ce269b BJ |
88 | |
89 | SetImageList(p_imageListNormal); | |
90 | ||
91 | // Add some items to the tree | |
92 | // AddTestItemsToTree(3, 2); | |
b5ffecfc GT |
93 | } |
94 | //--------------------------------------------------------------------------- | |
95 | PgmCtrl::~PgmCtrl() | |
96 | { | |
b5ce269b BJ |
97 | // wxMessageBox("PgmCtrl::~PgmCtrl() - vor DeleteAllItems"); |
98 | // DeleteAllItems(); | |
99 | // wxMessageBox("nach DeleteAllItems"); | |
100 | delete p_imageListNormal; | |
b5ffecfc GT |
101 | } |
102 | //--------------------------------------------------------------------------- | |
103 | #undef TREE_EVENT_HANDLER | |
104 | //--------------------------------------------------------------------------- | |
105 | int PgmCtrl::OnPopulate() | |
106 | { | |
b5ce269b BJ |
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 GT |
139 | } |
140 | //--------------------------------------------------------------------------- | |
141 | void PgmCtrl::OnSelChanged(wxTreeEvent& WXUNUSED(event)) | |
142 | { | |
b5ce269b BJ |
143 | int i; |
144 | Temp0.Empty(); Temp1.Empty(); | |
145 | pDoc->p_MainFrame->SetStatusText(Temp0,0); | |
146 | // Get the Information that we need | |
147 | wxTreeItemId itemId = GetSelection(); | |
148 | TreeData *item = (TreeData *)GetItemData(itemId); | |
149 | if ( item != NULL ) | |
b5ffecfc | 150 | { |
b5ce269b BJ |
151 | int Treffer = 0; |
152 | Temp1.Printf("%s",item->m_desc.c_str()); | |
153 | //----------------------------------------------------------------------------------------- | |
154 | if (Temp1 == "Language English") | |
155 | { | |
156 | Temp0 = "std"; | |
157 | p_ProgramCfg->Write("/Local/langid",Temp0); | |
158 | Temp0 = _("-I-> After a programm restart, the language will be changed to English."); | |
159 | wxMessageBox(Temp0); | |
160 | } | |
161 | if (Temp1 == "Language German") | |
162 | { | |
163 | Temp0 = "de"; | |
164 | p_ProgramCfg->Write("/Local/langid",Temp0); | |
165 | Temp0 = _("-I-> After a programm restart, the language will be changed to German."); | |
166 | wxMessageBox(Temp0); | |
167 | } | |
168 | //----------------------------------------------------------------------------------------- | |
169 | if (Temp1 == "wxConfigBase Delete") | |
170 | { | |
171 | if (p_ProgramCfg->DeleteAll()) // Default Diretory for wxFileSelector | |
172 | Temp0 = _("-I-> wxConfigBase.p_ProgramCfg->DeleteAll() was succesfull."); | |
173 | else | |
174 | Temp0 = _("-E-> wxConfigBase.p_ProgramCfg->DeleteAll() was not succesfull !"); | |
175 | wxBell(); // Ding_a_Ling | |
176 | Treffer++; | |
177 | } | |
178 | //----------------------------------------------------------------------------------------- | |
179 | if (Temp1.Contains("ODBC-")) | |
180 | { | |
181 | Temp1 = Temp1.Mid(5,wxSTRING_MAXLEN); | |
182 | for (i=0;i<pDoc->i_DSN;i++) | |
183 | { | |
184 | if (Temp1 == (pDoc->p_DSN+i)->Dsn) | |
185 | { | |
186 | pDoc->OnChosenDSN(i); | |
187 | } | |
188 | } | |
189 | Treffer++; | |
190 | } | |
191 | //----------------------------------------------------------------------------------------- | |
192 | if (Treffer == 0) | |
193 | { | |
194 | //--------------------------------------------------- | |
195 | Temp0.Printf(_("Item '%s': %sselected, %sexpanded, %sbold," | |
b5ffecfc | 196 | "%u children (%u immediately under this item)."), |
b5ce269b BJ |
197 | item->m_desc.c_str(), |
198 | bool2String(IsSelected(itemId)), | |
199 | bool2String(IsExpanded(itemId)), | |
200 | bool2String(IsBold(itemId)), | |
201 | GetChildrenCount(itemId), | |
202 | GetChildrenCount(itemId)); | |
203 | LogBuf.Printf("-I-> PgmCtrl::OnSelChanged - %s",Temp0.c_str()); | |
204 | wxLogMessage( "%s", LogBuf.c_str() ); | |
205 | //--------------------------------------------------- | |
206 | } | |
207 | } | |
b5ffecfc GT |
208 | } |
209 | //--------------------------------------------------------------------------- | |
210 | void PgmCtrl::OnRightSelect(wxTreeEvent& WXUNUSED(event)) | |
211 | { | |
b5ce269b BJ |
212 | int i; |
213 | Temp0.Empty(); | |
214 | // Get the Information that we need | |
215 | wxTreeItemId itemId = GetSelection(); | |
216 | DBTreeData *item = (DBTreeData *)GetItemData(itemId); | |
217 | SaveDSN.Empty(); | |
218 | if ( item != NULL ) | |
b5ffecfc | 219 | { |
b5ce269b BJ |
220 | int Treffer = 0; |
221 | Temp1.Printf("%s",item->m_desc.c_str()); | |
222 | //----------------------------------------------------------------------------------------- | |
223 | if (Temp1.Contains("ODBC-")) | |
224 | { | |
225 | Temp1 = Temp1.Mid(5,wxSTRING_MAXLEN); | |
226 | for (i=0;i<pDoc->i_DSN;i++) | |
227 | { | |
228 | if (Temp1 == (pDoc->p_DSN+i)->Dsn) | |
229 | { | |
230 | SaveDSN = Temp1; | |
231 | PopupMenu(popupMenu1,TreePos.x,TreePos.y); | |
232 | } | |
233 | } | |
234 | Treffer++; | |
235 | } | |
236 | //----------------------------------------------------------------------------------------- | |
237 | if (Treffer == 0) | |
238 | { | |
239 | //--------------------------------------------------- | |
240 | /* | |
241 | Temp0.Printf(_("Item '%s': %sselected, %sexpanded, %sbold," | |
242 | "%u children (%u immediately under this item)."), | |
243 | item->m_desc.c_str(), | |
244 | bool2String(IsSelected(itemId)), | |
245 | bool2String(IsExpanded(itemId)), | |
b5ffecfc GT |
246 | bool2String(IsBold(itemId)), |
247 | GetChildrenCount(itemId), | |
248 | GetChildrenCount(itemId)); | |
b5ce269b BJ |
249 | LogBuf.Printf("-I-> DBTree::OnSelChanged - %s",Temp0.c_str()); |
250 | wxLogMessage( "%s", LogBuf.c_str() ); | |
251 | */ | |
252 | //--------------------------------------------------- | |
253 | } | |
254 | } | |
b5ffecfc GT |
255 | } |
256 | //------------------------------------------------------------------------------ | |
257 | void PgmCtrl::OnMouseMove(wxMouseEvent &event) | |
258 | { | |
b5ce269b | 259 | TreePos = event.GetPosition(); |
b5ffecfc GT |
260 | } |
261 | //------------------------------------------------------------------------------ | |
262 | void PgmCtrl::OnUserPassword() | |
263 | { | |
b5ce269b BJ |
264 | // wxMessageBox(SaveDSN); |
265 | int i, rc=0; | |
266 | //------------------------------------------- | |
c09d434d | 267 | DlgUser p_Dlg(this, "Username and Password"); |
b5ce269b BJ |
268 | //------------------------------------------- |
269 | for (i=0;i<pDoc->i_DSN;i++) | |
270 | { | |
271 | if (SaveDSN == (pDoc->p_DSN+i)->Dsn) | |
272 | { | |
273 | p_Dlg.s_DSN = (pDoc->p_DSN+i)->Dsn; | |
274 | p_Dlg.s_User = (pDoc->p_DSN+i)->Usr; | |
275 | p_Dlg.s_Password = (pDoc->p_DSN+i)->Pas; | |
276 | p_Dlg.OnInit(); | |
c09d434d | 277 | p_Dlg.Fit(); |
b5ce269b BJ |
278 | //-------------------- |
279 | // 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); | |
280 | // wxMessageBox(Temp0); | |
c09d434d | 281 | bool OK = FALSE; |
b5ce269b BJ |
282 | if (p_Dlg.ShowModal() == wxID_OK) |
283 | { | |
284 | (pDoc->p_DSN+i)->Usr = p_Dlg.s_User; | |
285 | (pDoc->p_DSN+i)->Pas = p_Dlg.s_Password; | |
286 | (pDoc->db_Br+i)->UserName = (pDoc->p_DSN+i)->Usr; | |
287 | (pDoc->db_Br+i)->Password = (pDoc->p_DSN+i)->Pas; | |
c09d434d | 288 | OK = TRUE; |
b5ce269b BJ |
289 | } |
290 | p_Dlg.Destroy(); | |
c09d434d | 291 | if (!OK) return; |
b5ce269b | 292 | //-------------------- |
c09d434d | 293 | break; // We have what we want, leave |
b5ce269b BJ |
294 | } |
295 | } | |
c09d434d | 296 | |
b5ce269b BJ |
297 | //------------------------------------------- |
298 | SaveDSN.Empty(); | |
b5ffecfc GT |
299 | } |
300 | //--------------------------------------------------------------------------- |