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