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

kunitoki / popsicle / 8316461477

17 Mar 2024 03:25PM UTC coverage: 20.182% (+1.4%) from 18.801%
8316461477

Pull #24

github

kunitoki
Fix issues
Pull Request #24: More tests coverage

320 of 461 new or added lines in 7 files covered. (69.41%)

45 existing lines in 5 files now uncovered.

23834 of 118096 relevant lines covered (20.18%)

3610.34 hits per line

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

13.52
/modules/juce_python/bindings/ScriptJuceGuiBasicsBindings.h
1
/**
2
 * juce_python - Python bindings for the JUCE framework.
3
 *
4
 * This file is part of the popsicle project.
5
 *
6
 * Copyright (c) 2024 - kunitoki <kunitoki@gmail.com>
7
 *
8
 * popsicle is an open source library subject to commercial or open-source licensing.
9
 *
10
 * By using popsicle, you agree to the terms of the popsicle License Agreement, which can
11
 * be found at https://raw.githubusercontent.com/kunitoki/popsicle/master/LICENSE
12
 *
13
 * Or: You may also use this code under the terms of the GPL v3 (see www.gnu.org/licenses).
14
 *
15
 * POPSICLE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER EXPRESSED
16
 * OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE DISCLAIMED.
17
 */
18

19
#pragma once
20

21
#if !JUCE_MODULE_AVAILABLE_juce_gui_basics
22
 #error This binding file requires adding the juce_gui_basics module in the project
23
#else
24
 #include <juce_gui_basics/juce_gui_basics.h>
25
#endif
26

27
#define JUCE_PYTHON_INCLUDE_PYBIND11_FUNCTIONAL
28
#define JUCE_PYTHON_INCLUDE_PYBIND11_IOSTREAM
29
#define JUCE_PYTHON_INCLUDE_PYBIND11_OPERATORS
30
#include "../utilities/PyBind11Includes.h"
31

32
#include "ScriptJuceOptionsBindings.h"
33

34
#include <cstddef>
35
#include <exception>
36
#include <functional>
37
#include <memory>
38
#include <vector>
39
#include <utility>
40

41
namespace popsicle::Bindings {
42

43
// =================================================================================================
44

45
void registerJuceGuiBasicsBindings (pybind11::module_& m);
46

47
// =================================================================================================
48

49
struct PyNativeHandle
50
{
51
    explicit PyNativeHandle (void* value) noexcept
×
52
        : value (value)
×
53
    {
54
    }
×
55

56
    operator void*() const noexcept
×
57
    {
58
        return value;
×
59
    }
60

61
    bool operator== (const PyNativeHandle& other) const noexcept
62
    {
63
        return value == other.value;
64
    }
65

66
    bool operator!= (const PyNativeHandle& other) const noexcept
67
    {
68
        return value != other.value;
69
    }
70

71
private:
72
    void* value;
73
};
74

75
// =================================================================================================
76

77
struct PyJUCEApplication : juce::JUCEApplication
78
{
79
    const juce::String getApplicationName() override
×
80
    {
81
        PYBIND11_OVERRIDE_PURE (const juce::String, juce::JUCEApplication, getApplicationName);
×
82
    }
83

84
    const juce::String getApplicationVersion() override
×
85
    {
86
        PYBIND11_OVERRIDE_PURE (const juce::String, juce::JUCEApplication, getApplicationVersion);
×
87
    }
88

89
    bool moreThanOneInstanceAllowed() override
42✔
90
    {
91
        PYBIND11_OVERRIDE (bool, juce::JUCEApplication, moreThanOneInstanceAllowed);
84✔
92
    }
93

94
    void initialise (const juce::String& commandLineParameters) override
42✔
95
    {
96
        PYBIND11_OVERRIDE_PURE (void, juce::JUCEApplication, initialise, commandLineParameters);
42✔
97
    }
98

99
    void shutdown() override
×
100
    {
101
        PYBIND11_OVERRIDE_PURE (void, juce::JUCEApplication, shutdown);
×
102
    }
103

104
    void anotherInstanceStarted (const juce::String& commandLine) override
×
105
    {
106
        PYBIND11_OVERRIDE (void, juce::JUCEApplication, anotherInstanceStarted, commandLine);
×
107
    }
108

109
    void systemRequestedQuit() override
×
110
    {
111
        PYBIND11_OVERRIDE (void, juce::JUCEApplication, systemRequestedQuit);
×
112
    }
113

114
    void suspended() override
×
115
    {
116
        PYBIND11_OVERRIDE (void, juce::JUCEApplication, suspended);
×
117
    }
118

119
    void resumed() override
×
120
    {
121
        PYBIND11_OVERRIDE (void, juce::JUCEApplication, resumed);
×
122
    }
123

124
    void unhandledException (const std::exception* ex, const juce::String& sourceFilename, int lineNumber) override
×
125
    {
126
        pybind11::gil_scoped_acquire gil;
×
127

128
        const auto* pyEx = dynamic_cast<const pybind11::error_already_set*> (ex);
×
129
        auto traceback = pybind11::module_::import ("traceback");
×
130

131
        if (pybind11::function override_ = pybind11::get_override (static_cast<juce::JUCEApplication*> (this), "unhandledException"); override_)
×
132
        {
133
            if (pyEx != nullptr)
×
134
            {
135
                auto newPyEx = pyEx->type()(pyEx->value());
×
136
                PyException_SetTraceback (newPyEx.ptr(), pyEx->trace().ptr());
×
137

138
                override_ (newPyEx, sourceFilename, lineNumber);
×
139
            }
140
            else
141
            {
142
                auto runtimeError = pybind11::module_::import ("__builtins__").attr ("RuntimeError");
×
143
                auto newPyEx = runtimeError(ex != nullptr ? ex->what() : "unknown exception");
×
144
                PyException_SetTraceback (newPyEx.ptr(), traceback.attr ("extract_stack")().ptr());
×
145

146
                override_ (newPyEx, sourceFilename, lineNumber);
×
147
            }
148

149
            return;
×
150
        }
151

152
        if (globalOptions().catchExceptionsAndContinue)
×
153
        {
154
            pybind11::print (100, ex->what());
×
155

156
            if (pyEx != nullptr)
×
157
            {
158
                traceback.attr ("print_tb")(pyEx->trace());
×
159

160
                if (pyEx->matches (PyExc_KeyboardInterrupt))
×
161
                    globalOptions().caughtKeyboardInterrupt = true;
×
162
            }
163
            else
164
            {
165
                traceback.attr ("print_stack")();
×
166

167
                if (PyErr_CheckSignals() != 0)
×
168
                    globalOptions().caughtKeyboardInterrupt = true;
×
169
            }
170
        }
171
        else
172
        {
173
            std::terminate();
×
174
        }
175
    }
176

177
    void memoryWarningReceived() override
×
178
    {
179
        PYBIND11_OVERRIDE (void, juce::JUCEApplication, memoryWarningReceived);
×
180
    }
181

182
    bool backButtonPressed() override
×
183
    {
184
        PYBIND11_OVERRIDE (bool, juce::JUCEApplication, backButtonPressed);
×
185
    }
186
};
187

188
// =================================================================================================
189

190
struct PyKeyListener : juce::KeyListener
191
{
192
    using juce::KeyListener::KeyListener;
193

194
    bool keyPressed (const juce::KeyPress& key, juce::Component* originatingComponent) override
×
195
    {
196
        PYBIND11_OVERRIDE_PURE (bool, juce::KeyListener, keyPressed, key, originatingComponent);
×
197
    }
198

199
    bool keyStateChanged (bool isKeyDown, juce::Component* originatingComponent) override
×
200
    {
201
        PYBIND11_OVERRIDE (bool, KeyListener, keyStateChanged, isKeyDown, originatingComponent);
×
202
    }
203
};
204

205
// =================================================================================================
206

207
template <class Base = juce::MouseListener>
208
struct PyMouseListener : Base
209
{
210
    using Base::Base;
211

212
    void mouseMove (const juce::MouseEvent& event) override
×
213
    {
214
        PYBIND11_OVERRIDE (void, Base, mouseMove, event);
×
215
    }
216

217
    void mouseEnter (const juce::MouseEvent& event) override
×
218
    {
219
        {
NEW
220
            pybind11::gil_scoped_acquire gil;
×
221

NEW
222
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "mouseEnter"))
×
223
            {
NEW
224
                override_ (event);
×
NEW
225
                return;
×
226
            }
227
        }
228

229
        if constexpr (! std::is_same_v<Base, juce::TooltipWindow>)
NEW
230
            Base::mouseEnter (event);
×
231
    }
232

233
    void mouseExit (const juce::MouseEvent& event) override
