• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

antonvw / wex / 17877007475

20 Sep 2025 07:22AM UTC coverage: 64.153% (+5.5%) from 58.646%
17877007475

push

github

antonvw
Merge branch 'develop'

18261 of 31235 branches covered (58.46%)

Branch coverage included in aggregate %.

14571 of 19943 relevant lines covered (73.06%)

1401.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.94
/src/ui/notebook.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
// Name:      notebook.cpp
3
// Purpose:   Implementation of class wex::notebook
4
// Author:    Anton van Wezenbeek
5
// Copyright: (c) 2021-2025 Anton van Wezenbeek
6
////////////////////////////////////////////////////////////////////////////////
7

8
#include <wex/core/log.h>
9
#include <wex/ui/item-dialog.h>
10
#include <wex/ui/item-vector.h>
11
#include <wex/ui/notebook.h>
12
#include <wx/settings.h>
13

14
#define PAGE_DATA                                                              \
15
  data.page(), (data.caption().empty() ? data.key() : data.caption()),         \
16
    data.select(), data.bitmap()
17

18
namespace wex
19
{
20
const std::vector<item> notebook_config_items()
46✔
21
{
22
  return std::vector<item>(
23
    {{_("tab.Font"),
92✔
24
      item::FONTPICKERCTRL,
25
      wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)},
92✔
26
     });
230!
27
};
92!
28
} // namespace wex
29

30
wex::notebook::notebook(const data::window& data)
46✔
31
  : wxAuiNotebook(
32
      data.parent(),
33
      data.id(),
46✔
34
      data.pos(),
35
      data.size(),
36
      data.style() == data::NUMBER_NOT_SET ? default_style_t : data.style())
45✔
37
  , m_frame(dynamic_cast<frame*>(wxTheApp->GetTopWindow()))
137!
38
{
39
  config_get();
46✔
40

41
  SetArtProvider(new wxAuiDefaultTabArt);
46!
42

43
  Bind(
46✔
44
    wxEVT_AUINOTEBOOK_PAGE_CHANGED,
45
    [=, this](wxAuiNotebookEvent& event)
46✔
46
    {
47
      event.Skip(); // call base
72✔
48
      if (m_frame != nullptr)
72!
49
      {
50
        m_frame->on_notebook(GetId(), GetPage(event.GetSelection()));
72✔
51
      }
52
    });
72✔
53

54
  Bind(
46✔
55
    wxEVT_AUINOTEBOOK_PAGE_CLOSE,
56
    [=, this](wxAuiNotebookEvent& event)
46✔
57
    {
58
      if (const auto sel = event.GetSelection(); sel != wxNOT_FOUND)
×
59
      {
60
        if (m_frame != nullptr && !m_frame->allow_close(GetId(), GetPage(sel)))
×
61
        {
62
          event.Veto();
×
63
        }
64
        else
65
        {
66
          auto*      page = GetPage(sel);
×
67
          const auto key  = m_windows[page];
×
68
          m_windows.erase(page);
×
69
          m_keys.erase(key);
×
70

71
          if (m_frame != nullptr && m_keys.empty())
×
72
          {
73
            m_frame->sync_close_all(GetId());
×
74
          }
75

76
          event.Skip(); // call base
×
77
        }
×
78
      }
79
    });
×
80
}
46✔
81

82
wxWindow* wex::notebook::add_page(const data::notebook& data)
413✔
83
{
84
  if (!AddPage(PAGE_DATA))
413!
85
  {
86
    return nullptr;
×
87
  }
88

89
  m_keys[data.key()]     = data.page();
413✔
90
  m_windows[data.page()] = data.key();
413✔
91

92
  return data.page();
413✔
93
}
94

95
const std::string wex::notebook::change_selection(const std::string& key)
3✔
96
{
97
  int previous;
98

99
  if (const auto index = page_index_by_key(key);
3✔
100
      index != wxNOT_FOUND &&
5✔
101
      ((previous = wxAuiNotebook::ChangeSelection(index))) >= 0)
2!
102
  {
103
    auto* page      = m_keys[key];
2✔
104
    m_keys[key]     = page;
2✔
105
    m_windows[page] = key;
2✔
106
    return key_by_page(GetPage(previous));
2✔
107
  }
108

109
  return std::string();
1✔
110
}
111

