Difference between revisions of "CIO 20133 Release 0.4 - OOP344"

From CDOT Wiki
Jump to: navigation, search
(Created page with '==CButton== Button is a child of CField. It displays a small piece of text (usually one word or two) and accepts one key hit entry.<br /> When CButton is in edit mode, to indicat…')
(No difference)

Revision as of 18:41, 12 November 2013

CButton

Button is a child of CField. It displays a small piece of text (usually one word or two) and accepts one key hit entry.
When CButton is in edit mode, to indicate the editing mode, it will surround the text with squared brackets.

#include "cfield.h"
namespace cio{
   class  CButton: public CField{
   public:
     CButton(const char *Str, int Row, int Col, 
              bool Bordered = true,
              const char* Border=C_BORDER_CHARS);
     virtual ~CButton();
     void draw(int fn=C_FULL_FRAME);
     int edit();
     bool editable()const;
     void set(const void* str);
   };
}

Attributes

This class does not have any attributes of its own!

Constructor / Destructor

     CButton(const char *Str, int Row, int Col, 
              bool Bordered = true,
              const char* Border=C_BORDER_CHARS);

When creating a Button, allocate enough memory to hold the contents of the Str and set Field's _data to point to it. Then copy the content of Str into the newly allocated memory.
Pass all the arguments directly to Field's constructor.
For Field size (width and hight) do the following:
For width: Set width to the length of Str + 2 (adding 2 for surrounding brackets) or if the Button is bordered set width to the length of Str + 4 (adding 2 for surrounding brackets and 2 for the borders). For height: Set the height to 1 or if the Button is bordered, set the height to 3.

   virtual ~CButton();

Deallocates the allocated memory pointed by Field's _data.

Methods

   void draw(int fn=C_FULL_FRAME);

Draws the Button with border around it if it is Bordered. Note that there should be a space before and after of the text that will be used to surround the text with "[" and "]"
hint:

  • First calls Frame's draw(fn) (passing the fn argument to the parents draw)
Use console.display() to display the Button's text (pointed by Field's _data)
  • If not bordered
    display the text at absRow() and absCol()
  • If bordered
    display the text at absRow()+1 and absCol()+2
   int edit();

First draw() the Button, then surround it by squared brackets, place the cursor under the first character of Button's text and wait for user entry.
When user hits a key, if the key is ENTER_KEY or SPACE, return C_BUTTON_HIT (defined in ciogh.h) otherwise return the entered key.

   void set(const void* str);

First deallocated what is pointed by Field's _data. Then allocate new memory to the size of content of str and copy the content into it and make Field's _data point to it.

   bool editable()const;

Always returns true

CButton Student Resources

CButton Help/Questions Blogs

CButton Blog Posts

CValEdit

This class works exactly like CLineEdit and improves it by adding two features; Validation and Help. CValEdit is capable of validating the user input on exit and also provide help when CValEdit::edit() is active by invoking a "help" method before and after editing. If these two functions, (Validation and Help) are not provided, then CValEdit literally works like CLineEdit.

#include "clineedit.h"

namespace cio{
  class CValEdit: public CLineEdit{
    void (*_help)(MessageStatus, CDialog&);
    bool (*_validate)(const char*, CDialog&);
  public:
    CValEdit(char* Str, int Row, int Col, int Width,
          int Maxdatalen, bool* Insertmode,
          bool (*Validate)(const char* , CDialog&) = NO_VALDFUNC, 
          void (*Help)(MessageStatus, CDialog&) = NO_HELPFUNC,
          bool Bordered = false,
          const char* Border=C_BORDER_CHARS);
    CValEdit(int Row, int Col, int Width,
          int Maxdatalen, bool* Insertmode,
          bool (*Validate)(const char* , CDialog&) = NO_VALDFUNC, 
          void (*Help)(MessageStatus, CDialog&) = NO_HELPFUNC,
          bool Bordered = false,
          const char* Border=C_BORDER_CHARS);
    int edit();
  };
}

Attributes

    void (*_help)(MessageStatus, CDialog&);
    bool (*_validate)(const char*, CDialog&);
  • _help, holds the address of the help logic (function) or NULL if there is no help function is assigned
  • _validate, holds the address of the validation logic (function) or NULL if there is no validation function is assgned