×
234
    {
235
        {
NEW
236
            pybind11::gil_scoped_acquire gil;
×
237

NEW
238
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "mouseExit"))
×
239
            {
NEW
240
                override_ (event);
×
NEW
241
                return;
×
242
            }
243
        }
244

245
        if constexpr (! std::is_same_v<Base, juce::TooltipWindow>)
NEW
246
            Base::mouseExit (event);
×
247
    }
248

249
    void mouseDown (const juce::MouseEvent& event) override
×
250
    {
251
        {
NEW
252
            pybind11::gil_scoped_acquire gil;
×
253

NEW
254
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "mouseDown"))
×
255
            {
NEW
256
                override_ (event);
×
NEW
257
                return;
×
258
            }
259
        }
260

261
        if constexpr (! std::is_same_v<Base, juce::TooltipWindow>)
NEW
262
            Base::mouseDown (event);
×
263
    }
264

265
    void mouseDrag (const juce::MouseEvent& event) override
×
266
    {
267
        PYBIND11_OVERRIDE (void, Base, mouseDrag, event);
×
268
    }
269

270
    void mouseUp (const juce::MouseEvent& event) override
×
271
    {
272
        PYBIND11_OVERRIDE (void, Base, mouseUp, event);
×
273
    }
274

275
    void mouseDoubleClick (const juce::MouseEvent& event) override
×
276
    {
277
        PYBIND11_OVERRIDE (void, Base, mouseDoubleClick, event);
×
278
    }
279

280
    void mouseWheelMove (const juce::MouseEvent& event, const juce::MouseWheelDetails& wheel) override
×
281
    {
282
        {
NEW
283
            pybind11::gil_scoped_acquire gil;
×
284

NEW
285
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "mouseWheelMove"))
×
286
            {
NEW
287
                override_ (event, wheel);
×
NEW
288
                return;
×
289
            }
290
        }
291

292
        if constexpr (! std::is_same_v<Base, juce::TooltipWindow>)
NEW
293
            Base::mouseWheelMove (event, wheel);
×
294
    }
295

296
    void mouseMagnify (const juce::MouseEvent& event, float scaleFactor) override
×
297
    {
298
        PYBIND11_OVERRIDE (void, Base, mouseMagnify, event, scaleFactor);
×
299
    }
300
};
301

302
// =================================================================================================
303

304
template <class Base = juce::TextInputTarget>
305
struct PyTextInputTarget : Base
306
{
307
    using Base::Base;
308

309
    bool isTextInputActive() const override
×
310
    {
311
        PYBIND11_OVERRIDE_PURE (bool, Base, isTextInputActive);
×
312
    }
313

314
    juce::Range<int> getHighlightedRegion() const override
×
315
    {
316
        PYBIND11_OVERRIDE_PURE (juce::Range<int>, Base, getHighlightedRegion);
×
317
    }
318

319
    void setHighlightedRegion (const juce::Range<int>& newRange) override
×
320
    {
321
        PYBIND11_OVERRIDE_PURE (void, Base, setHighlightedRegion, newRange);
×
322
    }
323

324
    void setTemporaryUnderlining (const juce::Array<juce::Range<int>>& underlinedRegions) override
×
325
    {
326
        PYBIND11_OVERRIDE_PURE (void, Base, setTemporaryUnderlining, underlinedRegions);
×
327
    }
328

329
    juce::String getTextInRange (const juce::Range<int>& range) const override
×
330
    {
331
        PYBIND11_OVERRIDE_PURE (juce::String, Base, getTextInRange, range);
×
332
    }
333

334
    void insertTextAtCaret (const juce::String& textToInsert) override
×
335
    {
336
        PYBIND11_OVERRIDE_PURE (void, Base, insertTextAtCaret, textToInsert);
×
337
    }
338

339
    int getCaretPosition() const override
×
340
    {
341
        PYBIND11_OVERRIDE_PURE (int, Base, getCaretPosition);
×
342
    }
343

344
    juce::Rectangle<int> getCaretRectangleForCharIndex (int characterIndex) const override
×
345
    {
346
        PYBIND11_OVERRIDE_PURE (juce::Rectangle<int>, Base, getCaretRectangleForCharIndex, characterIndex);
×
347
    }
348

349
    int getTotalNumChars() const override
×
350
    {
351
        PYBIND11_OVERRIDE_PURE (int, Base, getTotalNumChars);
×
352
    }
353

354
    int getCharIndexForPoint (juce::Point<int> point) const override
×
355
    {
356
        PYBIND11_OVERRIDE_PURE (int, Base, getCharIndexForPoint, point);
×
357
    }
358

359
    juce::RectangleList<int> getTextBounds (juce::Range<int> textRange) const override
×
360
    {
361
        PYBIND11_OVERRIDE_PURE (juce::Rectangle<int>, Base, getTextBounds, textRange);
×
362
    }
363

364
    juce::TextInputTarget::VirtualKeyboardType getKeyboardType() override
×
365
    {
366
        PYBIND11_OVERRIDE (juce::TextInputTarget::VirtualKeyboardType, Base, getKeyboardType);
×
367
    }
368
};
369

370
// =================================================================================================
371

372
template <class Base = juce::LookAndFeel>
373
struct PyLookAndFeel : Base
374
{
375
    using Base::Base;
376

377
    void drawSpinningWaitAnimation(juce::Graphics& g, const juce::Colour& colour, int x, int y, int w, int h) override
378
    {
379
        {
380
            pybind11::gil_scoped_acquire gil;
381

382
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "drawSpinningWaitAnimation"))
383
            {
384
                override_ (std::addressof (g), colour, x, y, w, h);
385
                return;
386
            }
387
        }
388

389
        pybind11::pybind11_fail ("Tried to call pure virtual function \"LookAndFeel::drawSpinningWaitAnimation\"");
390
    }
391

392
    juce::Path getTickShape (float height) override
393
    {
394
        PYBIND11_OVERRIDE_PURE (juce::Path, Base, getTickShape, height);
395
    }
396

397
    juce::Path getCrossShape (float height) override
398
    {
399
        PYBIND11_OVERRIDE_PURE (juce::Path, Base, getCrossShape, height);
400
    }
401

402
    std::unique_ptr<juce::DropShadower> createDropShadowerForComponent (juce::Component&) override
403
    {
404
        return {}; // TODO
405
    }
406

407
    std::unique_ptr<juce::FocusOutline> createFocusOutlineForComponent (juce::Component&) override
408
    {
409
        return {}; // TODO
410
    }
411

412
    juce::MouseCursor getMouseCursorFor (juce::Component& c) override
413
    {
414
        PYBIND11_OVERRIDE (juce::MouseCursor, Base, getMouseCursorFor, c);
415
    }
416

417
    void playAlertSound() override
418
    {
419
        PYBIND11_OVERRIDE (void, Base, playAlertSound);
420
    }
421
};
422

423
template <class Base = juce::LookAndFeel_V2>
424
struct PyLookAndFeel_V2 : PyLookAndFeel<Base>
425
{
426
    using PyLookAndFeel<Base>::PyLookAndFeel;
427

428
    void drawButtonBackground (juce::Graphics& g, juce::Button& b, const juce::Colour& backgroundColour,
429
                               bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override
430
    {
431
        {
432
            pybind11::gil_scoped_acquire gil;
433

434
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "drawButtonBackground"))
435
            {
436
                override_ (std::addressof (g), std::addressof (b), backgroundColour, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
437
                return;
438
            }
439
        }
440

441
        Base::drawButtonBackground (g, b, backgroundColour, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
442
    }
443

444
    juce::Font getTextButtonFont (juce::TextButton& button, int buttonHeight) override
445
    {
446
        {
447
            pybind11::gil_scoped_acquire gil;
448

449
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "getTextButtonFont"))
450
            {
451
                return override_ (std::addressof (button), buttonHeight).cast<juce::Font>();
452
            }
453
        }
454

455
        return Base::getTextButtonFont (button, buttonHeight);
456
    }
457

