Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
NyqTextCtrl Class Reference

#include <NyqBench.h>

Inheritance diagram for NyqTextCtrl:
[legend]
Collaboration diagram for NyqTextCtrl:
[legend]

Public Member Functions

 NyqTextCtrl (wxWindow *parent, wxWindowID id, const wxString &value, const wxPoint &pos, const wxSize &size, int style=0)
 
void SetFocusFromKbd ()
 
void MarkDirty ()
 
void GoMatch ()
 
void GoTop ()
 
void GoUp ()
 
void GoPrev ()
 
void GoNext ()
 

Private Member Functions

void OnKeyUp (wxKeyEvent &e)
 
void OnChar (wxKeyEvent &e)
 
void OnUpdate (wxUpdateUIEvent &e)
 
void MoveCursor (long first, long second)
 
void Colorize (long left, long right)
 
void FindParens ()
 
 DECLARE_EVENT_TABLE ()
 

Private Attributes

wxLongToLongHashMap mLeftParens
 
wxLongToLongHashMap mRightParens
 
long mLeftParen
 
long mRightParen
 
long mLastCaretPos
 
wxTextAttr mOn
 
wxTextAttr mOff
 

Detailed Description

Definition at line 29 of file NyqBench.h.

Constructor & Destructor Documentation

◆ NyqTextCtrl()

NyqTextCtrl::NyqTextCtrl ( wxWindow *  parent,
wxWindowID  id,
const wxString &  value,
const wxPoint &  pos,
const wxSize &  size,
int  style = 0 
)

Definition at line 162 of file NyqBench.cpp.

168: wxTextCtrl(parent, id, value, pos, size, style)
169{
170 mLastCaretPos = -1;
171 mLeftParen = -1;
172 mRightParen = -1;
173
174 mOn.SetTextColour(*wxRED);
175 mOff.SetTextColour(*wxBLACK);
176}
wxTextAttr mOff
Definition: NyqBench.h:70
wxTextAttr mOn
Definition: NyqBench.h:69
long mRightParen
Definition: NyqBench.h:65
long mLastCaretPos
Definition: NyqBench.h:67
long mLeftParen
Definition: NyqBench.h:64

Member Function Documentation

◆ Colorize()

void NyqTextCtrl::Colorize ( long  left,
long  right 
)
private

Definition at line 397 of file NyqBench.cpp.

398{
399 // Hide any previously highlighted parens
400 if (mLeftParen >= 0) {
401#if defined(__WXMSW__)
402 Freeze(); // Prevents selection flashing on Windows
403#endif
404
405 SetStyle(mLeftParen, mLeftParen + 1, mOff);
407 mLeftParen = -1;
408 mRightParen = -1;
409
410#if defined(__WXMSW__)
411 Thaw(); // Prevents selection flashing on Windows
412#endif
413 }
414
415 mLeftParen = left;
416 mRightParen = right;
417
418 if (mLeftParen != -1) {
419 SetStyle(mLeftParen, mLeftParen + 1, mOn);
420 SetStyle(mRightParen, mRightParen + 1, mOn);
421
422 SetStyle(mLeftParen + 1, mLeftParen + 1, mOff);
423 SetStyle(mRightParen + 1, mRightParen + 1, mOff);
424 }
425}
wxLongToLongHashMap mLeftParens
Definition: NyqBench.h:61

References mLeftParen, mLeftParens, mOff, mOn, and mRightParen.

Referenced by MoveCursor(), OnKeyUp(), and OnUpdate().

Here is the caller graph for this function:

◆ DECLARE_EVENT_TABLE()

NyqTextCtrl::DECLARE_EVENT_TABLE ( )
private

◆ FindParens()

void NyqTextCtrl::FindParens ( )
private

Definition at line 427 of file NyqBench.cpp.

428{
429 wxString text = GetValue();
430 bool inquotes = false;
431 wxArrayInt stack;
432 long len = (long) text.Length();
433 long pos;
434
435 mLeftParens.clear();
436 mRightParens.clear();
437
438 for (pos = 0; pos < len; pos++) {
439 wxChar c = text[pos];
440 switch (c)
441 {
442 case wxT('"'):
443 inquotes = !inquotes;
444 break;
445
446 case wxT(';'):
447 if (!inquotes) {
448 pos = (long)text.find(wxT('\n'), pos);
449 if (pos == (long)wxString::npos) {
450 pos = len;
451 }
452 }
453 break;
454
455 case wxT('#'):
456 if (!inquotes) {
457 long ndx = pos + 1;
458 if (ndx < len && text[(int)ndx] == wxT('|')) {
459 // Shamelessly stolen from xlread.c/pcomment()
460 wxChar lastch = -1;
461 int n = 1;
462
463 /* look for the matching delimiter (and handle nesting) */
464 while (n > 0 && ++pos < len) {
465 wxChar ch = text[(int)pos];
466 if (lastch == '|' && ch == '#') {
467 --n;
468 ch = -1;
469 }
470 else if (lastch == '#' && ch == '|') {
471 ++n;
472 ch = -1;
473 }
474 lastch = ch;
475 }
476 }
477 }
478 break;
479
480 case wxT('('):
481 if (!inquotes) {
482 stack.Add(pos);
483 }
484 break;
485
486 case wxT(')'):
487 if (!inquotes) {
488 if (stack.GetCount() > 0) {
489 int left = stack.Last();
490 stack.RemoveAt(stack.GetCount() - 1);
491
492 mLeftParens[left] = pos;
493 mRightParens[pos] = left;
494 }
495 }
496 break;
497 }
498 }
499}
wxT("CloseDown"))
wxLongToLongHashMap mRightParens
Definition: NyqBench.h:62
constexpr size_t npos(-1)

