introduction to systems programming (cs 0449)

Post on 27-Jan-2016

39 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Introduction to Systems Programming (CS 0449). User Interface Elements (UIE) - Resources Palm OS resources ( Ch.4—PDA Programming in C Book & Ch.6,7 PalmOS Bible Book ). Forms Alerts Menus Tables Lists Pop-up Triggers Buttons Repeating Buttons Selector Triggers Push Buttons. - PowerPoint PPT Presentation

TRANSCRIPT

Introduction to Systems Programming(CS 0449)

User Interface Elements (UIE) - Resources

•Palm OS resources (Ch.4—PDA Programming in C Book & Ch.6,7 PalmOS Bible Book)

Palm OS Resources -User Interface Elements

• Forms

• Alerts

• Menus

• Tables

• Lists

• Pop-up Triggers

• Buttons

• Repeating Buttons

• Selector Triggers

• Push Buttons

• Check Boxes

• Slides• Labels• Form Bitmaps• Fields• Graffiti Shift Indicator• Scroll Bars• Gadgets

Palm Resources (User Interface Elements)

• Forms

• Alerts

• Menus

• Tables

• Lists/Popup

• Buttons

• Push buttons

• Check boxes

• Sliders, scrollbars

• Labels Look Up:

• Form bitmaps

• TextFields

Resource Files//This is a file used by PilRC to create a .prc file.

#include "helloRsc.h"

APPLICATIONICONNAME ID 100 "Hello 1"

APPLICATION ID 1 "49p1"

VERSION ID 1 "1.0.0g"

ICONFAMILY "largeicon_1bpp.bmp" "largeicon_2bpp.bmp" "" "largeicon_8bpp.bmp" TRANSPARENT 0 255 0

SMALLICONFAMILY "smallicon_1bpp.bmp" "smallicon_2bpp.bmp" "" "smallicon_8bpp.bmp" TRANSPARENT 0 255 0

Resource Files (2)// Here we define the form that we need for our program.

FORM ID MainForm AT (0 0 160 160) //more details nextUSABLEBEGIN TITLE "Hello World"END

ALERT ID ByeAlert //more details after nextINFORMATIONBEGIN TITLE "Hello World Alert" MESSAGE "Goodbye, my friend !" BUTTONS "OK"END

Resource Files (3)

BITMAP ID MyBitmap "picture.bmp" COMPRESS

FORM ID MainForm AT (0 0 160 160)USABLEBEGIN TITLE "Hello World“

TABLE ID MainTable AT (0 16 160 121) ROWS 11 COLUMNS 9 COLUMNWIDTHS 12 25 12 18 12 33 17 20 9

LABEL "Enter your name here:" AUTOID AT (0 17) FONT 1

FIELD ID MyFieldName AT (PrevLeft PrevBottom 159 13) UNDERLINED AUTOSHIFT MAXCHARS 40

BUTTON "Hello" ID MyButtonHi AT (1 147 AUTO AUTO)

BUTTON "Bye" ID MyButtonBye AT (PrevRight+5 PrevTop AUTO AUTO)

FORMBITMAP AT (7 19) BITMAP MyBitmapEND

Programming User Interface Elements - ALERT

Programming Alerts An Alert resource dialog box could be either

1.Information. (i) 2.Confirmation. (?)

3.Warning. (!)4.Error. (x)

ALERT ID HelloAlertINFORMATIONBEGIN

TITLE “Hello World” (i) MESSAGE “Good Day To you, My Friend, ^1 !”BUTTONS “OK”

END // ^1 resource ID –first arg in FrmCustomAlert(HelloAlert, “yourname”)

ALERT ID DeleteAlertCONFIRMATIONBEGIN

TITLE “Please Confirm deletion” (?) MESSAGE “About to delete ^1 records from ^2 category!”

“Proceed?”BUTTONS “OK” “Cancel”

END// ^2 –2nd arg in FrmCustomAlert(DeleteAlert,”5”, business”, NULL) FrmAlert ( ) is equivalent to FrmCustonAlert(AlertID, NULL, NULL, NULL) –does not take ^1, ^2, ^3

