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