112
int wex::notebook::config_dialog(const data::window& par)
×
113
{
114
  const data::window data(data::window(par).title(_("Tab Options")));
×
115

116
  if (m_config_dialog == nullptr)
×
117
  {
118
    m_config_dialog = new item_dialog(notebook_config_items(), data);
×
119
  }
120

121
  return (data.button() & wxAPPLY) ? m_config_dialog->Show() :
×
122
                                     m_config_dialog->ShowModal();
×
123
}
×
124

125
void wex::notebook::config_get()
46✔
126
{
127
  const auto&       ci(notebook_config_items());
46✔
128
  const item_vector iv(&ci);
46✔
129

130
  SetFont(iv.find<wxFont>(_("tab.Font")));
46✔
131
}
46✔
132

133
bool wex::notebook::delete_page(const std::string& key)
6✔
134
{
135
  if (const auto index = page_index_by_key(key);
6✔
136
      index != wxNOT_FOUND && DeletePage(index))
6!
137
  {
138
    auto* page = m_keys[key];
5✔
139
    m_keys.erase(key);
5✔
140
    m_windows.erase(page);
5✔
141

142
    if (m_frame != nullptr && m_keys.empty())
5!
143
    {
144
      m_frame->sync_close_all(GetId());
×
145
    }
146

147
    return true;
5✔
148
  }
149

150
  return false;
1✔
151
}
152

153
const std::string wex::notebook::current_page_key()
6✔
154
{
155
  return key_by_page(GetCurrentPage());
6✔
156
}
157

158
wxWindow* wex::notebook::insert_page(const data::notebook& data)
2✔
159
{
160
  if (!InsertPage(data.index(), PAGE_DATA))
2!
161
  {
162
    return nullptr;
×
163
  }
164

165
  m_keys[data.key()]     = data.page();
2✔
166
  m_windows[data.page()] = data.key();
2✔
167

168
  return data.page();
2✔
169
}
170

171
void wex::notebook::rearrange(int direction)
2✔
172
{
173
  for (size_t i = 0; i < GetPageCount(); ++i)
8✔
174
  {
175
    wxAuiNotebook::Split(i, direction);
6✔
176
  }
177
}
2✔
178

179
bool wex::notebook::set_page_text(
1✔
180
  const std::string&    key,
181
  const std::string&    new_key,
182
  const std::string&    caption,
183
  const wxBitmapBundle& bitmap)
184
{
185
  const auto index = page_index_by_key(key);
1✔
186
  if (index == wxNOT_FOUND || !SetPageText(index, caption))
1!
187
  {
188
    return false;
×
189
  }
190

191
  auto* page = m_keys[key];
1✔
192
  m_keys.erase(key);
1✔
193
  m_keys[new_key] = page;
1✔
194
  m_windows[page] = new_key;
1✔
195

196
  if (bitmap.IsOk())
1!
197
  {
198
    SetPageBitmap(index, bitmap);
×
199
  }
200

201
  return true;
1✔
202
}
203

204
wxWindow* wex::notebook::set_selection(const std::string& key)
3✔
205
{
206
  const auto index = page_index_by_key(key);
3✔
207
  if (index == wxNOT_FOUND)
3✔
208
  {
209
    return nullptr;
1✔
210
  }
211

212
  wxAuiNotebook::SetSelection(index);
2✔
213
  auto* page = GetPage(index);
2✔
214
  page->SetFocus();
2✔
215
  return page;
2✔
216
}
217

218
bool wex::notebook::split(const std::string& key, int direction)
3✔
219
{
220
  const auto index = page_index_by_key(key);
3✔
221
  if (index == wxNOT_FOUND)
3✔
222
  {
223
    return false;
1✔
224
  }
225

226
  wxAuiNotebook::Split(index, direction);
2✔
227
  return true;
2✔
228
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc