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