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