Labyrinth
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
form.hpp
1 //////////////////////////////
2 //
3 // File: lxs/windowing/form.hpp
4 // Author: Maciej Kaminski
5 // E-mail: maciej.a.kaminski@gmail.com
6 // Website: maciejkaminski.pl
7 //
8 // File creation date: Oct 24 2012
9 // This file is part of Project Labyrinth
10 // This file is going to be released under terms of GNU GPL in near future
11 //
12 //////////////////////////////
13 
14 #ifndef __LXS_FORM_WINDOW__
15 #define __LXS_FORM_WINDOW__
16 #include <string>
17 #include <list>
18 #include "lxs/windowing/button.hpp"
19 #include "lxs/windowing/containerwindow.hpp"
20 namespace LxS
21 {
22  class Font;
23  namespace Windowing
24  {
25  class Rectangle2D;
26  //! form - window that arranges its fields itself
27  class Form: public ContainerWindow
28  {
29  protected:
30  //!"back" button
32  //! window, that is gonna be displayed when "back" button is pressed
34  //! background image
36  //! subforms (are handled in refresh routine)
37  std::list <Form*> subforms;
38  //! function for switching to other window (when form button is clicked)
39  void TransitionFunction(Button * b, Window * target);
40  float internal_height; //!<height of contents
41  float reference_y; //!< point from which dragging has started
42  //! position of contents
43  float position_y;
44  //! number of columns
46  float far_top; //!< top of topmost element
47  float far_bottom; //!< bottom of lowest element
48  ContainerWindow * footer; //!< special set of form items added to footer
49  //! scrolling
50  void MoveContents(float y);
51  protected:
52  //! utility method for rendering background image
53  void RenderBackground(Renderable::Rendermode mode);
54  //! remove children and subforms
55  void ResetForm();
56  //! set position of "back" button
57  virtual void PositionBackButton();
58  //! return form that shall be presented upon clicking "back"
59  Form * GetParentForm() { return dynamic_cast<Form*>(back);}
60  //! error message
61  void Error(const std::string& message, Form* target); // target=backlink
62  //! alignment (Left , Right, Center)
63  int align;
64  public:
65  //! window contents alignment enum
66  enum alignment
67  {
68  //! content is centered
70  //! content is aligned to left
72  //! content is aligned to right (NOT IMPLEMENTED)
74  };
75  //! set alignment (left, right, center)
76  void SetAlignment(int a) {align=a;}
77  //! default constructor of an empty form
78  Form();
79  //! remove footer
80  virtual void DetachFooter();
81  //! single subwindow
82  virtual void AttachFooter(ContainerWindow * f);
83  virtual void AttachChild(Window * child);
84  virtual void DetachChild(Window * child);
85  virtual void ReplaceChild(Window * old_child, Window * new_child);
86  virtual void EraseChildren();
87  //! attach child at front
88  virtual void AttachChildAtFront(Window * child);
89  void OnFocus();
90  //! return function object
92  //! attasch form object - it will be serviced in form's default initialize/unloadresources functions
93  void AttachSubForm(Form * sf);
94  //! set path to background image
95  void SetBackground(const std::string & background);
96  //! get path to background image
97  const std::string GetBackground();
98  //! back button pressed
99  virtual void Back(Button * b);
100  //! link to "previous" - window that will be maximized after pressing "back"
101  virtual void SetBackLink(Window * b);
102  //! arrange contents (called after movement/resize)
103  virtual void Arrange();
104  //! genericized event handler - passed to children
105  virtual void SaveFile();
108  void ResizeHandler() {Refresh();}
109  void Initialize();
110 
111  void Render(Renderable::Rendermode mode);
112  virtual void Released(float x, float y)
113  {
114  if (reference_y!=-1)
116  reference_y=-1;
117  }
118  virtual void Clicked(float x, float y)
119  {
120  //reference_y=y;
122  }
123  // within interface
124  virtual void Dragged(float x, float y)
125  {
126  if (reference_y!=-1)
128  reference_y=y;
129  }
130 
131  void UnloadResources();
132  virtual ~Form();
133  //! click handler for "back" button
134  virtual void BackButtonPressed() {Back(0);}
135  };
136  }
137 }
138 #endif