]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/ogl/studio/cspalette.cpp
Make radiobutton tab behaviour the same on MSW
[wxWidgets.git] / contrib / samples / ogl / studio / cspalette.cpp
CommitLineData
1fc25a89
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: cspalette.cpp
3// Purpose: OGLEdit palette
4// Author: Julian Smart
5// Modified by:
6// Created: 12/07/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
2ba06d5a 9// Licence: wxWindows licence
1fc25a89
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13// #pragma implementation
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
92a19c2e 17#include "wx/wxprec.h"
1fc25a89
JS
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/laywin.h>
28
29#include <ctype.h>
30#include <stdlib.h>
31#include <math.h>
32
33#include "doc.h"
34#include "view.h"
35#include "studio.h"
36#include "cspalette.h"
37#include "symbols.h"
38
618f2efa 39#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
1fc25a89
JS
40#include "bitmaps/arrow.xpm"
41#include "bitmaps/texttool.xpm"
42#endif
43
44/*
45 * Object editor tool palette
46 *
47 */
48
49csEditorToolPalette::csEditorToolPalette(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
50 long style):
51 TOOLPALETTECLASS(parent, id, pos, size, style)
52{
53 m_currentlySelected = -1;
54
55 SetMaxRowsCols(1, 1000);
56}
57
58bool csEditorToolPalette::OnLeftClick(int toolIndex, bool toggled)
59{
60 // BEGIN mutual exclusivity code
61 if (toggled && (m_currentlySelected != -1) && (toolIndex != m_currentlySelected))
2ba06d5a 62 ToggleTool(m_currentlySelected, false);
1fc25a89
JS
63
64 if (toggled)
65 m_currentlySelected = toolIndex;
66 else if (m_currentlySelected == toolIndex)
67 m_currentlySelected = -1;
68 // END mutual exclusivity code
69
2ba06d5a 70 return true;
1fc25a89
JS
71}
72
73void csEditorToolPalette::OnMouseEnter(int toolIndex)
74{
d96cdd4a 75#if wxUSE_STATUSBAR
1484b5cc 76 wxString msg = wxEmptyString;
1fc25a89 77 if (toolIndex == PALETTE_ARROW)
1484b5cc 78 msg = _T("Pointer");
1fc25a89
JS
79 else if (toolIndex != -1)
80 {
81 csSymbol* symbol = wxGetApp().GetSymbolDatabase()->FindSymbol(toolIndex);
82 if (symbol)
83 msg = symbol->GetName();
84 }
85 ((wxFrame*) wxGetApp().GetTopWindow())->SetStatusText(msg);
d96cdd4a
WS
86#else
87 wxUnusedVar(toolIndex);
88#endif // wxUSE_STATUSBAR
1fc25a89
JS
89}
90
91void csEditorToolPalette::SetSize(int x, int y, int width, int height, int sizeFlags)
92{
93 TOOLPALETTECLASS::SetSize(x, y, width, height, sizeFlags);
94}
95
96void csEditorToolPalette::SetSelection(int sel)
97{
98 if ((sel != m_currentlySelected) && (m_currentlySelected != -1))
99 {
2ba06d5a 100 ToggleTool(m_currentlySelected, false);
1fc25a89
JS
101 }
102 m_currentlySelected = sel;
2ba06d5a 103 ToggleTool(m_currentlySelected, true);
1fc25a89
JS
104}
105
106bool csApp::CreatePalette(wxFrame *parent)
107{
108 // First create a layout window
109 wxSashLayoutWindow* win = new wxSashLayoutWindow(parent, ID_LAYOUT_WINDOW_PALETTE, wxDefaultPosition, wxSize(200, 30), wxNO_BORDER|wxSW_3D|wxCLIP_CHILDREN);
110 win->SetDefaultSize(wxSize(10000, 40));
111 win->SetOrientation(wxLAYOUT_HORIZONTAL);
112 win->SetAlignment(wxLAYOUT_TOP);
e1c6c6ae 113 win->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
2ba06d5a 114 win->SetSashVisible(wxSASH_BOTTOM, true);
1fc25a89
JS
115
116 m_diagramPaletteSashWindow = win;
117
2ba06d5a 118 m_diagramPaletteSashWindow->Show(false);
1fc25a89
JS
119
120 // Load palette bitmaps
121#ifdef __WXMSW__
1484b5cc
VS
122 wxBitmap PaletteArrow(_T("arrowtool"));
123 wxBitmap TextTool(_T("texttool"));
0a0352f2 124 wxSize toolBitmapSize(32, 32);
618f2efa 125#elif defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
1fc25a89
JS
126 wxBitmap PaletteArrow(arrow_xpm);
127 wxBitmap TextTool(texttool_xpm);
0a0352f2 128 wxSize toolBitmapSize(22, 22);
1fc25a89
JS
129#endif
130
2ba06d5a 131 csEditorToolPalette *palette = new csEditorToolPalette(m_diagramPaletteSashWindow, ID_DIAGRAM_PALETTE, wxPoint(0, 0), wxDefaultSize, wxTB_HORIZONTAL|wxNO_BORDER);
1fc25a89
JS
132
133 palette->SetMargins(2, 2);
134
0a0352f2 135 palette->SetToolBitmapSize(toolBitmapSize);
1fc25a89 136
422d0ff0
WS
137 palette->AddTool(PALETTE_ARROW, PaletteArrow, wxNullBitmap, true, 0, wxDefaultCoord, NULL, _T("Pointer"));
138 palette->AddTool(PALETTE_TEXT_TOOL, TextTool, wxNullBitmap, true, 0, wxDefaultCoord, NULL, _T("Text"));
1fc25a89 139
42c37dec 140 wxChar** symbols = new wxChar*[20];
0a0352f2
JS
141 int noSymbols = 0;
142
1484b5cc 143 symbols[noSymbols] = _T("Wide Rectangle");
0a0352f2
JS
144 noSymbols ++;
145
1484b5cc 146 symbols[noSymbols] = _T("Thin Rectangle");
0a0352f2
JS
147 noSymbols ++;
148
1484b5cc 149 symbols[noSymbols] = _T("Triangle");
0a0352f2
JS
150 noSymbols ++;
151
1484b5cc 152 symbols[noSymbols] = _T("Octagon");
0a0352f2
JS
153 noSymbols ++;
154
155 // For some reason, we're getting Gdk errors with
156 // some shapes, such as ones that use DrawEllipse.
157#ifndef __WXGTK__
1484b5cc 158 symbols[noSymbols] = _T("Group");
0a0352f2
JS
159 noSymbols ++;
160
1484b5cc 161 symbols[noSymbols] = _T("Circle");
0a0352f2
JS
162 noSymbols ++;
163
1484b5cc 164 symbols[noSymbols] = _T("Circle shadow");
0a0352f2
JS
165 noSymbols ++;
166
1484b5cc 167 symbols[noSymbols] = _T("SemiCircle");
0a0352f2
JS
168 noSymbols ++;
169#endif
170
171 int i;
172 for (i = 0; i < noSymbols; i++)
173 {
174 csSymbol* symbol = GetSymbolDatabase()->FindSymbol(symbols[i]);
175 if (symbol)
176 {
177 wxBitmap* bitmap = GetSymbolDatabase()->CreateToolBitmap(symbol, toolBitmapSize);
422d0ff0 178 palette->AddTool(symbol->GetToolId(), *bitmap, wxNullBitmap, true, 0, wxDefaultCoord, NULL, symbol->GetName());
0a0352f2
JS
179
180 delete bitmap;
181 }
182 }
183 delete[] symbols;
184
185#if 0
1fc25a89
JS
186 wxNode* node = GetSymbolDatabase()->GetSymbols().First();
187 while (node)
188 {
189 csSymbol* symbol = (csSymbol*) node->Data();
0a0352f2
JS
190
191 wxBitmap* bitmap = GetSymbolDatabase()->CreateToolBitmap(symbol, toolBitmapSize);
422d0ff0 192 palette->AddTool(symbol->GetToolId(), *bitmap, wxNullBitmap, true, 0, wxDefaultCoord, NULL, symbol->GetName());
1fc25a89
JS
193
194 delete bitmap;
195
196 node = node->Next();
197 }
0a0352f2 198#endif
1fc25a89
JS
199
200 palette->Realize();
201
202 palette->SetSelection(PALETTE_ARROW);
203 m_diagramPalette = palette;
204
2ba06d5a 205 return true;
1fc25a89
JS
206}
207