1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: cbSimpleCustomizationPlugin class declaration
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/fl/cbcustom.h"
25 // helper class to receive menu customization event
27 class cbContextMenuHandler
: public wxEvtHandler
30 cbSimpleCustomizationPlugin
* mpBackRef
;
33 void OnCommandEvents( wxCommandEvent
& evt
);
38 // FIXME:: is this "safe" ?
40 #define CB_CUSTOMIZE_MENU_FIRST_ITEM_ID 17500
42 /***** Implementation for helper class cbContextMenuHandler *****/
44 BEGIN_EVENT_TABLE( cbContextMenuHandler
, wxEvtHandler
)
46 // FIXME:: what is the right range for these ids ? so that they
47 // would not collide with user commands?
49 EVT_COMMAND_RANGE( CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
,
50 CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
+ 300,
51 wxEVT_COMMAND_MENU_SELECTED
,
52 cbContextMenuHandler::OnCommandEvents
)
56 void cbContextMenuHandler::OnCommandEvents( wxCommandEvent
& evt
)
58 //wxMessageBox("Wowwwww, Yeah!");
60 mpBackRef
->OnMenuItemSelected( evt
);
63 /***** Implementation for class cbSimpleCustomizationPlugin *****/
65 IMPLEMENT_DYNAMIC_CLASS( cbSimpleCustomizationPlugin
, cbPluginBase
)
67 BEGIN_EVENT_TABLE( cbSimpleCustomizationPlugin
, cbPluginBase
)
69 EVT_PL_CUSTOMIZE_BAR ( cbSimpleCustomizationPlugin::OnCustomizeBar
)
70 EVT_PL_CUSTOMIZE_LAYOUT( cbSimpleCustomizationPlugin::OnCustomizeLayout
)
74 cbSimpleCustomizationPlugin::cbSimpleCustomizationPlugin(void)
77 cbSimpleCustomizationPlugin::cbSimpleCustomizationPlugin( wxFrameLayout
* pPanel
, int paneMask
)
79 : cbPluginBase( pPanel
, paneMask
)
82 void cbSimpleCustomizationPlugin::OnCustomizeBar( cbCustomizeBarEvent
& event
)
84 // ingnore bar customization, treat it
85 // as layout-customization...ugly, eh?
87 cbCustomizeLayoutEvent
clEvt( event
.mClickPos
);
89 OnCustomizeLayout( clEvt
);
92 void cbSimpleCustomizationPlugin::OnCustomizeLayout( cbCustomizeLayoutEvent
& event
)
94 wxString helpStr1
= wxT("Select this item to show the corresponding control bar");
95 wxString helpStr2
= wxT("Select this itme to hide the corresponding control bar");
97 int id
= CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
;
99 wxMenu
* pMenu
= new wxMenu();
101 BarArrayT
& bars
= mpLayout
->GetBars();
103 for( size_t i
= 0; i
!= bars
.GetCount(); ++i
)
105 cbBarInfo
& bar
= *bars
[i
];
107 bool isHidden
= ( bar
.mState
== wxCBAR_HIDDEN
);
109 wxString
* pHelpStr
= ( isHidden
) ? &helpStr1
: &helpStr2
;
111 pMenu
->Append( id
, bar
.mName
, *pHelpStr
, true );
113 pMenu
->Check( id
, (isHidden
== false) );
118 // Customization dialog not implemented, so don't show the menu item
120 pMenu
->AppendSeparator();
121 pMenu
->Append( id
, "Customize...", "Show layout customization dialog", false );
123 mCustMenuItemId
= id
;
125 cbContextMenuHandler
* pHandler
= new cbContextMenuHandler();
126 pHandler
->mpBackRef
= this;
128 wxWindow
* pFrm
= &mpLayout
->GetParentFrame();
130 // FOR NOW FOR NOW:: to work-around wxFrame's (MSW) nasty event-handling bugs!!!
132 wxWindow
* pTmpWnd
= new wxWindow( pFrm
, wxID_ANY
, event
.mClickPos
, wxSize(0,0) );
134 pMenu
->SetEventHandler( pHandler
);
136 pTmpWnd
->PopupMenu( pMenu
, 0,0 );
143 // event is "eaten" by this plugin
146 void cbSimpleCustomizationPlugin::OnMenuItemSelected( wxCommandEvent
& event
)
148 if ( event
.GetId() == mCustMenuItemId
)
150 wxMessageBox(wxT("Customization dialog box is not supported by this plugin yet"));
156 cbBarInfo
* pBar
= mpLayout
->GetBars()[ event
.GetId() - CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
];
158 wxASSERT( pBar
); // DBG::
160 // "inverse" bar-visibility of the selected bar
164 if ( pBar
->mState
== wxCBAR_HIDDEN
)
166 if ( pBar
->mAlignment
== -1 )
168 pBar
->mAlignment
= 0; // just remove "-1" marking
169 newState
= wxCBAR_FLOATING
;
172 if ( pBar
->mAlignment
== FL_ALIGN_TOP
||
173 pBar
->mAlignment
== FL_ALIGN_BOTTOM
)
175 newState
= wxCBAR_DOCKED_HORIZONTALLY
;
177 newState
= wxCBAR_DOCKED_VERTICALLY
;
181 newState
= wxCBAR_HIDDEN
;
183 if ( pBar
->mState
== wxCBAR_FLOATING
)
185 pBar
->mAlignment
= -1;
188 mpLayout
->SetBarState( pBar
, newState
, true );
190 if ( newState
== wxCBAR_FLOATING
)
191 mpLayout
->RepositionFloatedBar( pBar
);
194 // menu-item-selected event is "eaten"