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