1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>Creating and Using Components (KParts)</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.54"/><LINK
REL="HOME"
TITLE="KDE 2.0 Development"
HREF="index.html"/><LINK
REL="UP"
TITLE="Application Interaction and Integration"
HREF="p03.html"/><LINK
REL="PREVIOUS"
TITLE="Application Interaction and Integration"
HREF="p03.html"/><LINK
REL="NEXT"
TITLE="The KDE Component Framework"
HREF="ch12lev1sec2.html"/><META
HTTP-EQUIV="Content-Style-Type"
CONTENT="text/css"/><LINK
REL="stylesheet"
HREF="kde-common.css"
TYPE="text/css"/><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=iso-8859-1"/><META
HTTP-EQUIV="Content-Language"
CONTENT="en"/><LINK
REL="stylesheet"
HREF="kde-localised.css"
TYPE="text/css"
TITLE="KDE-English"/><LINK
REL="stylesheet"
HREF="kde-default.css"
TYPE="text/css"
TITLE="KDE-Default"/></HEAD
><BODY
CLASS="chapter"
LINK="#336699"
VLINK="#336699"
ALINK="#336699"
BGCOLOR="#FFFFFF"
><DIV
ALIGN="RIGHT"
CLASS="NAVBAR"
><P
><A
HREF="p03.html"
>Prev</A
> <A
HREF="ch12lev1sec2.html"
>Next</A
> <A
HREF="index.html"
>Table of Contents</A
></P
></DIV
><DIV
CLASS="chapter"
><H1
><A
NAME="ch12"
>Chapter 12. Creating and Using Components (KParts)</A
></H1
><P
> <I
CLASS="emphasis"
>by David Faure</I
>
</P
><DIV
CLASS="highlights"
><A
NAME="AEN16434"
></A
><P
><B
>In this chapter</B
></P
><UL
COMPACT="COMPACT"
><LI
STYLE="list-style-type: disc"
><P
> <I
CLASS="emphasis"
> <A
HREF="ch12.html#ch12lev1sec1"
>The Difference Between Components and Widgets</A
>
</I
>
</P
></LI
><LI
STYLE="list-style-type: disc"
><P
> <I
CLASS="emphasis"
> <A
HREF="ch12lev1sec2.html"
>The KDE Component Framework</A
>
</I
>
</P
></LI
><LI
STYLE="list-style-type: disc"
><P
> <I
CLASS="emphasis"
> <A
HREF="ch12lev1sec3.html"
>Describing User Interface in XML</A
>
</I
>
</P
></LI
><LI
STYLE="list-style-type: disc"
><P
> <I
CLASS="emphasis"
> <A
HREF="ch12lev1sec4.html"
>Read-Only and Read/Write Parts</A
>
</I
>
</P
></LI
><LI
STYLE="list-style-type: disc"
><P
> <I
CLASS="emphasis"
> <A
HREF="ch12lev1sec5.html"
>Creating a Part</A
>
</I
>
</P
></LI
><LI
STYLE="list-style-type: disc"
><P
> <I
CLASS="emphasis"
> <A
HREF="ch12lev1sec6.html"
>Making a Part Available Using Shared Libraries</A
>
</I
>
</P
></LI
><LI
STYLE="list-style-type: disc"
><P
> <I
CLASS="emphasis"
> <A
HREF="ch12lev1sec7.html"
>Creating a KParts Application</A
>
</I
>
</P
></LI
><LI
STYLE="list-style-type: disc"
><P
> <I
CLASS="emphasis"
> <A
HREF="ch12lev1sec8.html"
>Embedding More Than One Part in the Same Window</A
>
</I
>
</P
></LI
><LI
STYLE="list-style-type: disc"
><P
> <I
CLASS="emphasis"
> <A
HREF="ch12lev1sec9.html"
>Creating a KParts Plug-in</A
>
</I
>
</P
></LI
></UL
></DIV
><P
>The
main idea behind components is reusability. Often, an application wants to use a functionality that another application provides. Of course, the way to do that is simply to create a shared library that both applications use. But without a standard framework for this, it means both applications are very much coupled to the library's API and will need to be changed if the applications decide to use another library instead. Furthermore, integrating the shared functionality has to be done manually by every application.</P
><P
>A framework for components enables an application to use a component it never heard of—and wasn't specifically adapted for—because both the application and the component comply to the framework and know what to expect from each other. An existing component can be replaced with a new implementation of the same functionality, without changing a single line of code in the application, because the interface remains the same.</P
><P
>The framework presented here concerns elaborate graphical components, such as an image viewer, a text editor, a mail composer, and so on. Simpler graphical components are usually widgets; I refine this distinction in the next section. Nongraphical components, such as a parser or a string manipulation class, are usually libraries with a specific Application Programming Interface (API).</P
><P
>Similar frameworks for graphical components exist for a different environment, such as IBM and Apple's OpenDoc, Microsoft's OLE, Gnome's Bonobo, and KDE's previous OpenParts.
</P
><DIV
CLASS="section"
><TABLE
WIDTH="100%"
CELLPADDING="0"
CELLSPACING="0"
BORDER="0"
ALIGN="CENTER"
><TR
><TD
WIDTH="90%"
><H1
CLASS="section"
><A
NAME="ch12lev1sec1"
>12.1. The Difference Between Components and Widgets</A
></H1
><P
>A KDE
component is called a part, and it encapsulates three things: a widget, the functionality that comes with it, and the user interface for this functionality.</P
><P
>The usual example is a text editor component. Its widget is a multiline text widget; its functionality might include Search And Replace, Copy, Cut, Paste, Undo, Redo, Spell Checking. To make it possible for the user to access this functionality, the component also provides the user interface for it: menu items and toolbar buttons.</P
><P
>An application using this component will get the widget embedded into a parent widget it provides, as well as the component's user interface merged into its own menubar and toolbars. This is like embedding a MS Excel document into MS Word, an example everybody knows, or when embedding a KSpread document into KWord, an example that will hopefully become very well known as well.</P
><P
>Another example of very useful component is an image viewer. When using KDE's file manager (Konqueror), clicking an image file opens the image viewer component from KDE's image viewer (KView) and shows it inside Konqueror's window. The part provides actions for zoom in, zoom out, rotate, reset to original size, and orientation.
</P
><DIV
CLASS="note"
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="note.png"
HSPACE="5"
ALT="Note"/></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Note that KOffice parts are a bit different because they don't embed as a full window, but as a frame into the parent's view, which can be moved, resized, and even rotated—a functionality only KOffice has. This and the document/view architecture of KOffice applications mean that the framework for KOffice parts, although based on KParts, is much more elaborate and out of topic here.</P
></TD
></TR
></TABLE
></DIV
><P
>So, when do you use a part and when do you use a widget?</P
><P
>Use a widget when all the functionality is in the widget itself and doesn't need additional user interface (menu items or toolbar buttons). A button is a widget, a multiline edit is a widget, but a text editor with all the functionality previously mentioned is a part. As you can see there is no problem choosing which one to use.
</P
></TD
><TD
WIDTH="10%"
VALIGN="BOTTOM"
ALIGN="CENTER"
><ANNMARK
NAME="ch12lev1sec1"/></TD
></TR
><ANNOTATION
NAME="ch12lev1sec1"
TITLE="The Difference Between Components and Widgets"/></TABLE
></DIV
></DIV
><DIV
ALIGN="RIGHT"
CLASS="NAVBAR"
><P
><A
HREF="p03.html"
>Prev</A
> <A
HREF="ch12lev1sec2.html"
>Next</A
> <A
HREF="index.html"
>Table of Contents</A
></P
></DIV
><HR
WIDTH="100%"
SIZE="2"
ALIGN="CENTER"
NOSHADE="NOSHADE"/></BODY
></HTML
>
|