wxdragon-sys 0.9.16

Raw FFI bindings to libwxdragon (which statically links wxWidgets).
Documentation
#include <wx/wxprec.h>
#include <wx/wx.h>
#include "../include/wxdragon.h"
#include <wx/bmpbuttn.h> // For wxBitmapButton
#include <wx/bitmap.h>   // For wxBitmap

extern "C" {

// wxd_BitmapButton_Create is already implemented (likely in button.cpp or a shared file if not generated by a macro)
// For now, we assume its implementation exists based on prior Rust FFI calls.
// If it's missing, the linker will complain, and it can be added here or to button.cpp.

// --- Setters for individual bitmaps after creation ---
WXD_EXPORTED void
wxd_BitmapButton_SetBitmapLabel(wxd_BitmapButton_t* self, const wxd_Bitmap_t* bitmap)
{
    if (!self)
        return;
    wxBitmapButton* btn = reinterpret_cast<wxBitmapButton*>(self);
    const wxBitmap* bmp = reinterpret_cast<const wxBitmap*>(bitmap);
    // wxBitmapButton::SetBitmapLabel takes a wxBitmap, not wxBitmapBundle
    btn->SetBitmapLabel(bmp ? *bmp : wxNullBitmap);
}

WXD_EXPORTED void
wxd_BitmapButton_SetBitmapDisabled(wxd_BitmapButton_t* self, const wxd_Bitmap_t* bitmap)
{
    if (!self)
        return;
    wxBitmapButton* btn = reinterpret_cast<wxBitmapButton*>(self);
    const wxBitmap* bmp = reinterpret_cast<const wxBitmap*>(bitmap);
    btn->SetBitmapDisabled(bmp ? *bmp : wxNullBitmap);
}

WXD_EXPORTED void
wxd_BitmapButton_SetBitmapFocus(wxd_BitmapButton_t* self, const wxd_Bitmap_t* bitmap)
{
    if (!self)
        return;
    wxBitmapButton* btn = reinterpret_cast<wxBitmapButton*>(self);
    const wxBitmap* bmp = reinterpret_cast<const wxBitmap*>(bitmap);
    btn->SetBitmapFocus(bmp ? *bmp : wxNullBitmap);
}

WXD_EXPORTED void
wxd_BitmapButton_SetBitmapHover(wxd_BitmapButton_t* self, const wxd_Bitmap_t* bitmap)
{
    if (!self)
        return;
    wxBitmapButton* btn = reinterpret_cast<wxBitmapButton*>(self);
    const wxBitmap* bmp = reinterpret_cast<const wxBitmap*>(bitmap);
    btn->SetBitmapCurrent(bmp ? *bmp : wxNullBitmap); // wxWidgets uses SetBitmapCurrent for hover
}

// --- Getters for individual bitmaps ---
// Note: wxBitmapButton::GetBitmapLabel etc. return const wxBitmap&.
// Returning wxd_Bitmap_t* implies either returning a pointer to an internal bitmap (dangerous if its lifetime isn't managed by Rust)
// or creating a new wxBitmap and returning a pointer to that (Rust would need to free it).
// For now, these will return a const_cast pointer to the internal bitmap if it's valid.
// The Rust side should treat this as an unowned reference and ideally copy it if modification or longer lifetime is needed.

WXD_EXPORTED wxd_Bitmap_t*
wxd_BitmapButton_GetBitmapLabel(wxd_BitmapButton_t* self)
{
    if (!self)
        return nullptr;
    wxBitmapButton* btn = reinterpret_cast<wxBitmapButton*>(self);
    const wxBitmap& bmp = btn->GetBitmapLabel();
    if (!bmp.IsOk())
        return nullptr;
    return (wxd_Bitmap_t*)new wxBitmap(bmp); // Return a heap-allocated copy
}

WXD_EXPORTED wxd_Bitmap_t*
wxd_BitmapButton_GetBitmapDisabled(wxd_BitmapButton_t* self)
{
    if (!self)
        return nullptr;
    wxBitmapButton* btn = reinterpret_cast<wxBitmapButton*>(self);
    const wxBitmap& bmp = btn->GetBitmapDisabled();
    if (!bmp.IsOk())
        return nullptr;
    return (wxd_Bitmap_t*)new wxBitmap(bmp); // Return a heap-allocated copy
}

WXD_EXPORTED wxd_Bitmap_t*
wxd_BitmapButton_GetBitmapFocus(wxd_BitmapButton_t* self)
{
    if (!self)
        return nullptr;
    wxBitmapButton* btn = reinterpret_cast<wxBitmapButton*>(self);
    const wxBitmap& bmp = btn->GetBitmapFocus();
    if (!bmp.IsOk())
        return nullptr;
    return (wxd_Bitmap_t*)new wxBitmap(bmp); // Return a heap-allocated copy
}

WXD_EXPORTED wxd_Bitmap_t*
wxd_BitmapButton_GetBitmapHover(wxd_BitmapButton_t* self)
{
    if (!self)
        return nullptr;
    wxBitmapButton* btn = reinterpret_cast<wxBitmapButton*>(self);
    const wxBitmap& bmp = btn->GetBitmapCurrent(); // wxWidgets uses GetBitmapCurrent for hover
    if (!bmp.IsOk())
        return nullptr;
    return (wxd_Bitmap_t*)new wxBitmap(bmp); // Return a heap-allocated copy
}

} // extern "C"