References mLeftParens, mRightParens, Tuple::detail::npos(), and wxT().

Referenced by MarkDirty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GoMatch()

void NyqTextCtrl::GoMatch ( )

Definition at line 291 of file NyqBench.cpp.

292{
294}
void MoveCursor(long first, long second)
Definition: NyqBench.cpp:380

References mLeftParen, MoveCursor(), and mRightParen.

Referenced by NyqBench::OnGoMatch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GoNext()

void NyqTextCtrl::GoNext ( )

Definition at line 360 of file NyqBench.cpp.

361{
362 wxLongToLongHashMap::const_iterator it;
363 long first = -1;
364 long second = -1;
365
366 if (mLeftParen != -1) {
367 for (it = mLeftParens.begin(); it != mLeftParens.end(); it++) {
368 if (it->first > mLeftParen && (first == -1 || it->first < first)) {
369 first = it->first;
370 second = it->second;
371 }
372 }
373 }
374
375 if (first != -1) {
376 MoveCursor(first, second);
377 }
378}

References mLeftParen, mLeftParens, and MoveCursor().

Referenced by NyqBench::OnGoNext().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GoPrev()

void NyqTextCtrl::GoPrev ( )

Definition at line 340 of file NyqBench.cpp.

341{
342 wxLongToLongHashMap::const_iterator it;
343 long first = -1;
344 long second = -1;
345
346 if (mLeftParen != -1) {
347 for (it = mLeftParens.begin(); it != mLeftParens.end(); it++) {
348 if (it->first < mLeftParen && it->first >= first) {
349 first = it->first;
350 second = it->second;
351 }
352 }
353 }
354
355 if (first != -1) {
356 MoveCursor(first, second);
357 }
358}

References mLeftParen, mLeftParens, and MoveCursor().

Referenced by NyqBench::OnGoPrev().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GoTop()

void NyqTextCtrl::GoTop ( )

Definition at line 296 of file NyqBench.cpp.

297{
298 wxLongToLongHashMap::const_iterator it;
299 long first = -1;
300 long second = -1;
301
302 if (mLeftParen != -1) {
303 for (it = mLeftParens.begin(); it != mLeftParens.end(); it++) {
304 if (mLeftParen > it->first && mLeftParen < it->second) {
305 if (first == -1 || it->first < first) {
306 first = it->first;
307 second = it->second;
308 }
309 }
310 }
311 }
312
313 if (first != -1) {
314 MoveCursor(first, second);
315 }
316}

References mLeftParen, mLeftParens, and MoveCursor().

Referenced by NyqBench::OnGoTop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GoUp()

void NyqTextCtrl::GoUp ( )

Definition at line 318 of file NyqBench.cpp.

319{
320 wxLongToLongHashMap::const_iterator it;
321 long first = -1;
322 long second = -1;
323
324 if (mLeftParen != -1) {
325 for (it = mLeftParens.begin(); it != mLeftParens.end(); it++) {
326 if (mLeftParen > it->first && mLeftParen < it->second) {
327 if (first == -1 || it->first > first) {
328 first = it->first;
329 second = it->second;
330 }
331 }
332 }
333 }
334
335 if (first != -1) {
336 MoveCursor(first, second);
337 }
338}

References mLeftParen, mLeftParens, and MoveCursor().

Referenced by NyqBench::OnGoUp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MarkDirty()

void NyqTextCtrl::MarkDirty ( )

Definition at line 189 of file NyqBench.cpp.

190{
191 wxTextCtrl::MarkDirty();
192 FindParens();
193}
void FindParens()
Definition: NyqBench.cpp:427

References FindParens().

Here is the call graph for this function:

◆ MoveCursor()

void NyqTextCtrl::MoveCursor ( long  first,
long  second 
)
private

Definition at line 380 of file NyqBench.cpp.

381{
382 int pos = GetInsertionPoint();
383 int lpos = wxMax(0, pos - 1);
384
385 wxString text = GetRange(lpos, pos);
386
387 if (text[0] == wxT('(')) {
388 SetInsertionPoint(first + 1);
389 Colorize(first, second);
390 }
391 else if (text[0] == wxT(')')) {
392 SetInsertionPoint(second + 1);
393 Colorize(first, second);
394 }
395}
void Colorize(long left, long right)
Definition: NyqBench.cpp:397

