NCBI C++ ToolKit
select_sequence_dlg.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: select_sequence_dlg.cpp 35537 2016-05-18 17:18:09Z katargir $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 ////@begin includes
32 #include "wx/imaglist.h"
33 ////@end includes
34 
35 #include <wx/msgdlg.h>
36 #include <wx/sizer.h>
37 #include <wx/button.h>
38 
39 #include "select_sequence_dlg.hpp"
40 
42 
44 
45 /*!
46  * CSelectSequenceDlg type definition
47  */
48 
49 IMPLEMENT_DYNAMIC_CLASS( CSelectSequenceDlg, CDialog )
50 
51 
52 /*!
53  * CSelectSequenceDlg event table definition
54  */
55 
56 BEGIN_EVENT_TABLE( CSelectSequenceDlg, CDialog )
57 
58 ////@begin CSelectSequenceDlg event table entries
60 
61 ////@end CSelectSequenceDlg event table entries
62 
64 
65 
66 /*!
67  * CSelectSequenceDlg constructors
68  */
69 
71 {
72  Init();
73 }
74 
75 CSelectSequenceDlg::CSelectSequenceDlg(wxWindow* parent, vector<CFlatFileSeq>& seqs, const wxString& select)
76  : m_SequenceId(select), m_Seqs(&seqs)
77 {
78  Init();
80 }
81 
82 
83 
84 /*!
85  * CSelectSequenceDlg creator
86  */
87 
88 bool CSelectSequenceDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
89 {
90 ////@begin CSelectSequenceDlg creation
91  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
92  CDialog::Create( parent, id, caption, pos, size, style );
93 
95  if (GetSizer())
96  {
97  GetSizer()->SetSizeHints(this);
98  }
99  Centre();
100 ////@end CSelectSequenceDlg creation
101  return true;
102 }
103 
104 
105 /*!
106  * CSelectSequenceDlg destructor
107  */
108 
110 {
111 ////@begin CSelectSequenceDlg destruction
112 ////@end CSelectSequenceDlg destruction
113 }
114 
115 
116 /*!
117  * Member initialisation
118  */
119 
121 {
122 ////@begin CSelectSequenceDlg member initialisation
123  m_SeqList = NULL;
124 ////@end CSelectSequenceDlg member initialisation
125 }
126 
127 class CListCtrlSeqs : public wxListCtrl
128 {
129  DECLARE_EVENT_TABLE()
130 
131 public:
132  CListCtrlSeqs(wxWindow* parent,
133  wxWindowID id,
134  const wxPoint& pos,
135  const wxSize& size,
136  long style);
137 
138  virtual wxString OnGetItemText(long item, long column) const;
139  void OnSize(wxSizeEvent& event);
140 
141  void SetSeqs(vector<CFlatFileSeq>& seqs);
142 
143 private:
144  vector<CFlatFileSeq>* m_Seqs;
145 };
146 
147 BEGIN_EVENT_TABLE( CListCtrlSeqs, wxListCtrl )
148  EVT_SIZE( CListCtrlSeqs::OnSize )
150 
151 
152 CListCtrlSeqs::CListCtrlSeqs(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
153  : wxListCtrl(parent, id, pos, size, style)
154 {
155  AppendColumn(wxT("Sequence Id"));
156 }
157 
158 void CListCtrlSeqs::OnSize(wxSizeEvent& event)
159 {
160  wxRect rect = GetClientRect();
161  SetColumnWidth(0, rect.GetWidth());
162  event.Skip();
163 }
164 
165 void CListCtrlSeqs::SetSeqs(vector<CFlatFileSeq>& seqs)
166 {
167  m_Seqs = &seqs;
168  SetItemCount((long)m_Seqs->size());
169 }
170 
171 wxString CListCtrlSeqs::OnGetItemText(long item, long column) const
172 {
173  if (column != 0 || !m_Seqs || (size_t)item >= m_Seqs->size())
174  return wxEmptyString;
175 
176  return ToWxString((*m_Seqs)[item].m_Name);
177 }
178 
179 
180 /*!
181  * Control creation for CSelectSequenceDlg
182  */
183 
185 {
186 ////@begin CSelectSequenceDlg content construction
187  CSelectSequenceDlg* itemCDialog1 = this;
188 
189  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
190  itemCDialog1->SetSizer(itemBoxSizer2);
191 
192  m_SeqList = new CListCtrlSeqs( itemCDialog1, ID_LISTCTRL, wxDefaultPosition, itemCDialog1->ConvertDialogToPixels(wxSize(100, 150)), wxLC_REPORT|wxLC_VIRTUAL|wxLC_SINGLE_SEL );
193  itemBoxSizer2->Add(m_SeqList, 1, wxGROW|wxALL, 5);
194 
195  wxStdDialogButtonSizer* itemStdDialogButtonSizer4 = new wxStdDialogButtonSizer;
196 
197  itemBoxSizer2->Add(itemStdDialogButtonSizer4, 0, wxALIGN_RIGHT|wxALL, 5);
198  wxButton* itemButton5 = new wxButton( itemCDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
199  itemStdDialogButtonSizer4->AddButton(itemButton5);
200 
201  wxButton* itemButton6 = new wxButton( itemCDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
202  itemStdDialogButtonSizer4->AddButton(itemButton6);
203 
204  itemStdDialogButtonSizer4->Realize();
205 
206 ////@end CSelectSequenceDlg content construction
207 
209  if (!m_SequenceId.empty()) {
210  for (size_t i = 0; i < m_Seqs->size(); ++i) {
211  if ((*m_Seqs)[i].m_Name == m_SequenceId) {
212  m_SeqList->SetItemState((long)i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
213  m_SeqList->EnsureVisible((long)i);
214  }
215  }
216  }
217 }
218 
220 {
221  if (m_SeqList->GetSelectedItemCount() != 1) {
222  wxMessageBox(wxT("Please, select sequence id."), wxT("Error"),
223  wxOK | wxICON_ERROR, this);
224  return false;
225  }
226 
227  long item = -1;
228  item = m_SeqList->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
229  m_SequenceId = m_SeqList->GetItemText(item);
230  return CDialog::TransferDataFromWindow();
231 }
232 
233 /*!
234  * Should we show tooltips?
235  */
236 
238 {
239  return true;
240 }
241 
242 /*!
243  * Get bitmap resources
244  */
245 
246 wxBitmap CSelectSequenceDlg::GetBitmapResource( const wxString& name )
247 {
248  // Bitmap retrieval
249 ////@begin CSelectSequenceDlg bitmap retrieval
250  wxUnusedVar(name);
251  return wxNullBitmap;
252 ////@end CSelectSequenceDlg bitmap retrieval
253 }
254 
255 /*!
256  * Get icon resources
257  */
258 
259 wxIcon CSelectSequenceDlg::GetIconResource( const wxString& name )
260 {
261  // Icon retrieval
262 ////@begin CSelectSequenceDlg icon retrieval
263  wxUnusedVar(name);
264  return wxNullIcon;
265 ////@end CSelectSequenceDlg icon retrieval
266 }
267 
269 {
271  EndModal(wxID_OK);
272 }
273 
#define ID_LISTCTRL
CDialog.
Definition: dialog.hpp:47
virtual void EndModal(int retCode)
Definition: dialog.cpp:142
void OnSize(wxSizeEvent &event)
vector< CFlatFileSeq > * m_Seqs
virtual wxString OnGetItemText(long item, long column) const
void SetSeqs(vector< CFlatFileSeq > &seqs)
CListCtrlSeqs(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style)
void CreateControls()
Creates the controls and sizers.
bool Create(wxWindow *parent, wxWindowID id=ID_CSELECTSEQUENCEDLG, const wxString &caption=_("Select Sequence to View"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(266, 184), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
virtual bool TransferDataFromWindow()
CSelectSequenceDlg()
Constructors.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void Init()
Initialises member variables.
~CSelectSequenceDlg()
Destructor.
void OnListctrlItemActivated(wxListEvent &event)
wxEVT_COMMAND_LIST_ITEM_ACTIVATED event handler for ID_LISTCTRL
vector< CFlatFileSeq > * m_Seqs
static bool ShowToolTips()
Should we show tooltips?
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
END_EVENT_TABLE()
int i
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
#define SYMBOL_CSELECTSEQUENCEDLG_POSITION
#define SYMBOL_CSELECTSEQUENCEDLG_TITLE
#define SYMBOL_CSELECTSEQUENCEDLG_SIZE
#define SYMBOL_CSELECTSEQUENCEDLG_IDNAME
#define SYMBOL_CSELECTSEQUENCEDLG_STYLE
static const char * column
Definition: stats.c:23
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
#define const
Definition: zconf.h:230
Modified on Sun Mar 03 03:10:23 2024 by modify_doxy.py rev. 669887