1/////////////////////////////////////////////////////////////////////////////
2// Name:        src/motif/statbmp.cpp
3// Purpose:     wxStaticBitmap
4// Author:      Julian Smart
5// Modified by:
6// Created:     17/09/98
7// RCS-ID:      $Id: statbmp.cpp 41640 2006-10-05 19:34:25Z MBN $
8// Copyright:   (c) Julian Smart
9// Licence:     wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#include "wx/statbmp.h"
16
17#ifdef __VMS__
18#pragma message disable nosimpint
19#endif
20#include <Xm/Xm.h>
21#include <Xm/Label.h>
22#include <Xm/LabelG.h>
23#ifdef __VMS__
24#pragma message enable nosimpint
25#endif
26
27#include "wx/motif/private.h"
28
29IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
30
31/*
32 * wxStaticBitmap
33 */
34
35bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id,
36           const wxBitmap& bitmap,
37           const wxPoint& pos,
38           const wxSize& size,
39           long style,
40           const wxString& name)
41{
42    if( !CreateControl( parent, id, pos, size, style, wxDefaultValidator,
43                        name ) )
44        return false;
45
46    m_messageBitmap = bitmap;
47    m_messageBitmapOriginal = bitmap;
48
49    Widget parentWidget = (Widget) parent->GetClientWidget();
50
51    m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("staticBitmap",
52#if wxUSE_GADGETS
53                    xmLabelGadgetClass, parentWidget,
54#else
55                    xmLabelWidgetClass, parentWidget,
56#endif
57                    XmNalignment, XmALIGNMENT_BEGINNING,
58                    NULL);
59
60    ChangeBackgroundColour ();
61
62    DoSetBitmap();
63
64    ChangeFont(false);
65
66    wxSize actualSize(size);
67    // work around the cases where the bitmap is a wxNull(Icon/Bitmap)
68    if (actualSize.x == -1)
69        actualSize.x = bitmap.Ok() ? bitmap.GetWidth() : 1;
70    if (actualSize.y == -1)
71        actualSize.y = bitmap.Ok() ? bitmap.GetHeight() : 1;
72    AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
73                  pos.x, pos.y, actualSize.x, actualSize.y);
74
75    return true;
76}
77
78wxStaticBitmap::~wxStaticBitmap()
79{
80    SetBitmap(wxNullBitmap);
81}
82
83void wxStaticBitmap::DoSetBitmap()
84{
85    Widget widget = (Widget) m_mainWidget;
86    int w2, h2;
87
88    if (m_messageBitmapOriginal.Ok())
89    {
90        w2 = m_messageBitmapOriginal.GetWidth();
91        h2 = m_messageBitmapOriginal.GetHeight();
92
93        Pixmap pixmap;
94
95        // Must re-make the bitmap to have its transparent areas drawn
96        // in the current widget background colour.
97        if (m_messageBitmapOriginal.GetMask())
98        {
99            WXPixel backgroundPixel;
100            XtVaGetValues( widget, XmNbackground, &backgroundPixel,
101                NULL);
102
103            wxColour col;
104            col.SetPixel(backgroundPixel);
105
106            wxBitmap newBitmap = wxCreateMaskedBitmap(m_messageBitmapOriginal, col);
107            m_messageBitmap = newBitmap;
108
109            pixmap = (Pixmap) m_messageBitmap.GetDrawable();
110        }
111        else
112        {
113            m_bitmapCache.SetBitmap( m_messageBitmap );
114            pixmap = (Pixmap)m_bitmapCache.GetLabelPixmap(widget);
115        }
116
117        XtVaSetValues (widget,
118            XmNlabelPixmap, pixmap,
119            XmNlabelType, XmPIXMAP,
120            NULL);
121
122        SetSize(w2, h2);
123    }
124    else
125    {
126        // Null bitmap: must not use current pixmap
127        // since it is no longer valid.
128        XtVaSetValues (widget,
129            XmNlabelType, XmSTRING,
130            XmNlabelPixmap, XmUNSPECIFIED_PIXMAP,
131            NULL);
132    }
133}
134
135void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap)
136{
137    m_messageBitmap = bitmap;
138    m_messageBitmapOriginal = bitmap;
139
140    DoSetBitmap();
141}
142
143void wxStaticBitmap::ChangeBackgroundColour()
144{
145    wxWindow::ChangeBackgroundColour();
146
147    // must recalculate the background colour
148    m_bitmapCache.SetColoursChanged();
149    DoSetBitmap();
150}
151
152void wxStaticBitmap::ChangeForegroundColour()
153{
154    m_bitmapCache.SetColoursChanged();
155    wxWindow::ChangeForegroundColour();
156}
157