view anagram/guisupport/windowreg.h @ 7:57b2cc9b87f7

Use memcpy instead of strncpy when we know the length anyway. Modern gcc seems to think it knows how to detect misuse of strncpy, but it's wrong (in fact: very, very wrong) and the path of least resistance is to not try to fight with it.
author David A. Holland
date Mon, 30 May 2022 23:47:52 -0400
parents 13d2b8934445
children
line wrap: on
line source

/*
 * AnaGram, A System for Syntax Directed Programming
 * Copyright 1997-2002 Parsifal Software. All Rights Reserved.
 * See the file COPYING for license and usage terms.
 *
 * windowreg.h
 */

#ifndef WINDOWREG_H
#define WINDOWREG_H

//#include <icmdevt.hpp>
//#include <ievent.hpp>
//#include <iframe.hpp>

#include "action.h"
#include "agstack.h"
#include "agstring.h"

class AgFrame;


struct WindowRecord {
  int id;
  AgString title;
  AgAction action;
  AgFrame *window;
  int isShowing;
  int isActive;
  WindowRecord()
    : id(0), title(), action(), window(0), isShowing(0), isActive(0)
  {}
  WindowRecord(int i, const AgString t, const AgAction a, AgFrame *w)
    : id(i), title(t), action(a), window(w), isShowing(1), isActive(1)
  {}
  int operator < (const WindowRecord &w) const { return title < w.title; }
};

class WindowRegistry {
private:
  AgStack<WindowRecord> registry;

public:
  int cascadeFlag;

  WindowRegistry()
    : cascadeFlag(0)
  {}

  void registerId(AgFrame *window, AgString title, AgAction action);
  void refresh(AgString title);

  void remove(int id);
  AgFrame *find(AgString title);
  AgFrame *find(int id);
  AgString getTitle(int id);

  //void bubbleUp(int id);
  void markActive(int id);
  void clearActive();
  int action(int id);
  int action(AgString title);
  int size() { return registry.size();}

  WindowRecord &operator [] (int k) {
    return registry[k];
  }
};


#endif /* WINDOWREG_H */