1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: cbSimpleCustomizationPlugin class declaration
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "cbcustom.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/fl/cbcustom.h"
29 // helper class to receive menu customization event
31 class cbContextMenuHandler
: public wxEvtHandler
34 cbSimpleCustomizationPlugin
* mpBackRef
;
37 void OnMenuCommand( wxCommandEvent
& evt
);
39 void OnCommandEvents( wxCommandEvent
& evt
);
44 // FIXME:: is this "safe" ?
46 #define CB_CUSTOMIZE_MENU_FIRST_ITEM_ID 17500
48 /***** Implementation for helper class cbContextMenuHandler *****/
50 BEGIN_EVENT_TABLE( cbContextMenuHandler
, wxEvtHandler
)
52 // FIXME:: what is the right range for these ids ? so that they
53 // would not collide with user commands?
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
)
62 void cbContextMenuHandler::OnCommandEvents( wxCommandEvent
& evt
)
64 //wxMessageBox("Wowwwww, Yeah!");
66 mpBackRef
->OnMenuItemSelected( evt
);
69 /***** Implementation for class cbSimpleCustomizationPlugin *****/
71 IMPLEMENT_DYNAMIC_CLASS( cbSimpleCustomizationPlugin
, cbPluginBase
)
73 BEGIN_EVENT_TABLE( cbSimpleCustomizationPlugin
, cbPluginBase
)
75 EVT_PL_CUSTOMIZE_BAR ( cbSimpleCustomizationPlugin::OnCustomizeBar
)
76 EVT_PL_CUSTOMIZE_LAYOUT( cbSimpleCustomizationPlugin::OnCustomizeLayout
)
80 cbSimpleCustomizationPlugin::cbSimpleCustomizationPlugin(void)
83 cbSimpleCustomizationPlugin::cbSimpleCustomizationPlugin( wxFrameLayout
* pPanel
, int paneMask
)
85 : cbPluginBase( pPanel
, paneMask
)
88 void cbSimpleCustomizationPlugin::OnCustomizeBar( cbCustomizeBarEvent
& event
)
90 // ingnore bar customization, treat it
91 // as layout-customization...ugly, eh?
93 cbCustomizeLayoutEvent
clEvt( event
.mClickPos
);
95 OnCustomizeLayout( clEvt
);
98 void cbSimpleCustomizationPlugin::OnCustomizeLayout( cbCustomizeLayoutEvent
& event
)
100 wxString helpStr1
= "Select this item to show the corresponding control bar";
101 wxString helpStr2
= "Select this itme to hide the corresponding control bar";
103 int id
= CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
;
105 wxMenu
* pMenu
= new wxMenu();
107 BarArrayT
& bars
= mpLayout
->GetBars();
109 for( size_t i
= 0; i
!= bars
.GetCount(); ++i
)
111 cbBarInfo
& bar
= *bars
[i
];
113 bool isHidden
= ( bar
.mState
== wxCBAR_HIDDEN
);
115 wxString
* pHelpStr
= ( isHidden
) ? &helpStr1
: &helpStr2
;
117 pMenu
->Append( id
, bar
.mName
, *pHelpStr
, TRUE
);
119 pMenu
->Check( id
, (isHidden
== FALSE
) );
124 pMenu
->AppendSeparator();
125 pMenu
->Append( id
, "Customize...", "Show layout customization dialog", FALSE
);
126 mCustMenuItemId
= id
;
128 cbContextMenuHandler
* pHandler
= new cbContextMenuHandler();
129 pHandler
->mpBackRef
= this;
131 wxWindow
* pFrm
= &mpLayout
->GetParentFrame();
133 // FOR NOW FOR NOW:: to work-around wxFrame's (MSW) nasty event-handling bugs!!!
135 wxWindow
* pTmpWnd
= new wxWindow( pFrm
, -1, event
.mClickPos
, wxSize(0,0) );
137 pMenu
->SetEventHandler( pHandler
);
139 pTmpWnd
->PopupMenu( pMenu
, 0,0 );
146 // event is "eaten" by this plugin
149 void cbSimpleCustomizationPlugin::OnMenuItemSelected( wxCommandEvent
& event
)
151 if ( event
.GetId() == mCustMenuItemId
)
153 wxMessageBox("Customization dialog box is not supported by this plugin yet");
159 cbBarInfo
* pBar
= mpLayout
->GetBars()[ event
.GetId() -
160 CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
163 wxASSERT( pBar
); // DBG::
165 // "inverse" bar-visibility of the selected bar
169 if ( pBar
->mState
== wxCBAR_HIDDEN
)
171 if ( pBar
->mAlignment
== -1 )
173 pBar
->mAlignment
= 0; // just remove "-1" marking
174 newState
= wxCBAR_FLOATING
;
177 if ( pBar
->mAlignment
== FL_ALIGN_TOP
||
178 pBar
->mAlignment
== FL_ALIGN_BOTTOM
)
180 newState
= wxCBAR_DOCKED_HORIZONTALLY
;
182 newState
= wxCBAR_DOCKED_VERTICALLY
;
186 newState
= wxCBAR_HIDDEN
;
188 if ( pBar
->mState
== wxCBAR_FLOATING
)
190 pBar
->mAlignment
= -1;
193 mpLayout
->SetBarState( pBar
, newState
, TRUE
);
195 if ( newState
== wxCBAR_FLOATING
)
197 mpLayout
->RepositionFloatedBar( pBar
);
200 // menu-item-selected event is "eaten"