458
    void drawButtonText (juce::Graphics& g, juce::TextButton& button,
459
                         bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override
460
    {
461
        {
462
            pybind11::gil_scoped_acquire gil;
463

464
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "drawButtonText"))
465
            {
466
                override_ (std::addressof (g), std::addressof (button), shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
467
                return;
468
            }
469
        }
470

471
        Base::drawButtonText (g, button, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
472
    }
473

474
    int getTextButtonWidthToFitText (juce::TextButton& button, int buttonHeight) override
475
    {
476
        {
477
            pybind11::gil_scoped_acquire gil;
478

479
            if (pybind11::function override_ = pybind11::get_override(static_cast<Base*>(this), "getTextButtonWidthToFitText"))
480
            {
481
                return override_ (std::addressof(button), buttonHeight).cast<int>();
482
            }
483
        }
484

485
        return Base::getTextButtonWidthToFitText(button, buttonHeight);
486
    }
487

488
    void drawToggleButton (juce::Graphics& g, juce::ToggleButton& button,
489
                           bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override
490
    {
491
        {
492
            pybind11::gil_scoped_acquire gil;
493

494
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "drawToggleButton"))
495
            {
496
                override_ (std::addressof (g), std::addressof (button), shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
497
                return;
498
            }
499
        }
500

501
        Base::drawToggleButton (g, button, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
502
    }
503

504
    void changeToggleButtonWidthToFitText (juce::ToggleButton& button) override
505
    {
506
        {
507
            pybind11::gil_scoped_acquire gil;
508

509
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "changeToggleButtonWidthToFitText"); override_)
510
            {
511
                override_ (std::addressof (button));
512
                return;
513
            }
514
        }
515

516
        Base::changeToggleButtonWidthToFitText (button);
517
    }
518

519
    void drawTickBox (juce::Graphics& g, juce::Component& component,
520
                      float x, float y, float w, float h,
521
                      bool ticked, bool isEnabled,
522
                      bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override
523
    {
524
        {
525
            pybind11::gil_scoped_acquire gil;
526

527
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "drawTickBox"); override_)
528
            {
529
                override_ (std::addressof (g), std::addressof (component), x, y, w, h, ticked, isEnabled, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
530
                return;
531
            }
532
        }
533

534
        Base::drawTickBox (g, component, x, y, w, h, ticked, isEnabled, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
535
    }
536

537
    void drawDrawableButton (juce::Graphics& g, juce::DrawableButton& button,
538
                             bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override
539
    {
540
        {
541
            pybind11::gil_scoped_acquire gil;
542

543
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "drawDrawableButton"); override_)
544
            {
545
                override_ (std::addressof (g), std::addressof (button), shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
546
                return;
547
            }
548
        }
549

550
        Base::drawDrawableButton (g, button, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
551
    }
552

553
    juce::AlertWindow* createAlertWindow (const juce::String& title, const juce::String& message,
554
                                          const juce::String& button1, const juce::String& button2,
555
                                          const juce::String& button3, juce::MessageBoxIconType iconType,
556
                                          int numButtons, juce::Component* associatedComponent) override
557
    {
558
        PYBIND11_OVERRIDE (juce::AlertWindow*, Base, createAlertWindow, title, message, button1, button2, button3, iconType, numButtons, associatedComponent);
559
    }
560

561
    void drawAlertBox (juce::Graphics& g, juce::AlertWindow& alertWindow, const juce::Rectangle<int>& textArea, juce::TextLayout& textLayout) override
562
    {
563
        {
564
            pybind11::gil_scoped_acquire gil;
565

566
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "drawAlertBox"); override_)
567
            {
568
                override_ (std::addressof (g), std::addressof (alertWindow), textArea, std::addressof (textLayout));
569
                return;
570
            }
571
        }
572

573
        Base::drawAlertBox (g, alertWindow, textArea, textLayout);
574
    }
575

576
    int getAlertBoxWindowFlags() override
577
    {
578
        PYBIND11_OVERRIDE (int, Base, getAlertBoxWindowFlags);
579
    }
580

581
    juce::Array<int> getWidthsForTextButtons (juce::AlertWindow& alertWindow, const juce::Array<juce::TextButton*>& buttons) override
582
    {
583
        {
584
            pybind11::gil_scoped_acquire gil;
585

586
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "getWidthsForTextButtons"); override_)
587
            {
588
                pybind11::list list (buttons.size());
589
                for (int i = 0; i < buttons.size(); ++i)
590
                    list[static_cast<size_t> (i)] = buttons.getUnchecked (i);
591

592
                return override_ (std::addressof (alertWindow), list).cast<juce::Array<int>>();
593
            }
594
        }
595

596
        return Base::getWidthsForTextButtons (alertWindow, buttons);
597
    }
598

599
    int getAlertWindowButtonHeight() override
600
    {
601
        PYBIND11_OVERRIDE (int, Base, getAlertWindowButtonHeight);
602
    }
603

604
    juce::Font getAlertWindowTitleFont() override
605
    {
606
        PYBIND11_OVERRIDE (juce::Font, Base, getAlertWindowTitleFont);
607
    }
608

609
    juce::Font getAlertWindowMessageFont() override
610
    {
611
        PYBIND11_OVERRIDE (juce::Font, Base, getAlertWindowMessageFont);
612
    }
613

614
    juce::Font getAlertWindowFont() override
615
    {
616
        PYBIND11_OVERRIDE (juce::Font, Base, getAlertWindowFont);
617
    }
618
};
619

620
// =================================================================================================
621

622
template <class Base = juce::ComponentTraverser>
623
struct PyComponentTraverser : Base
624
{
625
    using Base::Base;
626

627
    juce::Component* getDefaultComponent (juce::Component* parentComponent) override
×
628
    {
629
        PYBIND11_OVERRIDE_PURE (juce::Component*, Base, getDefaultComponent, parentComponent);
×
630
    }
631

632
    juce::Component* getNextComponent (juce::Component* current) override
×
633
    {
634
        PYBIND11_OVERRIDE_PURE (juce::Component*, Base, getNextComponent, current);
×
635
    }
636

637
    juce::Component* getPreviousComponent (juce::Component* current) override
×
638
    {
639
        PYBIND11_OVERRIDE_PURE (juce::Component*, Base, getPreviousComponent, current);
×
640
    }
641

642
    std::vector<juce::Component*> getAllComponents (juce::Component* parentComponent) override
×
643
    {
644
        PYBIND11_OVERRIDE_PURE (std::vector<juce::Component*>, Base, getAllComponents, parentComponent);
×
645
    }
646
};
647

648
template <class Base = juce::FocusTraverser>
649
struct PyFocusTraverser : PyComponentTraverser<Base>
650
{
651
    using PyComponentTraverser<Base>::PyComponentTraverser;
652
};
653

654
// =================================================================================================
655

656
struct PyComponentListener : juce::ComponentListener
657
{
658
    using juce::ComponentListener::ComponentListener;
659

660
    void componentMovedOrResized (juce::Component& component, bool wasMoved, bool wasResized) override
×
661
    {
662
        PYBIND11_OVERRIDE (void, juce::ComponentListener, componentMovedOrResized, component, wasMoved, wasResized);
×
663
    }
664

665
    void componentBroughtToFront (juce::Component& component) override
×
666
    {
667
        PYBIND11_OVERRIDE (void, juce::ComponentListener, componentBroughtToFront, component);
×
668
    }
669

670
    void componentVisibilityChanged (juce::Component& component) override
×
671
    {
672
        PYBIND11_OVERRIDE (void, juce::ComponentListener, componentVisibilityChanged, component);
×
673
    }
674

675
    void componentChildrenChanged (juce::Component& component) override
×
676
    {
677
        PYBIND11_OVERRIDE (void, juce::ComponentListener, componentChildrenChanged, component);
×
678
    }
679

680
    void componentParentHierarchyChanged (juce::Component& component) override
×
681
    {
682
        PYBIND11_OVERRIDE (void, juce::ComponentListener, componentParentHierarchyChanged, component);
×
683
    }
684

685
    void componentNameChanged (juce::Component& component) override
×
686
    {
687
        PYBIND11_OVERRIDE (void, juce::ComponentListener, componentNameChanged, component);
×
688
    }
689

690
    void componentBeingDeleted (juce::Component& component) override
×
691
    {
692
        PYBIND11_OVERRIDE (void, juce::ComponentListener, componentBeingDeleted, component);
×
693
    }
694

695
    void componentEnablementChanged (juce::Component& component) override
×
696
    {
697
        PYBIND11_OVERRIDE (void, juce::ComponentListener, componentEnablementChanged, component);
×
698
    }
699
};
700

701
// =================================================================================================
702

703
struct PyModalComponentManagerCallback : juce::ModalComponentManager::Callback
704
{
705
    using juce::ModalComponentManager::Callback::Callback;
706

707
    void modalStateFinished (int returnValue) override
×
708
    {
709
        PYBIND11_OVERRIDE_PURE (void, juce::ModalComponentManager::Callback, modalStateFinished, returnValue);
×
710
    }
711
};
712

713
struct PyModalComponentManagerCallbackCallable : juce::ModalComponentManager::Callback
714
{
715
    explicit PyModalComponentManagerCallbackCallable (pybind11::function f)
×
716
        : fn (std::move (f))
×
717
    {
718
    }
×
719

720
    void modalStateFinished (int result) override
×
721
    {
722
        if (fn)
×
723
            fn (result);
×
724
    }
×
725

726
private:
727
    pybind11::function fn;
728
};
729

