]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/minifram.cpp
wxMimeTypesManagerImpl::GetFileTypeFromMimeType() implemented
[wxWidgets.git] / src / gtk1 / minifram.cpp
CommitLineData
b2b3ccc5
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: minifram.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "minifram.h"
12#endif
13
14#include "wx/minifram.h"
15#include "wx/dcscreen.h"
16
83624f79
RR
17#include "gtk/gtk.h"
18#include "wx/gtk/win_gtk.h"
19
b2b3ccc5
RR
20//-----------------------------------------------------------------------------
21// "clicked"
22//-----------------------------------------------------------------------------
23
24static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxMiniFrame *mf )
25{
26 mf->Close();
27}
28
29//-----------------------------------------------------------------------------
30// wxMiniFrame
31//-----------------------------------------------------------------------------
32
33BEGIN_EVENT_TABLE(wxMiniFrame,wxFrame)
34 EVT_PAINT(wxMiniFrame::OnPaint)
35 EVT_MOUSE_EVENTS(wxMiniFrame::OnMouse)
36END_EVENT_TABLE()
37
38IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame,wxFrame)
39
40bool wxMiniFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
41 const wxPoint &pos, const wxSize &size,
42 long style, const wxString &name )
43{
44 style = style | wxSIMPLE_BORDER;
45
46 m_miniEdge = 3;
47 m_miniTitle = 13;
48 m_isDragging = FALSE;
49 m_oldX = -1;
50 m_oldY = -1;
51 m_diffX = 0;
52 m_diffY = 0;
53
54 wxFrame::Create( parent, id, title, pos, size, style, name );
55
56 GtkWidget *close_button = gtk_button_new_with_label( "x" );
57
58 gtk_myfixed_put( GTK_MYFIXED(m_wxwindow), close_button, 4, 4 );
59 gtk_widget_set_usize( close_button, 12, 11 );
60
61 gtk_widget_show( close_button );
62
63 gtk_signal_connect( GTK_OBJECT(close_button), "clicked",
64 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
65
66 return TRUE;
67}
68
69void wxMiniFrame::OnPaint( wxPaintEvent &WXUNUSED(event) )
70{
71 if (m_miniTitle == 0) return;
72 if (m_title.IsEmpty()) return;
73
74 wxPaintDC dc(this);
75
76 dc.SetBrush( *wxTRANSPARENT_BRUSH );
77 dc.DrawRectangle( 0, 0, m_width, m_height );
78
79 dc.SetPen( *wxWHITE_PEN );
80 dc.DrawLine( 1, 1, m_width-2, 1 );
81 dc.DrawLine( 1, 1, 1, m_height-2 );
82
83 dc.SetPen( *wxMEDIUM_GREY_PEN );
84 dc.DrawLine( 1, m_height-1, m_width-2, m_height-1 );
85 dc.DrawLine( m_width-1, 1, m_width-1, m_height-2 );
86
87 dc.SetBrush( *wxBLUE_BRUSH );
88 dc.SetPen( *wxTRANSPARENT_PEN );
89 dc.DrawRectangle( m_miniEdge, m_miniEdge, m_width - 2*m_miniEdge, m_miniTitle );
90
91 dc.SetTextForeground( *wxWHITE );
92 dc.SetFont( *wxSMALL_FONT );
93 dc.DrawText( m_title, 14 + m_miniEdge, 1 + m_miniEdge );
94}
95
96void wxMiniFrame::DrawFrame( int x, int y )
97{
98 int org_x = 0;
99 int org_y = 0;
100 gdk_window_get_origin( m_wxwindow->window, &org_x, &org_y );
101 x += org_x;
102 y += org_y;
103
104 wxScreenDC dc;
105 dc.SetLogicalFunction( wxXOR );
106
107 dc.DrawRectangle( x, y, m_width, m_height );
108}
109
110void wxMiniFrame::OnMouse( wxMouseEvent &event )
111{
112 int x = event.GetX();
113 int y = event.GetY();
114
115 if (event.LeftDown())
116 {
117 CaptureMouse();
118 m_diffX = x;
119 m_diffY = y;
120 DrawFrame( 0, 0 );
121 m_oldX = 0;
122 m_oldY = 0;
123 m_isDragging = TRUE;
124 return;
125 }
126
127 if (event.Dragging() && m_isDragging)
128 {
129 DrawFrame( m_oldX, m_oldY );
130 m_oldX = x - m_diffX;
131 m_oldY = y - m_diffY;
132 DrawFrame( m_oldX, m_oldY );
133 return;
134 }
135
136 if (event.LeftUp() && m_isDragging)
137 {
138 m_isDragging = FALSE;
139 DrawFrame( m_oldX, m_oldY );
140 ReleaseMouse();
141
142 int org_x = 0;
143 int org_y = 0;
144 gdk_window_get_origin( m_wxwindow->window, &org_x, &org_y );
145 x += org_x - m_diffX;
146 y += org_y - m_diffY;
147 m_x = x;
148 m_y = y;
149 gtk_widget_set_uposition( m_widget, x, y );
150
151 return;
152 }
153
154 event.Skip();
155}
156