Constructors

    CValEdit(char* Str, int Row, int Col, int Width,
          int Maxdatalen, bool* Insertmode,
          bool (*Validate)(const char* , CDialog&) = NO_VALDFUNC, 
          void (*Help)(MessageStatus, CDialog&) = NO_HELPFUNC,
          bool Bordered = false,
          const char* Border=C_BORDER_CHARS);
    CValEdit(int Row, int Col, int Width,
          int Maxdatalen, bool* Insertmode,
          bool (*Validate)(const char* , CDialog&) = NO_VALDFUNC, 
          void (*Help)(MessageStatus, CDialog&) = NO_HELPFUNC,
          bool Bordered = false,
          const char* Border=C_BORDER_CHARS);

These constructors pass all their arguments to corresponding arguments of CLineEdit constructor and then set _help and _validate attributes to the corresponding incoming arguments

Method

  int edit();

If the container() is NULL then this function works exactly like LineEdit::edit().
If the container() is not NULL:

  1. If _help function exist, it calls the function passing MessageStatus::SetMessage and container()'s reference as arguments.
  2. Calls CLineEdit's edit()
  3. If validation function exists, and the terminating key of CLineEdit's edit() is a navigation key(see below)
    It will call the validation function on the Field's _data, if the data is valid, it goes to next step, otherwise it will repeat calling CLineEdit's edit().
  4. After validation is done, if _help function exists, it will recall the help function using MessageStatus::ClearMessage and contianer()'s reference as arguments.
  5. It will return the terminating key

Navigation keys are Up key, Down key, Tab key or Enter key.
MessageStatus is enumerated in ciogh.h

CValedit Student Resources

CValEdit Help/Questions Blogs

CValedit Blog Posts

CCheckMark

Creates a single CheckMark on the screen and allows the user to:

  1. Toggle it, if it is set to be a CheckMark for a Check List.
  2. Only check it when its unchecked, if it is set to be a CheckMark for a Radio Button List.
#include "cfield.h"
#include "clabel.h"
namespace cio{
  class CCheckMark : public CField{
    bool _flag;
    bool _radio;
    char _format[4];
    CLabel _Label;
  public:
    CCheckMark(bool Checked,const char* Format, const char* Text,
               int Row, int Col, int Width, bool IsRadio = false);
    CCheckMark(const CCheckMark& C);
    void draw(int fn = C_NO_FRAME) ;
    int edit();
    bool editable()const;
    void set(const void* flag);
    bool checked()const;
    void checked(bool val);
    bool radio(); 
    void radio(bool isRadio);
    operator bool(); 
    operator char*(); 
    bool operator=(bool flag);
  };
}

Attributes

  int _flag;
  bool _radio;
  char _format[4];
  CLabel _Label;
  • _flag holds the status of the Checkbox (0: unchecked or 1: checked ) and is pointed by _data pointer .
  • _radio dictates the behavior of the Checkbox as a radio-button, or a check-mark.
  • _format holds the characters, the Checkbox is drawn with (i.e. "[X]", "(O)", "<*>", etc...).
  • _Label holds the Label attached to the this Checkbox

Constructor / Destructor

  CCheckMark(bool Checked,const char* Format, const char* Text, int Row, int Col, int Width, bool IsRadio = false);
  • Passes the Row, Col, Width and "1" to row, col, width and height arguments of CField and directly initializes _Label with Text, 0, 4, and (Width-4) for Str, Row, Col and Len, arguments of CLabel's Constructor.
  • Sets the frame of _Label to its owner (Checkmark i.e. 'this');
  • Sets _flag to Checked
  • Sets _radio to IsRadio
  • Copies Format to _format
  • Sets _data to the address of _flag
  CCheckMark(const CCheckMark& C);
  • Passes incoming CCheckMark reference ("C") to CField's copy constructor, and directly initializes the _Label with the _Label of C
  • Sets all the attributes of this object to the attributes of incoming CCheckMark reference ("C")
  • Sets _data to the address of _flag

