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