730
// =================================================================================================
731

732
template <class Base = juce::Component>
733
struct PyComponent : PyMouseListener<Base>
734
{
735
    using PyMouseListener<Base>::PyMouseListener;
736

737
    void setName (const juce::String& newName) override
×
738
    {
739
        PYBIND11_OVERRIDE (void, Base, setName, newName);
×
740
    }
741

742
    void setVisible (bool shouldBeVisible) override
3✔
743
    {
744
        PYBIND11_OVERRIDE (void, Base, setVisible, shouldBeVisible);
6✔
745
    }
746

747
    void visibilityChanged() override
3✔
748
    {
749
        PYBIND11_OVERRIDE (void, Base, visibilityChanged);
6✔
750
    }
751

752
    void userTriedToCloseWindow() override
×
753
    {
754
        PYBIND11_OVERRIDE (void, Base, userTriedToCloseWindow);
×
755
    }
756

757
    void minimisationStateChanged(bool isNowMinimised) override
×
758
    {
759
        PYBIND11_OVERRIDE (void, Base, minimisationStateChanged, isNowMinimised);
×
760
    }
761

762
    float getDesktopScaleFactor() const override
6✔
763
    {
764
        PYBIND11_OVERRIDE (float, Base, getDesktopScaleFactor);
12✔
765
    }
766

767
    void parentHierarchyChanged() override
7✔
768
    {
769
        PYBIND11_OVERRIDE (void, Base, parentHierarchyChanged);
14✔
770
    }
771

772
    void childrenChanged() override
18✔
773
    {
774
        PYBIND11_OVERRIDE (void, Base, childrenChanged);
36✔
775
    }
776

777
    bool hitTest (int x, int y) override
×
778
    {
779
        PYBIND11_OVERRIDE (bool, Base, hitTest, x, y);
×
780
    }
781

782
    void lookAndFeelChanged() override
4✔
783
    {
784
        PYBIND11_OVERRIDE (void, Base, lookAndFeelChanged);
8✔
785
    }
786

787
    void enablementChanged() override
×
788
    {
789
        PYBIND11_OVERRIDE (void, Base, enablementChanged);
×
790
    }
791

792
    void alphaChanged() override
×
793
    {
794
        PYBIND11_OVERRIDE (void, Base, alphaChanged);
×
795
    }
796

797
    void paint (juce::Graphics& g) override
2✔
798
    {
799
        {
800
            pybind11::gil_scoped_acquire gil;
2✔
801

802
            if (pybind11::function override_ = pybind11::get_override (static_cast<const Base*> (this), "paint"); override_)
2✔
803
            {
804
                override_ (std::addressof (g));
×
805
                return;
×
806
            }
807
        }
808

809
        if constexpr (! std::is_same_v<Base, juce::TooltipWindow>)
810
            Base::paint (g);
2✔
811
    }
812

813
    void paintOverChildren (juce::Graphics& g) override
2✔
814
    {
815
        {
816
            pybind11::gil_scoped_acquire gil;
2✔
817

818
            if (pybind11::function override_ = pybind11::get_override (static_cast<const Base*> (this), "paintOverChildren"); override_)
2✔
819
            {
820
                override_ (std::addressof (g));
×
821
                return;
×
822
            }
823
        }
824

825
        Base::paintOverChildren (g);
2✔
826
    }
827

828
    bool keyPressed (const juce::KeyPress& key) override
×
829
    {
830
        PYBIND11_OVERRIDE (bool, Base, keyPressed, key);
×
831
    }
832

833
    bool keyStateChanged (bool isDown) override
×
834
    {
835
        PYBIND11_OVERRIDE (bool, Base, keyStateChanged, isDown);
×
836
    }
837

838
    void modifierKeysChanged (const juce::ModifierKeys& modifiers) override
×
839
    {
840
        PYBIND11_OVERRIDE (void, Base, modifierKeysChanged, modifiers);
×
841
    }
842

843
    void focusGained (juce::Component::FocusChangeType cause) override
2✔
844
    {
845
        PYBIND11_OVERRIDE (void, Base, focusGained, cause);
4✔
846
    }
847

848
    void focusGainedWithDirection (juce::Component::FocusChangeType cause, juce::Component::FocusChangeDirection direction) override
2✔
849
    {
850
        PYBIND11_OVERRIDE (void, Base, focusGainedWithDirection, cause, direction);
4✔
851
    }
852

853
    void focusLost (juce::Component::FocusChangeType cause) override
1✔
854
    {
855
        PYBIND11_OVERRIDE (void, Base, focusLost, cause);
2✔
856
    }
857

858
    void focusOfChildComponentChanged (juce::Component::FocusChangeType cause) override
3✔
859
    {
860
        PYBIND11_OVERRIDE (void, Base, focusOfChildComponentChanged, cause);
6✔
861
    }
862

863
    void resized () override
8✔
864
    {
865
        PYBIND11_OVERRIDE (void, Base, resized);
16✔
866
    }
867

868
    void moved () override
1✔
869
    {
870
        PYBIND11_OVERRIDE (void, Base, moved);
2✔
871
    }
872

873
    void childBoundsChanged (juce::Component* child) override
15✔
874
    {
875
        PYBIND11_OVERRIDE (void, Base, childBoundsChanged, child);
30✔
876
    }
877

878
    void parentSizeChanged () override
×
879
    {
880
        PYBIND11_OVERRIDE (void, Base, parentSizeChanged);
×
881
    }
882

883
    void broughtToFront () override
2✔
884
    {
885
        PYBIND11_OVERRIDE (void, Base, broughtToFront);
4✔
886
    }
887

888
    void handleCommandMessage (int commandId) override
5✔
889
    {
890
        {
891
            pybind11::gil_scoped_acquire gil;
5✔
892

893
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "handleCommandMessage"); override_)
5✔
894
            {
895
                override_ (commandId);
×
896
                return;
×
897
            }
898
        }
899

900
        if constexpr (! std::is_same_v<Base, juce::TextEditor>)
901
            Base::handleCommandMessage (commandId);
5✔
902
    }
903

904
    bool canModalEventBeSentToComponent (const juce::Component* targetComponent) override
×
905
    {
906
        PYBIND11_OVERRIDE (bool, Base, canModalEventBeSentToComponent, targetComponent);
×
907
    }
908

909
    void inputAttemptWhenModal () override
×
910
    {
911
        PYBIND11_OVERRIDE (void, Base, inputAttemptWhenModal);
×
912
    }
913

914
    void colourChanged () override
×
915
    {
916
        PYBIND11_OVERRIDE (void, Base, colourChanged);
×
917
    }
918
};
919

920
// =================================================================================================
921

922
template <class Base = juce::Drawable>
923
struct PyDrawable : PyComponent<Base>
924
{
925
    using PyComponent<Base>::PyComponent;
926

927
    std::unique_ptr<juce::Drawable> createCopy() const override
×
928
    {
929
        /*
930
        {
931
            pybind11::gil_scoped_acquire gil;
932

933
            if (pybind11::function override_ = pybind11::get_override (static_cast<const Base*> (this), "createCopy"); override_)
934
            {
935
                pybind11::object result = override_();
936

937
                return std::unique_ptr<Drawable> (result.release().cast<Base*>());
938
            }
939
        }
940

941
        pybind11::pybind11_fail("Tried to call pure virtual function \"Drawable::createCopy\"");
942
        */
943

944
        return nullptr;
×
945
    }
946

947
    juce::Path getOutlineAsPath() const override
×
948
    {
949
        PYBIND11_OVERRIDE_PURE (juce::Path, Base, getOutlineAsPath);
×
950
    }
951

952
    juce::Rectangle<float> getDrawableBounds() const override
×
953
    {
954
        PYBIND11_OVERRIDE_PURE (juce::Rectangle<float>, Base, getDrawableBounds);
×
955
    }
956

957
    bool replaceColour (juce::Colour originalColour, juce::Colour replacementColour) override
×
958
    {
959
        PYBIND11_OVERRIDE (bool, Base, replaceColour, originalColour, replacementColour);
×
960
    }
961
};
962

963
template <class Base = juce::DrawableComposite>
964
struct PyDrawableComposite : PyDrawable<Base>
965
{
966
    using PyDrawable<Base>::PyDrawable;
967

968
    std::unique_ptr<juce::Drawable> createCopy() const override { return nullptr; }
×
969

970
    juce::Path getOutlineAsPath() const override
×
971
    {
972
        PYBIND11_OVERRIDE (juce::Path, Base, getOutlineAsPath);
×
973
    }
974

975
    juce::Rectangle<float> getDrawableBounds() const override
×
976
    {
977
        PYBIND11_OVERRIDE (juce::Rectangle<float>, Base, getDrawableBounds);
×
978
    }
979
};
980

