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 OnMenuCommand( wxCommandEvent
& evt
);
35 void OnCommandEvents( wxCommandEvent
& evt
);
40 // FIXME:: is this "safe" ?
42 #define CB_CUSTOMIZE_MENU_FIRST_ITEM_ID 17500
44 /***** Implementation for helper class cbContextMenuHandler *****/
46 BEGIN_EVENT_TABLE( cbContextMenuHandler
, wxEvtHandler
)
48 // FIXME:: what is the right range for these ids ? so that they
49 // would not collide with user commands?
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
)
58 void cbContextMenuHandler::OnCommandEvents( wxCommandEvent
& evt
)
60 //wxMessageBox("Wowwwww, Yeah!");
62 mpBackRef
->OnMenuItemSelected( evt
);
65 /***** Implementation for class cbSimpleCustomizationPlugin *****/
67 IMPLEMENT_DYNAMIC_CLASS( cbSimpleCustomizationPlugin
, cbPluginBase
)
69 BEGIN_EVENT_TABLE( cbSimpleCustomizationPlugin
, cbPluginBase
)
71 EVT_PL_CUSTOMIZE_BAR ( cbSimpleCustomizationPlugin::OnCustomizeBar
)
72 EVT_PL_CUSTOMIZE_LAYOUT( cbSimpleCustomizationPlugin::OnCustomizeLayout
)
76 cbSimpleCustomizationPlugin::cbSimpleCustomizationPlugin(void)
79 cbSimpleCustomizationPlugin::cbSimpleCustomizationPlugin( wxFrameLayout
* pPanel
, int paneMask
)
81 : cbPluginBase( pPanel
, paneMask
)
84 void cbSimpleCustomizationPlugin::OnCustomizeBar( cbCustomizeBarEvent
& event
)
86 // ingnore bar customization, treat it
87 // as layout-customization...ugly, eh?
89 cbCustomizeLayoutEvent
clEvt( event
.mClickPos
);
91 OnCustomizeLayout( clEvt
);
94 void cbSimpleCustomizationPlugin::OnCustomizeLayout( cbCustomizeLayoutEvent
& event
)
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");
99 int id
= CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
;
101 wxMenu
* pMenu
= new wxMenu();
103 BarArrayT
& bars
= mpLayout
->GetBars();
105 for( size_t i
= 0; i
!= bars
.GetCount(); ++i
)
107 cbBarInfo
& bar
= *bars
[i
];
109 bool isHidden
= ( bar
.mState
== wxCBAR_HIDDEN
);
111 wxString
* pHelpStr
= ( isHidden
) ? &helpStr1
: &helpStr2
;
113 pMenu
->Append( id
, bar
.mName
, *pHelpStr
, true );
115 pMenu
->Check( id
, (isHidden
== false) );
120 // Customization dialog not implemented, so don't show the menu item
122 pMenu
->AppendSeparator();
123 pMenu
->Append( id
, "Customize...", "Show layout customization dialog", false );
125 mCustMenuItemId
= id
;
127 cbContextMenuHandler
* pHandler
= new cbContextMenuHandler();
128 pHandler
->mpBackRef
= this;
130 wxWindow
* pFrm
= &mpLayout
->GetParentFrame();
132 // FOR NOW FOR NOW:: to work-around wxFrame's (MSW) nasty event-handling bugs!!!
134 wxWindow
* pTmpWnd
= new wxWindow( pFrm
, wxID_ANY
, event
.mClickPos
, wxSize(0,0) );
136 pMenu
->SetEventHandler( pHandler
);
138 pTmpWnd
->PopupMenu( pMenu
, 0,0 );
145 // event is "eaten" by this plugin
148 void cbSimpleCustomizationPlugin::OnMenuItemSelected( wxCommandEvent
& event
)
150 if ( event
.GetId() == mCustMenuItemId
)
152 wxMessageBox(wxT("Customization dialog box is not supported by this plugin yet"));
158 cbBarInfo
* pBar
= mpLayout
->GetBars()[ event
.GetId() - CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
];
160 wxASSERT( pBar
); // DBG::
162 // "inverse" bar-visibility of the selected bar
166 if ( pBar
->mState
== wxCBAR_HIDDEN
)
168 if ( pBar
->mAlignment
== -1 )
170 pBar
->mAlignment
= 0; // just remove "-1" marking
171 newState
= wxCBAR_FLOATING
;
174 if ( pBar
->mAlignment
== FL_ALIGN_TOP
||
175 pBar
->mAlignment
== FL_ALIGN_BOTTOM
)
177 newState
= wxCBAR_DOCKED_HORIZONTALLY
;
179 newState
= wxCBAR_DOCKED_VERTICALLY
;
183 newState
= wxCBAR_HIDDEN
;
185 if ( pBar
->mState
== wxCBAR_FLOATING
)
187 pBar
->mAlignment
= -1;
190 mpLayout
->SetBarState( pBar
, newState
, true );
192 if ( newState
== wxCBAR_FLOATING
)
193 mpLayout
->RepositionFloatedBar( pBar
);
196 // menu-item-selected event is "eaten"