]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/fl/cbcustom.cpp
Inital fill in background, removed tabs, -1->wxID_ANY, TRUE->true, FALSE->false
[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 #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 = wxT("Select this item to show the corresponding control bar");
101 wxString helpStr2 = wxT("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 // Customization dialog not implemented, so don't show the menu item
125 #if 0
126 pMenu->AppendSeparator();
127 pMenu->Append( id, "Customize...", "Show layout customization dialog", FALSE );
128 #endif
129 mCustMenuItemId = id;
130
131 cbContextMenuHandler* pHandler = new cbContextMenuHandler();
132 pHandler->mpBackRef = this;
133
134 wxWindow* pFrm = &mpLayout->GetParentFrame();
135
136 // FOR NOW FOR NOW:: to work-around wxFrame's (MSW) nasty event-handling bugs!!!
137
138 wxWindow* pTmpWnd = new wxWindow( pFrm, -1, event.mClickPos, wxSize(0,0) );
139
140 pMenu->SetEventHandler( pHandler );
141
142 pTmpWnd->PopupMenu( pMenu, 0,0 );
143
144 pTmpWnd->Destroy();
145
146 delete pMenu;
147 delete pHandler;
148
149 // event is "eaten" by this plugin
150 }
151
152 void cbSimpleCustomizationPlugin::OnMenuItemSelected( wxCommandEvent& event )
153 {
154 if ( event.GetId() == mCustMenuItemId )
155 {
156 wxMessageBox(wxT("Customization dialog box is not supported by this plugin yet"));
157
158 return;
159 }
160 else
161 {
162 cbBarInfo* pBar = mpLayout->GetBars()[ event.GetId() -
163 CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
164 ];
165
166 wxASSERT( pBar ); // DBG::
167
168 // "inverse" bar-visibility of the selected bar
169
170 int newState;
171
172 if ( pBar->mState == wxCBAR_HIDDEN )
173 {
174 if ( pBar->mAlignment == -1 )
175 {
176 pBar->mAlignment = 0; // just remove "-1" marking
177 newState = wxCBAR_FLOATING;
178 }
179 else
180 if ( pBar->mAlignment == FL_ALIGN_TOP ||
181 pBar->mAlignment == FL_ALIGN_BOTTOM )
182
183 newState = wxCBAR_DOCKED_HORIZONTALLY;
184 else
185 newState = wxCBAR_DOCKED_VERTICALLY;
186 }
187 else
188 {
189 newState = wxCBAR_HIDDEN;
190
191 if ( pBar->mState == wxCBAR_FLOATING )
192
193 pBar->mAlignment = -1;
194 }
195
196 mpLayout->SetBarState( pBar, newState, TRUE );
197
198 if ( newState == wxCBAR_FLOATING )
199
200 mpLayout->RepositionFloatedBar( pBar );
201 }
202
203 // menu-item-selected event is "eaten"
204 }
205