981
template <class Base = juce::DrawableImage>
982
struct PyDrawableImage : PyDrawable<Base>
983
{
984
    using PyDrawable<Base>::PyDrawable;
985

986
    std::unique_ptr<juce::Drawable> createCopy() const override { return nullptr; }
987

988
    juce::Path getOutlineAsPath() const override
989
    {
990
        PYBIND11_OVERRIDE (juce::Path, Base, getOutlineAsPath);
991
    }
992

993
    juce::Rectangle<float> getDrawableBounds() const override
994
    {
995
        PYBIND11_OVERRIDE (juce::Rectangle<float>, Base, getDrawableBounds);
996
    }
997
};
998

999
template <class Base = juce::DrawablePath>
1000
struct PyDrawablePath : PyDrawable<Base>
1001
{
1002
    using PyDrawable<Base>::PyDrawable;
1003

1004
    std::unique_ptr<juce::Drawable> createCopy() const override { return nullptr; }
×
1005
};
1006

1007
template <class Base = juce::DrawableShape>
1008
struct PyDrawableShape : PyDrawable<Base>
1009
{
1010
    using PyDrawable<Base>::PyDrawable;
1011

1012
    std::unique_ptr<juce::Drawable> createCopy() const override { return nullptr; }
×
1013

1014
    juce::Path getOutlineAsPath() const override
×
1015
    {
1016
        PYBIND11_OVERRIDE (juce::Path, Base, getOutlineAsPath);
×
1017
    }
1018

1019
    juce::Rectangle<float> getDrawableBounds() const override
×
1020
    {
1021
        PYBIND11_OVERRIDE (juce::Rectangle<float>, Base, getDrawableBounds);
×
1022
    }
1023

1024
    bool replaceColour (juce::Colour originalColour, juce::Colour replacementColour) override
×
1025
    {
1026
        PYBIND11_OVERRIDE (bool, Base, replaceColour, originalColour, replacementColour);
×
1027
    }
1028
};
1029

1030
template <class Base = juce::DrawableText>
1031
struct PyDrawableText : PyDrawable<Base>
1032
{
1033
    using PyDrawable<Base>::PyDrawable;
1034

1035
    std::unique_ptr<juce::Drawable> createCopy() const override { return nullptr; }
×
1036

1037
    juce::Path getOutlineAsPath() const override
×
1038
    {
1039
        PYBIND11_OVERRIDE (juce::Path, Base, getOutlineAsPath);
×
1040
    }
1041

1042
    juce::Rectangle<float> getDrawableBounds() const override
×
1043
    {
1044
        PYBIND11_OVERRIDE (juce::Rectangle<float>, Base, getDrawableBounds);
×
1045
    }
1046

1047
    bool replaceColour (juce::Colour originalColour, juce::Colour replacementColour) override
×
1048
    {
1049
        PYBIND11_OVERRIDE (bool, Base, replaceColour, originalColour, replacementColour);
×
1050
    }
1051
};
1052

1053
// =================================================================================================
1054

1055
template <class Base = juce::Button>
1056
struct PyButton : PyComponent<Base>
1057
{
1058
    using PyComponent<Base>::PyComponent;
1059

1060
    explicit PyButton (const juce::String& name)
10✔
1061
        : PyComponent<Base> (name)
10✔
1062
    {
1063
    }
10✔
1064

1065
    void triggerClick() override
5✔
1066
    {
1067
        PYBIND11_OVERRIDE (void, Base, triggerClick);
10✔
1068
    }
1069

1070
    void clicked() override
7✔
1071
    {
1072
        PYBIND11_OVERRIDE (void, Base, clicked);
7✔
1073
    }
1074

1075
    void clicked (const juce::ModifierKeys& modifiers) override
7✔
1076
    {
1077
        {
1078
            pybind11::gil_scoped_acquire gil;
7✔
1079

1080
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "clickedWithModifiers"); override_)
7✔
1081
            {
1082
                override_ (modifiers);
×
1083
                return;
×
1084
            }
1085
        }
1086

1087
        if constexpr (! std::is_same_v<Base, juce::HyperlinkButton>)
1088
            Base::clicked (modifiers);
7✔
1089
    }
1090

1091
    void paintButton (juce::Graphics& g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override
2✔
1092
    {
1093
        {
1094
            pybind11::gil_scoped_acquire gil;
2✔
1095

1096
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "paintButton"); override_)
2✔
1097
            {
1098
                override_ (std::addressof (g), shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
2✔
1099
                return;
4✔
1100
            }
1101
        }
1102

1103
        pybind11::pybind11_fail ("Tried to call pure virtual function \"Button::paintButton\"");
×
1104
    }
1105

1106
    void buttonStateChanged() override
11✔
1107
    {
1108
        PYBIND11_OVERRIDE (void, Base, buttonStateChanged);
11✔
1109
    }
1110
};
1111

1112
struct PyButtonListener : juce::Button::Listener
1113
{
1114
    using juce::Button::Listener::Listener;
1115

1116
    void buttonClicked (juce::Button* button) override
3✔
1117
    {
1118
        PYBIND11_OVERRIDE_PURE (void, juce::Button::Listener, buttonClicked, button);
3✔
1119
    }
1120

1121
    void buttonStateChanged (juce::Button* button) override
3✔
1122
    {
1123
        PYBIND11_OVERRIDE (void, juce::Button::Listener, buttonStateChanged, button);
3✔
1124
    }
1125
};
1126

1127
template <class Base = juce::DrawableButton>
1128
struct PyDrawableButton : PyButton<Base>
1129
{
1130
    using PyButton<Base>::PyButton;
1131

1132
    juce::Rectangle<float> getImageBounds() const override
×
1133
    {
1134
        PYBIND11_OVERRIDE (juce::Rectangle<float>, Base, getImageBounds);
×
1135
    }
1136
};
1137

1138
// =================================================================================================
1139

1140
template <class Base = juce::Label>
1141
struct PyLabel : PyComponent<Base>
1142
{
1143
    using PyComponent<Base>::PyComponent;
1144

1145
    juce::TextEditor* createEditorComponent() override
×
1146
    {
1147
        PYBIND11_OVERRIDE (juce::TextEditor*, Base, createEditorComponent);
×
1148
    }
1149

1150
    void textWasEdited() override
×
1151
    {
1152
        PYBIND11_OVERRIDE (void, Base, textWasEdited);
×
1153
    }
1154

1155
    void textWasChanged() override
×
1156
    {
1157
        PYBIND11_OVERRIDE (void, Base, textWasChanged);
×
1158
    }
1159

1160
    void editorShown (juce::TextEditor* e) override
×
1161
    {
1162
        PYBIND11_OVERRIDE (void, Base, editorShown, e);
×
1163
    }
1164

1165
    void editorAboutToBeHidden (juce::TextEditor* e) override
×
1166
    {
1167
        PYBIND11_OVERRIDE (void, Base, editorAboutToBeHidden, e);
×
1168
    }
1169
};
1170

1171
struct PyLabelListener : juce::Label::Listener
1172
{
1173
    using juce::Label::Listener::Listener;
1174

1175
    void labelTextChanged (juce::Label* labelThatHasChanged) override
×
1176
    {
1177
        PYBIND11_OVERRIDE_PURE (void, juce::Label::Listener, labelTextChanged, labelThatHasChanged);
×
1178
    }
1179

1180
    void editorShown (juce::Label* label, juce::TextEditor& e) override
×
1181
    {
1182
        PYBIND11_OVERRIDE (void, juce::Label::Listener, editorShown, label, e);
×
1183
    }
1184

1185
    void editorHidden (juce::Label* label, juce::TextEditor& e) override
×
1186
    {
1187
        PYBIND11_OVERRIDE (void, juce::Label::Listener, editorHidden, label, e);
×
1188
    }
1189
};
1190

1191
// =================================================================================================
1192

1193
template <class Base = juce::TextEditor>
1194
struct PyTextEditor : /*PyTextInputTarget<Base>,*/ PyComponent<Base>
1195
{
1196
    using PyComponent<Base>::PyComponent;
1197
    //using PyTextInputTarget<Base>::PyTextInputTarget;
1198

1199
    void addPopupMenuItems (juce::PopupMenu& menuToAddTo, const juce::MouseEvent* mouseClickEvent) override
×
1200
    {
1201
        PYBIND11_OVERRIDE (void, Base, addPopupMenuItems, menuToAddTo, mouseClickEvent);
×
1202
    }
1203

1204
    void performPopupMenuAction (int menuItemID) override
×
1205
    {
1206
        PYBIND11_OVERRIDE (void, Base, performPopupMenuAction, menuItemID);
×
1207
    }
1208
};
1209

