Home > Products > SophiaFramework UNIVERSE > Tutorial > Scheduler > - 4 / 7 -

BREW Scheduler Supporting vCalendar - 4 / 7 -

How to Use TemplateApp

TemplateApp included in the Example folder of SophiaFramework is a template application with menu, dialog, and softkey windows which are common to many applications.

Steps to Make an Application by Using TemplateApp

Step 1. Copy the following files included in theTemplate folder to one of the Example folders into your project.

MainWindow.hpp
MainWindow.cpp
PreferenceDialog.hpp
PreferenceDialog.cpp
SoftkeyWindow.hpp
SoftkeyWindow.cpp
TemplateApp.hpp
TemplateApp.cpp
VersionDialog.hpp
VersionDialog.cpp
templateapp_res.h
templateapp.bri
templateapp.bar
All included in the Resource folder 

Step 2. Change the application name in the files of TemplateApp, templateapp and TEMPLATEAPP to that of your application's name.

Step 3. Generate a bid file and a mif file.

Step 4. Compile and check whether it will work on emulator.

Result Display Menu with Softkey(Right) Display Dialog with Softkey(Left)
TemplateApp Result 1 TemplateApp Result 2 TemplateApp Result 3

Step 5. Delete the code for the enclosed demo with the following macro.

#if defined USE_EXAMPLE_UI

#endif

Display Calendar

Define MainWindow

SFMRESPONDERATTRIBUTE(MAINWINDOW, four_char_code('M', 'a', 'i', 'n'))

SFMTYPEDEFCLASS(MainWindow)
class MainWindow : public SFRPlainWindow {
    SFMSEALCOPY(MainWindow)

    // for drawing variables

private:
    SFXDate _cursor; // Position of cursor
    SInt16 _boxSize; // length of a square unit of calendar
    SInt16 _calLeft; // left end of the calendar

public:
    explicit MainWindow(SFRApplicationPtr director) static_throws;
    virtual ~MainWindow(Void);

    // for drawing handler and key handler

    HANDLER_DECLARE_VOIDRENDER(OnRenderContent) // drawing handler
    HANDLER_DECLARE_BOOLEVENT(OnKey) // key handler

      ...    
}

Modyfy Constructor

#define     CAL_TOP_MARGIN          (20)
#define     CAL_SIDE_MARGIN         (20)

MainWindow::MainWindow(SFRApplicationPtr director) static_throws
    : SFRPlainWindow(director, SFXRectangle(0, 0, 0, 0),
        BEHAVIOR_PLAINWINDOW, ATTRIBUTE_MAINWINDOW)
{
    SoftkeyWindowPtr softkey;

    SoftkeyWindow::Initialize(this);

    // The following code is added -------------------------

    if (static_try()) {
        // Register drawing handler
        static_throw(RegisterHandler(SREVT_RESPONDER_RENDER,
            SRP16_RENDER_CONTENT, HANDLER_BEFORE,
            HANDLER_FUNCTION(OnRenderContent)));
        if (static_try()) {
            // Register key handler 
            static_throw(RegisterHandler(SFEVT_KEY,
                HANDLER_AFTER, HANDLER_FUNCTION(OnKey)));
        }
    }

    // -------------------------------------------------------

    if (static_try()) {
        static_throw(RegisterHandler(static_cast<SFCEventEnum>(
            SoftkeyWindow::USEREVT_SOFTKEY), HANDLER_AFTER,
            HANDLER_FUNCTION(OnSoftkey)));
        if (static_try()) {
            // 
               ...
        }
    }

    // The following codes are added -------------------------
 
    // Calendar square unit length
    _boxSize =(GetContentWorld().GetRight() - 2* CAL_SIDE_MARGIN) / 7;
    // Left end of calendar
    _calLeft = (GetContentWorld().GetRight() - 7 * _boxSize) / 2;
    // Get current date
    _currentDay = SFXDate::CurrentDate();

    // -------------------------------------------------------
}

Add Drawing Handler and Key Handler

// The following code is added -------------------------

// Drawing Handler ( Draw within Window )
HANDLER_IMPLEMENT_VOIDRENDER(MainWindow, OnRenderContent, graphics)
{
    // Get the screen size
    SFXRectangle screenRect(GetContentWorld());

	// Get cursor position
    SInt16 year = _cursor.GetYear();
    SInt16 month = _cursor.GetMonth();
    SInt16 day = _cursor.GetDay();

	// Get current date
    SFXDate current = SFXDate::CurrentDate();
    
    // ScreenRect is painted out with white
    graphics->FillRectangle(screenRect, 
    SFXRGBColor(0xff, 0xff, 0xff, 0x00));

    // Drawing the frame of the calendar 
    DrawCalendarLine(screenRect, graphics); 

    // Drawing the date at the top
    graphics->DrawText(
        SFXAnsiString::Format("%2d-%2d", year, month), 
        SFXGrid(CAL_SIDE_MARGIN, 0));

    // Drawing the days of the week part of calendar. 
    DrawDayOfWeek(screenRect, graphics); 

    // Drawing the date part of the calendar. 
    DrawDate(current, screenRect, graphics);

    // If a schedule exists, it is drawn on the bottom. 
    if (SyncScheduler::GetVCalCollection()->
    	IsDataExist(year, month, day)) {
        DrawContent(screenRect, graphics);
    }
    return;
}

/* 
** The implementations of the DrawCalendarLine(),
** DrawDayOfWeek(), DrawDate() and DrawContent()
** are not included here. See source code for details.
*/ 

// Key Handler
HANDLER_IMPLEMENT_BOOLEVENT(MainWindow, OnKey, event)
{
    Bool result(false);

    switch (event.GetP16()) {
    	case AVK_SELECT:           // If select key is pressed
            ::new OneDayWindow(_cursor);
            result = true;
            break;
        case AVK_LEFT:
            _currentDay.SubDay(1); // Move day left 
            InvalidateContent(); // A new area is registered
            result = true;
            break;
        case AVK_RIGHT:
            _currentDay.AddDay(1); // Move day right
            InvalidateContent(); // A new area is registered
            result = true;
            break;
        case AVK_UP:
            _currentDay.SubDay(7); // Move day up
            InvalidateContent(); // A new area is registered
            result = true;
            break;
        case AVK_DOWN:
            _currentDay.AddDay(7); // Move day down 
            InvalidateContent(); // A new area is registered
            result = true;
            break;
    }
    return result;
}

Result with the above code:

TemplateApp result4

The cursor can be moved by pushing the Up, Down, Left or Right keys.

If the select key is pressed, a new OneDayWindow is generated.

Every time the cursor moves to a new area, it is registered, and its contents are then acted upon.

Go back  1   2   3   4   5   6   Apdx   Next page