21
edits
Changes
→CButton
==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 in edit mode, to indicate the editing mode, it will surround the text with squared brackets.
<big><syntaxhighlight lang="cpp">
#pragma once
#include "cfield.h"
class CButton: public CField{
public:
CButton(const char *Str, int Row, int Col,
const char* Border=C_BORDER_CHARS);
virtual ~CButton();
void draw(int rnfn=C_FULL_FRAME);
int edit();
bool editable()const;
</syntaxhighlight></big>
===Attributes===
===Constructor / Destructor===
<big><syntaxhighlight lang="cpp">
const char* Border=C_BORDER_CHARS);
</syntaxhighlight></big>
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.<br />
Pass all the arguments directly to Field's constructor.<br />
For Field size (width and hight) do the following:<br />
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.
<big><syntaxhighlight lang="cpp">
virtual ~CButton();
</syntaxhighlight></big>
Deallocates the allocated memory pointed by Field's '''_data'''.
===Methods===
<big><syntaxhighlight lang="cpp">
void draw(int rnfn=C_FULL_FRAME);
</syntaxhighlight></big>
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 "]"<br />
hint:<br />
:*First calls Frame's draw(fn) (passing the fn argument to the parents draw)
:Use bio_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
<big><syntaxhighlight lang="cpp">
int edit();
</syntaxhighlight></big>
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.<br />When user hits a key, if the key is ENTER_KEY or SPACE, return FW_BUTTON_HIT (defined in confw.h) otherwise return the entered key.<br />
<big><syntaxhighlight lang="cpp">
bool editable()const;
</syntaxhighlight></big>
Always returns true;
<big><syntaxhighlight lang="cpp">
void set(const void* str);
</syntaxhighlight></big>
Reallocate memory for new text and then set it to content of '''str'''<br />
hint:<br />
:''First deallocated what is pointed by Field's '''_data'''.''<br />
:''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.''
==CCheck==