To include ^`, ^2, ^3, then use FrmCustomALert

Programming User Interface Elements - ALERT

ALERT ID WarningAlert

WARNING

BEGINTITLE “Warning Alert Dialog Box” (!)MESSAGE “Are you sure you want to delete, ^1 !”BUTTONS “Yes” “NO”

END// ^1 resource ID –first arg in FrmCustomAlert(WarningAlert)

ALERT ID ErrorAlert

ERROR

BEGINTITLE ”Password Dialog Box” (x)

MESSAGE “Incorrect Password”

BUTTONS “OK” END

Creating Resources – Adding Objects to a Form Resource

1) BUTTONS:

BUTTON “label” ID resourceID AT (Left Top Width Height) AT Positions: AUTO, CENTER, CENTER@<number>,

RIGHT@<number>, BOTTOM@<number>, PREVLEFT, PREVRIGHT, PREVTOP, PREVBOTTOM, PREVWIDTH,PREVHEIGHT.

2) PUSHBUTTONS:

PUSHBUTTON “HEX” ID Hex GROUP 1

PUSHBUTTON “DEC” ID Dec GROUP 1

3) CHECKBOXES:

CHECKBOX “label” ID resourceID AT (Left Top Width Height)

Creating Resources – Adding Objects to a Form Resource

4) Fields:

FIELD “label” ID resourceID AT (Left Top Width Height) [ USABLE | NONUSABLE ] [LEFTALIGN | RIGHTALIGN] [ FONT fontnumber ] [EDITABLE | NONEDITABLE] [ UNDERLINED] [ SINGLELINE | MULTIPLELINES] [DYNAMICSIZE] MAXCHARS maxChars [ AUTOSHIFT ] [NUMERIC] [HASSCROLLBAR]

[DYNAMICSIZE]– causes field to out fldheightChangedEvent onto the queue whenever user input causes field to scroll.

[ AUTOSHIFT ]– tells system to perform graffiti auto shifting in the field.

[HASSCROLLBAR] – update scrollbar constantly.

Creating Resources – Adding Objects to a Form Resource

1) BUTTONS:

BUTTON “label” ID resourceID AT (Left Top Width Height)

AT Positions: AUTO, CENTER, CENTER@<number>, RIGHT@<number>, BOTTOM@<number>, PREVLEFT, PREVRIGHT, PREVTOP, PREVBOTTOM, PREVWIDTH,PREVHEIGHT.

2) PUSHBUTTONS:

PUSHBUTTON “HEX” ID Hex GROUP 1PUSHBUTTON “DEC” ID Dec GROUP 1

3) CHECKBOXES: HEX DEC

CHECKBOX “label” ID resourceID AT (Left Top Width Height)

HEX DEC

1) BUTTONS:

BUTTON “label” ID resourceID AT (Left Top Width Height)

AT Positions: AUTO, CENTER, CENTER@<number>, RIGHT@<number>, BOTTOM@<number>, PREVLEFT, PREVRIGHT, PREVTOP, PREVBOTTOM, PREVWIDTH,PREVHEIGHT.

2) PUSHBUTTONS:

PUSHBUTTON “HEX” ID Hex GROUP 1PUSHBUTTON “DEC” ID Dec GROUP 1

3) CHECKBOXES: HEX DEC

CHECKBOX “label” ID resourceID AT (Left Top Width Height)

Creating Resources – Adding Objects to a Form Resource

4) Text Fields: Enter your name: ______________

FIELD “label” ID resourceID AT (Left Top Width Height) [ USABLE | NONUSABLE ] [LEFTALIGN | RIGHTALIGN] [ FONT fontnumber ] [EDITABLE | NONEDITABLE] [ UNDERLINED] [ SINGLELINE | MULTIPLELINES] [DYNAMICSIZE] MAXCHARS maxChars [ AUTOSHIFT ] [NUMERIC] [HASSCROLLBAR]

[DYNAMICSIZE]– causes field to out fldheightChangedEvent onto the queue whenever user input causes field to scroll.

[ AUTOSHIFT ]– tells system to perform graffiti auto shifting in the field.

[HASSCROLLBAR] – update scrollbar constantly.

Programming User Interface Elements – Forms

FORM ID MainForm AT (0 0 160 160) USABLE | MODAL BEGIN TITLE "CS 0449 Calculator“ FIELD ID InputFld AT(14 20 130 24) FONT 0

UNDERLINED SINGLELINE MAXCHARS 8 BUTTON "1" ID One BUTTON "F" ID HexF PUSHBUTTON “HEX” ID Hex GROUP 1 PUSHBUTTON “DEC” ID Dec GROUP 1 BUTTON "Exit" ID Exit END

Programming User Interface Elements - Forms

Programming Forms 1-Switch to a new form: Erase current form and display a new one (Full-SCREEN, VIEWS-Modeless, or USABLE)2-Display a modal dialog box: A quick prompt for user input. i.e. delete confirmation dialog box (POP-UP, MODAL-DIALOGS) - MODAL: forms and windows ignore taps outside them. User must finish the dialog and exit the form. FORM ID MainForm AT (0 0 160 160) USABLE BEGIN TITLE "CS 0449 Calculator“

FIELD ID InputFld AT(14 20 130 24) FONT 0UNDERLINED SINGLELINE MAXCHARS 8

BUTTON "1" ID One BUTTON "F" ID HexF

PUSHBUTTON “HEX” ID Hex GROUP 1PUSHBUTTON “DEC” ID Dec GROUP 1

BUTTON "Exit" ID Exit END

FORM ID MainForm AT (0 0 160 160) MODAL DEFAULTBTNID MyDeleteButtonID BEGIN TITLE “Delete Book“ LABEL “Delete Selected Book Record?” BUTTON “OK" ID DeleteBookOK

BUTTON “Cancel” ID DeleteBookCancel END

Programming User Interface Elements - Forms

Programming Forms 1-Switch to a new form: Erase current form and display a new one.

2-Display a modal dialog box: A quick prompt for user input, i.e. delete confirmation dialog box.

•To switch forms call:FrmGotoForm( MyOtherFormID )

•What happens in OS?frmColseEvent is sent to the current form

FrmHandleEvent() takes care of this event

frmLoadEvent is sent to MyOtherFormfrom your AppHandleEvent() call:

FrmInitForm()FrmSetActiveForm()FrmSetEventHandler()

FrmOpenEvent -- respond by calling FrmDrawForm()

Event Driven Architecture

PalmMain()

AppEventLoop()

AppHandleEvent()

MainFormHandleEvent()

FrmDispatchEvent()frmColseEvent

FrmHandleEvent()

Events

frmLoadEventFrmInitForm()FrmSetActiveForm()FrmSetEventHandler()

frmOpenEventFrmDrawForm()

Hiding and Showing Form Objects (page 270 – Palm OS Bible)

// Hides MyButtonID when MyHideBushbuttonID tapped// ... in your FormHandleEvent() ... and Handling Control Groups (pp.273)

on pushbuttons and check boxes.

if( event -> eType == ctlSelectEvent ) {switch ( event . data . ctlSelect . controlID ) { //see what button is tapped

case MyHidePushButtonID :form = GetActiveForm( ); //get active formbuttonIndex =FrmGetObjectIndex( form, MyButton);ctl = GetObjectPtr (MyHidePushButtonID);if( CtlGetValue ( ctl ) )

FrmHideObject( form, buttonIndex ); //Hide Pushbuttonelse

FrmShowObject( form, buttonIndex ); //Show Pushbuttonbreak;

case MyButton :. . .//do something when user taps MyButton

} Related Slides for CsCalProject

Adding TABLE to Form// ...in the resource file, add to the form definition

FORM ID MainForm AT (0 0 160 160)USABLEBEGIN TITLE “Tables“

TABLE ID MainTable AT (0 16 160 121) ROWS 11 COLUMNS 9 COLUMNWIDTHS 12 25 12 18 12 33 17 20 9

BUTTON “HideRows” ID MainHideRowsButton AT(1 147 50 12)BUTTON “HideColumns” ID MainHideColumnsButton AT(56 147 64 12)

LIST “X” “Y” “Z” ID MainList AT(120 141 19 33) NONUSABLE VISIBLEITEMS 3

. . .END

typedef struct{ // in Table.hTableItemStyleType itemType;FontID fontID;Int16 intValue;Char *ptr;} TableItemType;

Item Type Editable by User TableItemType Fields Used by This typecheckboxTableItem Yes intValuecustomTableItem Yes None, although you may store data in the

intValue and ptr fields if required by yourapplication

dataTableItem No intValuelabelTableItem No ptrnumericTableItem No intValuepopupTriggerTableItem Yes intValue, ptrtextTableItem Yes fontID, ptrtextWithNoteTableItem Yes fontID, ptrnarrowTextTableItem Yes fontID, intValue, ptr

TABLE Item Types (ref: table page 397)

TblSetItemStyle(params) -- Set value of the table item’s itemType field

Given a pointer to the table, the row and column of the item to set, and the type desired.

params= (ptr to table, row of cell to set, column of cell to set, TableItemStyleType value)

TblSetItemFont( ) -- Set fontID for a table item.

TblSetItemInt( ) -- Set the intValue.

TblSetItemPtr( ) -- Set the ptr field.

TblGetItemFont( ) – Retrieve the fontID for a table item.

TblGetItemInt( ) – Retrieve the intValue.

TblGetItemPtr( ) -- Retrieve the ptr field. Given a pointer to the table, the row & column of the desired table

item.

PalmOS Table Functions: Set/Retrieve Values

-Usually, initializing the table is when handling the form’s frmOpenEvent-In the given table sample code,

-MainFormHandleEvent initializes the form in the MainFormInit

static Boolean MainFormHandleEvent(EventPtr event){ Boolean handled = false; FormPtr form;

switch (event->eType) { case frmOpenEvent: form = FrmGetActiveForm(); MainFormInit(form); FrmDrawForm(form); handled = true;

//other event handling omitted default: break; } return handled; }

Initializing a Table

Click to see MainFormInit() functionTable sample codes:  Table.c      MainFormInit()       MainFormHandleEvent

// allocate new memory handle for each array element and filling the handle’s contents with single training null.

static Err StartApplication(void){ Int16 i, j; for (i = 0; i < numTextColumns; i++) { //num of columns for (j = 0; j < numTableRows; j++) { //num of rows Char *str; gTextHandles[i][j] = MemHandleNew(1); str = MemHandleLock(gTextHandles[i][j]); *str = '\0'; MemHandleUnlock(gTextHandles[i][j]); } } return false;}

Initializing a Table Array in StartApplication

Creating Menu Resourcepg 244, PalmOS Bible

MENU ID MyMenuIDBEGIN

PULLDOWN "Edit"BEGIN

MENUITEM "Copy" ID MyMenuCopyID "C"MENUITEM "Paste" ID MyMenuPasteID "P"

ENDPULLDOWN "Help"BEGIN

MENUITEM "Help" ID MyMenuHelpID "H"MENUITEM SEPARATORMENUITEM "About" ID MyMenuAboutID "A"

ENDEND

Adding Menu to Form

// ...in the resource file, add to the form definition

FORM ID MainForm AT (0 0 160 160)

MENUID MyMenuID

USABLE

BEGIN

TITLE "CsCalc by Leo"

. . .

END

Programming Menuspg 296, PalmOS Bible

// ... in your FormHandleEvent()if( event -> eType == menuEvent ) {

switch ( event . data . menu . itemID ) {case MyMenuCopyID :

// Do your copy businessbreak;

case MyMenuPasteID :// Do your paste businessbreak;. . .

}}

Using Standard Edit Menu

• Sometimes we can use resources that are built in Palm OS, such as Edit menu– We still have to define the menu resource,

using the correct IDs – We do not need to write code, it is built in

PalmOS

• Details in PalmOS Bible, pg 247.

top related