]>
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 //----------------------------------------------------------------------------------------
11 //-- all #ifdefs that the whole Project needs. -------------------------------------------
12 //----------------------------------------------------------------------------------------
14 #pragma implementation
17 //----------------------------------------------------------------------------------------
18 // For compilers that support precompilation, includes "wx/wx.h".
19 #include "wx/wxprec.h"
20 //----------------------------------------------------------------------------------------
24 //----------------------------------------------------------------------------------------
28 //----------------------------------------------------------------------------------------
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"
38 //----------------------------------------------------------------------------------------
39 //-- all #includes that every .cpp needs --- 19990807.mj10777 ----------------
40 //----------------------------------------------------------------------------------------
41 #include "std.h" // sorgsam Pflegen !
43 //----------------------------------------------------------------------------------------
44 //-- Global functions --------------------------------------------------------------------
45 //----------------------------------------------------------------------------------------
46 static inline const wxChar
*bool2String(bool b
)
48 return b
? _T("") : _T("not ");
51 //----------------------------------------------------------------------------------------
52 BEGIN_EVENT_TABLE(PgmCtrl
, wxTreeCtrl
)
53 EVT_MOTION (PgmCtrl::OnMouseMove
)
54 EVT_LEFT_DCLICK(PgmCtrl::OnSelChanged
)
55 EVT_TREE_ITEM_RIGHT_CLICK(TREE_CTRL_PGM
,PgmCtrl::OnRightSelect
)
56 EVT_MENU(PGMCTRL_ODBC_USER
,PgmCtrl::OnUserPassword
)
59 //----------------------------------------------------------------------------------------
60 // PgmCtrl implementation
61 //----------------------------------------------------------------------------------------
62 IMPLEMENT_DYNAMIC_CLASS(PgmCtrl
, wxTreeCtrl
)
64 //----------------------------------------------------------------------------------------
65 PgmCtrl::PgmCtrl(wxWindow
*parent
) : wxTreeCtrl(parent
)
69 //----------------------------------------------------------------------------------------
70 PgmCtrl::PgmCtrl(wxWindow
*parent
, const wxWindowID id
,const wxPoint
& pos
, const wxSize
& size
, long style
)
71 : wxTreeCtrl(parent
, id
, pos
, size
, style
)
73 const int image_size
= 16;
74 // Make an image list containing small icons
75 p_imageListNormal
= new wxImageList(image_size
, image_size
, true);
76 // should correspond to TreeIc_xxx enum
77 p_imageListNormal
->Add(wxBitmap(wxBitmap(wxICON(aLogo
)).ConvertToImage().Rescale(image_size
, image_size
)));
78 p_imageListNormal
->Add(wxBitmap(wxBitmap(wxICON(DsnClosed
)).ConvertToImage().Rescale(image_size
, image_size
)));
79 p_imageListNormal
->Add(wxBitmap(wxBitmap(wxICON(DsnOpen
)).ConvertToImage().Rescale(image_size
, image_size
)));
80 p_imageListNormal
->Add(wxBitmap(wxBitmap(wxICON(DocClosed
)).ConvertToImage().Rescale(image_size
, image_size
)));
81 p_imageListNormal
->Add(wxBitmap(wxBitmap(wxICON(DocOpen
)).ConvertToImage().Rescale(image_size
, image_size
)));
82 p_imageListNormal
->Add(wxBitmap(wxBitmap(wxICON(FolderClosed
)).ConvertToImage().Rescale(image_size
, image_size
)));
83 p_imageListNormal
->Add(wxBitmap(wxBitmap(wxICON(FolderOpen
)).ConvertToImage().Rescale(image_size
, image_size
)));
84 SetImageList(p_imageListNormal
);
87 //----------------------------------------------------------------------------------------
90 delete p_imageListNormal
;
94 //----------------------------------------------------------------------------------------
95 #undef TREE_EVENT_HANDLER
97 //----------------------------------------------------------------------------------------
98 int PgmCtrl::OnPopulate()
100 SetFont(* pDoc
->ft_Doc
);
101 wxTreeItemId Root
, Folder
, Docu
;
102 //---------------------------------------------------------------------------------------
104 double dTmp
= 1234567.89;
105 Temp0
.Printf(_("%s Functions"),p_ProgramCfg
->GetAppName().c_str());
106 Root
= AddRoot(Temp0
,TreeIc_Logo
,TreeIc_Logo
, new TreeData(_T("Root")));
107 //---------------------------------------------------------------------------------------
108 Folder
= AppendItem(Root
, _("Program settings") ,TreeIc_FolderClosed
, TreeIc_FolderOpen
, new TreeData(_T("Settings")));
109 p_ProgramCfg
->Read(_T("/Local/langid"),&Temp0
); p_ProgramCfg
->Read(_T("/Local/language"),&Temp2
);
110 Temp1
.Printf(_("locale (%s) ; Language (%s) ; Number(%2.2f)"),Temp0
.c_str(), Temp2
.c_str(), dTmp
); Temp0
.Empty(); Temp2
.Empty();
111 Docu
= AppendItem(Folder
, Temp1
,TreeIc_DocClosed
,TreeIc_DocOpen
,new TreeData(_T("Setting Language")));
112 p_ProgramCfg
->Read(_T("/Paths/Work"),&Temp0
); Temp1
.Printf(_("Work Path : %s"),Temp0
.c_str()); Temp0
.Empty();
113 Docu
= AppendItem(Folder
,Temp1
,TreeIc_DocClosed
,TreeIc_DocOpen
,new TreeData(_T("Path Work")));
114 Docu
= AppendItem(Folder
, _("Change the language to English") ,TreeIc_DocClosed
,TreeIc_DocOpen
,new TreeData(_T("Language English")));
115 Docu
= AppendItem(Folder
, _("Change the language to German") ,TreeIc_DocClosed
,TreeIc_DocOpen
,new TreeData(_T("Language German")));
116 Docu
= AppendItem(Folder
, _("Delete all wxConfigBase Entry's"),TreeIc_DocClosed
,TreeIc_DocOpen
,new TreeData(_T("wxConfigBase Delete")));
117 Folder
= AppendItem(Root
, _T("ODBC DSN"),TreeIc_FolderClosed
,TreeIc_FolderOpen
,new TreeData(_T("ODBC-DSN")));
118 for (i
=0;i
<pDoc
->i_DSN
;i
++)
120 Temp0
.Printf(_T("ODBC-%s"),(pDoc
->p_DSN
+i
)->Dsn
.c_str());
121 Docu
= AppendItem(Folder
,(pDoc
->p_DSN
+i
)->Dsn
,TreeIc_DsnClosed
,TreeIc_DsnOpen
, new TreeData(Temp0
));
123 //---------------------------------------------------------------------------------------
125 popupMenu1
= new wxMenu(_T(""));
126 popupMenu1
->Append(PGMCTRL_ODBC_USER
, _("Set Username and Password"));
127 // popupMenu1->AppendSeparator();
128 //---------------------------------------------------------------------------------------
131 //---------------------------------------------------------------------------------------
135 //----------------------------------------------------------------------------------------
136 void PgmCtrl::OnSelChanged(wxMouseEvent
& WXUNUSED(event
))
139 Temp0
.Empty(); Temp1
.Empty();
140 pDoc
->p_MainFrame
->SetStatusText(Temp0
,0);
141 // Get the Information that we need
142 wxTreeItemId itemId
= GetSelection();
143 TreeData
*item
= (TreeData
*)GetItemData(itemId
);
147 Temp1
.Printf(_T("%s"),item
->m_desc
.c_str());
148 //--------------------------------------------------------------------------------------
149 if (Temp1
== _T("Language English"))
152 p_ProgramCfg
->Write(_T("/Local/langid"),Temp0
);
153 Temp0
= _("-I-> After a programm restart, the language will be changed to English.");
156 if (Temp1
== _T("Language German"))
159 p_ProgramCfg
->Write(_T("/Local/langid"),Temp0
);
160 Temp0
= _("-I-> After a programm restart, the language will be changed to German.");
163 //--------------------------------------------------------------------------------------
164 if (Temp1
== _T("wxConfigBase Delete"))
166 if (p_ProgramCfg
->DeleteAll()) // Default Diretory for wxFileSelector
167 Temp0
= _("-I-> wxConfigBase.p_ProgramCfg->DeleteAll() was succesfull.");
169 Temp0
= _("-E-> wxConfigBase.p_ProgramCfg->DeleteAll() was not succesfull !");
170 wxBell(); // Ding_a_Ling
173 //--------------------------------------------------------------------------------------
174 if (Temp1
.Contains(_T("ODBC-")))
176 Temp1
= Temp1
.Mid(5,wxSTRING_MAXLEN
);
177 for (i
=0;i
<pDoc
->i_DSN
;i
++)
179 if (Temp1
== (pDoc
->p_DSN
+i
)->Dsn
)
181 pDoc
->OnChosenDSN(i
);
186 //--------------------------------------------------------------------------------------
189 //-------------------------------------------------------------------------------------
190 Temp0
.Printf(_("Item '%s': %sselected, %sexpanded, %sbold, %u children (%u immediately under this item)."),
191 item
->m_desc
.c_str(),
192 bool2String(IsSelected(itemId
)),
193 bool2String(IsExpanded(itemId
)),
194 bool2String(IsBold(itemId
)),
195 GetChildrenCount(itemId
),
196 GetChildrenCount(itemId
));
197 LogBuf
.Printf(_T("-I-> PgmCtrl::OnSelChanged - %s"),Temp0
.c_str());
198 wxLogMessage( _T("%s"), LogBuf
.c_str() );
199 //-------------------------------------------------------------------------------------
204 //----------------------------------------------------------------------------------------
205 void PgmCtrl::OnRightSelect(wxTreeEvent
& WXUNUSED(event
))
209 // Get the Information that we need
210 wxTreeItemId itemId
= GetSelection();
211 DBTreeData
*item
= (DBTreeData
*)GetItemData(itemId
);
216 Temp1
.Printf(_T("%s"),item
->m_desc
.c_str());
217 //--------------------------------------------------------------------------------------
218 if (Temp1
.Contains(_T("ODBC-")))
220 Temp1
= Temp1
.Mid(5,wxSTRING_MAXLEN
);
221 for (i
=0;i
<pDoc
->i_DSN
;i
++)
223 if (Temp1
== (pDoc
->p_DSN
+i
)->Dsn
)
226 PopupMenu(popupMenu1
,TreePos
.x
,TreePos
.y
);
231 //--------------------------------------------------------------------------------------
235 Temp0.Printf(_("Item '%s': %sselected, %sexpanded, %sbold,"
236 "%u children (%u immediately under this item)."),
237 item->m_desc.c_str(),
238 bool2String(IsSelected(itemId)),
239 bool2String(IsExpanded(itemId)),
240 bool2String(IsBold(itemId)),
241 GetChildrenCount(itemId),
242 GetChildrenCount(itemId));
243 LogBuf.Printf("-I-> DBTree::OnSelChanged - %s",Temp0.c_str());
244 wxLogMessage( "%s", LogBuf.c_str() );
247 //--------------------------------------------------------------------------------------
249 } // void PgmCtrl::OnRightSelect(wxTreeEvent& WXUNUSED(event))
251 //----------------------------------------------------------------------------------------
252 void PgmCtrl::OnMouseMove(wxMouseEvent
&event
)
254 TreePos
= event
.GetPosition();
257 //----------------------------------------------------------------------------------------
258 void PgmCtrl::OnUserPassword(wxCommandEvent
& WXUNUSED(event
))
260 // wxMessageBox(SaveDSN);
262 //--------------------------------------------
263 DlgUser
*p_Dlg
= new DlgUser(this,pDoc
,_T(""));
264 //-------------------------------------------
265 for (i
=0;i
<pDoc
->i_DSN
;i
++)
268 if (SaveDSN
== (pDoc
->p_DSN
+i
)->Dsn
)
271 p_Dlg
->s_DSN
= (pDoc
->p_DSN
+i
)->Dsn
;
272 p_Dlg
->s_User
= (pDoc
->p_DSN
+i
)->Usr
;
273 p_Dlg
->s_Password
= (pDoc
->p_DSN
+i
)->Pas
;
276 //--------------------
277 // 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);
278 // wxMessageBox(Temp0);
280 if (p_Dlg
->ShowModal() == wxID_OK
)
282 (pDoc
->p_DSN
+i
)->Usr
= p_Dlg
->s_User
;
283 (pDoc
->p_DSN
+i
)->Pas
= p_Dlg
->s_Password
;
284 (pDoc
->db_Br
+i
)->UserName
= (pDoc
->p_DSN
+i
)->Usr
;
285 (pDoc
->db_Br
+i
)->Password
= (pDoc
->p_DSN
+i
)->Pas
;
291 //--------------------
292 break; // We have what we want, leave
295 //-------------------------------------------
298 //----------------------------------------------------------------------------------------