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