1210
struct PyTextEditorListener : juce::TextEditor::Listener
1211
{
1212
    using juce::TextEditor::Listener::Listener;
1213

1214
    void textEditorTextChanged (juce::TextEditor& e) override
×
1215
    {
1216
        PYBIND11_OVERRIDE_PURE (void, juce::TextEditor::Listener, textEditorTextChanged, e);
×
1217
    }
1218

1219
    void textEditorReturnKeyPressed (juce::TextEditor& e) override
×
1220
    {
1221
        PYBIND11_OVERRIDE_PURE (void, juce::TextEditor::Listener, textEditorReturnKeyPressed, e);
×
1222
    }
1223

1224
    void textEditorEscapeKeyPressed (juce::TextEditor& e) override
×
1225
    {
1226
        PYBIND11_OVERRIDE_PURE (void, juce::TextEditor::Listener, textEditorEscapeKeyPressed, e);
×
1227
    }
1228

1229
    void textEditorFocusLost (juce::TextEditor& e) override
×
1230
    {
1231
        PYBIND11_OVERRIDE_PURE (void, juce::TextEditor::Listener, textEditorFocusLost, e);
×
1232
    }
1233
};
1234

1235
template <class Base = juce::TextEditor::InputFilter>
1236
struct PyTextEditorInputFilter : Base
1237
{
1238
    using Base::Base;
1239

1240
    juce::String filterNewText (juce::TextEditor& e, const juce::String& newInput) override
×
1241
    {
1242
        PYBIND11_OVERRIDE_PURE (juce::String, Base, filterNewText, e, newInput);
×
1243
    }
1244
};
1245

1246
// =================================================================================================
1247

1248
struct PyListBoxModel : juce::ListBoxModel
1249
{
1250
    using juce::ListBoxModel::ListBoxModel;
1251

1252
    int getNumRows() override
×
1253
    {
1254
        PYBIND11_OVERRIDE_PURE (int, juce::ListBoxModel, getNumRows);
×
1255
    }
1256

1257
    void paintListBoxItem (int rowNumber, juce::Graphics& g, int width, int height, bool rowIsSelected) override
×
1258
    {
1259
        {
1260
            pybind11::gil_scoped_acquire gil;
×
1261

1262
            if (pybind11::function override_ = pybind11::get_override (static_cast<juce::ListBoxModel*> (this), "paintListBoxItem"); override_)
×
1263
            {
1264
                override_ (rowNumber, std::addressof (g), width, height, rowIsSelected);
×
1265
                return;
×
1266
            }
1267
        }
1268

1269
        pybind11::pybind11_fail ("Tried to call pure virtual function \"ListBoxModel::paintListBoxItem\"");
×
1270
    }
1271

1272
    juce::Component* refreshComponentForRow (int rowNumber, bool isRowSelected, juce::Component* existingComponentToUpdate) override
×
1273
    {
1274
        {
1275
            pybind11::gil_scoped_acquire gil;
×
1276

1277
            if (pybind11::function override_ = pybind11::get_override (static_cast<juce::ListBoxModel*> (this), "refreshComponentForRow"); override_)
×
1278
            {
1279
                auto result = override_ (rowNumber, isRowSelected, existingComponentToUpdate);
×
1280
                if (result.is_none())
×
1281
                    return nullptr;
×
1282

1283
                if (! pybind11::isinstance<juce::Component> (result))
×
1284
                    pybind11::pybind11_fail ("Method \"ListBoxModel::refreshComponentForRow\" returned something else than a \"Component\"");
×
1285

1286
                return result.release().cast<juce::Component*>();
×
1287
            }
1288
        }
1289

1290
        return juce::ListBoxModel::refreshComponentForRow (rowNumber, isRowSelected, existingComponentToUpdate);
×
1291
    }
1292

1293
    juce::String getNameForRow (int rowNumber) override
×
1294
    {
1295
        PYBIND11_OVERRIDE (juce::String, juce::ListBoxModel, getNameForRow, rowNumber);
×
1296
    }
1297

1298
    void listBoxItemClicked (int row, const juce::MouseEvent& event) override
×
1299
    {
1300
        PYBIND11_OVERRIDE (void, juce::ListBoxModel, listBoxItemClicked, row, event);
×
1301
    }
1302

1303
    void listBoxItemDoubleClicked (int row, const juce::MouseEvent& event) override
×
1304
    {
1305
        PYBIND11_OVERRIDE (void, juce::ListBoxModel, listBoxItemDoubleClicked, row, event);
×
1306
    }
1307

1308
    void backgroundClicked (const juce::MouseEvent& event) override
×
1309
    {
1310
        PYBIND11_OVERRIDE (void, juce::ListBoxModel, backgroundClicked, event);
×
1311
    }
1312

1313
    void selectedRowsChanged (int lastRowSelected) override
×
1314
    {
1315
        PYBIND11_OVERRIDE (void, juce::ListBoxModel, selectedRowsChanged, lastRowSelected);
×
1316
    }
1317

1318
    void deleteKeyPressed (int lastRowSelected) override
×
1319
    {
1320
        PYBIND11_OVERRIDE (void, juce::ListBoxModel, deleteKeyPressed, lastRowSelected);
×
1321
    }
1322

1323
    void returnKeyPressed (int lastRowSelected) override
×
1324
    {
1325
        PYBIND11_OVERRIDE (void, juce::ListBoxModel, returnKeyPressed, lastRowSelected);
×
1326
    }
1327

1328
    void listWasScrolled() override
×
1329
    {
1330
        PYBIND11_OVERRIDE (void, juce::ListBoxModel, listWasScrolled);
×
1331
    }
1332

1333
    juce::var getDragSourceDescription (const juce::SparseSet<int>& rowsToDescribe) override
×
1334
    {
1335
        PYBIND11_OVERRIDE (juce::var, juce::ListBoxModel, getDragSourceDescription, rowsToDescribe);
×
1336
    }
1337

1338
    bool mayDragToExternalWindows() const override
×
1339
    {
1340
        PYBIND11_OVERRIDE (bool, juce::ListBoxModel, mayDragToExternalWindows);
×
1341
    }
1342

1343
    juce::String getTooltipForRow (int row) override
×
1344
    {
1345
        PYBIND11_OVERRIDE (juce::String, juce::ListBoxModel, getTooltipForRow, row);
×
1346
    }
1347

1348
    juce::MouseCursor getMouseCursorForRow (int row) override
×
1349
    {
1350
        PYBIND11_OVERRIDE (juce::MouseCursor, juce::ListBoxModel, getMouseCursorForRow, row);
×
1351
    }
1352
};
1353

1354
template <class Base = juce::ListBox>
1355
struct PyListBox : PyComponent<Base>
1356
{
1357
    using PyComponent<Base>::PyComponent;
1358

1359
    juce::ScaledImage createSnapshotOfRows (const juce::SparseSet<int>& rows, int& x, int& y) override
×
1360
    {
1361
        juce::ignoreUnused (rows, x, y);
×
1362

1363
        return {}; // TODO
×
1364
    }
1365
};
1366

1367
// =================================================================================================
1368

1369
template <class Base = juce::TableHeaderComponent>
1370
struct PyTableHeaderComponent : PyComponent<Base>
1371
{
1372
    using PyComponent<Base>::PyComponent;
1373

1374
    void columnClicked (int columnId, const juce::ModifierKeys& mods) override
×
1375
    {
1376
        PYBIND11_OVERRIDE (void, juce::TableHeaderComponent, columnClicked, columnId, mods);
×
1377
    }
1378

1379
    void addMenuItems (juce::PopupMenu& menu, int columnIdClicked) override
×
1380
    {
1381
        PYBIND11_OVERRIDE (void, juce::TableHeaderComponent, addMenuItems, menu, columnIdClicked);
×
1382
    }
1383

1384
    void reactToMenuItem (int menuReturnId, int columnIdClicked) override
×
1385
    {
1386
        PYBIND11_OVERRIDE (void, juce::TableHeaderComponent, reactToMenuItem, menuReturnId, columnIdClicked);
×
1387
    }
1388

1389
    void showColumnChooserMenu (int columnIdClicked) override
×
1390
    {
1391
        PYBIND11_OVERRIDE (void, juce::TableHeaderComponent, showColumnChooserMenu, columnIdClicked);
×
1392
    }
1393
};
1394

