Symbian OS: Quickstart and Carbide.c++ UI-Design
Symbian OS: Quickstart and Carbide.c++ UI-Design
Disclaimer
These slides are provided free of charge at http://www.symbianresources.com and are used during Symbian OS courses at the University of Applied Sciences in Hagenberg, Austria ( http://www.fh-hagenberg.at/ )
Respecting the copyright laws, you are allowed to use them:
for your own, personal, non-commercial use in the academic environment
In all other cases (e.g. for commercial training), please contact [email protected] The correctness of the contents of these materials cannot be guaranteed. Andreas Jakl is not liable for incorrect information or damage that may arise from using the materials.
Parts of these materials are based on information from Symbian Press-books published by John Wiley & Sons, Ltd. This document contains copyright materials which are proprietary to Symbian, UIQ, Nokia and SonyEricsson. S60 is a trademark of Nokia. UIQ is a trademark of UIQ Technology. Pictures of mobile phones or applications are copyright their respective manufacturers / developers. Symbian , Symbian OS and all other Symbian-based marks and logos are trademarks of Symbian Software Limited and are used under license. Symbian Software Limited 2006.
Contents
HelloWorld, Workflow
Conventions
Symbian OS was created before exceptions and smart pointers were introduced to C++
Different requirements concerning applications, error handling, clean-up and efficiency
5 Andreas Jakl, 2007
Data Types
Own data types to be 100% independent from the compiler (like in OpenGL, ...)
Standard ANSI Symbian OS
int
unsigend int float double boolean void* void
TInt
TUint TReal32 TReal64 TBool (ETrue, False) TAny* void
Naming Conventions
Why?
Make code more self-explaining (... and where's this variable coming from?) Get rid of references using this-> for instance variables
Important for clean-up (Instance variables stored on the heap have to be deleted in the destructor of your class) Common syntax no matter who developed the code
7 Andreas Jakl, 2007
Conventions: Variables
Enumeration constants
Enumeration itself: TDayOfWeek
Constants
Create with #define or const TInt ... e.g.: KMaxFileName, KRgbWhite
Conventions: Variables
Parameters (Arguments)
a is for Argument. Therefore no an!
Automatic variables
Without special prefix e.g.: position, text
Conventions: Classes
Classification of categories
Indirectly describe properties and behavior
10
Conventions: Classes
T-Classes
Must not own data on the heap: no destructor allowed
C-Classes
Always create them on the heap (using new()) Derived from CBase (compare to Java's Object)
Conventions: Classes
R-Classes
R = Handle to an external Resource Typical functions: Open(), Create(), Initialize() Don't forget: Close with Close() or Release()! e.g.: RFile, RTimer, RWindow
M-Classes
For abstract interfaces (see Java)
Static Classes
Without prefix. E.g.: User::After(1000)
12 Andreas Jakl, 2007
Symbian OS
Jump-Start
13
IDEs Carbide.c++
Editions:
Express: free
Carbide.c++
15
S60 SDKs
SDK 1st Ed.
Devices 7650 N-Gage, SX1, 3650, SendoX, 6600, 7610, 6670, 6260, 6630, 6680, 6681, N70, N90, E61, N73, N75, N95, E90, N96, N78, ? ?
Choose SDK depending on required compatibility and features Binary compatibility break with Symbian OS 9 www.forum.nokia.com
Commonly used for maximum compatibility
1st Ed, FP 1
2nd Ed
v7.0s
2nd Ed, FP 1 v7.0s 2nd Ed, FP 2 v8.0 2nd Ed, FP 3 v8.1 3rd Ed 3rd Ed, FP 1 3rd Ed, FP 2 5th Ed 5th Ed, FP1 v9.1 v9.2 v9.3 v9.4 v9.5?
Installation
1.
2.
3.
17
Updating Carbide.c++
Go to: Help Software Updates Find and Install... Choose: Search for new features to install Only use the Carbide.c++ Update Site do updating from other sites might overwrite Carbide.c++ settings!
18
Workspace
Workspace location:
Has to be on the same drive as the SDK ( C:\)
19
The Challenge
Features:
Displaying an image Text entry dialog Display text
20
21
22
Phone Build
Build configurations:
WINSCW: Build for the windows-based emulator ARMV5: Optimized builds for the device using the ARM RealView-compiler (commercial) GCCE: Standard builds for the device using the free GCC(E) compiler. Comes with the SDK
23
Choose UI-Design
24
Purpose Development use (< v9) Legacy UID (pre-v9) v9 protected UIDs
0xA0000000 0xAFFFFFFF v9 unprotected UIDs 0xE0000000 0xEFFFFFFF 0xF0000000 0xFFFFFFFF Development use (v9) Legacy UID (pre-v9)
25
Our Project
26
First tests
Compile
27
28
Compile Project
You can only use the mouse to navigate on the screen on touch-enabled emulators! Otherwise, use the buttons below.
Or:
29
Possible Problems
Compilation error:
***Generating makefiles. bldmake.bat bldfiles WINSCW UDEB WARNING: EPOCROOT does not specify an existing directory BLDMAKE ERROR: Directory "\Symbian\9.1\S60_3rd_MR\EPOC32\" does not exist Total Time: 0 sec ===Build Command = build WINSCW UDEB -v=== Exec error:Launching failed***build returned with exit value = -1 ***Stopping. Check the Problems view or Console output for errors. -1
your workspace / project is not on the same drive as the Symbian OS SDK (usually C:\) (told you to put it there several times )
30 Andreas Jakl, 2007
Possible Problems II
Emulator
32
33
Automatic Building
You might be used to Eclipse displaying errors as you type... ... but this is for Java, not for C++! You can still enable automatic compilation on resource change might be useful for smaller projects
Window Preferences... General Workspace Build automatically or: Project Build automatically
34 Andreas Jakl, 2007
Application structure
Application class
35
36
37
Handling of title- and status pane Command handling (for this view)
38
Handling of UI components
39
Avkon
CAknViewAppUi CAknApplication CAknDocument CAknAppUi CAknAppUiBase CAknView
Uikon
CEikApplication CEikDocument CEikAppUi
AppArc
CApaApplication
40
Cone
CApaDocument CCoeAppUi
Andreas Jakl, 2007
CCoeControl
UI-Design
Displaying an Image
41
Create an Image
42
Within Carbide.c++, go to the gfxfolder and press F5 to refresh the directory contents
43
Image
HelloWorldContainer.uidesign:
1.+2. add new image control
44
4. Switch to the .mbm-file (multi-bitmap, .mif is for vector graphics) 5. Edit MBM/MIF File...
6. Add From Project
45
* if the colours are not displayed correctly in the emulator, set the colour depth of the image to 12 bit instead of 8 bit.
46 Andreas Jakl, 2007
Interaction
47
48
Add a dialog
Edit properties:
Name: queryName Prompt: Enter name:
49
Maximum Length: 20
50
Click on optionsMenu
Create item Enter name by clicking into the menu Let Carbide write the code by selecting Handle selected Event
2.
3.
51
52
Strings in Symbian OS
Descriptors
53
Descriptors
Efficiency:
54
Strings in C
Memory view:
char* 0x64243184 h e l l o \0
Function strlen()
Reads from the beginning to '\0' and counts number of chars
55 Andreas Jakl, 2007
Pointer Descriptors
Constant: TPtrC 5
iLength (TDesC)
H e l l o
ROM, heap or stack
Buffer Descriptors
Constant: TBufC<5> H e l l o
Modifiable: TBuf<9> 5
iLength (TDesC)
9
iMaxLength (TDes)
H e l l o
57
New and easier to use: RBuf (see Descriptors section of this course)
Heap
HBufC* 0x64243184
H e l l o
58
Inheritance Hierarchy
Provide basic functions shared by all types (e.g. Compare(), Find(), Mid(), ...)
59
constant
modifiable
Literals
_LIT(KHello, Hello);
Builds a named object called KHello of type TLitC16 Stores the string Hello into the object
Displaying Text
61
Adding a Label
Category: Controls
Add: Label
Adapt properties:
Name: labelName Text:
62
63
64
65
Exceptions Java
66
Leave Symbian
DoExampleL()-Function void DoExampleL() { RFs fsSession; // Connect to the file server User::LeaveIfError(fsSession.Connect()); // fsSession.Close(); } Leaves if the Connect() function does not return KErrNone
Handling Leaves
69
2.
Failed object-construction
when using the new (ELeave)-operator
3.
User::Leave(TInt aReason)
Error code (aReason) = value that will be received by TRAP Causes leave in any case
User::LeaveIfError(TInt aReason)
Causes leave if parameter is negative, e.g.:
TInt foundAt = iElementArray.Find(example, aRelation); User::LeaveIfError(foundAt); // Leaves if foundAt == KErrNotFound (-1)
User::LeaveNoMemory()
Is the same as: User:Leave(KErrNoMem);
User::LeaveIfNull(TAny* aPtr)
71 Andreas Jakl, 2007
TRAP / TRAPD
TRAPD(result, MayLeaveL()); if (KErrNone!=result) ... is equivalent to: TInt result; TRAP(result, MayLeaveL()); if (KErrNone!=result) ...
If a leave occurs inside MayLeaveL(), which is executed inside the harness, the program code will return immediately to the TRAP harness macro
The variable result will contain the error code associated with the leave or will be KErrNone if no leave occured
72 Andreas Jakl, 2007
Panics
If a panic happens:
Make sure you fix it, as you cant handle it!
// Stray signal detected! _LIT(KMsgStraySignal, "Stray signal\n"); User::Panic(KMsgStraySignal, 1); // Panic with code 1
73 Andreas Jakl, 2007
TBool CHelloWorldContainerView::HandleEnter_name_MenuItemSelectedL( TInt aCommand ) { TBuf<20> userName; _LIT(KLongText, "This text is too long for a maximum length of 20, so a panic will occur."); userName.Copy(KLongText); // [...] }
75
In debug mode , your app. will be halted and you get more useful information:
76
USER 11 Panic: See SDK-Help Symbian OS v9.x Symbian OS reference System panic reference USER This panic is raised when any operation that moves or copies data to a 16-bit variant descriptor, causes the length of that descriptor to exceed its maximum length. It may be caused by any of the copying, appending or formatting member functions and, specifically, by the Insert(), Replace(), Fill(), Fillz() and ZeroTerminate() descriptor member functions. It can also be caused by the Andreas Jakl, 2007 SetLength() function. See TDes16.
Thats it!
77