AWind
MainWindow.h
1 #pragma once
2 /*
3  AWind.h - Arduino window library support for Color TFT LCD Boards
4  Copyright (C)2015 Andrei Degtiarev. All right reserved
5 
6 
7  You can always find the latest version of the library at
8  https://github.com/AndreiDegtiarev/AWind
9 
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the CC BY-NC-SA 3.0 license.
13  Please see the included documents for further information.
14 
15  Commercial use of this library requires you to buy a license that
16  will allow commercial use. This includes using the library,
17  modified or not, as a tool to sell products.
18 
19  The license applies to all part of the library including the
20  examples and tools supplied with the library.
21 */
22 #include "Dialog.h"
23 #include "ATimer.h"
24 #include "ICriticalProcess.h"
26 {
27 public:
28  virtual void loop()=0;
29 };
31 {
32 public:
33  const __FlashStringHelper *ID;
34  Dialog *DlgWindow;
35 };
36 class TextBoxNumber;
39 {
40  Window *_modalWindow;
41  ILoopProcess *_idleProcess;
42  LinkedList<DialogEntry> _dialogs;
43  LinkedList<ATimer> _timers;
44  DialogResults _lastDialogResults;
45  bool _isModalDialogActive;
46 public:
48 
52  MainWindow(int width,int height):Window(F("Main"),0,0,width,height),_isModalDialogActive(false)
53  {
54  _modalWindow=NULL;
55  }
57  void RegisterDialog(const __FlashStringHelper *id,Dialog * widnow)
58  {
59  widnow->RegisterEndDialogEventReceiver(this);
60 
61  DialogEntry *dlgEntry=new DialogEntry();
62  dlgEntry->ID=id;
63  dlgEntry->DlgWindow=widnow;
64  _dialogs.Add(dlgEntry);
65  widnow->SetVisible(false);
66  AddChild(widnow);
67  }
69  Dialog *FindDialog(const __FlashStringHelper *id)
70  {
71  for(int i=0;i<_dialogs.Count();i++)
72  {
73  //out<<F("Find dialog:")<<id<<F(" Candidate:")<<_dialogs[i]->ID<<F(" Res:");
74  if(AHelper::compare_F(id, _dialogs[i]->ID))
75  return _dialogs[i]->DlgWindow;
76 
77  }
78  return NULL;
79  }
81  DialogResults ProcessDoDialog(Window *dlg)
82  {
83  //out<<F("Begin::ProcessDoDialog")<<endln;
84  _isModalDialogActive=true;
85  Window *lastModalWindow=ModalWnd();
86  SetModalWindow(dlg);
87  dlg->SetVisible(true);
88  dlg->Invalidate();
89 
90  while(_isModalDialogActive)
91  {
92  _idleProcess->loop();
93  }
94  dlg->SetVisible(false);
95  _isModalDialogActive=lastModalWindow!=NULL?true:false;
96  SetModalWindow(lastModalWindow);
97  Invalidate();
98  if(lastModalWindow!=NULL)
99  {
100  lastModalWindow->Invalidate();
101  _idleProcess->loop();
102  }
103  //out<<F("End::ProcessDoDialog")<<endln;
104  return _lastDialogResults;
105  }
106  void RegisterTimer(ATimer *timer)
107  {
108  _timers.Add(timer);
109  }
110  LinkedList<ATimer> &Timers()
111  {
112  return _timers;
113  }
114  void SetLoopProcess(ILoopProcess *process)
115  {
116  _idleProcess=process;
117  }
119  void NotifyDialogClosed(Window *window,DialogResults results)
120  {
121  //out<<F("NotifyDialogClosed")<<endln;
122  _isModalDialogActive=false;
123  _lastDialogResults=results;
124  }
127  {
128  return _modalWindow;
129  }
131  void SetModalWindow(Window * modalWindow)
132  {
133  _modalWindow=modalWindow;
134  }
136  void Move(int left,int top,int width,int height)
137  {
138  Window::Move(left,top,width,height);
139  }
140 };
Definition: MainWindow.h:30
Definition: ATimer.h:28
void SetModalWindow(Window *modalWindow)
Sets active modal (window that received all user input, like dialog window) window.
Definition: MainWindow.h:131
Base class for all window objects. Provides basic window functionality.
Definition: Window.h:34
void RegisterEndDialogEventReceiver(IDialogClosedEventReceiver *receiver)
Registers extern interface that will be called if dialog is closed.
Definition: Dialog.h:70
void NotifyDialogClosed(Window *window, DialogResults results)
Process dialog closed notification.
Definition: MainWindow.h:119
Text box for numbers.
Definition: TextBoxNumber.h:24
virtual void Move(int left, int top, int width, int height)
Moves and resizes window relativly to the parent window.
Definition: Window.h:149
Window * ModalWnd()
Returns pointer to active modal (window that received all user input, like dialog window) window...
Definition: MainWindow.h:126
void Move(int left, int top, int width, int height)
Changes position and size.
Definition: MainWindow.h:136
Base class for dialog objects. See Dialogs example Provides basic window functionality.
Definition: Dialog.h:25
DialogResults ProcessDoDialog(Window *dlg)
Starts dialog.
Definition: MainWindow.h:81
void Invalidate()
If function is called than the window manager updates the window.
Definition: Window.h:157
Definition: MainWindow.h:25
Dialog * FindDialog(const __FlashStringHelper *id)
Finds registered dialog by the name.
Definition: MainWindow.h:69
void SetVisible(bool isVisible)
Sets window visibility status.
Definition: Window.h:205
MainWindow(int width, int height)
Constructor.
Definition: MainWindow.h:52
Interface that provides dialog closed notifications (user closes dialog window, by pressing OK or can...
Definition: IDialogClosedEventReceiver.h:24
Base class for main application window. Each application has to have one main window, which is root parent for all other application windows.
Definition: MainWindow.h:38
void RegisterDialog(const __FlashStringHelper *id, Dialog *widnow)
Registers dialog window. All application dialogs have to be registered.
Definition: MainWindow.h:57