1395
struct PyTableHeaderComponentListener : juce::TableHeaderComponent::Listener
1396
{
1397
    using juce::TableHeaderComponent::Listener::Listener;
1398

1399
    void tableColumnsChanged (juce::TableHeaderComponent* tableHeader) override
×
1400
    {
1401
        PYBIND11_OVERRIDE_PURE (void, juce::TableHeaderComponent::Listener, tableColumnsChanged, tableHeader);
×
1402
    }
1403

1404
    void tableColumnsResized (juce::TableHeaderComponent* tableHeader) override
×
1405
    {
1406
        PYBIND11_OVERRIDE_PURE (void, juce::TableHeaderComponent::Listener, tableColumnsResized, tableHeader);
×
1407
    }
1408

1409
    void tableSortOrderChanged (juce::TableHeaderComponent* tableHeader) override
×
1410
    {
1411
        PYBIND11_OVERRIDE_PURE (void, juce::TableHeaderComponent::Listener, tableSortOrderChanged, tableHeader);
×
1412
    }
1413

1414
    void tableColumnDraggingChanged (juce::TableHeaderComponent* tableHeader, int columnIdNowBeingDragged) override
×
1415
    {
1416
        PYBIND11_OVERRIDE (void, juce::TableHeaderComponent::Listener, tableColumnDraggingChanged, tableHeader, columnIdNowBeingDragged);
×
1417
    }
1418
};
1419

1420
// =================================================================================================
1421

1422
struct PyTableListBoxModel : juce::TableListBoxModel
1423
{
1424
    using juce::TableListBoxModel::TableListBoxModel;
1425

1426
    int getNumRows() override
×
1427
    {
1428
        PYBIND11_OVERRIDE_PURE (int, juce::TableListBoxModel, getNumRows);
×
1429
    }
1430

1431
    void paintRowBackground (juce::Graphics& g, int rowNumber, int width, int height, bool rowIsSelected) override
×
1432
    {
1433
        {
1434
            pybind11::gil_scoped_acquire gil;
×
1435

1436
            if (pybind11::function override_ = pybind11::get_override (static_cast<juce::TableListBoxModel*> (this), "paintRowBackground"); override_)
×
1437
            {
1438
                override_ (std::addressof (g), rowNumber, width, height, rowIsSelected);
×
1439
                return;
×
1440
            }
1441
        }
1442

1443
        pybind11::pybind11_fail ("Tried to call pure virtual function \"TableListBoxModel::paintListBoxItem\"");
×
1444
    }
1445

1446
    void paintCell (juce::Graphics& g, int rowNumber, int columnId, int width, int height, bool rowIsSelected) override
×
1447
    {
1448
        {
1449
            pybind11::gil_scoped_acquire gil;
×
1450

1451
            if (pybind11::function override_ = pybind11::get_override (static_cast<juce::TableListBoxModel*> (this), "paintCell"); override_)
×
1452
            {
1453
                override_ (std::addressof (g), rowNumber, columnId, width, height, rowIsSelected);
×
1454
                return;
×
1455
            }
1456
        }
1457

1458
        pybind11::pybind11_fail ("Tried to call pure virtual function \"TableListBoxModel::paintCell\"");
×
1459
    }
1460

1461
    juce::Component* refreshComponentForCell (int rowNumber, int columnId, bool isRowSelected, juce::Component* existingComponentToUpdate) override
×
1462
    {
1463
        {
1464
            pybind11::gil_scoped_acquire gil;
×
1465

1466
            if (pybind11::function override_ = pybind11::get_override (static_cast<juce::TableListBoxModel*> (this), "refreshComponentForCell"); override_)
×
1467
            {
1468
                auto result = override_ (rowNumber, columnId, isRowSelected, existingComponentToUpdate);
×
1469
                if (result.is_none())
×
1470
                    return nullptr;
×
1471

1472
                if (! pybind11::isinstance<juce::Component> (result))
×
1473
                    pybind11::pybind11_fail ("Method \"TableListBoxModel::refreshComponentForRow\" returned something else than a \"Component\"");
×
1474

1475
                return result.release().cast<juce::Component*>();
×
1476
            }
1477
        }
1478

1479
        return juce::TableListBoxModel::refreshComponentForCell (rowNumber, columnId, isRowSelected, existingComponentToUpdate);
×
1480
    }
1481

1482
    void cellClicked (int rowNumber, int columnId, const juce::MouseEvent& event) override
×
1483
    {
1484
        PYBIND11_OVERRIDE (void, juce::TableListBoxModel, cellClicked, rowNumber, columnId, event);
×
1485
    }
1486

1487
    void cellDoubleClicked (int rowNumber, int columnId, const juce::MouseEvent& event) override
×
1488
    {
1489
        PYBIND11_OVERRIDE (void, juce::TableListBoxModel, cellDoubleClicked, rowNumber, columnId, event);
×
1490
    }
1491

1492
    void backgroundClicked (const juce::MouseEvent& event) override
×
1493
    {
1494
        PYBIND11_OVERRIDE (void, juce::TableListBoxModel, backgroundClicked, event);
×
1495
    }
1496

1497
    void sortOrderChanged (int newSortColumnId, bool isForwards) override
×
1498
    {
1499
        PYBIND11_OVERRIDE (void, juce::TableListBoxModel, sortOrderChanged, newSortColumnId, isForwards);
×
1500
    }
1501

1502
    int getColumnAutoSizeWidth (int columnId) override
×
1503
    {
1504
        PYBIND11_OVERRIDE (int, juce::TableListBoxModel, getColumnAutoSizeWidth, columnId);
×
1505
    }
1506

1507
    juce::String getCellTooltip (int rowNumber, int columnId) override
×
1508
    {
1509
        PYBIND11_OVERRIDE ( juce::String, juce::TableListBoxModel, getCellTooltip, rowNumber, columnId);
×
1510
    }
1511

1512
    void selectedRowsChanged (int lastRowSelected) override
×
1513
    {
1514
        PYBIND11_OVERRIDE (void, juce::TableListBoxModel, selectedRowsChanged, lastRowSelected);
×
1515
    }
1516

1517
    void deleteKeyPressed (int lastRowSelected) override
×
1518
    {
1519
        PYBIND11_OVERRIDE (void, juce::TableListBoxModel, deleteKeyPressed, lastRowSelected);
×
1520
    }
1521

1522
    void returnKeyPressed (int lastRowSelected) override
×
1523
    {
1524
        PYBIND11_OVERRIDE (void, juce::TableListBoxModel, returnKeyPressed, lastRowSelected);
×
1525
    }
1526

1527
    void listWasScrolled() override
×
1528
    {
1529
        PYBIND11_OVERRIDE (void, juce::TableListBoxModel, listWasScrolled);
×
1530
    }
1531

1532
    juce::var getDragSourceDescription (const juce::SparseSet<int>& currentlySelectedRows) override
×
1533
    {
1534
        PYBIND11_OVERRIDE (juce::var, juce::TableListBoxModel, getDragSourceDescription, currentlySelectedRows);
×
1535
    }
1536

1537
    bool mayDragToExternalWindows() const override
×
1538
    {
1539
        PYBIND11_OVERRIDE (bool, juce::TableListBoxModel, mayDragToExternalWindows);
×
1540
    }
1541
};
1542

1543
// =================================================================================================
1544

1545
struct PyToolbarItemFactory : juce::ToolbarItemFactory
1546
{
1547
    using juce::ToolbarItemFactory::ToolbarItemFactory;
1548

1549
    void getAllToolbarItemIds (juce::Array<int>& ids) override
×
1550
    {
1551
        {
1552
            pybind11::gil_scoped_acquire gil;
×
1553

1554
            if (pybind11::function override_ = pybind11::get_override (static_cast<juce::ToolbarItemFactory*> (this), "getAllToolbarItemIds"); override_)
×
1555
            {
1556
                auto result = override_ ();
×
1557

1558
                ids.addArray (result.cast<juce::Array<int>>());
×
1559
            }
1560
        }
1561

1562
        pybind11::pybind11_fail ("Tried to call pure virtual function \"ToolbarItemFactory::getAllToolbarItemIds\"");
×
1563
    }
1564

1565
    void getDefaultItemSet (juce::Array<int>& ids) override
×
1566
    {
1567
        {
1568
            pybind11::gil_scoped_acquire gil;
×
1569

1570
            if (pybind11::function override_ = pybind11::get_override (static_cast<juce::ToolbarItemFactory*> (this), "getDefaultItemSet"); override_)
×
1571
            {
1572
                auto result = override_ ();
×
1573

1574
                ids.addArray (result.cast<juce::Array<int>>());
×
1575
            }
1576
        }
1577

1578
        pybind11::pybind11_fail ("Tried to call pure virtual function \"ToolbarItemFactory::getDefaultItemSet\"");
×
1579
    }
1580

1581
    juce::ToolbarItemComponent* createItem (int itemId) override
×
1582
    {
1583
        PYBIND11_OVERRIDE_PURE (juce::ToolbarItemComponent*, juce::ToolbarItemFactory, createItem, itemId);
×
1584
    }
1585
};
1586