References Colorize(), and wxT().

Referenced by GoMatch(), GoNext(), GoPrev(), GoTop(), and GoUp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnChar()

void NyqTextCtrl::OnChar ( wxKeyEvent &  e)
private

Definition at line 195 of file NyqBench.cpp.

196{
197 e.Skip();
198
199 // Hide any previously highlighted parens
200 if (mLeftParen >= 0) {
201#if defined(__WXMSW__)
202 Freeze(); // Prevents selection flashing on Windows
203#endif
204
205 SetStyle(mLeftParen, mLeftParen + 1, mOff);
207 mLeftParen = -1;
208 mRightParen = -1;
209
210#if defined(__WXMSW__)
211 Thaw(); // Prevents selection flashing on Windows
212#endif
213 }
214}

References mLeftParen, mLeftParens, mOff, and mRightParen.

◆ OnKeyUp()

void NyqTextCtrl::OnKeyUp ( wxKeyEvent &  e)
private

Definition at line 241 of file NyqBench.cpp.

242{
243 e.Skip();
244
245 int pos = GetInsertionPoint();
246 int lpos = wxMax(0, pos - 1);
247
248 wxString text = GetRange(lpos, pos);
249
250 if (text[0] == wxT('(')) {
251 wxLongToLongHashMap::const_iterator left = mLeftParens.find(lpos);
252 if (left != mLeftParens.end()) {
253 Colorize(lpos, left->second);
254 }
255 }
256 else if (text[0] == wxT(')')) {
257 wxLongToLongHashMap::const_iterator right = mRightParens.find(lpos);
258 if (right != mRightParens.end()) {
259 Colorize(right->second, lpos);
260 }
261 }
262}

References Colorize(), mLeftParens, mRightParens, and wxT().

Here is the call graph for this function:

◆ OnUpdate()

void NyqTextCtrl::OnUpdate ( wxUpdateUIEvent &  e)
private

Definition at line 264 of file NyqBench.cpp.

265{
266 int pos = GetInsertionPoint();
267
268 if (pos != mLastCaretPos) {
269 int lpos = wxMax(0, pos - 1);
270
271 wxString text = GetRange(lpos, pos);
272 if (text.Length() > 0) {
273 if (text[0] == wxT('(')) {
274 wxLongToLongHashMap::const_iterator left = mLeftParens.find(lpos);
275 if (left != mLeftParens.end()) {
276 Colorize(lpos, left->second);
277 }
278 }
279 else if (text[0] == wxT(')')) {
280 wxLongToLongHashMap::const_iterator right = mRightParens.find(lpos);
281 if (right != mRightParens.end()) {
282 Colorize(right->second, lpos);
283 }
284 }
285 }
286
287 mLastCaretPos = pos;
288 }
289}

References Colorize(), mLastCaretPos, mLeftParens, mRightParens, and wxT().

Here is the call graph for this function:

◆ SetFocusFromKbd()

void NyqTextCtrl::SetFocusFromKbd ( )

Definition at line 178 of file NyqBench.cpp.

179{
180#if defined(__WXMSW__)
181 // We do this to prevent wxMSW from selecting all text when the
182 // user tabs into the text controls.
183 wxWindowBase::SetFocusFromKbd();
184#else
185 wxTextCtrl::SetFocusFromKbd();
186#endif
187}

Member Data Documentation

◆ mLastCaretPos

long NyqTextCtrl::mLastCaretPos
private

Definition at line 67 of file NyqBench.h.

Referenced by OnUpdate().

◆ mLeftParen

long NyqTextCtrl::mLeftParen
private

Definition at line 64 of file NyqBench.h.

Referenced by Colorize(), GoMatch(), GoNext(), GoPrev(), GoTop(), GoUp(), and OnChar().

◆ mLeftParens

wxLongToLongHashMap NyqTextCtrl::mLeftParens
private

Definition at line 61 of file NyqBench.h.

Referenced by Colorize(), FindParens(), GoNext(), GoPrev(), GoTop(), GoUp(), OnChar(), OnKeyUp(), and OnUpdate().

◆ mOff

wxTextAttr NyqTextCtrl::mOff
private

Definition at line 70 of file NyqBench.h.

Referenced by Colorize(), and OnChar().

◆ mOn

wxTextAttr NyqTextCtrl::mOn
private

Definition at line 69 of file NyqBench.h.

Referenced by Colorize().

◆ mRightParen

long NyqTextCtrl::mRightParen
private

Definition at line 65 of file NyqBench.h.

Referenced by Colorize(), GoMatch(), and OnChar().

◆ mRightParens

wxLongToLongHashMap NyqTextCtrl::mRightParens
private

Definition at line 62 of file NyqBench.h.

Referenced by FindParens(), OnKeyUp(), and OnUpdate().


The documentation for this class was generated from the following files: