]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/fl/cbcustom.cpp
Added regex to WXINC line (patch from Markus G)
[wxWidgets.git] / contrib / src / fl / cbcustom.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: No names yet.
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
5 // Modified by:
6 // Created: 06/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "cbcustom.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 #include "wx/fl/cbcustom.h"
28
29 // helper class to receive menu customization event
30
31 class cbContextMenuHandler : public wxEvtHandler
32 {
33 public:
34 cbSimpleCustomizationPlugin* mpBackRef;
35
36 public:
37 void OnMenuCommand( wxCommandEvent& evt );
38
39 void OnCommandEvents( wxCommandEvent& evt );
40
41 DECLARE_EVENT_TABLE()
42 };
43
44 // FIXME:: is this "safe" ?
45
46 #define CB_CUSTOMIZE_MENU_FIRST_ITEM_ID 17500
47
48 /***** Implementation for helper class cbContextMenuHandler *****/
49
50 BEGIN_EVENT_TABLE( cbContextMenuHandler, wxEvtHandler )
51
52 // FIXME:: what is the right range for these ids ? so that they
53 // would not collide with user commands?
54
55 EVT_COMMAND_RANGE( CB_CUSTOMIZE_MENU_FIRST_ITEM_ID,
56 CB_CUSTOMIZE_MENU_FIRST_ITEM_ID + 300,
57 wxEVT_COMMAND_MENU_SELECTED,
58 cbContextMenuHandler::OnCommandEvents )
59
60 END_EVENT_TABLE()
61
62 void cbContextMenuHandler::OnCommandEvents( wxCommandEvent& evt )
63 {
64 //wxMessageBox("Wowwwww, Yeah!");
65
66 mpBackRef->OnMenuItemSelected( evt );
67 }
68
69 /***** Implementation for class cbSimpleCustomizationPlugin *****/
70
71 IMPLEMENT_DYNAMIC_CLASS( cbSimpleCustomizationPlugin, cbPluginBase )
72
73 BEGIN_EVENT_TABLE( cbSimpleCustomizationPlugin, cbPluginBase )
74
75 EVT_PL_CUSTOMIZE_BAR ( cbSimpleCustomizationPlugin::OnCustomizeBar )
76 EVT_PL_CUSTOMIZE_LAYOUT( cbSimpleCustomizationPlugin::OnCustomizeLayout )
77
78 END_EVENT_TABLE()
79
80 cbSimpleCustomizationPlugin::cbSimpleCustomizationPlugin(void)
81 {}
82
83 cbSimpleCustomizationPlugin::cbSimpleCustomizationPlugin( wxFrameLayout* pPanel, int paneMask )
84
85 : cbPluginBase( pPanel, paneMask )
86 {}
87
88 void cbSimpleCustomizationPlugin::OnCustomizeBar( cbCustomizeBarEvent& event )
89 {
90 // ingnore bar customization, treat it
91 // as layout-customization...ugly, eh?
92
93 cbCustomizeLayoutEvent clEvt( event.mClickPos );
94
95 OnCustomizeLayout( clEvt );
96 }
97
98 void cbSimpleCustomizationPlugin::OnCustomizeLayout( cbCustomizeLayoutEvent& event )
99 {
100 wxString helpStr1 = "Select this item to show the corresponding control bar";
101 wxString helpStr2 = "Select this itme to hide the corresponding control bar";
102
103 int id = CB_CUSTOMIZE_MENU_FIRST_ITEM_ID;
104
105 wxMenu* pMenu = new wxMenu();
106
107 BarArrayT& bars = mpLayout->GetBars();
108
109 for( size_t i = 0; i != bars.GetCount(); ++i )
110 {
111 cbBarInfo& bar = *bars[i];
112
113 bool isHidden = ( bar.mState == wxCBAR_HIDDEN );
114
115 wxString* pHelpStr = ( isHidden ) ? &helpStr1 : &helpStr2;
116
117 pMenu->Append( id, bar.mName, *pHelpStr, TRUE );
118
119 pMenu->Check( id, (isHidden == FALSE) );
120
121 ++id;
122 }
123
124 pMenu->AppendSeparator();
125 pMenu->Append( id, "Customize...", "Show layout customization dialog", FALSE );
126 mCustMenuItemId = id;
127
128 cbContextMenuHandler* pHandler = new cbContextMenuHandler();
129 pHandler->mpBackRef = this;
130
131 wxWindow* pFrm = &mpLayout->GetParentFrame();
132
133 // FOR NOW FOR NOW:: to work-around wxFrame's (MSW) nasty event-handling bugs!!!
134
135 wxWindow* pTmpWnd = new wxWindow( pFrm, -1, event.mClickPos, wxSize(0,0) );
136
137 pMenu->SetEventHandler( pHandler );
138
139 pTmpWnd->PopupMenu( pMenu, 0,0 );
140
141 pTmpWnd->Destroy();
142
143 delete pMenu;
144 delete pHandler;
145
146 // event is "eaten" by this plugin
147 }
148
149 void cbSimpleCustomizationPlugin::OnMenuItemSelected( wxCommandEvent& event )
150 {
151 if ( event.GetId() == mCustMenuItemId )
152 {
153 wxMessageBox("Customization dialog box is not supported by this plugin yet");
154
155 return;
156 }
157 else
158 {
159 cbBarInfo* pBar = mpLayout->GetBars()[ event.GetId() -
160 CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
161 ];
162
163 wxASSERT( pBar ); // DBG::
164
165 // "inverse" bar-visibility of the selected bar
166
167 int newState = 0;
168
169 if ( pBar->mState == wxCBAR_HIDDEN )
170 {
171 if ( pBar->mAlignment == -1 )
172 {
173 pBar->mAlignment = 0; // just remove "-1" marking
174 newState = wxCBAR_FLOATING;
175 }
176 else
177 if ( pBar->mAlignment == FL_ALIGN_TOP ||
178 pBar->mAlignment == FL_ALIGN_BOTTOM )
179
180 newState = wxCBAR_DOCKED_HORIZONTALLY;
181 else
182 newState = wxCBAR_DOCKED_VERTICALLY;
183 }
184 else
185 {
186 newState = wxCBAR_HIDDEN;
187
188 if ( pBar->mState == wxCBAR_FLOATING )
189
190 pBar->mAlignment = -1;
191 }
192
193 mpLayout->SetBarState( pBar, newState, TRUE );
194
195 if ( newState == wxCBAR_FLOATING )
196
197 mpLayout->RepositionFloatedBar( pBar );
198 }
199
200 // menu-item-selected event is "eaten"
201 }
202