1587
template <class Base = juce::ToolbarItemComponent>
1588
struct PyToolbarItemComponent : PyButton<Base>
1589
{
1590
    using PyButton<Base>::PyButton;
1591

1592
    void setStyle (const juce::Toolbar::ToolbarItemStyle& newStyle) override
×
1593
    {
1594
        PYBIND11_OVERRIDE (void, Base, setStyle, newStyle);
×
1595
    }
1596

1597
    bool getToolbarItemSizes (int toolbarThickness, bool isToolbarVertical, int& preferredSize, int& minSize, int& maxSize) override
×
1598
    {
1599
        {
1600
            pybind11::gil_scoped_acquire gil;
×
1601

1602
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "getToolbarItemSizes"); override_)
×
1603
            {
1604
                auto result = override_ (toolbarThickness, isToolbarVertical, std::ref (preferredSize), std::ref (minSize), std::ref (maxSize));
×
1605

1606
                return pybind11::detail::cast_safe<bool> (std::move (result));
×
1607
            }
1608
        }
1609

1610
        pybind11::pybind11_fail ("Tried to call pure virtual function \"ToolbarItemComponent::getToolbarItemSizes\"");
×
1611
    }
1612

1613
    void paintButtonArea (juce::Graphics& g, int width, int height, bool isMouseOver, bool isMouseDown) override
×
1614
    {
1615
        {
1616
            pybind11::gil_scoped_acquire gil;
×
1617

1618
            if (pybind11::function override_ = pybind11::get_override (static_cast<Base*> (this), "paintButtonArea"); override_)
×
1619
            {
1620
                override_ (std::addressof (g), width, height, isMouseOver, isMouseDown);
×
1621

1622
                return;
×
1623
            }
1624
        }
1625

1626
        pybind11::pybind11_fail ("Tried to call pure virtual function \"ToolbarItemComponent::paintButtonArea\"");
×
1627
    }
1628

1629
    void contentAreaChanged (const juce::Rectangle<int>& newBounds) override
×
1630
    {
1631
        PYBIND11_OVERRIDE_PURE (void, Base, contentAreaChanged, newBounds);
×
1632
    }
1633
};
1634

1635
// ============================================================================================
1636

1637
struct PyMenuBarModel : juce::MenuBarModel
1638
{
1639
    juce::StringArray getMenuBarNames() override
×
1640
    {
1641
        PYBIND11_OVERRIDE_PURE (juce::StringArray, juce::MenuBarModel, getMenuBarNames);
×
1642
    }
1643

1644
    juce::PopupMenu getMenuForIndex (int topLevelMenuIndex, const juce::String& menuName) override
×
1645
    {
1646
        PYBIND11_OVERRIDE_PURE (juce::PopupMenu, juce::MenuBarModel, getMenuForIndex, topLevelMenuIndex, menuName);
×
1647
    }
1648

1649
    void menuItemSelected (int menuItemID, int topLevelMenuIndex) override
×
1650
    {
1651
        PYBIND11_OVERRIDE_PURE (void, juce::MenuBarModel, menuItemSelected, menuItemID, topLevelMenuIndex);
×
1652
    }
1653

1654
    void menuBarActivated (bool isActive) override
×
1655
    {
1656
        PYBIND11_OVERRIDE (void, juce::MenuBarModel, menuBarActivated, isActive);
×
1657
    }
1658
};
1659

1660
struct PyMenuBarModelListener : juce::MenuBarModel::Listener
1661
{
1662
    void menuBarItemsChanged (juce::MenuBarModel* menuBarModel) override
×
1663
    {
1664
        PYBIND11_OVERRIDE_PURE (void, juce::MenuBarModel::Listener, menuBarItemsChanged, menuBarModel);
×
1665
    }
1666

1667
    void menuCommandInvoked (juce::MenuBarModel* menuBarModel, const juce::ApplicationCommandTarget::InvocationInfo& info) override
×
1668
    {
1669
        PYBIND11_OVERRIDE_PURE (void, juce::MenuBarModel::Listener, menuCommandInvoked, menuBarModel, info);
×
1670
    }
1671

1672
    void menuBarActivated (juce::MenuBarModel* menuBarModel, bool isActive) override
×
1673
    {
1674
        PYBIND11_OVERRIDE_PURE (void, juce::MenuBarModel::Listener, menuBarActivated, menuBarModel, isActive);
×
1675
    }
1676
};
1677

1678
// =================================================================================================
1679

1680
template <class Base = juce::Slider>
1681
struct PySlider : PyComponent<Base>
1682
{
1683
    using PyComponent<Base>::PyComponent;
1684

1685
    void startedDragging() override
×
1686
    {
1687
        PYBIND11_OVERRIDE (void, Base, startedDragging);
×
1688
    }
1689

1690
    void stoppedDragging() override
×
1691
    {
1692
        PYBIND11_OVERRIDE (void, Base, stoppedDragging);
×
1693
    }
1694

1695
    void valueChanged() override
×
1696
    {
1697
        PYBIND11_OVERRIDE (void, Base, valueChanged);
×
1698
    }
1699

1700
    double getValueFromText (const juce::String& text) override
×
1701
    {
1702
        PYBIND11_OVERRIDE (double, Base, getValueFromText, text);
×
1703
    }
1704

1705
    juce::String getTextFromValue (double value) override
×
1706
    {
1707
        PYBIND11_OVERRIDE (juce::String, Base, getTextFromValue, value);
×
1708
    }
1709

1710
    double proportionOfLengthToValue (double proportion) override
×
1711
    {
1712
        PYBIND11_OVERRIDE (double, Base, proportionOfLengthToValue, proportion);
×
1713
    }
1714

1715
    double valueToProportionOfLength (double value) override
×
1716
    {
1717
        PYBIND11_OVERRIDE (double, Base, valueToProportionOfLength, value);
×
1718
    }
1719

1720
    double snapValue (double attemptedValue, juce::Slider::DragMode dragMode) override
×
1721
    {
1722
        PYBIND11_OVERRIDE (double, Base, snapValue, attemptedValue, dragMode);
×
1723
    }
1724
};
1725

1726
struct PySliderListener : juce::Slider::Listener
1727
{
1728
    using juce::Slider::Listener::Listener;
1729

1730
    void sliderValueChanged (juce::Slider* slider) override
×
1731
    {
1732
        PYBIND11_OVERRIDE_PURE (void, juce::Slider::Listener, sliderValueChanged, slider);
×
1733
    }
1734

1735
    void sliderDragStarted (juce::Slider* slider) override
×
1736
    {
1737
        PYBIND11_OVERRIDE (void, juce::Slider::Listener, sliderDragStarted, slider);
×
1738
    }
1739

1740
    void sliderDragEnded (juce::Slider* slider) override
×
1741
    {
1742
        PYBIND11_OVERRIDE (void, juce::Slider::Listener, sliderDragEnded, slider);
×
1743
    }
1744
};
1745

1746
// ============================================================================================
1747

1748
template <class Base = juce::DocumentWindow>
1749
struct PyDocumentWindow : PyComponent<Base>
1750
{
1751
    using PyComponent<Base>::PyComponent;
1752

1753
    void closeButtonPressed() override
×
1754
    {
1755
        PYBIND11_OVERRIDE (void, Base, closeButtonPressed);
×
1756
    }
1757

1758
    void minimiseButtonPressed() override
×
1759
    {
1760
        PYBIND11_OVERRIDE (void, Base, minimiseButtonPressed);
×
1761
    }
1762

1763
    void maximiseButtonPressed() override
×
1764
    {
1765
        PYBIND11_OVERRIDE (void, Base, maximiseButtonPressed);
×
1766
    }
1767
};
1768

1769
// ============================================================================================
1770

1771
template <class Base = juce::TooltipWindow>
1772
struct PyTooltipWindow : PyComponent<Base>
1773
{
1774
    using PyComponent<Base>::PyComponent;
1775

NEW
1776
    juce::String getTipFor (juce::Component& c) override
×
1777
    {
NEW
1778
        PYBIND11_OVERRIDE (juce::String, Base, getTipFor, c);
×
1779
    }
1780
};
1781

1782
// ============================================================================================
1783

1784
template <class Base = juce::ThreadWithProgressWindow>
1785
struct PyThreadWithProgressWindow : PyThread<Base>
1786
{
1787
    using PyThread<Base>::PyThread;
1788

NEW
1789
    void threadComplete (bool userPressedCancel) override
×
1790
    {
NEW
1791
        PYBIND11_OVERRIDE (void, Base, threadComplete, userPressedCancel);
×
1792
    }
1793
};
1794

1795
} // namespace popsicle::Bindings
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

© 2025 Coveralls, Inc