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

Go to the SVN repository for this file.

1 /* $Id: dialog.cpp 46560 2021-07-12 15:02:25Z asztalos $
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  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
37 
38 #include <wx/display.h>
39 #include <wx/app.h>
40 
42 
44 {
45  wxAcceleratorEntry entries[6];
46 
47  entries[0].Set(wxACCEL_CMD, (int) 'C', wxID_COPY);
48  entries[1].Set(wxACCEL_CMD, (int) 'X', wxID_CUT);
49  entries[2].Set(wxACCEL_CMD, (int) 'V', wxID_PASTE);
50  entries[3].Set(wxACCEL_CMD, (int) 'A', wxID_SELECTALL);
51  entries[4].Set(wxACCEL_CMD, 384, wxID_COPY);
52  entries[5].Set(wxACCEL_SHIFT, 384, wxID_PASTE);
53 
54  wxAcceleratorTable accel(6, entries);
55  SetAcceleratorTable(accel);
56 }
57 
58 
59 void CDialog::SetRegistryPath(const string& path)
60 {
61  m_RegPath = path; // store for later use
62 }
63 
64 
65 static const char* kWinRectTag = "WindowRect";
66 
68 {
69  if( ! m_RegPath.empty()) {
70  SaveWindowRectToRegistry(GetRect(),
71  CWndLayoutReg::GetInstance().GetWriteView(m_RegPath + "." + kWinRectTag));
72 
74  x_SaveSettings(view);
75  }
76 }
77 
78 void CDialog::x_CorrectDisplay(wxRect& rc)
79 {
80  auto parent = this->GetParent() ? this->GetParent() : wxTheApp->GetTopWindow();
81  if (!parent)
82  return;
84  if (!gui_reg.GetBool("GBENCH.Application.ViewOptions.SameScreenDialogs", false))
85  return;
86 
87  // At edge of screen somtimes GetFromWindow does not work
88  int display_idx = wxDisplay::GetFromPoint(rc.GetPosition());
89  int parent_display_idx = wxDisplay::GetFromWindow(parent);
90  // In unlikely event still not found, pick 0
91  if (parent_display_idx != wxNOT_FOUND && display_idx != parent_display_idx) {
92  wxDisplay display0(display_idx);
93  wxRect geometry0 = display0.GetGeometry();
94  wxDisplay display(parent_display_idx);
95  wxRect geometry = display.GetGeometry();
96 
97  if (geometry0.GetWidth() > 0) {
98  float offset_x = max<float>(0., rc.GetX() - geometry0.GetX());
99  offset_x /= geometry0.GetWidth();
100  rc.SetLeft(geometry.GetX() + round(offset_x * geometry.GetWidth()));
101  }
102  if (geometry0.GetHeight() > 0) {
103  float offset_y = max<float>(0., rc.GetY() - geometry0.GetY());
104  offset_y /= geometry0.GetHeight();
105  rc.SetTop(geometry.GetY() + round(offset_y * geometry.GetHeight()));
106  }
107  CorrectWindowRect(this, rc);
108  }
109 
110 }
111 
113 {
114  if( ! m_RegPath.empty()) {
115  wxRect rc = GetRect();
117  CWndLayoutReg::GetInstance().GetReadView(m_RegPath + "." + kWinRectTag));
118 
119  CorrectWindowRect(this, rc);
120  x_CorrectDisplay(rc);
121 
122  long style = GetWindowStyleFlag();
123  if (style&wxRESIZE_BORDER)
124  SetSize(rc);
125  else
126  Move(rc.GetLeftTop());
127 
129  x_LoadSettings(view);
130  }
131 }
132 
133 
135 {
136  LoadSettings();
137 
138  wxDialog::InitDialog();
139 }
140 
141 
142 void CDialog::EndModal(int retCode)
143 {
144  SaveSettings();
145 
146  wxDialog::EndModal(retCode);
147 }
148 
149 
T round(const T &v)
virtual void x_SaveSettings(CRegistryWriteView) const
Definition: dialog.hpp:64
virtual void EndModal(int retCode)
Definition: dialog.cpp:142
virtual void InitDialog()
Definition: dialog.cpp:134
virtual void x_LoadSettings(const CRegistryReadView &)
override these functions in derived classes
Definition: dialog.hpp:63
virtual void SaveSettings() const
Definition: dialog.cpp:67
virtual void SetRegistryPath(const string &path)
Definition: dialog.cpp:59
void x_CorrectDisplay(wxRect &rc)
move to the parent display
Definition: dialog.cpp:78
virtual void LoadSettings()
Definition: dialog.cpp:112
string m_RegPath
Definition: dialog.hpp:70
CDialog()
Definition: dialog.cpp:43
CRegistryWriteView GetWriteView(const string &section)
get a read-write view at a particular level.
Definition: registry.cpp:462
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
CRegistryReadView GetReadView(const string &section) const
get a read-only view at a particular level.
Definition: registry.cpp:428
bool GetBool(const string &key, bool default_val=false) const
Definition: registry.cpp:143
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
static CWndLayoutReg & GetInstance()
static const char * kWinRectTag
Definition: dialog.cpp:65
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static wxAcceleratorEntry entries[3]
void LoadWindowRectFromRegistry(wxRect &rc, const CRegistryReadView &view)
Definition: wx_utils.cpp:1018
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 Fri Sep 20 14:57:12 2024 by modify_doxy.py rev. 669887