]> git.saurik.com Git - wxWidgets.git/blame_incremental - contrib/src/fl/cbcustom.cpp
Fixed bug in setting/getting value for wxComboBox. Read-only status
[wxWidgets.git] / contrib / src / fl / cbcustom.cpp
... / ...
CommitLineData
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
31class cbContextMenuHandler : public wxEvtHandler
32{
33public:
34 cbSimpleCustomizationPlugin* mpBackRef;
35
36public:
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
50BEGIN_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
60END_EVENT_TABLE()
61
62void cbContextMenuHandler::OnCommandEvents( wxCommandEvent& evt )
63{
64 //wxMessageBox("Wowwwww, Yeah!");
65
66 mpBackRef->OnMenuItemSelected( evt );
67}
68
69/***** Implementation for class cbSimpleCustomizationPlugin *****/
70
71IMPLEMENT_DYNAMIC_CLASS( cbSimpleCustomizationPlugin, cbPluginBase )
72
73BEGIN_EVENT_TABLE( cbSimpleCustomizationPlugin, cbPluginBase )
74
75 EVT_PL_CUSTOMIZE_BAR ( cbSimpleCustomizationPlugin::OnCustomizeBar )
76 EVT_PL_CUSTOMIZE_LAYOUT( cbSimpleCustomizationPlugin::OnCustomizeLayout )
77
78END_EVENT_TABLE()
79
80cbSimpleCustomizationPlugin::cbSimpleCustomizationPlugin(void)
81{}
82
83cbSimpleCustomizationPlugin::cbSimpleCustomizationPlugin( wxFrameLayout* pPanel, int paneMask )
84
85 : cbPluginBase( pPanel, paneMask )
86{}
87
88void 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
98void 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, wxID_ANY, 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
152void 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() - CB_CUSTOMIZE_MENU_FIRST_ITEM_ID ];
163
164 wxASSERT( pBar ); // DBG::
165
166 // "inverse" bar-visibility of the selected bar
167
168 int newState;
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 == FL_ALIGN_TOP ||
179 pBar->mAlignment == FL_ALIGN_BOTTOM )
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 mpLayout->RepositionFloatedBar( pBar );
198 }
199
200 // menu-item-selected event is "eaten"
201}
202