Methods

  void draw(int fn = C_NO_FRAME) ;

Using Console methods:

  1. displays the _format string at absRow() and absCol()
  2. if _flag is false, it will overwrite the second character printed above, with a space (removes the check mark on console)
  3. draw()s the _Label
  4. sets the position of the cursor at the checkmark (second character of printed _format)
  int edit();
  1. draw()s the checkmark
  2. gets a key
    the key must be either SPACE or any non-printable character (all printable character are ignored)
  3. if the entered key is space
    1. if _radio is true, it will set the _flag to true
    2. if _radio is false, it will flip the value of _flag.
    3. draw()s the checkmark again
  bool editable()const;
  • Always return true;
  void set(const void* flag);
  • Casts the incoming flag pointer to an (bool*) and sets the content of _flag to where flag is pointing to.
  bool checked()const;
  void checked(bool val);
  • These methods set and get _flag.
    bool radio(); // addition for R0.6
    void radio(bool isRadio); // addition for R0.6
  • These to methods, get and set the _radio attribute.
    operator bool(); // addtion for R0.6
  • Overload the bool cast to return the value of _flag
     operator char*(); // addtion for R0.6
  • Overload the char* cast to return the value of _Label.data()
     bool operator=(bool flag);; // addtion for R0.6
  • Overload the operator= and set the _flag to flag

CCheckMark Student Resources

CCheckMark Help/Questions Blogs

CCheckMark Blog Posts

CMenuItem

CMenuItem provides a Label that can be marked as selected by pressing the space bar.

#include "clabel.h"
#include "cfield.h"
namespace cio{
  class CMenuItem:public CField{
    bool  _selected;
    char _format[3];
    CLabel Label;
  public:
    CMenuItem(bool Selected,const char* Format, const char* Text, int Row, int Col, int Width);
    CMenuItem(const CMenuItem &CM);
    void draw(int fn = C_NO_FRAME) ;
    int edit();
    bool editable()const;
    void set(const void* Selected);
    bool selected()const;
    void selected(bool val);
    const char* Text()const;
  };
}

Attributes

    bool  _selected;

Holds the status of the MenuItem, being selected or not;

    char _format[3];

Holds the surrounding characters with which a selected MenuItem is shown:
If _format holds "[]", then a selected MenuItem will be like [MenuText]

    CLabel Label;

Hold the Text of the MenuItem.

Constructors / Destructor

    CMenuItem(bool Selected,const char* Format, const char* Text, int Row, int Col, int Width);
  1. Initializes the CField with Row, Col, Width and 1 for Height
  2. Initializes the Label with (Text, 0, 1 and Width-2) for (Str, Row, Col, and Len)
  3. Sets the attributes to corresponding arguments
  4. Sets CFields::_data to the address of _format
  5. Sets the Label's frame to this object.
    CMenuItem(const CMenuItem &CM);
  1. Passes CM to CField and Initializes the Label with CM
  2. Sets the _selected to _selected of CM
  3. Sets CFields::_data to the address of _format
  4. Sets the Label's frame to this object.

Methods

    void draw(int fn = C_NO_FRAME) ;
  1. Draws the Label with fn
  2. If _selected is true, it surrounds the Label Text the _format[0] and _format[1]
  3. If _selected if false, it surrounds the Label with SPACEs (overwrites _format[0] and _format[1])
  4. Positions the cursor at the first character of the Label
    int edit();
  1. draw()s the MenuItem
  2. gets a key
    the key must be either SPACE or any non-printable character (all printable character are ignored)
  3. if the entered key is space
    1. it will set the _selected to true
    2. draw()s the MenuItem again
  4. returns the key
    bool editable()const;

Returns true.

    void set(const void* Selected);

Sets _selected to where Selected is pointing to

    bool selected()const;

Returns Selected

    void selected(bool val);

Sets _selected to val

    const char* Text();

Returns the text of Label

CMenuItem Student Resources

CMenuItem Help/Questions Blogs

CMenuItem Blog Posts

Tester Programs and Sub Releases

R0.4.1 CButton

R0.4.2 CValEdit

R0.4.3 CCheckMark

R0.4.4 CMenuItem

Due Date