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

Go to the SVN repository for this file.

1 /* $Id: main_frame.cpp 39675 2017-10-26 15:13:40Z 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: Andrey Yazhuk
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 
32 #include <wx/platform.h>
33 
35 
38 
39 #include <wx/menu.h>
40 
41 
43 
44 
45 BEGIN_EVENT_TABLE( CMainFrame, CMainFrame::TParent )
47 #ifdef NCBI_OS_MSWIN
48  EVT_ACTIVATE(CMainFrame::OnActivate)
49 #endif
51 
52 
54 {
55 }
56 
57 
58 CMainFrame::CMainFrame( wxWindow* parent, wxWindowID id, const wxString& caption,
59  const wxPoint& pos, const wxSize& size, long style )
60 : TParent(parent, id, caption, pos, size, style),
61  m_HintListener(NULL)
62 #ifdef NCBI_OS_MSWIN
63  , m_ModalCounter(0)
64  , m_MenuFocusWnd()
65 #endif
66 {
67 }
68 
69 
71 {
72 }
73 
74 
76 {
77  m_HintListener = listener;
78 }
79 
80 
81 void CMainFrame::SetRegistryPath(const string& path)
82 {
83  m_RegPath = path;
84 }
85 
86 
87 static const char* kWinRectTag = "WindowRect";
88 static const char* kMaxTag = "Maximized";
89 
91 {
92  if( ! m_RegPath.empty()) {
93  // load window rect
94  wxRect rc = GetRect();
95  CRegistryReadView view =
98  CorrectWindowRect(this, rc);
99  SetSize(rc);
100 
101  bool max = view.GetBool(kMaxTag, true);
102  if(max) {
103  Maximize();
104  }
105 
106  }
107 }
108 
109 
111 {
112  if( ! m_RegPath.empty()) {
113  CRegistryWriteView view =
115  SaveWindowRectToRegistry(GetRect(), view);
116 
117  bool max = IsMaximized();
118  view.Set(kMaxTag, max);
119  }
120 }
121 
122 
123 void CMainFrame::DoGiveHelp(const wxString& text, bool show)
124 {
125  /// instead of accessing Status Bar directly (this may be destructive)
126  /// we forward messages to the provided interface
127  if(m_HintListener) {
128  if(show) {
129  string s = ToStdString(text);
131  } else {
133  }
134  }
135 }
136 
137 
138 void CMainFrame::OnExitClick( wxCommandEvent& WXUNUSED(event) )
139 {
140  wxFrame::Close(false);
141 }
142 
143 #ifdef NCBI_OS_MSWIN
144 
145 void CMainFrame::OnActivate(wxActivateEvent& event)
146 {
147  if (m_MenuFocusWnd == 0)
148  event.Skip();
149 }
150 
151 /// To make modal dialogs truly modal we need to disable all top-level windows
152 /// in the application when a modal dialog box is shown. Enabling all windows
153 /// will guarantee that they do not get user input.
154 /// When the system show a modal dialog it send WM_ENABLE (false) event to the
155 /// main application window, when the dialog is closed WM_ENABLE (true) is sent.
156 /// We handle these events and enabled / disbale child frames.
157 
158 WXLRESULT CMainFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
159 {
160  WXLRESULT rc;
161 
162  if (message == WM_MOUSEACTIVATE && LOWORD(lParam) == HTMENU) {
163  x_SaveMenuFocus();
164  }
165 
166  // for most messages we should return 0 when we do process the message
167  rc = TParent::MSWWindowProc(message, wParam, lParam);
168 
169  if( message == WM_ENABLE) {
170  _ASSERT(m_ModalCounter >= 0);
171 
172  bool enable = (wParam == TRUE);
173 
174  //LOG_POST("");
175  //LOG_POST("Main frame - handling WM_ENABLE" << enable);
176 
177  wxWindowList& children = GetChildren();
178 
179  wxWindowList::compatibility_iterator node = children.GetFirst();
180  while (node)
181  {
182  wxWindow *child = node->GetData();
183  wxFrame* frame = dynamic_cast<wxFrame*>(child);
184  if(frame) {
185  //LOG_POST("Enabling window " << frame->GetHWND() << " " << enable);
186  frame->Enable(enable);
187  }
188 
189  node = node->GetNext();
190  }
191  }
192  else if (message == WM_EXITMENULOOP) {
194  }
195 
196  return rc;
197 }
198 
200 {
201  m_MenuFocusWnd = FindFocus();
202  if (m_MenuFocusWnd == 0)
203  return;
204 
205  if (wxGetTopLevelParent(m_MenuFocusWnd) == this)
206  m_MenuFocusWnd = 0;
207 }
208 
210 {
211  if (m_MenuFocusWnd) {
212  m_MenuFocusWnd->SetFocus();
213  m_MenuFocusWnd = 0;
214  }
215 }
216 
217 #endif
218 
IHintListener - an interface for a component that shows command help hints.
Definition: main_frame.hpp:57
virtual void ShowCommandHint(const string &text)=0
virtual void HideCommandHint()=0
CMainFrame Base class for Application Main Frame, derive your frames from this one.
Definition: main_frame.hpp:52
virtual void SetHintListener(IHintListener *listener)
Definition: main_frame.cpp:75
void OnActivate(wxActivateEvent &event)
Definition: main_frame.cpp:145
wxFrame TParent
Definition: main_frame.hpp:65
virtual void SetRegistryPath(const string &path)
Definition: main_frame.cpp:81
virtual void DoGiveHelp(const wxString &text, bool show)
overriding these function to make it less intrusive
Definition: main_frame.cpp:123
void x_SaveMenuFocus()
Definition: main_frame.cpp:199
virtual void LoadSettings()
Definition: main_frame.cpp:90
virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
Override wxFrame::MSWWindowProc() in order to handle WM_ENABLE event.
Definition: main_frame.cpp:158
int m_ModalCounter
Definition: main_frame.hpp:104
void OnExitClick(wxCommandEvent &event)
Definition: main_frame.cpp:138
IHintListener * m_HintListener
path in registry
Definition: main_frame.hpp:101
void x_RestoreMenuFocus()
Definition: main_frame.cpp:209
wxWindow * m_MenuFocusWnd
Definition: main_frame.hpp:105
virtual void SaveSettings() const
Definition: main_frame.cpp:110
CMainFrame()
Constructors.
Definition: main_frame.cpp:53
string m_RegPath
Definition: main_frame.hpp:99
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
bool GetBool(const string &key, bool default_val=false) const
Definition: reg_view.cpp:241
void Set(const string &key, int val)
access a named key at this level, with no recursion
Definition: reg_view.cpp:533
CRegistryWriteView GetWriteView(const string &section)
CRegistryReadView GetReadView(const string &section) const
static CWndLayoutReg & GetInstance()
#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()
static const char * kMaxTag
Definition: main_frame.cpp:88
static const char * kWinRectTag
Definition: main_frame.cpp:87
static void text(MDB_val *v)
Definition: mdb_dump.c:62
const struct ncbi::grid::netcache::search::fields::SIZE size
#define TRUE
bool replacment for C indicating true.
Definition: ncbi_std.h:97
#define NCBI_OS_MSWIN
Definition: ncbiconf_msvc.h:19
T max(T x_, T y_)
ViewerWindowBase::OnEditMenu ViewerWindowBase::OnJustification EVT_MENU(MID_SHOW_GEOM_VLTNS, ViewerWindowBase::OnShowGeomVltns) EVT_MENU(MID_FIND_PATTERN
#define _ASSERT
void LoadWindowRectFromRegistry(wxRect &rc, const CRegistryReadView &view)
Definition: wx_utils.cpp:1018
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
void CorrectWindowRect(wxTopLevelWindow *win, wxRect &rc)
Definition: wx_utils.cpp:1026
void SaveWindowRectToRegistry(const wxRect &rc, CRegistryWriteView view)
Definition: wx_utils.cpp:1009
Modified on Mon May 13 04:33:05 2024 by modify_doxy.py rev. 669887