]>
git.saurik.com Git - wxWidgets.git/blob - demos/dbbrowse/pgmctrl.cpp
1 //----------------------------------------------------------------------------------------
3 // Purpose: Programm Control with a Tree
4 // Author: Mark Johnson
5 // Modified by: 19990806.mj10777
8 // Copyright: (c) Mark Johnson, Berlin Germany
9 // Licence: wxWindows license
10 //----------------------------------------------------------------------------------------
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
14 //----------------------------------------------------------------------------------------
18 //----------------------------------------------------------------------------------------
22 //----------------------------------------------------------------------------------------
24 #include "bitmaps/d_closed.xpm"
25 #include "bitmaps/d_open.xpm"
26 #include "bitmaps/f_closed.xpm"
27 #include "bitmaps/f_open.xpm"
28 #include "bitmaps/logo.xpm"
29 #include "bitmaps/dsnclose.xpm"
30 #include "bitmaps/dsnopen.xpm"
32 //----------------------------------------------------------------------------------------
33 //-- all #includes that every .cpp needs --- 19990807.mj10777 ----------------
34 //----------------------------------------------------------------------------------------
35 #include "std.h" // sorgsam Pflegen !
37 //----------------------------------------------------------------------------------------
38 //-- Global functions --------------------------------------------------------------------
39 //----------------------------------------------------------------------------------------
40 static inline const wxChar
*bool2String(bool b
)
42 return b
? wxEmptyString
: _T("not ");
45 //----------------------------------------------------------------------------------------
46 BEGIN_EVENT_TABLE(PgmCtrl
, wxTreeCtrl
)
47 EVT_MOTION (PgmCtrl::OnMouseMove
)
48 EVT_LEFT_DCLICK(PgmCtrl::OnSelChanged
)
49 EVT_TREE_ITEM_RIGHT_CLICK(TREE_CTRL_PGM
,PgmCtrl::OnRightSelect
)
50 EVT_MENU(PGMCTRL_ODBC_USER
,PgmCtrl::OnUserPassword
)
53 //----------------------------------------------------------------------------------------
54 // PgmCtrl implementation
55 //----------------------------------------------------------------------------------------
56 IMPLEMENT_DYNAMIC_CLASS(PgmCtrl
, wxTreeCtrl
)
58 //----------------------------------------------------------------------------------------
59 PgmCtrl::PgmCtrl(wxWindow
*parent
) : wxTreeCtrl(parent
)
63 //----------------------------------------------------------------------------------------
64 PgmCtrl::PgmCtrl(wxWindow
*parent
, const wxWindowID id
,const wxPoint
& pos
, const wxSize
& size
, long style
)
65 : wxTreeCtrl(parent
, id
, pos
, size
, style
)
67 const int image_size
= 16;
68 // Make an image list containing small icons
69 p_imageListNormal
= new wxImageList(image_size
, image_size
, true);
70 // should correspond to TreeIc_xxx enum
71 p_imageListNormal
->Add(wxBitmap(wxBitmap(wxICON(aLogo
)).ConvertToImage().Rescale(image_size
, image_size
)));
72 p_imageListNormal
->Add(wxBitmap(wxBitmap(wxICON(DsnClosed
)).ConvertToImage().Rescale(image_size
, image_size
)));
73 p_imageListNormal
->Add(wxBitmap(wxBitmap(wxICON(DsnOpen
)).ConvertToImage().Rescale(image_size
, image_size
)));
74 p_imageListNormal
->Add(wxBitmap(wxBitmap(wxICON(DocClosed
)).ConvertToImage().Rescale(image_size
, image_size
)));
75 p_imageListNormal
->Add(wxBitmap(wxBitmap(wxICON(DocOpen
)).ConvertToImage().Rescale(image_size
, image_size
)));
76 p_imageListNormal
->Add(wxBitmap(wxBitmap(wxICON(FolderClosed
)).ConvertToImage().Rescale(image_size
, image_size
)));
77 p_imageListNormal
->Add(wxBitmap(wxBitmap(wxICON(FolderOpen
)).ConvertToImage().Rescale(image_size
, image_size
)));
78 SetImageList(p_imageListNormal
);
81 //----------------------------------------------------------------------------------------
84 delete p_imageListNormal
;
88 //----------------------------------------------------------------------------------------
89 #undef TREE_EVENT_HANDLER
91 //----------------------------------------------------------------------------------------
92 int PgmCtrl::OnPopulate()
94 SetFont(* pDoc
->ft_Doc
);
95 wxTreeItemId Root
, Folder
, Docu
;
96 //---------------------------------------------------------------------------------------
98 double dTmp
= 1234567.89;
99 Temp0
.Printf(_("%s Functions"),p_ProgramCfg
->GetAppName().c_str());
100 Root
= AddRoot(Temp0
,TreeIc_Logo
,TreeIc_Logo
, new TreeData(_T("Root")));
101 //---------------------------------------------------------------------------------------
102 Folder
= AppendItem(Root
, _("Program settings") ,TreeIc_FolderClosed
, TreeIc_FolderOpen
, new TreeData(_T("Settings")));
103 p_ProgramCfg
->Read(_T("/Local/langid"),&Temp0
); p_ProgramCfg
->Read(_T("/Local/language"),&Temp2
);
104 Temp1
.Printf(_("locale (%s) ; Language (%s) ; Number(%2.2f)"),Temp0
.c_str(), Temp2
.c_str(), dTmp
); Temp0
.Empty(); Temp2
.Empty();
105 Docu
= AppendItem(Folder
, Temp1
,TreeIc_DocClosed
,TreeIc_DocOpen
,new TreeData(_T("Setting Language")));
106 p_ProgramCfg
->Read(_T("/Paths/Work"),&Temp0
); Temp1
.Printf(_("Work Path : %s"),Temp0
.c_str()); Temp0
.Empty();
107 Docu
= AppendItem(Folder
,Temp1
,TreeIc_DocClosed
,TreeIc_DocOpen
,new TreeData(_T("Path Work")));
108 Docu
= AppendItem(Folder
, _("Change the language to English") ,TreeIc_DocClosed
,TreeIc_DocOpen
,new TreeData(_T("Language English")));
109 Docu
= AppendItem(Folder
, _("Change the language to German") ,TreeIc_DocClosed
,TreeIc_DocOpen
,new TreeData(_T("Language German")));
110 Docu
= AppendItem(Folder
, _("Delete all wxConfigBase Entry's"),TreeIc_DocClosed
,TreeIc_DocOpen
,new TreeData(_T("wxConfigBase Delete")));
111 Folder
= AppendItem(Root
, _T("ODBC DSN"),TreeIc_FolderClosed
,TreeIc_FolderOpen
,new TreeData(_T("ODBC-DSN")));
112 for (i
=0;i
<pDoc
->i_DSN
;i
++)
114 Temp0
.Printf(_T("ODBC-%s"),(pDoc
->p_DSN
+i
)->Dsn
.c_str());
115 Docu
= AppendItem(Folder
,(pDoc
->p_DSN
+i
)->Dsn
,TreeIc_DsnClosed
,TreeIc_DsnOpen
, new TreeData(Temp0
));
117 //---------------------------------------------------------------------------------------
119 popupMenu1
= new wxMenu
;
120 popupMenu1
->Append(PGMCTRL_ODBC_USER
, _("Set Username and Password"));
121 // popupMenu1->AppendSeparator();
122 //---------------------------------------------------------------------------------------
125 //---------------------------------------------------------------------------------------
129 //----------------------------------------------------------------------------------------
130 void PgmCtrl::OnSelChanged(wxMouseEvent
& WXUNUSED(event
))
133 Temp0
.Empty(); Temp1
.Empty();
135 pDoc
->p_MainFrame
->SetStatusText(Temp0
,0);
136 #endif // wxUSE_STATUSBAR
137 // Get the Information that we need
138 wxTreeItemId itemId
= GetSelection();
139 TreeData
*item
= (TreeData
*)GetItemData(itemId
);
143 Temp1
.Printf(_T("%s"),item
->m_desc
.c_str());
144 //--------------------------------------------------------------------------------------
145 if (Temp1
== _T("Language English"))
148 p_ProgramCfg
->Write(_T("/Local/langid"),Temp0
);
149 Temp0
= _("-I-> After a programm restart, the language will be changed to English.");
152 if (Temp1
== _T("Language German"))
155 p_ProgramCfg
->Write(_T("/Local/langid"),Temp0
);
156 Temp0
= _("-I-> After a programm restart, the language will be changed to German.");
159 //--------------------------------------------------------------------------------------
160 if (Temp1
== _T("wxConfigBase Delete"))
162 if (p_ProgramCfg
->DeleteAll()) // Default Diretory for wxFileSelector
163 Temp0
= _("-I-> wxConfigBase.p_ProgramCfg->DeleteAll() was successful.");
165 Temp0
= _("-E-> wxConfigBase.p_ProgramCfg->DeleteAll() was not successful !");
166 wxBell(); // Ding_a_Ling
169 //--------------------------------------------------------------------------------------
170 if (Temp1
.Contains(_T("ODBC-")))
172 Temp1
= Temp1
.Mid(5,wxSTRING_MAXLEN
);
173 for (i
=0;i
<pDoc
->i_DSN
;i
++)
175 if (Temp1
== (pDoc
->p_DSN
+i
)->Dsn
)
177 pDoc
->OnChosenDSN(i
);
182 //--------------------------------------------------------------------------------------
185 //-------------------------------------------------------------------------------------
186 Temp0
.Printf(_("Item '%s': %sselected, %sexpanded, %sbold, %u children (%u immediately under this item)."),
187 item
->m_desc
.c_str(),
188 bool2String(IsSelected(itemId
)),
189 bool2String(IsExpanded(itemId
)),
190 bool2String(IsBold(itemId
)),
191 GetChildrenCount(itemId
),
192 GetChildrenCount(itemId
));
193 LogBuf
.Printf(_T("-I-> PgmCtrl::OnSelChanged - %s"),Temp0
.c_str());
194 wxLogMessage( _T("%s"), LogBuf
.c_str() );
195 //-------------------------------------------------------------------------------------
200 //----------------------------------------------------------------------------------------
201 void PgmCtrl::OnRightSelect(wxTreeEvent
& WXUNUSED(event
))
205 // Get the Information that we need
206 wxTreeItemId itemId
= GetSelection();
207 DBTreeData
*item
= (DBTreeData
*)GetItemData(itemId
);
212 Temp1
.Printf(_T("%s"),item
->m_desc
.c_str());
213 //--------------------------------------------------------------------------------------
214 if (Temp1
.Contains(_T("ODBC-")))
216 Temp1
= Temp1
.Mid(5,wxSTRING_MAXLEN
);
217 for (i
=0;i
<pDoc
->i_DSN
;i
++)
219 if (Temp1
== (pDoc
->p_DSN
+i
)->Dsn
)
222 PopupMenu(popupMenu1
,TreePos
.x
,TreePos
.y
);
227 //--------------------------------------------------------------------------------------
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() );
243 //--------------------------------------------------------------------------------------
245 } // void PgmCtrl::OnRightSelect(wxTreeEvent& WXUNUSED(event))
247 //----------------------------------------------------------------------------------------
248 void PgmCtrl::OnMouseMove(wxMouseEvent
&event
)
250 TreePos
= event
.GetPosition();
253 //----------------------------------------------------------------------------------------
254 void PgmCtrl::OnUserPassword(wxCommandEvent
& WXUNUSED(event
))
256 // wxMessageBox(SaveDSN);
258 //--------------------------------------------
259 DlgUser
*p_Dlg
= new DlgUser(this,pDoc
,wxEmptyString
);
260 //-------------------------------------------
261 for (i
=0;i
<pDoc
->i_DSN
;i
++)
264 if (SaveDSN
== (pDoc
->p_DSN
+i
)->Dsn
)
267 p_Dlg
->s_DSN
= (pDoc
->p_DSN
+i
)->Dsn
;
268 p_Dlg
->s_User
= (pDoc
->p_DSN
+i
)->Usr
;
269 p_Dlg
->s_Password
= (pDoc
->p_DSN
+i
)->Pas
;
272 //--------------------
273 // 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);
274 // wxMessageBox(Temp0);
276 if (p_Dlg
->ShowModal() == wxID_OK
)
278 (pDoc
->p_DSN
+i
)->Usr
= p_Dlg
->s_User
;
279 (pDoc
->p_DSN
+i
)->Pas
= p_Dlg
->s_Password
;
280 (pDoc
->db_Br
+i
)->UserName
= (pDoc
->p_DSN
+i
)->Usr
;
281 (pDoc
->db_Br
+i
)->Password
= (pDoc
->p_DSN
+i
)->Pas
;
287 //--------------------
288 break; // We have what we want, leave
291 //-------------------------------------------
294 //----------------------------------------------------------------------------------------